Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

io-ts-serverless-handler

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

io-ts-serverless-handler - npm Package Compare versions

Comparing version 2.1.1 to 2.1.2

8

CHANGELOG.md

@@ -6,2 +6,10 @@ # Changelog

## [2.1.2](https://github.com/NoxHarmonium/io-ts-serverless-handler/compare/v2.1.1...v2.1.2) (2021-08-27)
### Bug Fixes
* expose GH_TOKEN ([9e3a6e6](https://github.com/NoxHarmonium/io-ts-serverless-handler/commit/9e3a6e6acbe459321373e22a6c490e41b737d904))
* force release for dependency updates ([fb14d52](https://github.com/NoxHarmonium/io-ts-serverless-handler/commit/fb14d522483bb8062c5be98450826fc6776b141f))
## [2.1.1](https://github.com/NoxHarmonium/io-ts-serverless-handler/compare/v2.1.0...v2.1.1) (2020-03-21)

@@ -8,0 +16,0 @@

2

es6/__tests__/codecs.test.js

@@ -20,3 +20,3 @@ import { isLeft, isRight } from "fp-ts/lib/Either";

["dfsjlsf"],
['{ "hello": 4 ']
['{ "hello": 4 '],
]).test("fails when decoding [%p]", function (input) {

@@ -23,0 +23,0 @@ expect.assertions(2);

import { isLeft } from "fp-ts/lib/Either";
import * as t from "io-ts";
import { defaultSuccessHandler, defaultUnhandledErrorHandler, defaultValidationErrorHandler } from "../default-handlers";
import { defaultSuccessHandler, defaultUnhandledErrorHandler, defaultValidationErrorHandler, } from "../default-handlers";
// tslint:disable: no-duplicate-string

@@ -31,3 +31,3 @@ describe("defaultValidationErrorHandler", function () {

expect(defaultSuccessHandler({
some: "object"
some: "object",
})).toMatchSnapshot();

@@ -34,0 +34,0 @@ });

@@ -54,3 +54,3 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {

cognitoIdentityId: "mock-identity-id",
cognitoIdentityPoolId: "mock-identity-pool-id"
cognitoIdentityPoolId: "mock-identity-pool-id",
},

@@ -63,3 +63,3 @@ clientContext: {

appVersionCode: "string",
appPackageName: "string"
appPackageName: "string",
},

@@ -72,4 +72,4 @@ Custom: "some custom",

model: "string",
locale: "string"
}
locale: "string",
},
},

@@ -81,4 +81,3 @@ getRemainingTimeInMillis: function () { return 60000; },

// type-coverage:ignore-next-line
succeed: function (_messageOrObject) { }
// tslint:enable: no-empty no-any
succeed: function (_messageOrObject) { },
};

@@ -106,7 +105,7 @@ // tslint:disable: no-duplicate-string no-identical-functions no-big-function

queryStringParameters: t.type({
pageSize: NumberFromString
pageSize: NumberFromString,
}),
body: t.type({
message: t.string
})
message: t.string,
}),
};

@@ -121,3 +120,3 @@ var mockHandler = function (_a, _b) {

body: body,
awsRequestId: awsRequestId
awsRequestId: awsRequestId,
})];

@@ -135,7 +134,7 @@ });

queryStringParameters: {
pageSize: "4"
pageSize: "4",
},
body: JSON.stringify({
message: "hello"
})
message: "hello",
}),
};

@@ -161,5 +160,5 @@ handler = codecHandler(mockSchema, mockHandler);

queryStringParameters: {
pageSize: "4"
pageSize: "4",
},
body: 5
body: 5,
};

@@ -182,5 +181,5 @@ handler = codecHandler(mockSchema, mockHandler);

queryStringParameters: {
pageSize: "not-a-number"
pageSize: "not-a-number",
},
body: false
body: false,
};

@@ -200,4 +199,4 @@ handler = codecHandler(mockSchema, mockHandler);

queryStringParameters: t.type({
pageNumber: NumberFromString
})
pageNumber: NumberFromString,
}),
},

@@ -215,4 +214,4 @@ // tslint:disable-next-line: no-reject

