@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.
Files changed (124) hide show
  1. package/CHANGELOG.md +154 -0
  2. package/README.md +181 -19
  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 +6 -0
  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 +43 -1
  56. package/dist/resources/messages.d.ts.map +1 -1
  57. package/dist/resources/messages.js +113 -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 +63 -1
  64. package/dist/resources/numbers.d.ts.map +1 -1
  65. package/dist/resources/numbers.js +101 -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 +993 -23
  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 +109 -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 +144 -2
  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/dist/types.d.ts CHANGED
@@ -1,10 +1,39 @@
1
1
  export type MessageStatus = "QUEUED" | "SENT" | "DELIVERED" | "FAILED" | "READ" | "CANCELED";
2
- export type ButtonType = "QUICK_REPLY" | "URL" | "PHONE_NUMBER" | "COPY_CODE";
2
+ /**
3
+ * The API accepts BOTH spellings. The uppercase set is the current one (aligned with
4
+ * the Meta Cloud API); the lowercase set is kept for backward compatibility and is
5
+ * still what most of the server's own tests send — see `buttonSchema` in
6
+ * `packages/shared/src/validation.ts`, e.g. `z.enum(["QUICK_REPLY", "reply"])`.
7
+ * Declaring only half of it made valid calls fail to type-check.
8
+ */
9
+ export type ButtonType = "QUICK_REPLY" | "URL" | "PHONE_NUMBER" | "COPY_CODE" | "reply" | "url" | "call" | "copy";
3
10
  export type Button = {
4
11
  type: ButtonType;
5
- label: string;
12
+ /**
13
+ * The button's visible text. THIS is the field the platform reads.
14
+ *
15
+ * ⚠️ Do not use `label`. It was the only text field this type ever declared, and
16
+ * nothing on the server or in the providers reads it: the Meta adapter builds the
17
+ * button from `displayText` (`packages/whatsapp-provider/src/meta/message.ts`), and
18
+ * the request schema only passes `label` through untouched. A button sent with
19
+ * `label` alone therefore arrived with an EMPTY title. The SDK now copies `label`
20
+ * into `displayText` when you send one, so existing code keeps working, but new
21
+ * code should set `displayText`.
22
+ */
23
+ displayText?: string;
24
+ /** Alias the request schema also accepts for {@link displayText}. */
25
+ text?: string;
26
+ /**
27
+ * @deprecated Never read by the platform — see {@link displayText}. Still accepted
28
+ * and mapped for you, so old code does not break.
29
+ */
30
+ label?: string;
31
+ /** Payload id echoed back on the reply. Quick-reply buttons only. */
32
+ id?: string;
6
33
  url?: string;
7
34
  phone_number?: string;
35
+ phoneNumber?: string;
36
+ copyCode?: string;
8
37
  example?: string[];
9
38
  };
