Skip to content

Commit

Permalink
js: Temporarily add back Svix._configuration (#1681)
Browse files Browse the repository at this point in the history
  • Loading branch information
svix-jplatte authored Jan 31, 2025
2 parents 1443140 + 653ba7a commit 5b40e53
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
27 changes: 26 additions & 1 deletion javascript/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import { Message } from "./api/message";
import { MessageAttempt } from "./api/message_attempt";
import { OperationalWebhookEndpoint } from "./api/operational_webhook_endpoint";
import { Statistics } from "./api/statistics";
import { SvixRequestContext } from "./request";
import { LIB_VERSION, SvixRequestContext } from "./request";
import * as openapi from "./openapi";

export * from "./openapi/models/all";
export * from "./openapi/apis/exception";
Expand Down Expand Up @@ -39,14 +40,38 @@ const REGIONS = [
{ region: "in", url: "https://api.in.svix.com" },
];

class UserAgentMiddleware implements openapi.Middleware {
public pre(context: openapi.RequestContext): Promise<openapi.RequestContext> {
context.setHeaderParam("User-Agent", `svix-libs/${LIB_VERSION}/javascript`);
return Promise.resolve(context);
}

public post(context: openapi.ResponseContext): Promise<openapi.ResponseContext> {
return Promise.resolve(context);
}
}

export class Svix {
private readonly requestCtx: SvixRequestContext;
public readonly _configuration: openapi.Configuration;

public constructor(token: string, options: SvixOptions = {}) {
const regionalUrl = REGIONS.find((x) => x.region === token.split(".")[1])?.url;
const baseUrl: string = options.serverUrl ?? regionalUrl ?? "https://api.svix.com";

this.requestCtx = { baseUrl, token };

this._configuration = openapi.createConfiguration({
baseServer: new openapi.ServerConfiguration<any>(baseUrl, {}),
promiseMiddleware: [new UserAgentMiddleware()],
authMethods: {
HTTPBearer: {
tokenProvider: {
getToken: () => token,
},
},
},
});
}

public get authentication() {
Expand Down
2 changes: 1 addition & 1 deletion javascript/src/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { ApiException } from "./util";
import { HttpErrorOut, HTTPValidationError } from "./openapi";
import { ObjectSerializer } from "./openapi/models/ObjectSerializer";

const LIB_VERSION = "1.56.0";
export const LIB_VERSION = "1.56.0";
const USER_AGENT = `svix-libs/${LIB_VERSION}/javascript`;

export enum HttpMethod {
Expand Down

0 comments on commit 5b40e53

Please sign in to comment.