phonic 0.13.3 → 0.15.0

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
@@ -65,7 +65,10 @@ if (error === null) {
65
65
  ### Get conversation by external id
66
66
 
67
67
  ```ts
68
- const { data, error } = await phonic.conversations.getByExternalId("CAdb9c032c809fec7feb932ea4c96d71e1");
68
+ const { data, error } = await phonic.conversations.getByExternalId({
69
+ project: "main",
70
+ externalId: "CAdb9c032c809fec7feb932ea4c96d71e1"
71
+ });
69
72
 
70
73
  if (error === null) {
71
74
  console.log(data.conversation);
@@ -76,6 +79,7 @@ if (error === null) {
76
79
 
77
80
  ```ts
78
81
  const { data, error } = await phonic.conversations.list({
82
+ project: "main",
79
83
  durationMin: 10, // sec
80
84
  durationMax: 20, // sec
81
85
  startedAtMin: "2025-04-17", // 00:00:00 UTC time is assumed
@@ -96,6 +100,7 @@ const { data, error } = await phonic.sts.websocket({
96
100
  input_format: "mulaw_8000",
97
101
 
98
102
  // Optional fields
103
+ project: "main",
99
104
  system_prompt: "You are a helpful assistant.",
100
105
  welcome_message: "Hello, how can I help you?",
101
106
  voice_id: "meredith",
package/dist/index.d.mts CHANGED
@@ -63,8 +63,12 @@ declare class Conversations {
63
63
  private readonly phonic;
64
64
  constructor(phonic: Phonic);
65
65
  get(id: string): DataOrError<ConversationSuccessResponse>;
66
- getByExternalId(externalId: string): DataOrError<ConversationSuccessResponse>;
67
- list({ durationMin, durationMax, startedAtMin, startedAtMax, }: {
66
+ getByExternalId({ project, externalId, }: {
67
+ project?: string;
68
+ externalId: string;
69
+ }): DataOrError<ConversationSuccessResponse>;
70
+ list({ project, durationMin, durationMax, startedAtMin, startedAtMax, }: {
71
+ project?: string;
68
72
  durationMin?: number;
69
73
  durationMax?: number;
70
74
  startedAtMin?: ISODate | ISODateTime$1;
@@ -73,6 +77,7 @@ declare class Conversations {
73
77
  }
74
78
 
75
79
  type PhonicSTSConfig = {
80
+ project: string;
76
81
  input_format: "pcm_44100" | "mulaw_8000";
77
82
  system_prompt?: string;
78
83
  welcome_message?: string;
package/dist/index.d.ts CHANGED
@@ -63,8 +63,12 @@ declare class Conversations {
63
63
  private readonly phonic;
64
64
  constructor(phonic: Phonic);
65
65
  get(id: string): DataOrError<ConversationSuccessResponse>;
66
- getByExternalId(externalId: string): DataOrError<ConversationSuccessResponse>;
67
- list({ durationMin, durationMax, startedAtMin, startedAtMax, }: {
66
+ getByExternalId({ project, externalId, }: {
67
+ project?: string;
68
+ externalId: string;
69
+ }): DataOrError<ConversationSuccessResponse>;
70
+ list({ project, durationMin, durationMax, startedAtMin, startedAtMax, }: {
71
+ project?: string;
68
72
  durationMin?: number;
69
73
  durationMax?: number;
70
74
  startedAtMin?: ISODate | ISODateTime$1;
@@ -73,6 +77,7 @@ declare class Conversations {
73
77
  }
74
78
 
75
79
  type PhonicSTSConfig = {
80
+ project: string;
76
81
  input_format: "pcm_44100" | "mulaw_8000";
77
82
  system_prompt?: string;
78
83
  welcome_message?: string;
package/dist/index.js CHANGED
@@ -35,7 +35,7 @@ __export(index_exports, {
35
35
  module.exports = __toCommonJS(index_exports);
36
36
 
37
37
  // package.json
38
- var version = "0.13.3";
38
+ var version = "0.15.0";
39
39
 
40
40
  // src/conversations/index.ts
41
41
  var Conversations = class {
@@ -48,8 +48,12 @@ var Conversations = class {
48
48
  );
49
49
  return response;
50
50
  }
51
- async getByExternalId(externalId) {
51
+ async getByExternalId({
52
+ project,
53
+ externalId
54
+ }) {
52
55
  const queryString = new URLSearchParams({
56
+ ...project !== void 0 && { project },
53
57
  external_id: externalId
54
58
  }).toString();
55
59
  const response = await this.phonic.get(
@@ -58,12 +62,14 @@ var Conversations = class {
58
62
  return response;
59
63
  }
60
64
  async list({
65
+ project,
61
66
  durationMin,
62
67
  durationMax,
63
68
  startedAtMin,
64
69
  startedAtMax
65
70
  }) {
66
71
  const queryString = new URLSearchParams({
72
+ ...project !== void 0 && { project },
67
73
  ...durationMin !== void 0 && { duration_min: String(durationMin) },
68
74
  ...durationMax !== void 0 && { duration_max: String(durationMax) },
69
75
  ...startedAtMin !== void 0 && { started_at_min: startedAtMin },
@@ -304,18 +310,27 @@ var Phonic = class {
304
310
  headers: this.headers,
305
311
  ...options
306
312
  });
307
- if (!response.ok) {
308
- const statusText = await response.text();
309
- console.error(response);
313
+ if (response.ok) {
314
+ const data = await response.json();
315
+ return { data, error: null };
316
+ }
317
+ try {
318
+ const data = await response.json();
319
+ const errorMessage = data.error.message || response.statusText;
320
+ return {
321
+ data: null,
322
+ error: {
323
+ message: errorMessage
324
+ }
325
+ };
326
+ } catch (error) {
310
327
  return {
311
328
  data: null,
312
329
  error: {
313
- message: statusText
330
+ message: response.statusText
314
331
  }
315
332
  };
316
333
  }
317
- const data = await response.json();
318
- return { data, error: null };
319
334
  } catch (error) {
320
335
  console.error(error);
321
336
  return {
package/dist/index.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  // package.json
2
- var version = "0.13.3";
2
+ var version = "0.15.0";
3
3
 
4
4
  // src/conversations/index.ts
5
5
  var Conversations = class {
@@ -12,8 +12,12 @@ var Conversations = class {
12
12
  );
13
13
  return response;
14
14
  }
15
- async getByExternalId(externalId) {
15
+ async getByExternalId({
16
+ project,
17
+ externalId
18
+ }) {
16
19
  const queryString = new URLSearchParams({
20
+ ...project !== void 0 && { project },
17
21
  external_id: externalId
18
22
  }).toString();
19
23
  const response = await this.phonic.get(
@@ -22,12 +26,14 @@ var Conversations = class {
22
26
  return response;
23
27
  }
24
28
  async list({
29
+ project,
25
30
  durationMin,
26
31
  durationMax,
27
32
  startedAtMin,
28
33
  startedAtMax
29
34
  }) {
30
35
  const queryString = new URLSearchParams({
36
+ ...project !== void 0 && { project },
31
37
  ...durationMin !== void 0 && { duration_min: String(durationMin) },
32
38
  ...durationMax !== void 0 && { duration_max: String(durationMax) },
33
39
  ...startedAtMin !== void 0 && { started_at_min: startedAtMin },
@@ -268,18 +274,27 @@ var Phonic = class {
268
274
  headers: this.headers,
269
275
  ...options
270
276
  });
271
- if (!response.ok) {
272
- const statusText = await response.text();
273
- console.error(response);
277
+ if (response.ok) {
278
+ const data = await response.json();
279
+ return { data, error: null };
280
+ }
281
+ try {
282
+ const data = await response.json();
283
+ const errorMessage = data.error.message || response.statusText;
284
+ return {
285
+ data: null,
286
+ error: {
287
+ message: errorMessage
288
+ }
289
+ };
290
+ } catch (error) {
274
291
  return {
275
292
  data: null,
276
293
  error: {
277
- message: statusText
294
+ message: response.statusText
278
295
  }
279
296
  };
280
297
  }
281
- const data = await response.json();
282
- return { data, error: null };
283
298
  } catch (error) {
284
299
  console.error(error);
285
300
  return {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "phonic",
3
- "version": "0.13.3",
3
+ "version": "0.15.0",
4
4
  "description": "Phonic Node.js SDK",
5
5
  "scripts": {
6
6
  "build": "tsup",
@@ -39,9 +39,9 @@
39
39
  "@biomejs/biome": "1.9.4",
40
40
  "@changesets/changelog-github": "0.5.1",
41
41
  "@changesets/cli": "2.28.1",
42
- "@types/bun": "1.2.5",
42
+ "@types/bun": "1.2.8",
43
43
  "tsup": "8.4.0",
44
- "typescript": "5.8.2",
44
+ "typescript": "5.8.3",
45
45
  "zod": "3.24.2"
46
46
  },
47
47
  "files": ["dist/**"],