@wats/graph 0.3.26 → 0.3.28

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 (52) hide show
  1. package/README.md +1 -1
  2. package/dist/endpoints/businessManagement.d.ts +372 -1
  3. package/dist/endpoints/businessManagement.js +775 -5
  4. package/dist/endpoints/calling.d.ts +41 -1
  5. package/dist/endpoints/calling.js +100 -2
  6. package/dist/endpoints/flows/dataChannel.d.ts +139 -0
  7. package/dist/endpoints/flows/dataChannel.js +252 -0
  8. package/dist/endpoints/flows/flowDsl.d.ts +306 -0
  9. package/dist/endpoints/flows/flowDsl.js +610 -0
  10. package/dist/endpoints/flows/flowMediaUpload.d.ts +102 -0
  11. package/dist/endpoints/flows/flowMediaUpload.js +188 -0
  12. package/dist/endpoints/flows/index.d.ts +9 -1
  13. package/dist/endpoints/flows/index.js +70 -0
  14. package/dist/endpoints/flows/metricsMigration.d.ts +36 -0
  15. package/dist/endpoints/flows/metricsMigration.js +207 -0
  16. package/dist/endpoints/flows/types.d.ts +145 -0
  17. package/dist/endpoints/flows/types.js +14 -0
  18. package/dist/endpoints/flows.d.ts +2 -2
  19. package/dist/endpoints/flows.js +49 -1
  20. package/dist/endpoints/messages/builders-interactive.d.ts +9 -1
  21. package/dist/endpoints/messages/builders-interactive.js +49 -0
  22. package/dist/endpoints/messages/builders-template.d.ts +2 -1
  23. package/dist/endpoints/messages/builders-template.js +53 -2
  24. package/dist/endpoints/messages/deepLinks.d.ts +12 -0
  25. package/dist/endpoints/messages/deepLinks.js +38 -0
  26. package/dist/endpoints/messages/index.d.ts +4 -3
  27. package/dist/endpoints/messages/index.js +13 -2
  28. package/dist/endpoints/messages/types.d.ts +26 -3
  29. package/dist/endpoints/messages/validation.d.ts +7 -0
  30. package/dist/endpoints/messages/validation.js +12 -0
  31. package/dist/endpoints/oauth.d.ts +57 -0
  32. package/dist/endpoints/oauth.js +116 -0
  33. package/dist/endpoints/templates/advanced.d.ts +280 -0
  34. package/dist/endpoints/templates/advanced.js +519 -0
  35. package/dist/endpoints/templates/builders.js +21 -1
  36. package/dist/endpoints/templates/index.d.ts +2 -0
  37. package/dist/endpoints/templates/index.js +15 -0
  38. package/dist/endpoints/templates/shared.js +7 -1
  39. package/dist/endpoints/templates/types.d.ts +17 -2
  40. package/dist/endpoints/templates.d.ts +2 -1
  41. package/dist/endpoints/templates.js +14 -1
  42. package/dist/endpoints/wabaEndpoints.d.ts +4 -4
  43. package/dist/endpoints/wabaEndpoints.js +56 -0
  44. package/dist/index.d.ts +2 -1
  45. package/dist/index.js +1 -0
  46. package/dist/nodeMedia.d.ts +57 -0
  47. package/dist/nodeMedia.js +178 -0
  48. package/dist/subclients/phoneNumberClient.d.ts +92 -2
  49. package/dist/subclients/phoneNumberClient.js +133 -1
  50. package/dist/subclients/wabaClient.d.ts +82 -2
  51. package/dist/subclients/wabaClient.js +102 -2
  52. package/package.json +10 -3
