@rempays/shared-core 1.0.2-beta.6 → 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.
- package/dist/facebook-api/embedded-signup.d.ts +14 -0
- package/dist/facebook-api/embedded-signup.js +59 -0
- package/dist/facebook-api/facebook.d.ts +1 -19
- package/dist/facebook-api/facebook.js +0 -95
- package/dist/facebook-api/index.d.ts +5 -0
- package/dist/facebook-api/index.js +8 -1
- package/dist/facebook-api/types.d.ts +0 -7
- package/package.json +1 -1
|
@@ -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
|
|
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,22 +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
|
-
* 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>;
|
|
35
17
|
}
|
|
@@ -162,101 +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
|
-
* 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
|
-
}
|
|
260
165
|
}
|
|
261
166
|
exports.FacebookApi = FacebookApi;
|
|
262
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.
|
|
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",
|