@8ms/helpers 1.1.82 → 1.1.85

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.
@@ -1,12 +1,13 @@
1
1
  declare type Invoke = {
2
+ awaitResponse?: boolean;
2
3
  functionName: string;
4
+ isJson?: boolean;
3
5
  payload?: object;
4
- response?: boolean;
5
6
  };
6
7
  /**
7
8
  * Invoke a AWS Lambda function by passing in the Function name and optional Payload data.
8
9
  * Runs asynchronously, doesn't wait for function to fully end.
9
10
  * Library: @aws-sdk/client-lambda
10
11
  */
11
- declare const invoke: ({ functionName, payload, response }: Invoke) => Promise<any>;
12
+ declare const invoke: ({ awaitResponse, functionName, isJson, payload }: Invoke) => Promise<any>;
12
13
  export default invoke;
@@ -9,10 +9,11 @@ const isResponse200_1 = __importDefault(require("../isResponse200"));
9
9
  * Runs asynchronously, doesn't wait for function to fully end.
10
10
  * Library: @aws-sdk/client-lambda
11
11
  */
12
- const invoke = async ({ functionName, payload, response }) => {
12
+ const invoke = async ({ awaitResponse, functionName, isJson, payload }) => {
13
+ let response = false;
13
14
  const params = {
14
15
  FunctionName: functionName,
15
- InvocationType: true === response ? 'RequestResponse' : 'Event',
16
+ InvocationType: true === awaitResponse ? 'RequestResponse' : 'Event',
16
17
  };
17
18
  // Payload is defined add to parameters
18
19
  if (undefined !== payload) {
@@ -26,17 +27,23 @@ const invoke = async ({ functionName, payload, response }) => {
26
27
  // Success
27
28
  if ((0, isResponse200_1.default)({ apiResponse })) {
28
29
  // Return the data
29
- if (response && undefined !== apiResponse['Payload']) {
30
+ if (awaitResponse && undefined !== apiResponse.Payload) {
30
31
  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'];
32
+ response = asciiDecoder.decode(apiResponse.Payload);
33
+ // Decode string as JSON object
34
+ if (true === isJson) {
35
+ response = JSON.parse(response);
36
+ // If it's still a string, double decode it
37
+ if ('string' === typeof response) {
38
+ response = JSON.parse(response);
39
+ }
35
40
  }
36
- return decodedJson;
37
41
  }
38
- return true;
42
+ // Success but not waiting for response
43
+ else {
44
+ response = true;
45
+ }
39
46
  }
40
- return false;
47
+ return response;
41
48
  };
42
49
  exports.default = invoke;
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Shorthand to get the current date.
3
+ */
4
+ declare const getTodayYmd: () => string;
5
+ export default getTodayYmd;
@@ -0,0 +1,20 @@
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 format_1 = __importDefault(require("./format"));
7
+ const getToday_1 = __importDefault(require("./getToday"));
8
+ /**
9
+ * Shorthand to get the current date.
10
+ */
11
+ const getTodayYmd = () => {
12
+ const today = (0, getToday_1.default)({ setMidnight: false });
13
+ const todayYmd = (0, format_1.default)({
14
+ input: today,
15
+ dateFormat: 'yyyy-MM-dd',
16
+ setMidnight: false,
17
+ });
18
+ return todayYmd;
19
+ };
20
+ exports.default = getTodayYmd;
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Shorthand to get the current timestamp.
3
+ */
4
+ declare const getTodayYmdhis: () => string;
5
+ export default getTodayYmdhis;
@@ -0,0 +1,20 @@
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 format_1 = __importDefault(require("./format"));
7
+ const getToday_1 = __importDefault(require("./getToday"));
8
+ /**
9
+ * Shorthand to get the current timestamp.
10
+ */
11
+ const getTodayYmdhis = () => {
12
+ const today = (0, getToday_1.default)({ setMidnight: false });
13
+ const todayYmdhis = (0, format_1.default)({
14
+ input: today,
15
+ dateFormat: 'yyyy-MM-dd HH:mm:ss',
16
+ setMidnight: false,
17
+ });
18
+ return todayYmdhis;
19
+ };
20
+ exports.default = getTodayYmdhis;
@@ -12,7 +12,6 @@ declare type Keyword = {
12
12
  competition: number;
13
13
  competitionIndex: number;
14
14
  months: Month[];
15
- monthsAll: number;
16
15
  topOfPageBidHigh: number;
17
16
  topOfPageBidLow: number;
18
17
  totalSearchVolume: number;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@8ms/helpers",
3
3
  "license": "UNLICENSED",
4
- "version": "1.1.82",
4
+ "version": "1.1.85",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "git+https://github.com/8millionstories-organisation/8ms-helpers-ts.git"