Skip to content
This repository was archived by the owner on Jul 2, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/clients.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { Client as BaseUserApi } from "./userapi.ts";

interface AdminApiOptions {
adminKey: string;
apiVersion?: string;
baseUrl?: string;
}

Expand Down Expand Up @@ -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 }));
Expand All @@ -48,6 +53,7 @@ export class AdminApi extends BaseAdminApi {
interface UserApiOptions {
userKey: string;
accessToken?: string;
apiVersion?: string;
baseUrl?: string;
}

Expand Down Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions src/internal/constants.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down
12 changes: 12 additions & 0 deletions test/node/basics.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down