ag-common 0.0.83 → 0.0.87

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.
@@ -34,7 +34,8 @@ const setUpApiGw = ({ stack, NODE_ENV, baseUrl, certificate, hostedZone, shortSt
34
34
  });
35
35
  return api;
36
36
  };
37
- const getDynamoPermissions = ({ lambdaPermissions, pathV, verb, seenPermissions, }) => {
37
+ const setupLambda = ({ lambdaPermissions, pathV, verb, seenPermissions, }) => {
38
+ var _a, _b, _c, _d;
38
39
  const pathCompute = pathV + '/' + verb;
39
40
  const lp = lambdaPermissions === null || lambdaPermissions === void 0 ? void 0 : lambdaPermissions[pathCompute];
40
41
  if (lp) {
@@ -48,11 +49,12 @@ const getDynamoPermissions = ({ lambdaPermissions, pathV, verb, seenPermissions,
48
49
  seenPermissions.default = true;
49
50
  }
50
51
  //
51
- const readTables = (0, distinctBy_1.distinctBy)([...((def === null || def === void 0 ? void 0 : def.reads) || []), ...((lp === null || lp === void 0 ? void 0 : lp.reads) || [])], (s) => s.shortName);
52
- const writeTables = (0, distinctBy_1.distinctBy)([...((def === null || def === void 0 ? void 0 : def.writes) || []), ...((lp === null || lp === void 0 ? void 0 : lp.writes) || [])], (s) => s.shortName);
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
+ 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);
53
54
  const policies = [...(def.policies || []), ...((lp === null || lp === void 0 ? void 0 : lp.policies) || [])].filter(__1.notEmpty);
55
+ const env = Object.assign(Object.assign({}, (def.env || {})), ((lp === null || lp === void 0 ? void 0 : lp.env) || {}));
54
56
  const tables = [...readTables, ...writeTables];
55
- const environment = {};
57
+ const environment = env;
56
58
  Object.values(tables).forEach((v) => {
57
59
  environment[v.shortName] = v.table.tableName;
58
60
  });
@@ -89,7 +91,7 @@ const openApiImpl = (p) => {
89
91
  paths.forEach(({ fullPath, verbs, pathList }) => {
90
92
  const apiPath = addApiPaths(api, pathList, apiRoots);
91
93
  verbs.forEach((verb) => {
92
- const { environment, readTables, writeTables, policies } = getDynamoPermissions({
94
+ const { environment, readTables, writeTables, policies } = setupLambda({
93
95
  lambdaPermissions,
94
96
  pathV: fullPath,
95
97
  verb,
@@ -13,3 +13,12 @@ export declare const putS3Object: ({ Body, Bucket, Key, ContentType, }: {
13
13
  Bucket: string;
14
14
  Key: string;
15
15
  }) => Promise<void>;
16
+ export declare const uploadFile: ({ Bucket, Key, Body, }: {
17
+ Bucket: string;
18
+ Key: string;
19
+ Body: string;
20
+ }) => Promise<string>;
21
+ export declare const deleteFile: ({ Bucket, Key, }: {
22
+ Bucket: string;
23
+ Key: string;
24
+ }) => 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;
@@ -58,7 +58,7 @@ function validateOpenApi({ event, next, authorized, schema, COGNITO_USER_POOL_ID
58
58
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
59
59
  params: undefined,
60
60
  query: event.queryStringParameters,
61
- body: event.body && JSON.parse(event.body),
61
+ body: (0, object_1.tryJsonParse)(event.body, event.body),
62
62
  headers: (0, object_1.objectKeysToLowerCase)(event === null || event === void 0 ? void 0 : event.headers),
63
63
  };
64
64
  const method = event.requestContext.httpMethod.toLowerCase();
@@ -116,7 +116,7 @@ function validateOpenApi({ event, next, authorized, schema, COGNITO_USER_POOL_ID
116
116
  const res = yield next({
117
117
  params,
118
118
  event,
119
- body: (event.body && JSON.parse(event.body)),
119
+ body: (0, object_1.tryJsonParse)(event.body, event.body),
120
120
  userProfile,
121
121
  lang: (0, i18n_1.getValidatedLang)((_e = event.headers['x-lang']) !== null && _e !== void 0 ? _e : ''),
122
122
  });
@@ -17,17 +17,17 @@ export interface IGeneratedDynamoData {
17
17
  table: dynamodb.ITable;
18
18
  shortName: string;
19
19
  }
20
- export interface ILambdaPermissions {
21
- [pathHyphenVerb: string]: {
20
+ export interface ILambdaPermission {
21
+ dynamo?: {
22
22
  reads?: IGeneratedDynamoData[];
23
23
  writes?: IGeneratedDynamoData[];
24
- policies?: iam.PolicyStatement[];
25
- } & {
26
- default?: {
27
- reads?: IGeneratedDynamoData[];
28
- writes?: IGeneratedDynamoData[];
29
- policies?: iam.PolicyStatement[];
30
- };
24
+ };
25
+ policies?: iam.PolicyStatement[];
26
+ env?: Record<string, string>;
27
+ }
28
+ export interface ILambdaPermissions {
29
+ [pathHyphenVerb: string]: ILambdaPermission & {
30
+ default?: ILambdaPermission;
31
31
  };
32
32
  }
33
33
  export interface IQueryDynamo {
@@ -10,4 +10,5 @@ export interface ICallOpenApi<T, TDefaultApi> {
10
10
  logout: () => void;
11
11
  refreshToken: () => Promise<User | undefined>;
12
12
  newDefaultApi: (config: any) => TDefaultApi;
13
+ disabled?: boolean;
13
14
  }
@@ -34,7 +34,7 @@ const useCallOpenApi = (p) => {
34
34
  });
35
35
  }
36
36
  const { error, loaded, loading, loadcount } = data;
37
- if (loaded || loading || (error && loadcount < 2)) {
37
+ if (p.disabled || loaded || loading || (error && loadcount < 2)) {
38
38
  return;
39
39
  }
40
40
  setData((d) => (Object.assign(Object.assign({}, d), { loading: true })));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ag-common",
3
- "version": "0.0.83",
3
+ "version": "0.0.87",
4
4
  "main": "./dist/index.js",
5
5
  "types": "./dist/index.d.ts",
6
6
  "author": "Andrei Gec <@andreigec> (https://gec.dev/)",
@@ -13,7 +13,7 @@
13
13
  "start": "tsc --watch"
14
14
  },
15
15
  "dependencies": {
16
- "aws-sdk": "2.1060.0",
16
+ "aws-sdk": "2.1062.0",
17
17
  "axios": "0.25.0",
18
18
  "jsonwebtoken": "8.5.1",
19
19
  "jwks-rsa": "2.0.5",
@@ -31,7 +31,7 @@
31
31
  "@types/node": "17.0.10",
32
32
  "@types/react": "17.0.38",
33
33
  "@types/react-dom": "17.0.11",
34
- "@types/styled-components": "5.1.20",
34
+ "@types/styled-components": "5.1.21",
35
35
  "@typescript-eslint/eslint-plugin": "5.10.0",
36
36
  "@typescript-eslint/parser": "5.10.0",
37
37
  "eslint": "8.7.0",