ag-common 0.0.418 → 0.0.419

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 (179) hide show
  1. package/dist/api/helpers/api.js +34 -35
  2. package/dist/api/helpers/aws.js +9 -13
  3. package/dist/api/helpers/cloudfront.js +7 -24
  4. package/dist/api/helpers/dynamo.js +85 -134
  5. package/dist/api/helpers/dynamoInfra.js +14 -19
  6. package/dist/api/helpers/enforceDynamoProvisionCap.js +14 -18
  7. package/dist/api/helpers/index.js +14 -30
  8. package/dist/api/helpers/openApiHelpers.d.ts +2 -3
  9. package/dist/api/helpers/openApiHelpers.js +34 -37
  10. package/dist/api/helpers/s3.js +81 -126
  11. package/dist/api/helpers/ses.js +9 -28
  12. package/dist/api/helpers/sqs.js +9 -26
  13. package/dist/api/helpers/ssm.js +8 -14
  14. package/dist/api/helpers/sts.js +16 -34
  15. package/dist/api/helpers/validateOpenApi.js +92 -103
  16. package/dist/api/helpers/validations.js +29 -46
  17. package/dist/api/index.js +2 -18
  18. package/dist/api/openapi-prefix.js +25 -38
  19. package/dist/api/types/aws.js +1 -2
  20. package/dist/api/types/index.js +1 -17
  21. package/dist/common/const.js +2 -5
  22. package/dist/common/helpers/array.js +8 -19
  23. package/dist/common/helpers/async.js +10 -28
  24. package/dist/common/helpers/binary.js +5 -10
  25. package/dist/common/helpers/date.js +14 -25
  26. package/dist/common/helpers/email.js +5 -11
  27. package/dist/common/helpers/func.js +3 -7
  28. package/dist/common/helpers/generator.js +9 -24
  29. package/dist/common/helpers/groupBy.js +3 -9
  30. package/dist/common/helpers/hashCode.js +3 -9
  31. package/dist/common/helpers/i18n.js +9 -17
  32. package/dist/common/helpers/index.js +18 -34
  33. package/dist/common/helpers/log.js +16 -28
  34. package/dist/common/helpers/math.js +9 -21
  35. package/dist/common/helpers/memo.js +3 -7
  36. package/dist/common/helpers/object.js +20 -35
  37. package/dist/common/helpers/random.js +4 -10
  38. package/dist/common/helpers/secondsInNearest.js +2 -7
  39. package/dist/common/helpers/sleep.js +1 -5
  40. package/dist/common/helpers/string/base64.js +2 -7
  41. package/dist/common/helpers/string/chunk.js +1 -5
  42. package/dist/common/helpers/string/contains.js +2 -7
  43. package/dist/common/helpers/string/getExtendedStringSegment.js +5 -9
  44. package/dist/common/helpers/string/index.js +10 -26
  45. package/dist/common/helpers/string/json.js +1 -5
  46. package/dist/common/helpers/string/object.js +1 -5
  47. package/dist/common/helpers/string/surround.js +1 -5
  48. package/dist/common/helpers/string/trim.js +2 -7
  49. package/dist/common/helpers/string/truncate.js +1 -5
  50. package/dist/common/helpers/string/url.js +4 -9
  51. package/dist/common/index.js +2 -18
  52. package/dist/index.js +3 -19
  53. package/dist/ui/components/BorderGradient/index.js +18 -25
  54. package/dist/ui/components/Button/index.js +17 -25
  55. package/dist/ui/components/Chevron/index.js +9 -16
  56. package/dist/ui/components/Close/index.js +6 -13
  57. package/dist/ui/components/Confirm/Dialog.js +9 -25
  58. package/dist/ui/components/Confirm/Modal.js +20 -27
  59. package/dist/ui/components/Confirm/index.js +3 -19
  60. package/dist/ui/components/Confirm/types.js +1 -2
  61. package/dist/ui/components/DropdownList/Base.js +33 -64
  62. package/dist/ui/components/DropdownList/Dialog.js +8 -24
  63. package/dist/ui/components/DropdownList/index.js +2 -18
  64. package/dist/ui/components/DropdownList/types.js +1 -2
  65. package/dist/ui/components/FlexColumn/index.js +4 -14
  66. package/dist/ui/components/FlexRow/index.js +4 -14
  67. package/dist/ui/components/HeadersRaw/index.js +20 -27
  68. package/dist/ui/components/HorizontalScrollBar/index.js +6 -34
  69. package/dist/ui/components/Icon/index.js +9 -16
  70. package/dist/ui/components/Image/index.js +10 -28
  71. package/dist/ui/components/InfiniteScroll/index.js +18 -50
  72. package/dist/ui/components/KebabDots/index.js +6 -13
  73. package/dist/ui/components/Loader/index.js +9 -39
  74. package/dist/ui/components/Modal/Dialog.js +7 -23
  75. package/dist/ui/components/Modal/Modal.js +19 -49
  76. package/dist/ui/components/Modal/index.js +3 -19
  77. package/dist/ui/components/Modal/types.js +1 -2
  78. package/dist/ui/components/OpenApiCodeBlock/OpenApiCodeBlock.js +26 -34
  79. package/dist/ui/components/OpenApiCodeBlock/curl/helpers/body.js +12 -19
  80. package/dist/ui/components/OpenApiCodeBlock/curl/helpers/getCurlLines.js +6 -11
  81. package/dist/ui/components/OpenApiCodeBlock/curl/helpers/security.js +8 -15
  82. package/dist/ui/components/OpenApiCodeBlock/curl/index.js +14 -21
  83. package/dist/ui/components/OpenApiCodeBlock/fetch/helpers/call.js +8 -15
  84. package/dist/ui/components/OpenApiCodeBlock/fetch/helpers/getFetchLines.js +3 -8
  85. package/dist/ui/components/OpenApiCodeBlock/fetch/helpers/req.js +27 -34
  86. package/dist/ui/components/OpenApiCodeBlock/fetch/index.js +11 -18
  87. package/dist/ui/components/OpenApiCodeBlock/helpers/common.js +7 -17
  88. package/dist/ui/components/OpenApiCodeBlock/helpers/joinJsx.js +6 -15
  89. package/dist/ui/components/OpenApiCodeBlock/index.js +2 -18
  90. package/dist/ui/components/OpenApiCodeBlock/types.js +1 -2
  91. package/dist/ui/components/PieChart/index.js +11 -18
  92. package/dist/ui/components/ProgressBar/index.js +15 -45
  93. package/dist/ui/components/Prompt/Dialog.js +7 -23
  94. package/dist/ui/components/Prompt/Modal.js +25 -55
  95. package/dist/ui/components/Prompt/index.js +2 -18
  96. package/dist/ui/components/RowOrColumn/index.js +7 -17
  97. package/dist/ui/components/Search/AutoHideSearchBox.js +24 -56
  98. package/dist/ui/components/Search/Base.js +21 -52
  99. package/dist/ui/components/Search/Dialog.js +10 -26
  100. package/dist/ui/components/Search/Inline.js +3 -10
  101. package/dist/ui/components/Search/Modal.js +10 -17
  102. package/dist/ui/components/Search/SearchBox.js +26 -58
  103. package/dist/ui/components/Search/index.js +7 -23
  104. package/dist/ui/components/Search/types.js +1 -2
  105. package/dist/ui/components/Sidebar/index.js +18 -25
  106. package/dist/ui/components/SparkLine/index.js +17 -27
  107. package/dist/ui/components/Table/index.js +15 -22
  108. package/dist/ui/components/TextEdit/CheckboxEdit.js +21 -51
  109. package/dist/ui/components/TextEdit/ColourEdit.js +17 -44
  110. package/dist/ui/components/TextEdit/LengthBox.js +5 -12
  111. package/dist/ui/components/TextEdit/ListboxEdit.js +15 -42
  112. package/dist/ui/components/TextEdit/RadioGroup.js +13 -43
  113. package/dist/ui/components/TextEdit/TextEdit.js +48 -78
  114. package/dist/ui/components/TextEdit/common.js +11 -17
  115. package/dist/ui/components/TextEdit/index.js +6 -22
  116. package/dist/ui/components/TextEdit/types.js +1 -2
  117. package/dist/ui/components/TextWithButton/index.js +10 -40
  118. package/dist/ui/components/TimelineChart/index.js +14 -24
  119. package/dist/ui/components/Toast/Cross.js +9 -16
  120. package/dist/ui/components/Toast/Tick.js +4 -11
  121. package/dist/ui/components/Toast/Warning.js +8 -15
  122. package/dist/ui/components/Toast/base.js +33 -65
  123. package/dist/ui/components/Toast/index.js +2 -18
  124. package/dist/ui/components/Toast/types.js +1 -2
  125. package/dist/ui/components/UserImage/index.js +17 -48
  126. package/dist/ui/components/index.js +30 -46
  127. package/dist/ui/helpers/axiosHelper.js +25 -39
  128. package/dist/ui/helpers/browserHelpers.js +7 -22
  129. package/dist/ui/helpers/callOpenApi/cached.js +18 -37
  130. package/dist/ui/helpers/callOpenApi/direct.js +46 -59
  131. package/dist/ui/helpers/callOpenApi/helpers.js +25 -40
  132. package/dist/ui/helpers/callOpenApi/hook.js +47 -36
  133. package/dist/ui/helpers/callOpenApi/index.js +5 -21
  134. package/dist/ui/helpers/callOpenApi/types.js +1 -2
  135. package/dist/ui/helpers/cognito.js +1 -2
  136. package/dist/ui/helpers/cookie/const.js +2 -5
  137. package/dist/ui/helpers/cookie/get.js +13 -14
  138. package/dist/ui/helpers/cookie/index.js +5 -21
  139. package/dist/ui/helpers/cookie/raw.js +9 -16
  140. package/dist/ui/helpers/cookie/set.js +10 -15
  141. package/dist/ui/helpers/cookie/use.js +23 -16
  142. package/dist/ui/helpers/date.js +10 -15
  143. package/dist/ui/helpers/debounce.js +5 -10
  144. package/dist/ui/helpers/dom.js +6 -13
  145. package/dist/ui/helpers/extractAttributes.js +2 -7
  146. package/dist/ui/helpers/index.js +25 -41
  147. package/dist/ui/helpers/jwt.js +1 -2
  148. package/dist/ui/helpers/plural.js +1 -5
  149. package/dist/ui/helpers/routes.js +17 -24
  150. package/dist/ui/helpers/serviceWorker.js +8 -23
  151. package/dist/ui/helpers/useContextMenu.js +9 -14
  152. package/dist/ui/helpers/useElementAttribute.js +3 -7
  153. package/dist/ui/helpers/useGranularHook.js +5 -10
  154. package/dist/ui/helpers/useInterval.js +8 -12
  155. package/dist/ui/helpers/useLocalStorage.js +24 -32
  156. package/dist/ui/helpers/useLockBodyScroll.js +3 -7
  157. package/dist/ui/helpers/useOnClickOutside.js +7 -12
  158. package/dist/ui/helpers/useOnScroll.js +15 -21
  159. package/dist/ui/helpers/useOverloadPageSearch.js +3 -7
  160. package/dist/ui/helpers/useQueryString.js +14 -20
  161. package/dist/ui/helpers/useResize.js +8 -12
  162. package/dist/ui/helpers/useTimeout.js +5 -9
  163. package/dist/ui/icons/ChevronRight.js +3 -9
  164. package/dist/ui/icons/CrossIcon.js +5 -12
  165. package/dist/ui/icons/Door.js +4 -10
  166. package/dist/ui/icons/HorizontalDots.js +3 -9
  167. package/dist/ui/icons/Magnify.js +3 -10
  168. package/dist/ui/icons/Pencil.js +5 -12
  169. package/dist/ui/icons/Save.js +4 -11
  170. package/dist/ui/icons/Undo.js +5 -12
  171. package/dist/ui/icons/UserOutline.js +3 -9
  172. package/dist/ui/icons/index.js +9 -25
  173. package/dist/ui/index.js +4 -20
  174. package/dist/ui/styles/colours.js +7 -12
  175. package/dist/ui/styles/common.js +14 -22
  176. package/dist/ui/styles/index.js +4 -20
  177. package/dist/ui/styles/media.js +7 -10
  178. package/dist/ui/styles/standaloneStyles.js +10 -16
  179. package/package.json +18 -17
