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

lambda-serverless-api

Package Overview
Dependencies
Maintainers
1
Versions
396
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

lambda-serverless-api - npm Package Compare versions

Comparing version 10.1.0 to 10.1.1

24

lib/index.js

@@ -9,16 +9,16 @@ import Joi from 'joi-strict';

import {
ApiError as ApiError_,
ApiErrorClass as ApiErrorClass_
ApiErrorFn,
ApiError as ApiErrorClass_
} from './response/api-error.js';
import {
ApiResponse as ApiResponse_,
ApiResponseClass as ApiResponseClass_
ApiResponseFn,
ApiResponse as ApiResponseClass_
} from './response/api-response.js';
import {
JsonResponse as JsonResponse_,
JsonResponseClass as JsonResponseClass_
JsonResponseFn,
JsonResponse as JsonResponseClass_
} from './response/json-response.js';
import {
BinaryResponse as BinaryResponse_,
BinaryResponseClass as BinaryResponseClass_
BinaryResponseFn,
BinaryResponse as BinaryResponseClass_
} from './response/binary-response.js';

@@ -53,9 +53,9 @@

export const ApiError = ApiError_;
export const ApiError = ApiErrorFn;
export const ApiErrorClass = ApiErrorClass_;
export const ApiResponse = ApiResponse_;
export const ApiResponse = ApiResponseFn;
export const ApiResponseClass = ApiResponseClass_;
export const JsonResponse = JsonResponse_;
export const JsonResponse = JsonResponseFn;
export const JsonResponseClass = JsonResponseClass_;
export const BinaryResponse = BinaryResponse_;
export const BinaryResponse = BinaryResponseFn;
export const BinaryResponseClass = BinaryResponseClass_;

@@ -62,0 +62,0 @@

@@ -5,3 +5,3 @@ import get from 'lodash.get';

import * as apiGateway from './api-gateway.js';
import { ApiError } from '../response/api-error.js';
import { ApiErrorFn } from '../response/api-error.js';

