chatbot-nc 2.0.81 → 2.0.84

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 (75) hide show
  1. package/dist/cjs/aws/index.d.ts +1 -0
  2. package/dist/cjs/aws/services/AESEncryptionUsingKMS.js +11 -20
  3. package/dist/cjs/aws/services/AESEncryptionUsingKMS.js.map +1 -1
  4. package/dist/cjs/aws/services/AWSChimeMeeting.js +15 -24
  5. package/dist/cjs/aws/services/AWSChimeMeeting.js.map +1 -1
  6. package/dist/cjs/aws/services/AWSCodepipeline.js +21 -34
  7. package/dist/cjs/aws/services/AWSCodepipeline.js.map +1 -1
  8. package/dist/cjs/aws/services/AWSComprehend.js +3 -12
  9. package/dist/cjs/aws/services/AWSComprehend.js.map +1 -1
  10. package/dist/cjs/aws/services/AWSConnect.js +135 -146
  11. package/dist/cjs/aws/services/AWSConnect.js.map +1 -1
  12. package/dist/cjs/aws/services/AWSConnectCases.js +12 -21
  13. package/dist/cjs/aws/services/AWSConnectCases.js.map +1 -1
  14. package/dist/cjs/aws/services/AWSConnectParticipant.js +12 -21
  15. package/dist/cjs/aws/services/AWSConnectParticipant.js.map +1 -1
  16. package/dist/cjs/aws/services/AWSCustomerProfiles.js +6 -15
  17. package/dist/cjs/aws/services/AWSCustomerProfiles.js.map +1 -1
  18. package/dist/cjs/aws/services/AWSDynamoDb.js +9 -18
  19. package/dist/cjs/aws/services/AWSDynamoDb.js.map +1 -1
  20. package/dist/cjs/aws/services/AWSGateway.js +6 -15
  21. package/dist/cjs/aws/services/AWSGateway.js.map +1 -1
  22. package/dist/cjs/aws/services/AWSGatewayManagement.js +6 -15
  23. package/dist/cjs/aws/services/AWSGatewayManagement.js.map +1 -1
  24. package/dist/cjs/aws/services/AWSLambda.js +4 -13
  25. package/dist/cjs/aws/services/AWSLambda.js.map +1 -1
  26. package/dist/cjs/aws/services/AWSLexModel.js +63 -72
  27. package/dist/cjs/aws/services/AWSLexModel.js.map +1 -1
  28. package/dist/cjs/aws/services/AWSLexRuntime.js +6 -15
  29. package/dist/cjs/aws/services/AWSLexRuntime.js.map +1 -1
  30. package/dist/cjs/aws/services/AWSPinpoint.js +9 -18
  31. package/dist/cjs/aws/services/AWSPinpoint.js.map +1 -1
  32. package/dist/cjs/aws/services/AWSPinpointSMSVoice.js +18 -27
  33. package/dist/cjs/aws/services/AWSPinpointSMSVoice.js.map +1 -1
  34. package/dist/cjs/aws/services/AWSQConnect.js +18 -27
  35. package/dist/cjs/aws/services/AWSQConnect.js.map +1 -1
  36. package/dist/cjs/aws/services/AWSS3.js +28 -37
  37. package/dist/cjs/aws/services/AWSS3.js.map +1 -1
  38. package/dist/cjs/aws/services/AWSSES.js +4 -13
  39. package/dist/cjs/aws/services/AWSSES.js.map +1 -1
  40. package/dist/cjs/aws/services/AWSSNS.js +11 -20
  41. package/dist/cjs/aws/services/AWSSNS.js.map +1 -1
  42. package/dist/cjs/aws/services/AWSSSM.d.ts +1 -0
  43. package/dist/cjs/aws/services/AWSSSM.js +42 -13
  44. package/dist/cjs/aws/services/AWSSSM.js.map +1 -1
  45. package/dist/cjs/aws/services/AWSSTS.js +3 -12
  46. package/dist/cjs/aws/services/AWSSTS.js.map +1 -1
  47. package/dist/cjs/aws/services/AWSTranslate.js +3 -12
  48. package/dist/cjs/aws/services/AWSTranslate.js.map +1 -1
  49. package/dist/cjs/communication/communicationService.js +29 -38
  50. package/dist/cjs/communication/communicationService.js.map +1 -1
  51. package/dist/cjs/communication/index.js +125 -148
  52. package/dist/cjs/communication/index.js.map +1 -1
  53. package/dist/cjs/hashing/idObfuscation.js +28 -42
  54. package/dist/cjs/hashing/idObfuscation.js.map +1 -1
  55. package/dist/cjs/hashing/index.js +141 -168
  56. package/dist/cjs/hashing/index.js.map +1 -1
  57. package/dist/cjs/repository/dynamodb.js +369 -398
  58. package/dist/cjs/repository/dynamodb.js.map +1 -1
  59. package/dist/cjs/shortner/index.js +20 -31
  60. package/dist/cjs/shortner/index.js.map +1 -1
  61. package/dist/cjs/utils/common.js +2 -11
  62. package/dist/cjs/utils/common.js.map +1 -1
  63. package/dist/cjs/utils/intent.js +24 -33
  64. package/dist/cjs/utils/intent.js.map +1 -1
  65. package/dist/cjs/webbookEvent/index.js +105 -128
  66. package/dist/cjs/webbookEvent/index.js.map +1 -1
  67. package/dist/esm/aws/index.d.ts +1 -0
  68. package/dist/esm/aws/services/AWSConnect.js +0 -2
  69. package/dist/esm/aws/services/AWSConnect.js.map +1 -1
  70. package/dist/esm/aws/services/AWSSSM.d.ts +1 -0
  71. package/dist/esm/aws/services/AWSSSM.js +39 -1
  72. package/dist/esm/aws/services/AWSSSM.js.map +1 -1
  73. package/dist/esm/hashing/idObfuscation.js +2 -1
  74. package/dist/esm/hashing/idObfuscation.js.map +1 -1
  75. package/package.json +2 -2