queryStringParameters: {
pageNumber: "4"
}
pageNumber: "4",
},
};

@@ -234,7 +233,7 @@ return [4 /*yield*/, brokenHandler(mockEvent, mockContext)];

pageNumber: NumberFromString,
pageSize: t.union([t.undefined, NumberFromString])
pageSize: t.union([t.undefined, NumberFromString]),
}),
headers: t.partial({
someHeader: NumberFromString
})
someHeader: NumberFromString,
}),
}, function (_a) {

@@ -249,4 +248,4 @@ var _b = _a.queryStringParameters, pageNumber = _b.pageNumber, pageSize = _b.pageSize, someHeader = _a.headers.someHeader;

pageSize: pageSize,
someHeader: someHeader
}
someHeader: someHeader,
},
})];

@@ -259,4 +258,4 @@ });

queryStringParameters: {
pageNumber: "4"
}
pageNumber: "4",
},
};

@@ -280,5 +279,5 @@ it("should succeed", function () { return __awaiter(void 0, void 0, void 0, function () {

queryStringParameters: {
pageNumber: "4"
pageNumber: "4",
},
headers: {}
headers: {},
};

@@ -302,5 +301,5 @@ it("should succeed", function () { return __awaiter(void 0, void 0, void 0, function () {

queryStringParameters: {
pageNumber: "4"
pageNumber: "4",
},
headers: null
headers: null,
};

@@ -325,7 +324,7 @@ it("should succeed", function () { return __awaiter(void 0, void 0, void 0, function () {

pageNumber: "4",
pageSize: "9"
pageSize: "9",
},
headers: {
someHeader: "6"
}
someHeader: "6",
},
};

@@ -350,4 +349,4 @@ it("should succeed", function () { return __awaiter(void 0, void 0, void 0, function () {

queryStringParameters: t.type({
pageNumber: NumberFromString
})
pageNumber: NumberFromString,
}),
}, function (params) { return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_a) {

@@ -359,7 +358,7 @@ return [2 /*return*/, params];

pageNumber: "4",
extraParameter: "hello"
extraParameter: "hello",
},
pathParameters: {
something: "true"
}
something: "true",
},
};

@@ -385,7 +384,7 @@ it("should not strip the extra parameters", function () { return __awaiter(void 0, void 0, void 0, function () {

t.type({
requiredHeader: NumberFromString
requiredHeader: NumberFromString,
}),
t.partial({
optionalHeader: t.union([BooleanFromString, t.null])
})
optionalHeader: t.union([BooleanFromString, t.null]),
}),
]),

@@ -395,4 +394,4 @@ multiValueHeaders: t.intersection([

t.partial({
optionalMVH: t.union([t.array(t.union([t.string, t.null])), t.null])
})
optionalMVH: t.union([t.array(t.union([t.string, t.null])), t.null]),
}),
]),

@@ -402,7 +401,7 @@ pathParameters: t.intersection([

requiredPathParamA: t.string,
requiredPathParamB: DateFromISOString
requiredPathParamB: DateFromISOString,
}),
t.partial({
optionalPathParam: NumberFromString
})
optionalPathParam: NumberFromString,
}),
]),

@@ -412,27 +411,30 @@ queryStringParameters: t.intersection([

requiredQueryStringA: t.string,
requiredQueryStringB: jsonFromStringCodec.pipe(t.array(t.number))
requiredQueryStringB: jsonFromStringCodec.pipe(t.array(t.number)),
}),
t.partial({
optionalQueryString: t.union([t.string, t.null])
})
optionalQueryString: t.union([t.string, t.null]),
}),
]),
multiValueQueryStringParameters: t.intersection([
t.type({
requiredMVQueryString: t.array(BooleanFromString)
requiredMVQueryString: t.array(BooleanFromString),
}),
t.partial({
optionalMVQueryString: t.union([t.array(jsonFromStringCodec), t.null])
})
optionalMVQueryString: t.union([
t.array(jsonFromStringCodec),
t.null,
]),
}),
]),
stageVariables: t.intersection([
t.type({
requiredStageVariable: t.string
requiredStageVariable: t.string,
}),
t.partial({
optionalStageVariable: t.union([jsonFromStringCodec, t.null])
})
optionalStageVariable: t.union([jsonFromStringCodec, t.null]),
}),
]),
body: t.type({
some: t.string
})
some: t.string,
}),
};

