ag-common 0.0.320 → 0.0.321
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/dynamo.d.ts +1 -3
- package/dist/api/helpers/dynamo.js +11 -12
- package/dist/api/helpers/s3.d.ts +6 -2
- package/dist/api/helpers/s3.js +7 -2
- package/dist/api/helpers/ses.d.ts +6 -2
- package/dist/api/helpers/ses.js +6 -1
- package/dist/api/helpers/sqs.d.ts +3 -1
- package/dist/api/helpers/sqs.js +3 -4
- package/package.json +1 -1
|
@@ -7,9 +7,7 @@ export declare const putDynamo: <T>(item: T, tableName: string) => Promise<{
|
|
|
7
7
|
data?: T | undefined;
|
|
8
8
|
}>;
|
|
9
9
|
export declare const batchWrite: <T extends {}>(tableName: string, itemsIn: T[], breakOnError?: boolean) => Promise<{
|
|
10
|
-
error
|
|
11
|
-
} | {
|
|
12
|
-
error?: undefined;
|
|
10
|
+
error?: string | undefined;
|
|
13
11
|
}>;
|
|
14
12
|
export declare const batchDelete: ({ tableName, breakOnError, pkName, keys, rangeName, rangeKeys, }: {
|
|
15
13
|
pkName: string;
|
|
@@ -33,10 +33,8 @@ const putDynamo = (item, tableName) => __awaiter(void 0, void 0, void 0, functio
|
|
|
33
33
|
(0, log_1.info)(`running dynamo put=${JSON.stringify(params, null, 2)}`);
|
|
34
34
|
// write the todo to the database
|
|
35
35
|
const put = yield exports.dynamoDb.put(params).promise();
|
|
36
|
-
if (put.$response.error &&
|
|
37
|
-
put.$response.error.
|
|
38
|
-
put.$response.error.statusCode >= 400) {
|
|
39
|
-
throw new Error(put.$response.error.message);
|
|
36
|
+
if (put.$response.error && put.$response.error.statusCode) {
|
|
37
|
+
return { error: put.$response.error.message };
|
|
40
38
|
}
|
|
41
39
|
// put never returns into, so just use what we have already
|
|
42
40
|
return { data: item };
|
|
@@ -53,6 +51,9 @@ let batchWriteRaw = (req) => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
53
51
|
RequestItems: req,
|
|
54
52
|
})
|
|
55
53
|
.promise();
|
|
54
|
+
if (res.$response.error) {
|
|
55
|
+
throw new Error(res.$response.error.message);
|
|
56
|
+
}
|
|
56
57
|
return res;
|
|
57
58
|
}
|
|
58
59
|
catch (e) {
|
|
@@ -153,9 +154,7 @@ const scan = (tableName) => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
153
154
|
.scan({ TableName: tableName, ExclusiveStartKey })
|
|
154
155
|
.promise();
|
|
155
156
|
ExclusiveStartKey = LastEvaluatedKey;
|
|
156
|
-
if ($response.error &&
|
|
157
|
-
$response.error.statusCode &&
|
|
158
|
-
$response.error.statusCode >= 400) {
|
|
157
|
+
if ($response.error && $response.error.statusCode) {
|
|
159
158
|
throw new Error($response.error.message);
|
|
160
159
|
}
|
|
161
160
|
if (newitems) {
|
|
@@ -213,7 +212,7 @@ const getItemsDynamo = ({ tableName, items, }) => __awaiter(void 0, void 0, void
|
|
|
213
212
|
});
|
|
214
213
|
exports.getItemsDynamo = getItemsDynamo;
|
|
215
214
|
const queryDynamo = ({ tableName, pkName, pkValue, pkOperator = '=', skName, skValue, skOperator = '=', indexName, count = 1000, startKey: startKeyIn, filterName, filterValue, filterOperator = '=', sortAscending = true, }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
216
|
-
var _g
|
|
215
|
+
var _g;
|
|
217
216
|
let startKey = startKeyIn;
|
|
218
217
|
let kce = `#${pkName.toLowerCase()} ${pkOperator} :${pkName.toLowerCase()}`;
|
|
219
218
|
const ean = { [`#${pkName.toLowerCase()}`]: pkName };
|
|
@@ -293,7 +292,7 @@ const queryDynamo = ({ tableName, pkName, pkValue, pkOperator = '=', skName, skV
|
|
|
293
292
|
throw e;
|
|
294
293
|
}
|
|
295
294
|
startKey = lek;
|
|
296
|
-
if ($response.error
|
|
295
|
+
if ($response.error) {
|
|
297
296
|
(0, log_1.error)('error. query params=', JSON.stringify(params));
|
|
298
297
|
throw new Error($response.error.message);
|
|
299
298
|
}
|
|
@@ -301,7 +300,7 @@ const queryDynamo = ({ tableName, pkName, pkValue, pkOperator = '=', skName, skV
|
|
|
301
300
|
if (newitems) {
|
|
302
301
|
Items.push(...newitems.map((r) => r));
|
|
303
302
|
}
|
|
304
|
-
if (count > 0 && ((
|
|
303
|
+
if (count > 0 && ((_g = newitems === null || newitems === void 0 ? void 0 : newitems.length) !== null && _g !== void 0 ? _g : 0) >= count) {
|
|
305
304
|
return { Items, startKey };
|
|
306
305
|
}
|
|
307
306
|
} while (startKey && Object.keys(startKey).length > 0);
|
|
@@ -311,7 +310,7 @@ exports.queryDynamo = queryDynamo;
|
|
|
311
310
|
const getDynamoTtl = (days) => Math.ceil(new Date().getTime() / 1000) + days * 86400;
|
|
312
311
|
exports.getDynamoTtl = getDynamoTtl;
|
|
313
312
|
const wipeTable = (tableName) => __awaiter(void 0, void 0, void 0, function* () {
|
|
314
|
-
var
|
|
313
|
+
var _h;
|
|
315
314
|
const dbRaw = new dynamodb_1.default({ apiVersion: '2012-10-08' });
|
|
316
315
|
let infoV = yield dbRaw
|
|
317
316
|
.describeTable({
|
|
@@ -326,7 +325,7 @@ const wipeTable = (tableName) => __awaiter(void 0, void 0, void 0, function* ()
|
|
|
326
325
|
TableName: tableName,
|
|
327
326
|
})
|
|
328
327
|
.promise();
|
|
329
|
-
(0, log_1.warn)(`will delete ${(
|
|
328
|
+
(0, log_1.warn)(`will delete ${(_h = all === null || all === void 0 ? void 0 : all.Items) === null || _h === void 0 ? void 0 : _h.length} items from ${tableName}`);
|
|
330
329
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
331
330
|
// @ts-ignore
|
|
332
331
|
const datagr = (0, array_1.chunk)(all.Items, 25);
|
package/dist/api/helpers/s3.d.ts
CHANGED
|
@@ -13,7 +13,9 @@ export declare const putS3Object: ({ Body, Bucket, Key, ContentType, }: {
|
|
|
13
13
|
Body: string | Blob;
|
|
14
14
|
Bucket: string;
|
|
15
15
|
Key: string;
|
|
16
|
-
}) => Promise<
|
|
16
|
+
}) => Promise<{
|
|
17
|
+
error?: string;
|
|
18
|
+
}>;
|
|
17
19
|
export declare const uploadFile: ({ Bucket, Key, Body, }: {
|
|
18
20
|
Bucket: string;
|
|
19
21
|
Key: string;
|
|
@@ -22,4 +24,6 @@ export declare const uploadFile: ({ Bucket, Key, Body, }: {
|
|
|
22
24
|
export declare const deleteFile: ({ Bucket, Key, }: {
|
|
23
25
|
Bucket: string;
|
|
24
26
|
Key: string;
|
|
25
|
-
}) => Promise<
|
|
27
|
+
}) => Promise<{
|
|
28
|
+
error?: string;
|
|
29
|
+
}>;
|
package/dist/api/helpers/s3.js
CHANGED
|
@@ -25,7 +25,7 @@ const getS3Object = ({ fileurl, }) => __awaiter(void 0, void 0, void 0, function
|
|
|
25
25
|
});
|
|
26
26
|
exports.getS3Object = getS3Object;
|
|
27
27
|
const putS3Object = ({ Body, Bucket, Key, ContentType, }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
28
|
-
yield s3
|
|
28
|
+
const r = yield s3
|
|
29
29
|
.putObject({
|
|
30
30
|
Body,
|
|
31
31
|
Bucket,
|
|
@@ -33,6 +33,10 @@ const putS3Object = ({ Body, Bucket, Key, ContentType, }) => __awaiter(void 0, v
|
|
|
33
33
|
ContentType,
|
|
34
34
|
})
|
|
35
35
|
.promise();
|
|
36
|
+
if (r.$response.error) {
|
|
37
|
+
return { error: r.$response.error.message };
|
|
38
|
+
}
|
|
39
|
+
return {};
|
|
36
40
|
});
|
|
37
41
|
exports.putS3Object = putS3Object;
|
|
38
42
|
const uploadFile = ({ Bucket, Key, Body, }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
@@ -43,7 +47,8 @@ exports.uploadFile = uploadFile;
|
|
|
43
47
|
const deleteFile = ({ Bucket, Key, }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
44
48
|
const res = yield s3.deleteObject({ Bucket, Key }).promise();
|
|
45
49
|
if (res.$response.error) {
|
|
46
|
-
|
|
50
|
+
return { error: res.$response.error.message };
|
|
47
51
|
}
|
|
52
|
+
return {};
|
|
48
53
|
});
|
|
49
54
|
exports.deleteFile = deleteFile;
|
|
@@ -8,5 +8,9 @@ export interface ISendEmail {
|
|
|
8
8
|
sourceArn: string;
|
|
9
9
|
from: string;
|
|
10
10
|
}
|
|
11
|
-
export declare const sendEmail: ({ to, message, subject, sourceArn, from, }: ISendEmail) => Promise<
|
|
12
|
-
|
|
11
|
+
export declare const sendEmail: ({ to, message, subject, sourceArn, from, }: ISendEmail) => Promise<{
|
|
12
|
+
error?: string;
|
|
13
|
+
}>;
|
|
14
|
+
export declare const sendEmails: (emails: ISendEmail[]) => Promise<{
|
|
15
|
+
error?: string | undefined;
|
|
16
|
+
}[]>;
|
package/dist/api/helpers/ses.js
CHANGED
|
@@ -20,6 +20,7 @@ const setSes = (region) => {
|
|
|
20
20
|
};
|
|
21
21
|
exports.setSes = setSes;
|
|
22
22
|
const sendEmail = ({ to, message, subject, sourceArn, from, }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
23
|
+
var _a;
|
|
23
24
|
// Create sendEmail params
|
|
24
25
|
const params = {
|
|
25
26
|
Destination: {
|
|
@@ -42,7 +43,11 @@ const sendEmail = ({ to, message, subject, sourceArn, from, }) => __awaiter(void
|
|
|
42
43
|
ReplyToAddresses: [from],
|
|
43
44
|
SourceArn: sourceArn,
|
|
44
45
|
};
|
|
45
|
-
yield exports.ses.sendEmail(params).promise();
|
|
46
|
+
const res = yield exports.ses.sendEmail(params).promise();
|
|
47
|
+
if (res.$response.error) {
|
|
48
|
+
return { error: (_a = res.$response.error) === null || _a === void 0 ? void 0 : _a.message };
|
|
49
|
+
}
|
|
50
|
+
return {};
|
|
46
51
|
});
|
|
47
52
|
exports.sendEmail = sendEmail;
|
|
48
53
|
const sendEmails = (emails) => __awaiter(void 0, void 0, void 0, function* () { return Promise.all(emails.map(exports.sendEmail)); });
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import SQS from 'aws-sdk/clients/sqs';
|
|
2
2
|
export declare let sqs: SQS;
|
|
3
3
|
export declare const setSqs: (region: string) => void;
|
|
4
|
-
export declare const sendMessages: <T>(items: T[], queueUrl: string) => Promise<
|
|
4
|
+
export declare const sendMessages: <T>(items: T[], queueUrl: string) => Promise<{
|
|
5
|
+
error?: string;
|
|
6
|
+
}>;
|
package/dist/api/helpers/sqs.js
CHANGED
|
@@ -30,10 +30,9 @@ const sendMessages = (items, queueUrl) => __awaiter(void 0, void 0, void 0, func
|
|
|
30
30
|
})),
|
|
31
31
|
};
|
|
32
32
|
const put = yield exports.sqs.sendMessageBatch(req).promise();
|
|
33
|
-
if (put.$response.error &&
|
|
34
|
-
put.$response.error.
|
|
35
|
-
put.$response.error.statusCode >= 400) {
|
|
36
|
-
throw new Error(put.$response.error.message);
|
|
33
|
+
if (put.$response.error && put.$response.error.statusCode) {
|
|
34
|
+
return { error: put.$response.error.message };
|
|
37
35
|
}
|
|
36
|
+
return {};
|
|
38
37
|
});
|
|
39
38
|
exports.sendMessages = sendMessages;
|