diff --git a/src/clients.ts b/src/clients.ts index 0154ceb..cfd81cb 100644 --- a/src/clients.ts +++ b/src/clients.ts @@ -6,6 +6,7 @@ import { Client as BaseUserApi } from "./userapi.ts"; interface AdminApiOptions { adminKey: string; + apiVersion?: string; baseUrl?: string; } @@ -39,6 +40,10 @@ export class AdminApi extends BaseAdminApi { } const headers: Headers = new Headers(); + headers.set( + constants.API_VERSION_HEADER, + options.apiVersion || constants.API_VERSION, + ); headers.set(constants.AUTH_HEADER, "Bearer " + adminKey); super(new HttpTransport({ headers, baseUrl: options.baseUrl })); @@ -48,6 +53,7 @@ export class AdminApi extends BaseAdminApi { interface UserApiOptions { userKey: string; accessToken?: string; + apiVersion?: string; baseUrl?: string; } @@ -103,6 +109,10 @@ export class UserApi extends BaseUserApi { } const headers: Headers = new Headers(); + headers.set( + constants.API_VERSION_HEADER, + options.apiVersion || constants.API_VERSION, + ); headers.set(constants.API_KEY_HEADER, userKey); if (accessToken) { headers.set(constants.AUTH_HEADER, "Bearer " + accessToken); diff --git a/src/internal/constants.ts b/src/internal/constants.ts index 1f30cb0..b63d8ba 100644 --- a/src/internal/constants.ts +++ b/src/internal/constants.ts @@ -1,11 +1,13 @@ // Code generated. DO NOT EDIT. export const API_BASE_URL = "https://api.userhub.com"; +export const API_VERSION = "2022-11-15"; export const USER_AGENT = "UserHub-JavaScript/0.7.0"; export const VERSION = "0.7.0"; export const AUTH_HEADER = "Authorization"; export const API_KEY_HEADER = "UserHub-Api-Key"; +export const API_VERSION_HEADER = "UserHub-Api-Version"; export const WEBHOOK_ACTION_HEADER = "UserHub-Action"; export const WEBHOOK_AGENT_HEADER = "Webhook-Agent"; diff --git a/test/node/basics.test.ts b/test/node/basics.test.ts index 9f5ae2c..2c01433 100644 --- a/test/node/basics.test.ts +++ b/test/node/basics.test.ts @@ -75,6 +75,9 @@ test("API GET", async () => { expect(requests[0].method).equal("GET"); expect(requests[0].url).equal("/admin/v1/users/usr_1"); expect(requests[0].headers["accept"]).equal("application/json"); + expect(requests[0].headers["userhub-api-version"]).equal( + constants.API_VERSION, + ); expect(requests[0].headers["authorization"]).equal("Bearer sk_test"); expect(requests[0].headers["content-type"]).toBeUndefined(); expect(requests[0].headers["user-agent"]).equal(constants.USER_AGENT); @@ -101,6 +104,9 @@ test("API POST", async () => { expect(requests[0].method).equal("POST"); expect(requests[0].url).equal("/admin/v1/users"); expect(requests[0].headers["accept"]).equal("application/json"); + expect(requests[0].headers["userhub-api-version"]).equal( + constants.API_VERSION, + ); expect(requests[0].headers["authorization"]).equal("Bearer sk_test"); expect(requests[0].headers["content-type"]).equal("application/json"); expect(requests[0].headers["user-agent"]).equal(constants.USER_AGENT); @@ -128,6 +134,9 @@ test("API PATCH", async () => { expect(requests[0].method).equal("PATCH"); expect(requests[0].url).equal("/admin/v1/users/usr_1?allowMissing=true"); expect(requests[0].headers["accept"]).equal("application/json"); + expect(requests[0].headers["userhub-api-version"]).equal( + constants.API_VERSION, + ); expect(requests[0].headers["authorization"]).equal("Bearer sk_test"); expect(requests[0].headers["content-type"]).equal("application/json"); expect(requests[0].headers["user-agent"]).equal(constants.USER_AGENT); @@ -158,6 +167,9 @@ test("API DELETE", async () => { expect(requests[0].method).equal("DELETE"); expect(requests[0].url).equal("/admin/v1/users/usr_1"); expect(requests[0].headers["accept"]).equal("application/json"); + expect(requests[0].headers["userhub-api-version"]).equal( + constants.API_VERSION, + ); expect(requests[0].headers["authorization"]).equal("Bearer sk_test"); expect(requests[0].headers["content-type"]).toBeUndefined(); expect(requests[0].headers["user-agent"]).equal(constants.USER_AGENT);