chatbot-nc 2.0.80 → 2.0.83

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 (188) hide show
  1. package/dist/esm/aws/services/AESEncryptionUsingKMS.js +11 -20
  2. package/dist/esm/aws/services/AESEncryptionUsingKMS.js.map +1 -1
  3. package/dist/esm/aws/services/AWSChimeMeeting.js +15 -24
  4. package/dist/esm/aws/services/AWSChimeMeeting.js.map +1 -1
  5. package/dist/esm/aws/services/AWSCodepipeline.js +21 -34
  6. package/dist/esm/aws/services/AWSCodepipeline.js.map +1 -1
  7. package/dist/esm/aws/services/AWSComprehend.js +3 -12
  8. package/dist/esm/aws/services/AWSComprehend.js.map +1 -1
  9. package/dist/esm/aws/services/AWSConnect.js +135 -146
  10. package/dist/esm/aws/services/AWSConnect.js.map +1 -1
  11. package/dist/esm/aws/services/AWSConnectCases.js +12 -21
  12. package/dist/esm/aws/services/AWSConnectCases.js.map +1 -1
  13. package/dist/esm/aws/services/AWSConnectParticipant.js +12 -21
  14. package/dist/esm/aws/services/AWSConnectParticipant.js.map +1 -1
  15. package/dist/esm/aws/services/AWSCustomerProfiles.js +6 -15
  16. package/dist/esm/aws/services/AWSCustomerProfiles.js.map +1 -1
  17. package/dist/esm/aws/services/AWSDynamoDb.js +9 -18
  18. package/dist/esm/aws/services/AWSDynamoDb.js.map +1 -1
  19. package/dist/esm/aws/services/AWSGateway.js +6 -15
  20. package/dist/esm/aws/services/AWSGateway.js.map +1 -1
  21. package/dist/esm/aws/services/AWSGatewayManagement.js +6 -15
  22. package/dist/esm/aws/services/AWSGatewayManagement.js.map +1 -1
  23. package/dist/esm/aws/services/AWSLambda.js +4 -13
  24. package/dist/esm/aws/services/AWSLambda.js.map +1 -1
  25. package/dist/esm/aws/services/AWSLexModel.js +63 -72
  26. package/dist/esm/aws/services/AWSLexModel.js.map +1 -1
  27. package/dist/esm/aws/services/AWSLexRuntime.js +6 -15
  28. package/dist/esm/aws/services/AWSLexRuntime.js.map +1 -1
  29. package/dist/esm/aws/services/AWSPinpoint.js +9 -18
  30. package/dist/esm/aws/services/AWSPinpoint.js.map +1 -1
  31. package/dist/esm/aws/services/AWSPinpointSMSVoice.js +18 -27
  32. package/dist/esm/aws/services/AWSPinpointSMSVoice.js.map +1 -1
  33. package/dist/esm/aws/services/AWSQConnect.js +18 -27
  34. package/dist/esm/aws/services/AWSQConnect.js.map +1 -1
  35. package/dist/esm/aws/services/AWSS3.js +28 -37
  36. package/dist/esm/aws/services/AWSS3.js.map +1 -1
  37. package/dist/esm/aws/services/AWSSES.js +4 -13
  38. package/dist/esm/aws/services/AWSSES.js.map +1 -1
  39. package/dist/esm/aws/services/AWSSNS.js +11 -20
  40. package/dist/esm/aws/services/AWSSNS.js.map +1 -1
  41. package/dist/esm/aws/services/AWSSSM.js +3 -12
  42. package/dist/esm/aws/services/AWSSSM.js.map +1 -1
  43. package/dist/esm/aws/services/AWSSTS.js +3 -12
  44. package/dist/esm/aws/services/AWSSTS.js.map +1 -1
  45. package/dist/esm/aws/services/AWSTranslate.js +3 -12
  46. package/dist/esm/aws/services/AWSTranslate.js.map +1 -1
  47. package/dist/esm/communication/communicationService.js +29 -38
  48. package/dist/esm/communication/communicationService.js.map +1 -1
  49. package/dist/esm/communication/index.js +125 -148
  50. package/dist/esm/communication/index.js.map +1 -1
  51. package/dist/esm/enum/index.d.ts +4 -1
  52. package/dist/esm/enum/index.js +3 -0
  53. package/dist/esm/enum/index.js.map +1 -1
  54. package/dist/esm/hashing/idObfuscation.js +29 -43
  55. package/dist/esm/hashing/idObfuscation.js.map +1 -1
  56. package/dist/esm/hashing/index.js +141 -168
  57. package/dist/esm/hashing/index.js.map +1 -1
  58. package/dist/esm/repository/dynamodb.js +369 -398
  59. package/dist/esm/repository/dynamodb.js.map +1 -1
  60. package/dist/esm/shortner/index.js +20 -31
  61. package/dist/esm/shortner/index.js.map +1 -1
  62. package/dist/esm/utils/common.js +2 -11
  63. package/dist/esm/utils/common.js.map +1 -1
  64. package/dist/esm/utils/intent.js +24 -33
  65. package/dist/esm/utils/intent.js.map +1 -1
  66. package/dist/esm/webbookEvent/index.js +105 -128
  67. package/dist/esm/webbookEvent/index.js.map +1 -1
  68. package/package.json +4 -5
  69. package/dist/cjs/aws/index.d.ts +0 -178
  70. package/dist/cjs/aws/index.js +0 -52
  71. package/dist/cjs/aws/index.js.map +0 -1
  72. package/dist/cjs/aws/services/AESEncryptionUsingKMS.d.ts +0 -4
  73. package/dist/cjs/aws/services/AESEncryptionUsingKMS.js +0 -110
  74. package/dist/cjs/aws/services/AESEncryptionUsingKMS.js.map +0 -1
  75. package/dist/cjs/aws/services/AWSChimeMeeting.d.ts +0 -8
  76. package/dist/cjs/aws/services/AWSChimeMeeting.js +0 -108
  77. package/dist/cjs/aws/services/AWSChimeMeeting.js.map +0 -1
  78. package/dist/cjs/aws/services/AWSCodepipeline.d.ts +0 -16
  79. package/dist/cjs/aws/services/AWSCodepipeline.js +0 -56
  80. package/dist/cjs/aws/services/AWSCodepipeline.js.map +0 -1
  81. package/dist/cjs/aws/services/AWSComprehend.d.ts +0 -3
  82. package/dist/cjs/aws/services/AWSComprehend.js +0 -39
  83. package/dist/cjs/aws/services/AWSComprehend.js.map +0 -1
  84. package/dist/cjs/aws/services/AWSConnect.d.ts +0 -296
  85. package/dist/cjs/aws/services/AWSConnect.js +0 -876
  86. package/dist/cjs/aws/services/AWSConnect.js.map +0 -1
  87. package/dist/cjs/aws/services/AWSConnectCases.d.ts +0 -7
  88. package/dist/cjs/aws/services/AWSConnectCases.js +0 -90
  89. package/dist/cjs/aws/services/AWSConnectCases.js.map +0 -1
  90. package/dist/cjs/aws/services/AWSConnectParticipant.d.ts +0 -7
  91. package/dist/cjs/aws/services/AWSConnectParticipant.js +0 -96
  92. package/dist/cjs/aws/services/AWSConnectParticipant.js.map +0 -1
  93. package/dist/cjs/aws/services/AWSCustomerProfiles.d.ts +0 -5
  94. package/dist/cjs/aws/services/AWSCustomerProfiles.js +0 -54
  95. package/dist/cjs/aws/services/AWSCustomerProfiles.js.map +0 -1
  96. package/dist/cjs/aws/services/AWSDynamoDb.d.ts +0 -6
  97. package/dist/cjs/aws/services/AWSDynamoDb.js +0 -86
  98. package/dist/cjs/aws/services/AWSDynamoDb.js.map +0 -1
  99. package/dist/cjs/aws/services/AWSGateway.d.ts +0 -5
  100. package/dist/cjs/aws/services/AWSGateway.js +0 -54
  101. package/dist/cjs/aws/services/AWSGateway.js.map +0 -1
  102. package/dist/cjs/aws/services/AWSGatewayManagement.d.ts +0 -5
  103. package/dist/cjs/aws/services/AWSGatewayManagement.js +0 -58
  104. package/dist/cjs/aws/services/AWSGatewayManagement.js.map +0 -1
  105. package/dist/cjs/aws/services/AWSLambda.d.ts +0 -3
  106. package/dist/cjs/aws/services/AWSLambda.js +0 -34
  107. package/dist/cjs/aws/services/AWSLambda.js.map +0 -1
  108. package/dist/cjs/aws/services/AWSLexModel.d.ts +0 -24
  109. package/dist/cjs/aws/services/AWSLexModel.js +0 -396
  110. package/dist/cjs/aws/services/AWSLexModel.js.map +0 -1
  111. package/dist/cjs/aws/services/AWSLexRuntime.d.ts +0 -5
  112. package/dist/cjs/aws/services/AWSLexRuntime.js +0 -56
  113. package/dist/cjs/aws/services/AWSLexRuntime.js.map +0 -1
  114. package/dist/cjs/aws/services/AWSPinpoint.d.ts +0 -6
  115. package/dist/cjs/aws/services/AWSPinpoint.js +0 -74
  116. package/dist/cjs/aws/services/AWSPinpoint.js.map +0 -1
  117. package/dist/cjs/aws/services/AWSPinpointSMSVoice.d.ts +0 -9
  118. package/dist/cjs/aws/services/AWSPinpointSMSVoice.js +0 -120
  119. package/dist/cjs/aws/services/AWSPinpointSMSVoice.js.map +0 -1
  120. package/dist/cjs/aws/services/AWSQConnect.d.ts +0 -9
  121. package/dist/cjs/aws/services/AWSQConnect.js +0 -127
  122. package/dist/cjs/aws/services/AWSQConnect.js.map +0 -1
  123. package/dist/cjs/aws/services/AWSS3.d.ts +0 -11
  124. package/dist/cjs/aws/services/AWSS3.js +0 -195
  125. package/dist/cjs/aws/services/AWSS3.js.map +0 -1
  126. package/dist/cjs/aws/services/AWSSES.d.ts +0 -4
  127. package/dist/cjs/aws/services/AWSSES.js +0 -32
  128. package/dist/cjs/aws/services/AWSSES.js.map +0 -1
  129. package/dist/cjs/aws/services/AWSSNS.d.ts +0 -12
  130. package/dist/cjs/aws/services/AWSSNS.js +0 -82
  131. package/dist/cjs/aws/services/AWSSNS.js.map +0 -1
  132. package/dist/cjs/aws/services/AWSSSM.d.ts +0 -3
  133. package/dist/cjs/aws/services/AWSSSM.js +0 -53
  134. package/dist/cjs/aws/services/AWSSSM.js.map +0 -1
  135. package/dist/cjs/aws/services/AWSSTS.d.ts +0 -4
  136. package/dist/cjs/aws/services/AWSSTS.js +0 -37
  137. package/dist/cjs/aws/services/AWSSTS.js.map +0 -1
  138. package/dist/cjs/aws/services/AWSTranslate.d.ts +0 -4
  139. package/dist/cjs/aws/services/AWSTranslate.js +0 -36
  140. package/dist/cjs/aws/services/AWSTranslate.js.map +0 -1
  141. package/dist/cjs/communication/communicationService.d.ts +0 -20
  142. package/dist/cjs/communication/communicationService.js +0 -292
  143. package/dist/cjs/communication/communicationService.js.map +0 -1
  144. package/dist/cjs/communication/index.d.ts +0 -49
  145. package/dist/cjs/communication/index.js +0 -242
  146. package/dist/cjs/communication/index.js.map +0 -1
  147. package/dist/cjs/config/SSMParameters.d.ts +0 -26
  148. package/dist/cjs/config/SSMParameters.js +0 -34
  149. package/dist/cjs/config/SSMParameters.js.map +0 -1
  150. package/dist/cjs/enum/index.d.ts +0 -233
  151. package/dist/cjs/enum/index.js +0 -286
  152. package/dist/cjs/enum/index.js.map +0 -1
  153. package/dist/cjs/hashing/idObfuscation.d.ts +0 -20
  154. package/dist/cjs/hashing/idObfuscation.js +0 -70
  155. package/dist/cjs/hashing/idObfuscation.js.map +0 -1
  156. package/dist/cjs/hashing/index.d.ts +0 -33
  157. package/dist/cjs/hashing/index.js +0 -219
  158. package/dist/cjs/hashing/index.js.map +0 -1
  159. package/dist/cjs/index.d.ts +0 -12
  160. package/dist/cjs/index.js +0 -52
  161. package/dist/cjs/index.js.map +0 -1
  162. package/dist/cjs/logger/index.d.ts +0 -3
  163. package/dist/cjs/logger/index.js +0 -70
  164. package/dist/cjs/logger/index.js.map +0 -1
  165. package/dist/cjs/logger/loggerTransports.d.ts +0 -11
  166. package/dist/cjs/logger/loggerTransports.js +0 -72
  167. package/dist/cjs/logger/loggerTransports.js.map +0 -1
  168. package/dist/cjs/repository/dynamodb.d.ts +0 -121
  169. package/dist/cjs/repository/dynamodb.js +0 -725
  170. package/dist/cjs/repository/dynamodb.js.map +0 -1
  171. package/dist/cjs/shortner/index.d.ts +0 -4
  172. package/dist/cjs/shortner/index.js +0 -45
  173. package/dist/cjs/shortner/index.js.map +0 -1
  174. package/dist/cjs/utils/common.d.ts +0 -7
  175. package/dist/cjs/utils/common.js +0 -208
  176. package/dist/cjs/utils/common.js.map +0 -1
  177. package/dist/cjs/utils/date-format.d.ts +0 -16
  178. package/dist/cjs/utils/date-format.js +0 -282
  179. package/dist/cjs/utils/date-format.js.map +0 -1
  180. package/dist/cjs/utils/index.d.ts +0 -37
  181. package/dist/cjs/utils/index.js +0 -12
  182. package/dist/cjs/utils/index.js.map +0 -1
  183. package/dist/cjs/utils/intent.d.ts +0 -12
  184. package/dist/cjs/utils/intent.js +0 -214
  185. package/dist/cjs/utils/intent.js.map +0 -1
  186. package/dist/cjs/webbookEvent/index.d.ts +0 -22
  187. package/dist/cjs/webbookEvent/index.js +0 -174
  188. package/dist/cjs/webbookEvent/index.js.map +0 -1
