@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,223 @@
1
+ import { GraphRequestValidationError } from "./errors";
2
+ const ALLOWED_METHODS = new Set([
3
+ "GET",
4
+ "POST",
5
+ "PUT",
6
+ "PATCH",
7
+ "DELETE"
8
+ ]);
9
+ const PLACEHOLDER_NAME_REGEXP = /^[a-zA-Z_][a-zA-Z0-9_]*$/;
10
+ const PLACEHOLDER_SCAN_REGEXP = /\{([^{}]*)\}/g;
11
+ function hasControlChar(value) {
12
+ for (let i = 0;i < value.length; i += 1) {
13
+ const code = value.charCodeAt(i);
14
+ if (code < 32 || code === 127) {
15
+ return true;
16
+ }
17
+ }
18
+ return false;
19
+ }
20
+ function parsePathTemplate(template) {
21
+ const placeholders = [];
22
+ const seen = new Set;
23
+ let match;
24
+ const rx = new RegExp(PLACEHOLDER_SCAN_REGEXP.source, "g");
25
+ while ((match = rx.exec(template)) !== null) {
26
+ const name = match[1] ?? "";
27
+ if (name.length === 0) {
28
+ throw new GraphRequestValidationError(`Invalid defineEndpoint pathTemplate: empty placeholder '{}' in ${JSON.stringify(template)}.`);
29
+ }
30
+ if (!PLACEHOLDER_NAME_REGEXP.test(name)) {
31
+ throw new GraphRequestValidationError(`Invalid defineEndpoint pathTemplate: placeholder name ${JSON.stringify(name)} must match /^[a-zA-Z_][a-zA-Z0-9_]*$/.`);
32
+ }
33
+ if (seen.has(name)) {
34
+ throw new GraphRequestValidationError(`Invalid defineEndpoint pathTemplate: duplicate placeholder ${JSON.stringify(name)}.`);
35
+ }
36
+ seen.add(name);
37
+ placeholders.push(name);
38
+ }
39
+ const stripped = template.replace(new RegExp(PLACEHOLDER_SCAN_REGEXP.source, "g"), "");
40
+ if (stripped.includes("{") || stripped.includes("}")) {
41
+ throw new GraphRequestValidationError(`Invalid defineEndpoint pathTemplate: unbalanced or malformed braces in ${JSON.stringify(template)}.`);
42
+ }
43
+ return placeholders;
44
+ }
45
+ function validateDefinition(def) {
46
+ if (typeof def !== "object" || def === null) {
47
+ throw new GraphRequestValidationError("Invalid defineEndpoint spec: expected an options object.");
48
+ }
49
+ if (typeof def.method !== "string" || !ALLOWED_METHODS.has(def.method)) {
50
+ throw new GraphRequestValidationError(`Invalid defineEndpoint method: ${JSON.stringify(def.method)}. Expected one of GET|POST|PUT|PATCH|DELETE.`);
51
+ }
52
+ if (typeof def.pathTemplate !== "string" || def.pathTemplate.length === 0) {
53
+ throw new GraphRequestValidationError("Invalid defineEndpoint pathTemplate: expected a non-empty string.");
54
+ }
55
+ if (hasControlChar(def.pathTemplate)) {
56
+ throw new GraphRequestValidationError("Invalid defineEndpoint pathTemplate: control characters are not allowed.");
57
+ }
58
+ if (typeof def.params !== "object" || def.params === null) {
59
+ throw new GraphRequestValidationError("Invalid defineEndpoint params: expected an object keyed by parameter name.");
60
+ }
61
+ if (def.buildBody !== undefined && typeof def.buildBody !== "function") {
62
+ throw new GraphRequestValidationError("Invalid defineEndpoint buildBody: must be a function when provided.");
63
+ }
64
+ if (def.bodyContentType !== undefined && (typeof def.bodyContentType !== "string" || def.bodyContentType.length === 0)) {
65
+ throw new GraphRequestValidationError("Invalid defineEndpoint bodyContentType: must be a non-empty string when provided.");
66
+ }
67
+ const placeholders = parsePathTemplate(def.pathTemplate);
68
+ const placeholderSet = new Set(placeholders);
69
+ const paramKeys = Object.keys(def.params);
70
+ for (const key of paramKeys) {
71
+ if (!PLACEHOLDER_NAME_REGEXP.test(key)) {
72
+ throw new GraphRequestValidationError(`Invalid defineEndpoint params key ${JSON.stringify(key)}: must match /^[a-zA-Z_][a-zA-Z0-9_]*$/.`);
73
+ }
74
+ const spec = def.params[key];
75
+ if (typeof spec !== "object" || spec === null) {
76
+ throw new GraphRequestValidationError(`Invalid defineEndpoint params[${JSON.stringify(key)}]: expected an object.`);
77
+ }
78
+ if (spec.in !== "path" && spec.in !== "query") {
79
+ throw new GraphRequestValidationError(`Invalid defineEndpoint params[${JSON.stringify(key)}].in: expected 'path' or 'query'.`);
80
+ }
81
+ if (spec.in === "path" && !placeholderSet.has(key)) {
82
+ throw new GraphRequestValidationError(`Invalid defineEndpoint params[${JSON.stringify(key)}]: declared as path param but absent from pathTemplate ${JSON.stringify(def.pathTemplate)}.`);
83
+ }
84
+ }
85
+ for (const name of placeholders) {
86
+ const spec = def.params[name];
87
+ if (spec === undefined || spec.in !== "path") {
88
+ throw new GraphRequestValidationError(`Invalid defineEndpoint pathTemplate: placeholder ${JSON.stringify(name)} has no matching params entry with in:'path'.`);
89
+ }
90
+ }
91
+ return placeholders;
92
+ }
93
+ export function assertSafePathParamValue(name, value) {
94
+ if (value.length === 0) {
95
+ throw new GraphRequestValidationError(`Invalid defineEndpoint param ${JSON.stringify(name)}: path parameter value must be a non-empty string.`);
96
+ }
97
+ if (value === "." || value === "..") {
98
+ throw new GraphRequestValidationError(`Invalid defineEndpoint param ${JSON.stringify(name)}: dot-segments are not allowed.`);
99
+ }
100
+ if (value.includes("/") || value.includes("\\")) {
101
+ throw new GraphRequestValidationError(`Invalid defineEndpoint param ${JSON.stringify(name)}: path traversal patterns are not allowed.`);
102
+ }
103
+ if (value.includes("?") || value.includes("#")) {
104
+ throw new GraphRequestValidationError(`Invalid defineEndpoint param ${JSON.stringify(name)}: query strings and fragments are not allowed.`);
105
+ }
106
+ if (hasControlChar(value)) {
107
+ throw new GraphRequestValidationError(`Invalid defineEndpoint param ${JSON.stringify(name)}: control characters are not allowed.`);
108
+ }
109
+ }
110
+ function assertSafeQueryValue(name, value) {
111
+ for (let i = 0;i < value.length; i += 1) {
112
+ const code = value.charCodeAt(i);
113
+ if (code === 0 || code === 10 || code === 13) {
114
+ throw new GraphRequestValidationError(`Invalid defineEndpoint query param ${JSON.stringify(name)}: CR, LF, and NUL are not allowed.`);
115
+ }
116
+ }
117
+ }
118
+ function resolvePath(template, params, pathParamNames) {
119
+ let resolved = template;
120
+ for (const name of pathParamNames) {
121
+ const value = params[name];
122
+ if (typeof value !== "string") {
123
+ throw new GraphRequestValidationError(`Invalid defineEndpoint call: missing required path param ${JSON.stringify(name)}.`);
124
+ }
125
+ assertSafePathParamValue(name, value);
126
+ resolved = resolved.replace(`{${name}}`, value);
127
+ }
128
+ return resolved;
129
+ }
130
+ function buildQuery(params, spec) {
131
+ const out = {};
132
+ let any = false;
133
+ for (const [name, s] of Object.entries(spec)) {
134
+ if (s.in !== "query") {
135
+ continue;
136
+ }
137
+ const raw = params[name];
138
+ if (raw === undefined) {
139
+ if (s.required === true) {
140
+ throw new GraphRequestValidationError(`Invalid defineEndpoint call: missing required query param ${JSON.stringify(name)}.`);
141
+ }
142
+ continue;
143
+ }
144
+ if (typeof raw !== "string") {
145
+ throw new GraphRequestValidationError(`Invalid defineEndpoint param ${JSON.stringify(name)}: must be a string (got ${typeof raw}).`);
146
+ }
147
+ assertSafeQueryValue(name, raw);
148
+ out[name] = raw;
149
+ any = true;
150
+ }
151
+ return any ? out : undefined;
152
+ }
153
+ export function defineEndpoint(def) {
154
+ const pathParamNames = validateDefinition(def);
155
+ const paramsSpec = def.params;
156
+ const knownParamNames = new Set(Object.keys(paramsSpec));
157
+ const frozenDef = Object.freeze({
158
+ ...def,
159
+ params: Object.freeze({ ...def.params })
160
+ });
161
+ const callable = Object.assign(async function invoke(client, params, body, opts) {
162
+ if (typeof params !== "object" || params === null) {
163
+ throw new GraphRequestValidationError("Invalid defineEndpoint call: params must be an object.");
164
+ }
165
+ const paramsRec = params;
166
+ for (const key of Object.keys(paramsRec)) {
167
+ if (!knownParamNames.has(key)) {
168
+ throw new GraphRequestValidationError(`Invalid defineEndpoint call: unknown param ${JSON.stringify(key)}.`);
169
+ }
170
+ }
171
+ const pathValues = {};
172
+ for (const name of pathParamNames) {
173
+ const raw = paramsRec[name];
174
+ if (raw === undefined) {
175
+ throw new GraphRequestValidationError(`Invalid defineEndpoint call: missing required path param ${JSON.stringify(name)}.`);
176
+ }
177
+ if (typeof raw !== "string") {
178
+ throw new GraphRequestValidationError(`Invalid defineEndpoint param ${JSON.stringify(name)}: must be a string (got ${typeof raw}).`);
179
+ }
180
+ pathValues[name] = raw;
181
+ }
182
+ const resolvedPath = resolvePath(def.pathTemplate, pathValues, pathParamNames);
183
+ const resolvedQuery = buildQuery(paramsRec, paramsSpec);
184
+ const resolvedBody = body === undefined ? undefined : def.buildBody !== undefined ? def.buildBody(body) : body;
185
+ let headersInit;
186
+ if (opts?.headers !== undefined || def.bodyContentType !== undefined) {
187
+ const merged = {};
188
+ if (def.bodyContentType !== undefined && resolvedBody !== undefined) {
189
+ merged["content-type"] = def.bodyContentType;
190
+ }
191
+ if (opts?.headers !== undefined) {
192
+ if (opts.headers instanceof Headers) {
193
+ opts.headers.forEach((value, key) => {
194
+ merged[key] = value;
195
+ });
196
+ } else {
197
+ for (const [k, v] of Object.entries(opts.headers)) {
198
+ merged[k] = v;
199
+ }
200
+ }
201
+ }
202
+ headersInit = merged;
203
+ }
204
+ const requestOptions = {
205
+ method: def.method,
206
+ path: resolvedPath
207
+ };
208
+ if (resolvedBody !== undefined) {
209
+ requestOptions.body = resolvedBody;
210
+ }
211
+ if (resolvedQuery !== undefined) {
212
+ requestOptions.query = resolvedQuery;
213
+ }
214
+ if (headersInit !== undefined) {
215
+ requestOptions.headers = headersInit;
216
+ }
217
+ if (opts?.signal !== undefined) {
218
+ requestOptions.signal = opts.signal;
219
+ }
220
+ return client.request(requestOptions);
221
+ }, { definition: frozenDef });
222
+ return callable;
223
+ }
@@ -0,0 +1,157 @@
1
+ import { type EndpointInvokeOptions } from "../endpoint";
2
+ import type { GraphClient } from "../client";
3
+ import type { GraphPaging } from "./waba/types";
4
+ export type BusinessManagementFields = string | readonly string[];
5
+ export interface WabaInfo {
6
+ readonly id?: string;
7
+ readonly name?: string;
8
+ readonly timezone_id?: string;
9
+ readonly message_template_namespace?: string;
10
+ readonly status?: string;
11
+ readonly business_verification_status?: string;
12
+ readonly is_enabled_for_insights?: boolean;
13
+ readonly marketing_messages_lite_api_status?: string;
14
+ readonly marketing_messages_onboarding_status?: string;
15
+ readonly ownership_type?: string;
16
+ readonly health_status?: unknown;
17
+ readonly currency?: string;
18
+ readonly country?: string;
19
+ readonly subscribed_apps?: unknown;
20
+ readonly [key: string]: unknown;
21
+ }
22
+ export interface SubscribedAppInfo {
23
+ readonly app_id?: string;
24
+ readonly id?: string;
25
+ readonly name?: string;
26
+ readonly whatsapp_business_api_data?: unknown;
27
+ readonly override_callback_uri?: string;
28
+ readonly [key: string]: unknown;
29
+ }
30
+ export interface SubscribedAppsResponse {
31
+ readonly data?: readonly SubscribedAppInfo[];
32
+ readonly paging?: GraphPaging;
33
+ readonly [key: string]: unknown;
34
+ }
35
+ export interface PhoneNumberInfo {
36
+ readonly id?: string;
37
+ readonly display_phone_number?: string;
38
+ readonly verified_name?: string;
39
+ readonly quality_rating?: string;
40
+ readonly code_verification_status?: string;
41
+ readonly platform_type?: string;
42
+ readonly throughput?: unknown;
43
+ readonly webhook_configuration?: unknown;
44
+ readonly [key: string]: unknown;
45
+ }
46
+ export interface PhoneNumberSettingsEntry {
47
+ readonly [key: string]: unknown;
48
+ }
49
+ export interface PhoneNumberSettingsResponse {
50
+ readonly data?: readonly PhoneNumberSettingsEntry[];
51
+ readonly paging?: GraphPaging;
52
+ readonly [key: string]: unknown;
53
+ }
54
+ export interface BusinessProfileEntry {
55
+ readonly about?: string;
56
+ readonly address?: string;
57
+ readonly description?: string;
58
+ readonly email?: string;
59
+ readonly messaging_product?: string;
60
+ readonly profile_picture_url?: string;
61
+ readonly vertical?: string;
62
+ readonly websites?: readonly string[];
63
+ readonly [key: string]: unknown;
64
+ }
65
+ export interface BusinessProfileResponse {
66
+ readonly data?: readonly BusinessProfileEntry[];
67
+ readonly paging?: GraphPaging;
68
+ readonly [key: string]: unknown;
69
+ }
70
+ export interface CommerceSettingsEntry {
71
+ readonly is_cart_enabled?: boolean;
72
+ readonly is_catalog_visible?: boolean;
73
+ readonly [key: string]: unknown;
74
+ }
75
+ export interface CommerceSettingsResponse {
76
+ readonly data?: readonly CommerceSettingsEntry[];
77
+ readonly paging?: GraphPaging;
78
+ readonly [key: string]: unknown;
79
+ }
80
+ export interface GetWabaInfoInput {
81
+ readonly wabaId: string;
82
+ readonly fields?: BusinessManagementFields;
83
+ }
84
+ export interface ListSubscribedAppsInput {
85
+ readonly wabaId: string;
86
+ }
87
+ export interface ListPhoneNumbersInput {
88
+ readonly wabaId: string;
89
+ readonly fields?: BusinessManagementFields;
90
+ readonly limit?: string;
91
+ readonly after?: string;
92
+ readonly before?: string;
93
+ }
94
+ export interface GetPhoneNumberInfoInput {
95
+ readonly phoneNumberId: string;
96
+ readonly fields?: BusinessManagementFields;
97
+ }
98
+ export interface GetPhoneNumberSettingsInput {
99
+ readonly phoneNumberId: string;
100
+ readonly fields?: BusinessManagementFields;
101
+ /** Maps to Graph query parameter `include_sip_credentials`; responses may contain sensitive SIP credentials. */
102
+ readonly includeSipCredentials?: boolean;
103
+ }
104
+ export interface GetBusinessProfileInput {
105
+ readonly phoneNumberId: string;
106
+ readonly fields?: BusinessManagementFields;
107
+ }
108
+ export interface GetCommerceSettingsInput {
109
+ readonly phoneNumberId: string;
110
+ readonly fields?: BusinessManagementFields;
111
+ }
112
+ type WireParams = Record<string, string>;
113
+ export declare function normalizeWabaInfoParams(input: GetWabaInfoInput): WireParams;
114
+ export declare function normalizeListSubscribedAppsParams(input: ListSubscribedAppsInput): WireParams;
115
+ export declare function normalizeListPhoneNumbersParams(input: ListPhoneNumbersInput): WireParams;
116
+ export declare function normalizePhoneNumberInfoParams(input: GetPhoneNumberInfoInput): WireParams;
117
+ export declare function normalizePhoneNumberSettingsParams(input: GetPhoneNumberSettingsInput): WireParams;
118
+ export declare function normalizeBusinessProfileParams(input: GetBusinessProfileInput): WireParams;
119
+ export declare function normalizeCommerceSettingsParams(input: GetCommerceSettingsInput): WireParams;
120
+ export declare function sanitizeBusinessManagementOptions(opts: EndpointInvokeOptions | undefined, helperName: string): EndpointInvokeOptions | undefined;
121
+ export declare const getWabaInfo: ((client: GraphClient, params: GetWabaInfoInput, body?: never, opts?: EndpointInvokeOptions) => Promise<WabaInfo>) & {
122
+ definition: import("..").EndpointDefinition<{
123
+ wabaId: string;
124
+ fields?: string;
125
+ }, never, WabaInfo>;
126
+ };
127
+ export declare const listSubscribedApps: ((client: GraphClient, params: ListSubscribedAppsInput, body?: never, opts?: EndpointInvokeOptions) => Promise<SubscribedAppsResponse>) & {
128
+ definition: import("..").EndpointDefinition<{
129
+ wabaId: string;
130
+ }, never, SubscribedAppsResponse>;
131
+ };
132
+ export declare const getPhoneNumberInfo: ((client: GraphClient, params: GetPhoneNumberInfoInput, body?: never, opts?: EndpointInvokeOptions) => Promise<PhoneNumberInfo>) & {
133
+ definition: import("..").EndpointDefinition<{
134
+ phoneNumberId: string;
135
+ fields?: string;
136
+ }, never, PhoneNumberInfo>;
137
+ };
138
+ export declare const getPhoneNumberSettings: ((client: GraphClient, params: GetPhoneNumberSettingsInput, body?: never, opts?: EndpointInvokeOptions) => Promise<PhoneNumberSettingsResponse>) & {
139
+ definition: import("..").EndpointDefinition<{
140
+ phoneNumberId: string;
141
+ fields?: string;
142
+ include_sip_credentials?: string;
143
+ }, never, PhoneNumberSettingsResponse>;
144
+ };
145
+ export declare const getBusinessProfile: ((client: GraphClient, params: GetBusinessProfileInput, body?: never, opts?: EndpointInvokeOptions) => Promise<BusinessProfileResponse>) & {
146
+ definition: import("..").EndpointDefinition<{
147
+ phoneNumberId: string;
148
+ fields?: string;
149
+ }, never, BusinessProfileResponse>;
150
+ };
151
+ export declare const getCommerceSettings: ((client: GraphClient, params: GetCommerceSettingsInput, body?: never, opts?: EndpointInvokeOptions) => Promise<CommerceSettingsResponse>) & {
152
+ definition: import("..").EndpointDefinition<{
153
+ phoneNumberId: string;
154
+ fields?: string;
155
+ }, never, CommerceSettingsResponse>;
156
+ };
157
+ export {};
@@ -0,0 +1,277 @@
1
+ import { defineEndpoint } from "../endpoint";
2
+ import { GraphRequestValidationError } from "../errors";
3
+ import {
4
+ assertRepeatedlyDecodedSafePathId
5
+ } from "../internal/validation/paths";
6
+ import {
7
+ assertQueryString as assertInternalQueryString
8
+ } from "../internal/validation/strings";
9
+ import { assertJoinedStringQueryArray } from "../internal/validation/arrays";
10
+ import { sanitizeHeaderInit } from "../internal/validation/headers";
11
+ import {
12
+ assertPlainDataRecord,
13
+ ownDataValue as ownInternalDataValue
14
+ } from "../internal/validation/records";
15
+ const MAX_ID_LENGTH = 512;
16
+ const MAX_QUERY_STRING_LENGTH = 1024;
17
+ const MAX_FIELD_ARRAY_LENGTH = 50;
18
+ const MAX_FIELD_ITEM_LENGTH = 128;
19
+ const MAX_CURSOR_LENGTH = 512;
20
+ const MAX_PERCENT_DECODE_ROUNDS = 8;
21
+ function validationError(message, cause) {
22
+ return new GraphRequestValidationError(message, cause);
23
+ }
24
+ function wrapValidation(message, fn) {
25
+ try {
26
+ return fn();
27
+ } catch (error) {
28
+ if (error instanceof GraphRequestValidationError)
29
+ throw error;
30
+ throw validationError(message, error);
31
+ }
32
+ }
33
+ function assertPlainRecord(value, helperName, path = "params") {
34
+ try {
35
+ return assertPlainDataRecord(value, {
36
+ helperName,
37
+ path,
38
+ rejectFunctionsSymbolsBigInts: true
39
+ });
40
+ } catch (error) {
41
+ if (error instanceof GraphRequestValidationError)
42
+ throw error;
43
+ throw validationError(`Invalid ${helperName} input: ${path} could not be inspected.`, error);
44
+ }
45
+ }
46
+ function ownDataValue(record, key, helperName, required) {
47
+ return ownInternalDataValue(record, key, {
48
+ helperName,
49
+ path: key,
50
+ required
51
+ });
52
+ }
53
+ function assertPathId(value, fieldName, helperName) {
54
+ if (typeof value === "string" && value.length > 0 && value.trim().length === 0) {
55
+ throw validationError(`Invalid ${helperName} input: ${fieldName} must be non-empty.`);
56
+ }
57
+ return assertRepeatedlyDecodedSafePathId(value, {
58
+ helperName,
59
+ fieldName,
60
+ maxLength: MAX_ID_LENGTH,
61
+ maxDecodeRounds: MAX_PERCENT_DECODE_ROUNDS
62
+ });
63
+ }
64
+ function assertQueryString(value, fieldName, helperName, maxLength = MAX_QUERY_STRING_LENGTH) {
65
+ return assertInternalQueryString(value, {
66
+ helperName,
67
+ fieldName,
68
+ maxLength
69
+ });
70
+ }
71
+ function assertFieldsArray(value, helperName) {
72
+ wrapValidation(`Invalid ${helperName} input: fields could not be inspected.`, () => {
73
+ if (Array.isArray(value) && !Object.prototype.hasOwnProperty.call(value, "toJSON") && "toJSON" in value) {
74
+ throw validationError(`Invalid ${helperName} input: fields must not inherit toJSON.`);
75
+ }
76
+ });
77
+ return assertJoinedStringQueryArray(value, {
78
+ helperName,
79
+ path: "fields",
80
+ minLength: 1,
81
+ maxLength: MAX_FIELD_ARRAY_LENGTH,
82
+ maxItemLength: MAX_FIELD_ITEM_LENGTH,
83
+ rejectCommas: true,
84
+ invalidTypeMessage: `Invalid ${helperName} input: fields must be a string or array of strings.`,
85
+ invalidLengthMessage: `Invalid ${helperName} input: fields length must be between 1 and ${MAX_FIELD_ARRAY_LENGTH}.`,
86
+ unsafePrototypeKeyMessage: `Invalid ${helperName} input: fields contains an unsafe prototype key.`,
87
+ sparseArrayMessage: `Invalid ${helperName} input: fields must not contain sparse array holes.`,
88
+ unsupportedPropertyMessage: `Invalid ${helperName} input: fields contains unsupported properties.`,
89
+ commaMessage: `Invalid ${helperName} input: fields array entries must not contain commas.`
90
+ });
91
+ }
92
+ function optionalFields(record, helperName) {
93
+ const value = ownDataValue(record, "fields", helperName, false);
94
+ if (value === undefined)
95
+ return;
96
+ if (typeof value === "string")
97
+ return assertQueryString(value, "fields", helperName);
98
+ return assertFieldsArray(value, helperName);
99
+ }
100
+ function optionalQueryString(record, key, helperName) {
101
+ const value = ownDataValue(record, key, helperName, false);
102
+ if (value === undefined)
103
+ return;
104
+ return assertQueryString(value, key, helperName, key === "limit" ? 32 : MAX_CURSOR_LENGTH);
105
+ }
106
+ function optionalIncludeSipCredentials(record, helperName) {
107
+ const value = ownDataValue(record, "includeSipCredentials", helperName, false);
108
+ if (value === undefined)
109
+ return;
110
+ if (typeof value !== "boolean") {
111
+ throw validationError(`Invalid ${helperName} input: includeSipCredentials must be boolean when provided.`);
112
+ }
113
+ return value ? "true" : "false";
114
+ }
115
+ export function normalizeWabaInfoParams(input) {
116
+ const helperName = "getWabaInfo";
117
+ const record = assertPlainRecord(input, "getWabaInfo");
118
+ const out = { wabaId: assertPathId(ownDataValue(record, "wabaId", "getWabaInfo", true), "wabaId", "getWabaInfo") };
119
+ const fields = optionalFields(record, "getWabaInfo");
120
+ if (fields !== undefined)
121
+ out.fields = fields;
122
+ return out;
123
+ }
124
+ export function normalizeListSubscribedAppsParams(input) {
125
+ const helperName = "listSubscribedApps";
126
+ const record = assertPlainRecord(input, "listSubscribedApps");
127
+ return { wabaId: assertPathId(ownDataValue(record, "wabaId", "listSubscribedApps", true), "wabaId", "listSubscribedApps") };
128
+ }
129
+ export function normalizeListPhoneNumbersParams(input) {
130
+ const helperName = "listPhoneNumbers";
131
+ const record = assertPlainRecord(input, "listPhoneNumbers");
132
+ const out = { wabaId: assertPathId(ownDataValue(record, "wabaId", "listPhoneNumbers", true), "wabaId", "listPhoneNumbers") };
133
+ const fields = optionalFields(record, "listPhoneNumbers");
134
+ const limit = optionalQueryString(record, "limit", "listPhoneNumbers");
135
+ const after = optionalQueryString(record, "after", "listPhoneNumbers");
136
+ const before = optionalQueryString(record, "before", "listPhoneNumbers");
137
+ if (fields !== undefined)
138
+ out.fields = fields;
139
+ if (limit !== undefined)
140
+ out.limit = limit;
141
+ if (after !== undefined)
142
+ out.after = after;
143
+ if (before !== undefined)
144
+ out.before = before;
145
+ return out;
146
+ }
147
+ export function normalizePhoneNumberInfoParams(input) {
148
+ const helperName = "getPhoneNumberInfo";
149
+ const record = assertPlainRecord(input, "getPhoneNumberInfo");
150
+ const out = { phoneNumberId: assertPathId(ownDataValue(record, "phoneNumberId", "getPhoneNumberInfo", true), "phoneNumberId", "getPhoneNumberInfo") };
151
+ const fields = optionalFields(record, "getPhoneNumberInfo");
152
+ if (fields !== undefined)
153
+ out.fields = fields;
154
+ return out;
155
+ }
156
+ export function normalizePhoneNumberSettingsParams(input) {
157
+ const helperName = "getPhoneNumberSettings";
158
+ const record = assertPlainRecord(input, "getPhoneNumberSettings");
159
+ const out = { phoneNumberId: assertPathId(ownDataValue(record, "phoneNumberId", "getPhoneNumberSettings", true), "phoneNumberId", "getPhoneNumberSettings") };
160
+ const fields = optionalFields(record, "getPhoneNumberSettings");
161
+ const includeSipCredentials = optionalIncludeSipCredentials(record, "getPhoneNumberSettings");
162
+ if (fields !== undefined)
163
+ out.fields = fields;
164
+ if (includeSipCredentials !== undefined)
165
+ out.include_sip_credentials = includeSipCredentials;
166
+ return out;
167
+ }
168
+ export function normalizeBusinessProfileParams(input) {
169
+ const helperName = "getBusinessProfile";
170
+ const record = assertPlainRecord(input, "getBusinessProfile");
171
+ const out = { phoneNumberId: assertPathId(ownDataValue(record, "phoneNumberId", "getBusinessProfile", true), "phoneNumberId", "getBusinessProfile") };
172
+ const fields = optionalFields(record, "getBusinessProfile");
173
+ if (fields !== undefined)
174
+ out.fields = fields;
175
+ return out;
176
+ }
177
+ export function normalizeCommerceSettingsParams(input) {
178
+ const helperName = "getCommerceSettings";
179
+ const record = assertPlainRecord(input, "getCommerceSettings");
180
+ const out = { phoneNumberId: assertPathId(ownDataValue(record, "phoneNumberId", "getCommerceSettings", true), "phoneNumberId", "getCommerceSettings") };
181
+ const fields = optionalFields(record, "getCommerceSettings");
182
+ if (fields !== undefined)
183
+ out.fields = fields;
184
+ return out;
185
+ }
186
+ function sanitizeHeaders(headers, helperName) {
187
+ return sanitizeHeaderInit(headers, {
188
+ helperName,
189
+ path: "opts.headers",
190
+ invalidTypeMessage: `Invalid ${helperName} input: opts.headers must be a plain object.`,
191
+ inspectMessage: `Invalid ${helperName} input: opts.headers could not be inspected.`,
192
+ descriptorInspectMessage: `Invalid ${helperName} input: opts.headers descriptors could not be inspected.`,
193
+ accessorMessage: `Invalid ${helperName} options: headers must not use accessors.`,
194
+ nonStringValueMessage: `Invalid ${helperName} options: header values must be strings.`,
195
+ unsafePrototypeKeyMessage: `Invalid ${helperName} input: opts.headers contains an unsafe prototype key.`,
196
+ invalidKeyMessage: `Invalid ${helperName} input: opts.headers contains an invalid key.`,
197
+ symbolAccessorMessage: `Invalid ${helperName} input: opts.headers must not use symbol-keyed accessors.`,
198
+ symbolKeyMessage: `Invalid ${helperName} input: opts.headers must not contain symbol keys.`,
199
+ ownToJSONMessage: `Invalid ${helperName} input: opts.headers must not define toJSON.`
200
+ });
201
+ }
202
+ export function sanitizeBusinessManagementOptions(opts, helperName) {
203
+ if (opts === undefined)
204
+ return;
205
+ const record = assertPlainRecord(opts, helperName, "opts");
206
+ const out = {};
207
+ const signal = ownDataValue(record, "signal", helperName, false);
208
+ const headers = ownDataValue(record, "headers", helperName, false);
209
+ if (signal !== undefined)
210
+ out.signal = signal;
211
+ if (headers !== undefined)
212
+ out.headers = sanitizeHeaders(headers, helperName);
213
+ return out;
214
+ }
215
+ function assertNoBody(body, helperName) {
216
+ if (body !== undefined) {
217
+ throw validationError(`Invalid ${helperName} input: GET endpoints do not accept a body.`);
218
+ }
219
+ }
220
+ const getWabaInfoRaw = defineEndpoint({
221
+ method: "GET",
222
+ pathTemplate: "/{wabaId}",
223
+ params: { wabaId: { in: "path", required: true }, fields: { in: "query" } }
224
+ });
225
+ const listSubscribedAppsRaw = defineEndpoint({
226
+ method: "GET",
227
+ pathTemplate: "/{wabaId}/subscribed_apps",
228
+ params: { wabaId: { in: "path", required: true } }
229
+ });
230
+ const getPhoneNumberInfoRaw = defineEndpoint({
231
+ method: "GET",
232
+ pathTemplate: "/{phoneNumberId}",
233
+ params: { phoneNumberId: { in: "path", required: true }, fields: { in: "query" } }
234
+ });
235
+ const getPhoneNumberSettingsRaw = defineEndpoint({
236
+ method: "GET",
237
+ pathTemplate: "/{phoneNumberId}/settings",
238
+ params: {
239
+ phoneNumberId: { in: "path", required: true },
240
+ fields: { in: "query" },
241
+ include_sip_credentials: { in: "query" }
242
+ }
243
+ });
244
+ const getBusinessProfileRaw = defineEndpoint({
245
+ method: "GET",
246
+ pathTemplate: "/{phoneNumberId}/whatsapp_business_profile",
247
+ params: { phoneNumberId: { in: "path", required: true }, fields: { in: "query" } }
248
+ });
249
+ const getCommerceSettingsRaw = defineEndpoint({
250
+ method: "GET",
251
+ pathTemplate: "/{phoneNumberId}/whatsapp_commerce_settings",
252
+ params: { phoneNumberId: { in: "path", required: true }, fields: { in: "query" } }
253
+ });
254
+ export const getWabaInfo = Object.assign(async function getWabaInfo(client, params, body, opts) {
255
+ assertNoBody(body, "getWabaInfo");
256
+ return getWabaInfoRaw(client, normalizeWabaInfoParams(params), undefined, sanitizeBusinessManagementOptions(opts, "getWabaInfo"));
257
+ }, { definition: getWabaInfoRaw.definition });
258
+ export const listSubscribedApps = Object.assign(async function listSubscribedApps(client, params, body, opts) {
259
+ assertNoBody(body, "listSubscribedApps");
260
+ return listSubscribedAppsRaw(client, normalizeListSubscribedAppsParams(params), undefined, sanitizeBusinessManagementOptions(opts, "listSubscribedApps"));
261
+ }, { definition: listSubscribedAppsRaw.definition });
262
+ export const getPhoneNumberInfo = Object.assign(async function getPhoneNumberInfo(client, params, body, opts) {
263
+ assertNoBody(body, "getPhoneNumberInfo");
264
+ return getPhoneNumberInfoRaw(client, normalizePhoneNumberInfoParams(params), undefined, sanitizeBusinessManagementOptions(opts, "getPhoneNumberInfo"));
265
+ }, { definition: getPhoneNumberInfoRaw.definition });
266
+ export const getPhoneNumberSettings = Object.assign(async function getPhoneNumberSettings(client, params, body, opts) {
267
+ assertNoBody(body, "getPhoneNumberSettings");
268
+ return getPhoneNumberSettingsRaw(client, normalizePhoneNumberSettingsParams(params), undefined, sanitizeBusinessManagementOptions(opts, "getPhoneNumberSettings"));
269
+ }, { definition: getPhoneNumberSettingsRaw.definition });
270
+ export const getBusinessProfile = Object.assign(async function getBusinessProfile(client, params, body, opts) {
271
+ assertNoBody(body, "getBusinessProfile");
272
+ return getBusinessProfileRaw(client, normalizeBusinessProfileParams(params), undefined, sanitizeBusinessManagementOptions(opts, "getBusinessProfile"));
273
+ }, { definition: getBusinessProfileRaw.definition });
274
+ export const getCommerceSettings = Object.assign(async function getCommerceSettings(client, params, body, opts) {
275
+ assertNoBody(body, "getCommerceSettings");
276
+ return getCommerceSettingsRaw(client, normalizeCommerceSettingsParams(params), undefined, sanitizeBusinessManagementOptions(opts, "getCommerceSettings"));
277
+ }, { definition: getCommerceSettingsRaw.definition });