@@ -460,3 +462,3 @@ var mockHandler = codecHandler(mockSchema, function (_a, _b) {

body: body,
awsRequestId: awsRequestId
awsRequestId: awsRequestId,
})];

@@ -474,3 +476,3 @@ });

requiredHeader: "123",
optionalHeader: "false"
optionalHeader: "false",
},

@@ -480,5 +482,5 @@ multiValueHeaders: {

new Date(0).toISOString(),
new Date(100000).toUTCString()
new Date(100000).toUTCString(),
],
optionalMVH: ["abc", null, "def", null, null]
optionalMVH: ["abc", null, "def", null, null],
},

@@ -488,3 +490,3 @@ pathParameters: {

requiredPathParamB: new Date(999999).toISOString(),
optionalPathParam: "321.123"
optionalPathParam: "321.123",
},

@@ -494,3 +496,3 @@ queryStringParameters: {

requiredQueryStringB: JSON.stringify([1, 2, 3]),
optionalQueryString: "123abc"
optionalQueryString: "123abc",
},

@@ -501,12 +503,12 @@ multiValueQueryStringParameters: {

JSON.stringify({ a: true }),
JSON.stringify(false)
]
JSON.stringify(false),
],
},
stageVariables: {
requiredStageVariable: "asdf",
optionalStageVariable: JSON.stringify({ a: { b: { c: 4 } } })
optionalStageVariable: JSON.stringify({ a: { b: { c: 4 } } }),
},
body: JSON.stringify({
some: "string"
})
some: "string",
}),
};

@@ -525,8 +527,8 @@ return [4 /*yield*/, mockHandler(mockEvent, mockContext)];

var strictCodecHandler = configureWrapper({
strict: true
strict: true,
});
var strictHandler = strictCodecHandler({
queryStringParameters: t.type({
pageNumber: NumberFromString
})
pageNumber: NumberFromString,
}),
}, function (params, context) { return __awaiter(void 0, void 0, void 0, function () {

@@ -536,3 +538,3 @@ return __generator(this, function (_a) {

params: params,
context: context
context: context,
})];

@@ -544,4 +546,4 @@ });

queryStringParameters: {
pageNumber: "4"
}
pageNumber: "4",
},
};

@@ -566,7 +568,7 @@ it("should succeed", function () { return __awaiter(void 0, void 0, void 0, function () {

pageNumber: "4",
extraParameter: "hello"
extraParameter: "hello",
},
pathParameters: {
something: "true"
}
something: "true",
},
};

@@ -594,4 +596,4 @@ it("should strip the extra parameters", function () { return __awaiter(void 0, void 0, void 0, function () {

result: result,
custom: true
})
custom: true,
}),
}); },

@@ -602,4 +604,4 @@ unhandledErrorHandler: function (e) { return ({

oops: JSON.stringify(e),
custom: true
})
custom: true,
}),
}); },

@@ -610,10 +612,10 @@ validationErrorHandler: function (e) { return ({

error: e,
custom: true
})
}); }
custom: true,
}),
}); },
});
var handler = customCodecHandler({
queryStringParameters: t.type({
pageNumber: NumberFromString
})
pageNumber: NumberFromString,
}),
}, function (_a, _b) {

@@ -627,5 +629,5 @@ var pageNumber = _a.queryStringParameters.pageNumber;

params: {
pageNumber: pageNumber
pageNumber: pageNumber,
},
awsRequestId: awsRequestId
awsRequestId: awsRequestId,
})];

@@ -643,7 +645,7 @@ });

queryStringParameters: {
pageNumber: "4"
pageNumber: "4",
},
body: JSON.stringify({
message: "hello"
})
message: "hello",
}),
};

@@ -668,5 +670,5 @@ return [4 /*yield*/, handler(mockEvent, mockContext)];

queryStringParameters: {
pageSize: "4"
pageSize: "4",
},
body: 5
body: 5,
};

