phonic 0.31.6 → 0.31.8

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.
Files changed (67) hide show
  1. package/README.md +34 -11
  2. package/dist/cjs/BaseClient.js +2 -2
  3. package/dist/cjs/Client.d.ts +12 -0
  4. package/dist/cjs/Client.js +74 -0
  5. package/dist/cjs/api/resources/conversations/client/Client.d.ts +4 -1
  6. package/dist/cjs/api/resources/conversations/client/Client.js +18 -11
  7. package/dist/cjs/api/resources/conversations/client/Socket.d.ts +4 -3
  8. package/dist/cjs/api/resources/conversations/client/Socket.js +6 -2
  9. package/dist/cjs/api/resources/conversations/client/requests/ConversationsGetRequest.d.ts +9 -0
  10. package/dist/cjs/api/resources/conversations/client/requests/ConversationsGetRequest.js +3 -0
  11. package/dist/cjs/api/resources/conversations/client/requests/ConversationsListRequest.d.ts +3 -0
  12. package/dist/cjs/api/resources/conversations/client/requests/index.d.ts +1 -0
  13. package/dist/cjs/api/resources/conversations/exports.d.ts +1 -0
  14. package/dist/cjs/api/resources/conversations/exports.js +3 -1
  15. package/dist/cjs/api/resources/conversations/types/ConversationsGetRequestAudioContainer.d.ts +5 -0
  16. package/dist/cjs/api/resources/conversations/types/ConversationsGetRequestAudioContainer.js +8 -0
  17. package/dist/cjs/api/resources/conversations/types/ConversationsListRequestAudioContainer.d.ts +5 -0
  18. package/dist/cjs/api/resources/conversations/types/ConversationsListRequestAudioContainer.js +8 -0
  19. package/dist/cjs/api/resources/conversations/types/index.d.ts +2 -0
  20. package/dist/cjs/api/resources/conversations/types/index.js +2 -0
  21. package/dist/cjs/api/types/SayPayload.d.ts +7 -0
  22. package/dist/cjs/api/types/SayPayload.js +3 -0
  23. package/dist/cjs/api/types/index.d.ts +1 -0
  24. package/dist/cjs/api/types/index.js +1 -0
  25. package/dist/cjs/core/fetcher/BinaryResponse.d.ts +1 -1
  26. package/dist/cjs/core/fetcher/index.d.ts +2 -0
  27. package/dist/cjs/core/fetcher/index.js +3 -1
  28. package/dist/cjs/core/fetcher/makePassthroughRequest.d.ts +49 -0
  29. package/dist/cjs/core/fetcher/makePassthroughRequest.js +135 -0
  30. package/dist/cjs/core/websocket/ws.d.ts +10 -1
  31. package/dist/cjs/core/websocket/ws.js +17 -5
  32. package/dist/cjs/version.d.ts +1 -1
  33. package/dist/cjs/version.js +1 -1
  34. package/dist/esm/BaseClient.mjs +2 -2
  35. package/dist/esm/Client.d.mts +12 -0
  36. package/dist/esm/Client.mjs +41 -0
  37. package/dist/esm/api/resources/conversations/client/Client.d.mts +4 -1
  38. package/dist/esm/api/resources/conversations/client/Client.mjs +18 -11
  39. package/dist/esm/api/resources/conversations/client/Socket.d.mts +4 -3
  40. package/dist/esm/api/resources/conversations/client/Socket.mjs +6 -2
  41. package/dist/esm/api/resources/conversations/client/requests/ConversationsGetRequest.d.mts +9 -0
  42. package/dist/esm/api/resources/conversations/client/requests/ConversationsGetRequest.mjs +2 -0
  43. package/dist/esm/api/resources/conversations/client/requests/ConversationsListRequest.d.mts +3 -0
  44. package/dist/esm/api/resources/conversations/client/requests/index.d.mts +1 -0
  45. package/dist/esm/api/resources/conversations/exports.d.mts +1 -0
  46. package/dist/esm/api/resources/conversations/exports.mjs +1 -0
  47. package/dist/esm/api/resources/conversations/types/ConversationsGetRequestAudioContainer.d.mts +5 -0
  48. package/dist/esm/api/resources/conversations/types/ConversationsGetRequestAudioContainer.mjs +5 -0
  49. package/dist/esm/api/resources/conversations/types/ConversationsListRequestAudioContainer.d.mts +5 -0
  50. package/dist/esm/api/resources/conversations/types/ConversationsListRequestAudioContainer.mjs +5 -0
  51. package/dist/esm/api/resources/conversations/types/index.d.mts +2 -0
  52. package/dist/esm/api/resources/conversations/types/index.mjs +2 -0
  53. package/dist/esm/api/types/SayPayload.d.mts +7 -0
  54. package/dist/esm/api/types/SayPayload.mjs +2 -0
  55. package/dist/esm/api/types/index.d.mts +1 -0
  56. package/dist/esm/api/types/index.mjs +1 -0
  57. package/dist/esm/core/fetcher/BinaryResponse.d.mts +1 -1
  58. package/dist/esm/core/fetcher/index.d.mts +2 -0
  59. package/dist/esm/core/fetcher/index.mjs +1 -0
  60. package/dist/esm/core/fetcher/makePassthroughRequest.d.mts +49 -0
  61. package/dist/esm/core/fetcher/makePassthroughRequest.mjs +132 -0
  62. package/dist/esm/core/websocket/ws.d.mts +10 -1
  63. package/dist/esm/core/websocket/ws.mjs +17 -5
  64. package/dist/esm/version.d.mts +1 -1
  65. package/dist/esm/version.mjs +1 -1
  66. package/package.json +7 -7
  67. package/reference.md +9 -1
