@8ms/helpers 1.1.84 → 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.
@@ -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
+ };
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Shorthand to get the current date.
3
+ */
4
+ declare const getTodayYmd: () => string;
5
+ export default getTodayYmd;
@@ -0,0 +1,20 @@
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 format_1 = __importDefault(require("./format"));
7
+ const getToday_1 = __importDefault(require("./getToday"));
8
+ /**
9
+ * Shorthand to get the current date.
10
+ */
11
+ const getTodayYmd = () => {
12
+ const today = (0, getToday_1.default)({ setMidnight: false });
13
+ const todayYmd = (0, format_1.default)({
14
+ input: today,
15
+ dateFormat: 'yyyy-MM-dd',
16
+ setMidnight: false,
17
+ });
18
+ return todayYmd;
19
+ };
20
+ exports.default = getTodayYmd;
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Shorthand to get the current timestamp.
3
+ */
4
+ declare const getTodayYmdhis: () => string;
5
+ export default getTodayYmdhis;
@@ -0,0 +1,20 @@
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 format_1 = __importDefault(require("./format"));
7
+ const getToday_1 = __importDefault(require("./getToday"));
8
+ /**
9
+ * Shorthand to get the current timestamp.
10
+ */
11
+ const getTodayYmdhis = () => {
12
+ const today = (0, getToday_1.default)({ setMidnight: false });
13
+ const todayYmdhis = (0, format_1.default)({
14
+ input: today,
15
+ dateFormat: 'yyyy-MM-dd HH:mm:ss',
16
+ setMidnight: false,
17
+ });
18
+ return todayYmdhis;
19
+ };
20
+ exports.default = getTodayYmdhis;
File without changes
File without changes
File without changes
File without changes
@@ -1,4 +1,4 @@
1
- import { Response } from '../api/response';
1
+ import { Response } from '../../api/response';
2
2
  declare const getData: ({ url }: {
3
3
  url: string;
4
4
  }) => Promise<Response>;
@@ -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("../axios/get"));
7
- const response_1 = __importDefault(require("../api/response"));
8
- const states_1 = __importDefault(require("../api/states"));
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.deepcrawl.token,
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("../axios/post"));
7
- global.deepcrawl = {
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.deepcrawl.token) {
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.deepcrawl.token = apiResponse.data.token;
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
- deepCrawl?: {
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, deepCrawl, googleAds, googleConfig, googleBigQuery, googleSheets, googleStorage, prisma, }: InitClients) => Promise<void>;
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("./deepCrawl/initClient"));
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, deepCrawl, googleAds, googleConfig, googleBigQuery, googleSheets, googleStorage, prisma, }) => {
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 || deepCrawl || googleAds || googleConfig) {
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 (deepCrawl) {
58
- const deepcrawlParameter = await (0, getParameter_1.default)({
59
- name: deepCrawl.parameterName,
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: deepcrawlParameter });
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.84",
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.2",
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": "3.163.0",
24
- "@aws-sdk/client-ses": "3.163.0",
25
- "@aws-sdk/client-ssm": "3.163.0",
26
- "@aws-sdk/s3-request-presigner": "3.163.0",
27
- "@babel/preset-env": "7.18.10",
28
- "@babel/preset-flow": "7.18.6",
29
- "@babel/preset-typescript": "7.18.6",
30
- "@google-cloud/bigquery": "6.0.2",
31
- "@google-cloud/storage": "6.4.2",
32
- "@prisma/client": "4.3.1",
33
- "@types/jest": "29.0.0",
34
- "@types/lodash": "4.14.184",
35
- "@types/node": "18.7.14",
36
- "babel-jest": "29.0.2",
37
- "jest": "29.0.2",
38
- "node-fetch": "3.2.10",
39
- "numbro": "2.3.6",
40
- "prisma-query-log": "3.2.0",
41
- "timezone-mock": "1.3.4",
42
- "ts-node": "10.9.1",
43
- "tslib": "2.4.0",
44
- "typescript": "4.8.2"
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
  }