ag-common 0.0.86 → 0.0.90

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.
@@ -1,13 +1,13 @@
1
1
  import { aws_certificatemanager as certmgr, aws_route53 as route53 } from 'aws-cdk-lib';
2
2
  import { Construct } from 'constructs';
3
- import { ILambdaPermissions } from '../types';
3
+ import { ILambdaConfigs } from '../types';
4
4
  export declare const openApiImpl: (p: {
5
5
  schema: any;
6
6
  stack: Construct;
7
7
  NODE_ENV: string;
8
8
  baseUrl: string;
9
9
  endpointsBase: string;
10
- lambdaPermissions: ILambdaPermissions;
10
+ lambdaConfig: ILambdaConfigs;
11
11
  certificate: certmgr.ICertificate;
12
12
  hostedZone: route53.IHostedZone;
13
13
  shortStackName: string;
@@ -34,17 +34,17 @@ const setUpApiGw = ({ stack, NODE_ENV, baseUrl, certificate, hostedZone, shortSt
34
34
  });
35
35
  return api;
36
36
  };
37
- const setupLambda = ({ lambdaPermissions, pathV, verb, seenPermissions, }) => {
37
+ const setupLambda = ({ lambdaConfig, pathV, verb, seenPermissions, }) => {
38
38
  var _a, _b, _c, _d;
39
39
  const pathCompute = pathV + '/' + verb;
40
- const lp = lambdaPermissions === null || lambdaPermissions === void 0 ? void 0 : lambdaPermissions[pathCompute];
40
+ const lp = lambdaConfig === null || lambdaConfig === void 0 ? void 0 : lambdaConfig[pathCompute];
41
41
  if (lp) {
42
42
  seenPermissions[pathCompute] = true;
43
43
  }
44
44
  else {
45
45
  seenPermissions[pathCompute] = false;
46
46
  }
47
- const def = lambdaPermissions === null || lambdaPermissions === void 0 ? void 0 : lambdaPermissions.default;
47
+ const def = lambdaConfig === null || lambdaConfig === void 0 ? void 0 : lambdaConfig.default;
48
48
  if (def) {
49
49
  seenPermissions.default = true;
50
50
  }
@@ -52,13 +52,14 @@ const setupLambda = ({ lambdaPermissions, pathV, verb, seenPermissions, }) => {
52
52
  const readTables = (0, distinctBy_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);
53
53
  const writeTables = (0, distinctBy_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);
54
54
  const policies = [...(def.policies || []), ...((lp === null || lp === void 0 ? void 0 : lp.policies) || [])].filter(__1.notEmpty);
55
+ const layers = [...(def.layers || []), ...((lp === null || lp === void 0 ? void 0 : lp.layers) || [])].filter(__1.notEmpty);
55
56
  const env = Object.assign(Object.assign({}, (def.env || {})), ((lp === null || lp === void 0 ? void 0 : lp.env) || {}));
56
57
  const tables = [...readTables, ...writeTables];
57
58
  const environment = env;
58
59
  Object.values(tables).forEach((v) => {
59
60
  environment[v.shortName] = v.table.tableName;
60
61
  });
61
- return { environment, readTables, writeTables, policies };
62
+ return { environment, readTables, writeTables, policies, layers };
62
63
  };
63
64
  const addApiPaths = (api, pathList, apiRoots) => {
64
65
  let pathBuild = '';
@@ -83,7 +84,7 @@ const openApiImpl = (p) => {
83
84
  if (!p.schema) {
84
85
  throw new Error('no openapi schema found');
85
86
  }
86
- const { stack, NODE_ENV, endpointsBase, lambdaPermissions } = p;
87
+ const { stack, NODE_ENV, endpointsBase, lambdaConfig } = p;
87
88
  const paths = getPaths(p.schema);
88
89
  const api = setUpApiGw(p);
89
90
  const apiRoots = {};
@@ -91,8 +92,8 @@ const openApiImpl = (p) => {
91
92
  paths.forEach(({ fullPath, verbs, pathList }) => {
92
93
  const apiPath = addApiPaths(api, pathList, apiRoots);
93
94
  verbs.forEach((verb) => {
94
- const { environment, readTables, writeTables, policies } = setupLambda({
95
- lambdaPermissions,
95
+ const { environment, readTables, writeTables, policies, layers } = setupLambda({
96
+ lambdaConfig,
96
97
  pathV: fullPath,
97
98
  verb,
98
99
  seenPermissions,
@@ -113,6 +114,7 @@ const openApiImpl = (p) => {
113
114
  },
114
115
  reservedConcurrentExecutions: 5,
115
116
  logRetention: aws_cdk_lib_1.aws_logs.RetentionDays.FIVE_DAYS,
117
+ layers,
116
118
  });
117
119
  readTables.forEach((t) => t.table.grantReadData(lambdaV));
118
120
  writeTables.forEach((t) => t.table.grantReadWriteData(lambdaV));
@@ -121,7 +123,7 @@ const openApiImpl = (p) => {
121
123
  apiPath.addMethod(verb.toUpperCase(), new aws_cdk_lib_1.aws_apigateway.LambdaIntegration(lambdaV, {}));
122
124
  });
123
125
  });
124
- Object.keys(lambdaPermissions).forEach((k) => {
126
+ Object.keys(lambdaConfig).forEach((k) => {
125
127
  if (!seenPermissions[k] || seenPermissions[k] === false) {
126
128
  (0, log_1.warn)(`unused permissions for '${k}', did you mean one of these paths?=`, Object.entries(seenPermissions)
127
129
  .filter(([, b]) => !b)
@@ -1,3 +1,4 @@
1
+ /// <reference types="node" />
1
2
  import { Blob } from 'aws-sdk/lib/dynamodb/document_client';
2
3
  import AWS from 'aws-sdk';
3
4
  export declare const setS3: (region: string) => void;
@@ -13,3 +14,12 @@ export declare const putS3Object: ({ Body, Bucket, Key, ContentType, }: {
13
14
  Bucket: string;
14
15
  Key: string;
15
16
  }) => Promise<void>;
17
+ export declare const uploadFile: ({ Bucket, Key, Body, }: {
18
+ Bucket: string;
19
+ Key: string;
20
+ Body: Buffer | Uint8Array | Blob | string;
21
+ }) => Promise<string>;
22
+ export declare const deleteFile: ({ Bucket, Key, }: {
23
+ Bucket: string;
24
+ Key: string;
25
+ }) => Promise<void>;
@@ -12,7 +12,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
12
12
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
13
  };
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.putS3Object = exports.getS3Object = exports.setS3 = void 0;
15
+ exports.deleteFile = exports.uploadFile = exports.putS3Object = exports.getS3Object = exports.setS3 = void 0;
16
16
  const aws_sdk_1 = __importDefault(require("aws-sdk"));
17
17
  let s3 = new aws_sdk_1.default.S3();
18
18
  const setS3 = (region) => {
@@ -35,3 +35,15 @@ const putS3Object = ({ Body, Bucket, Key, ContentType, }) => __awaiter(void 0, v
35
35
  .promise();
36
36
  });
37
37
  exports.putS3Object = putS3Object;
38
+ const uploadFile = ({ Bucket, Key, Body, }) => __awaiter(void 0, void 0, void 0, function* () {
39
+ const res = yield s3.upload({ Bucket, Key, Body }).promise();
40
+ return res.Location;
41
+ });
42
+ exports.uploadFile = uploadFile;
43
+ const deleteFile = ({ Bucket, Key, }) => __awaiter(void 0, void 0, void 0, function* () {
44
+ const res = yield s3.deleteObject({ Bucket, Key }).promise();
45
+ if (res.$response.error) {
46
+ throw res.$response.error;
47
+ }
48
+ });
49
+ exports.deleteFile = deleteFile;
@@ -1,4 +1,4 @@
1
- import { aws_dynamodb as dynamodb, aws_iam as iam } from 'aws-cdk-lib';
1
+ import { aws_dynamodb as dynamodb, aws_iam as iam, aws_lambda as lambda } from 'aws-cdk-lib';
2
2
  import { Key } from './aws';
3
3
  export interface DYNAMOKEYS {
4
4
  type: string;
@@ -17,17 +17,18 @@ export interface IGeneratedDynamoData {
17
17
  table: dynamodb.ITable;
18
18
  shortName: string;
19
19
  }
20
- export interface ILambdaPermission {
20
+ export interface ILambdaConfig {
21
21
  dynamo?: {
22
22
  reads?: IGeneratedDynamoData[];
23
23
  writes?: IGeneratedDynamoData[];
24
24
  };
25
25
  policies?: iam.PolicyStatement[];
26
26
  env?: Record<string, string>;
27
+ layers?: lambda.ILayerVersion[];
27
28
  }
28
- export interface ILambdaPermissions {
29
- [pathHyphenVerb: string]: ILambdaPermission & {
30
- default?: ILambdaPermission;
29
+ export interface ILambdaConfigs {
30
+ [pathHyphenVerb: string]: ILambdaConfig & {
31
+ default?: ILambdaConfig;
31
32
  };
32
33
  }
33
34
  export interface IQueryDynamo {
@@ -1,4 +1,3 @@
1
- /// <reference types="react" />
2
1
  export declare type TOnMessage = (m: string, options?: {
3
2
  appearance: 'error' | 'success';
4
3
  }) => void;
@@ -12,20 +11,3 @@ export interface ICognitoAuth {
12
11
  cognitoRefresh: string;
13
12
  vendToken: string;
14
13
  }
15
- export interface ICognitoAuthProviderProps {
16
- redirectUrl?: string;
17
- location: {
18
- pathname: string;
19
- hash: string;
20
- search: string;
21
- origin: string;
22
- };
23
- goToPageUrl: ({ url, state, login, }: {
24
- url: string;
25
- state?: any;
26
- login: boolean;
27
- }) => Promise<void>;
28
- children: JSX.Element | JSX.Element[];
29
- config: ICognitoAuth;
30
- onMessage?: TOnMessage;
31
- }
@@ -1,7 +1,5 @@
1
- /// <reference types="react" />
2
1
  import { TLang } from '../..';
3
- import { ICognitoAuth, ICognitoAuthProviderProps } from './cognito';
4
- import { AuthedUserContext } from './jwt';
2
+ import { ICognitoAuth } from './cognito';
5
3
  export interface LocationSubset {
6
4
  pathname: string;
7
5
  hash: string;
@@ -30,7 +28,5 @@ export interface IRequestCommon {
30
28
  export interface IStateCommon<TRequest extends IRequestCommon> extends IInitialStateCommon {
31
29
  request: TRequest;
32
30
  auth: ICognitoAuth;
33
- CognitoAuthContext: React.Context<AuthedUserContext>;
34
- CognitoAuthProvider: (p: ICognitoAuthProviderProps) => JSX.Element;
35
31
  pushPath: (path: string) => Promise<void>;
36
32
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ag-common",
3
- "version": "0.0.86",
3
+ "version": "0.0.90",
4
4
  "main": "./dist/index.js",
5
5
  "types": "./dist/index.d.ts",
6
6
  "author": "Andrei Gec <@andreigec> (https://gec.dev/)",