@8ms/helpers 2.2.9 → 2.2.12

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 (178) hide show
  1. package/.github/workflows/deploy_npmjs.yml +3 -0
  2. package/_class/BaseClass.js +43 -52
  3. package/_class/BaseNamespace.js +17 -20
  4. package/_class/index.js +2 -7
  5. package/adverity/getJobs.js +7 -11
  6. package/adverity/index.js +51 -54
  7. package/adverity/server.js +1 -5
  8. package/api/ApiResponseClass.js +84 -88
  9. package/api/functions.js +13 -22
  10. package/api/index.js +3 -19
  11. package/api/types.js +5 -9
  12. package/array/index.js +3 -11
  13. package/atInternet/index.js +10 -13
  14. package/aws/ec2/AwsEc2Namespace.js +34 -74
  15. package/aws/ec2/server.js +5 -9
  16. package/aws/ecs/AwsEcsNamespace.js +110 -150
  17. package/aws/ecs/server.js +5 -9
  18. package/aws/glue/AwsGlueNamespace.js +26 -66
  19. package/aws/glue/server.js +5 -9
  20. package/aws/isResponse200.js +3 -7
  21. package/aws/lambda/AwsLambdaNamespace.js +62 -102
  22. package/aws/lambda/server.js +6 -11
  23. package/aws/s3/AwsS3Namespace.js +347 -390
  24. package/aws/s3/payload.js +29 -32
  25. package/aws/s3/server.js +9 -14
  26. package/aws/server.js +5 -10
  27. package/aws/ses/AwsSesNamespace.js +36 -76
  28. package/aws/ses/SimpleEmail.js +267 -304
  29. package/aws/ses/server.js +6 -11
  30. package/aws/sqs/AwsSqsNamespace.js +49 -89
  31. package/aws/sqs/server.js +5 -9
  32. package/aws/ssm/AwsSsmNamespace.js +43 -79
  33. package/aws/ssm/server.js +5 -9
  34. package/axios/deleteRequest.js +8 -15
  35. package/axios/get.js +8 -15
  36. package/axios/index.js +3 -9
  37. package/axios/post.js +8 -15
  38. package/boolean/index.js +3 -10
  39. package/brightData/serpApi/buildGoogleSerpUrl.js +1 -5
  40. package/brightData/serpApi/buildGoogleTrendsUrl.js +1 -5
  41. package/brightData/serpApi/getAsyncRequestId.js +8 -12
  42. package/brightData/serpApi/getAsyncResults.js +8 -12
  43. package/brightData/serpApi/getRealtime.js +3 -7
  44. package/brightData/serpApi/server.js +6 -14
  45. package/brightData/server.js +2 -7
  46. package/brightData/webScraperIde/getBatch.js +3 -7
  47. package/brightData/webScraperIde/getRealtime.js +11 -15
  48. package/brightData/webScraperIde/server.js +2 -7
  49. package/cache/server.js +2 -7
  50. package/cache/test/cache.test.js +4 -6
  51. package/crud/index.js +1 -4
  52. package/crypto/getDecrypt.js +2 -39
  53. package/crypto/getEncrypt.js +2 -39
  54. package/crypto/getRandom.js +1 -5
  55. package/crypto/getSha256.js +4 -41
  56. package/crypto/index.js +4 -11
  57. package/date/calculation.js +70 -99
  58. package/date/financialYear.js +16 -23
  59. package/date/format.js +40 -61
  60. package/date/index.js +4 -20
  61. package/date/type.js +4 -7
  62. package/environment/index.js +15 -25
  63. package/eskimi/getAgeGroup.js +3 -7
  64. package/eskimi/getData.js +3 -7
  65. package/eskimi/getDevice.js +3 -7
  66. package/eskimi/getGender.js +3 -7
  67. package/eskimi/server.js +23 -26
  68. package/file/index.js +8 -46
  69. package/geo/countries.js +1 -4
  70. package/geo/index.js +2 -7
  71. package/geo/languages.js +1 -4
  72. package/google/bigQuery/GoogleBigQueryNamespace.js +108 -148
  73. package/google/bigQuery/loadData.js +1 -5
  74. package/google/bigQuery/server.js +8 -14
  75. package/google/server.js +1 -5
  76. package/google/sheets/GoogleSheetsNamespace.js +34 -74
  77. package/google/sheets/getAssociatedData.js +1 -5
  78. package/google/sheets/server.js +8 -14
  79. package/google/storage/GoogleCloudStorageNamespace.js +62 -102
  80. package/google/storage/server.js +6 -10
  81. package/googleAds/GoogleAdsNamespace.js +28 -68
  82. package/googleAds/keywordPlanner/server.js +32 -35
  83. package/googleAds/server.js +6 -10
  84. package/googlePageSpeed/GooglePageSpeedNamespace.js +21 -28
  85. package/googlePageSpeed/server.js +8 -12
  86. package/googleSearchIncidents/server.js +28 -32
  87. package/greenDomain/server.js +17 -21
  88. package/inngest/server.js +1 -4
  89. package/json/getJsonNewline.js +3 -7
  90. package/json/index.js +2 -7
  91. package/json/isJson.js +1 -5
  92. package/littleWarden/LittleWardenNamespace.js +24 -31
  93. package/littleWarden/getUrlStatus.js +3 -7
  94. package/littleWarden/server.js +14 -22
  95. package/lumar/api/buildRequest.js +14 -18
  96. package/lumar/api/getData.js +3 -7
  97. package/lumar/api/initClient.js +3 -7
  98. package/lumar/api/server.js +6 -12
  99. package/lumar/graphql/columns.js +1 -4
  100. package/lumar/graphql/getData.js +3 -7
  101. package/lumar/graphql/initClient.js +3 -7
  102. package/lumar/graphql/queries/crawl.js +1 -2
  103. package/lumar/graphql/queries/getCrawls.js +1 -3
  104. package/lumar/graphql/queries/getReportDifferences.js +3 -5
  105. package/lumar/graphql/queries/getRows.js +1 -3
  106. package/lumar/graphql/queries/getTotals.js +1 -3
  107. package/lumar/graphql/queries/row.js +1 -2
  108. package/lumar/graphql/reportTemplates.js +1 -4
  109. package/lumar/graphql/server.js +7 -15
  110. package/myTarget/server.js +3 -7
  111. package/nextAuth/index.js +2 -6
  112. package/nextAuth/isSessionReady.js +1 -5
  113. package/nextJs/client/LazyLoad.js +5 -12
  114. package/nextJs/client.js +1 -5
  115. package/nextJs/index.js +2 -7
  116. package/number/format.js +3 -7
  117. package/number/formatCurrency.js +1 -5
  118. package/number/getDecimal.js +3 -7
  119. package/number/getNumber.js +3 -7
  120. package/number/getPercentIncrease.js +4 -8
  121. package/number/getSafeDivide.js +6 -10
  122. package/number/index.js +6 -15
  123. package/object/index.js +1 -5
  124. package/object/replaceKeys.js +3 -7
  125. package/onePassword/OnePasswordNamespace.js +36 -76
  126. package/onePassword/server.js +3 -7
  127. package/openAi/OpenAiNamespace.js +32 -39
  128. package/openAi/server.js +6 -10
  129. package/package.json +224 -122
  130. package/prisma/PrismaNamespace.js +53 -93
  131. package/prisma/getDecimal.js +5 -12
  132. package/prisma/server.js +4 -9
  133. package/scripts/generate-exports.js +50 -0
  134. package/snapchat/SnapchatNamespace.js +20 -27
  135. package/snapchat/server.js +6 -10
  136. package/sorting/byNumberAscending.js +1 -5
  137. package/sorting/byNumberDescending.js +1 -5
  138. package/sorting/byStringAscending.js +1 -5
  139. package/sorting/byStringDescending.js +1 -5
  140. package/sorting/index.js +4 -11
  141. package/stream/server.js +1 -5
  142. package/stream/sort.js +1 -5
  143. package/string/getCapitalised.js +3 -7
  144. package/string/getClean.js +17 -21
  145. package/string/getFolder.js +3 -10
  146. package/string/getProperCase.js +4 -8
  147. package/string/getString.js +8 -15
  148. package/string/getStringFromStream.js +1 -5
  149. package/string/getUnescaped.js +3 -10
  150. package/string/getWithoutAccents.js +1 -5
  151. package/string/getWithoutHtmlTags.js +1 -5
  152. package/string/getWithoutPunctuation.js +1 -5
  153. package/string/getWithoutUnderscores.js +1 -5
  154. package/string/getWithoutWhitespaces.js +1 -5
  155. package/string/index.js +12 -27
  156. package/string/reservedWords.js +5 -9
  157. package/swr/index.js +9 -18
  158. package/upTimeRobot/UpTimeRobotNamespace.js +32 -42
  159. package/upTimeRobot/server.js +11 -15
  160. package/url/index.js +12 -23
  161. package/url/server.js +1 -5
  162. package/url/writeUrlContents.js +6 -46
  163. package/util/defaultTo.js +5 -12
  164. package/util/getBrotliCompressed.js +3 -10
  165. package/util/getBrotliDecompressed.js +3 -10
  166. package/util/getClean.js +5 -9
  167. package/util/getError.js +1 -5
  168. package/util/getGzipCompressed.js +3 -10
  169. package/util/getGzipDecompressed.js +3 -10
  170. package/util/getWithoutHash.js +1 -5
  171. package/util/getWithoutParameter.js +1 -5
  172. package/util/index.js +7 -17
  173. package/util/isUndefined.js +3 -7
  174. package/util/promiseChunks.js +6 -10
  175. package/util/server.js +4 -11
  176. package/util/sleep.js +1 -5
  177. package/webWorker/index.js +1 -4
  178. package/xml/getXml.js +3 -7
