meta-cloud-api 0.1.22 → 0.1.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.
- package/LICENSE +21 -0
- package/README.md +210 -140
- package/dist/api/base.d.mts +1 -1
- package/dist/api/base.d.ts +1 -1
- package/dist/api/businessProfile.d.mts +1 -1
- package/dist/api/businessProfile.d.ts +1 -1
- package/dist/api/businessProfile.js +1 -1
- package/dist/api/encryption.d.mts +1 -1
- package/dist/api/encryption.d.ts +1 -1
- package/dist/api/flow.d.mts +1 -1
- package/dist/api/flow.d.ts +1 -1
- package/dist/api/flow.js +1 -1
- package/dist/api/flow.mjs +1 -1
- package/dist/api/index.d.mts +1 -1
- package/dist/api/index.d.ts +1 -1
- package/dist/api/index.js +1 -1
- package/dist/api/index.mjs +1 -1
- package/dist/api/media.d.mts +1 -1
- package/dist/api/media.d.ts +1 -1
- package/dist/api/media.js +1 -1
- package/dist/api/messages.d.mts +1 -1
- package/dist/api/messages.d.ts +1 -1
- package/dist/api/phoneNumber.d.mts +1 -1
- package/dist/api/phoneNumber.d.ts +1 -1
- package/dist/api/phoneNumber.js +1 -1
- package/dist/api/phoneNumber.mjs +1 -1
- package/dist/api/qrCode.d.mts +1 -1
- package/dist/api/qrCode.d.ts +1 -1
- package/dist/api/qrCode.js +1 -1
- package/dist/api/qrCode.mjs +1 -1
- package/dist/api/registration.d.mts +1 -1
- package/dist/api/registration.d.ts +1 -1
- package/dist/api/template.d.mts +1 -1
- package/dist/api/template.d.ts +1 -1
- package/dist/api/template.js +1 -1
- package/dist/api/template.mjs +1 -1
- package/dist/api/twoStepVerification.d.mts +1 -1
- package/dist/api/twoStepVerification.d.ts +1 -1
- package/dist/api/twoStepVerification.js +1 -1
- package/dist/api/twoStepVerification.mjs +1 -1
- package/dist/api/waba.d.mts +1 -1
- package/dist/api/waba.d.ts +1 -1
- package/dist/api/waba.js +1 -1
- package/dist/api/waba.mjs +1 -1
- package/dist/{enums-BYfW0iLO.d.mts → enums-Bcd3jLw2.d.mts} +0 -1
- package/dist/{enums-BYfW0iLO.d.ts → enums-Bcd3jLw2.d.ts} +0 -1
- package/dist/httpsClient.d.mts +1 -1
- package/dist/httpsClient.d.ts +1 -1
- package/dist/index.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1 -1
- package/dist/index.mjs.map +1 -1
- package/dist/request.d.mts +2 -2
- package/dist/request.d.ts +2 -2
- package/dist/request.js +1 -1
- package/dist/request.js.map +1 -1
- package/dist/request.mjs +1 -1
- package/dist/request.mjs.map +1 -1
- package/dist/types/base.d.mts +1 -1
- package/dist/types/base.d.ts +1 -1
- package/dist/types/businessProfile.d.mts +1 -1
- package/dist/types/businessProfile.d.ts +1 -1
- package/dist/types/config.d.mts +1 -6
- package/dist/types/config.d.ts +1 -6
- package/dist/types/config.js.map +1 -1
- package/dist/types/encryption.d.mts +1 -1
- package/dist/types/encryption.d.ts +1 -1
- package/dist/types/enums.d.mts +1 -1
- package/dist/types/enums.d.ts +1 -1
- package/dist/types/enums.js +1 -1
- package/dist/types/enums.js.map +1 -1
- package/dist/types/enums.mjs +1 -1
- package/dist/types/enums.mjs.map +1 -1
- package/dist/types/flow.d.mts +1 -1
- package/dist/types/flow.d.ts +1 -1
- package/dist/types/httpsClient.d.mts +1 -1
- package/dist/types/httpsClient.d.ts +1 -1
- package/dist/types/index.d.mts +1 -1
- package/dist/types/index.d.ts +1 -1
- package/dist/types/index.js +1 -1
- package/dist/types/index.js.map +1 -1
- package/dist/types/index.mjs +1 -1
- package/dist/types/index.mjs.map +1 -1
- package/dist/types/media.d.mts +1 -1
- package/dist/types/media.d.ts +1 -1
- package/dist/types/messages.d.mts +1 -1
- package/dist/types/messages.d.ts +1 -1
- package/dist/types/phoneNumber.d.mts +1 -1
- package/dist/types/phoneNumber.d.ts +1 -1
- package/dist/types/qrCode.d.mts +1 -1
- package/dist/types/qrCode.d.ts +1 -1
- package/dist/types/registration.d.mts +1 -1
- package/dist/types/registration.d.ts +1 -1
- package/dist/types/request.d.mts +2 -2
- package/dist/types/request.d.ts +2 -2
- package/dist/types/request.js.map +1 -1
- package/dist/types/template.d.mts +1 -1
- package/dist/types/template.d.ts +1 -1
- package/dist/types/twoStepVerification.d.mts +1 -1
- package/dist/types/twoStepVerification.d.ts +1 -1
- package/dist/types/waba.d.mts +1 -1
- package/dist/types/waba.d.ts +1 -1
- package/dist/types/webhook.d.mts +1 -1
- package/dist/types/webhook.d.ts +1 -1
- package/dist/types/whatsapp.d.mts +1 -2
- package/dist/types/whatsapp.d.ts +1 -2
- package/dist/types/whatsapp.js.map +1 -1
- package/dist/utils/filters.d.mts +1 -1
- package/dist/utils/filters.d.ts +1 -1
- package/dist/utils/importConfig.d.mts +1 -1
- package/dist/utils/importConfig.d.ts +1 -1
- package/dist/utils/importConfig.js +1 -1
- package/dist/utils/importConfig.js.map +1 -1
- package/dist/utils/importConfig.mjs +1 -1
- package/dist/utils/importConfig.mjs.map +1 -1
- package/dist/utils/index.d.mts +1 -1
- package/dist/utils/index.d.ts +1 -1
- package/dist/utils/index.js +1 -1
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/index.mjs +1 -1
- package/dist/utils/index.mjs.map +1 -1
- package/dist/webhook.d.mts +1 -1
- package/dist/webhook.d.ts +1 -1
- package/dist/webhook.js +1 -1
- package/dist/webhook.js.map +1 -1
- package/dist/webhook.mjs +1 -1
- package/dist/webhook.mjs.map +1 -1
- package/dist/whatsapp.d.mts +1 -1
- package/dist/whatsapp.d.ts +1 -1
- package/dist/whatsapp.js +1 -1
- package/dist/whatsapp.js.map +1 -1
- package/dist/whatsapp.mjs +1 -1
- package/dist/whatsapp.mjs.map +1 -1
- package/package.json +1 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { BaseClass } from './base.mjs';
|
|
2
|
-
import { I as InteractiveTypesEnum, b as ComponentTypesEnum, L as LanguagesEnum, P as ParametersTypesEnum, i as CurrencyCodesEnum, B as ButtonTypesEnum, a as ButtonPositionEnum, M as MessageTypesEnum } from '../enums-
|
|
2
|
+
import { I as InteractiveTypesEnum, b as ComponentTypesEnum, L as LanguagesEnum, P as ParametersTypesEnum, i as CurrencyCodesEnum, B as ButtonTypesEnum, a as ButtonPositionEnum, M as MessageTypesEnum } from '../enums-Bcd3jLw2.mjs';
|
|
3
3
|
import { GeneralRequestBody } from './request.mjs';
|
|
4
4
|
import './config.mjs';
|
|
5
5
|
|
package/dist/types/messages.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { BaseClass } from './base.js';
|
|
2
|
-
import { I as InteractiveTypesEnum, b as ComponentTypesEnum, L as LanguagesEnum, P as ParametersTypesEnum, i as CurrencyCodesEnum, B as ButtonTypesEnum, a as ButtonPositionEnum, M as MessageTypesEnum } from '../enums-
|
|
2
|
+
import { I as InteractiveTypesEnum, b as ComponentTypesEnum, L as LanguagesEnum, P as ParametersTypesEnum, i as CurrencyCodesEnum, B as ButtonTypesEnum, a as ButtonPositionEnum, M as MessageTypesEnum } from '../enums-Bcd3jLw2.js';
|
|
3
3
|
import { GeneralRequestBody } from './request.js';
|
|
4
4
|
import './config.js';
|
|
5
5
|
|
package/dist/types/qrCode.d.mts
CHANGED
package/dist/types/qrCode.d.ts
CHANGED
package/dist/types/request.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { H as HttpMethodsEnum } from '../enums-
|
|
1
|
+
import { H as HttpMethodsEnum } from '../enums-Bcd3jLw2.mjs';
|
|
2
2
|
|
|
3
3
|
type GeneralRequestBody = Record<string, unknown>;
|
|
4
4
|
interface GeneralHeaderInterface {
|
|
@@ -40,7 +40,7 @@ interface Paging {
|
|
|
40
40
|
next: string;
|
|
41
41
|
}
|
|
42
42
|
declare class RequesterClass {
|
|
43
|
-
constructor(
|
|
43
|
+
constructor(apiVersion: string, phoneNumberId: number, accessToken: string, businessAcctId: string, userAgent: string);
|
|
44
44
|
sendRequest: (method: HttpMethodsEnum, path: string, timeout: number, body?: GeneralRequestBody, contentType?: string, additionalHeaders?: Record<string, string>) => Promise<RequesterResponseInterface<unknown>>;
|
|
45
45
|
getJson<T>(method: HttpMethodsEnum, endpoint: string, timeout: number, body?: GeneralRequestBody, additionalHeaders?: Record<string, string>): Promise<T>;
|
|
46
46
|
sendFormData<T>(method: HttpMethodsEnum, endpoint: string, timeout: number, formData: FormData, additionalHeaders?: Record<string, string>): Promise<T>;
|
package/dist/types/request.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { H as HttpMethodsEnum } from '../enums-
|
|
1
|
+
import { H as HttpMethodsEnum } from '../enums-Bcd3jLw2.js';
|
|
2
2
|
|
|
3
3
|
type GeneralRequestBody = Record<string, unknown>;
|
|
4
4
|
interface GeneralHeaderInterface {
|
|
@@ -40,7 +40,7 @@ interface Paging {
|
|
|
40
40
|
next: string;
|
|
41
41
|
}
|
|
42
42
|
declare class RequesterClass {
|
|
43
|
-
constructor(
|
|
43
|
+
constructor(apiVersion: string, phoneNumberId: number, accessToken: string, businessAcctId: string, userAgent: string);
|
|
44
44
|
sendRequest: (method: HttpMethodsEnum, path: string, timeout: number, body?: GeneralRequestBody, contentType?: string, additionalHeaders?: Record<string, string>) => Promise<RequesterResponseInterface<unknown>>;
|
|
45
45
|
getJson<T>(method: HttpMethodsEnum, endpoint: string, timeout: number, body?: GeneralRequestBody, additionalHeaders?: Record<string, string>): Promise<T>;
|
|
46
46
|
sendFormData<T>(method: HttpMethodsEnum, endpoint: string, timeout: number, formData: FormData, additionalHeaders?: Record<string, string>): Promise<T>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/types/request.ts"],"sourcesContent":["import { HttpMethodsEnum } from './enums';\n\nexport type GeneralRequestBody = Record<string, unknown>;\n\nexport interface GeneralHeaderInterface {\n /**\n * Authorization token. This is required for all HTTP requests made to the graph API.\n * @default 'Bearer '\n */\n Authorization: string;\n\n /**\n * Content type of the message being sent. This is required for all HTTP requests made to the graph API.\n * @default 'application/json'\n */\n 'Content-Type': string;\n\n /**\n * User agent field sent in all requests. This is used to gather SDK usage metrics and help\n * better triage support requests.\n * @default `WA_SDK/${ SDK_version } (Node.js ${ process.version })`\n */\n 'User-Agent': string;\n}\n\nexport interface RequesterResponseInterface<T> {\n json: () => Promise<T>;\n}\n\nexport interface ResponseSuccess {\n success: boolean;\n}\n\nexport interface ResponseData<T> {\n data: T;\n}\n\nexport interface ResponsePagination<T> {\n data: T[];\n paging: Paging;\n}\n\nexport interface Paging {\n cursors: {\n before: string;\n after: string;\n };\n next: string;\n}\n\nexport declare class RequesterClass {\n constructor(\n
|
|
1
|
+
{"version":3,"sources":["../../src/types/request.ts"],"sourcesContent":["import { HttpMethodsEnum } from './enums';\n\nexport type GeneralRequestBody = Record<string, unknown>;\n\nexport interface GeneralHeaderInterface {\n /**\n * Authorization token. This is required for all HTTP requests made to the graph API.\n * @default 'Bearer '\n */\n Authorization: string;\n\n /**\n * Content type of the message being sent. This is required for all HTTP requests made to the graph API.\n * @default 'application/json'\n */\n 'Content-Type': string;\n\n /**\n * User agent field sent in all requests. This is used to gather SDK usage metrics and help\n * better triage support requests.\n * @default `WA_SDK/${ SDK_version } (Node.js ${ process.version })`\n */\n 'User-Agent': string;\n}\n\nexport interface RequesterResponseInterface<T> {\n json: () => Promise<T>;\n}\n\nexport interface ResponseSuccess {\n success: boolean;\n}\n\nexport interface ResponseData<T> {\n data: T;\n}\n\nexport interface ResponsePagination<T> {\n data: T[];\n paging: Paging;\n}\n\nexport interface Paging {\n cursors: {\n before: string;\n after: string;\n };\n next: string;\n}\n\nexport declare class RequesterClass {\n constructor(\n apiVersion: string,\n phoneNumberId: number,\n accessToken: string,\n businessAcctId: string,\n userAgent: string,\n );\n\n sendRequest: (\n method: HttpMethodsEnum,\n path: string,\n timeout: number,\n body?: GeneralRequestBody,\n contentType?: string,\n additionalHeaders?: Record<string, string>,\n ) => Promise<RequesterResponseInterface<unknown>>;\n\n getJson<T>(\n method: HttpMethodsEnum,\n endpoint: string,\n timeout: number,\n body?: GeneralRequestBody,\n additionalHeaders?: Record<string, string>,\n ): Promise<T>;\n\n sendFormData<T>(\n method: HttpMethodsEnum,\n endpoint: string,\n timeout: number,\n formData: FormData,\n additionalHeaders?: Record<string, string>,\n ): Promise<T>;\n\n sendUrlEncodedForm<T>(\n method: HttpMethodsEnum,\n endpoint: string,\n timeout: number,\n formData: Record<string, string>,\n additionalHeaders?: Record<string, string>,\n ): Promise<T>;\n}\n"],"mappings":"+WAAA,IAAAA,EAAA,kBAAAC,EAAAD","names":["request_exports","__toCommonJS"]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { L as LanguagesEnum, C as CategoryEnum, T as TemplateStatusEnum } from '../enums-
|
|
1
|
+
import { L as LanguagesEnum, C as CategoryEnum, T as TemplateStatusEnum } from '../enums-Bcd3jLw2.mjs';
|
|
2
2
|
import { GeneralRequestBody, ResponseSuccess, ResponsePagination } from './request.mjs';
|
|
3
3
|
|
|
4
4
|
type TemplateFormat = 'TEXT' | 'IMAGE' | 'VIDEO' | 'DOCUMENT' | 'LOCATION';
|
package/dist/types/template.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { L as LanguagesEnum, C as CategoryEnum, T as TemplateStatusEnum } from '../enums-
|
|
1
|
+
import { L as LanguagesEnum, C as CategoryEnum, T as TemplateStatusEnum } from '../enums-Bcd3jLw2.js';
|
|
2
2
|
import { GeneralRequestBody, ResponseSuccess, ResponsePagination } from './request.js';
|
|
3
3
|
|
|
4
4
|
type TemplateFormat = 'TEXT' | 'IMAGE' | 'VIDEO' | 'DOCUMENT' | 'LOCATION';
|
package/dist/types/waba.d.mts
CHANGED
package/dist/types/waba.d.ts
CHANGED
package/dist/types/webhook.d.mts
CHANGED
package/dist/types/webhook.d.ts
CHANGED
|
@@ -9,7 +9,7 @@ import { RegistrationClass } from './registration.mjs';
|
|
|
9
9
|
import { TemplateClass } from './template.mjs';
|
|
10
10
|
import { TwoStepVerificationClass } from './twoStepVerification.mjs';
|
|
11
11
|
import { WABAClass } from './waba.mjs';
|
|
12
|
-
import '../enums-
|
|
12
|
+
import '../enums-Bcd3jLw2.mjs';
|
|
13
13
|
import './request.mjs';
|
|
14
14
|
import './base.mjs';
|
|
15
15
|
import './config.mjs';
|
|
@@ -24,7 +24,6 @@ import './config.mjs';
|
|
|
24
24
|
|
|
25
25
|
type WhatsAppConfig = {
|
|
26
26
|
accessToken: string;
|
|
27
|
-
baseUrl?: string;
|
|
28
27
|
appId?: string;
|
|
29
28
|
appSecret?: string;
|
|
30
29
|
phoneNumberId?: number;
|
package/dist/types/whatsapp.d.ts
CHANGED
|
@@ -9,7 +9,7 @@ import { RegistrationClass } from './registration.js';
|
|
|
9
9
|
import { TemplateClass } from './template.js';
|
|
10
10
|
import { TwoStepVerificationClass } from './twoStepVerification.js';
|
|
11
11
|
import { WABAClass } from './waba.js';
|
|
12
|
-
import '../enums-
|
|
12
|
+
import '../enums-Bcd3jLw2.js';
|
|
13
13
|
import './request.js';
|
|
14
14
|
import './base.js';
|
|
15
15
|
import './config.js';
|
|
@@ -24,7 +24,6 @@ import './config.js';
|
|
|
24
24
|
|
|
25
25
|
type WhatsAppConfig = {
|
|
26
26
|
accessToken: string;
|
|
27
|
-
baseUrl?: string;
|
|
28
27
|
appId?: string;
|
|
29
28
|
appSecret?: string;
|
|
30
29
|
phoneNumberId?: number;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/types/whatsapp.ts"],"sourcesContent":["/**\n * Copyright (c) Meta Platforms, Inc. and affiliates.\n * All rights reserved.\n *\n * This source code is licensed under the license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\nimport { BusinessProfileClass } from './businessProfile';\nimport { EncryptionClass } from './encryption';\nimport { FlowClass } from './flow';\nimport { MediaClass } from './media';\nimport { MessagesClass } from './messages';\nimport { PhoneNumberClass } from './phoneNumber';\nimport { QrCodeClass } from './qrCode';\nimport { RegistrationClass } from './registration';\nimport { TemplateClass } from './template';\nimport { TwoStepVerificationClass } from './twoStepVerification';\nimport { WABAClass } from './waba';\n\nexport type WhatsAppConfig = {\n accessToken: string;\n
|
|
1
|
+
{"version":3,"sources":["../../src/types/whatsapp.ts"],"sourcesContent":["/**\n * Copyright (c) Meta Platforms, Inc. and affiliates.\n * All rights reserved.\n *\n * This source code is licensed under the license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\nimport { BusinessProfileClass } from './businessProfile';\nimport { EncryptionClass } from './encryption';\nimport { FlowClass } from './flow';\nimport { MediaClass } from './media';\nimport { MessagesClass } from './messages';\nimport { PhoneNumberClass } from './phoneNumber';\nimport { QrCodeClass } from './qrCode';\nimport { RegistrationClass } from './registration';\nimport { TemplateClass } from './template';\nimport { TwoStepVerificationClass } from './twoStepVerification';\nimport { WABAClass } from './waba';\n\nexport type WhatsAppConfig = {\n accessToken: string;\n appId?: string;\n appSecret?: string;\n phoneNumberId?: number;\n businessAcctId?: string;\n apiVersion?: string;\n webhookEndpoint?: string;\n webhookVerificationToken?: string;\n listenerPort?: number;\n debug?: boolean;\n maxRetriesAfterWait?: number;\n requestTimeout?: number;\n};\n\nexport declare class WhatsAppClass {\n constructor(config?: WhatsAppConfig);\n readonly messages: MessagesClass;\n readonly templates: TemplateClass;\n readonly phoneNumber: PhoneNumberClass;\n readonly qrCode: QrCodeClass;\n readonly encryption: EncryptionClass;\n readonly twoStepVerification: TwoStepVerificationClass;\n readonly registration: RegistrationClass;\n readonly media: MediaClass;\n readonly waba: WABAClass;\n readonly flow: FlowClass;\n readonly businessProfile: BusinessProfileClass;\n updateTimeout(ms: number): boolean;\n updatePhoneNumberId(phoneNumberId: number): boolean;\n updateAccessToken(accessToken: string): boolean;\n updateWabaId(wabaId: string): boolean;\n}\n"],"mappings":"+WAAA,IAAAA,EAAA,kBAAAC,EAAAD","names":["whatsapp_exports","__toCommonJS"]}
|
package/dist/utils/filters.d.mts
CHANGED
package/dist/utils/filters.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { WhatsAppConfig } from '../types/whatsapp.mjs';
|
|
2
2
|
import { WabaConfigType } from '../types/config.mjs';
|
|
3
3
|
import '../types/businessProfile.mjs';
|
|
4
|
-
import '../enums-
|
|
4
|
+
import '../enums-Bcd3jLw2.mjs';
|
|
5
5
|
import '../types/request.mjs';
|
|
6
6
|
import '../types/encryption.mjs';
|
|
7
7
|
import '../types/flow.mjs';
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { WhatsAppConfig } from '../types/whatsapp.js';
|
|
2
2
|
import { WabaConfigType } from '../types/config.js';
|
|
3
3
|
import '../types/businessProfile.js';
|
|
4
|
-
import '../enums-
|
|
4
|
+
import '../enums-Bcd3jLw2.js';
|
|
5
5
|
import '../types/request.js';
|
|
6
6
|
import '../types/encryption.js';
|
|
7
7
|
import '../types/flow.js';
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var N=Object.defineProperty;var O=Object.getOwnPropertyDescriptor;var t=Object.getOwnPropertyNames;var
|
|
1
|
+
"use strict";var N=Object.defineProperty;var O=Object.getOwnPropertyDescriptor;var t=Object.getOwnPropertyNames;var G=Object.prototype.hasOwnProperty;var B=(A,R)=>{for(var S in R)N(A,S,{get:R[S],enumerable:!0})},T=(A,R,S,U)=>{if(R&&typeof R=="object"||typeof R=="function")for(let D of t(R))!G.call(A,D)&&D!==S&&N(A,D,{get:()=>R[D],enumerable:!(U=O(R,D))||U.enumerable});return A};var _=A=>T(N({},"__esModule",{value:!0}),A);var X={};B(X,{importConfig:()=>L});module.exports=_(X);var P=class{name;debug;constructor(R,S=!1){this.name=R,this.debug=S}log(...R){if(this.debug){let S=`[ ${Date.now()} ]`;this.name&&(S+=` - ${this.name}`),console.log.apply(console,[S,": ",...R])}}error(...R){let S=`[ ${Date.now()} ] - ERROR`;this.name&&(S+=` - ${this.name}`),console.error.apply(console,[S,": ",...R])}warn(...R){let S=`[ ${Date.now()} ] - WARN`;this.name&&(S+=` - ${this.name}`),console.warn.apply(console,[S,": ",...R])}info(...R){let S=`[ ${Date.now()} ] - INFO`;this.name&&(S+=` - ${this.name}`),console.info.apply(console,[S,": ",...R])}};var K="UTILS",M=!1,I=new P(K,process.env.DEBUG==="true"||M),F=3e3,i=30,H=2e4,p=A=>{if(!process.env.CLOUD_API_ACCESS_TOKEN&&!A?.accessToken)throw I.log("Environmental variable: CLOUD_API_ACCESS_TOKEN and/or access token argument is undefined."),new Error("Missing WhatsApp access token.")},L=A=>{p(A);let R={M4D_APP_ID:A?.appId||process.env.M4D_APP_ID||"",M4D_APP_SECRET:A?.appSecret||process.env.M4D_APP_SECRET||"",WA_PHONE_NUMBER_ID:A?.phoneNumberId||Number(process.env.WA_PHONE_NUMBER_ID),WA_BUSINESS_ACCOUNT_ID:A?.businessAcctId||process.env.WA_BUSINESS_ACCOUNT_ID||"",CLOUD_API_VERSION:A?.apiVersion||process.env.CLOUD_API_VERSION||"",CLOUD_API_ACCESS_TOKEN:A?.accessToken||process.env.CLOUD_API_ACCESS_TOKEN||"",WEBHOOK_ENDPOINT:A?.webhookEndpoint||process.env.WEBHOOK_ENDPOINT||"",WEBHOOK_VERIFICATION_TOKEN:A?.webhookVerificationToken||process.env.WEBHOOK_VERIFICATION_TOKEN||"",LISTENER_PORT:A?.listenerPort||parseInt(process.env.LISTENER_PORT||"")||F,MAX_RETRIES_AFTER_WAIT:A?.maxRetriesAfterWait||parseInt(process.env.MAX_RETRIES_AFTER_WAIT||"")||i,REQUEST_TIMEOUT:A?.requestTimeout||parseInt(process.env.REQUEST_TIMEOUT||"")||H,DEBUG:A?.debug||process.env.DEBUG==="true"};return I.log(`Configuration loaded for App Id ${R.M4D_APP_ID}`),R};0&&(module.exports={importConfig});
|
|
2
2
|
//# sourceMappingURL=importConfig.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utils/importConfig.ts","../../src/utils/logger.ts"],"sourcesContent":["import { WhatsAppConfig } from 'src/types/whatsapp';\nimport type { WabaConfigType } from '../types/config';\nimport { WabaConfigEnum } from '../types/enums';\nimport Logger from './logger';\n\nconst LIB_NAME = 'UTILS';\nconst LOG_LOCAL = false;\nconst LOGGER = new Logger(LIB_NAME, process.env.DEBUG === 'true' || LOG_LOCAL);\nconst
|
|
1
|
+
{"version":3,"sources":["../../src/utils/importConfig.ts","../../src/utils/logger.ts"],"sourcesContent":["import { WhatsAppConfig } from 'src/types/whatsapp';\nimport type { WabaConfigType } from '../types/config';\nimport { WabaConfigEnum } from '../types/enums';\nimport Logger from './logger';\n\nconst LIB_NAME = 'UTILS';\nconst LOG_LOCAL = false;\nconst LOGGER = new Logger(LIB_NAME, process.env.DEBUG === 'true' || LOG_LOCAL);\nconst DEFAULT_LISTENER_PORT = 3000;\nconst DEFAULT_MAX_RETRIES_AFTER_WAIT = 30;\nconst DEFAULT_REQUEST_TIMEOUT = 20000;\n\nconst emptyConfigChecker = (config: WhatsAppConfig | undefined) => {\n if (!process.env[WabaConfigEnum.AccessToken] && !config?.accessToken) {\n LOGGER.log(`Environmental variable: CLOUD_API_ACCESS_TOKEN and/or access token argument is undefined.`);\n throw new Error('Missing WhatsApp access token.');\n }\n};\n\nexport const importConfig = (inputConfig?: WhatsAppConfig) => {\n emptyConfigChecker(inputConfig);\n\n const wabaConfig: WabaConfigType = {\n [WabaConfigEnum.AppId]: inputConfig?.appId || process.env.M4D_APP_ID || '',\n [WabaConfigEnum.AppSecret]: inputConfig?.appSecret || process.env.M4D_APP_SECRET || '',\n [WabaConfigEnum.PhoneNumberId]: inputConfig?.phoneNumberId || Number(process.env.WA_PHONE_NUMBER_ID),\n [WabaConfigEnum.BusinessAcctId]: inputConfig?.businessAcctId || process.env.WA_BUSINESS_ACCOUNT_ID || '',\n [WabaConfigEnum.APIVersion]: inputConfig?.apiVersion || process.env.CLOUD_API_VERSION || '',\n [WabaConfigEnum.AccessToken]: inputConfig?.accessToken || process.env.CLOUD_API_ACCESS_TOKEN || '',\n [WabaConfigEnum.WebhookEndpoint]: inputConfig?.webhookEndpoint || process.env.WEBHOOK_ENDPOINT || '',\n [WabaConfigEnum.WebhookVerificationToken]:\n inputConfig?.webhookVerificationToken || process.env.WEBHOOK_VERIFICATION_TOKEN || '',\n [WabaConfigEnum.ListenerPort]:\n inputConfig?.listenerPort || parseInt(process.env.LISTENER_PORT || '') || DEFAULT_LISTENER_PORT,\n [WabaConfigEnum.MaxRetriesAfterWait]:\n inputConfig?.maxRetriesAfterWait ||\n parseInt(process.env.MAX_RETRIES_AFTER_WAIT || '') ||\n DEFAULT_MAX_RETRIES_AFTER_WAIT,\n [WabaConfigEnum.RequestTimeout]:\n inputConfig?.requestTimeout || parseInt(process.env.REQUEST_TIMEOUT || '') || DEFAULT_REQUEST_TIMEOUT,\n [WabaConfigEnum.Debug]: inputConfig?.debug || process.env.DEBUG === 'true',\n };\n\n LOGGER.log(`Configuration loaded for App Id ${wabaConfig[WabaConfigEnum.AppId]}`);\n\n return wabaConfig;\n};\n","// @ts-nocheck\nimport type { LoggerInterface } from '../types/logger';\n\nexport default class Logger implements LoggerInterface {\n private name: string;\n private debug: boolean;\n\n constructor(name: string, debug: boolean = false) {\n this.name = name;\n this.debug = debug;\n }\n\n log(...data: any[]) {\n if (this.debug) {\n let prefix = `[ ${Date.now()} ]`;\n if (this.name) {\n prefix += ` - ${this.name}`;\n }\n console.log.apply(console, [prefix, ': ', ...data]);\n }\n }\n\n error(...data: any[]) {\n let prefix = `[ ${Date.now()} ] - ERROR`;\n if (this.name) {\n prefix += ` - ${this.name}`;\n }\n console.error.apply(console, [prefix, ': ', ...data]);\n }\n\n warn(...data: any[]) {\n let prefix = `[ ${Date.now()} ] - WARN`;\n if (this.name) {\n prefix += ` - ${this.name}`;\n }\n console.warn.apply(console, [prefix, ': ', ...data]);\n }\n\n info(...data: any[]) {\n let prefix = `[ ${Date.now()} ] - INFO`;\n if (this.name) {\n prefix += ` - ${this.name}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AN,EAAO,IAAI,2FAA2F,EAChG,IAAI,MAAM,gCAAgC,CAExD,EAEaO,EAAgBC,GAAiC,CAC1DH,EAAmBG,CAAW,EAE9B,IAAMC,EAA6B,CAC9B,WAAuBD,GAAa,OAAS,QAAQ,IAAI,YAAc,GACvE,eAA2BA,GAAa,WAAa,QAAQ,IAAI,gBAAkB,GACnF,mBAA+BA,GAAa,eAAiB,OAAO,QAAQ,IAAI,kBAAkB,EAClG,uBAAgCA,GAAa,gBAAkB,QAAQ,IAAI,wBAA0B,GACrG,kBAA4BA,GAAa,YAAc,QAAQ,IAAI,mBAAqB,GACxF,uBAA6BA,GAAa,aAAe,QAAQ,IAAI,wBAA0B,GAC/F,iBAAiCA,GAAa,iBAAmB,QAAQ,IAAI,kBAAoB,GACjG,2BACGA,GAAa,0BAA4B,QAAQ,IAAI,4BAA8B,GACtF,cACGA,GAAa,cAAgB,SAAS,QAAQ,IAAI,eAAiB,EAAE,GAAKN,EAC7E,uBACGM,GAAa,qBACb,SAAS,QAAQ,IAAI,wBAA0B,EAAE,GACjDL,EACH,gBACGK,GAAa,gBAAkB,SAAS,QAAQ,IAAI,iBAAmB,EAAE,GAAKJ,EACjF,MAAuBI,GAAa,OAAS,QAAQ,IAAI,QAAU,MACxE,EAEA,OAAAR,EAAO,IAAI,mCAAmCS,EAAW,UAAqB,EAAE,EAEzEA,CACX","names":["importConfig_exports","__export","importConfig","__toCommonJS","Logger","name","debug","data","prefix","LIB_NAME","LOG_LOCAL","LOGGER","Logger","DEFAULT_LISTENER_PORT","DEFAULT_MAX_RETRIES_AFTER_WAIT","DEFAULT_REQUEST_TIMEOUT","emptyConfigChecker","config","importConfig","inputConfig","wabaConfig"]}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var D=class{name;debug;constructor(S,R=!1){this.name=S,this.debug=R}log(...S){if(this.debug){let R=`[ ${Date.now()} ]`;this.name&&(R+=` - ${this.name}`),console.log.apply(console,[R,": ",...S])}}error(...S){let R=`[ ${Date.now()} ] - ERROR`;this.name&&(R+=` - ${this.name}`),console.error.apply(console,[R,": ",...S])}warn(...S){let R=`[ ${Date.now()} ] - WARN`;this.name&&(R+=` - ${this.name}`),console.warn.apply(console,[R,": ",...S])}info(...S){let R=`[ ${Date.now()} ] - INFO`;this.name&&(R+=` - ${this.name}`),console.info.apply(console,[R,": ",...S])}};var N="UTILS",U=!1,P=new D(N,process.env.DEBUG==="true"||U),I=
|
|
1
|
+
var D=class{name;debug;constructor(S,R=!1){this.name=S,this.debug=R}log(...S){if(this.debug){let R=`[ ${Date.now()} ]`;this.name&&(R+=` - ${this.name}`),console.log.apply(console,[R,": ",...S])}}error(...S){let R=`[ ${Date.now()} ] - ERROR`;this.name&&(R+=` - ${this.name}`),console.error.apply(console,[R,": ",...S])}warn(...S){let R=`[ ${Date.now()} ] - WARN`;this.name&&(R+=` - ${this.name}`),console.warn.apply(console,[R,": ",...S])}info(...S){let R=`[ ${Date.now()} ] - INFO`;this.name&&(R+=` - ${this.name}`),console.info.apply(console,[R,": ",...S])}};var N="UTILS",U=!1,P=new D(N,process.env.DEBUG==="true"||U),I=3e3,O=30,t=2e4,G=A=>{if(!process.env.CLOUD_API_ACCESS_TOKEN&&!A?.accessToken)throw P.log("Environmental variable: CLOUD_API_ACCESS_TOKEN and/or access token argument is undefined."),new Error("Missing WhatsApp access token.")},F=A=>{G(A);let S={M4D_APP_ID:A?.appId||process.env.M4D_APP_ID||"",M4D_APP_SECRET:A?.appSecret||process.env.M4D_APP_SECRET||"",WA_PHONE_NUMBER_ID:A?.phoneNumberId||Number(process.env.WA_PHONE_NUMBER_ID),WA_BUSINESS_ACCOUNT_ID:A?.businessAcctId||process.env.WA_BUSINESS_ACCOUNT_ID||"",CLOUD_API_VERSION:A?.apiVersion||process.env.CLOUD_API_VERSION||"",CLOUD_API_ACCESS_TOKEN:A?.accessToken||process.env.CLOUD_API_ACCESS_TOKEN||"",WEBHOOK_ENDPOINT:A?.webhookEndpoint||process.env.WEBHOOK_ENDPOINT||"",WEBHOOK_VERIFICATION_TOKEN:A?.webhookVerificationToken||process.env.WEBHOOK_VERIFICATION_TOKEN||"",LISTENER_PORT:A?.listenerPort||parseInt(process.env.LISTENER_PORT||"")||I,MAX_RETRIES_AFTER_WAIT:A?.maxRetriesAfterWait||parseInt(process.env.MAX_RETRIES_AFTER_WAIT||"")||O,REQUEST_TIMEOUT:A?.requestTimeout||parseInt(process.env.REQUEST_TIMEOUT||"")||t,DEBUG:A?.debug||process.env.DEBUG==="true"};return P.log(`Configuration loaded for App Id ${S.M4D_APP_ID}`),S};export{F as importConfig};
|
|
2
2
|
//# sourceMappingURL=importConfig.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utils/logger.ts","../../src/utils/importConfig.ts"],"sourcesContent":["// @ts-nocheck\nimport type { LoggerInterface } from '../types/logger';\n\nexport default class Logger implements LoggerInterface {\n private name: string;\n private debug: boolean;\n\n constructor(name: string, debug: boolean = false) {\n this.name = name;\n this.debug = debug;\n }\n\n log(...data: any[]) {\n if (this.debug) {\n let prefix = `[ ${Date.now()} ]`;\n if (this.name) {\n prefix += ` - ${this.name}`;\n }\n console.log.apply(console, [prefix, ': ', ...data]);\n }\n }\n\n error(...data: any[]) {\n let prefix = `[ ${Date.now()} ] - ERROR`;\n if (this.name) {\n prefix += ` - ${this.name}`;\n }\n console.error.apply(console, [prefix, ': ', ...data]);\n }\n\n warn(...data: any[]) {\n let prefix = `[ ${Date.now()} ] - WARN`;\n if (this.name) {\n prefix += ` - ${this.name}`;\n }\n console.warn.apply(console, [prefix, ': ', ...data]);\n }\n\n info(...data: any[]) {\n let prefix = `[ ${Date.now()} ] - INFO`;\n if (this.name) {\n prefix += ` - ${this.name}`;\n }\n console.info.apply(console, [prefix, ': ', ...data]);\n }\n}\n","import { WhatsAppConfig } from 'src/types/whatsapp';\nimport type { WabaConfigType } from '../types/config';\nimport { WabaConfigEnum } from '../types/enums';\nimport Logger from './logger';\n\nconst LIB_NAME = 'UTILS';\nconst LOG_LOCAL = false;\nconst LOGGER = new Logger(LIB_NAME, process.env.DEBUG === 'true' || LOG_LOCAL);\nconst
|
|
1
|
+
{"version":3,"sources":["../../src/utils/logger.ts","../../src/utils/importConfig.ts"],"sourcesContent":["// @ts-nocheck\nimport type { LoggerInterface } from '../types/logger';\n\nexport default class Logger implements LoggerInterface {\n private name: string;\n private debug: boolean;\n\n constructor(name: string, debug: boolean = false) {\n this.name = name;\n this.debug = debug;\n }\n\n log(...data: any[]) {\n if (this.debug) {\n let prefix = `[ ${Date.now()} ]`;\n if (this.name) {\n prefix += ` - ${this.name}`;\n }\n console.log.apply(console, [prefix, ': ', ...data]);\n }\n }\n\n error(...data: any[]) {\n let prefix = `[ ${Date.now()} ] - ERROR`;\n if (this.name) {\n prefix += ` - ${this.name}`;\n }\n console.error.apply(console, [prefix, ': ', ...data]);\n }\n\n warn(...data: any[]) {\n let prefix = `[ ${Date.now()} ] - WARN`;\n if (this.name) {\n prefix += ` - ${this.name}`;\n }\n console.warn.apply(console, [prefix, ': ', ...data]);\n }\n\n info(...data: any[]) {\n let prefix = `[ ${Date.now()} ] - INFO`;\n if (this.name) {\n prefix += ` - ${this.name}`;\n }\n console.info.apply(console, [prefix, ': ', ...data]);\n }\n}\n","import { WhatsAppConfig } from 'src/types/whatsapp';\nimport type { WabaConfigType } from '../types/config';\nimport { WabaConfigEnum } from '../types/enums';\nimport Logger from './logger';\n\nconst LIB_NAME = 'UTILS';\nconst LOG_LOCAL = false;\nconst LOGGER = new Logger(LIB_NAME, process.env.DEBUG === 'true' || LOG_LOCAL);\nconst DEFAULT_LISTENER_PORT = 3000;\nconst DEFAULT_MAX_RETRIES_AFTER_WAIT = 30;\nconst DEFAULT_REQUEST_TIMEOUT = 20000;\n\nconst emptyConfigChecker = (config: WhatsAppConfig | undefined) => {\n if (!process.env[WabaConfigEnum.AccessToken] && !config?.accessToken) {\n LOGGER.log(`Environmental variable: CLOUD_API_ACCESS_TOKEN and/or access token argument is undefined.`);\n throw new Error('Missing WhatsApp access token.');\n }\n};\n\nexport const importConfig = (inputConfig?: WhatsAppConfig) => {\n emptyConfigChecker(inputConfig);\n\n const wabaConfig: WabaConfigType = {\n [WabaConfigEnum.AppId]: inputConfig?.appId || process.env.M4D_APP_ID || '',\n [WabaConfigEnum.AppSecret]: inputConfig?.appSecret || process.env.M4D_APP_SECRET || '',\n [WabaConfigEnum.PhoneNumberId]: inputConfig?.phoneNumberId || Number(process.env.WA_PHONE_NUMBER_ID),\n [WabaConfigEnum.BusinessAcctId]: inputConfig?.businessAcctId || process.env.WA_BUSINESS_ACCOUNT_ID || '',\n [WabaConfigEnum.APIVersion]: inputConfig?.apiVersion || process.env.CLOUD_API_VERSION || '',\n [WabaConfigEnum.AccessToken]: inputConfig?.accessToken || process.env.CLOUD_API_ACCESS_TOKEN || '',\n [WabaConfigEnum.WebhookEndpoint]: inputConfig?.webhookEndpoint || process.env.WEBHOOK_ENDPOINT || '',\n [WabaConfigEnum.WebhookVerificationToken]:\n inputConfig?.webhookVerificationToken || process.env.WEBHOOK_VERIFICATION_TOKEN || '',\n [WabaConfigEnum.ListenerPort]:\n inputConfig?.listenerPort || parseInt(process.env.LISTENER_PORT || '') || DEFAULT_LISTENER_PORT,\n [WabaConfigEnum.MaxRetriesAfterWait]:\n inputConfig?.maxRetriesAfterWait ||\n parseInt(process.env.MAX_RETRIES_AFTER_WAIT || '') ||\n DEFAULT_MAX_RETRIES_AFTER_WAIT,\n [WabaConfigEnum.RequestTimeout]:\n inputConfig?.requestTimeout || parseInt(process.env.REQUEST_TIMEOUT || '') || DEFAULT_REQUEST_TIMEOUT,\n [WabaConfigEnum.Debug]: inputConfig?.debug || process.env.DEBUG === 'true',\n };\n\n LOGGER.log(`Configuration loaded for App Id ${wabaConfig[WabaConfigEnum.AppId]}`);\n\n return wabaConfig;\n};\n"],"mappings":"AAGA,IAAqBA,EAArB,KAAuD,CAC3C,KACA,MAER,YAAYC,EAAcC,EAAiB,GAAO,CA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AQ,IAAI,gBAAkB,GACnF,mBAA+BA,GAAa,eAAiB,OAAO,QAAQ,IAAI,kBAAkB,EAClG,uBAAgCA,GAAa,gBAAkB,QAAQ,IAAI,wBAA0B,GACrG,kBAA4BA,GAAa,YAAc,QAAQ,IAAI,mBAAqB,GACxF,uBAA6BA,GAAa,aAAe,QAAQ,IAAI,wBAA0B,GAC/F,iBAAiCA,GAAa,iBAAmB,QAAQ,IAAI,kBAAoB,GACjG,2BACGA,GAAa,0BAA4B,QAAQ,IAAI,4BAA8B,GACtF,cACGA,GAAa,cAAgB,SAAS,QAAQ,IAAI,eAAiB,EAAE,GAAKN,EAC7E,uBACGM,GAAa,qBACb,SAAS,QAAQ,IAAI,wBAA0B,EAAE,GACjDL,EACH,gBACGK,GAAa,gBAAkB,SAAS,QAAQ,IAAI,iBAAmB,EAAE,GAAKJ,EACjF,MAAuBI,GAAa,OAAS,QAAQ,IAAI,QAAU,MACxE,EAEA,OAAAR,EAAO,IAAI,mCAAmCS,EAAW,UAAqB,EAAE,EAEzEA,CACX","names":["Logger","name","debug","data","prefix","LIB_NAME","LOG_LOCAL","LOGGER","Logger","DEFAULT_LISTENER_PORT","DEFAULT_MAX_RETRIES_AFTER_WAIT","DEFAULT_REQUEST_TIMEOUT","emptyConfigChecker","config","importConfig","inputConfig","wabaConfig"]}
|
package/dist/utils/index.d.mts
CHANGED
|
@@ -4,7 +4,7 @@ export { MetaError, isMetaError } from './isMetaError.mjs';
|
|
|
4
4
|
export { objectToQueryString } from './objectToQueryString.mjs';
|
|
5
5
|
import '../types/whatsapp.mjs';
|
|
6
6
|
import '../types/businessProfile.mjs';
|
|
7
|
-
import '../enums-
|
|
7
|
+
import '../enums-Bcd3jLw2.mjs';
|
|
8
8
|
import '../types/request.mjs';
|
|
9
9
|
import '../types/encryption.mjs';
|
|
10
10
|
import '../types/flow.mjs';
|
package/dist/utils/index.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ export { MetaError, isMetaError } from './isMetaError.js';
|
|
|
4
4
|
export { objectToQueryString } from './objectToQueryString.js';
|
|
5
5
|
import '../types/whatsapp.js';
|
|
6
6
|
import '../types/businessProfile.js';
|
|
7
|
-
import '../enums-
|
|
7
|
+
import '../enums-Bcd3jLw2.js';
|
|
8
8
|
import '../types/request.js';
|
|
9
9
|
import '../types/encryption.js';
|
|
10
10
|
import '../types/flow.js';
|
package/dist/utils/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var _=Object.create;var N=Object.defineProperty;var i=Object.getOwnPropertyDescriptor;var G=Object.getOwnPropertyNames;var T=Object.getPrototypeOf,B=Object.prototype.hasOwnProperty;var p=(t,A)=>{for(var R in A)N(t,R,{get:A[R],enumerable:!0})},U=(t,A,R,P)=>{if(A&&typeof A=="object"||typeof A=="function")for(let S of G(A))!B.call(t,S)&&S!==R&&N(t,S,{get:()=>A[S],enumerable:!(P=i(A,S))||P.enumerable});return t};var K=(t,A,R)=>(R=t!=null?_(T(t)):{},U(A||!t||!t.__esModule?N(R,"default",{value:t,enumerable:!0}):R,t)),M=t=>U(N({},"__esModule",{value:!0}),t);var W={};p(W,{generateXHub256Sig:()=>F,importConfig:()=>Y,isMetaError:()=>h,objectToQueryString:()=>Z});module.exports=M(W);var O=K(require("crypto")),F=(t,A)=>O.createHmac("sha256",A).update(t,"utf-8").digest("hex");var D=class{name;debug;constructor(A,R=!1){this.name=A,this.debug=R}log(...A){if(this.debug){let R=`[ ${Date.now()} ]`;this.name&&(R+=` - ${this.name}`),console.log.apply(console,[R,": ",...A])}}error(...A){let R=`[ ${Date.now()} ] - ERROR`;this.name&&(R+=` - ${this.name}`),console.error.apply(console,[R,": ",...A])}warn(...A){let R=`[ ${Date.now()} ] - WARN`;this.name&&(R+=` - ${this.name}`),console.warn.apply(console,[R,": ",...A])}info(...A){let R=`[ ${Date.now()} ] - INFO`;this.name&&(R+=` - ${this.name}`),console.info.apply(console,[R,": ",...A])}};var H="UTILS",l=!1,I=new D(H,process.env.DEBUG==="true"||l),L=3e3,f=30,X=2e4,x=t=>{if(!process.env.CLOUD_API_ACCESS_TOKEN&&!t?.accessToken)throw I.log("Environmental variable: CLOUD_API_ACCESS_TOKEN and/or access token argument is undefined."),new Error("Missing WhatsApp access token.")},Y=t=>{x(t);let A={M4D_APP_ID:t?.appId||process.env.M4D_APP_ID||"",M4D_APP_SECRET:t?.appSecret||process.env.M4D_APP_SECRET||"",WA_PHONE_NUMBER_ID:t?.phoneNumberId||Number(process.env.WA_PHONE_NUMBER_ID),WA_BUSINESS_ACCOUNT_ID:t?.businessAcctId||process.env.WA_BUSINESS_ACCOUNT_ID||"",CLOUD_API_VERSION:t?.apiVersion||process.env.CLOUD_API_VERSION||"",CLOUD_API_ACCESS_TOKEN:t?.accessToken||process.env.CLOUD_API_ACCESS_TOKEN||"",WEBHOOK_ENDPOINT:t?.webhookEndpoint||process.env.WEBHOOK_ENDPOINT||"",WEBHOOK_VERIFICATION_TOKEN:t?.webhookVerificationToken||process.env.WEBHOOK_VERIFICATION_TOKEN||"",LISTENER_PORT:t?.listenerPort||parseInt(process.env.LISTENER_PORT||"")||L,MAX_RETRIES_AFTER_WAIT:t?.maxRetriesAfterWait||parseInt(process.env.MAX_RETRIES_AFTER_WAIT||"")||f,REQUEST_TIMEOUT:t?.requestTimeout||parseInt(process.env.REQUEST_TIMEOUT||"")||X,DEBUG:t?.debug||process.env.DEBUG==="true"};return I.log(`Configuration loaded for App Id ${A.M4D_APP_ID}`),A};function h(t){return t!=null&&typeof t=="object"&&"error"in t&&typeof t.error=="object"&&t.error!=null&&"message"in t.error&&typeof t.error.message=="string"&&"type"in t.error&&typeof t.error.type=="string"&&"code"in t.error&&typeof t.error.code=="number"&&"fbtrace_id"in t.error&&typeof t.error.fbtrace_id=="string"&&(!("error_data"in t.error)||typeof t.error.error_data=="object"&&t.error.error_data!=null&&"messaging_product"in t.error.error_data&&t.error.error_data.messaging_product==="whatsapp"&&"details"in t.error.error_data&&typeof t.error.error_data.details=="string")&&(!("error_subcode"in t.error)||typeof t.error.error_subcode=="number")}var Z=t=>{if(!t||Object.keys(t).length===0)return"";let A=new URLSearchParams;for(let[P,S]of Object.entries(t))S!==void 0&&A.append(P,String(S));let R=A.toString();return R?`?${R}`:""};0&&(module.exports={generateXHub256Sig,importConfig,isMetaError,objectToQueryString});
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
package/dist/utils/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utils/index.ts","../../src/utils/generateXHub256Sig.ts","../../src/utils/logger.ts","../../src/utils/importConfig.ts","../../src/utils/isMetaError.ts","../../src/utils/objectToQueryString.ts"],"sourcesContent":["export * from './generateXHub256Sig';\nexport * from './importConfig';\nexport * from './isMetaError';\nexport * from './logger';\nexport * from './objectToQueryString';\n","import * as crypto from 'crypto';\n\nexport const generateXHub256Sig = (body: string, appSecret: string) => {\n return crypto.createHmac('sha256', appSecret).update(body, 'utf-8').digest('hex');\n};\n","// @ts-nocheck\nimport type { LoggerInterface } from '../types/logger';\n\nexport default class Logger implements LoggerInterface {\n private name: string;\n private debug: boolean;\n\n constructor(name: string, debug: boolean = false) {\n this.name = name;\n this.debug = debug;\n }\n\n log(...data: any[]) {\n if (this.debug) {\n let prefix = `[ ${Date.now()} ]`;\n if (this.name) {\n prefix += ` - ${this.name}`;\n }\n console.log.apply(console, [prefix, ': ', ...data]);\n }\n }\n\n error(...data: any[]) {\n let prefix = `[ ${Date.now()} ] - ERROR`;\n if (this.name) {\n prefix += ` - ${this.name}`;\n }\n console.error.apply(console, [prefix, ': ', ...data]);\n }\n\n warn(...data: any[]) {\n let prefix = `[ ${Date.now()} ] - WARN`;\n if (this.name) {\n prefix += ` - ${this.name}`;\n }\n console.warn.apply(console, [prefix, ': ', ...data]);\n }\n\n info(...data: any[]) {\n let prefix = `[ ${Date.now()} ] - INFO`;\n if (this.name) {\n prefix += ` - ${this.name}`;\n }\n console.info.apply(console, [prefix, ': ', ...data]);\n }\n}\n","import { WhatsAppConfig } from 'src/types/whatsapp';\nimport type { WabaConfigType } from '../types/config';\nimport { WabaConfigEnum } from '../types/enums';\nimport Logger from './logger';\n\nconst LIB_NAME = 'UTILS';\nconst LOG_LOCAL = false;\nconst LOGGER = new Logger(LIB_NAME, process.env.DEBUG === 'true' || LOG_LOCAL);\nconst
|
|
1
|
+
{"version":3,"sources":["../../src/utils/index.ts","../../src/utils/generateXHub256Sig.ts","../../src/utils/logger.ts","../../src/utils/importConfig.ts","../../src/utils/isMetaError.ts","../../src/utils/objectToQueryString.ts"],"sourcesContent":["export * from './generateXHub256Sig';\nexport * from './importConfig';\nexport * from './isMetaError';\nexport * from './logger';\nexport * from './objectToQueryString';\n","import * as crypto from 'crypto';\n\nexport const generateXHub256Sig = (body: string, appSecret: string) => {\n return crypto.createHmac('sha256', appSecret).update(body, 'utf-8').digest('hex');\n};\n","// @ts-nocheck\nimport type { LoggerInterface } from '../types/logger';\n\nexport default class Logger implements LoggerInterface {\n private name: string;\n private debug: boolean;\n\n constructor(name: string, debug: boolean = false) {\n this.name = name;\n this.debug = debug;\n }\n\n log(...data: any[]) {\n if (this.debug) {\n let prefix = `[ ${Date.now()} ]`;\n if (this.name) {\n prefix += ` - ${this.name}`;\n }\n console.log.apply(console, [prefix, ': ', ...data]);\n }\n }\n\n error(...data: any[]) {\n let prefix = `[ ${Date.now()} ] - ERROR`;\n if (this.name) {\n prefix += ` - ${this.name}`;\n }\n console.error.apply(console, [prefix, ': ', ...data]);\n }\n\n warn(...data: any[]) {\n let prefix = `[ ${Date.now()} ] - WARN`;\n if (this.name) {\n prefix += ` - ${this.name}`;\n }\n console.warn.apply(console, [prefix, ': ', ...data]);\n }\n\n info(...data: any[]) {\n let prefix = `[ ${Date.now()} ] - INFO`;\n if (this.name) {\n prefix += ` - ${this.name}`;\n }\n console.info.apply(console, [prefix, ': ', ...data]);\n }\n}\n","import { WhatsAppConfig } from 'src/types/whatsapp';\nimport type { WabaConfigType } from '../types/config';\nimport { WabaConfigEnum } from '../types/enums';\nimport Logger from './logger';\n\nconst LIB_NAME = 'UTILS';\nconst LOG_LOCAL = false;\nconst LOGGER = new Logger(LIB_NAME, process.env.DEBUG === 'true' || LOG_LOCAL);\nconst DEFAULT_LISTENER_PORT = 3000;\nconst DEFAULT_MAX_RETRIES_AFTER_WAIT = 30;\nconst DEFAULT_REQUEST_TIMEOUT = 20000;\n\nconst emptyConfigChecker = (config: WhatsAppConfig | undefined) => {\n if (!process.env[WabaConfigEnum.AccessToken] && !config?.accessToken) {\n LOGGER.log(`Environmental variable: CLOUD_API_ACCESS_TOKEN and/or access token argument is undefined.`);\n throw new Error('Missing WhatsApp access token.');\n }\n};\n\nexport const importConfig = (inputConfig?: WhatsAppConfig) => {\n emptyConfigChecker(inputConfig);\n\n const wabaConfig: WabaConfigType = {\n [WabaConfigEnum.AppId]: inputConfig?.appId || process.env.M4D_APP_ID || '',\n [WabaConfigEnum.AppSecret]: inputConfig?.appSecret || process.env.M4D_APP_SECRET || '',\n [WabaConfigEnum.PhoneNumberId]: inputConfig?.phoneNumberId || Number(process.env.WA_PHONE_NUMBER_ID),\n [WabaConfigEnum.BusinessAcctId]: inputConfig?.businessAcctId || process.env.WA_BUSINESS_ACCOUNT_ID || '',\n [WabaConfigEnum.APIVersion]: inputConfig?.apiVersion || process.env.CLOUD_API_VERSION || '',\n [WabaConfigEnum.AccessToken]: inputConfig?.accessToken || process.env.CLOUD_API_ACCESS_TOKEN || '',\n [WabaConfigEnum.WebhookEndpoint]: inputConfig?.webhookEndpoint || process.env.WEBHOOK_ENDPOINT || '',\n [WabaConfigEnum.WebhookVerificationToken]:\n inputConfig?.webhookVerificationToken || process.env.WEBHOOK_VERIFICATION_TOKEN || '',\n [WabaConfigEnum.ListenerPort]:\n inputConfig?.listenerPort || parseInt(process.env.LISTENER_PORT || '') || DEFAULT_LISTENER_PORT,\n [WabaConfigEnum.MaxRetriesAfterWait]:\n inputConfig?.maxRetriesAfterWait ||\n parseInt(process.env.MAX_RETRIES_AFTER_WAIT || '') ||\n DEFAULT_MAX_RETRIES_AFTER_WAIT,\n [WabaConfigEnum.RequestTimeout]:\n inputConfig?.requestTimeout || parseInt(process.env.REQUEST_TIMEOUT || '') || DEFAULT_REQUEST_TIMEOUT,\n [WabaConfigEnum.Debug]: inputConfig?.debug || process.env.DEBUG === 'true',\n };\n\n LOGGER.log(`Configuration loaded for App Id ${wabaConfig[WabaConfigEnum.AppId]}`);\n\n return wabaConfig;\n};\n","export interface MetaError extends Error {\n error: {\n message: string;\n type: string;\n code: number;\n error_data?: {\n messaging_product: 'whatsapp';\n details: string;\n };\n error_subcode?: number;\n fbtrace_id: string;\n };\n}\n\n/**\n * Determines if the error is a Meta API error response\n * @param error Any error object to check\n * @returns Type guard indicating if error is a Meta API error\n */\nexport function isMetaError(error: any): error is MetaError {\n return (\n error != null &&\n typeof error === 'object' &&\n 'error' in error &&\n typeof error.error === 'object' &&\n error.error != null &&\n 'message' in error.error &&\n typeof error.error.message === 'string' &&\n 'type' in error.error &&\n typeof error.error.type === 'string' &&\n 'code' in error.error &&\n typeof error.error.code === 'number' &&\n 'fbtrace_id' in error.error &&\n typeof error.error.fbtrace_id === 'string' &&\n (!('error_data' in error.error) ||\n (typeof error.error.error_data === 'object' &&\n error.error.error_data != null &&\n 'messaging_product' in error.error.error_data &&\n error.error.error_data.messaging_product === 'whatsapp' &&\n 'details' in error.error.error_data &&\n typeof error.error.error_data.details === 'string')) &&\n (!('error_subcode' in error.error) || typeof error.error.error_subcode === 'number')\n );\n}\n","export const objectToQueryString = (params: Record<string, any>): string => {\n if (!params || Object.keys(params).length === 0) {\n return '';\n }\n\n const searchParams = new URLSearchParams();\n\n for (const [key, value] of Object.entries(params)) {\n if (value !== undefined) {\n searchParams.append(key, String(value));\n }\n }\n\n const queryString = searchParams.toString();\n return queryString ? `?${queryString}` : '';\n};\n"],"mappings":"0jBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,wBAAAE,E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ACjC,EAAE,eAAgBA,EAAM,QACpB,OAAOA,EAAM,MAAM,YAAe,UAC/BA,EAAM,MAAM,YAAc,MAC1B,sBAAuBA,EAAM,MAAM,YACnCA,EAAM,MAAM,WAAW,oBAAsB,YAC7C,YAAaA,EAAM,MAAM,YACzB,OAAOA,EAAM,MAAM,WAAW,SAAY,YACjD,EAAE,kBAAmBA,EAAM,QAAU,OAAOA,EAAM,MAAM,eAAkB,SAEnF,CC3CO,IAAMC,EAAuBC,GAAwC,CACxE,GAAI,CAACA,GAAU,OAAO,KAAKA,CAAM,EAAE,SAAW,EAC1C,MAAO,GAGX,IAAMC,EAAe,IAAI,gBAEzB,OAAW,CAACC,EAAKC,CAAK,IAAK,OAAO,QAAQH,CAAM,EACxCG,IAAU,QACVF,EAAa,OAAOC,EAAK,OAAOC,CAAK,CAAC,EAI9C,IAAMC,EAAcH,EAAa,SAAS,EAC1C,OAAOG,EAAc,IAAIA,CAAW,GAAK,EAC7C","names":["utils_exports","__export","generateXHub256Sig","importConfig","isMetaError","objectToQueryString","__toCommonJS","crypto","generateXHub256Sig","body","appSecret","Logger","name","debug","data","prefix","LIB_NAME","LOG_LOCAL","LOGGER","Logger","DEFAULT_LISTENER_PORT","DEFAULT_MAX_RETRIES_AFTER_WAIT","DEFAULT_REQUEST_TIMEOUT","emptyConfigChecker","config","importConfig","inputConfig","wabaConfig","isMetaError","error","objectToQueryString","params","searchParams","key","value","queryString"]}
|
package/dist/utils/index.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import*as P from"crypto";var
|
|
1
|
+
import*as P from"crypto";var B=(t,A)=>P.createHmac("sha256",A).update(t,"utf-8").digest("hex");var S=class{name;debug;constructor(A,R=!1){this.name=A,this.debug=R}log(...A){if(this.debug){let R=`[ ${Date.now()} ]`;this.name&&(R+=` - ${this.name}`),console.log.apply(console,[R,": ",...A])}}error(...A){let R=`[ ${Date.now()} ] - ERROR`;this.name&&(R+=` - ${this.name}`),console.error.apply(console,[R,": ",...A])}warn(...A){let R=`[ ${Date.now()} ] - WARN`;this.name&&(R+=` - ${this.name}`),console.warn.apply(console,[R,": ",...A])}info(...A){let R=`[ ${Date.now()} ] - INFO`;this.name&&(R+=` - ${this.name}`),console.info.apply(console,[R,": ",...A])}};var O="UTILS",I=!1,N=new S(O,process.env.DEBUG==="true"||I),_=3e3,i=30,G=2e4,T=t=>{if(!process.env.CLOUD_API_ACCESS_TOKEN&&!t?.accessToken)throw N.log("Environmental variable: CLOUD_API_ACCESS_TOKEN and/or access token argument is undefined."),new Error("Missing WhatsApp access token.")},L=t=>{T(t);let A={M4D_APP_ID:t?.appId||process.env.M4D_APP_ID||"",M4D_APP_SECRET:t?.appSecret||process.env.M4D_APP_SECRET||"",WA_PHONE_NUMBER_ID:t?.phoneNumberId||Number(process.env.WA_PHONE_NUMBER_ID),WA_BUSINESS_ACCOUNT_ID:t?.businessAcctId||process.env.WA_BUSINESS_ACCOUNT_ID||"",CLOUD_API_VERSION:t?.apiVersion||process.env.CLOUD_API_VERSION||"",CLOUD_API_ACCESS_TOKEN:t?.accessToken||process.env.CLOUD_API_ACCESS_TOKEN||"",WEBHOOK_ENDPOINT:t?.webhookEndpoint||process.env.WEBHOOK_ENDPOINT||"",WEBHOOK_VERIFICATION_TOKEN:t?.webhookVerificationToken||process.env.WEBHOOK_VERIFICATION_TOKEN||"",LISTENER_PORT:t?.listenerPort||parseInt(process.env.LISTENER_PORT||"")||_,MAX_RETRIES_AFTER_WAIT:t?.maxRetriesAfterWait||parseInt(process.env.MAX_RETRIES_AFTER_WAIT||"")||i,REQUEST_TIMEOUT:t?.requestTimeout||parseInt(process.env.REQUEST_TIMEOUT||"")||G,DEBUG:t?.debug||process.env.DEBUG==="true"};return N.log(`Configuration loaded for App Id ${A.M4D_APP_ID}`),A};function X(t){return t!=null&&typeof t=="object"&&"error"in t&&typeof t.error=="object"&&t.error!=null&&"message"in t.error&&typeof t.error.message=="string"&&"type"in t.error&&typeof t.error.type=="string"&&"code"in t.error&&typeof t.error.code=="number"&&"fbtrace_id"in t.error&&typeof t.error.fbtrace_id=="string"&&(!("error_data"in t.error)||typeof t.error.error_data=="object"&&t.error.error_data!=null&&"messaging_product"in t.error.error_data&&t.error.error_data.messaging_product==="whatsapp"&&"details"in t.error.error_data&&typeof t.error.error_data.details=="string")&&(!("error_subcode"in t.error)||typeof t.error.error_subcode=="number")}var Y=t=>{if(!t||Object.keys(t).length===0)return"";let A=new URLSearchParams;for(let[U,D]of Object.entries(t))D!==void 0&&A.append(U,String(D));let R=A.toString();return R?`?${R}`:""};export{B as generateXHub256Sig,L as importConfig,X as isMetaError,Y as objectToQueryString};
|
|
2
2
|
//# sourceMappingURL=index.mjs.map
|
package/dist/utils/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utils/generateXHub256Sig.ts","../../src/utils/logger.ts","../../src/utils/importConfig.ts","../../src/utils/isMetaError.ts","../../src/utils/objectToQueryString.ts"],"sourcesContent":["import * as crypto from 'crypto';\n\nexport const generateXHub256Sig = (body: string, appSecret: string) => {\n return crypto.createHmac('sha256', appSecret).update(body, 'utf-8').digest('hex');\n};\n","// @ts-nocheck\nimport type { LoggerInterface } from '../types/logger';\n\nexport default class Logger implements LoggerInterface {\n private name: string;\n private debug: boolean;\n\n constructor(name: string, debug: boolean = false) {\n this.name = name;\n this.debug = debug;\n }\n\n log(...data: any[]) {\n if (this.debug) {\n let prefix = `[ ${Date.now()} ]`;\n if (this.name) {\n prefix += ` - ${this.name}`;\n }\n console.log.apply(console, [prefix, ': ', ...data]);\n }\n }\n\n error(...data: any[]) {\n let prefix = `[ ${Date.now()} ] - ERROR`;\n if (this.name) {\n prefix += ` - ${this.name}`;\n }\n console.error.apply(console, [prefix, ': ', ...data]);\n }\n\n warn(...data: any[]) {\n let prefix = `[ ${Date.now()} ] - WARN`;\n if (this.name) {\n prefix += ` - ${this.name}`;\n }\n console.warn.apply(console, [prefix, ': ', ...data]);\n }\n\n info(...data: any[]) {\n let prefix = `[ ${Date.now()} ] - INFO`;\n if (this.name) {\n prefix += ` - ${this.name}`;\n }\n console.info.apply(console, [prefix, ': ', ...data]);\n }\n}\n","import { WhatsAppConfig } from 'src/types/whatsapp';\nimport type { WabaConfigType } from '../types/config';\nimport { WabaConfigEnum } from '../types/enums';\nimport Logger from './logger';\n\nconst LIB_NAME = 'UTILS';\nconst LOG_LOCAL = false;\nconst LOGGER = new Logger(LIB_NAME, process.env.DEBUG === 'true' || LOG_LOCAL);\nconst
|
|
1
|
+
{"version":3,"sources":["../../src/utils/generateXHub256Sig.ts","../../src/utils/logger.ts","../../src/utils/importConfig.ts","../../src/utils/isMetaError.ts","../../src/utils/objectToQueryString.ts"],"sourcesContent":["import * as crypto from 'crypto';\n\nexport const generateXHub256Sig = (body: string, appSecret: string) => {\n return crypto.createHmac('sha256', appSecret).update(body, 'utf-8').digest('hex');\n};\n","// @ts-nocheck\nimport type { LoggerInterface } from '../types/logger';\n\nexport default class Logger implements LoggerInterface {\n private name: string;\n private debug: boolean;\n\n constructor(name: string, debug: boolean = false) {\n this.name = name;\n this.debug = debug;\n }\n\n log(...data: any[]) {\n if (this.debug) {\n let prefix = `[ ${Date.now()} ]`;\n if (this.name) {\n prefix += ` - ${this.name}`;\n }\n console.log.apply(console, [prefix, ': ', ...data]);\n }\n }\n\n error(...data: any[]) {\n let prefix = `[ ${Date.now()} ] - ERROR`;\n if (this.name) {\n prefix += ` - ${this.name}`;\n }\n console.error.apply(console, [prefix, ': ', ...data]);\n }\n\n warn(...data: any[]) {\n let prefix = `[ ${Date.now()} ] - WARN`;\n if (this.name) {\n prefix += ` - ${this.name}`;\n }\n console.warn.apply(console, [prefix, ': ', ...data]);\n }\n\n info(...data: any[]) {\n let prefix = `[ ${Date.now()} ] - INFO`;\n if (this.name) {\n prefix += ` - ${this.name}`;\n }\n console.info.apply(console, [prefix, ': ', ...data]);\n }\n}\n","import { WhatsAppConfig } from 'src/types/whatsapp';\nimport type { WabaConfigType } from '../types/config';\nimport { WabaConfigEnum } from '../types/enums';\nimport Logger from './logger';\n\nconst LIB_NAME = 'UTILS';\nconst LOG_LOCAL = false;\nconst LOGGER = new Logger(LIB_NAME, process.env.DEBUG === 'true' || LOG_LOCAL);\nconst DEFAULT_LISTENER_PORT = 3000;\nconst DEFAULT_MAX_RETRIES_AFTER_WAIT = 30;\nconst DEFAULT_REQUEST_TIMEOUT = 20000;\n\nconst emptyConfigChecker = (config: WhatsAppConfig | undefined) => {\n if (!process.env[WabaConfigEnum.AccessToken] && !config?.accessToken) {\n LOGGER.log(`Environmental variable: CLOUD_API_ACCESS_TOKEN and/or access token argument is undefined.`);\n throw new Error('Missing WhatsApp access token.');\n }\n};\n\nexport const importConfig = (inputConfig?: WhatsAppConfig) => {\n emptyConfigChecker(inputConfig);\n\n const wabaConfig: WabaConfigType = {\n [WabaConfigEnum.AppId]: inputConfig?.appId || process.env.M4D_APP_ID || '',\n [WabaConfigEnum.AppSecret]: inputConfig?.appSecret || process.env.M4D_APP_SECRET || '',\n [WabaConfigEnum.PhoneNumberId]: inputConfig?.phoneNumberId || Number(process.env.WA_PHONE_NUMBER_ID),\n [WabaConfigEnum.BusinessAcctId]: inputConfig?.businessAcctId || process.env.WA_BUSINESS_ACCOUNT_ID || '',\n [WabaConfigEnum.APIVersion]: inputConfig?.apiVersion || process.env.CLOUD_API_VERSION || '',\n [WabaConfigEnum.AccessToken]: inputConfig?.accessToken || process.env.CLOUD_API_ACCESS_TOKEN || '',\n [WabaConfigEnum.WebhookEndpoint]: inputConfig?.webhookEndpoint || process.env.WEBHOOK_ENDPOINT || '',\n [WabaConfigEnum.WebhookVerificationToken]:\n inputConfig?.webhookVerificationToken || process.env.WEBHOOK_VERIFICATION_TOKEN || '',\n [WabaConfigEnum.ListenerPort]:\n inputConfig?.listenerPort || parseInt(process.env.LISTENER_PORT || '') || DEFAULT_LISTENER_PORT,\n [WabaConfigEnum.MaxRetriesAfterWait]:\n inputConfig?.maxRetriesAfterWait ||\n parseInt(process.env.MAX_RETRIES_AFTER_WAIT || '') ||\n DEFAULT_MAX_RETRIES_AFTER_WAIT,\n [WabaConfigEnum.RequestTimeout]:\n inputConfig?.requestTimeout || parseInt(process.env.REQUEST_TIMEOUT || '') || DEFAULT_REQUEST_TIMEOUT,\n [WabaConfigEnum.Debug]: inputConfig?.debug || process.env.DEBUG === 'true',\n };\n\n LOGGER.log(`Configuration loaded for App Id ${wabaConfig[WabaConfigEnum.AppId]}`);\n\n return wabaConfig;\n};\n","export interface MetaError extends Error {\n error: {\n message: string;\n type: string;\n code: number;\n error_data?: {\n messaging_product: 'whatsapp';\n details: string;\n };\n error_subcode?: number;\n fbtrace_id: string;\n };\n}\n\n/**\n * Determines if the error is a Meta API error response\n * @param error Any error object to check\n * @returns Type guard indicating if error is a Meta API error\n */\nexport function isMetaError(error: any): error is MetaError {\n return (\n error != null &&\n typeof error === 'object' &&\n 'error' in error &&\n typeof error.error === 'object' &&\n error.error != null &&\n 'message' in error.error &&\n typeof error.error.message === 'string' &&\n 'type' in error.error &&\n typeof error.error.type === 'string' &&\n 'code' in error.error &&\n typeof error.error.code === 'number' &&\n 'fbtrace_id' in error.error &&\n typeof error.error.fbtrace_id === 'string' &&\n (!('error_data' in error.error) ||\n (typeof error.error.error_data === 'object' &&\n error.error.error_data != null &&\n 'messaging_product' in error.error.error_data &&\n error.error.error_data.messaging_product === 'whatsapp' &&\n 'details' in error.error.error_data &&\n typeof error.error.error_data.details === 'string')) &&\n (!('error_subcode' in error.error) || typeof error.error.error_subcode === 'number')\n );\n}\n","export const objectToQueryString = (params: Record<string, any>): string => {\n if (!params || Object.keys(params).length === 0) {\n return '';\n }\n\n const searchParams = new URLSearchParams();\n\n for (const [key, value] of Object.entries(params)) {\n if (value !== undefined) {\n searchParams.append(key, String(value));\n }\n }\n\n const queryString = searchParams.toString();\n return queryString ? `?${queryString}` : '';\n};\n"],"mappings":"AAAA,UAAYA,MAAY,SAEjB,IAAMC,EAAqB,CAACC,EAAc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M,YACnCA,EAAM,MAAM,WAAW,oBAAsB,YAC7C,YAAaA,EAAM,MAAM,YACzB,OAAOA,EAAM,MAAM,WAAW,SAAY,YACjD,EAAE,kBAAmBA,EAAM,QAAU,OAAOA,EAAM,MAAM,eAAkB,SAEnF,CC3CO,IAAMC,EAAuBC,GAAwC,CACxE,GAAI,CAACA,GAAU,OAAO,KAAKA,CAAM,EAAE,SAAW,EAC1C,MAAO,GAGX,IAAMC,EAAe,IAAI,gBAEzB,OAAW,CAACC,EAAKC,CAAK,IAAK,OAAO,QAAQH,CAAM,EACxCG,IAAU,QACVF,EAAa,OAAOC,EAAK,OAAOC,CAAK,CAAC,EAI9C,IAAMC,EAAcH,EAAa,SAAS,EAC1C,OAAOG,EAAc,IAAIA,CAAW,GAAK,EAC7C","names":["crypto","generateXHub256Sig","body","appSecret","Logger","name","debug","data","prefix","LIB_NAME","LOG_LOCAL","LOGGER","Logger","DEFAULT_LISTENER_PORT","DEFAULT_MAX_RETRIES_AFTER_WAIT","DEFAULT_REQUEST_TIMEOUT","emptyConfigChecker","config","importConfig","inputConfig","wabaConfig","isMetaError","error","objectToQueryString","params","searchParams","key","value","queryString"]}
|
package/dist/webhook.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { M as MessageTypesEnum } from './enums-
|
|
1
|
+
import { M as MessageTypesEnum } from './enums-Bcd3jLw2.mjs';
|
|
2
2
|
import { WebhookMessage, WebhookEvent } from './types/webhook.mjs';
|
|
3
3
|
import { WhatsAppConfig } from './types/whatsapp.mjs';
|
|
4
4
|
import WhatsApp from './whatsapp.mjs';
|
package/dist/webhook.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { M as MessageTypesEnum } from './enums-
|
|
1
|
+
import { M as MessageTypesEnum } from './enums-Bcd3jLw2.js';
|
|
2
2
|
import { WebhookMessage, WebhookEvent } from './types/webhook.js';
|
|
3
3
|
import { WhatsAppConfig } from './types/whatsapp.js';
|
|
4
4
|
import WhatsApp from './whatsapp.js';
|