ag-common 0.0.355 → 0.0.357
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.
package/dist/api/helpers/s3.js
CHANGED
|
@@ -86,7 +86,9 @@ const deleteFile = ({ Bucket, Key, }) => __awaiter(void 0, void 0, void 0, funct
|
|
|
86
86
|
});
|
|
87
87
|
exports.deleteFile = deleteFile;
|
|
88
88
|
const deleteFiles = ({ Bucket, Keys, }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
89
|
+
var _a;
|
|
89
90
|
let toDelete = Keys.map((Key) => ({ Key }));
|
|
91
|
+
let deleted = 0;
|
|
90
92
|
while (toDelete.length > 0) {
|
|
91
93
|
const { part, rest } = (0, array_1.take)(toDelete, 900);
|
|
92
94
|
toDelete = rest;
|
|
@@ -96,9 +98,14 @@ const deleteFiles = ({ Bucket, Keys, }) => __awaiter(void 0, void 0, void 0, fun
|
|
|
96
98
|
Delete: { Objects: part },
|
|
97
99
|
})
|
|
98
100
|
.promise();
|
|
101
|
+
if (!((_a = res.Deleted) === null || _a === void 0 ? void 0 : _a.length)) {
|
|
102
|
+
throw new Error('no deleted files');
|
|
103
|
+
}
|
|
104
|
+
deleted += res.Deleted.length;
|
|
99
105
|
if (res.$response.error) {
|
|
100
106
|
return { error: res.$response.error.message };
|
|
101
107
|
}
|
|
108
|
+
(0, log_1.info)(`deleted ${deleted} files`);
|
|
102
109
|
}
|
|
103
110
|
return {};
|
|
104
111
|
});
|
|
@@ -44,7 +44,7 @@ const getOperation = ({ path, method, resource, schema, }) => {
|
|
|
44
44
|
return { operation, pathParams };
|
|
45
45
|
};
|
|
46
46
|
function validateOpenApi({ event, next, authorized, schema, COGNITO_USER_POOL_ID, jwksRegion = 'ap-southeast-2', getAndValidateTokenOverride, }) {
|
|
47
|
-
var _a, _b, _c, _d, _e;
|
|
47
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
48
48
|
return __awaiter(this, void 0, void 0, function* () {
|
|
49
49
|
if (!schema) {
|
|
50
50
|
throw new Error('schema undefined!');
|
|
@@ -86,13 +86,15 @@ function validateOpenApi({ event, next, authorized, schema, COGNITO_USER_POOL_ID
|
|
|
86
86
|
else {
|
|
87
87
|
try {
|
|
88
88
|
request.params = opm.pathParams;
|
|
89
|
-
(0, log_1.info)('req=', JSON.stringify(request, null
|
|
89
|
+
(0, log_1.info)('req=', JSON.stringify(Object.assign(Object.assign({}, request), { body: ((_b = (_a = request.body) === null || _a === void 0 ? void 0 : _a.length) !== null && _b !== void 0 ? _b : 0) > 2000
|
|
90
|
+
? '(truncating long body)'
|
|
91
|
+
: request.body }), null, 2));
|
|
90
92
|
const resp = new openapi_request_validator_1.default(Object.assign(Object.assign({}, opm.operation), { schemas: schema.components.schemas })).validateRequest(request);
|
|
91
93
|
if (resp) {
|
|
92
94
|
(0, log_1.warn)('bad request');
|
|
93
95
|
(0, log_1.warn)('opm=', JSON.stringify(opm, null, 2));
|
|
94
96
|
(0, log_1.warn)('resp=', JSON.stringify(resp, null, 2));
|
|
95
|
-
return (0, api_1.returnCode)(400, `error:${(
|
|
97
|
+
return (0, api_1.returnCode)(400, `error:${(_d = (_c = resp === null || resp === void 0 ? void 0 : resp.errors) === null || _c === void 0 ? void 0 : _c[0]) === null || _d === void 0 ? void 0 : _d.message}`);
|
|
96
98
|
}
|
|
97
99
|
(0, log_1.debug)(`validated request:`, event.path);
|
|
98
100
|
}
|
|
@@ -102,7 +104,7 @@ function validateOpenApi({ event, next, authorized, schema, COGNITO_USER_POOL_ID
|
|
|
102
104
|
}
|
|
103
105
|
let userProfile;
|
|
104
106
|
let error;
|
|
105
|
-
const authHeader = ((
|
|
107
|
+
const authHeader = ((_e = event.headers) === null || _e === void 0 ? void 0 : _e.Authorization) || ((_f = event.headers) === null || _f === void 0 ? void 0 : _f.authorization);
|
|
106
108
|
if (authorized === true || (authorized === 'optional' && authHeader)) {
|
|
107
109
|
const vf = getAndValidateTokenOverride !== null && getAndValidateTokenOverride !== void 0 ? getAndValidateTokenOverride : validations_1.getAndValidateToken;
|
|
108
110
|
({ error, userProfile } = yield vf({
|
|
@@ -120,7 +122,7 @@ function validateOpenApi({ event, next, authorized, schema, COGNITO_USER_POOL_ID
|
|
|
120
122
|
event,
|
|
121
123
|
body: (0, object_1.tryJsonParse)(event.body, event.body),
|
|
122
124
|
userProfile,
|
|
123
|
-
lang: (0, i18n_1.getValidatedLang)((
|
|
125
|
+
lang: (0, i18n_1.getValidatedLang)((_g = event.headers['x-lang']) !== null && _g !== void 0 ? _g : ''),
|
|
124
126
|
});
|
|
125
127
|
return res;
|
|
126
128
|
});
|