@@ -1,21 +1,7 @@
1
- "use strict";
2
- var __rest = (this && this.__rest) || function (s, e) {
3
- var t = {};
4
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
5
- t[p] = s[p];
6
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
7
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
8
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
9
- t[p[i]] = s[p[i]];
10
- }
11
- return t;
12
- };
13
- Object.defineProperty(exports, "__esModule", { value: true });
14
- exports.generateDynamoPKS = exports.stripPKs = exports.returnCode = void 0;
15
1
  /* eslint-disable @typescript-eslint/ban-ts-comment */
16
2
  // eslint-disable-next-line
17
- const array_1 = require("../../common/helpers/array");
18
- const returnCode = (statusCode, body, extraHeaders, fullSiteUrl) => {
3
+ import { notEmpty } from '../../common/helpers/array';
4
+ export const returnCode = (statusCode, body, extraHeaders, fullSiteUrl) => {
19
5
  let headers = {
20
6
  'Access-Control-Allow-Headers': 'Content-Type,X-Amz-Date,Authorization,X-Api-Key,X-Amz-Security-Token,X-Amz-User-Agent,User-Agent,Origin',
21
7
  'Access-Control-Allow-Methods': '*',
@@ -23,7 +9,10 @@ const returnCode = (statusCode, body, extraHeaders, fullSiteUrl) => {
23
9
  'Access-Control-Allow-Credentials': true, // Required for cookies, authorization headers with HTTPS
24
10
  };
25
11
  if (extraHeaders && Object.keys(extraHeaders).length > 0) {
26
- headers = Object.assign(Object.assign({}, headers), extraHeaders);
12
+ headers = {
13
+ ...headers,
14
+ ...extraHeaders,
15
+ };
27
16
  }
28
17
  return {
29
18
  headers,
@@ -32,7 +21,6 @@ const returnCode = (statusCode, body, extraHeaders, fullSiteUrl) => {
32
21
  body: (!body ? undefined : JSON.stringify(body, null, 2)),
33
22
  };
34
23
  };
35
- exports.returnCode = returnCode;
36
24
  /**
37
25
  * strip all dynamo generated keys. can optionally keep PK
38
26
  * @param record
@@ -40,14 +28,14 @@ exports.returnCode = returnCode;
40
28
  * @returns stripped record
41
29
  */
42
30
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
43
- const stripPKs = (record, keepPk = true) => {
31
+ export const stripPKs = (record, keepPk = true) => {
44
32
  if (!record) {
45
33
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
46
34
  return null;
47
35
  }
48
36
  // @ts-ignore
49
37
  // eslint-disable-next-line
50
- const { PK, PK1, PK2, PK3, PK4, PK5, L1, L2, L3, L4, L5, L6, type } = record, rest = __rest(record, ["PK", "PK1", "PK2", "PK3", "PK4", "PK5", "L1", "L2", "L3", "L4", "L5", "L6", "type"]);
38
+ const { PK, PK1, PK2, PK3, PK4, PK5, L1, L2, L3, L4, L5, L6, type, ...rest } = record;
51
39
  if (keepPk) {
52
40
  //@ts-ignore
53
41
  rest.PK = PK;
@@ -56,7 +44,6 @@ const stripPKs = (record, keepPk = true) => {
56
44
  // @ts-ignore
57
45
  return rest;
58
46
  };
59
- exports.stripPKs = stripPKs;
60
47
  /**
61
48
  * generate dynamo PKs.
62
49
  * PK = all Ls joined with #
@@ -67,21 +54,33 @@ exports.stripPKs = stripPKs;
67
54
  * @param param0
68
55
  * @returns
69
56
  */
70
- const generateDynamoPKS = ({ type, L1, L2, L3, L4, L5, L6, additionalPKValues, }) => {
57
+ export const generateDynamoPKS = ({ type, L1, L2, L3, L4, L5, L6, additionalPKValues, }) => {
71
58
  const c = '#';
72
- const keys = [L1, L2, L3, L4, L5, L6].filter(array_1.notEmpty);
73
- const additionalPK = additionalPKValues && (additionalPKValues === null || additionalPKValues === void 0 ? void 0 : additionalPKValues.length) > 0
59
+ const keys = [L1, L2, L3, L4, L5, L6].filter(notEmpty);
60
+ const additionalPK = additionalPKValues && additionalPKValues?.length > 0
74
61
  ? `#${additionalPKValues.join(c)}`
75
62
  : '';
76
- return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({ PK: keys.join(c) + additionalPK, type,
77
- L1 }, (L2 && { L2 })), (L3 && { L3 })), (L4 && { L4 })), (L5 && { L5 })), (L6 && { L6 })), { PK1: L1 }), (keys.length >= 2 && {
78
- PK2: [keys[0], keys[1]].join(c),
79
- })), (keys.length >= 3 && {
80
- PK3: [keys[0], keys[1], keys[2]].join(c),
81
- })), (keys.length >= 4 && {
82
- PK4: [keys[0], keys[1], keys[2], keys[3]].join(c),
83
- })), (keys.length >= 5 && {
84
- PK5: [keys[0], keys[1], keys[2], keys[3], keys[4]].join(c),
85
- }));
63
+ return {
64
+ PK: keys.join(c) + additionalPK,
65
+ type,
66
+ L1,
67
+ ...(L2 && { L2 }),
68
+ ...(L3 && { L3 }),
69
+ ...(L4 && { L4 }),
70
+ ...(L5 && { L5 }),
71
+ ...(L6 && { L6 }),
72
+ PK1: L1,
73
+ ...(keys.length >= 2 && {
74
+ PK2: [keys[0], keys[1]].join(c),
75
+ }),
76
+ ...(keys.length >= 3 && {
77
+ PK3: [keys[0], keys[1], keys[2]].join(c),
78
+ }),
79
+ ...(keys.length >= 4 && {
80
+ PK4: [keys[0], keys[1], keys[2], keys[3]].join(c),
81
+ }),
82
+ ...(keys.length >= 5 && {
83
+ PK5: [keys[0], keys[1], keys[2], keys[3], keys[4]].join(c),
84
+ }),
85
+ };
86
86
  };