@@ -2,5 +2,6 @@ export { EndpointSupplier } from "./EndpointSupplier.mjs";
2
2
  export { fetcher } from "./Fetcher.mjs";
3
3
  export { getHeader } from "./getHeader.mjs";
4
4
  export { HttpResponsePromise } from "./HttpResponsePromise.mjs";
5
+ export { makePassthroughRequest } from "./makePassthroughRequest.mjs";
5
6
  export { abortRawResponse, toRawResponse, unknownRawResponse } from "./RawResponse.mjs";
6
7
  export { Supplier } from "./Supplier.mjs";
@@ -0,0 +1,49 @@
1
+ import { type LogConfig, type Logger } from "../logging/logger.mjs";
2
+ import { Supplier } from "./Supplier.mjs";
3
+ export declare namespace PassthroughRequest {
4
+ /**
5
+ * Per-request options that can override the SDK client defaults.
6
+ */
7
+ interface RequestOptions {
8
+ /** Override the default timeout for this request (in seconds). */
9
+ timeoutInSeconds?: number;
10
+ /** Override the default number of retries for this request. */
11
+ maxRetries?: number;
12
+ /** Additional headers to include in this request. */
13
+ headers?: Record<string, string>;
14
+ /** Abort signal for this request. */
15
+ abortSignal?: AbortSignal;
16
+ }
17
+ /**
18
+ * SDK client configuration used by the passthrough fetch method.
19
+ */
20
+ interface ClientOptions {
21
+ /** The base URL or environment for the client. */
22
+ environment?: Supplier<string>;
23
+ /** Override the base URL. */
24
+ baseUrl?: Supplier<string>;
25
+ /** Default headers to include in requests. */
26
+ headers?: Record<string, unknown>;
27
+ /** Default maximum time to wait for a response in seconds. */
28
+ timeoutInSeconds?: number;
29
+ /** Default number of times to retry the request. Defaults to 2. */
30
+ maxRetries?: number;
31
+ /** A custom fetch function. */
32
+ fetch?: typeof fetch;
33
+ /** Logging configuration. */
34
+ logging?: LogConfig | Logger;
35
+ /** A function that returns auth headers. */
36
+ getAuthHeaders?: () => Promise<Record<string, string>>;
37
+ }
38
+ }
39
+ /**
40
+ * Makes a passthrough HTTP request using the SDK's configuration (auth, retry, logging, etc.)
41
+ * while mimicking the standard `fetch` API.
42
+ *
43
+ * @param input - The URL, path, or Request object. If a relative path, it will be resolved against the configured base URL.
44
+ * @param init - Standard RequestInit options (method, headers, body, signal, etc.)
45
+ * @param clientOptions - SDK client options (auth, default headers, logging, etc.)
46
+ * @param requestOptions - Per-request overrides (timeout, retries, extra headers, abort signal).
47
+ * @returns A standard Response object.
48
+ */
49
+ export declare function makePassthroughRequest(input: Request | string | URL, init: RequestInit | undefined, clientOptions: PassthroughRequest.ClientOptions, requestOptions?: PassthroughRequest.RequestOptions): Promise<Response>;
@@ -0,0 +1,132 @@
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 { createLogger } from "../logging/logger.mjs";
11
+ import { join } from "../url/join.mjs";
12
+ import { EndpointSupplier } from "./EndpointSupplier.mjs";
13
+ import { getFetchFn } from "./getFetchFn.mjs";
14
+ import { makeRequest } from "./makeRequest.mjs";
15
+ import { requestWithRetries } from "./requestWithRetries.mjs";
16
+ import { Supplier } from "./Supplier.mjs";
17
+ /**
18
+ * Makes a passthrough HTTP request using the SDK's configuration (auth, retry, logging, etc.)
19
+ * while mimicking the standard `fetch` API.
20
+ *
21
+ * @param input - The URL, path, or Request object. If a relative path, it will be resolved against the configured base URL.
22
+ * @param init - Standard RequestInit options (method, headers, body, signal, etc.)
23
+ * @param clientOptions - SDK client options (auth, default headers, logging, etc.)
24
+ * @param requestOptions - Per-request overrides (timeout, retries, extra headers, abort signal).
25
+ * @returns A standard Response object.
26
+ */
27
+ export function makePassthroughRequest(input, init, clientOptions, requestOptions) {
28
+ return __awaiter(this, void 0, void 0, function* () {
29
+ var _a, _b, _c, _d, _e, _f, _g;
30
+ const logger = createLogger(clientOptions.logging);
31
+ // Extract URL and default init properties from Request object if provided
32
+ let url;
33
+ let effectiveInit = init;
34
+ if (input instanceof Request) {
35
+ url = input.url;
36
+ // If no explicit init provided, extract properties from the Request object
37
+ if (init == null) {
38
+ effectiveInit = {
39
+ method: input.method,
40
+ headers: Object.fromEntries(input.headers.entries()),
41
+ body: input.body,
42
+ signal: input.signal,
43
+ credentials: input.credentials,
44
+ cache: input.cache,
45
+ redirect: input.redirect,
46
+ referrer: input.referrer,
47
+ integrity: input.integrity,
48
+ mode: input.mode,
49
+ };
50
+ }
51
+ }
52
+ else {
53
+ url = input instanceof URL ? input.toString() : input;
54
+ }
55
+ // Resolve the base URL
56
+ const baseUrl = (_a = (clientOptions.baseUrl != null ? yield Supplier.get(clientOptions.baseUrl) : undefined)) !== null && _a !== void 0 ? _a : (clientOptions.environment != null ? yield Supplier.get(clientOptions.environment) : undefined);
57
+ // Determine the full URL
58
+ let fullUrl;
59
+ if (url.startsWith("http://") || url.startsWith("https://")) {
60
+ fullUrl = url;
61
+ }
62
+ else if (baseUrl != null) {
63
+ fullUrl = join(baseUrl, url);
64
+ }
65
+ else {
66
+ fullUrl = url;
67
+ }
68
+ // Merge headers: SDK default headers -> auth headers -> user-provided headers
69
+ const mergedHeaders = {};
70
+ // Apply SDK default headers (resolve suppliers)
71
+ if (clientOptions.headers != null) {
72
+ for (const [key, value] of Object.entries(clientOptions.headers)) {
73
+ const resolved = yield EndpointSupplier.get(value, { endpointMetadata: {} });
74
+ if (resolved != null) {
75
+ mergedHeaders[key.toLowerCase()] = `${resolved}`;
76
+ }
77
+ }
78
+ }
79
+ // Apply auth headers
80
+ if (clientOptions.getAuthHeaders != null) {
81
+ const authHeaders = yield clientOptions.getAuthHeaders();
82
+ for (const [key, value] of Object.entries(authHeaders)) {
83
+ mergedHeaders[key.toLowerCase()] = value;
84
+ }
85
+ }
86
+ // Apply user-provided headers from init
87
+ if ((effectiveInit === null || effectiveInit === void 0 ? void 0 : effectiveInit.headers) != null) {
88
+ const initHeaders = effectiveInit.headers instanceof Headers
89
+ ? Object.fromEntries(effectiveInit.headers.entries())
90
+ : Array.isArray(effectiveInit.headers)
91
+ ? Object.fromEntries(effectiveInit.headers)
92
+ : effectiveInit.headers;
93
+ for (const [key, value] of Object.entries(initHeaders)) {
94
+ if (value != null) {
95
+ mergedHeaders[key.toLowerCase()] = value;
96
+ }
97
+ }
98
+ }
99
+ // Apply per-request option headers (highest priority)
100
+ if ((requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.headers) != null) {
101
+ for (const [key, value] of Object.entries(requestOptions.headers)) {
102
+ mergedHeaders[key.toLowerCase()] = value;
103
+ }
104
+ }
105
+ const method = (_b = effectiveInit === null || effectiveInit === void 0 ? void 0 : effectiveInit.method) !== null && _b !== void 0 ? _b : "GET";
106
+ const body = effectiveInit === null || effectiveInit === void 0 ? void 0 : effectiveInit.body;
107
+ const timeoutInSeconds = (_c = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.timeoutInSeconds) !== null && _c !== void 0 ? _c : clientOptions.timeoutInSeconds;
108
+ const timeoutMs = timeoutInSeconds != null ? timeoutInSeconds * 1000 : undefined;
109
+ const maxRetries = (_d = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.maxRetries) !== null && _d !== void 0 ? _d : clientOptions.maxRetries;
110
+ const abortSignal = (_f = (_e = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.abortSignal) !== null && _e !== void 0 ? _e : effectiveInit === null || effectiveInit === void 0 ? void 0 : effectiveInit.signal) !== null && _f !== void 0 ? _f : undefined;
111
+ const fetchFn = (_g = clientOptions.fetch) !== null && _g !== void 0 ? _g : (yield getFetchFn());
112
+ if (logger.isDebug()) {
113
+ logger.debug("Making passthrough HTTP request", {
114
+ method,
115
+ url: fullUrl,
116
+ hasBody: body != null,
117
+ });
118
+ }
119
+ const response = yield requestWithRetries(() => __awaiter(this, void 0, void 0, function* () {
120
+ return makeRequest(fetchFn, fullUrl, method, mergedHeaders, body !== null && body !== void 0 ? body : undefined, timeoutMs, abortSignal, (effectiveInit === null || effectiveInit === void 0 ? void 0 : effectiveInit.credentials) === "include", undefined, // duplex
121
+ false);
122
+ }), maxRetries);
123
+ if (logger.isDebug()) {
124
+ logger.debug("Passthrough HTTP request completed", {
125
+ method,
126
+ url: fullUrl,
127
+ statusCode: response.status,
128
+ });
129
+ }
130
+ return response;
131
+ });
132
+ }
@@ -85,7 +85,7 @@ export declare class ReconnectingWebSocket {
85
85
  /**
86
86
  * The current state of the connection; this is one of the Ready state constants
87
87
  */
88
- get readyState(): number;
88
+ get readyState(): ReconnectingWebSocket.ReadyState;
89
89
  /**
90
90
  * The URL as resolved by the constructor
91
91
  */
@@ -148,3 +148,12 @@ export declare class ReconnectingWebSocket {
148
148
  private _addListeners;
149
149
  private _clearTimeouts;
150
150
  }
151
+ export declare namespace ReconnectingWebSocket {
152
+ const ReadyState: {
153
+ readonly CONNECTING: 0;
154
+ readonly OPEN: 1;
155
+ readonly CLOSING: 2;
156
+ readonly CLOSED: 3;
157
+ };
158
+ type ReadyState = (typeof ReadyState)[keyof typeof ReadyState];
159
+ }
@@ -3,13 +3,13 @@ import { RUNTIME } from "../runtime/index.mjs";
3
3
  import { toQueryString } from "../url/qs.mjs";
4
4
  import * as Events from "./events.mjs";
5
5
  const getGlobalWebSocket = () => {
6
- if (typeof WebSocket !== "undefined") {
6
+ if (RUNTIME.type === "node" || RUNTIME.type === "bun" || RUNTIME.type === "deno") {
7
+ return NodeWebSocket;
8
+ }
9
+ else if (typeof WebSocket !== "undefined") {
7
10
  // @ts-ignore
8
11
  return WebSocket;
9
12
  }
10
- else if (RUNTIME.type === "node") {
11
- return NodeWebSocket;
12
- }
13
13
  return undefined;
14
14
  };
15
15
  /**
@@ -72,6 +72,7 @@ export class ReconnectingWebSocket {
72
72
  this._clearTimeouts();
73
73
  if (this._ws) {
74
74
  this._removeListeners();
75
+ // Absorb async errors emitted by ws when closing during CONNECTING state
75
76
  this._ws.addEventListener("error", () => { });
76
77
  try {
77
78
  this._ws.close(1000, "aborted");
@@ -199,7 +200,9 @@ export class ReconnectingWebSocket {
199
200
  if (this._ws) {
200
201
  return this._ws.readyState;
201
202
  }
202
- return this._options.startClosed ? ReconnectingWebSocket.CLOSED : ReconnectingWebSocket.CONNECTING;
203
+ return this._options.startClosed
204
+ ? ReconnectingWebSocket.ReadyState.CLOSED
205
+ : ReconnectingWebSocket.ReadyState.CONNECTING;
203
206
  }
204
207
  /**
205
208
  * The URL as resolved by the constructor
@@ -383,6 +386,7 @@ export class ReconnectingWebSocket {
383
386
  return;
384
387
  }
385
388
  this._removeListeners();
389
+ // Absorb async errors emitted by ws when closing during CONNECTING state
386
390
  this._ws.addEventListener("error", () => { });
387
391
  try {
388
392
  this._ws.close(code, reason);
@@ -437,3 +441,11 @@ ReconnectingWebSocket.CONNECTING = 0;
437
441
  ReconnectingWebSocket.OPEN = 1;
438
442
  ReconnectingWebSocket.CLOSING = 2;
439
443
  ReconnectingWebSocket.CLOSED = 3;
444
+ (function (ReconnectingWebSocket) {
445
+ ReconnectingWebSocket.ReadyState = {
446
+ CONNECTING: 0,
447
+ OPEN: 1,
448
+ CLOSING: 2,
449
+ CLOSED: 3,
450
+ };
451
+ })(ReconnectingWebSocket || (ReconnectingWebSocket = {}));
@@ -1 +1 @@
1
- export declare const SDK_VERSION = "0.31.4";
1
+ export declare const SDK_VERSION = "0.31.8";
@@ -1 +1 @@
1
- export const SDK_VERSION = "0.31.4";
1
+ export const SDK_VERSION = "0.31.8";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "phonic",
3
- "version": "0.31.6",
3
+ "version": "0.31.8",
4
4
  "private": false,
5
5
  "repository": {
6
6
  "type": "git",
@@ -122,12 +122,12 @@
122
122
  "test:wire": "jest --selectProjects wire"
123
123
  },
124
124
  "dependencies": {
125
- "ws": "^8.16.0"
125
+ "ws": "^8.20.0"
126
126
  },
127
127
  "devDependencies": {
128
- "webpack": "^5.97.1",
129
- "ts-loader": "^9.5.1",
130
- "@types/ws": "^8.5.10",
128
+ "webpack": "^5.105.4",
129
+ "ts-loader": "^9.5.4",
130
+ "@types/ws": "^8.18.1",
131
131
  "jest": "^29.7.0",
132
132
  "@jest/globals": "^29.7.0",
133
133
  "@types/jest": "^29.5.14",
@@ -135,8 +135,8 @@
135
135
  "jest-environment-jsdom": "^29.7.0",
136
136
  "msw": "2.11.2",
137
137
  "@types/node": "^18.19.70",
138
- "typescript": "~5.7.2",
139
- "@biomejs/biome": "2.4.3"
138
+ "typescript": "~5.9.3",
139
+ "@biomejs/biome": "2.4.9"
140
140
  },
141
141
  "browser": {
142
142
  "fs": false,
package/reference.md CHANGED
@@ -1681,7 +1681,7 @@ await client.conversations.list();
1681
1681
  </dl>
1682
1682
  </details>
1683
1683
 
1684
- <details><summary><code>client.conversations.<a href="/src/api/resources/conversations/client/Client.ts">get</a>(id) -> Phonic.ConversationsGetResponse</code></summary>
1684
+ <details><summary><code>client.conversations.<a href="/src/api/resources/conversations/client/Client.ts">get</a>(id, { ...params }) -> Phonic.ConversationsGetResponse</code></summary>
1685
1685
  <dl>
1686
1686
  <dd>
1687
1687
 
@@ -1732,6 +1732,14 @@ await client.conversations.get("id");
1732
1732
  <dl>
1733
1733
  <dd>
1734
1734
 
1735
+ **request:** `Phonic.ConversationsGetRequest`
1736
+
1737
+ </dd>
1738
+ </dl>
1739
+
1740
+ <dl>
1741
+ <dd>
1742
+
1735
1743
  **requestOptions:** `ConversationsClient.RequestOptions`
1736
1744
 
1737
1745
  </dd>