ag-common 0.0.762 → 0.0.764

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 (64) hide show
  1. package/dist/api/helpers/apigw.d.ts +1 -1
  2. package/dist/api/helpers/apigw.js +6 -8
  3. package/dist/api/helpers/index.d.ts +0 -2
  4. package/dist/api/helpers/index.js +0 -2
  5. package/dist/api/types/index.d.ts +0 -32
  6. package/dist/ui/components/index.d.ts +0 -1
  7. package/dist/ui/components/index.js +0 -1
  8. package/dist/ui/helpers/dom.js +2 -0
  9. package/dist/ui/helpers/index.d.ts +0 -2
  10. package/dist/ui/helpers/index.js +0 -2
  11. package/dist/ui/helpers/jwt.d.ts +0 -12
  12. package/dist/ui/helpers/routes.d.ts +0 -18
  13. package/dist/ui/helpers/useContextMenu.js +3 -0
  14. package/dist/ui/helpers/useIsInViewport.js +1 -0
  15. package/dist/ui/helpers/useOnScroll.js +2 -3
  16. package/package.json +24 -32
  17. package/dist/api/helpers/openApiHelpers.d.ts +0 -43
  18. package/dist/api/helpers/openApiHelpers.js +0 -163
  19. package/dist/api/helpers/validateOpenApi.d.ts +0 -25
  20. package/dist/api/helpers/validateOpenApi.js +0 -127
  21. package/dist/api/openapi-postfix.d.ts +0 -1
  22. package/dist/api/openapi-postfix.js +0 -42
  23. package/dist/api/openapi-prefix.d.ts +0 -1
  24. package/dist/api/openapi-prefix.js +0 -88
  25. package/dist/ui/components/OpenApiCodeBlock/OpenApiCodeBlock.d.ts +0 -3
  26. package/dist/ui/components/OpenApiCodeBlock/OpenApiCodeBlock.js +0 -69
  27. package/dist/ui/components/OpenApiCodeBlock/curl/helpers/body.d.ts +0 -6
  28. package/dist/ui/components/OpenApiCodeBlock/curl/helpers/body.js +0 -30
  29. package/dist/ui/components/OpenApiCodeBlock/curl/helpers/getCurlLines.d.ts +0 -2
  30. package/dist/ui/components/OpenApiCodeBlock/curl/helpers/getCurlLines.js +0 -31
  31. package/dist/ui/components/OpenApiCodeBlock/curl/helpers/security.d.ts +0 -11
  32. package/dist/ui/components/OpenApiCodeBlock/curl/helpers/security.js +0 -28
  33. package/dist/ui/components/OpenApiCodeBlock/curl/index.d.ts +0 -6
  34. package/dist/ui/components/OpenApiCodeBlock/curl/index.js +0 -35
  35. package/dist/ui/components/OpenApiCodeBlock/fetch/helpers/call.d.ts +0 -3
  36. package/dist/ui/components/OpenApiCodeBlock/fetch/helpers/call.js +0 -23
  37. package/dist/ui/components/OpenApiCodeBlock/fetch/helpers/getFetchLines.d.ts +0 -2
  38. package/dist/ui/components/OpenApiCodeBlock/fetch/helpers/getFetchLines.js +0 -19
  39. package/dist/ui/components/OpenApiCodeBlock/fetch/helpers/req.d.ts +0 -3
  40. package/dist/ui/components/OpenApiCodeBlock/fetch/helpers/req.js +0 -78
  41. package/dist/ui/components/OpenApiCodeBlock/fetch/index.d.ts +0 -6
  42. package/dist/ui/components/OpenApiCodeBlock/fetch/index.js +0 -24
  43. package/dist/ui/components/OpenApiCodeBlock/helpers/common.d.ts +0 -20
  44. package/dist/ui/components/OpenApiCodeBlock/helpers/common.js +0 -89
  45. package/dist/ui/components/OpenApiCodeBlock/helpers/joinJsx.d.ts +0 -4
  46. package/dist/ui/components/OpenApiCodeBlock/helpers/joinJsx.js +0 -25
  47. package/dist/ui/components/OpenApiCodeBlock/index.d.ts +0 -2
  48. package/dist/ui/components/OpenApiCodeBlock/index.js +0 -17
  49. package/dist/ui/components/OpenApiCodeBlock/types.d.ts +0 -60
  50. package/dist/ui/components/OpenApiCodeBlock/types.js +0 -2
  51. package/dist/ui/helpers/axiosHelper.d.ts +0 -17
  52. package/dist/ui/helpers/axiosHelper.js +0 -92
  53. package/dist/ui/helpers/callOpenApi/cached.d.ts +0 -34
  54. package/dist/ui/helpers/callOpenApi/cached.js +0 -92
  55. package/dist/ui/helpers/callOpenApi/direct.d.ts +0 -9
  56. package/dist/ui/helpers/callOpenApi/direct.js +0 -137
  57. package/dist/ui/helpers/callOpenApi/helpers.d.ts +0 -9
  58. package/dist/ui/helpers/callOpenApi/helpers.js +0 -60
  59. package/dist/ui/helpers/callOpenApi/hook.d.ts +0 -27
  60. package/dist/ui/helpers/callOpenApi/hook.js +0 -82
  61. package/dist/ui/helpers/callOpenApi/index.d.ts +0 -5
  62. package/dist/ui/helpers/callOpenApi/index.js +0 -20
  63. package/dist/ui/helpers/callOpenApi/types.d.ts +0 -19
  64. package/dist/ui/helpers/callOpenApi/types.js +0 -2
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * Sends a message to a specific WebSocket connection
3
3
  */