@@ -43,3 +43,3 @@ export const Router = ({ module }) => {

if (resp === null) {
throw ApiError('Method / Route not allowed', 403);
throw ApiErrorFn('Method / Route not allowed', 403);
}

@@ -46,0 +46,0 @@ return resp;

import assert from 'assert';
import get from 'lodash.get';
import { ApiError } from '../response/api-error.js';
import { ApiErrorFn } from '../response/api-error.js';

@@ -48,10 +48,10 @@ const positionMapping = {

if (this.required) {
throw ApiError(`Required ${this.position}-Parameter "${this.name}" missing.`, 400, 99002);
throw ApiErrorFn(`Required ${this.position}-Parameter "${this.name}" missing.`, 400, 99002);
}
} else if (result === null) {
if (this.nullable !== true) {
throw ApiError(`Non-nullable ${this.position}-Parameter "${this.name}" is null.`, 400, 99006);
throw ApiErrorFn(`Non-nullable ${this.position}-Parameter "${this.name}" is null.`, 400, 99006);
}
} else if (!this.validate(result)) {
throw ApiError(`Invalid Value for ${this.position}-Parameter "${this.name}" provided.`, 400, 99003, {
throw ApiErrorFn(`Invalid Value for ${this.position}-Parameter "${this.name}" provided.`, 400, 99003, {
value: result

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

@@ -5,4 +5,4 @@ import get from 'lodash.get';

import { Plugin } from '../plugin.js';
import { ApiError } from '../response/api-error.js';
import { ApiResponse } from '../response/api-response.js';
import { ApiErrorFn } from '../response/api-error.js';
import { ApiResponseFn } from '../response/api-response.js';

@@ -48,3 +48,3 @@ const compile = (staticOrFn, kwargs) => (typeof staticOrFn === 'function' ? staticOrFn(kwargs) : staticOrFn);

].some((h) => h === undefined)) {
throw ApiError('Required header missing', 403);
throw ApiErrorFn('Required header missing', 403);
}

@@ -54,6 +54,6 @@

if (!allowedOrigins.includes(origin) && !allowedOrigins.includes('*')) {
throw ApiError('Origin not allowed', 403);
throw ApiErrorFn('Origin not allowed', 403);
}
if (!router.recognize(accessControlRequestMethod, get(event, 'path', ''))) {
throw ApiError('Method not allowed', 403);
throw ApiErrorFn('Method not allowed', 403);
}

@@ -68,6 +68,6 @@ const allowedHeaders = [

.trim().toLowerCase()).every((h) => allowedHeaders.includes(h))) {
throw ApiError('Header not allowed', 403);
throw ApiErrorFn('Header not allowed', 403);
}
return ApiResponse('', 200, {
return ApiResponseFn('', 200, {
'Access-Control-Allow-Origin': origin,

@@ -74,0 +74,0 @@ 'Access-Control-Allow-Headers': allowedHeaders.join(','),

import Joi from 'joi-strict';
import { Plugin } from '../plugin.js';
import { ApiError } from '../response/api-error.js';
import { ApiErrorFn } from '../response/api-error.js';
import objectAsLowerCase from '../util/object-rekey-lower-case.js';

@@ -35,3 +35,3 @@

} catch (e) {
throw ApiError('Invalid Json Body detected.', 400, 99001, {
throw ApiErrorFn('Invalid Json Body detected.', 400, 99001, {
value: event.body

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

@@ -5,3 +5,3 @@ import assert from 'assert';

import { ApiError } from '../response/api-error.js';
import { ApiErrorFn } from '../response/api-error.js';
import { Plugin } from '../plugin.js';

@@ -70,3 +70,3 @@ import Limiter from '../util/limiter.js';

} catch (e) {
const err = ApiError('Rate limit exceeded.', 429);
const err = ApiErrorFn('Rate limit exceeded.', 429);
err.headers = {

@@ -73,0 +73,0 @@ 'X-Rate-Limit-Reset': 60 - new Date().getSeconds()

import get from 'lodash.get';
import Joi from 'joi-strict';
import { Plugin } from '../plugin.js';
import { ApiResponse } from '../response/api-response.js';
import { ApiResponseFn } from '../response/api-response.js';

@@ -28,5 +28,5 @@ class Robots extends Plugin {

}
return ApiResponse(this.response);
return ApiResponseFn(this.response);
}
}
export default Robots;

@@ -7,3 +7,3 @@ import get from 'lodash.get';

import { Plugin } from '../plugin.js';
import { ApiError } from '../response/api-error.js';
import { ApiErrorFn } from '../response/api-error.js';

@@ -74,3 +74,3 @@ class Validator extends Plugin {

].join('\n'));
throw ApiError('Server Configuration Error.', 400, 99006);
throw ApiErrorFn('Server Configuration Error.', 400, 99006);
}

@@ -84,3 +84,3 @@ }

if (invalidQsParams.length !== 0) {
throw ApiError('Invalid Query Param(s) detected.', 400, 99004, {
throw ApiErrorFn('Invalid Query Param(s) detected.', 400, 99004, {
value: invalidQsParams

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

if (invalidJsonParams.length !== 0) {
throw ApiError('Invalid Json Body Param(s) detected.', 400, 99005, {
throw ApiErrorFn('Invalid Json Body Param(s) detected.', 400, 99005, {
value: invalidJsonParams

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

@@ -8,3 +8,3 @@ import get from 'lodash.get';

import { Plugin } from '../plugin.js';
import { ApiError } from '../response/api-error.js';
import { ApiErrorFn } from '../response/api-error.js';
import { VERSION_REGEX } from '../resources/format.js';

@@ -64,13 +64,13 @@ import Enum from '../param/enum.js';

if (apiVersion === undefined) {
throw ApiError(`Required header "${apiVersionHeader}" missing`, 403);
throw ApiErrorFn(`Required header "${apiVersionHeader}" missing`, 403);
}
if (!VERSION_REGEX.test(apiVersion)) {
throw ApiError(`Invalid value "${apiVersion}" for header "${apiVersionHeader}" provided`, 403);
throw ApiErrorFn(`Invalid value "${apiVersion}" for header "${apiVersionHeader}" provided`, 403);
}
if (versions[apiVersion] === undefined) {
throw ApiError(`Unknown version "${apiVersion}" for header "${apiVersionHeader}" provided`, 403);
throw ApiErrorFn(`Unknown version "${apiVersion}" for header "${apiVersionHeader}" provided`, 403);
}
const deprecated = get(request, 'options.deprecated');
if (deprecated !== undefined && pv.test(`${deprecated} <= ${apiVersion}`)) {
throw ApiError(`Endpoint deprecated since version "${deprecated}"`, 403);
throw ApiErrorFn(`Endpoint deprecated since version "${deprecated}"`, 403);
}

@@ -81,3 +81,3 @@ const apiVersionMeta = versions[apiVersion];

if (forceSunset === true) {
throw ApiError(`Version "${apiVersion}" is sunset as of "${apiVersionMeta.sunsetDate.toUTCString()}"`, 403);
throw ApiErrorFn(`Version "${apiVersion}" is sunset as of "${apiVersionMeta.sunsetDate.toUTCString()}"`, 403);
}

@@ -84,0 +84,0 @@ }

@@ -1,5 +0,5 @@

export class ApiErrorClass extends Error {
export class ApiError extends Error {
constructor(message, statusCode = 400, messageId = undefined, context = undefined) {
super(message);
this.name = 'ApiError';
this.name = this.constructor.name;
Error.captureStackTrace(this, this.constructor);

@@ -15,2 +15,2 @@ this.statusCode = statusCode;

}
export const ApiError = (...args) => new ApiErrorClass(...args);
export const ApiErrorFn = (...args) => new ApiError(...args);

@@ -1,2 +0,2 @@

export class ApiResponseClass {
export class ApiResponse {
constructor(payload, statusCode = 200, headers = {}) {

@@ -15,2 +15,2 @@ this.payload = payload;

}
export const ApiResponse = (...args) => new ApiResponseClass(...args);
export const ApiResponseFn = (...args) => new ApiResponse(...args);

@@ -1,4 +0,4 @@

import { ApiResponseClass } from './api-response.js';
import { ApiResponse } from './api-response.js';
export class BinaryResponseClass extends ApiResponseClass {
export class BinaryResponse extends ApiResponse {
constructor(...args) {

@@ -9,2 +9,2 @@ super(...args);

}
export const BinaryResponse = (...args) => new BinaryResponseClass(...args);
export const BinaryResponseFn = (...args) => new BinaryResponse(...args);

@@ -1,4 +0,4 @@

import { ApiResponseClass } from './api-response.js';
import { ApiResponse } from './api-response.js';
export class JsonResponseClass extends ApiResponseClass {
export class JsonResponse extends ApiResponse {
constructor(...args) {

@@ -9,2 +9,2 @@ super(...args);

}
export const JsonResponse = (...args) => new JsonResponseClass(...args);
export const JsonResponseFn = (...args) => new JsonResponse(...args);

@@ -42,3 +42,3 @@ {

},
"version": "10.1.0",
"version": "10.1.1",
"scripts": {

@@ -45,0 +45,0 @@ "clean": "rm -rf lib",

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