meta-cloud-api 0.2.14 → 0.2.16
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/dist/BusinessProfileApi-DDkv2WQK.d.ts +352 -0
- package/dist/EncryptionApi-CwxQlC-2.d.ts +21 -0
- package/dist/FlowApi-BIBrWYEv.d.ts +471 -0
- package/dist/MediaApi-VqxndaBJ.d.ts +89 -0
- package/dist/MessageApi-CHc6bn3g.d.ts +591 -0
- package/dist/PhoneNumberApi-C-bs6YAe.d.ts +141 -0
- package/dist/QrCodeApi-BjlyPUXV.d.ts +97 -0
- package/dist/RegistrationApi-D7Bg8BUz.d.ts +46 -0
- package/dist/TemplateApi-dmZbvMkO.d.ts +117 -0
- package/dist/TwoStepVerificationApi-DaYWPjY_.d.ts +32 -0
- package/dist/WabaApi-CMoTCWiH.d.ts +174 -0
- package/dist/base-BG2gtoDs.d.ts +46 -0
- package/dist/chunk-2NJVBJUN.js +2 -0
- package/dist/chunk-2NJVBJUN.js.map +1 -0
- package/dist/chunk-3MO3BTBC.js +2 -0
- package/dist/chunk-3MO3BTBC.js.map +1 -0
- package/dist/chunk-4C666HHU.js +2 -0
- package/dist/chunk-4C666HHU.js.map +1 -0
- package/dist/chunk-5JGM556C.js +2 -0
- package/dist/chunk-5JGM556C.js.map +1 -0
- package/dist/chunk-7GL74SXM.js +2 -0
- package/dist/chunk-7GL74SXM.js.map +1 -0
- package/dist/chunk-7NQLQPLH.js +2 -0
- package/dist/chunk-7NQLQPLH.js.map +1 -0
- package/dist/chunk-A264MT4Q.js +2 -0
- package/dist/chunk-A264MT4Q.js.map +1 -0
- package/dist/chunk-BZ5QDXNR.js +2 -0
- package/dist/chunk-BZ5QDXNR.js.map +1 -0
- package/dist/chunk-EYGUX4EA.js +2 -0
- package/dist/chunk-EYGUX4EA.js.map +1 -0
- package/dist/chunk-FFOE5YKT.js +2 -0
- package/dist/chunk-FFOE5YKT.js.map +1 -0
- package/dist/chunk-GIQLIMOD.js +2 -0
- package/dist/chunk-GIQLIMOD.js.map +1 -0
- package/dist/chunk-KFPOVYEJ.js +2 -0
- package/dist/chunk-KFPOVYEJ.js.map +1 -0
- package/dist/chunk-O2OTHNWM.js +2 -0
- package/dist/chunk-O2OTHNWM.js.map +1 -0
- package/dist/chunk-UQPD6GIF.js +2 -0
- package/dist/chunk-UQPD6GIF.js.map +1 -0
- package/dist/chunk-VW3LGHTJ.js +2 -0
- package/dist/chunk-VW3LGHTJ.js.map +1 -0
- package/dist/chunk-XIIJD6SG.js +2 -0
- package/dist/chunk-XIIJD6SG.js.map +1 -0
- package/dist/chunk-XPPDOFBN.js +2 -0
- package/dist/chunk-XPPDOFBN.js.map +1 -0
- package/dist/enums-Z1f7QuVx.d.ts +687 -0
- package/dist/features/encryption/index.d.ts +9 -0
- package/dist/features/encryption/index.js +2 -0
- package/dist/{types/index.mjs.map → features/encryption/index.js.map} +1 -1
- package/dist/features/flow/index.d.ts +9 -0
- package/dist/features/flow/index.js +2 -0
- package/dist/{utils/index.mjs.map → features/flow/index.js.map} +1 -1
- package/dist/features/media/index.d.ts +9 -0
- package/dist/features/media/index.js +2 -0
- package/dist/{api/index.mjs.map → features/media/index.js.map} +1 -1
- package/dist/features/messages/index.d.ts +9 -0
- package/dist/features/messages/index.js +2 -0
- package/dist/features/messages/index.js.map +1 -0
- package/dist/features/phone/index.d.ts +9 -0
- package/dist/features/phone/index.js +2 -0
- package/dist/features/phone/index.js.map +1 -0
- package/dist/features/profile/index.d.ts +9 -0
- package/dist/features/profile/index.js +2 -0
- package/dist/features/profile/index.js.map +1 -0
- package/dist/features/qrCode/index.d.ts +9 -0
- package/dist/features/qrCode/index.js +2 -0
- package/dist/features/qrCode/index.js.map +1 -0
- package/dist/features/registration/index.d.ts +9 -0
- package/dist/features/registration/index.js +2 -0
- package/dist/features/registration/index.js.map +1 -0
- package/dist/features/template/index.d.ts +9 -0
- package/dist/features/template/index.js +2 -0
- package/dist/features/template/index.js.map +1 -0
- package/dist/features/twoStepVerification/index.d.ts +9 -0
- package/dist/features/twoStepVerification/index.js +2 -0
- package/dist/features/twoStepVerification/index.js.map +1 -0
- package/dist/features/waba/index.d.ts +9 -0
- package/dist/features/waba/index.js +2 -0
- package/dist/features/waba/index.js.map +1 -0
- package/dist/{types/index.d.mts → index.d.ts} +222 -72
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -0
- package/dist/shared/types/config.d.ts +78 -0
- package/dist/shared/types/config.js +2 -0
- package/dist/shared/types/config.js.map +1 -0
- package/dist/shared/types/enums.d.ts +1 -0
- package/dist/shared/types/enums.js +2 -0
- package/dist/shared/types/enums.js.map +1 -0
- package/dist/shared/utils/isMetaError.d.ts +21 -0
- package/dist/shared/utils/isMetaError.js +2 -0
- package/dist/shared/utils/isMetaError.js.map +1 -0
- package/package.json +81 -15
- package/dist/api/index.d.mts +0 -496
- package/dist/api/index.mjs +0 -2
- package/dist/chunk-KZQQJAPX.mjs +0 -2
- package/dist/chunk-KZQQJAPX.mjs.map +0 -1
- package/dist/chunk-N7A7DQDX.mjs +0 -2
- package/dist/chunk-N7A7DQDX.mjs.map +0 -1
- package/dist/chunk-QE4PKOSW.mjs +0 -2
- package/dist/chunk-QE4PKOSW.mjs.map +0 -1
- package/dist/chunk-R4CFE2XP.mjs +0 -2
- package/dist/chunk-R4CFE2XP.mjs.map +0 -1
- package/dist/chunk-XVYL7ZTG.mjs +0 -2
- package/dist/chunk-XVYL7ZTG.mjs.map +0 -1
- package/dist/index.d.mts +0 -145
- package/dist/index.mjs +0 -3
- package/dist/index.mjs.map +0 -1
- package/dist/types/index.mjs +0 -2
- package/dist/utils/index.d.mts +0 -71
- package/dist/utils/index.mjs +0 -2
- package/dist/waba-RRlZTQUG.d.mts +0 -2229
- package/dist/whatsapp-BNHXjrds.d.mts +0 -46
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { F as FlowApi } from '../../FlowApi-BIBrWYEv.js';
|
|
2
|
+
export { C as CreateFlowResponse, c as Flow, f as FlowActionEnum, g as FlowAssetsResponse, h as FlowCategoryEnum, d as FlowClass, a as FlowEndpointRequest, e as FlowEndpointResponse, i as FlowMigrationResponse, j as FlowPreviewResponse, l as FlowStatusEnum, m as FlowValidationError, k as FlowsListResponse, U as UpdateFlowResponse, V as ValidateFlowJsonResponse } from '../../FlowApi-BIBrWYEv.js';
|
|
3
|
+
import '../../base-BG2gtoDs.js';
|
|
4
|
+
import '../../shared/types/config.js';
|
|
5
|
+
import '../../enums-Z1f7QuVx.js';
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
export { FlowApi, FlowApi as default };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":[],"names":[],"mappings":"","file":"index.
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"index.js"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { M as MediaApi } from '../../MediaApi-VqxndaBJ.js';
|
|
2
|
+
export { a as MediaClass, b as MediaResponse, c as MediasResponse, U as UploadMediaResponse } from '../../MediaApi-VqxndaBJ.js';
|
|
3
|
+
import '../../base-BG2gtoDs.js';
|
|
4
|
+
import '../../shared/types/config.js';
|
|
5
|
+
import '../../enums-Z1f7QuVx.js';
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
export { MediaApi, MediaApi as default };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":[],"names":[],"mappings":"","file":"index.
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"index.js"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { M as MessagesApi } from '../../MessageApi-CHc6bn3g.js';
|
|
2
|
+
export { A as AudioMediaObject, C as ContactObject, D as DocumentMediaObject, I as ImageMediaObject, a as InteractiveObject, L as LocationObject, b as MessageRequestParams, d as MessageTemplateObject, c as MessagesResponse, R as ReactionParams, S as StatusParams, e as StickerMediaObject, T as TextMessageParams, f as TextObject, V as VideoMediaObject } from '../../MessageApi-CHc6bn3g.js';
|
|
3
|
+
import '../../base-BG2gtoDs.js';
|
|
4
|
+
import '../../shared/types/config.js';
|
|
5
|
+
import '../../enums-Z1f7QuVx.js';
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
export { MessagesApi as MessageApi, MessagesApi as default };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"index.js"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { P as PhoneNumberApi } from '../../PhoneNumberApi-C-bs6YAe.js';
|
|
2
|
+
export { A as AccountMode, C as CodeVerificationStatus, c as Cursors, H as HealthStatus, d as HealthStatusEntity, M as MessagingLimitTier, a as PhoneNumberClass, b as PhoneNumberResponse, e as PhoneNumbersResponse, f as PlatformType, Q as QualityRating, g as QualityScore, R as RequestVerificationCodeRequest, T as Throughput, h as ThroughputLevel, i as TwoStepVerificationParams, V as VerifyCodeRequest } from '../../PhoneNumberApi-C-bs6YAe.js';
|
|
3
|
+
import '../../base-BG2gtoDs.js';
|
|
4
|
+
import '../../shared/types/config.js';
|
|
5
|
+
import '../../enums-Z1f7QuVx.js';
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
export { PhoneNumberApi, PhoneNumberApi as default };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"index.js"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { B as BusinessProfileApi } from '../../BusinessProfileApi-DDkv2WQK.js';
|
|
2
|
+
export { a as BusinessProfileClass, c as BusinessProfileData, d as BusinessProfileField, e as BusinessProfileFieldsParam, b as BusinessProfileResponse, C as CreateUploadSessionParams, G as GetUploadHandleParams, U as UpdateBusinessProfileRequest, f as UploadBusinessProfileResponse, g as UploadHandle, h as UploadMediaParams, i as UploadSession, j as UploadSessionResponse } from '../../BusinessProfileApi-DDkv2WQK.js';
|
|
3
|
+
import '../../base-BG2gtoDs.js';
|
|
4
|
+
import '../../shared/types/config.js';
|
|
5
|
+
import '../../enums-Z1f7QuVx.js';
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
export { BusinessProfileApi, BusinessProfileApi as default };
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
export{a as BusinessProfileApi,b as default}from'../../chunk-KFPOVYEJ.js';import'../../chunk-7GL74SXM.js';import'../../chunk-BZ5QDXNR.js';import'../../chunk-VW3LGHTJ.js';import'../../chunk-EYGUX4EA.js';import'../../chunk-4C666HHU.js';//# sourceMappingURL=index.js.map
|
|
2
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"index.js"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Q as QrCodeApi } from '../../QrCodeApi-BjlyPUXV.js';
|
|
2
|
+
export { C as CreateQrCodeRequest, a as QrCodeClass, b as QrCodeResponse, c as QrCodesResponse, U as UpdateQrCodeRequest } from '../../QrCodeApi-BjlyPUXV.js';
|
|
3
|
+
import '../../base-BG2gtoDs.js';
|
|
4
|
+
import '../../shared/types/config.js';
|
|
5
|
+
import '../../enums-Z1f7QuVx.js';
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
export { QrCodeApi, QrCodeApi as default };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"index.js"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { R as RegistrationApi } from '../../RegistrationApi-D7Bg8BUz.js';
|
|
2
|
+
export { a as RegistrationClass, b as RegistrationRequest } from '../../RegistrationApi-D7Bg8BUz.js';
|
|
3
|
+
import '../../base-BG2gtoDs.js';
|
|
4
|
+
import '../../shared/types/config.js';
|
|
5
|
+
import '../../enums-Z1f7QuVx.js';
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
export { RegistrationApi, RegistrationApi as default };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"index.js"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { T as TemplateApi } from '../../TemplateApi-dmZbvMkO.js';
|
|
2
|
+
export { a as TemplateClass, c as TemplateDeleteParams, d as TemplateGetParams, e as TemplateRequestBody, b as TemplateResponse } from '../../TemplateApi-dmZbvMkO.js';
|
|
3
|
+
import '../../base-BG2gtoDs.js';
|
|
4
|
+
import '../../shared/types/config.js';
|
|
5
|
+
import '../../enums-Z1f7QuVx.js';
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
export { TemplateApi, TemplateApi as default };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"index.js"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { T as TwoStepVerificationApi } from '../../TwoStepVerificationApi-DaYWPjY_.js';
|
|
2
|
+
export { a as TwoStepVerificationClass, b as TwoStepVerificationRequest } from '../../TwoStepVerificationApi-DaYWPjY_.js';
|
|
3
|
+
import '../../base-BG2gtoDs.js';
|
|
4
|
+
import '../../shared/types/config.js';
|
|
5
|
+
import '../../enums-Z1f7QuVx.js';
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
export { TwoStepVerificationApi, TwoStepVerificationApi as default };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"index.js"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { W as WabaApi } from '../../WabaApi-CMoTCWiH.js';
|
|
2
|
+
export { U as UpdateWabaSubscription, b as WABAClass, a as WabaAccount, c as WabaSubscriptions } from '../../WabaApi-CMoTCWiH.js';
|
|
3
|
+
import '../../base-BG2gtoDs.js';
|
|
4
|
+
import '../../shared/types/config.js';
|
|
5
|
+
import '../../enums-Z1f7QuVx.js';
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
export { WabaApi, WabaApi as default };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"index.js"}
|
|
@@ -1,51 +1,31 @@
|
|
|
1
|
-
import { H as HttpMethodsEnum,
|
|
2
|
-
export { a
|
|
3
|
-
|
|
4
|
-
import 'http';
|
|
1
|
+
import { M as MessageTypesEnum, H as HttpMethodsEnum, S as SDKEnums } from './enums-Z1f7QuVx.js';
|
|
2
|
+
export { a as StatusEnum, W as WebhookTypesEnum } from './enums-Z1f7QuVx.js';
|
|
3
|
+
import { WhatsAppConfig, WabaConfigType } from './shared/types/config.js';
|
|
4
|
+
import { IncomingMessage } from 'http';
|
|
5
|
+
import { F as FlowApi, a as FlowEndpointRequest, b as FlowTypeEnum } from './FlowApi-BIBrWYEv.js';
|
|
6
|
+
export { c as Flow, d as FlowClass, e as FlowEndpointResponse } from './FlowApi-BIBrWYEv.js';
|
|
7
|
+
import { E as EncryptionApi } from './EncryptionApi-CwxQlC-2.js';
|
|
8
|
+
import { M as MediaApi } from './MediaApi-VqxndaBJ.js';
|
|
9
|
+
export { a as MediaClass, b as MediaResponse, c as MediasResponse, U as UploadMediaResponse } from './MediaApi-VqxndaBJ.js';
|
|
10
|
+
import { M as MessagesApi } from './MessageApi-CHc6bn3g.js';
|
|
11
|
+
export { A as AudioMediaObject, C as ContactObject, D as DocumentMediaObject, I as ImageMediaObject, a as InteractiveObject, L as LocationObject, b as MessageRequestParams, d as MessageTemplateObject, c as MessagesResponse, R as ReactionParams, S as StatusParams, e as StickerMediaObject, T as TextMessageParams, f as TextObject, V as VideoMediaObject } from './MessageApi-CHc6bn3g.js';
|
|
12
|
+
import { P as PhoneNumberApi } from './PhoneNumberApi-C-bs6YAe.js';
|
|
13
|
+
export { a as PhoneNumberClass, b as PhoneNumberResponse } from './PhoneNumberApi-C-bs6YAe.js';
|
|
14
|
+
import { B as BusinessProfileApi } from './BusinessProfileApi-DDkv2WQK.js';
|
|
15
|
+
export { a as BusinessProfileClass, b as BusinessProfileResponse } from './BusinessProfileApi-DDkv2WQK.js';
|
|
16
|
+
import { Q as QrCodeApi } from './QrCodeApi-BjlyPUXV.js';
|
|
17
|
+
export { a as QrCodeClass, b as QrCodeResponse } from './QrCodeApi-BjlyPUXV.js';
|
|
18
|
+
import { R as RegistrationApi } from './RegistrationApi-D7Bg8BUz.js';
|
|
19
|
+
export { a as RegistrationClass } from './RegistrationApi-D7Bg8BUz.js';
|
|
20
|
+
import { T as TemplateApi } from './TemplateApi-dmZbvMkO.js';
|
|
21
|
+
export { a as TemplateClass, b as TemplateResponse } from './TemplateApi-dmZbvMkO.js';
|
|
22
|
+
import { T as TwoStepVerificationApi } from './TwoStepVerificationApi-DaYWPjY_.js';
|
|
23
|
+
import { W as WabaApi } from './WabaApi-CMoTCWiH.js';
|
|
24
|
+
export { b as WABAClass, a as WabaAccount } from './WabaApi-CMoTCWiH.js';
|
|
25
|
+
import { Agent } from 'https';
|
|
26
|
+
import { R as RequesterClass } from './base-BG2gtoDs.js';
|
|
27
|
+
export { MetaError, isMetaError } from './shared/utils/isMetaError.js';
|
|
5
28
|
|
|
6
|
-
type ResponseHeaderValue = string | string[] | undefined;
|
|
7
|
-
type ResponseHeaders = Record<string, ResponseHeaderValue>;
|
|
8
|
-
type ResponseJSONBody = Record<string, unknown>;
|
|
9
|
-
declare class HttpsClientResponseClass {
|
|
10
|
-
constructor(resp: Response);
|
|
11
|
-
statusCode: () => number;
|
|
12
|
-
headers: () => ResponseHeaders;
|
|
13
|
-
rawResponse: () => Response;
|
|
14
|
-
json: () => Promise<ResponseJSONBody>;
|
|
15
|
-
}
|
|
16
|
-
declare class HttpsClientClass {
|
|
17
|
-
constructor();
|
|
18
|
-
clearSockets: () => boolean;
|
|
19
|
-
sendRequest: (host: string, path: string, method: HttpMethodsEnum, headers: HeadersInit, timeout: number, body?: BodyInit | null) => Promise<HttpsClientResponseClass>;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
interface LoggerInterface {
|
|
23
|
-
log(...data: any[]): void;
|
|
24
|
-
error(...data: any[]): void;
|
|
25
|
-
warn(...data: any[]): void;
|
|
26
|
-
info(...data: any[]): void;
|
|
27
|
-
debug(...data: any[]): void;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
interface WebhookContact {
|
|
31
|
-
/**
|
|
32
|
-
* WhatsApp ID of the contact. Business can respond to this contact using this ID.
|
|
33
|
-
*/
|
|
34
|
-
wa_id: string;
|
|
35
|
-
/**
|
|
36
|
-
* Additional unique, alphanumeric identifier for a WhatsApp user
|
|
37
|
-
*/
|
|
38
|
-
user_id?: string;
|
|
39
|
-
/**
|
|
40
|
-
* Profile of Whatsapp user
|
|
41
|
-
*/
|
|
42
|
-
profile: {
|
|
43
|
-
/**
|
|
44
|
-
* The display name of the contact
|
|
45
|
-
*/
|
|
46
|
-
name: string;
|
|
47
|
-
};
|
|
48
|
-
}
|
|
49
29
|
/**
|
|
50
30
|
* Represents a message received through the webhook
|
|
51
31
|
* Based on Meta's documentation: https://developers.facebook.com/docs/whatsapp/cloud-api/webhooks/components#messages-object
|
|
@@ -210,11 +190,29 @@ interface WebhookMessage {
|
|
|
210
190
|
* The contact's name
|
|
211
191
|
*/
|
|
212
192
|
name: {
|
|
193
|
+
/**
|
|
194
|
+
* The formatted name
|
|
195
|
+
*/
|
|
213
196
|
formatted_name: string;
|
|
197
|
+
/**
|
|
198
|
+
* The first name
|
|
199
|
+
*/
|
|
214
200
|
first_name?: string;
|
|
201
|
+
/**
|
|
202
|
+
* The last name
|
|
203
|
+
*/
|
|
215
204
|
last_name?: string;
|
|
205
|
+
/**
|
|
206
|
+
* The middle name
|
|
207
|
+
*/
|
|
216
208
|
middle_name?: string;
|
|
209
|
+
/**
|
|
210
|
+
* The suffix
|
|
211
|
+
*/
|
|
217
212
|
suffix?: string;
|
|
213
|
+
/**
|
|
214
|
+
* The prefix
|
|
215
|
+
*/
|
|
218
216
|
prefix?: string;
|
|
219
217
|
};
|
|
220
218
|
/**
|
|
@@ -470,7 +468,7 @@ interface WebhookMessage {
|
|
|
470
468
|
originalData: any;
|
|
471
469
|
}
|
|
472
470
|
/**
|
|
473
|
-
*
|
|
471
|
+
* Webhook event received from WhatsApp
|
|
474
472
|
*/
|
|
475
473
|
interface WebhookEvent {
|
|
476
474
|
/**
|
|
@@ -481,33 +479,185 @@ interface WebhookEvent {
|
|
|
481
479
|
* The event data
|
|
482
480
|
*/
|
|
483
481
|
value: any;
|
|
482
|
+
/**
|
|
483
|
+
* The timestamp when the event was received
|
|
484
|
+
*/
|
|
485
|
+
timestamp: number;
|
|
484
486
|
}
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
type
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
declare
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
487
|
+
|
|
488
|
+
type ResponseHeaderValue = string | string[] | undefined;
|
|
489
|
+
type ResponseHeaders = Record<string, ResponseHeaderValue>;
|
|
490
|
+
type ResponseJSONBody = Record<string, unknown>;
|
|
491
|
+
declare class HttpsClientResponseClass {
|
|
492
|
+
constructor(resp: Response);
|
|
493
|
+
statusCode: () => number;
|
|
494
|
+
headers: () => ResponseHeaders;
|
|
495
|
+
rawResponse: () => Response;
|
|
496
|
+
json: () => Promise<ResponseJSONBody>;
|
|
497
|
+
}
|
|
498
|
+
declare class HttpsClientClass {
|
|
499
|
+
constructor();
|
|
500
|
+
clearSockets: () => boolean;
|
|
501
|
+
sendRequest: (host: string, path: string, method: HttpMethodsEnum, headers: HeadersInit, timeout: number, body?: BodyInit | null) => Promise<HttpsClientResponseClass>;
|
|
502
|
+
}
|
|
503
|
+
|
|
504
|
+
declare class WhatsAppClass {
|
|
505
|
+
constructor(config?: WhatsAppConfig);
|
|
506
|
+
readonly messages: MessagesApi;
|
|
507
|
+
readonly templates: TemplateApi;
|
|
508
|
+
readonly phoneNumber: PhoneNumberApi;
|
|
509
|
+
readonly qrCode: QrCodeApi;
|
|
510
|
+
readonly encryption: EncryptionApi;
|
|
511
|
+
readonly twoStepVerification: TwoStepVerificationApi;
|
|
512
|
+
readonly registration: RegistrationApi;
|
|
513
|
+
readonly media: MediaApi;
|
|
514
|
+
readonly waba: WabaApi;
|
|
515
|
+
readonly flow: FlowApi;
|
|
516
|
+
readonly businessProfile: BusinessProfileApi;
|
|
517
|
+
updateTimeout(ms: number): boolean;
|
|
518
|
+
updatePhoneNumberId(phoneNumberId: number): boolean;
|
|
519
|
+
updateAccessToken(accessToken: string): boolean;
|
|
520
|
+
updateWabaId(wabaId: string): boolean;
|
|
521
|
+
}
|
|
522
|
+
|
|
523
|
+
declare class HttpsClient implements HttpsClientClass {
|
|
524
|
+
agent: Agent;
|
|
525
|
+
constructor();
|
|
526
|
+
clearSockets(): boolean;
|
|
527
|
+
sendRequest(hostname: string, path: string, method: HttpMethodsEnum, headers: HeadersInit, timeout: number, body?: BodyInit | null): Promise<HttpsClientResponseClass>;
|
|
528
|
+
}
|
|
529
|
+
|
|
530
|
+
declare const importConfig: (inputConfig?: WhatsAppConfig) => WabaConfigType;
|
|
531
|
+
|
|
532
|
+
declare class Requester implements RequesterClass {
|
|
533
|
+
client: Readonly<HttpsClient>;
|
|
534
|
+
accessToken: Readonly<string>;
|
|
535
|
+
phoneNumberId: Readonly<number>;
|
|
536
|
+
businessAcctId: Readonly<string>;
|
|
537
|
+
apiVersion: Readonly<string>;
|
|
538
|
+
userAgent: Readonly<string>;
|
|
539
|
+
host: Readonly<string>;
|
|
540
|
+
protocol: Readonly<string>;
|
|
541
|
+
constructor(apiVersion: string, phoneNumberId: number, accessToken: string, businessAcctId: string, userAgent: string);
|
|
542
|
+
buildHeader(contentType: string, additionalHeaders?: Record<string, string>): HeadersInit;
|
|
543
|
+
buildCAPIPath(endpoint: string): string;
|
|
544
|
+
sendRequest(method: HttpMethodsEnum, endpoint: string, timeout: number, body?: any, contentType?: string, additionalHeaders?: Record<string, string>): Promise<HttpsClientResponseClass>;
|
|
545
|
+
getJson<T>(method: HttpMethodsEnum, endpoint: string, timeout: number, body?: any, additionalHeaders?: Record<string, string>): Promise<T>;
|
|
546
|
+
sendFormData<T>(method: HttpMethodsEnum, endpoint: string, timeout: number, formData: FormData, additionalHeaders?: Record<string, string>): Promise<T>;
|
|
547
|
+
sendUrlEncodedForm<T>(method: HttpMethodsEnum, endpoint: string, timeout: number, formData: Record<string, string>, additionalHeaders?: Record<string, string>): Promise<T>;
|
|
548
|
+
}
|
|
549
|
+
|
|
550
|
+
declare class WhatsApp implements WhatsAppClass {
|
|
551
|
+
config: WabaConfigType;
|
|
552
|
+
requester: Readonly<Requester>;
|
|
553
|
+
readonly messages: MessagesApi;
|
|
554
|
+
readonly templates: TemplateApi;
|
|
555
|
+
readonly phoneNumber: PhoneNumberApi;
|
|
556
|
+
readonly qrCode: QrCodeApi;
|
|
557
|
+
readonly encryption: EncryptionApi;
|
|
558
|
+
readonly twoStepVerification: TwoStepVerificationApi;
|
|
559
|
+
readonly registration: RegistrationApi;
|
|
560
|
+
readonly media: MediaApi;
|
|
561
|
+
readonly waba: WabaApi;
|
|
562
|
+
readonly flow: FlowApi;
|
|
563
|
+
readonly businessProfile: BusinessProfileApi;
|
|
564
|
+
static readonly Enums: typeof SDKEnums;
|
|
565
|
+
constructor(config?: WhatsAppConfig);
|
|
566
|
+
private userAgent;
|
|
567
|
+
updateTimeout(ms: number): boolean;
|
|
568
|
+
updatePhoneNumberId(phoneNumberId: number): boolean;
|
|
569
|
+
updateAccessToken(accessToken: string): boolean;
|
|
570
|
+
updateWabaId(wabaId: string): boolean;
|
|
571
|
+
}
|
|
572
|
+
|
|
573
|
+
interface IRequest extends IncomingMessage {
|
|
574
|
+
body: any;
|
|
575
|
+
query: Record<string, any>;
|
|
576
|
+
method?: string;
|
|
577
|
+
}
|
|
578
|
+
interface IResponse {
|
|
579
|
+
status: (code: number) => IResponse;
|
|
580
|
+
send: (body: any) => IResponse | void;
|
|
581
|
+
json: (body: any) => IResponse | void;
|
|
582
|
+
end: () => void;
|
|
500
583
|
}
|
|
501
584
|
/**
|
|
502
|
-
*
|
|
585
|
+
* Webhook handler for WhatsApp Cloud API
|
|
503
586
|
*/
|
|
504
|
-
declare
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
587
|
+
declare class WebhookHandler {
|
|
588
|
+
private config;
|
|
589
|
+
private client;
|
|
590
|
+
private messageHandlers;
|
|
591
|
+
private eventHandlers;
|
|
592
|
+
private preProcessHandler;
|
|
593
|
+
private postProcessHandler;
|
|
594
|
+
private flowHandlers;
|
|
595
|
+
/**
|
|
596
|
+
* Create a new WebhookHandler
|
|
597
|
+
* @param config The WhatsApp configuration
|
|
598
|
+
*/
|
|
599
|
+
constructor(config: WhatsAppConfig);
|
|
600
|
+
/**
|
|
601
|
+
* Handle a GET request for webhook verification
|
|
602
|
+
*/
|
|
603
|
+
handleVerificationRequest<Req extends IRequest, Res extends IResponse>(req: Req, res: Res): void;
|
|
604
|
+
/**
|
|
605
|
+
* Handle a POST request for webhook events
|
|
606
|
+
*/
|
|
607
|
+
handleWebhookRequest<Req extends IRequest, Res extends IResponse>(req: Req, res: Res): Promise<void>;
|
|
608
|
+
/**
|
|
609
|
+
* Handle webhook requests (both verification and events)
|
|
610
|
+
*/
|
|
611
|
+
handleRequest(req: IRequest, res: IResponse): void | Promise<void>;
|
|
612
|
+
/**
|
|
613
|
+
* Process incoming messages
|
|
614
|
+
*/
|
|
615
|
+
private processMessages;
|
|
616
|
+
/**
|
|
617
|
+
* Process other webhook events
|
|
618
|
+
*/
|
|
619
|
+
private processEvent;
|
|
620
|
+
/**
|
|
621
|
+
* Register a message handler for a specific message type
|
|
622
|
+
*/
|
|
623
|
+
onMessage(type: MessageTypesEnum, handler: (whatsapp: WhatsApp, message: WebhookMessage) => void | Promise<void>): void;
|
|
624
|
+
/**
|
|
625
|
+
* Register an event handler for a specific field
|
|
626
|
+
*/
|
|
627
|
+
onEvent(field: string, handler: (event: WebhookEvent) => void | Promise<void>): void;
|
|
628
|
+
/**
|
|
629
|
+
* Register a pre-process handler that runs before all message handlers
|
|
630
|
+
*/
|
|
631
|
+
onMessagePreProcess(handler: (whatsapp: WhatsApp, message: WebhookMessage) => void | Promise<void>): void;
|
|
632
|
+
/**
|
|
633
|
+
* Register a post-process handler that runs after all message handlers
|
|
634
|
+
*/
|
|
635
|
+
onMessagePostProcess(handler: (whatsapp: WhatsApp, message: WebhookMessage) => void | Promise<void>): void;
|
|
636
|
+
handleFlowRequest<Req extends IRequest & {
|
|
637
|
+
rawBody: string;
|
|
638
|
+
}, Res extends IResponse>(req: Req, res: Res): Promise<void>;
|
|
639
|
+
/**
|
|
640
|
+
* Validate the request signature
|
|
641
|
+
*/
|
|
642
|
+
isRequestSignatureValid(req: IRequest & {
|
|
643
|
+
rawBody: string;
|
|
644
|
+
}): boolean;
|
|
645
|
+
/**
|
|
646
|
+
* Decrypt a flow request
|
|
647
|
+
*/
|
|
648
|
+
decryptRequest(body: any): {
|
|
649
|
+
decryptedBody: FlowEndpointRequest;
|
|
650
|
+
aesKeyBuffer: Buffer;
|
|
651
|
+
initialVectorBuffer: Buffer;
|
|
652
|
+
};
|
|
653
|
+
/**
|
|
654
|
+
* Encrypt a flow response
|
|
655
|
+
*/
|
|
656
|
+
private encryptResponse;
|
|
657
|
+
/**
|
|
658
|
+
* Register a flow handler for a specific flow type
|
|
659
|
+
*/
|
|
660
|
+
onFlow(type: FlowTypeEnum, handler: (whatsapp: WhatsApp, request: FlowEndpointRequest) => any | Promise<any>): void;
|
|
511
661
|
}
|
|
512
662
|
|
|
513
|
-
export {
|
|
663
|
+
export { BusinessProfileApi, EncryptionApi, FlowApi, FlowEndpointRequest, HttpMethodsEnum, type IRequest, type IResponse, MessageTypesEnum, MessagesApi, PhoneNumberApi, QrCodeApi, RegistrationApi, TemplateApi, TwoStepVerificationApi, WabaApi, WabaConfigType, WebhookHandler, WhatsApp as default, importConfig };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import {b as b$5}from'./chunk-O2OTHNWM.js';export{b as RegistrationApi}from'./chunk-O2OTHNWM.js';import {b as b$3}from'./chunk-7NQLQPLH.js';export{b as EncryptionApi}from'./chunk-7NQLQPLH.js';import {b as b$4}from'./chunk-UQPD6GIF.js';export{b as TwoStepVerificationApi}from'./chunk-UQPD6GIF.js';import {b as b$7}from'./chunk-5JGM556C.js';export{b as WabaApi}from'./chunk-5JGM556C.js';import {a as a$3}from'./chunk-3MO3BTBC.js';export{a as isMetaError}from'./chunk-3MO3BTBC.js';import {b as b$1}from'./chunk-2NJVBJUN.js';export{b as MessagesApi}from'./chunk-2NJVBJUN.js';import {b as b$6}from'./chunk-XPPDOFBN.js';import {b as b$9}from'./chunk-KFPOVYEJ.js';export{b as BusinessProfileApi}from'./chunk-KFPOVYEJ.js';import'./chunk-7GL74SXM.js';import {b as b$8}from'./chunk-A264MT4Q.js';export{b as FlowApi}from'./chunk-A264MT4Q.js';import {b as b$2}from'./chunk-GIQLIMOD.js';export{b as PhoneNumberApi}from'./chunk-GIQLIMOD.js';import {a as a$1}from'./chunk-XIIJD6SG.js';export{b as TemplateApi}from'./chunk-XIIJD6SG.js';import'./chunk-BZ5QDXNR.js';import {a as a$2}from'./chunk-FFOE5YKT.js';export{b as QrCodeApi}from'./chunk-FFOE5YKT.js';import {a}from'./chunk-VW3LGHTJ.js';import {z}from'./chunk-EYGUX4EA.js';export{c as HttpMethodsEnum,d as MessageTypesEnum,l as StatusEnum,r as WebhookTypesEnum}from'./chunk-EYGUX4EA.js';import'./chunk-4C666HHU.js';import g from'crypto';import {Agent}from'https';function K(r){return typeof r=="object"&&r!==null}function y(r){return typeof r=="string"}var se=["data_exchange","INIT","BACK"],te=["data_exchange","INIT"];function B(r){if(!("flow_token"in r&&y(r.flow_token)&&"action"in r))return false;let{action:e,version:s,screen:t,data:o}=r,a=s==="3.0",p=se.includes(e),n=typeof t>"u"||y(t)&&t!=="SUCCESS",d=e==="data_exchange"||K(o);return a&&p&&n&&d}function F(r){if(!("flow_token"in r&&y(r.flow_token)&&"action"in r))return false;let{action:e,screen:s,data:t}=r,o=te.includes(e),a=y(s),p=K(t)&&"error_key"in t&&y(t.error)&&"error_message"in t&&y(t.error_message);return o&&a&&p}function H(r){return "action"in r&&r.action==="ping"}var oe="UTILS",re=false,Q=new a(oe,process.env.DEBUG==="true"||re),ne=3e3,ae=30,ie=2e4,pe=r=>{if(!process.env.CLOUD_API_ACCESS_TOKEN&&!r?.accessToken)throw Q.log("Environmental variable: CLOUD_API_ACCESS_TOKEN and/or access token argument is undefined."),new Error("Missing WhatsApp access token.")},R=r=>{pe(r);let e={M4D_APP_ID:r?.appId||process.env.M4D_APP_ID||"",M4D_APP_SECRET:r?.appSecret||process.env.M4D_APP_SECRET||"",WA_PHONE_NUMBER_ID:r?.phoneNumberId||Number(process.env.WA_PHONE_NUMBER_ID),WA_BUSINESS_ACCOUNT_ID:r?.businessAcctId||process.env.WA_BUSINESS_ACCOUNT_ID||"",CLOUD_API_VERSION:r?.apiVersion||process.env.CLOUD_API_VERSION||"",CLOUD_API_ACCESS_TOKEN:r?.accessToken||process.env.CLOUD_API_ACCESS_TOKEN||"",WEBHOOK_ENDPOINT:r?.webhookEndpoint||process.env.WEBHOOK_ENDPOINT||"",WEBHOOK_VERIFICATION_TOKEN:r?.webhookVerificationToken||process.env.WEBHOOK_VERIFICATION_TOKEN||"",LISTENER_PORT:r?.listenerPort||parseInt(process.env.LISTENER_PORT||"")||ne,MAX_RETRIES_AFTER_WAIT:r?.maxRetriesAfterWait||parseInt(process.env.MAX_RETRIES_AFTER_WAIT||"")||ae,REQUEST_TIMEOUT:r?.requestTimeout||parseInt(process.env.REQUEST_TIMEOUT||"")||ie,DEBUG:r?.debug||process.env.DEBUG==="true",FLOW_API_PRIVATE_PEM:r?.privatePem||process.env.FLOW_API_PRIVATE_PEM||"",FLOW_API_PASSPHRASE:r?.passphrase||process.env.FLOW_API_PASSPHRASE||""};return Q.log(`Configuration loaded for App Id ${e.M4D_APP_ID}`),e};var ue="HttpsClient",de=false,J=new a(ue,process.env.DEBUG==="true"||de),E=class{agent;constructor(){this.agent=new Agent({keepAlive:true});}clearSockets(){return this.agent.destroy(),true}async sendRequest(e,s,t,o,a,p){let n=`https://${e}/${s}`,d=new AbortController,i=setTimeout(()=>d.abort(),a);try{let u=await fetch(n,{method:t,headers:o,body:p,signal:d.signal});return J.log(`${t} : ${n} - ${JSON.stringify(u)}`),clearTimeout(i),new N(u)}catch(u){throw J.error(`${t} : ${n} - ${JSON.stringify(u)}`),u}}},N=class{res;respStatusCode;respHeaders;constructor(e){this.res=e,this.respStatusCode=e.status,this.respHeaders=Object.fromEntries(e.headers.entries());}statusCode(){return this.respStatusCode}headers(){return this.respHeaders}rawResponse(){return this.res}async json(){try{return await this.res.json()}catch(e){throw new Error("Failed to parse response body to JSON: "+e.message)}}};var le="REQUESTER",me=false,fe=new a(le,process.env.DEBUG==="true"||me),b=class{client;accessToken;phoneNumberId;businessAcctId;apiVersion;userAgent;host;protocol="https:";constructor(e,s,t,o,a){this.client=new E,this.host="graph.facebook.com",this.apiVersion=e||"22",this.phoneNumberId=s,this.accessToken=t,this.businessAcctId=o,this.userAgent=a;}buildHeader(e,s){let t={Authorization:`Bearer ${this.accessToken}`,"User-Agent":this.userAgent};return e!=="multipart/form-data"&&(t["Content-Type"]=e),s&&Object.assign(t,s),t}buildCAPIPath(e){return `v${this.apiVersion}.0/${e}`}async sendRequest(e,s,t,o,a="application/json",p){let n=a;o instanceof FormData?n="multipart/form-data":typeof o=="string"&&o.startsWith("<?xml")&&(n="application/xml");let d=`${this.protocol.toLowerCase()}//${this.host}/${this.buildCAPIPath(s)}`;fe.log(`${e} : ${d} (${n})`);try{let i=await this.client.sendRequest(this.host,this.buildCAPIPath(s),e,this.buildHeader(n,p),t,e==="POST"||e==="PUT"?o:void 0);if(!i.rawResponse().ok){let u=await i.json();throw a$3(u)?u:{name:"MetaError",message:"Unknown error occurred",error:{message:u.message||"Unknown error occurred",type:"UnknownError",code:i.statusCode(),fbtrace_id:""}}}return i}catch(i){throw a$3(i)?i:{name:"MetaError",message:i instanceof Error?i.message:"Network error occurred",error:{message:i instanceof Error?i.message:"Network error occurred",type:"NetworkError",code:500,fbtrace_id:""}}}}async getJson(e,s,t,o,a){return await(await this.sendRequest(e,s,t,o,"application/json",a)).json()}async sendFormData(e,s,t,o,a){return await(await this.sendRequest(e,s,t,o,"multipart/form-data",a)).json()}async sendUrlEncodedForm(e,s,t,o,a){let p=new URLSearchParams(o).toString();return await(await this.sendRequest(e,s,t,p,"application/x-www-form-urlencoded",a)).json()}};var ge="WHATSAPP",he=false,A=new a(ge,process.env.DEBUG==="true"||he),ye="WA_SDK",f=class{config;requester;messages;templates;phoneNumber;qrCode;encryption;twoStepVerification;registration;media;waba;flow;businessProfile;static Enums=z;constructor(e){this.config=R(e),this.requester=new b(this.config.CLOUD_API_VERSION,this.config.WA_PHONE_NUMBER_ID,this.config.CLOUD_API_ACCESS_TOKEN,this.config.WA_BUSINESS_ACCOUNT_ID,this.userAgent()),this.messages=new b$1(this.config,this.requester),this.templates=new a$1(this.config,this.requester),this.phoneNumber=new b$2(this.config,this.requester),this.qrCode=new a$2(this.config,this.requester),this.encryption=new b$3(this.config,this.requester),this.twoStepVerification=new b$4(this.config,this.requester),this.registration=new b$5(this.config,this.requester),this.media=new b$6(this.config,this.requester),this.waba=new b$7(this.config,this.requester),this.flow=new b$8(this.config,this.requester),this.businessProfile=new b$9(this.config,this.requester),A.log("WhatsApp Node.js SDK instantiated!");}userAgent(){return `${ye}/0.0.1 (Node.js ${process.version})`}updateTimeout(e){return this.config.REQUEST_TIMEOUT=e,A.log(`Updated request timeout to ${e}ms`),true}updatePhoneNumberId(e){return this.config.WA_PHONE_NUMBER_ID=e,A.log(`Updated sender phone number id to ${e}`),true}updateAccessToken(e){return this.config.CLOUD_API_ACCESS_TOKEN=e,A.log("Updated access token"),true}updateWabaId(e){return this.config.WA_BUSINESS_ACCOUNT_ID=e,A.log(`Updated business account id to ${e}`),true}};var Re="WEBHOOK",Ee=false,c=new a(Re,process.env.DEBUG==="true"||Ee),w=class{config;client;messageHandlers=new Map;eventHandlers=new Map;preProcessHandler=null;postProcessHandler=null;flowHandlers=new Map;constructor(e){let s=R(e);this.config=s,this.client=new f(e),c.log("WebhookHandler instantiated!");}handleVerificationRequest(e,s){let t=e.query["hub.mode"],o=e.query["hub.verify_token"],a=e.query["hub.challenge"];t==="subscribe"&&o===this.config.WEBHOOK_VERIFICATION_TOKEN?(c.log("Webhook verified successfully"),s.status(200).send(a)):(c.log("Webhook verification failed"),s.status(403).end());}async handleWebhookRequest(e,s){let t=e.body;if(t.object!=="whatsapp_business_account"){c.log("Received webhook for non-WhatsApp event"),s.status(404).end();return}for(let o of t.entry)try{let a=o.changes;for(let p of a)p.field==="messages"?await this.processMessages(p.value):await this.processEvent(p.field,p.value);}catch(a){c.log(`Error processing webhook: ${a}`);}s.status(200).end();}handleRequest(e,s){if(e.method==="GET")return this.handleVerificationRequest(e,s);if(e.method==="POST")return this.handleWebhookRequest(e,s);s.status(405).end();}async processMessages(e){let s=e.metadata,t=s.display_phone_number,o=s.phone_number_id,a=e.contacts[0].profile.name,p=e.messages;if(p&&p.length>0)for(let n of p){let d=n.type,i={id:n.id,from:n.from,timestamp:n.timestamp,type:n.type,phoneNumberId:o,displayPhoneNumber:t,profileName:a,originalData:n};switch(n.type){case "text":i.text=n.text;break;case "image":i.image=n.image;break;case "video":i.video=n.video;break;case "audio":i.audio=n.audio;break;case "document":i.document=n.document;break;case "sticker":i.sticker=n.sticker;break;case "location":i.location=n.location;break;case "contacts":i.contacts=n.contacts;break;case "interactive":i.interactive=n.interactive;break;case "button":i.button=n.button;break;case "order":i.order=n.order;break;case "system":i.system=n.system;break;}if(n.context&&(i.context=n.context),n.errors&&(i.errors=n.errors),this.preProcessHandler)try{await this.preProcessHandler(this.client,i);}catch(m){c.log(`Error in pre-process handler: ${m}`);}let u=this.messageHandlers.get(d);if(u)try{await u(this.client,i);}catch(m){c.log(`Error in message handler for ${d}: ${m}`);}if(this.postProcessHandler)try{await this.postProcessHandler(this.client,i);}catch(m){c.log(`Error in post-process handler: ${m}`);}}}async processEvent(e,s){let t={field:e,value:s,timestamp:Date.now()},o=this.eventHandlers.get(e);if(o)try{await o(t);}catch(a){c.log(`Error in event handler for ${e}: ${a}`);}}onMessage(e,s){this.messageHandlers.set(e,s),c.log(`Registered message handler for ${e}`);}onEvent(e,s){this.eventHandlers.set(e,s),c.log(`Registered event handler for ${e}`);}onMessagePreProcess(e){this.preProcessHandler=e,c.log("Registered pre-process handler");}onMessagePostProcess(e){this.postProcessHandler=e,c.log("Registered post-process handler");}async handleFlowRequest(e,s){try{if(!this.isRequestSignatureValid(e)){c.log("Invalid request signature"),s.status(401).json({error:"Unauthorized"});return}let t=JSON.parse(e.rawBody),{decryptedBody:o}=this.decryptRequest(t),a=this.flowHandlers.get("*");if(!a){c.log(`No handler registered for flow action: ${o.action}`),s.status(404).json({error:"Handler not found"});return}if(H(o)){let p={version:"3.0",data:{status:"active"}};s.status(200).json(p);return}if(F(o)){c.log(`Flow error: ${JSON.stringify(o)}`),s.status(200).json({});return}if(B(o)){let p=await a(this.client,o),n=this.encryptResponse(p,Buffer.from(t.aes_key,"base64"),Buffer.from(t.initial_vector,"base64"));s.status(200).json(n);return}c.log(`Unknown flow request type: ${JSON.stringify(o)}`),s.status(400).json({error:"Unknown request type"});}catch(t){c.log(`Error handling flow request: ${t}`),s.status(500).json({error:"Internal server error"});}}isRequestSignatureValid(e){let s=e.headers["x-hub-signature-256"];if(!s)return false;let o=`sha256=${g.createHmac("sha256",this.config.WEBHOOK_VERIFICATION_TOKEN||"").update(e.rawBody,"utf8").digest("hex")}`;return g.timingSafeEqual(Buffer.from(s),Buffer.from(o))}decryptRequest(e){c.log("Received body for decryption:",JSON.stringify(e,null,2));let{encrypted_aes_key:s,encrypted_flow_data:t,initial_vector:o}=e;if(!s)throw new Error("Missing required property: encrypted_aes_key");if(!t)throw new Error("Missing required property: encrypted_flow_data");if(!o)throw new Error("Missing required property: initial_vector");c.log("Received body for privatePem:",JSON.stringify(this.config.FLOW_API_PRIVATE_PEM,null,2)),c.log("Received body for passphrase:",JSON.stringify(this.config.FLOW_API_PASSPHRASE,null,2));let a=this.config.FLOW_API_PRIVATE_PEM.replace(/\\n/g,`
|
|
2
|
+
`),p=this.config.FLOW_API_PASSPHRASE,n=g.createPrivateKey({key:a,passphrase:p}),d=null;try{d=g.privateDecrypt({key:n,padding:g.constants.RSA_PKCS1_OAEP_PADDING,oaepHash:"sha256"},Buffer.from(s,"base64"));}catch(Z){throw c.error(Z),new Error("Failed to decrypt the request. Please verify your private key.")}let i=Buffer.from(t,"base64"),u=Buffer.from(o,"base64"),X=i.subarray(0,-16),z=i.subarray(-16),q=g.createDecipheriv("aes-128-gcm",d,u);q.setAuthTag(z);let Y=Buffer.concat([q.update(X),q.final()]).toString("utf-8");return {decryptedBody:JSON.parse(Y),aesKeyBuffer:d,initialVectorBuffer:u}}encryptResponse(e,s,t){let o=[];for(let a of Array.from(t.entries()))o.push(~a[1]);try{let a=g.createCipheriv("aes-128-gcm",s,Buffer.from(o));return Buffer.concat([a.update(JSON.stringify(e||{}),"utf-8"),a.final(),a.getAuthTag()]).toString("base64")}catch(a){throw c.error("Response encryption error:",a),new Error("Failed to encrypt response. Internal server error.")}}onFlow(e,s){this.flowHandlers.set(e,s),c.log(`Registered flow handler for ${e}`);}};var Gs=f;export{w as WebhookHandler,Gs as default,R as importConfig};//# sourceMappingURL=index.js.map
|
|
3
|
+
//# sourceMappingURL=index.js.map
|