New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@campkit/core

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

@campkit/core - npm Package Compare versions

Comparing version 0.0.5 to 0.0.6

188

dist/core.cjs.development.js

@@ -6,21 +6,16 @@ 'use strict';

var Logger =
/*#__PURE__*/
function () {
function Logger(context) {
class Logger {
constructor(context) {
this.context = context;
}
var _proto = Logger.prototype;
_proto.log = function log(message, message2) {
log(message, message2) {
console.log(' ');
console.log("---- " + this.context + " -----");
console.log(`---- ${this.context} -----`);
console.log(' ');
console.log(message, message2 || '');
console.log(' ');
};
}
return Logger;
}();
}

@@ -105,10 +100,4 @@ // export enum RequestMethod {

function _inheritsLoose(subClass, superClass) {
subClass.prototype = Object.create(superClass.prototype);
subClass.prototype.constructor = subClass;
subClass.__proto__ = superClass;
}
function App(options) {
return function (target) {
return target => {
// logger.log({ options, target });

@@ -126,17 +115,15 @@ // const appName = options.name;

*/
var CampkitApplication =
/*#__PURE__*/
function () {
function CampkitApplication(options) {
class CampkitApplication {
constructor(options) {
this.appInstance = options.module;
}
var _proto = CampkitApplication.prototype;
run(requestOptions) {
const {
appInstance
} = this;
const appInstanceMetadata = getAppMetadata(appInstance);
const appClass = new appInstance(appInstanceMetadata);
const appOutput = appClass.run(requestOptions);
_proto.run = function run(requestOptions) {
var appInstance = this.appInstance;
var appInstanceMetadata = getAppMetadata(appInstance);
var appClass = new appInstance(appInstanceMetadata);
var appOutput = appClass.run(requestOptions);
if (!appOutput) {

@@ -147,11 +134,9 @@ throw Error('no app output');

return appOutput;
};
}
_proto.handleResponse = function handleResponse(response, isError) {
if (isError === void 0) {
isError = false;
}
handleResponse(response, isError = false) {
const {
appInstance
} = this;
var appInstance = this.appInstance;
if (isError) {

@@ -162,38 +147,30 @@ return appInstance.onError(response);

return appInstance.onSuccess(response);
};
}
return CampkitApplication;
}();
}
var logger =
const logger =
/*#__PURE__*/
new Logger('AWSLambdaApplication');
var AWSLambdaApplication =
/*#__PURE__*/
function (_CampkitApplication) {
_inheritsLoose(AWSLambdaApplication, _CampkitApplication);
function AWSLambdaApplication(options) {
var _this;
_this = _CampkitApplication.call(this, {
class AWSLambdaApplication extends CampkitApplication {
constructor(options) {
super({
module: options.module
}) || this;
_this.event = options.httpAdapter.event;
_this.context = options.httpAdapter.context;
return _this;
});
this.event = options.httpAdapter.event;
this.context = options.httpAdapter.context;
}
var _proto = AWSLambdaApplication.prototype;
handleRequest() {
const {
event,
context
} = this;
_proto.handleRequest = function handleRequest() {
var event = this.event,
context = this.context;
try {
var requestOptions = mapApiGatewayEventToHttpRequest({
event: event,
context: context
const requestOptions = mapApiGatewayEventToHttpRequest({
event,
context
});
var out = this.run(requestOptions);
const out = this.run(requestOptions);

@@ -204,10 +181,9 @@ if (!out) {

var res = this.handleLambdaResponse(context, {
const res = this.handleLambdaResponse(context, {
body: out
});
return _CampkitApplication.prototype.handleResponse.call(this, res);
return super.handleResponse(res);
} catch (error) {
logger.log(error);
var _res = this.handleLambdaResponse(context, {
const res = this.handleLambdaResponse(context, {
statusCode: 502,

@@ -219,16 +195,14 @@ body: {

});
return _CampkitApplication.prototype.handleResponse.call(this, _res, true);
return super.handleResponse(res, true);
}
};
}
_proto.handleLambdaResponse = function handleLambdaResponse(_context, response) {
var _response$statusCode = response.statusCode,
statusCode = _response$statusCode === void 0 ? 200 : _response$statusCode,
_response$headers = response.headers,
headers = _response$headers === void 0 ? {} : _response$headers,
_response$body = response.body,
body = _response$body === void 0 ? {} : _response$body;
handleLambdaResponse(_context, response) {
const {
statusCode = 200,
headers = {},
body = {}
} = response;
return {
statusCode: statusCode,
statusCode,
headers: _extends({}, headers, {

@@ -239,11 +213,11 @@ 'x-campkit': true

};
};
}
return AWSLambdaApplication;
}(CampkitApplication);
}
function mapApiGatewayEventToHttpRequest(_ref) {
var event = _ref.event,
context = _ref.context;
var headers = Object.assign({
function mapApiGatewayEventToHttpRequest({
event,
context
}) {
const headers = Object.assign({
'Content-Length': 0

@@ -253,3 +227,3 @@ }, event.headers); // NOTE: API Gateway is not setting Content-Length header on requests even when they have a body

if (event.body && !headers['Content-Length']) {
var body = getEventBody(event);
const body = getEventBody(event);

@@ -261,3 +235,3 @@ if (Object.keys(body).length) {

var clonedEventWithoutBody = clone(event);
const clonedEventWithoutBody = clone(event);
delete clonedEventWithoutBody.body;

@@ -269,3 +243,3 @@ headers['x-apigateway-event'] = encodeURIComponent(JSON.stringify(clonedEventWithoutBody));

path: getPathWithQueryStringParams(event),
headers: headers,
headers,
body: getEventBody(event)

@@ -302,27 +276,18 @@ };

var CampkitFactoryStatic =
/*#__PURE__*/
function () {
function CampkitFactoryStatic() {}
var _proto = CampkitFactoryStatic.prototype;
_proto.create = function create(module, httpAdapter, options) {
if (options === void 0) {
options = {
provider: 'aws'
};
}
class CampkitFactoryStatic {
create(module, httpAdapter, options = {
provider: 'aws'
}) {
try {
var _options = options,
provider = _options.provider;
var isAWSLambda = provider === 'aws';
const {
provider
} = options;
const isAWSLambda = provider === 'aws';
if (isAWSLambda) {
var lambdaApp = new AWSLambdaApplication({
module: module,
httpAdapter: httpAdapter
const lambdaApp = new AWSLambdaApplication({
module,
httpAdapter
});
return Promise.resolve(lambdaApp.handleRequest());
return lambdaApp.handleRequest();
} else {

@@ -334,6 +299,5 @@ throw Error('currently only aws lambda events are supported');

}
};
}
return CampkitFactoryStatic;
}();
}
/**

@@ -344,3 +308,3 @@ * Use CampkitFactory to create an application instance.

var CampkitFactory =
const CampkitFactory =
/*#__PURE__*/

@@ -347,0 +311,0 @@ new CampkitFactoryStatic();

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

"use strict";require("reflect-metadata");var t,e,E=require("url"),n=function(){function t(t){this.context=t}return t.prototype.log=function(t,e){console.log(" "),console.log("---- "+this.context+" -----"),console.log(" "),console.log(t,e||""),console.log(" ")},t}();function r(){return(r=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var E=arguments[e];for(var n in E)Object.prototype.hasOwnProperty.call(E,n)&&(t[n]=E[n])}return t}).apply(this,arguments)}function o(t){return Reflect.getMetadata("app",t)}(t=exports.RequestMethod||(exports.RequestMethod={})).GET="GET",t.POST="POST",t.PUT="PUT",t.DELETE="DELETE",t.PATCH="PATCH",t.ALL="ALL",t.OPTIONS="OPTIONS",t.HEAD="HEAD",(e=exports.HttpStatus||(exports.HttpStatus={}))[e.CONTINUE=100]="CONTINUE",e[e.SWITCHING_PROTOCOLS=101]="SWITCHING_PROTOCOLS",e[e.PROCESSING=102]="PROCESSING",e[e.OK=200]="OK",e[e.CREATED=201]="CREATED",e[e.ACCEPTED=202]="ACCEPTED",e[e.NON_AUTHORITATIVE_INFORMATION=203]="NON_AUTHORITATIVE_INFORMATION",e[e.NO_CONTENT=204]="NO_CONTENT",e[e.RESET_CONTENT=205]="RESET_CONTENT",e[e.PARTIAL_CONTENT=206]="PARTIAL_CONTENT",e[e.AMBIGUOUS=300]="AMBIGUOUS",e[e.MOVED_PERMANENTLY=301]="MOVED_PERMANENTLY",e[e.FOUND=302]="FOUND",e[e.SEE_OTHER=303]="SEE_OTHER",e[e.NOT_MODIFIED=304]="NOT_MODIFIED",e[e.TEMPORARY_REDIRECT=307]="TEMPORARY_REDIRECT",e[e.PERMANENT_REDIRECT=308]="PERMANENT_REDIRECT",e[e.BAD_REQUEST=400]="BAD_REQUEST",e[e.UNAUTHORIZED=401]="UNAUTHORIZED",e[e.PAYMENT_REQUIRED=402]="PAYMENT_REQUIRED",e[e.FORBIDDEN=403]="FORBIDDEN",e[e.NOT_FOUND=404]="NOT_FOUND",e[e.METHOD_NOT_ALLOWED=405]="METHOD_NOT_ALLOWED",e[e.NOT_ACCEPTABLE=406]="NOT_ACCEPTABLE",e[e.PROXY_AUTHENTICATION_REQUIRED=407]="PROXY_AUTHENTICATION_REQUIRED",e[e.REQUEST_TIMEOUT=408]="REQUEST_TIMEOUT",e[e.CONFLICT=409]="CONFLICT",e[e.GONE=410]="GONE",e[e.LENGTH_REQUIRED=411]="LENGTH_REQUIRED",e[e.PRECONDITION_FAILED=412]="PRECONDITION_FAILED",e[e.PAYLOAD_TOO_LARGE=413]="PAYLOAD_TOO_LARGE",e[e.URI_TOO_LONG=414]="URI_TOO_LONG",e[e.UNSUPPORTED_MEDIA_TYPE=415]="UNSUPPORTED_MEDIA_TYPE",e[e.REQUESTED_RANGE_NOT_SATISFIABLE=416]="REQUESTED_RANGE_NOT_SATISFIABLE",e[e.EXPECTATION_FAILED=417]="EXPECTATION_FAILED",e[e.I_AM_A_TEAPOT=418]="I_AM_A_TEAPOT",e[e.UNPROCESSABLE_ENTITY=422]="UNPROCESSABLE_ENTITY",e[e.TOO_MANY_REQUESTS=429]="TOO_MANY_REQUESTS",e[e.INTERNAL_SERVER_ERROR=500]="INTERNAL_SERVER_ERROR",e[e.NOT_IMPLEMENTED=501]="NOT_IMPLEMENTED",e[e.BAD_GATEWAY=502]="BAD_GATEWAY",e[e.SERVICE_UNAVAILABLE=503]="SERVICE_UNAVAILABLE",e[e.GATEWAY_TIMEOUT=504]="GATEWAY_TIMEOUT",e[e.HTTP_VERSION_NOT_SUPPORTED=505]="HTTP_VERSION_NOT_SUPPORTED";var T=function(){function t(t){this.appInstance=t.module}var e=t.prototype;return e.run=function(t){var e=this.appInstance,E=new e(o(e)).run(t);if(!E)throw Error("no app output");return E},e.handleResponse=function(t,e){void 0===e&&(e=!1);var E=this.appInstance;return e?E.onError(t):E.onSuccess(t)},t}(),O=new n("AWSLambdaApplication"),a=function(t){var e,E;function n(e){var E;return(E=t.call(this,{module:e.module})||this).event=e.httpAdapter.event,E.context=e.httpAdapter.context,E}E=t,(e=n).prototype=Object.create(E.prototype),e.prototype.constructor=e,e.__proto__=E;var o=n.prototype;return o.handleRequest=function(){var e=this.event,E=this.context;try{var n=function(t){var e=t.event,E=t.context,n=Object.assign({"Content-Length":0},e.headers);if(e.body&&!n["Content-Length"]){var r=R(e);Object.keys(r).length&&(n["Content-Length"]=Buffer.byteLength(JSON.stringify(r)))}var o=JSON.parse(JSON.stringify(e));return delete o.body,n["x-apigateway-event"]=encodeURIComponent(JSON.stringify(o)),n["x-apigateway-context"]=encodeURIComponent(JSON.stringify(E)),{method:e.httpMethod,path:N(e),headers:n,body:R(e)}}({event:e,context:E}),r=this.run(n);if(!r)throw new Error("no output from application");var o=this.handleLambdaResponse(E,{body:r});return t.prototype.handleResponse.call(this,o)}catch(e){O.log(e);var T=this.handleLambdaResponse(E,{statusCode:502,body:{error:e.message,type:e.name}});return t.prototype.handleResponse.call(this,T,!0)}},o.handleLambdaResponse=function(t,e){var E=e.statusCode,n=e.headers,o=e.body,T=void 0===o?{}:o;return{statusCode:void 0===E?200:E,headers:r({},void 0===n?{}:n,{"x-campkit":!0}),body:JSON.stringify(T)}},n}(T);function N(t){return E.format({pathname:t.path,query:t.queryStringParameters})}function R(t){return t.body?t.body:{}}var A=new(function(){function t(){}return t.prototype.create=function(t,e,E){void 0===E&&(E={provider:"aws"});try{if("aws"===E.provider){var n=new a({module:t,httpAdapter:e});return Promise.resolve(n.handleRequest())}throw Error("currently only aws lambda events are supported")}catch(t){return Promise.reject(t)}},t}());exports.App=function(t){return function(e){Reflect.defineMetadata("app",t,e)}},exports.CampkitFactory=A,exports.Logger=n,exports.getAppMetadata=o;
"use strict";require("reflect-metadata");var t,e,E=require("url");class T{constructor(t){this.context=t}log(t,e){console.log(" "),console.log(`---- ${this.context} -----`),console.log(" "),console.log(t,e||""),console.log(" ")}}function n(){return(n=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var E=arguments[e];for(var T in E)Object.prototype.hasOwnProperty.call(E,T)&&(t[T]=E[T])}return t}).apply(this,arguments)}function O(t){return Reflect.getMetadata("app",t)}(t=exports.RequestMethod||(exports.RequestMethod={})).GET="GET",t.POST="POST",t.PUT="PUT",t.DELETE="DELETE",t.PATCH="PATCH",t.ALL="ALL",t.OPTIONS="OPTIONS",t.HEAD="HEAD",(e=exports.HttpStatus||(exports.HttpStatus={}))[e.CONTINUE=100]="CONTINUE",e[e.SWITCHING_PROTOCOLS=101]="SWITCHING_PROTOCOLS",e[e.PROCESSING=102]="PROCESSING",e[e.OK=200]="OK",e[e.CREATED=201]="CREATED",e[e.ACCEPTED=202]="ACCEPTED",e[e.NON_AUTHORITATIVE_INFORMATION=203]="NON_AUTHORITATIVE_INFORMATION",e[e.NO_CONTENT=204]="NO_CONTENT",e[e.RESET_CONTENT=205]="RESET_CONTENT",e[e.PARTIAL_CONTENT=206]="PARTIAL_CONTENT",e[e.AMBIGUOUS=300]="AMBIGUOUS",e[e.MOVED_PERMANENTLY=301]="MOVED_PERMANENTLY",e[e.FOUND=302]="FOUND",e[e.SEE_OTHER=303]="SEE_OTHER",e[e.NOT_MODIFIED=304]="NOT_MODIFIED",e[e.TEMPORARY_REDIRECT=307]="TEMPORARY_REDIRECT",e[e.PERMANENT_REDIRECT=308]="PERMANENT_REDIRECT",e[e.BAD_REQUEST=400]="BAD_REQUEST",e[e.UNAUTHORIZED=401]="UNAUTHORIZED",e[e.PAYMENT_REQUIRED=402]="PAYMENT_REQUIRED",e[e.FORBIDDEN=403]="FORBIDDEN",e[e.NOT_FOUND=404]="NOT_FOUND",e[e.METHOD_NOT_ALLOWED=405]="METHOD_NOT_ALLOWED",e[e.NOT_ACCEPTABLE=406]="NOT_ACCEPTABLE",e[e.PROXY_AUTHENTICATION_REQUIRED=407]="PROXY_AUTHENTICATION_REQUIRED",e[e.REQUEST_TIMEOUT=408]="REQUEST_TIMEOUT",e[e.CONFLICT=409]="CONFLICT",e[e.GONE=410]="GONE",e[e.LENGTH_REQUIRED=411]="LENGTH_REQUIRED",e[e.PRECONDITION_FAILED=412]="PRECONDITION_FAILED",e[e.PAYLOAD_TOO_LARGE=413]="PAYLOAD_TOO_LARGE",e[e.URI_TOO_LONG=414]="URI_TOO_LONG",e[e.UNSUPPORTED_MEDIA_TYPE=415]="UNSUPPORTED_MEDIA_TYPE",e[e.REQUESTED_RANGE_NOT_SATISFIABLE=416]="REQUESTED_RANGE_NOT_SATISFIABLE",e[e.EXPECTATION_FAILED=417]="EXPECTATION_FAILED",e[e.I_AM_A_TEAPOT=418]="I_AM_A_TEAPOT",e[e.UNPROCESSABLE_ENTITY=422]="UNPROCESSABLE_ENTITY",e[e.TOO_MANY_REQUESTS=429]="TOO_MANY_REQUESTS",e[e.INTERNAL_SERVER_ERROR=500]="INTERNAL_SERVER_ERROR",e[e.NOT_IMPLEMENTED=501]="NOT_IMPLEMENTED",e[e.BAD_GATEWAY=502]="BAD_GATEWAY",e[e.SERVICE_UNAVAILABLE=503]="SERVICE_UNAVAILABLE",e[e.GATEWAY_TIMEOUT=504]="GATEWAY_TIMEOUT",e[e.HTTP_VERSION_NOT_SUPPORTED=505]="HTTP_VERSION_NOT_SUPPORTED";class o{constructor(t){this.appInstance=t.module}run(t){const{appInstance:e}=this,E=new e(O(e)).run(t);if(!E)throw Error("no app output");return E}handleResponse(t,e=!1){const{appInstance:E}=this;return e?E.onError(t):E.onSuccess(t)}}const r=new T("AWSLambdaApplication");class s extends o{constructor(t){super({module:t.module}),this.event=t.httpAdapter.event,this.context=t.httpAdapter.context}handleRequest(){const{event:t,context:e}=this;try{const E=function({event:t,context:e}){const E=Object.assign({"Content-Length":0},t.headers);if(t.body&&!E["Content-Length"]){const e=R(t);Object.keys(e).length&&(E["Content-Length"]=Buffer.byteLength(JSON.stringify(e)))}const T=JSON.parse(JSON.stringify(t));return delete T.body,E["x-apigateway-event"]=encodeURIComponent(JSON.stringify(T)),E["x-apigateway-context"]=encodeURIComponent(JSON.stringify(e)),{method:t.httpMethod,path:N(t),headers:E,body:R(t)}}({event:t,context:e}),T=this.run(E);if(!T)throw new Error("no output from application");const n=this.handleLambdaResponse(e,{body:T});return super.handleResponse(n)}catch(t){r.log(t);const E=this.handleLambdaResponse(e,{statusCode:502,body:{error:t.message,type:t.name}});return super.handleResponse(E,!0)}}handleLambdaResponse(t,e){const{statusCode:E=200,headers:T={},body:O={}}=e;return{statusCode:E,headers:n({},T,{"x-campkit":!0}),body:JSON.stringify(O)}}}function N(t){return E.format({pathname:t.path,query:t.queryStringParameters})}function R(t){return t.body?t.body:{}}class A{create(t,e,E={provider:"aws"}){try{const{provider:T}=E;if("aws"===T)return new s({module:t,httpAdapter:e}).handleRequest();throw Error("currently only aws lambda events are supported")}catch(t){return Promise.reject(t)}}}const _=new A;exports.App=function(t){return e=>{Reflect.defineMetadata("app",t,e)}},exports.CampkitFactory=_,exports.Logger=T,exports.getAppMetadata=O;
//# sourceMappingURL=core.cjs.production.min.js.map
{
"name": "@campkit/core",
"version": "0.0.5",
"version": "0.0.6",
"publishConfig": {
"access": "public"
},
"author": "Roger Rodriguez <roger@rrod.co>",

@@ -54,3 +57,3 @@ "description": "Build serverless Node.js microservices fast",

},
"gitHead": "681bcd77bf355874334f022d4eca417cb3497d4e"
"gitHead": "16be9272c6b9012a1c29fb460deaecc5dbebd095"
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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