@8ms/helpers 1.1.67 → 1.1.70

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 (202) 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.js +22 -78
  178. package/upTimeRobot/logTypes.js +1 -1
  179. package/upTimeRobot/monitorStatuses.js +1 -1
  180. package/upTimeRobot/monitorSubTypes.js +1 -1
  181. package/upTimeRobot/monitorTypes.js +1 -1
  182. package/upTimeRobot/requestStatuses.js +1 -1
  183. package/url/buildParameters.js +7 -8
  184. package/url/buildRelative.js +3 -4
  185. package/url/buildUrl.js +6 -7
  186. package/url/isAbsolute.js +1 -2
  187. package/url/isRelative.js +2 -5
  188. package/util/defaultTo.d.ts +6 -5
  189. package/util/defaultTo.js +6 -7
  190. package/util/isUndefined.d.ts +9 -0
  191. package/util/isUndefined.js +19 -0
  192. package/util/sleep.js +2 -3
  193. package/webWorker/states.js +1 -1
  194. package/xml/getXml.js +10 -58
  195. package/aws/athenaExpress/request.d.ts +0 -8
  196. package/aws/athenaExpress/request.js +0 -54
  197. package/aws/config.d.ts +0 -5
  198. package/aws/config.js +0 -2
  199. package/google/getCredentials.d.ts +0 -20
  200. package/google/getCredentials.js +0 -76
  201. package/google/sheets/getAuth.d.ts +0 -8
  202. package/google/sheets/getAuth.js +0 -69
