@zavudev/sdk 0.51.0 → 0.53.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.
Files changed (100) hide show
  1. package/CHANGELOG.md +29 -0
  2. package/package.json +1 -1
  3. package/resources/functions/functions.d.mts +28 -8
  4. package/resources/functions/functions.d.mts.map +1 -1
  5. package/resources/functions/functions.d.ts +28 -8
  6. package/resources/functions/functions.d.ts.map +1 -1
  7. package/resources/functions/functions.js +6 -4
  8. package/resources/functions/functions.js.map +1 -1
  9. package/resources/functions/functions.mjs +6 -4
  10. package/resources/functions/functions.mjs.map +1 -1
  11. package/resources/invitations.d.mts +85 -15
  12. package/resources/invitations.d.mts.map +1 -1
  13. package/resources/invitations.d.ts +85 -15
  14. package/resources/invitations.d.ts.map +1 -1
  15. package/resources/invitations.js +14 -4
  16. package/resources/invitations.js.map +1 -1
  17. package/resources/invitations.mjs +14 -4
  18. package/resources/invitations.mjs.map +1 -1
  19. package/resources/messages.d.mts +41 -4
  20. package/resources/messages.d.mts.map +1 -1
  21. package/resources/messages.d.ts +41 -4
  22. package/resources/messages.d.ts.map +1 -1
  23. package/resources/messages.js +12 -3
  24. package/resources/messages.js.map +1 -1
  25. package/resources/messages.mjs +12 -3
  26. package/resources/messages.mjs.map +1 -1
  27. package/resources/number-10dlc/brands.d.mts +5 -1
  28. package/resources/number-10dlc/brands.d.mts.map +1 -1
  29. package/resources/number-10dlc/brands.d.ts +5 -1
  30. package/resources/number-10dlc/brands.d.ts.map +1 -1
  31. package/resources/number-10dlc/brands.js +5 -1
  32. package/resources/number-10dlc/brands.js.map +1 -1
  33. package/resources/number-10dlc/brands.mjs +5 -1
  34. package/resources/number-10dlc/brands.mjs.map +1 -1
  35. package/resources/number-10dlc/campaigns/campaigns.d.mts +6 -1
  36. package/resources/number-10dlc/campaigns/campaigns.d.mts.map +1 -1
  37. package/resources/number-10dlc/campaigns/campaigns.d.ts +6 -1
  38. package/resources/number-10dlc/campaigns/campaigns.d.ts.map +1 -1
  39. package/resources/number-10dlc/campaigns/campaigns.js +6 -1
  40. package/resources/number-10dlc/campaigns/campaigns.js.map +1 -1
  41. package/resources/number-10dlc/campaigns/campaigns.mjs +6 -1
  42. package/resources/number-10dlc/campaigns/campaigns.mjs.map +1 -1
  43. package/resources/phone-numbers.d.mts +10 -3
  44. package/resources/phone-numbers.d.mts.map +1 -1
  45. package/resources/phone-numbers.d.ts +10 -3
  46. package/resources/phone-numbers.d.ts.map +1 -1
  47. package/resources/phone-numbers.js +3 -2
  48. package/resources/phone-numbers.js.map +1 -1
  49. package/resources/phone-numbers.mjs +3 -2
  50. package/resources/phone-numbers.mjs.map +1 -1
  51. package/resources/senders/agent/agent.d.mts +314 -0
  52. package/resources/senders/agent/agent.d.mts.map +1 -1
  53. package/resources/senders/agent/agent.d.ts +314 -0
  54. package/resources/senders/agent/agent.d.ts.map +1 -1
  55. package/resources/senders/agent/agent.js +6 -0
  56. package/resources/senders/agent/agent.js.map +1 -1
  57. package/resources/senders/agent/agent.mjs +6 -0
  58. package/resources/senders/agent/agent.mjs.map +1 -1
  59. package/resources/senders/agent/executions.d.mts +5 -0
  60. package/resources/senders/agent/executions.d.mts.map +1 -1
  61. package/resources/senders/agent/executions.d.ts +5 -0
  62. package/resources/senders/agent/executions.d.ts.map +1 -1
  63. package/resources/senders/agent/executions.js +5 -0
  64. package/resources/senders/agent/executions.js.map +1 -1
  65. package/resources/senders/agent/executions.mjs +5 -0
  66. package/resources/senders/agent/executions.mjs.map +1 -1
  67. package/resources/senders/agent/tools.d.mts +51 -2
  68. package/resources/senders/agent/tools.d.mts.map +1 -1
  69. package/resources/senders/agent/tools.d.ts +51 -2
  70. package/resources/senders/agent/tools.d.ts.map +1 -1
  71. package/resources/senders/agent/tools.js +10 -1
  72. package/resources/senders/agent/tools.js.map +1 -1
  73. package/resources/senders/agent/tools.mjs +10 -1
  74. package/resources/senders/agent/tools.mjs.map +1 -1
  75. package/resources/senders/senders.d.mts +64 -4
  76. package/resources/senders/senders.d.mts.map +1 -1
  77. package/resources/senders/senders.d.ts +64 -4
  78. package/resources/senders/senders.d.ts.map +1 -1
  79. package/resources/senders/senders.js.map +1 -1
  80. package/resources/senders/senders.mjs.map +1 -1
  81. package/resources/templates.d.mts +12 -3
  82. package/resources/templates.d.mts.map +1 -1
  83. package/resources/templates.d.ts +12 -3
  84. package/resources/templates.d.ts.map +1 -1
  85. package/src/resources/functions/functions.ts +29 -8
  86. package/src/resources/invitations.ts +91 -15
  87. package/src/resources/messages.ts +42 -3
  88. package/src/resources/number-10dlc/brands.ts +5 -1
  89. package/src/resources/number-10dlc/campaigns/campaigns.ts +6 -1
  90. package/src/resources/phone-numbers.ts +11 -3
  91. package/src/resources/senders/agent/agent.ts +365 -0
  92. package/src/resources/senders/agent/executions.ts +5 -0
  93. package/src/resources/senders/agent/tools.ts +58 -2
  94. package/src/resources/senders/senders.ts +73 -3
  95. package/src/resources/templates.ts +13 -4
  96. package/src/version.ts +1 -1
  97. package/version.d.mts +1 -1
  98. package/version.d.ts +1 -1
  99. package/version.js +1 -1
  100. package/version.mjs +1 -1
