@pilot-status/sdk 0.5.0 → 0.9.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/CHANGELOG.md +154 -0
- package/README.md +181 -19
- package/dist/client.d.ts +53 -2
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +54 -4
- package/dist/client.js.map +1 -1
- package/dist/errors.d.ts +58 -0
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +65 -0
- package/dist/errors.js.map +1 -1
- package/dist/http.d.ts +6 -0
- package/dist/http.d.ts.map +1 -1
- package/dist/http.js +3 -0
- package/dist/http.js.map +1 -1
- package/dist/index.d.ts +12 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +10 -3
- package/dist/index.js.map +1 -1
- package/dist/internal.d.ts +19 -0
- package/dist/internal.d.ts.map +1 -0
- package/dist/internal.js +27 -0
- package/dist/internal.js.map +1 -0
- package/dist/resources/api-keys.d.ts +20 -7
- package/dist/resources/api-keys.d.ts.map +1 -1
- package/dist/resources/api-keys.js +18 -5
- package/dist/resources/api-keys.js.map +1 -1
- package/dist/resources/billing.d.ts +18 -0
- package/dist/resources/billing.d.ts.map +1 -0
- package/dist/resources/billing.js +30 -0
- package/dist/resources/billing.js.map +1 -0
- package/dist/resources/branding.d.ts +18 -0
- package/dist/resources/branding.d.ts.map +1 -0
- package/dist/resources/branding.js +29 -0
- package/dist/resources/branding.js.map +1 -0
- package/dist/resources/chatwoot.d.ts +57 -0
- package/dist/resources/chatwoot.d.ts.map +1 -0
- package/dist/resources/chatwoot.js +117 -0
- package/dist/resources/chatwoot.js.map +1 -0
- package/dist/resources/conversations.d.ts +16 -0
- package/dist/resources/conversations.d.ts.map +1 -0
- package/dist/resources/conversations.js +28 -0
- package/dist/resources/conversations.js.map +1 -0
- package/dist/resources/embed.d.ts +24 -0
- package/dist/resources/embed.d.ts.map +1 -0
- package/dist/resources/embed.js +37 -0
- package/dist/resources/embed.js.map +1 -0
- package/dist/resources/flows.d.ts +203 -0
- package/dist/resources/flows.d.ts.map +1 -0
- package/dist/resources/flows.js +289 -0
- package/dist/resources/flows.js.map +1 -0
- package/dist/resources/groups.d.ts +37 -1
- package/dist/resources/groups.d.ts.map +1 -1
- package/dist/resources/groups.js +91 -0
- package/dist/resources/groups.js.map +1 -1
- package/dist/resources/messages.d.ts +43 -1
- package/dist/resources/messages.d.ts.map +1 -1
- package/dist/resources/messages.js +113 -1
- package/dist/resources/messages.js.map +1 -1
- package/dist/resources/meta.d.ts +19 -0
- package/dist/resources/meta.d.ts.map +1 -0
- package/dist/resources/meta.js +31 -0
- package/dist/resources/meta.js.map +1 -0
- package/dist/resources/numbers.d.ts +63 -1
- package/dist/resources/numbers.d.ts.map +1 -1
- package/dist/resources/numbers.js +101 -0
- package/dist/resources/numbers.js.map +1 -1
- package/dist/resources/service-window.d.ts +20 -0
- package/dist/resources/service-window.d.ts.map +1 -0
- package/dist/resources/service-window.js +26 -0
- package/dist/resources/service-window.js.map +1 -0
- package/dist/resources/subscription.d.ts +43 -0
- package/dist/resources/subscription.d.ts.map +1 -0
- package/dist/resources/subscription.js +60 -0
- package/dist/resources/subscription.js.map +1 -0
- package/dist/resources/templates.d.ts +31 -1
- package/dist/resources/templates.d.ts.map +1 -1
- package/dist/resources/templates.js +56 -0
- package/dist/resources/templates.js.map +1 -1
- package/dist/resources/webhooks.d.ts +53 -0
- package/dist/resources/webhooks.d.ts.map +1 -0
- package/dist/resources/webhooks.js +97 -0
- package/dist/resources/webhooks.js.map +1 -0
- package/dist/resources/workspace.d.ts +57 -0
- package/dist/resources/workspace.d.ts.map +1 -0
- package/dist/resources/workspace.js +73 -0
- package/dist/resources/workspace.js.map +1 -0
- package/dist/types.d.ts +993 -23
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/webhooks/parse.d.ts +16 -0
- package/dist/webhooks/parse.d.ts.map +1 -1
- package/dist/webhooks/parse.js +109 -0
- package/dist/webhooks/parse.js.map +1 -1
- package/dist/webhooks/signature.d.ts +42 -0
- package/dist/webhooks/signature.d.ts.map +1 -0
- package/dist/webhooks/signature.js +40 -0
- package/dist/webhooks/signature.js.map +1 -0
- package/dist/webhooks/types.d.ts +144 -2
- package/dist/webhooks/types.d.ts.map +1 -1
- package/package.json +5 -3
- package/dist/messages.test.d.ts +0 -2
- package/dist/messages.test.d.ts.map +0 -1
- package/dist/messages.test.js +0 -107
- package/dist/messages.test.js.map +0 -1
- package/dist/numbers.test.d.ts +0 -2
- package/dist/numbers.test.d.ts.map +0 -1
- package/dist/numbers.test.js +0 -57
- package/dist/numbers.test.js.map +0 -1
- package/dist/resources/groups.test.d.ts +0 -2
- package/dist/resources/groups.test.d.ts.map +0 -1
- package/dist/resources/groups.test.js +0 -19
- package/dist/resources/groups.test.js.map +0 -1
- package/dist/resources/newsletters.test.d.ts +0 -2
- package/dist/resources/newsletters.test.d.ts.map +0 -1
- package/dist/resources/newsletters.test.js +0 -19
- package/dist/resources/newsletters.test.js.map +0 -1
- package/dist/resources/projects.d.ts +0 -9
- package/dist/resources/projects.d.ts.map +0 -1
- package/dist/resources/projects.js +0 -23
- package/dist/resources/projects.js.map +0 -1
- package/dist/resources/templates.test.d.ts +0 -2
- package/dist/resources/templates.test.d.ts.map +0 -1
- package/dist/resources/templates.test.js +0 -28
- package/dist/resources/templates.test.js.map +0 -1
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to `@pilot-status/sdk`.
|
|
4
|
+
|
|
5
|
+
## 0.9.0 - 2026-09-10
|
|
6
|
+
|
|
7
|
+
### Blocos interativos: `list`, `carousel` e `flow`
|
|
8
|
+
|
|
9
|
+
Os tres blocos passam a ser tipados **e encaminhados**. Antes, `list` e `carousel`
|
|
10
|
+
eram descartados EM SILENCIO: o corpo do envio e montado campo a campo, e um campo
|
|
11
|
+
que ninguem acrescenta ao construtor nao chega ao servidor por mais bem tipado que
|
|
12
|
+
esteja. Quem os passasse via a mensagem sair como texto simples, sem erro nenhum.
|
|
13
|
+
|
|
14
|
+
- `list` — lista interativa single-select
|
|
15
|
+
- `carousel` — carrossel de cards de midia
|
|
16
|
+
- `flow` — **novo**: Flow escolhido no envio, em vez de fixo num template aprovado
|
|
17
|
+
|
|
18
|
+
`flow` exige a janela de 24h aberta. Com ela fechada a Meta responde `200` e descarta
|
|
19
|
+
a mensagem em silencio, entao o Pilot Status recusa com `FLOW_WINDOW_CLOSED` em vez de
|
|
20
|
+
a deixar desaparecer. Nao ha campo para `flowToken`: ele e gerado por mensagem, e um
|
|
21
|
+
escolhido por quem chama deixaria uma conta reclamar as respostas de outra.
|
|
22
|
+
|
|
23
|
+
## Unreleased
|
|
24
|
+
|
|
25
|
+
⚠️ **Heading deliberately not a number.** `0.8.0` is on npm and `package.json` still declares
|
|
26
|
+
`0.8.0`, so writing a version here would either backdate these fields into a release that
|
|
27
|
+
does not contain them or announce a bump nothing has made — which is the exact mistake the
|
|
28
|
+
`0.8.0` entry below is about. Whoever cuts the release renames this heading and bumps
|
|
29
|
+
`package.json` in the same commit.
|
|
30
|
+
|
|
31
|
+
### Added
|
|
32
|
+
|
|
33
|
+
- **What the person TYPED, on a `data_exchange` Flow.** `data.submitted` on the
|
|
34
|
+
`flow.response_received` webhook, and `submitted` on every entry of
|
|
35
|
+
`flows.listResponses()`. In a `data_exchange` Flow the answers go to YOUR endpoint inside
|
|
36
|
+
the exchange; Pilot Status relayed them and kept nothing, so a real submission produced an
|
|
37
|
+
event whose `response` was `{"flow_token": "…"}` and nothing else. This is that missing
|
|
38
|
+
half. Five things before you write the handler:
|
|
39
|
+
|
|
40
|
+
- ⛔ **It is not `response`, and they were deliberately not merged.** `response` means
|
|
41
|
+
"what your endpoint returned" — the `extension_message_response.params` of the final
|
|
42
|
+
exchange. `submitted` is what the respondent's device sent on the way there. Writing the
|
|
43
|
+
capture into `response` would make one field name mean two different things depending on
|
|
44
|
+
the Flow's type.
|
|
45
|
+
- ⛔ **A list, never one merged object.** Each `data_exchange` carries only the fields of
|
|
46
|
+
ITS screen, so merging would let the last field with a repeated name win in silence. A
|
|
47
|
+
screen appearing **twice is not a duplicate**: someone walked back and submitted it
|
|
48
|
+
again, and both answers are there, in order. Each entry is
|
|
49
|
+
`{ screen, at, data, omitted }`, and `data`/`omitted` are complementary — one is `null`
|
|
50
|
+
exactly when the other is not.
|
|
51
|
+
- ⛔ **Nothing is ever truncated in silence.** An exchange too large keeps its place and
|
|
52
|
+
says `omitted: "DATA_TOO_LARGE"`; a form with more exchanges than are kept ends with
|
|
53
|
+
`omitted: "LIMIT_REACHED"`, always as the last entry; `"UNREADABLE"` means stored bytes
|
|
54
|
+
that no longer parse. Treat `omitted` as an open **string** — a reason your SDK version
|
|
55
|
+
has not heard of must still arrive.
|
|
56
|
+
- ⛔ **Only `data_exchange` produces an entry**, so the list is shorter than the number of
|
|
57
|
+
calls your endpoint received: `INIT` carries the form's initial state and `BACK` is a
|
|
58
|
+
navigation gesture. And **nothing of what your endpoint answered is captured** —
|
|
59
|
+
`extension_message_response` still never appears anywhere in Pilot Status.
|
|
60
|
+
- **`null` on the event, `[]` on `listResponses()`**, the same asymmetry the attachment
|
|
61
|
+
shapes have and for the same reason: the redactor that blanks a `RELAY_ONLY` webhook log
|
|
62
|
+
replaces any field holding something, so `[]` would read as "there were answers and we
|
|
63
|
+
hid them". `submitted` is also OPTIONAL on the event — absent is a backend older than the
|
|
64
|
+
field. ⚠️ Empty is **not** "they typed nothing": a NAVIGATE-only Flow never calls an
|
|
65
|
+
endpoint at all, and its answers are wholly in `response`.
|
|
66
|
+
|
|
67
|
+
The element type is exported — `import type { FlowSubmittedExchange } from
|
|
68
|
+
"@pilot-status/sdk"` — and unlike the two attachment shapes it is the SAME type on both
|
|
69
|
+
surfaces.
|
|
70
|
+
|
|
71
|
+
- **Flow attachments — the files a person uploads inside the form.** `PhotoPicker` /
|
|
72
|
+
`DocumentPicker` uploads never appear in `response`: a media picker requires a
|
|
73
|
+
`data_exchange` endpoint, so what `response` holds for such a field is a reference to
|
|
74
|
+
Meta's CDN, and Meta deletes it after 20 days. The re-hosted copy is now published in
|
|
75
|
+
both places the answers are readable — `data.flowMedia` on the `flow.response_received`
|
|
76
|
+
webhook, and `media` on every entry of `flows.listResponses()`. Three things before you
|
|
77
|
+
write the handler:
|
|
78
|
+
|
|
79
|
+
- **`url` exists only when `status === "STORED"`**; it is `null` on `PENDING` and on
|
|
80
|
+
`FAILED`. The re-host is asynchronous, so the transfer is often still in flight at the
|
|
81
|
+
instant the event is dispatched — a handler reading `{ status: "PENDING", url: null }`
|
|
82
|
+
is reading the ordinary case, not a failure. The final URL comes from
|
|
83
|
+
`flows.listResponses()`. An optimistic URL in the event would be a link that 404s.
|
|
84
|
+
- **`flowMedia` is `null` — never `[]` — when nothing was attached**, while
|
|
85
|
+
`listResponses()`'s `media` is always an array. The asymmetry is not an oversight: the
|
|
86
|
+
payload stored in the webhook log of a `RELAY_ONLY` number is redacted field by field
|
|
87
|
+
and the redactor blanks any field that holds something, so an empty array would come
|
|
88
|
+
back as the "content unavailable" placeholder and be read as "there were attachments
|
|
89
|
+
and we hid them". `flowMedia` is also OPTIONAL, and absent is not `null` — absent is a
|
|
90
|
+
backend older than the field, which the parser accepts rather than rejecting every
|
|
91
|
+
event from an older deployment over one field it cannot read.
|
|
92
|
+
- **No `cdn_url` and no encryption material travel**, in either shape. Meta derives one
|
|
93
|
+
AES key **per file** and ships it beside the reference; forwarding either would put the
|
|
94
|
+
key that opens your customer's document into your webhook and into its logs.
|
|
95
|
+
|
|
96
|
+
The two shapes are similar and not equal — `media` carries `sizeBytes` and `flowMedia`
|
|
97
|
+
does not, so do not read one off the other — and `fileName` can be the FIELD's name
|
|
98
|
+
rather than a file name: a photo taken in the camera arrives without one and the field's
|
|
99
|
+
key is substituted, indistinguishably from a device that reported that name. Both element
|
|
100
|
+
types are exported by name — `FlowResponseMedia` for `media`, `FlowResponseMediaAttachment`
|
|
101
|
+
for `flowMedia` — so neither has to be reached by indexing into its container.
|
|
102
|
+
|
|
103
|
+
`parseCustomerWebhook` was widened in the same change. It had to be: `z.object` strips
|
|
104
|
+
keys it was not told about, so a `flowMedia` declared in the types and absent from the
|
|
105
|
+
schema would not fail — it would VANISH, and the integrator would see a submission with
|
|
106
|
+
no attachments instead of an error saying the SDK was behind.
|
|
107
|
+
|
|
108
|
+
## 0.8.0
|
|
109
|
+
|
|
110
|
+
⛔ **This release is the first one npm has seen since `0.5.0`.** `0.6.0` and `0.7.0` were
|
|
111
|
+
bumped in the repository and never published — the commit that set `0.7.0` even announced
|
|
112
|
+
the jump as done. Everything those two versions carried arrives here, at once, including a
|
|
113
|
+
breaking change. Read the whole entry before upgrading, not just the last section.
|
|
114
|
+
|
|
115
|
+
### Breaking
|
|
116
|
+
|
|
117
|
+
- **`client.projects` is gone.** The `/v1/projects` endpoint was withdrawn; the accessor had
|
|
118
|
+
already stopped doing anything before it was removed. Delete the call — there is no
|
|
119
|
+
replacement, because there is no longer a resource behind it. (Landed in the commit that
|
|
120
|
+
set `0.7.0`; published for the first time here.)
|
|
121
|
+
|
|
122
|
+
### Added
|
|
123
|
+
|
|
124
|
+
- **WhatsApp Flows, end to end.** `client.flows` — list, create, update, publish, deprecate,
|
|
125
|
+
and `uploadJson()` for the Flow JSON itself. `flowJsonValidationErrors(err)` reads Meta's
|
|
126
|
+
refusal list out of the error `uploadJson()` throws; that list is reachable nowhere else,
|
|
127
|
+
and without it a rejected upload is an opaque 400.
|
|
128
|
+
- **`flow.response_received`** in the webhook parser: the answers of a submitted Flow form.
|
|
129
|
+
META numbers only. Two things to know before you write the handler — the number field is
|
|
130
|
+
**`whatsappNumberId`, not `numberId`** (same value, different name on the wire), and
|
|
131
|
+
**`response` and `responseRaw` are mutually exclusive**: when the submission parsed you get
|
|
132
|
+
`response` and `responseRaw: null`, and when it did not you get the raw string, which is
|
|
133
|
+
then the only copy of the answer that exists anywhere.
|
|
134
|
+
- **`CUSTOMER_WEBHOOK_EVENTS`** — every event the parser accepts, derived from the parser's
|
|
135
|
+
own union. Until now the only way to enumerate them was to read the `.d.ts` and transcribe
|
|
136
|
+
the union by hand, which is exactly the transcription that drifted in this package's own
|
|
137
|
+
README.
|
|
138
|
+
- **Messages**: the operational log (`list`, with direction/status filters), conversation
|
|
139
|
+
history, group messages, unread, mark-as-read, and typing indicators.
|
|
140
|
+
- **Numbers**: create a Meta number, check numbers, logout, restore, purge, and the
|
|
141
|
+
portfolio tier as a field of its own.
|
|
142
|
+
- **Templates**: create, update and delete, with category and examples.
|
|
143
|
+
- **Sticker** as a message type on send.
|
|
144
|
+
- `UnprocessableEntityError` for 422.
|
|
145
|
+
|
|
146
|
+
### Fixed
|
|
147
|
+
|
|
148
|
+
- The README enumerated the parser's events by hand and had already drifted:
|
|
149
|
+
`flow.response_received` was parseable and undocumented. The list is now generated from the
|
|
150
|
+
union and a test compares the two, so the next addition updates both or fails the build.
|
|
151
|
+
|
|
152
|
+
## 0.7.0 / 0.6.0
|
|
153
|
+
|
|
154
|
+
Never published to npm. Their contents ship in `0.8.0`.
|
package/README.md
CHANGED
|
@@ -38,21 +38,28 @@ const history = await client.messages.history({
|
|
|
38
38
|
console.log(history.total, history.messages[0]?.providerTimestamp);
|
|
39
39
|
```
|
|
40
40
|
|
|
41
|
-
##
|
|
42
|
-
|
|
43
|
-
These endpoints create resources within the scope (project + environment) of the current `apiKey`.
|
|
44
|
-
|
|
45
|
-
### Projects
|
|
41
|
+
## Client options
|
|
46
42
|
|
|
47
43
|
```ts
|
|
48
|
-
const
|
|
49
|
-
|
|
50
|
-
|
|
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",
|
|
51
50
|
});
|
|
52
51
|
|
|
53
|
-
|
|
52
|
+
// Per-call override — returns a sibling client, never mutates this one:
|
|
53
|
+
await client.withNumber("wn_2").chatwoot.get();
|
|
54
54
|
```
|
|
55
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
|
+
|
|
56
63
|
### API keys
|
|
57
64
|
|
|
58
65
|
```ts
|
|
@@ -62,11 +69,31 @@ const regenerated = await client.apiKeys.regenerateNumber("wn_1");
|
|
|
62
69
|
console.log(regenerated.key); // shown only once
|
|
63
70
|
|
|
64
71
|
const keys = await client.apiKeys.list();
|
|
65
|
-
//
|
|
66
|
-
|
|
67
|
-
|
|
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
|
|
68
89
|
```
|
|
69
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
|
+
|
|
70
97
|
### Numbers (WhatsApp)
|
|
71
98
|
|
|
72
99
|
```ts
|
|
@@ -95,6 +122,10 @@ console.log(detail.settings.appliesTo.advanced); // "evolution-go" | "none"
|
|
|
95
122
|
// stop replaying the device's old messages into the webhook on every reconnect
|
|
96
123
|
await client.numbers.updateSettings(id, { webhookHistoricalMessages: false });
|
|
97
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
|
+
|
|
98
129
|
await client.numbers.update(id, {
|
|
99
130
|
piiMode: "STORE_X_DAYS",
|
|
100
131
|
piiRetentionDays: 30,
|
|
@@ -102,8 +133,13 @@ await client.numbers.update(id, {
|
|
|
102
133
|
});
|
|
103
134
|
```
|
|
104
135
|
|
|
105
|
-
`historyImportEnabled`
|
|
106
|
-
|
|
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
|
|
107
143
|
(`ignoreGroups`, not the v2 `groupsIgnore`); passing `null` resets one to the
|
|
108
144
|
provider default. On a Meta number they are stored but never applied — which is
|
|
109
145
|
what `settings.appliesTo.advanced === "none"` tells you.
|
|
@@ -113,6 +149,95 @@ They are also pushed to the number's connected instances; `settingsSync`
|
|
|
113
149
|
disconnected instance still keeps the persisted value and picks it up on its next
|
|
114
150
|
provisioning.
|
|
115
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
|
+
});
|
|
239
|
+
```
|
|
240
|
+
|
|
116
241
|
## Analytics
|
|
117
242
|
|
|
118
243
|
```ts
|
|
@@ -200,14 +325,29 @@ await client.calls.play(call.id, "https://cdn.example.com/ivr-greeting.mp3");
|
|
|
200
325
|
const session = await client.calls.realtimeSession(call.id, "talk");
|
|
201
326
|
```
|
|
202
327
|
|
|
203
|
-
##
|
|
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:
|
|
204
332
|
|
|
205
333
|
```ts
|
|
206
|
-
import { parseCustomerWebhook } from "@pilot-status/sdk";
|
|
334
|
+
import { parseCustomerWebhook, verifyWebhookSignature } from "@pilot-status/sdk";
|
|
207
335
|
|
|
208
336
|
export async function handler(req: Request) {
|
|
209
|
-
|
|
210
|
-
const
|
|
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));
|
|
211
351
|
|
|
212
352
|
if (event.event === "message.failed") {
|
|
213
353
|
console.log(event.data.errorMessage);
|
|
@@ -217,13 +357,35 @@ export async function handler(req: Request) {
|
|
|
217
357
|
}
|
|
218
358
|
```
|
|
219
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
|
+
|
|
220
365
|
Notes:
|
|
221
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.
|
|
222
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.
|
|
223
368
|
- `message.received` includes `fromMe` (boolean).
|
|
224
369
|
- `message.group` is delivered for inbound group messages (includes `groupName`).
|
|
225
370
|
- `message.newsletter` is delivered for inbound WhatsApp channel / newsletter messages (`@newsletter`, includes `newsletterId`).
|
|
226
|
-
- 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, flowMedia, submitted } }`. 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.
|
|
373
|
+
- **Files attached inside a Flow form** (`PhotoPicker` / `DocumentPicker`) are **not in `response`**. A media picker requires a `data_exchange` endpoint, so what `response` holds for such a field is a reference to Meta's CDN — which Meta deletes after 20 days. The re-hosted copy is the only way to reach the bytes, and it is published in the two places the answers are readable, in shapes that are similar and **not** the same:
|
|
374
|
+
- On the event, `data.flowMedia` — `null` when nothing was attached, and **never `[]`**. The asymmetry is deliberate: the payload stored in the webhook log of a `RELAY_ONLY` number is redacted field by field, and the redactor blanks any field that holds something. An empty array holds something, so it would be replaced by the "content unavailable" placeholder and read back as *"there were attachments and we hid them"*; `null` passes through untouched. `flowMedia` is also **optional**, and absent is not `null` — absent is a backend older than the field, which the parser accepts rather than rejecting every event from an older deployment over one field it cannot read.
|
|
375
|
+
- On `client.flows.listResponses(flowId)` (`GET /v1/flows/{id}/responses`), `responses[].media` — **always an array**, empty when nothing was attached.
|
|
376
|
+
- Both attachment shapes carry `field`, `fileName`, `mimeType`, `status` and `url`. The `listResponses()` one **also carries `sizeBytes`; the event does not** — do not read one shape off the other. Both element types are exported by name, and the name says which shape you have: `import type { FlowResponseMedia, FlowResponseMediaAttachment } from "@pilot-status/sdk"` — `FlowResponseMedia` is the `listResponses()` element (the one with `sizeBytes`), `FlowResponseMediaAttachment` the event one.
|
|
377
|
+
- ⛔ **`url` exists only when `status === "STORED"`** — it is `null` on `PENDING` and on `FAILED`. The re-host is asynchronous, so the transfer is often still in flight at the instant the event is dispatched: a handler that reads `{ status: "PENDING", url: null }` is reading the ordinary case, not a failure. The final URL comes from `client.flows.listResponses(flowId)`. Publishing an optimistic URL in the event would hand you a link that 404s.
|
|
378
|
+
- ⛔ **No `cdn_url` and no encryption material travel**, in either shape. Meta derives one AES key **per file** and ships it beside the reference; forwarding either would put the key that opens your customer's document into your webhook — and into its logs, and into anything downstream of them.
|
|
379
|
+
- ⚠️ **`fileName` may be the FIELD's name rather than a file name.** A photo taken in the camera arrives without one, and the field's key is substituted so the stored object still has a readable name. From the outside the two cases are indistinguishable.
|
|
380
|
+
- `field` is whatever the Flow's **author** named the component in the Flow JSON — `photo_picker` is Meta's documentation example, not a reserved word. Attachments are matched by shape, never by name.
|
|
381
|
+
- **What the person TYPED, screen by screen** — `data.submitted` on the event, `responses[].submitted` on `client.flows.listResponses(flowId)`. ⛔ **It is not `response`.** `response` is what *your* endpoint returned (the `extension_message_response.params` of the final exchange); `submitted` is what the respondent's device sent on the way there, captured as Pilot Status relayed each screen. Before this field, a `data_exchange` Flow's answers went to your endpoint and were kept nowhere — a real submission produced an event whose `response` was `{"flow_token": "…"}` and nothing else.
|
|
382
|
+
- ⛔ **A list, never merged into one object.** Each `data_exchange` carries only the fields of ITS screen, and merging would let the last field with a repeated name win in silence. A screen that appears **twice is not a duplicate** — someone walked back and submitted it again, and both answers are there, in order.
|
|
383
|
+
- Each entry is `{ screen, at, data, omitted }`. `screen` is `null` when Meta named none; `at` is ISO-8601, when the exchange was relayed. **`data` and `omitted` are complementary** — one is `null` exactly when the other is not, never both, never neither.
|
|
384
|
+
- ⛔ **Nothing is ever truncated in silence.** An exchange too large to store keeps its place and its screen name and says `omitted: "DATA_TOO_LARGE"`; a form with more exchanges than are kept ends with an entry saying `omitted: "LIMIT_REACHED"`, which is always the last one. `"UNREADABLE"` means the stored bytes no longer parse. ⚠️ Treat `omitted` as an open **string**, not a union of those three: a reason your SDK version has not heard of must still arrive.
|
|
385
|
+
- ⛔ **Only `data_exchange` produces an entry**, so the list is SHORTER than the number of calls your endpoint received. `INIT` carries the form's initial state (the params seeded at send time) and `BACK` is a navigation gesture; neither is something the person filled in.
|
|
386
|
+
- ⛔ **Nothing of what YOUR endpoint answered is captured** — `extension_message_response` never appears anywhere in Pilot Status. What you returned is already `response` on the same event.
|
|
387
|
+
- The two shapes differ in exactly one way, the same way the attachment shapes do: on the event `submitted` is **`null`, never `[]`**, when nothing was captured (the redactor that blanks a `RELAY_ONLY` log replaces anything non-empty, so `[]` would read as *"there were answers and we hid them"*), and it is also **optional** — absent means a backend older than the field. On `listResponses()` it is **always an array**.
|
|
388
|
+
- ⚠️ **Empty is not "they typed nothing".** A NAVIGATE-only Flow never calls an endpoint at all — its answers are wholly in `response` — and a number configured to relay and keep nothing captures none. The element type is exported: `import type { FlowSubmittedExchange } from "@pilot-status/sdk"`, and it is the SAME type on both surfaces.
|
|
227
389
|
- `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`.
|
|
228
390
|
|
|
229
391
|
## 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 {
|
|
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
|
package/dist/client.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","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;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,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 {
|
|
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:
|
|
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
|
package/dist/client.js.map
CHANGED
|
@@ -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,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