@corti/sdk 0.0.0-rc.2 → 0.0.0-rc.359

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -38,29 +38,23 @@ const client = new CortiClient({
38
38
 
39
39
  // Or using a bearer token
40
40
  const client = new CortiClient({
41
- environment: CortiEnvironment.Eu,
42
- tenantName: "YOUR_TENANT_NAME",
43
41
  auth: {
44
- accessToken: "YOUR_ACCESS_TOKEN",
45
- // Optional: refresh token for automatic token refresh
46
- refreshToken: "YOUR_REFRESH_TOKEN",
47
- expiresIn: 3600,
48
- refreshExpiresIn: 86400,
42
+ accessToken: "YOUR_ACCESS_TOKEN"
49
43
  },
50
44
  });
51
45
 
52
46
  // Or using just a refresh function (no initial access token needed)
53
47
  const client = new CortiClient({
54
- environment: CortiEnvironment.Eu,
55
- tenantName: "YOUR_TENANT_NAME",
56
48
  auth: {
49
+ // refreshToken will be undefined for the first call, then it will be the refreshToken returned from the previous token request
57
50
  refreshAccessToken: async (refreshToken?: string) => {
58
51
  // Your custom logic to get a new access token
59
- const response = await fetch("https://your-auth-server/refresh", {
52
+ const response = await fetch("https://your-auth-server/token", {
60
53
  method: "POST",
61
54
  headers: { "Content-Type": "application/json" },
62
- body: JSON.stringify({ refreshToken: refreshToken }),
55
+ body: JSON.stringify({ refreshToken }),
63
56
  });
57
+
64
58
  return response.json();
65
59
  },
66
60
  },
@@ -64,8 +64,8 @@ class CortiClient {
64
64
  "Tenant-Name": _options === null || _options === void 0 ? void 0 : _options.tenantName,
65
65
  "X-Fern-Language": "JavaScript",
66
66
  "X-Fern-SDK-Name": "@corti/sdk",
67
- "X-Fern-SDK-Version": "0.0.0-rc.2",
68
- "User-Agent": "@corti/sdk/0.0.0-rc.2",
67
+ "X-Fern-SDK-Version": "0.0.0-rc.359",
68
+ "User-Agent": "@corti/sdk/0.0.0-rc.359",
69
69
  "X-Fern-Runtime": core.RUNTIME.type,
70
70
  "X-Fern-Runtime-Version": core.RUNTIME.version,
71
71
  }, _options === null || _options === void 0 ? void 0 : _options.headers) });
@@ -27,14 +27,11 @@ import { Agents } from "../api/resources/agents/client/Client.js";
27
27
  */
28
28
  import { Stream } from "./CustomStream.js";
29
29
  import { Transcribe } from "./CustomTranscribe.js";
30
- /**
31
- * Patch: added custom RefreshBearerProvider
32
- */
33
- import { BearerOptions } from "./RefreshBearerProvider.js";
34
30
  import { Environment, CortiInternalEnvironment } from "./utils/getEnvironmentFromString.js";
31
+ import { BearerOptions } from "./RefreshBearerProvider.js";
35
32
  export declare namespace CortiClient {
36
33
  /**
37
- * Patch: added new public interface for `Options` (+ `ClientCredentials` interface)
34
+ * Patch: added new public type for `Options` + internal interfaces to create it
38
35
  */
39
36
  interface ClientCredentials {
40
37
  clientId: core.Supplier<string>;
@@ -44,10 +41,6 @@ export declare namespace CortiClient {
44
41
  /** Additional headers to include in requests. */
45
42
  headers?: Record<string, string | core.Supplier<string | undefined> | undefined>;
46
43
  }
47
- /**
48
- * Options when using Client Credentials authentication
49
- * tenantName and environment are required
50
- */
51
44
  interface OptionsWithClientCredentials extends BaseOptions {
52
45
  /**
53
46
  * Patch: allow to pass a custom string-based environment
@@ -57,12 +50,12 @@ export declare namespace CortiClient {
57
50
  tenantName: core.Supplier<string>;
58
51
  auth: ClientCredentials;
59
52
  }
60
- /**
61
- * Options when using Bearer token authentication
62
- * tenantName and environment are optional (extracted from token if not provided)
63
- */
64
53
  interface OptionsWithBearerToken extends BaseOptions {
54
+ /**
55
+ * Patch: allow to pass a custom string-based environment
56
+ * */
65
57
  environment?: Environment;
58
+ /** Override the Tenant-Name header */
66
59
  tenantName?: core.Supplier<string>;
67
60
  auth: BearerOptions;
68
61
  }
@@ -72,6 +65,7 @@ export declare namespace CortiClient {
72
65
  * - renamed `Options` to `InternalOptions`
73
66
  * - added `token` field to support BearerProvider
74
67
  * - made clientId and clientSecret optional
68
+ * - updated environment type to CortiInternalEnvironment
75
69
  */
76
70
  interface InternalOptions {
77
71
  environment: CortiInternalEnvironment;
@@ -78,21 +78,21 @@ const Client_js_7 = require("../api/resources/agents/client/Client.js");
78
78
  const CustomStream_js_1 = require("./CustomStream.js");
79
79
  const CustomTranscribe_js_1 = require("./CustomTranscribe.js");
80
80
  /**
81
- * Patch: added custom RefreshBearerProvider
82
- */
83
- const RefreshBearerProvider_js_1 = require("./RefreshBearerProvider.js");
84
- /**
85
- * Patch: added SDK_VERSION import
81
+ * Patch: added SDK_VERSION import and custom code imports
86
82
  */
87
83
  const version_js_1 = require("../version.js");
88
84
  const getEnvironmentFromString_js_1 = require("./utils/getEnvironmentFromString.js");
89
85
  const resolveClientOptions_js_1 = require("./utils/resolveClientOptions.js");
86
+ const RefreshBearerProvider_js_1 = require("./RefreshBearerProvider.js");
90
87
  class CortiClient {
91
88
  constructor(_options) {
92
89
  /**
93
90
  * Patch: resolve tenantName and environment from options or token
94
91
  */
95
92
  const { tenantName, environment, initialTokenResponse } = (0, resolveClientOptions_js_1.resolveClientOptions)(_options);
93
+ /**
94
+ * Patch: redefining options based on new schema
95
+ */
96
96
  this._options = Object.assign(Object.assign({}, _options), { headers: (0, headers_js_1.mergeHeaders)({
97
97
  "Tenant-Name": tenantName,
98
98
  "X-Fern-Language": "JavaScript",
@@ -108,17 +108,16 @@ class CortiClient {
108
108
  /**
109
109
  * Patch: if `clientId` is provided, use OAuthTokenProvider, otherwise use BearerProvider
110
110
  */
111
- this._oauthTokenProvider =
112
- "clientId" in _options.auth
113
- ? new core.OAuthTokenProvider({
114
- clientId: _options.auth.clientId,
115
- clientSecret: _options.auth.clientSecret,
116
- /**
117
- * Patch: provide whole `options` object to the Auth client, since it depends on both tenantName and environment
118
- */
119
- authClient: new CortiAuth_js_1.Auth(this._options),
120
- })
121
- : new RefreshBearerProvider_js_1.RefreshBearerProvider(Object.assign(Object.assign({}, _options.auth), { initialTokenResponse }));
111
+ this._oauthTokenProvider = "clientId" in _options.auth ?
112
+ new core.OAuthTokenProvider({
113
+ clientId: _options.auth.clientId,
114
+ clientSecret: _options.auth.clientSecret,
115
+ /**
116
+ * Patch: provide whole `options` object to the Auth client, since it depends on both tenantName and environment
117
+ */
118
+ authClient: new CortiAuth_js_1.Auth(this._options),
119
+ }) :
120
+ new RefreshBearerProvider_js_1.RefreshBearerProvider(Object.assign(Object.assign({}, _options.auth), { initialTokenResponse }));
122
121
  }
123
122
  get interactions() {
124
123
  var _a;
@@ -2,7 +2,7 @@
2
2
  * RefreshBearerProvider used as a replacement of OAuthTokenProvider, in case when accessToken from outside of library was used instead of Client credentials.
3
3
  */
4
4
  import * as api from "../api/index.js";
5
- export type ExpectedTokenResponse = Omit<api.GetTokenResponse, 'tokenType' | 'expiresIn'> & {
5
+ export type ExpectedTokenResponse = Omit<api.GetTokenResponse, "tokenType" | "expiresIn"> & {
6
6
  tokenType?: string;
7
7
  expiresIn?: number;
8
8
  };
@@ -13,9 +13,7 @@ export type BearerOptions = Partial<Omit<api.GetTokenResponse, 'accessToken'>> &
13
13
  } | {
14
14
  refreshAccessToken: RefreshAccessTokenFunction;
15
15
  accessToken?: string;
16
- }) & {
17
- initialTokenResponse?: Promise<ExpectedTokenResponse>;
18
- };
16
+ });
19
17
  export declare class RefreshBearerProvider {
20
18
  private readonly BUFFER_IN_MINUTES;
21
19
  private _accessToken;
@@ -24,7 +22,9 @@ export declare class RefreshBearerProvider {
24
22
  private _expiresAt;
25
23
  private _refreshExpiresAt;
26
24
  private _initialTokenResponse;
27
- constructor({ accessToken, refreshAccessToken, refreshToken, refreshExpiresIn, expiresIn, initialTokenResponse, }: BearerOptions);
25
+ constructor({ accessToken, refreshAccessToken, refreshToken, refreshExpiresIn, expiresIn, initialTokenResponse, }: BearerOptions & {
26
+ initialTokenResponse?: Promise<ExpectedTokenResponse>;
27
+ });
28
28
  getToken(): Promise<string>;
29
29
  private refresh;
30
30
  private getExpiresAt;
@@ -51,7 +51,7 @@ const decodeToken_js_1 = require("./utils/decodeToken.js");
51
51
  class RefreshBearerProvider {
52
52
  constructor({ accessToken, refreshAccessToken, refreshToken, refreshExpiresIn, expiresIn, initialTokenResponse, }) {
53
53
  this.BUFFER_IN_MINUTES = 2;
54
- this._accessToken = accessToken || 'no_token';
54
+ this._accessToken = accessToken || "no_token";
55
55
  this._refreshToken = refreshToken;
56
56
  this._initialTokenResponse = initialTokenResponse;
57
57
  this._expiresAt = this.getExpiresAt(expiresIn, this._accessToken, this.BUFFER_IN_MINUTES);
@@ -60,7 +60,7 @@ class RefreshBearerProvider {
60
60
  }
61
61
  getToken() {
62
62
  return __awaiter(this, void 0, void 0, function* () {
63
- if (this._accessToken && this._accessToken !== 'no_token' && this._expiresAt > new Date()) {
63
+ if (this._accessToken && this._accessToken !== "no_token" && this._expiresAt > new Date()) {
64
64
  return core.Supplier.get(this._accessToken);
65
65
  }
66
66
  if (this._initialTokenResponse) {
@@ -77,7 +77,7 @@ class RefreshBearerProvider {
77
77
  }
78
78
  refresh() {
79
79
  return __awaiter(this, void 0, void 0, function* () {
80
- if (!this._refreshAccessToken || this._refreshToken && this._refreshExpiresAt < new Date()) {
80
+ if (!this._refreshAccessToken || (this._refreshToken && this._refreshExpiresAt < new Date())) {
81
81
  return core.Supplier.get(this._accessToken);
82
82
  }
83
83
  const tokenResponse = yield this._refreshAccessToken(this._refreshToken);
@@ -96,12 +96,12 @@ class RefreshBearerProvider {
96
96
  return this.parseTokenExpiry(token, bufferInMinutes) || this.getExpiresAt(0, token, bufferInMinutes);
97
97
  }
98
98
  parseTokenExpiry(token, bufferInMinutes) {
99
- if (!token || token === 'no_token') {
99
+ if (!token || token === "no_token") {
100
100
  return;
101
101
  }
102
102
  try {
103
103
  const decoded = (0, decodeToken_js_1.decodeToken)(token);
104
- if (decoded && typeof decoded.expiresAt === 'number') {
104
+ if (decoded && typeof decoded.expiresAt === "number") {
105
105
  const ms = decoded.expiresAt * 1000 - bufferInMinutes * 60 * 1000;
106
106
  return new Date(ms);
107
107
  }
@@ -24,4 +24,4 @@ export declare function decodeToken(token: string): {
24
24
  tenantName: string;
25
25
  accessToken: string;
26
26
  expiresAt: number | undefined;
27
- } | undefined;
27
+ } | null;
@@ -24,9 +24,9 @@ exports.decodeToken = decodeToken;
24
24
  */
25
25
  function decodeToken(token) {
26
26
  // Validate the token structure (should contain at least header and payload parts)
27
- const parts = token.split('.');
27
+ const parts = token ? token.split('.') : '';
28
28
  if (parts.length < 2) {
29
- throw new Error('Invalid token format');
29
+ return null;
30
30
  }
31
31
  // Retrieve the payload (second part) of the JWT token
32
32
  const base64Url = parts[1];
@@ -41,7 +41,7 @@ function decodeToken(token) {
41
41
  .join(''));
42
42
  }
43
43
  catch (error) {
44
- throw new Error('Failed to decode token payload');
44
+ return null;
45
45
  }
46
46
  // Parse the JSON string to obtain token details
47
47
  let tokenDetails;
@@ -49,12 +49,12 @@ function decodeToken(token) {
49
49
  tokenDetails = JSON.parse(jsonPayload);
50
50
  }
51
51
  catch (error) {
52
- throw new Error('Invalid JSON payload in token');
52
+ return null;
53
53
  }
54
54
  // Extract the issuer URL from the token details
55
55
  const issuerUrl = tokenDetails.iss;
56
56
  if (!issuerUrl) {
57
- throw new Error('Token payload does not contain an issuer (iss) field');
57
+ return null;
58
58
  }
59
59
  // Regex to extract environment and tenant from issuer URL:
60
60
  // Expected format: https://keycloak.{environment}.corti.app/realms/{tenant}
@@ -73,4 +73,5 @@ function decodeToken(token) {
73
73
  expiresAt,
74
74
  };
75
75
  }
76
+ return null;
76
77
  }
@@ -101,17 +101,9 @@ function resolveClientOptions(options) {
101
101
  }))();
102
102
  return {
103
103
  tenantName: options.tenantName ||
104
- function () {
105
- return __awaiter(this, void 0, void 0, function* () {
106
- return (yield tokenResponsePromise).tenantName;
107
- });
108
- },
109
- environment: options.environment || function () {
110
- return __awaiter(this, void 0, void 0, function* () {
111
- const environment = (0, getEnvironmentFromString_js_1.getEnvironment)((yield tokenResponsePromise).environment);
112
- return core.Supplier.get(environment);
113
- });
114
- },
115
- initialTokenResponse: tokenResponsePromise.then(result => result.tokenResponse),
104
+ tokenResponsePromise.then(({ tenantName }) => tenantName),
105
+ environment: options.environment ||
106
+ tokenResponsePromise.then(({ environment }) => core.Supplier.get((0, getEnvironmentFromString_js_1.getEnvironment)(environment))),
107
+ initialTokenResponse: tokenResponsePromise.then((result) => result.tokenResponse),
116
108
  };
117
109
  }
@@ -1 +1 @@
1
- export declare const SDK_VERSION = "0.0.0-rc.2";
1
+ export declare const SDK_VERSION = "0.0.0-rc.359";
@@ -1,4 +1,4 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.SDK_VERSION = void 0;
4
- exports.SDK_VERSION = "0.0.0-rc.2";
4
+ exports.SDK_VERSION = "0.0.0-rc.359";
@@ -28,8 +28,8 @@ export class CortiClient {
28
28
  "Tenant-Name": _options === null || _options === void 0 ? void 0 : _options.tenantName,
29
29
  "X-Fern-Language": "JavaScript",
30
30
  "X-Fern-SDK-Name": "@corti/sdk",
31
- "X-Fern-SDK-Version": "0.0.0-rc.2",
32
- "User-Agent": "@corti/sdk/0.0.0-rc.2",
31
+ "X-Fern-SDK-Version": "0.0.0-rc.359",
32
+ "User-Agent": "@corti/sdk/0.0.0-rc.359",
33
33
  "X-Fern-Runtime": core.RUNTIME.type,
34
34
  "X-Fern-Runtime-Version": core.RUNTIME.version,
35
35
  }, _options === null || _options === void 0 ? void 0 : _options.headers) });
@@ -27,14 +27,11 @@ import { Agents } from "../api/resources/agents/client/Client.mjs";
27
27
  */
28
28
  import { Stream } from "./CustomStream.mjs";
29
29
  import { Transcribe } from "./CustomTranscribe.mjs";
30
- /**
31
- * Patch: added custom RefreshBearerProvider
32
- */
33
- import { BearerOptions } from "./RefreshBearerProvider.mjs";
34
30
  import { Environment, CortiInternalEnvironment } from "./utils/getEnvironmentFromString.mjs";
31
+ import { BearerOptions } from "./RefreshBearerProvider.mjs";
35
32
  export declare namespace CortiClient {
36
33
  /**
37
- * Patch: added new public interface for `Options` (+ `ClientCredentials` interface)
34
+ * Patch: added new public type for `Options` + internal interfaces to create it
38
35
  */
39
36
  interface ClientCredentials {
40
37
  clientId: core.Supplier<string>;
@@ -44,10 +41,6 @@ export declare namespace CortiClient {
44
41
  /** Additional headers to include in requests. */
45
42
  headers?: Record<string, string | core.Supplier<string | undefined> | undefined>;
46
43
  }
47
- /**
48
- * Options when using Client Credentials authentication
49
- * tenantName and environment are required
50
- */
51
44
  interface OptionsWithClientCredentials extends BaseOptions {
52
45
  /**
53
46
  * Patch: allow to pass a custom string-based environment
@@ -57,12 +50,12 @@ export declare namespace CortiClient {
57
50
  tenantName: core.Supplier<string>;
58
51
  auth: ClientCredentials;
59
52
  }
60
- /**
61
- * Options when using Bearer token authentication
62
- * tenantName and environment are optional (extracted from token if not provided)
63
- */
64
53
  interface OptionsWithBearerToken extends BaseOptions {
54
+ /**
55
+ * Patch: allow to pass a custom string-based environment
56
+ * */
65
57
  environment?: Environment;
58
+ /** Override the Tenant-Name header */
66
59
  tenantName?: core.Supplier<string>;
67
60
  auth: BearerOptions;
68
61
  }
@@ -72,6 +65,7 @@ export declare namespace CortiClient {
72
65
  * - renamed `Options` to `InternalOptions`
73
66
  * - added `token` field to support BearerProvider
74
67
  * - made clientId and clientSecret optional
68
+ * - updated environment type to CortiInternalEnvironment
75
69
  */
76
70
  interface InternalOptions {
77
71
  environment: CortiInternalEnvironment;
@@ -42,21 +42,21 @@ import { Agents } from "../api/resources/agents/client/Client.mjs";
42
42
  import { Stream } from "./CustomStream.mjs";
43
43
  import { Transcribe } from "./CustomTranscribe.mjs";
44
44
  /**
45
- * Patch: added custom RefreshBearerProvider
46
- */
47
- import { RefreshBearerProvider } from "./RefreshBearerProvider.mjs";
48
- /**
49
- * Patch: added SDK_VERSION import
45
+ * Patch: added SDK_VERSION import and custom code imports
50
46
  */
51
47
  import { SDK_VERSION } from "../version.mjs";
52
48
  import { getEnvironment } from "./utils/getEnvironmentFromString.mjs";
53
49
  import { resolveClientOptions } from "./utils/resolveClientOptions.mjs";
50
+ import { RefreshBearerProvider } from "./RefreshBearerProvider.mjs";
54
51
  export class CortiClient {
55
52
  constructor(_options) {
56
53
  /**
57
54
  * Patch: resolve tenantName and environment from options or token
58
55
  */
59
56
  const { tenantName, environment, initialTokenResponse } = resolveClientOptions(_options);
57
+ /**
58
+ * Patch: redefining options based on new schema
59
+ */
60
60
  this._options = Object.assign(Object.assign({}, _options), { headers: mergeHeaders({
61
61
  "Tenant-Name": tenantName,
62
62
  "X-Fern-Language": "JavaScript",
@@ -72,17 +72,16 @@ export class CortiClient {
72
72
  /**
73
73
  * Patch: if `clientId` is provided, use OAuthTokenProvider, otherwise use BearerProvider
74
74
  */
75
- this._oauthTokenProvider =
76
- "clientId" in _options.auth
77
- ? new core.OAuthTokenProvider({
78
- clientId: _options.auth.clientId,
79
- clientSecret: _options.auth.clientSecret,
80
- /**
81
- * Patch: provide whole `options` object to the Auth client, since it depends on both tenantName and environment
82
- */
83
- authClient: new Auth(this._options),
84
- })
85
- : new RefreshBearerProvider(Object.assign(Object.assign({}, _options.auth), { initialTokenResponse }));
75
+ this._oauthTokenProvider = "clientId" in _options.auth ?
76
+ new core.OAuthTokenProvider({
77
+ clientId: _options.auth.clientId,
78
+ clientSecret: _options.auth.clientSecret,
79
+ /**
80
+ * Patch: provide whole `options` object to the Auth client, since it depends on both tenantName and environment
81
+ */
82
+ authClient: new Auth(this._options),
83
+ }) :
84
+ new RefreshBearerProvider(Object.assign(Object.assign({}, _options.auth), { initialTokenResponse }));
86
85
  }
87
86
  get interactions() {
88
87
  var _a;
@@ -2,7 +2,7 @@
2
2
  * RefreshBearerProvider used as a replacement of OAuthTokenProvider, in case when accessToken from outside of library was used instead of Client credentials.
3
3
  */
4
4
  import * as api from "../api/index.mjs";
5
- export type ExpectedTokenResponse = Omit<api.GetTokenResponse, 'tokenType' | 'expiresIn'> & {
5
+ export type ExpectedTokenResponse = Omit<api.GetTokenResponse, "tokenType" | "expiresIn"> & {
6
6
  tokenType?: string;
7
7
  expiresIn?: number;
8
8
  };
@@ -13,9 +13,7 @@ export type BearerOptions = Partial<Omit<api.GetTokenResponse, 'accessToken'>> &
13
13
  } | {
14
14
  refreshAccessToken: RefreshAccessTokenFunction;
15
15
  accessToken?: string;
16
- }) & {
17
- initialTokenResponse?: Promise<ExpectedTokenResponse>;
18
- };
16
+ });
19
17
  export declare class RefreshBearerProvider {
20
18
  private readonly BUFFER_IN_MINUTES;
21
19
  private _accessToken;
@@ -24,7 +22,9 @@ export declare class RefreshBearerProvider {
24
22
  private _expiresAt;
25
23
  private _refreshExpiresAt;
26
24
  private _initialTokenResponse;
27
- constructor({ accessToken, refreshAccessToken, refreshToken, refreshExpiresIn, expiresIn, initialTokenResponse, }: BearerOptions);
25
+ constructor({ accessToken, refreshAccessToken, refreshToken, refreshExpiresIn, expiresIn, initialTokenResponse, }: BearerOptions & {
26
+ initialTokenResponse?: Promise<ExpectedTokenResponse>;
27
+ });
28
28
  getToken(): Promise<string>;
29
29
  private refresh;
30
30
  private getExpiresAt;
@@ -15,7 +15,7 @@ import { decodeToken } from "./utils/decodeToken.mjs";
15
15
  export class RefreshBearerProvider {
16
16
  constructor({ accessToken, refreshAccessToken, refreshToken, refreshExpiresIn, expiresIn, initialTokenResponse, }) {
17
17
  this.BUFFER_IN_MINUTES = 2;
18
- this._accessToken = accessToken || 'no_token';
18
+ this._accessToken = accessToken || "no_token";
19
19
  this._refreshToken = refreshToken;
20
20
  this._initialTokenResponse = initialTokenResponse;
21
21
  this._expiresAt = this.getExpiresAt(expiresIn, this._accessToken, this.BUFFER_IN_MINUTES);
@@ -24,7 +24,7 @@ export class RefreshBearerProvider {
24
24
  }
25
25
  getToken() {
26
26
  return __awaiter(this, void 0, void 0, function* () {
27
- if (this._accessToken && this._accessToken !== 'no_token' && this._expiresAt > new Date()) {
27
+ if (this._accessToken && this._accessToken !== "no_token" && this._expiresAt > new Date()) {
28
28
  return core.Supplier.get(this._accessToken);
29
29
  }
30
30
  if (this._initialTokenResponse) {
@@ -41,7 +41,7 @@ export class RefreshBearerProvider {
41
41
  }
42
42
  refresh() {
43
43
  return __awaiter(this, void 0, void 0, function* () {
44
- if (!this._refreshAccessToken || this._refreshToken && this._refreshExpiresAt < new Date()) {
44
+ if (!this._refreshAccessToken || (this._refreshToken && this._refreshExpiresAt < new Date())) {
45
45
  return core.Supplier.get(this._accessToken);
46
46
  }
47
47
  const tokenResponse = yield this._refreshAccessToken(this._refreshToken);
@@ -60,12 +60,12 @@ export class RefreshBearerProvider {
60
60
  return this.parseTokenExpiry(token, bufferInMinutes) || this.getExpiresAt(0, token, bufferInMinutes);
61
61
  }
62
62
  parseTokenExpiry(token, bufferInMinutes) {
63
- if (!token || token === 'no_token') {
63
+ if (!token || token === "no_token") {
64
64
  return;
65
65
  }
66
66
  try {
67
67
  const decoded = decodeToken(token);
68
- if (decoded && typeof decoded.expiresAt === 'number') {
68
+ if (decoded && typeof decoded.expiresAt === "number") {
69
69
  const ms = decoded.expiresAt * 1000 - bufferInMinutes * 60 * 1000;
70
70
  return new Date(ms);
71
71
  }
@@ -24,4 +24,4 @@ export declare function decodeToken(token: string): {
24
24
  tenantName: string;
25
25
  accessToken: string;
26
26
  expiresAt: number | undefined;
27
- } | undefined;
27
+ } | null;
@@ -21,9 +21,9 @@
21
21
  */
22
22
  export function decodeToken(token) {
23
23
  // Validate the token structure (should contain at least header and payload parts)
24
- const parts = token.split('.');
24
+ const parts = token ? token.split('.') : '';
25
25
  if (parts.length < 2) {
26
- throw new Error('Invalid token format');
26
+ return null;
27
27
  }
28
28
  // Retrieve the payload (second part) of the JWT token
29
29
  const base64Url = parts[1];
@@ -38,7 +38,7 @@ export function decodeToken(token) {
38
38
  .join(''));
39
39
  }
40
40
  catch (error) {
41
- throw new Error('Failed to decode token payload');
41
+ return null;
42
42
  }
43
43
  // Parse the JSON string to obtain token details
44
44
  let tokenDetails;
@@ -46,12 +46,12 @@ export function decodeToken(token) {
46
46
  tokenDetails = JSON.parse(jsonPayload);
47
47
  }
48
48
  catch (error) {
49
- throw new Error('Invalid JSON payload in token');
49
+ return null;
50
50
  }
51
51
  // Extract the issuer URL from the token details
52
52
  const issuerUrl = tokenDetails.iss;
53
53
  if (!issuerUrl) {
54
- throw new Error('Token payload does not contain an issuer (iss) field');
54
+ return null;
55
55
  }
56
56
  // Regex to extract environment and tenant from issuer URL:
57
57
  // Expected format: https://keycloak.{environment}.corti.app/realms/{tenant}
@@ -70,4 +70,5 @@ export function decodeToken(token) {
70
70
  expiresAt,
71
71
  };
72
72
  }
73
+ return null;
73
74
  }
@@ -65,17 +65,9 @@ export function resolveClientOptions(options) {
65
65
  }))();
66
66
  return {
67
67
  tenantName: options.tenantName ||
68
- function () {
69
- return __awaiter(this, void 0, void 0, function* () {
70
- return (yield tokenResponsePromise).tenantName;
71
- });
72
- },
73
- environment: options.environment || function () {
74
- return __awaiter(this, void 0, void 0, function* () {
75
- const environment = getEnvironment((yield tokenResponsePromise).environment);
76
- return core.Supplier.get(environment);
77
- });
78
- },
79
- initialTokenResponse: tokenResponsePromise.then(result => result.tokenResponse),
68
+ tokenResponsePromise.then(({ tenantName }) => tenantName),
69
+ environment: options.environment ||
70
+ tokenResponsePromise.then(({ environment }) => core.Supplier.get(getEnvironment(environment))),
71
+ initialTokenResponse: tokenResponsePromise.then((result) => result.tokenResponse),
80
72
  };
81
73
  }
@@ -1 +1 @@
1
- export declare const SDK_VERSION = "0.0.0-rc.2";
1
+ export declare const SDK_VERSION = "0.0.0-rc.359";
@@ -1 +1 @@
1
- export const SDK_VERSION = "0.0.0-rc.2";
1
+ export const SDK_VERSION = "0.0.0-rc.359";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@corti/sdk",
3
- "version": "0.0.0-rc.2",
3
+ "version": "0.0.0-rc.359",
4
4
  "private": false,
5
5
  "repository": "github:corticph/corti-sdk-javascript",
6
6
  "license": "MIT",