@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.
Files changed (89) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +3 -0
  3. package/dist/client.d.ts +41 -0
  4. package/dist/client.js +392 -0
  5. package/dist/createFetchTransport.d.ts +6 -0
  6. package/dist/createFetchTransport.js +46 -0
  7. package/dist/createMockTransport.d.ts +20 -0
  8. package/dist/createMockTransport.js +120 -0
  9. package/dist/endpoint.d.ts +26 -0
  10. package/dist/endpoint.js +223 -0
  11. package/dist/endpoints/businessManagement.d.ts +157 -0
  12. package/dist/endpoints/businessManagement.js +277 -0
  13. package/dist/endpoints/calling.d.ts +65 -0
  14. package/dist/endpoints/calling.js +284 -0
  15. package/dist/endpoints/flows/callables.d.ts +90 -0
  16. package/dist/endpoints/flows/callables.js +97 -0
  17. package/dist/endpoints/flows/dataExchange.d.ts +4 -0
  18. package/dist/endpoints/flows/dataExchange.js +40 -0
  19. package/dist/endpoints/flows/flowJson.d.ts +18 -0
  20. package/dist/endpoints/flows/flowJson.js +214 -0
  21. package/dist/endpoints/flows/index.d.ts +6 -0
  22. package/dist/endpoints/flows/index.js +26 -0
  23. package/dist/endpoints/flows/shared.d.ts +17 -0
  24. package/dist/endpoints/flows/shared.js +113 -0
  25. package/dist/endpoints/flows/types.d.ts +105 -0
  26. package/dist/endpoints/flows/types.js +0 -0
  27. package/dist/endpoints/flows.d.ts +2 -0
  28. package/dist/endpoints/flows.js +23 -0
  29. package/dist/endpoints/media.d.ts +123 -0
  30. package/dist/endpoints/media.js +976 -0
  31. package/dist/endpoints/messages.d.ts +375 -0
  32. package/dist/endpoints/messages.js +675 -0
  33. package/dist/endpoints/templates/builders.d.ts +9 -0
  34. package/dist/endpoints/templates/builders.js +101 -0
  35. package/dist/endpoints/templates/callables.d.ts +54 -0
  36. package/dist/endpoints/templates/callables.js +98 -0
  37. package/dist/endpoints/templates/index.d.ts +5 -0
  38. package/dist/endpoints/templates/index.js +16 -0
  39. package/dist/endpoints/templates/shared.d.ts +21 -0
  40. package/dist/endpoints/templates/shared.js +203 -0
  41. package/dist/endpoints/templates/types.d.ts +135 -0
  42. package/dist/endpoints/templates/types.js +0 -0
  43. package/dist/endpoints/templates/validation.d.ts +2 -0
  44. package/dist/endpoints/templates/validation.js +113 -0
  45. package/dist/endpoints/templates.d.ts +2 -0
  46. package/dist/endpoints/templates.js +14 -0
  47. package/dist/endpoints/waba/index.d.ts +4 -0
  48. package/dist/endpoints/waba/index.js +1 -0
  49. package/dist/endpoints/waba/phoneNumbers.d.ts +25 -0
  50. package/dist/endpoints/waba/phoneNumbers.js +23 -0
  51. package/dist/endpoints/waba/types.d.ts +8 -0
  52. package/dist/endpoints/waba/types.js +0 -0
  53. package/dist/endpoints/wabaEndpoints.d.ts +6 -0
  54. package/dist/endpoints/wabaEndpoints.js +38 -0
  55. package/dist/errorRegistry.d.ts +45 -0
  56. package/dist/errorRegistry.js +68 -0
  57. package/dist/errorSubclasses.d.ts +277 -0
  58. package/dist/errorSubclasses.js +613 -0
  59. package/dist/errors.d.ts +92 -0
  60. package/dist/errors.js +250 -0
  61. package/dist/index.d.ts +20 -0
  62. package/dist/index.js +48 -0
  63. package/dist/internal/validation/arrays.d.ts +19 -0
  64. package/dist/internal/validation/arrays.js +102 -0
  65. package/dist/internal/validation/errors.d.ts +3 -0
  66. package/dist/internal/validation/errors.js +13 -0
  67. package/dist/internal/validation/headers.d.ts +15 -0
  68. package/dist/internal/validation/headers.js +77 -0
  69. package/dist/internal/validation/index.d.ts +8 -0
  70. package/dist/internal/validation/index.js +8 -0
  71. package/dist/internal/validation/json.d.ts +10 -0
  72. package/dist/internal/validation/json.js +79 -0
  73. package/dist/internal/validation/options.d.ts +5 -0
  74. package/dist/internal/validation/options.js +36 -0
  75. package/dist/internal/validation/paths.d.ts +8 -0
  76. package/dist/internal/validation/paths.js +37 -0
  77. package/dist/internal/validation/records.d.ts +20 -0
  78. package/dist/internal/validation/records.js +69 -0
  79. package/dist/internal/validation/strings.d.ts +12 -0
  80. package/dist/internal/validation/strings.js +46 -0
  81. package/dist/pagination.d.ts +35 -0
  82. package/dist/pagination.js +160 -0
  83. package/dist/subclients/phoneNumberClient.d.ts +60 -0
  84. package/dist/subclients/phoneNumberClient.js +194 -0
  85. package/dist/subclients/wabaClient.d.ts +66 -0
  86. package/dist/subclients/wabaClient.js +180 -0
  87. package/dist/transport.d.ts +32 -0
  88. package/dist/transport.js +5 -0
  89. package/package.json +70 -0
