Skip to content

Commit a44e916

Browse files
committed
minimum api version check
1 parent 558306a commit a44e916

3 files changed

Lines changed: 38 additions & 3 deletions

File tree

src/appConfigurationClient.ts

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,7 @@ export function getFeatureFlagClientOptions(options?: ConfigurationClientOptions
8181
if (options === undefined) {
8282
return undefined;
8383
}
84-
if (options.apiVersion !== undefined &&
85-
options.apiVersion !== KnownAppConfigurationApiVersion.V20260501Preview) {
84+
if (options.apiVersion !== undefined && !isSupportedApiVersion(options.apiVersion)) {
8685
throw new ArgumentError(ErrorMessages.API_VERSION_NOT_SUPPORTED);
8786
}
8887

@@ -96,3 +95,23 @@ export function getFeatureFlagClientOptions(options?: ConfigurationClientOptions
9695
...(options.additionalPolicies && { additionalPolicies: [...options.additionalPolicies] })
9796
};
9897
}
98+
99+
function isSupportedApiVersion(apiVersion: string): boolean {
100+
const apiVersionDate = parseApiVersionDate(apiVersion);
101+
const minimumApiVersionDate = parseApiVersionDate(KnownAppConfigurationApiVersion.V20260501Preview)!;
102+
return apiVersionDate !== undefined && apiVersionDate >= minimumApiVersionDate;
103+
}
104+
105+
function parseApiVersionDate(apiVersion: string): number | undefined {
106+
const match = /^(\d{4}-\d{2}-\d{2})(?:-[0-9A-Za-z.-]+)?$/.exec(apiVersion);
107+
if (match === null) {
108+
return undefined;
109+
}
110+
111+
const date = new Date(`${match[1]}T00:00:00Z`);
112+
if (Number.isNaN(date.getTime()) || date.toISOString().slice(0, 10) !== match[1]) {
113+
return undefined;
114+
}
115+
116+
return date.getTime();
117+
}

src/common/errorMessages.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export const enum ErrorMessages {
2020
INVALID_KEY_FILTER = "Key filter cannot be null or empty.",
2121
INVALID_LABEL_FILTER = "The characters '*' and ',' are not supported in label filters.",
2222
INVALID_TAG_FILTER = "Tag filter must follow the format 'tagName=tagValue'",
23-
API_VERSION_NOT_SUPPORTED = "The App Configuration provider requires API version '2026-05-01-preview'.",
23+
API_VERSION_NOT_SUPPORTED = "The App Configuration provider requires API version '2026-05-01-preview' or later.",
2424
CONNECTION_STRING_OR_ENDPOINT_MISSED = "A connection string or an endpoint with credential must be specified to create a client.",
2525
REPLICA_DISCOVERY_NOT_SUPPORTED = "Replica discovery is not supported when loading from Azure Front Door. For guidance on how to take advantage of geo-replication when Azure Front Door is used, visit https://aka.ms/appconfig/geo-replication-with-afd",
2626
LOAD_BALANCING_NOT_SUPPORTED = "Load balancing is not supported when loading from Azure Front Door. For guidance on how to take advantage of geo-replication when Azure Front Door is used, visit https://aka.ms/appconfig/geo-replication-with-afd",

test/clientOptions.test.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,22 @@ describe("custom client options", function () {
5353
expect(createClientManager).throws(ErrorMessages.API_VERSION_NOT_SUPPORTED);
5454
});
5555

56+
it("should reject a malformed API version", () => {
57+
const createFeatureFlagClientOptions = () => getFeatureFlagClientOptions({
58+
apiVersion: "2026-13-01-preview"
59+
});
60+
61+
expect(createFeatureFlagClientOptions).throws(ErrorMessages.API_VERSION_NOT_SUPPORTED);
62+
});
63+
64+
it("should allow the stable API version with the minimum date", () => {
65+
expect(() => getFeatureFlagClientOptions({ apiVersion: "2026-05-01" })).not.throws();
66+
});
67+
68+
it("should allow an API version later than the minimum", () => {
69+
expect(() => getFeatureFlagClientOptions({ apiVersion: "2026-06-01-preview" })).not.throws();
70+
});
71+
5672
it("should use equivalent options for configuration and feature flag clients", () => {
5773
const countPolicy = new HttpRequestCountPolicy();
5874
const configurationClientOptions = getClientOptions({

0 commit comments

Comments
 (0)