@@ -33,7 +33,7 @@ export class Functions extends APIResource {
33
33
  * description:
34
34
  * 'Replies to order status questions on WhatsApp.',
35
35
  * sourceCode:
36
- * "import { defineFunction } from '@zavu/functions';\n\nexport default defineFunction(async (event, ctx) => {\n ctx.log('received', event.type);\n});\n",
36
+ * "import { defineFunction } from '@zavudev/functions';\n\nexport default defineFunction(async (event, ctx) => {\n ctx.log('received', event.type);\n});\n",
37
37
  * });
38
38
  * ```
39
39
  */
@@ -56,9 +56,11 @@ export class Functions extends APIResource {
56
56
  }
57
57
 
58
58
  /**
59
- * Update the draft source code and/or dependency map without triggering a build.
60
- * Visible in the dashboard immediately, but the live (deployed) function does not
61
- * change until `POST /v1/functions/{functionId}/deploy` runs.
59
+ * Update an existing function. `sourceCode` / `dependencies` edit the draft
60
+ * without triggering a build — they go live on the next
61
+ * `POST /v1/functions/{functionId}/deploy`. `httpEnabled` is applied to the
62
+ * deployed function immediately, so turning the public endpoint on or off does not
63
+ * require a redeploy.
62
64
  *
63
65
  * @example
64
66
  * ```ts
@@ -213,7 +215,9 @@ export namespace FunctionCreateResponse {
213
215
  description?: string | null;
214
216
 
215
217
  /**
216
- * HTTPS endpoint when httpEnabled is true.
218
+ * HTTPS endpoint, present only while httpEnabled is true. Null otherwise,
219
+ * including for a function that was previously exposed — the stored URL stops
220
+ * serving the moment HTTP is turned off, so it is never returned.
217
221
  */
218
222
  publicUrl?: string | null;
219
223
  }