@@ -0,0 +1,214 @@
1
+ import {
2
+ FLOW_JSON_MAX_ARRAY_LENGTH,
3
+ FLOW_JSON_MAX_BYTES,
4
+ FLOW_JSON_MAX_COMPONENTS,
5
+ FLOW_JSON_MAX_DEPTH,
6
+ FLOW_JSON_MAX_SCREENS,
7
+ FLOW_JSON_MAX_STRING_LENGTH,
8
+ FLOW_MAX_CATEGORIES,
9
+ flowArray,
10
+ flowAssertPlainRecord,
11
+ flowError,
12
+ flowHasControlChar,
13
+ flowIsUnsafeObjectKey,
14
+ flowMaybeString,
15
+ flowString,
16
+ flowUrl
17
+ } from "./shared";
18
+ export function flowJsonClone(value, helperName, path = "input", state = { seen: new WeakSet, componentCount: 0 }, depth = 0, parentKey = "") {
19
+ if (depth > FLOW_JSON_MAX_DEPTH) {
20
+ throw flowError(`Invalid ${helperName} input: ${path} exceeds maximum depth ${FLOW_JSON_MAX_DEPTH}.`);
21
+ }
22
+ if (value === null || typeof value === "boolean")
23
+ return value;
24
+ if (typeof value === "string") {
25
+ if (flowHasControlChar(value))
26
+ throw flowError(`Invalid ${helperName} input: ${path} contains control characters.`);
27
+ if (value.length > FLOW_JSON_MAX_STRING_LENGTH)
28
+ throw flowError(`Invalid ${helperName} input: ${path} string exceeds ${FLOW_JSON_MAX_STRING_LENGTH}-character limit.`);
29
+ return value;
30
+ }
31
+ if (typeof value === "number") {
32
+ if (!Number.isFinite(value))
33
+ throw flowError(`Invalid ${helperName} input: ${path} contains a non-finite number.`);
34
+ return value;
35
+ }
36
+ if (value === undefined)
37
+ return;
38
+ if (typeof value === "function" || typeof value === "symbol") {
39
+ throw flowError(`Invalid ${helperName} input: ${path} must be JSON-serializable.`);
40
+ }
41
+ if (Array.isArray(value)) {
42
+ if (state.seen.has(value))
43
+ throw flowError(`Invalid ${helperName} input: ${path} must not contain cycles.`);
44
+ state.seen.add(value);
45
+ const arr = flowArray(value, path, 0, FLOW_JSON_MAX_ARRAY_LENGTH, helperName);
46
+ const out = [];
47
+ for (let index = 0;index < arr.length; index += 1) {
48
+ out.push(flowJsonClone(arr[index], helperName, `${path}[${index}]`, state, depth + 1, parentKey));
49
+ }
50
+ state.seen.delete(value);
51
+ return out;
52
+ }
53
+ const record = flowAssertPlainRecord(value, helperName, path);
54
+ if (state.seen.has(record))
55
+ throw flowError(`Invalid ${helperName} input: ${path} must not contain cycles.`);
56
+ state.seen.add(record);
57
+ if (parentKey === "children" && typeof record.type === "string") {
58
+ state.componentCount += 1;
59
+ if (state.componentCount > FLOW_JSON_MAX_COMPONENTS) {
60
+ throw flowError(`Invalid ${helperName} input: Flow JSON exceeds ${FLOW_JSON_MAX_COMPONENTS}-component limit.`);
61
+ }
62
+ }
63
+ const out = {};
64
+ for (const [key, nested] of Object.entries(record)) {
65
+ if (flowIsUnsafeObjectKey(key)) {
66
+ throw flowError(`Invalid ${helperName} input: ${path} contains an unsafe prototype key.`);
67
+ }
68
+ if (key.length === 0 || key.length > 1024 || flowHasControlChar(key)) {
69
+ throw flowError(`Invalid ${helperName} input: ${path} contains an invalid key.`);
70
+ }
71
+ const cloned = flowJsonClone(nested, helperName, `${path}.${key}`, state, depth + 1, key);
72
+ if (cloned !== undefined)
73
+ out[key] = cloned;
74
+ }
75
+ state.seen.delete(record);
76
+ return out;
77
+ }
78
+ export function buildFlowJson(input) {
79
+ const cloned = flowJsonClone(input, "buildFlowJson");
80
+ const record = flowAssertPlainRecord(cloned, "buildFlowJson");
81
+ const screens = flowArray(record.screens, "screens", 1, FLOW_JSON_MAX_SCREENS, "buildFlowJson");
82
+ for (let index = 0;index < screens.length; index += 1) {
83
+ const screen = flowAssertPlainRecord(screens[index], "buildFlowJson", `screens[${index}]`);
84
+ flowString(screen.id, `screens[${index}].id`, "buildFlowJson", 256);
85
+ }
86
+ const encoded = JSON.stringify(record);
87
+ if (new TextEncoder().encode(encoded).byteLength > FLOW_JSON_MAX_BYTES) {
88
+ throw flowError(`Invalid buildFlowJson input: Flow JSON exceeds ${FLOW_JSON_MAX_BYTES}-byte serialized limit.`);
89
+ }
90
+ return record;
91
+ }
92
+ export function validateFlowJson(input) {
93
+ buildFlowJson(input);
94
+ }
95
+ export function normalizeFlowCategories(value, helperName, required) {
96
+ if (value === undefined) {
97
+ if (required)
98
+ throw flowError(`Invalid ${helperName} input: categories must be provided.`);
99
+ return;
100
+ }
101
+ const raw = flowArray(value, "categories", required ? 1 : 0, FLOW_MAX_CATEGORIES, helperName);
102
+ const out = [];
103
+ for (let index = 0;index < raw.length; index += 1) {
104
+ out.push(flowString(raw[index], `categories[${index}]`, helperName, 64));
105
+ }
106
+ return out;
107
+ }
108
+ export function normalizeFlowJsonLike(value, helperName) {
109
+ if (value === undefined)
110
+ return;
111
+ return buildFlowJson(value);
112
+ }
113
+ export function mapCreateFlowBody(input) {
114
+ const record = flowAssertPlainRecord(input, "createFlow");
115
+ const out = {};
116
+ out.name = flowString(record.name, "name", "createFlow");
117
+ out.categories = normalizeFlowCategories(record.categories, "createFlow", true);
118
+ const cloneFlowId = flowMaybeString(record.cloneFlowId, "cloneFlowId", "createFlow");
119
+ if (cloneFlowId !== undefined)
120
+ out.clone_flow_id = cloneFlowId;
121
+ if (record.endpointUri !== undefined)
122
+ out.endpoint_uri = flowUrl(record.endpointUri, "endpointUri", "createFlow");
123
+ const flowJson = normalizeFlowJsonLike(record.flowJson, "createFlow");
124
+ if (flowJson !== undefined)
125
+ out.flow_json = flowJson;
126
+ if (record.publish !== undefined) {
127
+ if (typeof record.publish !== "boolean")
128
+ throw flowError("Invalid createFlow input: publish must be boolean.");
129
+ out.publish = record.publish;
130
+ }
131
+ for (const [key, value] of Object.entries(record)) {
132
+ if (flowIsUnsafeObjectKey(key))
133
+ throw flowError("Invalid createFlow input: unsafe prototype keys are not allowed.");
134
+ if (["name", "categories", "cloneFlowId", "endpointUri", "flowJson", "publish"].includes(key) || value === undefined)
135
+ continue;
136
+ out[key] = flowJsonClone(value, "createFlow", key);
137
+ }
138
+ return out;
139
+ }
140
+ export function mapUpdateFlowMetadataBody(input) {
141
+ const record = flowAssertPlainRecord(input, "updateFlowMetadata");
142
+ const out = {};
143
+ if (record.name !== undefined)
144
+ out.name = flowString(record.name, "name", "updateFlowMetadata");
145
+ const categories = normalizeFlowCategories(record.categories, "updateFlowMetadata", false);
146
+ if (categories !== undefined)
147
+ out.categories = categories;
148
+ if (record.endpointUri !== undefined)
149
+ out.endpoint_uri = flowUrl(record.endpointUri, "endpointUri", "updateFlowMetadata");
150
+ if (record.applicationId !== undefined)
151
+ out.application_id = flowString(record.applicationId, "applicationId", "updateFlowMetadata");
152
+ for (const [key, value] of Object.entries(record)) {
153
+ if (flowIsUnsafeObjectKey(key))
154
+ throw flowError("Invalid updateFlowMetadata input: unsafe prototype keys are not allowed.");
155
+ if (["name", "categories", "endpointUri", "applicationId"].includes(key) || value === undefined)
156
+ continue;
157
+ out[key] = flowJsonClone(value, "updateFlowMetadata", key);
158
+ }
159
+ return out;
160
+ }
161
+ export function mapUpdateFlowJsonBody(input) {
162
+ const record = flowAssertPlainRecord(input, "updateFlowJson");
163
+ const flowJson = buildFlowJson(record.flowJson);
164
+ const name = flowMaybeString(record.name, "name", "updateFlowJson", 256) ?? "flow.json";
165
+ return { name, asset_type: "FLOW_JSON", file: JSON.stringify(flowJson) };
166
+ }
167
+ export function flowNormalizePathParams(input, helperName, fieldName) {
168
+ const record = flowAssertPlainRecord(input, helperName, "params");
169
+ const descriptors = Object.getOwnPropertyDescriptors(record);
170
+ const descriptor = descriptors[fieldName];
171
+ if (descriptor === undefined || typeof descriptor.get === "function" || typeof descriptor.set === "function" || typeof descriptor.value !== "string") {
172
+ throw flowError(`Invalid ${helperName} input: ${fieldName} must be a string data property.`);
173
+ }
174
+ return { [fieldName]: flowString(descriptor.value, fieldName, helperName) };
175
+ }
176
+ export function normalizeListFlowsParams(input) {
177
+ const record = flowAssertPlainRecord(input, "listFlows");
178
+ const out = { wabaId: flowString(record.wabaId, "wabaId", "listFlows") };
179
+ for (const [publicKey, graphKey] of [
180
+ ["fields", "fields"],
181
+ ["status", "status"],
182
+ ["name", "name"],
183
+ ["invalidatePreview", "invalidate_preview"],
184
+ ["phoneNumberId", "phone_number_id"],
185
+ ["limit", "limit"],
186
+ ["after", "after"]
187
+ ]) {
188
+ if (record[publicKey] !== undefined)
189
+ out[graphKey] = flowString(record[publicKey], publicKey, "listFlows");
190
+ }
191
+ return out;
192
+ }
193
+ export function normalizeGetFlowParams(input) {
194
+ const record = flowAssertPlainRecord(input, "getFlow");
195
+ const out = { flowId: flowString(record.flowId, "flowId", "getFlow") };
196
+ for (const [publicKey, graphKey] of [
197
+ ["fields", "fields"],
198
+ ["invalidatePreview", "invalidate_preview"],
199
+ ["phoneNumberId", "phone_number_id"]
200
+ ]) {
201
+ if (record[publicKey] !== undefined)
202
+ out[graphKey] = flowString(record[publicKey], publicKey, "getFlow");
203
+ }
204
+ return out;
205
+ }
206
+ export function normalizeFlowAssetsParams(input) {
207
+ const record = flowAssertPlainRecord(input, "getFlowAssets");
208
+ const out = { flowId: flowString(record.flowId, "flowId", "getFlowAssets") };
209
+ for (const key of ["fields", "limit", "after"]) {
210
+ if (record[key] !== undefined)
211
+ out[key] = flowString(record[key], key, "getFlowAssets");
212
+ }
213
+ return out;
214
+ }
@@ -0,0 +1,6 @@
1
+ export { createFlow, deleteFlow, deprecateFlow, getFlow, getFlowAssets, listFlows, publishFlow, updateFlowJson, updateFlowMetadata } from "./callables";
2
+ export { FLOW_JSON_MAX_ARRAY_LENGTH, FLOW_JSON_MAX_BYTES, FLOW_JSON_MAX_COMPONENTS, FLOW_JSON_MAX_DEPTH, FLOW_JSON_MAX_SCREENS, FLOW_JSON_MAX_STRING_LENGTH, FLOW_MAX_CATEGORIES } from "./shared";
3
+ export { buildFlowJson, validateFlowJson } from "./flowJson";
4
+ export { buildFlowCloseResponse, buildFlowErrorResponse, buildFlowScreenResponse } from "./dataExchange";
5
+ export type { GraphPaging } from "../wabaEndpoints";
6
+ export type { CreateFlowBody, FlowAssetDetails, FlowAssetsResponse, FlowCategory, FlowCloseResponse, FlowCloseResponseInput, FlowDetails, FlowErrorResponse, FlowErrorResponseInput, FlowJson, FlowListResponse, FlowMutationResponse, FlowScreenResponse, FlowScreenResponseInput, FlowStatus, GetFlowAssetsInput, GetFlowInput, ListFlowsInput, UpdateFlowJsonBody, UpdateFlowMetadataBody } from "./types";
@@ -0,0 +1,26 @@
1
+ export {
2
+ createFlow,
3
+ deleteFlow,
4
+ deprecateFlow,
5
+ getFlow,
6
+ getFlowAssets,
7
+ listFlows,
8
+ publishFlow,
9
+ updateFlowJson,
10
+ updateFlowMetadata
11
+ } from "./callables";
12
+ export {
13
+ FLOW_JSON_MAX_ARRAY_LENGTH,
14
+ FLOW_JSON_MAX_BYTES,
15
+ FLOW_JSON_MAX_COMPONENTS,
16
+ FLOW_JSON_MAX_DEPTH,
17
+ FLOW_JSON_MAX_SCREENS,
18
+ FLOW_JSON_MAX_STRING_LENGTH,
19
+ FLOW_MAX_CATEGORIES
20
+ } from "./shared";
21
+ export { buildFlowJson, validateFlowJson } from "./flowJson";
22
+ export {
23
+ buildFlowCloseResponse,
24
+ buildFlowErrorResponse,
25
+ buildFlowScreenResponse
26
+ } from "./dataExchange";
@@ -0,0 +1,17 @@
1
+ import { GraphRequestValidationError } from "../../errors";
2
+ export declare const FLOW_JSON_MAX_DEPTH = 16;
3
+ export declare const FLOW_JSON_MAX_ARRAY_LENGTH = 1000;
4
+ export declare const FLOW_JSON_MAX_SCREENS = 50;
5
+ export declare const FLOW_JSON_MAX_COMPONENTS = 1000;
6
+ export declare const FLOW_JSON_MAX_STRING_LENGTH = 16384;
7
+ export declare const FLOW_JSON_MAX_BYTES = 131072;
8
+ export declare const FLOW_MAX_CATEGORIES = 5;
9
+ export declare function flowError(message: string): GraphRequestValidationError;
10
+ export declare function flowHasControlChar(value: string): boolean;
11
+ export declare function flowIsUnsafeObjectKey(key: string): boolean;
12
+ export declare function flowIsPlainObject(value: unknown): value is Record<string, unknown>;
13
+ export declare function flowAssertPlainRecord(value: unknown, helperName: string, path?: string): Record<string, unknown>;
14
+ export declare function flowString(value: unknown, fieldName: string, helperName: string, maxLength?: number): string;
15
+ export declare function flowMaybeString(value: unknown, fieldName: string, helperName: string, maxLength?: number): string | undefined;
16
+ export declare function flowUrl(value: unknown, fieldName: string, helperName: string): string;
17
+ export declare function flowArray(value: unknown, fieldName: string, min: number, max: number, helperName: string): readonly unknown[];
@@ -0,0 +1,113 @@
1
+ import { GraphRequestValidationError } from "../../errors";
2
+ export const FLOW_JSON_MAX_DEPTH = 16;
3
+ export const FLOW_JSON_MAX_ARRAY_LENGTH = 1000;
4
+ export const FLOW_JSON_MAX_SCREENS = 50;
5
+ export const FLOW_JSON_MAX_COMPONENTS = 1000;
6
+ export const FLOW_JSON_MAX_STRING_LENGTH = 16384;
7
+ export const FLOW_JSON_MAX_BYTES = 131072;
8
+ export const FLOW_MAX_CATEGORIES = 5;
9
+ export function flowError(message) {
10
+ return new GraphRequestValidationError(message);
11
+ }
12
+ export function flowHasControlChar(value) {
13
+ for (let i = 0;i < value.length; i += 1) {
14
+ const code = value.charCodeAt(i);
15
+ if (code < 32 || code === 127)
16
+ return true;
17
+ }
18
+ return false;
19
+ }
20
+ export function flowIsUnsafeObjectKey(key) {
21
+ return key === "__proto__" || key === "constructor" || key === "prototype";
22
+ }
23
+ export function flowIsPlainObject(value) {
24
+ return typeof value === "object" && value !== null && !Array.isArray(value);
25
+ }
26
+ export function flowAssertPlainRecord(value, helperName, path = "input") {
27
+ if (!flowIsPlainObject(value)) {
28
+ throw flowError(`Invalid ${helperName} input: ${path} must be an object.`);
29
+ }
30
+ const proto = Object.getPrototypeOf(value);
31
+ if (proto !== Object.prototype && proto !== null) {
32
+ throw flowError(`Invalid ${helperName} input: ${path} must be a plain object.`);
33
+ }
34
+ const descriptors = Object.getOwnPropertyDescriptors(value);
35
+ if (Object.prototype.hasOwnProperty.call(descriptors, "toJSON") || "toJSON" in value) {
36
+ throw flowError(`Invalid ${helperName} input: ${path} must not define toJSON.`);
37
+ }
38
+ for (const [key, descriptor] of Object.entries(descriptors)) {
39
+ if (typeof descriptor.get === "function" || typeof descriptor.set === "function") {
40
+ throw flowError(`Invalid ${helperName} input: ${path}.${key} must not use accessors.`);
41
+ }
42
+ if (typeof descriptor.value === "function" || typeof descriptor.value === "symbol") {
43
+ throw flowError(`Invalid ${helperName} input: ${path}.${key} must be JSON-serializable.`);
44
+ }
45
+ }
46
+ return value;
47
+ }
48
+ export function flowString(value, fieldName, helperName, maxLength = 512) {
49
+ if (typeof value !== "string") {
50
+ throw flowError(`Invalid ${helperName} input: ${fieldName} must be a string.`);
51
+ }
52
+ if (value.length === 0 || value.trim().length === 0) {
53
+ throw flowError(`Invalid ${helperName} input: ${fieldName} must be non-empty.`);
54
+ }
55
+ if (flowHasControlChar(value)) {
56
+ throw flowError(`Invalid ${helperName} input: ${fieldName} must not contain control characters.`);
57
+ }
58
+ if (value.length > maxLength) {
59
+ throw flowError(`Invalid ${helperName} input: ${fieldName} exceeds ${maxLength}-character limit.`);
60
+ }
61
+ return value;
62
+ }
63
+ export function flowMaybeString(value, fieldName, helperName, maxLength = 512) {
64
+ if (value === undefined)
65
+ return;
66
+ return flowString(value, fieldName, helperName, maxLength);
67
+ }
68
+ export function flowUrl(value, fieldName, helperName) {
69
+ const urlValue = flowString(value, fieldName, helperName, 2048);
70
+ if (urlValue !== urlValue.trim()) {
71
+ throw flowError(`Invalid ${helperName} input: ${fieldName} must not contain leading/trailing whitespace.`);
72
+ }
73
+ let parsed;
74
+ try {
75
+ parsed = new URL(urlValue);
76
+ } catch {
77
+ throw flowError(`Invalid ${helperName} input: ${fieldName} must be an absolute http(s) URL.`);
78
+ }
79
+ if (parsed.protocol !== "http:" && parsed.protocol !== "https:") {
80
+ throw flowError(`Invalid ${helperName} input: ${fieldName} protocol must be http: or https:.`);
81
+ }
82
+ return urlValue;
83
+ }
84
+ export function flowArray(value, fieldName, min, max, helperName) {
85
+ if (!Array.isArray(value)) {
86
+ throw flowError(`Invalid ${helperName} input: ${fieldName} must be an array.`);
87
+ }
88
+ if (value.length < min || value.length > max) {
89
+ throw flowError(`Invalid ${helperName} input: ${fieldName} length must be between ${min} and ${max}.`);
90
+ }
91
+ if (Object.getPrototypeOf(value) !== Array.prototype) {
92
+ throw flowError(`Invalid ${helperName} input: ${fieldName} must use Array.prototype.`);
93
+ }
94
+ if (Object.prototype.hasOwnProperty.call(value, Symbol.iterator) || Object.prototype.hasOwnProperty.call(value, "map")) {
95
+ throw flowError(`Invalid ${helperName} input: ${fieldName} must not override Array.prototype methods.`);
96
+ }
97
+ const descriptors = Object.getOwnPropertyDescriptors(value);
98
+ if (Object.prototype.hasOwnProperty.call(descriptors, "toJSON") || "toJSON" in value) {
99
+ throw flowError(`Invalid ${helperName} input: ${fieldName} must not define toJSON.`);
100
+ }
101
+ const out = [];
102
+ for (let index = 0;index < value.length; index += 1) {
103
+ if (!Object.prototype.hasOwnProperty.call(value, index)) {
104
+ throw flowError(`Invalid ${helperName} input: ${fieldName} must not contain sparse array holes.`);
105
+ }
106
+ const descriptor = descriptors[String(index)];
107
+ if (descriptor === undefined || typeof descriptor.get === "function" || typeof descriptor.set === "function") {
108
+ throw flowError(`Invalid ${helperName} input: ${fieldName} must not use accessors.`);
109
+ }
110
+ out.push(descriptor.value);
111
+ }
112
+ return out;
113
+ }
@@ -0,0 +1,105 @@
1
+ import type { GraphPaging } from "../wabaEndpoints";
2
+ export type FlowStatus = "DRAFT" | "PUBLISHED" | "DEPRECATED" | "BLOCKED" | "THROTTLED" | string;
3
+ export type FlowCategory = "SIGN_UP" | "SIGN_IN" | "APPOINTMENT_BOOKING" | "LEAD_GENERATION" | "CONTACT_US" | "CUSTOMER_SUPPORT" | "SURVEY" | "OTHER" | string;
4
+ export interface FlowDetails {
5
+ readonly id?: string;
6
+ readonly name?: string;
7
+ readonly status?: FlowStatus;
8
+ readonly categories?: readonly FlowCategory[];
9
+ readonly endpoint_uri?: string;
10
+ readonly validation_errors?: readonly unknown[];
11
+ readonly preview?: Record<string, unknown>;
12
+ readonly [key: string]: unknown;
13
+ }
14
+ export interface FlowListResponse {
15
+ readonly data?: readonly FlowDetails[];
16
+ readonly paging?: GraphPaging;
17
+ }
18
+ export interface FlowMutationResponse {
19
+ readonly id?: string;
20
+ readonly success?: boolean;
21
+ readonly [key: string]: unknown;
22
+ }
23
+ export interface FlowAssetDetails {
24
+ readonly name?: string;
25
+ readonly asset_type?: string;
26
+ readonly download_url?: string;
27
+ readonly [key: string]: unknown;
28
+ }
29
+ export interface FlowAssetsResponse {
30
+ readonly data?: readonly FlowAssetDetails[];
31
+ readonly paging?: GraphPaging;
32
+ }
33
+ export type FlowJson = Record<string, unknown>;
34
+ export interface ListFlowsInput {
35
+ readonly wabaId: string;
36
+ readonly fields?: string;
37
+ readonly status?: FlowStatus;
38
+ readonly name?: string;
39
+ readonly invalidatePreview?: string;
40
+ readonly phoneNumberId?: string;
41
+ readonly limit?: string;
42
+ readonly after?: string;
43
+ }
44
+ export interface GetFlowInput {
45
+ readonly flowId: string;
46
+ readonly fields?: string;
47
+ readonly invalidatePreview?: string;
48
+ readonly phoneNumberId?: string;
49
+ }
50
+ export interface CreateFlowBody {
51
+ readonly name: string;
52
+ readonly categories: readonly FlowCategory[];
53
+ readonly cloneFlowId?: string;
54
+ readonly endpointUri?: string;
55
+ readonly flowJson?: FlowJson | Record<string, unknown>;
56
+ readonly publish?: boolean;
57
+ readonly [key: string]: unknown;
58
+ }
59
+ export interface UpdateFlowMetadataBody {
60
+ readonly name?: string;
61
+ readonly categories?: readonly FlowCategory[];
62
+ readonly endpointUri?: string;
63
+ readonly applicationId?: string;
64
+ readonly [key: string]: unknown;
65
+ }
66
+ export interface UpdateFlowJsonBody {
67
+ readonly flowJson: FlowJson | Record<string, unknown>;
68
+ /** Defaults to Meta's stable Flow JSON asset name, `flow.json`. */
69
+ readonly name?: string;
70
+ }
71
+ export interface GetFlowAssetsInput {
72
+ readonly flowId: string;
73
+ readonly fields?: string;
74
+ readonly limit?: string;
75
+ readonly after?: string;
76
+ }
77
+ export interface FlowScreenResponseInput {
78
+ readonly screen: string;
79
+ readonly data?: unknown;
80
+ readonly flowToken?: string;
81
+ }
82
+ export interface FlowCloseResponseInput {
83
+ readonly data?: unknown;
84
+ readonly flowToken?: string;
85
+ }
86
+ export interface FlowErrorResponseInput {
87
+ readonly error: string;
88
+ readonly errorMessage?: string;
89
+ readonly flowToken?: string;
90
+ }
91
+ export interface FlowScreenResponse {
92
+ readonly screen: string;
93
+ readonly data?: unknown;
94
+ readonly flow_token?: string;
95
+ }
96
+ export interface FlowCloseResponse {
97
+ readonly close_flow: true;
98
+ readonly data?: unknown;
99
+ readonly flow_token?: string;
100
+ }
101
+ export interface FlowErrorResponse {
102
+ readonly error: string;
103
+ readonly error_message?: string;
104
+ readonly flow_token?: string;
105
+ }
File without changes
@@ -0,0 +1,2 @@
1
+ export { FLOW_JSON_MAX_ARRAY_LENGTH, FLOW_JSON_MAX_BYTES, FLOW_JSON_MAX_COMPONENTS, FLOW_JSON_MAX_DEPTH, FLOW_JSON_MAX_SCREENS, FLOW_JSON_MAX_STRING_LENGTH, FLOW_MAX_CATEGORIES, buildFlowCloseResponse, buildFlowErrorResponse, buildFlowJson, buildFlowScreenResponse, createFlow, deleteFlow, deprecateFlow, getFlow, getFlowAssets, listFlows, publishFlow, updateFlowJson, updateFlowMetadata, validateFlowJson } from "./flows/index";
2
+ export type { CreateFlowBody, FlowAssetDetails, FlowAssetsResponse, FlowCategory, FlowCloseResponse, FlowCloseResponseInput, FlowDetails, FlowErrorResponse, FlowErrorResponseInput, FlowJson, FlowListResponse, FlowMutationResponse, FlowScreenResponse, FlowScreenResponseInput, FlowStatus, GetFlowAssetsInput, GetFlowInput, GraphPaging, ListFlowsInput, UpdateFlowJsonBody, UpdateFlowMetadataBody } from "./flows/index";
@@ -0,0 +1,23 @@
1
+ export {
2
+ FLOW_JSON_MAX_ARRAY_LENGTH,
3
+ FLOW_JSON_MAX_BYTES,
4
+ FLOW_JSON_MAX_COMPONENTS,
5
+ FLOW_JSON_MAX_DEPTH,
6
+ FLOW_JSON_MAX_SCREENS,
7
+ FLOW_JSON_MAX_STRING_LENGTH,
8
+ FLOW_MAX_CATEGORIES,
9
+ buildFlowCloseResponse,
10
+ buildFlowErrorResponse,
11
+ buildFlowJson,
12
+ buildFlowScreenResponse,
13
+ createFlow,
14
+ deleteFlow,
15
+ deprecateFlow,
16
+ getFlow,
17
+ getFlowAssets,
18
+ listFlows,
19
+ publishFlow,
20
+ updateFlowJson,
21
+ updateFlowMetadata,
22
+ validateFlowJson
23
+ } from "./flows/index";
@@ -0,0 +1,123 @@
1
+ import type { GraphClient } from "../client";
2
+ export type MediaOperation = "upload" | "download" | "delete" | "download_bytes" | "decrypt_encrypted" | "create_upload_session" | "upload_file_to_session" | "get_upload_session";
3
+ export type MediaNotImplementedCode = "not_implemented";
4
+ export declare class MediaNotImplementedError extends Error {
5
+ readonly code: MediaNotImplementedCode;
6
+ readonly operation: MediaOperation;
7
+ readonly linearIssue: string;
8
+ constructor(operation: MediaOperation, linearIssue: string);
9
+ }
10
+ export type MediaValidationErrorCode = "invalid_client" | "invalid_params" | "invalid_options" | "invalid_url" | "invalid_phone_number_id" | "invalid_media_id" | "invalid_app_id" | "invalid_upload_session_id" | "invalid_upload_body" | "invalid_file" | "invalid_file_name" | "invalid_file_length" | "invalid_media_type" | "invalid_file_type" | "unsupported_media_type" | "invalid_messaging_product" | "upload_too_large" | "download_too_large" | "invalid_file_offset" | "invalid_content_length" | "invalid_response";
11
+ export declare class MediaValidationError extends Error {
12
+ readonly code: MediaValidationErrorCode;
13
+ constructor(code: MediaValidationErrorCode, message: string, cause?: unknown);
14
+ }
15
+ export type MediaCryptoErrorCode = "invalid_bundle" | "invalid_base64" | "invalid_key_length" | "invalid_ciphertext" | "invalid_padding" | "decrypt_failed" | "unsupported_crypto";
16
+ export declare class MediaCryptoError extends Error {
17
+ readonly code: MediaCryptoErrorCode;
18
+ constructor(code: MediaCryptoErrorCode, message: string, cause?: unknown);
19
+ }
20
+ export type MediaIntegrityErrorCode = "sha256_mismatch" | "encrypted_hash_mismatch" | "hmac_mismatch" | "plaintext_hash_mismatch";
21
+ export declare class MediaIntegrityError extends Error {
22
+ readonly code: MediaIntegrityErrorCode;
23
+ constructor(code: MediaIntegrityErrorCode, message: string);
24
+ }
25
+ export declare const DEFAULT_MAX_MEDIA_UPLOAD_BYTES: number;
26
+ export declare const MAX_MEDIA_UPLOAD_BYTES: number;
27
+ export declare const DEFAULT_MAX_MEDIA_DOWNLOAD_BYTES: number;
28
+ export declare const MAX_MEDIA_DOWNLOAD_BYTES: number;
29
+ export declare const DEFAULT_MAX_UPLOAD_SESSION_BYTES: number;
30
+ export declare const MAX_UPLOAD_SESSION_BYTES: number;
31
+ export interface MediaUploadBody {
32
+ readonly file: Blob | ArrayBuffer | Uint8Array;
33
+ readonly type: string;
34
+ readonly messagingProduct: "whatsapp";
35
+ }
36
+ export interface MediaUploadOptions {
37
+ readonly maxBytes?: number;
38
+ readonly signal?: AbortSignal;
39
+ }
40
+ export interface MediaUploadResponse {
41
+ readonly id: string;
42
+ }
43
+ export interface MediaDownloadOptions {
44
+ readonly mediaId: string;
45
+ readonly signal?: AbortSignal;
46
+ }
47
+ export interface MediaDownloadResponse {
48
+ readonly url: string;
49
+ readonly mimeType: string;
50
+ readonly sha256: string;
51
+ readonly fileSize: number;
52
+ readonly messagingProduct: "whatsapp";
53
+ }
54
+ export interface MediaDeleteOptions {
55
+ readonly mediaId: string;
56
+ readonly signal?: AbortSignal;
57
+ }
58
+ export interface MediaDeleteResponse {
59
+ readonly success: boolean;
60
+ }
61
+ export interface MediaDownloadBytesOptions {
62
+ readonly url: string;
63
+ readonly expectedSha256?: string;
64
+ readonly maxBytes?: number;
65
+ readonly signal?: AbortSignal;
66
+ }
67
+ export interface MediaDownloadBytesResponse {
68
+ readonly bytes: Uint8Array;
69
+ readonly sha256: string;
70
+ readonly contentType?: string;
71
+ }
72
+ export interface EncryptedMediaBundle {
73
+ readonly url: string;
74
+ readonly encryptionKey: string;
75
+ readonly hmacKey: string;
76
+ readonly iv: string;
77
+ readonly sha256: string;
78
+ readonly sha256Enc: string;
79
+ }
80
+ export interface CreateUploadSessionParams {
81
+ readonly appId: string;
82
+ readonly fileName: string;
83
+ readonly fileLength: number;
84
+ readonly fileType: string;
85
+ }
86
+ export interface UploadSessionOptions {
87
+ readonly maxBytes?: number;
88
+ readonly signal?: AbortSignal;
89
+ }
90
+ export interface CreateUploadSessionResponse {
91
+ readonly id: string;
92
+ }
93
+ export interface UploadFileToSessionParams {
94
+ readonly uploadSessionId: string;
95
+ readonly file: Blob | ArrayBuffer | Uint8Array | ReadableStream<Uint8Array>;
96
+ readonly fileOffset?: number;
97
+ readonly contentLength?: number;
98
+ }
99
+ export interface UploadFileToSessionResponse {
100
+ readonly h: string;
101
+ }
102
+ export interface GetUploadSessionParams {
103
+ readonly uploadSessionId: string;
104
+ readonly signal?: AbortSignal;
105
+ }
106
+ export interface GetUploadSessionResponse {
107
+ readonly id: string;
108
+ readonly fileOffset: number;
109
+ }
110
+ export declare const MEDIA_LINEAR_ISSUE_UPLOAD = "WATS-37";
111
+ export declare const MEDIA_LINEAR_ISSUE_DOWNLOAD = "WATS-37";
112
+ export declare const MEDIA_LINEAR_ISSUE_DELETE = "WATS-37";
113
+ export declare const MEDIA_LINEAR_ISSUE_DECRYPT = "WATS-37";
114
+ export declare function uploadMedia(client: GraphClient, params: {
115
+ phoneNumberId: string;
116
+ }, body: MediaUploadBody, options?: MediaUploadOptions): Promise<MediaUploadResponse>;
117
+ export declare function downloadMedia(client: GraphClient, opts: MediaDownloadOptions): Promise<MediaDownloadResponse>;
118
+ export declare function deleteMedia(client: GraphClient, params: MediaDeleteOptions): Promise<MediaDeleteResponse>;
119
+ export declare function decryptEncryptedMedia(bundle: EncryptedMediaBundle, encrypted: Uint8Array): Promise<Uint8Array>;
120
+ export declare function downloadMediaBytes(client: GraphClient, opts: MediaDownloadBytesOptions): Promise<MediaDownloadBytesResponse>;
121
+ export declare function createUploadSession(client: GraphClient, params: CreateUploadSessionParams, opts?: UploadSessionOptions): Promise<CreateUploadSessionResponse>;
122
+ export declare function uploadFileToSession(client: GraphClient, params: UploadFileToSessionParams, opts?: UploadSessionOptions): Promise<UploadFileToSessionResponse>;
123
+ export declare function getUploadSession(client: GraphClient, params: GetUploadSessionParams): Promise<GetUploadSessionResponse>;