ag-common 0.0.75 → 0.0.79

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.
@@ -11,11 +11,13 @@ export declare const batchWrite: <T extends {}>(tableName: string, itemsIn: T[],
11
11
  } | {
12
12
  error?: undefined;
13
13
  }>;
14
- export declare const batchDelete: ({ tableName, keys, breakOnError, pkName, }: {
14
+ export declare const batchDelete: ({ tableName, breakOnError, pkName, keys, rangeName, rangeKeys, }: {
15
15
  pkName: string;
16
16
  breakOnError?: boolean | undefined;
17
17
  tableName: string;
18
18
  keys: string[];
19
+ rangeName?: string | undefined;
20
+ rangeKeys?: string[] | undefined;
19
21
  }) => Promise<{
20
22
  error: string;
21
23
  } | {
@@ -17,6 +17,7 @@ const aws_sdk_1 = __importDefault(require("aws-sdk"));
17
17
  const log_1 = require("../../common/helpers/log");
18
18
  const array_1 = require("../../common/helpers/array");
19
19
  const sleep_1 = require("../../common/helpers/sleep");
20
+ const async_1 = require("../../common/helpers/async");
20
21
  // eslint-disable-next-line import/no-mutable-exports
21
22
  exports.dynamoDb = new aws_sdk_1.default.DynamoDB.DocumentClient();
22
23
  const setDynamo = (region) => {
@@ -106,21 +107,26 @@ const batchWrite = (tableName, itemsIn, breakOnError = false) => __awaiter(void
106
107
  return {};
107
108
  });
108
109
  exports.batchWrite = batchWrite;
109
- const batchDelete = ({ tableName, keys, breakOnError = true, pkName, }) => __awaiter(void 0, void 0, void 0, function* () {
110
- var _c, _d;
110
+ const batchDelete = ({ tableName, breakOnError = true, pkName, keys, rangeName, rangeKeys, }) => __awaiter(void 0, void 0, void 0, function* () {
111
111
  (0, log_1.info)(`wipe keys dynamo:${tableName} - count=${keys.length}`);
112
112
  const error = [];
113
113
  let breakV = false;
114
- for (let key of keys) {
114
+ yield (0, async_1.asyncForEach)(keys, (key, i) => __awaiter(void 0, void 0, void 0, function* () {
115
+ var _c, _d;
115
116
  if (breakV) {
116
- break;
117
+ return;
117
118
  }
118
- const res = yield exports.dynamoDb
119
- .delete({
119
+ let params = {
120
120
  TableName: tableName,
121
- Key: { [`${pkName}`]: key },
122
- })
123
- .promise();
121
+ Key: { [pkName]: key },
122
+ };
123
+ if (rangeName) {
124
+ let rangeValue = rangeKeys === null || rangeKeys === void 0 ? void 0 : rangeKeys[i];
125
+ if (rangeValue) {
126
+ params.Key[rangeName] = rangeValue;
127
+ }
128
+ }
129
+ const res = yield exports.dynamoDb.delete(params).promise();
124
130
  const newError = (_d = (_c = res.$response) === null || _c === void 0 ? void 0 : _c.error) !== null && _d !== void 0 ? _d : null;
125
131
  if (newError) {
126
132
  error.push(newError);
@@ -128,7 +134,7 @@ const batchDelete = ({ tableName, keys, breakOnError = true, pkName, }) => __awa
128
134
  breakV = true;
129
135
  }
130
136
  }
131
- }
137
+ }));
132
138
  if ((error === null || error === void 0 ? void 0 : error.length) > 0) {
133
139
  const me = error.join('\n');
134
140
  (0, log_1.error)(`batch write error=${me}`);
@@ -12,8 +12,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.callOpenApi = void 0;
13
13
  const cookie_1 = require("./cookie");
14
14
  const sleep_1 = require("../../common/helpers/sleep");
15
+ const array_1 = require("../../common/helpers/array");
15
16
  const callOpenApi = ({ func, apiUrl, overrideAuth, refreshToken, logout, newDefaultApi, }) => __awaiter(void 0, void 0, void 0, function* () {
16
- var _a, _b, _c, _d, _e, _f;
17
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p;
17
18
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
18
19
  let error;
19
20
  let data;
@@ -49,11 +50,15 @@ const callOpenApi = ({ func, apiUrl, overrideAuth, refreshToken, logout, newDefa
49
50
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
50
51
  const ae = e;
51
52
  const status = (_c = ae.response) === null || _c === void 0 ? void 0 : _c.status;
52
- const errorMessage = (((_d = ae.response) === null || _d === void 0 ? void 0 : _d.data) ||
53
- ((_e = ae.response) === null || _e === void 0 ? void 0 : _e.statusText) ||
54
- ((_f = ae.response) === null || _f === void 0 ? void 0 : _f.status) ||
55
- ae.message ||
56
- 'ERROR');
53
+ const errorMessage = [
54
+ (_f = (_e = (_d = ae.response) === null || _d === void 0 ? void 0 : _d.data) === null || _e === void 0 ? void 0 : _e.toString()) !== null && _f !== void 0 ? _f : '',
55
+ (_j = (_h = (_g = ae.response) === null || _g === void 0 ? void 0 : _g.statusText) === null || _h === void 0 ? void 0 : _h.toString()) !== null && _j !== void 0 ? _j : '',
56
+ (_m = (_l = (_k = ae.response) === null || _k === void 0 ? void 0 : _k.status) === null || _l === void 0 ? void 0 : _l.toString()) !== null && _m !== void 0 ? _m : '',
57
+ (_p = (_o = ae.message) === null || _o === void 0 ? void 0 : _o.toString()) !== null && _p !== void 0 ? _p : '',
58
+ ]
59
+ .filter(array_1.notEmpty)
60
+ .sort((a, b) => (a.length < b.length ? -1 : 1))
61
+ .join('\n');
57
62
  if (status === 403 || status === 401) {
58
63
  logout();
59
64
  return {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ag-common",
3
- "version": "0.0.75",
3
+ "version": "0.0.79",
4
4
  "main": "./dist/index.js",
5
5
  "types": "./dist/index.d.ts",
6
6
  "author": "Andrei Gec <@andreigec> (https://gec.dev/)",
@@ -14,8 +14,8 @@
14
14
  },
15
15
  "dependencies": {
16
16
  "aws-cdk-lib": "2.8.0",
17
- "aws-sdk": "2.1058.0",
18
- "axios": "0.24.0",
17
+ "aws-sdk": "2.1060.0",
18
+ "axios": "0.25.0",
19
19
  "constructs": "10.0.39",
20
20
  "jsonwebtoken": "8.5.1",
21
21
  "jwks-rsa": "2.0.5",
@@ -24,17 +24,17 @@
24
24
  "react-dom": "17.0.2",
25
25
  "react-hot-toast": "2.2.0",
26
26
  "styled-components": "5.3.3",
27
- "typescript": "4.5.4"
27
+ "typescript": "4.5.5"
28
28
  },
29
29
  "devDependencies": {
30
30
  "@types/jsonwebtoken": "8.5.8",
31
- "@types/node": "17.0.9",
31
+ "@types/node": "17.0.10",
32
32
  "@types/react": "17.0.38",
33
33
  "@types/react-dom": "17.0.11",
34
34
  "@types/styled-components": "5.1.20",
35
- "@typescript-eslint/eslint-plugin": "5.9.1",
36
- "@typescript-eslint/parser": "5.9.1",
37
- "eslint": "8.6.0",
35
+ "@typescript-eslint/eslint-plugin": "5.10.0",
36
+ "@typescript-eslint/parser": "5.10.0",
37
+ "eslint": "8.7.0",
38
38
  "eslint-config-airbnb-typescript": "16.1.0",
39
39
  "eslint-config-prettier": "8.3.0",
40
40
  "eslint-config-react-app": "7.0.0",