@8ms/helpers 1.1.66 → 1.1.71

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 (208) hide show
  1. package/api/response.js +2 -2
  2. package/api/states.js +1 -1
  3. package/api/unexpectedError.js +1 -1
  4. package/array/contains.js +1 -4
  5. package/array/getArray.js +2 -5
  6. package/aws/athenaExpress/initClient.d.ts +1 -1
  7. package/aws/athenaExpress/initClient.js +6 -7
  8. package/aws/athenaExpress/query.d.ts +8 -0
  9. package/aws/athenaExpress/query.js +10 -0
  10. package/aws/getConfig.d.ts +5 -1
  11. package/aws/getConfig.js +2 -3
  12. package/aws/glue/initClient.d.ts +5 -4
  13. package/aws/glue/initClient.js +4 -5
  14. package/aws/glue/invoke.d.ts +1 -3
  15. package/aws/glue/invoke.js +12 -63
  16. package/aws/isResponse200.js +4 -5
  17. package/aws/lambda/getHandlerPath.d.ts +4 -3
  18. package/aws/lambda/getHandlerPath.js +3 -4
  19. package/aws/lambda/initClient.d.ts +5 -4
  20. package/aws/lambda/initClient.js +4 -5
  21. package/aws/lambda/invoke.d.ts +1 -3
  22. package/aws/lambda/invoke.js +29 -77
  23. package/aws/s3/copyFile.js +7 -55
  24. package/aws/s3/deleteFile.js +6 -54
  25. package/aws/s3/deleteFiles.d.ts +5 -6
  26. package/aws/s3/deleteFiles.js +10 -58
  27. package/aws/s3/deleteFolder.d.ts +5 -6
  28. package/aws/s3/deleteFolder.js +26 -76
  29. package/aws/s3/getGlueJson.d.ts +3 -2
  30. package/aws/s3/getGlueJson.js +4 -5
  31. package/aws/s3/getPresignedPost.d.ts +6 -7
  32. package/aws/s3/getPresignedPost.js +9 -56
  33. package/aws/s3/getSignedUrl.js +8 -76
  34. package/aws/s3/initClient.d.ts +5 -4
  35. package/aws/s3/initClient.js +4 -5
  36. package/aws/s3/isFileExists.js +17 -66
  37. package/aws/s3/listFiles.js +22 -69
  38. package/aws/s3/listFolders.js +21 -68
  39. package/aws/s3/moveFile.d.ts +5 -4
  40. package/aws/s3/moveFile.js +10 -58
  41. package/aws/s3/readBuffer.js +41 -89
  42. package/aws/s3/readFile.js +42 -93
  43. package/aws/s3/writeFile.js +10 -72
  44. package/aws/s3/writePresignedPost.d.ts +2 -3
  45. package/aws/s3/writePresignedPost.js +22 -93
  46. package/aws/s3cache/getCache.js +25 -69
  47. package/aws/s3cache/getKey.js +7 -8
  48. package/aws/s3cache/saveCache.js +3 -49
  49. package/aws/s3cache/updateCache.js +13 -65
  50. package/aws/ses/SimpleEmail.d.ts +10 -13
  51. package/aws/ses/SimpleEmail.js +85 -189
  52. package/aws/ses/initClient.d.ts +5 -4
  53. package/aws/ses/initClient.js +4 -5
  54. package/aws/ssm/getParameter.js +31 -78
  55. package/aws/ssm/initClient.d.ts +5 -4
  56. package/aws/ssm/initClient.js +4 -5
  57. package/axios/get.js +35 -106
  58. package/axios/post.js +35 -106
  59. package/boolean/getBoolean.js +2 -3
  60. package/class/BaseClass.js +15 -22
  61. package/crypto/getDecrypt.js +3 -4
  62. package/crypto/getEncrypt.js +3 -4
  63. package/crypto/getRandom.js +1 -2
  64. package/crypto/getSha256.js +4 -5
  65. package/date/durationComparisons.js +1 -1
  66. package/date/durations.js +1 -1
  67. package/date/format.js +7 -8
  68. package/date/getDate.js +19 -20
  69. package/date/getDatesBetween.js +8 -9
  70. package/date/getDurationHours.js +6 -7
  71. package/date/getDurationMinutes.js +6 -7
  72. package/date/getFinancialYear.js +11 -12
  73. package/date/getFinancialYearToDate.js +5 -5
  74. package/date/getFinancialYearToYesterday.js +5 -5
  75. package/date/getFinancialYearWeeks.js +10 -11
  76. package/date/getLastWeek.js +11 -12
  77. package/date/getMax.js +5 -6
  78. package/date/getMidnight.js +2 -3
  79. package/date/getMin.js +5 -6
  80. package/date/getMonday.js +10 -11
  81. package/date/getNumber.js +4 -5
  82. package/date/getPredefinedTimeframe.js +5 -6
  83. package/date/getSunday.js +10 -11
  84. package/date/getThisWeek.js +11 -12
  85. package/date/getTimeZoned.js +11 -12
  86. package/date/getToday.js +6 -7
  87. package/date/getTwoWeeksAgo.js +11 -12
  88. package/date/getWeeksAgo.js +5 -6
  89. package/date/getYesterday.js +7 -8
  90. package/date/isDateValid.js +6 -7
  91. package/date/isLastWeek.js +3 -4
  92. package/date/isThisWeek.js +3 -4
  93. package/date/parseExcelDate.js +9 -10
  94. package/deepCrawl/buildRequest.js +19 -20
  95. package/deepCrawl/getData.js +21 -79
  96. package/deepCrawl/initClient.js +17 -64
  97. package/deepCrawl/operands.js +1 -1
  98. package/deepCrawl/orders.js +1 -1
  99. package/deepCrawl/reports.js +1 -1
  100. package/environment/environments.js +1 -1
  101. package/environment/getEnvironment.js +8 -8
  102. package/environment/isAws.js +2 -2
  103. package/environment/isDevelopment.js +3 -3
  104. package/environment/isLocalhost.js +4 -4
  105. package/environment/isProduction.js +3 -3
  106. package/environment/isStaging.js +3 -3
  107. package/environment/isVercel.js +1 -1
  108. package/environment/platforms.d.ts +1 -1
  109. package/environment/platforms.js +1 -1
  110. package/eskimi/ageGroups.js +1 -1
  111. package/eskimi/devices.js +1 -1
  112. package/eskimi/endpoints.js +1 -1
  113. package/eskimi/genders.js +1 -1
  114. package/eskimi/getAccessToken.js +11 -57
  115. package/eskimi/getAgeGroup.js +3 -4
  116. package/eskimi/getCampaignIds.js +2 -3
  117. package/eskimi/getDevice.js +3 -4
  118. package/eskimi/getGender.js +3 -4
  119. package/eskimi/request.js +13 -59
  120. package/google/bigQuery/initClient.d.ts +11 -0
  121. package/google/bigQuery/initClient.js +22 -0
  122. package/google/bigQuery/query.d.ts +9 -0
  123. package/google/bigQuery/query.js +10 -0
  124. package/google/getConfig.d.ts +20 -0
  125. package/google/getConfig.js +23 -0
  126. package/google/sheets/getAssociatedData.d.ts +2 -6
  127. package/google/sheets/getAssociatedData.js +42 -89
  128. package/google/sheets/getBatchData.d.ts +1 -3
  129. package/google/sheets/getBatchData.js +15 -60
  130. package/google/sheets/initClient.d.ts +11 -0
  131. package/google/sheets/initClient.js +25 -0
  132. package/google/sheets/isCellNa.js +1 -4
  133. package/google/storage/initClient.d.ts +12 -0
  134. package/google/storage/initClient.js +23 -0
  135. package/google/storage/writeFile.d.ts +2 -1
  136. package/google/storage/writeFile.js +20 -77
  137. package/googleAds/getCustomer.js +7 -48
  138. package/googleAds/initClient.d.ts +9 -8
  139. package/googleAds/initClient.js +13 -56
  140. package/initClients.d.ts +13 -3
  141. package/initClients.js +95 -101
  142. package/json/isJson.js +1 -2
  143. package/littleWarden/getUrlStatus.js +10 -56
  144. package/littleWarden/isAllGood.js +3 -4
  145. package/littleWarden/isDanger.js +3 -4
  146. package/littleWarden/isWarning.js +3 -4
  147. package/littleWarden/states.js +1 -1
  148. package/myTarget/getAccessToken.js +11 -57
  149. package/myTarget/request.js +13 -59
  150. package/nextAuth/isSessionReady.js +2 -3
  151. package/nextAuth/states.js +1 -1
  152. package/nextJs/getIp.js +2 -3
  153. package/nextJs/getUserAgent.js +1 -4
  154. package/number/getDivide.js +4 -5
  155. package/number/getNumber.js +6 -7
  156. package/number/getPercent.js +4 -5
  157. package/number/getPercentIncrease.js +4 -5
  158. package/number/getRounded.js +5 -6
  159. package/package.json +2 -1
  160. package/prisma/initClient.js +4 -5
  161. package/snapchat/getAccessToken.js +25 -72
  162. package/sorting/byNumberAscending.js +3 -4
  163. package/sorting/byNumberDescending.js +3 -4
  164. package/sorting/byStringAscending.js +3 -4
  165. package/sorting/byStringDescending.js +3 -4
  166. package/string/formatCapitalise.js +2 -3
  167. package/string/getCleanFolder.js +3 -6
  168. package/string/getString.js +9 -10
  169. package/string/getStringFromStream.js +7 -8
  170. package/string/toProperCase.js +6 -7
  171. package/swr/isAllData.js +4 -5
  172. package/swr/isAnyError.js +4 -5
  173. package/swr/isAnyLoading.js +4 -5
  174. package/swr/isData.js +1 -4
  175. package/swr/isError.js +1 -4
  176. package/swr/isLoading.js +3 -6
  177. package/upTimeRobot/getMonitors.d.ts +1 -0
  178. package/upTimeRobot/getMonitors.js +33 -0
  179. package/upTimeRobot/logTypes.d.ts +7 -0
  180. package/upTimeRobot/logTypes.js +9 -0
  181. package/upTimeRobot/monitorStatuses.d.ts +8 -0
  182. package/upTimeRobot/monitorStatuses.js +10 -0
  183. package/upTimeRobot/monitorSubTypes.d.ts +10 -0
  184. package/upTimeRobot/monitorSubTypes.js +12 -0
  185. package/upTimeRobot/monitorTypes.d.ts +8 -0
  186. package/upTimeRobot/monitorTypes.js +10 -0
  187. package/upTimeRobot/requestStatuses.d.ts +5 -0
  188. package/upTimeRobot/requestStatuses.js +7 -0
  189. package/url/buildParameters.js +7 -8
  190. package/url/buildRelative.js +3 -4
  191. package/url/buildUrl.js +6 -7
  192. package/url/isAbsolute.js +1 -2
  193. package/url/isRelative.js +2 -5
  194. package/util/defaultTo.d.ts +6 -5
  195. package/util/defaultTo.js +6 -7
  196. package/util/isUndefined.d.ts +9 -0
  197. package/util/isUndefined.js +19 -0
  198. package/util/sleep.js +2 -3
  199. package/webWorker/states.js +1 -1
  200. package/xml/getXml.js +10 -58
  201. package/aws/athenaExpress/request.d.ts +0 -8
  202. package/aws/athenaExpress/request.js +0 -54
  203. package/aws/config.d.ts +0 -5
  204. package/aws/config.js +0 -2
  205. package/google/getCredentials.d.ts +0 -20
  206. package/google/getCredentials.js +0 -76
  207. package/google/sheets/getAuth.d.ts +0 -8
  208. package/google/sheets/getAuth.js +0 -69