@@ -688,5 +690,5 @@ return [4 /*yield*/, handler(mockEvent, mockContext)];

queryStringParameters: {
pageSize: "string"
pageSize: "string",
},
body: false
body: false,
};

@@ -705,4 +707,4 @@ return [4 /*yield*/, handler(mockEvent, mockContext)];

queryStringParameters: t.type({
pageNumber: NumberFromString
})
pageNumber: NumberFromString,
}),
},

@@ -720,4 +722,4 @@ // tslint:disable-next-line: no-reject

queryStringParameters: {
pageNumber: "4"
}
pageNumber: "4",
},
};

@@ -724,0 +726,0 @@ return [4 /*yield*/, brokenHandler(mockEvent, mockContext)];

@@ -10,3 +10,3 @@ import { removeEmpty } from "../utils";

e: false,
f: {}
f: {},
};

@@ -18,3 +18,3 @@ it("should filter out keys with null values", function () {

e: false,
f: {}
f: {},
});

@@ -28,3 +28,3 @@ });

e: false,
f: {}
f: {},
};

@@ -31,0 +31,0 @@ it("should leave the payload untouched", function () {

@@ -9,4 +9,4 @@ import { left } from "fp-ts/lib/Either";

body: JSON.stringify({
error: PathReporter.report(left(e)).join(", ")
})
error: PathReporter.report(left(e)).join(", "),
}),
}); };

@@ -19,4 +19,4 @@ /**

body: JSON.stringify({
error: "Unhandled error: " + JSON.stringify(e)
})
error: "Unhandled error: " + JSON.stringify(e),
}),
}); };

@@ -28,3 +28,3 @@ /**

statusCode: 200,
body: JSON.stringify(e)
body: JSON.stringify(e),
}); };
import { APIGatewayProxyEvent, APIGatewayProxyResult, Context } from "aws-lambda";
import * as t from "io-ts";
import { HandlerConfig, ValueMap } from "./types";
import { HandlerConfig, HandlerFunction, ValueMap } from "./types";
export * from "./types";

@@ -5,0 +5,0 @@ /**

@@ -51,4 +51,5 @@ var __assign = (this && this.__assign) || function () {

import { jsonFromStringCodec } from "./codecs";
import { defaultSuccessHandler, defaultUnhandledErrorHandler, defaultValidationErrorHandler } from "./default-handlers";
import { defaultSuccessHandler, defaultUnhandledErrorHandler, defaultValidationErrorHandler, } from "./default-handlers";
import { removeEmpty, typedKeys } from "./utils";
export * from "./types";
var defaultConfig = {

@@ -58,3 +59,3 @@ validationErrorHandler: defaultValidationErrorHandler,

successHandler: defaultSuccessHandler,
strict: false
strict: false,
};

@@ -68,3 +69,3 @@ var defaultEvent = {

stageVariables: {},
body: null
body: null,
};

@@ -91,3 +92,3 @@ var callbackUnsupportedMessage = "The callback handler form is not supported. Please return a promise from your handler function. \n" +

// type-coverage:ignore-next-line - io-ts types use any
body: jsonFromStringCodec.pipe(body)
body: jsonFromStringCodec.pipe(body),
}); };

@@ -109,3 +110,3 @@ mergedCodecs = codecMaps.body === undefined

requestContext: event.requestContext,
resource: event.resource
resource: event.resource,
};

@@ -112,0 +113,0 @@ result = handlerFn(__assign(__assign({}, passableParameters), decoded.right), context, function () {

@@ -9,3 +9,3 @@ /**

export var jsonParser = {
parse: JSON.parse
parse: JSON.parse,
};

@@ -22,3 +22,3 @@ "use strict";

["dfsjlsf"],
['{ "hello": 4 ']
['{ "hello": 4 '],
]).test("fails when decoding [%p]", function (input) {

@@ -25,0 +25,0 @@ expect.assertions(2);

@@ -33,3 +33,3 @@ "use strict";

expect(default_handlers_1.defaultSuccessHandler({
some: "object"
some: "object",
})).toMatchSnapshot();

@@ -36,0 +36,0 @@ });

@@ -56,3 +56,3 @@ "use strict";

cognitoIdentityId: "mock-identity-id",
cognitoIdentityPoolId: "mock-identity-pool-id"
cognitoIdentityPoolId: "mock-identity-pool-id",
},

@@ -65,3 +65,3 @@ clientContext: {

appVersionCode: "string",
appPackageName: "string"
appPackageName: "string",
},

@@ -74,4 +74,4 @@ Custom: "some custom",

model: "string",
locale: "string"
}
locale: "string",
},
},

@@ -83,4 +83,3 @@ getRemainingTimeInMillis: function () { return 60000; },

// type-coverage:ignore-next-line
succeed: function (_messageOrObject) { }
// tslint:enable: no-empty no-any
succeed: function (_messageOrObject) { },
};

@@ -108,7 +107,7 @@ // tslint:disable: no-duplicate-string no-identical-functions no-big-function

queryStringParameters: t.type({
pageSize: NumberFromString_1.NumberFromString
pageSize: NumberFromString_1.NumberFromString,
}),
body: t.type({
message: t.string
})
message: t.string,
}),
};

@@ -123,3 +122,3 @@ var mockHandler = function (_a, _b) {

body: body,
awsRequestId: awsRequestId
awsRequestId: awsRequestId,
})];

@@ -137,7 +136,7 @@ });

queryStringParameters: {
pageSize: "4"
pageSize: "4",
},
body: JSON.stringify({
message: "hello"
})
message: "hello",
}),
};

@@ -163,5 +162,5 @@ handler = codecHandler(mockSchema, mockHandler);

queryStringParameters: {
pageSize: "4"
pageSize: "4",
},
body: 5
body: 5,
};

@@ -184,5 +183,5 @@ handler = codecHandler(mockSchema, mockHandler);

queryStringParameters: {
pageSize: "not-a-number"
pageSize: "not-a-number",
},
body: false
body: false,
};

@@ -202,4 +201,4 @@ handler = codecHandler(mockSchema, mockHandler);

queryStringParameters: t.type({
pageNumber: NumberFromString_1.NumberFromString
})
pageNumber: NumberFromString_1.NumberFromString,
}),
},

@@ -217,4 +216,4 @@ // tslint:disable-next-line: no-reject

queryStringParameters: {
pageNumber: "4"
}
pageNumber: "4",
},
};

@@ -236,7 +235,7 @@ return [4 /*yield*/, brokenHandler(mockEvent, mockContext)];

