@rempays/shared-core 1.0.2-beta.1 → 1.0.2-beta.11

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.
Files changed (45) hide show
  1. package/README.md +133 -267
  2. package/dist/auth/authorizer-example.js +7 -3
  3. package/dist/auth/index.js +5 -1
  4. package/dist/auth/jwt-validator.js +7 -3
  5. package/dist/auth/types.js +2 -1
  6. package/dist/cognito/cognito.service.js +21 -17
  7. package/dist/cognito/index.js +20 -2
  8. package/dist/cognito/types.js +2 -1
  9. package/dist/dynamodb/dynamodb.client.d.ts +56 -6
  10. package/dist/dynamodb/dynamodb.client.js +191 -34
  11. package/dist/dynamodb/index.d.ts +1 -0
  12. package/dist/dynamodb/index.js +18 -1
  13. package/dist/dynamodb/modules/chat/chat.service.d.ts +59 -0
  14. package/dist/dynamodb/modules/chat/chat.service.js +294 -0
  15. package/dist/dynamodb/modules/chat/index.d.ts +2 -0
  16. package/dist/dynamodb/modules/chat/index.js +18 -0
  17. package/dist/dynamodb/modules/chat/types.d.ts +27 -0
  18. package/dist/dynamodb/modules/chat/types.js +2 -0
  19. package/dist/dynamodb/modules/index.d.ts +2 -0
  20. package/dist/dynamodb/modules/index.js +18 -0
  21. package/dist/dynamodb/modules/shared-types.d.ts +10 -0
  22. package/dist/dynamodb/modules/shared-types.js +2 -0
  23. package/dist/dynamodb/modules/system-prompt/index.d.ts +2 -0
  24. package/dist/dynamodb/modules/system-prompt/index.js +18 -0
  25. package/dist/dynamodb/modules/system-prompt/system-prompt.service.d.ts +51 -0
  26. package/dist/dynamodb/modules/system-prompt/system-prompt.service.js +262 -0
  27. package/dist/dynamodb/modules/system-prompt/types.d.ts +13 -0
  28. package/dist/dynamodb/modules/system-prompt/types.js +2 -0
  29. package/dist/facebook-api/embedded-signup.d.ts +56 -0
  30. package/dist/facebook-api/embedded-signup.js +203 -0
  31. package/dist/facebook-api/facebook.d.ts +1 -67
  32. package/dist/facebook-api/facebook.js +7 -3
  33. package/dist/facebook-api/http.js +9 -3
  34. package/dist/facebook-api/index.d.ts +7 -2
  35. package/dist/facebook-api/index.js +27 -1
  36. package/dist/facebook-api/types.d.ts +109 -0
  37. package/dist/facebook-api/types.js +2 -0
  38. package/dist/http/client.js +12 -4
  39. package/dist/http/index.js +6 -1
  40. package/dist/index.js +23 -7
  41. package/dist/s3/index.js +17 -1
  42. package/dist/s3/s3.service.js +9 -5
  43. package/dist/textract/index.js +17 -1
  44. package/dist/textract/textract.service.js +9 -5
  45. package/package.json +2 -2