@@ -285,7 +289,9 @@ export namespace FunctionRetrieveResponse {
285
289
  description?: string | null;
286
290
 
287
291
  /**
288
- * HTTPS endpoint when httpEnabled is true.
292
+ * HTTPS endpoint, present only while httpEnabled is true. Null otherwise,
293
+ * including for a function that was previously exposed — the stored URL stops
294
+ * serving the moment HTTP is turned off, so it is never returned.
289
295
  */
290
296
  publicUrl?: string | null;
291
297
  }
@@ -357,7 +363,9 @@ export namespace FunctionUpdateResponse {
357
363
  description?: string | null;
358
364
 
359
365
  /**
360
- * HTTPS endpoint when httpEnabled is true.
366
+ * HTTPS endpoint, present only while httpEnabled is true. Null otherwise,
367
+ * including for a function that was previously exposed — the stored URL stops
368
+ * serving the moment HTTP is turned off, so it is never returned.
361
369
  */
362
370
  publicUrl?: string | null;
363
371
  }
@@ -490,6 +498,12 @@ export interface FunctionCreateParams {
490
498
  */
491
499
  sourceCode?: string;
492
500
 
501
+ /**
502
+ * Per-invocation timeout in seconds. Event and cron invocations are asynchronous,
503
+ * so a long timeout only bounds cost; a tool called during a live conversation
504
+ * holds up the reply, and a function exposed over HTTP is additionally bounded by
505
+ * the platform's HTTP response limit.
506
+ */
493
507
  timeoutSec?: number;
494
508
  }
495
509
 
@@ -500,7 +514,14 @@ export interface FunctionUpdateParams {
500
514
  dependencies?: { [key: string]: string };
501
515
 
502
516
  /**
503
- * New source code to publish (replaces the draft).
517
+ * Expose the function on its public HTTPS URL, or take it down. Applies to the
518
+ * already-deployed function without redeploying; the URL is returned as
519
+ * `publicUrl`.
520
+ */
521
+ httpEnabled?: boolean;
522
+
523
+ /**
524
+ * New source code for the draft (replaces it).
504
525
  */
505
526
  sourceCode?: string;
506
527
  }
@@ -8,12 +8,22 @@ import { path } from '../internal/utils/path';
8
8
 
