@rempays/shared-core 1.0.2-beta.1
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/README.md +346 -0
- package/dist/auth/authorizer-example.d.ts +24 -0
- package/dist/auth/authorizer-example.js +51 -0
- package/dist/auth/index.d.ts +2 -0
- package/dist/auth/index.js +1 -0
- package/dist/auth/jwt-validator.d.ts +37 -0
- package/dist/auth/jwt-validator.js +101 -0
- package/dist/auth/types.d.ts +28 -0
- package/dist/auth/types.js +1 -0
- package/dist/cognito/cognito.service.d.ts +45 -0
- package/dist/cognito/cognito.service.js +180 -0
- package/dist/cognito/index.d.ts +2 -0
- package/dist/cognito/index.js +2 -0
- package/dist/cognito/types.d.ts +38 -0
- package/dist/cognito/types.js +1 -0
- package/dist/dynamodb/dynamodb.client.d.ts +67 -0
- package/dist/dynamodb/dynamodb.client.js +166 -0
- package/dist/dynamodb/index.d.ts +1 -0
- package/dist/dynamodb/index.js +1 -0
- package/dist/facebook-api/facebook.d.ts +83 -0
- package/dist/facebook-api/facebook.js +165 -0
- package/dist/facebook-api/http.d.ts +2 -0
- package/dist/facebook-api/http.js +14 -0
- package/dist/facebook-api/index.d.ts +2 -0
- package/dist/facebook-api/index.js +1 -0
- package/dist/http/client.d.ts +17 -0
- package/dist/http/client.js +46 -0
- package/dist/http/index.d.ts +2 -0
- package/dist/http/index.js +1 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +8 -0
- package/dist/s3/index.d.ts +1 -0
- package/dist/s3/index.js +1 -0
- package/dist/s3/s3.service.d.ts +29 -0
- package/dist/s3/s3.service.js +60 -0
- package/dist/textract/index.d.ts +1 -0
- package/dist/textract/index.js +1 -0
- package/dist/textract/textract.service.d.ts +14 -0
- package/dist/textract/textract.service.js +63 -0
- package/package.json +103 -0
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
import { CognitoIdentityProviderClient, SignUpCommand, InitiateAuthCommand, RespondToAuthChallengeCommand, ConfirmSignUpCommand, GetUserCommand, AdminGetUserCommand, AdminInitiateAuthCommand, AuthFlowType, ChallengeNameType, } from '@aws-sdk/client-cognito-identity-provider';
|
|
2
|
+
export class CognitoService {
|
|
3
|
+
constructor(config) {
|
|
4
|
+
this.config = config;
|
|
5
|
+
this.client = new CognitoIdentityProviderClient({
|
|
6
|
+
region: config.region,
|
|
7
|
+
});
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Registra un nuevo usuario en Cognito
|
|
11
|
+
*/
|
|
12
|
+
async signUp(params) {
|
|
13
|
+
const { phoneNumber, email, password } = params;
|
|
14
|
+
const userAttributes = [
|
|
15
|
+
{ Name: 'phone_number', Value: phoneNumber },
|
|
16
|
+
];
|
|
17
|
+
if (email) {
|
|
18
|
+
userAttributes.push({ Name: 'email', Value: email });
|
|
19
|
+
}
|
|
20
|
+
const command = new SignUpCommand({
|
|
21
|
+
ClientId: this.config.clientId,
|
|
22
|
+
Username: phoneNumber,
|
|
23
|
+
Password: password,
|
|
24
|
+
UserAttributes: userAttributes,
|
|
25
|
+
});
|
|
26
|
+
const response = await this.client.send(command);
|
|
27
|
+
return {
|
|
28
|
+
userSub: response.UserSub,
|
|
29
|
+
codeDeliveryDetails: response.CodeDeliveryDetails,
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Confirma el registro de un usuario con el código OTP
|
|
34
|
+
*/
|
|
35
|
+
async confirmSignUp(phoneNumber, code) {
|
|
36
|
+
const command = new ConfirmSignUpCommand({
|
|
37
|
+
ClientId: this.config.clientId,
|
|
38
|
+
Username: phoneNumber,
|
|
39
|
+
ConfirmationCode: code,
|
|
40
|
+
});
|
|
41
|
+
await this.client.send(command);
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Inicia sesión con autenticación personalizada (CUSTOM_AUTH)
|
|
45
|
+
*/
|
|
46
|
+
async signInCustomAuth(params) {
|
|
47
|
+
const { phoneNumber } = params;
|
|
48
|
+
const command = new InitiateAuthCommand({
|
|
49
|
+
ClientId: this.config.clientId,
|
|
50
|
+
AuthFlow: AuthFlowType.CUSTOM_AUTH,
|
|
51
|
+
AuthParameters: {
|
|
52
|
+
USERNAME: phoneNumber,
|
|
53
|
+
},
|
|
54
|
+
});
|
|
55
|
+
const response = await this.client.send(command);
|
|
56
|
+
return {
|
|
57
|
+
session: response.Session,
|
|
58
|
+
challengeName: response.ChallengeName,
|
|
59
|
+
challengeParameters: response.ChallengeParameters,
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Inicia sesión con SRP (Secure Remote Password)
|
|
64
|
+
*/
|
|
65
|
+
async signInSRP(params) {
|
|
66
|
+
const { phoneNumber } = params;
|
|
67
|
+
const command = new InitiateAuthCommand({
|
|
68
|
+
ClientId: this.config.clientId,
|
|
69
|
+
AuthFlow: AuthFlowType.USER_SRP_AUTH,
|
|
70
|
+
AuthParameters: {
|
|
71
|
+
USERNAME: phoneNumber,
|
|
72
|
+
},
|
|
73
|
+
});
|
|
74
|
+
const response = await this.client.send(command);
|
|
75
|
+
return {
|
|
76
|
+
session: response.Session,
|
|
77
|
+
challengeName: response.ChallengeName,
|
|
78
|
+
challengeParameters: response.ChallengeParameters,
|
|
79
|
+
accessToken: response.AuthenticationResult?.AccessToken,
|
|
80
|
+
idToken: response.AuthenticationResult?.IdToken,
|
|
81
|
+
refreshToken: response.AuthenticationResult?.RefreshToken,
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Responde al desafío de autenticación (ej: verificar código OTP)
|
|
86
|
+
*/
|
|
87
|
+
async respondToAuthChallenge(params) {
|
|
88
|
+
const { phoneNumber, code, session } = params;
|
|
89
|
+
const command = new RespondToAuthChallengeCommand({
|
|
90
|
+
ClientId: this.config.clientId,
|
|
91
|
+
ChallengeName: ChallengeNameType.CUSTOM_CHALLENGE,
|
|
92
|
+
Session: session,
|
|
93
|
+
ChallengeResponses: {
|
|
94
|
+
USERNAME: phoneNumber,
|
|
95
|
+
ANSWER: code,
|
|
96
|
+
},
|
|
97
|
+
});
|
|
98
|
+
const response = await this.client.send(command);
|
|
99
|
+
return {
|
|
100
|
+
accessToken: response.AuthenticationResult?.AccessToken,
|
|
101
|
+
idToken: response.AuthenticationResult?.IdToken,
|
|
102
|
+
refreshToken: response.AuthenticationResult?.RefreshToken,
|
|
103
|
+
session: response.Session,
|
|
104
|
+
challengeName: response.ChallengeName,
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Refresca el token de acceso usando el refresh token
|
|
109
|
+
*/
|
|
110
|
+
async refreshToken(params) {
|
|
111
|
+
const { refreshToken } = params;
|
|
112
|
+
const command = new InitiateAuthCommand({
|
|
113
|
+
ClientId: this.config.clientId,
|
|
114
|
+
AuthFlow: AuthFlowType.REFRESH_TOKEN_AUTH,
|
|
115
|
+
AuthParameters: {
|
|
116
|
+
REFRESH_TOKEN: refreshToken,
|
|
117
|
+
},
|
|
118
|
+
});
|
|
119
|
+
const response = await this.client.send(command);
|
|
120
|
+
return {
|
|
121
|
+
accessToken: response.AuthenticationResult?.AccessToken,
|
|
122
|
+
idToken: response.AuthenticationResult?.IdToken,
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Obtiene información del usuario autenticado usando el access token
|
|
127
|
+
*/
|
|
128
|
+
async getUser(accessToken) {
|
|
129
|
+
const command = new GetUserCommand({
|
|
130
|
+
AccessToken: accessToken,
|
|
131
|
+
});
|
|
132
|
+
const response = await this.client.send(command);
|
|
133
|
+
const attributes = {};
|
|
134
|
+
response.UserAttributes?.forEach((attr) => {
|
|
135
|
+
if (attr.Name && attr.Value) {
|
|
136
|
+
attributes[attr.Name] = attr.Value;
|
|
137
|
+
}
|
|
138
|
+
});
|
|
139
|
+
return attributes;
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Obtiene información del usuario por username (requiere permisos de admin)
|
|
143
|
+
*/
|
|
144
|
+
async adminGetUser(phoneNumber) {
|
|
145
|
+
const command = new AdminGetUserCommand({
|
|
146
|
+
UserPoolId: this.config.userPoolId,
|
|
147
|
+
Username: phoneNumber,
|
|
148
|
+
});
|
|
149
|
+
const response = await this.client.send(command);
|
|
150
|
+
const attributes = {};
|
|
151
|
+
response.UserAttributes?.forEach((attr) => {
|
|
152
|
+
if (attr.Name && attr.Value) {
|
|
153
|
+
attributes[attr.Name] = attr.Value;
|
|
154
|
+
}
|
|
155
|
+
});
|
|
156
|
+
return attributes;
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Inicia autenticación como admin (útil para backend)
|
|
160
|
+
*/
|
|
161
|
+
async adminInitiateAuth(phoneNumber) {
|
|
162
|
+
const command = new AdminInitiateAuthCommand({
|
|
163
|
+
UserPoolId: this.config.userPoolId,
|
|
164
|
+
ClientId: this.config.clientId,
|
|
165
|
+
AuthFlow: AuthFlowType.CUSTOM_AUTH,
|
|
166
|
+
AuthParameters: {
|
|
167
|
+
USERNAME: phoneNumber,
|
|
168
|
+
},
|
|
169
|
+
});
|
|
170
|
+
const response = await this.client.send(command);
|
|
171
|
+
return {
|
|
172
|
+
session: response.Session,
|
|
173
|
+
challengeName: response.ChallengeName,
|
|
174
|
+
challengeParameters: response.ChallengeParameters,
|
|
175
|
+
accessToken: response.AuthenticationResult?.AccessToken,
|
|
176
|
+
idToken: response.AuthenticationResult?.IdToken,
|
|
177
|
+
refreshToken: response.AuthenticationResult?.RefreshToken,
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
export interface CognitoConfig {
|
|
2
|
+
userPoolId: string;
|
|
3
|
+
clientId: string;
|
|
4
|
+
region: string;
|
|
5
|
+
}
|
|
6
|
+
export interface SignUpParams {
|
|
7
|
+
phoneNumber: string;
|
|
8
|
+
email?: string;
|
|
9
|
+
password: string;
|
|
10
|
+
}
|
|
11
|
+
export interface SignInParams {
|
|
12
|
+
phoneNumber: string;
|
|
13
|
+
password?: string;
|
|
14
|
+
}
|
|
15
|
+
export interface VerifyCodeParams {
|
|
16
|
+
phoneNumber: string;
|
|
17
|
+
code: string;
|
|
18
|
+
session?: string;
|
|
19
|
+
}
|
|
20
|
+
export interface RefreshTokenParams {
|
|
21
|
+
refreshToken: string;
|
|
22
|
+
}
|
|
23
|
+
export interface AuthResponse {
|
|
24
|
+
accessToken?: string;
|
|
25
|
+
idToken?: string;
|
|
26
|
+
refreshToken?: string;
|
|
27
|
+
session?: string;
|
|
28
|
+
challengeName?: string;
|
|
29
|
+
challengeParameters?: Record<string, string>;
|
|
30
|
+
}
|
|
31
|
+
export interface UserAttributes {
|
|
32
|
+
sub?: string;
|
|
33
|
+
phone_number?: string;
|
|
34
|
+
email?: string;
|
|
35
|
+
phone_number_verified?: boolean;
|
|
36
|
+
email_verified?: boolean;
|
|
37
|
+
[key: string]: string | boolean | undefined;
|
|
38
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cliente genérico de DynamoDB
|
|
3
|
+
* Wrapper type-safe sobre AWS SDK
|
|
4
|
+
*/
|
|
5
|
+
export interface DynamoDBConfig {
|
|
6
|
+
region?: string;
|
|
7
|
+
endpoint?: string;
|
|
8
|
+
}
|
|
9
|
+
export interface PutItemOptions {
|
|
10
|
+
conditionExpression?: string;
|
|
11
|
+
expressionAttributeNames?: Record<string, string>;
|
|
12
|
+
expressionAttributeValues?: Record<string, any>;
|
|
13
|
+
}
|
|
14
|
+
export interface UpdateItemOptions {
|
|
15
|
+
updateExpression: string;
|
|
16
|
+
conditionExpression?: string;
|
|
17
|
+
expressionAttributeNames?: Record<string, string>;
|
|
18
|
+
expressionAttributeValues?: Record<string, any>;
|
|
19
|
+
}
|
|
20
|
+
export interface QueryOptions {
|
|
21
|
+
indexName?: string;
|
|
22
|
+
keyConditionExpression: string;
|
|
23
|
+
filterExpression?: string;
|
|
24
|
+
expressionAttributeNames?: Record<string, string>;
|
|
25
|
+
expressionAttributeValues?: Record<string, any>;
|
|
26
|
+
limit?: number;
|
|
27
|
+
scanIndexForward?: boolean;
|
|
28
|
+
}
|
|
29
|
+
export declare class DynamoDBClientWrapper {
|
|
30
|
+
private client;
|
|
31
|
+
constructor(config?: DynamoDBConfig);
|
|
32
|
+
/**
|
|
33
|
+
* Inserta o actualiza un item
|
|
34
|
+
*/
|
|
35
|
+
put<T extends Record<string, any>>(tableName: string, item: T, options?: PutItemOptions): Promise<void>;
|
|
36
|
+
/**
|
|
37
|
+
* Obtiene un item por su clave primaria
|
|
38
|
+
*/
|
|
39
|
+
get<T extends Record<string, any>>(tableName: string, key: Record<string, any>): Promise<T | null>;
|
|
40
|
+
/**
|
|
41
|
+
* Actualiza un item
|
|
42
|
+
*/
|
|
43
|
+
update<T extends Record<string, any>>(tableName: string, key: Record<string, any>, options: UpdateItemOptions): Promise<T>;
|
|
44
|
+
/**
|
|
45
|
+
* Elimina un item
|
|
46
|
+
*/
|
|
47
|
+
delete(tableName: string, key: Record<string, any>): Promise<void>;
|
|
48
|
+
/**
|
|
49
|
+
* Query con índice o clave primaria
|
|
50
|
+
*/
|
|
51
|
+
query<T extends Record<string, any>>(tableName: string, options: QueryOptions): Promise<T[]>;
|
|
52
|
+
/**
|
|
53
|
+
* Scan completo de la tabla (usar con cuidado)
|
|
54
|
+
*/
|
|
55
|
+
scan<T extends Record<string, any>>(tableName: string, limit?: number): Promise<T[]>;
|
|
56
|
+
/**
|
|
57
|
+
* Batch write (put o delete múltiples items)
|
|
58
|
+
*/
|
|
59
|
+
batchWrite(tableName: string, items: Array<{
|
|
60
|
+
put?: Record<string, any>;
|
|
61
|
+
delete?: Record<string, any>;
|
|
62
|
+
}>): Promise<void>;
|
|
63
|
+
/**
|
|
64
|
+
* Batch get (obtener múltiples items)
|
|
65
|
+
*/
|
|
66
|
+
batchGet<T extends Record<string, any>>(tableName: string, keys: Array<Record<string, any>>): Promise<T[]>;
|
|
67
|
+
}
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cliente genérico de DynamoDB
|
|
3
|
+
* Wrapper type-safe sobre AWS SDK
|
|
4
|
+
*/
|
|
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 {
|
|
8
|
+
constructor(config = {}) {
|
|
9
|
+
this.client = new DynamoDBClient({
|
|
10
|
+
region: config.region || process.env.AWS_REGION || 'us-east-1',
|
|
11
|
+
...(config.endpoint && { endpoint: config.endpoint }),
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Inserta o actualiza un item
|
|
16
|
+
*/
|
|
17
|
+
async put(tableName, item, options) {
|
|
18
|
+
const command = new PutItemCommand({
|
|
19
|
+
TableName: tableName,
|
|
20
|
+
Item: marshall(item, { removeUndefinedValues: true }),
|
|
21
|
+
...(options?.conditionExpression && {
|
|
22
|
+
ConditionExpression: options.conditionExpression,
|
|
23
|
+
}),
|
|
24
|
+
...(options?.expressionAttributeNames && {
|
|
25
|
+
ExpressionAttributeNames: options.expressionAttributeNames,
|
|
26
|
+
}),
|
|
27
|
+
...(options?.expressionAttributeValues && {
|
|
28
|
+
ExpressionAttributeValues: marshall(options.expressionAttributeValues),
|
|
29
|
+
}),
|
|
30
|
+
});
|
|
31
|
+
await this.client.send(command);
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Obtiene un item por su clave primaria
|
|
35
|
+
*/
|
|
36
|
+
async get(tableName, key) {
|
|
37
|
+
const command = new GetItemCommand({
|
|
38
|
+
TableName: tableName,
|
|
39
|
+
Key: marshall(key),
|
|
40
|
+
});
|
|
41
|
+
const response = await this.client.send(command);
|
|
42
|
+
if (!response.Item) {
|
|
43
|
+
return null;
|
|
44
|
+
}
|
|
45
|
+
return unmarshall(response.Item);
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Actualiza un item
|
|
49
|
+
*/
|
|
50
|
+
async update(tableName, key, options) {
|
|
51
|
+
const command = new UpdateItemCommand({
|
|
52
|
+
TableName: tableName,
|
|
53
|
+
Key: marshall(key),
|
|
54
|
+
UpdateExpression: options.updateExpression,
|
|
55
|
+
...(options.conditionExpression && {
|
|
56
|
+
ConditionExpression: options.conditionExpression,
|
|
57
|
+
}),
|
|
58
|
+
...(options.expressionAttributeNames && {
|
|
59
|
+
ExpressionAttributeNames: options.expressionAttributeNames,
|
|
60
|
+
}),
|
|
61
|
+
...(options.expressionAttributeValues && {
|
|
62
|
+
ExpressionAttributeValues: marshall(options.expressionAttributeValues),
|
|
63
|
+
}),
|
|
64
|
+
ReturnValues: 'ALL_NEW',
|
|
65
|
+
});
|
|
66
|
+
const response = await this.client.send(command);
|
|
67
|
+
return unmarshall(response.Attributes);
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Elimina un item
|
|
71
|
+
*/
|
|
72
|
+
async delete(tableName, key) {
|
|
73
|
+
const command = new DeleteItemCommand({
|
|
74
|
+
TableName: tableName,
|
|
75
|
+
Key: marshall(key),
|
|
76
|
+
});
|
|
77
|
+
await this.client.send(command);
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Query con índice o clave primaria
|
|
81
|
+
*/
|
|
82
|
+
async query(tableName, options) {
|
|
83
|
+
const command = new QueryCommand({
|
|
84
|
+
TableName: tableName,
|
|
85
|
+
...(options.indexName && { IndexName: options.indexName }),
|
|
86
|
+
KeyConditionExpression: options.keyConditionExpression,
|
|
87
|
+
...(options.filterExpression && {
|
|
88
|
+
FilterExpression: options.filterExpression,
|
|
89
|
+
}),
|
|
90
|
+
...(options.expressionAttributeNames && {
|
|
91
|
+
ExpressionAttributeNames: options.expressionAttributeNames,
|
|
92
|
+
}),
|
|
93
|
+
...(options.expressionAttributeValues && {
|
|
94
|
+
ExpressionAttributeValues: marshall(options.expressionAttributeValues),
|
|
95
|
+
}),
|
|
96
|
+
...(options.limit && { Limit: options.limit }),
|
|
97
|
+
...(options.scanIndexForward !== undefined && {
|
|
98
|
+
ScanIndexForward: options.scanIndexForward,
|
|
99
|
+
}),
|
|
100
|
+
});
|
|
101
|
+
const response = await this.client.send(command);
|
|
102
|
+
if (!response.Items || response.Items.length === 0) {
|
|
103
|
+
return [];
|
|
104
|
+
}
|
|
105
|
+
return response.Items.map((item) => unmarshall(item));
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Scan completo de la tabla (usar con cuidado)
|
|
109
|
+
*/
|
|
110
|
+
async scan(tableName, limit) {
|
|
111
|
+
const command = new ScanCommand({
|
|
112
|
+
TableName: tableName,
|
|
113
|
+
...(limit && { Limit: limit }),
|
|
114
|
+
});
|
|
115
|
+
const response = await this.client.send(command);
|
|
116
|
+
if (!response.Items || response.Items.length === 0) {
|
|
117
|
+
return [];
|
|
118
|
+
}
|
|
119
|
+
return response.Items.map((item) => unmarshall(item));
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Batch write (put o delete múltiples items)
|
|
123
|
+
*/
|
|
124
|
+
async batchWrite(tableName, items) {
|
|
125
|
+
const requests = items.map((item) => {
|
|
126
|
+
if (item.put) {
|
|
127
|
+
return {
|
|
128
|
+
PutRequest: {
|
|
129
|
+
Item: marshall(item.put, { removeUndefinedValues: true }),
|
|
130
|
+
},
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
else if (item.delete) {
|
|
134
|
+
return {
|
|
135
|
+
DeleteRequest: {
|
|
136
|
+
Key: marshall(item.delete),
|
|
137
|
+
},
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
throw new Error('Invalid batch write item');
|
|
141
|
+
});
|
|
142
|
+
const command = new BatchWriteItemCommand({
|
|
143
|
+
RequestItems: {
|
|
144
|
+
[tableName]: requests,
|
|
145
|
+
},
|
|
146
|
+
});
|
|
147
|
+
await this.client.send(command);
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Batch get (obtener múltiples items)
|
|
151
|
+
*/
|
|
152
|
+
async batchGet(tableName, keys) {
|
|
153
|
+
const command = new BatchGetItemCommand({
|
|
154
|
+
RequestItems: {
|
|
155
|
+
[tableName]: {
|
|
156
|
+
Keys: keys.map((key) => marshall(key)),
|
|
157
|
+
},
|
|
158
|
+
},
|
|
159
|
+
});
|
|
160
|
+
const response = await this.client.send(command);
|
|
161
|
+
if (!response.Responses || !response.Responses[tableName]) {
|
|
162
|
+
return [];
|
|
163
|
+
}
|
|
164
|
+
return response.Responses[tableName].map((item) => unmarshall(item));
|
|
165
|
+
}
|
|
166
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './dynamodb.client.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './dynamodb.client.js';
|
|
@@ -0,0 +1,83 @@
|
|
|
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 declare class FacebookApi {
|
|
69
|
+
private static token;
|
|
70
|
+
private static phoneNumberId;
|
|
71
|
+
private static apiVersion;
|
|
72
|
+
private static init;
|
|
73
|
+
private static post;
|
|
74
|
+
static sendText(params: SendTextParams): Promise<any>;
|
|
75
|
+
static sendTemplate(params: SendTemplateParams): Promise<any>;
|
|
76
|
+
static sendInteractiveButtons(params: SendInteractiveParams): Promise<any>;
|
|
77
|
+
static sendInteractiveList(params: SendInteractiveListParams): Promise<any>;
|
|
78
|
+
static sendImage(params: SendImageParams): Promise<any>;
|
|
79
|
+
static sendDocument(params: SendDocumentParams): Promise<any>;
|
|
80
|
+
static sendLocation(params: SendLocationParams): Promise<any>;
|
|
81
|
+
static setTyping(params: SetTypingParams): Promise<any>;
|
|
82
|
+
static markAsRead(params: MarkAsReadParams): Promise<any>;
|
|
83
|
+
}
|