@wats/graph 0.3.1
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/LICENSE +21 -0
- package/README.md +3 -0
- package/dist/client.d.ts +41 -0
- package/dist/client.js +392 -0
- package/dist/createFetchTransport.d.ts +6 -0
- package/dist/createFetchTransport.js +46 -0
- package/dist/createMockTransport.d.ts +20 -0
- package/dist/createMockTransport.js +120 -0
- package/dist/endpoint.d.ts +26 -0
- package/dist/endpoint.js +223 -0
- package/dist/endpoints/businessManagement.d.ts +157 -0
- package/dist/endpoints/businessManagement.js +277 -0
- package/dist/endpoints/calling.d.ts +65 -0
- package/dist/endpoints/calling.js +284 -0
- package/dist/endpoints/flows/callables.d.ts +90 -0
- package/dist/endpoints/flows/callables.js +97 -0
- package/dist/endpoints/flows/dataExchange.d.ts +4 -0
- package/dist/endpoints/flows/dataExchange.js +40 -0
- package/dist/endpoints/flows/flowJson.d.ts +18 -0
- package/dist/endpoints/flows/flowJson.js +214 -0
- package/dist/endpoints/flows/index.d.ts +6 -0
- package/dist/endpoints/flows/index.js +26 -0
- package/dist/endpoints/flows/shared.d.ts +17 -0
- package/dist/endpoints/flows/shared.js +113 -0
- package/dist/endpoints/flows/types.d.ts +105 -0
- package/dist/endpoints/flows/types.js +0 -0
- package/dist/endpoints/flows.d.ts +2 -0
- package/dist/endpoints/flows.js +23 -0
- package/dist/endpoints/media.d.ts +123 -0
- package/dist/endpoints/media.js +976 -0
- package/dist/endpoints/messages.d.ts +375 -0
- package/dist/endpoints/messages.js +675 -0
- package/dist/endpoints/templates/builders.d.ts +9 -0
- package/dist/endpoints/templates/builders.js +101 -0
- package/dist/endpoints/templates/callables.d.ts +54 -0
- package/dist/endpoints/templates/callables.js +98 -0
- package/dist/endpoints/templates/index.d.ts +5 -0
- package/dist/endpoints/templates/index.js +16 -0
- package/dist/endpoints/templates/shared.d.ts +21 -0
- package/dist/endpoints/templates/shared.js +203 -0
- package/dist/endpoints/templates/types.d.ts +135 -0
- package/dist/endpoints/templates/types.js +0 -0
- package/dist/endpoints/templates/validation.d.ts +2 -0
- package/dist/endpoints/templates/validation.js +113 -0
- package/dist/endpoints/templates.d.ts +2 -0
- package/dist/endpoints/templates.js +14 -0
- package/dist/endpoints/waba/index.d.ts +4 -0
- package/dist/endpoints/waba/index.js +1 -0
- package/dist/endpoints/waba/phoneNumbers.d.ts +25 -0
- package/dist/endpoints/waba/phoneNumbers.js +23 -0
- package/dist/endpoints/waba/types.d.ts +8 -0
- package/dist/endpoints/waba/types.js +0 -0
- package/dist/endpoints/wabaEndpoints.d.ts +6 -0
- package/dist/endpoints/wabaEndpoints.js +38 -0
- package/dist/errorRegistry.d.ts +45 -0
- package/dist/errorRegistry.js +68 -0
- package/dist/errorSubclasses.d.ts +277 -0
- package/dist/errorSubclasses.js +613 -0
- package/dist/errors.d.ts +92 -0
- package/dist/errors.js +250 -0
- package/dist/index.d.ts +20 -0
- package/dist/index.js +48 -0
- package/dist/internal/validation/arrays.d.ts +19 -0
- package/dist/internal/validation/arrays.js +102 -0
- package/dist/internal/validation/errors.d.ts +3 -0
- package/dist/internal/validation/errors.js +13 -0
- package/dist/internal/validation/headers.d.ts +15 -0
- package/dist/internal/validation/headers.js +77 -0
- package/dist/internal/validation/index.d.ts +8 -0
- package/dist/internal/validation/index.js +8 -0
- package/dist/internal/validation/json.d.ts +10 -0
- package/dist/internal/validation/json.js +79 -0
- package/dist/internal/validation/options.d.ts +5 -0
- package/dist/internal/validation/options.js +36 -0
- package/dist/internal/validation/paths.d.ts +8 -0
- package/dist/internal/validation/paths.js +37 -0
- package/dist/internal/validation/records.d.ts +20 -0
- package/dist/internal/validation/records.js +69 -0
- package/dist/internal/validation/strings.d.ts +12 -0
- package/dist/internal/validation/strings.js +46 -0
- package/dist/pagination.d.ts +35 -0
- package/dist/pagination.js +160 -0
- package/dist/subclients/phoneNumberClient.d.ts +60 -0
- package/dist/subclients/phoneNumberClient.js +194 -0
- package/dist/subclients/wabaClient.d.ts +66 -0
- package/dist/subclients/wabaClient.js +180 -0
- package/dist/transport.d.ts +32 -0
- package/dist/transport.js +5 -0
- package/package.json +70 -0
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { type EndpointInvokeOptions } from "../endpoint";
|
|
2
|
+
import type { GraphClient } from "../client";
|
|
3
|
+
export type CallAction = "connect" | "pre_accept" | "accept" | "reject" | "terminate";
|
|
4
|
+
export type CallSdpType = "offer" | "answer" | string;
|
|
5
|
+
export declare const CALL_BIZ_OPAQUE_CALLBACK_DATA_MAX_LENGTH = 512;
|
|
6
|
+
export declare const CALL_SESSION_MAX_STRING_LENGTH = 16384;
|
|
7
|
+
export declare const CALL_SESSION_MAX_DEPTH = 8;
|
|
8
|
+
export declare const CALL_SESSION_MAX_ARRAY_LENGTH = 100;
|
|
9
|
+
export declare const CALL_SESSION_MAX_BYTES = 65536;
|
|
10
|
+
export interface CallSessionDescription {
|
|
11
|
+
readonly sdpType?: CallSdpType;
|
|
12
|
+
readonly sdp: string;
|
|
13
|
+
readonly [key: string]: unknown;
|
|
14
|
+
}
|
|
15
|
+
export interface CallSessionDescriptionPayload {
|
|
16
|
+
readonly sdp_type?: CallSdpType;
|
|
17
|
+
readonly sdp: string;
|
|
18
|
+
readonly [key: string]: unknown;
|
|
19
|
+
}
|
|
20
|
+
export interface InitiateCallRequest {
|
|
21
|
+
readonly to: string;
|
|
22
|
+
readonly session: CallSessionDescription | Record<string, unknown>;
|
|
23
|
+
readonly bizOpaqueCallbackData?: string;
|
|
24
|
+
}
|
|
25
|
+
export interface PreAcceptCallRequest {
|
|
26
|
+
readonly callId: string;
|
|
27
|
+
readonly session?: CallSessionDescription | Record<string, unknown>;
|
|
28
|
+
}
|
|
29
|
+
export interface AcceptCallRequest {
|
|
30
|
+
readonly callId: string;
|
|
31
|
+
readonly session?: CallSessionDescription | Record<string, unknown>;
|
|
32
|
+
readonly bizOpaqueCallbackData?: string;
|
|
33
|
+
}
|
|
34
|
+
export interface RejectCallRequest {
|
|
35
|
+
readonly callId: string;
|
|
36
|
+
}
|
|
37
|
+
export interface TerminateCallRequest {
|
|
38
|
+
readonly callId: string;
|
|
39
|
+
}
|
|
40
|
+
export interface CallLifecycleResponse {
|
|
41
|
+
readonly id?: string;
|
|
42
|
+
readonly success?: boolean;
|
|
43
|
+
readonly [key: string]: unknown;
|
|
44
|
+
}
|
|
45
|
+
type CallsParams = {
|
|
46
|
+
readonly phoneNumberId: string;
|
|
47
|
+
};
|
|
48
|
+
type WireBody = Record<string, unknown>;
|
|
49
|
+
export declare function sanitizeCallSession(input: unknown): CallSessionDescriptionPayload;
|
|
50
|
+
export declare const initiateCall: ((client: GraphClient, params: CallsParams, body: InitiateCallRequest, opts?: EndpointInvokeOptions) => Promise<CallLifecycleResponse>) & {
|
|
51
|
+
definition: import("..").EndpointDefinition<CallsParams, WireBody, CallLifecycleResponse>;
|
|
52
|
+
};
|
|
53
|
+
export declare const preAcceptCall: ((client: GraphClient, params: CallsParams, body: PreAcceptCallRequest, opts?: EndpointInvokeOptions) => Promise<CallLifecycleResponse>) & {
|
|
54
|
+
definition: import("..").EndpointDefinition<CallsParams, WireBody, CallLifecycleResponse>;
|
|
55
|
+
};
|
|
56
|
+
export declare const acceptCall: ((client: GraphClient, params: CallsParams, body: AcceptCallRequest, opts?: EndpointInvokeOptions) => Promise<CallLifecycleResponse>) & {
|
|
57
|
+
definition: import("..").EndpointDefinition<CallsParams, WireBody, CallLifecycleResponse>;
|
|
58
|
+
};
|
|
59
|
+
export declare const rejectCall: ((client: GraphClient, params: CallsParams, body: RejectCallRequest, opts?: EndpointInvokeOptions) => Promise<CallLifecycleResponse>) & {
|
|
60
|
+
definition: import("..").EndpointDefinition<CallsParams, WireBody, CallLifecycleResponse>;
|
|
61
|
+
};
|
|
62
|
+
export declare const terminateCall: ((client: GraphClient, params: CallsParams, body: TerminateCallRequest, opts?: EndpointInvokeOptions) => Promise<CallLifecycleResponse>) & {
|
|
63
|
+
definition: import("..").EndpointDefinition<CallsParams, WireBody, CallLifecycleResponse>;
|
|
64
|
+
};
|
|
65
|
+
export {};
|
|
@@ -0,0 +1,284 @@
|
|
|
1
|
+
import { defineEndpoint } from "../endpoint";
|
|
2
|
+
import { GraphRequestValidationError } from "../errors";
|
|
3
|
+
export const CALL_BIZ_OPAQUE_CALLBACK_DATA_MAX_LENGTH = 512;
|
|
4
|
+
export const CALL_SESSION_MAX_STRING_LENGTH = 16384;
|
|
5
|
+
export const CALL_SESSION_MAX_DEPTH = 8;
|
|
6
|
+
export const CALL_SESSION_MAX_ARRAY_LENGTH = 100;
|
|
7
|
+
export const CALL_SESSION_MAX_BYTES = 65536;
|
|
8
|
+
function hasControlChar(value) {
|
|
9
|
+
for (let i = 0;i < value.length; i += 1) {
|
|
10
|
+
const code = value.charCodeAt(i);
|
|
11
|
+
if (code < 32 || code === 127)
|
|
12
|
+
return true;
|
|
13
|
+
}
|
|
14
|
+
return false;
|
|
15
|
+
}
|
|
16
|
+
function validationError(message) {
|
|
17
|
+
return new GraphRequestValidationError(message);
|
|
18
|
+
}
|
|
19
|
+
function isUnsafePrototypeKey(key) {
|
|
20
|
+
return key === "__proto__" || key === "constructor" || key === "prototype";
|
|
21
|
+
}
|
|
22
|
+
function assertPublicString(value, fieldName, maxLength = 256) {
|
|
23
|
+
if (typeof value !== "string") {
|
|
24
|
+
throw validationError(`Invalid Calling API input: ${fieldName} must be a string.`);
|
|
25
|
+
}
|
|
26
|
+
if (value.length === 0 || value.trim().length === 0) {
|
|
27
|
+
throw validationError(`Invalid Calling API input: ${fieldName} must be non-empty.`);
|
|
28
|
+
}
|
|
29
|
+
if (value.length > maxLength) {
|
|
30
|
+
throw validationError(`Invalid Calling API input: ${fieldName} exceeds ${maxLength}-character limit.`);
|
|
31
|
+
}
|
|
32
|
+
if (hasControlChar(value)) {
|
|
33
|
+
throw validationError(`Invalid Calling API input: ${fieldName} must not contain control characters.`);
|
|
34
|
+
}
|
|
35
|
+
if (value === "." || value === ".." || value.includes("/") || value.includes("\\") || value.includes("?") || value.includes("#")) {
|
|
36
|
+
throw validationError(`Invalid Calling API input: ${fieldName} contains an unsafe path segment.`);
|
|
37
|
+
}
|
|
38
|
+
let decoded = value;
|
|
39
|
+
for (let round = 0;round < 5; round += 1) {
|
|
40
|
+
let next;
|
|
41
|
+
try {
|
|
42
|
+
next = decodeURIComponent(decoded);
|
|
43
|
+
} catch {
|
|
44
|
+
throw validationError(`Invalid Calling API input: ${fieldName} contains malformed percent encoding.`);
|
|
45
|
+
}
|
|
46
|
+
if (next === decoded)
|
|
47
|
+
break;
|
|
48
|
+
decoded = next;
|
|
49
|
+
if (decoded === "." || decoded === ".." || decoded.includes("/") || decoded.includes("\\") || decoded.includes("?") || decoded.includes("#")) {
|
|
50
|
+
throw validationError(`Invalid Calling API input: ${fieldName} contains an unsafe path segment.`);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
return value;
|
|
54
|
+
}
|
|
55
|
+
function assertNoEncodedUnsafePathSegment(value, fieldName) {
|
|
56
|
+
let decoded = value;
|
|
57
|
+
for (let round = 0;round < 5; round += 1) {
|
|
58
|
+
let next;
|
|
59
|
+
try {
|
|
60
|
+
next = decodeURIComponent(decoded);
|
|
61
|
+
} catch {
|
|
62
|
+
throw validationError(`Invalid Calling API input: ${fieldName} contains malformed percent encoding.`);
|
|
63
|
+
}
|
|
64
|
+
if (next === decoded)
|
|
65
|
+
break;
|
|
66
|
+
decoded = next;
|
|
67
|
+
if (decoded === "." || decoded === ".." || decoded.includes("/") || decoded.includes("\\") || decoded.includes("?") || decoded.includes("#")) {
|
|
68
|
+
throw validationError(`Invalid Calling API input: ${fieldName} contains an unsafe path segment.`);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
function optionalTracker(value) {
|
|
73
|
+
if (value === undefined)
|
|
74
|
+
return;
|
|
75
|
+
return assertPublicString(value, "bizOpaqueCallbackData", CALL_BIZ_OPAQUE_CALLBACK_DATA_MAX_LENGTH);
|
|
76
|
+
}
|
|
77
|
+
function assertPlainRecord(value, path) {
|
|
78
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) {
|
|
79
|
+
throw validationError(`Invalid Calling API input: ${path} must be a plain object.`);
|
|
80
|
+
}
|
|
81
|
+
const proto = Object.getPrototypeOf(value);
|
|
82
|
+
if (proto !== Object.prototype && proto !== null) {
|
|
83
|
+
throw validationError(`Invalid Calling API input: ${path} must be a plain object.`);
|
|
84
|
+
}
|
|
85
|
+
const descriptors = Object.getOwnPropertyDescriptors(value);
|
|
86
|
+
if (Object.prototype.hasOwnProperty.call(descriptors, "toJSON") || "toJSON" in value) {
|
|
87
|
+
throw validationError(`Invalid Calling API input: ${path} must not define toJSON.`);
|
|
88
|
+
}
|
|
89
|
+
for (const [key, descriptor] of Object.entries(descriptors)) {
|
|
90
|
+
if (isUnsafePrototypeKey(key)) {
|
|
91
|
+
throw validationError(`Invalid Calling API input: ${path} contains an unsafe prototype key.`);
|
|
92
|
+
}
|
|
93
|
+
if (key.length === 0 || hasControlChar(key)) {
|
|
94
|
+
throw validationError(`Invalid Calling API input: ${path} contains an invalid key.`);
|
|
95
|
+
}
|
|
96
|
+
if (typeof descriptor.get === "function" || typeof descriptor.set === "function") {
|
|
97
|
+
throw validationError(`Invalid Calling API input: ${path}.${key} must not use accessors.`);
|
|
98
|
+
}
|
|
99
|
+
if (typeof descriptor.value === "function" || typeof descriptor.value === "symbol") {
|
|
100
|
+
throw validationError(`Invalid Calling API input: ${path}.${key} must be JSON-serializable.`);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
return value;
|
|
104
|
+
}
|
|
105
|
+
function assertArray(value, path) {
|
|
106
|
+
if (!Array.isArray(value)) {
|
|
107
|
+
throw validationError(`Invalid Calling API input: ${path} must be an array.`);
|
|
108
|
+
}
|
|
109
|
+
if (value.length > CALL_SESSION_MAX_ARRAY_LENGTH) {
|
|
110
|
+
throw validationError(`Invalid Calling API input: ${path} exceeds ${CALL_SESSION_MAX_ARRAY_LENGTH}-item limit.`);
|
|
111
|
+
}
|
|
112
|
+
if (Object.getPrototypeOf(value) !== Array.prototype) {
|
|
113
|
+
throw validationError(`Invalid Calling API input: ${path} must use Array.prototype.`);
|
|
114
|
+
}
|
|
115
|
+
if (Object.prototype.hasOwnProperty.call(value, Symbol.iterator) || Object.prototype.hasOwnProperty.call(value, "map")) {
|
|
116
|
+
throw validationError(`Invalid Calling API input: ${path} must not override Array.prototype methods.`);
|
|
117
|
+
}
|
|
118
|
+
const descriptors = Object.getOwnPropertyDescriptors(value);
|
|
119
|
+
if (Object.prototype.hasOwnProperty.call(descriptors, "toJSON") || "toJSON" in value) {
|
|
120
|
+
throw validationError(`Invalid Calling API input: ${path} must not define toJSON.`);
|
|
121
|
+
}
|
|
122
|
+
const out = [];
|
|
123
|
+
for (let index = 0;index < value.length; index += 1) {
|
|
124
|
+
if (!Object.prototype.hasOwnProperty.call(value, index)) {
|
|
125
|
+
throw validationError(`Invalid Calling API input: ${path} must not contain sparse array holes.`);
|
|
126
|
+
}
|
|
127
|
+
const descriptor = descriptors[String(index)];
|
|
128
|
+
if (descriptor === undefined || typeof descriptor.get === "function" || typeof descriptor.set === "function") {
|
|
129
|
+
throw validationError(`Invalid Calling API input: ${path} must not use accessors.`);
|
|
130
|
+
}
|
|
131
|
+
out.push(descriptor.value);
|
|
132
|
+
}
|
|
133
|
+
return out;
|
|
134
|
+
}
|
|
135
|
+
function cloneJson(value, path, seen, depth) {
|
|
136
|
+
if (depth > CALL_SESSION_MAX_DEPTH) {
|
|
137
|
+
throw validationError(`Invalid Calling API input: ${path} exceeds maximum depth ${CALL_SESSION_MAX_DEPTH}.`);
|
|
138
|
+
}
|
|
139
|
+
if (value === null || typeof value === "boolean")
|
|
140
|
+
return value;
|
|
141
|
+
if (typeof value === "string") {
|
|
142
|
+
if (value.length === 0 || value.length > CALL_SESSION_MAX_STRING_LENGTH || value.includes("\x00") || value.includes("\x7F")) {
|
|
143
|
+
throw validationError(`Invalid Calling API input: ${path} contains an invalid string.`);
|
|
144
|
+
}
|
|
145
|
+
return value;
|
|
146
|
+
}
|
|
147
|
+
if (typeof value === "number") {
|
|
148
|
+
if (!Number.isFinite(value)) {
|
|
149
|
+
throw validationError(`Invalid Calling API input: ${path} contains a non-finite number.`);
|
|
150
|
+
}
|
|
151
|
+
return value;
|
|
152
|
+
}
|
|
153
|
+
if (value === undefined)
|
|
154
|
+
return;
|
|
155
|
+
if (typeof value === "function" || typeof value === "symbol") {
|
|
156
|
+
throw validationError(`Invalid Calling API input: ${path} must be JSON-serializable.`);
|
|
157
|
+
}
|
|
158
|
+
if (Array.isArray(value)) {
|
|
159
|
+
if (seen.has(value))
|
|
160
|
+
throw validationError(`Invalid Calling API input: ${path} must not contain cycles.`);
|
|
161
|
+
seen.add(value);
|
|
162
|
+
const arr = assertArray(value, path);
|
|
163
|
+
const out = [];
|
|
164
|
+
for (let index = 0;index < arr.length; index += 1) {
|
|
165
|
+
const cloned = cloneJson(arr[index], `${path}[${index}]`, seen, depth + 1);
|
|
166
|
+
if (cloned !== undefined)
|
|
167
|
+
out.push(cloned);
|
|
168
|
+
}
|
|
169
|
+
seen.delete(value);
|
|
170
|
+
return out;
|
|
171
|
+
}
|
|
172
|
+
const record = assertPlainRecord(value, path);
|
|
173
|
+
if (seen.has(record))
|
|
174
|
+
throw validationError(`Invalid Calling API input: ${path} must not contain cycles.`);
|
|
175
|
+
seen.add(record);
|
|
176
|
+
const descriptors = Object.getOwnPropertyDescriptors(record);
|
|
177
|
+
const out = {};
|
|
178
|
+
for (const [key, descriptor] of Object.entries(descriptors)) {
|
|
179
|
+
if (path === "session" && key === "sdp_type") {
|
|
180
|
+
throw validationError("Invalid Calling API input: session.sdpType must use camelCase; Graph snake_case is reserved for the transport boundary.");
|
|
181
|
+
}
|
|
182
|
+
const wireKey = key === "sdpType" ? "sdp_type" : key;
|
|
183
|
+
const cloned = cloneJson(descriptor.value, `${path}.${key}`, seen, depth + 1);
|
|
184
|
+
if (cloned !== undefined)
|
|
185
|
+
out[wireKey] = cloned;
|
|
186
|
+
}
|
|
187
|
+
seen.delete(record);
|
|
188
|
+
return out;
|
|
189
|
+
}
|
|
190
|
+
export function sanitizeCallSession(input) {
|
|
191
|
+
const cloned = cloneJson(input, "session", new WeakSet, 0);
|
|
192
|
+
const record = assertPlainRecord(cloned, "session");
|
|
193
|
+
if (record.sdp_type !== undefined && typeof record.sdp_type !== "string") {
|
|
194
|
+
throw validationError("Invalid Calling API input: session.sdpType must be a string.");
|
|
195
|
+
}
|
|
196
|
+
if (typeof record.sdp !== "string" || record.sdp.length === 0 || record.sdp.length > CALL_SESSION_MAX_STRING_LENGTH) {
|
|
197
|
+
throw validationError("Invalid Calling API input: session.sdp must be a non-empty string within the session string limit.");
|
|
198
|
+
}
|
|
199
|
+
const encoded = JSON.stringify(record);
|
|
200
|
+
if (new TextEncoder().encode(encoded).byteLength > CALL_SESSION_MAX_BYTES) {
|
|
201
|
+
throw validationError(`Invalid Calling API input: session exceeds ${CALL_SESSION_MAX_BYTES}-byte serialized limit.`);
|
|
202
|
+
}
|
|
203
|
+
return record;
|
|
204
|
+
}
|
|
205
|
+
function assertBodyRecord(value, helperName) {
|
|
206
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) {
|
|
207
|
+
throw validationError(`Invalid ${helperName} input: expected an object.`);
|
|
208
|
+
}
|
|
209
|
+
return assertPlainRecord(value, helperName);
|
|
210
|
+
}
|
|
211
|
+
function buildInitiate(body) {
|
|
212
|
+
const record = assertBodyRecord(body, "initiateCall");
|
|
213
|
+
const tracker = optionalTracker(record.bizOpaqueCallbackData);
|
|
214
|
+
return {
|
|
215
|
+
messaging_product: "whatsapp",
|
|
216
|
+
to: assertPublicString(record.to, "to"),
|
|
217
|
+
action: "connect",
|
|
218
|
+
session: sanitizeCallSession(record.session),
|
|
219
|
+
...tracker !== undefined ? { biz_opaque_callback_data: tracker } : {}
|
|
220
|
+
};
|
|
221
|
+
}
|
|
222
|
+
function buildPreAccept(body) {
|
|
223
|
+
const record = assertBodyRecord(body, "preAcceptCall");
|
|
224
|
+
const out = {
|
|
225
|
+
messaging_product: "whatsapp",
|
|
226
|
+
call_id: assertPublicString(record.callId, "callId"),
|
|
227
|
+
action: "pre_accept"
|
|
228
|
+
};
|
|
229
|
+
if (record.session !== undefined)
|
|
230
|
+
out.session = sanitizeCallSession(record.session);
|
|
231
|
+
return out;
|
|
232
|
+
}
|
|
233
|
+
function buildAccept(body) {
|
|
234
|
+
const record = assertBodyRecord(body, "acceptCall");
|
|
235
|
+
const tracker = optionalTracker(record.bizOpaqueCallbackData);
|
|
236
|
+
const out = {
|
|
237
|
+
messaging_product: "whatsapp",
|
|
238
|
+
call_id: assertPublicString(record.callId, "callId"),
|
|
239
|
+
action: "accept"
|
|
240
|
+
};
|
|
241
|
+
if (record.session !== undefined)
|
|
242
|
+
out.session = sanitizeCallSession(record.session);
|
|
243
|
+
if (tracker !== undefined)
|
|
244
|
+
out.biz_opaque_callback_data = tracker;
|
|
245
|
+
return out;
|
|
246
|
+
}
|
|
247
|
+
function buildReject(body) {
|
|
248
|
+
const record = assertBodyRecord(body, "rejectCall");
|
|
249
|
+
return {
|
|
250
|
+
messaging_product: "whatsapp",
|
|
251
|
+
call_id: assertPublicString(record.callId, "callId"),
|
|
252
|
+
action: "reject"
|
|
253
|
+
};
|
|
254
|
+
}
|
|
255
|
+
function buildTerminate(body) {
|
|
256
|
+
const record = assertBodyRecord(body, "terminateCall");
|
|
257
|
+
return {
|
|
258
|
+
messaging_product: "whatsapp",
|
|
259
|
+
call_id: assertPublicString(record.callId, "callId"),
|
|
260
|
+
action: "terminate"
|
|
261
|
+
};
|
|
262
|
+
}
|
|
263
|
+
const callsEndpoint = defineEndpoint({
|
|
264
|
+
method: "POST",
|
|
265
|
+
pathTemplate: "/{phoneNumberId}/calls",
|
|
266
|
+
params: { phoneNumberId: { in: "path", required: true } },
|
|
267
|
+
bodyContentType: "application/json"
|
|
268
|
+
});
|
|
269
|
+
function safeParams(params) {
|
|
270
|
+
if (typeof params !== "object" || params === null || Array.isArray(params)) {
|
|
271
|
+
throw validationError("Invalid Calling API input: params must be an object.");
|
|
272
|
+
}
|
|
273
|
+
const descriptors = Object.getOwnPropertyDescriptors(params);
|
|
274
|
+
const descriptor = descriptors.phoneNumberId;
|
|
275
|
+
if (descriptor === undefined || typeof descriptor.get === "function" || typeof descriptor.set === "function") {
|
|
276
|
+
throw validationError("Invalid Calling API input: phoneNumberId must be a string data property.");
|
|
277
|
+
}
|
|
278
|
+
return { phoneNumberId: assertPublicString(descriptor.value, "phoneNumberId") };
|
|
279
|
+
}
|
|
280
|
+
export const initiateCall = Object.assign(async (client, params, body, opts) => callsEndpoint(client, safeParams(params), buildInitiate(body), opts), { definition: callsEndpoint.definition });
|
|
281
|
+
export const preAcceptCall = Object.assign(async (client, params, body, opts) => callsEndpoint(client, safeParams(params), buildPreAccept(body), opts), { definition: callsEndpoint.definition });
|
|
282
|
+
export const acceptCall = Object.assign(async (client, params, body, opts) => callsEndpoint(client, safeParams(params), buildAccept(body), opts), { definition: callsEndpoint.definition });
|
|
283
|
+
export const rejectCall = Object.assign(async (client, params, body, opts) => callsEndpoint(client, safeParams(params), buildReject(body), opts), { definition: callsEndpoint.definition });
|
|
284
|
+
export const terminateCall = Object.assign(async (client, params, body, opts) => callsEndpoint(client, safeParams(params), buildTerminate(body), opts), { definition: callsEndpoint.definition });
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import type { CreateFlowBody, FlowAssetsResponse, FlowDetails, FlowListResponse, FlowMutationResponse, GetFlowAssetsInput, GetFlowInput, ListFlowsInput, UpdateFlowJsonBody, UpdateFlowMetadataBody } from "./types";
|
|
2
|
+
declare const listFlowsRaw: import("../..").EndpointCallable<{
|
|
3
|
+
wabaId: string;
|
|
4
|
+
fields?: string;
|
|
5
|
+
status?: string;
|
|
6
|
+
name?: string;
|
|
7
|
+
invalidate_preview?: string;
|
|
8
|
+
phone_number_id?: string;
|
|
9
|
+
limit?: string;
|
|
10
|
+
after?: string;
|
|
11
|
+
}, never, FlowListResponse>;
|
|
12
|
+
export declare const listFlows: {
|
|
13
|
+
(client: Parameters<typeof listFlowsRaw>[0], params: ListFlowsInput, body?: never, opts?: Parameters<typeof listFlowsRaw>[3]): Promise<FlowListResponse>;
|
|
14
|
+
readonly definition: typeof listFlowsRaw.definition;
|
|
15
|
+
};
|
|
16
|
+
declare const getFlowRaw: import("../..").EndpointCallable<{
|
|
17
|
+
flowId: string;
|
|
18
|
+
fields?: string;
|
|
19
|
+
invalidate_preview?: string;
|
|
20
|
+
phone_number_id?: string;
|
|
21
|
+
}, never, FlowDetails>;
|
|
22
|
+
export declare const getFlow: {
|
|
23
|
+
(client: Parameters<typeof getFlowRaw>[0], params: GetFlowInput, body?: never, opts?: Parameters<typeof getFlowRaw>[3]): Promise<FlowDetails>;
|
|
24
|
+
readonly definition: typeof getFlowRaw.definition;
|
|
25
|
+
};
|
|
26
|
+
declare const createFlowRaw: import("../..").EndpointCallable<{
|
|
27
|
+
wabaId: string;
|
|
28
|
+
}, CreateFlowBody, FlowMutationResponse>;
|
|
29
|
+
export declare const createFlow: {
|
|
30
|
+
(client: Parameters<typeof createFlowRaw>[0], params: {
|
|
31
|
+
readonly wabaId: string;
|
|
32
|
+
}, body: CreateFlowBody, opts?: Parameters<typeof createFlowRaw>[3]): Promise<FlowMutationResponse>;
|
|
33
|
+
readonly definition: typeof createFlowRaw.definition;
|
|
34
|
+
};
|
|
35
|
+
declare const updateFlowMetadataRaw: import("../..").EndpointCallable<{
|
|
36
|
+
flowId: string;
|
|
37
|
+
}, UpdateFlowMetadataBody, FlowMutationResponse>;
|
|
38
|
+
export declare const updateFlowMetadata: {
|
|
39
|
+
(client: Parameters<typeof updateFlowMetadataRaw>[0], params: {
|
|
40
|
+
readonly flowId: string;
|
|
41
|
+
}, body: UpdateFlowMetadataBody, opts?: Parameters<typeof updateFlowMetadataRaw>[3]): Promise<FlowMutationResponse>;
|
|
42
|
+
readonly definition: typeof updateFlowMetadataRaw.definition;
|
|
43
|
+
};
|
|
44
|
+
declare const updateFlowJsonRaw: import("../..").EndpointCallable<{
|
|
45
|
+
flowId: string;
|
|
46
|
+
}, UpdateFlowJsonBody, FlowMutationResponse>;
|
|
47
|
+
export declare const updateFlowJson: {
|
|
48
|
+
(client: Parameters<typeof updateFlowJsonRaw>[0], params: {
|
|
49
|
+
readonly flowId: string;
|
|
50
|
+
}, body: UpdateFlowJsonBody, opts?: Parameters<typeof updateFlowJsonRaw>[3]): Promise<FlowMutationResponse>;
|
|
51
|
+
readonly definition: typeof updateFlowJsonRaw.definition;
|
|
52
|
+
};
|
|
53
|
+
declare const publishFlowRaw: import("../..").EndpointCallable<{
|
|
54
|
+
flowId: string;
|
|
55
|
+
}, never, FlowMutationResponse>;
|
|
56
|
+
export declare const publishFlow: {
|
|
57
|
+
(client: Parameters<typeof publishFlowRaw>[0], params: {
|
|
58
|
+
readonly flowId: string;
|
|
59
|
+
}, body?: never, opts?: Parameters<typeof publishFlowRaw>[3]): Promise<FlowMutationResponse>;
|
|
60
|
+
readonly definition: typeof publishFlowRaw.definition;
|
|
61
|
+
};
|
|
62
|
+
declare const deleteFlowRaw: import("../..").EndpointCallable<{
|
|
63
|
+
flowId: string;
|
|
64
|
+
}, never, FlowMutationResponse>;
|
|
65
|
+
export declare const deleteFlow: {
|
|
66
|
+
(client: Parameters<typeof deleteFlowRaw>[0], params: {
|
|
67
|
+
readonly flowId: string;
|
|
68
|
+
}, body?: never, opts?: Parameters<typeof deleteFlowRaw>[3]): Promise<FlowMutationResponse>;
|
|
69
|
+
readonly definition: typeof deleteFlowRaw.definition;
|
|
70
|
+
};
|
|
71
|
+
declare const deprecateFlowRaw: import("../..").EndpointCallable<{
|
|
72
|
+
flowId: string;
|
|
73
|
+
}, never, FlowMutationResponse>;
|
|
74
|
+
export declare const deprecateFlow: {
|
|
75
|
+
(client: Parameters<typeof deprecateFlowRaw>[0], params: {
|
|
76
|
+
readonly flowId: string;
|
|
77
|
+
}, body?: never, opts?: Parameters<typeof deprecateFlowRaw>[3]): Promise<FlowMutationResponse>;
|
|
78
|
+
readonly definition: typeof deprecateFlowRaw.definition;
|
|
79
|
+
};
|
|
80
|
+
declare const getFlowAssetsRaw: import("../..").EndpointCallable<{
|
|
81
|
+
flowId: string;
|
|
82
|
+
fields?: string;
|
|
83
|
+
limit?: string;
|
|
84
|
+
after?: string;
|
|
85
|
+
}, never, FlowAssetsResponse>;
|
|
86
|
+
export declare const getFlowAssets: {
|
|
87
|
+
(client: Parameters<typeof getFlowAssetsRaw>[0], params: GetFlowAssetsInput, body?: never, opts?: Parameters<typeof getFlowAssetsRaw>[3]): Promise<FlowAssetsResponse>;
|
|
88
|
+
readonly definition: typeof getFlowAssetsRaw.definition;
|
|
89
|
+
};
|
|
90
|
+
export {};
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { defineEndpoint } from "../../endpoint";
|
|
2
|
+
import {
|
|
3
|
+
flowNormalizePathParams,
|
|
4
|
+
mapCreateFlowBody,
|
|
5
|
+
mapUpdateFlowJsonBody,
|
|
6
|
+
mapUpdateFlowMetadataBody,
|
|
7
|
+
normalizeFlowAssetsParams,
|
|
8
|
+
normalizeGetFlowParams,
|
|
9
|
+
normalizeListFlowsParams
|
|
10
|
+
} from "./flowJson";
|
|
11
|
+
const listFlowsRaw = defineEndpoint({
|
|
12
|
+
method: "GET",
|
|
13
|
+
pathTemplate: "/{wabaId}/flows",
|
|
14
|
+
params: {
|
|
15
|
+
wabaId: { in: "path", required: true },
|
|
16
|
+
fields: { in: "query" },
|
|
17
|
+
status: { in: "query" },
|
|
18
|
+
name: { in: "query" },
|
|
19
|
+
invalidate_preview: { in: "query" },
|
|
20
|
+
phone_number_id: { in: "query" },
|
|
21
|
+
limit: { in: "query" },
|
|
22
|
+
after: { in: "query" }
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
export const listFlows = Object.assign(async function listFlows(client, params, body, opts) {
|
|
26
|
+
return listFlowsRaw(client, normalizeListFlowsParams(params), body, opts);
|
|
27
|
+
}, { definition: listFlowsRaw.definition });
|
|
28
|
+
const getFlowRaw = defineEndpoint({
|
|
29
|
+
method: "GET",
|
|
30
|
+
pathTemplate: "/{flowId}",
|
|
31
|
+
params: { flowId: { in: "path", required: true }, fields: { in: "query" }, invalidate_preview: { in: "query" }, phone_number_id: { in: "query" } }
|
|
32
|
+
});
|
|
33
|
+
export const getFlow = Object.assign(async function getFlow(client, params, body, opts) {
|
|
34
|
+
return getFlowRaw(client, normalizeGetFlowParams(params), body, opts);
|
|
35
|
+
}, { definition: getFlowRaw.definition });
|
|
36
|
+
const createFlowRaw = defineEndpoint({
|
|
37
|
+
method: "POST",
|
|
38
|
+
pathTemplate: "/{wabaId}/flows",
|
|
39
|
+
params: { wabaId: { in: "path", required: true } },
|
|
40
|
+
bodyContentType: "application/json",
|
|
41
|
+
buildBody: mapCreateFlowBody
|
|
42
|
+
});
|
|
43
|
+
export const createFlow = Object.assign(async function createFlow(client, params, body, opts) {
|
|
44
|
+
return createFlowRaw(client, flowNormalizePathParams(params, "createFlow", "wabaId"), body, opts);
|
|
45
|
+
}, { definition: createFlowRaw.definition });
|
|
46
|
+
const updateFlowMetadataRaw = defineEndpoint({
|
|
47
|
+
method: "POST",
|
|
48
|
+
pathTemplate: "/{flowId}",
|
|
49
|
+
params: { flowId: { in: "path", required: true } },
|
|
50
|
+
bodyContentType: "application/json",
|
|
51
|
+
buildBody: mapUpdateFlowMetadataBody
|
|
52
|
+
});
|
|
53
|
+
export const updateFlowMetadata = Object.assign(async function updateFlowMetadata(client, params, body, opts) {
|
|
54
|
+
return updateFlowMetadataRaw(client, flowNormalizePathParams(params, "updateFlowMetadata", "flowId"), body, opts);
|
|
55
|
+
}, { definition: updateFlowMetadataRaw.definition });
|
|
56
|
+
const updateFlowJsonRaw = defineEndpoint({
|
|
57
|
+
method: "POST",
|
|
58
|
+
pathTemplate: "/{flowId}/assets",
|
|
59
|
+
params: { flowId: { in: "path", required: true } },
|
|
60
|
+
bodyContentType: "application/json",
|
|
61
|
+
buildBody: mapUpdateFlowJsonBody
|
|
62
|
+
});
|
|
63
|
+
export const updateFlowJson = Object.assign(async function updateFlowJson(client, params, body, opts) {
|
|
64
|
+
return updateFlowJsonRaw(client, flowNormalizePathParams(params, "updateFlowJson", "flowId"), body, opts);
|
|
65
|
+
}, { definition: updateFlowJsonRaw.definition });
|
|
66
|
+
const publishFlowRaw = defineEndpoint({
|
|
67
|
+
method: "POST",
|
|
68
|
+
pathTemplate: "/{flowId}/publish",
|
|
69
|
+
params: { flowId: { in: "path", required: true } }
|
|
70
|
+
});
|
|
71
|
+
export const publishFlow = Object.assign(async function publishFlow(client, params, body, opts) {
|
|
72
|
+
return publishFlowRaw(client, flowNormalizePathParams(params, "publishFlow", "flowId"), body, opts);
|
|
73
|
+
}, { definition: publishFlowRaw.definition });
|
|
74
|
+
const deleteFlowRaw = defineEndpoint({
|
|
75
|
+
method: "DELETE",
|
|
76
|
+
pathTemplate: "/{flowId}",
|
|
77
|
+
params: { flowId: { in: "path", required: true } }
|
|
78
|
+
});
|
|
79
|
+
export const deleteFlow = Object.assign(async function deleteFlow(client, params, body, opts) {
|
|
80
|
+
return deleteFlowRaw(client, flowNormalizePathParams(params, "deleteFlow", "flowId"), body, opts);
|
|
81
|
+
}, { definition: deleteFlowRaw.definition });
|
|
82
|
+
const deprecateFlowRaw = defineEndpoint({
|
|
83
|
+
method: "POST",
|
|
84
|
+
pathTemplate: "/{flowId}/deprecate",
|
|
85
|
+
params: { flowId: { in: "path", required: true } }
|
|
86
|
+
});
|
|
87
|
+
export const deprecateFlow = Object.assign(async function deprecateFlow(client, params, body, opts) {
|
|
88
|
+
return deprecateFlowRaw(client, flowNormalizePathParams(params, "deprecateFlow", "flowId"), body, opts);
|
|
89
|
+
}, { definition: deprecateFlowRaw.definition });
|
|
90
|
+
const getFlowAssetsRaw = defineEndpoint({
|
|
91
|
+
method: "GET",
|
|
92
|
+
pathTemplate: "/{flowId}/assets",
|
|
93
|
+
params: { flowId: { in: "path", required: true }, fields: { in: "query" }, limit: { in: "query" }, after: { in: "query" } }
|
|
94
|
+
});
|
|
95
|
+
export const getFlowAssets = Object.assign(async function getFlowAssets(client, params, body, opts) {
|
|
96
|
+
return getFlowAssetsRaw(client, normalizeFlowAssetsParams(params), body, opts);
|
|
97
|
+
}, { definition: getFlowAssetsRaw.definition });
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { FlowCloseResponse, FlowCloseResponseInput, FlowErrorResponse, FlowErrorResponseInput, FlowScreenResponse, FlowScreenResponseInput } from "./types";
|
|
2
|
+
export declare function buildFlowScreenResponse(input: FlowScreenResponseInput): FlowScreenResponse;
|
|
3
|
+
export declare function buildFlowCloseResponse(input?: FlowCloseResponseInput): FlowCloseResponse;
|
|
4
|
+
export declare function buildFlowErrorResponse(input: FlowErrorResponseInput): FlowErrorResponse;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { flowAssertPlainRecord, flowMaybeString, flowString } from "./shared";
|
|
2
|
+
import { flowJsonClone } from "./flowJson";
|
|
3
|
+
function cloneFlowResponseData(value, helperName) {
|
|
4
|
+
if (value === undefined)
|
|
5
|
+
return;
|
|
6
|
+
return flowJsonClone(value, helperName, "data", { seen: new WeakSet, componentCount: 0 }, 0);
|
|
7
|
+
}
|
|
8
|
+
export function buildFlowScreenResponse(input) {
|
|
9
|
+
const record = flowAssertPlainRecord(input, "buildFlowScreenResponse");
|
|
10
|
+
const out = { screen: flowString(record.screen, "screen", "buildFlowScreenResponse", 256) };
|
|
11
|
+
const data = cloneFlowResponseData(record.data, "buildFlowScreenResponse");
|
|
12
|
+
if (data !== undefined)
|
|
13
|
+
out.data = data;
|
|
14
|
+
const token = flowMaybeString(record.flowToken, "flowToken", "buildFlowScreenResponse", 2048);
|
|
15
|
+
if (token !== undefined)
|
|
16
|
+
out.flow_token = token;
|
|
17
|
+
return out;
|
|
18
|
+
}
|
|
19
|
+
export function buildFlowCloseResponse(input = {}) {
|
|
20
|
+
const record = flowAssertPlainRecord(input, "buildFlowCloseResponse");
|
|
21
|
+
const out = { close_flow: true };
|
|
22
|
+
const data = cloneFlowResponseData(record.data, "buildFlowCloseResponse");
|
|
23
|
+
if (data !== undefined)
|
|
24
|
+
out.data = data;
|
|
25
|
+
const token = flowMaybeString(record.flowToken, "flowToken", "buildFlowCloseResponse", 2048);
|
|
26
|
+
if (token !== undefined)
|
|
27
|
+
out.flow_token = token;
|
|
28
|
+
return out;
|
|
29
|
+
}
|
|
30
|
+
export function buildFlowErrorResponse(input) {
|
|
31
|
+
const record = flowAssertPlainRecord(input, "buildFlowErrorResponse");
|
|
32
|
+
const out = { error: flowString(record.error, "error", "buildFlowErrorResponse", 256) };
|
|
33
|
+
const message = flowMaybeString(record.errorMessage, "errorMessage", "buildFlowErrorResponse", 2048);
|
|
34
|
+
if (message !== undefined)
|
|
35
|
+
out.error_message = message;
|
|
36
|
+
const token = flowMaybeString(record.flowToken, "flowToken", "buildFlowErrorResponse", 2048);
|
|
37
|
+
if (token !== undefined)
|
|
38
|
+
out.flow_token = token;
|
|
39
|
+
return out;
|
|
40
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { CreateFlowBody, FlowJson, GetFlowAssetsInput, GetFlowInput, ListFlowsInput, UpdateFlowJsonBody, UpdateFlowMetadataBody } from "./types";
|
|
2
|
+
interface FlowJsonCloneState {
|
|
3
|
+
readonly seen: WeakSet<object>;
|
|
4
|
+
componentCount: number;
|
|
5
|
+
}
|
|
6
|
+
export declare function flowJsonClone(value: unknown, helperName: string, path?: string, state?: FlowJsonCloneState, depth?: number, parentKey?: string): unknown;
|
|
7
|
+
export declare function buildFlowJson(input: FlowJson | Record<string, unknown>): FlowJson;
|
|
8
|
+
export declare function validateFlowJson(input: FlowJson | Record<string, unknown>): void;
|
|
9
|
+
export declare function normalizeFlowCategories(value: unknown, helperName: string, required: boolean): string[] | undefined;
|
|
10
|
+
export declare function normalizeFlowJsonLike(value: unknown, helperName: string): FlowJson | undefined;
|
|
11
|
+
export declare function mapCreateFlowBody(input: CreateFlowBody): Record<string, unknown>;
|
|
12
|
+
export declare function mapUpdateFlowMetadataBody(input: UpdateFlowMetadataBody): Record<string, unknown>;
|
|
13
|
+
export declare function mapUpdateFlowJsonBody(input: UpdateFlowJsonBody): Record<string, unknown>;
|
|
14
|
+
export declare function flowNormalizePathParams(input: unknown, helperName: string, fieldName: "wabaId" | "flowId"): Record<string, string>;
|
|
15
|
+
export declare function normalizeListFlowsParams(input: ListFlowsInput): Record<string, string>;
|
|
16
|
+
export declare function normalizeGetFlowParams(input: GetFlowInput): Record<string, string>;
|
|
17
|
+
export declare function normalizeFlowAssetsParams(input: GetFlowAssetsInput): Record<string, string>;
|
|
18
|
+
export {};
|