pageNumber: NumberFromString_1.NumberFromString,
pageSize: t.union([t.undefined, NumberFromString_1.NumberFromString])
pageSize: t.union([t.undefined, NumberFromString_1.NumberFromString]),
}),
headers: t.partial({
someHeader: NumberFromString_1.NumberFromString
})
someHeader: NumberFromString_1.NumberFromString,
}),
}, function (_a) {

@@ -251,4 +250,4 @@ var _b = _a.queryStringParameters, pageNumber = _b.pageNumber, pageSize = _b.pageSize, someHeader = _a.headers.someHeader;

pageSize: pageSize,
someHeader: someHeader
}
someHeader: someHeader,
},
})];

@@ -261,4 +260,4 @@ });

queryStringParameters: {
pageNumber: "4"
}
pageNumber: "4",
},
};

@@ -282,5 +281,5 @@ it("should succeed", function () { return __awaiter(void 0, void 0, void 0, function () {

queryStringParameters: {
pageNumber: "4"
pageNumber: "4",
},
headers: {}
headers: {},
};

@@ -304,5 +303,5 @@ it("should succeed", function () { return __awaiter(void 0, void 0, void 0, function () {

queryStringParameters: {
pageNumber: "4"
pageNumber: "4",
},
headers: null
headers: null,
};

@@ -327,7 +326,7 @@ it("should succeed", function () { return __awaiter(void 0, void 0, void 0, function () {

pageNumber: "4",
pageSize: "9"
pageSize: "9",
},
headers: {
someHeader: "6"
}
someHeader: "6",
},
};

@@ -352,4 +351,4 @@ it("should succeed", function () { return __awaiter(void 0, void 0, void 0, function () {

queryStringParameters: t.type({
pageNumber: NumberFromString_1.NumberFromString
})
pageNumber: NumberFromString_1.NumberFromString,
}),
}, function (params) { return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_a) {

@@ -361,7 +360,7 @@ return [2 /*return*/, params];

pageNumber: "4",
extraParameter: "hello"
extraParameter: "hello",
},
pathParameters: {
something: "true"
}
something: "true",
},
};

@@ -387,7 +386,7 @@ it("should not strip the extra parameters", function () { return __awaiter(void 0, void 0, void 0, function () {

t.type({
requiredHeader: NumberFromString_1.NumberFromString
requiredHeader: NumberFromString_1.NumberFromString,
}),
t.partial({
optionalHeader: t.union([BooleanFromString_1.BooleanFromString, t.null])
})
optionalHeader: t.union([BooleanFromString_1.BooleanFromString, t.null]),
}),
]),

@@ -397,4 +396,4 @@ multiValueHeaders: t.intersection([

t.partial({
optionalMVH: t.union([t.array(t.union([t.string, t.null])), t.null])
})
optionalMVH: t.union([t.array(t.union([t.string, t.null])), t.null]),
}),
]),

@@ -404,7 +403,7 @@ pathParameters: t.intersection([

requiredPathParamA: t.string,
requiredPathParamB: DateFromISOString_1.DateFromISOString
requiredPathParamB: DateFromISOString_1.DateFromISOString,
}),
t.partial({
optionalPathParam: NumberFromString_1.NumberFromString
})
optionalPathParam: NumberFromString_1.NumberFromString,
}),
]),