@@ -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,7 +1,4 @@
1
- /**
2
- * Cliente genérico de DynamoDB
3
- * Wrapper type-safe sobre AWS SDK
4
- */
1
+ import type { PaginatedResult } from './modules/shared-types.js';
5
2
  export interface DynamoDBConfig {
6
3
  region?: string;
7
4
  endpoint?: string;
@@ -25,6 +22,7 @@ export interface QueryOptions {
25
22
  expressionAttributeValues?: Record<string, any>;
26
23
  limit?: number;
27
24
  scanIndexForward?: boolean;
25
+ lastEvaluatedKey?: Record<string, any>;
28
26
  }
29
27
  export declare class DynamoDBClientWrapper {
30
28
  private client;
@@ -46,9 +44,33 @@ export declare class DynamoDBClientWrapper {
46
44
  */
47
45
  delete(tableName: string, key: Record<string, any>): Promise<void>;
48
46
  /**
49
- * Query con índice o clave primaria
47
+ * Query con índice o clave primaria (con paginación)
50
48
  */
51
- query<T extends Record<string, any>>(tableName: string, options: QueryOptions): Promise<T[]>;
49
+ query<T extends Record<string, any>>(tableName: string, options: QueryOptions): Promise<PaginatedResult<T>>;
50
+ /**
51
+ * Query simple por PK (Partition Key)
52
+ */
53
+ queryByPK<T extends Record<string, any>>(tableName: string, pkName: string, pkValue: any, options?: {
54
+ limit?: number;
55
+ scanIndexForward?: boolean;
56
+ lastEvaluatedKey?: Record<string, any>;
57
+ }): Promise<PaginatedResult<T>>;
58
+ /**
59
+ * Query por PK y SK (Sort Key) con operador
60
+ */
61
+ queryByPKAndSK<T extends Record<string, any>>(tableName: string, pkName: string, pkValue: any, skName: string, skOperator: '=' | '<' | '<=' | '>' | '>=' | 'BETWEEN' | 'begins_with', skValue: any, skValue2?: any, // Para BETWEEN
62
+ options?: {
63
+ limit?: number;
64
+ scanIndexForward?: boolean;
65
+ lastEvaluatedKey?: Record<string, any>;
66
+ indexName?: string;
67
+ }): Promise<PaginatedResult<T>>;
68
+ /**
69
+ * Query todos los items por PK (sin límite, con paginación automática)
70
+ */
71
+ queryAllByPK<T extends Record<string, any>>(tableName: string, pkName: string, pkValue: any, options?: {
72
+ scanIndexForward?: boolean;
73
+ }): Promise<T[]>;
52
74
  /**
53
75
  * Scan completo de la tabla (usar con cuidado)
54
76
  */
@@ -64,4 +86,32 @@ export declare class DynamoDBClientWrapper {
64
86
  * Batch get (obtener múltiples items)
65
87
  */
66
88
  batchGet<T extends Record<string, any>>(tableName: string, keys: Array<Record<string, any>>): Promise<T[]>;
89
+ /**
90
+ * Verifica si un item existe
91
+ */
92
+ exists(tableName: string, key: Record<string, any>): Promise<boolean>;
93
+ /**
94
+ * Incrementa un atributo numérico
95
+ */
96
+ increment<T extends Record<string, any>>(tableName: string, key: Record<string, any>, attributeName: string, incrementBy?: number): Promise<T>;
97
+ /**
98
+ * Decrementa un atributo numérico
99
+ */
100
+ decrement<T extends Record<string, any>>(tableName: string, key: Record<string, any>, attributeName: string, decrementBy?: number): Promise<T>;
101
+ /**
102
+ * Agrega items a una lista (array)
103
+ */
104
+ appendToList<T extends Record<string, any>>(tableName: string, key: Record<string, any>, attributeName: string, values: any[]): Promise<T>;
105
+ /**
106
+ * Agrega items a un Set
107
+ */
108
+ addToSet<T extends Record<string, any>>(tableName: string, key: Record<string, any>, attributeName: string, values: any[]): Promise<T>;
109
+ /**
110
+ * Elimina items de un Set
111
+ */
112
+ removeFromSet<T extends Record<string, any>>(tableName: string, key: Record<string, any>, attributeName: string, values: any[]): Promise<T>;
113
+ /**
114
+ * Elimina un atributo
115
+ */
116
+ removeAttribute<T extends Record<string, any>>(tableName: string, key: Record<string, any>, attributeName: string): Promise<T>;
67
117
  }
@@ -1,12 +1,11 @@
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 {
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DynamoDBClientWrapper = void 0;
4
+ const client_dynamodb_1 = require("@aws-sdk/client-dynamodb");
5
+ const util_dynamodb_1 = require("@aws-sdk/util-dynamodb");
6
+ class DynamoDBClientWrapper {
8
7
  constructor(config = {}) {
9
- this.client = new DynamoDBClient({
8
+ this.client = new client_dynamodb_1.DynamoDBClient({
10
9
  region: config.region || process.env.AWS_REGION || 'us-east-1',
11
10
  ...(config.endpoint && { endpoint: config.endpoint }),
12
11
  });
@@ -15,9 +14,9 @@ export class DynamoDBClientWrapper {
15
14
  * Inserta o actualiza un item
16
15
  */
17
16
  async put(tableName, item, options) {
18
- const command = new PutItemCommand({
17
+ const command = new client_dynamodb_1.PutItemCommand({
19
18
  TableName: tableName,
20
- Item: marshall(item, { removeUndefinedValues: true }),
19
+ Item: (0, util_dynamodb_1.marshall)(item, { removeUndefinedValues: true }),
21
20
  ...(options?.conditionExpression && {
22
21
  ConditionExpression: options.conditionExpression,
23
22
  }),
@@ -25,7 +24,7 @@ export class DynamoDBClientWrapper {
25
24
  ExpressionAttributeNames: options.expressionAttributeNames,
26
25
  }),
27
26
  ...(options?.expressionAttributeValues && {
28
- ExpressionAttributeValues: marshall(options.expressionAttributeValues),
27
+ ExpressionAttributeValues: (0, util_dynamodb_1.marshall)(options.expressionAttributeValues),
29
28
  }),
30
29
  });
31
30
  await this.client.send(command);
@@ -34,23 +33,23 @@ export class DynamoDBClientWrapper {
34
33
  * Obtiene un item por su clave primaria
35
34
  */
36
35
  async get(tableName, key) {
37
- const command = new GetItemCommand({
36
+ const command = new client_dynamodb_1.GetItemCommand({
38
37
  TableName: tableName,
39
- Key: marshall(key),
38
+ Key: (0, util_dynamodb_1.marshall)(key),
40
39
  });
41
40
  const response = await this.client.send(command);
42
41
  if (!response.Item) {
43
42
  return null;
44
43
  }
45
- return unmarshall(response.Item);
44
+ return (0, util_dynamodb_1.unmarshall)(response.Item);
46
45
  }
47
46
  /**
48
47
  * Actualiza un item
49
48
  */
50
49
  async update(tableName, key, options) {
51
- const command = new UpdateItemCommand({
50
+ const command = new client_dynamodb_1.UpdateItemCommand({
52
51
  TableName: tableName,
53
- Key: marshall(key),
52
+ Key: (0, util_dynamodb_1.marshall)(key),
54
53
  UpdateExpression: options.updateExpression,
55
54
  ...(options.conditionExpression && {
56
55
  ConditionExpression: options.conditionExpression,
@@ -59,28 +58,28 @@ export class DynamoDBClientWrapper {
59
58
  ExpressionAttributeNames: options.expressionAttributeNames,
60
59
  }),
61
60
  ...(options.expressionAttributeValues && {
62
- ExpressionAttributeValues: marshall(options.expressionAttributeValues),
61
+ ExpressionAttributeValues: (0, util_dynamodb_1.marshall)(options.expressionAttributeValues),
63
62
  }),
64
63
  ReturnValues: 'ALL_NEW',
65
64
  });
66
65
  const response = await this.client.send(command);
67
- return unmarshall(response.Attributes);
66
+ return (0, util_dynamodb_1.unmarshall)(response.Attributes);
68
67
  }
69
68
  /**
70
69
  * Elimina un item
71
70
  */
72
71
  async delete(tableName, key) {
73
- const command = new DeleteItemCommand({
72
+ const command = new client_dynamodb_1.DeleteItemCommand({
74
73
  TableName: tableName,
75
- Key: marshall(key),
74
+ Key: (0, util_dynamodb_1.marshall)(key),
76
75
  });
77
76
  await this.client.send(command);
78
77
  }
79
78
  /**
80
- * Query con índice o clave primaria
79
+ * Query con índice o clave primaria (con paginación)
81
80
  */
82
81
  async query(tableName, options) {
83
- const command = new QueryCommand({
82
+ const command = new client_dynamodb_1.QueryCommand({
84
83
  TableName: tableName,
85
84
  ...(options.indexName && { IndexName: options.indexName }),
86
85
  KeyConditionExpression: options.keyConditionExpression,
@@ -91,24 +90,99 @@ export class DynamoDBClientWrapper {
91
90
  ExpressionAttributeNames: options.expressionAttributeNames,
92
91
  }),
93
92
  ...(options.expressionAttributeValues && {
94
- ExpressionAttributeValues: marshall(options.expressionAttributeValues),
93
+ ExpressionAttributeValues: (0, util_dynamodb_1.marshall)(options.expressionAttributeValues),
95
94
  }),
96
95
  ...(options.limit && { Limit: options.limit }),
97
96
  ...(options.scanIndexForward !== undefined && {
98
97
  ScanIndexForward: options.scanIndexForward,
99
98
  }),
99
+ ...(options.lastEvaluatedKey && {
100
+ ExclusiveStartKey: (0, util_dynamodb_1.marshall)(options.lastEvaluatedKey),
101
+ }),
100
102
  });
101
103
  const response = await this.client.send(command);
102
- if (!response.Items || response.Items.length === 0) {
103
- return [];
104
+ const items = response.Items?.map((item) => (0, util_dynamodb_1.unmarshall)(item)) || [];
105
+ const lastEvaluatedKey = response.LastEvaluatedKey
106
+ ? (0, util_dynamodb_1.unmarshall)(response.LastEvaluatedKey)
107
+ : undefined;
108
+ return {
109
+ items,
110
+ lastEvaluatedKey,
111
+ hasMore: !!lastEvaluatedKey,
112
+ count: items.length,
113
+ };
114
+ }
115
+ /**
116
+ * Query simple por PK (Partition Key)
117
+ */
118
+ async queryByPK(tableName, pkName, pkValue, options) {
119
+ return this.query(tableName, {
120
+ keyConditionExpression: `#pk = :pk`,
121
+ expressionAttributeNames: { '#pk': pkName },
122
+ expressionAttributeValues: { ':pk': pkValue },
123
+ ...options,
124
+ });
125
+ }
126
+ /**
127
+ * Query por PK y SK (Sort Key) con operador
128
+ */
129
+ async queryByPKAndSK(tableName, pkName, pkValue, skName, skOperator, skValue, skValue2, // Para BETWEEN
130
+ options) {
131
+ let keyConditionExpression;
132
+ let expressionAttributeValues;
133
+ if (skOperator === 'BETWEEN' && skValue2 !== undefined) {
134
+ keyConditionExpression = `#pk = :pk AND #sk BETWEEN :sk1 AND :sk2`;
135
+ expressionAttributeValues = {
136
+ ':pk': pkValue,
137
+ ':sk1': skValue,
138
+ ':sk2': skValue2,
139
+ };
104
140
  }
105
- return response.Items.map((item) => unmarshall(item));
141
+ else if (skOperator === 'begins_with') {
142
+ keyConditionExpression = `#pk = :pk AND begins_with(#sk, :sk)`;
143
+ expressionAttributeValues = {
144
+ ':pk': pkValue,
145
+ ':sk': skValue,
146
+ };
147
+ }
148
+ else {
149
+ keyConditionExpression = `#pk = :pk AND #sk ${skOperator} :sk`;
150
+ expressionAttributeValues = {
151
+ ':pk': pkValue,
152
+ ':sk': skValue,
153
+ };
154
+ }
155
+ return this.query(tableName, {
156
+ keyConditionExpression,
157
+ expressionAttributeNames: {
158
+ '#pk': pkName,
159
+ '#sk': skName,
160
+ },
161
+ expressionAttributeValues,
162
+ ...options,
163
+ });
164
+ }
165
+ /**
166
+ * Query todos los items por PK (sin límite, con paginación automática)
167
+ */
168
+ async queryAllByPK(tableName, pkName, pkValue, options) {
169
+ const allItems = [];
170
+ let lastEvaluatedKey;
171
+ do {
172
+ const result = await this.queryByPK(tableName, pkName, pkValue, {
173
+ ...options,
174
+ lastEvaluatedKey,
175
+ });
176
+ allItems.push(...result.items);
177
+ lastEvaluatedKey = result.lastEvaluatedKey;
178
+ } while (lastEvaluatedKey);
179
+ return allItems;
106
180
  }
107
181
  /**
108
182
  * Scan completo de la tabla (usar con cuidado)
109
183
  */
110
184
  async scan(tableName, limit) {
111
- const command = new ScanCommand({
185
+ const command = new client_dynamodb_1.ScanCommand({
112
186
  TableName: tableName,
113
187
  ...(limit && { Limit: limit }),
114
188
  });
@@ -116,7 +190,7 @@ export class DynamoDBClientWrapper {
116
190
  if (!response.Items || response.Items.length === 0) {
117
191
  return [];
118
192
  }
119
- return response.Items.map((item) => unmarshall(item));
193
+ return response.Items.map((item) => (0, util_dynamodb_1.unmarshall)(item));
120
194
  }
121
195
  /**
122
196
  * Batch write (put o delete múltiples items)
@@ -126,20 +200,20 @@ export class DynamoDBClientWrapper {
126
200
  if (item.put) {
127
201
  return {
128
202
  PutRequest: {
129
- Item: marshall(item.put, { removeUndefinedValues: true }),
203
+ Item: (0, util_dynamodb_1.marshall)(item.put, { removeUndefinedValues: true }),
130
204
  },
131
205
  };
132
206
  }
133
207
  else if (item.delete) {
134
208
  return {
135
209
  DeleteRequest: {
136
- Key: marshall(item.delete),
210
+ Key: (0, util_dynamodb_1.marshall)(item.delete),
137
211
  },
138
212
  };
139
213
  }
140
214
  throw new Error('Invalid batch write item');
141
215
  });
142
- const command = new BatchWriteItemCommand({
216
+ const command = new client_dynamodb_1.BatchWriteItemCommand({
143
217
  RequestItems: {
144
218
  [tableName]: requests,
145
219
  },
@@ -150,10 +224,10 @@ export class DynamoDBClientWrapper {
150
224
  * Batch get (obtener múltiples items)
151
225
  */
152
226
  async batchGet(tableName, keys) {
153
- const command = new BatchGetItemCommand({
227
+ const command = new client_dynamodb_1.BatchGetItemCommand({
154
228
  RequestItems: {
155
229
  [tableName]: {
156
- Keys: keys.map((key) => marshall(key)),
230
+ Keys: keys.map((key) => (0, util_dynamodb_1.marshall)(key)),
157
231
  },
158
232
  },
159
233
  });
@@ -161,6 +235,89 @@ export class DynamoDBClientWrapper {
161
235
  if (!response.Responses || !response.Responses[tableName]) {
162
236
  return [];
163
237
  }
164
- return response.Responses[tableName].map((item) => unmarshall(item));
238
+ return response.Responses[tableName].map((item) => (0, util_dynamodb_1.unmarshall)(item));
239
+ }
240
+ /**
241
+ * Verifica si un item existe
242
+ */
243
+ async exists(tableName, key) {
244
+ const item = await this.get(tableName, key);
245
+ return item !== null;
246
+ }
247
+ /**
248
+ * Incrementa un atributo numérico
249
+ */
250
+ async increment(tableName, key, attributeName, incrementBy = 1) {
251
+ return this.update(tableName, key, {
252
+ updateExpression: `SET #attr = if_not_exists(#attr, :zero) + :inc`,
253
+ expressionAttributeNames: {
254
+ '#attr': attributeName,
255
+ },
256
+ expressionAttributeValues: {
257
+ ':zero': 0,
258
+ ':inc': incrementBy,
259
+ },
260
+ });
261
+ }
262
+ /**
263
+ * Decrementa un atributo numérico
264
+ */
265
+ async decrement(tableName, key, attributeName, decrementBy = 1) {
266
+ return this.increment(tableName, key, attributeName, -decrementBy);
267
+ }
268
+ /**
269
+ * Agrega items a una lista (array)
270
+ */
271
+ async appendToList(tableName, key, attributeName, values) {
272
+ return this.update(tableName, key, {
273
+ updateExpression: `SET #attr = list_append(if_not_exists(#attr, :empty), :vals)`,
274
+ expressionAttributeNames: {
275
+ '#attr': attributeName,
276
+ },
277
+ expressionAttributeValues: {
278
+ ':empty': [],
279
+ ':vals': values,
280
+ },
281
+ });
282
+ }
283
+ /**
284
+ * Agrega items a un Set
285
+ */
286
+ async addToSet(tableName, key, attributeName, values) {
287
+ return this.update(tableName, key, {
288
+ updateExpression: `ADD #attr :vals`,
289
+ expressionAttributeNames: {
290
+ '#attr': attributeName,
291
+ },
292
+ expressionAttributeValues: {
293
+ ':vals': new Set(values),
294
+ },
295
+ });
296
+ }
297
+ /**
298
+ * Elimina items de un Set
299
+ */
300
+ async removeFromSet(tableName, key, attributeName, values) {
301
+ return this.update(tableName, key, {
302
+ updateExpression: `DELETE #attr :vals`,
303
+ expressionAttributeNames: {
304
+ '#attr': attributeName,
305
+ },
306
+ expressionAttributeValues: {
307
+ ':vals': new Set(values),
308
+ },
309
+ });
310
+ }
311
+ /**
312
+ * Elimina un atributo
313
+ */
314
+ async removeAttribute(tableName, key, attributeName) {
315
+ return this.update(tableName, key, {
316
+ updateExpression: `REMOVE #attr`,
317
+ expressionAttributeNames: {
318
+ '#attr': attributeName,
319
+ },
320
+ });
165
321
  }
166
322
  }
323
+ exports.DynamoDBClientWrapper = DynamoDBClientWrapper;
@@ -1 +1,2 @@
1
1
  export * from './dynamodb.client.js';
2
+ export * from './modules/index.js';
@@ -1 +1,18 @@
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.js"), exports);
18
+ __exportStar(require("./modules/index.js"), exports);
@@ -0,0 +1,59 @@
1
+ import type { Chat, Message, ChatWithMessages } from './types.js';
2
+ import type { PaginatedResult, PaginationParams } from '../shared-types.js';
3
+ export declare class ChatService {
4
+ private client;
5
+ private tableName;
6
+ constructor(tableName?: string, region?: string);
7
+ /**
8
+ * Crea un nuevo chat
9
+ */
10
+ createChat(chat: Omit<Chat, 'createdAt' | 'updatedAt'>): Promise<Chat>;
11
+ /**
12
+ * Obtiene un chat por ID
13
+ */
14
+ getChat(chatId: string): Promise<Chat | null>;
15
+ /**
16
+ * Actualiza un chat
17
+ */
18
+ updateChat(chatId: string, updates: Partial<Omit<Chat, 'chatId' | 'createdAt'>>): Promise<Chat>;
19
+ /**
20
+ * Elimina un chat y todos sus mensajes
21
+ */
22
+ deleteChat(chatId: string): Promise<void>;
23
+ /**
24
+ * Agrega un mensaje a un chat
25
+ */
26
+ addMessage(chatId: string, message: Omit<Message, 'chatId'>): Promise<Message>;
27
+ /**
28
+ * Obtiene mensajes de un chat (paginados)
29
+ */
30
+ getMessages(chatId: string, params?: PaginationParams): Promise<PaginatedResult<Message>>;
31
+ /**
32
+ * Obtiene los últimos N mensajes de un chat
33
+ */
34
+ getLastMessages(chatId: string, count?: number): Promise<Message[]>;
35
+ /**
36
+ * Obtiene todos los mensajes de un chat (sin paginación)
37
+ */
38
+ private getAllMessages;
39
+ /**
40
+ * Obtiene un chat con sus mensajes
41
+ */
42
+ getChatWithMessages(chatId: string, messageLimit?: number): Promise<ChatWithMessages | null>;
43
+ /**
44
+ * Lista chats por business y status (paginados)
45
+ */
46
+ listChatsByBusiness(businessId: string, status: string, params?: PaginationParams): Promise<PaginatedResult<Chat>>;
47
+ /**
48
+ * Lista todos los chats de un business (todos los status)
49
+ */
50
+ listAllChatsByBusiness(businessId: string, params?: PaginationParams): Promise<PaginatedResult<Chat>>;
51
+ /**
52
+ * Incrementa el contador de mensajes no leídos
53
+ */
54
+ incrementUnreadCount(chatId: string): Promise<void>;
55
+ /**
56
+ * Marca todos los mensajes como leídos
57
+ */
58
+ markAsRead(chatId: string): Promise<void>;
59
+ }