@pilot-status/sdk 0.4.0 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +51 -0
- package/README.md +203 -17
- 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 +7 -1
- 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 +61 -1
- package/dist/resources/messages.d.ts.map +1 -1
- package/dist/resources/messages.js +134 -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 +102 -1
- package/dist/resources/numbers.d.ts.map +1 -1
- package/dist/resources/numbers.js +152 -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 +957 -21
- 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 +49 -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 +59 -1
- 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
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import { compact } from "../internal.js";
|
|
2
|
+
/**
|
|
3
|
+
* Mirroring into Chatwoot (`/v1/chatwoot*`).
|
|
4
|
+
*
|
|
5
|
+
* ⚠️ **All 8 endpoints are PER NUMBER.** With a tenant-scoped key and no resolved
|
|
6
|
+
* number they answer `400 NUMBER_REQUIRED` — build the client with
|
|
7
|
+
* `whatsappNumberId`, or use `client.withNumber(id).chatwoot.…`. With a
|
|
8
|
+
* number-scoped key the key's number wins and the header is ignored.
|
|
9
|
+
*
|
|
10
|
+
* The Chatwoot `userAccessToken` never comes back in any response; what you can
|
|
11
|
+
* observe is `hasToken`.
|
|
12
|
+
*/
|
|
13
|
+
export class ChatwootResource {
|
|
14
|
+
#http;
|
|
15
|
+
constructor(http) {
|
|
16
|
+
this.#http = http;
|
|
17
|
+
}
|
|
18
|
+
async get() {
|
|
19
|
+
return this.#http.requestJson({
|
|
20
|
+
method: "GET",
|
|
21
|
+
path: "/v1/chatwoot",
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Connects (or reconnects with a new credential). It validates against the
|
|
26
|
+
* Chatwoot instance, creates the inbox and starts mirroring. It is worth
|
|
27
|
+
* running {@link test} first — that one writes nothing.
|
|
28
|
+
*/
|
|
29
|
+
async connect(input) {
|
|
30
|
+
return this.#http.requestJson({
|
|
31
|
+
method: "POST",
|
|
32
|
+
path: "/v1/chatwoot",
|
|
33
|
+
body: compact({
|
|
34
|
+
instanceUrl: input.instanceUrl,
|
|
35
|
+
accountId: input.accountId,
|
|
36
|
+
userAccessToken: input.userAccessToken,
|
|
37
|
+
channelMode: input.channelMode,
|
|
38
|
+
}),
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Partial update of an existing integration.
|
|
43
|
+
*
|
|
44
|
+
* `enabled: false` PAUSES the mirroring without disconnecting. Changing
|
|
45
|
+
* `instanceUrl`/`accountId`/`userAccessToken` re-runs the whole connect and
|
|
46
|
+
* RECREATES the inbox; `action: "reconnect"` rebuilds the inbox reusing the
|
|
47
|
+
* stored credential.
|
|
48
|
+
*/
|
|
49
|
+
async update(input) {
|
|
50
|
+
return this.#http.requestJson({
|
|
51
|
+
method: "PATCH",
|
|
52
|
+
path: "/v1/chatwoot",
|
|
53
|
+
body: compact({
|
|
54
|
+
enabled: input.enabled,
|
|
55
|
+
instanceUrl: input.instanceUrl,
|
|
56
|
+
accountId: input.accountId,
|
|
57
|
+
userAccessToken: input.userAccessToken,
|
|
58
|
+
action: input.action,
|
|
59
|
+
channelMode: input.channelMode,
|
|
60
|
+
}),
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Disconnects (idempotent). `deleteInbox: true` ALSO deletes the remote inbox
|
|
65
|
+
* in Chatwoot, along with the history that lives there. To merely pause,
|
|
66
|
+
* prefer `update({ enabled: false })`.
|
|
67
|
+
*/
|
|
68
|
+
async disconnect(params) {
|
|
69
|
+
return this.#http.requestJson({
|
|
70
|
+
method: "DELETE",
|
|
71
|
+
path: "/v1/chatwoot",
|
|
72
|
+
query: compact({ deleteInbox: params?.deleteInbox }),
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
/** Dry-run of the credentials: creates no inbox and writes nothing. Omit `userAccessToken` to reuse the stored one. */
|
|
76
|
+
async test(input) {
|
|
77
|
+
return this.#http.requestJson({
|
|
78
|
+
method: "POST",
|
|
79
|
+
path: "/v1/chatwoot/test",
|
|
80
|
+
body: compact({
|
|
81
|
+
instanceUrl: input.instanceUrl,
|
|
82
|
+
accountId: input.accountId,
|
|
83
|
+
userAccessToken: input.userAccessToken,
|
|
84
|
+
}),
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Pushes this number's ALREADY STORED history into the connected inbox
|
|
89
|
+
* (`POST /v1/chatwoot/history-sync`). Only for Meta numbers in COEXISTENCE
|
|
90
|
+
* with Chatwoot on the API channel.
|
|
91
|
+
*
|
|
92
|
+
* Messages go in oldest to newest with the original date/time prefixed INTO
|
|
93
|
+
* THE BODY — Chatwoot ignores `created_at` on the API, so there is no way to
|
|
94
|
+
* truly backdate them. Idempotent: running it again only re-posts what did
|
|
95
|
+
* not make it through.
|
|
96
|
+
*/
|
|
97
|
+
async startHistoryReplay(input) {
|
|
98
|
+
return this.#http.requestJson({
|
|
99
|
+
method: "POST",
|
|
100
|
+
path: "/v1/chatwoot/history-sync",
|
|
101
|
+
body: compact({ windowDays: input?.windowDays, markRead: input?.markRead }),
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
async getHistoryReplay() {
|
|
105
|
+
return this.#http.requestJson({
|
|
106
|
+
method: "GET",
|
|
107
|
+
path: "/v1/chatwoot/history-sync",
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
async cancelHistoryReplay() {
|
|
111
|
+
return this.#http.requestJson({
|
|
112
|
+
method: "DELETE",
|
|
113
|
+
path: "/v1/chatwoot/history-sync",
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
//# sourceMappingURL=chatwoot.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chatwoot.js","sourceRoot":"","sources":["../../src/resources/chatwoot.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { HttpClient } from "../http.js";
|
|
2
|
+
import type { ConversationListParams, ConversationListResult } from "../types.js";
|
|
3
|
+
/** Conversations of the key's number (`GET /v1/conversations`), ordered by last message. */
|
|
4
|
+
export declare class ConversationsResource {
|
|
5
|
+
#private;
|
|
6
|
+
constructor(http: HttpClient);
|
|
7
|
+
/**
|
|
8
|
+
* Requires a NUMBER-scoped key.
|
|
9
|
+
*
|
|
10
|
+
* Returns an empty list when the number is on `piiMode: "RELAY_ONLY"` — that
|
|
11
|
+
* is not an error, it is the retention policy: nothing was stored to list. On
|
|
12
|
+
* `STORE_X_DAYS` the retention window also trims the result.
|
|
13
|
+
*/
|
|
14
|
+
list(params?: ConversationListParams): Promise<ConversationListResult>;
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=conversations.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"conversations.d.ts","sourceRoot":"","sources":["../../src/resources/conversations.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAE7C,OAAO,KAAK,EAAE,sBAAsB,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAC;AAElF,4FAA4F;AAC5F,qBAAa,qBAAqB;;gBAGlB,IAAI,EAAE,UAAU;IAI5B;;;;;;OAMG;IACG,IAAI,CAAC,MAAM,CAAC,EAAE,sBAAsB,GAAG,OAAO,CAAC,sBAAsB,CAAC;CAY/E"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { compact } from "../internal.js";
|
|
2
|
+
/** Conversations of the key's number (`GET /v1/conversations`), ordered by last message. */
|
|
3
|
+
export class ConversationsResource {
|
|
4
|
+
#http;
|
|
5
|
+
constructor(http) {
|
|
6
|
+
this.#http = http;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Requires a NUMBER-scoped key.
|
|
10
|
+
*
|
|
11
|
+
* Returns an empty list when the number is on `piiMode: "RELAY_ONLY"` — that
|
|
12
|
+
* is not an error, it is the retention policy: nothing was stored to list. On
|
|
13
|
+
* `STORE_X_DAYS` the retention window also trims the result.
|
|
14
|
+
*/
|
|
15
|
+
async list(params) {
|
|
16
|
+
return this.#http.requestJson({
|
|
17
|
+
method: "GET",
|
|
18
|
+
path: "/v1/conversations",
|
|
19
|
+
query: compact({
|
|
20
|
+
startDate: params?.startDate,
|
|
21
|
+
endDate: params?.endDate,
|
|
22
|
+
page: params?.page,
|
|
23
|
+
pageSize: params?.pageSize,
|
|
24
|
+
}),
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=conversations.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"conversations.js","sourceRoot":"","sources":["../../src/resources/conversations.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAGzC,4FAA4F;AAC5F,MAAM,OAAO,qBAAqB;IACrB,KAAK,CAAa;IAE3B,YAAY,IAAgB;QACxB,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC;IACtB,CAAC;IAED;;;;;;OAMG;IACH,KAAK,CAAC,IAAI,CAAC,MAA+B;QACtC,OAAO,IAAI,CAAC,KAAK,CAAC,WAAW,CAAyB;YAClD,MAAM,EAAE,KAAK;YACb,IAAI,EAAE,mBAAmB;YACzB,KAAK,EAAE,OAAO,CAAC;gBACX,SAAS,EAAE,MAAM,EAAE,SAAS;gBAC5B,OAAO,EAAE,MAAM,EAAE,OAAO;gBACxB,IAAI,EAAE,MAAM,EAAE,IAAI;gBAClB,QAAQ,EAAE,MAAM,EAAE,QAAQ;aAC7B,CAAC;SACL,CAAC,CAAC;IACP,CAAC;CACJ"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { HttpClient } from "../http.js";
|
|
2
|
+
import type { EmbedSessionInput, EmbedSessionResult } from "../types.js";
|
|
3
|
+
/** Embed sessions for the chat / connect microfrontends (`POST /v1/embed/sessions`). */
|
|
4
|
+
export declare class EmbedResource {
|
|
5
|
+
#private;
|
|
6
|
+
constructor(http: HttpClient);
|
|
7
|
+
/**
|
|
8
|
+
* Mints a short-lived token for YOUR end user's browser to mount the iframe.
|
|
9
|
+
* Always call it from the backend: the token is derived from the `ps_` key,
|
|
10
|
+
* which must never reach the browser.
|
|
11
|
+
*
|
|
12
|
+
* - `surface: "chat"` — needs `whatsappNumberIds`, unless the credential is
|
|
13
|
+
* already number-scoped (in which case it is the only possible number).
|
|
14
|
+
* Default TTL 15 min.
|
|
15
|
+
* - `surface: "connect"` — it is account-wide, so it requires a tenant-scoped
|
|
16
|
+
* credential (403 `NUMBER_SCOPE_NOT_ALLOWED` with a number key).
|
|
17
|
+
* Default TTL 30 min.
|
|
18
|
+
*
|
|
19
|
+
* `allowedOrigins` are EXACT origins (`https://app.customer.com`, with no path
|
|
20
|
+
* and no trailing slash) and the maximum `ttlSeconds` is 3600.
|
|
21
|
+
*/
|
|
22
|
+
createSession(input: EmbedSessionInput): Promise<EmbedSessionResult>;
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=embed.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"embed.d.ts","sourceRoot":"","sources":["../../src/resources/embed.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAE7C,OAAO,KAAK,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAEzE,wFAAwF;AACxF,qBAAa,aAAa;;gBAGV,IAAI,EAAE,UAAU;IAI5B;;;;;;;;;;;;;;OAcG;IACG,aAAa,CAAC,KAAK,EAAE,iBAAiB,GAAG,OAAO,CAAC,kBAAkB,CAAC;CAa7E"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { compact } from "../internal.js";
|
|
2
|
+
/** Embed sessions for the chat / connect microfrontends (`POST /v1/embed/sessions`). */
|
|
3
|
+
export class EmbedResource {
|
|
4
|
+
#http;
|
|
5
|
+
constructor(http) {
|
|
6
|
+
this.#http = http;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Mints a short-lived token for YOUR end user's browser to mount the iframe.
|
|
10
|
+
* Always call it from the backend: the token is derived from the `ps_` key,
|
|
11
|
+
* which must never reach the browser.
|
|
12
|
+
*
|
|
13
|
+
* - `surface: "chat"` — needs `whatsappNumberIds`, unless the credential is
|
|
14
|
+
* already number-scoped (in which case it is the only possible number).
|
|
15
|
+
* Default TTL 15 min.
|
|
16
|
+
* - `surface: "connect"` — it is account-wide, so it requires a tenant-scoped
|
|
17
|
+
* credential (403 `NUMBER_SCOPE_NOT_ALLOWED` with a number key).
|
|
18
|
+
* Default TTL 30 min.
|
|
19
|
+
*
|
|
20
|
+
* `allowedOrigins` are EXACT origins (`https://app.customer.com`, with no path
|
|
21
|
+
* and no trailing slash) and the maximum `ttlSeconds` is 3600.
|
|
22
|
+
*/
|
|
23
|
+
async createSession(input) {
|
|
24
|
+
return this.#http.requestJson({
|
|
25
|
+
method: "POST",
|
|
26
|
+
path: "/v1/embed/sessions",
|
|
27
|
+
body: compact({
|
|
28
|
+
surface: input.surface,
|
|
29
|
+
allowedOrigins: input.allowedOrigins,
|
|
30
|
+
whatsappNumberIds: input.whatsappNumberIds,
|
|
31
|
+
brandingOverride: input.brandingOverride,
|
|
32
|
+
ttlSeconds: input.ttlSeconds,
|
|
33
|
+
}),
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
//# sourceMappingURL=embed.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"embed.js","sourceRoot":"","sources":["../../src/resources/embed.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAGzC,wFAAwF;AACxF,MAAM,OAAO,aAAa;IACb,KAAK,CAAa;IAE3B,YAAY,IAAgB;QACxB,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC;IACtB,CAAC;IAED;;;;;;;;;;;;;;OAcG;IACH,KAAK,CAAC,aAAa,CAAC,KAAwB;QACxC,OAAO,IAAI,CAAC,KAAK,CAAC,WAAW,CAAqB;YAC9C,MAAM,EAAE,MAAM;YACd,IAAI,EAAE,oBAAoB;YAC1B,IAAI,EAAE,OAAO,CAAC;gBACV,OAAO,EAAE,KAAK,CAAC,OAAO;gBACtB,cAAc,EAAE,KAAK,CAAC,cAAc;gBACpC,iBAAiB,EAAE,KAAK,CAAC,iBAAiB;gBAC1C,gBAAgB,EAAE,KAAK,CAAC,gBAAgB;gBACxC,UAAU,EAAE,KAAK,CAAC,UAAU;aAC/B,CAAC;SACL,CAAC,CAAC;IACP,CAAC;CACJ"}
|
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
import type { HttpClient } from "../http.js";
|
|
2
|
+
import type { CreateFlowInput, FlowCreated, FlowDeleteResult, FlowDeprecateInput, FlowDeprecateResult, FlowEndpointKeyRotateInput, FlowEndpointKeyRotateResult, FlowEndpointKeyStatus, FlowJsonUploadResult, FlowListParams, FlowListResult, FlowPublishInput, FlowPublishResult, FlowResponseListParams, FlowResponseListResult, FlowUpdateResult, UpdateFlowInput } from "../types.js";
|
|
3
|
+
/**
|
|
4
|
+
* Meta's `validation_errors` list, pulled out of a thrown `uploadJson` failure.
|
|
5
|
+
*
|
|
6
|
+
* ⛔ THIS IS THE ONE PLACE THE LIST LIVES, AND IT IS NOT IN A SUCCESSFUL RESPONSE.
|
|
7
|
+
* `POST /flows/{id}/assets` on the GRAPH answers HTTP 200 with the errors inside the
|
|
8
|
+
* body — whoever reads the status concludes the upload was accepted, the editor shows
|
|
9
|
+
* "saved", the Flow keeps the PREVIOUS JSON and nobody sees an error until a customer
|
|
10
|
+
* opens the old form in production. OUR route refuses to propagate that shape: a
|
|
11
|
+
* refused JSON is a 422 `FLOW_JSON_INVALID`, which this SDK raises as a
|
|
12
|
+
* {@link PilotStatusHttpError}. So {@link FlowsResource.uploadJson} resolving at all
|
|
13
|
+
* means `validationErrors` was empty; a non-empty list is only ever reachable from the
|
|
14
|
+
* exception, and this function is how you read it without unwrapping `error.body`
|
|
15
|
+
* yourself.
|
|
16
|
+
*
|
|
17
|
+
* ```ts
|
|
18
|
+
* try {
|
|
19
|
+
* await client.flows.uploadJson("flw_1", json);
|
|
20
|
+
* } catch (err) {
|
|
21
|
+
* const problems = flowJsonValidationErrors(err);
|
|
22
|
+
* if (problems) console.error("Meta refused the Flow JSON:", problems);
|
|
23
|
+
* else throw err; // 401/403/404/409/5xx — not a JSON problem
|
|
24
|
+
* }
|
|
25
|
+
* ```
|
|
26
|
+
*
|
|
27
|
+
* Returns `null` — never `[]` — for anything that is not that 422, so "Meta refused
|
|
28
|
+
* the content" stays distinguishable from "the token expired" and from "the Flow is
|
|
29
|
+
* already published". The list itself is Meta's, VERBATIM: it names the line and the
|
|
30
|
+
* component it refused, its shape is theirs to change, and translating it would
|
|
31
|
+
* replace the only text that says what to fix.
|
|
32
|
+
*/
|
|
33
|
+
export declare function flowJsonValidationErrors(error: unknown): unknown[] | null;
|
|
34
|
+
/**
|
|
35
|
+
* WhatsApp Flows: the forms a customer fills in inside the chat.
|
|
36
|
+
*
|
|
37
|
+
* ⛔ EVERY `{id}` THIS RESOURCE TAKES IS THE LOCAL CUID (`Flow.id`), never Meta's
|
|
38
|
+
* `metaFlowId`. Meta's id is published for correlating with Flow Manager and is never
|
|
39
|
+
* an input: an identifier we do not mint is one we cannot scope to a tenant. The two
|
|
40
|
+
* are both opaque strings, so nothing but a 404 will tell you which one you sent —
|
|
41
|
+
* see `cloneFromFlowId` and `supersededByFlowId`, where the confusion actually costs.
|
|
42
|
+
*
|
|
43
|
+
* ⚠️ NUMBER-SCOPED KEYS ONLY, and the number must be a Meta (Cloud API) one. The WABA
|
|
44
|
+
* is derived from the key's bound number — there is no parameter that names one, and
|
|
45
|
+
* sending `whatsappNumberId`/`wabaId` in any body is REFUSED (400
|
|
46
|
+
* `FLOW_NUMBER_FROM_KEY`), not ignored. Use `client.withNumber(...)` to aim at another
|
|
47
|
+
* number. A non-Meta number answers 422 `FLOW_REQUIRES_META_NUMBER`.
|
|
48
|
+
*
|
|
49
|
+
* The lifecycle is one-way: DRAFT → published → deprecated. Only a DRAFT can be
|
|
50
|
+
* renamed, re-uploaded or deleted; once published, Meta never lets a Flow be edited
|
|
51
|
+
* again and the only revision is a CLONE under a new id.
|
|
52
|
+
*/
|
|
53
|
+
export declare class FlowsResource {
|
|
54
|
+
#private;
|
|
55
|
+
constructor(http: HttpClient);
|
|
56
|
+
/**
|
|
57
|
+
* The Flows of the WABA behind the key's number, most recently updated first.
|
|
58
|
+
*
|
|
59
|
+
* ⚠️ Answers an ENVELOPE (`{flows, total, page, pageSize, totalPages}`) and not a
|
|
60
|
+
* bare array like `templates.list()`. Deep paging is refused: `page * pageSize`
|
|
61
|
+
* beyond 100 000 is a 400 `FLOW_INVALID_PAGINATION`.
|
|
62
|
+
*/
|
|
63
|
+
list(params?: FlowListParams): Promise<FlowListResult>;
|
|
64
|
+
/**
|
|
65
|
+
* Creates a Flow in DRAFT, or CLONES an existing one.
|
|
66
|
+
*
|
|
67
|
+
* ⚠️ Cloning is not a convenience: a published Flow is frozen on Meta forever, so
|
|
68
|
+
* `cloneFromFlowId` is the only way to ship a new version of a form that is
|
|
69
|
+
* already live. Read its JSDoc — it takes the LOCAL id, and a `metaFlowId` there
|
|
70
|
+
* comes back as a 404 for a Flow you can plainly see in Flow Manager.
|
|
71
|
+
*
|
|
72
|
+
* Answers 201 `{id, metaFlowId}`. `status` is NOT a field here: publishing has a
|
|
73
|
+
* route of its own precisely so it cannot happen by typo.
|
|
74
|
+
*/
|
|
75
|
+
create(input: CreateFlowInput): Promise<FlowCreated>;
|
|
76
|
+
/**
|
|
77
|
+
* Renames and/or recategorises a Flow. DRAFT only — a published Flow answers 409
|
|
78
|
+
* `FLOW_NOT_DRAFT`, and the remedy is `create({ cloneFromFlowId })`.
|
|
79
|
+
*
|
|
80
|
+
* ⛔ `name` and `categories` are the ONLY fields, and the omission is the guard: a
|
|
81
|
+
* do-everything PATCH that accepted `status` would turn a client's typo into a
|
|
82
|
+
* permanent publish. At least one of the two is required (400 `FLOW_PATCH_EMPTY`).
|
|
83
|
+
*/
|
|
84
|
+
update(id: string, input: UpdateFlowInput): Promise<FlowUpdateResult>;
|
|
85
|
+
/**
|
|
86
|
+
* Deletes a Flow. DRAFT only — a published one answers 409 `FLOW_NOT_DRAFT` and
|
|
87
|
+
* cannot be removed at all; deprecate it instead.
|
|
88
|
+
*/
|
|
89
|
+
delete(id: string): Promise<FlowDeleteResult>;
|
|
90
|
+
/**
|
|
91
|
+
* Uploads the Flow JSON of a DRAFT. `flowJson` is the complete document as a
|
|
92
|
+
* STRING — the text you wrote, not an object we would re-serialise, because
|
|
93
|
+
* Meta's validation errors point at positions inside the text they received.
|
|
94
|
+
*
|
|
95
|
+
* ⛔ RESOLVING MEANS META ACCEPTED IT. This is the whole reason the method exists
|
|
96
|
+
* rather than a thin wrapper: the Graph answers 200 with `validation_errors`
|
|
97
|
+
* inside the body when it REFUSES, so a status-reading client concludes it saved
|
|
98
|
+
* while the Flow silently keeps the previous JSON. Our route reads the LIST, not
|
|
99
|
+
* the status, and answers 422 `FLOW_JSON_INVALID` — which lands here as a thrown
|
|
100
|
+
* {@link PilotStatusHttpError} carrying Meta's list untouched. Read it with
|
|
101
|
+
* {@link flowJsonValidationErrors}; the exception is not to be swallowed.
|
|
102
|
+
*
|
|
103
|
+
* On success `validationErrors` is `[]` and it is present on purpose, so the
|
|
104
|
+
* client that branches on the status and the one that branches on the list reach
|
|
105
|
+
* the same conclusion.
|
|
106
|
+
*
|
|
107
|
+
* ⚠️ Reversible while the Flow is a DRAFT — upload another one. Publishing is not.
|
|
108
|
+
*/
|
|
109
|
+
uploadJson(id: string, flowJson: string): Promise<FlowJsonUploadResult>;
|
|
110
|
+
/**
|
|
111
|
+
* ⛔ PUBLISHES THE FLOW ON META. IRREVERSIBLE, WITH NO UNDO ANYWHERE.
|
|
112
|
+
*
|
|
113
|
+
* A published Flow can never be edited again — not by us, not in Flow Manager.
|
|
114
|
+
* The only revision after this call is `create({ cloneFromFlowId: id })`, which
|
|
115
|
+
* mints a DIFFERENT Flow under a new id that customers have to be pointed at.
|
|
116
|
+
*
|
|
117
|
+
* ⛔ `{ confirm: true }` IS REQUIRED AND IS THE LITERAL `true`. The argument is
|
|
118
|
+
* not optional and the type is not `boolean`, so `publish(id)` and
|
|
119
|
+
* `publish(id, { confirm: someFlag })` are COMPILE errors: the flag has to be
|
|
120
|
+
* written out at the call site, where the person writing it can see what it does.
|
|
121
|
+
* The value is passed THROUGH rather than hardcoded — a JavaScript caller who
|
|
122
|
+
* sends `false` gets a 400 `FLOW_PUBLISH_REQUIRES_CONFIRMATION` instead of a
|
|
123
|
+
* publish they did not ask for.
|
|
124
|
+
*
|
|
125
|
+
* A Flow that is not a DRAFT answers 409 `FLOW_NOT_DRAFT`.
|
|
126
|
+
*/
|
|
127
|
+
publish(id: string, options: FlowPublishInput): Promise<FlowPublishResult>;
|
|
128
|
+
/**
|
|
129
|
+
* Takes a PUBLISHED Flow out of circulation.
|
|
130
|
+
*
|
|
131
|
+
* ⚠️ Not `delete()`: deleting only works on a DRAFT and removes the row;
|
|
132
|
+
* deprecating works on a published Flow and only marks it.
|
|
133
|
+
*
|
|
134
|
+
* `supersededByFlowId` is the LOCAL id of the successor — read its JSDoc. It is
|
|
135
|
+
* the forward half of the version chain whose backward half `cloneFromFlowId`
|
|
136
|
+
* writes; a `metaFlowId` there records a pointer to no row of ours and the chain
|
|
137
|
+
* ends silently. Omitting it is legitimate and means "nothing replaces this".
|
|
138
|
+
*
|
|
139
|
+
* The result echoes `supersededBy` ALWAYS, `null` included, so a successor that
|
|
140
|
+
* was recorded is distinguishable from one that got dropped on the way.
|
|
141
|
+
*/
|
|
142
|
+
deprecate(id: string, options?: FlowDeprecateInput): Promise<FlowDeprecateResult>;
|
|
143
|
+
/**
|
|
144
|
+
* The forms customers submitted to ONE Flow, newest first.
|
|
145
|
+
*
|
|
146
|
+
* ⚠️ CHECK `notice`. `"FLOW_RESPONSES_WINDOW_TRUNCATED"` means the Flow has minted
|
|
147
|
+
* more sends than one request will correlate, so the page is SHORT — a truncated
|
|
148
|
+
* answer read as a complete one is how a caller concludes submissions were lost.
|
|
149
|
+
*
|
|
150
|
+
* ⚠️ Two retention windows, and neither is a bug. An answer stops being readable
|
|
151
|
+
* 30 days after it arrived; a `contactPhone` disappears (becomes `null`) 37 days
|
|
152
|
+
* after the SEND, so a response can outlive the phone that produced it.
|
|
153
|
+
*/
|
|
154
|
+
listResponses(id: string, params?: FlowResponseListParams): Promise<FlowResponseListResult>;
|
|
155
|
+
/**
|
|
156
|
+
* The state of ONE number's `data_exchange` endpoint keypair: what we hold, where
|
|
157
|
+
* Meta calls, and whether Meta still holds the public half we hold.
|
|
158
|
+
*
|
|
159
|
+
* `whatsappNumberId` must be the number THIS KEY is bound to — the path is checked
|
|
160
|
+
* against the credential, never used to look a number up, so another number of
|
|
161
|
+
* your own tenant answers 404 `FLOW_NUMBER_NOT_FOUND` (404 and not 403, so an id
|
|
162
|
+
* cannot be confirmed by guessing). Reach another number with
|
|
163
|
+
* `client.withNumber(...)`.
|
|
164
|
+
*
|
|
165
|
+
* ⛔ Read `metaStatus` as four values, not two. `NOT_SET` is Meta saying it holds
|
|
166
|
+
* no key; `UNKNOWN` is us failing to ask. Rotating on an `UNKNOWN` — i.e. on a
|
|
167
|
+
* transient Graph 500 — destroys a key that was working perfectly.
|
|
168
|
+
*
|
|
169
|
+
* ⚠️ Needs `flows:manage`, although it only reads: `endpointUrl` is a credential.
|
|
170
|
+
* See {@link FlowEndpointKeyStatus}.
|
|
171
|
+
*/
|
|
172
|
+
getEndpointKey(whatsappNumberId: string): Promise<FlowEndpointKeyStatus>;
|
|
173
|
+
/**
|
|
174
|
+
* ⛔ THREE OPERATIONS BEHIND ONE `POST`, AND THE THIRD IS DESTRUCTIVE. Whoever
|
|
175
|
+
* reads "POST" reads "create"; this call is named `rotate` because on a number
|
|
176
|
+
* that already has a live key it does not create anything — it REPLACES.
|
|
177
|
+
*
|
|
178
|
+
* 1. **Creation** — no keypair has ever been generated. Mints one, uploads the
|
|
179
|
+
* public half, done. Answers `replaced: false`.
|
|
180
|
+
* 2. **Resume** — a pair exists but Meta never accepted it (`uploadedAt` is
|
|
181
|
+
* `null`). Re-uploads the SAME stored public half, so the call CONVERGES and
|
|
182
|
+
* destroys nothing. Also `replaced: false`.
|
|
183
|
+
* 3. **⛔ REPLACEMENT** — a key of ours is live at Meta. Meta holds exactly ONE
|
|
184
|
+
* public key per phone id, so registering a second does not add it: the first
|
|
185
|
+
* is GONE, and with it every `data_exchange` Flow on that number, at the
|
|
186
|
+
* instant Meta accepts. The customer's symptom is the form no longer opening,
|
|
187
|
+
* and NOTHING on our side reports it — the endpoint just answers 421 to
|
|
188
|
+
* bodies encrypted for a key we no longer hold. Answers `replaced: true`.
|
|
189
|
+
*
|
|
190
|
+
* ⛔ Case 3 requires `{ confirm: true }` (the literal `true`, strictly) and
|
|
191
|
+
* answers 400 `FLOW_ENDPOINT_KEY_REQUIRES_CONFIRMATION` without it. Cases 1 and 2
|
|
192
|
+
* do NOT — which is why `confirm` is optional here while `publish`'s is
|
|
193
|
+
* mandatory: the gate is on the STATE of the number, not on the call. Call
|
|
194
|
+
* {@link getEndpointKey} first if you need to know which of the three you are
|
|
195
|
+
* about to do.
|
|
196
|
+
*
|
|
197
|
+
* ⚠️ ALWAYS read `replaced` in the result. `replaced: true` is the only place the
|
|
198
|
+
* sentence "the key that was working is gone" is ever said; a 200 alone does not
|
|
199
|
+
* say it.
|
|
200
|
+
*/
|
|
201
|
+
rotateEndpointKey(whatsappNumberId: string, options?: FlowEndpointKeyRotateInput): Promise<FlowEndpointKeyRotateResult>;
|
|
202
|
+
}
|
|
203
|
+
//# sourceMappingURL=flows.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"flows.d.ts","sourceRoot":"","sources":["../../src/resources/flows.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAE7C,OAAO,KAAK,EACR,eAAe,EACf,WAAW,EACX,gBAAgB,EAChB,kBAAkB,EAClB,mBAAmB,EACnB,0BAA0B,EAC1B,2BAA2B,EAC3B,qBAAqB,EACrB,oBAAoB,EACpB,cAAc,EACd,cAAc,EACd,gBAAgB,EAChB,iBAAiB,EACjB,sBAAsB,EACtB,sBAAsB,EACtB,gBAAgB,EAChB,eAAe,EAClB,MAAM,aAAa,CAAC;AAErB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,wBAAgB,wBAAwB,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,EAAE,GAAG,IAAI,CASzE;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,qBAAa,aAAa;;gBAGV,IAAI,EAAE,UAAU;IAI5B;;;;;;OAMG;IACG,IAAI,CAAC,MAAM,CAAC,EAAE,cAAc,GAAG,OAAO,CAAC,cAAc,CAAC;IAW5D;;;;;;;;;;OAUG;IACG,MAAM,CAAC,KAAK,EAAE,eAAe,GAAG,OAAO,CAAC,WAAW,CAAC;IAY1D;;;;;;;OAOG;IACG,MAAM,CAAC,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,eAAe,GAAG,OAAO,CAAC,gBAAgB,CAAC;IAW3E;;;OAGG;IACG,MAAM,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,gBAAgB,CAAC;IAOnD;;;;;;;;;;;;;;;;;;OAkBG;IACG,UAAU,CAAC,EAAE,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,oBAAoB,CAAC;IAQ7E;;;;;;;;;;;;;;;;OAgBG;IACG,OAAO,CAAC,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE,gBAAgB,GAAG,OAAO,CAAC,iBAAiB,CAAC;IAQhF;;;;;;;;;;;;;OAaG;IACG,SAAS,CACX,EAAE,EAAE,MAAM,EACV,OAAO,GAAE,kBAAuB,GACjC,OAAO,CAAC,mBAAmB,CAAC;IAU/B;;;;;;;;;;OAUG;IACG,aAAa,CACf,EAAE,EAAE,MAAM,EACV,MAAM,CAAC,EAAE,sBAAsB,GAChC,OAAO,CAAC,sBAAsB,CAAC;IAWlC;;;;;;;;;;;;;;;;OAgBG;IACG,cAAc,CAAC,gBAAgB,EAAE,MAAM,GAAG,OAAO,CAAC,qBAAqB,CAAC;IAO9E;;;;;;;;;;;;;;;;;;;;;;;;;;;OA2BG;IACG,iBAAiB,CACnB,gBAAgB,EAAE,MAAM,EACxB,OAAO,GAAE,0BAA+B,GACzC,OAAO,CAAC,2BAA2B,CAAC;CAS1C"}
|