87
- exports.generateDynamoPKS = generateDynamoPKS;
@@ -1,14 +1,10 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.setAwsRegion = void 0;
4
- const dynamo_1 = require("./dynamo");
5
- const s3_1 = require("./s3");
6
- const ses_1 = require("./ses");
7
- const sqs_1 = require("./sqs");
8
- const setAwsRegion = (region) => {
9
- (0, dynamo_1.setDynamo)(region);
10
- (0, s3_1.setS3)(region);
11
- (0, ses_1.setSes)(region);
12
- (0, sqs_1.setSqs)(region);
1
+ import { setDynamo } from './dynamo';
2
+ import { setS3 } from './s3';
3
+ import { setSes } from './ses';
4
+ import { setSqs } from './sqs';
5
+ export const setAwsRegion = (region) => {
6
+ setDynamo(region);
7
+ setS3(region);
8
+ setSes(region);
9
+ setSqs(region);
13
10
  };
14
- exports.setAwsRegion = setAwsRegion;
@@ -1,25 +1,9 @@
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
- });
1
+ import CF from 'aws-sdk/clients/cloudfront';
2
+ let cf = new CF();
3
+ export const setCF = (region) => {
4
+ cf = new CF({ region });
10
5
  };
11
- var __importDefault = (this && this.__importDefault) || function (mod) {
12
- return (mod && mod.__esModule) ? mod : { "default": mod };
13
- };
14
- Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.invalidateCloudfrontPath = exports.setCF = void 0;
16
- const cloudfront_1 = __importDefault(require("aws-sdk/clients/cloudfront"));
17
- let cf = new cloudfront_1.default();
18
- const setCF = (region) => {
19
- cf = new cloudfront_1.default({ region });
20
- };
21
- exports.setCF = setCF;
22
- const invalidateCloudfrontPath = ({ path, distributionId, }) => __awaiter(void 0, void 0, void 0, function* () {
6
+ export const invalidateCloudfrontPath = async ({ path, distributionId, }) => {
23
7
  const params = {
24
8
  DistributionId: distributionId,
25
9
  InvalidationBatch: {
@@ -30,6 +14,5 @@ const invalidateCloudfrontPath = ({ path, distributionId, }) => __awaiter(void 0
30
14
  },
31
15
  },
32
16
  };
33
- yield cf.createInvalidation(params).promise();
34
- });
35
- exports.invalidateCloudfrontPath = invalidateCloudfrontPath;
17
+ await cf.createInvalidation(params).promise();
18
+ };
@@ -1,76 +1,42 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
26
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
27
- return new (P || (P = Promise))(function (resolve, reject) {
28
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
29
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
30
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
31
- step((generator = generator.apply(thisArg, _arguments || [])).next());
32
- });
33
- };
34
- Object.defineProperty(exports, "__esModule", { value: true });
35
- exports.getDynamoUpdates = exports.wipeTable = exports.getDynamoTtlMinutes = exports.getDynamoTtlDays = exports.queryDynamo = exports.getItemsDynamo = exports.getItemDynamo = exports.scan = exports.batchDelete = exports.batchWrite = exports.putDynamo = exports.setDynamo = exports.dynamoDb = void 0;
36
1
  /* eslint-disable guard-for-in */
