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.
- package/dist/cjs/aws/index.d.ts +1 -0
- package/dist/cjs/aws/services/AESEncryptionUsingKMS.js +11 -20
- package/dist/cjs/aws/services/AESEncryptionUsingKMS.js.map +1 -1
- package/dist/cjs/aws/services/AWSChimeMeeting.js +15 -24
- package/dist/cjs/aws/services/AWSChimeMeeting.js.map +1 -1
- package/dist/cjs/aws/services/AWSCodepipeline.js +21 -34
- package/dist/cjs/aws/services/AWSCodepipeline.js.map +1 -1
- package/dist/cjs/aws/services/AWSComprehend.js +3 -12
- package/dist/cjs/aws/services/AWSComprehend.js.map +1 -1
- package/dist/cjs/aws/services/AWSConnect.js +135 -146
- package/dist/cjs/aws/services/AWSConnect.js.map +1 -1
- package/dist/cjs/aws/services/AWSConnectCases.js +12 -21
- package/dist/cjs/aws/services/AWSConnectCases.js.map +1 -1
- package/dist/cjs/aws/services/AWSConnectParticipant.js +12 -21
- package/dist/cjs/aws/services/AWSConnectParticipant.js.map +1 -1
- package/dist/cjs/aws/services/AWSCustomerProfiles.js +6 -15
- package/dist/cjs/aws/services/AWSCustomerProfiles.js.map +1 -1
- package/dist/cjs/aws/services/AWSDynamoDb.js +9 -18
- package/dist/cjs/aws/services/AWSDynamoDb.js.map +1 -1
- package/dist/cjs/aws/services/AWSGateway.js +6 -15
- package/dist/cjs/aws/services/AWSGateway.js.map +1 -1
- package/dist/cjs/aws/services/AWSGatewayManagement.js +6 -15
- package/dist/cjs/aws/services/AWSGatewayManagement.js.map +1 -1
- package/dist/cjs/aws/services/AWSLambda.js +4 -13
- package/dist/cjs/aws/services/AWSLambda.js.map +1 -1
- package/dist/cjs/aws/services/AWSLexModel.js +63 -72
- package/dist/cjs/aws/services/AWSLexModel.js.map +1 -1
- package/dist/cjs/aws/services/AWSLexRuntime.js +6 -15
- package/dist/cjs/aws/services/AWSLexRuntime.js.map +1 -1
- package/dist/cjs/aws/services/AWSPinpoint.js +9 -18
- package/dist/cjs/aws/services/AWSPinpoint.js.map +1 -1
- package/dist/cjs/aws/services/AWSPinpointSMSVoice.js +18 -27
- package/dist/cjs/aws/services/AWSPinpointSMSVoice.js.map +1 -1
- package/dist/cjs/aws/services/AWSQConnect.js +18 -27
- package/dist/cjs/aws/services/AWSQConnect.js.map +1 -1
- package/dist/cjs/aws/services/AWSS3.js +28 -37
- package/dist/cjs/aws/services/AWSS3.js.map +1 -1
- package/dist/cjs/aws/services/AWSSES.js +4 -13
- package/dist/cjs/aws/services/AWSSES.js.map +1 -1
- package/dist/cjs/aws/services/AWSSNS.js +11 -20
- package/dist/cjs/aws/services/AWSSNS.js.map +1 -1
- package/dist/cjs/aws/services/AWSSSM.d.ts +1 -0
- package/dist/cjs/aws/services/AWSSSM.js +42 -13
- package/dist/cjs/aws/services/AWSSSM.js.map +1 -1
- package/dist/cjs/aws/services/AWSSTS.js +3 -12
- package/dist/cjs/aws/services/AWSSTS.js.map +1 -1
- package/dist/cjs/aws/services/AWSTranslate.js +3 -12
- package/dist/cjs/aws/services/AWSTranslate.js.map +1 -1
- package/dist/cjs/communication/communicationService.js +29 -38
- package/dist/cjs/communication/communicationService.js.map +1 -1
- package/dist/cjs/communication/index.js +125 -148
- package/dist/cjs/communication/index.js.map +1 -1
- package/dist/cjs/hashing/idObfuscation.js +28 -42
- package/dist/cjs/hashing/idObfuscation.js.map +1 -1
- package/dist/cjs/hashing/index.js +141 -168
- package/dist/cjs/hashing/index.js.map +1 -1
- package/dist/cjs/repository/dynamodb.js +369 -398
- package/dist/cjs/repository/dynamodb.js.map +1 -1
- package/dist/cjs/shortner/index.js +20 -31
- package/dist/cjs/shortner/index.js.map +1 -1
- package/dist/cjs/utils/common.js +2 -11
- package/dist/cjs/utils/common.js.map +1 -1
- package/dist/cjs/utils/intent.js +24 -33
- package/dist/cjs/utils/intent.js.map +1 -1
- package/dist/cjs/webbookEvent/index.js +105 -128
- package/dist/cjs/webbookEvent/index.js.map +1 -1
- package/dist/esm/aws/index.d.ts +1 -0
- package/dist/esm/aws/services/AWSConnect.js +0 -2
- package/dist/esm/aws/services/AWSConnect.js.map +1 -1
- package/dist/esm/aws/services/AWSSSM.d.ts +1 -0
- package/dist/esm/aws/services/AWSSSM.js +39 -1
- package/dist/esm/aws/services/AWSSSM.js.map +1 -1
- package/dist/esm/hashing/idObfuscation.js +2 -1
- package/dist/esm/hashing/idObfuscation.js.map +1 -1
- 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
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
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
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
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
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
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
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
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
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
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
|
-
|
|
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
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
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
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
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 =
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
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
|
-
|
|
381
|
-
|
|
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
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
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
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
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
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
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
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
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
|
*
|