Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[App Config] updateSyncToken method #14507

Merged
11 commits merged into from
Mar 26, 2021
7 changes: 6 additions & 1 deletion sdk/appconfiguration/app-configuration/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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 (Unreleased)

- Fix issues with `select`ing fields to be returned from `listConfigurationSettings`, `listConfigurationRevisions`
Expand All @@ -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)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ export class AppConfigurationClient {
listRevisions(options?: ListRevisionsOptions): PagedAsyncIterableIterator<ConfigurationSetting, ListRevisionsPage>;
setConfigurationSetting(configurationSetting: SetConfigurationSettingParam, options?: SetConfigurationSettingOptions): Promise<SetConfigurationSettingResponse>;
setReadOnly(id: ConfigurationSettingId, readOnly: boolean, options?: SetReadOnlyOptions): Promise<SetReadOnlyResponse>;
}
updateSyncToken(syncToken: string): void;
}

// @public
export interface AppConfigurationClientOptions {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ export interface InternalAppConfigurationClientOptions extends AppConfigurationC
*/
export class AppConfigurationClient {
private client: AppConfiguration;
private _syncTokens: SyncTokens;
// (for tests)
private _trace = traceFromTracingHelpers;

Expand Down Expand Up @@ -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)
);
}

Expand Down Expand Up @@ -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
Expand Down
32 changes: 32 additions & 0 deletions sdk/appconfiguration/app-configuration/test/internal/http.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,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 {
Expand Down