package/api/response.js CHANGED
@@ -3,8 +3,8 @@ 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 states_1 = __importDefault(require("./states"));
7
- var response = {
6
+ const states_1 = __importDefault(require("./states"));
7
+ const response = {
8
8
  body: null,
9
9
  error: null,
10
10
  state: states_1.default.IDLE,
package/api/states.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- var states = {
3
+ const states = {
4
4
  ERROR: 'error',
5
5
  IDLE: 'idle',
6
6
  PENDING: 'pending',
@@ -1,4 +1,4 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- var unexpectedError = 'An unexpected error occurred, please try again.';
3
+ const unexpectedError = 'An unexpected error occurred, please try again.';
4
4
  exports.default = unexpectedError;
package/array/contains.js CHANGED
@@ -3,8 +3,5 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  /**
4
4
  * Shorthand to check if an array or string contains a needle.
5
5
  */
6
- var contains = function (_a) {
7
- var haystack = _a.haystack, needle = _a.needle;
8
- return haystack.indexOf(needle) > -1;
9
- };
6
+ const contains = ({ haystack, needle }) => haystack.indexOf(needle) > -1;
10
7
  exports.default = contains;
package/array/getArray.js CHANGED
@@ -3,12 +3,9 @@ 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 isArray_1 = __importDefault(require("lodash/isArray"));
6
+ const isArray_1 = __importDefault(require("lodash/isArray"));
7
7
  /**
8
8
  * Convert an array into an array or return if already an array.
9
9
  */
10
- var getArray = function (_a) {
11
- var input = _a.input;
12
- return (0, isArray_1.default)(input) ? input : [input];
13
- };
10
+ const getArray = ({ input }) => (0, isArray_1.default)(input) ? input : [input];
14
11
  exports.default = getArray;
@@ -1,4 +1,4 @@
1
- import { Config } from '../config';
1
+ import { Config } from '../getConfig';
2
2
  declare type InitClient = {
3
3
  config: Config;
4
4
  database: string;
@@ -3,22 +3,21 @@ 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 getConfig_1 = __importDefault(require("../getConfig"));
6
+ const getConfig_1 = __importDefault(require("../getConfig"));
7
7
  global.awsAthenaExpressClient = null;
8
8
  /**
9
9
  * Initialise the database using manually provided credentials.
10
10
  */
11
- var initClient = function (_a) {
12
- var config = _a.config, database = _a.database, s3Bucket = _a.s3Bucket, s3Key = _a.s3Key;
11
+ const initClient = ({ config, database, s3Bucket, s3Key }) => {
13
12
  if (!global.awsAthenaExpressClient) {
14
- var athenaExpress = require('athena-express');
15
- var awsSdk = require('aws-sdk');
16
- var formattedConfig = (0, getConfig_1.default)({ config: config, isAthenaExpress: true });
13
+ const athenaExpress = require('athena-express');
14
+ const awsSdk = require('aws-sdk');
15
+ const formattedConfig = (0, getConfig_1.default)({ config, isAthenaExpress: true });
17
16
  // Set the aws authentication
18
17
  awsSdk.config.update(formattedConfig);
19
18
  global.awsAthenaExpressClient = new athenaExpress.AthenaExpress({
20
19
  aws: awsSdk,
21
- s3: "s3://".concat(s3Bucket, "/").concat(s3Key),
20
+ s3: `s3://${s3Bucket}/${s3Key}`,
22
21
  db: database,
23
22
  formatJson: true,
24
23
  retry: 200,
@@ -0,0 +1,8 @@
1
+ declare type Query = {
2
+ query: string;
3
+ };
4
+ /**
5
+ * Build the query and return the data.
6
+ */
7
+ declare const query: ({ query }: Query) => Promise<any>;
8
+ 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 ({ query }) => {
7
+ return await global.awsAthenaExpressClient.query(query)
8
+ .then(data => undefined === data['Items'] ? [] : data['Items']);
9
+ };
10
+ exports.default = query;
@@ -1,4 +1,8 @@
1
- import { Config } from './config';
1
+ export declare type Config = {
2
+ accessKeyId: string;
3
+ region: string;
4
+ secretAccessKey: string;
5
+ };
2
6
  /**
3
7
  * The config must be in a specific structure, if the properties aren't defined don't specify them as they could be inferred (e.g. Lambda).
4
8
  */
package/aws/getConfig.js CHANGED
@@ -3,9 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  /**
4
4
  * The config must be in a specific structure, if the properties aren't defined don't specify them as they could be inferred (e.g. Lambda).
5
5
  */
6
- var getConfig = function (_a) {
7
- var config = _a.config, isAthenaExpress = _a.isAthenaExpress;
8
- var response = {
6
+ const getConfig = ({ config, isAthenaExpress }) => {
7
+ let response = {
9
8
  region: config.region,
10
9
  };
11
10
  // Set the key id and access key if its defined (not required for AWS SAM)
@@ -1,9 +1,10 @@
1
- import { Config } from '../config';
1
+ import { Config } from '../getConfig';
2
+ declare type InitClient = {
3
+ config: Config;
4
+ };
2
5
  /**
3
6
  * Shorthand function to get the Glue Client.
4
7
  * Library: @aws-sdk/client-glue
5
8
  */
6
- declare const initClient: ({ config }: {
7
- config?: Config;
8
- }) => void;
9
+ declare const initClient: ({ config }: InitClient) => void;
9
10
  export default initClient;
@@ -3,17 +3,16 @@ 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 getConfig_1 = __importDefault(require("../getConfig"));
6
+ const getConfig_1 = __importDefault(require("../getConfig"));
7
7
  global.awsGlueClient = null;
8
8
  /**
9
9
  * Shorthand function to get the Glue Client.
10
10
  * Library: @aws-sdk/client-glue
11
11
  */
12
- var initClient = function (_a) {
13
- var config = _a.config;
12
+ const initClient = ({ config }) => {
14
13
  if (!global.awsGlueClient) {
15
- var GlueClient = require('@aws-sdk/client-glue').GlueClient;
16
- var formattedConfig = (0, getConfig_1.default)({ config: config });
14
+ const { GlueClient } = require('@aws-sdk/client-glue');
15
+ const formattedConfig = (0, getConfig_1.default)({ config });
17
16
  global.awsGlueClient = new GlueClient(formattedConfig);
18
17
  }
19
18
  };
@@ -1,11 +1,9 @@
1
- import { Config } from '../config';
2
1
  declare type Invoke = {
3
- config?: Config;
4
2
  crawler: string;
5
3
  };
6
4
  /**
7
5
  * Invoke an AWS Glue Crawler by passing in the name of the Crawler.
8
6
  * Library: @aws-sdk/client-glue
9
7
  */
10
- declare const invoke: ({ config, crawler }: Invoke) => Promise<boolean>;
8
+ declare const invoke: ({ crawler }: Invoke) => Promise<boolean>;
11
9
  export default invoke;
@@ -1,75 +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 isResponse200_1 = __importDefault(require("../isResponse200"));
43
- var initClient_1 = __importDefault(require("./initClient"));
6
+ const isResponse200_1 = __importDefault(require("../isResponse200"));
44
7
  /**
45
8
  * Invoke an AWS Glue Crawler by passing in the name of the Crawler.
46
9
  * Library: @aws-sdk/client-glue
47
10
  */
48
- var invoke = function (_a) {
49
- var config = _a.config, crawler = _a.crawler;
50
- return __awaiter(void 0, void 0, void 0, function () {
51
- var params, StartCrawlerCommand, command, apiResponse;
52
- return __generator(this, function (_b) {
53
- switch (_b.label) {
54
- case 0:
55
- // Ensure the client has been initialised
56
- (0, initClient_1.default)({ config: config });
57
- params = {
58
- Name: crawler,
59
- };
60
- StartCrawlerCommand = require('@aws-sdk/client-glue').StartCrawlerCommand;
61
- ;
62
- command = new StartCrawlerCommand(params);
63
- return [4 /*yield*/, global.awsGlueClient.send(command)];
64
- case 1:
65
- apiResponse = _b.sent();
66
- // Success
67
- if ((0, isResponse200_1.default)({ apiResponse: apiResponse })) {
68
- return [2 /*return*/, true];
69
- }
70
- return [2 /*return*/, false];
71
- }
72
- });
11
+ const invoke = async ({ crawler }) => {
12
+ const { StartCrawlerCommand } = require('@aws-sdk/client-glue');
13
+ const command = new StartCrawlerCommand({
14
+ Name: crawler,
73
15
  });
16
+ // Fire the event but don't wait for it to complete
17
+ const apiResponse = await global.awsGlueClient.send(command);
18
+ // Success
19
+ if ((0, isResponse200_1.default)({ apiResponse })) {
20
+ return true;
21
+ }
22
+ return false;
74
23
  };
75
24
  exports.default = invoke;
@@ -3,14 +3,13 @@ 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 defaultTo_1 = __importDefault(require("../util/defaultTo"));
6
+ const defaultTo_1 = __importDefault(require("../util/defaultTo"));
7
7
  /**
8
8
  * Was the API response a 200?
9
9
  */
10
- var isResponse200 = function (_a) {
11
- var apiResponse = _a.apiResponse;
12
- var response = false;
13
- var responseCode = (0, defaultTo_1.default)({
10
+ const isResponse200 = ({ apiResponse }) => {
11
+ let response = false;
12
+ const responseCode = (0, defaultTo_1.default)({
14
13
  defaultValue: 0,
15
14
  instance: apiResponse,
16
15
  keys: ['$metadata', 'httpStatusCode'],
@@ -1,4 +1,5 @@
1
- declare const getHandlerPath: ({ context }: {
2
- context: string;
3
- }) => string;
1
+ declare type GetHandlerPath = {
2
+ input: string;
3
+ };
4
+ declare const getHandlerPath: ({ input }: GetHandlerPath) => string;
4
5
  export default getHandlerPath;
@@ -1,8 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- var getHandlerPath = function (_a) {
4
- var context = _a.context;
5
- return "".concat(context.split(process.cwd())[1].substring(1)
6
- .replace(/\\/g, '/'));
3
+ const getHandlerPath = ({ input }) => {
4
+ return `${input.split(process.cwd())[1].substring(1)
5
+ .replace(/\\/g, '/')}`;
7
6
  };
8
7
  exports.default = getHandlerPath;
@@ -1,9 +1,10 @@
1
- import { Config } from '../config';
1
+ import { Config } from '../getConfig';
2
+ declare type InitClient = {
3
+ config: Config;
4
+ };
2
5
  /**
3
6
  * Shorthand function to get the Lambda Client.
4
7
  * Library: @aws-sdk/client-lambda
5
8
  */
6
- declare const initClient: ({ config }: {
7
- config?: Config;
8
- }) => void;
9
+ declare const initClient: ({ config }: InitClient) => void;
9
10
  export default initClient;
@@ -3,17 +3,16 @@ 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 getConfig_1 = __importDefault(require("../getConfig"));
6
+ const getConfig_1 = __importDefault(require("../getConfig"));
7
7
  global.awsLambdaClient = null;
8
8
  /**
9
9
  * Shorthand function to get the Lambda Client.
10
10
  * Library: @aws-sdk/client-lambda
11
11
  */
12
- var initClient = function (_a) {
13
- var config = _a.config;
12
+ const initClient = ({ config }) => {
14
13
  if (!global.awsLambdaClient) {
15
- var S3Client = require('@aws-sdk/client-lambda').S3Client;
16
- var formattedConfig = (0, getConfig_1.default)({ config: config });
14
+ const { S3Client } = require('@aws-sdk/client-lambda');
15
+ const formattedConfig = (0, getConfig_1.default)({ config });
17
16
  global.awsLambdaClient = new S3Client(formattedConfig);
18
17
  }
19
18
  };
@@ -1,6 +1,4 @@
1
- import { Config } from '../config';
2
1
  declare type Invoke = {
3
- config?: Config;
4
2
  functionName: string;
5
3
  payload?: object;
6
4
  response?: boolean;
@@ -10,5 +8,5 @@ declare type Invoke = {
10
8
  * Runs asynchronously, doesn't wait for function to fully end.
11
9
  * Library: @aws-sdk/client-lambda
12
10
  */
13
- declare const invoke: ({ config, functionName, payload, response }: Invoke) => Promise<any>;
11
+ declare const invoke: ({ functionName, payload, response }: Invoke) => Promise<any>;
14
12
  export default invoke;
@@ -1,90 +1,42 @@
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 isResponse200_1 = __importDefault(require("../isResponse200"));
43
- var initClient_1 = __importDefault(require("./initClient"));
6
+ const isResponse200_1 = __importDefault(require("../isResponse200"));
44
7
  /**
45
8
  * Invoke a AWS Lambda function by passing in the Function name and optional Payload data.
46
9
  * Runs asynchronously, doesn't wait for function to fully end.
47
10
  * Library: @aws-sdk/client-lambda
48
11
  */
49
- var invoke = function (_a) {
50
- var config = _a.config, functionName = _a.functionName, payload = _a.payload, response = _a.response;
51
- return __awaiter(void 0, void 0, void 0, function () {
52
- var params, InvokeCommand, command, apiResponse, asciiDecoder, decoded, decodedJson;
53
- return __generator(this, function (_b) {
54
- switch (_b.label) {
55
- case 0:
56
- // Ensure the client has been initialised
57
- (0, initClient_1.default)({ config: config });
58
- params = {
59
- FunctionName: functionName,
60
- InvocationType: true === response ? 'RequestResponse' : 'Event',
61
- };
62
- // Payload is defined add to parameters
63
- if (undefined !== payload) {
64
- params['Payload'] = new Uint8Array(Buffer.from(JSON.stringify(payload)));
65
- }
66
- InvokeCommand = require('@aws-sdk/client-lambda').InvokeCommand;
67
- command = new InvokeCommand(params);
68
- return [4 /*yield*/, global.awsLambdaClient.send(command)];
69
- case 1:
70
- apiResponse = _b.sent();
71
- // Success
72
- if ((0, isResponse200_1.default)({ apiResponse: apiResponse })) {
73
- // Return the data
74
- if (response && undefined !== apiResponse['Payload']) {
75
- asciiDecoder = new TextDecoder('ascii');
76
- decoded = asciiDecoder.decode(apiResponse['Payload']);
77
- decodedJson = JSON.parse(decoded);
78
- if (undefined !== decodedJson['body']) {
79
- return [2 /*return*/, decodedJson['body']];
80
- }
81
- return [2 /*return*/, decodedJson];
82
- }
83
- return [2 /*return*/, true];
84
- }
85
- return [2 /*return*/, false];
12
+ const invoke = async ({ functionName, payload, response }) => {
13
+ const params = {
14
+ FunctionName: functionName,
15
+ InvocationType: true === response ? 'RequestResponse' : 'Event',
16
+ };
17
+ // Payload is defined add to parameters
18
+ if (undefined !== payload) {
19
+ params['Payload'] = new Uint8Array(Buffer.from(JSON.stringify(payload)));
20
+ }
21
+ // Create the Lambda Command
22
+ const { InvokeCommand } = require('@aws-sdk/client-lambda');
23
+ const command = new InvokeCommand(params);
24
+ // Fire the event but don't wait for it to complete
25
+ const apiResponse = await global.awsLambdaClient.send(command);
26
+ // Success
27
+ if ((0, isResponse200_1.default)({ apiResponse })) {
28
+ // Return the data
29
+ if (response && undefined !== apiResponse['Payload']) {
30
+ const asciiDecoder = new TextDecoder('ascii');
31
+ const decoded = asciiDecoder.decode(apiResponse['Payload']);
32
+ const decodedJson = JSON.parse(decoded);
33
+ if (undefined !== decodedJson['body']) {
34
+ return decodedJson['body'];
86
35
  }
87
- });
88
- });
36
+ return decodedJson;
37
+ }
38
+ return true;
39
+ }
40
+ return false;
89
41
  };
90
42
  exports.default = invoke;
@@ -1,62 +1,14 @@
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
  * Copy a file from one bucket/path to another bucket/path.
41
5
  */
42
- var copyFile = function (_a) {
43
- var from = _a.from, to = _a.to;
44
- return __awaiter(void 0, void 0, void 0, function () {
45
- var CopyObjectCommand;
46
- return __generator(this, function (_b) {
47
- switch (_b.label) {
48
- case 0:
49
- CopyObjectCommand = require('@aws-sdk/client-s3').CopyObjectCommand;
50
- return [4 /*yield*/, global.awsS3Client.send(new CopyObjectCommand({
51
- Bucket: to.bucket,
52
- CopySource: encodeURIComponent("".concat(from.bucket, "/").concat(from.key)),
53
- Key: to.key,
54
- }))];
55
- case 1:
56
- _b.sent();
57
- return [2 /*return*/];
58
- }
59
- });
60
- });
6
+ const copyFile = async ({ from, to }) => {
7
+ const { CopyObjectCommand } = require('@aws-sdk/client-s3');
8
+ await global.awsS3Client.send(new CopyObjectCommand({
9
+ Bucket: to.bucket,
10
+ CopySource: encodeURIComponent(`${from.bucket}/${from.key}`),
11
+ Key: to.key,
12
+ }));
61
13
  };
62
14
  exports.default = copyFile;
@@ -1,61 +1,13 @@
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
  * Delete a single file.
41
5
  */
42
- var deleteFile = function (_a) {
43
- var bucket = _a.bucket, key = _a.key;
44
- return __awaiter(void 0, void 0, void 0, function () {
45
- var DeleteObjectCommand;
46
- return __generator(this, function (_b) {
47
- switch (_b.label) {
48
- case 0:
49
- DeleteObjectCommand = require('@aws-sdk/client-s3').DeleteObjectCommand;
50
- return [4 /*yield*/, global.awsS3Client.send(new DeleteObjectCommand({
51
- Bucket: bucket,
52
- Key: key,
53
- }))];
54
- case 1:
55
- _b.sent();
56
- return [2 /*return*/];
57
- }
58
- });
59
- });
6
+ const deleteFile = async ({ bucket, key }) => {
7
+ const { DeleteObjectCommand } = require('@aws-sdk/client-s3');
8
+ await global.awsS3Client.send(new DeleteObjectCommand({
9
+ Bucket: bucket,
10
+ Key: key,
11
+ }));
60
12
  };
61
13
  exports.default = deleteFile;