From a89dc8d9be0d9a88200ece070e9c7416b06b536d Mon Sep 17 00:00:00 2001 From: Harsha Nalluru Date: Fri, 26 Mar 2021 12:18:38 -0700 Subject: [PATCH] [App Config] updateSyncToken method (#14507) ### TODOs - [x] Add the new `updateSyncToken` method to `AppConfigurationClient` (Picked up pieces from @richardpark-msft's work here https://github.com/Azure/azure-sdk-for-js/pull/14342.) - [x] Add a unit test - [x] ~~Hoping to add a live test by leveraging the eventgrid SDK~~ - [x] Changelog - [x] Hold off merging - wait for 1.1.1 to be released - [x] What's the new version number for preview? - `1.2.0-beta.1` fine? Reference: PR from .NET https://github.com/Azure/azure-sdk-for-net/pull/18487 --- .../app-configuration/CHANGELOG.md | 7 +++- .../review/app-configuration.api.md | 3 +- .../src/appConfigurationClient.ts | 15 +++++++-- .../test/internal/http.spec.ts | 32 +++++++++++++++++++ 4 files changed, 52 insertions(+), 5 deletions(-) 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 {