9
9
  export class Invitations extends APIResource {
10
10
  /**
11
- * Create a partner invitation link for a client to connect WhatsApp. The client
12
- * opens the returned `url` and completes Meta's embedded signup, linking an
13
- * official WhatsApp Business Account. The resulting sender is created in your
14
- * project when the client completes the flow, and the invitation transitions to
11
+ * Create a partner invitation link for a client to connect a Meta channel. The
12
+ * client opens the returned `url` and authorizes with Meta; the resulting sender
13
+ * is created in your project when they finish, and the invitation transitions to
15
14
  * `completed`.
16
15
  *
16
+ * `connectionType` picks the channel:
17
+ *
18
+ * - `whatsapp_waba` (default): Meta's embedded signup links an official WhatsApp
19
+ * Business Account.
20
+ * - `messenger`: the client picks a Facebook Page they administer; its Messenger
21
+ * inbox (including Marketplace chats) is routed to Zavu.
22
+ *
23
+ * One invitation connects one channel — create one per channel to onboard a client
24
+ * on several. `phoneNumberId` and `allowedPhoneCountries` apply to `whatsapp_waba`
25
+ * only.
26
+ *
17
27
  * @example
18
28
  * ```ts
19
29
  * const invitation = await client.invitations.create({
@@ -92,8 +102,13 @@ export interface Invitation {
92
102
 
93
103
  /**
94
104
  * Current status of the partner invitation.
105
+ *
106
+ * `failed` means the client started the connection and it did not finish (they
107
+ * cancelled Meta's dialog, denied a permission, or abandoned the tab). A failed
108
+ * invitation is still usable: the same link can be retried, and it moves back to
109
+ * `in_progress` when the client tries again.
95
110
  */
96
- status: 'pending' | 'in_progress' | 'completed' | 'expired' | 'cancelled';
111
+ status: 'pending' | 'in_progress' | 'completed' | 'expired' | 'cancelled' | 'failed';
97
112
 
98
113
  updatedAt: string;
99
114
 
@@ -111,13 +126,33 @@ export interface Invitation {
111
126
  completedAt?: string | null;
112
127
 
113
128
  /**
114
- * How the client connects WhatsApp: `whatsapp_waba` (official Cloud API via
115
- * embedded signup).
129
+ * The account the client linked, populated once the invitation is `completed`.
130
+ * Null before that. Use it to show the partner what was connected without fetching
131
+ * the sender.
132
+ */
133
+ connectedAccount?: Invitation.ConnectedAccount | null;
134
+
135
+ /**
136
+ * Which Meta channel the client connects: `whatsapp_waba` (official WhatsApp Cloud
137
+ * API via embedded signup) or `messenger` (a Facebook Page's Messenger inbox,
138
+ * including Marketplace chats).
116
139
  */
117
- connectionType?: 'whatsapp_waba';
140
+ connectionType?: 'whatsapp_waba' | 'messenger';
141
+
142
+ failedAt?: string | null;
118
143
 
119
144
  /**
120
- * ID of a pre-assigned Zavu phone number for WhatsApp registration.
145
+ * Stable code for why the last attempt failed, present when `status` is `failed`.
146
+ * Values include `fb_cancelled` (client closed Meta's dialog), `fb_not_authorized`
147
+ * (permission denied), `signup_abandoned` (started but never finished),
148
+ * `meta_no_pages` (the client administers no Facebook Page), and `internal_error`.
149
+ * Treat unknown codes as a generic failure.
150
+ */
151
+ failureReason?: string | null;
152
+
153
+ /**
154
+ * ID of a pre-assigned Zavu phone number for WhatsApp registration. Always null
155
+ * for `messenger` invitations.
121
156
  */
122
157
  phoneNumberId?: string | null;
123
158
 
@@ -131,6 +166,28 @@ export interface Invitation {
131
166
  viewedAt?: string | null;
132
167
  }
133
168
 
169
+ export namespace Invitation {
170
+ /**
171
+ * The account the client linked, populated once the invitation is `completed`.
172
+ * Null before that. Use it to show the partner what was connected without fetching
173
+ * the sender.
174
+ */
175
+ export interface ConnectedAccount {
176
+ /**
177
+ * Provider-side identifier: the WhatsApp phone number ID, or the Facebook Page ID.
178
+ */
179
+ id: string;
180
+
181
+ channel: 'whatsapp' | 'messenger';
182
+
183
+ /**
184
+ * Display name of the connected account: the WhatsApp verified name, or the
185
+ * Facebook Page name.
186
+ */
187
+ name?: string | null;
188
+ }
189
+ }
190
+
134
191
  export interface InvitationCreateResponse {
135
192
  invitation: Invitation;
136
193
  }
@@ -145,7 +202,8 @@ export interface InvitationCancelResponse {
145
202
 
146
203
  export interface InvitationCreateParams {
147
204
  /**
148
- * ISO country codes for allowed phone numbers.
205
+ * ISO country codes for allowed phone numbers. Only valid when `connectionType` is
206
+ * `whatsapp_waba` — sending it with `messenger` returns 400.
149
207
  */
150
208
  allowedPhoneCountries?: Array<string>;
151
209
 
@@ -165,10 +223,21 @@ export interface InvitationCreateParams {
165
223
  clientPhone?: string;
166
224
 
167
225
  /**
168
- * How the client connects WhatsApp. `whatsapp_waba` (default) runs Meta's embedded
169
- * signup to link an official WhatsApp Business Account.
226
+ * Which Meta channel the client connects, and how.
227
+ *
228
+ * - `whatsapp_waba` (default): Meta's embedded signup links an official WhatsApp
229
+ * Business Account. Accepts `phoneNumberId` and `allowedPhoneCountries`.
230
+ * - `messenger`: the client authorizes with Facebook and picks a Facebook Page
231
+ * they administer. The Page's Messenger inbox — including Marketplace chats — is
232
+ * routed to Zavu. They must be an admin of at least one Page. A Page can only be
233
+ * connected to one Zavu project at a time: if the client picks a Page that
234
+ * another project already connected, the newer connection wins and the older one
235
+ * is disconnected.
236
+ *
237
+ * One invitation connects one channel. To onboard a client on several channels,
238
+ * create one invitation per channel; each completes into its own sender.
170
239
  */
171
- connectionType?: 'whatsapp_waba';
240
+ connectionType?: 'whatsapp_waba' | 'messenger';
172
241
 
173
242
  /**
174
243
  * Number of days until the invitation expires.
@@ -177,7 +246,9 @@ export interface InvitationCreateParams {
177
246
 
178
247
  /**
179
248
  * ID of a Zavu phone number to pre-assign for WhatsApp registration. If provided,
180
- * the client will use this number instead of their own.
249
+ * the client will use this number instead of their own. Only valid when
250
+ * `connectionType` is `whatsapp_waba` — sending it with `messenger` returns 400,
251
+ * since a Facebook Page has no phone number.
181
252
  */
182
253
  phoneNumberId?: string;
183
254
  }
@@ -185,8 +256,13 @@ export interface InvitationCreateParams {
185
256
  export interface InvitationListParams extends CursorParams {
186
257
  /**
187
258
  * Current status of the partner invitation.
259
+ *
260
+ * `failed` means the client started the connection and it did not finish (they
261
+ * cancelled Meta's dialog, denied a permission, or abandoned the tab). A failed
262
+ * invitation is still usable: the same link can be retried, and it moves back to
263
+ * `in_progress` when the client tries again.
188
264
  */
189
- status?: 'pending' | 'in_progress' | 'completed' | 'expired' | 'cancelled';
265
+ status?: 'pending' | 'in_progress' | 'completed' | 'expired' | 'cancelled' | 'failed';
190
266
  }
191
267
 
192
268
  export declare namespace Invitations {
@@ -82,10 +82,19 @@ export class Messages extends APIResource {
82
82
  * - Window opens when the user messages you first
83
83
  * - Use template messages to initiate conversations outside the window
84
84
  *
85
- * **Daily limits:**
85
+ * **Plan allowances and email billing:**
86
86
  *
87
- * - Unverified accounts: 200 messages per channel per day
88
- * - Complete KYC verification to increase limits to 10,000/day
87
+ * - WhatsApp, Telegram, Instagram and Messenger share an allowance of 2,000
88
+ * messages per month on Free. Over it, sends return 429 with code
89
+ * `a2p_limit_exceeded` and upgrade details; the counter resets on the 1st of
90
+ * each month. Paid plans have no message caps
91
+ * - Email is billed from your prepaid balance in 1,000-message blocks: $0.40 per
92
+ * 1,000 transactional emails, $0.80 per 1,000 marketing (broadcast) emails. A
93
+ * block is charged when your monthly count crosses each 1,000 boundary, and at
94
+ * zero balance email sends return 402 with code `insufficient_balance`. Free
95
+ * teams start with $2 of credit and additionally cap at 3,000 emails/month and
96
+ * 100/day. Teams on earlier plans keep their original email quotas instead
97
+ * - SMS and voice are billed per message from your balance on every plan
89
98
  *
90
99
  * **Email recipient pre-flight:** Email messages are validated automatically
91
100
  * before dispatch. Sends that would be a guaranteed hard bounce are failed instead
@@ -177,6 +186,20 @@ export interface Message {
177
186
  /**
178
187
  * Type of message. Non-text types are supported by WhatsApp and Telegram (varies
179
188
  * by type).
189
+ *
190
+ * `location_request` asks the recipient to share their location and is
191
+ * WhatsApp-only. It takes no `content` object — the prompt goes in `text` (max
192
+ * 1024 characters) and the button label is fixed by WhatsApp. The recipient's
193
+ * answer arrives as an inbound `location` message whose `content.replyToMessageId`
194
+ * is the ID of the request.
195
+ *
196
+ * `request_contact_info` asks the recipient to share their phone number and is
197
+ * WhatsApp-only. Like `location_request` it takes no `content` object — the prompt
198
+ * goes in `text` (max 1024 characters) and WhatsApp renders a fixed **Share
199
+ * Contact Info** button. The answer arrives as an inbound `contact` message. Use
200
+ * it to recover the phone number of a contact who adopted a WhatsApp username and
201
+ * is only known by their business-scoped user ID (BSUID); when they share it, Zavu
202
+ * automatically links the phone number to that contact.
180
203
  */
181
204
  messageType: MessageType;
182
205
 
@@ -461,6 +484,20 @@ export type MessageStatus =
461
484
  /**
462
485
  * Type of message. Non-text types are supported by WhatsApp and Telegram (varies
463
486
  * by type).
487
+ *
488
+ * `location_request` asks the recipient to share their location and is
489
+ * WhatsApp-only. It takes no `content` object — the prompt goes in `text` (max
490
+ * 1024 characters) and the button label is fixed by WhatsApp. The recipient's
491
+ * answer arrives as an inbound `location` message whose `content.replyToMessageId`
492
+ * is the ID of the request.
493
+ *
494
+ * `request_contact_info` asks the recipient to share their phone number and is
495
+ * WhatsApp-only. Like `location_request` it takes no `content` object — the prompt
496
+ * goes in `text` (max 1024 characters) and WhatsApp renders a fixed **Share
497
+ * Contact Info** button. The answer arrives as an inbound `contact` message. Use
498
+ * it to recover the phone number of a contact who adopted a WhatsApp username and
499
+ * is only known by their business-scoped user ID (BSUID); when they share it, Zavu
500
+ * automatically links the phone number to that contact.
464
501
  */
465
502
  export type MessageType =
466
503
  | 'text'
@@ -474,6 +511,8 @@ export type MessageType =
474
511
  | 'buttons'
475
512
  | 'list'
476
513
  | 'cta_url'
514
+ | 'request_contact_info'
515
+ | 'location_request'
477
516
  | 'reaction'
478
517
  | 'template';
479
518
 
@@ -115,7 +115,11 @@ export class Brands extends APIResource {
115
115
 
116
116
  /**
117
117
  * Submit a draft brand to The Campaign Registry (TCR) for vetting. The brand must
118
- * be in draft status. A $35 registration fee is charged from your balance.
118
+ * be in draft status. TCR's one-time $4 brand registration fee is charged from
119
+ * your balance at submission (passed through at cost) and refunded if the carrier
120
+ * rejects the registration. A team that already paid this fee through the
121
+ * compliance flow is not charged again. Campaign registration is billed separately
122
+ * when a campaign is submitted.
119
123
  *
120
124
  * @example
121
125
  * ```ts
@@ -117,7 +117,12 @@ export class Campaigns extends APIResource {
117
117
 
118
118
  /**
119
119
  * Submit a draft campaign for carrier review. The campaign must be in draft status
120
- * and its brand must be verified.
120
+ * and its brand must be verified. TCR's one-time registration fee is charged from
121
+ * your balance at submission ($15 for standard use cases, $2 for LOW_VOLUME),
122
+ * passed through at cost and refunded if the carrier rejects it. Once approved,
123
+ * the campaign's monthly TCR fee ($10 standard, $2 LOW_VOLUME) is charged from
124
+ * your balance while the campaign is active — see registrationCostCents and
125
+ * monthlyFeeCents on the campaign object.
121
126
  *
122
127
  * @example
123
128
  * ```ts
@@ -60,8 +60,9 @@ export class PhoneNumbers extends APIResource {
60
60
  }
61
61
 
62
62
  /**
63
- * Purchase an available phone number. The first US phone number is free for each
64
- * team.
63
+ * Purchase an available phone number. Requires a paid plan: the Free plan cannot
64
+ * purchase phone numbers and receives `402` with code `paid_plan_required`. Paid
65
+ * plans include the first US number at no charge.
65
66
  *
66
67
  * @example
67
68
  * ```ts
@@ -206,7 +207,8 @@ export interface PhoneNumberCapabilities {
206
207
 
207
208
  export interface PhoneNumberPricing {
208
209
  /**
209
- * Whether this number qualifies for the free first US number offer.
210
+ * Whether this number qualifies as the plan-included first US number on paid
211
+ * plans.
210
212
  */
211
213
  isFreeEligible?: boolean;
212
214
 
@@ -350,6 +352,12 @@ export interface PhoneNumberSearchAvailableParams {
350
352
  */
351
353
  countryCode: string;
352
354
 
355
+ /**
356
+ * Comma-separated capabilities the number must have: `sms`, `voice`, `mms`.
357
+ * Numbers missing any of them are dropped.
358
+ */
359
+ capabilities?: string;
360
+
353
361
  /**
354
362
  * Search for numbers containing this string.
355
363
  */