@pilot-status/sdk 0.4.0 → 0.8.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 (124) hide show
  1. package/CHANGELOG.md +51 -0
  2. package/README.md +203 -17
  3. package/dist/client.d.ts +53 -2
  4. package/dist/client.d.ts.map +1 -1
  5. package/dist/client.js +54 -4
  6. package/dist/client.js.map +1 -1
  7. package/dist/errors.d.ts +58 -0
  8. package/dist/errors.d.ts.map +1 -1
  9. package/dist/errors.js +65 -0
  10. package/dist/errors.js.map +1 -1
  11. package/dist/http.d.ts +7 -1
  12. package/dist/http.d.ts.map +1 -1
  13. package/dist/http.js +3 -0
  14. package/dist/http.js.map +1 -1
  15. package/dist/index.d.ts +12 -5
  16. package/dist/index.d.ts.map +1 -1
  17. package/dist/index.js +10 -3
  18. package/dist/index.js.map +1 -1
  19. package/dist/internal.d.ts +19 -0
  20. package/dist/internal.d.ts.map +1 -0
  21. package/dist/internal.js +27 -0
  22. package/dist/internal.js.map +1 -0
  23. package/dist/resources/api-keys.d.ts +20 -7
  24. package/dist/resources/api-keys.d.ts.map +1 -1
  25. package/dist/resources/api-keys.js +18 -5
  26. package/dist/resources/api-keys.js.map +1 -1
  27. package/dist/resources/billing.d.ts +18 -0
  28. package/dist/resources/billing.d.ts.map +1 -0
  29. package/dist/resources/billing.js +30 -0
  30. package/dist/resources/billing.js.map +1 -0
  31. package/dist/resources/branding.d.ts +18 -0
  32. package/dist/resources/branding.d.ts.map +1 -0
  33. package/dist/resources/branding.js +29 -0
  34. package/dist/resources/branding.js.map +1 -0
  35. package/dist/resources/chatwoot.d.ts +57 -0
  36. package/dist/resources/chatwoot.d.ts.map +1 -0
  37. package/dist/resources/chatwoot.js +117 -0
  38. package/dist/resources/chatwoot.js.map +1 -0
  39. package/dist/resources/conversations.d.ts +16 -0
  40. package/dist/resources/conversations.d.ts.map +1 -0
  41. package/dist/resources/conversations.js +28 -0
  42. package/dist/resources/conversations.js.map +1 -0
  43. package/dist/resources/embed.d.ts +24 -0
  44. package/dist/resources/embed.d.ts.map +1 -0
  45. package/dist/resources/embed.js +37 -0
  46. package/dist/resources/embed.js.map +1 -0
  47. package/dist/resources/flows.d.ts +203 -0
  48. package/dist/resources/flows.d.ts.map +1 -0
  49. package/dist/resources/flows.js +289 -0
  50. package/dist/resources/flows.js.map +1 -0
  51. package/dist/resources/groups.d.ts +37 -1
  52. package/dist/resources/groups.d.ts.map +1 -1
  53. package/dist/resources/groups.js +91 -0
  54. package/dist/resources/groups.js.map +1 -1
  55. package/dist/resources/messages.d.ts +61 -1
  56. package/dist/resources/messages.d.ts.map +1 -1
  57. package/dist/resources/messages.js +134 -1
  58. package/dist/resources/messages.js.map +1 -1
  59. package/dist/resources/meta.d.ts +19 -0
  60. package/dist/resources/meta.d.ts.map +1 -0
  61. package/dist/resources/meta.js +31 -0
  62. package/dist/resources/meta.js.map +1 -0
  63. package/dist/resources/numbers.d.ts +102 -1
  64. package/dist/resources/numbers.d.ts.map +1 -1
  65. package/dist/resources/numbers.js +152 -0
  66. package/dist/resources/numbers.js.map +1 -1
  67. package/dist/resources/service-window.d.ts +20 -0
  68. package/dist/resources/service-window.d.ts.map +1 -0
  69. package/dist/resources/service-window.js +26 -0
  70. package/dist/resources/service-window.js.map +1 -0
  71. package/dist/resources/subscription.d.ts +43 -0
  72. package/dist/resources/subscription.d.ts.map +1 -0
  73. package/dist/resources/subscription.js +60 -0
  74. package/dist/resources/subscription.js.map +1 -0
  75. package/dist/resources/templates.d.ts +31 -1
  76. package/dist/resources/templates.d.ts.map +1 -1
  77. package/dist/resources/templates.js +56 -0
  78. package/dist/resources/templates.js.map +1 -1
  79. package/dist/resources/webhooks.d.ts +53 -0
  80. package/dist/resources/webhooks.d.ts.map +1 -0
  81. package/dist/resources/webhooks.js +97 -0
  82. package/dist/resources/webhooks.js.map +1 -0
  83. package/dist/resources/workspace.d.ts +57 -0
  84. package/dist/resources/workspace.d.ts.map +1 -0
  85. package/dist/resources/workspace.js +73 -0
  86. package/dist/resources/workspace.js.map +1 -0
  87. package/dist/types.d.ts +957 -21
  88. package/dist/types.d.ts.map +1 -1
  89. package/dist/types.js.map +1 -1
  90. package/dist/webhooks/parse.d.ts +16 -0
  91. package/dist/webhooks/parse.d.ts.map +1 -1
  92. package/dist/webhooks/parse.js +49 -0
  93. package/dist/webhooks/parse.js.map +1 -1
  94. package/dist/webhooks/signature.d.ts +42 -0
  95. package/dist/webhooks/signature.d.ts.map +1 -0
  96. package/dist/webhooks/signature.js +40 -0
  97. package/dist/webhooks/signature.js.map +1 -0
  98. package/dist/webhooks/types.d.ts +59 -1
  99. package/dist/webhooks/types.d.ts.map +1 -1
  100. package/package.json +5 -3
  101. package/dist/messages.test.d.ts +0 -2
  102. package/dist/messages.test.d.ts.map +0 -1
  103. package/dist/messages.test.js +0 -107
  104. package/dist/messages.test.js.map +0 -1
  105. package/dist/numbers.test.d.ts +0 -2
  106. package/dist/numbers.test.d.ts.map +0 -1
  107. package/dist/numbers.test.js +0 -57
  108. package/dist/numbers.test.js.map +0 -1
  109. package/dist/resources/groups.test.d.ts +0 -2
  110. package/dist/resources/groups.test.d.ts.map +0 -1
  111. package/dist/resources/groups.test.js +0 -19
  112. package/dist/resources/groups.test.js.map +0 -1
  113. package/dist/resources/newsletters.test.d.ts +0 -2
  114. package/dist/resources/newsletters.test.d.ts.map +0 -1
  115. package/dist/resources/newsletters.test.js +0 -19
  116. package/dist/resources/newsletters.test.js.map +0 -1
  117. package/dist/resources/projects.d.ts +0 -9
  118. package/dist/resources/projects.d.ts.map +0 -1
  119. package/dist/resources/projects.js +0 -23
  120. package/dist/resources/projects.js.map +0 -1
  121. package/dist/resources/templates.test.d.ts +0 -2
  122. package/dist/resources/templates.test.d.ts.map +0 -1
  123. package/dist/resources/templates.test.js +0 -28
  124. package/dist/resources/templates.test.js.map +0 -1
