@corti/sdk 0.1.0-alpha → 0.1.1-alpha

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.
@@ -63,8 +63,8 @@ class CortiClient {
63
63
  "Tenant-Name": _options === null || _options === void 0 ? void 0 : _options.tenantName,
64
64
  "X-Fern-Language": "JavaScript",
65
65
  "X-Fern-SDK-Name": "@corti/sdk",
66
- "X-Fern-SDK-Version": "0.1.0-alpha",
67
- "User-Agent": "@corti/sdk/0.1.0-alpha",
66
+ "X-Fern-SDK-Version": "0.1.1-alpha",
67
+ "User-Agent": "@corti/sdk/0.1.1-alpha",
68
68
  "X-Fern-Runtime": core.RUNTIME.type,
69
69
  "X-Fern-Runtime-Version": core.RUNTIME.version,
70
70
  }, _options === null || _options === void 0 ? void 0 : _options.headers) });
@@ -1,5 +1,5 @@
1
1
  import { ResponseWithBody } from "./ResponseWithBody.js";
2
- export interface BinaryResponse {
2
+ export type BinaryResponse = {
3
3
  /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Request/bodyUsed) */
4
4
  bodyUsed: boolean;
5
5
  /**
@@ -11,7 +11,10 @@ export interface BinaryResponse {
11
11
  arrayBuffer: () => Promise<ArrayBuffer>;
12
12
  /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Request/blob) */
13
13
  blob: () => Promise<Blob>;
14
- /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Request/bytes) */
15
- bytes(): Promise<Uint8Array>;
16
- }
14
+ /**
15
+ * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Request/bytes)
16
+ * Some versions of the Fetch API may not support this method.
17
+ */
18
+ bytes?(): Promise<Uint8Array>;
19
+ };
17
20
  export declare function getBinaryResponse(response: ResponseWithBody): BinaryResponse;