@@ -7,6 +7,12 @@ export {
7
7
  buildTemplateHeaderComponent,
8
8
  createMessageTemplate,
9
9
  createTemplateGroup,
10
+ compareTemplates,
11
+ migrateTemplates,
12
+ archiveTemplates,
13
+ unarchiveTemplates,
14
+ upsertAuthenticationTemplate,
15
+ buildUpsertAuthenticationTemplateBody,
10
16
  deleteMessageTemplate,
11
17
  deleteTemplateGroup,
12
18
  getMessageTemplate,
@@ -14,7 +20,14 @@ export {
14
20
  getTemplateGroupAnalytics,
15
21
  listMessageTemplates,
16
22
  listTemplateGroups,
23
+ unpauseTemplate,
17
24
  updateMessageTemplate,
18
25
  updateTemplateGroup,
19
- validateTemplateParameterCounts
26
+ validateTemplateParameterCounts,
27
+ ARCHIVE_TEMPLATES_MAX_IDS,
28
+ COMPARE_TEMPLATES_MAX_IDS,
29
+ UPSERT_AUTH_LANGUAGES_MAX,
30
+ UPSERT_AUTH_SUPPORTED_APPS_MAX,
31
+ KNOWN_TEMPLATE_TOP_BLOCK_REASONS,
32
+ KNOWN_UPSERT_AUTH_OTP_TYPES
20
33
  } from "./templates/index.js";
@@ -1,9 +1,9 @@
1
1
  export { listPhoneNumbers } from "./waba/index.js";
2
2
  export type { GraphPaging, PhoneNumberListEntry, PhoneNumberListResponse } from "./waba/index.js";
3
- export { buildCreateMessageTemplateBody, buildUpdateMessageTemplateBody, buildTemplateBodyComponent, buildTemplateButtonComponent, buildTemplateFooterComponent, buildTemplateHeaderComponent, createMessageTemplate, deleteMessageTemplate, getMessageTemplate, listMessageTemplates, updateMessageTemplate, listTemplateGroups, createTemplateGroup, getTemplateGroup, updateTemplateGroup, deleteTemplateGroup, getTemplateGroupAnalytics, validateTemplateParameterCounts } from "./templates/index.js";
4
- export type { CreateMessageTemplateBody, DeleteMessageTemplateInput, GetMessageTemplateInput, ListMessageTemplatesInput, ListTemplateGroupsInput, SendTemplateComponentForValidation, TemplateBodyComponentInput, TemplateButtonInput, TemplateButtonsComponentInput, TemplateButtonType, TemplateCategory, TemplateComponent, TemplateDefinitionForValidation, TemplateDetails, TemplateGroupAnalyticsInput, TemplateGroupAnalyticsPoint, TemplateGroupAnalyticsResponse, TemplateGroupBody, TemplateGroupDetails, TemplateGroupListResponse, TemplateGroupMutationResponse, TemplateFooterComponentInput, TemplateHeaderComponentInput, TemplateHeaderFormat, TemplateLanguageCode, TemplateListResponse, TemplateMutationResponse, TemplateOtpType, TemplateParameterFormat, TemplateQualityScore, TemplateStatus, TemplateSupportedAppInput, UpdateMessageTemplateBody, CreateTemplateGroupBody, DeleteTemplateGroupInput, GetTemplateGroupInput, UpdateTemplateGroupBody } from "./templates/index.js";
3
+ export { buildCreateMessageTemplateBody, buildUpdateMessageTemplateBody, buildTemplateBodyComponent, buildTemplateButtonComponent, buildTemplateFooterComponent, buildTemplateHeaderComponent, createMessageTemplate, deleteMessageTemplate, getMessageTemplate, listMessageTemplates, updateMessageTemplate, listTemplateGroups, createTemplateGroup, getTemplateGroup, updateTemplateGroup, deleteTemplateGroup, getTemplateGroupAnalytics, compareTemplates, unpauseTemplate, migrateTemplates, archiveTemplates, unarchiveTemplates, upsertAuthenticationTemplate, buildUpsertAuthenticationTemplateBody, COMPARE_TEMPLATES_MAX_IDS, ARCHIVE_TEMPLATES_MAX_IDS, UPSERT_AUTH_LANGUAGES_MAX, UPSERT_AUTH_SUPPORTED_APPS_MAX, KNOWN_TEMPLATE_TOP_BLOCK_REASONS, KNOWN_UPSERT_AUTH_OTP_TYPES, validateTemplateParameterCounts } from "./templates/index.js";
4
+ export type { CreateMessageTemplateBody, DeleteMessageTemplateInput, GetMessageTemplateInput, ListMessageTemplatesInput, ListTemplateGroupsInput, SendTemplateComponentForValidation, TemplateBodyComponentInput, TemplateButtonInput, TemplateButtonsComponentInput, TemplateButtonType, TemplateCategory, TemplateComponent, TemplateDefinitionForValidation, TemplateDetails, TemplateGroupAnalyticsInput, TemplateGroupAnalyticsPoint, TemplateGroupAnalyticsResponse, TemplateGroupBody, TemplateGroupDetails, TemplateGroupListResponse, TemplateGroupMutationResponse, TemplateFooterComponentInput, TemplateHeaderComponentInput, TemplateHeaderFormat, TemplateLanguageCode, TemplateListResponse, TemplateMutationResponse, TemplateOtpType, TemplateParameterFormat, TemplateQualityScore, TemplateStatus, TemplateSupportedAppInput, UpdateMessageTemplateBody, CreateTemplateGroupBody, DeleteTemplateGroupInput, GetTemplateGroupInput, UpdateTemplateGroupBody, CompareTemplatesInput, FailedTemplateEntry, MigrateTemplatesInput, MigrateTemplatesResponse, MigratedTemplateEntry, ArchiveTemplatesInput, ArchiveTemplatesResponse, UnarchiveTemplatesInput, UnarchiveTemplatesResponse, TemplateTopBlockReason, TemplateUnpauseResult, TemplatesCompareResult, UnpauseTemplateInput, UpsertAuthOtpButtonInput, UpsertAuthOtpType, UpsertAuthSupportedAppInput, UpsertAuthenticationTemplateBody, UpsertAuthenticationTemplateResponse, UpsertedAuthTemplateEntry } from "./templates/index.js";
5
5
  /**
6
6
  * @experimental Flow DSL and data-channel helpers may change in 0.x minors while WATS expands Flow parity.
7
7
  */
8
- 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.js";
9
- export type { CreateFlowBody, FlowAssetDetails, FlowAssetsResponse, FlowCategory, FlowCloseResponse, FlowCloseResponseInput, FlowDetails, FlowErrorResponse, FlowErrorResponseInput, FlowJson, FlowListResponse, FlowMutationResponse, FlowScreenResponse, FlowScreenResponseInput, FlowStatus, GetFlowAssetsInput, GetFlowInput, ListFlowsInput, UpdateFlowJsonBody, UpdateFlowMetadataBody } from "./flows/index.js";
8
+ export { FLOW_DSL_MAX_CONTROL_DEPTH, 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, KNOWN_FLOW_METRIC_GRANULARITIES, KNOWN_FLOW_METRIC_NAMES, MIGRATE_FLOWS_MAX_NAMES, MIGRATE_FLOWS_NAME_MAX_LENGTH, buildFlowCloseResponse, buildFlowErrorResponse, buildFlowJson, buildFlowMetricField, buildFlowScreenResponse, calendarPicker, checkboxGroup, chipsSelector, completeAction, createFlow, dataExchangeAction, dataSource, datePicker, deleteFlow, deprecateFlow, documentPicker, dropdown, embeddedLink, flowJson, footer, form, getFlow, getFlowAssets, getFlowMetrics, ifComponent, image, imageCarousel, imageCarouselItem, listFlows, migrateFlows, navigateAction, navigationItem, navigationList, openUrlAction, optIn, photoPicker, publishFlow, radioButtonsGroup, richText, screen, singleColumnLayout, switchComponent, textArea, textBody, textCaption, textHeading, textInput, textSubheading, updateDataAction, updateFlowJson, updateFlowMetadata, validateFlowJson } from "./flows/index.js";
9
+ export type { CreateFlowBody, FlowAssetDetails, FlowAssetsResponse, FlowCategory, FlowCloseResponse, FlowCloseResponseInput, FlowDetails, FlowErrorResponse, FlowErrorResponseInput, FlowJson, FlowJsonProps, FlowListResponse, FlowMetric, FlowMetricDataPoint, FlowMetricGranularity, FlowMetricName, FlowMutationResponse, FlowScreenResponse, FlowScreenResponseInput, FlowStatus, FormProps, GetFlowAssetsInput, GetFlowInput, GetFlowMetricsInput, IfProps, ImageCarouselItemProps, ListFlowsInput, MigratedFlow, MigratedFlowError, MigrateFlowsInput, MigrateFlowsResponse, NavigateActionProps, NavigationItemProps, ScreenProps, SwitchProps, UpdateFlowJsonBody, UpdateFlowMetadataBody } from "./flows/index.js";
@@ -17,9 +17,23 @@ export {
17
17
  updateTemplateGroup,
18
18
  deleteTemplateGroup,
19
19
  getTemplateGroupAnalytics,
20
+ compareTemplates,
21
+ unpauseTemplate,
22
+ migrateTemplates,
23
+ archiveTemplates,
24
+ unarchiveTemplates,
25
+ upsertAuthenticationTemplate,
26
+ buildUpsertAuthenticationTemplateBody,
27
+ COMPARE_TEMPLATES_MAX_IDS,
28
+ ARCHIVE_TEMPLATES_MAX_IDS,
29
+ UPSERT_AUTH_LANGUAGES_MAX,
30
+ UPSERT_AUTH_SUPPORTED_APPS_MAX,
31
+ KNOWN_TEMPLATE_TOP_BLOCK_REASONS,
32
+ KNOWN_UPSERT_AUTH_OTP_TYPES,
20
33
  validateTemplateParameterCounts
21
34
  } from "./templates/index.js";
22
35
  export {
36
+ FLOW_DSL_MAX_CONTROL_DEPTH,
23
37
  FLOW_JSON_MAX_ARRAY_LENGTH,
24
38
  FLOW_JSON_MAX_BYTES,
25
39
  FLOW_JSON_MAX_COMPONENTS,
@@ -27,17 +41,59 @@ export {
27
41
  FLOW_JSON_MAX_SCREENS,
28
42
  FLOW_JSON_MAX_STRING_LENGTH,
29
43
  FLOW_MAX_CATEGORIES,
44
+ KNOWN_FLOW_METRIC_GRANULARITIES,
45
+ KNOWN_FLOW_METRIC_NAMES,
46
+ MIGRATE_FLOWS_MAX_NAMES,
47
+ MIGRATE_FLOWS_NAME_MAX_LENGTH,
30
48
  buildFlowCloseResponse,
31
49
  buildFlowErrorResponse,
32
50
  buildFlowJson,
51
+ buildFlowMetricField,
33
52
  buildFlowScreenResponse,
53
+ calendarPicker,
54
+ checkboxGroup,
55
+ chipsSelector,
56
+ completeAction,
34
57
  createFlow,
58
+ dataExchangeAction,
59
+ dataSource,
60
+ datePicker,
35
61
  deleteFlow,
36
62
  deprecateFlow,
63
+ documentPicker,
64
+ dropdown,
65
+ embeddedLink,
66
+ flowJson,
67
+ footer,
68
+ form,
37
69
  getFlow,
38
70
  getFlowAssets,
71
+ getFlowMetrics,
72
+ ifComponent,
73
+ image,
74
+ imageCarousel,
75
+ imageCarouselItem,
39
76
  listFlows,
77
+ migrateFlows,
78
+ navigateAction,
79
+ navigationItem,
80
+ navigationList,
81
+ openUrlAction,
82
+ optIn,
83
+ photoPicker,
40
84
  publishFlow,
85
+ radioButtonsGroup,
86
+ richText,
87
+ screen,
88
+ singleColumnLayout,
89
+ switchComponent,
90
+ textArea,
91
+ textBody,
92
+ textCaption,
93
+ textHeading,
94
+ textInput,
95
+ textSubheading,
96
+ updateDataAction,
41
97
  updateFlowJson,
42
98
  updateFlowMetadata,
43
99
  validateFlowJson
package/dist/index.d.ts CHANGED
@@ -5,11 +5,12 @@ export * from "./errorSubclasses.js";
5
5
  export * from "./endpoints/messages.js";
6
6
  export * from "./endpoints/calling.js";
7
7
  export * from "./endpoints/businessManagement.js";
8
+ export * from "./endpoints/oauth.js";
8
9
  export * from "./endpoints/groups.js";
9
10
  export * from "./endpoints/wabaEndpoints.js";
10
11
  export * from "./endpoint.js";
11
12
  export { PhoneNumberClient, validatePhoneNumberClientConfig } from "./subclients/phoneNumberClient.js";
12
- export type { PhoneNumberClientConfig } from "./subclients/phoneNumberClient.js";
13
+ export type { PhoneNumberClientConfig, UploadAndSendMediaBaseInput, UploadAndSendImageInput, UploadAndSendVideoInput, UploadAndSendAudioInput, UploadAndSendDocumentInput, UploadAndSendStickerInput } from "./subclients/phoneNumberClient.js";
13
14
  export { GroupClient, validateGroupClientConfig } from "./subclients/groupClient.js";
14
15
  export type { GroupClientConfig } from "./subclients/groupClient.js";
15
16
  export { WABAClient, validateWABAClientConfig } from "./subclients/wabaClient.js";
package/dist/index.js CHANGED
@@ -5,6 +5,7 @@ export * from "./errorSubclasses.js";
5
5
  export * from "./endpoints/messages.js";
6
6
  export * from "./endpoints/calling.js";
7
7
  export * from "./endpoints/businessManagement.js";
8
+ export * from "./endpoints/oauth.js";
8
9
  export * from "./endpoints/groups.js";
9
10
  export * from "./endpoints/wabaEndpoints.js";
10
11
  export * from "./endpoint.js";
@@ -0,0 +1,57 @@
1
+ import type { EndpointInvokeOptions } from "./endpoint.js";
2
+ import type { GraphMessagesSendResponse } from "./endpoints/messages.js";
3
+ import type { PhoneNumberClient } from "./subclients/phoneNumberClient.js";
4
+ /**
5
+ * Base input for every path-based upload-and-send helper. `path` is a
6
+ * filesystem path resolved by `node:fs`; `mimeType` optionally overrides the
7
+ * extension-derived MIME (the extension must still be in the helper's
8
+ * allowlist). `maxBytes` optionally tightens the upload-size cap.
9
+ */
10
+ export interface NodeMediaFromPathBaseInput {
11
+ readonly to: string;
12
+ readonly path: string;
13
+ readonly mimeType?: string;
14
+ readonly replyToMessageId?: string;
15
+ readonly maxBytes?: number;
16
+ }
17
+ export interface NodeImageFromPathInput extends NodeMediaFromPathBaseInput {
18
+ readonly caption?: string;
19
+ }
20
+ export interface NodeVideoFromPathInput extends NodeMediaFromPathBaseInput {
21
+ readonly caption?: string;
22
+ }
23
+ export interface NodeAudioFromPathInput extends NodeMediaFromPathBaseInput {
24
+ /** Graph v24+ voice-message designation for audio sends. */
25
+ readonly voice?: boolean;
26
+ }
27
+ export interface NodeDocumentFromPathInput extends NodeMediaFromPathBaseInput {
28
+ readonly caption?: string;
29
+ readonly filename?: string;
30
+ }
31
+ export type NodeStickerFromPathInput = NodeMediaFromPathBaseInput;
32
+ /**
33
+ * Upload an image file from the local filesystem and send it. Performs
34
+ * exactly two Graph requests (media upload, then message send). Supported
35
+ * extensions: `.jpg`, `.jpeg`, `.png`, `.webp`.
36
+ */
37
+ export declare function uploadAndSendImageFromPath(client: PhoneNumberClient, input: NodeImageFromPathInput, opts?: EndpointInvokeOptions): Promise<GraphMessagesSendResponse>;
38
+ /**
39
+ * Upload a video file from the local filesystem and send it. Performs
40
+ * exactly two Graph requests. Supported extension: `.mp4`.
41
+ */
42
+ export declare function uploadAndSendVideoFromPath(client: PhoneNumberClient, input: NodeVideoFromPathInput, opts?: EndpointInvokeOptions): Promise<GraphMessagesSendResponse>;
43
+ /**
44
+ * Upload an audio file from the local filesystem and send it. Performs
45
+ * exactly two Graph requests. Supported extensions: `.mp3`, `.ogg`, `.m4a`.
46
+ */
47
+ export declare function uploadAndSendAudioFromPath(client: PhoneNumberClient, input: NodeAudioFromPathInput, opts?: EndpointInvokeOptions): Promise<GraphMessagesSendResponse>;
48
+ /**
49
+ * Upload a document file from the local filesystem and send it. Performs
50
+ * exactly two Graph requests. Supported extension: `.pdf`.
51
+ */
52
+ export declare function uploadAndSendDocumentFromPath(client: PhoneNumberClient, input: NodeDocumentFromPathInput, opts?: EndpointInvokeOptions): Promise<GraphMessagesSendResponse>;
53
+ /**
54
+ * Upload a sticker file from the local filesystem and send it. Performs
55
+ * exactly two Graph requests. Supported extension: `.webp`.
56
+ */
57
+ export declare function uploadAndSendStickerFromPath(client: PhoneNumberClient, input: NodeStickerFromPathInput, opts?: EndpointInvokeOptions): Promise<GraphMessagesSendResponse>;
@@ -0,0 +1,178 @@
1
+ import {
2
+ DEFAULT_MAX_MEDIA_UPLOAD_BYTES,
3
+ MediaValidationError
4
+ } from "./endpoints/media.js";
5
+ const IMAGE_EXTENSIONS = new Map([
6
+ ["jpg", "image/jpeg"],
7
+ ["jpeg", "image/jpeg"],
8
+ ["png", "image/png"],
9
+ ["webp", "image/webp"]
10
+ ]);
11
+ const VIDEO_EXTENSIONS = new Map([
12
+ ["mp4", "video/mp4"]
13
+ ]);
14
+ const AUDIO_EXTENSIONS = new Map([
15
+ ["mp3", "audio/mpeg"],
16
+ ["ogg", "audio/ogg"],
17
+ ["m4a", "audio/mp4"]
18
+ ]);
19
+ const DOCUMENT_EXTENSIONS = new Map([
20
+ ["pdf", "application/pdf"]
21
+ ]);
22
+ const STICKER_EXTENSIONS = new Map([
23
+ ["webp", "image/webp"]
24
+ ]);
25
+ const FS_PROMISES_SPECIFIER = "node:fs/promises";
26
+ const PATH_SPECIFIER = "node:path";
27
+ let fsPromisesLoader;
28
+ let pathModuleLoader;
29
+ function loadFsPromises() {
30
+ if (fsPromisesLoader === undefined) {
31
+ fsPromisesLoader = import(FS_PROMISES_SPECIFIER).then((mod) => mod);
32
+ }
33
+ return fsPromisesLoader;
34
+ }
35
+ function loadPathModule() {
36
+ if (pathModuleLoader === undefined) {
37
+ pathModuleLoader = import(PATH_SPECIFIER).then((mod) => mod);
38
+ }
39
+ return pathModuleLoader;
40
+ }
41
+ function hasControlChar(value) {
42
+ for (let i = 0;i < value.length; i += 1) {
43
+ const code = value.charCodeAt(i);
44
+ if (code < 32 || code === 127)
45
+ return true;
46
+ }
47
+ return false;
48
+ }
49
+ function assertPhoneNumberClient(client, method) {
50
+ if (client === null || typeof client !== "object") {
51
+ throw new MediaValidationError("invalid_client", "Invalid client: expected a PhoneNumberClient instance.");
52
+ }
53
+ const fn = client[method];
54
+ if (typeof fn !== "function") {
55
+ throw new MediaValidationError("invalid_client", `Invalid client: expected a PhoneNumberClient with ${method}().`);
56
+ }
57
+ }
58
+ function assertRecipient(input) {
59
+ if (typeof input.to !== "string" || input.to.length === 0 || input.to.trim().length === 0) {
60
+ throw new MediaValidationError("invalid_params", "Invalid recipient: expected a non-empty string.");
61
+ }
62
+ }
63
+ function resolveMaxBytes(input, defaultMaxBytes) {
64
+ const candidate = input.maxBytes;
65
+ if (candidate === undefined)
66
+ return defaultMaxBytes;
67
+ if (typeof candidate !== "number" || !Number.isFinite(candidate) || !Number.isInteger(candidate) || candidate <= 0) {
68
+ throw new MediaValidationError("invalid_params", "Invalid maxBytes: expected a positive integer.");
69
+ }
70
+ return candidate;
71
+ }
72
+ async function resolveMediaFile(input, allowedExtensions, defaultMaxBytes, label) {
73
+ if (typeof input.path !== "string" || input.path.length === 0 || input.path.trim().length === 0) {
74
+ throw new MediaValidationError("invalid_params", "Invalid media path: expected a non-empty string.");
75
+ }
76
+ if (hasControlChar(input.path)) {
77
+ throw new MediaValidationError("invalid_file", "Invalid media path: control characters (including NUL) are not allowed.");
78
+ }
79
+ const segments = input.path.split(/[\\/]/u);
80
+ if (segments.some((segment) => segment === "..")) {
81
+ throw new MediaValidationError("invalid_file", "Invalid media path: parent-directory segments are not allowed.");
82
+ }
83
+ const pathModule = await loadPathModule();
84
+ const ext = pathModule.extname(input.path).toLowerCase().replace(/^\./u, "");
85
+ const inferred = allowedExtensions.get(ext);
86
+ if (inferred === undefined) {
87
+ throw new MediaValidationError("unsupported_media_type", `Unsupported media extension: ${ext.length === 0 ? "<none>" : ext} is not allowed for ${label} sends.`);
88
+ }
89
+ const mimeType = typeof input.mimeType === "string" && input.mimeType.trim().length > 0 ? input.mimeType.trim() : inferred;
90
+ const maxBytes = resolveMaxBytes(input, defaultMaxBytes);
91
+ const fsPromises = await loadFsPromises();
92
+ let info;
93
+ try {
94
+ info = await fsPromises.stat(input.path);
95
+ } catch {
96
+ throw new MediaValidationError("invalid_file", "Media file could not be accessed.");
97
+ }
98
+ if (info.isDirectory()) {
99
+ throw new MediaValidationError("invalid_file", "Invalid media path: expected a regular file, not a directory.");
100
+ }
101
+ if (!info.isFile()) {
102
+ throw new MediaValidationError("invalid_file", "Invalid media path: expected a regular file.");
103
+ }
104
+ if (info.size > maxBytes) {
105
+ throw new MediaValidationError("upload_too_large", "Media file exceeds the maximum upload size.");
106
+ }
107
+ let raw;
108
+ try {
109
+ raw = await fsPromises.readFile(input.path);
110
+ } catch {
111
+ throw new MediaValidationError("invalid_file", "Media file could not be read.");
112
+ }
113
+ if (raw.byteLength > maxBytes) {
114
+ throw new MediaValidationError("upload_too_large", "Media file exceeds the maximum upload size.");
115
+ }
116
+ const bytes = new Uint8Array(raw);
117
+ return { bytes, mimeType };
118
+ }
119
+ export async function uploadAndSendImageFromPath(client, input, opts) {
120
+ assertPhoneNumberClient(client, "uploadAndSendImage");
121
+ assertRecipient(input);
122
+ const { bytes, mimeType } = await resolveMediaFile(input, IMAGE_EXTENSIONS, DEFAULT_MAX_MEDIA_UPLOAD_BYTES, "image");
123
+ return client.uploadAndSendImage({
124
+ to: input.to,
125
+ file: bytes,
126
+ mimeType,
127
+ ...input.caption !== undefined ? { caption: input.caption } : {},
128
+ ...input.replyToMessageId !== undefined ? { replyToMessageId: input.replyToMessageId } : {}
129
+ }, opts);
130
+ }
131
+ export async function uploadAndSendVideoFromPath(client, input, opts) {
132
+ assertPhoneNumberClient(client, "uploadAndSendVideo");
133
+ assertRecipient(input);
134
+ const { bytes, mimeType } = await resolveMediaFile(input, VIDEO_EXTENSIONS, DEFAULT_MAX_MEDIA_UPLOAD_BYTES, "video");
135
+ return client.uploadAndSendVideo({
136
+ to: input.to,
137
+ file: bytes,
138
+ mimeType,
139
+ ...input.caption !== undefined ? { caption: input.caption } : {},
140
+ ...input.replyToMessageId !== undefined ? { replyToMessageId: input.replyToMessageId } : {}
141
+ }, opts);
142
+ }
143
+ export async function uploadAndSendAudioFromPath(client, input, opts) {
144
+ assertPhoneNumberClient(client, "uploadAndSendAudio");
145
+ assertRecipient(input);
146
+ const { bytes, mimeType } = await resolveMediaFile(input, AUDIO_EXTENSIONS, DEFAULT_MAX_MEDIA_UPLOAD_BYTES, "audio");
147
+ return client.uploadAndSendAudio({
148
+ to: input.to,
149
+ file: bytes,
150
+ mimeType,
151
+ ...input.voice !== undefined ? { voice: input.voice } : {},
152
+ ...input.replyToMessageId !== undefined ? { replyToMessageId: input.replyToMessageId } : {}
153
+ }, opts);
154
+ }
155
+ export async function uploadAndSendDocumentFromPath(client, input, opts) {
156
+ assertPhoneNumberClient(client, "uploadAndSendDocument");
157
+ assertRecipient(input);
158
+ const { bytes, mimeType } = await resolveMediaFile(input, DOCUMENT_EXTENSIONS, DEFAULT_MAX_MEDIA_UPLOAD_BYTES, "document");
159
+ return client.uploadAndSendDocument({
160
+ to: input.to,
161
+ file: bytes,
162
+ mimeType,
163
+ ...input.caption !== undefined ? { caption: input.caption } : {},
164
+ ...input.filename !== undefined ? { filename: input.filename } : {},
165
+ ...input.replyToMessageId !== undefined ? { replyToMessageId: input.replyToMessageId } : {}
166
+ }, opts);
167
+ }
168
+ export async function uploadAndSendStickerFromPath(client, input, opts) {
169
+ assertPhoneNumberClient(client, "uploadAndSendSticker");
170
+ assertRecipient(input);
171
+ const { bytes, mimeType } = await resolveMediaFile(input, STICKER_EXTENSIONS, DEFAULT_MAX_MEDIA_UPLOAD_BYTES, "sticker");
172
+ return client.uploadAndSendSticker({
173
+ to: input.to,
174
+ file: bytes,
175
+ mimeType,
176
+ ...input.replyToMessageId !== undefined ? { replyToMessageId: input.replyToMessageId } : {}
177
+ }, opts);
178
+ }
@@ -1,14 +1,44 @@
1
1
  import type { GraphClient } from "../client.js";
2
2
  import type { EndpointInvokeOptions } from "../endpoint.js";
3
3
  import { GroupClient } from "./groupClient.js";
4
- import { type BlockUsersInput, type BlockUsersResponse, type BlockedUsersResponse, type BusinessProfileResponse, type CommerceSettingsResponse, type GetBusinessProfileInput, type GetCommerceSettingsInput, type GetOfficialBusinessAccountStatusInput, type GetPhoneNumberInfoInput, type GetPhoneNumberSettingsInput, type UpdateBusinessProfileInput, type UpdateCommerceSettingsInput, type BusinessProfileUpdateResponse, type CommerceSettingsUpdateResponse, type ListBlockedUsersInput, type OfficialBusinessAccountReviewResponse, type OfficialBusinessAccountStatusResponse, type PhoneNumberInfo, type PhoneNumberSettingsResponse, type PhoneNumberSettingsUpdateResponse, type RequestOfficialBusinessAccountReviewInput, type SubmitDisplayNameForReviewInput, type SubmitDisplayNameForReviewResponse, type UnblockUsersInput, type UnblockUsersResponse, type UpdatePhoneNumberSettingsInput } from "../endpoints/businessManagement.js";
4
+ import { type BlockUsersInput, type BlockUsersResponse, type BlockedUsersResponse, type BusinessProfileResponse, type BusinessPublicKeyResponse, type BusinessPublicKeyUpdateResponse, type CommerceSettingsResponse, type CreateQrCodeInput, type CreateQrCodeResponse, type DeleteQrCodeInput, type DeleteQrCodeResponse, type DeregisterPhoneNumberInput, type DeregisterPhoneNumberResponse, type GetBusinessProfileInput, type GetBusinessPublicKeyInput, type GetCommerceSettingsInput, type GetOfficialBusinessAccountStatusInput, type GetPhoneNumberInfoInput, type GetPhoneNumberSettingsInput, type GetQrCodeInput, type GetQrCodeResponse, type ListQrCodesInput, type ListQrCodesResponse, type OfficialBusinessAccountReviewResponse, type OfficialBusinessAccountStatusResponse, type PhoneNumberInfo, type PhoneNumberSettingsResponse, type PhoneNumberSettingsUpdateResponse, type RegisterPhoneNumberInput, type RegisterPhoneNumberResponse, type RequestVerificationCodeInput, type RequestVerificationCodeResponse, type SetTwoStepVerificationPinInput, type SetTwoStepVerificationPinResponse, type SetBusinessPublicKeyInput, type UpdateBusinessProfileInput, type UpdateCommerceSettingsInput, type BusinessProfileUpdateResponse, type CommerceSettingsUpdateResponse, type ListBlockedUsersInput, type RequestOfficialBusinessAccountReviewInput, type SubmitDisplayNameForReviewInput, type SubmitDisplayNameForReviewResponse, type UnblockUsersInput, type UnblockUsersResponse, type UpdatePhoneNumberSettingsInput, type UpdateQrCodeInput, type UpdateQrCodeResponse, type VerifyPhoneNumberInput, type VerifyPhoneNumberResponse } from "../endpoints/businessManagement.js";
5
5
  import { type AcceptCallRequest, type CallLifecycleResponse, type InitiateCallRequest, type PreAcceptCallRequest, type RejectCallRequest, type TerminateCallRequest } from "../endpoints/calling.js";
6
6
  import { type CreateGroupBody, type GroupMutationResponse, type ListGroupsParams, type ListGroupsResponse } from "../endpoints/groups.js";
7
- import { type GraphMessagesMarkMessageAsReadInput, type GraphMessagesRemoveReactionInput, type GraphMessagesRequestLocationInput, type GraphMessagesSendAudioInput, type GraphMessagesSendBody, type GraphMessagesSendButtonsInput, type GraphMessagesSendCallPermissionRequestInput, type GraphMessagesSendCatalogInput, type GraphMessagesSendContactsInput, type GraphMessagesSendCtaUrlInput, type GraphMessagesSendDocumentInput, type GraphMessagesSendImageInput, type GraphMessagesSendListInput, type GraphMessagesSendLocationInput, type GraphMessagesSendMarketingTemplateInput, type GraphMessagesMarketingTemplateResponse, type GraphMessagesSendProductInput, type GraphMessagesSendProductsInput, type GraphMessagesSendReactionInput, type GraphMessagesSendResponse, type GraphMessagesSendStickerInput, type GraphMessagesSendTemplateInput, type GraphMessagesSendTextInput, type GraphMessagesSendVideoInput, type GraphMessagesTypingIndicatorInput } from "../endpoints/messages.js";
7
+ import { type GraphMessagesMarkMessageAsReadInput, type GraphMessagesRemoveReactionInput, type GraphMessagesRequestLocationInput, type GraphMessagesSendAudioInput, type GraphMessagesSendBody, type GraphMessagesSendButtonsInput, type GraphMessagesSendCallPermissionRequestInput, type GraphMessagesSendCatalogInput, type GraphMessagesSendContactsInput, type GraphMessagesSendCtaUrlInput, type GraphMessagesSendDocumentInput, type GraphMessagesSendImageInput, type GraphMessagesSendListInput, type GraphMessagesSendLocationInput, type GraphMessagesSendMarketingTemplateInput, type GraphMessagesMarketingTemplateResponse, type GraphMessagesSendProductInput, type GraphMessagesSendProductsInput, type GraphMessagesSendReactionInput, type GraphMessagesSendResponse, type GraphMessagesSendStickerInput, type GraphMessagesSendTemplateInput, type GraphMessagesSendTextInput, type GraphMessagesSendVideoInput, type GraphMessagesSendVoiceCallInput, type GraphMessagesTypingIndicatorInput } from "../endpoints/messages.js";
8
8
  export interface PhoneNumberClientConfig {
9
9
  readonly graphClient: GraphClient;
10
10
  readonly phoneNumberId: string;
11
11
  }
12
+ /**
13
+ * WATS-152 slice 1: one-call upload-and-send helpers for in-memory media
14
+ * bodies (`Blob | ArrayBuffer | Uint8Array`). Each helper uploads the body
15
+ * to Graph via `POST /{phoneNumberId}/media` and immediately sends the
16
+ * resulting `media.id` through the corresponding `send*` composer.
17
+ *
18
+ * File-system path support is intentionally deferred to a follow-up slice;
19
+ * `@wats/graph` MUST stay runtime-neutral and never import `node:fs`.
20
+ */
21
+ export interface UploadAndSendMediaBaseInput {
22
+ readonly to: string;
23
+ readonly file: Blob | ArrayBuffer | Uint8Array;
24
+ readonly mimeType: string;
25
+ readonly replyToMessageId?: string;
26
+ }
27
+ export interface UploadAndSendImageInput extends UploadAndSendMediaBaseInput {
28
+ readonly caption?: string;
29
+ }
30
+ export interface UploadAndSendVideoInput extends UploadAndSendMediaBaseInput {
31
+ readonly caption?: string;
32
+ }
33
+ export interface UploadAndSendAudioInput extends UploadAndSendMediaBaseInput {
34
+ /** Graph v24+ voice-message designation for audio sends. */
35
+ readonly voice?: boolean;
36
+ }
37
+ export interface UploadAndSendDocumentInput extends UploadAndSendMediaBaseInput {
38
+ readonly caption?: string;
39
+ readonly filename?: string;
40
+ }
41
+ export type UploadAndSendStickerInput = UploadAndSendMediaBaseInput;
12
42
  export declare function validatePhoneNumberClientConfig(config: PhoneNumberClientConfig): void;
13
43
  export declare class PhoneNumberClient {
14
44
  #private;
@@ -29,6 +59,19 @@ export declare class PhoneNumberClient {
29
59
  updateSettings(params: Omit<UpdatePhoneNumberSettingsInput, "phoneNumberId">, opts?: EndpointInvokeOptions): Promise<PhoneNumberSettingsUpdateResponse>;
30
60
  /** Graph `GET /{phoneNumberId}/whatsapp_business_profile`. */
31
61
  getBusinessProfile(params?: Omit<GetBusinessProfileInput, "phoneNumberId">, opts?: EndpointInvokeOptions): Promise<BusinessProfileResponse>;
62
+ /**
63
+ * Graph `GET /{phoneNumberId}/whatsapp_business_encryption`.
64
+ *
65
+ * NOTE: the GET response shape is UNVERIFIED live (pywa has no getter); the
66
+ * returned `BusinessPublicKeyResponse` is shape-only with tolerant indexing.
67
+ */
68
+ getBusinessPublicKey(params?: Omit<GetBusinessPublicKeyInput, "phoneNumberId">, opts?: EndpointInvokeOptions): Promise<BusinessPublicKeyResponse>;
69
+ /**
70
+ * Graph `POST /{phoneNumberId}/whatsapp_business_encryption` — sets the
71
+ * business public key. The body is form-encoded
72
+ * (`business_public_key=<PEM>`) to match pywa's proven wire contract.
73
+ */
74
+ setBusinessPublicKey(params: Omit<SetBusinessPublicKeyInput, "phoneNumberId">, opts?: EndpointInvokeOptions): Promise<BusinessPublicKeyUpdateResponse>;
32
75
  /** Graph `GET /{phoneNumberId}/whatsapp_commerce_settings`. */
33
76
  getCommerceSettings(params?: Omit<GetCommerceSettingsInput, "phoneNumberId">, opts?: EndpointInvokeOptions): Promise<CommerceSettingsResponse>;
34
77
  /** Graph `POST /{phoneNumberId}/whatsapp_business_profile`. */
@@ -47,6 +90,47 @@ export declare class PhoneNumberClient {
47
90
  requestOfficialBusinessAccountReview(params: Omit<RequestOfficialBusinessAccountReviewInput, "phoneNumberId">, opts?: EndpointInvokeOptions): Promise<OfficialBusinessAccountReviewResponse>;
48
91
  /** Graph `POST /{phoneNumberId}` with Graph `new_display_name`. */
49
92
  submitDisplayNameForReview(params: Omit<SubmitDisplayNameForReviewInput, "phoneNumberId">, opts?: EndpointInvokeOptions): Promise<SubmitDisplayNameForReviewResponse>;
93
+ /** Graph `POST /{phoneNumberId}/request_code?code_method=...&language=...` (WATS-155). */
94
+ requestVerificationCode(params: Omit<RequestVerificationCodeInput, "phoneNumberId">, opts?: EndpointInvokeOptions): Promise<RequestVerificationCodeResponse>;
95
+ /** Graph `POST /{phoneNumberId}/verify_code?code=...` (WATS-155). */
96
+ verifyPhoneNumber(params: Omit<VerifyPhoneNumberInput, "phoneNumberId">, opts?: EndpointInvokeOptions): Promise<VerifyPhoneNumberResponse>;
97
+ /** Graph `POST /{phoneNumberId}/register` (WATS-155). */
98
+ registerPhoneNumber(params: Omit<RegisterPhoneNumberInput, "phoneNumberId">, opts?: EndpointInvokeOptions): Promise<RegisterPhoneNumberResponse>;
99
+ /** Graph `POST /{phoneNumberId}/deregister` (WATS-155). */
100
+ deregisterPhoneNumber(params?: Omit<DeregisterPhoneNumberInput, "phoneNumberId">, opts?: EndpointInvokeOptions): Promise<DeregisterPhoneNumberResponse>;
101
+ /** Graph `POST /{phoneNumberId}` with Graph `two_step_verification.pin` (WATS-155). */
102
+ setTwoStepVerificationPin(params: Omit<SetTwoStepVerificationPinInput, "phoneNumberId">, opts?: EndpointInvokeOptions): Promise<SetTwoStepVerificationPinResponse>;
103
+ /**
104
+ * Graph `POST /{phoneNumberId}/message_qrdls` (WATS-156) — creates a QR
105
+ * code / short link with a prefilled message and image format. The bound
106
+ * phoneNumberId is injected and wins over any caller-supplied value.
107
+ */
108
+ createQrCode(params: Omit<CreateQrCodeInput, "phoneNumberId">, opts?: EndpointInvokeOptions): Promise<CreateQrCodeResponse>;
109
+ /**
110
+ * Graph `GET /{phoneNumberId}/message_qrdls` (WATS-156) — lists all QR
111
+ * codes / short links for the bound phone number. Supports optional
112
+ * `fields` and cursor pagination (`before` / `after`).
113
+ */
114
+ listQrCodes(params?: Omit<ListQrCodesInput, "phoneNumberId">, opts?: EndpointInvokeOptions): Promise<ListQrCodesResponse>;
115
+ /**
116
+ * Graph `GET /{phoneNumberId}/message_qrdls/{code}` (WATS-156) — gets a
117
+ * single QR code / short link by code. The bound phoneNumberId is
118
+ * injected; `code` and optional `fields` come from the caller.
119
+ */
120
+ getQrCode(params: Omit<GetQrCodeInput, "phoneNumberId">, opts?: EndpointInvokeOptions): Promise<GetQrCodeResponse>;
121
+ /**
122
+ * Graph `POST /{phoneNumberId}/message_qrdls` (WATS-156) — updates an
123
+ * existing QR code's prefilled message. Same path as create but body
124
+ * carries the existing `code` plus the new `prefilledMessage`. The bound
125
+ * phoneNumberId is injected.
126
+ */
127
+ updateQrCode(params: Omit<UpdateQrCodeInput, "phoneNumberId">, opts?: EndpointInvokeOptions): Promise<UpdateQrCodeResponse>;
128
+ /**
129
+ * Graph `DELETE /{phoneNumberId}/message_qrdls/{code}` (WATS-156) —
130
+ * deletes a QR code / short link by code. The bound phoneNumberId is
131
+ * injected; `code` comes from the caller.
132
+ */
133
+ deleteQrCode(params: Omit<DeleteQrCodeInput, "phoneNumberId">, opts?: EndpointInvokeOptions): Promise<DeleteQrCodeResponse>;
50
134
  /**
51
135
  * Graph `POST /{phoneNumberId}/messages` — delegates to the F-6
52
136
  * endpoint-registry `sendMessage` callable with the bound
@@ -63,6 +147,7 @@ export declare class PhoneNumberClient {
63
147
  sendVideo(input: GraphMessagesSendVideoInput, opts?: EndpointInvokeOptions): Promise<GraphMessagesSendResponse>;
64
148
  sendAudio(input: GraphMessagesSendAudioInput, opts?: EndpointInvokeOptions): Promise<GraphMessagesSendResponse>;
65
149
  sendCallPermissionRequest(input: GraphMessagesSendCallPermissionRequestInput, opts?: EndpointInvokeOptions): Promise<GraphMessagesSendResponse>;
150
+ sendVoiceCall(input: GraphMessagesSendVoiceCallInput, opts?: EndpointInvokeOptions): Promise<GraphMessagesSendResponse>;
66
151
  sendDocument(input: GraphMessagesSendDocumentInput, opts?: EndpointInvokeOptions): Promise<GraphMessagesSendResponse>;
67
152
  sendSticker(input: GraphMessagesSendStickerInput, opts?: EndpointInvokeOptions): Promise<GraphMessagesSendResponse>;
68
153
  sendLocation(input: GraphMessagesSendLocationInput, opts?: EndpointInvokeOptions): Promise<GraphMessagesSendResponse>;
@@ -85,4 +170,9 @@ export declare class PhoneNumberClient {
85
170
  acceptCall(input: AcceptCallRequest, opts?: EndpointInvokeOptions): Promise<CallLifecycleResponse>;
86
171
  rejectCall(input: RejectCallRequest, opts?: EndpointInvokeOptions): Promise<CallLifecycleResponse>;
87
172
  terminateCall(input: TerminateCallRequest, opts?: EndpointInvokeOptions): Promise<CallLifecycleResponse>;
173
+ uploadAndSendImage(input: UploadAndSendImageInput, opts?: EndpointInvokeOptions): Promise<GraphMessagesSendResponse>;
174
+ uploadAndSendVideo(input: UploadAndSendVideoInput, opts?: EndpointInvokeOptions): Promise<GraphMessagesSendResponse>;
175
+ uploadAndSendAudio(input: UploadAndSendAudioInput, opts?: EndpointInvokeOptions): Promise<GraphMessagesSendResponse>;
176
+ uploadAndSendDocument(input: UploadAndSendDocumentInput, opts?: EndpointInvokeOptions): Promise<GraphMessagesSendResponse>;
177
+ uploadAndSendSticker(input: UploadAndSendStickerInput, opts?: EndpointInvokeOptions): Promise<GraphMessagesSendResponse>;
88
178
  }