@8ms/helpers 1.3.7 → 1.3.9

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.
Files changed (52) hide show
  1. package/api/isError.d.ts +2 -2
  2. package/aws/s3/getGlueJson.d.ts +3 -0
  3. package/aws/s3/getGlueJson.js +5 -9
  4. package/google/bigQuery/getDatasets.d.ts +13 -0
  5. package/google/bigQuery/getDatasets.js +27 -0
  6. package/google/bigQuery/loadData.d.ts +1 -0
  7. package/google/bigQuery/loadData.js +6 -3
  8. package/initClients.d.ts +3 -3
  9. package/initClients.js +18 -14
  10. package/json/getJsonNewline.d.ts +5 -0
  11. package/json/getJsonNewline.js +17 -0
  12. package/{deepcrawl → lumar}/api/initClient.d.ts +1 -1
  13. package/{deepcrawl → lumar}/api/initClient.js +4 -4
  14. package/{deepcrawl → lumar}/graphql/getData.js +2 -2
  15. package/{deepcrawl → lumar}/graphql/initClient.d.ts +2 -2
  16. package/{deepcrawl → lumar}/graphql/initClient.js +7 -7
  17. package/package.json +1 -1
  18. /package/{deepcrawl → lumar}/api/buildRequest.d.ts +0 -0
  19. /package/{deepcrawl → lumar}/api/buildRequest.js +0 -0
  20. /package/{deepcrawl → lumar}/api/filter.d.ts +0 -0
  21. /package/{deepcrawl → lumar}/api/filter.js +0 -0
  22. /package/{deepcrawl → lumar}/api/getData.d.ts +0 -0
  23. /package/{deepcrawl → lumar}/api/getData.js +0 -0
  24. /package/{deepcrawl → lumar}/api/operands.d.ts +0 -0
  25. /package/{deepcrawl → lumar}/api/operands.js +0 -0
  26. /package/{deepcrawl → lumar}/api/orders.d.ts +0 -0
  27. /package/{deepcrawl → lumar}/api/orders.js +0 -0
  28. /package/{deepcrawl → lumar}/api/reports.d.ts +0 -0
  29. /package/{deepcrawl → lumar}/api/reports.js +0 -0
  30. /package/{deepcrawl → lumar}/graphql/columns.d.ts +0 -0
  31. /package/{deepcrawl → lumar}/graphql/columns.js +0 -0
  32. /package/{deepcrawl → lumar}/graphql/getData.d.ts +0 -0
  33. /package/{deepcrawl → lumar}/graphql/getReportKey.d.ts +0 -0
  34. /package/{deepcrawl → lumar}/graphql/getReportKey.js +0 -0
  35. /package/{deepcrawl → lumar}/graphql/operands.d.ts +0 -0
  36. /package/{deepcrawl → lumar}/graphql/operands.js +0 -0
  37. /package/{deepcrawl → lumar}/graphql/queries/crawl.d.ts +0 -0
  38. /package/{deepcrawl → lumar}/graphql/queries/crawl.js +0 -0
  39. /package/{deepcrawl → lumar}/graphql/queries/getCrawls.d.ts +0 -0
  40. /package/{deepcrawl → lumar}/graphql/queries/getCrawls.js +0 -0
  41. /package/{deepcrawl → lumar}/graphql/queries/getReportDifferences.d.ts +0 -0
  42. /package/{deepcrawl → lumar}/graphql/queries/getReportDifferences.js +0 -0
  43. /package/{deepcrawl → lumar}/graphql/queries/getRows.d.ts +0 -0
  44. /package/{deepcrawl → lumar}/graphql/queries/getRows.js +0 -0
  45. /package/{deepcrawl → lumar}/graphql/queries/getTotals.d.ts +0 -0
  46. /package/{deepcrawl → lumar}/graphql/queries/getTotals.js +0 -0
  47. /package/{deepcrawl → lumar}/graphql/queries/row.d.ts +0 -0
  48. /package/{deepcrawl → lumar}/graphql/queries/row.js +0 -0
  49. /package/{deepcrawl → lumar}/graphql/reportTemplates.d.ts +0 -0
  50. /package/{deepcrawl → lumar}/graphql/reportTemplates.js +0 -0
  51. /package/{deepcrawl → lumar}/graphql/reportTypes.d.ts +0 -0
  52. /package/{deepcrawl → lumar}/graphql/reportTypes.js +0 -0
