@8ms/helpers 2.0.36 → 2.0.38

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.
Binary file
@@ -2,8 +2,8 @@ import { BaseNamespace } from "../../_class";
2
2
  import { AwsConfig } from "../server";
3
3
  import type { EC2Client } from "@aws-sdk/client-ec2";
4
4
  export declare class AwsEc2Namespace extends BaseNamespace {
5
- client: EC2Client | null;
6
- config: AwsConfig | null;
5
+ client: EC2Client;
6
+ config: AwsConfig;
7
7
  ensureInit: () => Promise<void>;
8
8
  startInstances: (instanceIds: string[], additionalInfo?: string, dryRun?: boolean) => Promise<any>;
9
9
  stopInstances: (instanceIds: string[], hibernate?: boolean, force?: boolean, dryRun?: boolean) => Promise<any>;
@@ -25,8 +25,8 @@ type RunTaskProps = {
25
25
  taskDefinition?: string;
26
26
  };
27
27
  export declare class AwsEcsNamespace extends BaseNamespace {
28
- client: ECSClient | null;
29
- config: AwsConfig | null;
28
+ client: ECSClient;
29
+ config: AwsConfig;
30
30
  ensureInit: () => Promise<void>;
31
31
  /**
32
32
  * https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/client/ecs/command/ListClustersCommand/
@@ -2,8 +2,8 @@ import { BaseNamespace } from "../../_class";
2
2
  import { AwsConfig } from "../server";
3
3
  import type { GlueClient } from "@aws-sdk/client-glue";
4
4
  export declare class AwsGlueNamespace extends BaseNamespace {
5
- client: GlueClient | null;
6
- config: AwsConfig | null;
5
+ client: GlueClient;
6
+ config: AwsConfig;
7
7
  ensureInit: () => Promise<void>;
8
8
  /**
9
9
  * Invoke an AWS Glue Crawler by passing in the name of the Crawler.
@@ -8,8 +8,8 @@ type InvokeProps = {
8
8
  payload?: object;
9
9
  };
10
10
  export declare class AwsLambdaNamespace extends BaseNamespace {
11
- client: LambdaClient | null;
12
- config: AwsConfig | null;
11
+ client: LambdaClient;
12
+ config: AwsConfig;
13
13
  ensureInit: () => Promise<void>;
14
14
  /**
15
15
  * Invoke a AWS Lambda function by passing in the Function name and optional Payload data.
@@ -16,8 +16,8 @@ type WritePresignedPostProps = {
16
16
  url: string;
17
17
  };
18
18
  export declare class AwsS3Namespace extends BaseNamespace {
19
- client: S3Client | null;
20
- config: AwsConfig | null;
19
+ client: S3Client;
20
+ config: AwsConfig;
21
21
  ensureInit: () => Promise<void>;
22
22
  copy: (fromBucket: string, fromKey: string, toBucket: string, toKey: string) => Promise<void>;
23
23
  deleteFile: (bucket: string, key: string) => Promise<void>;
@@ -2,8 +2,8 @@ import { BaseNamespace } from "../../_class";
2
2
  import { AwsConfig } from "../server";
3
3
  import type { SendEmailCommandInput, SESClient } from "@aws-sdk/client-ses";
4
4
  export declare class AwsSesNamespace extends BaseNamespace {
5
- client: SESClient | null;
6
- config: AwsConfig | null;
5
+ client: SESClient;
6
+ config: AwsConfig;
7
7
  ensureInit: () => Promise<void>;
8
8
  send: (input: SendEmailCommandInput) => Promise<any>;
9
9
  }
@@ -24,8 +24,8 @@ type AddToQueue = {
24
24
  queueUrl: string;
25
25
  };
26
26
  export declare class AwsSqsNamespace extends BaseNamespace {
27
- client: SQSClient | null;
28
- config: AwsConfig | null;
27
+ client: SQSClient;
28
+ config: AwsConfig;
29
29
  ensureInit: () => Promise<void>;
30
30
  addToQueue: (props: AddToQueue) => Promise<import("@aws-sdk/client-sqs").SendMessageCommandOutput>;
31
31
  deleteFromQueue: (queueUrl: string, recipientHandle: string) => Promise<import("@aws-sdk/client-sqs").DeleteMessageCommandOutput>;
@@ -2,8 +2,8 @@ import { BaseNamespace } from "../../_class";
2
2
  import { AwsConfig } from "../server";
3
3
  import type { SSMClient } from "@aws-sdk/client-ssm";
4
4
  export declare class AwsSsmNamespace extends BaseNamespace {
5
- client: SSMClient | null;
6
- config: AwsConfig | null;
5
+ client: SSMClient;
6
+ config: AwsConfig;
7
7
  parameters: Map<string, any>;
8
8
  constructor(key: string, config: any);
9
9
  ensureInit: () => Promise<void>;
package/date/format.d.ts CHANGED
@@ -33,6 +33,11 @@ export declare const getFullDateTime: (input: InputDate) => string;
33
33
  * Example: 1901-02-03 → Feb 1901
34
34
  */
35
35
  export declare const getMonthYearString: (input: InputDate) => string;
36
+ /**
37
+ * Returns a YYYY MMM value as a number for a given year.
38
+ * Example: 1901-02-03 → 1901 Feb
39
+ */
40
+ export declare const getYearMonthString: (input: InputDate) => string;
36
41
  /**
37
42
  * Shorthand to get the current date.
38
43
  */
package/date/format.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.parseExcelDate = exports.getYmdString = exports.getYmdNumber = exports.getYmdHisString = exports.getYmdHisNumber = exports.getYearNumber = exports.getTodayYmdHisNumber = exports.getTodayYmdNumber = exports.getTodayYmdHisString = exports.getTodayYmdString = exports.getMonthYearString = exports.getFullDateTime = exports.getFullDate = exports.getDayNumber = exports.format = exports.getDurationMinutes = exports.getDurationHours = void 0;
3
+ exports.parseExcelDate = exports.getYmdString = exports.getYmdNumber = exports.getYmdHisString = exports.getYmdHisNumber = exports.getYearNumber = exports.getTodayYmdHisNumber = exports.getTodayYmdNumber = exports.getTodayYmdHisString = exports.getTodayYmdString = exports.getYearMonthString = exports.getMonthYearString = exports.getFullDateTime = exports.getFullDate = exports.getDayNumber = exports.format = exports.getDurationMinutes = exports.getDurationHours = void 0;
4
4
  const calculation_1 = require("./calculation");
5
5
  const luxon_1 = require("luxon");
6
6
  /**
@@ -73,7 +73,7 @@ exports.getFullDate = getFullDate;
73
73
  * Example: 1901-02-03 01:23:45 → 1:23am 3 Feb 1901
74
74
  */
75
75
  const getFullDateTime = (input) => {
76
- return (0, exports.format)(input, "d MMM yyyy h:mmaaa");
76
+ return (0, exports.format)(input, "d MMM yyyy h:mm:ss");
77
77
  };
78
78
  exports.getFullDateTime = getFullDateTime;
79
79
  /**
@@ -84,6 +84,14 @@ const getMonthYearString = (input) => {
84
84
  return (0, exports.format)(input, "MMM yyyy");
85
85
  };
86
86
  exports.getMonthYearString = getMonthYearString;
87
+ /**
88
+ * Returns a YYYY MMM value as a number for a given year.
89
+ * Example: 1901-02-03 → 1901 Feb
90
+ */
91
+ const getYearMonthString = (input) => {
92
+ return (0, exports.format)(input, "yyyy MMM");
93
+ };
94
+ exports.getYearMonthString = getYearMonthString;
87
95
  /**
88
96
  * Shorthand to get the current date.
89
97
  */
@@ -1,5 +1,5 @@
1
1
  import { BaseNamespace } from "../../_class";
2
- import type { BigQuery, QueryOptions } from "@google-cloud/bigquery";
2
+ import type { BigQuery, DatasetResource, QueryOptions } from "@google-cloud/bigquery";
3
3
  import { GoogleCloudConfig } from "../server";
4
4
  export type QueryInput = string | {
5
5
  query: string;
@@ -15,14 +15,16 @@ type Tables = {
15
15
  id: string;
16
16
  };
17
17
  export declare class GoogleBigQueryNamespace extends BaseNamespace {
18
- client: BigQuery | null;
19
- config: GoogleCloudConfig | null;
18
+ client: BigQuery;
19
+ config: GoogleCloudConfig & {
20
+ defaultProjectId: string;
21
+ };
20
22
  ensureInit: () => Promise<void>;
21
23
  /**
22
24
  * Create a Dataset if it doesn't already exist.
23
25
  * Returns table instance.
24
26
  */
25
- createDataset: (datasetId: string, options?: object) => Promise<void>;
27
+ createDataset: (datasetId: string, options?: DatasetResource) => Promise<void>;
26
28
  /**
27
29
  * Check to see whether a given BigQuery dataset exists.
28
30
  * Based off:
@@ -44,8 +44,10 @@ class GoogleBigQueryNamespace extends _class_1.BaseNamespace {
44
44
  try {
45
45
  const { BigQuery } = await Promise.resolve().then(() => __importStar(require("@google-cloud/bigquery")));
46
46
  const formattedConfig = (0, server_1.getConfig)(this.config);
47
- // @ts-ignore
48
- this.client = new BigQuery(formattedConfig);
47
+ this.client = new BigQuery({
48
+ ...formattedConfig,
49
+ projectId: this.config.defaultProjectId,
50
+ });
49
51
  }
50
52
  catch (e) {
51
53
  throw new Error("Google BigQuery Client not installed");
@@ -60,7 +62,8 @@ class GoogleBigQueryNamespace extends _class_1.BaseNamespace {
60
62
  await this.ensureInit();
61
63
  const datasetExists = await this.datasetExists(datasetId);
62
64
  if (!datasetExists) {
63
- await this.client.createDataset(datasetId, options || {});
65
+ await this.client
66
+ .createDataset(datasetId);
64
67
  }
65
68
  };
66
69
  /**
@@ -103,11 +106,7 @@ class GoogleBigQueryNamespace extends _class_1.BaseNamespace {
103
106
  await this.ensureInit();
104
107
  let queryString = "string" === typeof props ? props : props.query;
105
108
  let options = "string" === typeof props ? {} : props?.params;
106
- const apiResponse = await this.client.query({
107
- query: queryString,
108
- // @ts-ignore
109
- options,
110
- });
109
+ const apiResponse = await this.client.query(queryString, options);
111
110
  return apiResponse;
112
111
  };
113
112
  /**
@@ -1,6 +1,6 @@
1
1
  import { GoogleBigQueryNamespace } from "./GoogleBigQueryNamespace";
2
2
  import type { GoogleAuthOptions } from "@google-cloud/common";
3
- export declare const googleBigQueryClient: (key?: string, config?: GoogleAuthOptions, vaultId?: string, itemId?: string) => Promise<GoogleBigQueryNamespace>;
3
+ export declare const googleBigQueryClient: (defaultProjectId: string, key?: string, config?: GoogleAuthOptions, vaultId?: string, itemId?: string) => Promise<GoogleBigQueryNamespace>;
4
4
  export declare const getHandlerPath: (input: string) => string;
5
5
  export { loadData } from "./loadData";
6
6
  export type { QueryInput } from "./GoogleBigQueryNamespace";
@@ -4,21 +4,32 @@ exports.loadData = exports.getHandlerPath = exports.googleBigQueryClient = void
4
4
  const GoogleBigQueryNamespace_1 = require("./GoogleBigQueryNamespace");
5
5
  const server_1 = require("../../onePassword/server");
6
6
  const googleBigQueryNamespaces = new Map();
7
- const googleBigQueryClient = async (key = "default", config, vaultId, itemId) => {
7
+ const googleBigQueryClient = async (defaultProjectId, key = "default", config, vaultId, itemId) => {
8
8
  if (googleBigQueryNamespaces.has(key)) {
9
9
  return googleBigQueryNamespaces.get(key);
10
10
  }
11
11
  let instanceConfig;
12
12
  if (config) {
13
- instanceConfig = config;
13
+ instanceConfig = {
14
+ ...config,
15
+ defaultProjectId,
16
+ };
14
17
  }
15
18
  else if (vaultId && itemId) {
16
- instanceConfig = await (await (0, server_1.onePasswordClient)())
19
+ const onePasswordConfig = await (await (0, server_1.onePasswordClient)())
17
20
  .getJsonNote(vaultId, itemId);
21
+ instanceConfig = {
22
+ ...onePasswordConfig,
23
+ defaultProjectId,
24
+ };
18
25
  }
19
26
  else if ("default" === key && process.env.GOOGLE_CLOUD_VAULT_ID && process.env.GOOGLE_CLOUD_ITEM_ID) {
20
- instanceConfig = await (await (0, server_1.onePasswordClient)())
27
+ const onePasswordConfig = await (await (0, server_1.onePasswordClient)())
21
28
  .getJsonNote(process.env.GOOGLE_CLOUD_VAULT_ID, process.env.GOOGLE_CLOUD_ITEM_ID);
29
+ instanceConfig = {
30
+ ...onePasswordConfig,
31
+ defaultProjectId,
32
+ };
22
33
  }
23
34
  else {
24
35
  throw new Error(`Config required for namespace '${key}'`);
@@ -8,8 +8,8 @@ type GetBatchDataProps = {
8
8
  valueRender?: string;
9
9
  };
10
10
  export declare class GoogleSheetsNamespace extends BaseNamespace {
11
- client: GoogleAuth | null;
12
- config: GoogleCloudConfig | null;
11
+ client: GoogleAuth;
12
+ config: GoogleCloudConfig;
13
13
  ensureInit: () => Promise<void>;
14
14
  getBatchData: (props: GetBatchDataProps) => Promise<import("@googleapis/sheets").sheets_v4.Schema$BatchGetValuesResponse>;
15
15
  }
@@ -2,8 +2,8 @@ import { BaseNamespace } from "../../_class";
2
2
  import type { Storage } from "@google-cloud/storage";
3
3
  import { GoogleCloudConfig } from "../server";
4
4
  export declare class GoogleCloudStorageNamespace extends BaseNamespace {
5
- client: Storage | null;
6
- config: GoogleCloudConfig | null;
5
+ client: Storage;
6
+ config: GoogleCloudConfig;
7
7
  ensureInit: () => Promise<void>;
8
8
  /**
9
9
  * Copy a local file to Google Cloud Storage.
@@ -2,8 +2,8 @@ import { BaseNamespace } from "../_class";
2
2
  import type { GoogleAdsApi } from "google-ads-api";
3
3
  import { Config } from "./server";
4
4
  export declare class GoogleAdsNamespace extends BaseNamespace {
5
- client: GoogleAdsApi | null;
6
- config: Config | null;
5
+ client: GoogleAdsApi;
6
+ config: Config;
7
7
  mccAccountId: string;
8
8
  refreshToken: string;
9
9
  ensureInit: () => Promise<void>;
@@ -4,8 +4,8 @@ import { Category, GooglePageSpeedConfig, Strategy } from "./server";
4
4
  * Based on https://developers.google.com/speed/docs/insights/rest/v5/pagespeedapi/runpagespeed
5
5
  */
6
6
  export declare class GooglePageSpeedNamespace extends BaseNamespace {
7
- client: boolean | null;
8
- config: GooglePageSpeedConfig | null;
7
+ client: boolean;
8
+ config: GooglePageSpeedConfig;
9
9
  ensureInit: () => Promise<void>;
10
10
  getReport: (url: string, category?: Category, strategy?: Strategy) => Promise<any>;
11
11
  }
@@ -4,8 +4,8 @@ import { LittleWardenConfig } from "./server";
4
4
  * Based on https://developers.google.com/speed/docs/insights/rest/v5/pagespeedapi/runpagespeed
5
5
  */
6
6
  export declare class LittleWardenNamespace extends BaseNamespace {
7
- client: boolean | null;
8
- config: LittleWardenConfig | null;
7
+ client: boolean;
8
+ config: LittleWardenConfig;
9
9
  ensureInit: () => Promise<void>;
10
10
  getReport: (urlId: string) => Promise<any>;
11
11
  }
@@ -2,8 +2,8 @@ import { OnePasswordConfig } from "./server";
2
2
  import { BaseNamespace } from "../_class";
3
3
  import type { Client } from "@1password/sdk";
4
4
  export declare class OnePasswordNamespace extends BaseNamespace {
5
- client: Client | null;
6
- config: OnePasswordConfig | null;
5
+ client: Client;
6
+ config: OnePasswordConfig;
7
7
  ensureInit: () => Promise<void>;
8
8
  listVaults: () => Promise<import("@1password/sdk").VaultOverview[]>;
9
9
  getItem: (vaultId: string, itemId: string) => Promise<import("@1password/sdk").Item>;
@@ -1,8 +1,8 @@
1
1
  import { OpenAiConfig } from "./server";
2
2
  import { BaseNamespace } from "../_class";
3
3
  export declare class OpenAiNamespace extends BaseNamespace {
4
- client: boolean | null;
5
- config: OpenAiConfig | null;
4
+ client: boolean;
5
+ config: OpenAiConfig;
6
6
  /**
7
7
  * Renew the access token as it expires every 3 hours.
8
8
  */
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@8ms/helpers",
3
3
  "license": "UNLICENSED",
4
- "version": "2.0.36",
4
+ "version": "2.0.38",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "git+https://github.com/8millionstories-organisation/8ms-helpers-ts.git"
@@ -5,8 +5,8 @@ type Client = {
5
5
  refreshToken: string;
6
6
  };
7
7
  export declare class SnapchatNamespace extends BaseNamespace {
8
- client: Client | null;
9
- config: SnapchatConfig | null;
8
+ client: Client;
9
+ config: SnapchatConfig;
10
10
  /**
11
11
  * Renew the access token as it expires every 3 hours.
12
12
  */
@@ -20,8 +20,8 @@ type GetReportProps = {
20
20
  * https://uptimerobot.com/api/
21
21
  */
22
22
  export declare class UpTimeRobotNamespace extends BaseNamespace {
23
- client: boolean | null;
24
- config: UpTimeRobotConfig | null;
23
+ client: boolean;
24
+ config: UpTimeRobotConfig;
25
25
  /**
26
26
  * Renew the access token as it expires every 3 hours.
27
27
  */