@spytecgps/lambda-utils 1.0.16 → 1.0.18

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.
package/dist/types.d.ts CHANGED
@@ -40,6 +40,7 @@ export interface HandlerResponse<R> {
40
40
  message?: string;
41
41
  data?: R;
42
42
  rawResult?: boolean;
43
+ stringifyBody?: boolean;
43
44
  }
44
45
  export declare type BaseRecord = Omit<SQSRecord, 'body' | 'messageAttributes'>;
45
46
  export interface MessageEvent<RecordType extends BaseRecord> {
@@ -2,8 +2,8 @@ import * as Joi from 'joi';
2
2
  import { ArraySchema, ObjectSchema, SchemaMap, StringSchema } from 'joi';
3
3
  export declare const json: any;
4
4
  export declare const urlEncoded: any;
5
- export declare const imeiSchema: Joi.StringSchema;
6
- export declare const iccidSchema: Joi.StringSchema;
5
+ export declare const imeiSchema: Joi.StringSchema<string>;
6
+ export declare const iccidSchema: Joi.StringSchema<string>;
7
7
  interface SpytecJoi extends Joi.Root {
8
8
  urlEncodedObject<TSchema = any, T = TSchema>(schema?: SchemaMap<T>): ObjectSchema<TSchema>;
9
9
  jsonObject<TSchema = any, T = TSchema>(schema?: SchemaMap<T>): ObjectSchema<TSchema>;
@@ -11,6 +11,7 @@ interface SpytecJoi extends Joi.Root {
11
11
  iccid(): StringSchema;
12
12
  delimitedArray(): ArraySchema;
13
13
  dateString(): StringSchema;
14
+ jsonArray<TSchema = any, T = TSchema>(schema?: Joi.SchemaMap<T>): ArraySchema<TSchema>;
14
15
  }
15
16
  export declare const SpytecJoi: SpytecJoi;
16
17
  export {};
@@ -85,7 +85,6 @@ exports.SpytecJoi = Joi.extend(function (joi) { return ({
85
85
  }); }, function (joi) { return ({
86
86
  type: 'jsonObject',
87
87
  base: joi.object(),
88
- messages: 'must be valid JSON',
89
88
  coerce: function (value) {
90
89
  try {
91
90
  return { value: JSON.parse(value) };
@@ -124,4 +123,21 @@ exports.SpytecJoi = Joi.extend(function (joi) { return ({
124
123
  return helpers.error('any.invalid');
125
124
  }
126
125
  },
126
+ }); }, function (joi) { return ({
127
+ type: 'jsonArray',
128
+ base: joi.array(),
129
+ coerce: function (value) {
130
+ try {
131
+ return { value: JSON.parse(value) };
132
+ }
133
+ catch (err) {
134
+ return { value: null };
135
+ }
136
+ },
137
+ validate: function (value, helpers) {
138
+ if (!Array.isArray(value)) {
139
+ return { value: value, errors: helpers.error('jsonArray.schema') };
140
+ }
141
+ return { value: value };
142
+ },
127
143
  }); });
@@ -5,4 +5,4 @@ export declare const buildResponseBody: <T>(statusCode: number, message: string,
5
5
  message: string;
6
6
  result: T;
7
7
  };
8
- export declare const buildProxyResult: <R>({ statusCode, message, data, headers, rawResult, }: HandlerResponse<R>) => APIGatewayProxyResult;
8
+ export declare const buildProxyResult: <R>({ statusCode, message, data, headers, rawResult, stringifyBody, }: HandlerResponse<R>) => APIGatewayProxyResult;
@@ -25,11 +25,12 @@ exports.buildResponseBody = function (statusCode, message, data) {
25
25
  };
26
26
  };
27
27
  exports.buildProxyResult = function (_a) {
28
- var _b = _a.statusCode, statusCode = _b === void 0 ? 200 : _b, _c = _a.message, message = _c === void 0 ? 'ok' : _c, data = _a.data, _d = _a.headers, headers = _d === void 0 ? {} : _d, _e = _a.rawResult, rawResult = _e === void 0 ? false : _e;
28
+ var _b = _a.statusCode, statusCode = _b === void 0 ? 200 : _b, _c = _a.message, message = _c === void 0 ? 'ok' : _c, data = _a.data, _d = _a.headers, headers = _d === void 0 ? {} : _d, _e = _a.rawResult, rawResult = _e === void 0 ? false : _e, _f = _a.stringifyBody, stringifyBody = _f === void 0 ? true : _f;
29
29
  var resp = rawResult ? data : exports.buildResponseBody(statusCode, message, data);
30
+ var body = stringifyBody ? resp && JSON.stringify(resp) : data;
30
31
  return {
31
32
  headers: __assign(__assign({}, baseHeaders), headers),
32
33
  statusCode: statusCode,
33
- body: resp && JSON.stringify(resp),
34
+ body: body,
34
35
  };
35
36
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@spytecgps/lambda-utils",
3
- "version": "1.0.16",
3
+ "version": "1.0.18",
4
4
  "description": "Lambda Utils",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -34,7 +34,7 @@
34
34
  "@middy/input-output-logger": "^2.5.7",
35
35
  "@spytecgps/sdk": "0.5.97",
36
36
  "dayjs": "^1.11.9",
37
- "joi": "^17.4.0",
37
+ "joi": "^17.12.2",
38
38
  "logform": "^2.4.0",
39
39
  "qs": "^6.10.1",
40
40
  "winston": "^3.7.2",