4
- export declare function sendWebSocketMessage<T>({ connectionId, message, endpoint, }: {
4
+ export declare function sendWebSocketMessage<T>(p: {
5
5
  connectionId: string;
6
6
  message: T;
7
7
  endpoint: string;
@@ -18,15 +18,13 @@ const common_1 = require("../../common");
18
18
  /**
19
19
  * Sends a message to a specific WebSocket connection
20
20
  */
21
- function sendWebSocketMessage(_a) {
22
- return __awaiter(this, arguments, void 0, function* ({ connectionId, message, endpoint, }) {
23
- const wsClient = new client_apigatewaymanagementapi_1.ApiGatewayManagementApiClient({
24
- endpoint,
25
- });
21
+ function sendWebSocketMessage(p) {
22
+ return __awaiter(this, void 0, void 0, function* () {
23
+ const wsClient = new client_apigatewaymanagementapi_1.ApiGatewayManagementApiClient(p);
26
24
  try {
27
25
  const s = yield wsClient.send(new client_apigatewaymanagementapi_1.PostToConnectionCommand({
28
- ConnectionId: connectionId,
29
- Data: JSON.stringify(message),
26
+ ConnectionId: p.connectionId,
27
+ Data: JSON.stringify(p.message),
30
28
  }));
31
29
  if (s.$metadata.httpStatusCode === 200) {
32
30
  return true;
@@ -34,7 +32,7 @@ function sendWebSocketMessage(_a) {
34
32
  throw new Error('Error:' + JSON.stringify(s));
35
33
  }
36
34
  catch (e) {
37
- (0, common_1.warn)('Failed to send WebSocket message:', e.message);
35
+ (0, common_1.warn)('Failed to send WebSocket message:', p, e);
38
36
  return false;
39
37
  }
40
38
  });
@@ -3,12 +3,10 @@ export * from './apigw';
3
3
  export * from './aws';
4
4
  export * from './dynamo';
5
5
  export * from './enforceDynamoProvisionCap';
6
- export * from './openApiHelpers';
7
6
  export * from './s3';
8
7
  export * from './ses';
9
8
  export * from './sqs';
10
9
  export * from './ssm';
11
10
  export * from './ssmInfra';
12
11
  export * from './sts';
13
- export * from './validateOpenApi';
14
12
  export * from './validations';
@@ -19,12 +19,10 @@ __exportStar(require("./apigw"), exports);
19
19
  __exportStar(require("./aws"), exports);
20
20
  __exportStar(require("./dynamo"), exports);
21
21
  __exportStar(require("./enforceDynamoProvisionCap"), exports);
22
- __exportStar(require("./openApiHelpers"), exports);
23
22
  __exportStar(require("./s3"), exports);
24
23
  __exportStar(require("./ses"), exports);
25
24
  __exportStar(require("./sqs"), exports);
26
25
  __exportStar(require("./ssm"), exports);
27
26
  __exportStar(require("./ssmInfra"), exports);
28
27
  __exportStar(require("./sts"), exports);
29
- __exportStar(require("./validateOpenApi"), exports);
30
28
  __exportStar(require("./validations"), exports);
@@ -1,4 +1,3 @@
1
- import type { aws_dynamodb as dynamodb, aws_iam as iam, aws_lambda as lambda } from 'aws-cdk-lib';
2
1
  export interface Key {
3
2
  [key: string]: string | number;
4
3
  }
@@ -15,35 +14,4 @@ export interface DYNAMOKEYS {
15
14
  PK3?: string;
16
15
  PK4?: string;
17
16
  }
18
- export interface ILambdaConfig {
19
- dynamo?: {
20
- reads?: dynamodb.ITable[];
21
- writes?: dynamodb.ITable[];
22
- };
23
- policies?: iam.PolicyStatement[];
24
- env?: Record<string, string>;
25
- layers?: lambda.ILayerVersion[];
26
- /**
27
- * use the name of the lambda authorizer passed in in the openApiImpl config
28
- */
29
- authorizerName?: string;
30
- /**
31
- * timeout in seconds. defaults to 30
32
- */
33
- timeoutS?: number;
34
- /**
35
- * lambda memory. defaults to 128
36
- */
37
- memory?: number;
38
- /**
39
- * reserved lambda concurrency. defaults to 5. if null, doesnt apply
40
- */
41
- reservedConcurrentExecutions?: number | null;
42
- }
43
- /**
44
- * 'default' will be applied to all functions
45
- */
46
- export type ILambdaConfigs = Partial<Record<string, ILambdaConfig & {
47
- default?: ILambdaConfig;
48
- }>>;
49
17
  export type * from './aws';
@@ -20,7 +20,6 @@ export * from './Loader';
20
20
  export * from './Markdown';
21
21
  export * from './MinSidebar';
22
22
  export * from './Modal';
23
- export * from './OpenApiCodeBlock';
24
23
  export * from './PieChart';
25
24
  export * from './ProgressBar';
26
25
  export * from './Prompt';
@@ -36,7 +36,6 @@ __exportStar(require("./Loader"), exports);
36
36
  __exportStar(require("./Markdown"), exports);
37
37
  __exportStar(require("./MinSidebar"), exports);
38
38
  __exportStar(require("./Modal"), exports);
39
- __exportStar(require("./OpenApiCodeBlock"), exports);
40
39
  __exportStar(require("./PieChart"), exports);
41
40
  __exportStar(require("./ProgressBar"), exports);
42
41
  __exportStar(require("./Prompt"), exports);
@@ -22,6 +22,7 @@ exports.convertRemToPixels = convertRemToPixels;
22
22
  * @param p
23
23
  * @returns
24
24
  */
25
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
25
26
  const filterDataProps = (p) => {
26
27
  const x = Object.entries(p)
27
28
  .filter((r) => r[0].startsWith('data-'))
@@ -37,6 +38,7 @@ const isRightClick = (event) => {
37
38
  isRightMB = event.which == 3;
38
39
  else if ('button' in event)
39
40
  // IE, Opera
41
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
40
42
  isRightMB = event.button == 2;
41
43
  return isRightMB;
42
44
  };
@@ -1,5 +1,3 @@
1
- export * from './axiosHelper';
2
- export * from './callOpenApi';
3
1
  export type * from './cognito';
4
2
  export * from './cookie';
5
3
  export * from './date';
@@ -14,8 +14,6 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./axiosHelper"), exports);
18
- __exportStar(require("./callOpenApi"), exports);
19
17
  __exportStar(require("./cookie"), exports);
20
18
  __exportStar(require("./date"), exports);
21
19
  __exportStar(require("./debounce"), exports);
@@ -1,4 +1,3 @@
1
- import type { AxiosError } from 'axios';
2
1
  export interface Jwt {
3
2
  access_token: string;
4
3
  expires_at: number;
@@ -49,14 +48,3 @@ export interface User {
49
48
  isAdmin: boolean;
50
49
  jwt?: Jwt;
51
50
  }
52
- export interface AxiosWrapper<T> {
53
- data: T | undefined;
54
- error?: AxiosError<unknown, any>;
55
- loading: boolean;
56
- reFetch: () => Promise<any>;
57
- datetime: number;
58
- }
59
- export interface AxiosWrapperLite<T> {
60
- data: T | undefined;
61
- error?: AxiosError;
62
- }
@@ -1,5 +1,4 @@
1
1
  import type { TLang } from '../../common/helpers/i18n';
2
- import type { AxiosWrapperLite } from './jwt';
3
2
  export type TProtocol = 'http:' | 'https:';
4
3
  export interface URLLite {
5
4
  hash: string;
@@ -14,29 +13,12 @@ export interface URLLite {
14
13
  search: string;
15
14
  username: string;
16
15
  }
17
- export type CacheItems = CacheItem<any>[];
18
- export interface CacheItem<T> {
19
- cacheKey: string;
20
- prefillData: AxiosWrapperLite<T>;
21
- ttlSeconds: number;
22
- }
23
- export interface IInitialStateCommon {
24
- openApiCache?: CacheItem<any>[];
25
- }
26
16
  export interface IRequestCommon {
27
17
  url: URLLite;
28
18
  query: Record<string, string>;
29
19
  lang: TLang;
30
20
  userAgent: string;
31
21
  }
32
- export interface IStateCommon<TRequest extends IRequestCommon> extends IInitialStateCommon {
33
- request: TRequest;
34
- pushPath: (path: string) => Promise<void>;
35
- /**
36
- * set for ssr
37
- */
38
- cookieDocument: string | undefined;
39
- }
40
22
  export declare const getRenderLanguage: (host?: string | null) => TLang;
41
23
  export declare const getClientReqHref: () => IRequestCommon;
42
24
  /**
@@ -9,6 +9,9 @@ const useContextMenu = ({ ref, }) => {
9
9
  const [showMenu, setShowMenu] = (0, react_1.useState)(false);
10
10
  const handleContextMenu = (0, react_1.useCallback)((e) => {
11
11
  var _a;
12
+ if (!e.target) {
13
+ return;
14
+ }
12
15
  if (!((_a = ref.current) === null || _a === void 0 ? void 0 : _a.contains(e.target))) {
13
16
  return;
14
17
  }
@@ -8,6 +8,7 @@ function useIsInViewport(ref) {
8
8
  const observer = new IntersectionObserver((entries) => {
9
9
  setIsInViewport(entries[0].isIntersecting);
10
10
  });
11
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
11
12
  if (ref.current) {
12
13
  observer.observe(ref.current);
13
14
  }
@@ -18,12 +18,11 @@ function useOnScroll({ onScroll, element, } = {}) {
18
18
  (0, useGranularHook_1.useGranularEffect)(() => {
19
19
  var _a;
20
20
  const listener = (e) => {
21
- var _a, _b;
22
21
  if (!(element === null || element === void 0 ? void 0 : element.current)) {
23
22
  return null;
24
23
  }
25
- const y = (_a = element.current.scrollTop) !== null && _a !== void 0 ? _a : window.scrollY;
26
- const x = (_b = element.current.scrollLeft) !== null && _b !== void 0 ? _b : window.scrollX;
24
+ const y = element.current.scrollTop;
25
+ const x = element.current.scrollLeft;
27
26
  const r = {
28
27
  y,
29
28
  x,
package/package.json CHANGED
@@ -1,10 +1,9 @@
1
1
  {
2
- "version": "0.0.762",
2
+ "version": "0.0.764",
3
3
  "name": "ag-common",
4
4
  "main": "./dist/index.js",
5
5
  "types": "./dist/index.d.ts",
6
- "author": "Andrei Gec <@andreigec> (https://gec.dev/)",
7
- "repository": "github:andreigec/ag-common",
6
+ "author": "admin@gec.dev",
8
7
  "license": "ISC",
9
8
  "scripts": {
10
9
  "preinstall": "npx only-allow pnpm",
@@ -18,58 +17,51 @@
18
17
  "test": "globstar -- node --import tsx --test \"src/**/*.test.ts\""
19
18
  },
20
19
  "dependencies": {
21
- "@aws-sdk/client-apigatewaymanagementapi": "^3.864.0",
22
- "@aws-sdk/client-dynamodb": "^3.868.0",
23
- "@aws-sdk/client-s3": "^3.864.0",
24
- "@aws-sdk/client-ses": "^3.864.0",
25
- "@aws-sdk/client-sqs": "^3.864.0",
26
- "@aws-sdk/client-sts": "^3.864.0",
27
- "@aws-sdk/lib-dynamodb": "^3.868.0",
28
- "@aws-sdk/s3-presigned-post": "^3.864.0",
29
- "@aws-sdk/util-dynamodb": "^3.868.0",
30
- "aws-cdk-lib": "^2.211.0",
31
- "axios": "^1.11.0",
20
+ "@aws-sdk/client-apigatewaymanagementapi": "^3.879.0",
21
+ "@aws-sdk/client-dynamodb": "^3.879.0",
22
+ "@aws-sdk/client-s3": "^3.879.0",
23
+ "@aws-sdk/client-ses": "^3.879.0",
24
+ "@aws-sdk/client-sqs": "^3.879.0",
25
+ "@aws-sdk/client-sts": "^3.879.0",
26
+ "@aws-sdk/lib-dynamodb": "^3.879.0",
27
+ "@aws-sdk/s3-presigned-post": "^3.879.0",
28
+ "aws-cdk-lib": "^2.213.0",
32
29
  "buffer": "^6.0.3",
33
- "constructs": "^10.4.2",
34
30
  "jsonwebtoken": "^9.0.2",
35
31
  "jwks-rsa": "^3.2.0",
36
- "node-cache": "^5.1.2",
37
- "openapi-request-validator": "^12.1.3",
38
32
  "react": "^19.1.1",
39
33
  "react-dom": "^19.1.1",
40
34
  "typescript": "^5.9.2"
41
35
  },
42
36
  "devDependencies": {
43
- "@babel/core": "^7.28.3",
44
- "@babel/preset-typescript": "^7.27.1",
45
- "@babel/types": "^7.28.2",
46
37
  "@emotion/react": "^11.14.0",
47
38
  "@emotion/styled": "^11.14.1",
48
39
  "@smithy/types": "^4.3.2",
49
- "@storybook/addon-docs": "^9.1.2",
50
- "@storybook/addon-links": "^9.1.2",
40
+ "@storybook/addon-docs": "^9.1.3",
41
+ "@storybook/addon-links": "^9.1.3",
51
42
  "@storybook/addon-webpack5-compiler-swc": "^3.0.0",
52
43
  "@storybook/addons": "^7.6.17",
53
44
  "@storybook/manager-api": "^8.6.14",
54
- "@storybook/react-webpack5": "^9.1.2",
45
+ "@storybook/react": "^9.1.3",
46
+ "@storybook/react-webpack5": "^9.1.3",
55
47
  "@storybook/theming": "^8.6.14",
56
48
  "@types/jsonwebtoken": "^9.0.10",
57
49
  "@types/node": "^24.3.0",
58
- "@types/react": "^19.1.10",
59
- "@types/react-dom": "^19.1.7",
60
- "@typescript-eslint/eslint-plugin": "^8.40.0",
61
- "@typescript-eslint/parser": "^8.40.0",
50
+ "@types/react": "^19.1.12",
51
+ "@types/react-dom": "^19.1.9",
52
+ "@typescript-eslint/eslint-plugin": "^8.41.0",
53
+ "@typescript-eslint/parser": "^8.41.0",
62
54
  "cross-env": "^10.0.0",
63
- "eslint": "^9.33.0",
55
+ "eslint": "^9.34.0",
64
56
  "eslint-config-e7npm": "^0.1.24",
65
- "eslint-plugin-storybook": "9.1.3",
57
+ "eslint-plugin-storybook": "^9.1.3",
66
58
  "globstar": "^1.0.0",
67
59
  "rimraf": "^6.0.1",
68
- "storybook": "^9.1.2",
69
- "tsx": "^4.20.4"
60
+ "storybook": "^9.1.3",
61
+ "tsx": "^4.20.5"
70
62
  },
71
63
  "resolutions": {
72
- "globals": "15.15.0"
64
+ "globals": "16.3.0"
73
65
  },
74
66
  "files": [
75
67
  "dist/**/*",
@@ -1,43 +0,0 @@
1
- import type { aws_certificatemanager as certmgr } from 'aws-cdk-lib';
2
- import { aws_apigateway as apigw, aws_route53 as route53 } from 'aws-cdk-lib';
3
- import type { Construct } from 'constructs';
4
- import type { ILambdaConfigs } from '../types';
5
- export declare const openApiImpl: (p: {
6
- stack: Construct;
7
- /**
8
- * pass in generated openapi file
9
- * eg schema: require('common/openapi.generated').default;
10
- */
11
- schema: unknown;
12
- NODE_ENV: string;
13
- endpointsBase: string;
14
- /**
15
- * 'default' will be applied to all functions
16
- */
17
- lambdaConfig: ILambdaConfigs;
18
- shortStackName: string;
19
- /**
20
- * defaults:
21
- * allowOrigins: apigw.Cors.ALL_ORIGINS,
22
- allowHeaders: apigw.Cors.DEFAULT_HEADERS,
23
- */
24
- cors?: {
25
- allowOrigins: string[];
26
- allowHeaders: string[];
27
- };
28
- /**
29
- * dictionary of named authorizer functions. these names are to be used in the lambdaConfig param
30
- */
31
- authorizers?: Record<string, apigw.TokenAuthorizer>;
32
- /**
33
- * A record will be created in hosted zone for the apigw on this path. if undefined, record wont be created
34
- */
35
- r53?: {
36
- /** will create apigw domainname
37
- * eg api.mydomain.com */
38
- apiUrl: string;
39
- /** if provided will add r53 record to apigw domainame */
40
- hostedZone?: route53.IHostedZone;
41
- certificate: certmgr.ICertificate;
42
- };
43
- }) => void;
@@ -1,163 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.openApiImpl = void 0;
4
- const aws_cdk_lib_1 = require("aws-cdk-lib");
5
- const array_1 = require("../../common/helpers/array");
6
- const log_1 = require("../../common/helpers/log");
7
- const getPaths = (schema) => Object.entries(schema.paths).map(([fullPath, verbs]) => ({
8
- fullPath,
9
- pathList: fullPath.split('/').filter((s) => s),
10
- verbs: Object.keys(verbs),
11
- }));
12
- const setUpApiGw = ({ stack, NODE_ENV, shortStackName, r53, cors = {
13
- allowOrigins: aws_cdk_lib_1.aws_apigateway.Cors.ALL_ORIGINS,
14
- allowHeaders: aws_cdk_lib_1.aws_apigateway.Cors.DEFAULT_HEADERS,
15
- }, }) => {
16
- const api = new aws_cdk_lib_1.aws_apigateway.RestApi(stack, `${shortStackName}-api-${NODE_ENV}`, {
17
- defaultCorsPreflightOptions: Object.assign({}, (cors || {})),
18
- });
19
- if (r53) {
20
- const dn = new aws_cdk_lib_1.aws_apigateway.DomainName(stack, 'domain', {
21
- domainName: r53.apiUrl,
22
- certificate: r53.certificate,
23
- endpointType: aws_cdk_lib_1.aws_apigateway.EndpointType.EDGE,
24
- securityPolicy: aws_cdk_lib_1.aws_apigateway.SecurityPolicy.TLS_1_2,
25
- mapping: api,
26
- });
27
- if (r53.hostedZone) {
28
- new aws_cdk_lib_1.aws_route53.ARecord(stack, 'ARecord', {
29
- comment: '(cdk)',
30
- recordName: r53.apiUrl.substring(0, r53.apiUrl.indexOf('.')),
31
- zone: r53.hostedZone,
32
- target: aws_cdk_lib_1.aws_route53.RecordTarget.fromAlias(new aws_cdk_lib_1.aws_route53_targets.ApiGatewayDomain(dn)),
33
- });
34
- }
35
- }
36
- return api;
37
- };
38
- const setupLambda = ({ lambdaConfig, pathV, verb, seenPermissions, authorizers, }) => {
39
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t;
40
- const pathCompute = pathV + '/' + verb;
41
- const lp = lambdaConfig[pathCompute];
42
- if (lp) {
43
- seenPermissions[pathCompute] = true;
44
- }
45
- else {
46
- seenPermissions[pathCompute] = false;
47
- }
48
- const def = lambdaConfig.default;
49
- if (def) {
50
- seenPermissions.default = true;
51
- }
52
- //
53
- const readTables = (0, array_1.distinctBy)([...((_b = (_a = def === null || def === void 0 ? void 0 : def.dynamo) === null || _a === void 0 ? void 0 : _a.reads) !== null && _b !== void 0 ? _b : []), ...((_d = (_c = lp === null || lp === void 0 ? void 0 : lp.dynamo) === null || _c === void 0 ? void 0 : _c.reads) !== null && _d !== void 0 ? _d : [])], (s) => s.tableName);
54
- const writeTables = (0, array_1.distinctBy)([...((_f = (_e = def === null || def === void 0 ? void 0 : def.dynamo) === null || _e === void 0 ? void 0 : _e.writes) !== null && _f !== void 0 ? _f : []), ...((_h = (_g = lp === null || lp === void 0 ? void 0 : lp.dynamo) === null || _g === void 0 ? void 0 : _g.writes) !== null && _h !== void 0 ? _h : [])], (s) => s.tableName);
55
- const policies = [...((_j = def === null || def === void 0 ? void 0 : def.policies) !== null && _j !== void 0 ? _j : []), ...((_k = lp === null || lp === void 0 ? void 0 : lp.policies) !== null && _k !== void 0 ? _k : [])].filter(array_1.notEmpty);
56
- const layers = [...((_l = def === null || def === void 0 ? void 0 : def.layers) !== null && _l !== void 0 ? _l : []), ...((_m = lp === null || lp === void 0 ? void 0 : lp.layers) !== null && _m !== void 0 ? _m : [])].filter(array_1.notEmpty);
57
- const memory = (_p = (_o = lp === null || lp === void 0 ? void 0 : lp.memory) !== null && _o !== void 0 ? _o : def === null || def === void 0 ? void 0 : def.memory) !== null && _p !== void 0 ? _p : 128;
58
- // null forces undefined, undefined forces 5
59
- let reservedConcurrentExecutions = lp === null || lp === void 0 ? void 0 : lp.reservedConcurrentExecutions;
60
- if (reservedConcurrentExecutions === undefined) {
61
- reservedConcurrentExecutions = def === null || def === void 0 ? void 0 : def.reservedConcurrentExecutions;
62
- }
63
- if (reservedConcurrentExecutions === undefined) {
64
- reservedConcurrentExecutions = 5;
65
- }
66
- reservedConcurrentExecutions = reservedConcurrentExecutions !== null && reservedConcurrentExecutions !== void 0 ? reservedConcurrentExecutions : undefined;
67
- //
68
- const timeout = aws_cdk_lib_1.Duration.seconds((_r = (_q = lp === null || lp === void 0 ? void 0 : lp.timeoutS) !== null && _q !== void 0 ? _q : def === null || def === void 0 ? void 0 : def.timeoutS) !== null && _r !== void 0 ? _r : 30);
69
- let authorizerName = lp === null || lp === void 0 ? void 0 : lp.authorizerName;
70
- if (authorizerName === undefined) {
71
- authorizerName = def === null || def === void 0 ? void 0 : def.authorizerName;
72
- }
73
- if (authorizerName && (!authorizers || !authorizers[authorizerName])) {
74
- throw new Error('unseen auth name:' + authorizerName);
75
- }
76
- const authorizer = !authorizerName
77
- ? undefined
78
- : authorizers === null || authorizers === void 0 ? void 0 : authorizers[authorizerName];
79
- const env = Object.assign(Object.assign({}, ((_s = def === null || def === void 0 ? void 0 : def.env) !== null && _s !== void 0 ? _s : {})), ((_t = lp === null || lp === void 0 ? void 0 : lp.env) !== null && _t !== void 0 ? _t : {}));
80
- const environment = env;
81
- return {
82
- environment,
83
- readTables,
84
- writeTables,
85
- policies,
86
- layers,
87
- authorizer,
88
- memory,
89
- timeout,
90
- reservedConcurrentExecutions,
91
- };
92
- };
93
- const addApiPaths = (api, pathList, apiRoots) => {
94
- let pathBuild = '';
95
- let apiPath = api.root;
96
- pathList.forEach((path) => {
97
- pathBuild += '/' + path;
98
- if (apiRoots[pathBuild]) {
99
- apiPath = apiRoots[pathBuild];
100
- }
101
- else {
102
- apiRoots[pathBuild] = apiPath.addResource(path);
103
- apiPath = apiRoots[pathBuild];
104
- }
105
- });
106
- if (!apiPath) {
107
- throw new Error('no apipath');
108
- }
109
- return apiPath;
110
- };
111
- const lambdaNameSafe = (raw) => raw.replace(/[^a-zA-Z0-9-.]/gim, '-').replace(/(-){2,}/gim, '-');
112
- const openApiImpl = (p) => {
113
- if (!p.schema) {
114
- throw new Error('no openapi schema found');
115
- }
116
- const { stack, NODE_ENV, endpointsBase, lambdaConfig } = p;
117
- const paths = getPaths(p.schema);
118
- const api = setUpApiGw(p);
119
- const apiRoots = {};
120
- const seenPermissions = {};
121
- paths.forEach(({ fullPath, verbs, pathList }) => {
122
- const apiPath = addApiPaths(api, pathList, apiRoots);
123
- verbs.forEach((verb) => {
124
- const lc = setupLambda({
125
- lambdaConfig,
126
- pathV: fullPath,
127
- verb,
128
- seenPermissions,
129
- authorizers: p.authorizers,
130
- });
131
- const lambdaName = lambdaNameSafe(`${p.shortStackName}-${fullPath}-${verb}-${NODE_ENV}`);
132
- const entry = `${endpointsBase}${fullPath}/${verb.toUpperCase()}.ts`;
133
- const lambdaV = new aws_cdk_lib_1.aws_lambda_nodejs.NodejsFunction(stack, lambdaName, {
134
- functionName: lambdaName,
135
- runtime: aws_cdk_lib_1.aws_lambda.Runtime.NODEJS_18_X,
136
- handler: 'handler',
137
- environment: lc.environment,
138
- memorySize: lc.memory,
139
- timeout: lc.timeout,
140
- description: '(cdk)',
141
- entry,
142
- reservedConcurrentExecutions: lc.reservedConcurrentExecutions,
143
- logRetention: aws_cdk_lib_1.aws_logs.RetentionDays.FIVE_DAYS,
144
- layers: lc.layers,
145
- });
146
- lc.readTables.forEach((t) => t.grantReadData(lambdaV));
147
- lc.writeTables.forEach((t) => t.grantReadWriteData(lambdaV));
148
- lc.policies.forEach((p1) => lambdaV.addToRolePolicy(p1));
149
- //
150
- apiPath.addMethod(verb.toUpperCase(), new aws_cdk_lib_1.aws_apigateway.LambdaIntegration(lambdaV, {}), { authorizer: lc.authorizer });
151
- });
152
- });
153
- Object.keys(lambdaConfig).forEach((k) => {
154
- if (!seenPermissions[k]) {
155
- (0, log_1.warn)(`unused permissions for '${k}', did you mean one of these paths?=`, Object.entries(seenPermissions)
156
- .filter(([, b]) => !b)
157
- .map(([f]) => f)
158
- .join('\n'));
159
- throw new Error('unused permissions!:' + k);
160
- }
161
- });
162
- };
163
- exports.openApiImpl = openApiImpl;
@@ -1,25 +0,0 @@
1
- import type { TLang } from '../../common/helpers/i18n';
2
- import type { User } from '../../ui/helpers/jwt';
3
- import type { APIGatewayEvent, APIGatewayProxyResult } from '../types';
4
- import type { TGetAndValidateToken } from './validations';
5
- export type NextType<T> = ({ event, body, params, userProfile, lang, }: {
6
- params: Record<string, string>;
7
- event: APIGatewayEvent;
8
- body: T;
9
- userProfile?: User;
10
- lang: TLang;
11
- }) => Promise<APIGatewayProxyResult>;
12
- export declare function validateOpenApi<T>({ event, next, authorized, schema, COGNITO_USER_POOL_ID, jwksRegion, getAndValidateTokenOverride, }: {
13
- getAndValidateTokenOverride?: TGetAndValidateToken;
14
- COGNITO_USER_POOL_ID: string;
15
- /** pass in openapi schema. eg require('common/openapi.generated').default; */
16
- schema: any;
17
- event: APIGatewayEvent;
18
- next: NextType<T>;
19
- /** default false */
20
- authorized?: true | false | 'optional';
21
- /**
22
- * default ap-southeast-2
23
- */
24
- jwksRegion?: string;
25
- }): Promise<APIGatewayProxyResult>;