@corti/sdk 1.0.0-rc → 1.0.0-rc.3

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
@@ -29,7 +29,7 @@ The Corti JavaScript library provides convenient access to the Corti APIs from J
29
29
 
30
30
  ## Documentation
31
31
 
32
- - [Documentation](https://docs.corti.ai/)
32
+ - [Documentation](https://docs.corti.ai/sdk/js)
33
33
  - [API Reference](https://docs.corti.ai/api-reference)
34
34
  - [Console](https://console.corti.app/) — get your credentials here
35
35
  - [Examples](https://github.com/corticph/corti-examples)
@@ -43,8 +43,8 @@ function normalizeClientOptions(options) {
43
43
  const headers = (0, headers_js_1.mergeHeaders)({
44
44
  "X-Fern-Language": "JavaScript",
45
45
  "X-Fern-SDK-Name": "@corti/sdk",
46
- "X-Fern-SDK-Version": "1.0.0-rc",
47
- "User-Agent": "@corti/sdk/1.0.0-rc",
46
+ "X-Fern-SDK-Version": "1.0.0-rc.3",
47
+ "User-Agent": "@corti/sdk/1.0.0-rc.3",
48
48
  "X-Fern-Runtime": core.RUNTIME.type,
49
49
  "X-Fern-Runtime-Version": core.RUNTIME.version,
50
50
  "Tenant-Name": options === null || options === void 0 ? void 0 : options.tenantName,
@@ -61,6 +61,7 @@ export declare namespace CortiAuth {
61
61
  }
62
62
  }
63
63
  export declare class CortiAuth extends AuthClient {
64
+ private readonly _tenantName;
64
65
  /** No-op auth provider so super.token() does not trigger OAuth refresh. When auth is omitted, a dummy token is passed so the base constructor does not throw. */
65
66
  constructor(options: CortiAuth.Options);
66
67
  /**
@@ -61,13 +61,17 @@ const buildTokenRequestBody_js_1 = require("../utils/buildTokenRequestBody.js");
61
61
  const environment_js_1 = require("../utils/environment.js");
62
62
  const localStorageHelpers_js_1 = require("../utils/localStorageHelpers.js");
63
63
  const pkceHelpers_js_1 = require("../utils/pkceHelpers.js");
64
+ const stripFernNormalizedHeaders_js_1 = require("../utils/stripFernNormalizedHeaders.js");
64
65
  class CortiAuth extends Client_js_1.AuthClient {
65
66
  /** No-op auth provider so super.token() does not trigger OAuth refresh. When auth is omitted, a dummy token is passed so the base constructor does not throw. */
66
67
  constructor(options) {
67
68
  var _a;
68
- const { environment } = options, rest = __rest(options, ["environment"]);
69
- super(Object.assign(Object.assign({}, rest), { environment: (0, environment_js_1.getEnvironment)(environment), token: (_a = options.token) !== null && _a !== void 0 ? _a : (() => "") }));
69
+ const { environment, tenantName } = options, rest = __rest(options, ["environment", "tenantName"]);
70
+ super(Object.assign(Object.assign({}, rest), { tenantName: "", environment: (0, environment_js_1.getEnvironment)(environment), token: (_a = options.token) !== null && _a !== void 0 ? _a : (() => "") }));
71
+ this._tenantName = tenantName;
70
72
  this._options.authProvider = new core.NoOpAuthProvider();
73
+ /** Stripping Fern headers to bypass CORS on authentication requests */
74
+ this._options.headers = (0, stripFernNormalizedHeaders_js_1.stripFernNormalizedHeaders)(this._options.headers);
71
75
  }
72
76
  /**
73
77
  * Exchange credentials for a short-lived access token using the tenant token endpoint (client_credentials).
@@ -92,7 +96,7 @@ class CortiAuth extends Client_js_1.AuthClient {
92
96
  _getTokenWithTenant(request, requestOptions) {
93
97
  return __awaiter(this, void 0, void 0, function* () {
94
98
  const authRequest = (0, buildTokenRequestBody_js_1.buildTokenRequestBody)(request);
95
- const tenantName = yield core.Supplier.get(this._options.tenantName);
99
+ const tenantName = yield core.Supplier.get(this._tenantName);
96
100
  return this.token(tenantName, authRequest, requestOptions).withRawResponse();
97
101
  });
98
102
  }
@@ -168,7 +172,7 @@ class CortiAuth extends Client_js_1.AuthClient {
168
172
  authorizeURL(_a, options_1) {
169
173
  return __awaiter(this, arguments, void 0, function* ({ clientId, redirectUri, codeChallenge, scopes }, options) {
170
174
  const envUrls = yield core.Supplier.get(this._options.environment);
171
- const tenantName = yield core.Supplier.get(this._options.tenantName);
175
+ const tenantName = yield core.Supplier.get(this._tenantName);
172
176
  const authUrl = new URL(core.url.join(envUrls.login, tenantName, "protocol/openid-connect/auth"));
173
177
  authUrl.searchParams.set("response_type", "code");
174
178
  const allScopes = ["openid", "profile", ...(scopes !== null && scopes !== void 0 ? scopes : [])];
@@ -49,16 +49,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
49
49
  exports.buildProtocolsFromHeaders = buildProtocolsFromHeaders;
50
50
  exports.getWsProtocols = getWsProtocols;
51
51
  const core = __importStar(require("../../core/index.js"));
52
- /** Headers added by the SDK; exclude these when filterSdkHeaders is true (e.g. merged client headers). */
53
- const SDK_HEADER_NAMES = new Set([
54
- "Tenant-Name",
55
- "X-Fern-Language",
56
- "X-Fern-SDK-Name",
57
- "X-Fern-SDK-Version",
58
- "User-Agent",
59
- "X-Fern-Runtime",
60
- "X-Fern-Runtime-Version",
61
- ]);
52
+ const sdkHeaderNames_js_1 = require("./sdkHeaderNames.js");
62
53
  /**
63
54
  * Resolves header values (including suppliers/functions) and returns a flat array
64
55
  * of [name, encodeURIComponent(value)] for each header, skipping undefined/empty values.
@@ -71,7 +62,7 @@ function buildProtocolsFromHeaders(headers_1) {
71
62
  }
72
63
  const protocols = [];
73
64
  for (const [name, valueOrSupplier] of Object.entries(headers)) {
74
- if (filterSdkHeaders && SDK_HEADER_NAMES.has(name)) {
65
+ if (filterSdkHeaders && sdkHeaderNames_js_1.SDK_HEADER_NAMES.has(name)) {
75
66
  continue;
76
67
  }
77
68
  const value = yield core.Supplier.get(valueOrSupplier);
@@ -0,0 +1 @@
1
+ export declare const SDK_HEADER_NAMES: ReadonlySet<string>;
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SDK_HEADER_NAMES = void 0;
4
+ exports.SDK_HEADER_NAMES = new Set([
5
+ "Tenant-Name",
6
+ "X-Fern-Language",
7
+ "X-Fern-SDK-Name",
8
+ "X-Fern-SDK-Version",
9
+ "User-Agent",
10
+ "X-Fern-Runtime",
11
+ "X-Fern-Runtime-Version",
12
+ ]);
@@ -0,0 +1,5 @@
1
+ import type { BaseClientOptions } from "../../BaseClient.js";
2
+ type Headers = BaseClientOptions["headers"];
3
+ type HeaderValue = NonNullable<Headers>[string];
4
+ export declare function stripFernNormalizedHeaders(headers: Headers): Record<string, HeaderValue>;
5
+ export {};
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.stripFernNormalizedHeaders = stripFernNormalizedHeaders;
4
+ const sdkHeaderNames_js_1 = require("./sdkHeaderNames.js");
5
+ function normalizeHeaderKeys(headers) {
6
+ const result = {};
7
+ if (headers == null) {
8
+ return result;
9
+ }
10
+ for (const [key, value] of Object.entries(headers)) {
11
+ const insensitiveKey = key.toLowerCase();
12
+ if (value != null) {
13
+ result[insensitiveKey] = value;
14
+ }
15
+ else if (insensitiveKey in result) {
16
+ delete result[insensitiveKey];
17
+ }
18
+ }
19
+ return result;
20
+ }
21
+ function stripFernNormalizedHeaders(headers) {
22
+ const normalized = normalizeHeaderKeys(headers);
23
+ for (const headerName of sdkHeaderNames_js_1.SDK_HEADER_NAMES) {
24
+ delete normalized[headerName.toLowerCase()];
25
+ }
26
+ return normalized;
27
+ }
@@ -1 +1 @@
1
- export declare const SDK_VERSION = "1.0.0-rc";
1
+ export declare const SDK_VERSION = "1.0.0-rc.3";
@@ -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 = "1.0.0-rc";
4
+ exports.SDK_VERSION = "1.0.0-rc.3";
@@ -6,8 +6,8 @@ export function normalizeClientOptions(options) {
6
6
  const headers = mergeHeaders({
7
7
  "X-Fern-Language": "JavaScript",
8
8
  "X-Fern-SDK-Name": "@corti/sdk",
9
- "X-Fern-SDK-Version": "1.0.0-rc",
10
- "User-Agent": "@corti/sdk/1.0.0-rc",
9
+ "X-Fern-SDK-Version": "1.0.0-rc.3",
10
+ "User-Agent": "@corti/sdk/1.0.0-rc.3",
11
11
  "X-Fern-Runtime": core.RUNTIME.type,
12
12
  "X-Fern-Runtime-Version": core.RUNTIME.version,
13
13
  "Tenant-Name": options === null || options === void 0 ? void 0 : options.tenantName,
@@ -61,6 +61,7 @@ export declare namespace CortiAuth {
61
61
  }
62
62
  }
63
63
  export declare class CortiAuth extends AuthClient {
64
+ private readonly _tenantName;
64
65
  /** No-op auth provider so super.token() does not trigger OAuth refresh. When auth is omitted, a dummy token is passed so the base constructor does not throw. */
65
66
  constructor(options: CortiAuth.Options);
66
67
  /**
@@ -25,13 +25,17 @@ import { buildTokenRequestBody } from "../utils/buildTokenRequestBody.mjs";
25
25
  import { getEnvironment } from "../utils/environment.mjs";
26
26
  import { CODE_VERIFIER_KEY, getLocalStorageItem, setLocalStorageItem } from "../utils/localStorageHelpers.mjs";
27
27
  import { generateCodeChallenge, generateCodeVerifier } from "../utils/pkceHelpers.mjs";
28
+ import { stripFernNormalizedHeaders } from "../utils/stripFernNormalizedHeaders.mjs";
28
29
  export class CortiAuth extends AuthClient {
29
30
  /** No-op auth provider so super.token() does not trigger OAuth refresh. When auth is omitted, a dummy token is passed so the base constructor does not throw. */
30
31
  constructor(options) {
31
32
  var _a;
32
- const { environment } = options, rest = __rest(options, ["environment"]);
33
- super(Object.assign(Object.assign({}, rest), { environment: getEnvironment(environment), token: (_a = options.token) !== null && _a !== void 0 ? _a : (() => "") }));
33
+ const { environment, tenantName } = options, rest = __rest(options, ["environment", "tenantName"]);
34
+ super(Object.assign(Object.assign({}, rest), { tenantName: "", environment: getEnvironment(environment), token: (_a = options.token) !== null && _a !== void 0 ? _a : (() => "") }));
35
+ this._tenantName = tenantName;
34
36
  this._options.authProvider = new core.NoOpAuthProvider();
37
+ /** Stripping Fern headers to bypass CORS on authentication requests */
38
+ this._options.headers = stripFernNormalizedHeaders(this._options.headers);
35
39
  }
36
40
  /**
37
41
  * Exchange credentials for a short-lived access token using the tenant token endpoint (client_credentials).
@@ -56,7 +60,7 @@ export class CortiAuth extends AuthClient {
56
60
  _getTokenWithTenant(request, requestOptions) {
57
61
  return __awaiter(this, void 0, void 0, function* () {
58
62
  const authRequest = buildTokenRequestBody(request);
59
- const tenantName = yield core.Supplier.get(this._options.tenantName);
63
+ const tenantName = yield core.Supplier.get(this._tenantName);
60
64
  return this.token(tenantName, authRequest, requestOptions).withRawResponse();
61
65
  });
62
66
  }
@@ -132,7 +136,7 @@ export class CortiAuth extends AuthClient {
132
136
  authorizeURL(_a, options_1) {
133
137
  return __awaiter(this, arguments, void 0, function* ({ clientId, redirectUri, codeChallenge, scopes }, options) {
134
138
  const envUrls = yield core.Supplier.get(this._options.environment);
135
- const tenantName = yield core.Supplier.get(this._options.tenantName);
139
+ const tenantName = yield core.Supplier.get(this._tenantName);
136
140
  const authUrl = new URL(core.url.join(envUrls.login, tenantName, "protocol/openid-connect/auth"));
137
141
  authUrl.searchParams.set("response_type", "code");
138
142
  const allScopes = ["openid", "profile", ...(scopes !== null && scopes !== void 0 ? scopes : [])];
@@ -12,16 +12,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
12
12
  });
13
13
  };
14
14
  import * as core from "../../core/index.mjs";
15
- /** Headers added by the SDK; exclude these when filterSdkHeaders is true (e.g. merged client headers). */
16
- const SDK_HEADER_NAMES = new Set([
17
- "Tenant-Name",
18
- "X-Fern-Language",
19
- "X-Fern-SDK-Name",
20
- "X-Fern-SDK-Version",
21
- "User-Agent",
22
- "X-Fern-Runtime",
23
- "X-Fern-Runtime-Version",
24
- ]);
15
+ import { SDK_HEADER_NAMES } from "./sdkHeaderNames.mjs";
25
16
  /**
26
17
  * Resolves header values (including suppliers/functions) and returns a flat array
27
18
  * of [name, encodeURIComponent(value)] for each header, skipping undefined/empty values.
@@ -0,0 +1 @@
1
+ export declare const SDK_HEADER_NAMES: ReadonlySet<string>;
@@ -0,0 +1,9 @@
1
+ export const SDK_HEADER_NAMES = new Set([
2
+ "Tenant-Name",
3
+ "X-Fern-Language",
4
+ "X-Fern-SDK-Name",
5
+ "X-Fern-SDK-Version",
6
+ "User-Agent",
7
+ "X-Fern-Runtime",
8
+ "X-Fern-Runtime-Version",
9
+ ]);
@@ -0,0 +1,5 @@
1
+ import type { BaseClientOptions } from "../../BaseClient.mjs";
2
+ type Headers = BaseClientOptions["headers"];
3
+ type HeaderValue = NonNullable<Headers>[string];
4
+ export declare function stripFernNormalizedHeaders(headers: Headers): Record<string, HeaderValue>;
5
+ export {};
@@ -0,0 +1,24 @@
1
+ import { SDK_HEADER_NAMES } from "./sdkHeaderNames.mjs";
2
+ function normalizeHeaderKeys(headers) {
3
+ const result = {};
4
+ if (headers == null) {
5
+ return result;
6
+ }
7
+ for (const [key, value] of Object.entries(headers)) {
8
+ const insensitiveKey = key.toLowerCase();
9
+ if (value != null) {
10
+ result[insensitiveKey] = value;
11
+ }
12
+ else if (insensitiveKey in result) {
13
+ delete result[insensitiveKey];
14
+ }
15
+ }
16
+ return result;
17
+ }
18
+ export function stripFernNormalizedHeaders(headers) {
19
+ const normalized = normalizeHeaderKeys(headers);
20
+ for (const headerName of SDK_HEADER_NAMES) {
21
+ delete normalized[headerName.toLowerCase()];
22
+ }
23
+ return normalized;
24
+ }
@@ -1 +1 @@
1
- export declare const SDK_VERSION = "1.0.0-rc";
1
+ export declare const SDK_VERSION = "1.0.0-rc.3";
@@ -1 +1 @@
1
- export const SDK_VERSION = "1.0.0-rc";
1
+ export const SDK_VERSION = "1.0.0-rc.3";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@corti/sdk",
3
- "version": "1.0.0-rc",
3
+ "version": "1.0.0-rc.3",
4
4
  "private": false,
5
5
  "repository": {
6
6
  "type": "git",