@rempays/shared-core 1.0.2-beta.3 → 1.0.2-beta.4-beta.5

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,18 +1,21 @@
1
+ "use strict";
1
2
  /**
2
3
  * Ejemplo de uso del JwtValidator en un Lambda Authorizer
3
4
  *
4
5
  * Este archivo es solo de referencia, no se exporta en el paquete
5
6
  */
6
- import { JwtValidator } from './jwt-validator';
7
+ Object.defineProperty(exports, "__esModule", { value: true });
8
+ exports.handler = void 0;
9
+ const jwt_validator_1 = require("./jwt-validator");
7
10
  // Configuración del validador
8
- const validator = new JwtValidator({
11
+ const validator = new jwt_validator_1.JwtValidator({
9
12
  region: process.env.AWS_REGION || 'us-east-1',
10
13
  userPoolId: process.env.USER_POOL_ID,
11
14
  });
12
15
  /**
13
16
  * Lambda Authorizer Handler
14
17
  */
15
- export const handler = async (event) => {
18
+ const handler = async (event) => {
16
19
  try {
17
20
  // Extraer y validar el token
18
21
  const token = event.headers?.Authorization || event.headers?.authorization;
@@ -26,6 +29,7 @@ export const handler = async (event) => {
26
29
  return generatePolicy('user', 'Deny', event.methodArn);
27
30
  }
28
31
  };
32
+ exports.handler = handler;
29
33
  /**
30
34
  * Genera una policy de IAM para API Gateway
31
35
  */
@@ -1 +1,5 @@
1
- export { JwtValidator } from './jwt-validator';
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.JwtValidator = void 0;
4
+ var jwt_validator_1 = require("./jwt-validator");
5
+ Object.defineProperty(exports, "JwtValidator", { enumerable: true, get: function () { return jwt_validator_1.JwtValidator; } });
@@ -1,5 +1,8 @@
1
- import { createHttpClient } from '../http/client';
2
- export class JwtValidator {
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.JwtValidator = void 0;
4
+ const client_1 = require("../http/client");
5
+ class JwtValidator {
3
6
  constructor(config) {
4
7
  this.jwksCache = null;
5
8
  this.config = config;
@@ -60,7 +63,7 @@ export class JwtValidator {
60
63
  return this.jwksCache;
61
64
  }
62
65
  const jwksUrl = `${this.issuer}/.well-known/jwks.json`;
63
- const httpClient = createHttpClient();
66
+ const httpClient = (0, client_1.createHttpClient)();
64
67
  this.jwksCache = await httpClient.get(jwksUrl);
65
68
  return this.jwksCache;
66
69
  }
@@ -99,3 +102,4 @@ export class JwtValidator {
99
102
  return this.validate(token);
100
103
  }
101
104
  }
105
+ exports.JwtValidator = JwtValidator;
@@ -1 +1,2 @@
1
- export {};
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,8 +1,11 @@
1
- import { CognitoIdentityProviderClient, SignUpCommand, InitiateAuthCommand, RespondToAuthChallengeCommand, ConfirmSignUpCommand, GetUserCommand, AdminGetUserCommand, AdminInitiateAuthCommand, AuthFlowType, ChallengeNameType, } from '@aws-sdk/client-cognito-identity-provider';
2
- export class CognitoService {
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CognitoService = void 0;
4
+ const client_cognito_identity_provider_1 = require("@aws-sdk/client-cognito-identity-provider");
5
+ class CognitoService {
3
6
  constructor(config) {
4
7
  this.config = config;
5
- this.client = new CognitoIdentityProviderClient({
8
+ this.client = new client_cognito_identity_provider_1.CognitoIdentityProviderClient({
6
9
  region: config.region,
7
10
  });
8
11
  }
@@ -17,7 +20,7 @@ export class CognitoService {
17
20
  if (email) {
18
21
  userAttributes.push({ Name: 'email', Value: email });
19
22
  }
20
- const command = new SignUpCommand({
23
+ const command = new client_cognito_identity_provider_1.SignUpCommand({
21
24
  ClientId: this.config.clientId,
22
25
  Username: phoneNumber,
23
26
  Password: password,
@@ -33,7 +36,7 @@ export class CognitoService {
33
36
  * Confirma el registro de un usuario con el código OTP
34
37
  */
35
38
  async confirmSignUp(phoneNumber, code) {
36
- const command = new ConfirmSignUpCommand({
39
+ const command = new client_cognito_identity_provider_1.ConfirmSignUpCommand({
37
40
  ClientId: this.config.clientId,
38
41
  Username: phoneNumber,
39
42
  ConfirmationCode: code,
@@ -45,9 +48,9 @@ export class CognitoService {
45
48
  */
46
49
  async signInCustomAuth(params) {
47
50
  const { phoneNumber } = params;
48
- const command = new InitiateAuthCommand({
51
+ const command = new client_cognito_identity_provider_1.InitiateAuthCommand({
49
52
  ClientId: this.config.clientId,
50
- AuthFlow: AuthFlowType.CUSTOM_AUTH,
53
+ AuthFlow: client_cognito_identity_provider_1.AuthFlowType.CUSTOM_AUTH,
51
54
  AuthParameters: {
52
55
  USERNAME: phoneNumber,
53
56
  },
@@ -64,9 +67,9 @@ export class CognitoService {
64
67
  */
65
68
  async signInSRP(params) {
66
69
  const { phoneNumber } = params;
67
- const command = new InitiateAuthCommand({
70
+ const command = new client_cognito_identity_provider_1.InitiateAuthCommand({
68
71
  ClientId: this.config.clientId,
69
- AuthFlow: AuthFlowType.USER_SRP_AUTH,
72
+ AuthFlow: client_cognito_identity_provider_1.AuthFlowType.USER_SRP_AUTH,
70
73
  AuthParameters: {
71
74
  USERNAME: phoneNumber,
72
75
  },
@@ -86,9 +89,9 @@ export class CognitoService {
86
89
  */
87
90
  async respondToAuthChallenge(params) {
88
91
  const { phoneNumber, code, session } = params;
89
- const command = new RespondToAuthChallengeCommand({
92
+ const command = new client_cognito_identity_provider_1.RespondToAuthChallengeCommand({
90
93
  ClientId: this.config.clientId,
91
- ChallengeName: ChallengeNameType.CUSTOM_CHALLENGE,
94
+ ChallengeName: client_cognito_identity_provider_1.ChallengeNameType.CUSTOM_CHALLENGE,
92
95
  Session: session,
93
96
  ChallengeResponses: {
94
97
  USERNAME: phoneNumber,
@@ -109,9 +112,9 @@ export class CognitoService {
109
112
  */
110
113
  async refreshToken(params) {
111
114
  const { refreshToken } = params;
112
- const command = new InitiateAuthCommand({
115
+ const command = new client_cognito_identity_provider_1.InitiateAuthCommand({
113
116
  ClientId: this.config.clientId,
114
- AuthFlow: AuthFlowType.REFRESH_TOKEN_AUTH,
117
+ AuthFlow: client_cognito_identity_provider_1.AuthFlowType.REFRESH_TOKEN_AUTH,
115
118
  AuthParameters: {
116
119
  REFRESH_TOKEN: refreshToken,
117
120
  },
@@ -126,7 +129,7 @@ export class CognitoService {
126
129
  * Obtiene información del usuario autenticado usando el access token
127
130
  */
128
131
  async getUser(accessToken) {
129
- const command = new GetUserCommand({
132
+ const command = new client_cognito_identity_provider_1.GetUserCommand({
130
133
  AccessToken: accessToken,
131
134
  });
132
135
  const response = await this.client.send(command);
@@ -142,7 +145,7 @@ export class CognitoService {
142
145
  * Obtiene información del usuario por username (requiere permisos de admin)
143
146
  */
144
147
  async adminGetUser(phoneNumber) {
145
- const command = new AdminGetUserCommand({
148
+ const command = new client_cognito_identity_provider_1.AdminGetUserCommand({
146
149
  UserPoolId: this.config.userPoolId,
147
150
  Username: phoneNumber,
148
151
  });
@@ -159,10 +162,10 @@ export class CognitoService {
159
162
  * Inicia autenticación como admin (útil para backend)
160
163
  */
161
164
  async adminInitiateAuth(phoneNumber) {
162
- const command = new AdminInitiateAuthCommand({
165
+ const command = new client_cognito_identity_provider_1.AdminInitiateAuthCommand({
163
166
  UserPoolId: this.config.userPoolId,
164
167
  ClientId: this.config.clientId,
165
- AuthFlow: AuthFlowType.CUSTOM_AUTH,
168
+ AuthFlow: client_cognito_identity_provider_1.AuthFlowType.CUSTOM_AUTH,
166
169
  AuthParameters: {
167
170
  USERNAME: phoneNumber,
168
171
  },
@@ -178,3 +181,4 @@ export class CognitoService {
178
181
  };
179
182
  }
180
183
  }
184
+ exports.CognitoService = CognitoService;
@@ -1,2 +1,20 @@
1
- export { CognitoService } from './cognito.service';
2
- export * from './types';
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
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.CognitoService = void 0;
18
+ var cognito_service_1 = require("./cognito.service");
19
+ Object.defineProperty(exports, "CognitoService", { enumerable: true, get: function () { return cognito_service_1.CognitoService; } });
20
+ __exportStar(require("./types"), exports);
@@ -1 +1,2 @@
1
- export {};
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,12 +1,15 @@
1
+ "use strict";
1
2
  /**
2
3
  * Cliente genérico de DynamoDB
3
4
  * Wrapper type-safe sobre AWS SDK
4
5
  */
5
- import { DynamoDBClient, PutItemCommand, GetItemCommand, UpdateItemCommand, DeleteItemCommand, QueryCommand, ScanCommand, BatchWriteItemCommand, BatchGetItemCommand, } from '@aws-sdk/client-dynamodb';
6
- import { marshall, unmarshall } from '@aws-sdk/util-dynamodb';
7
- export class DynamoDBClientWrapper {
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.DynamoDBClientWrapper = void 0;
8
+ const client_dynamodb_1 = require("@aws-sdk/client-dynamodb");
9
+ const util_dynamodb_1 = require("@aws-sdk/util-dynamodb");
10
+ class DynamoDBClientWrapper {
8
11
  constructor(config = {}) {
9
- this.client = new DynamoDBClient({
12
+ this.client = new client_dynamodb_1.DynamoDBClient({
10
13
  region: config.region || process.env.AWS_REGION || 'us-east-1',
11
14
  ...(config.endpoint && { endpoint: config.endpoint }),
12
15
  });
@@ -15,9 +18,9 @@ export class DynamoDBClientWrapper {
15
18
  * Inserta o actualiza un item
16
19
  */
17
20
  async put(tableName, item, options) {
18
- const command = new PutItemCommand({
21
+ const command = new client_dynamodb_1.PutItemCommand({
19
22
  TableName: tableName,
20
- Item: marshall(item, { removeUndefinedValues: true }),
23
+ Item: (0, util_dynamodb_1.marshall)(item, { removeUndefinedValues: true }),
21
24
  ...(options?.conditionExpression && {
22
25
  ConditionExpression: options.conditionExpression,
23
26
  }),
@@ -25,7 +28,7 @@ export class DynamoDBClientWrapper {
25
28
  ExpressionAttributeNames: options.expressionAttributeNames,
26
29
  }),
27
30
  ...(options?.expressionAttributeValues && {
28
- ExpressionAttributeValues: marshall(options.expressionAttributeValues),
31
+ ExpressionAttributeValues: (0, util_dynamodb_1.marshall)(options.expressionAttributeValues),
29
32
  }),
30
33
  });
31
34
  await this.client.send(command);
@@ -34,23 +37,23 @@ export class DynamoDBClientWrapper {
34
37
  * Obtiene un item por su clave primaria
35
38
  */
36
39
  async get(tableName, key) {
37
- const command = new GetItemCommand({
40
+ const command = new client_dynamodb_1.GetItemCommand({
38
41
  TableName: tableName,
39
- Key: marshall(key),
42
+ Key: (0, util_dynamodb_1.marshall)(key),
40
43
  });
41
44
  const response = await this.client.send(command);
42
45
  if (!response.Item) {
43
46
  return null;
44
47
  }
45
- return unmarshall(response.Item);
48
+ return (0, util_dynamodb_1.unmarshall)(response.Item);
46
49
  }
47
50
  /**
48
51
  * Actualiza un item
49
52
  */
50
53
  async update(tableName, key, options) {
51
- const command = new UpdateItemCommand({
54
+ const command = new client_dynamodb_1.UpdateItemCommand({
52
55
  TableName: tableName,
53
- Key: marshall(key),
56
+ Key: (0, util_dynamodb_1.marshall)(key),
54
57
  UpdateExpression: options.updateExpression,
55
58
  ...(options.conditionExpression && {
56
59
  ConditionExpression: options.conditionExpression,
@@ -59,20 +62,20 @@ export class DynamoDBClientWrapper {
59
62
  ExpressionAttributeNames: options.expressionAttributeNames,
60
63
  }),
61
64
  ...(options.expressionAttributeValues && {
62
- ExpressionAttributeValues: marshall(options.expressionAttributeValues),
65
+ ExpressionAttributeValues: (0, util_dynamodb_1.marshall)(options.expressionAttributeValues),
63
66
  }),
64
67
  ReturnValues: 'ALL_NEW',
65
68
  });
66
69
  const response = await this.client.send(command);
67
- return unmarshall(response.Attributes);
70
+ return (0, util_dynamodb_1.unmarshall)(response.Attributes);
68
71
  }
69
72
  /**
70
73
  * Elimina un item
71
74
  */
72
75
  async delete(tableName, key) {
73
- const command = new DeleteItemCommand({
76
+ const command = new client_dynamodb_1.DeleteItemCommand({
74
77
  TableName: tableName,
75
- Key: marshall(key),
78
+ Key: (0, util_dynamodb_1.marshall)(key),
76
79
  });
77
80
  await this.client.send(command);
78
81
  }
@@ -80,7 +83,7 @@ export class DynamoDBClientWrapper {
80
83
  * Query con índice o clave primaria
81
84
  */
82
85
  async query(tableName, options) {
83
- const command = new QueryCommand({
86
+ const command = new client_dynamodb_1.QueryCommand({
84
87
  TableName: tableName,
85
88
  ...(options.indexName && { IndexName: options.indexName }),
86
89
  KeyConditionExpression: options.keyConditionExpression,
@@ -91,7 +94,7 @@ export class DynamoDBClientWrapper {
91
94
  ExpressionAttributeNames: options.expressionAttributeNames,
92
95
  }),
93
96
  ...(options.expressionAttributeValues && {
94
- ExpressionAttributeValues: marshall(options.expressionAttributeValues),
97
+ ExpressionAttributeValues: (0, util_dynamodb_1.marshall)(options.expressionAttributeValues),
95
98
  }),
96
99
  ...(options.limit && { Limit: options.limit }),
97
100
  ...(options.scanIndexForward !== undefined && {
@@ -102,13 +105,13 @@ export class DynamoDBClientWrapper {
102
105
  if (!response.Items || response.Items.length === 0) {
103
106
  return [];
104
107
  }
105
- return response.Items.map((item) => unmarshall(item));
108
+ return response.Items.map((item) => (0, util_dynamodb_1.unmarshall)(item));
106
109
  }
107
110
  /**
108
111
  * Scan completo de la tabla (usar con cuidado)
109
112
  */
110
113
  async scan(tableName, limit) {
111
- const command = new ScanCommand({
114
+ const command = new client_dynamodb_1.ScanCommand({
112
115
  TableName: tableName,
113
116
  ...(limit && { Limit: limit }),
114
117
  });
@@ -116,7 +119,7 @@ export class DynamoDBClientWrapper {
116
119
  if (!response.Items || response.Items.length === 0) {
117
120
  return [];
118
121
  }
119
- return response.Items.map((item) => unmarshall(item));
122
+ return response.Items.map((item) => (0, util_dynamodb_1.unmarshall)(item));
120
123
  }
121
124
  /**
122
125
  * Batch write (put o delete múltiples items)
@@ -126,20 +129,20 @@ export class DynamoDBClientWrapper {
126
129
  if (item.put) {
127
130
  return {
128
131
  PutRequest: {
129
- Item: marshall(item.put, { removeUndefinedValues: true }),
132
+ Item: (0, util_dynamodb_1.marshall)(item.put, { removeUndefinedValues: true }),
130
133
  },
131
134
  };
132
135
  }
133
136
  else if (item.delete) {
134
137
  return {
135
138
  DeleteRequest: {
136
- Key: marshall(item.delete),
139
+ Key: (0, util_dynamodb_1.marshall)(item.delete),
137
140
  },
138
141
  };
139
142
  }
140
143
  throw new Error('Invalid batch write item');
141
144
  });
142
- const command = new BatchWriteItemCommand({
145
+ const command = new client_dynamodb_1.BatchWriteItemCommand({
143
146
  RequestItems: {
144
147
  [tableName]: requests,
145
148
  },
@@ -150,10 +153,10 @@ export class DynamoDBClientWrapper {
150
153
  * Batch get (obtener múltiples items)
151
154
  */
152
155
  async batchGet(tableName, keys) {
153
- const command = new BatchGetItemCommand({
156
+ const command = new client_dynamodb_1.BatchGetItemCommand({
154
157
  RequestItems: {
155
158
  [tableName]: {
156
- Keys: keys.map((key) => marshall(key)),
159
+ Keys: keys.map((key) => (0, util_dynamodb_1.marshall)(key)),
157
160
  },
158
161
  },
159
162
  });
@@ -161,6 +164,7 @@ export class DynamoDBClientWrapper {
161
164
  if (!response.Responses || !response.Responses[tableName]) {
162
165
  return [];
163
166
  }
164
- return response.Responses[tableName].map((item) => unmarshall(item));
167
+ return response.Responses[tableName].map((item) => (0, util_dynamodb_1.unmarshall)(item));
165
168
  }
166
169
  }
170
+ exports.DynamoDBClientWrapper = DynamoDBClientWrapper;
@@ -1 +1 @@
1
- export * from './dynamodb.client.js';
1
+ export * from './dynamodb.client';
@@ -1 +1,17 @@
1
- export * from './dynamodb.client.js';
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
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./dynamodb.client"), exports);
@@ -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
  }
@@ -1,5 +1,8 @@
1
- import { getHttpClient } from "./http";
2
- export class FacebookApi {
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.FacebookApi = void 0;
4
+ const http_1 = require("./http");
5
+ class FacebookApi {
3
6
  static async init() {
4
7
  if (this.token && this.phoneNumberId && this.apiVersion)
5
8
  return;
@@ -23,7 +26,7 @@ export class FacebookApi {
23
26
  await this.init();
24
27
  const url = `https://graph.facebook.com/${this.apiVersion}/${this.phoneNumberId}/${path}`;
25
28
  try {
26
- const http = getHttpClient(this.token);
29
+ const http = (0, http_1.getHttpClient)(this.token);
27
30
  const { data } = await http.post(url, payload);
28
31
  return data;
29
32
  }
@@ -159,7 +162,103 @@ export class FacebookApi {
159
162
  };
160
163
  return await this.post("messages", payload);
161
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
+ }
162
260
  }
261
+ exports.FacebookApi = FacebookApi;
163
262
  FacebookApi.token = null;
164
263
  FacebookApi.phoneNumberId = null;
165
264
  FacebookApi.apiVersion = null;
@@ -1,9 +1,15 @@
1
- import axios from 'axios';
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.getHttpClient = getHttpClient;
7
+ const axios_1 = __importDefault(require("axios"));
2
8
  let client = null;
3
- export function getHttpClient(token) {
9
+ function getHttpClient(token) {
4
10
  if (client)
5
11
  return client;
6
- client = axios.create({
12
+ client = axios_1.default.create({
7
13
  timeout: 10000,
8
14
  headers: {
9
15
  'Authorization': `Bearer ${token}`,
@@ -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 +1,20 @@
1
- export { FacebookApi } from './facebook';
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
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.FacebookApi = void 0;
18
+ var facebook_1 = require("./facebook");
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 });
@@ -1,8 +1,15 @@
1
- import axios from 'axios';
2
- export class HttpClient {
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.HttpClient = void 0;
7
+ exports.createHttpClient = createHttpClient;
8
+ const axios_1 = __importDefault(require("axios"));
9
+ class HttpClient {
3
10
  constructor(config = {}) {
4
11
  const { token, ...axiosConfig } = config;
5
- this.client = axios.create({
12
+ this.client = axios_1.default.create({
6
13
  timeout: 10000,
7
14
  headers: {
8
15
  ...(token && { 'Authorization': `Bearer ${token}` }),
@@ -41,6 +48,7 @@ export class HttpClient {
41
48
  return response.data;
42
49
  }
43
50
  }
44
- export function createHttpClient(config) {
51
+ exports.HttpClient = HttpClient;
52
+ function createHttpClient(config) {
45
53
  return new HttpClient(config);
46
54
  }
@@ -1 +1,6 @@
1
- export { HttpClient, createHttpClient } from './client';
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createHttpClient = exports.HttpClient = void 0;
4
+ var client_1 = require("./client");
5
+ Object.defineProperty(exports, "HttpClient", { enumerable: true, get: function () { return client_1.HttpClient; } });
6
+ Object.defineProperty(exports, "createHttpClient", { enumerable: true, get: function () { return client_1.createHttpClient; } });
package/dist/index.js CHANGED
@@ -1,8 +1,24 @@
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
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
1
17
  // Export all modules
2
- export * from './cognito/index';
3
- export * from './auth/index';
4
- export * from './s3/index';
5
- export * from './textract/index';
6
- export * from './facebook-api/index';
7
- export * from './dynamodb/index';
8
- export * from './http/index';
18
+ __exportStar(require("./cognito/index"), exports);
19
+ __exportStar(require("./auth/index"), exports);
20
+ __exportStar(require("./s3/index"), exports);
21
+ __exportStar(require("./textract/index"), exports);
22
+ __exportStar(require("./facebook-api/index"), exports);
23
+ __exportStar(require("./dynamodb/index"), exports);
24
+ __exportStar(require("./http/index"), exports);
package/dist/s3/index.js CHANGED
@@ -1 +1,17 @@
1
- export * from './s3.service';
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
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./s3.service"), exports);
@@ -1,15 +1,18 @@
1
- import { S3Client, PutObjectCommand, GetObjectCommand } from '@aws-sdk/client-s3';
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.S3Service = void 0;
4
+ const client_s3_1 = require("@aws-sdk/client-s3");
2
5
  /**
3
6
  * Servicio para manejar archivos en S3
4
7
  * Usado para almacenar documentos antes de procesarlos con Textract
5
8
  */
6
- export class S3Service {
9
+ class S3Service {
7
10
  /**
8
11
  * Sube un archivo a S3 desde un buffer o URL
9
12
  */
10
13
  static async uploadFile(params) {
11
14
  try {
12
- const command = new PutObjectCommand({
15
+ const command = new client_s3_1.PutObjectCommand({
13
16
  Bucket: this.BUCKET_NAME,
14
17
  Key: params.key,
15
18
  Body: params.body,
@@ -28,7 +31,7 @@ export class S3Service {
28
31
  */
29
32
  static async downloadFile(key) {
30
33
  try {
31
- const command = new GetObjectCommand({
34
+ const command = new client_s3_1.GetObjectCommand({
32
35
  Bucket: this.BUCKET_NAME,
33
36
  Key: key,
34
37
  });
@@ -54,7 +57,8 @@ export class S3Service {
54
57
  return `chats/${params.chatId}/messages/${params.messageId}-${timestamp}${extension}`;
55
58
  }
56
59
  }
57
- S3Service.client = new S3Client({
60
+ exports.S3Service = S3Service;
61
+ S3Service.client = new client_s3_1.S3Client({
58
62
  region: process.env['AWS_REGION'] || 'us-east-1',
59
63
  });
60
64
  S3Service.BUCKET_NAME = process.env['S3_DOCUMENTS_BUCKET'] || 'rempays-documents';
@@ -1 +1,17 @@
1
- export * from './textract.service';
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
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./textract.service"), exports);
@@ -1,14 +1,17 @@
1
- import { TextractClient, AnalyzeDocumentCommand } from '@aws-sdk/client-textract';
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TextractService = void 0;
4
+ const client_textract_1 = require("@aws-sdk/client-textract");
2
5
  /**
3
6
  * Servicio para extraer texto de documentos usando AWS Textract
4
7
  */
5
- export class TextractService {
8
+ class TextractService {
6
9
  /**
7
10
  * Analiza un documento desde S3 y extrae el texto
8
11
  */
9
12
  static async analyzeDocumentFromS3(s3Bucket, s3Key) {
10
13
  try {
11
- const command = new AnalyzeDocumentCommand({
14
+ const command = new client_textract_1.AnalyzeDocumentCommand({
12
15
  Document: {
13
16
  S3Object: {
14
17
  Bucket: s3Bucket,
@@ -37,7 +40,7 @@ export class TextractService {
37
40
  */
38
41
  static async analyzeDocumentFromBytes(bytes) {
39
42
  try {
40
- const command = new AnalyzeDocumentCommand({
43
+ const command = new client_textract_1.AnalyzeDocumentCommand({
41
44
  Document: {
42
45
  Bytes: bytes,
43
46
  },
@@ -58,6 +61,7 @@ export class TextractService {
58
61
  }
59
62
  }
60
63
  }
61
- TextractService.client = new TextractClient({
64
+ exports.TextractService = TextractService;
65
+ TextractService.client = new client_textract_1.TextractClient({
62
66
  region: process.env['AWS_REGION'] || 'us-east-1',
63
67
  });
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "@rempays/shared-core",
3
- "version": "1.0.2-beta.3",
3
+ "version": "1.0.2-beta.4-beta.5",
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",
7
- "type": "module",
7
+ "type": "commonjs",
8
8
  "private": false,
9
9
  "author": "RemPays Team",
10
10
  "license": "UNLICENSED",