@rempays/shared-core 1.0.2-beta.4 → 1.0.2-beta.6

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.
@@ -1,70 +1,4 @@
1
- export interface SendTextParams {
2
- to: string;
3
- body: string;
4
- previewUrl?: boolean;
5
- }
6
- export interface SendTemplateParams {
7
- to: string;
8
- name: string;
9
- languageCode: string;
10
- components?: any[];
11
- }
12
- export interface SendInteractiveParams {
13
- to: string;
14
- header?: {
15
- type: "text";
16
- text: string;
17
- };
18
- body: string;
19
- footer?: string;
20
- buttons: Array<{
21
- type: "reply";
22
- id: string;
23
- title: string;
24
- }>;
25
- }
26
- export interface SendInteractiveListParams {
27
- to: string;
28
- header?: {
29
- type: "text";
30
- text: string;
31
- };
32
- body: string;
33
- footer?: string;
34
- buttonText: string;
35
- sections: Array<{
36
- title: string;
37
- rows: Array<{
38
- id: string;
39
- title: string;
40
- description?: string;
41
- }>;
42
- }>;
43
- }
44
- export interface SendImageParams {
45
- to: string;
46
- link: string;
47
- caption?: string;
48
- }
49
- export interface SendDocumentParams {
50
- to: string;
51
- link: string;
52
- filename?: string;
53
- caption?: string;
54
- }
55
- export interface SendLocationParams {
56
- to: string;
57
- latitude: number;
58
- longitude: number;
59
- name?: string;
60
- address?: string;
61
- }
62
- export interface SetTypingParams {
63
- messageId: string;
64
- }
65
- export interface MarkAsReadParams {
66
- messageId: string;
67
- }
1
+ import type { SendTextParams, SendTemplateParams, SendInteractiveParams, SendInteractiveListParams, SendImageParams, SendDocumentParams, SendLocationParams, SetTypingParams, MarkAsReadParams, ExchangeTokenParams, ExchangeTokenResponse, RegisterPhoneParams, VerifyPhoneCodeParams } from './types';
68
2
  export declare class FacebookApi {
69
3
  private static token;
70
4
  private static phoneNumberId;
@@ -80,4 +14,22 @@ export declare class FacebookApi {
80
14
  static sendLocation(params: SendLocationParams): Promise<any>;
81
15
  static setTyping(params: SetTypingParams): Promise<any>;
82
16
  static markAsRead(params: MarkAsReadParams): Promise<any>;
17
+ /**
18
+ * Exchange authorization code for access token (Embedded Signup)
19
+ * Used after user completes WhatsApp Business signup flow
20
+ */
21
+ static exchangeToken(params: ExchangeTokenParams): Promise<ExchangeTokenResponse>;
22
+ /**
23
+ * Register phone number for WhatsApp Business API
24
+ * Requires a 6-digit PIN for verification
25
+ */
26
+ static registerPhone(params: RegisterPhoneParams): Promise<any>;
27
+ /**
28
+ * Verify phone number with code sent via SMS
29
+ */
30
+ static verifyCode(params: VerifyPhoneCodeParams): Promise<any>;
31
+ /**
32
+ * Get WhatsApp Business Account info
33
+ */
34
+ static getBusinessAccount(wabaId: string): Promise<any>;
83
35
  }
@@ -162,6 +162,101 @@ class FacebookApi {
162
162
  };
163
163
  return await this.post("messages", payload);
164
164
  }
