diff --git a/sdk/appconfiguration/app-configuration/CHANGELOG.md b/sdk/appconfiguration/app-configuration/CHANGELOG.md index d28c42fe9419..cceb1680ff88 100644 --- a/sdk/appconfiguration/app-configuration/CHANGELOG.md +++ b/sdk/appconfiguration/app-configuration/CHANGELOG.md @@ -1,5 +1,10 @@ # Release History +## 1.2.0-beta.1 (Unreleased) + +- Added `updateSyncToken` method to `AppConfigurationClient` to be able to provide external synchronization tokens. + [PR #14507](https://github.com/Azure/azure-sdk-for-js/pull/14507) + ## 1.1.1 (2021-03-25) - Fix issues with `select`ing fields to be returned from `listConfigurationSettings`, `listConfigurationRevisions` @@ -13,7 +18,7 @@ ## 1.0.1 (2020-02-19) - The underlying filter behavior has changed for `listConfigurationSettings` and `listRevisions`. - Inline documentation has been revised to accomodate it. + Inline documentation has been revised to accommodate it. ## 1.0.0 (2020-01-06) diff --git a/sdk/appconfiguration/app-configuration/review/app-configuration.api.md b/sdk/appconfiguration/app-configuration/review/app-configuration.api.md index d4e7d36e40e6..8ff2c801fee2 100644 --- a/sdk/appconfiguration/app-configuration/review/app-configuration.api.md +++ b/sdk/appconfiguration/app-configuration/review/app-configuration.api.md @@ -33,7 +33,8 @@ export class AppConfigurationClient { listRevisions(options?: ListRevisionsOptions): PagedAsyncIterableIterator; setConfigurationSetting(configurationSetting: SetConfigurationSettingParam, options?: SetConfigurationSettingOptions): Promise; setReadOnly(id: ConfigurationSettingId, readOnly: boolean, options?: SetReadOnlyOptions): Promise; - } + updateSyncToken(syncToken: string): void; +} // @public export interface AppConfigurationClientOptions { diff --git a/sdk/appconfiguration/app-configuration/src/appConfigurationClient.ts b/sdk/appconfiguration/app-configuration/src/appConfigurationClient.ts index 3cf42a4fa36e..b66392178f95 100644 --- a/sdk/appconfiguration/app-configuration/src/appConfigurationClient.ts +++ b/sdk/appconfiguration/app-configuration/src/appConfigurationClient.ts @@ -115,6 +115,7 @@ export interface InternalAppConfigurationClientOptions extends AppConfigurationC */ export class AppConfigurationClient { private client: AppConfiguration; + private _syncTokens: SyncTokens; // (for tests) private _trace = traceFromTracingHelpers; @@ -164,13 +165,13 @@ export class AppConfigurationClient { } } - const syncTokens = appConfigOptions.syncTokens || new SyncTokens(); + this._syncTokens = appConfigOptions.syncTokens || new SyncTokens(); this.client = new AppConfiguration( appConfigCredential, appConfigEndpoint, apiVersion, - getGeneratedClientOptions(appConfigEndpoint, syncTokens, appConfigOptions) + getGeneratedClientOptions(appConfigEndpoint, this._syncTokens, appConfigOptions) ); } @@ -496,8 +497,16 @@ export class AppConfigurationClient { } }); } -} + /** + * Adds an external synchronization token to ensure service requests receive up-to-date values. + * + * @param syncToken The synchronization token value. + */ + updateSyncToken(syncToken: string): void { + this._syncTokens.addSyncTokenFromHeaderValue(syncToken); + } +} /** * Gets the options for the generated AppConfigurationClient * @internal diff --git a/sdk/appconfiguration/app-configuration/test/internal/http.spec.ts b/sdk/appconfiguration/app-configuration/test/internal/http.spec.ts index 32188c42deca..32a476e598e3 100644 --- a/sdk/appconfiguration/app-configuration/test/internal/http.spec.ts +++ b/sdk/appconfiguration/app-configuration/test/internal/http.spec.ts @@ -292,6 +292,38 @@ describe("http request related tests", function() { assert.equal(syncTokens.getSyncTokenHeaderValue(), "clearReadOnly=value"); }); }); + + describe("syncToken", async () => { + it("update sync token", async () => { + const syncTokens = new SyncTokens(); + syncTokens.addSyncTokenFromHeaderValue("a=value;sn=0"); + const client = new AppConfigurationClient( + "Endpoint=https://endpoint.azconfig.io;Id=abc;Secret=123", + { syncTokens } as InternalAppConfigurationClientOptions + ); + assert.equal( + syncTokens["_currentSyncTokens"].size, + 1, + "Unexpected number of syncTokens before the `update` call" + ); + client.updateSyncToken("b=value;sn=3"); + assert.equal( + syncTokens["_currentSyncTokens"].size, + 2, + "Unexpected number of syncTokens after the `update` call" + ); + assert.deepEqual( + syncTokens["_currentSyncTokens"].get("a"), + { id: "a", value: "value", sequenceNumber: 0 }, + "Unexpected object present for key `a`" + ); + assert.deepEqual( + syncTokens["_currentSyncTokens"].get("b"), + { id: "b", value: "value", sequenceNumber: 3 }, + "Unexpected object present for key `b`" + ); + }); + }); }); function splitAndSort(syncTokens: string | undefined): string {