@@ -1,725 +0,0 @@
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
- Object.defineProperty(exports, "__esModule", { value: true });
12
- const client_dynamodb_1 = require("@aws-sdk/client-dynamodb"); // ES Modules import
13
- const lib_dynamodb_1 = require("@aws-sdk/lib-dynamodb");
14
- const awsRegion = process.env.AWS_DEFAULT_REGION || 'us-east-1';
15
- /**
16
- * Base Repository of Dynamodb
17
- * @param {object} item // Object containing add for target item
18
- */
19
- class BaseDynamoDBRepository {
20
- constructor() {
21
- this.TABLE_NAME = '';
22
- this.PRIMARY_KEY = [];
23
- let client = new client_dynamodb_1.DynamoDBClient({
24
- region: awsRegion,
25
- });
26
- this.documentClient = lib_dynamodb_1.DynamoDBDocumentClient.from(client);
27
- }
28
- /**
29
- * Add item in DynamoDB table
30
- * @param {object} item // Object containing add for target item
31
- */
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
- });
53
- }
54
- /**
55
- * Update item in DynamoDB table
56
- * @param {object} key // Object containing target item key(s)
57
- * @param {object} item // Object containing updates for target item
58
- */
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
- });
79
- }
80
- /**
81
- * Update item in DynamoDB table
82
- * @param {String[]} keys // String Array containing target item key(s)
83
- * @param {object} item // Object containing updates for target item
84
- * @returns
85
- */
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
- });
109
- }
110
- /**
111
- *
112
- * @param key Only Partition Key (No Primary Key or Combination Key)
113
- * @param item Object of Keys
114
- * @returns
115
- */
116
- // public async updateByMutipleValue (key: string, item: any) {
117
- // try {
118
- // const keyItem = Object.keys(item).filter(k => k == key).reduce((obj: any, key: any) => {
119
- // obj[key] = item[key];
120
- // return obj;
121
- // }, {});
122
- // let responseItem = await this.getSingleItem(keyItem);
123
- // if(responseItem)
124
- // {
125
- // const itemKeys = Object.keys(item).filter(k => k !== key).reduce((obj: any, key: any) => {
126
- // obj[key] = item[key];
127
- // return obj;
128
- // }, {});
129
- // let returnResponse = this.parseDate({...responseItem,...itemKeys,updatedAt:Number(Date.now())});
130
- // var params: PutCommandInput = {
131
- // TableName: this.TABLE_NAME,
132
- // Item: returnResponse
133
- // }
134
- // console.log(returnResponse);
135
- // await this.documentClient.send(new PutCommand(params))
136
- // return returnResponse;
137
- // }
138
- // return responseItem;
139
- // } catch (error) {
140
- // this.handleError(error);
141
- // }
142
- // }
143
- /**
144
- * Get item in DynamoDB table
145
- * @param {object} id // Object containing target item key(s)
146
- * @param {object} version // Object containing updates for target item
147
- */
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 );
169
- }
170
- });
171
- }
172
- /**
173
- * Get item in DynamoDB table
174
- * @param {object} id // Object containing target item key(s)
175
- * @param {object} version // Object containing updates for target item
176
- */
177
- // public async getSingleItem (key: object) {
178
- // let response = await this.query(key);
179
- // if(response)
180
- // return response[0];
181
- // else
182
- // return null;
183
- // }
184
- /**
185
- * Get items in DynamoDB table
186
- * @param {object} item // Object containing target item key(s)
187
- */
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
- }
243
- 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
- }
272
- }
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
- });
285
- }
286
- /**
287
- * Get items in DynamoDB table with Pagination
288
- * @param {object} item // Object containing target item key(s)
289
- */
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 });
359
- 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;
379
- }
380
- catch (error) {
381
- this.handleError(error);
382
- }
383
- });
384
- }
385
- /**
386
- * Get items in DynamoDB table
387
- * @param {object} item // Object containing target item key(s)
388
- * @param {Array} condition // Array containing target item key(s) condition
389
- * @param {String} projectionExpression // if you want only selected filed should return
390
- */
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
- });
425
- }
426
- /**
427
- * Delete item in DynamoDB table
428
- * @param {object} key // Object containing target item key(s)
429
- */
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
- });
449
- }
450
- /**
451
- * Get All items in DynamoDB table
452
- */
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
- });
481
- }
482
- /**
483
- * Bulk Upload item in DynamoDB table
484
- * @param {object} item // Object containing add for target item
485
- */
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 );
520
- }
521
- });
522
- }
523
- /**
524
- *
525
- * @param data
526
- * @returns
527
- */
528
- parseDate(data) {
529
- return JSON.parse(JSON.stringify(data));
530
- }
531
- /**
532
- *
533
- * @param data
534
- * @returns
535
- */
536
- unparseDate(data) {
537
- //const dateFormat = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z$/;
538
- var ISO_8601_FULL = /^\d{4}-\d\d-\d\dT\d\d:\d\d:\d\d(\.\d+)?(([+-]\d\d:\d\d)|Z)?$/i;
539
- var DATE_STRING = /^\d{4}-\d\d-\d\d \d\d:\d\d:\d\d$/i;
540
- function reviver(key, value) {
541
- if ((typeof value === "string" && ISO_8601_FULL.test(value))) {
542
- //var tzoffset = (new Date(value)).getTimezoneOffset() * 60000; //offset in milliseconds
543
- var localISOTime = new Date(value).toISOString();
544
- return new Date(localISOTime);
545
- }
546
- if (typeof value === "string" && DATE_STRING.test(value)) {
547
- return new Date(value);
548
- }
549
- return value;
550
- }
551
- const text = JSON.stringify(data);
552
- const obj = JSON.parse(text, reviver);
553
- return obj;
554
- }
555
- /**
556
- *
557
- * @param err
558
- * @returns
559
- */
560
- // Handles errors during PutItem execution. Use recommendations in error messages below to
561
- // add error handling specific to your application use-case.
562
- handleError(err) {
563
- if (!err) {
564
- console.error("Encountered error object was empty");
565
- return;
566
- }
567
- if (!err.code) {
568
- console.error(`An exception occurred, investigate and configure retry strategy. Error: ${JSON.stringify(err)}`);
569
- }
570
- switch (err.code) {
571
- case "ConditionalCheckFailedException":
572
- console.error(`Condition check specified in the operation failed, review and update the condition check before retrying. Error: ${err.message}`);
573
- break;
574
- case "TransactionConflictException":
575
- console.error(`Operation was rejected because there is an ongoing transaction for the item, generally safe to retry ' +
576
- 'with exponential back-off. Error: ${err.message}`);
577
- break;
578
- case "ItemCollectionSizeLimitExceededException":
579
- console.error("An item collection is too large, you're using Local Secondary Index and exceeded size limit of" +
580
- `items per partition key. Consider using Global Secondary Index instead. Error: ${err.message}`);
581
- break;
582
- default:
583
- break;
584
- // Common DynamoDB API errors are handled below
585
- }
586
- this.handleCommonErrors(err);
587
- }
588
- /**
589
- *
590
- * @param err
591
- */
592
- handleCommonErrors(err) {
593
- switch (err.code) {
594
- case "InternalServerError":
595
- console.error(`Internal Server Error, generally safe to retry with exponential back-off. Error: ${err.message}`);
596
- break;
597
- case "ProvisionedThroughputExceededException":
598
- console.error("Request rate is too high. If you're using a custom retry strategy make sure to retry with exponential back-off."
599
- + `Otherwise consider reducing frequency of requests or increasing provisioned capacity for your table or secondary index. Error: ${err.message}`);
600
- break;
601
- case "ResourceNotFoundException":
602
- console.error(`One of the tables was not found, verify table exists before retrying. Error: ${err.message}`);
603
- break;
604
- case "ServiceUnavailable":
605
- console.error(`Had trouble reaching DynamoDB. generally safe to retry with exponential back-off. Error: ${err.message}`);
606
- break;
607
- case "ThrottlingException":
608
- console.error(`Request denied due to throttling, generally safe to retry with exponential back-off. Error: ${err.message}`);
609
- break;
610
- case "UnrecognizedClientException":
611
- console.error("The request signature is incorrect most likely due to an invalid AWS access key ID or secret key, fix before retrying."
612
- + `Error: ${err.message}`);
613
- break;
614
- case "ValidationException":
615
- console.error("The input fails to satisfy the constraints specified by DynamoDB, "
616
- + `fix input before retrying. Error: ${err.message}`);
617
- break;
618
- case "RequestLimitExceeded":
619
- console.error("Throughput exceeds the current throughput limit for your account, "
620
- + `increase account level throughput before retrying. Error: ${err.message}`);
621
- break;
622
- default:
623
- console.error(`An exception occurred, investigate and configure retry strategy. Error: ${err.message}`);
624
- break;
625
- }
626
- // throw new DatabaseException( err.code );
627
- }
628
- /**
629
- *
630
- * @param str
631
- * @returns
632
- */
633
- isComparator(str) {
634
- return ['=', '<>', '<', '<=', '>', '>='].includes(str);
635
- }
636
- /**
637
- *
638
- * @param item
639
- * @param index
640
- * @returns
641
- */
642
- getArrayValue(item, index) {
643
- return item.reduce((acc, key, idx) => {
644
- acc[`:value${index}${idx}`] = key;
645
- return acc;
646
- }, {});
647
- }
648
- /**
649
- *
650
- * @param item
651
- * @param condition
652
- * @param indexName
653
- * @returns
654
- */
655
- getKeyAndFilter(item, condition, indexName) {
656
- try {
657
- const itemKeys = Object.keys(item);
658
- let Key, Filter;
659
- if (!indexName) {
660
- Key = `${itemKeys.map((k, index) => {
661
- if (this.PRIMARY_KEY.length === 0 || this.PRIMARY_KEY.includes(k))
662
- if (!this.isComparator(condition[index] || '=')) {
663
- if (condition[index].toUpperCase() == 'BETWEEN')
664
- return `#field${index} ${condition[index]} ${Object.keys(this.getArrayValue(item[k], index)).join(' and ')}`;
665
- else if (condition[index].toUpperCase() == 'IN')
666
- return `#field${index} ${condition[index]}(${Object.keys(this.getArrayValue(item[k], index)).toString()})`;
667
- else
668
- return `${condition[index]}(#field${index} ,:value${index})`;
669
- }
670
- else
671
- return `#field${index} ${condition[index] || '='} :value${index}`;
672
- }).filter(a => a).join(' and ')}`;
673
- Filter = `${itemKeys.map((k, index) => {
674
- if (!this.PRIMARY_KEY.includes(k))
675
- if (!this.isComparator(condition[index] || '=')) {
676
- if (condition[index].toUpperCase() == 'BETWEEN')
677
- return `#field${index} ${condition[index]} ${Object.keys(this.getArrayValue(item[k], index)).join(' and ')}`;
678
- else if (condition[index].toUpperCase() == 'IN')
679
- return `#field${index} ${condition[index]}(${Object.keys(this.getArrayValue(item[k], index)).toString()})`;
680
- else
681
- return `${condition[index]}(#field${index} ,:value${index})`;
682
- }
683
- else
684
- return `#field${index} ${condition[index] || '='} :value${index}`;
685
- }).filter(a => a).join(' and ')}`;
686
- }
687
- else {
688
- Key = `${itemKeys.map((k, index) => {
689
- if (indexName.split('-').includes(k)) {
690
- if (!this.isComparator(condition[index] || '=')) {
691
- if (condition[index].toUpperCase() == 'BETWEEN')
692
- return `#field${index} ${condition[index]} ${Object.keys(this.getArrayValue(item[k], index)).join(' and ')}`;
693
- else if (condition[index].toUpperCase() == 'IN')
694
- return `#field${index} ${condition[index]}(${Object.keys(this.getArrayValue(item[k], index)).toString()})`;
695
- else
696
- return `${condition[index]}(#field${index} ,:value${index})`;
697
- }
698
- else
699
- return `#field${index} ${condition[index] || '='} :value${index}`;
700
- }
701
- }).filter(a => a).join(' and ')}`;
702
- Filter = `${itemKeys.map((k, index) => {
703
- if (!indexName.split('-').includes(k)) {
704
- if (!this.isComparator(condition[index] || '=')) {
705
- if (condition[index].toUpperCase() == 'BETWEEN')
706
- return `#field${index} ${condition[index]} ${Object.keys(this.getArrayValue(item[k], index)).join(' and ')}`;
707
- else if (condition[index].toUpperCase() == 'IN')
708
- return `#field${index} ${condition[index]}(${Object.keys(this.getArrayValue(item[k], index)).toString()})`;
709
- else
710
- return `${condition[index]}(#field${index} ,:value${index})`;
711
- }
712
- else
713
- return `#field${index} ${condition[index] || '='} :value${index}`;
714
- }
715
- }).filter(a => a).join(' and ')}`;
716
- }
717
- return [Key, Filter];
718
- }
719
- catch (error) {
720
- throw error;
721
- }
722
- }
723
- }
724
- exports.default = BaseDynamoDBRepository;
725
- //# sourceMappingURL=dynamodb.js.map