@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
@@ -1,69 +1,23 @@
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 getParameter_1 = __importDefault(require("../aws/ssm/getParameter"));
6
+ const getParameter_1 = __importDefault(require("../aws/ssm/getParameter"));
43
7
  global.eskimiAccessToken = null;
44
8
  /**
45
9
  * Retrieve the access token from SSM Parameter Store.
46
10
  */
47
- var getAccessToken = function (_a) {
48
- var force = _a.force, parameterName = _a.parameterName;
49
- return __awaiter(void 0, void 0, void 0, function () {
50
- var parameter;
51
- return __generator(this, function (_b) {
52
- switch (_b.label) {
53
- case 0:
54
- if (!(!global.eskimiAccessToken || force)) return [3 /*break*/, 2];
55
- return [4 /*yield*/, (0, getParameter_1.default)({
56
- name: parameterName,
57
- withDecryption: true,
58
- isJson: true,
59
- })];
60
- case 1:
61
- parameter = _b.sent();
62
- global.eskimiAccessToken = parameter.accessToken;
63
- _b.label = 2;
64
- case 2: return [2 /*return*/, global.eskimiAccessToken];
65
- }
11
+ const getAccessToken = async ({ force, parameterName }) => {
12
+ if (!global.eskimiAccessToken || force) {
13
+ // Get the credentials from SSM
14
+ const parameter = await (0, getParameter_1.default)({
15
+ name: parameterName,
16
+ withDecryption: true,
17
+ isJson: true,
66
18
  });
67
- });
19
+ global.eskimiAccessToken = parameter.accessToken;
20
+ }
21
+ return global.eskimiAccessToken;
68
22
  };
69
23
  exports.default = getAccessToken;
@@ -3,13 +3,12 @@ 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
- var ageGroups_1 = __importDefault(require("./ageGroups"));
6
+ const ageGroups_1 = __importDefault(require("./ageGroups"));
7
7
  /**
8
8
  * Map the Age Group and return the user-friendly string.
9
9
  */
10
- var getAgeGroup = function (_a) {
11
- var input = _a.input;
12
- var matches = ageGroups_1.default.filter(function (group) { return group.id === input; });
10
+ const getAgeGroup = ({ input }) => {
11
+ const matches = ageGroups_1.default.filter(group => group.id === input);
13
12
  if (1 === matches.length) {
14
13
  return matches[0].name;
15
14
  }
@@ -3,11 +3,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  /**
4
4
  * Convert the Regex of Campaign Ids into an array of integers.
5
5
  */
6
- var getCampaignIds = function (_a) {
7
- var accounts = _a.accounts;
6
+ const getCampaignIds = ({ accounts }) => {
8
7
  return accounts[0].campaignIdRegex.replace('(', '')
9
8
  .replace(')', '')
10
9
  .split('|')
11
- .map(function (id) { return parseInt(id); });
10
+ .map(id => parseInt(id));
12
11
  };
13
12
  exports.default = getCampaignIds;
@@ -3,13 +3,12 @@ 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
- var devices_1 = __importDefault(require("./devices"));
6
+ const devices_1 = __importDefault(require("./devices"));
7
7
  /**
8
8
  * Map the Devices and return the user-friendly string.
9
9
  */
10
- var getDevice = function (_a) {
11
- var input = _a.input;
12
- var matches = devices_1.default.filter(function (device) { return device.id === input; });
10
+ const getDevice = ({ input }) => {
11
+ const matches = devices_1.default.filter(device => device.id === input);
13
12
  if (1 === matches.length) {
14
13
  return matches[0].name;
15
14
  }
@@ -3,13 +3,12 @@ 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
- var genders_1 = __importDefault(require("./genders"));
6
+ const genders_1 = __importDefault(require("./genders"));
7
7
  /**
8
8
  * Map the Gender and return the user-friendly string.
9
9
  */
10
- var getGender = function (_a) {
11
- var input = _a.input;
12
- var matches = genders_1.default.filter(function (gender) { return gender.id === input; });
10
+ const getGender = ({ input }) => {
11
+ const matches = genders_1.default.filter(gender => gender.id === input);
13
12
  if (1 === matches.length) {
14
13
  return matches[0].name;
15
14
  }
package/eskimi/request.js CHANGED
@@ -1,70 +1,24 @@
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 post_1 = __importDefault(require("../axios/post"));
6
+ const post_1 = __importDefault(require("../axios/post"));
43
7
  /**
44
8
  * Make the request to Eskimi API using the access token.
45
9
  */
46
- var request = function (_a) {
47
- var data = _a.data, url = _a.url;
48
- return __awaiter(void 0, void 0, void 0, function () {
49
- var response;
50
- return __generator(this, function (_b) {
51
- switch (_b.label) {
52
- case 0: return [4 /*yield*/, (0, post_1.default)({
53
- config: {
54
- headers: {
55
- Authorization: "Bearer ".concat(global.eskimiAccessToken),
56
- "Content-Type": "application/json",
57
- },
58
- },
59
- data: data,
60
- onSuccess: function (response) { return response.data; },
61
- url: url,
62
- })];
63
- case 1:
64
- response = _b.sent();
65
- return [2 /*return*/, response];
66
- }
67
- });
10
+ const request = async ({ data, url }) => {
11
+ const response = await (0, post_1.default)({
12
+ config: {
13
+ headers: {
14
+ Authorization: `Bearer ${global.eskimiAccessToken}`,
15
+ "Content-Type": "application/json",
16
+ },
17
+ },
18
+ data: data,
19
+ onSuccess: response => response.data,
20
+ url: url,
68
21
  });
22
+ return response;
69
23
  };
70
24
  exports.default = request;
@@ -0,0 +1,11 @@
1
+ import { Config } from '../getConfig';
2
+ declare type InitClient = {
3
+ parameter: Config;
4
+ projectId: string;
5
+ };
6
+ /**
7
+ * Initialise the Big Query client.
8
+ * It's possible to use multiple clients, so we set one up per project id.
9
+ */
10
+ declare const initClient: ({ parameter, projectId }: InitClient) => void;
11
+ export default initClient;
@@ -0,0 +1,22 @@
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.googleBigQueryClient = {};
8
+ /**
9
+ * Initialise the Big Query client.
10
+ * It's possible to use multiple clients, so we set one up per project id.
11
+ */
12
+ const initClient = ({ parameter, projectId }) => {
13
+ if (!global.googleBigQueryClient[projectId]) {
14
+ const { BigQuery } = require('@google-cloud/bigquery');
15
+ const formattedConfig = (0, getConfig_1.default)({ parameter });
16
+ global.googleBigQueryClient[projectId] = new BigQuery({
17
+ credentials: formattedConfig,
18
+ projectId: projectId,
19
+ });
20
+ }
21
+ };
22
+ exports.default = initClient;
@@ -0,0 +1,9 @@
1
+ declare type Query = {
2
+ projectId: string;
3
+ query: string;
4
+ };
5
+ /**
6
+ * Build the query and return the data.
7
+ */
8
+ declare const query: ({ projectId, query }: Query) => Promise<any>;
9
+ export default query;
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ /**
4
+ * Build the query and return the data.
5
+ */
6
+ const query = async ({ projectId, query }) => {
7
+ const apiResponse = await global.googleBigQueryClient[projectId].query(query);
8
+ return apiResponse;
9
+ };
10
+ exports.default = query;
@@ -0,0 +1,20 @@
1
+ export declare type Config = {
2
+ type: string;
3
+ project_id: string;
4
+ private_key_id: string;
5
+ private_key: string;
6
+ client_email: string;
7
+ client_id: string;
8
+ auth_uri: string;
9
+ token_uri: string;
10
+ auth_provider_x509_cert_url: string;
11
+ client_x509_cert_url: string;
12
+ };
13
+ export declare type GetConfig = {
14
+ parameter: Config;
15
+ };
16
+ /**
17
+ * Using the response from Parameter Store and format it ready to be used with Google API.
18
+ */
19
+ declare const getConfig: (parameter: GetConfig) => Config;
20
+ export default getConfig;
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ /**
4
+ * Using the response from Parameter Store and format it ready to be used with Google API.
5
+ */
6
+ const getConfig = (parameter) => {
7
+ // Format the private key to be in the same format as required by Google
8
+ const privateKey = parameter['private_key'].replace(/\\n/g, '\n');
9
+ const response = {
10
+ type: parameter['type'],
11
+ project_id: parameter['project_id'],
12
+ private_key_id: parameter['private_key_id'],
13
+ private_key: privateKey,
14
+ client_email: parameter['client_email'],
15
+ client_id: parameter['client_id'],
16
+ auth_uri: parameter['auth_uri'],
17
+ token_uri: parameter['token_uri'],
18
+ auth_provider_x509_cert_url: parameter['auth_provider_x509_cert_url'],
19
+ client_x509_cert_url: parameter['client_x509_cert_url'],
20
+ };
21
+ return response;
22
+ };
23
+ exports.default = getConfig;
@@ -1,4 +1,4 @@
1
- export declare type AssociatedDataRequest = {
1
+ declare type GetAssociatedData = {
2
2
  spreadsheetId: string;
3
3
  ranges: [
4
4
  format: string,
@@ -12,9 +12,5 @@ export declare type AssociatedDataRequest = {
12
12
  /**
13
13
  * Make a batch get to Google Sheets to retrieve the data correctly formatted, with default values provided.
14
14
  */
15
- declare const getAssociatedData: ({ SheetsLib, client, request }: {
16
- SheetsLib: any;
17
- client: any;
18
- request: AssociatedDataRequest;
19
- }) => Promise<object[]>;
15
+ declare const getAssociatedData: ({ dateTimeRender, ranges, spreadsheetId, valueRender }: GetAssociatedData) => Promise<object[]>;
20
16
  export default getAssociatedData;
@@ -1,100 +1,53 @@
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 isUndefined_1 = __importDefault(require("lodash/isUndefined"));
43
- var getBatchData_1 = __importDefault(require("./getBatchData"));
6
+ const getBatchData_1 = __importDefault(require("./getBatchData"));
44
7
  /**
45
8
  * Make a batch get to Google Sheets to retrieve the data correctly formatted, with default values provided.
46
9
  */
47
- var getAssociatedData = function (_a) {
48
- var SheetsLib = _a.SheetsLib, client = _a.client, request = _a.request;
49
- return __awaiter(void 0, void 0, void 0, function () {
50
- var apiResponse, template, response, initialRangeLength, i, rowIndex, row, columnIndex, refValue, value;
51
- return __generator(this, function (_b) {
52
- switch (_b.label) {
53
- case 0: return [4 /*yield*/, (0, getBatchData_1.default)({
54
- SheetsLib: SheetsLib,
55
- client: client,
56
- spreadsheetId: request.spreadsheetId,
57
- ranges: request.ranges,
58
- dateTimeRender: request.dateTimeRender,
59
- valueRender: request.valueRender,
60
- })];
61
- case 1:
62
- apiResponse = _b.sent();
63
- template = [];
64
- response = [];
65
- // Missing ranges or too many ranges
66
- if (4 !== apiResponse.valueRanges.length) {
67
- throw new Error("Associated data response length must be 4.");
68
- }
69
- initialRangeLength = apiResponse.valueRanges[0].values[0].length;
70
- // Loop through the headings
71
- for (i = 0; i < initialRangeLength; i++) {
72
- template.push({
73
- format: apiResponse.valueRanges[0].values[0][i],
74
- default: apiResponse.valueRanges[1].values[0][i],
75
- heading: apiResponse.valueRanges[2].values[0][i],
76
- index: i,
77
- });
78
- }
79
- // console.log('template', template);
80
- // Loop through each row of data
81
- if (!(0, isUndefined_1.default)(apiResponse.valueRanges[3].values)) {
82
- for (rowIndex = 0; rowIndex < apiResponse.valueRanges[3].values.length; rowIndex++) {
83
- row = {};
84
- // Loop through each column within the row
85
- for (columnIndex = 0; columnIndex < apiResponse.valueRanges[3].values[rowIndex].length; columnIndex++) {
86
- refValue = apiResponse.valueRanges[3].values[rowIndex][columnIndex];
87
- value = ('' === refValue ? template[columnIndex]['default'] : refValue);
88
- // Add this to our row
89
- row[template[columnIndex]['heading']] = value;
90
- }
91
- // Add the row to our response
92
- response.push(row);
93
- }
94
- }
95
- return [2 /*return*/, response];
96
- }
97
- });
10
+ const getAssociatedData = async ({ dateTimeRender, ranges, spreadsheetId, valueRender }) => {
11
+ // Make the API request
12
+ const apiResponse = await (0, getBatchData_1.default)({
13
+ spreadsheetId,
14
+ ranges,
15
+ dateTimeRender,
16
+ valueRender,
98
17
  });
18
+ let template = [];
19
+ let response = [];
20
+ // Missing ranges or too many ranges
21
+ if (4 !== apiResponse.valueRanges.length) {
22
+ throw new Error("Associated data response length must be 4.");
23
+ }
24
+ // Get the first data range
25
+ const initialRangeLength = apiResponse.valueRanges[0].values[0].length;
26
+ // Loop through the headings
27
+ for (let i = 0; i < initialRangeLength; i++) {
28
+ template.push({
29
+ format: apiResponse.valueRanges[0].values[0][i],
30
+ default: apiResponse.valueRanges[1].values[0][i],
31
+ heading: apiResponse.valueRanges[2].values[0][i],
32
+ index: i,
33
+ });
34
+ }
35
+ // console.log('template', template);
36
+ // Loop through each row of data
37
+ if (undefined !== apiResponse.valueRanges[3].values) {
38
+ for (let rowIndex = 0; rowIndex < apiResponse.valueRanges[3].values.length; rowIndex++) {
39
+ let row = {};
40
+ // Loop through each column within the row
41
+ for (let columnIndex = 0; columnIndex < apiResponse.valueRanges[3].values[rowIndex].length; columnIndex++) {
42
+ const refValue = apiResponse.valueRanges[3].values[rowIndex][columnIndex];
43
+ const value = ('' === refValue ? template[columnIndex]['default'] : refValue);
44
+ // Add this to our row
45
+ row[template[columnIndex]['heading']] = value;
46
+ }
47
+ // Add the row to our response
48
+ response.push(row);
49
+ }
50
+ }
51
+ return response;
99
52
  };
100
53
  exports.default = getAssociatedData;
@@ -9,12 +9,10 @@ declare type BatchData = {
9
9
  }[];
10
10
  };
11
11
  declare type GetBatchData = {
12
- SheetsLib: any;
13
- client: any;
14
12
  spreadsheetId: string;
15
13
  ranges: string[];
16
14
  dateTimeRender?: string;
17
15
  valueRender?: string;
18
16
  };
19
- declare const getBatchData: ({ SheetsLib, client, spreadsheetId, ranges, dateTimeRender, valueRender, }: GetBatchData) => Promise<BatchData>;
17
+ declare const getBatchData: ({ spreadsheetId, ranges, dateTimeRender, valueRender, }: GetBatchData) => Promise<BatchData>;
20
18
  export default getBatchData;
@@ -1,64 +1,19 @@
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
- var getBatchData = function (_a) {
40
- var SheetsLib = _a.SheetsLib, client = _a.client, spreadsheetId = _a.spreadsheetId, ranges = _a.ranges, _b = _a.dateTimeRender, dateTimeRender = _b === void 0 ? 'FORMATTED_STRING' : _b, _c = _a.valueRender, valueRender = _c === void 0 ? 'UNFORMATTED_VALUE' : _c;
41
- return __awaiter(void 0, void 0, void 0, function () {
42
- var request, data;
43
- return __generator(this, function (_d) {
44
- switch (_d.label) {
45
- case 0:
46
- request = {
47
- auth: client,
48
- dateTimeRenderOption: dateTimeRender,
49
- ranges: ranges,
50
- spreadsheetId: spreadsheetId,
51
- valueRenderOption: valueRender,
52
- };
53
- return [4 /*yield*/, SheetsLib.sheets('v4')
54
- .spreadsheets
55
- .values
56
- .batchGet(request)];
57
- case 1:
58
- data = (_d.sent()).data;
59
- return [2 /*return*/, data];
60
- }
61
- });
62
- });
3
+ const getBatchData = async ({ spreadsheetId, ranges, dateTimeRender = 'FORMATTED_STRING', valueRender = 'UNFORMATTED_VALUE', }) => {
4
+ const googleApisSheets = require('@googleapis/sheets');
5
+ const request = {
6
+ auth: global.googleSheetsClient,
7
+ dateTimeRenderOption: dateTimeRender,
8
+ ranges: ranges,
9
+ spreadsheetId: spreadsheetId,
10
+ valueRenderOption: valueRender,
11
+ };
12
+ // Make the API request
13
+ const apiResponse = (await googleApisSheets.sheets('v4')
14
+ .spreadsheets
15
+ .values
16
+ .batchGet(request));
17
+ return apiResponse.data;
63
18
  };
64
19
  exports.default = getBatchData;
@@ -0,0 +1,11 @@
1
+ import { Config } from '../getConfig';
2
+ declare type InitClient = {
3
+ parameter: Config;
4
+ };
5
+ /**
6
+ * Initialise the Google Sheets instance using the separate service method.
7
+ * https://github.com/googleapis/google-api-nodejs-client
8
+ * Library: @googleapis/sheets
9
+ */
10
+ declare const initClient: ({ parameter }: InitClient) => void;
11
+ export default initClient;
@@ -0,0 +1,25 @@
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.googleSheetsClient = null;
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 }) => {
14
+ if (!global.googleSheetsClient) {
15
+ const googleApisSheets = require('@googleapis/sheets');
16
+ const formattedConfig = (0, getConfig_1.default)({ parameter });
17
+ global.googleSheetsClient = new googleApisSheets.auth.GoogleAuth({
18
+ credentials: formattedConfig,
19
+ scopes: [
20
+ 'https://www.googleapis.com/auth/spreadsheets',
21
+ ],
22
+ });
23
+ }
24
+ };
25
+ exports.default = initClient;
@@ -3,8 +3,5 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  /**
4
4
  * Noticed sometimes Google Sheets can struggle with import XML resulting to N/A values.
5
5
  */
6
- var isCellNa = function (_a) {
7
- var input = _a.input;
8
- return '#N/A' === input;
9
- };
6
+ const isCellNa = ({ input }) => '#N/A' === input;
10
7
  exports.default = isCellNa;