@rempays/shared-core 1.0.2-beta.15 → 1.0.2-beta.17

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.
@@ -3,8 +3,7 @@ export declare class FacebookApi {
3
3
  private static token;
4
4
  private static phoneNumberId;
5
5
  private static apiVersion;
6
- private static appId;
7
- constructor(token?: string, phoneNumberId?: string, apiVersion?: string, appId?: string);
6
+ constructor(token?: string, phoneNumberId?: string, apiVersion?: string);
8
7
  private static init;
9
8
  private static post;
10
9
  static sendText(params: SendTextParams): Promise<any>;
@@ -25,11 +24,10 @@ export declare class FacebookApi {
25
24
  static createTemplate(params: CreateTemplateParams): Promise<any>;
26
25
  static deleteTemplate(wabaId: string, name: string): Promise<any>;
27
26
  /**
28
- * Uploads an image and updates the business profile picture.
29
- * @param buffer Image binary data
30
- * @param mimeType Image MIME type (image/jpeg or image/png)
27
+ * Updates the business profile picture using a direct URL.
28
+ * @param url Public URL of the image
31
29
  */
32
- static updateProfilePicture(buffer: Buffer, mimeType: string): Promise<any>;
30
+ static updateProfilePicture(url: string): Promise<any>;
33
31
  /**
34
32
  * Uploads media for chat (messages).
35
33
  * @param buffer Media binary data
@@ -38,7 +36,9 @@ export declare class FacebookApi {
38
36
  static uploadMedia(buffer: Buffer, mimeType: string): Promise<{
39
37
  id: string;
40
38
  }>;
41
- static getBusinessProfile(): Promise<BusinessProfileResponse>;
39
+ static getBusinessProfile(): Promise<{
40
+ data: BusinessProfileResponse[];
41
+ }>;
42
42
  static updateBusinessProfile(params: BusinessProfileParams): Promise<any>;
43
43
  static updateDisplayName(params: UpdateDisplayNameParams): Promise<any>;
44
44
  static getDisplayNameStatus(): Promise<DisplayNameStatusResponse>;
@@ -3,15 +3,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.FacebookApi = void 0;
4
4
  const http_1 = require("./http");
5
5
  class FacebookApi {
6
- constructor(token, phoneNumberId, apiVersion, appId) {
6
+ constructor(token, phoneNumberId, apiVersion) {
7
7
  if (token)
8
8
  FacebookApi.token = token;
9
9
  if (phoneNumberId)
10
10
  FacebookApi.phoneNumberId = phoneNumberId;
11
11
  if (apiVersion)
12
12
  FacebookApi.apiVersion = apiVersion;
13
- if (appId)
14
- FacebookApi.appId = appId;
15
13
  }
16
14
  static async init() {
17
15
  if (this.token && this.phoneNumberId && this.apiVersion)
@@ -21,7 +19,6 @@ class FacebookApi {
21
19
  this.phoneNumberId || process.env.FACEBOOK_PHONE_NUMBER_ID || null;
22
20
  this.apiVersion =
23
21
  this.apiVersion || process.env.FACEBOOK_API_VERSION || "v18.0";
24
- this.appId = this.appId || process.env.FACEBOOK_APP_ID || null;
25
22
  if (!this.token || !this.phoneNumberId) {
26
23
  throw new Error("Facebook API environment variables are not properly configured (FACEBOOK_API_TOKEN, FACEBOOK_PHONE_NUMBER_ID)");
27
24
  }
@@ -307,38 +304,12 @@ class FacebookApi {
307
304
  PROFILE PICTURE UPLOAD (TWO-STEP)
308
305
  */
309
306
  /**
310
- * Uploads an image and updates the business profile picture.
311
- * @param buffer Image binary data
312
- * @param mimeType Image MIME type (image/jpeg or image/png)
307
+ * Updates the business profile picture using a direct URL.
308
+ * @param url Public URL of the image
313
309
  */
314
- static async updateProfilePicture(buffer, mimeType) {
315
- await this.init();
316
- if (!this.appId) {
317
- throw new Error("FACEBOOK_APP_ID is required for profile picture uploads");
318
- }
319
- const http = (0, http_1.getHttpClient)(this.token);
320
- // 1. Create upload session
321
- const sessionUrl = `https://graph.facebook.com/${this.apiVersion}/${this.appId}/uploads`;
322
- const { data: sessionData } = await http.post(sessionUrl, null, {
323
- params: {
324
- file_length: buffer.length,
325
- file_type: mimeType,
326
- access_token: this.token
327
- }
328
- });
329
- const sessionId = sessionData.id;
330
- // 2. Upload the file data
331
- const uploadUrl = `https://graph.facebook.com/${this.apiVersion}/${sessionId}`;
332
- const { data: uploadData } = await http.post(uploadUrl, buffer, {
333
- headers: {
334
- 'file_offset': 0,
335
- 'Content-Type': mimeType
336
- }
337
- });
338
- const handle = uploadData.h;
339
- // 3. Update the business profile with the handle
310
+ static async updateProfilePicture(url) {
340
311
  return await this.updateBusinessProfile({
341
- profile_picture_handle: handle
312
+ profile_picture_url: url
342
313
  });
343
314
  }
344
315
  /*
@@ -371,14 +342,12 @@ class FacebookApi {
371
342
  static async getBusinessProfile() {
372
343
  await this.init();
373
344
  const http = (0, http_1.getHttpClient)(this.token);
374
- const url = `https://graph.facebook.com/${this.apiVersion}/${this.phoneNumberId}/whatsapp_business_profile`;
375
- const { data } = await http.get(url, {
376
- params: {
377
- fields: "about,address,description,email,profile_picture_url,websites,vertical"
378
- }
379
- });
380
- // The response is usually { data: [ { ... } ] }
381
- return data.data?.[0] || data;
345
+ // Fields requested directly in URL to ensure they are always sent
346
+ const fields = "about,address,description,email,profile_picture_url,websites,vertical";
347
+ const url = `https://graph.facebook.com/${this.apiVersion}/${this.phoneNumberId}/whatsapp_business_profile?fields=${fields}`;
348
+ const { data } = await http.get(url);
349
+ // Returning the full structure { data: [ ... ] } as requested
350
+ return data;
382
351
  }
383
352
  static async updateBusinessProfile(params) {
384
353
  const payload = {
@@ -419,4 +388,3 @@ exports.FacebookApi = FacebookApi;
419
388
  FacebookApi.token = null;
420
389
  FacebookApi.phoneNumberId = null;
421
390
  FacebookApi.apiVersion = null;
422
- FacebookApi.appId = null;
@@ -147,6 +147,7 @@ export interface BusinessProfileParams {
147
147
  websites?: string[];
148
148
  vertical?: WhatsAppBusinessVertical;
149
149
  profile_picture_handle?: string;
150
+ profile_picture_url?: string;
150
151
  }
151
152
  export type WhatsAppBusinessVertical = "" | "UNDEFINED" | "OTHER" | "AUTO" | "BEAUTY" | "APPAREL" | "EDU" | "ENTERTAIN" | "EVENT_PLAN" | "FINANCE" | "GROCERY" | "GOVT" | "HOTEL" | "HEALTH" | "NONPROFIT" | "PROF_SERVICES" | "RETAIL" | "TRAVEL" | "RESTAURANT" | "NOT_A_BIZ";
152
153
  export interface BusinessProfileResponse {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rempays/shared-core",
3
- "version": "1.0.2-beta.15",
3
+ "version": "1.0.2-beta.17",
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",