@@ -0,0 +1,12 @@
1
+ import { Config } from '../getConfig';
2
+ declare type InitClient = {
3
+ parameter: Config;
4
+ projectId: string;
5
+ };
6
+ /**
7
+ * Initialise the Google Sheets instance using the separate service method.
8
+ * https://github.com/googleapis/google-api-nodejs-client
9
+ * Library: @googleapis/sheets
10
+ */
11
+ declare const initClient: ({ parameter, projectId }: InitClient) => void;
12
+ export default initClient;
@@ -0,0 +1,23 @@
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 getConfig_1 = __importDefault(require("../getConfig"));
7
+ global.googleStorageClient = {};
8
+ /**
9
+ * Initialise the Google Sheets instance using the separate service method.
10
+ * https://github.com/googleapis/google-api-nodejs-client
11
+ * Library: @googleapis/sheets
12
+ */
13
+ const initClient = ({ parameter, projectId }) => {
14
+ if (!global.googleStorageClient[projectId]) {
15
+ const { Storage } = require('@google-cloud/storage');
16
+ const formattedConfig = (0, getConfig_1.default)({ parameter });
17
+ global.googleStorageClient[projectId] = new Storage({
18
+ credentials: formattedConfig,
19
+ projectId: projectId,
20
+ });
21
+ }
22
+ };
23
+ exports.default = initClient;
@@ -3,9 +3,10 @@ declare type WriteFile = {
3
3
  credentials: any;
4
4
  data: any;
5
5
  key: string;
6
+ projectId: string;
6
7
  };