@@ -2,13 +2,16 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getBinaryResponse = getBinaryResponse;
4
4
  function getBinaryResponse(response) {
5
- return {
5
+ const binaryResponse = {
6
6
  get bodyUsed() {
7
7
  return response.bodyUsed;
8
8
  },
9
9
  stream: () => response.body,
10
10
  arrayBuffer: response.arrayBuffer.bind(response),
11
11
  blob: response.blob.bind(response),
12
- bytes: response.bytes.bind(response),
13
12
  };
13
+ if ("bytes" in response && typeof response.bytes === "function") {
14
+ binaryResponse.bytes = response.bytes.bind(response);
15
+ }
16
+ return binaryResponse;
14
17
  }
@@ -15,6 +15,7 @@ const json_js_1 = require("../json.js");
15
15
  const RawResponse_js_1 = require("./RawResponse.js");
16
16
  const Supplier_js_1 = require("./Supplier.js");
17
17
  const createRequestUrl_js_1 = require("./createRequestUrl.js");
18
+ const getErrorResponseBody_js_1 = require("./getErrorResponseBody.js");
18
19
  const getFetchFn_js_1 = require("./getFetchFn.js");
19
20
  const getRequestBody_js_1 = require("./getRequestBody.js");
20
21
  const getResponseBody_js_1 = require("./getResponseBody.js");
@@ -55,11 +56,10 @@ function fetcherImpl(args) {
55
56
  const response = yield (0, requestWithRetries_js_1.requestWithRetries)(() => __awaiter(this, void 0, void 0, function* () {
56
57
  return (0, makeRequest_js_1.makeRequest)(fetchFn, url, args.method, yield getHeaders(args), requestBody, args.timeoutMs, args.abortSignal, args.withCredentials, args.duplex);
57
58
  }), args.maxRetries);
58
- const responseBody = yield (0, getResponseBody_js_1.getResponseBody)(response, args.responseType);
59
59
  if (response.status >= 200 && response.status < 400) {
60
60
  return {
61
61
  ok: true,
62
- body: responseBody,
62
+ body: (yield (0, getResponseBody_js_1.getResponseBody)(response, args.responseType)),
63
63
  headers: response.headers,
64
64
  rawResponse: (0, RawResponse_js_1.toRawResponse)(response),
65
65
  };
@@ -70,7 +70,7 @@ function fetcherImpl(args) {
70
70
  error: {
71
71
  reason: "status-code",
72
72
  statusCode: response.status,
73
- body: responseBody,
73
+ body: yield (0, getErrorResponseBody_js_1.getErrorResponseBody)(response),
74
74
  },
75
75
  rawResponse: (0, RawResponse_js_1.toRawResponse)(response),
76
76
  };
@@ -0,0 +1 @@
1
+ export declare function getErrorResponseBody(response: Response): Promise<unknown>;
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.getErrorResponseBody = getErrorResponseBody;
13
+ const json_js_1 = require("../json.js");
14
+ const getResponseBody_js_1 = require("./getResponseBody.js");
15
+ function getErrorResponseBody(response) {
16
+ return __awaiter(this, void 0, void 0, function* () {
17
+ var _a, _b, _c;
18
+ let contentType = (_a = response.headers.get("Content-Type")) === null || _a === void 0 ? void 0 : _a.toLowerCase();
19
+ if (contentType == null || contentType.length === 0) {
20
+ return (0, getResponseBody_js_1.getResponseBody)(response);
21
+ }
22
+ if (contentType.indexOf(";") !== -1) {
23
+ contentType = (_c = (_b = contentType.split(";")[0]) === null || _b === void 0 ? void 0 : _b.trim()) !== null && _c !== void 0 ? _c : "";
24
+ }
25
+ switch (contentType) {
26
+ case "application/hal+json":
27
+ case "application/json":
28
+ case "application/ld+json":
29
+ case "application/problem+json":
30
+ case "application/vnd.api+json":
31
+ case "text/json":
32
+ const text = yield response.text();
33
+ return text.length > 0 ? (0, json_js_1.fromJson)(text) : undefined;
34
+ default:
35
+ if (contentType.startsWith("application/vnd.") && contentType.endsWith("+json")) {
36
+ const text = yield response.text();
37
+ return text.length > 0 ? (0, json_js_1.fromJson)(text) : undefined;
38
+ }
39
+ // Fallback to plain text if content type is not recognized
40
+ // Even if no body is present, the response will be an empty string
41
+ return yield response.text();
42
+ }
43
+ });
44
+ }
@@ -12,6 +12,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.getResponseBody = getResponseBody;
13
13
  const BinaryResponse_js_1 = require("./BinaryResponse.js");
14
14
  const ResponseWithBody_js_1 = require("./ResponseWithBody.js");
15
+ const json_js_1 = require("../json.js");
15
16
  function getResponseBody(response, responseType) {
16
17
  return __awaiter(this, void 0, void 0, function* () {
17
18
  if (!(0, ResponseWithBody_js_1.isResponseWithBody)(response)) {
@@ -35,7 +36,7 @@ function getResponseBody(response, responseType) {
35
36
  const text = yield response.text();
36
37
  if (text.length > 0) {
37
38
  try {
38
- let responseBody = JSON.parse(text);
39
+ let responseBody = (0, json_js_1.fromJson)(text);
39
40
  return responseBody;
40
41
  }
41
42
  catch (err) {
@@ -5,6 +5,9 @@ function join(base, ...segments) {
5
5
  if (!base) {
6
6
  return "";
7
7
  }
8
+ if (segments.length === 0) {
9
+ return base;
10
+ }
8
11
  if (base.includes("://")) {
9
12
  let url;
10
13
  try {
@@ -14,24 +17,37 @@ function join(base, ...segments) {
14
17
  // Fallback to path joining if URL is malformed
15
18
  return joinPath(base, ...segments);
16
19
  }
20
+ const lastSegment = segments[segments.length - 1];
21
+ const shouldPreserveTrailingSlash = lastSegment && lastSegment.endsWith("/");
17
22
  for (const segment of segments) {
18
23
  const cleanSegment = trimSlashes(segment);
19
24
  if (cleanSegment) {
20
25
  url.pathname = joinPathSegments(url.pathname, cleanSegment);
21
26
  }
22
27
  }
28
+ if (shouldPreserveTrailingSlash && !url.pathname.endsWith("/")) {
29
+ url.pathname += "/";
30
+ }
23
31
  return url.toString();
24
32
  }
25
33
  return joinPath(base, ...segments);
26
34
  }
27
35
  function joinPath(base, ...segments) {
36
+ if (segments.length === 0) {
37
+ return base;
38
+ }
28
39
  let result = base;
40
+ const lastSegment = segments[segments.length - 1];
41
+ const shouldPreserveTrailingSlash = lastSegment && lastSegment.endsWith("/");
29
42
  for (const segment of segments) {
30
43
  const cleanSegment = trimSlashes(segment);
31
44
  if (cleanSegment) {
32
45
  result = joinPathSegments(result, cleanSegment);
33
46
  }
34
47
  }
48
+ if (shouldPreserveTrailingSlash && !result.endsWith("/")) {
49
+ result += "/";
50
+ }
35
51
  return result;
36
52
  }
37
53
  function joinPathSegments(left, right) {
@@ -43,7 +59,11 @@ function joinPathSegments(left, right) {
43
59
  function trimSlashes(str) {
44
60
  if (!str)
45
61
  return str;
46
- let start = str.startsWith("/") ? 1 : 0;
47
- let end = str.endsWith("/") ? str.length - 1 : str.length;
48
- return str.slice(start, end);
62
+ let start = 0;
63
+ let end = str.length;
64
+ if (str.startsWith("/"))
65
+ start = 1;
66
+ if (str.endsWith("/"))
67
+ end = str.length - 1;
68
+ return start === 0 && end === str.length ? str : str.slice(start, end);
49
69
  }
@@ -14,5 +14,7 @@ export declare class Stream extends FernStream {
14
14
  /**
15
15
  * Patch: use custom connect method to support passing _options parameters
16
16
  */
17
- connect(args: Omit<FernStream.ConnectArgs, 'token' | 'tenantName'>, configuration?: api.StreamConfig): Promise<StreamSocket>;
17
+ connect({ configuration, ...args }: Omit<FernStream.ConnectArgs, 'token' | 'tenantName'> & {
18
+ configuration?: api.StreamConfig;
19
+ }): Promise<StreamSocket>;
18
20
  }
@@ -41,6 +41,17 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
41
41
  step((generator = generator.apply(thisArg, _arguments || [])).next());
42
42
  });
43
43
  };
44
+ var __rest = (this && this.__rest) || function (s, e) {
45
+ var t = {};
46
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
47
+ t[p] = s[p];
48
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
49
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
50
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
51
+ t[p[i]] = s[p[i]];
52
+ }
53
+ return t;
54
+ };
44
55
  Object.defineProperty(exports, "__esModule", { value: true });
45
56
  exports.Stream = void 0;
46
57
  /**
@@ -59,11 +70,12 @@ class Stream extends Client_js_1.Stream {
59
70
  /**
60
71
  * Patch: use custom connect method to support passing _options parameters
61
72
  */
62
- connect(args, configuration) {
73
+ connect(_a) {
63
74
  const _super = Object.create(null, {
64
75
  connect: { get: () => super.connect }
65
76
  });
66
77
  return __awaiter(this, void 0, void 0, function* () {
78
+ var { configuration } = _a, args = __rest(_a, ["configuration"]);
67
79
  const fernWs = yield _super.connect.call(this, Object.assign(Object.assign({}, args), { token: (yield this._getAuthorizationHeader()) || '', tenantName: yield core.Supplier.get(this._options.tenantName) }));
68
80
  const ws = new CustomStreamSocket_js_1.StreamSocket({ socket: fernWs.socket });
69
81
  if (!configuration) {
@@ -98,6 +110,14 @@ class Stream extends Client_js_1.Stream {
98
110
  ws.close();
99
111
  return;
100
112
  }
113
+ if (parsedResponse.ok && parsedResponse.value.type === 'error') {
114
+ ws.socket.dispatchEvent(new events_js_1.ErrorEvent({
115
+ name: 'error',
116
+ message: JSON.stringify(parsedResponse.value.error),
117
+ }, ''));
118
+ ws.close();
119
+ return;
120
+ }
101
121
  if (parsedResponse.ok && parsedResponse.value.type === 'ENDED') {
102
122
  ws.close();
103
123
  return;
@@ -14,5 +14,7 @@ export declare class Transcribe extends FernTranscribe {
14
14
  /**
15
15
  * Patch: use custom connect method to support passing _options parameters
16
16
  */
17
- connect(args?: Omit<FernTranscribe.ConnectArgs, 'token' | 'tenantName'>, configuration?: api.TranscribeConfig): Promise<TranscribeSocket>;
17
+ connect({ configuration, ...args }?: Omit<FernTranscribe.ConnectArgs, 'token' | 'tenantName'> & {
18
+ configuration?: api.TranscribeConfig;
19
+ }): Promise<TranscribeSocket>;
18
20
  }
@@ -41,6 +41,17 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
41
41
  step((generator = generator.apply(thisArg, _arguments || [])).next());
42
42
  });
43
43
  };
44
+ var __rest = (this && this.__rest) || function (s, e) {
45
+ var t = {};
46
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
47
+ t[p] = s[p];
48
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
49
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
50
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
51
+ t[p[i]] = s[p[i]];
52
+ }
53
+ return t;
54
+ };
44
55
  Object.defineProperty(exports, "__esModule", { value: true });
45
56
  exports.Transcribe = void 0;
46
57
  /**
@@ -63,7 +74,8 @@ class Transcribe extends Client_js_1.Transcribe {
63
74
  const _super = Object.create(null, {
64
75
  connect: { get: () => super.connect }
65
76
  });
66
- return __awaiter(this, arguments, void 0, function* (args = {}, configuration) {
77
+ return __awaiter(this, arguments, void 0, function* (_a = {}) {
78
+ var { configuration } = _a, args = __rest(_a, ["configuration"]);
67
79
  const fernWs = yield _super.connect.call(this, Object.assign(Object.assign({}, args), { token: (yield this._getAuthorizationHeader()) || '', tenantName: yield core.Supplier.get(this._options.tenantName) }));
68
80
  const ws = new CustomTranscribeSocket_js_1.TranscribeSocket({ socket: fernWs.socket });
69
81
  if (!configuration) {
@@ -96,6 +108,14 @@ class Transcribe extends Client_js_1.Transcribe {
96
108
  ws.close();
97
109
  return;
98
110
  }
111
+ if (parsedResponse.ok && parsedResponse.value.type === 'error') {
112
+ ws.socket.dispatchEvent(new events_js_1.ErrorEvent({
113
+ name: 'error',
114
+ message: JSON.stringify(parsedResponse.value.error),
115
+ }, ''));
116
+ ws.close();
117
+ return;
118
+ }
99
119
  if (parsedResponse.ok && parsedResponse.value.type === 'ended') {
100
120
  ws.close();
101
121
  return;
@@ -1 +1 @@
1
- export declare const SDK_VERSION = "0.1.0-alpha";
1
+ export declare const SDK_VERSION = "0.1.1-alpha";
@@ -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.1.0-alpha";
4
+ exports.SDK_VERSION = "0.1.1-alpha";
@@ -27,8 +27,8 @@ export class CortiClient {
27
27
  "Tenant-Name": _options === null || _options === void 0 ? void 0 : _options.tenantName,
28
28
  "X-Fern-Language": "JavaScript",
29
29
  "X-Fern-SDK-Name": "@corti/sdk",
30
- "X-Fern-SDK-Version": "0.1.0-alpha",
31
- "User-Agent": "@corti/sdk/0.1.0-alpha",
30
+ "X-Fern-SDK-Version": "0.1.1-alpha",
31
+ "User-Agent": "@corti/sdk/0.1.1-alpha",
32
32
  "X-Fern-Runtime": core.RUNTIME.type,
33
33
  "X-Fern-Runtime-Version": core.RUNTIME.version,
34
34
  }, _options === null || _options === void 0 ? void 0 : _options.headers) });
@@ -1,5 +1,5 @@
1
1
  import { ResponseWithBody } from "./ResponseWithBody.mjs";
2
- export interface BinaryResponse {
2
+ export type BinaryResponse = {
3
3
  /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Request/bodyUsed) */
4
4
  bodyUsed: boolean;
5
5
  /**
@@ -11,7 +11,10 @@ export interface BinaryResponse {
11
11
  arrayBuffer: () => Promise<ArrayBuffer>;
12
12
  /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Request/blob) */
13
13
  blob: () => Promise<Blob>;
14
- /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Request/bytes) */
15
- bytes(): Promise<Uint8Array>;
16
- }
14
+ /**
15
+ * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Request/bytes)
16
+ * Some versions of the Fetch API may not support this method.
17
+ */
18
+ bytes?(): Promise<Uint8Array>;
19
+ };
17
20
  export declare function getBinaryResponse(response: ResponseWithBody): BinaryResponse;
@@ -1,11 +1,14 @@
1
1
  export function getBinaryResponse(response) {
2
- return {
2
+ const binaryResponse = {
3
3
  get bodyUsed() {
4
4
  return response.bodyUsed;
5
5
  },
6
6
  stream: () => response.body,
7
7
  arrayBuffer: response.arrayBuffer.bind(response),
8
8
  blob: response.blob.bind(response),
9
- bytes: response.bytes.bind(response),
10
9
  };
10
+ if ("bytes" in response && typeof response.bytes === "function") {
11
+ binaryResponse.bytes = response.bytes.bind(response);
12
+ }
13
+ return binaryResponse;
11
14
  }
@@ -11,6 +11,7 @@ import { toJson } from "../json.mjs";
11
11
  import { abortRawResponse, toRawResponse, unknownRawResponse } from "./RawResponse.mjs";
12
12
  import { Supplier } from "./Supplier.mjs";
13
13
  import { createRequestUrl } from "./createRequestUrl.mjs";
14
+ import { getErrorResponseBody } from "./getErrorResponseBody.mjs";
14
15
  import { getFetchFn } from "./getFetchFn.mjs";
15
16
  import { getRequestBody } from "./getRequestBody.mjs";
16
17
  import { getResponseBody } from "./getResponseBody.mjs";
@@ -51,11 +52,10 @@ export function fetcherImpl(args) {
51
52
  const response = yield requestWithRetries(() => __awaiter(this, void 0, void 0, function* () {
52
53
  return makeRequest(fetchFn, url, args.method, yield getHeaders(args), requestBody, args.timeoutMs, args.abortSignal, args.withCredentials, args.duplex);
53
54
  }), args.maxRetries);
54
- const responseBody = yield getResponseBody(response, args.responseType);
55
55
  if (response.status >= 200 && response.status < 400) {
56
56
  return {
57
57
  ok: true,
58
- body: responseBody,
58
+ body: (yield getResponseBody(response, args.responseType)),
59
59
  headers: response.headers,
60
60
  rawResponse: toRawResponse(response),
61
61
  };
@@ -66,7 +66,7 @@ export function fetcherImpl(args) {
66
66
  error: {
67
67
  reason: "status-code",
68
68
  statusCode: response.status,
69
- body: responseBody,
69
+ body: yield getErrorResponseBody(response),
70
70
  },
71
71
  rawResponse: toRawResponse(response),
72
72
  };
@@ -0,0 +1 @@
1
+ export declare function getErrorResponseBody(response: Response): Promise<unknown>;
@@ -0,0 +1,41 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ import { fromJson } from "../json.mjs";
11
+ import { getResponseBody } from "./getResponseBody.mjs";
12
+ export function getErrorResponseBody(response) {
13
+ return __awaiter(this, void 0, void 0, function* () {
14
+ var _a, _b, _c;
15
+ let contentType = (_a = response.headers.get("Content-Type")) === null || _a === void 0 ? void 0 : _a.toLowerCase();
16
+ if (contentType == null || contentType.length === 0) {
17
+ return getResponseBody(response);
18
+ }
19
+ if (contentType.indexOf(";") !== -1) {
20
+ contentType = (_c = (_b = contentType.split(";")[0]) === null || _b === void 0 ? void 0 : _b.trim()) !== null && _c !== void 0 ? _c : "";
21
+ }
22
+ switch (contentType) {
23
+ case "application/hal+json":
24
+ case "application/json":
25
+ case "application/ld+json":
26
+ case "application/problem+json":
27
+ case "application/vnd.api+json":
28
+ case "text/json":
29
+ const text = yield response.text();
30
+ return text.length > 0 ? fromJson(text) : undefined;
31
+ default:
32
+ if (contentType.startsWith("application/vnd.") && contentType.endsWith("+json")) {
33
+ const text = yield response.text();
34
+ return text.length > 0 ? fromJson(text) : undefined;
35
+ }
36
+ // Fallback to plain text if content type is not recognized
37
+ // Even if no body is present, the response will be an empty string
38
+ return yield response.text();
39
+ }
40
+ });
41
+ }
@@ -9,6 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  };
10
10
  import { getBinaryResponse } from "./BinaryResponse.mjs";
11
11
  import { isResponseWithBody } from "./ResponseWithBody.mjs";
12
+ import { fromJson } from "../json.mjs";
12
13
  export function getResponseBody(response, responseType) {
13
14
  return __awaiter(this, void 0, void 0, function* () {
14
15
  if (!isResponseWithBody(response)) {
@@ -32,7 +33,7 @@ export function getResponseBody(response, responseType) {
32
33
  const text = yield response.text();
33
34
  if (text.length > 0) {
34
35
  try {
35
- let responseBody = JSON.parse(text);
36
+ let responseBody = fromJson(text);
36
37
  return responseBody;
37
38
  }
38
39
  catch (err) {
@@ -2,6 +2,9 @@ export function join(base, ...segments) {
2
2
  if (!base) {
3
3
  return "";
4
4
  }
5
+ if (segments.length === 0) {
6
+ return base;
7
+ }
5
8
  if (base.includes("://")) {
6
9
  let url;
7
10
  try {
@@ -11,24 +14,37 @@ export function join(base, ...segments) {
11
14
  // Fallback to path joining if URL is malformed
12
15
  return joinPath(base, ...segments);
13
16
  }
17
+ const lastSegment = segments[segments.length - 1];
18
+ const shouldPreserveTrailingSlash = lastSegment && lastSegment.endsWith("/");
14
19
  for (const segment of segments) {
15
20
  const cleanSegment = trimSlashes(segment);
16
21
  if (cleanSegment) {
17
22
  url.pathname = joinPathSegments(url.pathname, cleanSegment);
18
23
  }
19
24
  }
25
+ if (shouldPreserveTrailingSlash && !url.pathname.endsWith("/")) {
26
+ url.pathname += "/";
27
+ }
20
28
  return url.toString();
21
29
  }
22
30
  return joinPath(base, ...segments);
23
31
  }
24
32
  function joinPath(base, ...segments) {
33
+ if (segments.length === 0) {
34
+ return base;
35
+ }
25
36
  let result = base;
37
+ const lastSegment = segments[segments.length - 1];
38
+ const shouldPreserveTrailingSlash = lastSegment && lastSegment.endsWith("/");
26
39
  for (const segment of segments) {
27
40
  const cleanSegment = trimSlashes(segment);
28
41
  if (cleanSegment) {
29
42
  result = joinPathSegments(result, cleanSegment);
30
43
  }
31
44
  }
45
+ if (shouldPreserveTrailingSlash && !result.endsWith("/")) {
46
+ result += "/";
47
+ }
32
48
  return result;
33
49
  }
34
50
  function joinPathSegments(left, right) {
@@ -40,7 +56,11 @@ function joinPathSegments(left, right) {
40
56
  function trimSlashes(str) {
41
57
  if (!str)
42
58
  return str;
43
- let start = str.startsWith("/") ? 1 : 0;
44
- let end = str.endsWith("/") ? str.length - 1 : str.length;
45
- return str.slice(start, end);
59
+ let start = 0;
60
+ let end = str.length;
61
+ if (str.startsWith("/"))
62
+ start = 1;
63
+ if (str.endsWith("/"))
64
+ end = str.length - 1;
65
+ return start === 0 && end === str.length ? str : str.slice(start, end);
46
66
  }
@@ -14,5 +14,7 @@ export declare class Stream extends FernStream {
14
14
  /**
15
15
  * Patch: use custom connect method to support passing _options parameters
16
16
  */
17
- connect(args: Omit<FernStream.ConnectArgs, 'token' | 'tenantName'>, configuration?: api.StreamConfig): Promise<StreamSocket>;
17
+ connect({ configuration, ...args }: Omit<FernStream.ConnectArgs, 'token' | 'tenantName'> & {
18
+ configuration?: api.StreamConfig;
19
+ }): Promise<StreamSocket>;
18
20
  }
@@ -7,6 +7,17 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
7
7
  step((generator = generator.apply(thisArg, _arguments || [])).next());
8
8
  });
9
9
  };
10
+ var __rest = (this && this.__rest) || function (s, e) {
11
+ var t = {};
12
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
13
+ t[p] = s[p];
14
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
15
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
16
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
17
+ t[p[i]] = s[p[i]];
18
+ }
19
+ return t;
20
+ };
10
21
  /**
11
22
  * Patch: use custom Stream implementation to support passing _options parameters to connection function
12
23
  */
@@ -23,11 +34,12 @@ export class Stream extends FernStream {
23
34
  /**
24
35
  * Patch: use custom connect method to support passing _options parameters
25
36
  */
26
- connect(args, configuration) {
37
+ connect(_a) {
27
38
  const _super = Object.create(null, {
28
39
  connect: { get: () => super.connect }
29
40
  });
30
41
  return __awaiter(this, void 0, void 0, function* () {
42
+ var { configuration } = _a, args = __rest(_a, ["configuration"]);
31
43
  const fernWs = yield _super.connect.call(this, Object.assign(Object.assign({}, args), { token: (yield this._getAuthorizationHeader()) || '', tenantName: yield core.Supplier.get(this._options.tenantName) }));
32
44
  const ws = new StreamSocket({ socket: fernWs.socket });
33
45
  if (!configuration) {
@@ -62,6 +74,14 @@ export class Stream extends FernStream {
62
74
  ws.close();
63
75
  return;
64
76
  }
77
+ if (parsedResponse.ok && parsedResponse.value.type === 'error') {
78
+ ws.socket.dispatchEvent(new ErrorEvent({
79
+ name: 'error',
80
+ message: JSON.stringify(parsedResponse.value.error),
81
+ }, ''));
82
+ ws.close();
83
+ return;
84
+ }
65
85
  if (parsedResponse.ok && parsedResponse.value.type === 'ENDED') {
66
86
  ws.close();
67
87
  return;
@@ -14,5 +14,7 @@ export declare class Transcribe extends FernTranscribe {
14
14
  /**
15
15
  * Patch: use custom connect method to support passing _options parameters
16
16
  */
17
- connect(args?: Omit<FernTranscribe.ConnectArgs, 'token' | 'tenantName'>, configuration?: api.TranscribeConfig): Promise<TranscribeSocket>;
17
+ connect({ configuration, ...args }?: Omit<FernTranscribe.ConnectArgs, 'token' | 'tenantName'> & {
18
+ configuration?: api.TranscribeConfig;
19
+ }): Promise<TranscribeSocket>;
18
20
  }
@@ -7,6 +7,17 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
7
7
  step((generator = generator.apply(thisArg, _arguments || [])).next());
8
8
  });
9
9
  };
10
+ var __rest = (this && this.__rest) || function (s, e) {
11
+ var t = {};
12
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
13
+ t[p] = s[p];
14
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
15
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
16
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
17
+ t[p[i]] = s[p[i]];
18
+ }
19
+ return t;
20
+ };
10
21
  /**
11
22
  * Patch: use custom Transcribe implementation to support passing _options parameters to connection function
12
23
  */
@@ -27,7 +38,8 @@ export class Transcribe extends FernTranscribe {
27
38
  const _super = Object.create(null, {
28
39
  connect: { get: () => super.connect }
29
40
  });
30
- return __awaiter(this, arguments, void 0, function* (args = {}, configuration) {
41
+ return __awaiter(this, arguments, void 0, function* (_a = {}) {
42
+ var { configuration } = _a, args = __rest(_a, ["configuration"]);
31
43
  const fernWs = yield _super.connect.call(this, Object.assign(Object.assign({}, args), { token: (yield this._getAuthorizationHeader()) || '', tenantName: yield core.Supplier.get(this._options.tenantName) }));
32
44
  const ws = new TranscribeSocket({ socket: fernWs.socket });
33
45
  if (!configuration) {
@@ -60,6 +72,14 @@ export class Transcribe extends FernTranscribe {
60
72
  ws.close();
61
73
  return;
62
74
  }
75
+ if (parsedResponse.ok && parsedResponse.value.type === 'error') {
76
+ ws.socket.dispatchEvent(new ErrorEvent({
77
+ name: 'error',
78
+ message: JSON.stringify(parsedResponse.value.error),
79
+ }, ''));
80
+ ws.close();
81
+ return;
82
+ }
63
83
  if (parsedResponse.ok && parsedResponse.value.type === 'ended') {
64
84
  ws.close();
65
85
  return;
@@ -1 +1 @@
1
- export declare const SDK_VERSION = "0.1.0-alpha";
1
+ export declare const SDK_VERSION = "0.1.1-alpha";
@@ -1 +1 @@
1
- export const SDK_VERSION = "0.1.0-alpha";
1
+ export const SDK_VERSION = "0.1.1-alpha";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@corti/sdk",
3
- "version": "0.1.0-alpha",
3
+ "version": "0.1.1-alpha",
4
4
  "private": false,
5
5
  "repository": "github:corticph/corti-sdk-typescript",
6
6
  "license": "MIT",
package/reference.md CHANGED
@@ -36,7 +36,7 @@ for await (const item of response) {
36
36
  }
37
37
 
38
38
  // Or you can manually iterate page-by-page
39
- const page = await client.interactions.list();
39
+ let page = await client.interactions.list();
40
40
  while (page.hasNextPage()) {
41
41
  page = page.getNextPage();
42
42
  }