idea-aws 3.16.7 → 4.0.0

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,40 +1,40 @@
1
- import { DynamoDB as DDB } from 'aws-sdk';
1
+ import * as DDB from '@aws-sdk/lib-dynamodb';
2
+ import { AttributeValue, TransactWriteItem } from '@aws-sdk/client-dynamodb';
3
+ import * as DDBUtils from '@aws-sdk/util-dynamodb';
2
4
  import { Logger } from './logger';
3
5
  /**
4
6
  * A wrapper for AWS DynamoDB.
5
7
  */
6
8
  export declare class DynamoDB {
7
- protected dynamo: DDB.DocumentClient;
9
+ protected dynamo: DDB.DynamoDBDocument;
8
10
  logger: Logger;
9
11
  constructor(options?: {
10
12
  debug: boolean;
11
13
  });
12
14
  /**
13
- * Convert a JSON object from dynamoDB format to simple JSON.
15
+ * Convert a JSON object from DynamoDB format to simple JSON.
16
+ * @data the data in DynamoDB's original format to convert in plain objects
17
+ * @options the options to use to convert the data
14
18
  */
15
- unmarshall(data: DDB.AttributeMap, options?: DDB.DocumentClient.ConverterOptions): {
16
- [key: string]: any;
17
- };
19
+ unmarshall(data: Record<string, AttributeValue>, options?: DDBUtils.unmarshallOptions): Record<string, any>;
18
20
  /**
19
- * Returns an IUID: IDEA's Unique IDentifier, which is an id unique through all IDEA's projects.
20
- * Note: there's no need of an authorization check for extrernal uses: the permissions depend
21
- * from the context in which it's executed.
21
+ * Returns an IUID: IDEA's Unique IDentifier, which is an id unique through an IDEA's AWS account and region.
22
+ * Note: no need of an auth check for external uses: the permissions depend from the context in which it's executed.
22
23
  * @deprecated use IUNID instead (nano version)
23
24
  * @param project project code
24
25
  * @return the IUID
25
26
  */
26
27
  IUID(project: string): Promise<string>;
27
28
  /**
28
- * Returns an IUNID: IDEA's Unique Nano IDentifier, which is an id unique through all IDEA's projects.
29
+ * Returns an IUNID: IDEA's Unique Nano IDentifier, which is an id unique through an IDEA's AWS account and region.
29
30
  * Note: no need of an auth check for external uses: the permissions depend from the context in which it's executed.
30
31
  * @param project project code
31
32
  * @return the IUNID
32
33
  */
33
34
  IUNID(project: string): Promise<string>;
34
35
  /**
35
- * Returns an ISID: IDEA's Short IDentifier, which is a short, unique id through a single project.
36
- * Note: there's no need of an authorization check for extrernal uses: the permissions depend
37
- * from the context in which it's executed.
36
+ * Returns an ISID: IDEA's Short IDentifier, which is a short, unique id intended to be used in small namespaces.
37
+ * Note: no need of an auth check for external uses: the permissions depend from the context in which it's executed.
38
38
  * @param project project code
39
39
  * @return the ISID
40
40
  */
@@ -48,68 +48,74 @@ export declare class DynamoDB {
48
48
  getAtomicCounterByKey(key: string): Promise<number>;
49
49
  /**
50
50
  * Get an item of a DynamoDB table.
51
+ * @param params the params to apply to DynamoDB's function
51
52
  */
52
- get(params: DDB.DocumentClient.GetItemInput): Promise<any>;
53
+ get(params: DDB.GetCommandInput): Promise<Record<string, any>>;
53
54
  /**
54
55
  * Put an item in a DynamoDB table.
56
+ * @param params the params to apply to DynamoDB's function
55
57
  */
56
- put(params: DDB.DocumentClient.PutItemInput): Promise<DDB.DocumentClient.PutItemOutput>;
58
+ put(params: DDB.PutCommandInput): Promise<DDB.PutCommandOutput>;
57
59
  /**
58
60
  * Update an item of a DynamoDB table.
61
+ * @param params the params to apply to DynamoDB's function
59
62
  */
60
- update(params: DDB.DocumentClient.UpdateItemInput): Promise<DDB.DocumentClient.UpdateItemOutput>;
63
+ update(params: DDB.UpdateCommandInput): Promise<DDB.UpdateCommandOutput>;
61
64
  /**
62
65
  * Delete an item of a DynamoDB table.
66
+ * @param params the params to apply to DynamoDB's function
63
67
  */
64
- delete(params: DDB.DocumentClient.DeleteItemInput): Promise<DDB.DocumentClient.DeleteItemOutput>;
68
+ delete(params: DDB.DeleteCommandInput): Promise<DDB.DeleteCommandOutput>;
65
69
  /**
66
- * Get group of items based on their keys from DynamoDb table, avoiding the limits of DynamoDB's BatchGetItem.
70
+ * Get group of items based on their keys from DynamoDB table, avoiding the limits of DynamoDB's BatchGetItem.
71
+ * @param table the target DynamoDB table
72
+ * @param keys the keys of the objects to retrieve
67
73
  * @param ignoreErr if set, ignore the errors and continue the bulk op.
68
74
  */
69
- batchGet(table: string, keys: DDB.DocumentClient.Key[], ignoreErr?: boolean): Promise<any[]>;
70
- protected batchGetHelper(table: string, keys: DDB.DocumentClient.Key[], resultElements: DDB.DocumentClient.AttributeMap[], ignoreErr: boolean, currentChunk?: number, chunkSize?: number): Promise<DDB.DocumentClient.AttributeMap[]>;
75
+ batchGet(table: string, keys: Record<string, AttributeValue>[], ignoreErr?: boolean): Promise<Record<string, any>[]>;
76
+ protected batchGetHelper(table: string, keys: Record<string, AttributeValue>[], resultElements: Record<string, any>[], ignoreErr: boolean, currentChunk?: number, chunkSize?: number): Promise<Record<string, any>[]>;
71
77
  /**
72
- * Put an array of items in a DynamoDb table, avoiding the limits of DynamoDB's BatchWriteItem.
78
+ * Put an array of items in a DynamoDB table, avoiding the limits of DynamoDB's BatchWriteItem.
73
79
  * In case of errors, it will retry with a random back-off mechanism until the timeout.
74
80
  * Therefore, in case of timeout, there may be some elements written and some not.
81
+ * @param table the target DynamoDB table
82
+ * @param items the objects to insert
75
83
  */
76
- batchPut(table: string, items: DDB.DocumentClient.AttributeMap[]): Promise<void>;
84
+ batchPut(table: string, items: Record<string, any>[]): Promise<void>;
77
85
  /**
78
- * Delete an array of items from a DynamoDb table, avoiding the limits of DynamoDB's BatchWriteItem.
86
+ * Delete an array of items from a DynamoDB table, avoiding the limits of DynamoDB's BatchWriteItem.
79
87
  * In case of errors, it will retry with a random back-off mechanism until the timeout.
80
88
  * Therefore, in case of timeout, there may be some elements deleted and some not.
89
+ * @param table the target DynamoDB table
90
+ * @param keys the keys to delete
81
91
  */
82
- batchDelete(table: string, keys: DDB.DocumentClient.Key[]): Promise<void>;
83
- protected batchWriteHelper(table: string, itemsOrKeys: DDB.DocumentClient.AttributeMap[] | DDB.DocumentClient.Key[], isPut: boolean, currentChunk?: number, chunkSize?: number): Promise<void>;
84
- protected batchWriteChunkWithRetries(table: string, params: DDB.DocumentClient.BatchWriteItemInput): Promise<void>;
92
+ batchDelete(table: string, keys: Record<string, AttributeValue>[]): Promise<void>;
93
+ protected batchWriteHelper(table: string, itemsOrKeys: Record<string, any>[] | Record<string, AttributeValue>[], isPut: boolean, currentChunk?: number, chunkSize?: number): Promise<void>;
94
+ protected batchWriteChunkWithRetries(table: string, params: DDB.BatchWriteCommandInput): Promise<void>;
85
95
  /**
86
- * Query a DynamoDb table, avoiding the limits of DynamoDB's Query.
96
+ * Query a DynamoDB table, avoiding the limits of DynamoDB's Query.
87
97
  * @param params the params to apply to DynamoDB's function
88
98
  */
89
- query(params: DDB.DocumentClient.QueryInput): Promise<any[]>;
99
+ query(params: DDB.QueryCommandInput): Promise<Record<string, any>[]>;
90
100
  /**
91
- * Scan a DynamoDb table, avoiding the limits of DynamoDB's Query.
101
+ * Scan a DynamoDB table, avoiding the limits of DynamoDB's Query.
92
102
  * @param params the params to apply to DynamoDB's function
93
103
  */
94
- scan(params: DDB.DocumentClient.QueryInput): Promise<any[]>;
95
- protected queryScanHelper(params: DDB.DocumentClient.QueryInput | DDB.DocumentClient.ScanInput, items: DDB.DocumentClient.AttributeMap[], isQuery: boolean): Promise<DDB.DocumentClient.AttributeMap[]>;
104
+ scan(params: DDB.ScanCommandInput): Promise<Record<string, any>[]>;
105
+ protected queryScanHelper(params: DDB.QueryCommandInput | DDB.ScanCommandInput, items: Record<string, any>[], isQuery: boolean): Promise<Record<string, any>[]>;
96
106
  /**
97
- * Query a DynamoDb table in the traditional way (no pagination or data mapping).
107
+ * Query a DynamoDB table in the traditional way (no pagination or data mapping).
98
108
  * @param params the params to apply to DynamoDB's function
99
109
  */
100
- queryClassic(params: DDB.DocumentClient.QueryInput): Promise<DDB.DocumentClient.QueryOutput>;
110
+ queryClassic(params: DDB.QueryCommandInput): Promise<DDB.QueryCommandOutput>;
101
111
  /**
102
- * Scan a DynamoDb table in the traditional way (no pagination or data mapping).
112
+ * Scan a DynamoDB table in the traditional way (no pagination or data mapping).
103
113
  * @param params the params to apply to DynamoDB's function
104
114
  */
105
- scanClassic(params: DDB.DocumentClient.ScanInput): Promise<DDB.DocumentClient.ScanOutput>;
115
+ scanClassic(params: DDB.ScanCommandInput): Promise<DDB.ScanCommandOutput>;
106
116
  /**
107
117
  * Execute a series of max 10 write operations in a single transaction.
108
118
  * @param ops the operations to execute in the transaction
109
119
  */
110
- transactWrites(ops: DDB.DocumentClient.TransactWriteItem[]): Promise<void>;
111
- /**
112
- * Creates a set of elements (DynamoDB format) inferring the type of set from the type of the first element.
113
- */
114
- createSet(array: number[] | string[], options?: DDB.DocumentClient.CreateSetOptions): DDB.DocumentClient.DynamoDbSet;
120
+ transactWrites(ops: TransactWriteItem[]): Promise<void>;
115
121
  }
@@ -1,8 +1,35 @@
1
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 __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
2
25
  Object.defineProperty(exports, "__esModule", { value: true });
3
26
  exports.DynamoDB = void 0;
4
- const aws_sdk_1 = require("aws-sdk");
27
+ const DDB = __importStar(require("@aws-sdk/lib-dynamodb"));
28
+ const client_dynamodb_1 = require("@aws-sdk/client-dynamodb");
29
+ const DDBUtils = __importStar(require("@aws-sdk/util-dynamodb"));
5
30
  const uuid_1 = require("uuid");
31
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
32
+ // @ts-ignore
6
33
  const nanoid_1 = require("nanoid");
7
34
  const NanoID = (0, nanoid_1.customAlphabet)('0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz', 25);
8
35
  const shortid_1 = require("shortid");
@@ -13,19 +40,20 @@ const logger_1 = require("./logger");
13
40
  class DynamoDB {
14
41
  constructor(options = { debug: true }) {
15
42
  this.logger = new logger_1.Logger();
16
- this.dynamo = new aws_sdk_1.DynamoDB.DocumentClient();
43
+ this.dynamo = DDB.DynamoDBDocument.from(new client_dynamodb_1.DynamoDB());
17
44
  this.logger.level = options.debug ? 'DEBUG' : 'INFO';
18
45
  }
19
46
  /**
20
- * Convert a JSON object from dynamoDB format to simple JSON.
47
+ * Convert a JSON object from DynamoDB format to simple JSON.
48
+ * @data the data in DynamoDB's original format to convert in plain objects
49
+ * @options the options to use to convert the data
21
50
  */
22
51
  unmarshall(data, options) {
23
- return aws_sdk_1.DynamoDB.Converter.unmarshall(data, options);
52
+ return DDBUtils.unmarshall(data, options);
24
53
  }
25
54
  /**
26
- * Returns an IUID: IDEA's Unique IDentifier, which is an id unique through all IDEA's projects.
27
- * Note: there's no need of an authorization check for extrernal uses: the permissions depend
28
- * from the context in which it's executed.
55
+ * Returns an IUID: IDEA's Unique IDentifier, which is an id unique through an IDEA's AWS account and region.
56
+ * Note: no need of an auth check for external uses: the permissions depend from the context in which it's executed.
29
57
  * @deprecated use IUNID instead (nano version)
30
58
  * @param project project code
31
59
  * @return the IUID
@@ -37,7 +65,7 @@ class DynamoDB {
37
65
  return await this.identifiersGeneratorHelper(project, 'IUID', 0, MAX_ATTEMPTS);
38
66
  }
39
67
  /**
40
- * Returns an IUNID: IDEA's Unique Nano IDentifier, which is an id unique through all IDEA's projects.
68
+ * Returns an IUNID: IDEA's Unique Nano IDentifier, which is an id unique through an IDEA's AWS account and region.
41
69
  * Note: no need of an auth check for external uses: the permissions depend from the context in which it's executed.
42
70
  * @param project project code
43
71
  * @return the IUNID
@@ -49,9 +77,8 @@ class DynamoDB {
49
77
  return await this.identifiersGeneratorHelper(project, 'IUNID', 0, MAX_ATTEMPTS);
50
78
  }
51
79
  /**
52
- * Returns an ISID: IDEA's Short IDentifier, which is a short, unique id through a single project.
53
- * Note: there's no need of an authorization check for extrernal uses: the permissions depend
54
- * from the context in which it's executed.
80
+ * Returns an ISID: IDEA's Short IDentifier, which is a short, unique id intended to be used in small namespaces.
81
+ * Note: no need of an auth check for external uses: the permissions depend from the context in which it's executed.
55
82
  * @param project project code
56
83
  * @return the ISID
57
84
  */
@@ -117,37 +144,43 @@ class DynamoDB {
117
144
  }
118
145
  /**
119
146
  * Get an item of a DynamoDB table.
147
+ * @param params the params to apply to DynamoDB's function
120
148
  */
121
149
  async get(params) {
122
150
  this.logger.debug(`Get ${params.TableName}`);
123
- const result = await this.dynamo.get(params).promise();
151
+ const result = await this.dynamo.get(params);
124
152
  if (!result?.Item)
125
153
  throw new Error('Not found');
126
154
  return result.Item;
127
155
  }
128
156
  /**
129
157
  * Put an item in a DynamoDB table.
158
+ * @param params the params to apply to DynamoDB's function
130
159
  */
131
160
  async put(params) {
132
161
  this.logger.debug(`Put ${params.TableName}`);
133
- return await this.dynamo.put(params).promise();
162
+ return await this.dynamo.put(params);
134
163
  }
135
164
  /**
136
165
  * Update an item of a DynamoDB table.
166
+ * @param params the params to apply to DynamoDB's function
137
167
  */
138
168
  async update(params) {
139
169
  this.logger.debug(`Update ${params.TableName}`);
140
- return await this.dynamo.update(params).promise();
170
+ return await this.dynamo.update(params);
141
171
  }
142
172
  /**
143
173
  * Delete an item of a DynamoDB table.
174
+ * @param params the params to apply to DynamoDB's function
144
175
  */
145
176
  async delete(params) {
146
177
  this.logger.debug(`Delete ${params.TableName}`);
147
- return await this.dynamo.delete(params).promise();
178
+ return await this.dynamo.delete(params);
148
179
  }
149
180
  /**
150
- * Get group of items based on their keys from DynamoDb table, avoiding the limits of DynamoDB's BatchGetItem.
181
+ * Get group of items based on their keys from DynamoDB table, avoiding the limits of DynamoDB's BatchGetItem.
182
+ * @param table the target DynamoDB table
183
+ * @param keys the keys of the objects to retrieve
151
184
  * @param ignoreErr if set, ignore the errors and continue the bulk op.
152
185
  */
153
186
  async batchGet(table, keys, ignoreErr) {
@@ -166,7 +199,7 @@ class DynamoDB {
166
199
  this.logger.debug(`Batch get ${table}: ${currentChunk} of ${keys.length}`);
167
200
  let result;
168
201
  try {
169
- result = await this.dynamo.batchGet(batch).promise();
202
+ result = await this.dynamo.batchGet(batch);
170
203
  }
171
204
  catch (err) {
172
205
  if (!ignoreErr)
@@ -182,9 +215,11 @@ class DynamoDB {
182
215
  return resultElements;
183
216
  }
184
217
  /**
185
- * Put an array of items in a DynamoDb table, avoiding the limits of DynamoDB's BatchWriteItem.
218
+ * Put an array of items in a DynamoDB table, avoiding the limits of DynamoDB's BatchWriteItem.
186
219
  * In case of errors, it will retry with a random back-off mechanism until the timeout.
187
220
  * Therefore, in case of timeout, there may be some elements written and some not.
221
+ * @param table the target DynamoDB table
222
+ * @param items the objects to insert
188
223
  */
189
224
  async batchPut(table, items) {
190
225
  if (!items.length)
@@ -192,9 +227,11 @@ class DynamoDB {
192
227
  await this.batchWriteHelper(table, items, true);
193
228
  }
194
229
  /**
195
- * Delete an array of items from a DynamoDb table, avoiding the limits of DynamoDB's BatchWriteItem.
230
+ * Delete an array of items from a DynamoDB table, avoiding the limits of DynamoDB's BatchWriteItem.
196
231
  * In case of errors, it will retry with a random back-off mechanism until the timeout.
197
232
  * Therefore, in case of timeout, there may be some elements deleted and some not.
233
+ * @param table the target DynamoDB table
234
+ * @param keys the keys to delete
198
235
  */
199
236
  async batchDelete(table, keys) {
200
237
  if (!keys.length)
@@ -220,7 +257,7 @@ class DynamoDB {
220
257
  const wait = (seconds) => new Promise(x => setTimeout(() => x(), seconds * 1000));
221
258
  let attempts = 0;
222
259
  do {
223
- const response = await this.dynamo.batchWrite(params).promise();
260
+ const response = await this.dynamo.batchWrite(params);
224
261
  if (response.UnprocessedItems &&
225
262
  response.UnprocessedItems[table] &&
226
263
  response.UnprocessedItems[table].length > 0) {
@@ -236,7 +273,7 @@ class DynamoDB {
236
273
  } while (params.RequestItems);
237
274
  }
238
275
  /**
239
- * Query a DynamoDb table, avoiding the limits of DynamoDB's Query.
276
+ * Query a DynamoDB table, avoiding the limits of DynamoDB's Query.
240
277
  * @param params the params to apply to DynamoDB's function
241
278
  */
242
279
  async query(params) {
@@ -246,7 +283,7 @@ class DynamoDB {
246
283
  return result;
247
284
  }
248
285
  /**
249
- * Scan a DynamoDb table, avoiding the limits of DynamoDB's Query.
286
+ * Scan a DynamoDB table, avoiding the limits of DynamoDB's Query.
250
287
  * @param params the params to apply to DynamoDB's function
251
288
  */
252
289
  async scan(params) {
@@ -258,9 +295,9 @@ class DynamoDB {
258
295
  async queryScanHelper(params, items, isQuery) {
259
296
  let result;
260
297
  if (isQuery)
261
- result = await this.dynamo.query(params).promise();
298
+ result = await this.dynamo.query(params);
262
299
  else
263
- result = await this.dynamo.scan(params).promise();
300
+ result = await this.dynamo.scan(params);
264
301
  items = items.concat(result.Items);
265
302
  if (result.LastEvaluatedKey) {
266
303
  params.ExclusiveStartKey = result.LastEvaluatedKey;
@@ -270,22 +307,22 @@ class DynamoDB {
270
307
  return items;
271
308
  }
272
309
  /**
273
- * Query a DynamoDb table in the traditional way (no pagination or data mapping).
310
+ * Query a DynamoDB table in the traditional way (no pagination or data mapping).
274
311
  * @param params the params to apply to DynamoDB's function
275
312
  */
276
313
  async queryClassic(params) {
277
314
  this.logger.debug(`Query classic ${params.TableName}`);
278
- const result = await this.dynamo.query(params).promise();
315
+ const result = await this.dynamo.query(params);
279
316
  this.logger.debug(`Results query classic ${params.TableName}: ${result?.Items?.length || 0}`);
280
317
  return result;
281
318
  }
282
319
  /**
283
- * Scan a DynamoDb table in the traditional way (no pagination or data mapping).
320
+ * Scan a DynamoDB table in the traditional way (no pagination or data mapping).
284
321
  * @param params the params to apply to DynamoDB's function
285
322
  */
286
323
  async scanClassic(params) {
287
324
  this.logger.debug(`Scan classic ${params.TableName}`);
288
- const result = await this.dynamo.scan(params).promise();
325
+ const result = await this.dynamo.scan(params);
289
326
  this.logger.debug(`Results scan classic ${params.TableName}: ${result?.Items?.length || 0}`);
290
327
  return result;
291
328
  }
@@ -297,13 +334,7 @@ class DynamoDB {
297
334
  if (!ops.length)
298
335
  return this.logger.debug('Transaction writes: no elements to write');
299
336
  this.logger.debug('Transaction writes');
300
- await this.dynamo.transactWrite({ TransactItems: ops.slice(0, 10) }).promise();
301
- }
302
- /**
303
- * Creates a set of elements (DynamoDB format) inferring the type of set from the type of the first element.
304
- */
305
- createSet(array, options) {
306
- return this.dynamo.createSet(array, options);
337
+ await this.dynamo.transactWrite({ TransactItems: ops.slice(0, 10) });
307
338
  }
308
339
  }
309
340
  exports.DynamoDB = DynamoDB;
@@ -1,8 +1,32 @@
1
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 __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
2
25
  Object.defineProperty(exports, "__esModule", { value: true });
3
26
  exports.RCError = exports.ResourceController = void 0;
4
27
  const fs_1 = require("fs");
5
- const aws_sdk_1 = require("aws-sdk");
28
+ const Lambda = __importStar(require("@aws-sdk/client-lambda"));
29
+ const EventBridge = __importStar(require("@aws-sdk/client-eventbridge"));
6
30
  const idea_toolbox_1 = require("idea-toolbox");
7
31
  const metrics_1 = require("./metrics");
8
32
  const genericController_1 = require("./genericController");
@@ -378,14 +402,15 @@ class ResourceController extends genericController_1.GenericController {
378
402
  throw new Error('Either "lambda" or "eventBus" parameters must be set.');
379
403
  }
380
404
  async invokeInternalAPIRequestWithLambda(params) {
381
- const lambdaInvokeParams = {
405
+ const command = new Lambda.InvokeCommand({
382
406
  FunctionName: params.lambda,
383
407
  InvocationType: 'RequestResponse',
384
408
  Payload: this.mapEventForInternalApiRequest(params),
385
409
  Qualifier: params.stage || this.stage
386
- };
387
- const res = await new aws_sdk_1.Lambda().invoke(lambdaInvokeParams).promise();
388
- const payload = JSON.parse(res.Payload);
410
+ });
411
+ const client = new Lambda.LambdaClient();
412
+ const { Payload } = await client.send(command);
413
+ const payload = JSON.parse(Payload.transformToString());
389
414
  const body = JSON.parse(payload.body);
390
415
  if (Number(payload.statusCode) !== 200)
391
416
  throw new Error(body.message);
@@ -398,7 +423,9 @@ class ResourceController extends genericController_1.GenericController {
398
423
  DetailType: params.eventBridge.target,
399
424
  Detail: this.mapEventForInternalApiRequest(params)
400
425
  };
401
- return await new aws_sdk_1.EventBridge().putEvents({ Entries: [request] }).promise();
426
+ const client = new EventBridge.EventBridgeClient();
427
+ const command = new EventBridge.PutEventsCommand({ Entries: [request] });
428
+ return await client.send(command);
402
429
  }
403
430
  mapEventForInternalApiRequest(params) {
404
431
  const event = JSON.parse(JSON.stringify(this.event));
package/dist/src/s3.d.ts CHANGED
@@ -1,12 +1,12 @@
1
- /// <reference types="node" />
2
- import { S3 as AWSS3 } from 'aws-sdk';
1
+ import * as AWSS3 from '@aws-sdk/client-s3';
2
+ import { BodyDataTypes } from '@aws-sdk/lib-storage';
3
3
  import { SignedURL } from 'idea-toolbox';
4
4
  import { Logger } from './logger';
5
5
  /**
6
6
  * A wrapper for AWS Simple Storage Service.
7
7
  */
8
8
  export declare class S3 {
9
- protected s3: AWSS3;
9
+ protected s3: AWSS3.S3Client;
10
10
  protected DEFAULT_DOWNLOAD_BUCKET_PREFIX: string;
11
11
  protected DEFAULT_DOWNLOAD_BUCKET: string;
12
12
  protected DEFAULT_DOWNLOAD_BUCKET_SEC_TO_EXP: number;
@@ -19,17 +19,17 @@ export declare class S3 {
19
19
  * Create a download link of a piece of data (through S3).
20
20
  * *Practically*, it uploads the file on an S3 bucket, generating and returning a url to it.
21
21
  */
22
- createDownloadURLFromData(data: Buffer | any, options?: CreateDownloadURLFromDataOptions): Promise<SignedURL>;
22
+ createDownloadURLFromData(data: BodyDataTypes, options?: CreateDownloadURLFromDataOptions): Promise<SignedURL>;
23
23
  /**
24
24
  * Get a signed URL to put a file on a S3 bucket.
25
25
  * @param expires seconds after which the signed URL expires
26
26
  */
27
- signedURLPut(bucket: string, key: string, expires?: number): SignedURL;
27
+ signedURLPut(bucket: string, key: string, expires?: number): Promise<SignedURL>;
28
28
  /**
29
29
  * Get a signed URL to get a file on a S3 bucket.
30
30
  * @param expires seconds after which the signed URL expires
31
31
  */
32
- signedURLGet(bucket: string, key: string, expires?: number): SignedURL;
32
+ signedURLGet(bucket: string, key: string, expires?: number): Promise<SignedURL>;
33
33
  /**
34
34
  * Make a copy of an object of the bucket.
35
35
  */
@@ -37,7 +37,7 @@ export declare class S3 {
37
37
  /**
38
38
  * Get an object from a S3 bucket.
39
39
  */
40
- getObject(options: GetObjectOptions): Promise<any>;
40
+ getObject(options: GetObjectOptions): Promise<string | AWSS3.GetObjectCommandOutput>;
41
41
  /**
42
42
  * Put an object in a S3 bucket.
43
43
  */