165
+ /**
166
+ * Exchange authorization code for access token (Embedded Signup)
167
+ * Used after user completes WhatsApp Business signup flow
168
+ */
169
+ static async exchangeToken(params) {
170
+ const appId = process.env.FACEBOOK_APP_ID;
171
+ const appSecret = process.env.FACEBOOK_APP_SECRET;
172
+ const redirectUri = process.env.FACEBOOK_REDIRECT_URI || 'https://localhost';
173
+ if (!appId || !appSecret) {
174
+ throw new Error("FACEBOOK_APP_ID and FACEBOOK_APP_SECRET are required for token exchange");
175
+ }
176
+ const url = `https://graph.facebook.com/${this.apiVersion || 'v18.0'}/oauth/access_token`;
177
+ try {
178
+ const http = (0, http_1.getHttpClient)('');
179
+ const { data } = await http.get(url, {
180
+ params: {
181
+ client_id: appId,
182
+ client_secret: appSecret,
183
+ code: params.code,
184
+ redirect_uri: redirectUri,
185
+ }
186
+ });
187
+ return data;
188
+ }
189
+ catch (err) {
190
+ const status = err?.response?.status;
191
+ const data = err?.response?.data;
192
+ const msg = `Facebook token exchange error${status ? " " + status : ""}: ${typeof data === "string" ? data : JSON.stringify(data)}`;
193
+ throw new Error(msg);
194
+ }
195
+ }
196
+ /**
197
+ * Register phone number for WhatsApp Business API
198
+ * Requires a 6-digit PIN for verification
199
+ */
200
+ static async registerPhone(params) {
201
+ await this.init();
202
+ const url = `https://graph.facebook.com/${this.apiVersion}/${params.phoneNumberId}/register`;
203
+ try {
204
+ const http = (0, http_1.getHttpClient)(this.token);
205
+ const { data } = await http.post(url, {
206
+ messaging_product: "whatsapp",
207
+ pin: params.pin,
208
+ });
209
+ return data;
210
+ }
211
+ catch (err) {
212
+ const status = err?.response?.status;
213
+ const data = err?.response?.data;
214
+ const msg = `Facebook phone registration error${status ? " " + status : ""}: ${typeof data === "string" ? data : JSON.stringify(data)}`;
215
+ throw new Error(msg);
216
+ }
217
+ }
218
+ /**
219
+ * Verify phone number with code sent via SMS
220
+ */
221
+ static async verifyCode(params) {
222
+ await this.init();
223
+ const url = `https://graph.facebook.com/${this.apiVersion}/${this.phoneNumberId}/verify_code`;
224
+ try {
225
+ const http = (0, http_1.getHttpClient)(this.token);
226
+ const { data } = await http.post(url, {
227
+ code: params.code,
228
+ });
229
+ return data;
230
+ }
231
+ catch (err) {
232
+ const status = err?.response?.status;
233
+ const data = err?.response?.data;
234
+ const msg = `Facebook code verification error${status ? " " + status : ""}: ${typeof data === "string" ? data : JSON.stringify(data)}`;
235
+ throw new Error(msg);
236
+ }
237
+ }
238
+ /**
239
+ * Get WhatsApp Business Account info
240
+ */
241
+ static async getBusinessAccount(wabaId) {
242
+ await this.init();
243
+ const url = `https://graph.facebook.com/${this.apiVersion}/${wabaId}`;
244
+ try {
245
+ const http = (0, http_1.getHttpClient)(this.token);
246
+ const { data } = await http.get(url, {
247
+ params: {
248
+ fields: 'id,name,timezone_id,message_template_namespace,phone_numbers',
249
+ }
250
+ });
251
+ return data;
252
+ }
253
+ catch (err) {
254
+ const status = err?.response?.status;
255
+ const data = err?.response?.data;
256
+ const msg = `Facebook WABA info error${status ? " " + status : ""}: ${typeof data === "string" ? data : JSON.stringify(data)}`;
257
+ throw new Error(msg);
258
+ }
259
+ }
165
260
  }
166
261
  exports.FacebookApi = FacebookApi;
167
262
  FacebookApi.token = null;
@@ -1,2 +1,2 @@
1
1
  export { FacebookApi } from './facebook';
2
- export type { SendTextParams, SendTemplateParams, SendInteractiveParams, SendInteractiveListParams, SendImageParams, SendDocumentParams, SendLocationParams, SetTypingParams, MarkAsReadParams, } from './facebook';
2
+ export * from './types';
@@ -1,5 +1,20 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
2
16
  Object.defineProperty(exports, "__esModule", { value: true });
3
17
  exports.FacebookApi = void 0;
4
18
  var facebook_1 = require("./facebook");
5
19
  Object.defineProperty(exports, "FacebookApi", { enumerable: true, get: function () { return facebook_1.FacebookApi; } });
20
+ __exportStar(require("./types"), exports);
@@ -0,0 +1,82 @@
1
+ export interface SendTextParams {
2
+ to: string;
3
+ body: string;
4
+ previewUrl?: boolean;
5
+ }
6
+ export interface SendTemplateParams {
7
+ to: string;
8
+ name: string;
9
+ languageCode: string;
10
+ components?: any[];
11
+ }
12
+ export interface SendInteractiveParams {
13
+ to: string;
14
+ header?: {
15
+ type: "text";
16
+ text: string;
17
+ };
18
+ body: string;
19
+ footer?: string;
20
+ buttons: Array<{
21
+ type: "reply";
22
+ id: string;
23
+ title: string;
24
+ }>;
25
+ }
26
+ export interface SendInteractiveListParams {
27
+ to: string;
28
+ header?: {
29
+ type: "text";
30
+ text: string;
31
+ };
32
+ body: string;
33
+ footer?: string;
34
+ buttonText: string;
35
+ sections: Array<{
36
+ title: string;
37
+ rows: Array<{
38
+ id: string;
39
+ title: string;
40
+ description?: string;
41
+ }>;
42
+ }>;
43
+ }
44
+ export interface SendImageParams {
45
+ to: string;
46
+ link: string;
47
+ caption?: string;
48
+ }
49
+ export interface SendDocumentParams {
50
+ to: string;
51
+ link: string;
52
+ filename?: string;
53
+ caption?: string;
54
+ }
55
+ export interface SendLocationParams {
56
+ to: string;
57
+ latitude: number;
58
+ longitude: number;
59
+ name?: string;
60
+ address?: string;
61
+ }
62
+ export interface SetTypingParams {
63
+ messageId: string;
64
+ }
65
+ export interface MarkAsReadParams {
66
+ messageId: string;
67
+ }
68
+ export interface ExchangeTokenParams {
69
+ code: string;
70
+ }
71
+ export interface ExchangeTokenResponse {
72
+ access_token: string;
73
+ token_type: string;
74
+ expires_in?: number;
75
+ }
76
+ export interface RegisterPhoneParams {
77
+ phoneNumberId: string;
78
+ pin: string;
79
+ }
80
+ export interface VerifyPhoneCodeParams {
81
+ code: string;
82
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rempays/shared-core",
3
- "version": "1.0.2-beta.4",
3
+ "version": "1.0.2-beta.6",
4
4
  "description": "Core utilities layer for RemPays platform with AWS services integration (Cognito, S3, Secrets Manager, Textract, Facebook API, DynamoDB)",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",