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,28 +1,25 @@
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
- };
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)) || []);
13
10
  /** ensure that dynamo tables in stack dont exceed passed in provisioned limits */
14
- const enforceDynamoProvisionCap = ({ tables, readsMax = 25, writesMax = 25, mustEqual = false, }) => {
11
+ export const enforceDynamoProvisionCap = ({ tables, readsMax = 25, writesMax = 25, mustEqual = false, }) => {
15
12
  if (!tables || tables.length === 0) {
16
- (0, log_1.warn)('error in dynamo FT enforce');
13
+ warn('error in dynamo FT enforce');
17
14
  return;
18
15
  }
19
16
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
20
17
  const t = tables[0];
21
- const s = (0, json_1.safeStringify)(t.node._children.Resource.node.scope);
18
+ const s = safeStringify(t.node._children.Resource.node.scope);
22
19
  const reads = extractSum({ str: s, regex: /readCapacityUnits.*/gim });
23
20
  const writes = extractSum({ str: s, regex: /writeCapacityUnits.*/gim });
24
- (0, log_1.warn)(`dynamo table provisioned reads:${reads}/${readsMax}`);
25
- (0, log_1.warn)(`dynamo table provisioned writes:${writes}/${writesMax}`);
21
+ warn(`dynamo table provisioned reads:${reads}/${readsMax}`);
22
+ warn(`dynamo table provisioned writes:${writes}/${writesMax}`);
26
23
  if (reads > readsMax || writes > writesMax) {
27
24
  throw new Error('exceeded dynamo provision cap');
28
25
  }
@@ -30,4 +27,3 @@ const enforceDynamoProvisionCap = ({ tables, readsMax = 25, writesMax = 25, must
30
27
  throw new Error(`dynamo provision cap not met`);
31
28
  }
32
29
  };
33
- exports.enforceDynamoProvisionCap = enforceDynamoProvisionCap;
@@ -1,30 +1,14 @@
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
+ 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,5 +1,4 @@
1
- import { aws_certificatemanager as certmgr, aws_route53 as route53 } from 'aws-cdk-lib';
2
- import { TokenAuthorizer } from 'aws-cdk-lib/aws-apigateway/lib/authorizers/lambda';
1
+ import { aws_apigateway as apigw, aws_certificatemanager as certmgr, aws_route53 as route53 } from 'aws-cdk-lib';
3
2
  import { Construct } from 'constructs';
4
3
  import { ILambdaConfigs } from '../types';
5
4
  export declare const openApiImpl: (p: {
@@ -29,7 +28,7 @@ export declare const openApiImpl: (p: {
29
28
  /**
30
29
  * dictionary of named authorizer functions. these names are to be used in the lambdaConfig param
31
30
  */
32
- authorizers?: Record<string, TokenAuthorizer>;
31
+ authorizers?: Record<string, apigw.TokenAuthorizer>;
33
32
  /**
34
33
  * A record will be created in hosted zone for the apigw on this path. if undefined, record wont be created
35
34
  */
@@ -1,10 +1,7 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.openApiImpl = void 0;
4
1
  /* eslint-disable no-new */
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");
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';
8
5
  // eslint-disable-next-line
9
6
  const getPaths = (schema) => Object.entries(schema.paths).map(([fullPath, verbs]) => ({
10
7
  fullPath,
@@ -12,63 +9,64 @@ const getPaths = (schema) => Object.entries(schema.paths).map(([fullPath, verbs]
12
9
  verbs: Object.keys(verbs),
13
10
  }));
14
11
  const setUpApiGw = ({ stack, NODE_ENV, certificate, shortStackName, r53, cors = {
15
- allowOrigins: aws_cdk_lib_1.aws_apigateway.Cors.ALL_ORIGINS,
16
- allowHeaders: aws_cdk_lib_1.aws_apigateway.Cors.DEFAULT_HEADERS,
12
+ allowOrigins: apigw.Cors.ALL_ORIGINS,
13
+ allowHeaders: apigw.Cors.DEFAULT_HEADERS,
17
14
  }, }) => {
18
- const api = new aws_cdk_lib_1.aws_apigateway.RestApi(stack, `${shortStackName}-api-${NODE_ENV}`, {
19
- defaultCorsPreflightOptions: Object.assign({}, (cors || {})),
15
+ const api = new apigw.RestApi(stack, `${shortStackName}-api-${NODE_ENV}`, {
16
+ defaultCorsPreflightOptions: {
17
+ ...(cors || {}),
18
+ },
20
19
  });
21
20
  if (r53) {
22
- const dn = new aws_cdk_lib_1.aws_apigateway.DomainName(stack, 'domain', {
21
+ const dn = new apigw.DomainName(stack, 'domain', {
23
22
  domainName: r53.apiUrl,
24
23
  certificate,
25
- endpointType: aws_cdk_lib_1.aws_apigateway.EndpointType.EDGE,
26
- securityPolicy: aws_cdk_lib_1.aws_apigateway.SecurityPolicy.TLS_1_2,
24
+ endpointType: apigw.EndpointType.EDGE,
25
+ securityPolicy: apigw.SecurityPolicy.TLS_1_2,
27
26
  mapping: api,
28
27
  });
29
28
  if (r53.hostedZone) {
30
- new aws_cdk_lib_1.aws_route53.ARecord(stack, 'ARecord', {
29
+ new route53.ARecord(stack, 'ARecord', {
31
30
  comment: '(cdk)',
32
31
  recordName: r53.apiUrl.substring(0, r53.apiUrl.indexOf('.')),
33
32
  zone: r53.hostedZone,
34
- target: aws_cdk_lib_1.aws_route53.RecordTarget.fromAlias(new aws_cdk_lib_1.aws_route53_targets.ApiGatewayDomain(dn)),
33
+ target: route53.RecordTarget.fromAlias(new targets.ApiGatewayDomain(dn)),
35
34
  });
36
35
  }
37
36
  }
38
37
  return api;
39
38
  };
40
39
  const setupLambda = ({ lambdaConfig, pathV, verb, seenPermissions, authorizers, }) => {
41
- var _a, _b, _c, _d;
42
40
  const pathCompute = pathV + '/' + verb;
43
- const lp = lambdaConfig === null || lambdaConfig === void 0 ? void 0 : lambdaConfig[pathCompute];
41
+ const lp = lambdaConfig?.[pathCompute];
44
42
  if (lp) {
45
43
  seenPermissions[pathCompute] = true;
46
44
  }
47
45
  else {
48
46
  seenPermissions[pathCompute] = false;
49
47
  }
50
- const def = lambdaConfig === null || lambdaConfig === void 0 ? void 0 : lambdaConfig.default;
48
+ const def = lambdaConfig?.default;
51
49
  if (def) {
52
50
  seenPermissions.default = true;
53
51
  }
54
52
  //
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;
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;
60
58
  // null forces undefined, undefined forces 5
61
- let reservedConcurrentExecutions = lp === null || lp === void 0 ? void 0 : lp.reservedConcurrentExecutions;
59
+ let reservedConcurrentExecutions = lp?.reservedConcurrentExecutions;
62
60
  if (reservedConcurrentExecutions === undefined) {
63
- reservedConcurrentExecutions = def === null || def === void 0 ? void 0 : def.reservedConcurrentExecutions;
61
+ reservedConcurrentExecutions = def?.reservedConcurrentExecutions;
64
62
  }
65
63
  if (reservedConcurrentExecutions === undefined) {
66
64
  reservedConcurrentExecutions = 5;
67
65
  }
68
- reservedConcurrentExecutions = reservedConcurrentExecutions !== null && reservedConcurrentExecutions !== void 0 ? reservedConcurrentExecutions : undefined;
66
+ reservedConcurrentExecutions = reservedConcurrentExecutions ?? undefined;
69
67
  //
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;
68
+ const timeout = Duration.seconds(lp?.timeoutS || def?.timeoutS || 30);
69
+ let authorizerName = lp?.authorizerName;
72
70
  if (authorizerName === undefined) {
73
71
  authorizerName = def.authorizerName;
74
72
  }
@@ -77,8 +75,8 @@ const setupLambda = ({ lambdaConfig, pathV, verb, seenPermissions, authorizers,
77
75
  }
78
76
  const authorizer = !authorizerName
79
77
  ? undefined
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) || {}));
78
+ : authorizers?.[authorizerName];
79
+ const env = { ...(def.env || {}), ...(lp?.env || {}) };
82
80
  const tables = [...readTables, ...writeTables];
83
81
  const environment = env;
84
82
  Object.values(tables).forEach((v) => {
@@ -115,7 +113,7 @@ const addApiPaths = (api, pathList, apiRoots) => {
115
113
  return apiPath;
116
114
  };
117
115
  const lambdaNameSafe = (raw) => raw.replace(/[^a-zA-Z0-9-.]/gim, '-').replace(/(-){2,}/gim, '-');
118
- const openApiImpl = (p) => {
116
+ export const openApiImpl = (p) => {
119
117
  if (!p.schema) {
120
118
  throw new Error('no openapi schema found');
121
119
  }
@@ -136,9 +134,9 @@ const openApiImpl = (p) => {
136
134
  });
137
135
  const lambdaName = lambdaNameSafe(`${p.shortStackName}-${fullPath}-${verb}-${NODE_ENV}`);
138
136
  const entry = `${endpointsBase}${fullPath}/${verb.toUpperCase()}.ts`;
139
- const lambdaV = new aws_cdk_lib_1.aws_lambda_nodejs.NodejsFunction(stack, lambdaName, {
137
+ const lambdaV = new nodejs.NodejsFunction(stack, lambdaName, {
140
138
  functionName: lambdaName,
141
- runtime: aws_cdk_lib_1.aws_lambda.Runtime.NODEJS_16_X,
139
+ runtime: lambda.Runtime.NODEJS_16_X,
142
140
  handler: 'handler',
143
141
  environment: lc.environment,
144
142
  memorySize: lc.memory,
@@ -149,19 +147,19 @@ const openApiImpl = (p) => {
149
147
  externalModules: ['aws-sdk', 'aws-lambda'],
150
148
  },
151
149
  reservedConcurrentExecutions: lc.reservedConcurrentExecutions,
152
- logRetention: aws_cdk_lib_1.aws_logs.RetentionDays.FIVE_DAYS,
150
+ logRetention: logs.RetentionDays.FIVE_DAYS,
153
151
  layers: lc.layers,
154
152
  });
155
153
  lc.readTables.forEach((t) => t.table.grantReadData(lambdaV));
156
154
  lc.writeTables.forEach((t) => t.table.grantReadWriteData(lambdaV));
157
155
  lc.policies.forEach((p1) => lambdaV.addToRolePolicy(p1));
158
156
  //
159
- apiPath.addMethod(verb.toUpperCase(), new aws_cdk_lib_1.aws_apigateway.LambdaIntegration(lambdaV, {}), { authorizer: lc.authorizer });
157
+ apiPath.addMethod(verb.toUpperCase(), new apigw.LambdaIntegration(lambdaV, {}), { authorizer: lc.authorizer });
160
158
  });
161
159
  });
162
160
  Object.keys(lambdaConfig).forEach((k) => {
163
161
  if (!seenPermissions[k] || seenPermissions[k] === false) {
164
- (0, log_1.warn)(`unused permissions for '${k}', did you mean one of these paths?=`, Object.entries(seenPermissions)
162
+ warn(`unused permissions for '${k}', did you mean one of these paths?=`, Object.entries(seenPermissions)
165
163
  .filter(([, b]) => !b)
166
164
  .map(([f]) => f)
167
165
  .join('\n'));
@@ -169,4 +167,3 @@ const openApiImpl = (p) => {
169
167
  }
170
168
  });
171
169
  };
172
- exports.openApiImpl = openApiImpl;
@@ -1,64 +1,32 @@
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 };
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 });
25
7
  };
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;
8
+ export const getS3Object = async ({ fileurl, }) => s3.getObject(fileurl).promise();
38
9
  /** function generator to get s3 files */
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
- });
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
+ }
58
27
  }
59
- exports.getS3Objects = getS3Objects;
60
- const putS3Object = ({ Body, Bucket, Key, ContentType, }) => __awaiter(void 0, void 0, void 0, function* () {
61
- const r = yield s3
28
+ export const putS3Object = async ({ Body, Bucket, Key, ContentType, }) => {
29
+ const r = await s3
62
30
  .putObject({
63
31
  Body,
64
32
  Bucket,
@@ -70,49 +38,44 @@ const putS3Object = ({ Body, Bucket, Key, ContentType, }) => __awaiter(void 0, v
70
38
  return { error: r.$response.error.message };
71
39
  }
72
40
  return {};
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();
41
+ };
42
+ export const uploadFile = async ({ Bucket, Key, Body, }) => {
43
+ const res = await s3.upload({ Bucket, Key, Body }).promise();
77
44
  return res.Location;
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();
45
+ };
46
+ export const deleteFile = async ({ Bucket, Key, }) => {
47
+ const res = await s3.deleteObject({ Bucket, Key }).promise();
82
48
  if (res.$response.error) {
83
49
  return { error: res.$response.error.message };
84
50
  }
85
51
  return {};
86
- });
87
- exports.deleteFile = deleteFile;
88
- const deleteFiles = ({ Bucket, Keys, }) => __awaiter(void 0, void 0, void 0, function* () {
89
- var _a;
52
+ };
53
+ export const deleteFiles = async ({ Bucket, Keys, }) => {
90
54
  let toDelete = Keys.map((Key) => ({ Key }));
91
55
  let deleted = 0;
92
56
  while (toDelete.length > 0) {
93
- const { part, rest } = (0, array_1.take)(toDelete, 900);
57
+ const { part, rest } = take(toDelete, 900);
94
58
  toDelete = rest;
95
- const res = yield s3
59
+ const res = await s3
96
60
  .deleteObjects({
97
61
  Bucket,
98
62
  Delete: { Objects: part },
99
63
  })
100
64
  .promise();
101
- if (!((_a = res.Deleted) === null || _a === void 0 ? void 0 : _a.length)) {
65
+ if (!res.Deleted?.length) {
102
66
  throw new Error('no deleted files');
103
67
  }
104
68
  deleted += res.Deleted.length;
105
69
  if (res.$response.error) {
106
70
  return { error: res.$response.error.message };
107
71
  }
108
- (0, log_1.info)(`deleted ${deleted} files`);
72
+ info(`deleted ${deleted} files`);
109
73
  }
110
74
  return {};
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
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
116
79
  .copyObject({
117
80
  //incl bucket
118
81
  CopySource: Bucket + '/' + fromKey,
@@ -125,44 +88,39 @@ const copyFile = ({ Bucket, fromKey, toKey, deleteSource = false, }) => __awaite
125
88
  return { error: res.$response.error.message };
126
89
  }
127
90
  if (deleteSource) {
128
- const df = yield (0, exports.deleteFile)({ Bucket, Key: fromKey });
91
+ const df = await deleteFile({ Bucket, Key: fromKey });
129
92
  if (df.error) {
130
93
  return { error: df.error };
131
94
  }
132
95
  }
133
96
  return {};
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));
158
- }
159
- catch (err) {
160
- (0, log_1.error)('Error', err);
161
- 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
+ });
162
116
  }
163
- });
117
+ return distinct(ret.filter((r) => r));
118
+ }
119
+ catch (err) {
120
+ error('Error', err);
121
+ return [];
122
+ }
164
123
  }
165
- exports.listFiles = listFiles;
166
124
  /**
167
125
  * allow uploading of file directly to s3
168
126
  * @param param0
@@ -176,21 +134,18 @@ exports.listFiles = listFiles;
176
134
  formData.append('file', file);
177
135
  fetch.POST(url,formData)
178
136
  */
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 };
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
+ ],
194
148
  });
149
+ const fields = JSON.parse(JSON.stringify(ps.fields));
150
+ return { fields, url: ps.url };
195
151
  }
