@@ -8,7 +8,8 @@ import { Message } from "./api/message";
8
8
import { MessageAttempt } from "./api/message_attempt" ;
9
9
import { OperationalWebhookEndpoint } from "./api/operational_webhook_endpoint" ;
10
10
import { Statistics } from "./api/statistics" ;
11
- import { SvixRequestContext } from "./request" ;
11
+ import { LIB_VERSION , SvixRequestContext } from "./request" ;
12
+ import * as openapi from "./openapi" ;
12
13
13
14
export * from "./openapi/models/all" ;
14
15
export * from "./openapi/apis/exception" ;
@@ -39,14 +40,38 @@ const REGIONS = [
39
40
{ region : "in" , url : "https://api.in.svix.com" } ,
40
41
] ;
41
42
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
+
42
54
export class Svix {
43
55
private readonly requestCtx : SvixRequestContext ;
56
+ public readonly _configuration : openapi . Configuration ;
44
57
45
58
public constructor ( token : string , options : SvixOptions = { } ) {
46
59
const regionalUrl = REGIONS . find ( ( x ) => x . region === token . split ( "." ) [ 1 ] ) ?. url ;
47
60
const baseUrl : string = options . serverUrl ?? regionalUrl ?? "https://api.svix.com" ;
48
61
49
62
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
+ } ) ;
50
75
}
51
76
52
77
public get authentication ( ) {
0 commit comments