@8ms/helpers 1.1.85 → 1.1.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.
- package/aws/sqs/addToQueue.d.ts +27 -0
- package/aws/sqs/addToQueue.js +26 -0
- package/aws/sqs/deleteFromQueue.d.ts +10 -0
- package/aws/sqs/deleteFromQueue.js +15 -0
- package/aws/sqs/initClient.d.ts +10 -0
- package/aws/sqs/initClient.js +19 -0
- package/aws/sqs/isEventSqs.d.ts +1 -0
- package/aws/sqs/isEventSqs.js +13 -0
- package/{deepCrawl → deepcrawl/api}/buildRequest.d.ts +0 -0
- package/{deepCrawl → deepcrawl/api}/buildRequest.js +0 -0
- package/{deepCrawl → deepcrawl/api}/filter.d.ts +0 -0
- package/{deepCrawl → deepcrawl/api}/filter.js +0 -0
- package/{deepCrawl → deepcrawl/api}/getData.d.ts +1 -1
- package/{deepCrawl → deepcrawl/api}/getData.js +4 -4
- package/{deepCrawl → deepcrawl/api}/initClient.d.ts +0 -0
- package/{deepCrawl → deepcrawl/api}/initClient.js +4 -4
- package/{deepCrawl → deepcrawl/api}/operands.d.ts +0 -0
- package/{deepCrawl → deepcrawl/api}/operands.js +0 -0
- package/{deepCrawl → deepcrawl/api}/orders.d.ts +0 -0
- package/{deepCrawl → deepcrawl/api}/orders.js +0 -0
- package/{deepCrawl → deepcrawl/api}/reports.d.ts +0 -0
- package/{deepCrawl → deepcrawl/api}/reports.js +0 -0
- package/initClients.d.ts +2 -2
- package/initClients.js +19 -8
- package/package.json +30 -24
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export declare type AddedResponse = {
|
|
2
|
+
'$metadata': {
|
|
3
|
+
httpStatusCode: number;
|
|
4
|
+
requestId: string;
|
|
5
|
+
extendedRequestId: undefined | string;
|
|
6
|
+
cfId: undefined | string;
|
|
7
|
+
attempts: number;
|
|
8
|
+
totalRetryDelay: number;
|
|
9
|
+
};
|
|
10
|
+
MD5OfMessageBody: string;
|
|
11
|
+
MD5OfMessageAttributes: undefined | string;
|
|
12
|
+
MD5OfMessageSystemAttributes: undefined | string;
|
|
13
|
+
MessageId: string;
|
|
14
|
+
SequenceNumber: string;
|
|
15
|
+
};
|
|
16
|
+
declare type AddToQueue = {
|
|
17
|
+
data: any;
|
|
18
|
+
dedupeId: string;
|
|
19
|
+
groupId?: string;
|
|
20
|
+
queueId?: string;
|
|
21
|
+
queueUrl: string;
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* https://docs.aws.amazon.com/sdk-for-javascript/v3/developer-guide/sqs-examples-send-receive-messages.html
|
|
25
|
+
*/
|
|
26
|
+
declare const addToQueue: ({ data, dedupeId, groupId, queueId, queueUrl }: AddToQueue) => Promise<AddedResponse>;
|
|
27
|
+
export default addToQueue;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
/**
|
|
4
|
+
* https://docs.aws.amazon.com/sdk-for-javascript/v3/developer-guide/sqs-examples-send-receive-messages.html
|
|
5
|
+
*/
|
|
6
|
+
const addToQueue = async ({ data, dedupeId, groupId, queueId, queueUrl }) => {
|
|
7
|
+
const { SendMessageCommand } = require('@aws-sdk/client-sqs');
|
|
8
|
+
let params = {
|
|
9
|
+
MessageBody: JSON.stringify({
|
|
10
|
+
queueId,
|
|
11
|
+
data,
|
|
12
|
+
}),
|
|
13
|
+
QueueUrl: queueUrl,
|
|
14
|
+
};
|
|
15
|
+
// Required for FIFO
|
|
16
|
+
if (undefined !== dedupeId) {
|
|
17
|
+
params["MessageDeduplicationId"] = dedupeId;
|
|
18
|
+
}
|
|
19
|
+
// Required for FIFO
|
|
20
|
+
if (undefined !== groupId) {
|
|
21
|
+
params["MessageGroupId"] = dedupeId;
|
|
22
|
+
}
|
|
23
|
+
const sendData = await global.awsSqsClient.send(new SendMessageCommand(params));
|
|
24
|
+
return sendData;
|
|
25
|
+
};
|
|
26
|
+
exports.default = addToQueue;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { AddedResponse } from './addToQueue';
|
|
2
|
+
declare type DeleteFromQueue = {
|
|
3
|
+
queueUrl: string;
|
|
4
|
+
recipientHandle: string;
|
|
5
|
+
};
|
|
6
|
+
/**
|
|
7
|
+
* Delete a message from a queue.
|
|
8
|
+
*/
|
|
9
|
+
declare const deleteFromQueue: ({ queueUrl, recipientHandle }: DeleteFromQueue) => Promise<AddedResponse>;
|
|
10
|
+
export default deleteFromQueue;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
/**
|
|
4
|
+
* Delete a message from a queue.
|
|
5
|
+
*/
|
|
6
|
+
const deleteFromQueue = async ({ queueUrl, recipientHandle }) => {
|
|
7
|
+
const { DeleteMessageCommand } = require('@aws-sdk/client-sqs');
|
|
8
|
+
const params = {
|
|
9
|
+
QueueUrl: queueUrl,
|
|
10
|
+
ReceiptHandle: recipientHandle,
|
|
11
|
+
};
|
|
12
|
+
const sendData = await global.awsSqsClient.send(new DeleteMessageCommand(params));
|
|
13
|
+
return sendData;
|
|
14
|
+
};
|
|
15
|
+
exports.default = deleteFromQueue;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Config } from '../getConfig';
|
|
2
|
+
declare type InitClient = {
|
|
3
|
+
config: Config;
|
|
4
|
+
};
|
|
5
|
+
/**
|
|
6
|
+
* Shorthand function to get the Lambda Client.
|
|
7
|
+
* Library: @aws-sdk/client-lambda
|
|
8
|
+
*/
|
|
9
|
+
declare const initClient: ({ config }: InitClient) => void;
|
|
10
|
+
export default initClient;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const getConfig_1 = __importDefault(require("../getConfig"));
|
|
7
|
+
global.awsSqsClient = null;
|
|
8
|
+
/**
|
|
9
|
+
* Shorthand function to get the Lambda Client.
|
|
10
|
+
* Library: @aws-sdk/client-lambda
|
|
11
|
+
*/
|
|
12
|
+
const initClient = ({ config }) => {
|
|
13
|
+
if (!global.awsLambdaClient) {
|
|
14
|
+
const { SQSClient } = require('@aws-sdk/client-sqs');
|
|
15
|
+
const formattedConfig = (0, getConfig_1.default)({ config });
|
|
16
|
+
global.awsSqsClient = new SQSClient(formattedConfig);
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
exports.default = initClient;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
/**
|
|
4
|
+
* Check to see if the request is an SQS queued event,
|
|
5
|
+
*/
|
|
6
|
+
const isEventSqs = ({ event }) => {
|
|
7
|
+
let response = false;
|
|
8
|
+
if (undefined !== event['Records']) {
|
|
9
|
+
for (let i = 0; i < event['Records'].length; i++) {
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
return response;
|
|
13
|
+
};
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -3,15 +3,15 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const get_1 = __importDefault(require("
|
|
7
|
-
const response_1 = __importDefault(require("
|
|
8
|
-
const states_1 = __importDefault(require("
|
|
6
|
+
const get_1 = __importDefault(require("../../axios/get"));
|
|
7
|
+
const response_1 = __importDefault(require("../../api/response"));
|
|
8
|
+
const states_1 = __importDefault(require("../../api/states"));
|
|
9
9
|
const getData = async ({ url }) => {
|
|
10
10
|
let response = { ...response_1.default };
|
|
11
11
|
await (0, get_1.default)({
|
|
12
12
|
config: {
|
|
13
13
|
headers: {
|
|
14
|
-
'X-AUTH-TOKEN': global.
|
|
14
|
+
'X-AUTH-TOKEN': global.deepcrawlApi.token,
|
|
15
15
|
},
|
|
16
16
|
},
|
|
17
17
|
onError: error => {
|
|
File without changes
|
|
@@ -3,8 +3,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const post_1 = __importDefault(require("
|
|
7
|
-
global.
|
|
6
|
+
const post_1 = __importDefault(require("../../axios/post"));
|
|
7
|
+
global.deepcrawlApi = {
|
|
8
8
|
lastUpdated: null,
|
|
9
9
|
token: null,
|
|
10
10
|
};
|
|
@@ -15,7 +15,7 @@ global.deepcrawl = {
|
|
|
15
15
|
*/
|
|
16
16
|
const initClient = async ({ auth }) => {
|
|
17
17
|
// todo: Or was more than 6 hours ago
|
|
18
|
-
if (null === global.
|
|
18
|
+
if (null === global.deepcrawlApi.token) {
|
|
19
19
|
const apiResponse = await (0, post_1.default)({
|
|
20
20
|
config: {
|
|
21
21
|
auth: {
|
|
@@ -27,7 +27,7 @@ const initClient = async ({ auth }) => {
|
|
|
27
27
|
});
|
|
28
28
|
// Ensure the value exists
|
|
29
29
|
if (undefined !== apiResponse.data && undefined !== apiResponse.data.token) {
|
|
30
|
-
global.
|
|
30
|
+
global.deepcrawlApi.token = apiResponse.data.token;
|
|
31
31
|
}
|
|
32
32
|
}
|
|
33
33
|
};
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
package/initClients.d.ts
CHANGED
|
@@ -11,7 +11,7 @@ declare type InitClients = {
|
|
|
11
11
|
awsS3?: boolean;
|
|
12
12
|
awsSes?: boolean;
|
|
13
13
|
awsSsm?: boolean;
|
|
14
|
-
|
|
14
|
+
deepcrawlApi?: {
|
|
15
15
|
parameterName: string;
|
|
16
16
|
};
|
|
17
17
|
eskimi?: boolean;
|
|
@@ -33,5 +33,5 @@ declare type InitClients = {
|
|
|
33
33
|
/**
|
|
34
34
|
* Function to simplify initialising the clients.
|
|
35
35
|
*/
|
|
36
|
-
declare const initClients: ({ athenaExpress, awsConfig, awsGlue, awsLambda, awsS3, awsSes, awsSsm,
|
|
36
|
+
declare const initClients: ({ athenaExpress, awsConfig, awsGlue, awsLambda, awsS3, awsSes, awsSsm, deepcrawlApi, googleAds, googleConfig, googleBigQuery, googleSheets, googleStorage, prisma, }: InitClients) => Promise<void>;
|
|
37
37
|
export default initClients;
|
package/initClients.js
CHANGED
|
@@ -10,7 +10,7 @@ const initClient_4 = __importDefault(require("./aws/s3/initClient"));
|
|
|
10
10
|
const initClient_5 = __importDefault(require("./aws/ses/initClient"));
|
|
11
11
|
const getParameter_1 = __importDefault(require("./aws/ssm/getParameter"));
|
|
12
12
|
const initClient_6 = __importDefault(require("./aws/ssm/initClient"));
|
|
13
|
-
const initClient_7 = __importDefault(require("./
|
|
13
|
+
const initClient_7 = __importDefault(require("./deepcrawl/api/initClient"));
|
|
14
14
|
const initClient_8 = __importDefault(require("./google/bigQuery/initClient"));
|
|
15
15
|
const initClient_9 = __importDefault(require("./google/sheets/initClient"));
|
|
16
16
|
const initClient_10 = __importDefault(require("./google/storage/initClient"));
|
|
@@ -19,7 +19,7 @@ const initClient_12 = __importDefault(require("./prisma/initClient"));
|
|
|
19
19
|
/**
|
|
20
20
|
* Function to simplify initialising the clients.
|
|
21
21
|
*/
|
|
22
|
-
const initClients = async ({ athenaExpress, awsConfig, awsGlue, awsLambda, awsS3, awsSes, awsSsm,
|
|
22
|
+
const initClients = async ({ athenaExpress, awsConfig, awsGlue, awsLambda, awsS3, awsSes, awsSsm, deepcrawlApi, googleAds, googleConfig, googleBigQuery, googleSheets, googleStorage, prisma, }) => {
|
|
23
23
|
if (athenaExpress) {
|
|
24
24
|
(0, initClient_1.default)({
|
|
25
25
|
config: awsConfig,
|
|
@@ -48,18 +48,29 @@ const initClients = async ({ athenaExpress, awsConfig, awsGlue, awsLambda, awsS3
|
|
|
48
48
|
config: awsConfig,
|
|
49
49
|
});
|
|
50
50
|
}
|
|
51
|
-
if (awsSsm ||
|
|
51
|
+
if (awsSsm || deepcrawlApi || googleAds || googleConfig) {
|
|
52
52
|
(0, initClient_6.default)({
|
|
53
53
|
config: awsConfig,
|
|
54
54
|
});
|
|
55
55
|
}
|
|
56
|
-
// Deepcrawl authentication using SSM Parameter
|
|
57
|
-
if (
|
|
58
|
-
const
|
|
59
|
-
name:
|
|
56
|
+
// Deepcrawl (API) authentication using SSM Parameter
|
|
57
|
+
if (deepcrawlApi) {
|
|
58
|
+
const deepcrawlApiParameter = await (0, getParameter_1.default)({
|
|
59
|
+
name: deepcrawlApi.parameterName,
|
|
60
60
|
});
|
|
61
|
-
await (0, initClient_7.default)({ auth:
|
|
61
|
+
await (0, initClient_7.default)({ auth: deepcrawlApiParameter });
|
|
62
62
|
}
|
|
63
|
+
/**
|
|
64
|
+
// Deepcrawl (GraphQL) authentication using SSM Parameter
|
|
65
|
+
if (deepcrawlGraphql)
|
|
66
|
+
{
|
|
67
|
+
const deepcrawlGraphqlParameter = await getParameter({
|
|
68
|
+
name: deepcrawlApi.parameterName,
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
await initDeepCrawlGraphql({auth: deepcrawlGraphqlParameter});
|
|
72
|
+
}
|
|
73
|
+
*/
|
|
63
74
|
// Google authentication using SSM
|
|
64
75
|
if (googleConfig) {
|
|
65
76
|
// Google Parameter
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@8ms/helpers",
|
|
3
3
|
"license": "UNLICENSED",
|
|
4
|
-
"version": "1.1.
|
|
4
|
+
"version": "1.1.87",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
7
7
|
"url": "git+https://github.com/8millionstories-organisation/8ms-helpers-ts.git"
|
|
@@ -15,32 +15,38 @@
|
|
|
15
15
|
"dependencies": {
|
|
16
16
|
"axios": "0.27.2",
|
|
17
17
|
"crypto-js": "4.1.1",
|
|
18
|
-
"date-fns": "2.29.
|
|
18
|
+
"date-fns": "2.29.3",
|
|
19
19
|
"date-fns-tz": "1.3.7",
|
|
20
20
|
"lodash": "4.17.21"
|
|
21
21
|
},
|
|
22
22
|
"devDependencies": {
|
|
23
|
-
"@aws-sdk/client-s3":
|
|
24
|
-
"@aws-sdk/client-ses":
|
|
25
|
-
"@aws-sdk/client-
|
|
26
|
-
"@aws-sdk/
|
|
27
|
-
"@
|
|
28
|
-
"@babel/preset-
|
|
29
|
-
"@babel/preset-
|
|
30
|
-
"@
|
|
31
|
-
"@google-cloud/
|
|
32
|
-
"@
|
|
33
|
-
"@
|
|
34
|
-
"@
|
|
35
|
-
"@
|
|
36
|
-
"
|
|
37
|
-
"jest":
|
|
38
|
-
"
|
|
39
|
-
"
|
|
40
|
-
"
|
|
41
|
-
"
|
|
42
|
-
"
|
|
43
|
-
"
|
|
44
|
-
"
|
|
23
|
+
"@aws-sdk/client-s3": "3.178.0",
|
|
24
|
+
"@aws-sdk/client-ses": "3.178.0",
|
|
25
|
+
"@aws-sdk/client-sqs": "3.178.0",
|
|
26
|
+
"@aws-sdk/client-ssm": "3.178.0",
|
|
27
|
+
"@aws-sdk/s3-request-presigner": "3.178.0",
|
|
28
|
+
"@babel/preset-env": "7.19.1",
|
|
29
|
+
"@babel/preset-flow": "7.18.6",
|
|
30
|
+
"@babel/preset-typescript": "7.18.6",
|
|
31
|
+
"@google-cloud/bigquery": "6.0.3",
|
|
32
|
+
"@google-cloud/storage": "6.5.2",
|
|
33
|
+
"@graphql-codegen/cli": "2.12.1",
|
|
34
|
+
"@graphql-codegen/typescript-graphql-request": "4.5.5",
|
|
35
|
+
"@graphql-codegen/typescript-operations": "2.5.3",
|
|
36
|
+
"@prisma/client": "4.3.1",
|
|
37
|
+
"@types/jest": "29.0.3",
|
|
38
|
+
"@types/lodash": "4.14.185",
|
|
39
|
+
"@types/node": "18.7.21",
|
|
40
|
+
"babel-jest": "29.0.3",
|
|
41
|
+
"graphql": "16.6.0",
|
|
42
|
+
"graphql-request": "5.0.0",
|
|
43
|
+
"jest": "29.0.3",
|
|
44
|
+
"node-fetch": "3.2.10",
|
|
45
|
+
"numbro": "2.3.6",
|
|
46
|
+
"prisma-query-log": "3.2.0",
|
|
47
|
+
"timezone-mock": "1.3.4",
|
|
48
|
+
"ts-node": "10.9.1",
|
|
49
|
+
"tslib": "2.4.0",
|
|
50
|
+
"typescript": "4.8.3"
|
|
45
51
|
}
|
|
46
52
|
}
|