@campkit/core
Advanced tools
Comparing version 0.0.7 to 0.0.8
@@ -30,3 +30,3 @@ /** | ||
constructor(options: AWSLambdaApplicationOptions); | ||
handleRequest(): any; | ||
handleRequest(): Promise<any>; | ||
handleLambdaResponse(_context: Context, response: LambdaOutput): { | ||
@@ -33,0 +33,0 @@ statusCode: number; |
@@ -21,5 +21,5 @@ /** | ||
constructor(options: CampkitApplicationOptions); | ||
protected run(requestOptions: any): any; | ||
protected run(requestOptions: any): Promise<any>; | ||
protected handleResponse(response: any, isError?: boolean): any; | ||
} | ||
export {}; |
@@ -99,2 +99,28 @@ 'use strict'; | ||
// A type of promise-like that resolves synchronously and supports only one observer | ||
const _iteratorSymbol = | ||
/*#__PURE__*/ | ||
typeof Symbol !== "undefined" ? Symbol.iterator || (Symbol.iterator = | ||
/*#__PURE__*/ | ||
Symbol("Symbol.iterator")) : "@@iterator"; // Asynchronously iterate through an object's values | ||
const _asyncIteratorSymbol = | ||
/*#__PURE__*/ | ||
typeof Symbol !== "undefined" ? Symbol.asyncIterator || (Symbol.asyncIterator = | ||
/*#__PURE__*/ | ||
Symbol("Symbol.asyncIterator")) : "@@asyncIterator"; // Asynchronously iterate on a value using it's async iterator if present, or its synchronous iterator if missing | ||
function _catch(body, recover) { | ||
try { | ||
var result = body(); | ||
} catch (e) { | ||
return recover(e); | ||
} | ||
if (result && result.then) { | ||
return result.then(void 0, recover); | ||
} | ||
return result; | ||
} // Asynchronously await a promise and pass the result to a finally continuation | ||
function App(options) { | ||
@@ -120,14 +146,20 @@ return target => { | ||
run(requestOptions) { | ||
const { | ||
appInstance | ||
} = this; | ||
const appInstanceMetadata = getAppMetadata(appInstance); | ||
const appClass = new appInstance(appInstanceMetadata); | ||
const appOutput = appClass.run(requestOptions); | ||
try { | ||
const _this = this; | ||
if (!appOutput) { | ||
throw Error('no app output'); | ||
const { | ||
appInstance | ||
} = _this; | ||
const appInstanceMetadata = getAppMetadata(appInstance); | ||
const appClass = new appInstance(appInstanceMetadata); | ||
return Promise.resolve(appClass.run(requestOptions)).then(function (appOutput) { | ||
if (!appOutput) { | ||
throw Error('no app output'); | ||
} | ||
return appOutput; | ||
}); | ||
} catch (e) { | ||
return Promise.reject(e); | ||
} | ||
return appOutput; | ||
} | ||
@@ -162,32 +194,41 @@ | ||
handleRequest() { | ||
const { | ||
event, | ||
context | ||
} = this; | ||
try { | ||
const _this = this, | ||
_super$handleResponse = super.handleResponse; | ||
try { | ||
const requestOptions = mapApiGatewayEventToHttpRequest({ | ||
const { | ||
event, | ||
context | ||
}); | ||
const out = this.run(requestOptions); | ||
} = _this; | ||
return _catch(function () { | ||
const requestOptions = mapApiGatewayEventToHttpRequest({ | ||
event, | ||
context | ||
}); | ||
return Promise.resolve(_this.run(requestOptions)).then(function (out) { | ||
if (!out) { | ||
throw new Error('no output from application'); | ||
} | ||
if (!out) { | ||
throw new Error('no output from application'); | ||
} | ||
const res = _this.handleLambdaResponse(context, { | ||
body: out | ||
}); | ||
const res = this.handleLambdaResponse(context, { | ||
body: out | ||
return _super$handleResponse.call(_this, res); | ||
}); | ||
}, function (error) { | ||
logger.log(error); | ||
const res = _this.handleLambdaResponse(context, { | ||
statusCode: 502, | ||
body: { | ||
error: error.message, | ||
type: error.name | ||
} | ||
}); | ||
return _super$handleResponse.call(_this, res, true); | ||
}); | ||
return super.handleResponse(res); | ||
} catch (error) { | ||
logger.log(error); | ||
const res = this.handleLambdaResponse(context, { | ||
statusCode: 502, | ||
body: { | ||
error: error.message, | ||
type: error.name | ||
} | ||
}); | ||
return super.handleResponse(res, true); | ||
} catch (e) { | ||
return Promise.reject(e); | ||
} | ||
@@ -194,0 +235,0 @@ } |
@@ -1,2 +0,2 @@ | ||
"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; | ||
"use strict";require("reflect-metadata");var t,e,E=require("url");class n{constructor(t){this.context=t}log(t,e){console.log(" "),console.log(`---- ${this.context} -----`),console.log(" "),console.log(t,e||""),console.log(" ")}}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","undefined"!=typeof Symbol&&(Symbol.iterator||(Symbol.iterator=Symbol("Symbol.iterator"))),"undefined"!=typeof Symbol&&(Symbol.asyncIterator||(Symbol.asyncIterator=Symbol("Symbol.asyncIterator")));class T{constructor(t){this.appInstance=t.module}run(t){try{const e=this,{appInstance:E}=e,n=new E(o(E));return Promise.resolve(n.run(t)).then(function(t){if(!t)throw Error("no app output");return t})}catch(t){return Promise.reject(t)}}handleResponse(t,e=!1){const{appInstance:E}=this;return e?E.onError(t):E.onSuccess(t)}}const O=new n("AWSLambdaApplication");class s extends T{constructor(t){super({module:t.module}),this.event=t.httpAdapter.event,this.context=t.httpAdapter.context}handleRequest(){try{const t=this,e=super.handleResponse,{event:E,context:n}=t;return function(r,o){try{var T=function(){const r=function({event:t,context:e}){const E=Object.assign({"Content-Length":0},t.headers);if(t.body&&!E["Content-Length"]){const e=a(t);Object.keys(e).length&&(E["Content-Length"]=Buffer.byteLength(JSON.stringify(e)))}const n=JSON.parse(JSON.stringify(t));return delete n.body,E["x-apigateway-event"]=encodeURIComponent(JSON.stringify(n)),E["x-apigateway-context"]=encodeURIComponent(JSON.stringify(e)),{method:t.httpMethod,path:N(t),headers:E,body:a(t)}}({event:E,context:n});return Promise.resolve(t.run(r)).then(function(E){if(!E)throw new Error("no output from application");const r=t.handleLambdaResponse(n,{body:E});return e.call(t,r)})}()}catch(t){return o(t)}return T&&T.then?T.then(void 0,o):T}(0,function(E){O.log(E);const r=t.handleLambdaResponse(n,{statusCode:502,body:{error:E.message,type:E.name}});return e.call(t,r,!0)})}catch(t){return Promise.reject(t)}}handleLambdaResponse(t,e){const{statusCode:E=200,headers:n={},body:o={}}=e;return{statusCode:E,headers:r({},n,{"x-campkit":!0}),body:JSON.stringify(o)}}}function N(t){return E.format({pathname:t.path,query:t.queryStringParameters})}function a(t){return t.body?t.body:{}}class R{create(t,e,E={provider:"aws"}){try{const{provider:n}=E;if("aws"===n)return new s({module:t,httpAdapter:e}).handleRequest();throw Error("currently only aws lambda events are supported")}catch(t){return Promise.reject(t)}}}const A=new R;exports.App=function(t){return e=>{Reflect.defineMetadata("app",t,e)}},exports.CampkitFactory=A,exports.Logger=n,exports.getAppMetadata=o; | ||
//# sourceMappingURL=core.cjs.production.min.js.map |
{ | ||
"name": "@campkit/core", | ||
"version": "0.0.7", | ||
"version": "0.0.8", | ||
"publishConfig": { | ||
@@ -58,3 +58,3 @@ "access": "public" | ||
}, | ||
"gitHead": "3814beeff5e324bf02a4349629bf27ecdcdc2014" | ||
"gitHead": "ccb6baafcb02a23a4ae6fda1d71f49e1c463b29b" | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
141982
20
809