@rempays/shared-core 1.0.2-beta.7 → 1.0.2-beta.8

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.
@@ -0,0 +1,14 @@
1
+ import type { ExchangeTokenParams, ExchangeTokenResponse } from './types';
2
+ export declare class EmbeddedSignup {
3
+ private static apiVersion;
4
+ /**
5
+ * Exchange authorization code for access token (Embedded Signup)
6
+ * Used after user completes WhatsApp Business signup flow
7
+ */
8
+ static exchangeToken(params: ExchangeTokenParams): Promise<ExchangeTokenResponse>;
9
+ /**
10
+ * Get WhatsApp Business Account info
11
+ * Requires a valid access token from exchangeToken
12
+ */
13
+ static getBusinessAccount(wabaId: string, accessToken: string): Promise<any>;
14
+ }
@@ -0,0 +1,59 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.EmbeddedSignup = void 0;
4
+ const http_1 = require("./http");
5
+ class EmbeddedSignup {
6
+ /**
7
+ * Exchange authorization code for access token (Embedded Signup)
8
+ * Used after user completes WhatsApp Business signup flow
9
+ */
10
+ static async exchangeToken(params) {
11
+ const appId = process.env.FACEBOOK_APP_ID;
12
+ const appSecret = process.env.FACEBOOK_APP_SECRET;
13
+ if (!appId || !appSecret) {
14
+ throw new Error("FACEBOOK_APP_ID and FACEBOOK_APP_SECRET are required for token exchange");
15
+ }
16
+ const url = `https://graph.facebook.com/${this.apiVersion}/oauth/access_token`;
17
+ try {
18
+ const http = (0, http_1.getHttpClient)('');
19
+ const { data } = await http.get(url, {
20
+ params: {
21
+ client_id: appId,
22
+ client_secret: appSecret,
23
+ code: params.code,
24
+ }
25
+ });
26
+ return data;
27
+ }
28
+ catch (err) {
29
+ const status = err?.response?.status;
30
+ const data = err?.response?.data;
31
+ const msg = `Facebook token exchange error${status ? " " + status : ""}: ${typeof data === "string" ? data : JSON.stringify(data)}`;
32
+ throw new Error(msg);
33
+ }
34
+ }
35
+ /**
36
+ * Get WhatsApp Business Account info
37
+ * Requires a valid access token from exchangeToken
38
+ */
39
+ static async getBusinessAccount(wabaId, accessToken) {
40
+ const url = `https://graph.facebook.com/${this.apiVersion}/${wabaId}`;
41
+ try {
42
+ const http = (0, http_1.getHttpClient)(accessToken);
43
+ const { data } = await http.get(url, {
44
+ params: {
45
+ fields: 'id,name,timezone_id,message_template_namespace,phone_numbers',
46
+ }
47
+ });
48
+ return data;
49
+ }
50
+ catch (err) {
51
+ const status = err?.response?.status;
52
+ const data = err?.response?.data;
53
+ const msg = `Facebook WABA info error${status ? " " + status : ""}: ${typeof data === "string" ? data : JSON.stringify(data)}`;
54
+ throw new Error(msg);
55
+ }
56
+ }
57
+ }
58
+ exports.EmbeddedSignup = EmbeddedSignup;
59
+ EmbeddedSignup.apiVersion = 'v18.0';
@@ -1,4 +1,4 @@
1
- import type { SendTextParams, SendTemplateParams, SendInteractiveParams, SendInteractiveListParams, SendImageParams, SendDocumentParams, SendLocationParams, SetTypingParams, MarkAsReadParams, ExchangeTokenParams, ExchangeTokenResponse } from './types';
1
+ import type { SendTextParams, SendTemplateParams, SendInteractiveParams, SendInteractiveListParams, SendImageParams, SendDocumentParams, SendLocationParams, SetTypingParams, MarkAsReadParams } from './types';
2
2
  export declare class FacebookApi {
3
3
  private static token;
4
4
  private static phoneNumberId;
@@ -14,13 +14,4 @@ export declare class FacebookApi {
14
14
  static sendLocation(params: SendLocationParams): Promise<any>;
15
15
  static setTyping(params: SetTypingParams): Promise<any>;
16
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
- * Get WhatsApp Business Account info
24
- */
25
- static getBusinessAccount(wabaId: string): Promise<any>;
26
17
  }
@@ -162,59 +162,6 @@ 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
- * Get WhatsApp Business Account info
198
- */
199
- static async getBusinessAccount(wabaId) {
200
- await this.init();
201
- const url = `https://graph.facebook.com/${this.apiVersion}/${wabaId}`;
202
- try {
203
- const http = (0, http_1.getHttpClient)(this.token);
204
- const { data } = await http.get(url, {
205
- params: {
206
- fields: 'id,name,timezone_id,message_template_namespace,phone_numbers',
207
- }
208
- });
209
- return data;
210
- }
211
- catch (err) {
212
- const status = err?.response?.status;
213
- const data = err?.response?.data;
214
- const msg = `Facebook WABA info error${status ? " " + status : ""}: ${typeof data === "string" ? data : JSON.stringify(data)}`;
215
- throw new Error(msg);
216
- }
217
- }
218
165
  }
219
166
  exports.FacebookApi = FacebookApi;
220
167
  FacebookApi.token = null;
@@ -1,2 +1,7 @@
1
1
  export { FacebookApi } from './facebook';
2
+ export { EmbeddedSignup } from './embedded-signup';
2
3
  export * from './types';
4
+ import { FacebookApi } from './facebook';
5
+ import { EmbeddedSignup } from './embedded-signup';
6
+ export declare const facebookApi: typeof FacebookApi;
7
+ export declare const embeddedSignup: typeof EmbeddedSignup;
@@ -14,7 +14,14 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.FacebookApi = void 0;
17
+ exports.embeddedSignup = exports.facebookApi = exports.EmbeddedSignup = exports.FacebookApi = void 0;
18
18
  var facebook_1 = require("./facebook");
19
19
  Object.defineProperty(exports, "FacebookApi", { enumerable: true, get: function () { return facebook_1.FacebookApi; } });
20
+ var embedded_signup_1 = require("./embedded-signup");
21
+ Object.defineProperty(exports, "EmbeddedSignup", { enumerable: true, get: function () { return embedded_signup_1.EmbeddedSignup; } });
20
22
  __exportStar(require("./types"), exports);
23
+ // Export singleton instances for easy usage
24
+ const facebook_2 = require("./facebook");
25
+ const embedded_signup_2 = require("./embedded-signup");
26
+ exports.facebookApi = facebook_2.FacebookApi;
27
+ exports.embeddedSignup = embedded_signup_2.EmbeddedSignup;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rempays/shared-core",
3
- "version": "1.0.2-beta.7",
3
+ "version": "1.0.2-beta.8",
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",