@@ -1,10 +1,7 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.loadData = void 0;
4
1
  /**
5
2
  * Load data into a given table using Google Cloud Storage.
6
3
  */
7
- const loadData = async ({ file, googleBigQueryClient, googleCloudStorageClient, table }) => {
4
+ export const loadData = async ({ file, googleBigQueryClient, googleCloudStorageClient, table }) => {
8
5
  const tableExists = await googleBigQueryClient.tableExists(table.datasetId, table.tableId);
9
6
  if (tableExists) {
10
7
  await googleBigQueryClient.client
@@ -15,4 +12,3 @@ const loadData = async ({ file, googleBigQueryClient, googleCloudStorageClient,
15
12
  .file(file.key), file.metadata);
16
13
  }
17
14
  };
18
- exports.loadData = loadData;
@@ -1,10 +1,7 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.loadData = exports.getHandlerPath = exports.googleBigQueryClient = void 0;
4
- const GoogleBigQueryNamespace_1 = require("./GoogleBigQueryNamespace");
5
- const server_1 = require("../../onePassword/server");
1
+ import { GoogleBigQueryNamespace } from "./GoogleBigQueryNamespace";
2
+ import { onePasswordClient } from "../../onePassword/server";
6
3
  const googleBigQueryNamespaces = new Map();
7
- const googleBigQueryClient = async (key = "default", projectId, config, vaultId, itemId) => {
4
+ export const googleBigQueryClient = async (key = "default", projectId, config, vaultId, itemId) => {
8
5
  if (googleBigQueryNamespaces.has(key)) {
9
6
  return googleBigQueryNamespaces.get(key);
10
7
  }
@@ -16,7 +13,7 @@ const googleBigQueryClient = async (key = "default", projectId, config, vaultId,
16
13
  };
17
14
  }
18
15
  else if (vaultId && itemId) {
19
- const onePasswordConfig = await (await (0, server_1.onePasswordClient)())
16
+ const onePasswordConfig = await (await onePasswordClient())
20
17
  .getJsonNote(vaultId, itemId);
21
18
  instanceConfig = {
22
19
  ...onePasswordConfig,
@@ -24,7 +21,7 @@ const googleBigQueryClient = async (key = "default", projectId, config, vaultId,
24
21
  };
25
22
  }
26
23
  else if (process.env.GOOGLE_CLOUD_VAULT_ID && process.env.GOOGLE_CLOUD_ITEM_ID) {
27
- const onePasswordConfig = await (await (0, server_1.onePasswordClient)())
24
+ const onePasswordConfig = await (await onePasswordClient())
28
25
  .getJsonNote(process.env.GOOGLE_CLOUD_VAULT_ID, process.env.GOOGLE_CLOUD_ITEM_ID);
29
26
  instanceConfig = {
30
27
  ...onePasswordConfig,
@@ -34,15 +31,12 @@ const googleBigQueryClient = async (key = "default", projectId, config, vaultId,
34
31
  else {
35
32
  throw new Error(`Config required for namespace '${key}'`);
36
33
  }
37
- const namespace = new GoogleBigQueryNamespace_1.GoogleBigQueryNamespace(key, instanceConfig);
34
+ const namespace = new GoogleBigQueryNamespace(key, instanceConfig);
38
35
  googleBigQueryNamespaces.set(key, namespace);
39
36
  return namespace;
40
37
  };
41
- exports.googleBigQueryClient = googleBigQueryClient;
42
- const getHandlerPath = (input) => {
38
+ export const getHandlerPath = (input) => {
43
39
  return `${input.split(process.cwd())[1].substring(1)
44
40
  .replace(/\\/g, "/")}`;
45
41
  };
46
- exports.getHandlerPath = getHandlerPath;
47
- var loadData_1 = require("./loadData");
48
- Object.defineProperty(exports, "loadData", { enumerable: true, get: function () { return loadData_1.loadData; } });
42
+ export { loadData } from "./loadData";
package/google/server.js CHANGED
@@ -1,10 +1,7 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getConfig = void 0;
4
1
  /**
5
2
  * Using the response from Parameter Store and format it ready to be used with Google API.
6
3
  */
7
- const getConfig = (parameter, projectId) => {
4
+ export const getConfig = (parameter, projectId) => {
8
5
  // Format the private key to be in the same format as required by Google
9
6
  const privateKey = parameter["private_key"].replace(/\\n/g, "\n");
10
7
  let response = {
@@ -26,4 +23,3 @@ const getConfig = (parameter, projectId) => {
26
23
  }
27
24
  return response;
28
25
  };
29
- exports.getConfig = getConfig;
@@ -1,77 +1,37 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || (function () {
19
- var ownKeys = function(o) {
20
- ownKeys = Object.getOwnPropertyNames || function (o) {
21
- var ar = [];
22
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
- return ar;
24
- };
25
- return ownKeys(o);
1
+ import { BaseNamespace } from "../../_class";
2
+ import { getConfig } from "../server";
3
+ export class GoogleSheetsNamespace extends BaseNamespace {
4
+ ensureInit = async () => {
5
+ if (!this.client) {
6
+ try {
7
+ const googleApisSheets = await import("@googleapis/sheets");
8
+ const formattedConfig = getConfig(this.config, this.config?.projectId);
9
+ this.client = new googleApisSheets.auth.GoogleAuth({
10
+ ...formattedConfig,
11
+ scopes: [
12
+ "https://www.googleapis.com/auth/spreadsheets",
13
+ ],
14
+ });
15
+ }
16
+ catch (e) {
17
+ throw new Error("Google Sheets Client not installed");
18
+ }
19
+ }
26
20
  };
27
- return function (mod) {
28
- if (mod && mod.__esModule) return mod;
29
- var result = {};
30
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
- __setModuleDefault(result, mod);
32
- return result;
21
+ getBatchData = async (props) => {
22
+ await this.ensureInit();
23
+ const googleApisSheets = await import("@googleapis/sheets");
24
+ // Make the API request
25
+ const apiResponse = await googleApisSheets.sheets("v4")
26
+ .spreadsheets
27
+ .values
28
+ .batchGet({
29
+ auth: this.client,
30
+ dateTimeRenderOption: props?.dateTimeRender || "FORMATTED_STRING",
31
+ ranges: props.ranges,
32
+ spreadsheetId: props.spreadsheetId,
33
+ valueRenderOption: props?.valueRender || "UNFORMATTED_VALUE"
34
+ });
35
+ return apiResponse.data;
33
36
  };
34
- })();
35
- Object.defineProperty(exports, "__esModule", { value: true });
36
- exports.GoogleSheetsNamespace = void 0;
37
- const _class_1 = require("../../_class");
38
- const server_1 = require("../server");
39
- class GoogleSheetsNamespace extends _class_1.BaseNamespace {
40
- constructor() {
41
- super(...arguments);
42
- this.ensureInit = async () => {
43
- if (!this.client) {
44
- try {
45
- const googleApisSheets = await Promise.resolve().then(() => __importStar(require("@googleapis/sheets")));
46
- const formattedConfig = (0, server_1.getConfig)(this.config, this.config?.projectId);
47
- this.client = new googleApisSheets.auth.GoogleAuth({
48
- ...formattedConfig,
49
- scopes: [
50
- "https://www.googleapis.com/auth/spreadsheets",
51
- ],
52
- });
53
- }
54
- catch (e) {
55
- throw new Error("Google Sheets Client not installed");
56
- }
57
- }
58
- };
59
- this.getBatchData = async (props) => {
60
- await this.ensureInit();
61
- const googleApisSheets = await Promise.resolve().then(() => __importStar(require("@googleapis/sheets")));
62
- // Make the API request
63
- const apiResponse = await googleApisSheets.sheets("v4")
64
- .spreadsheets
65
- .values
66
- .batchGet({
67
- auth: this.client,
68
- dateTimeRenderOption: props?.dateTimeRender || "FORMATTED_STRING",
69
- ranges: props.ranges,
70
- spreadsheetId: props.spreadsheetId,
71
- valueRenderOption: props?.valueRender || "UNFORMATTED_VALUE"
72
- });
73
- return apiResponse.data;
74
- };
75
- }
76
37
  }
77
- exports.GoogleSheetsNamespace = GoogleSheetsNamespace;
@@ -1,10 +1,7 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getAssociatedData = void 0;
4
1
  /**
5
2
  * Pass a batch request using getBatchData and format the data into a key => value object per row.
6
3
  */
7
- const getAssociatedData = async (props) => {
4
+ export const getAssociatedData = async (props) => {
8
5
  let template = [];
9
6
  let response = [];
10
7
  // Missing ranges or too many ranges
@@ -40,4 +37,3 @@ const getAssociatedData = async (props) => {
40
37
  }
41
38
  return response;
42
39
  };
43
- exports.getAssociatedData = getAssociatedData;
@@ -1,10 +1,7 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getAssociatedData = exports.isCellNa = exports.googleSheetsAuths = void 0;
4
- const GoogleSheetsNamespace_1 = require("./GoogleSheetsNamespace");
5
- const server_1 = require("../../onePassword/server");
1
+ import { GoogleSheetsNamespace } from "./GoogleSheetsNamespace";
2
+ import { onePasswordClient } from "../../onePassword/server";
6
3
  const googleSheetsNamespaces = new Map();
7
- const googleSheetsAuths = async (key = "default", projectId, config, vaultId, itemId) => {
4
+ export const googleSheetsAuths = async (key = "default", projectId, config, vaultId, itemId) => {
8
5
  if (googleSheetsNamespaces.has(key)) {
9
6
  return googleSheetsNamespaces.get(key);
10
7
  }
@@ -16,7 +13,7 @@ const googleSheetsAuths = async (key = "default", projectId, config, vaultId, it
16
13
  };
17
14
  }
18
15
  else if (vaultId && itemId) {
19
- const onePasswordConfig = await (await (0, server_1.onePasswordClient)())
16
+ const onePasswordConfig = await (await onePasswordClient())
20
17
  .getJsonNote(vaultId, itemId);
21
18
  instanceConfig = {
22
19
  ...onePasswordConfig,
@@ -24,7 +21,7 @@ const googleSheetsAuths = async (key = "default", projectId, config, vaultId, it
24
21
  };
25
22
  }
26
23
  else if (process.env.GOOGLE_CLOUD_VAULT_ID && process.env.GOOGLE_CLOUD_ITEM_ID) {
27
- const onePasswordConfig = await (await (0, server_1.onePasswordClient)())
24
+ const onePasswordConfig = await (await onePasswordClient())
28
25
  .getJsonNote(process.env.GOOGLE_CLOUD_VAULT_ID, process.env.GOOGLE_CLOUD_ITEM_ID);
29
26
  instanceConfig = {
30
27
  ...onePasswordConfig,
@@ -34,15 +31,12 @@ const googleSheetsAuths = async (key = "default", projectId, config, vaultId, it
34
31
  else {
35
32
  throw new Error(`Config required for namespace '${key}'`);
36
33
  }
37
- const namespace = new GoogleSheetsNamespace_1.GoogleSheetsNamespace(key, instanceConfig);
34
+ const namespace = new GoogleSheetsNamespace(key, instanceConfig);
38
35
  googleSheetsNamespaces.set(key, namespace);
39
36
  return namespace;
40
37
  };
41
- exports.googleSheetsAuths = googleSheetsAuths;
42
38
  /**
43
39
  * Noticed sometimes Google Sheets can struggle with import XML resulting to N/A values.
44
40
  */
45
- const isCellNa = (input) => "#N/A" === input;
46
- exports.isCellNa = isCellNa;
47
- var getAssociatedData_1 = require("./getAssociatedData");
48
- Object.defineProperty(exports, "getAssociatedData", { enumerable: true, get: function () { return getAssociatedData_1.getAssociatedData; } });
41
+ export const isCellNa = (input) => "#N/A" === input;
42
+ export { getAssociatedData } from "./getAssociatedData";
@@ -1,106 +1,66 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || (function () {
19
- var ownKeys = function(o) {
20
- ownKeys = Object.getOwnPropertyNames || function (o) {
21
- var ar = [];
22
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
- return ar;
24
- };
25
- return ownKeys(o);
1
+ import { BaseNamespace } from "../../_class";
2
+ import { getConfig } from "../server";
3
+ export class GoogleCloudStorageNamespace extends BaseNamespace {
4
+ ensureInit = async () => {
5
+ if (!this.client) {
6
+ try {
7
+ const { Storage } = await import("@google-cloud/storage");
8
+ const formattedConfig = getConfig(this.config, this.config?.projectId);
9
+ this.client = new Storage(formattedConfig);
10
+ }
11
+ catch (e) {
12
+ throw new Error("Google Cloud Storage Client not installed");
13
+ }
14
+ }
26
15
  };
27
- return function (mod) {
28
- if (mod && mod.__esModule) return mod;
29
- var result = {};
30
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
- __setModuleDefault(result, mod);
32
- return result;
16
+ /**
17
+ * Copy a local file to Google Cloud Storage.
18
+ */
19
+ copyToCloud = async (bucket, localFile, options = {}) => {
20
+ await this.ensureInit();
21
+ const apiResponse = await this.client
22
+ .bucket(bucket)
23
+ .upload(localFile, options);
24
+ return apiResponse;
33
25
  };
34
- })();
35
- Object.defineProperty(exports, "__esModule", { value: true });
36
- exports.GoogleCloudStorageNamespace = void 0;
37
- const _class_1 = require("../../_class");
38
- const server_1 = require("../server");
39
- class GoogleCloudStorageNamespace extends _class_1.BaseNamespace {
40
- constructor() {
41
- super(...arguments);
42
- this.ensureInit = async () => {
43
- if (!this.client) {
44
- try {
45
- const { Storage } = await Promise.resolve().then(() => __importStar(require("@google-cloud/storage")));
46
- const formattedConfig = (0, server_1.getConfig)(this.config, this.config?.projectId);
47
- this.client = new Storage(formattedConfig);
48
- }
49
- catch (e) {
50
- throw new Error("Google Cloud Storage Client not installed");
51
- }
52
- }
53
- };
54
- /**
55
- * Copy a local file to Google Cloud Storage.
56
- */
57
- this.copyToCloud = async (bucket, localFile, options = {}) => {
58
- await this.ensureInit();
59
- const apiResponse = await this.client
60
- .bucket(bucket)
61
- .upload(localFile, options);
62
- return apiResponse;
63
- };
64
- /**
65
- * Check to see if a file exists but don't get the contents.
66
- */
67
- this.fileExists = async (bucket, key) => {
68
- await this.ensureInit();
69
- const googleFile = await this.client
70
- .bucket(bucket)
71
- .file(key)
72
- .exists();
73
- const response = googleFile?.[0];
74
- return response;
75
- };
76
- /**
77
- * Write a file to Google Cloud Storage.
78
- */
79
- this.writeFile = async (bucket, key, data, options = {}) => {
80
- await this.ensureInit();
81
- const stream = await Promise.resolve().then(() => __importStar(require("stream")));
82
- const dataStream = new stream.PassThrough();
83
- const googleFile = this.client
84
- .bucket(bucket)
85
- .file(key);
86
- dataStream.push(data);
87
- dataStream.push(null);
88
- return await new Promise((resolve, reject) => {
89
- dataStream.pipe(googleFile.createWriteStream({
90
- contentType: "auto",
91
- resumable: false,
92
- validation: false,
93
- metadata: {},
94
- ...options,
95
- }))
96
- .on("error", (error) => {
97
- reject(error);
98
- })
99
- .on("finish", () => {
100
- resolve(true);
101
- });
26
+ /**
27
+ * Check to see if a file exists but don't get the contents.
28
+ */
29
+ fileExists = async (bucket, key) => {
30
+ await this.ensureInit();
31
+ const googleFile = await this.client
32
+ .bucket(bucket)
33
+ .file(key)
34
+ .exists();
35
+ const response = googleFile?.[0];
36
+ return response;
37
+ };
38
+ /**
39
+ * Write a file to Google Cloud Storage.
40
+ */
41
+ writeFile = async (bucket, key, data, options = {}) => {
42
+ await this.ensureInit();
43
+ const stream = await import("stream");
44
+ const dataStream = new stream.PassThrough();
45
+ const googleFile = this.client
46
+ .bucket(bucket)
47
+ .file(key);
48
+ dataStream.push(data);
49
+ dataStream.push(null);
50
+ return await new Promise((resolve, reject) => {
51
+ dataStream.pipe(googleFile.createWriteStream({
52
+ contentType: "auto",
53
+ resumable: false,
54
+ validation: false,
55
+ metadata: {},
56
+ ...options,
57
+ }))
58
+ .on("error", (error) => {
59
+ reject(error);
60
+ })
61
+ .on("finish", () => {
62
+ resolve(true);
102
63
  });
103
- };
104
- }
64
+ });
65
+ };
105
66
  }
106
- exports.GoogleCloudStorageNamespace = GoogleCloudStorageNamespace;
@@ -1,10 +1,7 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.googleCloudStorageClient = void 0;
4
- const GoogleCloudStorageNamespace_1 = require("./GoogleCloudStorageNamespace");
5
- const server_1 = require("../../onePassword/server");
1
+ import { GoogleCloudStorageNamespace } from "./GoogleCloudStorageNamespace";
2
+ import { onePasswordClient } from "../../onePassword/server";
6
3
  const googleCloudStorageNamespaces = new Map();
7
- const googleCloudStorageClient = async (key = "default", projectId, config, vaultId, itemId) => {
4
+ export const googleCloudStorageClient = async (key = "default", projectId, config, vaultId, itemId) => {
8
5
  if (googleCloudStorageNamespaces.has(key)) {
9
6
  return googleCloudStorageNamespaces.get(key);
10
7
  }
@@ -16,7 +13,7 @@ const googleCloudStorageClient = async (key = "default", projectId, config, vaul
16
13
  };
17
14
  }
18
15
  else if (vaultId && itemId) {
19
- const onePasswordConfig = await (await (0, server_1.onePasswordClient)())
16
+ const onePasswordConfig = await (await onePasswordClient())
20
17
  .getJsonNote(vaultId, itemId);
21
18
  instanceConfig = {
22
19
  ...onePasswordConfig,
@@ -24,7 +21,7 @@ const googleCloudStorageClient = async (key = "default", projectId, config, vaul
24
21
  };
25
22
  }
26
23
  else if (process.env.GOOGLE_CLOUD_VAULT_ID && process.env.GOOGLE_CLOUD_ITEM_ID) {
27
- const onePasswordConfig = await (await (0, server_1.onePasswordClient)())
24
+ const onePasswordConfig = await (await onePasswordClient())
28
25
  .getJsonNote(process.env.GOOGLE_CLOUD_VAULT_ID, process.env.GOOGLE_CLOUD_ITEM_ID);
29
26
  instanceConfig = {
30
27
  ...onePasswordConfig,
@@ -34,8 +31,7 @@ const googleCloudStorageClient = async (key = "default", projectId, config, vaul
34
31
  else {
35
32
  throw new Error(`Config required for namespace '${key}'`);
36
33
  }
37
- const namespace = new GoogleCloudStorageNamespace_1.GoogleCloudStorageNamespace(key, instanceConfig);
34
+ const namespace = new GoogleCloudStorageNamespace(key, instanceConfig);
38
35
  googleCloudStorageNamespaces.set(key, namespace);
39
36
  return namespace;
40
37
  };
41
- exports.googleCloudStorageClient = googleCloudStorageClient;
@@ -1,71 +1,31 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || (function () {
19
- var ownKeys = function(o) {
20
- ownKeys = Object.getOwnPropertyNames || function (o) {
21
- var ar = [];
22
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
- return ar;
24
- };
25
- return ownKeys(o);
1
+ import { BaseNamespace } from "../_class";
2
+ export class GoogleAdsNamespace extends BaseNamespace {
3
+ mccAccountId = "";
4
+ refreshToken = "";
5
+ ensureInit = async () => {
6
+ if (!this.client) {
7
+ try {
8
+ const { GoogleAdsApi } = await import("google-ads-api");
9
+ this.client = new GoogleAdsApi({
10
+ client_id: this.config.client.clientId,
11
+ client_secret: this.config.client.clientSecret,
12
+ developer_token: this.config.client.developerToken,
13
+ });
14
+ this.mccAccountId = this.config.mccAccountId;
15
+ this.refreshToken = this.config.refreshToken;
16
+ }
17
+ catch (e) {
18
+ throw new Error("Google Sheets Client not installed");
19
+ }
20
+ }
26
21
  };
27
- return function (mod) {
28
- if (mod && mod.__esModule) return mod;
29
- var result = {};
30
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
- __setModuleDefault(result, mod);
32
- return result;
22
+ getCustomer = async (customerId) => {
23
+ await this.ensureInit();
24
+ const customer = this.client.Customer({
25
+ customer_id: customerId,
26
+ login_customer_id: global.googleAdsClient.mccAccountId,
27
+ refresh_token: global.googleAdsClient.refreshToken,
28
+ });
29
+ return customer;
33
30
  };
34
- })();
35
- Object.defineProperty(exports, "__esModule", { value: true });
36
- exports.GoogleAdsNamespace = void 0;
37
- const _class_1 = require("../_class");
38
- class GoogleAdsNamespace extends _class_1.BaseNamespace {
39
- constructor() {
40
- super(...arguments);
41
- this.mccAccountId = "";
42
- this.refreshToken = "";
43
- this.ensureInit = async () => {
44
- if (!this.client) {
45
- try {
46
- const { GoogleAdsApi } = await Promise.resolve().then(() => __importStar(require("google-ads-api")));
47
- this.client = new GoogleAdsApi({
48
- client_id: this.config.client.clientId,
49
- client_secret: this.config.client.clientSecret,
50
- developer_token: this.config.client.developerToken,
51
- });
52
- this.mccAccountId = this.config.mccAccountId;
53
- this.refreshToken = this.config.refreshToken;
54
- }
55
- catch (e) {
56
- throw new Error("Google Sheets Client not installed");
57
- }
58
- }
59
- };
60
- this.getCustomer = async (customerId) => {
61
- await this.ensureInit();
62
- const customer = this.client.Customer({
63
- customer_id: customerId,
64
- login_customer_id: global.googleAdsClient.mccAccountId,
65
- refresh_token: global.googleAdsClient.refreshToken,
66
- });
67
- return customer;
68
- };
69
- }
70
31
  }
71
- exports.GoogleAdsNamespace = GoogleAdsNamespace;