@@ -1,13 +1,4 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
2
  Object.defineProperty(exports, "__esModule", { value: true });
12
3
  const client_dynamodb_1 = require("@aws-sdk/client-dynamodb"); // ES Modules import
13
4
  const lib_dynamodb_1 = require("@aws-sdk/lib-dynamodb");
@@ -29,53 +20,49 @@ class BaseDynamoDBRepository {
29
20
  * Add item in DynamoDB table
30
21
  * @param {object} item // Object containing add for target item
31
22
  */
32
- add(item) {
33
- return __awaiter(this, void 0, void 0, function* () {
34
- try {
35
- item = this.parseDate(item);
36
- var params = {
37
- TableName: this.TABLE_NAME,
38
- Item: Object.assign({}, item)
39
- };
40
- if (!("createdAt" in params.Item))
41
- params.Item.createdAt = Number(Date.now());
42
- if (!("updatedAt" in params.Item))
43
- params.Item.updatedAt = Number(Date.now());
44
- const response = yield this.documentClient.send(new lib_dynamodb_1.PutCommand(params));
45
- console.log('dbItem');
46
- return response;
47
- }
48
- catch (error) {
49
- this.handleError(error);
50
- // // throw new DatabaseException( error.code );
51
- }
52
- });
23
+ async add(item) {
24
+ try {
25
+ item = this.parseDate(item);
26
+ var params = {
27
+ TableName: this.TABLE_NAME,
28
+ Item: Object.assign({}, item)
29
+ };
30
+ if (!("createdAt" in params.Item))
31
+ params.Item.createdAt = Number(Date.now());
32
+ if (!("updatedAt" in params.Item))
33
+ params.Item.updatedAt = Number(Date.now());
34
+ const response = await this.documentClient.send(new lib_dynamodb_1.PutCommand(params));
35
+ console.log('dbItem');
36
+ return response;
37
+ }
38
+ catch (error) {
39
+ this.handleError(error);
40
+ // // throw new DatabaseException( error.code );
41
+ }
53
42
  }
54
43
  /**
55
44
  * Update item in DynamoDB table
56
45
  * @param {object} key // Object containing target item key(s)
57
46
  * @param {object} item // Object containing updates for target item
58
47
  */
59
- update(key, item) {
60
- return __awaiter(this, void 0, void 0, function* () {
61
- try {
62
- const itemKeys = Object.keys(item).filter(k => k !== key);
63
- const params = {
64
- TableName: this.TABLE_NAME,
65
- UpdateExpression: `SET ${itemKeys.map((k, index) => `#field${index} = :value${index}`).join(', ')}`,
66
- ExpressionAttributeNames: itemKeys.reduce((accumulator, k, index) => (Object.assign(Object.assign({}, accumulator), { [`#field${index}`]: k })), {}),
67
- ExpressionAttributeValues: itemKeys.reduce((accumulator, k, index) => (Object.assign(Object.assign({}, accumulator), { [`:value${index}`]: item[k] })), {}),
68
- Key: {
69
- [key]: item[key]
70
- },
71
- ReturnValues: 'ALL_NEW'
72
- };
73
- return yield this.documentClient.send(new lib_dynamodb_1.UpdateCommand(params));
74
- }
75
- catch (error) {
76
- this.handleError(error);
77
- }
78
- });
48
+ async update(key, item) {
49
+ try {
50
+ const itemKeys = Object.keys(item).filter(k => k !== key);
51
+ const params = {
52
+ TableName: this.TABLE_NAME,
53
+ UpdateExpression: `SET ${itemKeys.map((k, index) => `#field${index} = :value${index}`).join(', ')}`,
54
+ ExpressionAttributeNames: itemKeys.reduce((accumulator, k, index) => (Object.assign(Object.assign({}, accumulator), { [`#field${index}`]: k })), {}),
55
+ ExpressionAttributeValues: itemKeys.reduce((accumulator, k, index) => (Object.assign(Object.assign({}, accumulator), { [`:value${index}`]: item[k] })), {}),
56
+ Key: {
57
+ [key]: item[key]
58
+ },
59
+ ReturnValues: 'ALL_NEW'
60
+ };
61
+ return await this.documentClient.send(new lib_dynamodb_1.UpdateCommand(params));
62
+ }
63
+ catch (error) {
64
+ this.handleError(error);
65
+ }
79
66
  }
80
67
  /**
81
68
  * Update item in DynamoDB table
@@ -83,29 +70,27 @@ class BaseDynamoDBRepository {
83
70
  * @param {object} item // Object containing updates for target item
84
71
  * @returns
85
72
  */
86
- updateByMutiple(keys, item) {
87
- return __awaiter(this, void 0, void 0, function* () {
88
- try {
89
- // const itemKeys = Object.keys(item).filter(k => !key.includes(k));
90
- const itemKeys = Object.keys(item).filter(k => !keys.includes(k));
91
- const keyItem = Object.keys(item).filter(k => keys.includes(k));
92
- const params = {
93
- TableName: this.TABLE_NAME,
94
- UpdateExpression: `SET ${itemKeys.map((k, index) => `#field${index} = :value${index}`).join(', ')}`,
95
- ExpressionAttributeNames: itemKeys.reduce((accumulator, k, index) => (Object.assign(Object.assign({}, accumulator), { [`#field${index}`]: k })), {}),
96
- ExpressionAttributeValues: itemKeys.reduce((accumulator, k, index) => (Object.assign(Object.assign({}, accumulator), { [`:value${index}`]: item[k] })), {}),
97
- Key: keyItem.reduce((obj, key) => {
98
- obj[key] = item[key];
99
- return obj;
100
- }, {}),
101
- ReturnValues: 'ALL_NEW'
102
- };
103
- return yield this.documentClient.send(new lib_dynamodb_1.UpdateCommand(params));
104
- }
105
- catch (error) {
106
- this.handleError(error);
107
- }
108
- });
73
+ async updateByMutiple(keys, item) {
74
+ try {
75
+ // const itemKeys = Object.keys(item).filter(k => !key.includes(k));
76
+ const itemKeys = Object.keys(item).filter(k => !keys.includes(k));
77
+ const keyItem = Object.keys(item).filter(k => keys.includes(k));
78
+ const params = {
79
+ TableName: this.TABLE_NAME,
80
+ UpdateExpression: `SET ${itemKeys.map((k, index) => `#field${index} = :value${index}`).join(', ')}`,
81
+ ExpressionAttributeNames: itemKeys.reduce((accumulator, k, index) => (Object.assign(Object.assign({}, accumulator), { [`#field${index}`]: k })), {}),
82
+ ExpressionAttributeValues: itemKeys.reduce((accumulator, k, index) => (Object.assign(Object.assign({}, accumulator), { [`:value${index}`]: item[k] })), {}),
83
+ Key: keyItem.reduce((obj, key) => {
84
+ obj[key] = item[key];
85
+ return obj;
86
+ }, {}),
87
+ ReturnValues: 'ALL_NEW'
88
+ };
89
+ return await this.documentClient.send(new lib_dynamodb_1.UpdateCommand(params));
90
+ }
91
+ catch (error) {
92
+ this.handleError(error);
93
+ }
109
94
  }
110
95
  /**
111
96
  *
@@ -145,29 +130,27 @@ class BaseDynamoDBRepository {
145
130
  * @param {object} id // Object containing target item key(s)
146
131
  * @param {object} version // Object containing updates for target item
147
132
  */
148
- getById(key) {
149
- return __awaiter(this, void 0, void 0, function* () {
150
- console.info("Dynamo db Repository: getById Start");
151
- var params = {
152
- TableName: this.TABLE_NAME,
153
- Key: key
154
- };
155
- try {
156
- console.info("Dynamo db Repository: getById End");
157
- const command = new lib_dynamodb_1.GetCommand(params);
158
- const response = yield this.documentClient.send(command);
159
- if (response && response.Item) {
160
- return this.unparseDate(response.Item);
161
- }
162
- return null;
163
- }
164
- catch (error) {
165
- console.error(`error occured while getting custom order log by primary keys - customOrderLog - ${error}`);
166
- console.error("Dynamo db Repository: Error: ");
167
- this.handleError(error);
168
- // throw new DatabaseException( error.code );
133
+ async getById(key) {
134
+ console.info("Dynamo db Repository: getById Start");
135
+ var params = {
136
+ TableName: this.TABLE_NAME,
137
+ Key: key
138
+ };
139
+ try {
140
+ console.info("Dynamo db Repository: getById End");
141
+ const command = new lib_dynamodb_1.GetCommand(params);
142
+ const response = await this.documentClient.send(command);
143
+ if (response && response.Item) {
144
+ return this.unparseDate(response.Item);
169
145
  }
170
- });
146
+ return null;
147
+ }
148
+ catch (error) {
149
+ console.error(`error occured while getting custom order log by primary keys - customOrderLog - ${error}`);
150
+ console.error("Dynamo db Repository: Error: ");
151
+ this.handleError(error);
152
+ // throw new DatabaseException( error.code );
153
+ }
171
154
  }
172
155
  /**
173
156
  * Get item in DynamoDB table
@@ -185,202 +168,198 @@ class BaseDynamoDBRepository {
185
168
  * Get items in DynamoDB table
186
169
  * @param {object} item // Object containing target item key(s)
187
170
  */
188
- query(item, condition, indexName, projectionExpression, limit, scanIndexForward = true, exclusiveStartKey) {
189
- return __awaiter(this, void 0, void 0, function* () {
190
- console.info("Dynamo db Repository: query Start");
191
- try {
192
- const itemKeys = Object.keys(item);
193
- // let Key, Filter;
194
- // if (!indexName) {
195
- // Key = `${itemKeys.map((k, index) => {
196
- // if (this.PRIMARY_KEY.length === 0 || this.PRIMARY_KEY.includes(k))
197
- // if (!this.isComparator(condition![index] || '='))
198
- // return `${condition![index]}(#field${index} ,:value${index})`
199
- // else
200
- // return `#field${index} ${condition![index] || '='} :value${index}`
201
- // }).filter(a => a).join(' and ')}`;
202
- // Filter = `${itemKeys.map((k, index) => {
203
- // if (!this.PRIMARY_KEY.includes(k))
204
- // if (!this.isComparator(condition![index] || '='))
205
- // if(condition![index].toUpperCase() == 'IN')
206
- // return `#field${index} ${condition![index]}(${Object.keys(this.getArrayValue(item[k],index)).toString()})`
207
- // else
208
- // return `${condition![index]}(#field${index} ,:value${index})`
209
- // else
210
- // return `#field${index} ${condition![index] || '='} :value${index}`
211
- // }).filter(a => a).join(' and ')}`;
212
- // }
213
- // else {
214
- // Key = `${itemKeys.map((k, index) => {
215
- // if (indexName.split('-').includes(k)) {
216
- // if (!this.isComparator(condition![index] || '='))
217
- // return `${condition![index]}(#field${index} ,:value${index})`
218
- // else
219
- // return `#field${index} ${condition![index] || '='} :value${index}`
220
- // }
221
- // }).filter(a => a).join(' and ')}`;
222
- // Filter = `${itemKeys.map((k, index) => {
223
- // if (!indexName.split('-').includes(k)) {
224
- // if (!this.isComparator(condition![index] || '='))
225
- // if(condition![index].toUpperCase() == 'IN')
226
- // return `#field${index} ${condition![index]}(${Object.keys(this.getArrayValue(item[k],index)).toString()})`
227
- // else
228
- // return `${condition![index]}(#field${index} ,:value${index})`
229
- // else
230
- // return `#field${index} ${condition![index] || '='} :value${index}`
231
- // }
232
- // }).filter(a => a).join(' and ')}`;
233
- // }
234
- let [Key, Filter] = yield this.getKeyAndFilter(item, condition, indexName);
235
- let params = {
236
- TableName: this.TABLE_NAME,
237
- ExpressionAttributeNames: itemKeys.reduce((accumulator, k, index) => (Object.assign(Object.assign({}, accumulator), { [`#field${index}`]: k })), {}),
238
- ExpressionAttributeValues: itemKeys.reduce((accumulator, k, index) => {
239
- if (Array.isArray(item[k])) {
240
- let data = this.getArrayValue(item[k], index);
241
- return Object.assign(Object.assign({}, accumulator), data);
242
- }
171
+ async query(item, condition, indexName, projectionExpression, limit, scanIndexForward = true, exclusiveStartKey) {
172
+ console.info("Dynamo db Repository: query Start");
173
+ try {
174
+ const itemKeys = Object.keys(item);
175
+ // let Key, Filter;
176
+ // if (!indexName) {
177
+ // Key = `${itemKeys.map((k, index) => {
178
+ // if (this.PRIMARY_KEY.length === 0 || this.PRIMARY_KEY.includes(k))
179
+ // if (!this.isComparator(condition![index] || '='))
180
+ // return `${condition![index]}(#field${index} ,:value${index})`
181
+ // else
182
+ // return `#field${index} ${condition![index] || '='} :value${index}`
183
+ // }).filter(a => a).join(' and ')}`;
184
+ // Filter = `${itemKeys.map((k, index) => {
185
+ // if (!this.PRIMARY_KEY.includes(k))
186
+ // if (!this.isComparator(condition![index] || '='))
187
+ // if(condition![index].toUpperCase() == 'IN')
188
+ // return `#field${index} ${condition![index]}(${Object.keys(this.getArrayValue(item[k],index)).toString()})`
189
+ // else
190
+ // return `${condition![index]}(#field${index} ,:value${index})`
191
+ // else
192
+ // return `#field${index} ${condition![index] || '='} :value${index}`
193
+ // }).filter(a => a).join(' and ')}`;
194
+ // }
195
+ // else {
196
+ // Key = `${itemKeys.map((k, index) => {
197
+ // if (indexName.split('-').includes(k)) {
198
+ // if (!this.isComparator(condition![index] || '='))
199
+ // return `${condition![index]}(#field${index} ,:value${index})`
200
+ // else
201
+ // return `#field${index} ${condition![index] || '='} :value${index}`
202
+ // }
203
+ // }).filter(a => a).join(' and ')}`;
204
+ // Filter = `${itemKeys.map((k, index) => {
205
+ // if (!indexName.split('-').includes(k)) {
206
+ // if (!this.isComparator(condition![index] || '='))
207
+ // if(condition![index].toUpperCase() == 'IN')
208
+ // return `#field${index} ${condition![index]}(${Object.keys(this.getArrayValue(item[k],index)).toString()})`
209
+ // else
210
+ // return `${condition![index]}(#field${index} ,:value${index})`
211
+ // else
212
+ // return `#field${index} ${condition![index] || '='} :value${index}`
213
+ // }
214
+ // }).filter(a => a).join(' and ')}`;
215
+ // }
216
+ let [Key, Filter] = await this.getKeyAndFilter(item, condition, indexName);
217
+ let params = {
218
+ TableName: this.TABLE_NAME,
219
+ ExpressionAttributeNames: itemKeys.reduce((accumulator, k, index) => (Object.assign(Object.assign({}, accumulator), { [`#field${index}`]: k })), {}),
220
+ ExpressionAttributeValues: itemKeys.reduce((accumulator, k, index) => {
221
+ if (Array.isArray(item[k])) {
222
+ let data = this.getArrayValue(item[k], index);
223
+ return Object.assign(Object.assign({}, accumulator), data);
224
+ }
225
+ else
226
+ return Object.assign(Object.assign({}, accumulator), { [`:value${index}`]: item[k] });
227
+ }, {}),
228
+ KeyConditionExpression: Key,
229
+ ScanIndexForward: scanIndexForward
230
+ };
231
+ if (exclusiveStartKey)
232
+ params = Object.assign(params, { ExclusiveStartKey: exclusiveStartKey });
233
+ if (indexName)
234
+ params = Object.assign(params, { IndexName: indexName });
235
+ if (projectionExpression)
236
+ params = Object.assign(params, { ProjectionExpression: projectionExpression });
237
+ if (Filter)
238
+ params = Object.assign(params, { FilterExpression: Filter });
239
+ // if (limit)
240
+ // params = Object.assign(params, { Limit:limit});
241
+ let response, acc = [];
242
+ do {
243
+ response = await this.documentClient.send(new lib_dynamodb_1.QueryCommand(params));
244
+ console.info("Repository: query End");
245
+ params.ExclusiveStartKey = response.LastEvaluatedKey;
246
+ console.log("Last Evaluated Key");
247
+ if (limit) {
248
+ if (response && response.Items) {
249
+ if (response.Items.length <= limit - acc.length)
250
+ acc = [...acc, ...response.Items];
243
251
  else
244
- return Object.assign(Object.assign({}, accumulator), { [`:value${index}`]: item[k] });
245
- }, {}),
246
- KeyConditionExpression: Key,
247
- ScanIndexForward: scanIndexForward
248
- };
249
- if (exclusiveStartKey)
250
- params = Object.assign(params, { ExclusiveStartKey: exclusiveStartKey });
251
- if (indexName)
252
- params = Object.assign(params, { IndexName: indexName });
253
- if (projectionExpression)
254
- params = Object.assign(params, { ProjectionExpression: projectionExpression });
255
- if (Filter)
256
- params = Object.assign(params, { FilterExpression: Filter });
257
- // if (limit)
258
- // params = Object.assign(params, { Limit:limit});
259
- let response, acc = [];
260
- do {
261
- response = yield this.documentClient.send(new lib_dynamodb_1.QueryCommand(params));
262
- console.info("Repository: query End");
263
- params.ExclusiveStartKey = response.LastEvaluatedKey;
264
- console.log("Last Evaluated Key");
265
- if (limit) {
266
- if (response && response.Items) {
267
- if (response.Items.length <= limit - acc.length)
268
- acc = [...acc, ...response.Items];
269
- else
270
- acc = [...acc, ...response.Items.slice(0, limit - acc.length)];
271
- }
252
+ acc = [...acc, ...response.Items.slice(0, limit - acc.length)];
272
253
  }
273
- else if (response && response.Items)
274
- acc = [...acc, ...response.Items];
275
- } while (response && response.Items && response.LastEvaluatedKey && (!limit || acc.length < limit));
276
- if (acc.length > 0)
277
- return this.unparseDate(acc);
278
- else
279
- return null;
280
- }
281
- catch (error) {
282
- this.handleError(error);
283
- }
284
- });
254
+ }
255
+ else if (response && response.Items)
256
+ acc = [...acc, ...response.Items];
257
+ } while (response && response.Items && response.LastEvaluatedKey && (!limit || acc.length < limit));
258
+ if (acc.length > 0)
259
+ return this.unparseDate(acc);
260
+ else
261
+ return null;
262
+ }
263
+ catch (error) {
264
+ this.handleError(error);
265
+ }
285
266
  }
286
267
  /**
287
268
  * Get items in DynamoDB table with Pagination
288
269
  * @param {object} item // Object containing target item key(s)
289
270
  */
290
- queryWithPagination(item, condition, indexName, projectionExpression, limit = 1000, scanIndexForward = true, exclusiveStartKey) {
291
- return __awaiter(this, void 0, void 0, function* () {
292
- console.info("Dynamo db Repository: query Start");
293
- try {
294
- const itemKeys = Object.keys(item);
295
- // let Key, Filter;
296
- // if (!indexName) {
297
- // Key = `${itemKeys.map((k, index) => {
298
- // if (this.PRIMARY_KEY.length === 0 || this.PRIMARY_KEY.includes(k))
299
- // if (!this.isComparator(condition![index] || '='))
300
- // return `${condition![index]}(#field${index} ,:value${index})`
301
- // else
302
- // return `#field${index} ${condition![index] || '='} :value${index}`
303
- // }).filter(a => a).join(' and ')}`;
304
- // Filter = `${itemKeys.map((k, index) => {
305
- // if (!this.PRIMARY_KEY.includes(k))
306
- // if (!this.isComparator(condition![index] || '='))
307
- // if(condition![index].toUpperCase() == 'IN')
308
- // return `#field${index} ${condition![index]}(${Object.keys(this.getArrayValue(item[k],index)).toString()})`
309
- // else
310
- // return `${condition![index]}(#field${index} ,:value${index})`
311
- // else
312
- // return `#field${index} ${condition![index] || '='} :value${index}`
313
- // }).filter(a => a).join(' and ')}`;
314
- // }
315
- // else {
316
- // Key = `${itemKeys.map((k, index) => {
317
- // if (indexName.split('-').includes(k)) {
318
- // if (!this.isComparator(condition![index] || '='))
319
- // return `${condition![index]}(#field${index} ,:value${index})`
320
- // else
321
- // return `#field${index} ${condition![index] || '='} :value${index}`
322
- // }
323
- // }).filter(a => a).join(' and ')}`;
324
- // Filter = `${itemKeys.map((k, index) => {
325
- // if (!indexName.split('-').includes(k)) {
326
- // if (!this.isComparator(condition![index] || '='))
327
- // if(condition![index].toUpperCase() == 'IN')
328
- // return `#field${index} ${condition![index]}(${Object.keys(this.getArrayValue(item[k],index)).toString()})`
329
- // else
330
- // return `${condition![index]}(#field${index} ,:value${index})`
331
- // else
332
- // return `#field${index} ${condition![index] || '='} :value${index}`
333
- // }
334
- // }).filter(a => a).join(' and ')}`;
335
- // }
336
- let [Key, Filter] = yield this.getKeyAndFilter(item, condition, indexName);
337
- let params = {
338
- TableName: this.TABLE_NAME,
339
- ExpressionAttributeNames: itemKeys.reduce((accumulator, k, index) => (Object.assign(Object.assign({}, accumulator), { [`#field${index}`]: k })), {}),
340
- ExpressionAttributeValues: itemKeys.reduce((accumulator, k, index) => {
341
- if (Array.isArray(item[k])) {
342
- let data = this.getArrayValue(item[k], index);
343
- return Object.assign(Object.assign({}, accumulator), data);
344
- }
345
- else
346
- return Object.assign(Object.assign({}, accumulator), { [`:value${index}`]: item[k] });
347
- }, {}),
348
- KeyConditionExpression: Key,
349
- ScanIndexForward: scanIndexForward
350
- };
351
- if (exclusiveStartKey)
352
- params = Object.assign(params, { ExclusiveStartKey: exclusiveStartKey });
353
- if (indexName)
354
- params = Object.assign(params, { IndexName: indexName });
355
- if (projectionExpression)
356
- params = Object.assign(params, { ProjectionExpression: projectionExpression });
357
- if (Filter)
358
- params = Object.assign(params, { FilterExpression: Filter });
271
+ async queryWithPagination(item, condition, indexName, projectionExpression, limit = 1000, scanIndexForward = true, exclusiveStartKey) {
272
+ console.info("Dynamo db Repository: query Start");
273
+ try {
274
+ const itemKeys = Object.keys(item);
275
+ // let Key, Filter;
276
+ // if (!indexName) {
277
+ // Key = `${itemKeys.map((k, index) => {
278
+ // if (this.PRIMARY_KEY.length === 0 || this.PRIMARY_KEY.includes(k))
279
+ // if (!this.isComparator(condition![index] || '='))
280
+ // return `${condition![index]}(#field${index} ,:value${index})`
281
+ // else
282
+ // return `#field${index} ${condition![index] || '='} :value${index}`
283
+ // }).filter(a => a).join(' and ')}`;
284
+ // Filter = `${itemKeys.map((k, index) => {
285
+ // if (!this.PRIMARY_KEY.includes(k))
286
+ // if (!this.isComparator(condition![index] || '='))
287
+ // if(condition![index].toUpperCase() == 'IN')
288
+ // return `#field${index} ${condition![index]}(${Object.keys(this.getArrayValue(item[k],index)).toString()})`
289
+ // else
290
+ // return `${condition![index]}(#field${index} ,:value${index})`
291
+ // else
292
+ // return `#field${index} ${condition![index] || '='} :value${index}`
293
+ // }).filter(a => a).join(' and ')}`;
294
+ // }
295
+ // else {
296
+ // Key = `${itemKeys.map((k, index) => {
297
+ // if (indexName.split('-').includes(k)) {
298
+ // if (!this.isComparator(condition![index] || '='))
299
+ // return `${condition![index]}(#field${index} ,:value${index})`
300
+ // else
301
+ // return `#field${index} ${condition![index] || '='} :value${index}`
302
+ // }
303
+ // }).filter(a => a).join(' and ')}`;
304
+ // Filter = `${itemKeys.map((k, index) => {
305
+ // if (!indexName.split('-').includes(k)) {
306
+ // if (!this.isComparator(condition![index] || '='))
307
+ // if(condition![index].toUpperCase() == 'IN')
308
+ // return `#field${index} ${condition![index]}(${Object.keys(this.getArrayValue(item[k],index)).toString()})`
309
+ // else
310
+ // return `${condition![index]}(#field${index} ,:value${index})`
311
+ // else
312
+ // return `#field${index} ${condition![index] || '='} :value${index}`
313
+ // }
314
+ // }).filter(a => a).join(' and ')}`;
315
+ // }
316
+ let [Key, Filter] = await this.getKeyAndFilter(item, condition, indexName);
317
+ let params = {
318
+ TableName: this.TABLE_NAME,
319
+ ExpressionAttributeNames: itemKeys.reduce((accumulator, k, index) => (Object.assign(Object.assign({}, accumulator), { [`#field${index}`]: k })), {}),
320
+ ExpressionAttributeValues: itemKeys.reduce((accumulator, k, index) => {
321
+ if (Array.isArray(item[k])) {
322
+ let data = this.getArrayValue(item[k], index);
323
+ return Object.assign(Object.assign({}, accumulator), data);
324
+ }
325
+ else
326
+ return Object.assign(Object.assign({}, accumulator), { [`:value${index}`]: item[k] });
327
+ }, {}),
328
+ KeyConditionExpression: Key,
329
+ ScanIndexForward: scanIndexForward
330
+ };
331
+ if (exclusiveStartKey)
332
+ params = Object.assign(params, { ExclusiveStartKey: exclusiveStartKey });
333
+ if (indexName)
334
+ params = Object.assign(params, { IndexName: indexName });
335
+ if (projectionExpression)
336
+ params = Object.assign(params, { ProjectionExpression: projectionExpression });
337
+ if (Filter)
338
+ params = Object.assign(params, { FilterExpression: Filter });
339
+ if (limit)
340
+ params = Object.assign(params, { Limit: limit });
341
+ let response, acc = { exclusiveStartKey: "", data: [] };
342
+ do {
343
+ response = await this.documentClient.send(new lib_dynamodb_1.QueryCommand(params));
344
+ console.info("Repository: query End");
345
+ params.ExclusiveStartKey = response.LastEvaluatedKey;
346
+ console.log("Last Evaluated Key");
347
+ acc.exclusiveStartKey = response.LastEvaluatedKey;
348
+ if (response && response.Items)
349
+ acc.data = [...acc.data, ...response.Items];
359
350
  if (limit)
360
- params = Object.assign(params, { Limit: limit });
361
- let response, acc = { exclusiveStartKey: "", data: [] };
362
- do {
363
- response = yield this.documentClient.send(new lib_dynamodb_1.QueryCommand(params));
364
- console.info("Repository: query End");
365
- params.ExclusiveStartKey = response.LastEvaluatedKey;
366
- console.log("Last Evaluated Key");
367
- acc.exclusiveStartKey = response.LastEvaluatedKey;
368
- if (response && response.Items)
369
- acc.data = [...acc.data, ...response.Items];
370
- if (limit)
371
- params.Limit = limit - acc.data.length;
372
- } while (response && response.Items && response.LastEvaluatedKey && acc.data.length < limit);
373
- if (acc.data.length > 0) {
374
- acc.data = this.unparseDate(acc.data);
375
- return acc;
376
- }
377
- else
378
- return null;
351
+ params.Limit = limit - acc.data.length;
352
+ } while (response && response.Items && response.LastEvaluatedKey && acc.data.length < limit);
353
+ if (acc.data.length > 0) {
354
+ acc.data = this.unparseDate(acc.data);
355
+ return acc;
379
356
  }
380
- catch (error) {
381
- this.handleError(error);
382
- }
383
- });
357
+ else
358
+ return null;
359
+ }
360
+ catch (error) {
361
+ this.handleError(error);
362
+ }
384
363
  }
385
364
  /**
386
365
  * Get items in DynamoDB table
@@ -388,137 +367,129 @@ class BaseDynamoDBRepository {
388
367
  * @param {Array} condition // Array containing target item key(s) condition
389
368
  * @param {String} projectionExpression // if you want only selected filed should return
390
369
  */
391
- scan(item, condition, projectionExpression, exclusiveStartKey) {
392
- return __awaiter(this, void 0, void 0, function* () {
393
- console.info("Dynamo db Repository: query Start");
394
- try {
395
- const itemKeys = Object.keys(item);
396
- const Key = `${itemKeys.map((k, index) => `#field${index} ${condition[index]} :value${index}`).join(' and ')}`;
397
- let params = {
398
- TableName: this.TABLE_NAME,
399
- ExpressionAttributeNames: itemKeys.reduce((accumulator, k, index) => (Object.assign(Object.assign({}, accumulator), { [`#field${index}`]: k })), {}),
400
- ExpressionAttributeValues: itemKeys.reduce((accumulator, k, index) => (Object.assign(Object.assign({}, accumulator), { [`:value${index}`]: item[k] })), {}),
401
- FilterExpression: Key
402
- };
403
- if (projectionExpression)
404
- params = Object.assign(params, { ProjectionExpression: projectionExpression });
405
- if (exclusiveStartKey)
406
- params = Object.assign(params, { ExclusiveStartKey: exclusiveStartKey });
407
- let response, acc = [];
408
- do {
409
- response = yield this.documentClient.send(new lib_dynamodb_1.ScanCommand(params));
410
- console.info("Repository: query End");
411
- params.ExclusiveStartKey = response.LastEvaluatedKey;
412
- console.log("Last Evaluated Key");
413
- if (response && response.Items)
414
- acc = [...acc, ...response.Items];
415
- } while (response && response.Items && response.LastEvaluatedKey);
416
- if (acc.length > 0)
417
- return this.unparseDate(acc);
418
- else
419
- return null;
420
- }
421
- catch (error) {
422
- this.handleError(error);
423
- }
424
- });
370
+ async scan(item, condition, projectionExpression, exclusiveStartKey) {
371
+ console.info("Dynamo db Repository: query Start");
372
+ try {
373
+ const itemKeys = Object.keys(item);
374
+ const Key = `${itemKeys.map((k, index) => `#field${index} ${condition[index]} :value${index}`).join(' and ')}`;
375
+ let params = {
376
+ TableName: this.TABLE_NAME,
377
+ ExpressionAttributeNames: itemKeys.reduce((accumulator, k, index) => (Object.assign(Object.assign({}, accumulator), { [`#field${index}`]: k })), {}),
378
+ ExpressionAttributeValues: itemKeys.reduce((accumulator, k, index) => (Object.assign(Object.assign({}, accumulator), { [`:value${index}`]: item[k] })), {}),
379
+ FilterExpression: Key
380
+ };
381
+ if (projectionExpression)
382
+ params = Object.assign(params, { ProjectionExpression: projectionExpression });
383
+ if (exclusiveStartKey)
384
+ params = Object.assign(params, { ExclusiveStartKey: exclusiveStartKey });
385
+ let response, acc = [];
386
+ do {
387
+ response = await this.documentClient.send(new lib_dynamodb_1.ScanCommand(params));
388
+ console.info("Repository: query End");
389
+ params.ExclusiveStartKey = response.LastEvaluatedKey;
390
+ console.log("Last Evaluated Key");
391
+ if (response && response.Items)
392
+ acc = [...acc, ...response.Items];
393
+ } while (response && response.Items && response.LastEvaluatedKey);
394
+ if (acc.length > 0)
395
+ return this.unparseDate(acc);
396
+ else
397
+ return null;
398
+ }
399
+ catch (error) {
400
+ this.handleError(error);
401
+ }
425
402
  }
426
403
  /**
427
404
  * Delete item in DynamoDB table
428
405
  * @param {object} key // Object containing target item key(s)
429
406
  */
430
- delete(key) {
431
- return __awaiter(this, void 0, void 0, function* () {
432
- console.info("Dynamo db Repository: delete Start");
433
- var params = {
434
- TableName: this.TABLE_NAME,
435
- Key: key
436
- };
437
- try {
438
- const command = new lib_dynamodb_1.DeleteCommand(params);
439
- const data = yield this.documentClient.send(command);
440
- console.info("Dynamo db Repository: delete End");
441
- }
442
- catch (error) {
443
- console.error(`error occured while deleting custom order log by primary keys - customOrderLog - ${error}`);
444
- console.error("Dynamo db Repository: Error: ");
445
- this.handleError(error);
446
- // throw new DatabaseException( error.code );
447
- }
448
- });
407
+ async delete(key) {
408
+ console.info("Dynamo db Repository: delete Start");
409
+ var params = {
410
+ TableName: this.TABLE_NAME,
411
+ Key: key
412
+ };
413
+ try {
414
+ const command = new lib_dynamodb_1.DeleteCommand(params);
415
+ const data = await this.documentClient.send(command);
416
+ console.info("Dynamo db Repository: delete End");
417
+ }
418
+ catch (error) {
419
+ console.error(`error occured while deleting custom order log by primary keys - customOrderLog - ${error}`);
420
+ console.error("Dynamo db Repository: Error: ");
421
+ this.handleError(error);
422
+ // throw new DatabaseException( error.code );
423
+ }
449
424
  }
450
425
  /**
451
426
  * Get All items in DynamoDB table
452
427
  */
453
- getAll(exclusiveStartKey) {
454
- return __awaiter(this, void 0, void 0, function* () {
455
- var params = {
456
- TableName: this.TABLE_NAME
457
- };
458
- try {
459
- console.info("Dynamo Repository: getAll Start");
460
- if (exclusiveStartKey)
461
- params = Object.assign(params, { ExclusiveStartKey: exclusiveStartKey });
462
- let response, acc = [];
463
- do {
464
- response = yield this.documentClient.send(new lib_dynamodb_1.ScanCommand(params));
465
- console.info("Repository: query End");
466
- params.ExclusiveStartKey = response.LastEvaluatedKey;
467
- console.log("Last Evaluated Key");
468
- if (response && response.Items)
469
- acc = [...acc, ...response.Items];
470
- } while (response && response.Items && response.LastEvaluatedKey);
471
- console.info("Dynamo db Repository: getAll End");
472
- return this.unparseDate(acc);
473
- }
474
- catch (error) {
475
- console.error(`error occured while get all custom order log by primary keys - customOrderLog - ${error}`);
476
- console.error("Dynamo db Repository: Error: ");
477
- this.handleError(error);
478
- // throw new DatabaseException( error.code );
479
- }
480
- });
428
+ async getAll(exclusiveStartKey) {
429
+ var params = {
430
+ TableName: this.TABLE_NAME
431
+ };
432
+ try {
433
+ console.info("Dynamo Repository: getAll Start");
434
+ if (exclusiveStartKey)
435
+ params = Object.assign(params, { ExclusiveStartKey: exclusiveStartKey });
436
+ let response, acc = [];
437
+ do {
438
+ response = await this.documentClient.send(new lib_dynamodb_1.ScanCommand(params));
439
+ console.info("Repository: query End");
440
+ params.ExclusiveStartKey = response.LastEvaluatedKey;
441
+ console.log("Last Evaluated Key");
442
+ if (response && response.Items)
443
+ acc = [...acc, ...response.Items];
444
+ } while (response && response.Items && response.LastEvaluatedKey);
445
+ console.info("Dynamo db Repository: getAll End");
446
+ return this.unparseDate(acc);
447
+ }
448
+ catch (error) {
449
+ console.error(`error occured while get all custom order log by primary keys - customOrderLog - ${error}`);
450
+ console.error("Dynamo db Repository: Error: ");
451
+ this.handleError(error);
452
+ // throw new DatabaseException( error.code );
453
+ }
481
454
  }
482
455
  /**
483
456
  * Bulk Upload item in DynamoDB table
484
457
  * @param {object} item // Object containing add for target item
485
458
  */
486
- bulkUpload(items) {
487
- return __awaiter(this, void 0, void 0, function* () {
488
- try {
489
- let insertItem = yield Promise.all(items.map((item) => __awaiter(this, void 0, void 0, function* () {
490
- item = this.parseDate(item);
491
- return item;
492
- // return {PutRequest:{Item:item}};
493
- })));
494
- // chunkArray is a local convenience function. It takes an array and returns
495
- // a generator function. The generator function yields every N items.
496
- const itemChunks = [...Array(Math.ceil(insertItem.length / 25))].map(_ => insertItem.splice(0, 25));
497
- // For every chunk of 25 items, make one BatchWrite request.
498
- for (const chunk of itemChunks) {
499
- const putRequests = chunk.map((data) => ({
500
- PutRequest: {
501
- Item: data,
502
- },
503
- }));
504
- const command = new lib_dynamodb_1.BatchWriteCommand({
505
- RequestItems: {
506
- // An existing table is required. A composite key of 'title' and 'year' is recommended
507
- // to account for duplicate titles.
508
- [this.TABLE_NAME]: putRequests
509
- }
510
- });
511
- const response = yield this.documentClient.send(command);
512
- console.log('dbItem');
513
- }
514
- console.log("Upload Successfully");
515
- return true;
516
- }
517
- catch (error) {
518
- this.handleError(error);
519
- // // throw new DatabaseException( error.code );
459
+ async bulkUpload(items) {
460
+ try {
461
+ let insertItem = await Promise.all(items.map(async (item) => {
462
+ item = this.parseDate(item);
463
+ return item;
464
+ // return {PutRequest:{Item:item}};
465
+ }));
466
+ // chunkArray is a local convenience function. It takes an array and returns
467
+ // a generator function. The generator function yields every N items.
468
+ const itemChunks = [...Array(Math.ceil(insertItem.length / 25))].map(_ => insertItem.splice(0, 25));
469
+ // For every chunk of 25 items, make one BatchWrite request.
470
+ for (const chunk of itemChunks) {
471
+ const putRequests = chunk.map((data) => ({
472
+ PutRequest: {
473
+ Item: data,
474
+ },
475
+ }));
476
+ const command = new lib_dynamodb_1.BatchWriteCommand({
477
+ RequestItems: {
478
+ // An existing table is required. A composite key of 'title' and 'year' is recommended
479
+ // to account for duplicate titles.
480
+ [this.TABLE_NAME]: putRequests
481
+ }
482
+ });
483
+ const response = await this.documentClient.send(command);
484
+ console.log('dbItem');
520
485
  }
521
- });
486
+ console.log("Upload Successfully");
487
+ return true;
488
+ }
489
+ catch (error) {
490
+ this.handleError(error);
491
+ // // throw new DatabaseException( error.code );
492
+ }
522
493
  }
523
494
  /**
524
495
  *