@8ms/helpers 2.0.42 → 2.0.44

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
@@ -6,7 +6,7 @@ export type QueryInput = string | {
6
6
  location?: string;
7
7
  params: QueryOptions;
8
8
  };
9
- type Datasets = {
9
+ type Dataset = {
10
10
  id: string;
11
11
  location: string;
12
12
  projectId: string;
@@ -34,7 +34,7 @@ export declare class GoogleBigQueryNamespace extends BaseNamespace {
34
34
  /**
35
35
  * Retrieve all the Datasets
36
36
  */
37
- getDataset: () => Promise<Datasets[]>;
37
+ getDatasets: () => Promise<Dataset[]>;
38
38
  query: (props: QueryInput) => Promise<any>;
39
39
  /**
40
40
  * Create a Table if it doesn't already exist.
@@ -43,11 +43,8 @@ class GoogleBigQueryNamespace extends _class_1.BaseNamespace {
43
43
  if (!this.client) {
44
44
  try {
45
45
  const { BigQuery } = await Promise.resolve().then(() => __importStar(require("@google-cloud/bigquery")));
46
- const formattedConfig = (0, server_1.getConfig)(this.config);
47
- this.client = new BigQuery({
48
- ...formattedConfig,
49
- projectId: this.config?.projectId,
50
- });
46
+ const formattedConfig = (0, server_1.getConfig)(this.config, this.config?.projectId);
47
+ this.client = new BigQuery(formattedConfig);
51
48
  }
52
49
  catch (e) {
53
50
  throw new Error("Google BigQuery Client not installed");
@@ -87,7 +84,7 @@ class GoogleBigQueryNamespace extends _class_1.BaseNamespace {
87
84
  /**
88
85
  * Retrieve all the Datasets
89
86
  */
90
- this.getDataset = async () => {
87
+ this.getDatasets = async () => {
91
88
  await this.ensureInit();
92
89
  let response = [];
93
90
  const datasets = await this.client.getDatasets();
@@ -13,15 +13,17 @@ export type GoogleCloudConfig = {
13
13
  /**
14
14
  * Using the response from Parameter Store and format it ready to be used with Google API.
15
15
  */
16
- export declare const getConfig: (parameter: GoogleCloudConfig) => {
17
- type: string;
18
- project_id: string;
19
- private_key_id: string;
20
- private_key: string;
21
- client_email: string;
22
- client_id: string;
23
- auth_uri: string;
24
- token_uri: string;
25
- auth_provider_x509_cert_url: string;
26
- client_x509_cert_url: string;
16
+ export declare const getConfig: (parameter: GoogleCloudConfig, projectId?: string) => {
17
+ credentials: {
18
+ type: string;
19
+ project_id: string;
20
+ private_key_id: string;
21
+ private_key: string;
22
+ client_email: string;
23
+ client_id: string;
24
+ auth_uri: string;
25
+ token_uri: string;
26
+ auth_provider_x509_cert_url: string;
27
+ client_x509_cert_url: string;
28
+ };
27
29
  };
package/google/server.js CHANGED
@@ -4,21 +4,26 @@ exports.getConfig = void 0;
4
4
  /**
5
5
  * Using the response from Parameter Store and format it ready to be used with Google API.
6
6
  */
7
- const getConfig = (parameter) => {
7
+ const getConfig = (parameter, projectId) => {
8
8
  // Format the private key to be in the same format as required by Google
9
9
  const privateKey = parameter["private_key"].replace(/\\n/g, "\n");
10
- const response = {
11
- type: parameter["type"],
12
- project_id: parameter["project_id"],
13
- private_key_id: parameter["private_key_id"],
14
- private_key: privateKey,
15
- client_email: parameter["client_email"],
16
- client_id: parameter["client_id"],
17
- auth_uri: parameter["auth_uri"],
18
- token_uri: parameter["token_uri"],
19
- auth_provider_x509_cert_url: parameter["auth_provider_x509_cert_url"],
20
- client_x509_cert_url: parameter["client_x509_cert_url"],
10
+ let response = {
11
+ credentials: {
12
+ type: parameter["type"],
13
+ project_id: parameter["project_id"],
14
+ private_key_id: parameter["private_key_id"],
15
+ private_key: privateKey,
16
+ client_email: parameter["client_email"],
17
+ client_id: parameter["client_id"],
18
+ auth_uri: parameter["auth_uri"],
19
+ token_uri: parameter["token_uri"],
20
+ auth_provider_x509_cert_url: parameter["auth_provider_x509_cert_url"],
21
+ client_x509_cert_url: parameter["client_x509_cert_url"],
22
+ },
21
23
  };
24
+ if (projectId) {
25
+ response['projectId'] = projectId;
26
+ }
22
27
  return response;
23
28
  };
24
29
  exports.getConfig = getConfig;
@@ -43,10 +43,9 @@ class GoogleSheetsNamespace extends _class_1.BaseNamespace {
43
43
  if (!this.client) {
44
44
  try {
45
45
  const googleApisSheets = await Promise.resolve().then(() => __importStar(require("@googleapis/sheets")));
46
- const formattedConfig = (0, server_1.getConfig)(this.config);
46
+ const formattedConfig = (0, server_1.getConfig)(this.config, this.config?.projectId);
47
47
  this.client = new googleApisSheets.auth.GoogleAuth({
48
- credentials: formattedConfig,
49
- projectId: this.config?.projectId,
48
+ ...formattedConfig,
50
49
  scopes: [
51
50
  "https://www.googleapis.com/auth/spreadsheets",
52
51
  ],
@@ -43,11 +43,8 @@ class GoogleCloudStorageNamespace extends _class_1.BaseNamespace {
43
43
  if (!this.client) {
44
44
  try {
45
45
  const { Storage } = await Promise.resolve().then(() => __importStar(require("@google-cloud/storage")));
46
- const formattedConfig = (0, server_1.getConfig)(this.config);
47
- this.client = new Storage({
48
- ...formattedConfig,
49
- projectId: this.config?.projectId,
50
- });
46
+ const formattedConfig = (0, server_1.getConfig)(this.config, this.config?.projectId);
47
+ this.client = new Storage(formattedConfig);
51
48
  }
52
49
  catch (e) {
53
50
  throw new Error("Google Cloud Storage Client not installed");
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@8ms/helpers",
3
3
  "license": "UNLICENSED",
4
- "version": "2.0.42",
4
+ "version": "2.0.44",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "git+https://github.com/8millionstories-organisation/8ms-helpers-ts.git"
package/prisma/server.js CHANGED
@@ -10,6 +10,7 @@ const prismaClient = async (key = "default", config) => {
10
10
  }
11
11
  if (!config) {
12
12
  if (key === "default") {
13
+ console.log('Library process.env.DATABASE_URL:', process.env.DATABASE_URL);
13
14
  config = {
14
15
  url: process.env.DATABASE_URL,
15
16
  isDebug: 'true' === process.env.DATABASE_IS_DEBUG,