10
39
  export type MarketingOptions = {
@@ -36,6 +65,80 @@ export type RemotePairingConnectResult = {
36
65
  qrcodeBase64: string | null;
37
66
  pairingCode: string | null;
38
67
  };
68
+ /** One row of an interactive list. `rowId` is what comes back when the customer picks it. */
69
+ export type ListRow = {
70
+ title: string;
71
+ description?: string;
72
+ rowId?: string;
73
+ };
74
+ /** A section of an interactive list. At most 10 rows across ALL sections. */
75
+ export type ListSection = {
76
+ title?: string;
77
+ rows: ListRow[];
78
+ };
79
+ /**
80
+ * Single-select interactive list. `text` is the body; the button opens the sections.
81
+ *
82
+ * Free-form only: it cannot travel with `templateId`, and it needs the 24-hour window
83
+ * open like any non-template message.
84
+ */
85
+ export type ListMessage = {
86
+ buttonText: string;
87
+ sections: ListSection[];
88
+ };
89
+ /** A button on a carousel card. */
90
+ export type CarouselCardButton = {
91
+ type: "QUICK_REPLY" | "URL";
92
+ text: string;
93
+ url?: string;
94
+ payload?: string;
95
+ };
96
+ /** One carousel card. Every card carries its own media — there is no shared header. */
97
+ export type CarouselCard = {
98
+ media: {
99
+ url: string;
100
+ format: "IMAGE" | "VIDEO";
101
+ };
102
+ body?: string;
103
+ buttons?: CarouselCardButton[];
104
+ };
105
+ /** Ad-hoc media carousel. `text` is the body that goes above the cards. */
106
+ export type CarouselMessage = {
107
+ cardTemplate: {
108
+ body?: string;
109
+ buttons?: Array<{
110
+ type: string;
111
+ }>;
112
+ };
113
+ cards: CarouselCard[];
114
+ };
115
+ /**
116
+ * A WhatsApp Flow chosen AT SEND TIME, instead of being fixed in an approved template.
117
+ *
118
+ * ⛔ Requires the 24-hour window to be open, and that is not a soft requirement: with the
119
+ * window closed Meta answers `HTTP 200` with a `wamid` and silently discards the message —
120
+ * no error, no failure status, nothing in any log. Pilot Status refuses the send with
121
+ * `FLOW_WINDOW_CLOSED` rather than let it vanish. To start a conversation, use a template
122
+ * with a FLOW button instead: templates do not depend on the window.
123
+ *
124
+ * There is no `flowToken` field on purpose. The token is minted per message by Pilot
125
+ * Status and is what ties the customer's answers back to this send; one supplied by the
126
+ * caller would let an account claim another account's answers, so it is refused.
127
+ */
128
+ export type FlowMessage = {
129
+ /** The Flow id ON META, not the Pilot Status row id. */
130
+ flowId: string;
131
+ /** Label on the button that opens the Flow. Up to 30 characters. */
132
+ cta: string;
133
+ /** `navigate` (default) opens a screen; `data_exchange` calls your endpoint. */
134
+ action?: "navigate" | "data_exchange";
135
+ /** Entry screen. Omit it and Pilot Status resolves the Flow's first screen. */
136
+ screen?: string;
137
+ /** Initial data for the first screen. */
138
+ data?: Record<string, unknown>;
139
+ /** `published` (default) or `draft` — `draft` reaches a real person too. */
140
+ mode?: "published" | "draft";
141
+ };
39
142
  export type SendMessageInput = {
40
143
  templateId?: string;
41
144
  destinationNumber?: string;
@@ -47,8 +150,17 @@ export type SendMessageInput = {
47
150
  deliverUntil?: string;
48
151
  marketingOptions?: MarketingOptions;
49
152
  media?: string;
50
- mediaType?: "image" | "video" | "document" | "audio" | "voice";
153
+ mediaType?: "image" | "video" | "document" | "audio" | "voice" | "sticker";
51
154
  buttons?: Button[];
155
+ /**
156
+ * Interactive single-select list. Mutually exclusive with `templateId`, `carousel`,
157
+ * `flow`, `buttons`, `header` and a direct media send.
158
+ */
159
+ list?: ListMessage;
160
+ /** Ad-hoc media carousel. Same exclusions as `list`. */
161
+ carousel?: CarouselMessage;
162
+ /** Dynamic Flow — see {@link FlowMessage}. Same exclusions as `list`. */
163
+ flow?: FlowMessage;
52
164
  text?: string;
53
165
  header?: SendMessageHeader;
54
166
  footer?: string;
@@ -91,17 +203,6 @@ export type DashboardStats = {
91
203
  read: number;
92
204
  };
93
205
  };
94
- export type Project = {
95
- id: string;
96
- name: string;
97
- slug: string;
98
- description: string;
99
- createdAt: string;
100
- };
101
- export type CreateProjectInput = {
102
- name: string;
103
- description?: string;
104
- };
105
206
  export type ApiKeyCreated = {
106
207
  id: string;
107
208
  name: string;
@@ -150,6 +251,12 @@ export type NumberApiKeyReveal = {
150
251
  key: string | null;
151
252
  revealable: boolean;
152
253
  };
254
+ /**
255
+ * What `GET /v1/api-keys` ACTUALLY returns — one shape or the other depending on
256
+ * the credential's scope, never both. Discriminate on `revealable`, which only
257
+ * exists on the tenant-scoped variant.
258
+ */
259
+ export type ApiKeyListResult = ApiKeyListItem[] | NumberApiKeyReveal[];
153
260
  /**
154
261
  * The new usable key returned by `POST /v1/api-keys` (tenant-scoped) when
155
262
  * regenerating the default key of one number. The raw `key` is shown only once.
@@ -198,13 +305,23 @@ export type CreateNumberInput = {
198
305
  name: string;
199
306
  number: string;
200
307
  linkToApiKey?: boolean;
308
+ /**
309
+ * Per-number settings the number is BORN with — same block as
310
+ * {@link NumberSettingsInput}.
311
+ *
312
+ * This is the only place `historyImportEnabled: true` can be asked for: the
313
+ * default is `false`, the provider dumps the device history in a burst right
314
+ * after the connection, and there is no way to request it later.
315
+ */
316
+ settings?: NumberSettingsInput;
201
317
  };
202
318
  /**
203
319
  * Per-number settings — `PATCH /v1/numbers/{id}` and the `settings` block of
204
320
  * `GET /v1/numbers/{id}`. There is NO `POST /v1/numbers/{id}/settings`, and
205
321
  * Evolution's `syncFullHistory` has no equivalent here: use `historyImportEnabled`.
206
322
  *
207
- * The `history*` pair applies to every provider. The rest are the Evolution GO
323
+ * `historyImportEnabled`, `webhookHistoricalMessages` and `ignoreNewsletters`
324
+ * are platform-level and apply to every provider. The rest are the Evolution GO
208
325
  * `advancedSettings`, in the GO dialect (`ignoreGroups` — NOT the v2
209
326
  * `groupsIgnore`); they are stored on a Meta number but never applied, which is
210
327
  * what `appliesTo.advanced === "none"` tells you.
@@ -212,7 +329,14 @@ export type CreateNumberInput = {
212
329
  * `null` on a GO field means "reset to the provider default", not `false`.
213
330
  */
214
331
  export type NumberSettingsInput = {
215
- /** Import the provider's on-connect history dump into the chat. Default true. */
332
+ /**
333
+ * Import the provider's on-connect history dump into the chat. Default
334
+ * **false** — a number starts existing at the moment it connected.
335
+ *
336
+ * ⚠️ Set it on `numbers.create()`, not afterwards. The provider hands the
337
+ * history over in a burst right after the connection, and nothing can ask for
338
+ * it again: a `create` followed by an `updateSettings` races that burst.
339
+ */
216
340
  historyImportEnabled?: boolean;
217
341
  /**
218
342
  * Deliver historical (backfilled) messages to your webhooks. Default FALSE:
@@ -221,6 +345,19 @@ export type NumberSettingsInput = {
221
345
  * `messages.history()` instead.
222
346
  */
223
347
  webhookHistoricalMessages?: boolean;
348
+ /**
349
+ * Drop WhatsApp CHANNEL (`@newsletter`) posts on ingestion: they become no
350
+ * conversation, no stored message and no webhook. Default FALSE — whoever
351
+ * already receives channels keeps receiving them.
352
+ *
353
+ * Asymmetric with `ignoreGroups` on purpose, and the asymmetry is the
354
+ * provider's, not ours: Evolution GO kills a group event inside its own
355
+ * handler, before it ever leaves the provider. There is no upstream gate for
356
+ * `@newsletter`, so a channel post always arrives and the only place it can be
357
+ * refused is on our side. Channels never reach a Meta number, where this field
358
+ * is accepted and stored but has nothing to drop.
359
+ */
360
+ ignoreNewsletters?: boolean;
224
361
  /** Keep the WhatsApp presence permanently online. Evolution GO only. */
225
362
  alwaysOnline?: boolean | null;
226
363
  /** Auto-reject incoming calls. Evolution GO only. */
@@ -275,7 +412,10 @@ export type NumberDetail = {
275
412
  updatedAt: string;
276
413
  health: {
277
414
  qualityRating: string | null;
415
+ /** The number's OWN messaging limit tier. `null` when Meta reports none for it. */
278
416
  messagingLimitTier: string | null;
417
+ /** The Business-Portfolio limit — a different thing, and usually higher. */
418
+ portfolioMessagingLimitTier: string | null;
279
419
  metaStatus: string | null;
280
420
  code: string | null;
281
421
  reason: string | null;
@@ -412,32 +552,140 @@ export type RemotePairingResult = {
412
552
  instance: WhatsAppNumberInstance;
413
553
  linkedApiKeyId: string | null;
414
554
  };
555
+ export type TemplateCategory = "OTP" | "UTILITY" | "MARKETING";
556
+ /**
557
+ * Only `sendable: true` can be passed to `messages.send()`. On a Meta number that
558
+ * means `source: "META"` + `metaStatus: "APPROVED"`.
559
+ */
415
560
  export type TemplateListItem = {
416
561
  id: string;
417
562
  name: string;
418
563
  category: string;
564
+ source?: "META" | "PILOT_STATUS";
565
+ metaStatus?: string | null;
566
+ metaLanguage?: string | null;
567
+ sendable?: boolean;
419
568
  latestVersion?: {
420
569
  variables?: string[];
421
570
  };
422
571
  };
423
- export type TemplateDetail = {
424
- id: string;
572
+ export type TemplateDetail = TemplateListItem;
573
+ /**
574
+ * One NON-EMPTY example per `{{variable}}` in the body, keyed by the variable
575
+ * name. Without it the API rejects with `TEMPLATE_EXAMPLES_REQUIRED`.
576
+ */
577
+ export type TemplateExamples = Record<string, string>;
578
+ export type CreateTemplateInput = {
425
579
  name: string;
426
- category: string;
427
- latestVersion?: {
428
- variables?: string[];
429
- };
580
+ /**
581
+ * Plain text with `{{variables}}`, or the full template JSON (header
582
+ * TEXT/IMAGE/VIDEO/DOCUMENT, body, footer, up to 10 buttons — at most 2 URL and
583
+ * 1 PHONE_NUMBER).
584
+ */
585
+ body: string;
586
+ examples: TemplateExamples;
587
+ /** Default `UTILITY`. */
588
+ category?: TemplateCategory;
589
+ /** Derived from the body when omitted. */
590
+ variables?: string[];
591
+ /** Meta language code, e.g. `pt_BR` (default `pt_BR`). */
592
+ language?: string;
593
+ };
594
+ export type UpdateTemplateInput = {
595
+ body: string;
596
+ examples: TemplateExamples;
597
+ };
598
+ export type TemplateDeleteResult = {
599
+ success: boolean;
430
600
  };
431
601
  export type GroupListItem = {
432
602
  id: string;
433
603
  subject: string;
434
604
  };
605
+ export type GroupParticipant = {
606
+ id: string;
607
+ admin?: string | null;
608
+ name?: string | null;
609
+ };
610
+ export type GroupDetail = {
611
+ id: string;
612
+ subject: string;
613
+ owner?: string | null;
614
+ creation?: number | null;
615
+ participants?: GroupParticipant[];
616
+ };
617
+ export type CreateGroupInput = {
618
+ subject: string;
619
+ /** Phone numbers as E.164 digits — not JIDs. */
620
+ participants?: string[];
621
+ };
622
+ export type GroupActionResult = {
623
+ success: boolean;
624
+ };
625
+ export type GroupInviteResult = {
626
+ inviteCode?: string | null;
627
+ inviteUrl?: string | null;
628
+ };
629
+ export type GroupPinAction = "pin" | "unpin";
435
630
  export type NewsletterListItem = {
436
631
  id: string;
437
632
  name: string;
438
633
  };
634
+ /**
635
+ * ⚠️ `DELETE /v1/numbers/{id}` is a 30-day SOFT delete. `restorableUntil` is the
636
+ * end of the window in which `numbers.restore()` still works; it was not returned
637
+ * by the version where the delete was destructive, hence optional.
638
+ */
439
639
  export type DeleteNumberResult = {
440
- success: boolean;
640
+ ok?: boolean;
641
+ success?: boolean;
642
+ /** ISO 8601 — until when restoring is still possible. */
643
+ restorableUntil?: string;
644
+ };
645
+ /** `requiresReconnect` is always `true`: restoring gives back the line, not the session. */
646
+ export type NumberRestoreResult = {
647
+ ok: boolean;
648
+ requiresReconnect: boolean;
649
+ };
650
+ export type NumberPurgeResult = {
651
+ ok: boolean;
652
+ };
653
+ export type NumberLogoutResult = {
654
+ ok?: boolean;
655
+ success?: boolean;
656
+ results?: Array<{
657
+ instanceId: string;
658
+ ok: boolean;
659
+ error?: string;
660
+ }>;
661
+ };
662
+ /** Pass `numbers` (up to 20) OR `number`. */
663
+ export type CheckNumbersInput = {
664
+ numbers?: string[];
665
+ number?: string;
666
+ };
667
+ export type CheckNumbersResult = {
668
+ results: Array<{
669
+ /** What you sent. */
670
+ input: string;
671
+ exists: boolean;
672
+ /** The digits REGISTERED on WhatsApp — use this one when sending. `null` when it does not exist. */
673
+ number: string | null;
674
+ name?: string | null;
675
+ }>;
676
+ };
677
+ /** Your own Cloud API credentials — the server-side path of the official onboarding. */
678
+ export type CreateMetaNumberInput = {
679
+ name: string;
680
+ number: string;
681
+ metaPhoneId: string;
682
+ metaWabaId: string;
683
+ metaAccessToken: string;
684
+ metaAppSecret: string;
685
+ metaAppId: string;
686
+ linkToApiKey?: boolean;
687
+ /** Points the WABA's webhooks at Pilot Status (`POST /{waba}/subscribed_apps`). */
688
+ routeWebhooksToPilot?: boolean;
441
689
  };
442
690
  export type MediaDownloadResult = {
443
691
  base64: string;
@@ -551,4 +799,726 @@ export type CallRealtimeSessionResult = {
551
799
  token: string;
552
800
  expiresInSeconds: number;
553
801
  };
802
+ /** `"IN"` = received, `"OUT"` = sent. Distinct from the chat's `INBOUND`/`OUTBOUND`. */
803
+ export type MessageLogDirection = "IN" | "OUT";
804
+ /**
805
+ * One row of the message LOG (`GET /v1/messages`) — the operational trail, not
806
+ * the conversation text. Rows covered by the number's PII policy come back with
807
+ * `content`/`from`/`to` null and `redacted: true`.
808
+ */
809
+ export type MessageLogEntry = {
810
+ id: string;
811
+ correlationId: string | null;
812
+ direction: MessageLogDirection;
813
+ from: string | null;
814
+ to: string | null;
815
+ content: string | null;
816
+ template: string | null;
817
+ status: string;
818
+ errorCode: string | null;
819
+ errorMessage: string | null;
820
+ /** Which surface it came in through (`"API"`, `"APP"`, …). `null` when not applicable. */
821
+ origin: string | null;
822
+ /** Whether the 24h window was open at send time. `null` on received messages. */
823
+ serviceWindowOpenAtSend: boolean | null;
824
+ createdAt: string | null;
825
+ sentAt: string | null;
826
+ deliveredAt: string | null;
827
+ readAt: string | null;
828
+ externalMessageId: string | null;
829
+ redacted?: true;
830
+ };
831
+ export type MessageListParams = {
832
+ page?: number;
833
+ /** Default 30, max 100. */
834
+ pageSize?: number;
835
+ /**
836
+ * Statuses comma-separated inside a single string — `"SENT,DELIVERED"`, not an
837
+ * array. That is the format the server reads.
838
+ */
839
+ status?: string;
840
+ direction?: "in" | "out";
841
+ startDate?: string;
842
+ endDate?: string;
843
+ /** Phone number in any format, or a template name. */
844
+ search?: string;
845
+ /** Template id or name. */
846
+ templateId?: string;
847
+ /** State of the 24h window at send time. */
848
+ window?: "open" | "closed";
849
+ };
850
+ export type MessageListResult = {
851
+ data: MessageLogEntry[];
852
+ page: number;
853
+ pageSize: number;
854
+ total: number;
855
+ totalPages: number;
856
+ /** Only on a `RELAY_ONLY` number, explaining why every row came back redacted. */
857
+ notice?: string;
858
+ };
859
+ export type GroupMessagesParams = MessageHistoryParams;
860
+ export type GroupMessagesResult = MessageHistoryResult;
861
+ export type UnreadMessagesParams = {
862
+ page?: number;
863
+ pageSize?: number;
864
+ };
865
+ /**
866
+ * ⚠️ `total` is the REAL unread count (the same one the dashboard shows), not the
867
+ * size of `messages` — the list only carries the latest unread of each conversation.
868
+ */
869
+ export type UnreadMessagesResult = {
870
+ messages: ChatHistoryMessage[];
871
+ total: number;
872
+ page: number;
873
+ pageSize: number;
874
+ totalPages: number;
875
+ notice?: string;
876
+ };
877
+ /** `acked: false` with HTTP 200 is the normal "there was nothing to acknowledge" case. */
878
+ export type MarkReadResult = {
879
+ ok: boolean;
880
+ acked: boolean;
881
+ /** `"NO_INBOUND_MESSAGE"` | `"PII_RELAY_ONLY"` when `acked` is false. */
882
+ reason?: string;
883
+ };
884
+ export type TypingState = "typing" | "recording" | "paused";
885
+ export type TypingInput = {
886
+ to: string;
887
+ /** Default `"typing"`. */
888
+ state?: TypingState;
889
+ };
890
+ /**
891
+ * `effectiveState` is what the provider ACTUALLY displayed: on a META number
892
+ * `"recording"` becomes `"typing"` and `"paused"` is a no-op. Branch on this, not
893
+ * on what you asked for.
894
+ */
895
+ export type TypingResult = {
896
+ ok: boolean;
897
+ sent: boolean;
898
+ provider: string;
899
+ effectiveState: string;
900
+ note?: string;
901
+ };
902
+ export type ConversationListParams = {
903
+ /** These filter on the timestamp of the conversation's LAST message. */
904
+ startDate?: string;
905
+ endDate?: string;
906
+ page?: number;
907
+ pageSize?: number;
908
+ };
909
+ export type ConversationSummary = {
910
+ id: string;
911
+ peerPhone: string | null;
912
+ peerName: string | null;
913
+ lastMessageAt: string | null;
914
+ lastInboundAt: string | null;
915
+ unreadCount: number;
916
+ redacted?: true;
917
+ };
918
+ export type ConversationListResult = {
919
+ conversations: ConversationSummary[];
920
+ total: number;
921
+ page: number;
922
+ pageSize: number;
923
+ totalPages: number;
924
+ notice?: string;
925
+ };
926
+ /**
927
+ * `"META_24H"` = Meta's rule genuinely applies. `"NONE"` = web/unofficial number,
928
+ * where the restriction does not exist and `open` is always `true`.
929
+ */
930
+ export type ServiceWindowType = "META_24H" | "NONE";
931
+ export type ServiceWindowResult = {
932
+ open: boolean;
933
+ windowType: ServiceWindowType;
934
+ /** ISO 8601, or `null` when there was never an inbound message. */
935
+ lastInboundAt: string | null;
936
+ /** `lastInboundAt` + 24h. */
937
+ expiresAt: string | null;
938
+ };
939
+ export type MetaPricingParams = {
940
+ /** ISO-3166 alpha-2 (BR, GB…), `NAM`, or a regional bucket (AFR, APAC, LATAM…). */
941
+ market?: string;
942
+ /** ISO 4217. */
943
+ currency?: string;
944
+ /** `marketing` | `utility` | `authentication` | `service` | `authentication_international`. */
945
+ category?: string;
946
+ /** Includes `volumeTiers` in the response. */
947
+ tiers?: boolean;
948
+ };
949
+ /**
950
+ * Without the three parameters, this is the catalog (markets/currencies/categories).
951
+ * With them, the price. The body is a passthrough of the rate card Meta publishes,
952
+ * so it is deliberately left as an open record — it is not the account's invoice.
953
+ */
954
+ export type MetaPricingResult = Record<string, unknown>;
955
+ /** The signing `secret` NEVER comes back here — only on creation, once, in the dashboard. */
956
+ export type Webhook = {
957
+ id: string;
958
+ name: string;
959
+ url: string;
960
+ /** `["*"]` = all of them. An EMPTY list = fires nothing. */
961
+ events: string[];
962
+ active: boolean;
963
+ lastTriggered: string | null;
964
+ whatsappNumberIds: string[];
965
+ whatsappInstanceIds: string[];
966
+ createdAt: string;
967
+ updatedAt: string;
968
+ };
969
+ export type CreateWebhookInput = {
970
+ url: string;
971
+ /** Default: the URL's hostname. */
972
+ name?: string;
973
+ /**
974
+ * Empty or omitted subscribes to NOTHING — there is no implicit subscribe-to-all.
975
+ * Use `["*"]` for all of them.
976
+ */
977
+ events?: string[];
978
+ /** Required with a tenant-scoped key when the client has no `whatsappNumberId`. */
979
+ whatsappNumberId?: string;
980
+ };
981
+ /** `events` REPLACES the whole list; it is not a merge. */
982
+ export type UpdateWebhookInput = {
983
+ name?: string;
984
+ url?: string;
985
+ /** `false` pauses the deliveries without deleting it. */
986
+ active?: boolean;
987
+ events?: string[];
988
+ };
989
+ export type WebhookDeleteResult = {
990
+ success: boolean;
991
+ };
992
+ export type WebhookLogsParams = {
993
+ /** 1–50. */
994
+ limit?: number;
995
+ /** Filters by a single event type. */
996
+ event?: string;
997
+ };
998
+ export type WebhookLogEntry = {
999
+ id: string;
1000
+ event: string;
1001
+ status: "SUCCESS" | "FAILED";
1002
+ statusCode: number | null;
1003
+ payload: unknown;
1004
+ response: string | null;
1005
+ durationMs: number | null;
1006
+ createdAt: string;
1007
+ };
1008
+ /** `null` on any field CLEARS the value; omitting it keeps the current one. */
1009
+ export type BrandingInput = {
1010
+ /** Must be https. */
1011
+ logoUrl?: string | null;
1012
+ /** `#RRGGBB`. */
1013
+ primaryColor?: string | null;
1014
+ backgroundColor?: string | null;
1015
+ companyName?: string | null;
1016
+ subtitle?: string | null;
1017
+ supportUrl?: string | null;
1018
+ defaultRedirectUrl?: string | null;
1019
+ hidePilotStatusBranding?: boolean;
1020
+ };
1021
+ export type BrandingResult = {
1022
+ branding: Record<string, unknown> | null;
1023
+ };
1024
+ export type EmbedSurface = "chat" | "connect";
1025
+ export type EmbedSessionInput = {
1026
+ surface: EmbedSurface;
1027
+ /** EXACT origins (`https://app.customer.com`), 1–20, with no path and no trailing slash. */
1028
+ allowedOrigins: string[];
1029
+ /** Required on `chat` with a tenant-scoped credential; ignored on `connect`. */
1030
+ whatsappNumberIds?: string[];
1031
+ brandingOverride?: BrandingInput;
1032
+ /** Max 3600. Default 900 (chat) / 1800 (connect). */
1033
+ ttlSeconds?: number;
1034
+ };
1035
+ export type EmbedSessionResult = {
1036
+ token: string;
1037
+ surface: EmbedSurface;
1038
+ whatsappNumberIds: string[] | null;
1039
+ allowedOrigins: string[];
1040
+ expiresAt: string;
1041
+ };
1042
+ export type CheckoutPurpose = "wallet_topup" | "add_card";
1043
+ export type CheckoutInput = {
1044
+ purpose: CheckoutPurpose;
1045
+ /** Required on `wallet_topup`, in the account's currency. */
1046
+ amount?: number;
1047
+ successUrl?: string;
1048
+ cancelUrl?: string;
1049
+ };
1050
+ /** Just a URL: nothing is charged until a human completes the payment on it. */
1051
+ export type CheckoutResult = {
1052
+ url: string;
1053
+ };
1054
+ export type ExtraNumbersPreview = {
1055
+ quantity: number;
1056
+ /** `true` when the purchase would convert a FREE plan into On Demand. */
1057
+ requiresConversion?: boolean;
1058
+ [key: string]: unknown;
1059
+ };
1060
+ /** With no card on file you get a `checkoutUrl` instead of a charge. */
1061
+ export type ExtraNumbersPurchaseResult = {
1062
+ success: boolean;
1063
+ checkoutUrl?: string;
1064
+ [key: string]: unknown;
1065
+ };
1066
+ export type ExtraNumbersScheduleResult = {
1067
+ success: boolean;
1068
+ [key: string]: unknown;
1069
+ };
1070
+ /**
1071
+ * `auto` (default) sends an official number to the native `whatsapp_cloud` inbox
1072
+ * and everything else to an API mirror inbox; `api`/`native` force one of the two.
1073
+ */
1074
+ export type ChatwootChannelMode = "auto" | "api" | "native";
1075
+ export type ChatwootStatus = {
1076
+ connected: boolean;
1077
+ status: "disconnected" | "pending" | "connected" | "error" | "disabled";
1078
+ enabled: boolean;
1079
+ inboxId: number | null;
1080
+ instanceUrl: string | null;
1081
+ accountId: string | null;
1082
+ /** The Chatwoot token never comes back; this is all you can observe of it. */
1083
+ hasToken: boolean;
1084
+ channelMode: ChatwootChannelMode | null;
1085
+ lastError: string | null;
1086
+ lastErrorCode: string | null;
1087
+ lastSyncAt: string | null;
1088
+ };
1089
+ export type ChatwootConnectInput = {
1090
+ instanceUrl: string;
1091
+ accountId: string;
1092
+ /** `api_access_token` of a Chatwoot agent/admin. */
1093
+ userAccessToken: string;
1094
+ channelMode?: ChatwootChannelMode;
1095
+ };
1096
+ export type ChatwootUpdateInput = {
1097
+ /** `false` pauses the mirroring without disconnecting. */
1098
+ enabled?: boolean;
1099
+ instanceUrl?: string;
1100
+ accountId?: string;
1101
+ userAccessToken?: string;
1102
+ /** Rebuilds the inbox reusing the stored credential. */
1103
+ action?: "reconnect";
1104
+ channelMode?: ChatwootChannelMode;
1105
+ };
1106
+ export type ChatwootTestInput = {
1107
+ instanceUrl: string;
1108
+ accountId: string;
1109
+ /** Omit to reuse the stored token. */
1110
+ userAccessToken?: string;
1111
+ };
1112
+ export type ChatwootTestResult = {
1113
+ ok: boolean;
1114
+ checks: Array<{
1115
+ name: string;
1116
+ ok: boolean;
1117
+ status?: number;
1118
+ detail?: string;
1119
+ }>;
1120
+ };
1121
+ export type ChatwootHistoryReplayInput = {
1122
+ /** 30 (default) or 90. */
1123
+ windowDays?: 30 | 90;
1124
+ /** Resolves + marks read every conversation it touches, to contain the notification flood. Default true. */
1125
+ markRead?: boolean;
1126
+ };
1127
+ export type ChatwootHistoryReplayState = {
1128
+ status: string;
1129
+ total: number;
1130
+ done: number;
1131
+ failed: number;
1132
+ skippedMedia: number;
1133
+ [key: string]: unknown;
1134
+ };
1135
+ export type WorkspaceRole = "OWNER" | "ADMIN" | "AGENT" | "ANALYST";
1136
+ export type WorkspaceMemberStatus = "ACTIVE" | "PENDING";
1137
+ export type WorkspaceDetail = {
1138
+ id: string;
1139
+ /** `null` while the tenant has no name set — the route sends `tenant?.name ?? null`. */
1140
+ name: string | null;
1141
+ plan: string;
1142
+ /** Counts ACTIVE **and** PENDING: an invite already holds the seat. */
1143
+ seatsUsed: number;
1144
+ seatLimit: number;
1145
+ };
1146
+ /**
1147
+ * An active member or a pending invite — the same list, discriminated by `status`.
1148
+ * It never carries the invite token nor the `inviteUrl`: only the hash is stored.
1149
+ *
1150
+ * ⚠️ Mirrors, field for field, the `MemberView` that
1151
+ * `apps/backend/src/services/workspace-member.service.ts` builds. Every `Date`
1152
+ * there arrives here as an ISO-8601 string, because `NextResponse.json`
1153
+ * serializes it. Do not add a field that the service does not select: this type
1154
+ * crosses an HTTP boundary, so `tsc` cannot catch an invention — only a test
1155
+ * against the real body can.
1156
+ */
1157
+ export type WorkspaceMember = {
1158
+ /** MEMBERSHIP id, not the user id. It is what the member routes take in the path. */
1159
+ id: string;
1160
+ email: string;
1161
+ /** `null` until the invitee has an account with a name on it. */
1162
+ name: string | null;
1163
+ role: WorkspaceRole;
1164
+ status: WorkspaceMemberStatus;
1165
+ /** Empty = every number in the account. */
1166
+ allowedNumberIds: string[];
1167
+ /** Always present, on ACTIVE rows too — it is when the invite was issued. */
1168
+ invitedAt: string;
1169
+ /** `null` while `status` is `PENDING`. */
1170
+ joinedAt: string | null;
1171
+ /** `null` once the invite has been accepted (the token is burned on acceptance). */
1172
+ inviteExpiresAt: string | null;
1173
+ /** `true` when the invite lapsed: the row survives but holds no seat any more. */
1174
+ inviteExpired: boolean;
1175
+ };
1176
+ /**
1177
+ * The literal body of `GET /v1/workspace/members` — an ENVELOPE, not a bare
1178
+ * array. `seatsUsed`/`seatLimit` are the same counters `GET /v1/workspace`
1179
+ * reports, returned here so listing and capacity take one round trip instead of
1180
+ * two.
1181
+ */
1182
+ export type WorkspaceMemberList = {
1183
+ members: WorkspaceMember[];
1184
+ seatsUsed: number;
1185
+ seatLimit: number;
1186
+ };
1187
+ /**
1188
+ * Meta's closed set. A value outside it only fails AFTER the trip to the Graph,
1189
+ * and Meta's message does not say WHICH category it refused — hence a union here
1190
+ * rather than `string`.
1191
+ */
1192
+ export type FlowCategory = "SIGN_UP" | "SIGN_IN" | "APPOINTMENT_BOOKING" | "LEAD_GENERATION" | "CONTACT_US" | "CUSTOMER_SUPPORT" | "SURVEY" | "OTHER";
1193
+ /**
1194
+ * One Flow, as `GET /v1/flows` publishes it.
1195
+ *
1196
+ * ⚠️ `id` is the LOCAL cuid and it is the ONLY id any method of this SDK accepts
1197
+ * back. `metaFlowId` is READ-ONLY — Meta's identifier, useful for correlating with
1198
+ * Flow Manager and nothing else. See {@link CreateFlowInput.cloneFromFlowId}.
1199
+ *
1200
+ * `healthStatus` is the last channel that ever says a Flow was throttled or that
1201
+ * its endpoint public key died: Meta's Flows Metrics API was discontinued on
1202
+ * 2026-04-30 with no successor, so this column (filled by the `flows` webhook) is
1203
+ * where "the form stopped opening" becomes visible.
1204
+ */
1205
+ export type Flow = {
1206
+ /** LOCAL cuid. The id every other method on this resource takes. */
1207
+ id: string;
1208
+ /** Meta's id. Read-only — never send it back to us. */
1209
+ metaFlowId: string | null;
1210
+ name: string;
1211
+ /** Meta's lifecycle: `DRAFT`, `PUBLISHED`, `DEPRECATED`, `BLOCKED`, `THROTTLED`. */
1212
+ metaStatus: string | null;
1213
+ healthStatus: string | null;
1214
+ categories: string[];
1215
+ jsonVersion: string | null;
1216
+ /** LOCAL id of the Flow this one was cloned FROM. Points backwards in the chain. */
1217
+ clonedFromFlowId: string | null;
1218
+ /** LOCAL id of the Flow that replaced this one. Points forwards in the chain. */
1219
+ supersededByFlowId: string | null;
1220
+ createdAt: string;
1221
+ updatedAt: string;
1222
+ };
1223
+ /**
1224
+ * `page` ≥ 1 (default 1), `pageSize` in [1, 100] (default 30).
1225
+ *
1226
+ * ⚠️ `page * pageSize` above 100 000 is refused with 400 `FLOW_INVALID_PAGINATION`
1227
+ * — deep offsets scan and discard everything before them.
1228
+ */
1229
+ export type FlowListParams = {
1230
+ page?: number;
1231
+ pageSize?: number;
1232
+ };
1233
+ /**
1234
+ * ⚠️ An ENVELOPE, unlike `GET /v1/templates`, which answers a bare array. Flows is
1235
+ * a newer surface and starts at the paginated default on purpose.
1236
+ */
1237
+ export type FlowListResult = {
1238
+ flows: Flow[];
1239
+ total: number;
1240
+ page: number;
1241
+ pageSize: number;
1242
+ totalPages: number;
1243
+ };
1244
+ export type CreateFlowInput = {
1245
+ name: string;
1246
+ /** Non-empty. Every value must be a {@link FlowCategory}. */
1247
+ categories: readonly FlowCategory[];
1248
+ /**
1249
+ * The LOCAL id (`Flow.id`) of the Flow to clone — ⛔ NEVER the `metaFlowId`.
1250
+ *
1251
+ * This is the mistake the API cannot catch for you: both are opaque strings, so
1252
+ * a `metaFlowId` here resolves to no row of ours and comes back as 404
1253
+ * `FLOW_NOT_FOUND` naming a Flow you can see in Flow Manager. Our resolver runs
1254
+ * `where: { id, tenantId }` and sends the resulting `metaFlowId` on to Meta, so
1255
+ * the local id is also what proves ownership.
1256
+ *
1257
+ * ⚠️ Cloning is the ONLY way to revise a published Flow: Meta never lets a
1258
+ * published Flow be edited again. `clonedFromFlowId` on the clone and
1259
+ * `supersededByFlowId` on the original are the two ends of that chain.
1260
+ */
1261
+ cloneFromFlowId?: string;
1262
+ };
1263
+ /** 201 from `POST /v1/flows`. `id` is LOCAL; `metaFlowId` is Meta's. */
1264
+ export type FlowCreated = {
1265
+ id: string;
1266
+ metaFlowId: string;
1267
+ };
1268
+ /** At least one of the two is required — an empty patch is 400 `FLOW_PATCH_EMPTY`. */
1269
+ export type UpdateFlowInput = {
1270
+ name?: string;
1271
+ categories?: readonly FlowCategory[];
1272
+ };
1273
+ export type FlowUpdateResult = {
1274
+ ok: true;
1275
+ id: string;
1276
+ };
1277
+ export type FlowDeleteResult = {
1278
+ ok: true;
1279
+ id: string;
1280
+ deleted: true;
1281
+ };
1282
+ /**
1283
+ * 200 from `POST /v1/flows/{id}/json`.
1284
+ *
1285
+ * ⛔ `validationErrors` is ALWAYS `[]` here. A non-empty list never arrives as a
1286
+ * 200 on our API — it arrives as a THROWN 422; see
1287
+ * {@link FlowJsonValidationFailure} and `flowJsonValidationErrors`.
1288
+ */
1289
+ export type FlowJsonUploadResult = {
1290
+ id: string;
1291
+ validationErrors: [];
1292
+ };
1293
+ /**
1294
+ * The body of the 422 `FLOW_JSON_INVALID` that a rejected Flow JSON throws.
1295
+ *
1296
+ * ⚠️ `validationErrors` is Meta's own list, VERBATIM and untyped: it names the
1297
+ * line and the refused component, its shape belongs to Meta, and they change it
1298
+ * without telling us. Read it, print it, do not branch on its internals.
1299
+ */
1300
+ export type FlowJsonValidationFailure = {
1301
+ error: string;
1302
+ errorEN: string;
1303
+ code: "FLOW_JSON_INVALID";
1304
+ validationErrors: unknown[];
1305
+ };
1306
+ /**
1307
+ * ⛔ `confirm` is the literal `true` and it is REQUIRED. Publishing is
1308
+ * irreversible on Meta: a published Flow is never edited again, only cloned.
1309
+ */
1310
+ export type FlowPublishInput = {
1311
+ confirm: true;
1312
+ };
1313
+ export type FlowPublishResult = {
1314
+ flowId: string;
1315
+ published: true;
1316
+ };
1317
+ export type FlowDeprecateInput = {
1318
+ /**
1319
+ * The LOCAL id (`Flow.id`) of the successor — ⛔ NEVER the `metaFlowId`.
1320
+ *
1321
+ * A `metaFlowId` here writes a pointer that resolves to no row of ours, so the
1322
+ * version chain ends silently at this Flow. It is the forward half of the pair
1323
+ * `clonedFromFlowId` opens.
1324
+ *
1325
+ * Optional on purpose: deprecating with no successor is legitimate (the Flow
1326
+ * left circulation and nothing replaces it). Omit the field — sending `""` or
1327
+ * `null` is refused with 400 rather than read as "no successor".
1328
+ */
1329
+ supersededByFlowId?: string;
1330
+ };
1331
+ export type FlowDeprecateResult = {
1332
+ flowId: string;
1333
+ deprecated: true;
1334
+ /** Echoed always, `null` included, so "recorded" is distinguishable from "dropped". */
1335
+ supersededBy: string | null;
1336
+ };
1337
+ /** One submitted form. Every id here is LOCAL except `externalMessageId`. */
1338
+ export type FlowResponse = {
1339
+ id: string;
1340
+ /** LOCAL id of the Flow this was read through. */
1341
+ flowId: string;
1342
+ /**
1343
+ * `null` once the SESSION's own retention window closed (37 days from the send)
1344
+ * or its row was pruned — the answer outlives the phone by design.
1345
+ */
1346
+ contactPhone: string | null;
1347
+ flowToken: string;
1348
+ /** Meta's `wamid` — a PROVIDER id, which is why it is not called `messageId`. */
1349
+ externalMessageId: string;
1350
+ /**
1351
+ * The submitted form, already parsed.
1352
+ *
1353
+ * `null` when the stored payload was corrupt, and — since 2026-09-06 — also when the
1354
+ * number is configured to relay and keep nothing, the same wording the sibling
1355
+ * `submitted` field carries below. The two now agree; before that date this field was
1356
+ * stored and served whatever the number's PII mode said, while its neighbour was not.
1357
+ *
1358
+ * ⚠️ On a Flow with a `data_exchange` endpoint this is empty even on a storing number:
1359
+ * Meta's `nfm_reply` carries only the `flow_token`, and what the person typed is in
1360
+ * `submitted`.
1361
+ */
1362
+ response: Record<string, unknown> | null;
1363
+ /**
1364
+ * The files attached inside the form (`PhotoPicker` / `DocumentPicker`).
1365
+ *
1366
+ * ⚠️ THEY ARE NOT IN `response`. A media picker requires a `data_exchange` endpoint,
1367
+ * so what `response` holds for such a field is a reference to Meta's CDN — which Meta
1368
+ * deletes after 20 days. This array is the re-hosted copy, and the only way to reach
1369
+ * the bytes. Always an array; empty when nothing was attached.
1370
+ */
1371
+ media: FlowResponseMedia[];
1372
+ /**
1373
+ * WHAT THE PERSON TYPED, screen by screen, on a `data_exchange` Flow.
1374
+ *
1375
+ * ⛔ IT IS NOT `response`. `response` is what YOUR endpoint returned — the
1376
+ * `extension_message_response.params` of the final exchange. This is what the
1377
+ * respondent's device sent on the way there, captured as each screen was relayed.
1378
+ *
1379
+ * ⛔ A LIST, NEVER MERGED: each `data_exchange` carries only the fields of ITS screen,
1380
+ * so merging would let the last field with a repeated name win silently. A screen that
1381
+ * appears twice is not a duplicate — someone walked back and submitted it again.
1382
+ *
1383
+ * Always an array; ⚠️ EMPTY IS NOT "they typed nothing". A NAVIGATE-only Flow never
1384
+ * calls an endpoint at all (its answers are wholly in `response`), a number configured
1385
+ * to relay and keep nothing captures none, and submissions from before this existed
1386
+ * have none.
1387
+ *
1388
+ * ⚠️ Shorter than the exchange count: only `data_exchange` produces an entry. `INIT`
1389
+ * carries the form's initial state and `BACK` is a navigation gesture.
1390
+ *
1391
+ * The same list is `data.submitted` on the `flow.response_received` webhook — with the
1392
+ * ONE difference the two attachment shapes also have: there it is `null`, never `[]`,
1393
+ * when nothing was captured.
1394
+ */
1395
+ submitted: FlowSubmittedExchange[];
1396
+ receivedAt: string;
1397
+ /** When this answer stops being readable (30 days from arrival). */
1398
+ expiresAt: string;
1399
+ };
1400
+ /**
1401
+ * ONE `data_exchange` exchange of a submitted form — one screen's worth of answers.
1402
+ *
1403
+ * ⛔ Carries nothing of what YOUR endpoint answered. `extension_message_response` never
1404
+ * appears anywhere in Pilot Status; what you returned is already `response`.
1405
+ */
1406
+ export type FlowSubmittedExchange = {
1407
+ /**
1408
+ * The screen the person was on, or `null` when Meta named none.
1409
+ *
1410
+ * ⚠️ A repeated screen name is not a duplicate — see the field's docblock.
1411
+ */
1412
+ screen: string | null;
1413
+ /** ISO-8601. When the exchange was relayed. */
1414
+ at: string;
1415
+ /**
1416
+ * The fields of THAT screen, exactly as the device sent them. `null` exactly when
1417
+ * {@link FlowSubmittedExchange.omitted} says why — never both, never neither.
1418
+ */
1419
+ data: Record<string, unknown> | null;
1420
+ /**
1421
+ * Why `data` is `null`; `null` when the data is there. ⛔ Nothing is ever truncated —
1422
+ * an exchange over a ceiling keeps its place and its screen and SAYS what was dropped.
1423
+ *
1424
+ * `DATA_TOO_LARGE` — that one exchange exceeded the per-exchange ceiling.
1425
+ * `LIMIT_REACHED` — the per-form ceiling was reached here; every exchange after it
1426
+ * was not stored either, so this is always the last entry.
1427
+ * `UNREADABLE` — stored bytes that no longer parse as a JSON object.
1428
+ *
1429
+ * ⚠️ A plain `string`, not a union: a value your SDK version has never heard of must
1430
+ * still arrive rather than fail a parse.
1431
+ */
1432
+ omitted: string | null;
1433
+ };
1434
+ /**
1435
+ * One attachment of a submitted form.
1436
+ *
1437
+ * ⭐ `url` IS THERE BEFORE THE BYTES ARE, including while `status` is `"PENDING"`. Fetch it
1438
+ * and it works: the link points at a Pilot Status route that waits for the transfer to
1439
+ * finish and then redirects, so you do not have to poll for `STORED` before you have
1440
+ * somewhere to point. The value does not change once the file lands, so it is safe to
1441
+ * store on arrival. Treat it as opaque.
1442
+ *
1443
+ * ⛔ THIS SAID THE OPPOSITE UNTIL 2026-09-06 — "`null` on anything but `STORED`" — and the
1444
+ * reason was sound at the time: the URL pointed at the object, and publishing it early
1445
+ * would have been a link that 404s. It no longer points at the object.
1446
+ *
1447
+ * ⚠️ Still `null` in three cases, none of which is "not transferred yet": the deployment
1448
+ * cannot sign a link (it then falls back to the object once `STORED`), Meta sent no
1449
+ * `media_id`, or the number keeps no customer content. `status` still tells you whether
1450
+ * the bytes have landed — it just no longer gates the URL.
1451
+ */
1452
+ export type FlowResponseMedia = {
1453
+ /** The key in the form the file was listed under, as the Flow's author named it. */
1454
+ field: string;
1455
+ /** The name the sender's device reported, when it reported one. */
1456
+ fileName: string | null;
1457
+ /** Sniffed from the decrypted bytes, never from the file name. `null` until stored. */
1458
+ mimeType: string | null;
1459
+ /** Size of the decrypted file. `null` until stored. */
1460
+ sizeBytes: number | null;
1461
+ /** `PENDING` while the transfer is in flight, then `STORED` or `FAILED`. */
1462
+ status: string;
1463
+ url: string | null;
1464
+ };
1465
+ export type FlowResponseListParams = FlowListParams;
1466
+ export type FlowResponseListResult = {
1467
+ responses: FlowResponse[];
1468
+ total: number;
1469
+ page: number;
1470
+ pageSize: number;
1471
+ totalPages: number;
1472
+ /**
1473
+ * `"FLOW_RESPONSES_WINDOW_TRUNCATED"` when the Flow has minted more sends than
1474
+ * one request will correlate. ⚠️ The page is then SHORT — treat it as "there may
1475
+ * be more", never as "these are all the submissions".
1476
+ */
1477
+ notice?: string;
1478
+ };
1479
+ /**
1480
+ * ⛔ FOUR values, and `UNKNOWN` is not `NOT_SET`. `NOT_SET` is Meta answering that
1481
+ * it holds no key; `UNKNOWN` is us failing to ask. Collapsing them makes an
1482
+ * operator rotate over a transient Graph 500 — and rotating breaks every
1483
+ * `data_exchange` Flow on the number.
1484
+ */
1485
+ export type FlowEndpointKeyMetaStatus = "VALID" | "MISMATCH" | "NOT_SET" | "UNKNOWN";
1486
+ /**
1487
+ * The `data_exchange` endpoint keypair of ONE number.
1488
+ *
1489
+ * ⚠️ `endpointUrl` IS A CREDENTIAL. Meta signs nothing and sends no key, so the
1490
+ * endpoint authenticates callers by decrypting the body — and the other half of
1491
+ * that pair is published here and by Meta. Anyone holding this URL plus the public
1492
+ * key can forge a request we will decrypt and forward to your webhook carrying our
1493
+ * signature. That is why these two methods need `flows:manage` and not
1494
+ * `flows:read`, and why `endpointUrl` never appears in the Flow listing.
1495
+ *
1496
+ * The PRIVATE half is never in this payload, on either verb.
1497
+ */
1498
+ export type FlowEndpointKeyStatus = {
1499
+ configured: boolean;
1500
+ /** PEM. Public by definition — this is the half Meta holds. */
1501
+ publicKey: string | null;
1502
+ /** ISO-8601, or `null` when we hold a pair Meta never accepted. */
1503
+ uploadedAt: string | null;
1504
+ endpointUrl: string | null;
1505
+ metaStatus: FlowEndpointKeyMetaStatus;
1506
+ };
1507
+ export type FlowEndpointKeyRotateInput = {
1508
+ /**
1509
+ * ⛔ REQUIRED exactly when a key of ours is already live at Meta, because the
1510
+ * call then DESTROYS it. See `FlowsResource.rotateEndpointKey`.
1511
+ */
1512
+ confirm?: true;
1513
+ };
1514
+ export type FlowEndpointKeyRotateResult = FlowEndpointKeyStatus & {
1515
+ /** `uploadedAt` is never `null` on a successful rotate — it was just stamped. */
1516
+ uploadedAt: string;
1517
+ /**
1518
+ * ⛔ `true` means the key that was working IS GONE and every Flow whose
1519
+ * `endpoint_uri` answered with the old pair now answers with the new one. That
1520
+ * sentence is not derivable from the 200.
1521
+ */
1522
+ replaced: boolean;
1523
+ };
554
1524
  //# sourceMappingURL=types.d.ts.map