package/api/isError.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { Response } from './response';
2
- type IsSuccess = {
2
+ type IsError = {
3
3
  response: Response;
4
4
  };
5
- declare const isError: ({ response }: IsSuccess) => boolean;
5
+ declare const isError: ({ response }: IsError) => boolean;
6
6
  export default isError;
@@ -1,5 +1,8 @@
1
1
  type GetGlueJson = {
2
2
  data: any;
3
3
  };
4
+ /**
5
+ * @deprecated in favour of getJsonNewline
6
+ */
4
7
  declare const getGlueJson: ({ data }: GetGlueJson) => string;
5
8
  export default getGlueJson;
@@ -3,13 +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 getArray_1 = __importDefault(require("../../array/getArray"));
7
- const getGlueJson = ({ data }) => {
8
- // Must be an array
9
- const inputArray = (0, getArray_1.default)({ input: data });
10
- // For each array row convert the row
11
- const stringRows = inputArray.map(row => JSON.stringify(row));
12
- // Combine each row with a line separator
13
- return stringRows.join("\n");
14
- };
6
+ const getJsonNewline_1 = __importDefault(require("../../json/getJsonNewline"));
7
+ /**
8
+ * @deprecated in favour of getJsonNewline
9
+ */
10
+ const getGlueJson = ({ data }) => (0, getJsonNewline_1.default)({ data });
15
11
  exports.default = getGlueJson;
@@ -0,0 +1,13 @@
1
+ type GetDatasets = {
2
+ projectId?: string;
3
+ };
4
+ type Datasets = {
5
+ id: string;
6
+ location: string;
7
+ projectId: string;
8
+ };
9
+ /**
10
+ * Retrieve all the Datasets from a given Project.
11
+ */
12
+ declare const getDatasets: ({ projectId }: GetDatasets) => Promise<Datasets[]>;
13
+ export default getDatasets;
@@ -0,0 +1,27 @@
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 getClient_1 = __importDefault(require("./getClient"));
7
+ /**
8
+ * Retrieve all the Datasets from a given Project.
9
+ */
10
+ const getDatasets = async ({ projectId }) => {
11
+ let response = [];
12
+ const client = (0, getClient_1.default)({
13
+ projectId,
14
+ });
15
+ const datasets = await client.getDatasets();
16
+ if (datasets?.[0]) {
17
+ for (let i = 0; i < datasets[0].length; i++) {
18
+ response.push({
19
+ id: datasets[0][i].id,
20
+ location: datasets[0][i].location,
21
+ projectId: datasets[0][i].bigQuery.projectId,
22
+ });
23
+ }
24
+ }
25
+ return response;
26
+ };
27
+ exports.default = getDatasets;
@@ -3,6 +3,7 @@ type LoadData = {
3
3
  bucket: string;
4
4
  key: string;
5
5
  metadata: object;
6
+ projectId?: string;
6
7
  };
7
8
  table: {
8
9
  projectId?: string;
@@ -15,13 +15,16 @@ const loadData = async ({ file, table }) => {
15
15
  tableId: table.tableId,
16
16
  });
17
17
  if (tableExists) {
18
- let client = (0, getClient_1.default)({
18
+ let bigqueryClient = (0, getClient_1.default)({
19
19
  projectId: table.projectId
20
20
  });
21
- await client
21
+ let storageClient = (0, getClient_1.default)({
22
+ projectId: file.projectId
23
+ });
24
+ await bigqueryClient
22
25
  .dataset(table.datasetId)
23
26
  .table(table.tableId)
24
- .load(global.googleStorageClient.bucket(file.bucket)
27
+ .load(storageClient.bucket(file.bucket)
25
28
  .file(file.key), file.metadata);
26
29
  }
27
30
  };
package/initClients.d.ts CHANGED
@@ -11,10 +11,10 @@ type InitClients = {
11
11
  awsS3?: boolean;
12
12
  awsSes?: boolean;
13
13
  awsSsm?: boolean;
14
- deepcrawlApi?: {
14
+ lumarApi?: {
15
15
  parameterName: string;
16
16
  };
17
- deepcrawlGraphql?: {
17
+ lumarGraphql?: {
18
18
  parameterName: string;
19
19
  };
20
20
  eskimi?: boolean;
@@ -36,5 +36,5 @@ type InitClients = {
36
36
  /**
37
37
  * Function to simplify initialising the clients.
38
38
  */
39
- declare const initClients: ({ athenaExpress, awsConfig, awsGlue, awsLambda, awsS3, awsSes, awsSsm, deepcrawlApi, deepcrawlGraphql, googleAds, googleConfig, googleBigQuery, googleSheets, googleStorage, prisma, }: InitClients) => Promise<void>;
39
+ declare const initClients: ({ athenaExpress, awsConfig, awsGlue, awsLambda, awsS3, awsSes, awsSsm, lumarApi, lumarGraphql, googleAds, googleConfig, googleBigQuery, googleSheets, googleStorage, prisma, }: InitClients) => Promise<void>;
40
40
  export default initClients;
package/initClients.js CHANGED
@@ -10,8 +10,8 @@ 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/api/initClient"));
14
- const initClient_8 = __importDefault(require("./deepcrawl/graphql/initClient"));
13
+ const initClient_7 = __importDefault(require("./lumar/api/initClient"));
14
+ const initClient_8 = __importDefault(require("./lumar/graphql/initClient"));
15
15
  const initClient_9 = __importDefault(require("./google/bigQuery/initClient"));
16
16
  const initClient_10 = __importDefault(require("./google/sheets/initClient"));
17
17
  const initClient_11 = __importDefault(require("./google/storage/initClient"));
@@ -20,7 +20,7 @@ const initClient_13 = __importDefault(require("./prisma/initClient"));
20
20
  /**
21
21
  * Function to simplify initialising the clients.
22
22
  */
23
- const initClients = async ({ athenaExpress, awsConfig, awsGlue, awsLambda, awsS3, awsSes, awsSsm, deepcrawlApi, deepcrawlGraphql, googleAds, googleConfig, googleBigQuery, googleSheets, googleStorage, prisma, }) => {
23
+ const initClients = async ({ athenaExpress, awsConfig, awsGlue, awsLambda, awsS3, awsSes, awsSsm, lumarApi, lumarGraphql, googleAds, googleConfig, googleBigQuery, googleSheets, googleStorage, prisma, }) => {
24
24
  if (athenaExpress) {
25
25
  (0, initClient_1.default)({
26
26
  config: awsConfig,
@@ -49,24 +49,28 @@ const initClients = async ({ athenaExpress, awsConfig, awsGlue, awsLambda, awsS3
49
49
  config: awsConfig,
50
50
  });
51
51
  }
52
- if (awsSsm || deepcrawlApi || googleAds || googleConfig) {
52
+ if (awsSsm || lumarApi || lumarGraphql || googleAds || googleConfig) {
53
53
  (0, initClient_6.default)({
54
54
  config: awsConfig,
55
55
  });
56
56
  }
57
- // Deepcrawl (API) authentication using SSM Parameter
58
- if (deepcrawlApi) {
59
- const deepcrawlApiParameter = await (0, getParameter_1.default)({
60
- name: deepcrawlApi.parameterName,
57
+ // Lumar (API) authentication using SSM Parameter
58
+ if (lumarApi) {
59
+ const lumarApiParameter = await (0, getParameter_1.default)({
60
+ name: lumarApi.parameterName,
61
+ });
62
+ await (0, initClient_7.default)({
63
+ auth: lumarApiParameter
61
64
  });
62
- await (0, initClient_7.default)({ auth: deepcrawlApiParameter });
63
65
  }
64
- // Deepcrawl (GraphQL) authentication using SSM Parameter
65
- if (deepcrawlGraphql) {
66
- const deepcrawlGraphqlParameter = await (0, getParameter_1.default)({
67
- name: deepcrawlGraphql.parameterName,
66
+ // Lumar (GraphQL) authentication using SSM Parameter
67
+ if (lumarGraphql) {
68
+ const lumarGraphqlParameter = await (0, getParameter_1.default)({
69
+ name: lumarGraphql.parameterName,
70
+ });
71
+ await (0, initClient_8.default)({
72
+ auth: lumarGraphqlParameter
68
73
  });
69
- await (0, initClient_8.default)({ auth: deepcrawlGraphqlParameter });
70
74
  }
71
75
  // Google authentication using SSM
72
76
  if (googleConfig) {
@@ -0,0 +1,5 @@
1
+ type GetGlueJson = {
2
+ data: any;
3
+ };
4
+ declare const GetJsonNewline: ({ data }: GetGlueJson) => string;
5
+ export default GetJsonNewline;
@@ -0,0 +1,17 @@
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 getArray_1 = __importDefault(require("../array/getArray"));
7
+ const GetJsonNewline = ({ data }) => {
8
+ // Must be an array
9
+ const inputArray = (0, getArray_1.default)({
10
+ input: data
11
+ });
12
+ // For each array row convert the row
13
+ const stringRows = inputArray.map(row => JSON.stringify(row));
14
+ // Combine each row with a line separator
15
+ return stringRows.join("\n");
16
+ };
17
+ exports.default = GetJsonNewline;
@@ -6,7 +6,7 @@ type InitClient = {
6
6
  };
7
7
  /**
8
8
  * http://api-docs.deepcrawl.com/
9
- * Renew the DeepCrawl user token.
9
+ * Renew the Lumar user token.
10
10
  * Token lasts for 6 hours.
11
11
  */
12
12
  declare const initClient: ({ auth }: InitClient) => Promise<void>;
@@ -4,18 +4,18 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const post_1 = __importDefault(require("../../axios/post"));
7
- global.deepcrawlApi = {
7
+ global.lumarApi = {
8
8
  token: null,
9
9
  updatedAt: null,
10
10
  };
11
11
  /**
12
12
  * http://api-docs.deepcrawl.com/
13
- * Renew the DeepCrawl user token.
13
+ * Renew the Lumar user token.
14
14
  * Token lasts for 6 hours.
15
15
  */
16
16
  const initClient = async ({ auth }) => {
17
17
  // todo: Or was more than 6 hours ago
18
- if (null === global.deepcrawlApi.token) {
18
+ if (null === global.lumarApi.token) {
19
19
  const apiResponse = await (0, post_1.default)({
20
20
  config: {
21
21
  auth: {
@@ -31,7 +31,7 @@ const initClient = async ({ auth }) => {
31
31
  keys: ['token'],
32
32
  });
33
33
  if (token) {
34
- global.deepcrawlApi.token = token;
34
+ global.lumarApi.token = token;
35
35
  }
36
36
  }
37
37
  };
@@ -12,14 +12,14 @@ const getData = async ({ query, variables }) => {
12
12
  const apiResponse = await (0, post_1.default)({
13
13
  config: {
14
14
  headers: {
15
- 'x-auth-token': global.deepcrawlGraphql.token,
15
+ 'x-auth-token': global.lumarGraphql.token,
16
16
  },
17
17
  },
18
18
  data: {
19
19
  query: queryClean,
20
20
  variables,
21
21
  },
22
- url: 'https://graph.deepcrawl.com/',
22
+ url: 'https://api.lumar.io/graphql',
23
23
  });
24
24
  return apiResponse;
25
25
  };
@@ -5,8 +5,8 @@ type InitClient = {
5
5
  };
6
6
  };
7
7
  /**
8
- * https://graph-docs.deepcrawl.com/graphql/explorer/
9
- * Renew the DeepCrawl user token.
8
+ * https://api-docs.lumar.io/graphql/explorer/
9
+ * Renew the Lumar user token.
10
10
  */
11
11
  declare const initClient: ({ auth }: InitClient) => Promise<void>;
12
12
  export default initClient;
@@ -4,17 +4,17 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const post_1 = __importDefault(require("../../axios/post"));
7
- global.deepcrawlGraphql = {
7
+ // Initialise
8
+ global.lumarGraphql = {
8
9
  token: null,
9
10
  updatedAt: null,
10
11
  };
11
12
  /**
12
- * https://graph-docs.deepcrawl.com/graphql/explorer/
13
- * Renew the DeepCrawl user token.
13
+ * https://api-docs.lumar.io/graphql/explorer/
14
+ * Renew the Lumar user token.
14
15
  */
15
16
  const initClient = async ({ auth }) => {
16
- // todo: Or was more than 6 hours ago
17
- if (null === global.deepcrawlGraphql.token) {
17
+ if (null === global.lumarGraphql.token) {
18
18
  const apiResponse = await (0, post_1.default)({
19
19
  data: {
20
20
  query: "mutation LoginWithUserKey($secret: String!, $userKeyId: ObjectID!) { createSessionUsingUserKey(input: {userKeyId: $userKeyId, secret: $secret}) { token }}",
@@ -23,7 +23,7 @@ const initClient = async ({ auth }) => {
23
23
  secret: auth.secret,
24
24
  },
25
25
  },
26
- url: `https://graph.deepcrawl.com/`,
26
+ url: `https://api.lumar.io/graphql`,
27
27
  });
28
28
  const token = apiResponse.getBodyDefaultTo({
29
29
  defaultValue: null,
@@ -31,7 +31,7 @@ const initClient = async ({ auth }) => {
31
31
  });
32
32
  // Ensure the value exists
33
33
  if (token) {
34
- global.deepcrawlGraphql.token = token;
34
+ global.lumarGraphql.token = token;
35
35
  }
36
36
  }
37
37
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@8ms/helpers",
3
3
  "license": "UNLICENSED",
4
- "version": "1.3.7",
4
+ "version": "1.3.9",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "git+https://github.com/8millionstories-organisation/8ms-helpers-ts.git"
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes