@spytecgps/lambda-utils 0.9.11 → 0.9.12

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,5 +1,5 @@
1
- import { BaseError } from './BaseError';
2
- export default class BadRequestError extends BaseError {
3
- code: number;
4
- name: string;
5
- }
1
+ import { BaseError } from './BaseError';
2
+ export default class BadRequestError extends BaseError {
3
+ code: number;
4
+ name: string;
5
+ }
@@ -1,27 +1,27 @@
1
- "use strict";
2
- var __extends = (this && this.__extends) || (function () {
3
- var extendStatics = function (d, b) {
4
- extendStatics = Object.setPrototypeOf ||
5
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
- function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
7
- return extendStatics(d, b);
8
- };
9
- return function (d, b) {
10
- extendStatics(d, b);
11
- function __() { this.constructor = d; }
12
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
13
- };
14
- })();
15
- Object.defineProperty(exports, "__esModule", { value: true });
16
- var BaseError_1 = require("./BaseError");
17
- var BadRequestError = /** @class */ (function (_super) {
18
- __extends(BadRequestError, _super);
19
- function BadRequestError() {
20
- var _this = _super !== null && _super.apply(this, arguments) || this;
21
- _this.code = 400;
22
- _this.name = 'BadRequestError';
23
- return _this;
24
- }
25
- return BadRequestError;
26
- }(BaseError_1.BaseError));
27
- exports.default = BadRequestError;
1
+ "use strict";
2
+ var __extends = (this && this.__extends) || (function () {
3
+ var extendStatics = function (d, b) {
4
+ extendStatics = Object.setPrototypeOf ||
5
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
+ function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
7
+ return extendStatics(d, b);
8
+ };
9
+ return function (d, b) {
10
+ extendStatics(d, b);
11
+ function __() { this.constructor = d; }
12
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
13
+ };
14
+ })();
15
+ Object.defineProperty(exports, "__esModule", { value: true });
16
+ var BaseError_1 = require("./BaseError");
17
+ var BadRequestError = /** @class */ (function (_super) {
18
+ __extends(BadRequestError, _super);
19
+ function BadRequestError() {
20
+ var _this = _super !== null && _super.apply(this, arguments) || this;
21
+ _this.code = 400;
22
+ _this.name = 'BadRequestError';
23
+ return _this;
24
+ }
25
+ return BadRequestError;
26
+ }(BaseError_1.BaseError));
27
+ exports.default = BadRequestError;
@@ -1,3 +1,3 @@
1
- export declare abstract class BaseError extends Error {
2
- abstract code: number;
3
- }
1
+ export declare abstract class BaseError extends Error {
2
+ abstract code: number;
3
+ }
@@ -1,24 +1,24 @@
1
- "use strict";
2
- var __extends = (this && this.__extends) || (function () {
3
- var extendStatics = function (d, b) {
4
- extendStatics = Object.setPrototypeOf ||
5
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
- function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
7
- return extendStatics(d, b);
8
- };
9
- return function (d, b) {
10
- extendStatics(d, b);
11
- function __() { this.constructor = d; }
12
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
13
- };
14
- })();
15
- Object.defineProperty(exports, "__esModule", { value: true });
16
- exports.BaseError = void 0;
17
- var BaseError = /** @class */ (function (_super) {
18
- __extends(BaseError, _super);
19
- function BaseError() {
20
- return _super !== null && _super.apply(this, arguments) || this;
21
- }
22
- return BaseError;
23
- }(Error));
24
- exports.BaseError = BaseError;
1
+ "use strict";
2
+ var __extends = (this && this.__extends) || (function () {
3
+ var extendStatics = function (d, b) {
4
+ extendStatics = Object.setPrototypeOf ||
5
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
+ function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
7
+ return extendStatics(d, b);
8
+ };
9
+ return function (d, b) {
10
+ extendStatics(d, b);
11
+ function __() { this.constructor = d; }
12
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
13
+ };
14
+ })();
15
+ Object.defineProperty(exports, "__esModule", { value: true });
16
+ exports.BaseError = void 0;
17
+ var BaseError = /** @class */ (function (_super) {
18
+ __extends(BaseError, _super);
19
+ function BaseError() {
20
+ return _super !== null && _super.apply(this, arguments) || this;
21
+ }
22
+ return BaseError;
23
+ }(Error));
24
+ exports.BaseError = BaseError;
@@ -1,5 +1,5 @@
1
- import { BaseError } from './BaseError';
2
- export default class NotFoundError extends BaseError {
3
- code: number;
4
- name: string;
5
- }
1
+ import { BaseError } from './BaseError';
2
+ export default class NotFoundError extends BaseError {
3
+ code: number;
4
+ name: string;
5
+ }
@@ -1,27 +1,27 @@
1
- "use strict";
2
- var __extends = (this && this.__extends) || (function () {
3
- var extendStatics = function (d, b) {
4
- extendStatics = Object.setPrototypeOf ||
5
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
- function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
7
- return extendStatics(d, b);
8
- };
9
- return function (d, b) {
10
- extendStatics(d, b);
11
- function __() { this.constructor = d; }
12
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
13
- };
14
- })();
15
- Object.defineProperty(exports, "__esModule", { value: true });
16
- var BaseError_1 = require("./BaseError");
17
- var NotFoundError = /** @class */ (function (_super) {
18
- __extends(NotFoundError, _super);
19
- function NotFoundError() {
20
- var _this = _super !== null && _super.apply(this, arguments) || this;
21
- _this.code = 404;
22
- _this.name = 'NotFoundError';
23
- return _this;
24
- }
25
- return NotFoundError;
26
- }(BaseError_1.BaseError));
27
- exports.default = NotFoundError;
1
+ "use strict";
2
+ var __extends = (this && this.__extends) || (function () {
3
+ var extendStatics = function (d, b) {
4
+ extendStatics = Object.setPrototypeOf ||
5
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
+ function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
7
+ return extendStatics(d, b);
8
+ };
9
+ return function (d, b) {
10
+ extendStatics(d, b);
11
+ function __() { this.constructor = d; }
12
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
13
+ };
14
+ })();
15
+ Object.defineProperty(exports, "__esModule", { value: true });
16
+ var BaseError_1 = require("./BaseError");
17
+ var NotFoundError = /** @class */ (function (_super) {
18
+ __extends(NotFoundError, _super);
19
+ function NotFoundError() {
20
+ var _this = _super !== null && _super.apply(this, arguments) || this;
21
+ _this.code = 404;
22
+ _this.name = 'NotFoundError';
23
+ return _this;
24
+ }
25
+ return NotFoundError;
26
+ }(BaseError_1.BaseError));
27
+ exports.default = NotFoundError;
@@ -1,5 +1,5 @@
1
- import { BaseError } from './BaseError';
2
- export default class UnauthorizedError extends BaseError {
3
- code: number;
4
- name: string;
5
- }
1
+ import { BaseError } from './BaseError';
2
+ export default class UnauthorizedError extends BaseError {
3
+ code: number;
4
+ name: string;
5
+ }
@@ -1,27 +1,27 @@
1
- "use strict";
2
- var __extends = (this && this.__extends) || (function () {
3
- var extendStatics = function (d, b) {
4
- extendStatics = Object.setPrototypeOf ||
5
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
- function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
7
- return extendStatics(d, b);
8
- };
9
- return function (d, b) {
10
- extendStatics(d, b);
11
- function __() { this.constructor = d; }
12
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
13
- };
14
- })();
15
- Object.defineProperty(exports, "__esModule", { value: true });
16
- var BaseError_1 = require("./BaseError");
17
- var UnauthorizedError = /** @class */ (function (_super) {
18
- __extends(UnauthorizedError, _super);
19
- function UnauthorizedError() {
20
- var _this = _super !== null && _super.apply(this, arguments) || this;
21
- _this.code = 401;
22
- _this.name = 'UnauthorizedError';
23
- return _this;
24
- }
25
- return UnauthorizedError;
26
- }(BaseError_1.BaseError));
27
- exports.default = UnauthorizedError;
1
+ "use strict";
2
+ var __extends = (this && this.__extends) || (function () {
3
+ var extendStatics = function (d, b) {
4
+ extendStatics = Object.setPrototypeOf ||
5
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
+ function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
7
+ return extendStatics(d, b);
8
+ };
9
+ return function (d, b) {
10
+ extendStatics(d, b);
11
+ function __() { this.constructor = d; }
12
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
13
+ };
14
+ })();
15
+ Object.defineProperty(exports, "__esModule", { value: true });
16
+ var BaseError_1 = require("./BaseError");
17
+ var UnauthorizedError = /** @class */ (function (_super) {
18
+ __extends(UnauthorizedError, _super);
19
+ function UnauthorizedError() {
20
+ var _this = _super !== null && _super.apply(this, arguments) || this;
21
+ _this.code = 401;
22
+ _this.name = 'UnauthorizedError';
23
+ return _this;
24
+ }
25
+ return UnauthorizedError;
26
+ }(BaseError_1.BaseError));
27
+ exports.default = UnauthorizedError;
@@ -1,4 +1,4 @@
1
- import BadRequestError from './BadRequestError';
2
- import NotFoundError from './NotFoundError';
3
- import UnauthorizedError from './UnauthorizedError';
4
- export { BadRequestError, NotFoundError, UnauthorizedError };
1
+ import BadRequestError from './BadRequestError';
2
+ import NotFoundError from './NotFoundError';
3
+ import UnauthorizedError from './UnauthorizedError';
4
+ export { BadRequestError, NotFoundError, UnauthorizedError };
@@ -1,9 +1,9 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.UnauthorizedError = exports.NotFoundError = exports.BadRequestError = void 0;
4
- var BadRequestError_1 = require("./BadRequestError");
5
- exports.BadRequestError = BadRequestError_1.default;
6
- var NotFoundError_1 = require("./NotFoundError");
7
- exports.NotFoundError = NotFoundError_1.default;
8
- var UnauthorizedError_1 = require("./UnauthorizedError");
9
- exports.UnauthorizedError = UnauthorizedError_1.default;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.UnauthorizedError = exports.NotFoundError = exports.BadRequestError = void 0;
4
+ var BadRequestError_1 = require("./BadRequestError");
5
+ exports.BadRequestError = BadRequestError_1.default;
6
+ var NotFoundError_1 = require("./NotFoundError");
7
+ exports.NotFoundError = NotFoundError_1.default;
8
+ var UnauthorizedError_1 = require("./UnauthorizedError");
9
+ exports.UnauthorizedError = UnauthorizedError_1.default;
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export * from './wrappers';
2
- export * from './errors';
3
- export * from './validation';
4
- export * from './types';
1
+ export * from './wrappers';
2
+ export * from './errors';
3
+ export * from './validation';
4
+ export * from './types';
package/dist/index.js CHANGED
@@ -1,16 +1,16 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
- }) : (function(o, m, k, k2) {
6
- if (k2 === undefined) k2 = k;
7
- o[k2] = m[k];
8
- }));
9
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
10
- for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p);
11
- };
12
- Object.defineProperty(exports, "__esModule", { value: true });
13
- __exportStar(require("./wrappers"), exports);
14
- __exportStar(require("./errors"), exports);
15
- __exportStar(require("./validation"), exports);
16
- __exportStar(require("./types"), exports);
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
10
+ for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p);
11
+ };
12
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ __exportStar(require("./wrappers"), exports);
14
+ __exportStar(require("./errors"), exports);
15
+ __exportStar(require("./validation"), exports);
16
+ __exportStar(require("./types"), exports);
package/dist/types.d.ts CHANGED
@@ -1,42 +1,43 @@
1
- import { APIGatewayEventRequestContext, APIGatewayProxyEvent, APIGatewayProxyWithLambdaAuthorizerEvent, SQSEvent, SQSRecord } from 'aws-lambda';
2
- import { ObjectSchema } from 'joi';
3
- import { APIGatewayProxyEventBase } from 'aws-lambda/trigger/api-gateway-proxy';
4
- import * as Joi from 'joi';
5
- export interface SpytecAuthorizedResources {
6
- devices: string[];
7
- }
8
- export declare type AuthClass = 'user' | 'client' | 'system';
9
- export interface SpytecAuthContext {
10
- type: AuthClass;
11
- userId?: string;
12
- clientId: number;
13
- resources: SpytecAuthorizedResources;
14
- principalId: string;
15
- scope?: string;
16
- }
17
- export declare type BaseAPIGatewayEvent = Omit<APIGatewayProxyEventBase<SpytecAuthContext>, 'pathParameters' | 'queryStringParameters' | 'body'>;
18
- export interface WrapperArgs<E, R> {
19
- event: APIGatewayProxyWithLambdaAuthorizerEvent<SpytecAuthContext> | APIGatewayProxyEvent;
20
- context?: APIGatewayEventRequestContext;
21
- schema?: ObjectSchema<E>;
22
- handler: Handler<E, R>;
23
- }
24
- export declare type Handler<E, R> = (event: E) => Promise<HandlerResponse<R>>;
25
- export interface HandlerResponse<R> {
26
- statusCode?: number;
27
- headers?: {
28
- [header: string]: boolean | number | string;
29
- };
30
- isBase64Encoded?: boolean;
31
- message?: string;
32
- data?: R;
33
- }
34
- export declare type BaseRecord = Omit<SQSRecord, 'body' | 'messageAttributes'>;
35
- export interface MessageEvent<RecordType extends BaseRecord> {
36
- Records: RecordType[];
37
- }
38
- export interface SQSWrapperArgs<RecordType extends BaseRecord> {
39
- event: SQSEvent;
40
- schema?: Joi.ObjectSchema<MessageEvent<RecordType>>;
41
- handler: (e: MessageEvent<RecordType>) => void | Promise<void>;
42
- }
1
+ import { APIGatewayEventRequestContext, APIGatewayProxyEvent, APIGatewayProxyWithLambdaAuthorizerEvent, SQSEvent, SQSRecord } from 'aws-lambda';
2
+ import { ObjectSchema } from 'joi';
3
+ import { APIGatewayProxyEventBase } from 'aws-lambda/trigger/api-gateway-proxy';
4
+ import * as Joi from 'joi';
5
+ export interface SpytecAuthorizedResources {
6
+ devices: string[];
7
+ }
8
+ export declare type AuthClass = 'user' | 'client' | 'system';
9
+ export interface SpytecAuthContext {
10
+ type: AuthClass;
11
+ userId?: string;
12
+ clientId: number;
13
+ resources: SpytecAuthorizedResources;
14
+ principalId: string;
15
+ scope?: string;
16
+ }
17
+ export declare type BaseAPIGatewayEvent = Omit<APIGatewayProxyEventBase<SpytecAuthContext>, 'pathParameters' | 'queryStringParameters' | 'body'>;
18
+ export interface WrapperArgs<E, R> {
19
+ event: APIGatewayProxyWithLambdaAuthorizerEvent<SpytecAuthContext> | APIGatewayProxyEvent;
20
+ context?: APIGatewayEventRequestContext;
21
+ schema?: ObjectSchema<E>;
22
+ handler: Handler<E, R>;
23
+ }
24
+ export declare type Handler<E, R> = (event: E) => Promise<HandlerResponse<R>>;
25
+ export interface HandlerResponse<R> {
26
+ statusCode?: number;
27
+ headers?: {
28
+ [header: string]: boolean | number | string;
29
+ };
30
+ isBase64Encoded?: boolean;
31
+ message?: string;
32
+ data?: R;
33
+ rawResult?: boolean;
34
+ }
35
+ export declare type BaseRecord = Omit<SQSRecord, 'body' | 'messageAttributes'>;
36
+ export interface MessageEvent<RecordType extends BaseRecord> {
37
+ Records: RecordType[];
38
+ }
39
+ export interface SQSWrapperArgs<RecordType extends BaseRecord> {
40
+ event: SQSEvent;
41
+ schema?: Joi.ObjectSchema<MessageEvent<RecordType>>;
42
+ handler: (e: MessageEvent<RecordType>) => void | Promise<void>;
43
+ }
package/dist/types.js CHANGED
@@ -1,2 +1,2 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,15 +1,15 @@
1
- import * as Joi from 'joi';
2
- import { ArraySchema, ObjectSchema, SchemaMap, StringSchema } from 'joi';
3
- export declare const json: any;
4
- export declare const urlEncoded: any;
5
- export declare const imeiSchema: Joi.StringSchema;
6
- export declare const iccidSchema: Joi.StringSchema;
7
- interface SpytecJoi extends Joi.Root {
8
- urlEncodedObject<TSchema = any, T = TSchema>(schema?: SchemaMap<T>): ObjectSchema<TSchema>;
9
- jsonObject<TSchema = any, T = TSchema>(schema?: SchemaMap<T>): ObjectSchema<TSchema>;
10
- imei(): StringSchema;
11
- iccid(): StringSchema;
12
- delimitedArray(): ArraySchema;
13
- }
14
- export declare const SpytecJoi: SpytecJoi;
15
- export {};
1
+ import * as Joi from 'joi';
2
+ import { ArraySchema, ObjectSchema, SchemaMap, StringSchema } from 'joi';
3
+ export declare const json: any;
4
+ export declare const urlEncoded: any;
5
+ export declare const imeiSchema: Joi.StringSchema;
6
+ export declare const iccidSchema: Joi.StringSchema;
7
+ interface SpytecJoi extends Joi.Root {
8
+ urlEncodedObject<TSchema = any, T = TSchema>(schema?: SchemaMap<T>): ObjectSchema<TSchema>;
9
+ jsonObject<TSchema = any, T = TSchema>(schema?: SchemaMap<T>): ObjectSchema<TSchema>;
10
+ imei(): StringSchema;
11
+ iccid(): StringSchema;
12
+ delimitedArray(): ArraySchema;
13
+ }
14
+ export declare const SpytecJoi: SpytecJoi;
15
+ export {};
@@ -1,88 +1,88 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.SpytecJoi = exports.iccidSchema = exports.imeiSchema = exports.urlEncoded = exports.json = void 0;
4
- var Joi = require("joi");
5
- var qs = require("qs");
6
- exports.json = Joi.extend(function (joi) {
7
- return {
8
- type: 'object',
9
- base: joi.object(),
10
- messages: {
11
- 'json.valid': 'must be valid JSON',
12
- },
13
- coerce: function (value) {
14
- try {
15
- return { value: JSON.parse(value) };
16
- }
17
- catch (err) {
18
- return null;
19
- }
20
- },
21
- validate: function (value, helpers) {
22
- if (!value) {
23
- return { value: value, errors: helpers.error('json.valid') };
24
- }
25
- return { value: value };
26
- },
27
- };
28
- });
29
- exports.urlEncoded = Joi.extend(function (joi) {
30
- return {
31
- type: 'object',
32
- base: joi.object(),
33
- coerce: function (value) {
34
- return { value: qs.parse(value) };
35
- },
36
- };
37
- });
38
- exports.imeiSchema = Joi.string()
39
- .regex(/^\d{15,16}$/)
40
- .error(new Error('Invalid IMEI'));
41
- exports.iccidSchema = Joi.string()
42
- .regex(/^[0-9A-Za-z]{18,22}$/)
43
- .error(new Error('Invalid ICCID'));
44
- exports.SpytecJoi = Joi.extend(function (joi) { return ({
45
- type: 'imei',
46
- base: joi
47
- .string()
48
- .regex(/^\d{15,16}$/)
49
- .error(new Error('Invalid IMEI')),
50
- }); }, function (joi) { return ({
51
- type: 'iccid',
52
- base: joi
53
- .string()
54
- .regex(/^[0-9A-Za-z]{18,22}$/)
55
- .error(new Error('Invalid ICCID')),
56
- }); }, function (joi) { return ({
57
- type: 'urlEncodedObject',
58
- base: joi.object(),
59
- coerce: function (value) {
60
- return { value: qs.parse(value) };
61
- },
62
- }); }, function (joi) { return ({
63
- type: 'jsonObject',
64
- base: joi.object(),
65
- messages: {
66
- 'json.valid': 'must be valid JSON',
67
- },
68
- coerce: function (value) {
69
- try {
70
- return { value: JSON.parse(value) };
71
- }
72
- catch (err) {
73
- return null;
74
- }
75
- },
76
- validate: function (value, helpers) {
77
- if (!value) {
78
- return { value: value, errors: helpers.error('json.valid') };
79
- }
80
- return { value: value };
81
- },
82
- }); }, function (joi) { return ({
83
- type: 'delimitedArray',
84
- base: joi.array().default([]),
85
- coerce: function (value) { return ({
86
- value: value.split ? value.split(',') : value,
87
- }); },
88
- }); });
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SpytecJoi = exports.iccidSchema = exports.imeiSchema = exports.urlEncoded = exports.json = void 0;
4
+ var Joi = require("joi");
5
+ var qs = require("qs");
6
+ exports.json = Joi.extend(function (joi) {
7
+ return {
8
+ type: 'object',
9
+ base: joi.object(),
10
+ messages: {
11
+ 'json.valid': 'must be valid JSON',
12
+ },
13
+ coerce: function (value) {
14
+ try {
15
+ return { value: JSON.parse(value) };
16
+ }
17
+ catch (err) {
18
+ return null;
19
+ }
20
+ },
21
+ validate: function (value, helpers) {
22
+ if (!value) {
23
+ return { value: value, errors: helpers.error('json.valid') };
24
+ }
25
+ return { value: value };
26
+ },
27
+ };
28
+ });
29
+ exports.urlEncoded = Joi.extend(function (joi) {
30
+ return {
31
+ type: 'object',
32
+ base: joi.object(),
33
+ coerce: function (value) {
34
+ return { value: qs.parse(value) };
35
+ },
36
+ };
37
+ });
38
+ exports.imeiSchema = Joi.string()
39
+ .regex(/^\d{15,16}$/)
40
+ .error(new Error('Invalid IMEI'));
41
+ exports.iccidSchema = Joi.string()
42
+ .regex(/^[0-9A-Za-z]{18,22}$/)
43
+ .error(new Error('Invalid ICCID'));
44
+ exports.SpytecJoi = Joi.extend(function (joi) { return ({
45
+ type: 'imei',
46
+ base: joi
47
+ .string()
48
+ .regex(/^\d{15,16}$/)
49
+ .error(new Error('Invalid IMEI')),
50
+ }); }, function (joi) { return ({
51
+ type: 'iccid',
52
+ base: joi
53
+ .string()
54
+ .regex(/^[0-9A-Za-z]{18,22}$/)
55
+ .error(new Error('Invalid ICCID')),
56
+ }); }, function (joi) { return ({
57
+ type: 'urlEncodedObject',
58
+ base: joi.object(),
59
+ coerce: function (value) {
60
+ return { value: qs.parse(value) };
61
+ },
62
+ }); }, function (joi) { return ({
63
+ type: 'jsonObject',
64
+ base: joi.object(),
65
+ messages: {
66
+ 'json.valid': 'must be valid JSON',
67
+ },
68
+ coerce: function (value) {
69
+ try {
70
+ return { value: JSON.parse(value) };
71
+ }
72
+ catch (err) {
73
+ return null;
74
+ }
75
+ },
76
+ validate: function (value, helpers) {
77
+ if (!value) {
78
+ return { value: value, errors: helpers.error('json.valid') };
79
+ }
80
+ return { value: value };
81
+ },
82
+ }); }, function (joi) { return ({
83
+ type: 'delimitedArray',
84
+ base: joi.array().default([]),
85
+ coerce: function (value) { return ({
86
+ value: value.split ? value.split(',') : value,
87
+ }); },
88
+ }); });
@@ -1,4 +1,4 @@
1
- import validateEvent from './validateEvent';
2
- export { validateEvent };
3
- export * from './custom';
4
- export * from './requestContext';
1
+ import validateEvent from './validateEvent';
2
+ export { validateEvent };
3
+ export * from './custom';
4
+ export * from './requestContext';