Skip to content

Commit 653ba7a

Browse files
committed
js: Temporarily add back Svix._configuration
1 parent 1443140 commit 653ba7a

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

javascript/src/index.ts

+26-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ import { Message } from "./api/message";
88
import { MessageAttempt } from "./api/message_attempt";
99
import { OperationalWebhookEndpoint } from "./api/operational_webhook_endpoint";
1010
import { Statistics } from "./api/statistics";
11-
import { SvixRequestContext } from "./request";
11+
import { LIB_VERSION, SvixRequestContext } from "./request";
12+
import * as openapi from "./openapi";
1213

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

43+
class UserAgentMiddleware implements openapi.Middleware {
44+
public pre(context: openapi.RequestContext): Promise<openapi.RequestContext> {
45+
context.setHeaderParam("User-Agent", `svix-libs/${LIB_VERSION}/javascript`);
46+
return Promise.resolve(context);
47+
}
48+
49+
public post(context: openapi.ResponseContext): Promise<openapi.ResponseContext> {
50+
return Promise.resolve(context);
51+
}
52+
}
53+
4254
export class Svix {
4355
private readonly requestCtx: SvixRequestContext;
56+
public readonly _configuration: openapi.Configuration;
4457

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

4962
this.requestCtx = { baseUrl, token };
63+
64+
this._configuration = openapi.createConfiguration({
65+
baseServer: new openapi.ServerConfiguration<any>(baseUrl, {}),
66+
promiseMiddleware: [new UserAgentMiddleware()],
67+
authMethods: {
68+
HTTPBearer: {
69+
tokenProvider: {
70+
getToken: () => token,
71+
},
72+
},
73+
},
74+
});
5075
}
5176

5277
public get authentication() {

javascript/src/request.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { ApiException } from "./util";
33
import { HttpErrorOut, HTTPValidationError } from "./openapi";
44
import { ObjectSerializer } from "./openapi/models/ObjectSerializer";
55

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

99
export enum HttpMethod {

0 commit comments

Comments
 (0)