@comicrelief/lambda-wrapper 1.10.2 → 2.0.0-beta.10
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.
- package/README.md +196 -50
- package/dist/core/DependencyAwareClass.d.ts +16 -0
- package/dist/core/DependencyAwareClass.d.ts.map +1 -0
- package/dist/core/DependencyAwareClass.js +20 -0
- package/dist/core/DependencyAwareClass.js.map +1 -0
- package/dist/core/DependencyInjection.d.ts +62 -0
- package/dist/core/DependencyInjection.d.ts.map +1 -0
- package/dist/core/DependencyInjection.js +105 -0
- package/dist/core/DependencyInjection.js.map +1 -0
- package/dist/core/LambdaWrapper.d.ts +73 -0
- package/dist/core/LambdaWrapper.d.ts.map +1 -0
- package/dist/core/LambdaWrapper.js +170 -0
- package/dist/core/LambdaWrapper.js.map +1 -0
- package/dist/core/config.d.ts +20 -0
- package/dist/core/config.d.ts.map +1 -0
- package/dist/core/config.js +21 -0
- package/dist/core/config.js.map +1 -0
- package/dist/index.d.ts +28 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +57 -143
- package/dist/index.js.map +1 -0
- package/dist/models/ResponseModel.d.ts +73 -0
- package/dist/models/ResponseModel.d.ts.map +1 -0
- package/dist/models/ResponseModel.js +100 -0
- package/dist/models/ResponseModel.js.map +1 -0
- package/dist/models/SQSMessageModel.d.ts +46 -0
- package/dist/models/SQSMessageModel.d.ts.map +1 -0
- package/dist/models/SQSMessageModel.js +65 -0
- package/dist/models/SQSMessageModel.js.map +1 -0
- package/dist/services/BaseConfigService.d.ts +101 -0
- package/dist/services/BaseConfigService.d.ts.map +1 -0
- package/dist/services/BaseConfigService.js +180 -0
- package/dist/services/BaseConfigService.js.map +1 -0
- package/dist/services/HTTPService.d.ts +29 -0
- package/dist/services/HTTPService.d.ts.map +1 -0
- package/dist/services/HTTPService.js +55 -0
- package/dist/services/HTTPService.js.map +1 -0
- package/dist/services/LoggerService.d.ts +102 -0
- package/dist/services/LoggerService.d.ts.map +1 -0
- package/dist/services/LoggerService.js +249 -0
- package/dist/services/LoggerService.js.map +1 -0
- package/dist/services/RequestService.d.ts +119 -0
- package/dist/services/RequestService.d.ts.map +1 -0
- package/dist/services/RequestService.js +293 -0
- package/dist/services/RequestService.js.map +1 -0
- package/dist/services/SQSService.d.ts +263 -0
- package/dist/services/SQSService.d.ts.map +1 -0
- package/dist/services/SQSService.js +411 -0
- package/dist/services/SQSService.js.map +1 -0
- package/dist/services/TimerService.d.ts +22 -0
- package/dist/services/TimerService.d.ts.map +1 -0
- package/dist/services/TimerService.js +40 -0
- package/dist/services/TimerService.js.map +1 -0
- package/dist/types/Status.d.ts +6 -0
- package/dist/types/Status.d.ts.map +1 -0
- package/dist/types/Status.js +3 -0
- package/dist/types/Status.js.map +1 -0
- package/dist/utils/LambdaTermination.d.ts +14 -0
- package/dist/utils/LambdaTermination.d.ts.map +1 -0
- package/dist/utils/LambdaTermination.js +23 -0
- package/dist/utils/LambdaTermination.js.map +1 -0
- package/dist/utils/PromisifiedDelay.d.ts +17 -0
- package/dist/utils/PromisifiedDelay.d.ts.map +1 -0
- package/dist/utils/PromisifiedDelay.js +48 -0
- package/dist/utils/PromisifiedDelay.js.map +1 -0
- package/package.json +36 -26
- package/.eslintrc.yml +0 -16
- package/.github/dependabot.yml +0 -11
- package/.github/workflows/main.yml +0 -74
- package/babel.config.js +0 -13
- package/dist/Config/Dependencies.js +0 -33
- package/dist/DependencyInjection/DependencyAware.class.js +0 -40
- package/dist/DependencyInjection/DependencyInjection.class.js +0 -115
- package/dist/Model/CloudEvent.model.js +0 -138
- package/dist/Model/Model.model.js +0 -39
- package/dist/Model/Response.model.js +0 -135
- package/dist/Model/SQS/MarketingPreference.constraints.json +0 -28
- package/dist/Model/SQS/MarketingPreference.model.js +0 -583
- package/dist/Model/SQS/Message.model.js +0 -92
- package/dist/Model/Status.model.js +0 -71
- package/dist/Service/BaseConfig.service.js +0 -204
- package/dist/Service/HTTP.service.js +0 -57
- package/dist/Service/Logger.service.js +0 -256
- package/dist/Service/Request.service.js +0 -294
- package/dist/Service/SQS.service.js +0 -367
- package/dist/Service/Timer.service.js +0 -46
- package/dist/Wrapper/LambdaTermination.js +0 -34
- package/dist/Wrapper/LambdaWrapper.js +0 -143
- package/dist/Wrapper/PromisifiedDelay.js +0 -55
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
+
};
|
|
28
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
const lumigo = __importStar(require("@lumigo/tracer"));
|
|
30
|
+
const ResponseModel_1 = __importDefault(require("../models/ResponseModel"));
|
|
31
|
+
const LoggerService_1 = __importDefault(require("../services/LoggerService"));
|
|
32
|
+
const RequestService_1 = __importDefault(require("../services/RequestService"));
|
|
33
|
+
const DependencyInjection_1 = __importDefault(require("./DependencyInjection"));
|
|
34
|
+
const config_1 = require("./config");
|
|
35
|
+
class LambdaWrapper {
|
|
36
|
+
constructor(config) {
|
|
37
|
+
this.config = config;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Returns a new Lambda Wrapper with the given configuration applied.
|
|
41
|
+
*
|
|
42
|
+
* @param config
|
|
43
|
+
*/
|
|
44
|
+
configure(config) {
|
|
45
|
+
return new LambdaWrapper((0, config_1.mergeConfig)(this.config, config));
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Wrap the given function.
|
|
49
|
+
*/
|
|
50
|
+
wrap(handler, options) {
|
|
51
|
+
const { handleUncaughtErrors = true, } = options || {};
|
|
52
|
+
let wrapper = async (event, context) => {
|
|
53
|
+
const di = new DependencyInjection_1.default(this.config, event, context);
|
|
54
|
+
const request = di.get(RequestService_1.default);
|
|
55
|
+
const logger = di.get(LoggerService_1.default);
|
|
56
|
+
context.callbackWaitsForEmptyEventLoop = false;
|
|
57
|
+
// if the event is a warmup, don't bother running the function
|
|
58
|
+
if (event.source === 'serverless-plugin-warmup') {
|
|
59
|
+
return 'Lambda is warm!';
|
|
60
|
+
}
|
|
61
|
+
// log the user's IP address silently for use in error tracing
|
|
62
|
+
const ipAddress = request.getIp();
|
|
63
|
+
if (ipAddress) {
|
|
64
|
+
logger.metric('ipAddress', ipAddress, true);
|
|
65
|
+
}
|
|
66
|
+
// add metrics with user browser information for rapid debugging
|
|
67
|
+
const userBrowserAndDevice = request.getUserBrowserAndDevice();
|
|
68
|
+
if (userBrowserAndDevice) {
|
|
69
|
+
Object.entries(userBrowserAndDevice).forEach(([key, value]) => {
|
|
70
|
+
logger.metric(key, value, true);
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
try {
|
|
74
|
+
const result = await handler.call(wrapper, di);
|
|
75
|
+
return LambdaWrapper.handleSuccess(di, result);
|
|
76
|
+
}
|
|
77
|
+
catch (error) {
|
|
78
|
+
const handled = LambdaWrapper.handleError(di, error, !handleUncaughtErrors);
|
|
79
|
+
if (!handleUncaughtErrors) {
|
|
80
|
+
// AWS Lambda with async handler is looking for a rejection
|
|
81
|
+
// and not an error object directly
|
|
82
|
+
// and will treat resolved errors as successful
|
|
83
|
+
// as it will cast the error to JSON, i.e. `{}`
|
|
84
|
+
throw handled;
|
|
85
|
+
}
|
|
86
|
+
return handled;
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
// If Lumigo is enabled, wrap the handler in the Lumigo wrapper
|
|
90
|
+
if (LambdaWrapper.isLumigoEnabled && !LambdaWrapper.isLumigoWrappingUs) {
|
|
91
|
+
const tracer = lumigo.initTracer({ token: process.env.LUMIGO_TRACER_TOKEN });
|
|
92
|
+
// Lumigo's wrapper works with both callbacks or promises handlers, and
|
|
93
|
+
// the returned function behaves the same way as the original. For our
|
|
94
|
+
// promise-based handler we can safely coerce the type.
|
|
95
|
+
wrapper = tracer.trace(wrapper);
|
|
96
|
+
}
|
|
97
|
+
return wrapper;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* `true` if we will send traces to Lumigo.
|
|
101
|
+
*
|
|
102
|
+
* The `LUMIGO_TRACER_TOKEN` env var is present in both manually traced and
|
|
103
|
+
* auto-traced functions.
|
|
104
|
+
*/
|
|
105
|
+
static get isLumigoEnabled() {
|
|
106
|
+
return !!process.env.LUMIGO_TRACER_TOKEN;
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* `true` if the Lambda function is already being traced by a higher-level
|
|
110
|
+
* Lumigo wrapper, in which case we don't need to manually wrap our handlers.
|
|
111
|
+
*
|
|
112
|
+
* There are two ways that this can be done, based on the documentation
|
|
113
|
+
* [here](https://docs.lumigo.io/docs/lambda-layers): using a Lambda runtime
|
|
114
|
+
* wrapper, or handler redirection. Each method can be detected via its
|
|
115
|
+
* environment variables. Auto-trace uses the runtime wrapper.
|
|
116
|
+
*/
|
|
117
|
+
static get isLumigoWrappingUs() {
|
|
118
|
+
return this.isLumigoEnabled && (process.env.AWS_LAMBDA_EXEC_WRAPPER === '/opt/lumigo_wrapper'
|
|
119
|
+
|| !!process.env.LUMIGO_ORIGINAL_HANDLER);
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Process the result once we have one.
|
|
123
|
+
*
|
|
124
|
+
* @param di
|
|
125
|
+
* @param result
|
|
126
|
+
*/
|
|
127
|
+
static handleSuccess(di, result) {
|
|
128
|
+
const logger = di.get(LoggerService_1.default);
|
|
129
|
+
// result may be undefined as not all lambdas have a return value
|
|
130
|
+
logger.metric('lambda.statusCode', result?.statusCode || 200);
|
|
131
|
+
return result;
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Gracefully handles an error, logging in Lumigo and generating a response
|
|
135
|
+
* reflecting the `code` of the error, if defined.
|
|
136
|
+
*
|
|
137
|
+
* Lumigo generates alerts for logs on level ERROR. This means that
|
|
138
|
+
* `logger.error` will produce an alert. To avoid meaningless notifications,
|
|
139
|
+
* most likely coming from tests, we log INFO unless either:
|
|
140
|
+
*
|
|
141
|
+
* 1. `error.raiseOnEpsagon` is defined & truthy
|
|
142
|
+
* 2. `error.code` is defined and `error.code >= 500`.
|
|
143
|
+
*
|
|
144
|
+
* @param di
|
|
145
|
+
* @param error
|
|
146
|
+
* @param [throwError=false]
|
|
147
|
+
*/
|
|
148
|
+
static handleError(di, error, throwError = false) {
|
|
149
|
+
const logger = di.get(LoggerService_1.default);
|
|
150
|
+
const { code, raiseOnEpsagon, body = {}, details = 'unknown error', } = error;
|
|
151
|
+
logger.metric('lambda.statusCode', code || 500);
|
|
152
|
+
if (raiseOnEpsagon || !code || code >= 500) {
|
|
153
|
+
logger.error(error);
|
|
154
|
+
}
|
|
155
|
+
else {
|
|
156
|
+
logger.info(error);
|
|
157
|
+
}
|
|
158
|
+
if (throwError) {
|
|
159
|
+
if (error instanceof Error) {
|
|
160
|
+
return error;
|
|
161
|
+
}
|
|
162
|
+
// We want to be absolutely sure that we are returning an error, as
|
|
163
|
+
// Lambda sync handlers will only fail if the object is instanceof Error
|
|
164
|
+
return new Error(error);
|
|
165
|
+
}
|
|
166
|
+
return ResponseModel_1.default.generate(body, code || 500, details);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
exports.default = LambdaWrapper;
|
|
170
|
+
//# sourceMappingURL=LambdaWrapper.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"LambdaWrapper.js","sourceRoot":"","sources":["../../src/core/LambdaWrapper.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,uDAAyC;AAGzC,4EAAoD;AACpD,8EAAsD;AACtD,gFAAwD;AACxD,gFAAwD;AACxD,qCAA4D;AAc5D,MAAqB,aAAa;IAChC,YAAqB,MAAe;QAAf,WAAM,GAAN,MAAM,CAAS;IAAG,CAAC;IAExC;;;;OAIG;IACH,SAAS,CAAc,MAAsC;QAC3D,OAAO,IAAI,aAAa,CAAC,IAAA,oBAAW,EAAC,IAAI,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;IAC7D,CAAC;IAED;;OAEG;IACH,IAAI,CACF,OAA6D,EAC7D,OAAqB;QAErB,MAAM,EACJ,oBAAoB,GAAG,IAAI,GAC5B,GAAG,OAAO,IAAI,EAAE,CAAC;QAElB,IAAI,OAAO,GAAG,KAAK,EAAE,KAAU,EAAE,OAAgB,EAAE,EAAE;YACnD,MAAM,EAAE,GAAG,IAAI,6BAAmB,CAAC,IAAI,CAAC,MAAM,EAAE,KAAK,EAAE,OAAO,CAAC,CAAC;YAChE,MAAM,OAAO,GAAG,EAAE,CAAC,GAAG,CAAC,wBAAc,CAAC,CAAC;YACvC,MAAM,MAAM,GAAG,EAAE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AI,CAAC,IAAI,IAAI,IAAI,IAAI,GAAG,EAAE;YAC1C,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;SACrB;aAAM;YACL,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;SACpB;QAED,IAAI,UAAU,EAAE;YACd,IAAI,KAAK,YAAY,KAAK,EAAE;gBAC1B,OAAO,KAAK,CAAC;aACd;YAED,mEAAmE;YACnE,wEAAwE;YACxE,OAAO,IAAI,KAAK,CAAC,KAAK,CAAC,CAAC;SACzB;QAED,OAAO,uBAAa,CAAC,QAAQ,CAAC,IAAI,EAAE,IAAI,IAAI,GAAG,EAAE,OAAO,CAAC,CAAC;IAC5D,CAAC;CACF;AAtKD,gCAsKC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import DependencyAwareClass from './DependencyAwareClass';
|
|
2
|
+
/**
|
|
3
|
+
* Config for Lambda Wrapper defining dependencies and their configuration.
|
|
4
|
+
*/
|
|
5
|
+
export interface LambdaWrapperConfig {
|
|
6
|
+
/**
|
|
7
|
+
* Dependencies to be provided by dependency injection.
|
|
8
|
+
*
|
|
9
|
+
* TODO: should this just be a list instead? keys are currently unused
|
|
10
|
+
*/
|
|
11
|
+
dependencies: Record<string, typeof DependencyAwareClass>;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Combine two Lambda Wrapper configs.
|
|
15
|
+
*
|
|
16
|
+
* @param old Current config.
|
|
17
|
+
* @param new_ New config that will override the old.
|
|
18
|
+
*/
|
|
19
|
+
export declare function mergeConfig<A extends LambdaWrapperConfig, B extends Partial<LambdaWrapperConfig>>(old: A, new_: B): A & B;
|
|
20
|
+
//# sourceMappingURL=config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/core/config.ts"],"names":[],"mappings":"AAAA,OAAO,oBAAoB,MAAM,wBAAwB,CAAC;AAE1D;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC;;;;OAIG;IACH,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,oBAAoB,CAAC,CAAC;CAC3D;AAED;;;;;GAKG;AACH,wBAAgB,WAAW,CACzB,CAAC,SAAS,mBAAmB,EAC7B,CAAC,SAAS,OAAO,CAAC,mBAAmB,CAAC,EAEtC,GAAG,EAAE,CAAC,EACN,IAAI,EAAE,CAAC,GACN,CAAC,GAAG,CAAC,CASP"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.mergeConfig = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Combine two Lambda Wrapper configs.
|
|
6
|
+
*
|
|
7
|
+
* @param old Current config.
|
|
8
|
+
* @param new_ New config that will override the old.
|
|
9
|
+
*/
|
|
10
|
+
function mergeConfig(old, new_) {
|
|
11
|
+
return {
|
|
12
|
+
...old,
|
|
13
|
+
...new_,
|
|
14
|
+
dependencies: {
|
|
15
|
+
...old.dependencies,
|
|
16
|
+
...new_.dependencies,
|
|
17
|
+
},
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
exports.mergeConfig = mergeConfig;
|
|
21
|
+
//# sourceMappingURL=config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../../src/core/config.ts"],"names":[],"mappings":";;;AAcA;;;;;GAKG;AACH,SAAgB,WAAW,CAIzB,GAAM,EACN,IAAO;IAEP,OAAO;QACL,GAAG,GAAG;QACN,GAAG,IAAI;QACP,YAAY,EAAE;YACZ,GAAG,GAAG,CAAC,YAAY;YACnB,GAAG,IAAI,CAAC,YAAY;SACrB;KACF,CAAC;AACJ,CAAC;AAfD,kCAeC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import LambdaWrapper from './core/LambdaWrapper';
|
|
2
|
+
import { LambdaWrapperConfig } from './core/config';
|
|
3
|
+
import { WithSQSServiceConfig } from './services/SQSService';
|
|
4
|
+
/**
|
|
5
|
+
* Lambda Wrapper preconfigured with our core services that can be used
|
|
6
|
+
* straight out of the box.
|
|
7
|
+
*
|
|
8
|
+
* Use `lambdaWrapper.configure()` to add your own dependencies.
|
|
9
|
+
*/
|
|
10
|
+
declare const lambdaWrapper: LambdaWrapper<LambdaWrapperConfig & WithSQSServiceConfig>;
|
|
11
|
+
export default lambdaWrapper;
|
|
12
|
+
export { Context, Handler } from 'aws-lambda';
|
|
13
|
+
export { LambdaWrapperConfig } from './core/config';
|
|
14
|
+
export { default as DependencyAwareClass } from './core/DependencyAwareClass';
|
|
15
|
+
export { default as DependencyInjection } from './core/DependencyInjection';
|
|
16
|
+
export { default as LambdaWrapper, WrapOptions } from './core/LambdaWrapper';
|
|
17
|
+
export { default as ResponseModel, RESPONSE_HEADERS, } from './models/ResponseModel';
|
|
18
|
+
export { default as SQSMessageModel, } from './models/SQSMessageModel';
|
|
19
|
+
export { default as BaseConfigService, } from './services/BaseConfigService';
|
|
20
|
+
export { default as HTTPService, COMICRELIEF_TEST_METADATA_HEADER, } from './services/HTTPService';
|
|
21
|
+
export { default as LoggerService, } from './services/LoggerService';
|
|
22
|
+
export { default as RequestService, REQUEST_TYPES, RequestFile, } from './services/RequestService';
|
|
23
|
+
export { default as SQSService, QueueName, SQS_OFFLINE_MODES, SQS_PUBLISH_FAILURE_MODES, SQSServiceConfig, WithSQSServiceConfig, } from './services/SQSService';
|
|
24
|
+
export { default as TimerService, } from './services/TimerService';
|
|
25
|
+
export { ServiceStatus, Status, } from './types/Status';
|
|
26
|
+
export { default as LambdaTermination } from './utils/LambdaTermination';
|
|
27
|
+
export { default as PromisifiedDelay } from './utils/PromisifiedDelay';
|
|
28
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAA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AAE,OAAO,IAAI,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AACzE,OAAO,EAAE,OAAO,IAAI,gBAAgB,EAAE,MAAM,0BAA0B,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,144 +1,58 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
});
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
Object.defineProperty(exports, "DependencyInjection", {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
});
|
|
42
|
-
Object.defineProperty(exports, "
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
});
|
|
60
|
-
Object.defineProperty(exports, "MarketingPreferenceModel", {
|
|
61
|
-
enumerable: true,
|
|
62
|
-
get: function () {
|
|
63
|
-
return _MarketingPreference.default;
|
|
64
|
-
}
|
|
65
|
-
});
|
|
66
|
-
Object.defineProperty(exports, "Model", {
|
|
67
|
-
enumerable: true,
|
|
68
|
-
get: function () {
|
|
69
|
-
return _Model.default;
|
|
70
|
-
}
|
|
71
|
-
});
|
|
72
|
-
Object.defineProperty(exports, "PromisifiedDelay", {
|
|
73
|
-
enumerable: true,
|
|
74
|
-
get: function () {
|
|
75
|
-
return _PromisifiedDelay.default;
|
|
76
|
-
}
|
|
77
|
-
});
|
|
78
|
-
Object.defineProperty(exports, "RequestService", {
|
|
79
|
-
enumerable: true,
|
|
80
|
-
get: function () {
|
|
81
|
-
return _Request.default;
|
|
82
|
-
}
|
|
83
|
-
});
|
|
84
|
-
Object.defineProperty(exports, "ResponseModel", {
|
|
85
|
-
enumerable: true,
|
|
86
|
-
get: function () {
|
|
87
|
-
return _Response.default;
|
|
88
|
-
}
|
|
89
|
-
});
|
|
90
|
-
Object.defineProperty(exports, "SQSMessageModel", {
|
|
91
|
-
enumerable: true,
|
|
92
|
-
get: function () {
|
|
93
|
-
return _Message.default;
|
|
94
|
-
}
|
|
95
|
-
});
|
|
96
|
-
Object.defineProperty(exports, "SQSService", {
|
|
97
|
-
enumerable: true,
|
|
98
|
-
get: function () {
|
|
99
|
-
return _SQS.default;
|
|
100
|
-
}
|
|
101
|
-
});
|
|
102
|
-
Object.defineProperty(exports, "SQS_OFFLINE_MODES", {
|
|
103
|
-
enumerable: true,
|
|
104
|
-
get: function () {
|
|
105
|
-
return _SQS.SQS_OFFLINE_MODES;
|
|
106
|
-
}
|
|
107
|
-
});
|
|
108
|
-
Object.defineProperty(exports, "SQS_PUBLISH_FAILURE_MODES", {
|
|
109
|
-
enumerable: true,
|
|
110
|
-
get: function () {
|
|
111
|
-
return _SQS.SQS_PUBLISH_FAILURE_MODES;
|
|
112
|
-
}
|
|
113
|
-
});
|
|
114
|
-
Object.defineProperty(exports, "STATUS_TYPES", {
|
|
115
|
-
enumerable: true,
|
|
116
|
-
get: function () {
|
|
117
|
-
return _Status.STATUS_TYPES;
|
|
118
|
-
}
|
|
119
|
-
});
|
|
120
|
-
Object.defineProperty(exports, "StatusModel", {
|
|
121
|
-
enumerable: true,
|
|
122
|
-
get: function () {
|
|
123
|
-
return _Status.default;
|
|
124
|
-
}
|
|
125
|
-
});
|
|
126
|
-
var _Dependencies = require("./Config/Dependencies");
|
|
127
|
-
var _DependencyAware = _interopRequireDefault(require("./DependencyInjection/DependencyAware.class"));
|
|
128
|
-
var _DependencyInjection = _interopRequireDefault(require("./DependencyInjection/DependencyInjection.class"));
|
|
129
|
-
var _Model = _interopRequireDefault(require("./Model/Model.model"));
|
|
130
|
-
var _Response = _interopRequireDefault(require("./Model/Response.model"));
|
|
131
|
-
var _Status = _interopRequireWildcard(require("./Model/Status.model"));
|
|
132
|
-
var _Message = _interopRequireDefault(require("./Model/SQS/Message.model"));
|
|
133
|
-
var _MarketingPreference = _interopRequireDefault(require("./Model/SQS/MarketingPreference.model"));
|
|
134
|
-
var _BaseConfig = _interopRequireDefault(require("./Service/BaseConfig.service"));
|
|
135
|
-
var _HTTP = _interopRequireWildcard(require("./Service/HTTP.service"));
|
|
136
|
-
var _Logger = _interopRequireDefault(require("./Service/Logger.service"));
|
|
137
|
-
var _Request = _interopRequireDefault(require("./Service/Request.service"));
|
|
138
|
-
var _SQS = _interopRequireWildcard(require("./Service/SQS.service"));
|
|
139
|
-
var _LambdaTermination = _interopRequireDefault(require("./Wrapper/LambdaTermination"));
|
|
140
|
-
var _LambdaWrapper = _interopRequireDefault(require("./Wrapper/LambdaWrapper"));
|
|
141
|
-
var _PromisifiedDelay = _interopRequireDefault(require("./Wrapper/PromisifiedDelay"));
|
|
142
|
-
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
143
|
-
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
144
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.PromisifiedDelay = exports.LambdaTermination = exports.TimerService = exports.SQS_PUBLISH_FAILURE_MODES = exports.SQS_OFFLINE_MODES = exports.SQSService = exports.REQUEST_TYPES = exports.RequestService = exports.LoggerService = exports.COMICRELIEF_TEST_METADATA_HEADER = exports.HTTPService = exports.BaseConfigService = exports.SQSMessageModel = exports.RESPONSE_HEADERS = exports.ResponseModel = exports.LambdaWrapper = exports.DependencyInjection = exports.DependencyAwareClass = void 0;
|
|
7
|
+
const LambdaWrapper_1 = __importDefault(require("./core/LambdaWrapper"));
|
|
8
|
+
const LoggerService_1 = __importDefault(require("./services/LoggerService"));
|
|
9
|
+
const RequestService_1 = __importDefault(require("./services/RequestService"));
|
|
10
|
+
const SQSService_1 = __importDefault(require("./services/SQSService"));
|
|
11
|
+
const TimerService_1 = __importDefault(require("./services/TimerService"));
|
|
12
|
+
/**
|
|
13
|
+
* Lambda Wrapper preconfigured with our core services that can be used
|
|
14
|
+
* straight out of the box.
|
|
15
|
+
*
|
|
16
|
+
* Use `lambdaWrapper.configure()` to add your own dependencies.
|
|
17
|
+
*/
|
|
18
|
+
const lambdaWrapper = new LambdaWrapper_1.default({
|
|
19
|
+
dependencies: {
|
|
20
|
+
LoggerService: LoggerService_1.default,
|
|
21
|
+
RequestService: RequestService_1.default,
|
|
22
|
+
SQSService: SQSService_1.default,
|
|
23
|
+
TimerService: TimerService_1.default,
|
|
24
|
+
},
|
|
25
|
+
});
|
|
26
|
+
exports.default = lambdaWrapper;
|
|
27
|
+
var DependencyAwareClass_1 = require("./core/DependencyAwareClass");
|
|
28
|
+
Object.defineProperty(exports, "DependencyAwareClass", { enumerable: true, get: function () { return __importDefault(DependencyAwareClass_1).default; } });
|
|
29
|
+
var DependencyInjection_1 = require("./core/DependencyInjection");
|
|
30
|
+
Object.defineProperty(exports, "DependencyInjection", { enumerable: true, get: function () { return __importDefault(DependencyInjection_1).default; } });
|
|
31
|
+
var LambdaWrapper_2 = require("./core/LambdaWrapper");
|
|
32
|
+
Object.defineProperty(exports, "LambdaWrapper", { enumerable: true, get: function () { return __importDefault(LambdaWrapper_2).default; } });
|
|
33
|
+
var ResponseModel_1 = require("./models/ResponseModel");
|
|
34
|
+
Object.defineProperty(exports, "ResponseModel", { enumerable: true, get: function () { return __importDefault(ResponseModel_1).default; } });
|
|
35
|
+
Object.defineProperty(exports, "RESPONSE_HEADERS", { enumerable: true, get: function () { return ResponseModel_1.RESPONSE_HEADERS; } });
|
|
36
|
+
var SQSMessageModel_1 = require("./models/SQSMessageModel");
|
|
37
|
+
Object.defineProperty(exports, "SQSMessageModel", { enumerable: true, get: function () { return __importDefault(SQSMessageModel_1).default; } });
|
|
38
|
+
var BaseConfigService_1 = require("./services/BaseConfigService");
|
|
39
|
+
Object.defineProperty(exports, "BaseConfigService", { enumerable: true, get: function () { return __importDefault(BaseConfigService_1).default; } });
|
|
40
|
+
var HTTPService_1 = require("./services/HTTPService");
|
|
41
|
+
Object.defineProperty(exports, "HTTPService", { enumerable: true, get: function () { return __importDefault(HTTPService_1).default; } });
|
|
42
|
+
Object.defineProperty(exports, "COMICRELIEF_TEST_METADATA_HEADER", { enumerable: true, get: function () { return HTTPService_1.COMICRELIEF_TEST_METADATA_HEADER; } });
|
|
43
|
+
var LoggerService_2 = require("./services/LoggerService");
|
|
44
|
+
Object.defineProperty(exports, "LoggerService", { enumerable: true, get: function () { return __importDefault(LoggerService_2).default; } });
|
|
45
|
+
var RequestService_2 = require("./services/RequestService");
|
|
46
|
+
Object.defineProperty(exports, "RequestService", { enumerable: true, get: function () { return __importDefault(RequestService_2).default; } });
|
|
47
|
+
Object.defineProperty(exports, "REQUEST_TYPES", { enumerable: true, get: function () { return RequestService_2.REQUEST_TYPES; } });
|
|
48
|
+
var SQSService_2 = require("./services/SQSService");
|
|
49
|
+
Object.defineProperty(exports, "SQSService", { enumerable: true, get: function () { return __importDefault(SQSService_2).default; } });
|
|
50
|
+
Object.defineProperty(exports, "SQS_OFFLINE_MODES", { enumerable: true, get: function () { return SQSService_2.SQS_OFFLINE_MODES; } });
|
|
51
|
+
Object.defineProperty(exports, "SQS_PUBLISH_FAILURE_MODES", { enumerable: true, get: function () { return SQSService_2.SQS_PUBLISH_FAILURE_MODES; } });
|
|
52
|
+
var TimerService_2 = require("./services/TimerService");
|
|
53
|
+
Object.defineProperty(exports, "TimerService", { enumerable: true, get: function () { return __importDefault(TimerService_2).default; } });
|
|
54
|
+
var LambdaTermination_1 = require("./utils/LambdaTermination");
|
|
55
|
+
Object.defineProperty(exports, "LambdaTermination", { enumerable: true, get: function () { return __importDefault(LambdaTermination_1).default; } });
|
|
56
|
+
var PromisifiedDelay_1 = require("./utils/PromisifiedDelay");
|
|
57
|
+
Object.defineProperty(exports, "PromisifiedDelay", { enumerable: true, get: function () { return __importDefault(PromisifiedDelay_1).default; } });
|
|
58
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;AAAA,yEAAiD;AAEjD,6EAAqD;AACrD,+EAAuD;AACvD,uEAAyE;AACzE,2EAAmD;AAEnD;;;;;GAKG;AACH,MAAM,aAAa,GAAG,IAAI,uBAAa,CAA6C;IAClF,YAAY,EAAE;QACZ,aAAa,EAAb,uBAAa;QACb,cAAc,EAAd,wBAAc;QACd,UAAU,EAAV,oBAAU;QACV,YAAY,EAAZ,sBAAY;KACb;CACF,CAAC,CAAC;AAEH,kBAAe,aAAa,CAAC;AAK7B,oEAA8E;AAArE,6IAAA,OAAO,OAAwB;AACxC,kEAA4E;AAAnE,2IAAA,OAAO,OAAuB;AACvC,sDAA6E;AAApE,+HAAA,OAAO,OAAiB;AAEjC,wDAGgC;AAF9B,+HAAA,OAAO,OAAiB;AACxB,iHAAA,gBAAgB,OAAA;AAElB,4DAEkC;AADhC,mIAAA,OAAO,OAAmB;AAG5B,kEAEsC;AADpC,uIAAA,OAAO,OAAqB;AAE9B,sDAGgC;AAF9B,2HAAA,OAAO,OAAe;AACtB,+HAAA,gCAAgC,OAAA;AAElC,0DAEkC;AADhC,+HAAA,OAAO,OAAiB;AAE1B,4DAImC;AAHjC,iIAAA,OAAO,OAAkB;AACzB,+GAAA,aAAa,OAAA;AAGf,oDAO+B;AAN7B,yHAAA,OAAO,OAAc;AAErB,+GAAA,iBAAiB,OAAA;AACjB,uHAAA,yBAAyB,OAAA;AAI3B,wDAEiC;AAD/B,6HAAA,OAAO,OAAgB;AAQzB,+DAAyE;AAAhE,uIAAA,OAAO,OAAqB;AACrC,6DAAuE;AAA9D,qIAAA,OAAO,OAAoB"}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* HTTP headers to be included in `ResponseModel`.
|
|
3
|
+
*/
|
|
4
|
+
export declare const RESPONSE_HEADERS: Record<string, string>;
|
|
5
|
+
/**
|
|
6
|
+
* Default message provided as part of response.
|
|
7
|
+
*/
|
|
8
|
+
export declare const DEFAULT_MESSAGE = "success";
|
|
9
|
+
/**
|
|
10
|
+
* Our standard response model for HTTP endpoints.
|
|
11
|
+
*/
|
|
12
|
+
export default class ResponseModel {
|
|
13
|
+
body: any;
|
|
14
|
+
code: any;
|
|
15
|
+
constructor(data?: any, code?: number, message?: string);
|
|
16
|
+
/**
|
|
17
|
+
* Add or update a body variable.
|
|
18
|
+
*
|
|
19
|
+
* @param key
|
|
20
|
+
* @param value
|
|
21
|
+
*/
|
|
22
|
+
setBodyVariable(key: string, value: any): void;
|
|
23
|
+
/**
|
|
24
|
+
* Set data.
|
|
25
|
+
*
|
|
26
|
+
* @param data
|
|
27
|
+
*/
|
|
28
|
+
setData(data: object): void;
|
|
29
|
+
/**
|
|
30
|
+
* Set status code.
|
|
31
|
+
*
|
|
32
|
+
* @param code
|
|
33
|
+
*/
|
|
34
|
+
setCode(code: number): void;
|
|
35
|
+
/**
|
|
36
|
+
* Get status code.
|
|
37
|
+
*/
|
|
38
|
+
getCode(): any;
|
|
39
|
+
/**
|
|
40
|
+
* Set message.
|
|
41
|
+
*
|
|
42
|
+
* @param message
|
|
43
|
+
*/
|
|
44
|
+
setMessage(message: string): void;
|
|
45
|
+
/**
|
|
46
|
+
* Get message.
|
|
47
|
+
*/
|
|
48
|
+
getMessage(): any;
|
|
49
|
+
/**
|
|
50
|
+
* Geneate a response.
|
|
51
|
+
*/
|
|
52
|
+
generate(): {
|
|
53
|
+
statusCode: any;
|
|
54
|
+
headers: Record<string, string>;
|
|
55
|
+
body: string;
|
|
56
|
+
};
|
|
57
|
+
/**
|
|
58
|
+
* Shorthand static method that generates the response immediately if no
|
|
59
|
+
* additional processing is required.
|
|
60
|
+
*
|
|
61
|
+
* Saves only 1 line of code but keeps code terse in a lot of places.
|
|
62
|
+
*
|
|
63
|
+
* @param data
|
|
64
|
+
* @param code
|
|
65
|
+
* @param message
|
|
66
|
+
*/
|
|
67
|
+
static generate(data?: any, code?: number, message?: string): {
|
|
68
|
+
statusCode: any;
|
|
69
|
+
headers: Record<string, string>;
|
|
70
|
+
body: string;
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
//# sourceMappingURL=ResponseModel.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ResponseModel.d.ts","sourceRoot":"","sources":["../../src/models/ResponseModel.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,eAAO,MAAM,gBAAgB,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAMnD,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,eAAe,YAAY,CAAC;AAEzC;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,aAAa;IAChC,IAAI,EAAE,GAAG,CAAC;IAEV,IAAI,EAAE,GAAG,CAAC;gBAEE,IAAI,CAAC,EAAE,GAAG,EAAE,IAAI,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM;IAQvD;;;;;OAKG;IACH,eAAe,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG;IAIvC;;;;OAIG;IACH,OAAO,CAAC,IAAI,EAAE,MAAM;IAIpB;;;;OAIG;IACH,OAAO,CAAC,IAAI,EAAE,MAAM;IAIpB;;OAEG;IACH,OAAO;IAIP;;;;OAIG;IACH,UAAU,CAAC,OAAO,EAAE,MAAM;IAI1B;;OAEG;IACH,UAAU;IAIV;;OAEG;IACH,QAAQ;;;;;IAQR;;;;;;;;;OASG;IACH,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,GAAG,EAAE,IAAI,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM;;;;;CAI5D"}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DEFAULT_MESSAGE = exports.RESPONSE_HEADERS = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* HTTP headers to be included in `ResponseModel`.
|
|
6
|
+
*/
|
|
7
|
+
exports.RESPONSE_HEADERS = {
|
|
8
|
+
'Content-Type': 'application/json',
|
|
9
|
+
/** Required for CORS support to work */
|
|
10
|
+
'Access-Control-Allow-Origin': '*',
|
|
11
|
+
/** Required for cookies, authorization headers with HTTPS */
|
|
12
|
+
'Access-Control-Allow-Credentials': 'true',
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* Default message provided as part of response.
|
|
16
|
+
*/
|
|
17
|
+
exports.DEFAULT_MESSAGE = 'success';
|
|
18
|
+
/**
|
|
19
|
+
* Our standard response model for HTTP endpoints.
|
|
20
|
+
*/
|
|
21
|
+
class ResponseModel {
|
|
22
|
+
constructor(data, code, message) {
|
|
23
|
+
this.body = {
|
|
24
|
+
data: data ?? {},
|
|
25
|
+
message: message ?? exports.DEFAULT_MESSAGE,
|
|
26
|
+
};
|
|
27
|
+
this.code = code ?? {};
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Add or update a body variable.
|
|
31
|
+
*
|
|
32
|
+
* @param key
|
|
33
|
+
* @param value
|
|
34
|
+
*/
|
|
35
|
+
setBodyVariable(key, value) {
|
|
36
|
+
this.body[key] = value;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Set data.
|
|
40
|
+
*
|
|
41
|
+
* @param data
|
|
42
|
+
*/
|
|
43
|
+
setData(data) {
|
|
44
|
+
this.body.data = data;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Set status code.
|
|
48
|
+
*
|
|
49
|
+
* @param code
|
|
50
|
+
*/
|
|
51
|
+
setCode(code) {
|
|
52
|
+
this.code = code;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Get status code.
|
|
56
|
+
*/
|
|
57
|
+
getCode() {
|
|
58
|
+
return this.code;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Set message.
|
|
62
|
+
*
|
|
63
|
+
* @param message
|
|
64
|
+
*/
|
|
65
|
+
setMessage(message) {
|
|
66
|
+
this.body.message = message;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Get message.
|
|
70
|
+
*/
|
|
71
|
+
getMessage() {
|
|
72
|
+
return this.body.message;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Geneate a response.
|
|
76
|
+
*/
|
|
77
|
+
generate() {
|
|
78
|
+
return {
|
|
79
|
+
statusCode: this.code,
|
|
80
|
+
headers: exports.RESPONSE_HEADERS,
|
|
81
|
+
body: JSON.stringify(this.body),
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Shorthand static method that generates the response immediately if no
|
|
86
|
+
* additional processing is required.
|
|
87
|
+
*
|
|
88
|
+
* Saves only 1 line of code but keeps code terse in a lot of places.
|
|
89
|
+
*
|
|
90
|
+
* @param data
|
|
91
|
+
* @param code
|
|
92
|
+
* @param message
|
|
93
|
+
*/
|
|
94
|
+
static generate(data, code, message) {
|
|
95
|
+
const response = new this(data, code, message);
|
|
96
|
+
return response.generate();
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
exports.default = ResponseModel;
|
|
100
|
+
//# sourceMappingURL=ResponseModel.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ResponseModel.js","sourceRoot":"","sources":["../../src/models/ResponseModel.ts"],"names":[],"mappings":";;;AAAA;;GAEG;AACU,QAAA,gBAAgB,GAA2B;IACtD,cAAc,EAAE,kBAAkB;IAClC,wCAAwC;IACxC,6BAA6B,EAAE,GAAG;IAClC,6DAA6D;IAC7D,kCAAkC,EAAE,MAAM;CAC3C,CAAC;AAEF;;GAEG;AACU,QAAA,eAAe,GAAG,SAAS,CAAC;AAEzC;;GAEG;AACH,MAAqB,aAAa;IAKhC,YAAY,IAAU,EAAE,IAAa,EAAE,OAAgB;QACrD,IAAI,CAAC,IAAI,GAAG;YACV,IAAI,EAAE,IAAI,IAAI,EAAE;YAChB,OAAO,EAAE,OAAO,IAAI,uBAAe;SACpC,CAAC;QACF,IAAI,CAAC,IAAI,GAAG,IAAI,IAAI,EAAE,CAAC;IACzB,CAAC;IAED;;;;;OAKG;IACH,eAAe,CAAC,GAAW,EAAE,KAAU;QACrC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,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