@wats/graph 0.3.21 → 0.3.23

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.
@@ -85,6 +85,29 @@ export interface CommerceSettingsResponse {
85
85
  readonly paging?: GraphPaging;
86
86
  readonly [key: string]: unknown;
87
87
  }
88
+ export interface BusinessProfileUpdateResponse {
89
+ readonly success?: boolean;
90
+ readonly [key: string]: unknown;
91
+ }
92
+ export interface CommerceSettingsUpdateResponse {
93
+ readonly success?: boolean;
94
+ readonly [key: string]: unknown;
95
+ }
96
+ export interface UpdateBusinessProfileInput {
97
+ readonly phoneNumberId: string;
98
+ readonly about?: string;
99
+ readonly address?: string;
100
+ readonly description?: string;
101
+ readonly email?: string;
102
+ readonly vertical?: string;
103
+ readonly websites?: readonly string[];
104
+ readonly profilePictureHandle?: string;
105
+ }
106
+ export interface UpdateCommerceSettingsInput {
107
+ readonly phoneNumberId: string;
108
+ readonly isCartEnabled?: boolean;
109
+ readonly isCatalogVisible?: boolean;
110
+ }
88
111
  export interface GetWabaInfoInput {
89
112
  readonly wabaId: string;
90
113
  readonly fields?: BusinessManagementFields;
@@ -225,6 +248,10 @@ export declare function buildDisplayNameReviewBody(input: SubmitDisplayNameForRe
225
248
  export declare function normalizeDisplayNameReviewParams(input: SubmitDisplayNameForReviewInput): WireParams;
226
249
  export declare function normalizeBusinessProfileParams(input: GetBusinessProfileInput): WireParams;
227
250
  export declare function normalizeCommerceSettingsParams(input: GetCommerceSettingsInput): WireParams;
251
+ export declare function buildUpdateBusinessProfileBody(input: UpdateBusinessProfileInput): Record<string, unknown>;
252
+ export declare function normalizeUpdateBusinessProfileParams(input: UpdateBusinessProfileInput): WireParams;
253
+ export declare function buildUpdateCommerceSettingsBody(input: UpdateCommerceSettingsInput): Record<string, unknown>;
254
+ export declare function normalizeUpdateCommerceSettingsParams(input: UpdateCommerceSettingsInput): WireParams;
228
255
  export declare function sanitizeBusinessManagementOptions(opts: EndpointInvokeOptions | undefined, helperName: string): EndpointInvokeOptions | undefined;
229
256
  export declare const getWabaInfo: ((client: GraphClient, params: GetWabaInfoInput, body?: never, opts?: EndpointInvokeOptions) => Promise<WabaInfo>) & {
230
257
  definition: import("../endpoint.js").EndpointDefinition<{
@@ -298,4 +325,14 @@ export declare const getCommerceSettings: ((client: GraphClient, params: GetComm
298
325
  fields?: string;
299
326
  }, never, CommerceSettingsResponse>;
300
327
  };
328
+ export declare const updateBusinessProfile: ((client: GraphClient, params: UpdateBusinessProfileInput, body?: never, opts?: EndpointInvokeOptions) => Promise<BusinessProfileUpdateResponse>) & {
329
+ definition: import("../endpoint.js").EndpointDefinition<{
330
+ phoneNumberId: string;
331
+ }, UpdateBusinessProfileInput, BusinessProfileUpdateResponse>;
332
+ };
333
+ export declare const updateCommerceSettings: ((client: GraphClient, params: UpdateCommerceSettingsInput, body?: never, opts?: EndpointInvokeOptions) => Promise<CommerceSettingsUpdateResponse>) & {
334
+ definition: import("../endpoint.js").EndpointDefinition<{
335
+ phoneNumberId: string;
336
+ }, UpdateCommerceSettingsInput, CommerceSettingsUpdateResponse>;
337
+ };
301
338
  export {};
@@ -25,6 +25,11 @@ const MAX_OBA_TEXT_LENGTH = 2048;
25
25
  const MAX_OBA_URL_LENGTH = 2048;
26
26
  const MAX_OBA_SUPPORTING_LINKS = 10;
27
27
  const MIN_OBA_SUPPORTING_LINKS = 5;
28
+ const MAX_BUSINESS_PROFILE_TEXT_LENGTH = 1024;
29
+ const MAX_BUSINESS_PROFILE_EMAIL_LENGTH = 320;
30
+ const MAX_BUSINESS_PROFILE_WEBSITES = 2;
31
+ const MAX_BUSINESS_PROFILE_WEBSITE_LENGTH = 2048;
32
+ const MAX_PROFILE_PICTURE_HANDLE_LENGTH = 1024;
28
33
  function validationError(message, cause) {
29
34
  return new GraphRequestValidationError(message, cause);
30
35
  }
@@ -382,6 +387,93 @@ export function normalizeCommerceSettingsParams(input) {
382
387
  out.fields = fields;
383
388
  return out;
384
389
  }
390
+ function optionalBusinessProfileString(record, key, helperName, maxLength = MAX_BUSINESS_PROFILE_TEXT_LENGTH) {
391
+ const value = ownDataValue(record, key, helperName, false);
392
+ if (value === undefined)
393
+ return;
394
+ return assertBoundedPlainString(value, key, helperName, maxLength);
395
+ }
396
+ function optionalBusinessProfileWebsites(record, helperName) {
397
+ const value = ownDataValue(record, "websites", helperName, false);
398
+ if (value === undefined)
399
+ return;
400
+ const items = assertDenseDataArray(value, {
401
+ helperName,
402
+ path: "websites",
403
+ minLength: 1,
404
+ maxLength: MAX_BUSINESS_PROFILE_WEBSITES,
405
+ invalidTypeMessage: `Invalid ${helperName} input: websites must be an array of http(s) URLs.`,
406
+ invalidLengthMessage: `Invalid ${helperName} input: websites length must be between 1 and ${MAX_BUSINESS_PROFILE_WEBSITES}.`,
407
+ sparseArrayMessage: `Invalid ${helperName} input: websites must not contain sparse array holes.`,
408
+ unsafePrototypeKeyMessage: `Invalid ${helperName} input: websites contains an unsafe prototype key.`,
409
+ unsupportedPropertyMessage: `Invalid ${helperName} input: websites contains unsupported properties.`
410
+ });
411
+ return items.map((item, index) => assertHttpUrl(item, `websites[${index}]`, helperName));
412
+ }
413
+ function optionalBoolean(record, key, helperName) {
414
+ const value = ownDataValue(record, key, helperName, false);
415
+ if (value === undefined)
416
+ return;
417
+ if (typeof value !== "boolean") {
418
+ throw validationError(`Invalid ${helperName} input: ${String(key)} must be boolean when provided.`);
419
+ }
420
+ return value;
421
+ }
422
+ export function buildUpdateBusinessProfileBody(input) {
423
+ const helperName = "updateBusinessProfile";
424
+ const record = assertPlainRecord(input, "updateBusinessProfile");
425
+ const out = { messaging_product: "whatsapp" };
426
+ const about = optionalBusinessProfileString(record, "about", "updateBusinessProfile");
427
+ const address = optionalBusinessProfileString(record, "address", "updateBusinessProfile");
428
+ const description = optionalBusinessProfileString(record, "description", "updateBusinessProfile");
429
+ const email = optionalBusinessProfileString(record, "email", "updateBusinessProfile", MAX_BUSINESS_PROFILE_EMAIL_LENGTH);
430
+ const vertical = optionalBusinessProfileString(record, "vertical", "updateBusinessProfile", 128);
431
+ const websites = optionalBusinessProfileWebsites(record, "updateBusinessProfile");
432
+ const profilePictureHandle = optionalBusinessProfileString(record, "profilePictureHandle", "updateBusinessProfile", MAX_PROFILE_PICTURE_HANDLE_LENGTH);
433
+ if (about !== undefined)
434
+ out.about = about;
435
+ if (address !== undefined)
436
+ out.address = address;
437
+ if (description !== undefined)
438
+ out.description = description;
439
+ if (email !== undefined)
440
+ out.email = email;
441
+ if (vertical !== undefined)
442
+ out.vertical = vertical;
443
+ if (websites !== undefined)
444
+ out.websites = websites;
445
+ if (profilePictureHandle !== undefined)
446
+ out.profile_picture_handle = profilePictureHandle;
447
+ if (Object.keys(out).length === 1) {
448
+ throw validationError("Invalid updateBusinessProfile input: at least one profile field is required.");
449
+ }
450
+ return out;
451
+ }
452
+ export function normalizeUpdateBusinessProfileParams(input) {
453
+ const helperName = "updateBusinessProfile";
454
+ const record = assertPlainRecord(input, "updateBusinessProfile");
455
+ return { phoneNumberId: assertPathId(ownDataValue(record, "phoneNumberId", "updateBusinessProfile", true), "phoneNumberId", "updateBusinessProfile") };
456
+ }
457
+ export function buildUpdateCommerceSettingsBody(input) {
458
+ const helperName = "updateCommerceSettings";
459
+ const record = assertPlainRecord(input, "updateCommerceSettings");
460
+ const out = {};
461
+ const isCartEnabled = optionalBoolean(record, "isCartEnabled", "updateCommerceSettings");
462
+ const isCatalogVisible = optionalBoolean(record, "isCatalogVisible", "updateCommerceSettings");
463
+ if (isCartEnabled !== undefined)
464
+ out.is_cart_enabled = isCartEnabled;
465
+ if (isCatalogVisible !== undefined)
466
+ out.is_catalog_visible = isCatalogVisible;
467
+ if (Object.keys(out).length === 0) {
468
+ throw validationError("Invalid updateCommerceSettings input: at least one commerce setting is required.");
469
+ }
470
+ return out;
471
+ }
472
+ export function normalizeUpdateCommerceSettingsParams(input) {
473
+ const helperName = "updateCommerceSettings";
474
+ const record = assertPlainRecord(input, "updateCommerceSettings");
475
+ return { phoneNumberId: assertPathId(ownDataValue(record, "phoneNumberId", "updateCommerceSettings", true), "phoneNumberId", "updateCommerceSettings") };
476
+ }
385
477
  function sanitizeHeaders(headers, helperName) {
386
478
  return sanitizeHeaderInit(headers, {
387
479
  helperName,
@@ -495,6 +587,20 @@ const getCommerceSettingsRaw = defineEndpoint({
495
587
  pathTemplate: "/{phoneNumberId}/whatsapp_commerce_settings",
496
588
  params: { phoneNumberId: { in: "path", required: true }, fields: { in: "query" } }
497
589
  });
590
+ const updateBusinessProfileRaw = defineEndpoint({
591
+ method: "POST",
592
+ pathTemplate: "/{phoneNumberId}/whatsapp_business_profile",
593
+ params: { phoneNumberId: { in: "path", required: true } },
594
+ bodyContentType: "application/json",
595
+ buildBody: buildUpdateBusinessProfileBody
596
+ });
597
+ const updateCommerceSettingsRaw = defineEndpoint({
598
+ method: "POST",
599
+ pathTemplate: "/{phoneNumberId}/whatsapp_commerce_settings",
600
+ params: { phoneNumberId: { in: "path", required: true } },
601
+ bodyContentType: "application/json",
602
+ buildBody: buildUpdateCommerceSettingsBody
603
+ });
498
604
  export const getWabaInfo = Object.assign(async function getWabaInfo(client, params, body, opts) {
499
605
  assertNoBody(body, "getWabaInfo");
500
606
  return getWabaInfoRaw(client, normalizeWabaInfoParams(params), undefined, sanitizeBusinessManagementOptions(opts, "getWabaInfo"));
@@ -547,3 +653,11 @@ export const getCommerceSettings = Object.assign(async function getCommerceSetti
547
653
  assertNoBody(body, "getCommerceSettings");
548
654
  return getCommerceSettingsRaw(client, normalizeCommerceSettingsParams(params), undefined, sanitizeBusinessManagementOptions(opts, "getCommerceSettings"));
549
655
  }, { definition: getCommerceSettingsRaw.definition });
656
+ export const updateBusinessProfile = Object.assign(async function updateBusinessProfile(client, params, body, opts) {
657
+ assertNoBody(body, "updateBusinessProfile");
658
+ return updateBusinessProfileRaw(client, normalizeUpdateBusinessProfileParams(params), params, sanitizeBusinessManagementOptions(opts, "updateBusinessProfile"));
659
+ }, { definition: updateBusinessProfileRaw.definition });
660
+ export const updateCommerceSettings = Object.assign(async function updateCommerceSettings(client, params, body, opts) {
661
+ assertNoBody(body, "updateCommerceSettings");
662
+ return updateCommerceSettingsRaw(client, normalizeUpdateCommerceSettingsParams(params), params, sanitizeBusinessManagementOptions(opts, "updateCommerceSettings"));
663
+ }, { definition: updateCommerceSettingsRaw.definition });
@@ -1,7 +1,7 @@
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 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 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";
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
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";
@@ -31,6 +31,10 @@ export declare class PhoneNumberClient {
31
31
  getBusinessProfile(params?: Omit<GetBusinessProfileInput, "phoneNumberId">, opts?: EndpointInvokeOptions): Promise<BusinessProfileResponse>;
32
32
  /** Graph `GET /{phoneNumberId}/whatsapp_commerce_settings`. */
33
33
  getCommerceSettings(params?: Omit<GetCommerceSettingsInput, "phoneNumberId">, opts?: EndpointInvokeOptions): Promise<CommerceSettingsResponse>;
34
+ /** Graph `POST /{phoneNumberId}/whatsapp_business_profile`. */
35
+ updateBusinessProfile(params: Omit<UpdateBusinessProfileInput, "phoneNumberId">, opts?: EndpointInvokeOptions): Promise<BusinessProfileUpdateResponse>;
36
+ /** Graph `POST /{phoneNumberId}/whatsapp_commerce_settings`. */
37
+ updateCommerceSettings(params: Omit<UpdateCommerceSettingsInput, "phoneNumberId">, opts?: EndpointInvokeOptions): Promise<CommerceSettingsUpdateResponse>;
34
38
  /** Graph `GET /{phoneNumberId}/block_users`. */
35
39
  listBlockedUsers(params?: Omit<ListBlockedUsersInput, "phoneNumberId">, opts?: EndpointInvokeOptions): Promise<BlockedUsersResponse>;
36
40
  /** Graph `POST /{phoneNumberId}/block_users`. */
@@ -50,6 +50,16 @@ export class PhoneNumberClient {
50
50
  scopedParams.phoneNumberId = this.#phoneNumberId;
51
51
  return getCommerceSettingsEndpoint(this.#graphClient, scopedParams, undefined, opts);
52
52
  }
53
+ async updateBusinessProfile(params, opts) {
54
+ const scopedParams = copyOptionalParamsObject(params, "PhoneNumberClient.updateBusinessProfile");
55
+ scopedParams.phoneNumberId = this.#phoneNumberId;
56
+ return updateBusinessProfileEndpoint(this.#graphClient, scopedParams, undefined, opts);
57
+ }
58
+ async updateCommerceSettings(params, opts) {
59
+ const scopedParams = copyOptionalParamsObject(params, "PhoneNumberClient.updateCommerceSettings");
60
+ scopedParams.phoneNumberId = this.#phoneNumberId;
61
+ return updateCommerceSettingsEndpoint(this.#graphClient, scopedParams, undefined, opts);
62
+ }
53
63
  async listBlockedUsers(params, opts) {
54
64
  copyOptionalParamsObject(params, "PhoneNumberClient.listBlockedUsers");
55
65
  return listBlockedUsersEndpoint(this.#graphClient, { phoneNumberId: this.#phoneNumberId }, undefined, opts);
@@ -193,6 +203,8 @@ import { GroupClient } from "./groupClient.js";
193
203
  import {
194
204
  getBusinessProfile as getBusinessProfileEndpoint,
195
205
  getCommerceSettings as getCommerceSettingsEndpoint,
206
+ updateBusinessProfile as updateBusinessProfileEndpoint,
207
+ updateCommerceSettings as updateCommerceSettingsEndpoint,
196
208
  getPhoneNumberInfo as getPhoneNumberInfoEndpoint,
197
209
  getPhoneNumberSettings as getPhoneNumberSettingsEndpoint,
198
210
  updatePhoneNumberSettings as updatePhoneNumberSettingsEndpoint,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wats/graph",
3
- "version": "0.3.21",
3
+ "version": "0.3.23",
4
4
  "private": false,
5
5
  "license": "MIT",
6
6
  "type": "module",