UNPKG

@azure/app-configuration

Version:
748 lines • 35.3 kB
"use strict"; // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. Object.defineProperty(exports, "__esModule", { value: true }); exports.AppConfigurationClient = void 0; const core_paging_1 = require("@azure/core-paging"); const core_rest_pipeline_1 = require("@azure/core-rest-pipeline"); const audienceErrorHandlingPolicy_js_1 = require("./internal/audienceErrorHandlingPolicy.js"); const syncTokenPolicy_js_1 = require("./internal/syncTokenPolicy.js"); const queryParamPolicy_js_1 = require("./internal/queryParamPolicy.js"); const core_auth_1 = require("@azure/core-auth"); const helpers_js_1 = require("./internal/helpers.js"); const appConfiguration_js_1 = require("./generated/src/appConfiguration.js"); const appConfigCredential_js_1 = require("./appConfigCredential.js"); const tracing_js_1 = require("./internal/tracing.js"); const logger_js_1 = require("./logger.js"); const constants_js_1 = require("./internal/constants.js"); const ConnectionStringRegex = /Endpoint=(.*);Id=(.*);Secret=(.*)/; const deserializationContentTypes = { json: [ "application/vnd.microsoft.appconfig.kvset+json", "application/vnd.microsoft.appconfig.kv+json", "application/vnd.microsoft.appconfig.kvs+json", "application/vnd.microsoft.appconfig.keyset+json", "application/vnd.microsoft.appconfig.revs+json", "application/vnd.microsoft.appconfig.snapshotset+json", "application/vnd.microsoft.appconfig.snapshot+json", "application/vnd.microsoft.appconfig.labelset+json", "application/json", ], }; /** * Client for the Azure App Configuration service. */ class AppConfigurationClient { client; _syncTokens; constructor(connectionStringOrEndpoint, tokenCredentialOrOptions, options) { let appConfigOptions = {}; let appConfigCredential; let appConfigEndpoint; let authPolicy; let scope; if ((0, core_auth_1.isTokenCredential)(tokenCredentialOrOptions)) { appConfigOptions = options || {}; appConfigCredential = tokenCredentialOrOptions; appConfigEndpoint = connectionStringOrEndpoint.endsWith("/") ? connectionStringOrEndpoint.slice(0, -1) : connectionStringOrEndpoint; scope = (0, helpers_js_1.getScope)(appConfigEndpoint, appConfigOptions.audience); authPolicy = (0, core_rest_pipeline_1.bearerTokenAuthenticationPolicy)({ scopes: scope, credential: appConfigCredential, }); } else { appConfigOptions = tokenCredentialOrOptions || {}; const regexMatch = connectionStringOrEndpoint?.match(ConnectionStringRegex); if (regexMatch) { appConfigEndpoint = regexMatch[1]; authPolicy = (0, appConfigCredential_js_1.appConfigKeyCredentialPolicy)(regexMatch[2], regexMatch[3]); } else { throw new Error(`Invalid connection string. Valid connection strings should match the regex '${ConnectionStringRegex.source}'.` + ` To mitigate the issue, please refer to the troubleshooting guide here at https://aka.ms/azsdk/js/app-configuration/troubleshoot.`); } } const internalClientPipelineOptions = { ...appConfigOptions, loggingOptions: { logger: logger_js_1.logger.info, }, deserializationOptions: { expectedContentTypes: deserializationContentTypes, }, }; this._syncTokens = appConfigOptions.syncTokens || new syncTokenPolicy_js_1.SyncTokens(); this.client = new appConfiguration_js_1.AppConfiguration(appConfigEndpoint, options?.apiVersion ?? constants_js_1.appConfigurationApiVersion, internalClientPipelineOptions); this.client.pipeline.addPolicy((0, audienceErrorHandlingPolicy_js_1.audienceErrorHandlingPolicy)(appConfigOptions?.audience !== undefined), { phase: "Sign", beforePolicies: [authPolicy.name], }); this.client.pipeline.addPolicy(authPolicy, { phase: "Sign" }); this.client.pipeline.addPolicy((0, queryParamPolicy_js_1.queryParamPolicy)()); this.client.pipeline.addPolicy((0, syncTokenPolicy_js_1.syncTokenPolicy)(this._syncTokens), { afterPhase: "Retry" }); } /** * Add a setting into the Azure App Configuration service, failing if it * already exists. * * Example usage: * ```ts snippet:AddConfigurationSetting * import { DefaultAzureCredential } from "@azure/identity"; * import { AppConfigurationClient } from "@azure/app-configuration"; * * // The endpoint for your App Configuration resource * const endpoint = "https://example.azconfig.io"; * const credential = new DefaultAzureCredential(); * const client = new AppConfigurationClient(endpoint, credential); * * const result = await client.addConfigurationSetting({ * key: "MyKey", * label: "MyLabel", * value: "MyValue", * }); * ``` * @param configurationSetting - A configuration setting. * @param options - Optional parameters for the request. */ addConfigurationSetting(configurationSetting, options = {}) { return tracing_js_1.tracingClient.withSpan("AppConfigurationClient.addConfigurationSetting", options, async (updatedOptions) => { const keyValue = (0, helpers_js_1.serializeAsConfigurationSettingParam)(configurationSetting); logger_js_1.logger.info("[addConfigurationSetting] Creating a key value pair"); try { const originalResponse = await this.client.putKeyValue(configurationSetting.key, { ifNoneMatch: "*", label: configurationSetting.label, entity: keyValue, ...updatedOptions, }); const response = (0, helpers_js_1.transformKeyValueResponse)(originalResponse); (0, helpers_js_1.assertResponse)(response); return response; } catch (error) { const err = error; // Service does not return an error message. Raise a 412 error similar to .NET if (err.statusCode === 412) { err.message = `Status 412: Setting was already present`; } throw err; } throw new Error("Unreachable code"); }); } /** * Delete a setting from the Azure App Configuration service * * Example usage: * ```ts snippet:DeleteConfigurationSetting * import { DefaultAzureCredential } from "@azure/identity"; * import { AppConfigurationClient } from "@azure/app-configuration"; * * // The endpoint for your App Configuration resource * const endpoint = "https://example.azconfig.io"; * const credential = new DefaultAzureCredential(); * const client = new AppConfigurationClient(endpoint, credential); * * const deletedSetting = await client.deleteConfigurationSetting({ * key: "MyKey", * label: "MyLabel", * }); * ``` * @param id - The id of the configuration setting to delete. * @param options - Optional parameters for the request (ex: etag, label) */ deleteConfigurationSetting(id, options = {}) { return tracing_js_1.tracingClient.withSpan("AppConfigurationClient.deleteConfigurationSetting", options, async (updatedOptions) => { let status; logger_js_1.logger.info("[deleteConfigurationSetting] Deleting key value pair"); const originalResponse = await this.client.deleteKeyValue(id.key, { label: id.label, ...updatedOptions, ...(0, helpers_js_1.checkAndFormatIfAndIfNoneMatch)(id, options), onResponse: (response) => { status = response.status; }, }); const response = (0, helpers_js_1.transformKeyValueResponseWithStatusCode)(originalResponse, status); (0, helpers_js_1.assertResponse)(response); return response; }); } /** * Gets a setting from the Azure App Configuration service. * * Example code: * ```ts snippet:GetConfigurationSetting * import { DefaultAzureCredential } from "@azure/identity"; * import { AppConfigurationClient } from "@azure/app-configuration"; * * // The endpoint for your App Configuration resource * const endpoint = "https://example.azconfig.io"; * const credential = new DefaultAzureCredential(); * const client = new AppConfigurationClient(endpoint, credential); * * const setting = await client.getConfigurationSetting({ key: "MyKey", label: "MyLabel" }); * ``` * @param id - The id of the configuration setting to get. * @param options - Optional parameters for the request. */ async getConfigurationSetting(id, options = {}) { return tracing_js_1.tracingClient.withSpan("AppConfigurationClient.getConfigurationSetting", options, async (updatedOptions) => { let status; logger_js_1.logger.info("[getConfigurationSetting] Getting key value pair"); const originalResponse = await this.client.getKeyValue(id.key, { ...updatedOptions, label: id.label, select: (0, helpers_js_1.formatFieldsForSelect)(options.fields), ...(0, helpers_js_1.formatAcceptDateTime)(options), ...(0, helpers_js_1.checkAndFormatIfAndIfNoneMatch)(id, options), onResponse: (response) => { status = response.status; }, }); const response = (0, helpers_js_1.transformKeyValueResponseWithStatusCode)(originalResponse, status); // 304 only comes back if the user has passed a conditional option in their // request _and_ the remote object has the same etag as what the user passed. if (response.statusCode === 304) { // this is one of our few 'required' fields so we'll make sure it does get initialized // with a value response.key = id.key; // and now we'll undefine all the other properties that are not HTTP related (0, helpers_js_1.makeConfigurationSettingEmpty)(response); } (0, helpers_js_1.assertResponse)(response); return response; }); } /** * Lists settings from the Azure App Configuration service, optionally * filtered by key names, labels and accept datetime. * * Example code: * ```ts snippet:ListConfigurationSettings * import { DefaultAzureCredential } from "@azure/identity"; * import { AppConfigurationClient } from "@azure/app-configuration"; * * // The endpoint for your App Configuration resource * const endpoint = "https://example.azconfig.io"; * const credential = new DefaultAzureCredential(); * const client = new AppConfigurationClient(endpoint, credential); * * const allSettingsWithLabel = client.listConfigurationSettings({ labelFilter: "MyLabel" }); * ``` * @param options - Optional parameters for the request. */ listConfigurationSettings(options = {}) { const pageEtags = options.pageEtags ? [...options.pageEtags] : undefined; delete options.pageEtags; const pagedResult = { firstPageLink: undefined, getPage: async (pageLink) => { const etag = pageEtags?.shift(); try { const response = await this.sendConfigurationSettingsRequest({ ...options, etag }, pageLink); const currentResponse = { ...response, items: response.items != null ? response.items?.map(helpers_js_1.transformKeyValue) : [], continuationToken: response.nextLink ? (0, helpers_js_1.extractAfterTokenFromNextLink)(response.nextLink) : undefined, _response: response._response, }; return { page: currentResponse, nextPageLink: currentResponse.continuationToken, }; } catch (error) { const err = error; const link = err.response?.headers?.get("link"); const continuationToken = link ? (0, helpers_js_1.extractAfterTokenFromLinkHeader)(link) : undefined; if (err.statusCode === 304) { err.message = `Status 304: No updates for this page`; logger_js_1.logger.info(`[listConfigurationSettings] No updates for this page. The current etag for the page is ${etag}`); return { page: { items: [], etag, _response: { ...err.response, status: 304 }, }, nextPageLink: continuationToken, }; } throw err; } }, toElements: (page) => page.items, }; return (0, core_paging_1.getPagedAsyncIterator)(pagedResult); } /** * Checks settings from the Azure App Configuration service using a HEAD request, returning only headers without the response body. * This is useful for efficiently checking if settings have changed by comparing ETags. * * Example code: * ```ts snippet:CheckConfigurationSettings * import { DefaultAzureCredential } from "@azure/identity"; * import { AppConfigurationClient } from "@azure/app-configuration"; * * // The endpoint for your App Configuration resource * const endpoint = "https://example.azconfig.io"; * const credential = new DefaultAzureCredential(); * const client = new AppConfigurationClient(endpoint, credential); * * const pageIterator = client.checkConfigurationSettings({ keyFilter: "MyKey" }).byPage(); * ``` * @param options - Optional parameters for the request. */ checkConfigurationSettings(options = {}) { const pageEtags = options.pageEtags ? [...options.pageEtags] : undefined; delete options.pageEtags; const pagedResult = { firstPageLink: undefined, getPage: async (pageLink) => { const etag = pageEtags?.shift(); try { const response = await this.checkConfigurationSettingsRequest({ ...options, etag }, pageLink); const link = response._response?.headers?.get("link"); const continuationToken = link ? (0, helpers_js_1.extractAfterTokenFromLinkHeader)(link) : undefined; const currentResponse = { ...response, etag: response._response?.headers?.get("etag"), items: [], continuationToken: continuationToken, _response: response._response, }; return { page: currentResponse, nextPageLink: currentResponse.continuationToken, }; } catch (error) { const err = error; const link = err.response?.headers?.get("link"); const continuationToken = link ? (0, helpers_js_1.extractAfterTokenFromLinkHeader)(link) : undefined; if (err.statusCode === 304) { err.message = `Status 304: No updates for this page`; logger_js_1.logger.info(`[checkConfigurationSettings] No updates for this page. The current etag for the page is ${etag}`); return { page: { items: [], etag, _response: { ...err.response, status: 304 }, }, nextPageLink: continuationToken, }; } throw err; } }, toElements: (page) => page.items, }; return (0, core_paging_1.getPagedAsyncIterator)(pagedResult); } /** * Lists settings from the Azure App Configuration service for snapshots based on name, optionally * filtered by key names, labels and accept datetime. * * Example code: * ```ts snippet:ListConfigurationSettingsForSnashots * import { DefaultAzureCredential } from "@azure/identity"; * import { AppConfigurationClient } from "@azure/app-configuration"; * * // The endpoint for your App Configuration resource * const endpoint = "https://example.azconfig.io"; * const credential = new DefaultAzureCredential(); * const client = new AppConfigurationClient(endpoint, credential); * * const allSettingsWithLabel = client.listConfigurationSettingsForSnashots({ * snapshotName: "MySnapshot", * }); * ``` * @param options - Optional parameters for the request. */ listConfigurationSettingsForSnapshot(snapshotName, options = {}) { const pagedResult = { firstPageLink: undefined, getPage: async (pageLink) => { const response = await this.sendConfigurationSettingsRequest({ snapshotName, ...options }, pageLink); const currentResponse = { ...response, items: response.items != null ? response.items?.map(helpers_js_1.transformKeyValue) : [], continuationToken: response.nextLink ? (0, helpers_js_1.extractAfterTokenFromNextLink)(response.nextLink) : undefined, }; return { page: currentResponse, nextPageLink: currentResponse.continuationToken, }; }, toElements: (page) => page.items, }; return (0, core_paging_1.getPagedAsyncIterator)(pagedResult); } /** * Get a list of labels from the Azure App Configuration service * * Example code: * ```ts snippet:ListLabels * import { DefaultAzureCredential } from "@azure/identity"; * import { AppConfigurationClient } from "@azure/app-configuration"; * * // The endpoint for your App Configuration resource * const endpoint = "https://example.azconfig.io"; * const credential = new DefaultAzureCredential(); * const client = new AppConfigurationClient(endpoint, credential); * * const allSettingsWithLabel = client.listLabels({ nameFilter: "prod*" }); * ``` * @param options - Optional parameters for the request. */ listLabels(options = {}) { const pagedResult = { firstPageLink: undefined, getPage: async (pageLink) => { const response = await this.sendLabelsRequest(options, pageLink); const currentResponse = { ...response, items: response.items ?? [], continuationToken: response.nextLink ? (0, helpers_js_1.extractAfterTokenFromNextLink)(response.nextLink) : undefined, _response: response._response, }; return { page: currentResponse, nextPageLink: currentResponse.continuationToken, }; }, toElements: (page) => page.items, }; return (0, core_paging_1.getPagedAsyncIterator)(pagedResult); } async sendLabelsRequest(options = {}, pageLink) { return tracing_js_1.tracingClient.withSpan("AppConfigurationClient.listConfigurationSettings", options, async (updatedOptions) => { const response = await this.client.getLabels({ ...updatedOptions, ...(0, helpers_js_1.formatAcceptDateTime)(options), ...(0, helpers_js_1.formatLabelsFiltersAndSelect)(options), after: pageLink, }); return response; }); } async sendConfigurationSettingsRequest(options = {}, pageLink) { return tracing_js_1.tracingClient.withSpan("AppConfigurationClient.listConfigurationSettings", options, async (updatedOptions) => { const response = await this.client.getKeyValues({ ...updatedOptions, ...(0, helpers_js_1.formatAcceptDateTime)(options), ...(0, helpers_js_1.formatConfigurationSettingsFiltersAndSelect)(options), ...(0, helpers_js_1.checkAndFormatIfAndIfNoneMatch)({ etag: options.etag }, { onlyIfChanged: true }), after: pageLink, }); return response; }); } async checkConfigurationSettingsRequest(options = {}, pageLink) { return tracing_js_1.tracingClient.withSpan("AppConfigurationClient.checkConfigurationSettings", options, async (updatedOptions) => { const response = await this.client.checkKeyValues({ ...updatedOptions, ...(0, helpers_js_1.formatAcceptDateTime)(options), ...(0, helpers_js_1.formatConfigurationSettingsFiltersAndSelect)(options), ...(0, helpers_js_1.checkAndFormatIfAndIfNoneMatch)({ etag: options.etag }, { onlyIfChanged: true }), after: pageLink, }); return response; }); } /** * Lists revisions of a set of keys, optionally filtered by key names, * labels and accept datetime. * * Example code: * ```ts snippet:ListRevisions * import { DefaultAzureCredential } from "@azure/identity"; * import { AppConfigurationClient } from "@azure/app-configuration"; * * // The endpoint for your App Configuration resource * const endpoint = "https://example.azconfig.io"; * const credential = new DefaultAzureCredential(); * const client = new AppConfigurationClient(endpoint, credential); * * const revisionsIterator = client.listRevisions({ keys: ["MyKey"] }); * ``` * @param options - Optional parameters for the request. */ listRevisions(options) { const pagedResult = { firstPageLink: undefined, getPage: async (pageLink) => { const response = await this.sendRevisionsRequest(options, pageLink); const currentResponse = { ...response, items: response.items != null ? response.items.map(helpers_js_1.transformKeyValue) : [], continuationToken: response.nextLink ? (0, helpers_js_1.extractAfterTokenFromNextLink)(response.nextLink) : undefined, }; // let itemList = currentResponse.items; return { page: currentResponse, nextPageLink: currentResponse.continuationToken, }; }, toElements: (page) => page.items, }; return (0, core_paging_1.getPagedAsyncIterator)(pagedResult); } async sendRevisionsRequest(options = {}, pageLink) { return tracing_js_1.tracingClient.withSpan("AppConfigurationClient.listRevisions", options, async (updatedOptions) => { const response = await this.client.getRevisions({ ...updatedOptions, ...(0, helpers_js_1.formatAcceptDateTime)(options), ...(0, helpers_js_1.formatFiltersAndSelect)(updatedOptions), after: pageLink, }); return response; }); } /** * Sets the value of a key in the Azure App Configuration service, allowing for an optional etag. * @param key - The name of the key. * @param configurationSetting - A configuration value. * @param options - Optional parameters for the request. * * Example code: * ```ts snippet:SetConfigurationSetting * import { DefaultAzureCredential } from "@azure/identity"; * import { AppConfigurationClient } from "@azure/app-configuration"; * * // The endpoint for your App Configuration resource * const endpoint = "https://example.azconfig.io"; * const credential = new DefaultAzureCredential(); * const client = new AppConfigurationClient(endpoint, credential); * * await client.setConfigurationSetting({ key: "MyKey", value: "MyValue" }); * ``` */ async setConfigurationSetting(configurationSetting, options = {}) { return tracing_js_1.tracingClient.withSpan("AppConfigurationClient.setConfigurationSetting", options, async (updatedOptions) => { const keyValue = (0, helpers_js_1.serializeAsConfigurationSettingParam)(configurationSetting); logger_js_1.logger.info("[setConfigurationSetting] Setting new key value"); const response = (0, helpers_js_1.transformKeyValueResponse)(await this.client.putKeyValue(configurationSetting.key, { ...updatedOptions, label: configurationSetting.label, entity: keyValue, ...(0, helpers_js_1.checkAndFormatIfAndIfNoneMatch)(configurationSetting, options), })); (0, helpers_js_1.assertResponse)(response); return response; }); } /** * Sets or clears a key's read-only status. * @param id - The id of the configuration setting to modify. */ async setReadOnly(id, readOnly, options = {}) { return tracing_js_1.tracingClient.withSpan("AppConfigurationClient.setReadOnly", options, async (newOptions) => { let response; if (readOnly) { logger_js_1.logger.info("[setReadOnly] Setting read-only status to ${readOnly}"); response = await this.client.putLock(id.key, { ...newOptions, label: id.label, ...(0, helpers_js_1.checkAndFormatIfAndIfNoneMatch)(id, options), }); } else { logger_js_1.logger.info("[setReadOnly] Deleting read-only lock"); response = await this.client.deleteLock(id.key, { ...newOptions, label: id.label, ...(0, helpers_js_1.checkAndFormatIfAndIfNoneMatch)(id, options), }); } response = (0, helpers_js_1.transformKeyValueResponse)(response); (0, helpers_js_1.assertResponse)(response); return response; }); } /** * Adds an external synchronization token to ensure service requests receive up-to-date values. * * @param syncToken - The synchronization token value. */ updateSyncToken(syncToken) { this._syncTokens.addSyncTokenFromHeaderValue(syncToken); } /** * Begins creating a snapshot for Azure App Configuration service, fails if it * already exists. */ beginCreateSnapshot(snapshot, // eslint-disable-next-line @azure/azure-sdk/ts-naming-options options = {}) { return tracing_js_1.tracingClient.withSpan(`${AppConfigurationClient.name}.beginCreateSnapshot`, options, (updatedOptions) => this.client.beginCreateSnapshot(snapshot.name, snapshot, { ...updatedOptions })); } /** * Begins creating a snapshot for Azure App Configuration service, waits until it is done, * fails if it already exists. */ beginCreateSnapshotAndWait(snapshot, // eslint-disable-next-line @azure/azure-sdk/ts-naming-options options = {}) { return tracing_js_1.tracingClient.withSpan(`${AppConfigurationClient.name}.beginCreateSnapshotAndWait`, options, (updatedOptions) => this.client.beginCreateSnapshotAndWait(snapshot.name, snapshot, { ...updatedOptions })); } /** * Get a snapshot from Azure App Configuration service * * Example usage: * ```ts snippet:GetSnapshot * import { DefaultAzureCredential } from "@azure/identity"; * import { AppConfigurationClient } from "@azure/app-configuration"; * * // The endpoint for your App Configuration resource * const endpoint = "https://example.azconfig.io"; * const credential = new DefaultAzureCredential(); * const client = new AppConfigurationClient(endpoint, credential); * * const retrievedSnapshot = await client.getSnapshot("testsnapshot"); * console.log("Retrieved snapshot:", retrievedSnapshot); * ``` * @param name - The name of the snapshot. * @param options - Optional parameters for the request. */ getSnapshot(name, options = {}) { return tracing_js_1.tracingClient.withSpan("AppConfigurationClient.getSnapshot", options, async (updatedOptions) => { logger_js_1.logger.info("[getSnapshot] Get a snapshot"); const originalResponse = await this.client.getSnapshot(name, { ...updatedOptions, }); const response = (0, helpers_js_1.transformSnapshotResponse)(originalResponse); (0, helpers_js_1.assertResponse)(response); return response; }); } /** * Recover an archived snapshot back to ready status * * Example usage: * ```ts snippet:RecoverSnapshot * import { DefaultAzureCredential } from "@azure/identity"; * import { AppConfigurationClient } from "@azure/app-configuration"; * * // The endpoint for your App Configuration resource * const endpoint = "https://example.azconfig.io"; * const credential = new DefaultAzureCredential(); * const client = new AppConfigurationClient(endpoint, credential); * * const result = await client.recoverSnapshot("MySnapshot"); * ``` * @param name - The name of the snapshot. * @param options - Optional parameters for the request. */ recoverSnapshot(name, // eslint-disable-next-line @azure/azure-sdk/ts-naming-options options = {}) { return tracing_js_1.tracingClient.withSpan("AppConfigurationClient.recoverSnapshot", options, async (updatedOptions) => { logger_js_1.logger.info("[recoverSnapshot] Recover a snapshot"); const originalResponse = await this.client.updateSnapshot(name, { status: "ready" }, { ...updatedOptions, ...(0, helpers_js_1.checkAndFormatIfAndIfNoneMatch)({ etag: options.etag }, { onlyIfUnchanged: true, ...options }), }); const response = (0, helpers_js_1.transformSnapshotResponse)(originalResponse); (0, helpers_js_1.assertResponse)(response); return response; }); } /** * Archive a ready snapshot * * Example usage: * ```ts snippet:ArchiveSnapshot * import { DefaultAzureCredential } from "@azure/identity"; * import { AppConfigurationClient } from "@azure/app-configuration"; * * // The endpoint for your App Configuration resource * const endpoint = "https://example.azconfig.io"; * const credential = new DefaultAzureCredential(); * const client = new AppConfigurationClient(endpoint, credential); * * const result = await client.archiveSnapshot({ name: "MySnapshot" }); * ``` * @param name - The name of the snapshot. * @param options - Optional parameters for the request. */ archiveSnapshot(name, // eslint-disable-next-line @azure/azure-sdk/ts-naming-options options = {}) { return tracing_js_1.tracingClient.withSpan("AppConfigurationClient.archiveSnapshot", options, async (updatedOptions) => { logger_js_1.logger.info("[archiveSnapshot] Archive a snapshot"); const originalResponse = await this.client.updateSnapshot(name, { status: "archived" }, { ...updatedOptions, ...(0, helpers_js_1.checkAndFormatIfAndIfNoneMatch)({ etag: options.etag }, { onlyIfUnchanged: true, ...options }), }); const response = (0, helpers_js_1.transformSnapshotResponse)(originalResponse); (0, helpers_js_1.assertResponse)(response); return response; }); } /** * List all snapshots from Azure App Configuration service * * Example usage: * ```ts snippet:ListSnapshots * import { DefaultAzureCredential } from "@azure/identity"; * import { AppConfigurationClient } from "@azure/app-configuration"; * * // The endpoint for your App Configuration resource * const endpoint = "https://example.azconfig.io"; * const credential = new DefaultAzureCredential(); * const client = new AppConfigurationClient(endpoint, credential); * * const snapshots = await client.listSnapshots(); * * for await (const snapshot of snapshots) { * console.log(`Found snapshot: ${snapshot.name}`); * } * ``` * @param options - Optional parameters for the request. */ listSnapshots(options = {}) { const pagedResult = { firstPageLink: undefined, getPage: async (pageLink) => { const response = await this.sendSnapShotsRequest(options, pageLink); const currentResponse = { ...response, items: response.items != null ? response.items : [], continuationToken: response.nextLink ? (0, helpers_js_1.extractAfterTokenFromNextLink)(response.nextLink) : undefined, }; return { page: currentResponse, nextPageLink: currentResponse.continuationToken, }; }, toElements: (page) => page.items, }; return (0, core_paging_1.getPagedAsyncIterator)(pagedResult); } async sendSnapShotsRequest(options = {}, pageLink) { return tracing_js_1.tracingClient.withSpan("AppConfigurationClient.listSnapshots", options, async (updatedOptions) => { const response = await this.client.getSnapshots({ ...updatedOptions, ...(0, helpers_js_1.formatSnapshotFiltersAndSelect)(options), after: pageLink, }); return response; }); } } exports.AppConfigurationClient = AppConfigurationClient; //# sourceMappingURL=appConfigurationClient.js.map