@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,194 @@
1
+ export class PhoneNumberClient {
2
+ #graphClient;
3
+ #phoneNumberId;
4
+ constructor(config) {
5
+ validatePhoneNumberClientConfig(config);
6
+ this.#graphClient = config.graphClient;
7
+ this.#phoneNumberId = config.phoneNumberId;
8
+ }
9
+ get phoneNumberId() {
10
+ return this.#phoneNumberId;
11
+ }
12
+ get graphClient() {
13
+ return this.#graphClient;
14
+ }
15
+ async getInfo(params, opts) {
16
+ const scopedParams = copyOptionalParamsObject(params, "PhoneNumberClient.getInfo");
17
+ scopedParams.phoneNumberId = this.#phoneNumberId;
18
+ return getPhoneNumberInfoEndpoint(this.#graphClient, scopedParams, undefined, opts);
19
+ }
20
+ async getSettings(params, opts) {
21
+ const scopedParams = copyOptionalParamsObject(params, "PhoneNumberClient.getSettings");
22
+ scopedParams.phoneNumberId = this.#phoneNumberId;
23
+ return getPhoneNumberSettingsEndpoint(this.#graphClient, scopedParams, undefined, opts);
24
+ }
25
+ async getBusinessProfile(params, opts) {
26
+ const scopedParams = copyOptionalParamsObject(params, "PhoneNumberClient.getBusinessProfile");
27
+ scopedParams.phoneNumberId = this.#phoneNumberId;
28
+ return getBusinessProfileEndpoint(this.#graphClient, scopedParams, undefined, opts);
29
+ }
30
+ async getCommerceSettings(params, opts) {
31
+ const scopedParams = copyOptionalParamsObject(params, "PhoneNumberClient.getCommerceSettings");
32
+ scopedParams.phoneNumberId = this.#phoneNumberId;
33
+ return getCommerceSettingsEndpoint(this.#graphClient, scopedParams, undefined, opts);
34
+ }
35
+ async sendMessage(body, opts) {
36
+ return sendMessageEndpoint(this.#graphClient, { phoneNumberId: this.#phoneNumberId }, body, opts);
37
+ }
38
+ async sendText(input, opts) {
39
+ return this.sendMessage(buildSendTextPayload(input), opts);
40
+ }
41
+ async sendImage(input, opts) {
42
+ return this.sendMessage(buildSendImagePayload(input), opts);
43
+ }
44
+ async sendVideo(input, opts) {
45
+ return this.sendMessage(buildSendVideoPayload(input), opts);
46
+ }
47
+ async sendAudio(input, opts) {
48
+ return this.sendMessage(buildSendAudioPayload(input), opts);
49
+ }
50
+ async sendDocument(input, opts) {
51
+ return this.sendMessage(buildSendDocumentPayload(input), opts);
52
+ }
53
+ async sendSticker(input, opts) {
54
+ return this.sendMessage(buildSendStickerPayload(input), opts);
55
+ }
56
+ async sendLocation(input, opts) {
57
+ return this.sendMessage(buildSendLocationPayload(input), opts);
58
+ }
59
+ async sendContacts(input, opts) {
60
+ return this.sendMessage(buildSendContactsPayload(input), opts);
61
+ }
62
+ async sendReaction(input, opts) {
63
+ return this.sendMessage(buildSendReactionPayload(input), opts);
64
+ }
65
+ async removeReaction(input, opts) {
66
+ return this.sendMessage(buildRemoveReactionPayload(input), opts);
67
+ }
68
+ async sendButtons(input, opts) {
69
+ return this.sendMessage(buildSendButtonsPayload(input), opts);
70
+ }
71
+ async sendList(input, opts) {
72
+ return this.sendMessage(buildSendListPayload(input), opts);
73
+ }
74
+ async sendCtaUrl(input, opts) {
75
+ return this.sendMessage(buildSendCtaUrlPayload(input), opts);
76
+ }
77
+ async sendProduct(input, opts) {
78
+ return this.sendMessage(buildSendProductPayload(input), opts);
79
+ }
80
+ async sendProducts(input, opts) {
81
+ return this.sendMessage(buildSendProductsPayload(input), opts);
82
+ }
83
+ async sendCatalog(input, opts) {
84
+ return this.sendMessage(buildSendCatalogPayload(input), opts);
85
+ }
86
+ async requestLocation(input, opts) {
87
+ return this.sendMessage(buildRequestLocationPayload(input), opts);
88
+ }
89
+ async markMessageAsRead(input, opts) {
90
+ return this.sendMessage(buildMarkMessageAsReadPayload(input), opts);
91
+ }
92
+ async indicateTyping(input, opts) {
93
+ return this.sendMessage(buildTypingIndicatorPayload(input), opts);
94
+ }
95
+ async sendTemplate(input, opts) {
96
+ return this.sendMessage(buildSendTemplatePayload(input), opts);
97
+ }
98
+ async initiateCall(input, opts) {
99
+ return initiateCallEndpoint(this.#graphClient, { phoneNumberId: this.#phoneNumberId }, input, opts);
100
+ }
101
+ async preAcceptCall(input, opts) {
102
+ return preAcceptCallEndpoint(this.#graphClient, { phoneNumberId: this.#phoneNumberId }, input, opts);
103
+ }
104
+ async acceptCall(input, opts) {
105
+ return acceptCallEndpoint(this.#graphClient, { phoneNumberId: this.#phoneNumberId }, input, opts);
106
+ }
107
+ async rejectCall(input, opts) {
108
+ return rejectCallEndpoint(this.#graphClient, { phoneNumberId: this.#phoneNumberId }, input, opts);
109
+ }
110
+ async terminateCall(input, opts) {
111
+ return terminateCallEndpoint(this.#graphClient, { phoneNumberId: this.#phoneNumberId }, input, opts);
112
+ }
113
+ }
114
+ import { assertSafePathParamValue } from "../endpoint";
115
+ import { GraphRequestValidationError } from "../errors";
116
+ import { copyOptionalParamsObject } from "../internal/validation/options";
117
+ import {
118
+ getBusinessProfile as getBusinessProfileEndpoint,
119
+ getCommerceSettings as getCommerceSettingsEndpoint,
120
+ getPhoneNumberInfo as getPhoneNumberInfoEndpoint,
121
+ getPhoneNumberSettings as getPhoneNumberSettingsEndpoint
122
+ } from "../endpoints/businessManagement";
123
+ import {
124
+ acceptCall as acceptCallEndpoint,
125
+ initiateCall as initiateCallEndpoint,
126
+ preAcceptCall as preAcceptCallEndpoint,
127
+ rejectCall as rejectCallEndpoint,
128
+ terminateCall as terminateCallEndpoint
129
+ } from "../endpoints/calling";
130
+ import {
131
+ buildMarkMessageAsReadPayload,
132
+ buildRemoveReactionPayload,
133
+ buildRequestLocationPayload,
134
+ buildSendAudioPayload,
135
+ buildSendButtonsPayload,
136
+ buildSendCatalogPayload,
137
+ buildSendContactsPayload,
138
+ buildSendCtaUrlPayload,
139
+ buildSendDocumentPayload,
140
+ buildSendImagePayload,
141
+ buildSendListPayload,
142
+ buildSendLocationPayload,
143
+ buildSendProductPayload,
144
+ buildSendProductsPayload,
145
+ buildSendReactionPayload,
146
+ buildSendStickerPayload,
147
+ buildSendTemplatePayload,
148
+ buildSendTextPayload,
149
+ buildSendVideoPayload,
150
+ buildTypingIndicatorPayload,
151
+ sendMessage as sendMessageEndpoint
152
+ } from "../endpoints/messages";
153
+ function hasRequestMethod(candidate) {
154
+ if (candidate === null || typeof candidate !== "object") {
155
+ return false;
156
+ }
157
+ const maybe = candidate;
158
+ return typeof maybe.request === "function";
159
+ }
160
+ function assertNoEncodedUnsafePathParam(value, fieldName) {
161
+ let decoded = value;
162
+ for (let round = 0;round < 8; round += 1) {
163
+ let next;
164
+ try {
165
+ next = decodeURIComponent(decoded);
166
+ } catch {
167
+ throw new GraphRequestValidationError(`Invalid PhoneNumberClient config: ${fieldName} contains malformed percent encoding.`);
168
+ }
169
+ if (next === decoded)
170
+ return;
171
+ decoded = next;
172
+ if (decoded === "." || decoded === ".." || decoded.includes("/") || decoded.includes("\\") || decoded.includes("?") || decoded.includes("#")) {
173
+ throw new GraphRequestValidationError(`Invalid PhoneNumberClient config: ${fieldName} contains an unsafe path segment.`);
174
+ }
175
+ }
176
+ throw new GraphRequestValidationError(`Invalid PhoneNumberClient config: ${fieldName} contains excessive percent encoding.`);
177
+ }
178
+ export function validatePhoneNumberClientConfig(config) {
179
+ if (typeof config !== "object" || config === null) {
180
+ throw new GraphRequestValidationError("Invalid PhoneNumberClient config: expected an options object.");
181
+ }
182
+ const raw = config;
183
+ if (!hasRequestMethod(raw.graphClient)) {
184
+ throw new GraphRequestValidationError("Invalid PhoneNumberClient config: graphClient must expose a request() method.");
185
+ }
186
+ if (typeof raw.phoneNumberId !== "string") {
187
+ throw new GraphRequestValidationError("Invalid PhoneNumberClient config: phoneNumberId must be a non-empty string.");
188
+ }
189
+ if (raw.phoneNumberId.length === 0 || raw.phoneNumberId.trim().length === 0) {
190
+ throw new GraphRequestValidationError("Invalid PhoneNumberClient config: phoneNumberId must be a non-empty string.");
191
+ }
192
+ assertSafePathParamValue("phoneNumberId", raw.phoneNumberId);
193
+ assertNoEncodedUnsafePathParam(raw.phoneNumberId, "phoneNumberId");
194
+ }
@@ -0,0 +1,66 @@
1
+ import type { GraphClient } from "../client";
2
+ import type { EndpointInvokeOptions } from "../endpoint";
3
+ import { type GetWabaInfoInput, type SubscribedAppsResponse, type WabaInfo } from "../endpoints/businessManagement";
4
+ import { type ListPhoneNumbersInput, type PhoneNumberListResponse } from "../endpoints/waba";
5
+ import { type CreateFlowBody, type CreateMessageTemplateBody, type DeleteMessageTemplateInput, type FlowAssetsResponse, type FlowDetails, type FlowListResponse, type FlowMutationResponse, type GetFlowAssetsInput, type GetFlowInput, type GetMessageTemplateInput, type ListFlowsInput, type ListMessageTemplatesInput, type TemplateDetails, type TemplateListResponse, type TemplateMutationResponse, type UpdateFlowJsonBody, type UpdateFlowMetadataBody, type UpdateMessageTemplateBody } from "../endpoints/wabaEndpoints";
6
+ export interface WABAClientConfig {
7
+ readonly graphClient: GraphClient;
8
+ readonly wabaId: string;
9
+ }
10
+ export declare function validateWABAClientConfig(config: WABAClientConfig): void;
11
+ export declare class WABAClient {
12
+ #private;
13
+ constructor(config: WABAClientConfig);
14
+ get wabaId(): string;
15
+ get graphClient(): GraphClient;
16
+ /** Graph `GET /{wabaId}` — returns WABA inventory/profile fields. */
17
+ getInfo(params?: Omit<GetWabaInfoInput, "wabaId">, opts?: EndpointInvokeOptions): Promise<WabaInfo>;
18
+ /** Graph `GET /{wabaId}/subscribed_apps`. */
19
+ listSubscribedApps(params?: Record<string, never>, opts?: EndpointInvokeOptions): Promise<SubscribedAppsResponse>;
20
+ /**
21
+ * Graph `GET /{wabaId}/phone_numbers` — returns the phone numbers
22
+ * attached to this WABA. Delegates to the F-6 `listPhoneNumbers`
23
+ * endpoint-registry callable with the bound wabaId injected.
24
+ */
25
+ listPhoneNumbers(params?: Omit<ListPhoneNumbersInput, "wabaId">, opts?: EndpointInvokeOptions): Promise<PhoneNumberListResponse>;
26
+ /** Graph `GET /{wabaId}/message_templates`. */
27
+ listMessageTemplates(params?: Omit<ListMessageTemplatesInput, "wabaId">, opts?: EndpointInvokeOptions): Promise<TemplateListResponse>;
28
+ /** Graph `POST /{wabaId}/message_templates`. */
29
+ createMessageTemplate(body: CreateMessageTemplateBody, opts?: EndpointInvokeOptions): Promise<TemplateMutationResponse>;
30
+ /** Graph `GET /{templateId}`. */
31
+ getMessageTemplate(params: GetMessageTemplateInput, opts?: EndpointInvokeOptions): Promise<TemplateDetails>;
32
+ /** Graph `POST /{templateId}`. */
33
+ updateMessageTemplate(params: {
34
+ readonly templateId: string;
35
+ } & UpdateMessageTemplateBody, opts?: EndpointInvokeOptions): Promise<TemplateMutationResponse>;
36
+ /** Graph `DELETE /{wabaId}/message_templates?name=...&hsm_id=...`. */
37
+ deleteMessageTemplate(params: Omit<DeleteMessageTemplateInput, "wabaId">, opts?: EndpointInvokeOptions): Promise<TemplateMutationResponse>;
38
+ /** Graph `GET /{wabaId}/flows`. */
39
+ listFlows(params?: Omit<ListFlowsInput, "wabaId">, opts?: EndpointInvokeOptions): Promise<FlowListResponse>;
40
+ /** Graph `POST /{wabaId}/flows`. */
41
+ createFlow(body: CreateFlowBody, opts?: EndpointInvokeOptions): Promise<FlowMutationResponse>;
42
+ /** Graph `GET /{flowId}`. */
43
+ getFlow(params: GetFlowInput, opts?: EndpointInvokeOptions): Promise<FlowDetails>;
44
+ /** Graph `POST /{flowId}` metadata update. */
45
+ updateFlowMetadata(params: {
46
+ readonly flowId: string;
47
+ } & UpdateFlowMetadataBody, opts?: EndpointInvokeOptions): Promise<FlowMutationResponse>;
48
+ /** Graph `POST /{flowId}/assets` Flow JSON update. */
49
+ updateFlowJson(params: {
50
+ readonly flowId: string;
51
+ } & UpdateFlowJsonBody, opts?: EndpointInvokeOptions): Promise<FlowMutationResponse>;
52
+ /** Graph `POST /{flowId}/publish`. */
53
+ publishFlow(params: {
54
+ readonly flowId: string;
55
+ }, opts?: EndpointInvokeOptions): Promise<FlowMutationResponse>;
56
+ /** Graph `DELETE /{flowId}`. */
57
+ deleteFlow(params: {
58
+ readonly flowId: string;
59
+ }, opts?: EndpointInvokeOptions): Promise<FlowMutationResponse>;
60
+ /** Graph `POST /{flowId}/deprecate`. */
61
+ deprecateFlow(params: {
62
+ readonly flowId: string;
63
+ }, opts?: EndpointInvokeOptions): Promise<FlowMutationResponse>;
64
+ /** Graph `GET /{flowId}/assets`. */
65
+ getFlowAssets(params: GetFlowAssetsInput, opts?: EndpointInvokeOptions): Promise<FlowAssetsResponse>;
66
+ }
@@ -0,0 +1,180 @@
1
+ export class WABAClient {
2
+ #graphClient;
3
+ #wabaId;
4
+ constructor(config) {
5
+ validateWABAClientConfig(config);
6
+ this.#graphClient = config.graphClient;
7
+ this.#wabaId = config.wabaId;
8
+ }
9
+ get wabaId() {
10
+ return this.#wabaId;
11
+ }
12
+ get graphClient() {
13
+ return this.#graphClient;
14
+ }
15
+ async getInfo(params, opts) {
16
+ const scopedParams = copyOptionalParamsObject(params, "WABAClient.getInfo");
17
+ scopedParams.wabaId = this.#wabaId;
18
+ return getWabaInfoEndpoint(this.#graphClient, scopedParams, undefined, opts);
19
+ }
20
+ async listSubscribedApps(params, opts) {
21
+ copyOptionalParamsObject(params, "WABAClient.listSubscribedApps");
22
+ return listSubscribedAppsEndpoint(this.#graphClient, { wabaId: this.#wabaId }, undefined, opts);
23
+ }
24
+ async listPhoneNumbers(params, opts) {
25
+ const scopedParams = copyOptionalParamsObject(params, "WABAClient.listPhoneNumbers");
26
+ scopedParams.wabaId = this.#wabaId;
27
+ return listPhoneNumbersEndpoint(this.#graphClient, scopedParams, undefined, opts);
28
+ }
29
+ async listMessageTemplates(params, opts) {
30
+ const scopedParams = {
31
+ ...copyOptionalParamsObject(params, "WABAClient.listMessageTemplates"),
32
+ wabaId: this.#wabaId
33
+ };
34
+ return listMessageTemplatesEndpoint(this.#graphClient, scopedParams, undefined, opts);
35
+ }
36
+ async createMessageTemplate(body, opts) {
37
+ return createMessageTemplateEndpoint(this.#graphClient, { wabaId: this.#wabaId }, body, opts);
38
+ }
39
+ async getMessageTemplate(params, opts) {
40
+ return getMessageTemplateEndpoint(this.#graphClient, params, undefined, opts);
41
+ }
42
+ async updateMessageTemplate(params, opts) {
43
+ if (typeof params !== "object" || params === null || Array.isArray(params)) {
44
+ throw new GraphRequestValidationError("Invalid WABAClient.updateMessageTemplate params: expected an options object.");
45
+ }
46
+ const descriptors = Object.getOwnPropertyDescriptors(params);
47
+ const templateIdDescriptor = descriptors.templateId;
48
+ if (templateIdDescriptor === undefined || typeof templateIdDescriptor.get === "function" || typeof templateIdDescriptor.set === "function" || typeof templateIdDescriptor.value !== "string") {
49
+ throw new GraphRequestValidationError("Invalid WABAClient.updateMessageTemplate params: templateId must be a string data property.");
50
+ }
51
+ const body = {};
52
+ for (const [key, descriptor] of Object.entries(descriptors)) {
53
+ if (key === "templateId")
54
+ continue;
55
+ if (typeof descriptor.get === "function" || typeof descriptor.set === "function") {
56
+ throw new GraphRequestValidationError("Invalid WABAClient.updateMessageTemplate params: accessors are not allowed.");
57
+ }
58
+ if (descriptor.value !== undefined)
59
+ body[key] = descriptor.value;
60
+ }
61
+ return updateMessageTemplateEndpoint(this.#graphClient, { templateId: templateIdDescriptor.value }, body, opts);
62
+ }
63
+ async deleteMessageTemplate(params, opts) {
64
+ const scopedParams = {
65
+ ...copyOptionalParamsObject(params, "WABAClient.deleteMessageTemplate"),
66
+ wabaId: this.#wabaId
67
+ };
68
+ return deleteMessageTemplateEndpoint(this.#graphClient, scopedParams, undefined, opts);
69
+ }
70
+ async listFlows(params, opts) {
71
+ const scopedParams = {
72
+ ...copyOptionalParamsObject(params, "WABAClient.listFlows"),
73
+ wabaId: this.#wabaId
74
+ };
75
+ return listFlowsEndpoint(this.#graphClient, scopedParams, undefined, opts);
76
+ }
77
+ async createFlow(body, opts) {
78
+ return createFlowEndpoint(this.#graphClient, { wabaId: this.#wabaId }, body, opts);
79
+ }
80
+ async getFlow(params, opts) {
81
+ const { flowId, rest } = splitFlowIdParams(params, "WABAClient.getFlow");
82
+ return getFlowEndpoint(this.#graphClient, { flowId, ...rest }, undefined, opts);
83
+ }
84
+ async updateFlowMetadata(params, opts) {
85
+ const { flowId, rest } = splitFlowIdParams(params, "WABAClient.updateFlowMetadata");
86
+ return updateFlowMetadataEndpoint(this.#graphClient, { flowId }, rest, opts);
87
+ }
88
+ async updateFlowJson(params, opts) {
89
+ const { flowId, rest } = splitFlowIdParams(params, "WABAClient.updateFlowJson");
90
+ return updateFlowJsonEndpoint(this.#graphClient, { flowId }, rest, opts);
91
+ }
92
+ async publishFlow(params, opts) {
93
+ const { flowId } = splitFlowIdParams(params, "WABAClient.publishFlow");
94
+ return publishFlowEndpoint(this.#graphClient, { flowId }, undefined, opts);
95
+ }
96
+ async deleteFlow(params, opts) {
97
+ const { flowId } = splitFlowIdParams(params, "WABAClient.deleteFlow");
98
+ return deleteFlowEndpoint(this.#graphClient, { flowId }, undefined, opts);
99
+ }
100
+ async deprecateFlow(params, opts) {
101
+ const { flowId } = splitFlowIdParams(params, "WABAClient.deprecateFlow");
102
+ return deprecateFlowEndpoint(this.#graphClient, { flowId }, undefined, opts);
103
+ }
104
+ async getFlowAssets(params, opts) {
105
+ const { flowId, rest } = splitFlowIdParams(params, "WABAClient.getFlowAssets");
106
+ return getFlowAssetsEndpoint(this.#graphClient, { flowId, ...rest }, undefined, opts);
107
+ }
108
+ }
109
+ import { assertSafePathParamValue } from "../endpoint";
110
+ import { GraphRequestValidationError } from "../errors";
111
+ import { copyOptionalParamsObject, splitRequiredStringDataProp } from "../internal/validation/options";
112
+ import {
113
+ getWabaInfo as getWabaInfoEndpoint,
114
+ listSubscribedApps as listSubscribedAppsEndpoint
115
+ } from "../endpoints/businessManagement";
116
+ import {
117
+ listPhoneNumbers as listPhoneNumbersEndpoint
118
+ } from "../endpoints/waba";
119
+ import {
120
+ createMessageTemplate as createMessageTemplateEndpoint,
121
+ deleteMessageTemplate as deleteMessageTemplateEndpoint,
122
+ getMessageTemplate as getMessageTemplateEndpoint,
123
+ listMessageTemplates as listMessageTemplatesEndpoint,
124
+ updateMessageTemplate as updateMessageTemplateEndpoint,
125
+ listFlows as listFlowsEndpoint,
126
+ getFlow as getFlowEndpoint,
127
+ createFlow as createFlowEndpoint,
128
+ updateFlowMetadata as updateFlowMetadataEndpoint,
129
+ updateFlowJson as updateFlowJsonEndpoint,
130
+ publishFlow as publishFlowEndpoint,
131
+ deleteFlow as deleteFlowEndpoint,
132
+ deprecateFlow as deprecateFlowEndpoint,
133
+ getFlowAssets as getFlowAssetsEndpoint
134
+ } from "../endpoints/wabaEndpoints";
135
+ function hasRequestMethod(candidate) {
136
+ if (candidate === null || typeof candidate !== "object") {
137
+ return false;
138
+ }
139
+ const maybe = candidate;
140
+ return typeof maybe.request === "function";
141
+ }
142
+ export function validateWABAClientConfig(config) {
143
+ if (typeof config !== "object" || config === null) {
144
+ throw new GraphRequestValidationError("Invalid WABAClient config: expected an options object.");
145
+ }
146
+ const raw = config;
147
+ if (!hasRequestMethod(raw.graphClient)) {
148
+ throw new GraphRequestValidationError("Invalid WABAClient config: graphClient must expose a request() method.");
149
+ }
150
+ if (typeof raw.wabaId !== "string") {
151
+ throw new GraphRequestValidationError("Invalid WABAClient config: wabaId must be a non-empty string.");
152
+ }
153
+ if (raw.wabaId.length === 0 || raw.wabaId.trim().length === 0) {
154
+ throw new GraphRequestValidationError("Invalid WABAClient config: wabaId must be a non-empty string.");
155
+ }
156
+ assertSafePathParamValue("wabaId", raw.wabaId);
157
+ assertNoEncodedUnsafePathParam(raw.wabaId, "wabaId");
158
+ }
159
+ function assertNoEncodedUnsafePathParam(value, fieldName) {
160
+ let decoded = value;
161
+ for (let round = 0;round < 8; round += 1) {
162
+ let next;
163
+ try {
164
+ next = decodeURIComponent(decoded);
165
+ } catch {
166
+ throw new GraphRequestValidationError(`Invalid WABAClient config: ${fieldName} contains malformed percent encoding.`);
167
+ }
168
+ if (next === decoded)
169
+ return;
170
+ decoded = next;
171
+ if (decoded === "." || decoded === ".." || decoded.includes("/") || decoded.includes("\\") || decoded.includes("?") || decoded.includes("#")) {
172
+ throw new GraphRequestValidationError(`Invalid WABAClient config: ${fieldName} contains an unsafe path segment.`);
173
+ }
174
+ }
175
+ throw new GraphRequestValidationError(`Invalid WABAClient config: ${fieldName} contains excessive percent encoding.`);
176
+ }
177
+ function splitFlowIdParams(params, helperName) {
178
+ const split = splitRequiredStringDataProp(params, "flowId", helperName);
179
+ return { flowId: split.value, rest: split.rest };
180
+ }
@@ -0,0 +1,32 @@
1
+ export type TransportHttpMethod = "GET" | "POST" | "PUT" | "PATCH" | "DELETE";
2
+ export interface TransportRequest {
3
+ readonly method: TransportHttpMethod;
4
+ readonly url: string;
5
+ readonly headers: Headers;
6
+ readonly body: BodyInit | null;
7
+ }
8
+ export interface TransportResponse {
9
+ readonly status: number;
10
+ readonly headers: Headers;
11
+ readonly body: ReadableStream<Uint8Array> | null;
12
+ arrayBuffer(): Promise<ArrayBuffer>;
13
+ json<T = unknown>(): Promise<T>;
14
+ text(): Promise<string>;
15
+ }
16
+ export interface TransportOptions {
17
+ readonly signal?: AbortSignal;
18
+ }
19
+ export interface Transport {
20
+ request(req: TransportRequest, opts?: TransportOptions): Promise<TransportResponse>;
21
+ }
22
+ export interface TransportRetryPolicy {
23
+ readonly retries: number;
24
+ readonly baseDelayMs: number;
25
+ readonly maxDelayMs: number;
26
+ readonly jitter?: (attempt: number, baseDelayMs: number) => number;
27
+ }
28
+ export declare const DEFAULT_TRANSPORT_RETRY_POLICY: TransportRetryPolicy;
29
+ export interface TransportInterceptor {
30
+ onRequest?(req: TransportRequest): TransportRequest | Promise<TransportRequest>;
31
+ onResponse?(req: TransportRequest, res: TransportResponse): TransportResponse | Promise<TransportResponse>;
32
+ }
@@ -0,0 +1,5 @@
1
+ export const DEFAULT_TRANSPORT_RETRY_POLICY = {
2
+ retries: 3,
3
+ baseDelayMs: 200,
4
+ maxDelayMs: 30000
5
+ };
package/package.json ADDED
@@ -0,0 +1,70 @@
1
+ {
2
+ "name": "@wats/graph",
3
+ "version": "0.3.1",
4
+ "private": false,
5
+ "license": "MIT",
6
+ "type": "module",
7
+ "main": "./dist/index.js",
8
+ "types": "./dist/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "types": "./dist/index.d.ts",
12
+ "import": "./dist/index.js"
13
+ },
14
+ "./client": {
15
+ "types": "./dist/client.d.ts",
16
+ "import": "./dist/client.js"
17
+ },
18
+ "./errors": {
19
+ "types": "./dist/errors.d.ts",
20
+ "import": "./dist/errors.js"
21
+ },
22
+ "./endpoints/messages": {
23
+ "types": "./dist/endpoints/messages.d.ts",
24
+ "import": "./dist/endpoints/messages.js"
25
+ },
26
+ "./endpoints/media": {
27
+ "types": "./dist/endpoints/media.d.ts",
28
+ "import": "./dist/endpoints/media.js"
29
+ },
30
+ "./endpoints/templates": {
31
+ "types": "./dist/endpoints/templates.d.ts",
32
+ "import": "./dist/endpoints/templates.js"
33
+ },
34
+ "./endpoints/flows": {
35
+ "types": "./dist/endpoints/flows.d.ts",
36
+ "import": "./dist/endpoints/flows.js"
37
+ },
38
+ "./endpoints/calling": {
39
+ "types": "./dist/endpoints/calling.d.ts",
40
+ "import": "./dist/endpoints/calling.js"
41
+ },
42
+ "./endpoints/business-management": {
43
+ "types": "./dist/endpoints/businessManagement.d.ts",
44
+ "import": "./dist/endpoints/businessManagement.js"
45
+ },
46
+ "./transport": {
47
+ "types": "./dist/transport.d.ts",
48
+ "import": "./dist/transport.js"
49
+ },
50
+ "./testing": {
51
+ "types": "./dist/createMockTransport.d.ts",
52
+ "import": "./dist/createMockTransport.js"
53
+ }
54
+ },
55
+ "files": [
56
+ "dist",
57
+ "README.md",
58
+ "LICENSE"
59
+ ],
60
+ "publishConfig": {
61
+ "access": "public"
62
+ },
63
+ "keywords": [
64
+ "whatsapp",
65
+ "whatsapp-cloud-api",
66
+ "bun",
67
+ "typescript",
68
+ "wats"
69
+ ]
70
+ }