196
- exports.getPresignedPostURL = getPresignedPostURL;
@@ -1,26 +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 SES from 'aws-sdk/clients/ses';
2
+ export let ses = new SES();
3
+ export const setSes = (region) => {
4
+ ses = new SES({ 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.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;
6
+ export const sendEmail = async ({ to, message, subject, sourceArn, from, }) => {
24
7
  // Create sendEmail params
25
8
  const params = {
26
9
  Destination: {
@@ -43,12 +26,10 @@ const sendEmail = ({ to, message, subject, sourceArn, from, }) => __awaiter(void
43
26
  ReplyToAddresses: [from],
44
27
  SourceArn: sourceArn,
45
28
  };
46
- const res = yield exports.ses.sendEmail(params).promise();
29
+ const res = await ses.sendEmail(params).promise();
47
30
  if (res.$response.error) {
48
- return { error: (_a = res.$response.error) === null || _a === void 0 ? void 0 : _a.message };
31
+ return { error: res.$response.error?.message };
49
32
  }
50
33
  return {};
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;
34
+ };
35
+ export const sendEmails = async (emails) => Promise.all(emails.map(sendEmail));
@@ -1,38 +1,21 @@
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");
1
+ import SQS from 'aws-sdk/clients/sqs';
2
+ import { hashCode } from '../../common/helpers/hashCode';
18
3
  // eslint-disable-next-line import/no-mutable-exports
19
- exports.sqs = new sqs_1.default();
20
- const setSqs = (region) => {
21
- exports.sqs = new sqs_1.default({ region });
4
+ export let sqs = new SQS();
5
+ export const setSqs = (region) => {
6
+ sqs = new SQS({ region });
22
7
  };
23
- exports.setSqs = setSqs;
24
- const sendMessages = (items, queueUrl) => __awaiter(void 0, void 0, void 0, function* () {
8
+ export const sendMessages = async (items, queueUrl) => {
25
9
  const req = {
26
10
  QueueUrl: queueUrl,
27
11
  Entries: items.map((i) => ({
28
12
  MessageBody: JSON.stringify(i),
29
- Id: (0, hashCode_1.hashCode)(JSON.stringify(i)),
13
+ Id: hashCode(JSON.stringify(i)),
30
14
  })),
31
15
  };
32
- const put = yield exports.sqs.sendMessageBatch(req).promise();
16
+ const put = await sqs.sendMessageBatch(req).promise();
33
17
  if (put.$response.error && put.$response.error.statusCode) {
34
18
  return { error: put.$response.error.message };
35
19
  }
36
20
  return {};
37
- });
38
- exports.sendMessages = sendMessages;
21
+ };