7
8
  /**
8
9
  * Write a file to Google Cloud Storage.
9
10
  */
10
- export declare const writeFile: ({ bucket, credentials, data, key }: WriteFile) => Promise<any>;
11
+ export declare const writeFile: ({ bucket, data, key, projectId }: WriteFile) => Promise<any>;
11
12
  export default writeFile;
@@ -1,86 +1,29 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- var __generator = (this && this.__generator) || function (thisArg, body) {
12
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
- function verb(n) { return function (v) { return step([n, v]); }; }
15
- function step(op) {
16
- if (f) throw new TypeError("Generator is already executing.");
17
- while (_) try {
18
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
- if (y = 0, t) op = [op[0] & 2, t.value];
20
- switch (op[0]) {
21
- case 0: case 1: t = op; break;
22
- case 4: _.label++; return { value: op[1], done: false };
23
- case 5: _.label++; y = op[1]; op = [0]; continue;
24
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
- default:
26
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
- if (t[2]) _.ops.pop();
31
- _.trys.pop(); continue;
32
- }
33
- op = body.call(thisArg, _);
34
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
- }
37
- };
38
- var __importDefault = (this && this.__importDefault) || function (mod) {
39
- return (mod && mod.__esModule) ? mod : { "default": mod };
40
- };
41
2
  Object.defineProperty(exports, "__esModule", { value: true });
42
3
  exports.writeFile = void 0;
43
- var stream_1 = __importDefault(require("stream"));
44
4
  /**
45
5
  * Write a file to Google Cloud Storage.
46
6
  */
47
- var writeFile = function (_a) {
48
- var bucket = _a.bucket, credentials = _a.credentials, data = _a.data, key = _a.key;
49
- return __awaiter(void 0, void 0, void 0, function () {
50
- var Storage, storage, data_stream, google_file;
51
- return __generator(this, function (_b) {
52
- switch (_b.label) {
53
- case 0:
54
- Storage = require('@google-cloud/storage').Storage;
55
- storage = new Storage({
56
- credentials: {
57
- client_email: credentials['client_email'],
58
- private_key: credentials['private_key'],
59
- },
60
- projectId: credentials['project_id'],
61
- });
62
- data_stream = new stream_1.default.PassThrough();
63
- google_file = storage.bucket(bucket)
64
- .file(key);
65
- data_stream.push(data);
66
- data_stream.push(null);
67
- return [4 /*yield*/, new Promise(function (resolve, reject) {
68
- data_stream.pipe(google_file.createWriteStream({
69
- contentType: 'auto',
70
- resumable: false,
71
- validation: false,
72
- metadata: {},
73
- }))
74
- .on('error', function (error) {
75
- reject(error);
76
- })
77
- .on('finish', function () {
78
- console.log("File uploaded successfully.");
79
- resolve(true);
80
- });
81
- })];
82
- case 1: return [2 /*return*/, _b.sent()];
83
- }
7
+ const writeFile = async ({ bucket, data, key, projectId }) => {
8
+ const stream = require('stream');
9
+ const dataStream = new stream.PassThrough();
10
+ const googleFile = global.googleStorageClient[projectId].bucket(bucket)
11
+ .file(key);
12
+ dataStream.push(data);
13
+ dataStream.push(null);
14
+ return await new Promise((resolve, reject) => {
15
+ dataStream.pipe(googleFile.createWriteStream({
16
+ contentType: 'auto',
17
+ resumable: false,
18
+ validation: false,
19
+ metadata: {},
20
+ }))
21
+ .on('error', (error) => {
22
+ reject(error);
23
+ })
24
+ .on('finish', () => {
25
+ // console.log(`File uploaded successfully.`);
26
+ resolve(true);
84
27
  });
85
28
  });
86
29
  };
@@ -1,56 +1,15 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- var __generator = (this && this.__generator) || function (thisArg, body) {
12
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
- function verb(n) { return function (v) { return step([n, v]); }; }
15
- function step(op) {
16
- if (f) throw new TypeError("Generator is already executing.");
17
- while (_) try {
18
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
- if (y = 0, t) op = [op[0] & 2, t.value];
20
- switch (op[0]) {
21
- case 0: case 1: t = op; break;
22
- case 4: _.label++; return { value: op[1], done: false };
23
- case 5: _.label++; y = op[1]; op = [0]; continue;
24
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
- default:
26
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
- if (t[2]) _.ops.pop();
31
- _.trys.pop(); continue;
32
- }
33
- op = body.call(thisArg, _);
34
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
- }
37
- };
38
2
  Object.defineProperty(exports, "__esModule", { value: true });
39
3
  /**
40
4
  * Return the Google Ads Client with the specified customer set.
41
5
  */
42
- var getCustomer = function (_a) {
43
- var customerId = _a.customerId;
44
- return __awaiter(void 0, void 0, void 0, function () {
45
- var customer;
46
- return __generator(this, function (_b) {
47
- customer = global.googleAdsClient.instance.Customer({
48
- customer_id: customerId,
49
- login_customer_id: global.googleAdsClient.mccAccountId,
50
- refresh_token: global.googleAdsClient.refreshToken,
51
- });
52
- return [2 /*return*/, customer];
53
- });
6
+ const getCustomer = async ({ customerId }) => {
7
+ // Login as a customer
8
+ const customer = global.googleAdsClient.instance.Customer({
9
+ customer_id: customerId,
10
+ login_customer_id: global.googleAdsClient.mccAccountId,
11
+ refresh_token: global.googleAdsClient.refreshToken,
54
12
  });
13
+ return customer;
55
14
  };
56
15
  exports.default = getCustomer;
@@ -1,15 +1,16 @@
1
+ export declare type GoogleAdsParameter = {
2
+ clientId: string;
3
+ clientSecret: string;
4
+ developerToken: string;
5
+ mccAccountId: string;
6
+ refreshToken: string;
7
+ };
1
8
  declare type InitClient = {
2
- auth: {
3
- clientId: string;
4
- clientSecret: string;
5
- developerToken: string;
6
- mccAccountId: string;
7
- refreshToken: string;
8
- };
9
+ parameter: GoogleAdsParameter;
9
10
  };
10
11
  /**
11
12
  * Shorthand function to get the Google Ads Client.
12
13
  * Library: google-ads-api
13
14
  */
14
- declare const initClient: ({ auth }: InitClient) => Promise<void>;
15
+ declare const initClient: ({ parameter }: InitClient) => Promise<void>;
15
16
  export default initClient;
@@ -1,40 +1,4 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- var __generator = (this && this.__generator) || function (thisArg, body) {
12
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
- function verb(n) { return function (v) { return step([n, v]); }; }
15
- function step(op) {
16
- if (f) throw new TypeError("Generator is already executing.");
17
- while (_) try {
18
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
- if (y = 0, t) op = [op[0] & 2, t.value];
20
- switch (op[0]) {
21
- case 0: case 1: t = op; break;
22
- case 4: _.label++; return { value: op[1], done: false };
23
- case 5: _.label++; y = op[1]; op = [0]; continue;
24
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
- default:
26
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
- if (t[2]) _.ops.pop();
31
- _.trys.pop(); continue;
32
- }
33
- op = body.call(thisArg, _);
34
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
- }
37
- };
38
2
  Object.defineProperty(exports, "__esModule", { value: true });
39
3
  global.googleAdsClient = {
40
4
  instance: null,
@@ -45,25 +9,18 @@ global.googleAdsClient = {
45
9
  * Shorthand function to get the Google Ads Client.
46
10
  * Library: google-ads-api
47
11
  */
48
- var initClient = function (_a) {
49
- var auth = _a.auth;
50
- return __awaiter(void 0, void 0, void 0, function () {
51
- var GoogleAdsApi;
52
- return __generator(this, function (_b) {
53
- if (!global.googleAdsClient.instance) {
54
- GoogleAdsApi = require('google-ads-api').GoogleAdsApi;
55
- // Create a new client instance
56
- global.googleAdsClient.instance =
57
- new GoogleAdsApi({
58
- client_id: auth.clientId,
59
- client_secret: auth.clientSecret,
60
- developer_token: auth.developerToken,
61
- });
62
- global.googleAdsClient.mccAccountId = auth.mccAccountId;
63
- global.googleAdsClient.refreshToken = auth.refreshToken;
64
- }
65
- return [2 /*return*/];
66
- });
67
- });
12
+ const initClient = async ({ parameter }) => {
13
+ if (!global.googleAdsClient.instance) {
14
+ const { GoogleAdsApi } = require('google-ads-api');
15
+ // Create a new client instance
16
+ global.googleAdsClient.instance =
17
+ new GoogleAdsApi({
18
+ client_id: parameter.clientId,
19
+ client_secret: parameter.clientSecret,
20
+ developer_token: parameter.developerToken,
21
+ });
22
+ global.googleAdsClient.mccAccountId = parameter.mccAccountId;
23
+ global.googleAdsClient.refreshToken = parameter.refreshToken;
24
+ }
68
25
  };
69
26
  exports.default = initClient;
package/initClients.d.ts CHANGED
@@ -1,11 +1,11 @@
1
- import { Config as ConfigAws } from './aws/config';
1
+ import { Config as AwsConfig } from './aws/getConfig';
2
2
  declare type InitClients = {
3
3
  athenaExpress?: {
4
4
  database: string;
5
5
  s3Bucket: string;
6
6
  s3Key: string;
7
7
  };
8
- awsConfig?: ConfigAws;
8
+ awsConfig?: AwsConfig;
9
9
  awsGlue?: boolean;
10
10
  awsLambda?: boolean;
11
11
  awsS3?: boolean;
@@ -18,6 +18,16 @@ declare type InitClients = {
18
18
  googleAds?: {
19
19
  parameterName: string;
20
20
  };
21
+ googleBigQuery?: {
22
+ projectIds: string | string[];
23
+ };
24
+ googleConfig?: {
25
+ parameterName: string;
26
+ };
27
+ googleSheets?: boolean;
28
+ googleStorage?: {
29
+ projectIds: string | string[];
30
+ };
21
31
  prisma?: {
22
32
  debug?: boolean;
23
33
  };
@@ -26,5 +36,5 @@ declare type InitClients = {
26
36
  /**
27
37
  * Function to simplify initialising the clients.
28
38
  */
29
- declare const initClients: ({ athenaExpress, awsConfig, awsGlue, awsS3, awsSes, awsSsm, deepCrawl, googleAds, prisma, }: InitClients) => Promise<void>;
39
+ declare const initClients: ({ athenaExpress, awsConfig, awsGlue, awsS3, awsSes, awsSsm, deepCrawl, googleAds, googleConfig, googleBigQuery, googleSheets, googleStorage, prisma, }: InitClients) => Promise<void>;
30
40
  export default initClients;
package/initClients.js CHANGED
@@ -1,113 +1,107 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- var __generator = (this && this.__generator) || function (thisArg, body) {
12
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
- function verb(n) { return function (v) { return step([n, v]); }; }
15
- function step(op) {
16
- if (f) throw new TypeError("Generator is already executing.");
17
- while (_) try {
18
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
- if (y = 0, t) op = [op[0] & 2, t.value];
20
- switch (op[0]) {
21
- case 0: case 1: t = op; break;
22
- case 4: _.label++; return { value: op[1], done: false };
23
- case 5: _.label++; y = op[1]; op = [0]; continue;
24
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
- default:
26
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
- if (t[2]) _.ops.pop();
31
- _.trys.pop(); continue;
32
- }
33
- op = body.call(thisArg, _);
34
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
- }
37
- };
38
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
39
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
40
4
  };
41
5
  Object.defineProperty(exports, "__esModule", { value: true });
42
- var initClient_1 = __importDefault(require("./aws/athenaExpress/initClient"));
43
- var initClient_2 = __importDefault(require("./aws/glue/initClient"));
44
- var initClient_3 = __importDefault(require("./aws/s3/initClient"));
45
- var initClient_4 = __importDefault(require("./aws/ses/initClient"));
46
- var getParameter_1 = __importDefault(require("./aws/ssm/getParameter"));
47
- var initClient_5 = __importDefault(require("./aws/ssm/initClient"));
48
- var initClient_6 = __importDefault(require("./deepCrawl/initClient"));
49
- var initClient_7 = __importDefault(require("./googleAds/initClient"));
50
- var initClient_8 = __importDefault(require("./prisma/initClient"));
6
+ const getArray_1 = __importDefault(require("./array/getArray"));
7
+ const initClient_1 = __importDefault(require("./aws/athenaExpress/initClient"));
8
+ const initClient_2 = __importDefault(require("./aws/glue/initClient"));
9
+ const initClient_3 = __importDefault(require("./aws/s3/initClient"));
10
+ const initClient_4 = __importDefault(require("./aws/ses/initClient"));
11
+ const getParameter_1 = __importDefault(require("./aws/ssm/getParameter"));
12
+ const initClient_5 = __importDefault(require("./aws/ssm/initClient"));
13
+ const initClient_6 = __importDefault(require("./deepCrawl/initClient"));
14
+ const initClient_7 = __importDefault(require("./google/bigQuery/initClient"));
15
+ const initClient_8 = __importDefault(require("./google/sheets/initClient"));
16
+ const initClient_9 = __importDefault(require("./google/storage/initClient"));
17
+ const initClient_10 = __importDefault(require("./googleAds/initClient"));
18
+ const initClient_11 = __importDefault(require("./prisma/initClient"));
51
19
  /**
52
20
  * Function to simplify initialising the clients.
53
21
  */
54
- var initClients = function (_a) {
55
- var athenaExpress = _a.athenaExpress, awsConfig = _a.awsConfig, awsGlue = _a.awsGlue, awsS3 = _a.awsS3, awsSes = _a.awsSes, awsSsm = _a.awsSsm, deepCrawl = _a.deepCrawl, googleAds = _a.googleAds, prisma = _a.prisma;
56
- return __awaiter(void 0, void 0, void 0, function () {
57
- var deepcrawlParameter, googleAdsParameter;
58
- return __generator(this, function (_b) {
59
- switch (_b.label) {
60
- case 0:
61
- if (undefined !== athenaExpress) {
62
- (0, initClient_1.default)({
63
- config: awsConfig,
64
- database: athenaExpress.database,
65
- s3Bucket: athenaExpress.s3Bucket,
66
- s3Key: athenaExpress.s3Key,
67
- });
68
- }
69
- if (true === awsGlue) {
70
- (0, initClient_2.default)({ config: awsConfig });
71
- }
72
- if (true === awsS3) {
73
- (0, initClient_3.default)({ config: awsConfig });
74
- }
75
- if (true === awsSes) {
76
- (0, initClient_4.default)({ config: awsConfig });
77
- }
78
- if (true === awsSsm) {
79
- (0, initClient_5.default)({ config: awsConfig });
80
- }
81
- if (!(undefined !== deepCrawl)) return [3 /*break*/, 3];
82
- return [4 /*yield*/, (0, getParameter_1.default)({
83
- name: deepCrawl.parameterName,
84
- })];
85
- case 1:
86
- deepcrawlParameter = _b.sent();
87
- return [4 /*yield*/, (0, initClient_6.default)({ auth: deepcrawlParameter })];
88
- case 2:
89
- _b.sent();
90
- _b.label = 3;
91
- case 3:
92
- if (!(undefined !== googleAds)) return [3 /*break*/, 6];
93
- return [4 /*yield*/, (0, getParameter_1.default)({
94
- name: googleAds.parameterName,
95
- })];
96
- case 4:
97
- googleAdsParameter = _b.sent();
98
- return [4 /*yield*/, (0, initClient_7.default)({ auth: googleAdsParameter })];
99
- case 5:
100
- _b.sent();
101
- _b.label = 6;
102
- case 6:
103
- if (undefined !== prisma) {
104
- (0, initClient_8.default)({
105
- debug: true === prisma ? false : prisma.debug || false,
106
- });
107
- }
108
- return [2 /*return*/];
22
+ const initClients = async ({ athenaExpress, awsConfig, awsGlue, awsS3, awsSes, awsSsm, deepCrawl, googleAds, googleConfig, googleBigQuery, googleSheets, googleStorage, prisma, }) => {
23
+ if (athenaExpress) {
24
+ (0, initClient_1.default)({
25
+ config: awsConfig,
26
+ database: athenaExpress.database,
27
+ s3Bucket: athenaExpress.s3Bucket,
28
+ s3Key: athenaExpress.s3Key,
29
+ });
30
+ }
31
+ if (awsGlue) {
32
+ (0, initClient_2.default)({
33
+ config: awsConfig,
34
+ });
35
+ }
36
+ if (awsS3) {
37
+ (0, initClient_3.default)({
38
+ config: awsConfig,
39
+ });
40
+ }
41
+ if (awsSes) {
42
+ (0, initClient_4.default)({
43
+ config: awsConfig,
44
+ });
45
+ }
46
+ if (awsSsm || deepCrawl || googleAds || googleConfig) {
47
+ (0, initClient_5.default)({
48
+ config: awsConfig,
49
+ });
50
+ }
51
+ // Deepcrawl authentication using SSM Parameter
52
+ if (deepCrawl) {
53
+ const deepcrawlParameter = await (0, getParameter_1.default)({
54
+ name: deepCrawl.parameterName,
55
+ });
56
+ await (0, initClient_6.default)({ auth: deepcrawlParameter });
57
+ }
58
+ // Google authentication using SSM
59
+ if (googleConfig) {
60
+ // Google Parameter
61
+ const googleParameter = await (0, getParameter_1.default)({
62
+ name: googleConfig.parameterName,
63
+ });
64
+ // BigQuery
65
+ if (googleBigQuery && googleBigQuery.projectIds) {
66
+ const googleBigQueryProjectIds = (0, getArray_1.default)({ input: googleBigQuery.projectIds });
67
+ for (let i = 0; i < googleBigQueryProjectIds.length; i++) {
68
+ (0, initClient_7.default)({
69
+ parameter: googleParameter,
70
+ projectId: googleBigQueryProjectIds[i],
71
+ });
72
+ }
73
+ }
74
+ // Google Sheets
75
+ if (googleSheets) {
76
+ (0, initClient_8.default)({
77
+ parameter: googleParameter,
78
+ });
79
+ }
80
+ // Google Storage
81
+ if (googleStorage && googleStorage.projectIds) {
82
+ const googleStorageProjectIds = (0, getArray_1.default)({ input: googleStorage.projectIds });
83
+ for (let i = 0; i < googleStorageProjectIds.length; i++) {
84
+ (0, initClient_9.default)({
85
+ parameter: googleParameter,
86
+ projectId: googleStorageProjectIds[i],
87
+ });
109
88
  }
89
+ }
90
+ }
91
+ // Google Ads authentication using SSM Parameter
92
+ if (googleAds) {
93
+ const googleAdsParameter = await (0, getParameter_1.default)({
94
+ name: googleAds.parameterName,
95
+ });
96
+ await (0, initClient_10.default)({
97
+ parameter: googleAdsParameter,
110
98
  });
111
- });
99
+ }
100
+ // Initialise Prisma
101
+ if (prisma) {
102
+ (0, initClient_11.default)({
103
+ debug: prisma ? false : prisma.debug || false,
104
+ });
105
+ }
112
106
  };
113
107
  exports.default = initClients;
package/json/isJson.js CHANGED
@@ -4,8 +4,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
4
4
  * Is the provided input JSON?
5
5
  * https://stackoverflow.com/a/33369954
6
6
  */
7
- var isJson = function (_a) {
8
- var input = _a.input;
7
+ const isJson = ({ input }) => {
9
8
  input = 'string' === typeof input ? input : JSON.stringify(input);
10
9
  try {
11
10
  input = JSON.parse(input);