@8ms/helpers 1.1.92 → 1.1.94

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.
@@ -1,5 +1,6 @@
1
1
  import { Response } from '../../api/response';
2
- declare const getData: ({ url }: {
2
+ declare type GetData = {
3
3
  url: string;
4
- }) => Promise<Response>;
4
+ };
5
+ declare const getData: ({ url }: GetData) => Promise<Response>;
5
6
  export default getData;
@@ -3,9 +3,9 @@ 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
6
  const response_1 = __importDefault(require("../../api/response"));
8
7
  const states_1 = __importDefault(require("../../api/states"));
8
+ const get_1 = __importDefault(require("../../axios/get"));
9
9
  const getData = async ({ url }) => {
10
10
  let response = { ...response_1.default };
11
11
  await (0, get_1.default)({
@@ -0,0 +1,9 @@
1
+ import { Response } from '../../api/response';
2
+ declare type GetData = {
3
+ query: string;
4
+ variables?: {
5
+ [key: string]: any;
6
+ };
7
+ };
8
+ declare const getData: ({ query, variables }: GetData) => Promise<Response>;
9
+ export default getData;
@@ -0,0 +1,33 @@
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 response_1 = __importDefault(require("../../api/response"));
7
+ const states_1 = __importDefault(require("../../api/states"));
8
+ const post_1 = __importDefault(require("../../axios/post"));
9
+ const getData = async ({ query, variables }) => {
10
+ let response = { ...response_1.default };
11
+ await (0, post_1.default)({
12
+ config: {
13
+ headers: {
14
+ 'x-auth-token': global.deepcrawlGraphql.token,
15
+ },
16
+ },
17
+ data: {
18
+ query,
19
+ variables,
20
+ },
21
+ onError: error => {
22
+ response.state = states_1.default.ERROR;
23
+ response.error = error.message;
24
+ },
25
+ onSuccess: success => {
26
+ response.state = states_1.default.SUCCESS;
27
+ response.body = success.data;
28
+ },
29
+ url: 'https://graph.deepcrawl.com/',
30
+ });
31
+ return response;
32
+ };
33
+ exports.default = getData;
@@ -0,0 +1,13 @@
1
+ declare type InitClient = {
2
+ auth: {
3
+ apiId: string;
4
+ apiKey: string;
5
+ };
6
+ };
7
+ /**
8
+ * http://api-docs.deepcrawl.com/
9
+ * Renew the DeepCrawl user token.
10
+ * Token lasts for 6 hours.
11
+ */
12
+ declare const initClient: ({ auth }: InitClient) => Promise<void>;
13
+ export default initClient;
@@ -0,0 +1,34 @@
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 post_1 = __importDefault(require("../../axios/post"));
7
+ global.deepcrawlGraphql = {
8
+ lastUpdated: null,
9
+ token: null,
10
+ };
11
+ /**
12
+ * http://api-docs.deepcrawl.com/
13
+ * Renew the DeepCrawl user token.
14
+ * Token lasts for 6 hours.
15
+ */
16
+ const initClient = async ({ auth }) => {
17
+ // todo: Or was more than 6 hours ago
18
+ if (null === global.deepcrawlGraphql.token) {
19
+ const apiResponse = await (0, post_1.default)({
20
+ config: {
21
+ auth: {
22
+ username: auth.apiId,
23
+ password: auth.apiKey,
24
+ },
25
+ },
26
+ url: `https://api.deepcrawl.com/sessions`,
27
+ });
28
+ // Ensure the value exists
29
+ if (undefined !== apiResponse.data && undefined !== apiResponse.data.token) {
30
+ global.deepcrawlGraphql.token = apiResponse.data.token;
31
+ }
32
+ }
33
+ };
34
+ exports.default = initClient;
@@ -5,6 +5,7 @@ declare type CreateTable = {
5
5
  };
6
6
  /**
7
7
  * Create a Table if it doesn't already exist.
8
+ * Returns table instance.
8
9
  */
9
10
  declare const createTable: ({ datasetId, options, tableId }: CreateTable) => Promise<void>;
10
11
  export default createTable;
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const IsTableExists_1 = __importDefault(require("./IsTableExists"));
7
7
  /**
8
8
  * Create a Table if it doesn't already exist.
9
+ * Returns table instance.
9
10
  */
10
11
  const createTable = async ({ datasetId, options, tableId }) => {
11
12
  const tableExists = await (0, IsTableExists_1.default)({ datasetId, tableId });
@@ -0,0 +1,12 @@
1
+ declare type LoadData = {
2
+ bucket: string;
3
+ key: string;
4
+ datasetId: string;
5
+ tableId: string;
6
+ metadata: object;
7
+ };
8
+ /**
9
+ * Load data into a given table.
10
+ */
11
+ declare const loadData: ({ bucket, datasetId, key, metadata, tableId }: LoadData) => Promise<void>;
12
+ export default loadData;
@@ -0,0 +1,18 @@
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 IsTableExists_1 = __importDefault(require("./IsTableExists"));
7
+ /**
8
+ * Load data into a given table.
9
+ */
10
+ const loadData = async ({ bucket, datasetId, key, metadata, tableId }) => {
11
+ const tableExists = await (0, IsTableExists_1.default)({ datasetId, tableId });
12
+ if (tableExists) {
13
+ await global.googleBigQueryClient.dataset(datasetId)
14
+ .table(tableId)
15
+ .load(global.googleStorageClient.bucket(bucket).file(key), metadata);
16
+ }
17
+ };
18
+ exports.default = loadData;
@@ -1,12 +1,10 @@
1
1
  declare type CopyToCloud = {
2
2
  bucket: string;
3
- data: any;
4
3
  localFile: string;
5
- key: string;
6
- [options: string]: any;
4
+ options?: object;
7
5
  };
8
6
  /**
9
7
  * Copy a local file to Google Cloud Storage.
10
8
  */
11
- export declare const copyToCloud: ({ bucket, localFile, ...options }: CopyToCloud) => Promise<any>;
9
+ export declare const copyToCloud: ({ bucket, localFile, options }: CopyToCloud) => Promise<any>;
12
10
  export default copyToCloud;
@@ -4,7 +4,7 @@ exports.copyToCloud = void 0;
4
4
  /**
5
5
  * Copy a local file to Google Cloud Storage.
6
6
  */
7
- const copyToCloud = async ({ bucket, localFile, ...options }) => {
7
+ const copyToCloud = async ({ bucket, localFile, options }) => {
8
8
  const bucketInstance = global.googleStorageClient.bucket(bucket);
9
9
  const apiResponse = bucketInstance.upload(localFile, options);
10
10
  return apiResponse;
package/initClients.d.ts CHANGED
@@ -14,6 +14,9 @@ declare type InitClients = {
14
14
  deepcrawlApi?: {
15
15
  parameterName: string;
16
16
  };
17
+ deepcrawlGraphql?: {
18
+ parameterName: string;
19
+ };
17
20
  eskimi?: boolean;
18
21
  googleAds?: {
19
22
  parameterName: string;
@@ -33,5 +36,5 @@ declare type InitClients = {
33
36
  /**
34
37
  * Function to simplify initialising the clients.
35
38
  */
36
- declare const initClients: ({ athenaExpress, awsConfig, awsGlue, awsLambda, awsS3, awsSes, awsSsm, deepcrawlApi, googleAds, googleConfig, googleBigQuery, googleSheets, googleStorage, prisma, }: InitClients) => Promise<void>;
39
+ declare const initClients: ({ athenaExpress, awsConfig, awsGlue, awsLambda, awsS3, awsSes, awsSsm, deepcrawlApi, deepcrawlGraphql, googleAds, googleConfig, googleBigQuery, googleSheets, googleStorage, prisma, }: InitClients) => Promise<void>;
37
40
  export default initClients;
package/initClients.js CHANGED
@@ -11,15 +11,16 @@ 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
13
  const initClient_7 = __importDefault(require("./deepcrawl/api/initClient"));
14
- const initClient_8 = __importDefault(require("./google/bigQuery/initClient"));
15
- const initClient_9 = __importDefault(require("./google/sheets/initClient"));
16
- const initClient_10 = __importDefault(require("./google/storage/initClient"));
17
- const initClient_11 = __importDefault(require("./googleAds/initClient"));
18
- const initClient_12 = __importDefault(require("./prisma/initClient"));
14
+ const initClient_8 = __importDefault(require("./deepcrawl/graphql/initClient"));
15
+ const initClient_9 = __importDefault(require("./google/bigQuery/initClient"));
16
+ const initClient_10 = __importDefault(require("./google/sheets/initClient"));
17
+ const initClient_11 = __importDefault(require("./google/storage/initClient"));
18
+ const initClient_12 = __importDefault(require("./googleAds/initClient"));
19
+ const initClient_13 = __importDefault(require("./prisma/initClient"));
19
20
  /**
20
21
  * Function to simplify initialising the clients.
21
22
  */
22
- const initClients = async ({ athenaExpress, awsConfig, awsGlue, awsLambda, awsS3, awsSes, awsSsm, deepcrawlApi, googleAds, googleConfig, googleBigQuery, googleSheets, googleStorage, prisma, }) => {
23
+ const initClients = async ({ athenaExpress, awsConfig, awsGlue, awsLambda, awsS3, awsSes, awsSsm, deepcrawlApi, deepcrawlGraphql, googleAds, googleConfig, googleBigQuery, googleSheets, googleStorage, prisma, }) => {
23
24
  if (athenaExpress) {
24
25
  (0, initClient_1.default)({
25
26
  config: awsConfig,
@@ -60,17 +61,13 @@ const initClients = async ({ athenaExpress, awsConfig, awsGlue, awsLambda, awsS3
60
61
  });
61
62
  await (0, initClient_7.default)({ auth: deepcrawlApiParameter });
62
63
  }
63
- /**
64
64
  // Deepcrawl (GraphQL) authentication using SSM Parameter
65
- if (deepcrawlGraphql)
66
- {
67
- const deepcrawlGraphqlParameter = await getParameter({
68
- name: deepcrawlApi.parameterName,
65
+ if (deepcrawlGraphql) {
66
+ const deepcrawlGraphqlParameter = await (0, getParameter_1.default)({
67
+ name: deepcrawlGraphql.parameterName,
69
68
  });
70
-
71
- await initDeepCrawlGraphql({auth: deepcrawlGraphqlParameter});
69
+ await (0, initClient_8.default)({ auth: deepcrawlGraphqlParameter });
72
70
  }
73
- */
74
71
  // Google authentication using SSM
75
72
  if (googleConfig) {
76
73
  // Google Parameter
@@ -79,20 +76,20 @@ const initClients = async ({ athenaExpress, awsConfig, awsGlue, awsLambda, awsS3
79
76
  });
80
77
  // BigQuery
81
78
  if (googleBigQuery && googleConfig.projectId) {
82
- (0, initClient_8.default)({
79
+ (0, initClient_9.default)({
83
80
  parameter: googleParameter,
84
81
  projectId: googleConfig.projectId,
85
82
  });
86
83
  }
87
84
  // Google Sheets
88
85
  if (googleSheets) {
89
- (0, initClient_9.default)({
86
+ (0, initClient_10.default)({
90
87
  parameter: googleParameter,
91
88
  });
92
89
  }
93
90
  // Google Storage
94
91
  if (googleStorage && googleConfig.projectId) {
95
- (0, initClient_10.default)({
92
+ (0, initClient_11.default)({
96
93
  parameter: googleParameter,
97
94
  projectId: googleConfig.projectId,
98
95
  });
@@ -103,13 +100,13 @@ const initClients = async ({ athenaExpress, awsConfig, awsGlue, awsLambda, awsS3
103
100
  const googleAdsParameter = await (0, getParameter_1.default)({
104
101
  name: googleAds.parameterName,
105
102
  });
106
- await (0, initClient_11.default)({
103
+ await (0, initClient_12.default)({
107
104
  parameter: googleAdsParameter,
108
105
  });
109
106
  }
110
107
  // Initialise Prisma
111
108
  if (prisma) {
112
- (0, initClient_12.default)({
109
+ (0, initClient_13.default)({
113
110
  debug: prisma ? false : prisma.debug || false,
114
111
  });
115
112
  }
package/package.json CHANGED
@@ -1,52 +1,52 @@
1
1
  {
2
- "name": "@8ms/helpers",
3
- "license": "UNLICENSED",
4
- "version": "1.1.92",
5
- "repository": {
6
- "type": "git",
7
- "url": "git+https://github.com/8millionstories-organisation/8ms-helpers-ts.git"
8
- },
9
- "main": "index.js",
10
- "types": "index.d.ts",
11
- "scripts": {
12
- "build": "tsc",
13
- "jest": "jest --watch"
14
- },
15
- "dependencies": {
16
- "axios": "0.27.2",
17
- "crypto-js": "4.1.1",
18
- "date-fns": "2.29.3",
19
- "date-fns-tz": "1.3.7",
20
- "lodash": "4.17.21"
21
- },
22
- "devDependencies": {
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"
51
- }
2
+ "name": "@8ms/helpers",
3
+ "license": "UNLICENSED",
4
+ "version": "1.1.94",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "git+https://github.com/8millionstories-organisation/8ms-helpers-ts.git"
8
+ },
9
+ "main": "index.js",
10
+ "types": "index.d.ts",
11
+ "scripts": {
12
+ "build": "tsc",
13
+ "jest": "jest --watch"
14
+ },
15
+ "dependencies": {
16
+ "axios": "0.27.2",
17
+ "crypto-js": "4.1.1",
18
+ "date-fns": "2.29.3",
19
+ "date-fns-tz": "1.3.7",
20
+ "lodash": "4.17.21"
21
+ },
22
+ "devDependencies": {
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"
51
+ }
52
52
  }