package/CHANGELOG.md ADDED
@@ -0,0 +1,51 @@
1
+ # Changelog
2
+
3
+ All notable changes to `@pilot-status/sdk`.
4
+
5
+ ## 0.8.0
6
+
7
+ ⛔ **This release is the first one npm has seen since `0.5.0`.** `0.6.0` and `0.7.0` were
8
+ bumped in the repository and never published — the commit that set `0.7.0` even announced
9
+ the jump as done. Everything those two versions carried arrives here, at once, including a
10
+ breaking change. Read the whole entry before upgrading, not just the last section.
11
+
12
+ ### Breaking
13
+
14
+ - **`client.projects` is gone.** The `/v1/projects` endpoint was withdrawn; the accessor had
15
+ already stopped doing anything before it was removed. Delete the call — there is no
16
+ replacement, because there is no longer a resource behind it. (Landed in the commit that
17
+ set `0.7.0`; published for the first time here.)
18
+
19
+ ### Added
20
+
21
+ - **WhatsApp Flows, end to end.** `client.flows` — list, create, update, publish, deprecate,
22
+ and `uploadJson()` for the Flow JSON itself. `flowJsonValidationErrors(err)` reads Meta's
23
+ refusal list out of the error `uploadJson()` throws; that list is reachable nowhere else,
24
+ and without it a rejected upload is an opaque 400.
25
+ - **`flow.response_received`** in the webhook parser: the answers of a submitted Flow form.
26
+ META numbers only. Two things to know before you write the handler — the number field is
27
+ **`whatsappNumberId`, not `numberId`** (same value, different name on the wire), and
28
+ **`response` and `responseRaw` are mutually exclusive**: when the submission parsed you get
29
+ `response` and `responseRaw: null`, and when it did not you get the raw string, which is
30
+ then the only copy of the answer that exists anywhere.
31
+ - **`CUSTOMER_WEBHOOK_EVENTS`** — every event the parser accepts, derived from the parser's
32
+ own union. Until now the only way to enumerate them was to read the `.d.ts` and transcribe
33
+ the union by hand, which is exactly the transcription that drifted in this package's own
34
+ README.
35
+ - **Messages**: the operational log (`list`, with direction/status filters), conversation
36
+ history, group messages, unread, mark-as-read, and typing indicators.
37
+ - **Numbers**: create a Meta number, check numbers, logout, restore, purge, and the
38
+ portfolio tier as a field of its own.
39
+ - **Templates**: create, update and delete, with category and examples.
40
+ - **Sticker** as a message type on send.
41
+ - `UnprocessableEntityError` for 422.
42
+
43
+ ### Fixed
44
+
45
+ - The README enumerated the parser's events by hand and had already drifted:
46
+ `flow.response_received` was parseable and undocumented. The list is now generated from the
47
+ union and a test compares the two, so the next addition updates both or fails the build.
48
+
49
+ ## 0.7.0 / 0.6.0
50
+
51
+ Never published to npm. Their contents ship in `0.8.0`.
package/README.md CHANGED
@@ -27,23 +27,39 @@ const accepted = await client.messages.send({
27
27
 
28
28
  const message = await client.messages.get(accepted.id);
29
29
  console.log(message.status);
30
- ```
31
-
32
- ## Management (projects, API keys, numbers)
33
30
 
34
- These endpoints create resources within the scope (project + environment) of the current `apiKey`.
31
+ // Conversation history (both directions, every provider), newest first.
32
+ // This is how you read old messages — the webhook does not replay history.
33
+ const history = await client.messages.history({
34
+ startDate: "2026-07-01T00:00:00Z",
35
+ endDate: "2026-07-31T23:59:59Z",
36
+ pageSize: 100,
37
+ });
38
+ console.log(history.total, history.messages[0]?.providerTimestamp);
39
+ ```
35
40
 
36
- ### Projects
41
+ ## Client options
37
42
 
38
43
  ```ts
39
- const project = await client.projects.create({
40
- name: "My Project",
41
- description: "Optional description",
44
+ const client = new PilotStatusClient({
45
+ apiKey: process.env.PILOT_STATUS_API_KEY!,
46
+ // Point at staging or a local mock. Default: https://pilotstatus.com.br
47
+ baseUrl: process.env.PILOT_STATUS_BASE_URL,
48
+ // Sent as `x-whatsapp-number-id` on every request.
49
+ whatsappNumberId: "wn_1",
42
50
  });
43
51
 
44
- const projects = await client.projects.list();
52
+ // Per-call override — returns a sibling client, never mutates this one:
53
+ await client.withNumber("wn_2").chatwoot.get();
45
54
  ```
46
55
 
56
+ `whatsappNumberId` is **required** for the per-number endpoints when your
57
+ credential is tenant-scoped: `chatwoot.*` and `webhooks.logs()` answer
58
+ `400 NUMBER_REQUIRED` without it. A number-scoped key already carries its
59
+ number, and the header is ignored (the key wins).
60
+
61
+ ## Management (API keys, numbers, workspace)
62
+
47
63
  ### API keys
48
64
 
49
65
  ```ts
@@ -53,11 +69,31 @@ const regenerated = await client.apiKeys.regenerateNumber("wn_1");
53
69
  console.log(regenerated.key); // shown only once
54
70
 
55
71
  const keys = await client.apiKeys.list();
56
- // With a number-scoped key this returns that number's masked keys (`ApiKeyListItem[]`).
57
- // With a tenant-scoped key it returns a lean per-number list (`NumberApiKeyReveal[]`):
58
- // { numberId, number, displayName, keyId, keyLast4, key, revealable } — `key` is the real usable value when `revealable` is true.
72
+ // The shape depends on the credential's scope — discriminate on `revealable`:
73
+ for (const k of keys) {
74
+ if ("revealable" in k) {
75
+ // TENANT-scoped: one row per number; `k.key` is the real value when revealable
76
+ } else {
77
+ // NUMBER-scoped: that number's masked keys
78
+ }
79
+ }
80
+ ```
81
+
82
+ ### Workspace (read-only)
83
+
84
+ ```ts
85
+ const ws = await client.workspace.get();
86
+ console.log(ws.seatsUsed, ws.seatLimit); // pending invites already hold a seat
87
+
88
+ const members = await client.workspace.members.list(); // ACTIVE + PENDING
59
89
  ```
60
90
 
91
+ Inviting, changing a role and removing a member exist in `/v1`, but they require
92
+ an **OAuth principal**: writing membership needs a user on the wire, and an
93
+ `x-api-key` request has none. Those calls answer
94
+ `403 MACHINE_CREDENTIAL_CANNOT_MANAGE_MEMBERS` for any `ps_` key, so this SDK
95
+ deliberately does not expose them — use the dashboard or an OAuth connector.
96
+
61
97
  ### Numbers (WhatsApp)
62
98
 
63
99
  ```ts
@@ -71,6 +107,135 @@ const refreshed = await client.numbers.connect(created.instance.id);
71
107
  // refreshed.qrcodeBase64, refreshed.pairingCode
72
108
 
73
109
  const status = await client.numbers.getStatus(created.instance.id);
110
+
111
+ const detail = await client.numbers.get(created.instance.id);
112
+ console.log(detail.settings.appliesTo.advanced); // "evolution-go" | "none"
113
+ ```
114
+
115
+ #### Per-number settings
116
+
117
+ `numbers.update()` is a PARTIAL patch of the number: retention policy and/or the
118
+ `settings` block. There is no `POST /v1/numbers/{id}/settings`, and Evolution's
119
+ `syncFullHistory` has no equivalent here.
120
+
121
+ ```ts
122
+ // stop replaying the device's old messages into the webhook on every reconnect
123
+ await client.numbers.updateSettings(id, { webhookHistoricalMessages: false });
124
+
125
+ // stop WhatsApp Channel (@newsletter) posts from becoming conversations,
126
+ // stored messages and webhook deliveries
127
+ await client.numbers.updateSettings(id, { ignoreNewsletters: true });
128
+
129
+ await client.numbers.update(id, {
130
+ piiMode: "STORE_X_DAYS",
131
+ piiRetentionDays: 30,
132
+ settings: { rejectCall: true, msgRejectCall: "I don't take calls here" },
133
+ });
134
+ ```
135
+
136
+ `historyImportEnabled`, `webhookHistoricalMessages` and `ignoreNewsletters` apply
137
+ to every provider. `ignoreNewsletters` is where a WhatsApp Channel post is
138
+ refused: the provider exposes no `@newsletter` gate (unlike `ignoreGroups`, which
139
+ it applies itself), so the post always arrives and is dropped on our side —
140
+ before the conversation, the stored message and the webhook. On a Meta number
141
+ channels never arrive at all. The other six are the Evolution GO
142
+ `advancedSettings`, in the GO dialect
143
+ (`ignoreGroups`, not the v2 `groupsIgnore`); passing `null` resets one to the
144
+ provider default. On a Meta number they are stored but never applied — which is
145
+ what `settings.appliesTo.advanced === "none"` tells you.
146
+
147
+ They are also pushed to the number's connected instances; `settingsSync`
148
+ (`{applied, failed, skipped}`) reports that push. It is best-effort: a
149
+ disconnected instance still keeps the persisted value and picks it up on its next
150
+ provisioning.
151
+
152
+ #### Deleting a number is reversible for 30 days
153
+
154
+ ```ts
155
+ const removed = await client.numbers.delete(id);
156
+ console.log(removed.restorableUntil); // end of the 30-day window
157
+
158
+ // Changed your mind — gives the row back, NOT the session:
159
+ await client.numbers.restore(id); // { requiresReconnect: true }
160
+ await client.numbers.connect(id); // scan the QR again
161
+
162
+ // The old destructive behaviour, when you really do delete-and-recreate:
163
+ await client.numbers.purge(id); // irreversible, cascades everything
164
+
165
+ // Just unpair the device, keeping id, keys, webhooks and history:
166
+ await client.numbers.logout(id);
167
+ ```
168
+
169
+ > **Breaking change in 0.6.0.** `numbers.delete()` used to destroy the number and
170
+ > free the phone for immediate reconnection. It is now a 30-day soft delete.
171
+ > Deleting a number still does **not** reduce paid capacity — the slot stays
172
+ > available to reconnect another number. To lower the bill, use
173
+ > `subscription.scheduleRemoval()` (applies next cycle).
174
+
175
+ ## Messages, conversations and the 24h window
176
+
177
+ ```ts
178
+ // The message LOG (delivery status), newest first — not the chat thread
179
+ const log = await client.messages.list({ status: "FAILED,SENT", direction: "out" });
180
+
181
+ // Unread inbound — `total` is the real count, NOT messages.length
182
+ const { total, messages } = await client.messages.unread();
183
+
184
+ // Read receipts and typing indicators, without sending a message
185
+ await client.messages.markRead("+5511999999999");
186
+ await client.messages.typing({ to: "+5511999999999", state: "typing" });
187
+
188
+ // Conversations, newest activity first
189
+ const { conversations } = await client.conversations.list({ pageSize: 50 });
190
+
191
+ // Can I send free-form right now?
192
+ const w = await client.serviceWindow.get("+5511999999999");
193
+ // Branch on windowType, not on `open`: web numbers always report open: true
194
+ if (w.windowType === "META_24H" && !w.open) {
195
+ /* only an approved template will go through */
196
+ }
197
+ ```
198
+
199
+ ## Templates, groups and webhooks
200
+
201
+ ```ts
202
+ // Templates — `examples` is required, one per {{variable}}
203
+ await client.templates.create({
204
+ name: "boas_vindas",
205
+ body: "Olá {{nome}}",
206
+ examples: { nome: "Alice" },
207
+ });
208
+
209
+ // Groups — E.164 digits, not JIDs, in `participants`
210
+ const group = await client.groups.create({ subject: "Support", participants: ["5511999999999"] });
211
+ await client.groups.promoteParticipants(group.id, ["5511999999999"]);
212
+ const { inviteUrl } = await client.groups.invite(group.id);
213
+
214
+ // Webhooks CRUD — an empty `events` list dispatches NOTHING; use ["*"] for all
215
+ const hook = await client.webhooks.create({
216
+ url: "https://api.example.com/pilot-status",
217
+ events: ["message.received"],
218
+ });
219
+ const attempts = await client.webhooks.logs(hook.id, { limit: 20 });
220
+ ```
221
+
222
+ ## Chatwoot, billing and embed sessions
223
+
224
+ ```ts
225
+ // Every /v1/chatwoot endpoint is per-number
226
+ const cw = client.withNumber("wn_1").chatwoot;
227
+ await cw.test({ instanceUrl: "https://app.chatwoot.com", accountId: "7" }); // dry run
228
+ await cw.connect({ instanceUrl: "https://app.chatwoot.com", accountId: "7", userAccessToken: t });
229
+
230
+ // A hosted payment page URL — nothing is charged until a human completes it
231
+ const { url } = await client.billing.createCheckout({ purpose: "wallet_topup", amount: 100 });
232
+
233
+ // Mint an embed token on YOUR backend, then hand it to the browser
234
+ const session = await client.embed.createSession({
235
+ surface: "chat",
236
+ whatsappNumberIds: ["wn_1"],
237
+ allowedOrigins: ["https://app.yourcompany.com"],
238
+ });
74
239
  ```
75
240
 
76
241
  ## Analytics
@@ -160,14 +325,29 @@ await client.calls.play(call.id, "https://cdn.example.com/ivr-greeting.mp3");
160
325
  const session = await client.calls.realtimeSession(call.id, "talk");
161
326
  ```
162
327
 
163
- ## Webhooks (parse / validation)
328
+ ## Receiving webhooks (verify, then parse)
329
+
330
+ `parseCustomerWebhook` proves the **shape** of an event, nothing else — anyone on
331
+ the internet can POST that JSON at your URL. Verify the signature first:
164
332
 
165
333
  ```ts
166
- import { parseCustomerWebhook } from "@pilot-status/sdk";
334
+ import { parseCustomerWebhook, verifyWebhookSignature } from "@pilot-status/sdk";
167
335
 
168
336
  export async function handler(req: Request) {
169
- const payload = await req.json();
170
- const event = parseCustomerWebhook(payload);
337
+ // The RAW body. Do NOT re-serialize: the HMAC is over the bytes we sent.
338
+ const raw = await req.text();
339
+
340
+ if (
341
+ !verifyWebhookSignature({
342
+ payload: raw,
343
+ signature: req.headers.get("x-pilot-status-signature"),
344
+ secret: process.env.PILOT_STATUS_WEBHOOK_SECRET!,
345
+ })
346
+ ) {
347
+ return new Response("invalid signature", { status: 401 });
348
+ }
349
+
350
+ const event = parseCustomerWebhook(JSON.parse(raw));
171
351
 
172
352
  if (event.event === "message.failed") {
173
353
  console.log(event.data.errorMessage);
@@ -177,13 +357,19 @@ export async function handler(req: Request) {
177
357
  }
178
358
  ```
179
359
 
360
+ The signature is `HMAC-SHA256` hex over the raw body, in
361
+ `x-pilot-status-signature`. A webhook created without a secret gets no header —
362
+ then there is nothing to verify, and accepting it anyway is your call to make
363
+ explicitly.
364
+
180
365
  Notes:
181
366
  - Customer webhook payloads do not include: `projectSlug`, `lastMessageId`. Optional `correlationId` (same as HTTP 202 when present) may appear on outbound status events and on `message.reply` / `message.received` when correlated to a prior send.
182
367
  - For outbound status events (`message.sent`, `message.delivered`, `message.read`, `message.failed`), `messageId` is the WhatsApp provider message id (key.id) and `internalMessageId` is the Pilot Status message id.
183
368
  - `message.received` includes `fromMe` (boolean).
184
369
  - `message.group` is delivered for inbound group messages (includes `groupName`).
185
370
  - `message.newsletter` is delivered for inbound WhatsApp channel / newsletter messages (`@newsletter`, includes `newsletterId`).
186
- - Supported events in the parser: `message.sent`, `message.delivered`, `message.read`, `message.failed`, `message.reply`, `message.received`, `message.group`, `message.newsletter`, `number.created`, `number.connected`, `number.disconnected`, `number.removed`, `call.ringing`, `call.connected`, `call.ended`, `call.missed`, `call.permission_updated`.
371
+ - Supported events in the parser: `message.sent`, `message.delivered`, `message.read`, `message.failed`, `message.reply`, `message.received`, `message.group`, `message.newsletter`, `number.created`, `number.connected`, `number.disconnected`, `number.removed`, `call.ringing`, `call.connected`, `call.ended`, `call.missed`, `call.permission_updated`, `flow.response_received`. The same list is exported as `CUSTOMER_WEBHOOK_EVENTS` — it is derived from the parser's own union, and a test compares this line against it, so the two cannot drift.
372
+ - `flow.response_received` carries the answers of a submitted WhatsApp Flow (`interactive.nfm_reply`), **META numbers only**. Wrapped in `data` like the `message.*` events: `{ event, data: { event, flowId, metaFlowId, flowToken, messageId, whatsappNumberId, from, receivedAt, response, responseRaw } }`. Two fields need care. **The number field is `whatsappNumberId`, not `numberId`** — same value as everywhere else, different name on the wire, so a handler reading `numberId` gets `undefined`. And **`response` and `responseRaw` are mutually exclusive**: `response` is the parsed answer object and `responseRaw` is `null`; when the submission could not be parsed it is the other way round, and the raw string is the only copy of the answer that exists. `flowId` is `null` for a Flow built in Meta's Flow Manager and not yet synced here — normal, not an error.
187
373
  - `call.*` payloads are **flat** (fields sit next to `event`, no `data` wrapper): `{ event, callId, externalCallId?, direction, status, from, to, timestamp, duration? }`. `duration` (seconds) appears on `call.ended` only when the call was answered; `call.permission_updated` has `callId`/`direction` `null` and `status` `NO_PERMISSION` | `TEMPORARY` | `PERMANENT`.
188
374
 
189
375
  ## Errors
package/dist/client.d.ts CHANGED
@@ -1,34 +1,85 @@
1
1
  import { AnalyticsResource } from "./resources/analytics.js";
2
+ import { BillingResource } from "./resources/billing.js";
3
+ import { BrandingResource } from "./resources/branding.js";
2
4
  import { CallsResource } from "./resources/calls.js";
5
+ import { ChatwootResource } from "./resources/chatwoot.js";
6
+ import { ConversationsResource } from "./resources/conversations.js";
7
+ import { EmbedResource } from "./resources/embed.js";
8
+ import { FlowsResource } from "./resources/flows.js";
3
9
  import { MessagesResource } from "./resources/messages.js";
10
+ import { MetaResource } from "./resources/meta.js";
4
11
  import { ApiKeysResource } from "./resources/api-keys.js";
5
12
  import { NumbersResource } from "./resources/numbers.js";
6
- import { ProjectsResource } from "./resources/projects.js";
13
+ import { ServiceWindowResource } from "./resources/service-window.js";
14
+ import { SubscriptionResource } from "./resources/subscription.js";
7
15
  import { TemplatesResource } from "./resources/templates.js";
8
16
  import { GroupsResource } from "./resources/groups.js";
9
17
  import { NewslettersResource } from "./resources/newsletters.js";
10
18
  import { RemotePairingResource } from "./resources/remote-pairing.js";
11
19
  import { MediaResource } from "./resources/media.js";
20
+ import { WebhooksResource } from "./resources/webhooks.js";
21
+ import { WorkspaceResource } from "./resources/workspace.js";
12
22
  import { type FetchLike } from "./http.js";
23
+ /** Production. Override with `baseUrl` to point at staging or a mock. */
24
+ export declare const DEFAULT_BASE_URL = "https://pilotstatus.com.br";
13
25
  export type PilotStatusClientOptions = {
14
26
  apiKey: string;
27
+ /**
28
+ * API root, without `/v1` (that already comes with each path). Defaults to
29
+ * {@link DEFAULT_BASE_URL}. It exists so you can point the SDK at staging or a
30
+ * test server without monkey-patching `fetch`.
31
+ */
32
+ baseUrl?: string;
33
+ /**
34
+ * Default target number, sent as `x-whatsapp-number-id` on every call.
35
+ *
36
+ * Required when the credential is tenant-scoped and the endpoint is per-number:
37
+ * `chatwoot.*` answers 400 `NUMBER_REQUIRED` without it, and so does
38
+ * `webhooks.logs()`. A number-scoped key already carries the number — the
39
+ * header is then ignored by the server (the key wins).
40
+ */
41
+ whatsappNumberId?: string;
15
42
  timeoutMs?: number;
16
43
  userAgent?: string;
17
44
  fetch?: FetchLike;
18
45
  getRetries?: number;
19
46
  };
20
47
  export declare class PilotStatusClient {
48
+ #private;
21
49
  readonly messages: MessagesResource;
22
50
  readonly analytics: AnalyticsResource;
23
51
  readonly apiKeys: ApiKeysResource;
24
52
  readonly numbers: NumbersResource;
25
- readonly projects: ProjectsResource;
26
53
  readonly templates: TemplatesResource;
54
+ readonly flows: FlowsResource;
27
55
  readonly groups: GroupsResource;
28
56
  readonly newsletters: NewslettersResource;
29
57
  readonly remotePairing: RemotePairingResource;
30
58
  readonly media: MediaResource;
31
59
  readonly calls: CallsResource;
60
+ readonly conversations: ConversationsResource;
61
+ readonly serviceWindow: ServiceWindowResource;
62
+ readonly meta: MetaResource;
63
+ readonly webhooks: WebhooksResource;
64
+ readonly branding: BrandingResource;
65
+ readonly embed: EmbedResource;
66
+ readonly billing: BillingResource;
67
+ readonly subscription: SubscriptionResource;
68
+ readonly chatwoot: ChatwootResource;
69
+ readonly workspace: WorkspaceResource;
32
70
  constructor(options: PilotStatusClientOptions);
71
+ /**
72
+ * A sibling client pointed at ANOTHER number — this is the per-call override of
73
+ * `whatsappNumberId`:
74
+ *
75
+ * ```ts
76
+ * await client.withNumber("wn_2").chatwoot.get();
77
+ * ```
78
+ *
79
+ * It returns a new instance instead of mutating this one because the header
80
+ * travels on EVERY request: mutating the default would make a call's target
81
+ * depend on when it was dispatched, which inside a `Promise.all` is a race.
82
+ */
83
+ withNumber(whatsappNumberId: string): PilotStatusClient;
33
84
  }
34
85
  //# sourceMappingURL=client.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,O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gBAAgB,CAAC;IACpC,QAAQ,CAAC,QAAQ,EAAE,gBAAgB,CAAC;IACpC,QAAQ,CAAC,KAAK,EAAE,aAAa,CAAC;IAC9B,QAAQ,CAAC,OAAO,EAAE,eAAe,CAAC;IAClC,QAAQ,CAAC,YAAY,EAAE,oBAAoB,CAAC;IAC5C,QAAQ,CAAC,QAAQ,EAAE,gBAAgB,CAAC;IACpC,QAAQ,CAAC,SAAS,EAAE,iBAAiB,CAAC;gBAI1B,OAAO,EAAE,wBAAwB;IA6C7C;;;;;;;;;;;OAWG;IACH,UAAU,CAAC,gBAAgB,EAAE,MAAM,GAAG,iBAAiB;CAGxD"}
package/dist/client.js CHANGED
@@ -1,51 +1,101 @@
1
1
  import { AnalyticsResource } from "./resources/analytics.js";
2
+ import { BillingResource } from "./resources/billing.js";
3
+ import { BrandingResource } from "./resources/branding.js";
2
4
  import { CallsResource } from "./resources/calls.js";
5
+ import { ChatwootResource } from "./resources/chatwoot.js";
6
+ import { ConversationsResource } from "./resources/conversations.js";
7
+ import { EmbedResource } from "./resources/embed.js";
8
+ import { FlowsResource } from "./resources/flows.js";
3
9
  import { MessagesResource } from "./resources/messages.js";
10
+ import { MetaResource } from "./resources/meta.js";
4
11
  import { ApiKeysResource } from "./resources/api-keys.js";
5
12
  import { NumbersResource } from "./resources/numbers.js";
6
- import { ProjectsResource } from "./resources/projects.js";
13
+ import { ServiceWindowResource } from "./resources/service-window.js";
14
+ import { SubscriptionResource } from "./resources/subscription.js";
7
15
  import { TemplatesResource } from "./resources/templates.js";
8
16
  import { GroupsResource } from "./resources/groups.js";
9
17
  import { NewslettersResource } from "./resources/newsletters.js";
10
18
  import { RemotePairingResource } from "./resources/remote-pairing.js";
11
19
  import { MediaResource } from "./resources/media.js";
20
+ import { WebhooksResource } from "./resources/webhooks.js";
21
+ import { WorkspaceResource } from "./resources/workspace.js";
12
22
  import { createHttpClient } from "./http.js";
23
+ /** Production. Override with `baseUrl` to point at staging or a mock. */
24
+ export const DEFAULT_BASE_URL = "https://pilotstatus.com.br";
13
25
  export class PilotStatusClient {
14
26
  messages;
15
27
  analytics;
16
28
  apiKeys;
17
29
  numbers;
18
- projects;
19
30
  templates;
31
+ flows;
20
32
  groups;
21
33
  newsletters;
22
34
  remotePairing;
23
35
  media;
24
36
  calls;
37
+ conversations;
38
+ serviceWindow;
39
+ meta;
40
+ webhooks;
41
+ branding;
42
+ embed;
43
+ billing;
44
+ subscription;
45
+ chatwoot;
46
+ workspace;
47
+ #options;
25
48
  constructor(options) {
49
+ this.#options = options;
26
50
  const fetchImpl = options.fetch ?? globalThis.fetch;
27
51
  if (!fetchImpl) {
28
52
  throw new Error("fetch is not available in this runtime; pass { fetch } to PilotStatusClient");
29
53
  }
30
54
  const http = createHttpClient({
31
- baseUrl: "https://pilotstatus.com.br",
55
+ baseUrl: options.baseUrl ?? DEFAULT_BASE_URL,
32
56
  apiKey: options.apiKey,
33
57
  timeoutMs: options.timeoutMs ?? 30_000,
34
58
  userAgent: options.userAgent,
35
59
  fetch: fetchImpl,
36
60
  getRetries: options.getRetries ?? 2,
61
+ whatsappNumberId: options.whatsappNumberId,
37
62
  });
38
63
  this.messages = new MessagesResource(http);
39
64
  this.analytics = new AnalyticsResource(http);
40
65
  this.apiKeys = new ApiKeysResource(http);
41
66
  this.numbers = new NumbersResource(http);
42
- this.projects = new ProjectsResource(http);
43
67
  this.templates = new TemplatesResource(http);
68
+ this.flows = new FlowsResource(http);
44
69
  this.groups = new GroupsResource(http);
45
70
  this.newsletters = new NewslettersResource(http);
46
71
  this.remotePairing = new RemotePairingResource(http);
47
72
  this.media = new MediaResource(http);
48
73
  this.calls = new CallsResource(http);
74
+ this.conversations = new ConversationsResource(http);
75
+ this.serviceWindow = new ServiceWindowResource(http);
76
+ this.meta = new MetaResource(http);
77
+ this.webhooks = new WebhooksResource(http);
78
+ this.branding = new BrandingResource(http);
79
+ this.embed = new EmbedResource(http);
80
+ this.billing = new BillingResource(http);
81
+ this.subscription = new SubscriptionResource(http);
82
+ this.chatwoot = new ChatwootResource(http);
83
+ this.workspace = new WorkspaceResource(http);
84
+ }
85
+ /**
86
+ * A sibling client pointed at ANOTHER number — this is the per-call override of
87
+ * `whatsappNumberId`:
88
+ *
89
+ * ```ts
90
+ * await client.withNumber("wn_2").chatwoot.get();
91
+ * ```
92
+ *
93
+ * It returns a new instance instead of mutating this one because the header
94
+ * travels on EVERY request: mutating the default would make a call's target
95
+ * depend on when it was dispatched, which inside a `Promise.all` is a race.
96
+ */
97
+ withNumber(whatsappNumberId) {
98
+ return new PilotStatusClient({ ...this.#options, whatsappNumberId });
49
99
  }
50
100
  }
51
101
  //# sourceMappingURL=client.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAC7D,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAC3D,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAC1D,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAC3D,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAC7D,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AACjE,OAAO,EAAE,qBAAqB,EAAE,MAAM,+BAA+B,CAAC;AACtE,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,EAAE,gBAAgB,EAAkB,MAAM,WAAW,CAAC;AAU7D,MAAM,OAAO,iBAAiB;IACnB,QAAQ,CAAmB;IAC3B,SAAS,CAAoB;IAC7B,OAAO,CAAkB;IACzB,OAAO,CAAkB;IACzB,QA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,CAAC,YAAY,GAAG,IAAI,oBAAoB,CAAC,IAAI,CAAC,CAAC;QACnD,IAAI,CAAC,QAAQ,GAAG,IAAI,gBAAgB,CAAC,IAAI,CAAC,CAAC;QAC3C,IAAI,CAAC,SAAS,GAAG,IAAI,iBAAiB,CAAC,IAAI,CAAC,CAAC;IAC/C,CAAC;IAED;;;;;;;;;;;OAWG;IACH,UAAU,CAAC,gBAAwB;QACjC,OAAO,IAAI,iBAAiB,CAAC,EAAE,GAAG,IAAI,CAAC,QAAQ,EAAE,gBAAgB,EAAE,CAAC,CAAC;IACvE,CAAC;CACF"}
package/dist/errors.d.ts CHANGED
@@ -33,6 +33,13 @@ export declare class PilotStatusHttpError extends PilotStatusError {
33
33
  export declare class AuthenticationError extends PilotStatusHttpError {
34
34
  name: string;
35
35
  }
36
+ /**
37
+ * 400 — the REQUEST is wrong: a missing field, a bad type, a body we could not read.
38
+ *
39
+ * ⚠️ The remedy is always in the code that built the call. A refusal of the CONTENT of
40
+ * a well-formed request is {@link UnprocessableEntityError} (422) and is deliberately
41
+ * NOT a subclass of this one — see its docblock for why the two must not merge.
42
+ */
36
43
  export declare class ValidationError extends PilotStatusHttpError {
37
44
  name: string;
38
45
  }
@@ -45,11 +52,62 @@ export declare class NotFoundError extends PilotStatusHttpError {
45
52
  export declare class ConflictError extends PilotStatusHttpError {
46
53
  name: string;
47
54
  }
55
+ /**
56
+ * 422 — the request was well-formed and the CONTENT was refused.
57
+ *
58
+ * ⛔ THIS IS NOT A {@link ValidationError}, AND THE SPLIT IS THE WHOLE POINT. A 400
59
+ * says "the call you built is wrong" and is fixed by editing the call site. A 422 says
60
+ * "the call was fine, and what it carried was refused": Meta rejected the Flow JSON,
61
+ * the number is not a Meta (Cloud API) one, the 24h service window has closed, the
62
+ * tenant is suspended. Those are fixed by editing the DOCUMENT, or the state of the
63
+ * account — never by re-reading the arguments. One status, one remedy.
64
+ *
65
+ * ⛔ IT DOES NOT EXTEND `ValidationError`, ON PURPOSE. `catch (e) { if (e instanceof
66
+ * ValidationError) … }` has to keep catching the 400 and has to NOT catch this; making
67
+ * 422 a subclass would route every content refusal into the "fix your arguments"
68
+ * branch, which is the exact confusion this class exists to end. To handle both, catch
69
+ * {@link PilotStatusHttpError} and read `status`.
70
+ *
71
+ * ⚠️ Before this class existed a 422 arrived as a bare `PilotStatusHttpError`, so a
72
+ * caller who branched only on `ValidationError` LOST THE CASE ENTIRELY — including the
73
+ * one 422 that carries the list of what was refused.
74
+ */
75
+ export declare class UnprocessableEntityError extends PilotStatusHttpError {
76
+ name: string;
77
+ /**
78
+ * The refusal list the API sent, VERBATIM — or `null` when this 422 carried none.
79
+ *
80
+ * ⚠️ `null`, never `[]`, for an absent list: "refused, and the list was empty" has
81
+ * to stay distinguishable from "this 422 was never about a document at all"
82
+ * (`META_OUTSIDE_24H_WINDOW`, `BILLING_SUSPENDED`, `FLOW_REQUIRES_META_NUMBER` —
83
+ * none of which carry one).
84
+ *
85
+ * Today the only producer is `flows.uploadJson()` (422 `FLOW_JSON_INVALID`), where
86
+ * the list is META'S OWN: it names the line and the component it refused, its shape
87
+ * belongs to Meta and they change it without telling us. Print it, do not branch on
88
+ * its internals.
89
+ *
90
+ * ⚠️ This does NOT make `flowJsonValidationErrors()` redundant and that helper
91
+ * stays. It answers a narrower question — "is this specifically the Flow JSON
92
+ * refusal?", i.e. `code === "FLOW_JSON_INVALID"` — and it takes an `unknown`, so a
93
+ * `catch` block reads it without an `instanceof` first. This field answers "did
94
+ * this 422 carry a list?" and nothing more.
95
+ */
96
+ readonly validationErrors: unknown[] | null;
97
+ constructor(params: ConstructorParameters<typeof PilotStatusHttpError>[0]);
98
+ }
48
99
  export declare class RateLimitError extends PilotStatusHttpError {
49
100
  name: string;
50
101
  }
51
102
  export declare class ServerError extends PilotStatusHttpError {
52
103
  name: string;
53
104
  }
105
+ /**
106
+ * Maps an HTTP failure onto the narrowest class that describes it.
107
+ *
108
+ * ⚠️ A status with no branch here falls through to a bare {@link PilotStatusHttpError},
109
+ * which is not a neutral outcome: every caller that branches on classes stops seeing
110
+ * that case. Adding a branch is how a status becomes catchable.
111
+ */
54
112
  export declare function createHttpError(params: ConstructorParameters<typeof PilotStatusHttpError>[0]): PilotStatusHttpError;
55
113
  //# sourceMappingURL=errors.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,oBAAoB,GAC1B;IACI,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,CAAC;CAClB,GACD,OAAO,CAAC;AAEd,qBAAa,gBAAiB,SAAQ,KAAK;IAC9B,IAAI,EAAE,MAAM,CAAsB;gBAE/B,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE;QAAE,KAAK,CAAC,EAAE,OAAO,CAAA;KAAE;CAM7D;AAED,qBAAa,oBAAqB,SAAQ,gBAAgB;IAC7C,IAAI,EAAE,MAAM,CAA0B;IAE/C,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,IAAI,EAAE,oBAAoB,GAAG,SAAS,CAAC;IAChD,QAAQ,CAAC,OAAO,EAAE,MAAM,GAAG,SAAS,CAAC;IACrC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;gBAE7B,MAAM,EAAE;QAChB,OAAO,EAAE,MAAM,CAAC;QAChB,MAAM,EAAE,MAAM,CAAC;QACf,MAAM,EAAE,MAAM,CAAC;QACf,GAAG,EAAE,MAAM,CAAC;QACZ,IAAI,CAAC,EAAE,oBAAoB,CAAC;QAC5B,OAAO,CAAC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