@@ -414,27 +413,30 @@ queryStringParameters: t.intersection([

requiredQueryStringA: t.string,
requiredQueryStringB: codecs_1.jsonFromStringCodec.pipe(t.array(t.number))
requiredQueryStringB: codecs_1.jsonFromStringCodec.pipe(t.array(t.number)),
}),
t.partial({
optionalQueryString: t.union([t.string, t.null])
})
optionalQueryString: t.union([t.string, t.null]),
}),
]),
multiValueQueryStringParameters: t.intersection([
t.type({
requiredMVQueryString: t.array(BooleanFromString_1.BooleanFromString)
requiredMVQueryString: t.array(BooleanFromString_1.BooleanFromString),
}),
t.partial({
optionalMVQueryString: t.union([t.array(codecs_1.jsonFromStringCodec), t.null])
})
optionalMVQueryString: t.union([
t.array(codecs_1.jsonFromStringCodec),
t.null,
]),
}),
]),
stageVariables: t.intersection([
t.type({
requiredStageVariable: t.string
requiredStageVariable: t.string,
}),
t.partial({
optionalStageVariable: t.union([codecs_1.jsonFromStringCodec, t.null])
})
optionalStageVariable: t.union([codecs_1.jsonFromStringCodec, t.null]),
}),
]),
body: t.type({
some: t.string
})
some: t.string,
}),
};

@@ -462,3 +464,3 @@ var mockHandler = codecHandler(mockSchema, function (_a, _b) {

body: body,
awsRequestId: awsRequestId
awsRequestId: awsRequestId,
})];

@@ -476,3 +478,3 @@ });

requiredHeader: "123",
optionalHeader: "false"
optionalHeader: "false",
},

@@ -482,5 +484,5 @@ multiValueHeaders: {

new Date(0).toISOString(),
new Date(100000).toUTCString()
new Date(100000).toUTCString(),
],
optionalMVH: ["abc", null, "def", null, null]
optionalMVH: ["abc", null, "def", null, null],
},

@@ -490,3 +492,3 @@ pathParameters: {

requiredPathParamB: new Date(999999).toISOString(),
optionalPathParam: "321.123"
optionalPathParam: "321.123",
},

@@ -496,3 +498,3 @@ queryStringParameters: {

requiredQueryStringB: JSON.stringify([1, 2, 3]),
optionalQueryString: "123abc"
optionalQueryString: "123abc",
},

