@spytecgps/lambda-utils 0.9.7 → 0.9.9

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,2 +1,15 @@
1
+ import * as Joi from 'joi';
2
+ import { ArraySchema, ObjectSchema, SchemaMap, StringSchema } from 'joi';
1
3
  export declare const json: any;
2
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,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.urlEncoded = exports.json = void 0;
3
+ exports.SpytecJoi = exports.iccidSchema = exports.imeiSchema = exports.urlEncoded = exports.json = void 0;
4
4
  var Joi = require("joi");
5
5
  var qs = require("qs");
6
6
  exports.json = Joi.extend(function (joi) {
@@ -35,3 +35,54 @@ exports.urlEncoded = Joi.extend(function (joi) {
35
35
  },
36
36
  };
37
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
+ }); });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@spytecgps/lambda-utils",
3
- "version": "0.9.7",
3
+ "version": "0.9.9",
4
4
  "description": "Lambda Utils",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",