ag-common 0.0.419 → 0.0.421

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 (178) hide show
  1. package/dist/api/helpers/api.js +35 -34
  2. package/dist/api/helpers/aws.js +13 -9
  3. package/dist/api/helpers/cloudfront.js +24 -7
  4. package/dist/api/helpers/dynamo.js +134 -85
  5. package/dist/api/helpers/dynamoInfra.js +19 -14
  6. package/dist/api/helpers/enforceDynamoProvisionCap.js +18 -14
  7. package/dist/api/helpers/index.js +30 -14
  8. package/dist/api/helpers/openApiHelpers.js +37 -34
  9. package/dist/api/helpers/s3.js +126 -81
  10. package/dist/api/helpers/ses.js +28 -9
  11. package/dist/api/helpers/sqs.js +26 -9
  12. package/dist/api/helpers/ssm.js +14 -8
  13. package/dist/api/helpers/sts.js +34 -16
  14. package/dist/api/helpers/validateOpenApi.js +103 -92
  15. package/dist/api/helpers/validations.js +46 -29
  16. package/dist/api/index.js +18 -2
  17. package/dist/api/openapi-prefix.js +38 -25
  18. package/dist/api/types/aws.js +2 -1
  19. package/dist/api/types/index.js +17 -1
  20. package/dist/common/const.js +5 -2
  21. package/dist/common/helpers/array.js +19 -8
  22. package/dist/common/helpers/async.js +28 -10
  23. package/dist/common/helpers/binary.js +10 -5
  24. package/dist/common/helpers/date.js +25 -14
  25. package/dist/common/helpers/email.js +11 -5
  26. package/dist/common/helpers/func.js +7 -3
  27. package/dist/common/helpers/generator.js +24 -9
  28. package/dist/common/helpers/groupBy.js +9 -3
  29. package/dist/common/helpers/hashCode.js +9 -3
  30. package/dist/common/helpers/i18n.js +17 -9
  31. package/dist/common/helpers/index.js +34 -18
  32. package/dist/common/helpers/log.js +28 -16
  33. package/dist/common/helpers/math.js +21 -9
  34. package/dist/common/helpers/memo.js +7 -3
  35. package/dist/common/helpers/object.js +35 -20
  36. package/dist/common/helpers/random.js +10 -4
  37. package/dist/common/helpers/secondsInNearest.js +7 -2
  38. package/dist/common/helpers/sleep.js +5 -1
  39. package/dist/common/helpers/string/base64.js +7 -2
  40. package/dist/common/helpers/string/chunk.js +5 -1
  41. package/dist/common/helpers/string/contains.js +7 -2
  42. package/dist/common/helpers/string/getExtendedStringSegment.js +9 -5
  43. package/dist/common/helpers/string/index.js +26 -10
  44. package/dist/common/helpers/string/json.js +5 -1
  45. package/dist/common/helpers/string/object.js +5 -1
  46. package/dist/common/helpers/string/surround.js +5 -1
  47. package/dist/common/helpers/string/trim.js +7 -2
  48. package/dist/common/helpers/string/truncate.js +5 -1
  49. package/dist/common/helpers/string/url.js +9 -4
  50. package/dist/common/index.js +18 -2
  51. package/dist/index.js +19 -3
  52. package/dist/ui/components/BorderGradient/index.js +25 -18
  53. package/dist/ui/components/Button/index.js +25 -17
  54. package/dist/ui/components/Chevron/index.js +16 -9
  55. package/dist/ui/components/Close/index.js +13 -6
  56. package/dist/ui/components/Confirm/Dialog.js +25 -9
  57. package/dist/ui/components/Confirm/Modal.js +27 -20
  58. package/dist/ui/components/Confirm/index.js +19 -3
  59. package/dist/ui/components/Confirm/types.js +2 -1
  60. package/dist/ui/components/DropdownList/Base.js +64 -33
  61. package/dist/ui/components/DropdownList/Dialog.js +24 -8
  62. package/dist/ui/components/DropdownList/index.js +18 -2
  63. package/dist/ui/components/DropdownList/types.js +2 -1
  64. package/dist/ui/components/FlexColumn/index.js +14 -4
  65. package/dist/ui/components/FlexRow/index.js +14 -4
  66. package/dist/ui/components/HeadersRaw/index.js +27 -20
  67. package/dist/ui/components/HorizontalScrollBar/index.js +34 -6
  68. package/dist/ui/components/Icon/index.js +16 -9
  69. package/dist/ui/components/Image/index.js +28 -10
  70. package/dist/ui/components/InfiniteScroll/index.js +50 -18
  71. package/dist/ui/components/KebabDots/index.js +13 -6
  72. package/dist/ui/components/Loader/index.js +39 -9
  73. package/dist/ui/components/Modal/Dialog.js +23 -7
  74. package/dist/ui/components/Modal/Modal.js +49 -19
  75. package/dist/ui/components/Modal/index.js +19 -3
  76. package/dist/ui/components/Modal/types.js +2 -1
  77. package/dist/ui/components/OpenApiCodeBlock/OpenApiCodeBlock.js +34 -26
  78. package/dist/ui/components/OpenApiCodeBlock/curl/helpers/body.js +19 -12
  79. package/dist/ui/components/OpenApiCodeBlock/curl/helpers/getCurlLines.js +11 -6
  80. package/dist/ui/components/OpenApiCodeBlock/curl/helpers/security.js +15 -8
  81. package/dist/ui/components/OpenApiCodeBlock/curl/index.js +21 -14
  82. package/dist/ui/components/OpenApiCodeBlock/fetch/helpers/call.js +15 -8
  83. package/dist/ui/components/OpenApiCodeBlock/fetch/helpers/getFetchLines.js +8 -3
  84. package/dist/ui/components/OpenApiCodeBlock/fetch/helpers/req.js +34 -27
  85. package/dist/ui/components/OpenApiCodeBlock/fetch/index.js +18 -11
  86. package/dist/ui/components/OpenApiCodeBlock/helpers/common.js +17 -7
  87. package/dist/ui/components/OpenApiCodeBlock/helpers/joinJsx.js +15 -6
  88. package/dist/ui/components/OpenApiCodeBlock/index.js +18 -2
  89. package/dist/ui/components/OpenApiCodeBlock/types.js +2 -1
  90. package/dist/ui/components/PieChart/index.js +18 -11
  91. package/dist/ui/components/ProgressBar/index.js +45 -15
  92. package/dist/ui/components/Prompt/Dialog.js +23 -7
  93. package/dist/ui/components/Prompt/Modal.js +55 -25
  94. package/dist/ui/components/Prompt/index.js +18 -2
  95. package/dist/ui/components/RowOrColumn/index.js +17 -7
  96. package/dist/ui/components/Search/AutoHideSearchBox.js +56 -24
  97. package/dist/ui/components/Search/Base.js +52 -21
  98. package/dist/ui/components/Search/Dialog.js +26 -10
  99. package/dist/ui/components/Search/Inline.js +10 -3
  100. package/dist/ui/components/Search/Modal.js +17 -10
  101. package/dist/ui/components/Search/SearchBox.js +58 -26
  102. package/dist/ui/components/Search/index.js +23 -7
  103. package/dist/ui/components/Search/types.js +2 -1
  104. package/dist/ui/components/Sidebar/index.js +25 -18
  105. package/dist/ui/components/SparkLine/index.js +27 -17
  106. package/dist/ui/components/Table/index.js +22 -15
  107. package/dist/ui/components/TextEdit/CheckboxEdit.js +51 -21
  108. package/dist/ui/components/TextEdit/ColourEdit.js +44 -17
  109. package/dist/ui/components/TextEdit/LengthBox.js +12 -5
  110. package/dist/ui/components/TextEdit/ListboxEdit.js +42 -15
  111. package/dist/ui/components/TextEdit/RadioGroup.js +43 -13
  112. package/dist/ui/components/TextEdit/TextEdit.js +78 -48
  113. package/dist/ui/components/TextEdit/common.js +17 -11
  114. package/dist/ui/components/TextEdit/index.js +22 -6
  115. package/dist/ui/components/TextEdit/types.js +2 -1
  116. package/dist/ui/components/TextWithButton/index.js +40 -10
  117. package/dist/ui/components/TimelineChart/index.js +24 -14
  118. package/dist/ui/components/Toast/Cross.js +16 -9
  119. package/dist/ui/components/Toast/Tick.js +11 -4
  120. package/dist/ui/components/Toast/Warning.js +15 -8
  121. package/dist/ui/components/Toast/base.js +65 -33
  122. package/dist/ui/components/Toast/index.js +18 -2
  123. package/dist/ui/components/Toast/types.js +2 -1
  124. package/dist/ui/components/UserImage/index.js +48 -17
  125. package/dist/ui/components/index.js +46 -30
  126. package/dist/ui/helpers/axiosHelper.js +39 -25
  127. package/dist/ui/helpers/browserHelpers.js +22 -7
  128. package/dist/ui/helpers/callOpenApi/cached.js +37 -18
  129. package/dist/ui/helpers/callOpenApi/direct.js +59 -46
  130. package/dist/ui/helpers/callOpenApi/helpers.js +40 -25
  131. package/dist/ui/helpers/callOpenApi/hook.js +36 -47
  132. package/dist/ui/helpers/callOpenApi/index.js +21 -5
  133. package/dist/ui/helpers/callOpenApi/types.js +2 -1
  134. package/dist/ui/helpers/cognito.js +2 -1
  135. package/dist/ui/helpers/cookie/const.js +5 -2
  136. package/dist/ui/helpers/cookie/get.js +14 -13
  137. package/dist/ui/helpers/cookie/index.js +21 -5
  138. package/dist/ui/helpers/cookie/raw.js +16 -9
  139. package/dist/ui/helpers/cookie/set.js +15 -10
  140. package/dist/ui/helpers/cookie/use.js +16 -23
  141. package/dist/ui/helpers/date.js +15 -10
  142. package/dist/ui/helpers/debounce.js +10 -5
  143. package/dist/ui/helpers/dom.js +13 -6
  144. package/dist/ui/helpers/extractAttributes.js +7 -2
  145. package/dist/ui/helpers/index.js +41 -25
  146. package/dist/ui/helpers/jwt.js +2 -1
  147. package/dist/ui/helpers/plural.js +5 -1
  148. package/dist/ui/helpers/routes.js +24 -17
  149. package/dist/ui/helpers/serviceWorker.js +23 -8
  150. package/dist/ui/helpers/useContextMenu.js +14 -9
  151. package/dist/ui/helpers/useElementAttribute.js +7 -3
  152. package/dist/ui/helpers/useGranularHook.js +10 -5
  153. package/dist/ui/helpers/useInterval.js +12 -8
  154. package/dist/ui/helpers/useLocalStorage.js +32 -24
  155. package/dist/ui/helpers/useLockBodyScroll.js +7 -3
  156. package/dist/ui/helpers/useOnClickOutside.js +12 -7
  157. package/dist/ui/helpers/useOnScroll.js +21 -15
  158. package/dist/ui/helpers/useOverloadPageSearch.js +7 -3
  159. package/dist/ui/helpers/useQueryString.js +20 -14
  160. package/dist/ui/helpers/useResize.js +19 -17
  161. package/dist/ui/helpers/useTimeout.js +9 -5
  162. package/dist/ui/icons/ChevronRight.js +9 -3
  163. package/dist/ui/icons/CrossIcon.js +12 -5
  164. package/dist/ui/icons/Door.js +10 -4
  165. package/dist/ui/icons/HorizontalDots.js +9 -3
  166. package/dist/ui/icons/Magnify.js +10 -3
  167. package/dist/ui/icons/Pencil.js +12 -5
  168. package/dist/ui/icons/Save.js +11 -4
  169. package/dist/ui/icons/Undo.js +12 -5
  170. package/dist/ui/icons/UserOutline.js +9 -3
  171. package/dist/ui/icons/index.js +25 -9
  172. package/dist/ui/index.js +20 -4
  173. package/dist/ui/styles/colours.js +12 -7
  174. package/dist/ui/styles/common.js +22 -14
  175. package/dist/ui/styles/index.js +20 -4
  176. package/dist/ui/styles/media.js +10 -7
  177. package/dist/ui/styles/standaloneStyles.js +16 -10
  178. package/package.json +2 -2