37
2
  /* eslint-disable no-restricted-syntax */
38
3
  /* eslint-disable no-await-in-loop */
39
4
  /* eslint-disable prefer-const */
40
- const dynamodb_1 = __importStar(require("aws-sdk/clients/dynamodb"));
41
- const array_1 = require("../../common/helpers/array");
42
- const async_1 = require("../../common/helpers/async");
43
- const log_1 = require("../../common/helpers/log");
44
- const sleep_1 = require("../../common/helpers/sleep");
5
+ import DynamoDB, { Converter, DocumentClient, } from 'aws-sdk/clients/dynamodb';
6
+ import { chunk, notEmpty, take } from '../../common/helpers/array';
7
+ import { asyncForEach } from '../../common/helpers/async';
8
+ import { debug, error as errorF, info, warn } from '../../common/helpers/log';
9
+ import { sleep } from '../../common/helpers/sleep';
45
10
  // eslint-disable-next-line import/no-mutable-exports
46
- exports.dynamoDb = new dynamodb_1.DocumentClient();
47
- const setDynamo = (region) => {
48
- exports.dynamoDb = new dynamodb_1.DocumentClient({ region });
11
+ export let dynamoDb = new DocumentClient();
12
+ export const setDynamo = (region) => {
13
+ dynamoDb = new DocumentClient({ region });
49
14
  };
50
- exports.setDynamo = setDynamo;
51
- const putDynamo = (item, tableName, opt) => __awaiter(void 0, void 0, void 0, function* () {
52
- const params = Object.assign({ TableName: tableName,
15
+ export const putDynamo = async (item, tableName, opt) => {
16
+ const params = {
17
+ TableName: tableName,
53
18
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
54
- Item: item }, ((opt === null || opt === void 0 ? void 0 : opt.pkName) && {
55
- ConditionExpression: `attribute_not_exists(${opt.pkName})`,
56
- }));
57
- (0, log_1.info)(`running dynamo put=${JSON.stringify(params, null, 2)}`);
19
+ Item: item,
20
+ ...(opt?.pkName && {
21
+ ConditionExpression: `attribute_not_exists(${opt.pkName})`,
22
+ }),
23
+ };
24
+ info(`running dynamo put=${JSON.stringify(params, null, 2)}`);
58
25
  // write the todo to the database
59
- const put = yield exports.dynamoDb.put(params).promise();
26
+ const put = await dynamoDb.put(params).promise();
60
27
  if (put.$response.error && put.$response.error.statusCode) {
61
28
  return { error: put.$response.error.message };
62
29
  }
63
30
  // put never returns into, so just use what we have already
64
31
  return { data: item };
65
- });
66
- exports.putDynamo = putDynamo;
67
- let batchWriteRaw = (req) => __awaiter(void 0, void 0, void 0, function* () {
32
+ };
33
+ let batchWriteRaw = async (req) => {
68
34
  let count = 0;
69
35
  let max = 5;
70
36
  // eslint-disable-next-line no-constant-condition
71
37
  while (true)
72
38
  try {
73
- const res = yield exports.dynamoDb
39
+ const res = await dynamoDb
74
40
  .batchWrite({
75
41
  RequestItems: req,
76
42
  })
@@ -84,7 +50,7 @@ let batchWriteRaw = (req) => __awaiter(void 0, void 0, void 0, function* () {
84
50
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
85
51
  let es = e.toString();
86
52
  let msg = es;
87
- (0, log_1.warn)('dynamo write error', msg);
53
+ warn('dynamo write error', msg);
88
54
  if (es.indexOf('429') !== -1 ||
89
55
  es.indexOf('ProvisionedThroughputExceeded') !== -1) {
90
56
  count += 1;
@@ -96,18 +62,17 @@ let batchWriteRaw = (req) => __awaiter(void 0, void 0, void 0, function* () {
96
62
  if (count >= max) {
97
63
  throw e;
98
64
  }
99
- (0, log_1.warn)(`dynamo retry ${count}/${max}`);
100
- yield (0, sleep_1.sleep)(2000);
65
+ warn(`dynamo retry ${count}/${max}`);
66
+ await sleep(2000);
101
67
  }
102
- });
68
+ };
103
69
  // eslint-disable-next-line @typescript-eslint/ban-types
104
- const batchWrite = (tableName, itemsIn, breakOnError = false) => __awaiter(void 0, void 0, void 0, function* () {
105
- var _a, _b;
70
+ export const batchWrite = async (tableName, itemsIn, breakOnError = false) => {
106
71
  let items = JSON.parse(JSON.stringify(itemsIn));
107
- (0, log_1.debug)(`push to dynamo:${tableName} - count=${itemsIn.length}`);
72
+ debug(`push to dynamo:${tableName} - count=${itemsIn.length}`);
108
73
  const error = [];
109
74
  while (items.length > 0) {
110
- const { part, rest } = (0, array_1.take)(items, 25);
75
+ const { part, rest } = take(items, 25);
111
76
  // eslint-disable-next-line no-param-reassign
112
77
  items = rest;
113
78
  let req = {
@@ -115,8 +80,8 @@ const batchWrite = (tableName, itemsIn, breakOnError = false) => __awaiter(void
115
80
  PutRequest: { Item: item },
116
81
  })),
117
82
  };
118
- let res = yield batchWriteRaw(req);
119
- const newError = (_b = (_a = res.$response) === null || _a === void 0 ? void 0 : _a.error) !== null && _b !== void 0 ? _b : null;
83
+ let res = await batchWriteRaw(req);
84
+ const newError = res.$response?.error ?? null;
120
85
  if (newError) {
121
86
  error.push(newError);
122
87
  if (breakOnError) {
@@ -124,20 +89,18 @@ const batchWrite = (tableName, itemsIn, breakOnError = false) => __awaiter(void
124
89
  }
125
90
  }
126
91
  }
127
- if ((error === null || error === void 0 ? void 0 : error.length) > 0) {
92
+ if (error?.length > 0) {
128
93
  const me = error.join('\n');
129
- (0, log_1.error)(`batch write error=${me}`);
94
+ errorF(`batch write error=${me}`);
130
95
  return { error: me };
131
96
  }
132
97
  return {};
133
- });
134
- exports.batchWrite = batchWrite;
135
- const batchDelete = ({ tableName, breakOnError = true, pkName, keys, rangeName, rangeKeys, }) => __awaiter(void 0, void 0, void 0, function* () {
136
- (0, log_1.info)(`wipe keys dynamo:${tableName} - count=${keys.length}`);
98
+ };
99
+ export const batchDelete = async ({ tableName, breakOnError = true, pkName, keys, rangeName, rangeKeys, }) => {
100
+ info(`wipe keys dynamo:${tableName} - count=${keys.length}`);
137
101
  const error = [];
138
102
  let breakV = false;
139
- yield (0, async_1.asyncForEach)(keys, (key, i) => __awaiter(void 0, void 0, void 0, function* () {
140
- var _c, _d;
103
+ await asyncForEach(keys, async (key, i) => {
141
104
  if (breakV) {
142
105
  return;
143
106
  }
@@ -146,29 +109,28 @@ const batchDelete = ({ tableName, breakOnError = true, pkName, keys, rangeName,
146
109
  Key: { [pkName]: key },
147
110
  };
148
111
  if (rangeName) {
149
- let rangeValue = rangeKeys === null || rangeKeys === void 0 ? void 0 : rangeKeys[i];
112
+ let rangeValue = rangeKeys?.[i];
150
113
  if (rangeValue) {
151
114
  params.Key[rangeName] = rangeValue;
152
115
  }
153
116
  }
154
- const res = yield exports.dynamoDb.delete(params).promise();
155
- const newError = (_d = (_c = res.$response) === null || _c === void 0 ? void 0 : _c.error) !== null && _d !== void 0 ? _d : null;
117
+ const res = await dynamoDb.delete(params).promise();
118
+ const newError = res.$response?.error ?? null;
156
119
  if (newError) {
157
120
  error.push(newError);
158
121
  if (breakOnError) {
159
122
  breakV = true;
160
123
  }
161
124
  }
162
- }));
163
- if ((error === null || error === void 0 ? void 0 : error.length) > 0) {
125
+ });
126
+ if (error?.length > 0) {
164
127
  const me = error.join('\n');
165
- (0, log_1.error)(`batch write error=${me}`);
128
+ errorF(`batch write error=${me}`);
166
129
  return { error: me };
167
130
  }
168
131
  return {};
169
- });
170
- exports.batchDelete = batchDelete;
171
- const scan = (tableName, opt) => __awaiter(void 0, void 0, void 0, function* () {
132
+ };
133
+ export const scan = async (tableName, opt) => {
172
134
  const Items = [];
173
135
  let ExclusiveStartKey;
174
136
  do {
@@ -176,17 +138,17 @@ const scan = (tableName, opt) => __awaiter(void 0, void 0, void 0, function* ()
176
138
  TableName: tableName,
177
139
  ExclusiveStartKey,
178
140
  };
179
- if (opt === null || opt === void 0 ? void 0 : opt.filter) {
141
+ if (opt?.filter) {
180
142
  params.FilterExpression = opt.filter.filterExpression;
181
143
  params.ExpressionAttributeNames = opt.filter.attrNames;
182
144
  params.ExpressionAttributeValues = opt.filter.attrValues;
183
145
  }
184
- if (opt === null || opt === void 0 ? void 0 : opt.requiredAttributeList) {
146
+ if (opt?.requiredAttributeList) {
185
147
  params.ProjectionExpression = opt.requiredAttributeList.join(', ');
186
148
  }
187
149
  const { Items: newitems, LastEvaluatedKey, $response,
188
150
  // eslint-disable-next-line no-await-in-loop
189
- } = yield exports.dynamoDb.scan(params).promise();
151
+ } = await dynamoDb.scan(params).promise();
190
152
  ExclusiveStartKey = LastEvaluatedKey;
191
153
  if ($response.error && $response.error.statusCode) {
192
154
  throw new Error($response.error.message);
@@ -195,29 +157,26 @@ const scan = (tableName, opt) => __awaiter(void 0, void 0, void 0, function* ()
195
157
  Items.push(...newitems.map((r) => r));
196
158
  }
197
159
  } while (ExclusiveStartKey);
198
- (0, log_1.info)(`dynamo scan against ${tableName} ok, count=${Items === null || Items === void 0 ? void 0 : Items.length}`);
160
+ info(`dynamo scan against ${tableName} ok, count=${Items?.length}`);
199
161
  return Items;
200
- });
201
- exports.scan = scan;
202
- const getItemDynamo = ({ tableName, pkName, pkValue, }) => __awaiter(void 0, void 0, void 0, function* () {
162
+ };
163
+ export const getItemDynamo = async ({ tableName, pkName, pkValue, }) => {
203
164
  const params = {
204
165
  Key: { [pkName]: pkValue },
205
166
  TableName: tableName,
206
167
  };
207
168
  try {
208
- const res = yield exports.dynamoDb.get(params).promise();
169
+ const res = await dynamoDb.get(params).promise();
209
170
  const ret = res.Item;
210
- (0, log_1.debug)(`got dynamo getitem=${JSON.stringify(params, null, 2)}`);
171
+ debug(`got dynamo getitem=${JSON.stringify(params, null, 2)}`);
211
172
  return ret;
212
173
  }
213
174
  catch (e) {
214
- (0, log_1.error)(e);
175
+ errorF(e);
215
176
  throw e;
216
177
  }
217
- });
218
- exports.getItemDynamo = getItemDynamo;
219
- const getItemsDynamo = ({ tableName, items, }) => __awaiter(void 0, void 0, void 0, function* () {
220
- var _e, _f;
178
+ };
179
+ export const getItemsDynamo = async ({ tableName, items, }) => {
221
180
  const params = {
222
181
  RequestItems: {
223
182
  [tableName]: {
@@ -227,11 +186,11 @@ const getItemsDynamo = ({ tableName, items, }) => __awaiter(void 0, void 0, void
227
186
  },
228
187
  },
229
188
  };
230
- const dbRaw = new dynamodb_1.default({ apiVersion: '2012-10-08' });
189
+ const dbRaw = new DynamoDB({ apiVersion: '2012-10-08' });
231
190
  try {
232
- const res = yield dbRaw.batchGetItem(params).promise();
233
- (0, log_1.debug)(`got dynamo getitems=${JSON.stringify(res, null, 2)}`);
234
- let ret = ((_f = (_e = res.Responses) === null || _e === void 0 ? void 0 : _e[tableName]) === null || _f === void 0 ? void 0 : _f.map((s) => dynamodb_1.Converter.unmarshall(s))) ||
191
+ const res = await dbRaw.batchGetItem(params).promise();
192
+ debug(`got dynamo getitems=${JSON.stringify(res, null, 2)}`);
193
+ let ret = res.Responses?.[tableName]?.map((s) => Converter.unmarshall(s)) ||
235
194
  [];
236
195
  return ret;
237
196
  }
@@ -241,13 +200,11 @@ const getItemsDynamo = ({ tableName, items, }) => __awaiter(void 0, void 0, void
241
200
  '\n' +
242
201
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
243
202
  e.toString();
244
- (0, log_1.error)(msg);
203
+ errorF(msg);
245
204
  throw e;
246
205
  }
247
- });
248
- exports.getItemsDynamo = getItemsDynamo;
249
- const queryDynamo = ({ tableName, pkName, pkValue, pkOperator = '=', skName, skValue, skOperator = '=', indexName, count = 1000, startKey: startKeyIn, filterName, filterValue, filterOperator = '=', sortAscending = true, }) => __awaiter(void 0, void 0, void 0, function* () {
250
- var _g;
206
+ };
207
+ export const queryDynamo = async ({ tableName, pkName, pkValue, pkOperator = '=', skName, skValue, skOperator = '=', indexName, count = 1000, startKey: startKeyIn, filterName, filterValue, filterOperator = '=', sortAscending = true, }) => {
251
208
  let startKey = startKeyIn;
252
209
  let kce = `#${pkName.toLowerCase()} ${pkOperator} :${pkName.toLowerCase()}`;
253
210
  const ean = { [`#${pkName.toLowerCase()}`]: pkName };
@@ -320,36 +277,32 @@ const queryDynamo = ({ tableName, pkName, pkValue, pkOperator = '=', skName, skV
320
277
  LastEvaluatedKey: lek,
321
278
  $response,
322
279
  // eslint-disable-next-line no-await-in-loop
323
- } = yield exports.dynamoDb.query(params).promise());
280
+ } = await dynamoDb.query(params).promise());
324
281
  }
325
282
  catch (e) {
326
- (0, log_1.error)('error. query params=', JSON.stringify(params), e);
283
+ errorF('error. query params=', JSON.stringify(params), e);
327
284
  throw e;
328
285
  }
329
286
  startKey = lek;
330
287
  if ($response.error) {
331
- (0, log_1.error)('error. query params=', JSON.stringify(params));
288
+ errorF('error. query params=', JSON.stringify(params));
332
289
  throw new Error($response.error.message);
333
290
  }
334
- (0, log_1.debug)(`dynamo query against ${params === null || params === void 0 ? void 0 : params.TableName} ok, count=${newitems === null || newitems === void 0 ? void 0 : newitems.length} ${JSON.stringify(params)}`, ` next startkey=${startKey}`);
291
+ debug(`dynamo query against ${params?.TableName} ok, count=${newitems?.length} ${JSON.stringify(params)}`, ` next startkey=${startKey}`);
335
292
  if (newitems) {
336
293
  Items.push(...newitems.map((r) => r));
337
294
  }
338
- if (count > 0 && ((_g = newitems === null || newitems === void 0 ? void 0 : newitems.length) !== null && _g !== void 0 ? _g : 0) >= count) {
295
+ if (count > 0 && (newitems?.length ?? 0) >= count) {
339
296
  return { Items, startKey };
340
297
  }
341
298
  } while (startKey && Object.keys(startKey).length > 0);
342
299
  return { Items, startKey: undefined };
343
- });
344
- exports.queryDynamo = queryDynamo;
345
- const getDynamoTtlDays = (days) => Math.ceil(new Date().getTime() / 1000) + days * 86400;
346
- exports.getDynamoTtlDays = getDynamoTtlDays;
347
- const getDynamoTtlMinutes = (mins) => Math.ceil(new Date().getTime() / 1000) + mins * 60;
348
- exports.getDynamoTtlMinutes = getDynamoTtlMinutes;
349
- const wipeTable = (tableName) => __awaiter(void 0, void 0, void 0, function* () {
350
- var _h;
351
- const dbRaw = new dynamodb_1.default({ apiVersion: '2012-10-08' });
352
- let infoV = yield dbRaw
300
+ };
301
+ export const getDynamoTtlDays = (days) => Math.ceil(new Date().getTime() / 1000) + days * 86400;
302
+ export const getDynamoTtlMinutes = (mins) => Math.ceil(new Date().getTime() / 1000) + mins * 60;
303
+ export const wipeTable = async (tableName) => {
304
+ const dbRaw = new DynamoDB({ apiVersion: '2012-10-08' });
305
+ let infoV = await dbRaw
353
306
  .describeTable({
354
307
  TableName: tableName,
355
308
  })
@@ -364,15 +317,15 @@ const wipeTable = (tableName) => __awaiter(void 0, void 0, void 0, function* ()
364
317
  let all = [];
365
318
  let working;
366
319
  do {
367
- working = yield dbRaw.scan(params).promise();
368
- (_h = working.Items) === null || _h === void 0 ? void 0 : _h.forEach((item) => all.push(item));
320
+ working = await dbRaw.scan(params).promise();
321
+ working.Items?.forEach((item) => all.push(item));
369
322
  params.ExclusiveStartKey = working.LastEvaluatedKey;
370
323
  } while (typeof working.LastEvaluatedKey !== 'undefined');
371
- (0, log_1.warn)(`will delete ${all === null || all === void 0 ? void 0 : all.length} items from ${tableName}`);
324
+ warn(`will delete ${all?.length} items from ${tableName}`);
372
325
  // eslint-disable-next-line @typescript-eslint/ban-ts-comment
373
326
  // @ts-ignore
374
- const datagr = (0, array_1.chunk)(all, 25);
375
- let res = yield Promise.all(datagr.map((group) => dbRaw
327
+ const datagr = chunk(all, 25);
328
+ let res = await Promise.all(datagr.map((group) => dbRaw
376
329
  .batchWriteItem({
377
330
  RequestItems: {
378
331
  [`${tableName}`]: group.map((s) => ({
@@ -386,17 +339,16 @@ const wipeTable = (tableName) => __awaiter(void 0, void 0, void 0, function* ()
386
339
  })
387
340
  .promise()));
388
341
  let errors = res
389
- .map((r) => { var _a, _b; return ((_b = (((_a = r === null || r === void 0 ? void 0 : r.$response) === null || _a === void 0 ? void 0 : _a.error) || {})) === null || _b === void 0 ? void 0 : _b.message) || undefined; })
390
- .filter(array_1.notEmpty);
342
+ .map((r) => (r?.$response?.error || {})?.message || undefined)
343
+ .filter(notEmpty);
391
344
  if (errors.length > 0) {
392
- (0, log_1.error)('errors=', JSON.stringify(errors));
345
+ errorF('errors=', JSON.stringify(errors));
393
346
  return { errors };
394
347
  }
395
- (0, log_1.warn)(`cleared table ${tableName}`);
348
+ warn(`cleared table ${tableName}`);
396
349
  return {};
397
- });
398
- exports.wipeTable = wipeTable;
399
- const getDynamoUpdates = (items) => {
350
+ };
351
+ export const getDynamoUpdates = (items) => {
400
352
  const cleanedKeys = Object.keys(items).filter((r) => r !== 'PK');
401
353
  let UpdateExpression = '';
402
354
  const ExpressionAttributeNames = {};
@@ -410,7 +362,7 @@ const getDynamoUpdates = (items) => {
410
362
  ExpressionAttributeValues[`:${key}`] = v;
411
363
  }
412
364
  else {
413
- (0, log_1.warn)(`no value for key:${key}`);
365
+ warn(`no value for key:${key}`);
414
366
  }
415
367
  });
416
368
  return {
@@ -419,4 +371,3 @@ const getDynamoUpdates = (items) => {
419
371
  ExpressionAttributeValues,
420
372
  };
421
373
  };
422
- exports.getDynamoUpdates = getDynamoUpdates;
@@ -1,18 +1,15 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.generateSSMParams = exports.generateTableRef = void 0;
4
- const aws_cdk_lib_1 = require("aws-cdk-lib");
5
- const ssm_1 = require("./ssm");
6
- const generateTableRef = ({ stack, baseKey, hasStream, hasGSI, }) => {
1
+ import { aws_dynamodb as dynamodb, aws_ssm as ssm } from 'aws-cdk-lib';
2
+ import { loadSsmString, loadSsmStringList, saveToSsm } from './ssm';
3
+ export const generateTableRef = ({ stack, baseKey, hasStream, hasGSI, }) => {
7
4
  const tableStreamArn = !hasStream
8
5
  ? undefined
9
- : (0, ssm_1.loadSsmString)({ stack, path: `${baseKey}/streamArn` });
6
+ : loadSsmString({ stack, path: `${baseKey}/streamArn` });
10
7
  const globalIndexes = !hasGSI
11
8
  ? undefined
12
- : (0, ssm_1.loadSsmStringList)({ stack, path: `${baseKey}/gsi` });
13
- const shortName = aws_cdk_lib_1.aws_ssm.StringParameter.valueFromLookup(stack, `${baseKey}/shortName`);
14
- const table = aws_cdk_lib_1.aws_dynamodb.Table.fromTableAttributes(stack, baseKey, {
15
- tableArn: (0, ssm_1.loadSsmString)({ stack, path: `${baseKey}/arn` }),
9
+ : loadSsmStringList({ stack, path: `${baseKey}/gsi` });
10
+ const shortName = ssm.StringParameter.valueFromLookup(stack, `${baseKey}/shortName`);
11
+ const table = dynamodb.Table.fromTableAttributes(stack, baseKey, {
12
+ tableArn: loadSsmString({ stack, path: `${baseKey}/arn` }),
16
13
  tableStreamArn,
17
14
  globalIndexes,
18
15
  });
@@ -21,27 +18,25 @@ const generateTableRef = ({ stack, baseKey, hasStream, hasGSI, }) => {
21
18
  table,
22
19
  };
23
20
  };
24
- exports.generateTableRef = generateTableRef;
25
- const generateSSMParams = ({ stack, table, baseKey, gsi, shortName, }) => {
26
- (0, ssm_1.saveToSsm)({ stack, path: `${baseKey}/arn`, value: table.tableArn });
21
+ export const generateSSMParams = ({ stack, table, baseKey, gsi, shortName, }) => {
22
+ saveToSsm({ stack, path: `${baseKey}/arn`, value: table.tableArn });
27
23
  if (table.tableStreamArn) {
28
- (0, ssm_1.saveToSsm)({
24
+ saveToSsm({
29
25
  stack,
30
26
  path: `${baseKey}/streamArn`,
31
27
  value: table.tableStreamArn,
32
28
  });
33
29
  }
34
- if (gsi && (gsi === null || gsi === void 0 ? void 0 : gsi.length) > 0) {
35
- (0, ssm_1.saveToSsm)({
30
+ if (gsi && gsi?.length > 0) {
31
+ saveToSsm({
36
32
  stack,
37
33
  path: `${baseKey}/gsi`,
38
34
  value: gsi.join(','),
39
35
  });
40
36
  }
41
- (0, ssm_1.saveToSsm)({
37
+ saveToSsm({
42
38
  stack,
43
39
  path: `${baseKey}/shortName`,
44
40
  value: shortName,
45
41
  });
46
42
  };
47
- exports.generateSSMParams = generateSSMParams;