@@ -503,12 +505,12 @@ multiValueQueryStringParameters: {

JSON.stringify({ a: true }),
JSON.stringify(false)
]
JSON.stringify(false),
],
},
stageVariables: {
requiredStageVariable: "asdf",
optionalStageVariable: JSON.stringify({ a: { b: { c: 4 } } })
optionalStageVariable: JSON.stringify({ a: { b: { c: 4 } } }),
},
body: JSON.stringify({
some: "string"
})
some: "string",
}),
};

@@ -527,8 +529,8 @@ return [4 /*yield*/, mockHandler(mockEvent, mockContext)];

var strictCodecHandler = __1.configureWrapper({
strict: true
strict: true,
});
var strictHandler = strictCodecHandler({
queryStringParameters: t.type({
pageNumber: NumberFromString_1.NumberFromString
})
pageNumber: NumberFromString_1.NumberFromString,
}),
}, function (params, context) { return __awaiter(void 0, void 0, void 0, function () {

@@ -538,3 +540,3 @@ return __generator(this, function (_a) {

params: params,
context: context
context: context,
})];

@@ -546,4 +548,4 @@ });

queryStringParameters: {
pageNumber: "4"
}
pageNumber: "4",
},
};

@@ -568,7 +570,7 @@ it("should succeed", function () { return __awaiter(void 0, void 0, void 0, function () {

pageNumber: "4",
extraParameter: "hello"
extraParameter: "hello",
},
pathParameters: {
something: "true"
}
something: "true",
},
};

@@ -596,4 +598,4 @@ it("should strip the extra parameters", function () { return __awaiter(void 0, void 0, void 0, function () {

result: result,
custom: true
})
custom: true,
}),
}); },

@@ -604,4 +606,4 @@ unhandledErrorHandler: function (e) { return ({

oops: JSON.stringify(e),
custom: true
})
custom: true,
}),
}); },

@@ -612,10 +614,10 @@ validationErrorHandler: function (e) { return ({

error: e,
custom: true
})
}); }
custom: true,
}),
}); },
});
var handler = customCodecHandler({
queryStringParameters: t.type({
pageNumber: NumberFromString_1.NumberFromString
})
pageNumber: NumberFromString_1.NumberFromString,
}),
}, function (_a, _b) {

@@ -629,5 +631,5 @@ var pageNumber = _a.queryStringParameters.pageNumber;

params: {
pageNumber: pageNumber
pageNumber: pageNumber,
},
awsRequestId: awsRequestId
awsRequestId: awsRequestId,
})];

@@ -645,7 +647,7 @@ });

queryStringParameters: {
pageNumber: "4"
pageNumber: "4",
},
body: JSON.stringify({
message: "hello"
})
message: "hello",
}),
};

@@ -670,5 +672,5 @@ return [4 /*yield*/, handler(mockEvent, mockContext)];

queryStringParameters: {
pageSize: "4"
pageSize: "4",
},
body: 5
body: 5,
};

@@ -690,5 +692,5 @@ return [4 /*yield*/, handler(mockEvent, mockContext)];

queryStringParameters: {
pageSize: "string"
pageSize: "string",
},
body: false
body: false,
};

@@ -707,4 +709,4 @@ return [4 /*yield*/, handler(mockEvent, mockContext)];

queryStringParameters: t.type({
pageNumber: NumberFromString_1.NumberFromString
})
pageNumber: NumberFromString_1.NumberFromString,
}),
},

@@ -722,4 +724,4 @@ // tslint:disable-next-line: no-reject

queryStringParameters: {
pageNumber: "4"
}
pageNumber: "4",
},
};

@@ -726,0 +728,0 @@ return [4 /*yield*/, brokenHandler(mockEvent, mockContext)];

@@ -12,3 +12,3 @@ "use strict";

e: false,
f: {}
f: {},
};

@@ -20,3 +20,3 @@ it("should filter out keys with null values", function () {

e: false,
f: {}
f: {},
});

@@ -30,3 +30,3 @@ });

e: false,
f: {}
f: {},
};