@@ -1,25 +1,28 @@
1
- import { warn } from '../../common/helpers/log';
2
- import { sumArray } from '../../common/helpers/math';
3
- import { safeStringify } from '../../common/helpers/string/json';
4
- import { trim } from '../../common/helpers/string/trim';
5
- const extractSum = ({ str, regex }) => sumArray(str
6
- .match(regex)
7
- ?.map((s2) => trim(s2.substring(s2.indexOf(':') + 1), ':', ',', ' '))
8
- .filter((r) => r && Number(r))
9
- .map((r) => Number(r)) || []);
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.enforceDynamoProvisionCap = void 0;
4
+ const log_1 = require("../../common/helpers/log");
5
+ const math_1 = require("../../common/helpers/math");
6
+ const json_1 = require("../../common/helpers/string/json");
7
+ const trim_1 = require("../../common/helpers/string/trim");
8
+ const extractSum = ({ str, regex }) => {
9
+ var _a;
10
+ return (0, math_1.sumArray)(((_a = str
11
+ .match(regex)) === null || _a === void 0 ? void 0 : _a.map((s2) => (0, trim_1.trim)(s2.substring(s2.indexOf(':') + 1), ':', ',', ' ')).filter((r) => r && Number(r)).map((r) => Number(r))) || []);
12
+ };
10
13
  /** ensure that dynamo tables in stack dont exceed passed in provisioned limits */
11
- export const enforceDynamoProvisionCap = ({ tables, readsMax = 25, writesMax = 25, mustEqual = false, }) => {
14
+ const enforceDynamoProvisionCap = ({ tables, readsMax = 25, writesMax = 25, mustEqual = false, }) => {
12
15
  if (!tables || tables.length === 0) {
13
- warn('error in dynamo FT enforce');
16
+ (0, log_1.warn)('error in dynamo FT enforce');
14
17
  return;
15
18
  }
16
19
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
17
20
  const t = tables[0];
18
- const s = safeStringify(t.node._children.Resource.node.scope);
21
+ const s = (0, json_1.safeStringify)(t.node._children.Resource.node.scope);
19
22
  const reads = extractSum({ str: s, regex: /readCapacityUnits.*/gim });
20
23
  const writes = extractSum({ str: s, regex: /writeCapacityUnits.*/gim });
21
- warn(`dynamo table provisioned reads:${reads}/${readsMax}`);
22
- warn(`dynamo table provisioned writes:${writes}/${writesMax}`);
24
+ (0, log_1.warn)(`dynamo table provisioned reads:${reads}/${readsMax}`);
25
+ (0, log_1.warn)(`dynamo table provisioned writes:${writes}/${writesMax}`);
23
26
  if (reads > readsMax || writes > writesMax) {
24
27
  throw new Error('exceeded dynamo provision cap');
25
28
  }
@@ -27,3 +30,4 @@ export const enforceDynamoProvisionCap = ({ tables, readsMax = 25, writesMax = 2
27
30
  throw new Error(`dynamo provision cap not met`);
28
31
  }
29
32
  };
33
+ exports.enforceDynamoProvisionCap = enforceDynamoProvisionCap;
@@ -1,14 +1,30 @@
1
- export * from './api';
2
- export * from './aws';
3
- export * from './cloudfront';
4
- export * from './dynamo';
5
- export * from './dynamoInfra';
6
- export * from './enforceDynamoProvisionCap';
7
- export * from './openApiHelpers';
8
- export * from './s3';
9
- export * from './ses';
10
- export * from './sqs';
11
- export * from './ssm';
12
- export * from './sts';
13
- export * from './validateOpenApi';
14
- export * from './validations';
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./api"), exports);
18
+ __exportStar(require("./aws"), exports);
19
+ __exportStar(require("./cloudfront"), exports);
20
+ __exportStar(require("./dynamo"), exports);
21
+ __exportStar(require("./dynamoInfra"), exports);
22
+ __exportStar(require("./enforceDynamoProvisionCap"), exports);
23
+ __exportStar(require("./openApiHelpers"), exports);
24
+ __exportStar(require("./s3"), exports);
25
+ __exportStar(require("./ses"), exports);
26
+ __exportStar(require("./sqs"), exports);
27
+ __exportStar(require("./ssm"), exports);
28
+ __exportStar(require("./sts"), exports);
29
+ __exportStar(require("./validateOpenApi"), exports);
30
+ __exportStar(require("./validations"), exports);
@@ -1,7 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.openApiImpl = void 0;
1
4
  /* eslint-disable no-new */
2
- import { aws_apigateway as apigw, aws_lambda as lambda, aws_lambda_nodejs as nodejs, aws_logs as logs, aws_route53 as route53, aws_route53_targets as targets, Duration, } from 'aws-cdk-lib';
3
- import { distinctBy, notEmpty } from '../../common/helpers/array';
4
- import { warn } from '../../common/helpers/log';
5
+ const aws_cdk_lib_1 = require("aws-cdk-lib");
6
+ const array_1 = require("../../common/helpers/array");
7
+ const log_1 = require("../../common/helpers/log");
5
8
  // eslint-disable-next-line
6
9
  const getPaths = (schema) => Object.entries(schema.paths).map(([fullPath, verbs]) => ({
7
10
  fullPath,
@@ -9,64 +12,63 @@ const getPaths = (schema) => Object.entries(schema.paths).map(([fullPath, verbs]
9
12
  verbs: Object.keys(verbs),
10
13
  }));
11
14
  const setUpApiGw = ({ stack, NODE_ENV, certificate, shortStackName, r53, cors = {
12
- allowOrigins: apigw.Cors.ALL_ORIGINS,
13
- allowHeaders: apigw.Cors.DEFAULT_HEADERS,
15
+ allowOrigins: aws_cdk_lib_1.aws_apigateway.Cors.ALL_ORIGINS,
16
+ allowHeaders: aws_cdk_lib_1.aws_apigateway.Cors.DEFAULT_HEADERS,
14
17
  }, }) => {
15
- const api = new apigw.RestApi(stack, `${shortStackName}-api-${NODE_ENV}`, {
16
- defaultCorsPreflightOptions: {
17
- ...(cors || {}),
18
- },
18
+ const api = new aws_cdk_lib_1.aws_apigateway.RestApi(stack, `${shortStackName}-api-${NODE_ENV}`, {
19
+ defaultCorsPreflightOptions: Object.assign({}, (cors || {})),
19
20
  });
20
21
  if (r53) {
21
- const dn = new apigw.DomainName(stack, 'domain', {
22
+ const dn = new aws_cdk_lib_1.aws_apigateway.DomainName(stack, 'domain', {
22
23
  domainName: r53.apiUrl,
23
24
  certificate,
24
- endpointType: apigw.EndpointType.EDGE,
25
- securityPolicy: apigw.SecurityPolicy.TLS_1_2,
25
+ endpointType: aws_cdk_lib_1.aws_apigateway.EndpointType.EDGE,
26
+ securityPolicy: aws_cdk_lib_1.aws_apigateway.SecurityPolicy.TLS_1_2,
26
27
  mapping: api,
27
28
  });
28
29
  if (r53.hostedZone) {
29
- new route53.ARecord(stack, 'ARecord', {
30
+ new aws_cdk_lib_1.aws_route53.ARecord(stack, 'ARecord', {
30
31
  comment: '(cdk)',
31
32
  recordName: r53.apiUrl.substring(0, r53.apiUrl.indexOf('.')),
32
33
  zone: r53.hostedZone,
33
- target: route53.RecordTarget.fromAlias(new targets.ApiGatewayDomain(dn)),
34
+ target: aws_cdk_lib_1.aws_route53.RecordTarget.fromAlias(new aws_cdk_lib_1.aws_route53_targets.ApiGatewayDomain(dn)),
34
35
  });
35
36
  }
36
37
  }
37
38
  return api;
38
39
  };
39
40
  const setupLambda = ({ lambdaConfig, pathV, verb, seenPermissions, authorizers, }) => {
41
+ var _a, _b, _c, _d;
40
42
  const pathCompute = pathV + '/' + verb;
41
- const lp = lambdaConfig?.[pathCompute];
43
+ const lp = lambdaConfig === null || lambdaConfig === void 0 ? void 0 : lambdaConfig[pathCompute];
42
44
  if (lp) {
43
45
  seenPermissions[pathCompute] = true;
44
46
  }
45
47
  else {
46
48
  seenPermissions[pathCompute] = false;
47
49
  }
48
- const def = lambdaConfig?.default;
50
+ const def = lambdaConfig === null || lambdaConfig === void 0 ? void 0 : lambdaConfig.default;
49
51
  if (def) {
50
52
  seenPermissions.default = true;
51
53
  }
52
54
  //
53
- const readTables = distinctBy([...(def?.dynamo?.reads || []), ...(lp?.dynamo?.reads || [])], (s) => s.shortName);
54
- const writeTables = distinctBy([...(def?.dynamo?.writes || []), ...(lp?.dynamo?.writes || [])], (s) => s.shortName);
55
- const policies = [...(def.policies || []), ...(lp?.policies || [])].filter(notEmpty);
56
- const layers = [...(def.layers || []), ...(lp?.layers || [])].filter(notEmpty);
57
- const memory = lp?.memory || def?.memory || 128;
55
+ const readTables = (0, array_1.distinctBy)([...(((_a = def === null || def === void 0 ? void 0 : def.dynamo) === null || _a === void 0 ? void 0 : _a.reads) || []), ...(((_b = lp === null || lp === void 0 ? void 0 : lp.dynamo) === null || _b === void 0 ? void 0 : _b.reads) || [])], (s) => s.shortName);
56
+ const writeTables = (0, array_1.distinctBy)([...(((_c = def === null || def === void 0 ? void 0 : def.dynamo) === null || _c === void 0 ? void 0 : _c.writes) || []), ...(((_d = lp === null || lp === void 0 ? void 0 : lp.dynamo) === null || _d === void 0 ? void 0 : _d.writes) || [])], (s) => s.shortName);
57
+ const policies = [...(def.policies || []), ...((lp === null || lp === void 0 ? void 0 : lp.policies) || [])].filter(array_1.notEmpty);
58
+ const layers = [...(def.layers || []), ...((lp === null || lp === void 0 ? void 0 : lp.layers) || [])].filter(array_1.notEmpty);
59
+ const memory = (lp === null || lp === void 0 ? void 0 : lp.memory) || (def === null || def === void 0 ? void 0 : def.memory) || 128;
58
60
  // null forces undefined, undefined forces 5
59
- let reservedConcurrentExecutions = lp?.reservedConcurrentExecutions;
61
+ let reservedConcurrentExecutions = lp === null || lp === void 0 ? void 0 : lp.reservedConcurrentExecutions;
60
62
  if (reservedConcurrentExecutions === undefined) {
61
- reservedConcurrentExecutions = def?.reservedConcurrentExecutions;
63
+ reservedConcurrentExecutions = def === null || def === void 0 ? void 0 : def.reservedConcurrentExecutions;
62
64
  }
63
65
  if (reservedConcurrentExecutions === undefined) {
64
66
  reservedConcurrentExecutions = 5;
65
67
  }
66
- reservedConcurrentExecutions = reservedConcurrentExecutions ?? undefined;
68
+ reservedConcurrentExecutions = reservedConcurrentExecutions !== null && reservedConcurrentExecutions !== void 0 ? reservedConcurrentExecutions : undefined;
67
69
  //
68
- const timeout = Duration.seconds(lp?.timeoutS || def?.timeoutS || 30);
69
- let authorizerName = lp?.authorizerName;
70
+ const timeout = aws_cdk_lib_1.Duration.seconds((lp === null || lp === void 0 ? void 0 : lp.timeoutS) || (def === null || def === void 0 ? void 0 : def.timeoutS) || 30);
71
+ let authorizerName = lp === null || lp === void 0 ? void 0 : lp.authorizerName;
70
72
  if (authorizerName === undefined) {
71
73
  authorizerName = def.authorizerName;
72
74
  }
@@ -75,8 +77,8 @@ const setupLambda = ({ lambdaConfig, pathV, verb, seenPermissions, authorizers,
75
77
  }
76
78
  const authorizer = !authorizerName
77
79
  ? undefined
78
- : authorizers?.[authorizerName];
79
- const env = { ...(def.env || {}), ...(lp?.env || {}) };
80
+ : authorizers === null || authorizers === void 0 ? void 0 : authorizers[authorizerName];
81
+ const env = Object.assign(Object.assign({}, (def.env || {})), ((lp === null || lp === void 0 ? void 0 : lp.env) || {}));
80
82
  const tables = [...readTables, ...writeTables];
81
83
  const environment = env;
82
84
  Object.values(tables).forEach((v) => {
@@ -113,7 +115,7 @@ const addApiPaths = (api, pathList, apiRoots) => {
113
115
  return apiPath;
114
116
  };
115
117
  const lambdaNameSafe = (raw) => raw.replace(/[^a-zA-Z0-9-.]/gim, '-').replace(/(-){2,}/gim, '-');
116
- export const openApiImpl = (p) => {
118
+ const openApiImpl = (p) => {
117
119
  if (!p.schema) {
118
120
  throw new Error('no openapi schema found');
119
121
  }
@@ -134,9 +136,9 @@ export const openApiImpl = (p) => {
134
136
  });
135
137
  const lambdaName = lambdaNameSafe(`${p.shortStackName}-${fullPath}-${verb}-${NODE_ENV}`);
136
138
  const entry = `${endpointsBase}${fullPath}/${verb.toUpperCase()}.ts`;
137
- const lambdaV = new nodejs.NodejsFunction(stack, lambdaName, {
139
+ const lambdaV = new aws_cdk_lib_1.aws_lambda_nodejs.NodejsFunction(stack, lambdaName, {
138
140
  functionName: lambdaName,
139
- runtime: lambda.Runtime.NODEJS_16_X,
141
+ runtime: aws_cdk_lib_1.aws_lambda.Runtime.NODEJS_16_X,
140
142
  handler: 'handler',
141
143
  environment: lc.environment,
142
144
  memorySize: lc.memory,
@@ -147,19 +149,19 @@ export const openApiImpl = (p) => {
147
149
  externalModules: ['aws-sdk', 'aws-lambda'],
148
150
  },
149
151
  reservedConcurrentExecutions: lc.reservedConcurrentExecutions,
150
- logRetention: logs.RetentionDays.FIVE_DAYS,
152
+ logRetention: aws_cdk_lib_1.aws_logs.RetentionDays.FIVE_DAYS,
151
153
  layers: lc.layers,
152
154
  });
153
155
  lc.readTables.forEach((t) => t.table.grantReadData(lambdaV));
154
156
  lc.writeTables.forEach((t) => t.table.grantReadWriteData(lambdaV));
155
157
  lc.policies.forEach((p1) => lambdaV.addToRolePolicy(p1));
156
158
  //
157
- apiPath.addMethod(verb.toUpperCase(), new apigw.LambdaIntegration(lambdaV, {}), { authorizer: lc.authorizer });
159
+ apiPath.addMethod(verb.toUpperCase(), new aws_cdk_lib_1.aws_apigateway.LambdaIntegration(lambdaV, {}), { authorizer: lc.authorizer });
158
160
  });
159
161
  });
160
162
  Object.keys(lambdaConfig).forEach((k) => {
161
163
  if (!seenPermissions[k] || seenPermissions[k] === false) {
162
- warn(`unused permissions for '${k}', did you mean one of these paths?=`, Object.entries(seenPermissions)
164
+ (0, log_1.warn)(`unused permissions for '${k}', did you mean one of these paths?=`, Object.entries(seenPermissions)
163
165
  .filter(([, b]) => !b)
164
166
  .map(([f]) => f)
165
167
  .join('\n'));
@@ -167,3 +169,4 @@ export const openApiImpl = (p) => {
167
169
  }
168
170
  });
169
171
  };
172
+ exports.openApiImpl = openApiImpl;
@@ -1,32 +1,64 @@
1
- import S3 from 'aws-sdk/clients/s3';
2
- import { distinct, take } from '../../common/helpers/array';
3
- import { debug, error, info } from '../../common/helpers/log';
4
- let s3 = new S3();
5
- export const setS3 = (region) => {
6
- s3 = new S3({ region });
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
+ var __await = (this && this.__await) || function (v) { return this instanceof __await ? (this.v = v, this) : new __await(v); }
12
+ var __asyncGenerator = (this && this.__asyncGenerator) || function (thisArg, _arguments, generator) {
13
+ if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
14
+ var g = generator.apply(thisArg, _arguments || []), i, q = [];
15
+ return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i;
16
+ function verb(n) { if (g[n]) i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }
17
+ function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }
18
+ function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
19
+ function fulfill(value) { resume("next", value); }
20
+ function reject(value) { resume("throw", value); }
21
+ function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }
22
+ };
23
+ var __importDefault = (this && this.__importDefault) || function (mod) {
24
+ return (mod && mod.__esModule) ? mod : { "default": mod };
7
25
  };
8
- export const getS3Object = async ({ fileurl, }) => s3.getObject(fileurl).promise();
26
+ Object.defineProperty(exports, "__esModule", { value: true });
27
+ exports.getPresignedPostURL = exports.listFiles = exports.copyFile = exports.deleteFiles = exports.deleteFile = exports.uploadFile = exports.putS3Object = exports.getS3Objects = exports.getS3Object = exports.setS3 = void 0;
28
+ const s3_1 = __importDefault(require("aws-sdk/clients/s3"));
29
+ const array_1 = require("../../common/helpers/array");
30
+ const log_1 = require("../../common/helpers/log");
31
+ let s3 = new s3_1.default();
32
+ const setS3 = (region) => {
33
+ s3 = new s3_1.default({ region });
34
+ };
35
+ exports.setS3 = setS3;
36
+ const getS3Object = ({ fileurl, }) => __awaiter(void 0, void 0, void 0, function* () { return s3.getObject(fileurl).promise(); });
37
+ exports.getS3Object = getS3Object;
9
38
  /** function generator to get s3 files */
10
- export async function* getS3Objects({ bucket, keys, }) {
11
- let toProcess = keys.map((Key) => ({
12
- Bucket: bucket,
13
- Key,
14
- }));
15
- while (toProcess.length > 0) {
16
- const { part, rest } = take(toProcess, 1);
17
- toProcess = rest;
18
- const fileurl = part[0];
19
- const content = await getS3Object({ fileurl });
20
- const ret1 = {
21
- bucket: fileurl.Bucket,
22
- key: fileurl.Key,
23
- content: content.Body,
24
- };
25
- yield ret1;
26
- }
39
+ function getS3Objects({ bucket, keys, }) {
40
+ return __asyncGenerator(this, arguments, function* getS3Objects_1() {
41
+ let toProcess = keys.map((Key) => ({
42
+ Bucket: bucket,
43
+ Key,
44
+ }));
45
+ while (toProcess.length > 0) {
46
+ const { part, rest } = (0, array_1.take)(toProcess, 1);
47
+ toProcess = rest;
48
+ const fileurl = part[0];
49
+ const content = yield __await((0, exports.getS3Object)({ fileurl }));
50
+ const ret1 = {
51
+ bucket: fileurl.Bucket,
52
+ key: fileurl.Key,
53
+ content: content.Body,
54
+ };
55
+ yield yield __await(ret1);
56
+ }
57
+ });
27
58
  }
28
- export const putS3Object = async ({ Body, Bucket, Key, ContentType, }) => {
29
- const r = await s3
59
+ exports.getS3Objects = getS3Objects;
60
+ const putS3Object = ({ Body, Bucket, Key, ContentType, }) => __awaiter(void 0, void 0, void 0, function* () {
61
+ const r = yield s3
30
62
  .putObject({
31
63
  Body,
32
64
  Bucket,
@@ -38,44 +70,49 @@ export const putS3Object = async ({ Body, Bucket, Key, ContentType, }) => {
38
70
  return { error: r.$response.error.message };
39
71
  }
40
72
  return {};
41
- };
42
- export const uploadFile = async ({ Bucket, Key, Body, }) => {
43
- const res = await s3.upload({ Bucket, Key, Body }).promise();
73
+ });
74
+ exports.putS3Object = putS3Object;
75
+ const uploadFile = ({ Bucket, Key, Body, }) => __awaiter(void 0, void 0, void 0, function* () {
76
+ const res = yield s3.upload({ Bucket, Key, Body }).promise();
44
77
  return res.Location;
45
- };
46
- export const deleteFile = async ({ Bucket, Key, }) => {
47
- const res = await s3.deleteObject({ Bucket, Key }).promise();
78
+ });
79
+ exports.uploadFile = uploadFile;
80
+ const deleteFile = ({ Bucket, Key, }) => __awaiter(void 0, void 0, void 0, function* () {
81
+ const res = yield s3.deleteObject({ Bucket, Key }).promise();
48
82
  if (res.$response.error) {
49
83
  return { error: res.$response.error.message };
50
84
  }
51
85
  return {};
52
- };
53
- export const deleteFiles = async ({ Bucket, Keys, }) => {
86
+ });
87
+ exports.deleteFile = deleteFile;
88
+ const deleteFiles = ({ Bucket, Keys, }) => __awaiter(void 0, void 0, void 0, function* () {
89
+ var _a;
54
90
  let toDelete = Keys.map((Key) => ({ Key }));
55
91
  let deleted = 0;
56
92
  while (toDelete.length > 0) {
57
- const { part, rest } = take(toDelete, 900);
93
+ const { part, rest } = (0, array_1.take)(toDelete, 900);
58
94
  toDelete = rest;
59
- const res = await s3
95
+ const res = yield s3
60
96
  .deleteObjects({
61
97
  Bucket,
62
98
  Delete: { Objects: part },
63
99
  })
64
100
  .promise();
65
- if (!res.Deleted?.length) {
101
+ if (!((_a = res.Deleted) === null || _a === void 0 ? void 0 : _a.length)) {
66
102
  throw new Error('no deleted files');
67
103
  }
68
104
  deleted += res.Deleted.length;
69
105
  if (res.$response.error) {
70
106
  return { error: res.$response.error.message };
71
107
  }
72
- info(`deleted ${deleted} files`);
108
+ (0, log_1.info)(`deleted ${deleted} files`);
73
109
  }
74
110
  return {};
75
- };
76
- export const copyFile = async ({ Bucket, fromKey, toKey, deleteSource = false, }) => {
77
- debug(`copying s3 file from ${Bucket}- ${fromKey} to ${toKey}`);
78
- const res = await s3
111
+ });
112
+ exports.deleteFiles = deleteFiles;
113
+ const copyFile = ({ Bucket, fromKey, toKey, deleteSource = false, }) => __awaiter(void 0, void 0, void 0, function* () {
114
+ (0, log_1.debug)(`copying s3 file from ${Bucket}- ${fromKey} to ${toKey}`);
115
+ const res = yield s3
79
116
  .copyObject({
80
117
  //incl bucket
81
118
  CopySource: Bucket + '/' + fromKey,
@@ -88,39 +125,44 @@ export const copyFile = async ({ Bucket, fromKey, toKey, deleteSource = false, }
88
125
  return { error: res.$response.error.message };
89
126
  }
90
127
  if (deleteSource) {
91
- const df = await deleteFile({ Bucket, Key: fromKey });
128
+ const df = yield (0, exports.deleteFile)({ Bucket, Key: fromKey });
92
129
  if (df.error) {
93
130
  return { error: df.error };
94
131
  }
95
132
  }
96
133
  return {};
97
- };
98
- export async function listFiles(bucketName, opt) {
99
- try {
100
- const ret = [];
101
- let response = {
102
- IsTruncated: true,
103
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
104
- };
105
- while (response.IsTruncated) {
106
- response = await s3
107
- .listObjectsV2({
108
- Bucket: bucketName,
109
- ContinuationToken: response.NextContinuationToken,
110
- Prefix: opt?.prefix,
111
- })
112
- .promise();
113
- response.Contents?.filter((r) => r.Key)?.map((c) => {
114
- ret.push(c.Key);
115
- });
134
+ });
135
+ exports.copyFile = copyFile;
136
+ function listFiles(bucketName, opt) {
137
+ var _a, _b;
138
+ return __awaiter(this, void 0, void 0, function* () {
139
+ try {
140
+ const ret = [];
141
+ let response = {
142
+ IsTruncated: true,
143
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
144
+ };
145
+ while (response.IsTruncated) {
146
+ response = yield s3
147
+ .listObjectsV2({
148
+ Bucket: bucketName,
149
+ ContinuationToken: response.NextContinuationToken,
150
+ Prefix: opt === null || opt === void 0 ? void 0 : opt.prefix,
151
+ })
152
+ .promise();
153
+ (_b = (_a = response.Contents) === null || _a === void 0 ? void 0 : _a.filter((r) => r.Key)) === null || _b === void 0 ? void 0 : _b.map((c) => {
154
+ ret.push(c.Key);
155
+ });
156
+ }
157
+ return (0, array_1.distinct)(ret.filter((r) => r));
116
158
  }
117
- return distinct(ret.filter((r) => r));
118
- }
119
- catch (err) {
120
- error('Error', err);
121
- return [];
122
- }
159
+ catch (err) {
160
+ (0, log_1.error)('Error', err);
161
+ return [];
162
+ }
163
+ });
123
164
  }
165
+ exports.listFiles = listFiles;
124
166
  /**
125
167
  * allow uploading of file directly to s3
126
168
  * @param param0
@@ -134,18 +176,21 @@ export async function listFiles(bucketName, opt) {
134
176
  formData.append('file', file);
135
177
  fetch.POST(url,formData)
136
178
  */
137
- export async function getPresignedPostURL({ bucket, key, maxMb = 5, }) {
138
- const ps = await s3.createPresignedPost({
139
- Bucket: bucket,
140
- Fields: {
141
- Key: key,
142
- },
143
- Expires: 600,
144
- Conditions: [
145
- ['content-length-range', 0, maxMb * 1049000],
146
- ['starts-with', '$Content-Type', 'image/'],
147
- ],
179
+ function getPresignedPostURL({ bucket, key, maxMb = 5, }) {
180
+ return __awaiter(this, void 0, void 0, function* () {
181
+ const ps = yield s3.createPresignedPost({
182
+ Bucket: bucket,
183
+ Fields: {
184
+ Key: key,
185
+ },
186
+ Expires: 600,
187
+ Conditions: [
188
+ ['content-length-range', 0, maxMb * 1049000],
189
+ ['starts-with', '$Content-Type', 'image/'],
190
+ ],
191
+ });
192
+ const fields = JSON.parse(JSON.stringify(ps.fields));
193
+ return { fields, url: ps.url };
148
194
  });
149
- const fields = JSON.parse(JSON.stringify(ps.fields));
150
- return { fields, url: ps.url };
151
195
  }
196
+ exports.getPresignedPostURL = getPresignedPostURL;
@@ -1,9 +1,26 @@
1
- import SES from 'aws-sdk/clients/ses';
2
- export let ses = new SES();
3
- export const setSes = (region) => {
4
- ses = new SES({ region });
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
+ });
5
10
  };
6
- export const sendEmail = async ({ to, message, subject, sourceArn, from, }) => {
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.sendEmails = exports.sendEmail = exports.setSes = exports.ses = void 0;
16
+ const ses_1 = __importDefault(require("aws-sdk/clients/ses"));
17
+ exports.ses = new ses_1.default();
18
+ const setSes = (region) => {
19
+ exports.ses = new ses_1.default({ region });
20
+ };
21
+ exports.setSes = setSes;
22
+ const sendEmail = ({ to, message, subject, sourceArn, from, }) => __awaiter(void 0, void 0, void 0, function* () {
23
+ var _a;
7
24
  // Create sendEmail params
8
25
  const params = {
9
26
  Destination: {
@@ -26,10 +43,12 @@ export const sendEmail = async ({ to, message, subject, sourceArn, from, }) => {
26
43
  ReplyToAddresses: [from],
27
44
  SourceArn: sourceArn,
28
45
  };
29
- const res = await ses.sendEmail(params).promise();
46
+ const res = yield exports.ses.sendEmail(params).promise();
30
47
  if (res.$response.error) {
31
- return { error: res.$response.error?.message };
48
+ return { error: (_a = res.$response.error) === null || _a === void 0 ? void 0 : _a.message };
32
49
  }
33
50
  return {};
34
- };
35
- export const sendEmails = async (emails) => Promise.all(emails.map(sendEmail));
51
+ });
52
+ exports.sendEmail = sendEmail;
53
+ const sendEmails = (emails) => __awaiter(void 0, void 0, void 0, function* () { return Promise.all(emails.map(exports.sendEmail)); });
54
+ exports.sendEmails = sendEmails;
@@ -1,21 +1,38 @@
1
- import SQS from 'aws-sdk/clients/sqs';
2
- import { hashCode } from '../../common/helpers/hashCode';
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
+ 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.sendMessages = exports.setSqs = exports.sqs = void 0;
16
+ const sqs_1 = __importDefault(require("aws-sdk/clients/sqs"));
17
+ const hashCode_1 = require("../../common/helpers/hashCode");
3
18
  // eslint-disable-next-line import/no-mutable-exports
4
- export let sqs = new SQS();
5
- export const setSqs = (region) => {
6
- sqs = new SQS({ region });
19
+ exports.sqs = new sqs_1.default();
20
+ const setSqs = (region) => {
21
+ exports.sqs = new sqs_1.default({ region });
7
22
  };
8
- export const sendMessages = async (items, queueUrl) => {
23
+ exports.setSqs = setSqs;
24
+ const sendMessages = (items, queueUrl) => __awaiter(void 0, void 0, void 0, function* () {
9
25
  const req = {
10
26
  QueueUrl: queueUrl,
11
27
  Entries: items.map((i) => ({
12
28
  MessageBody: JSON.stringify(i),
13
- Id: hashCode(JSON.stringify(i)),
29
+ Id: (0, hashCode_1.hashCode)(JSON.stringify(i)),
14
30
  })),
15
31
  };
16
- const put = await sqs.sendMessageBatch(req).promise();
32
+ const put = yield exports.sqs.sendMessageBatch(req).promise();
17
33
  if (put.$response.error && put.$response.error.statusCode) {
18
34
  return { error: put.$response.error.message };
19
35
  }
20
36
  return {};
21
- };
37
+ });
38
+ exports.sendMessages = sendMessages;