@@ -33,0 +33,0 @@ it("should leave the payload untouched", function () {

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.jsonFromStringCodec = void 0;
var Either_1 = require("fp-ts/lib/Either");

@@ -4,0 +5,0 @@ var t = require("io-ts");

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.defaultSuccessHandler = exports.defaultUnhandledErrorHandler = exports.defaultValidationErrorHandler = void 0;
var Either_1 = require("fp-ts/lib/Either");

@@ -11,4 +12,4 @@ var PathReporter_1 = require("io-ts/lib/PathReporter");

body: JSON.stringify({
error: PathReporter_1.PathReporter.report(Either_1.left(e)).join(", ")
})
error: PathReporter_1.PathReporter.report(Either_1.left(e)).join(", "),
}),
}); };

@@ -21,4 +22,4 @@ /**

body: JSON.stringify({
error: "Unhandled error: " + JSON.stringify(e)
})
error: "Unhandled error: " + JSON.stringify(e),
}),
}); };

@@ -30,3 +31,3 @@ /**

statusCode: 200,
body: JSON.stringify(e)
body: JSON.stringify(e),
}); };
import { APIGatewayProxyEvent, APIGatewayProxyResult, Context } from "aws-lambda";
import * as t from "io-ts";
import { HandlerConfig, ValueMap } from "./types";
import { HandlerConfig, HandlerFunction, ValueMap } from "./types";
export * from "./types";

@@ -5,0 +5,0 @@ /**

@@ -13,2 +13,12 @@ "use strict";

};
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __exportStar = (this && this.__exportStar) || function(m, exports) {
for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p);
};
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {

@@ -51,2 +61,3 @@ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }

Object.defineProperty(exports, "__esModule", { value: true });
exports.configureWrapper = void 0;
var Either_1 = require("fp-ts/lib/Either");

@@ -57,2 +68,3 @@ var t = require("io-ts");

var utils_1 = require("./utils");
__exportStar(require("./types"), exports);
var defaultConfig = {

@@ -62,3 +74,3 @@ validationErrorHandler: default_handlers_1.defaultValidationErrorHandler,

successHandler: default_handlers_1.defaultSuccessHandler,
strict: false
strict: false,
};

@@ -72,3 +84,3 @@ var defaultEvent = {

stageVariables: {},
body: null
body: null,
};

@@ -95,3 +107,3 @@ var callbackUnsupportedMessage = "The callback handler form is not supported. Please return a promise from your handler function. \n" +

// type-coverage:ignore-next-line - io-ts types use any
body: codecs_1.jsonFromStringCodec.pipe(body)
body: codecs_1.jsonFromStringCodec.pipe(body),
}); };

@@ -113,3 +125,3 @@ mergedCodecs = codecMaps.body === undefined

requestContext: event.requestContext,
resource: event.resource
resource: event.resource,
};

@@ -116,0 +128,0 @@ result = handlerFn(__assign(__assign({}, passableParameters), decoded.right), context, function () {

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.jsonParser = void 0;
/**

@@ -11,3 +12,3 @@ * A simple JSON parser.

exports.jsonParser = {
parse: JSON.parse
parse: JSON.parse,
};

@@ -14,2 +14,3 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.typedKeys = exports.removeEmpty = void 0;
/**

@@ -16,0 +17,0 @@ * Remove all keys with null values

{
"name": "io-ts-serverless-handler",
"version": "2.1.1",
"version": "2.1.2",
"description": "A simple wrapper for Serverless Framework HTTP handlers to remove the boilerplate of using io-ts codecs to validate and extract request parameters",

@@ -24,3 +24,3 @@ "main": "lib/index.js",

"lint-fix": "tslint --fix -p tsconfig.json -c tslint.json",
"format-check": "prettier-check src/**/*",
"format-check": "prettier --check '{src,test}/**/*.{ts,tsx}'",
"type-coverage": "type-coverage --strict --detail --ignore-catch",

@@ -36,3 +36,3 @@ "format": "prettier --write '{src,test}/**/*.{ts,tsx}'",

"dependencies": {
"type-fest": "^0.12.0"
"type-fest": "^0.15.1"
},

@@ -39,0 +39,0 @@ "typeCoverage": {

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc