@creator.co/wapi 1.2.3 → 1.2.4

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.
Files changed (83) hide show
  1. package/.github/workflows/npmpublish.yml +2 -5
  2. package/README.md +1 -3
  3. package/dist/index.d.ts +11 -0
  4. package/dist/index.js +24 -0
  5. package/dist/index.js.map +1 -0
  6. package/dist/jest.config.d.ts +3 -0
  7. package/dist/jest.config.js +34 -0
  8. package/dist/jest.config.js.map +1 -0
  9. package/dist/package.json +64 -0
  10. package/dist/src/API/Request.d.ts +140 -0
  11. package/dist/src/API/Request.js +182 -0
  12. package/dist/src/API/Request.js.map +1 -0
  13. package/dist/src/API/Response.d.ts +256 -0
  14. package/dist/src/API/Response.js +398 -0
  15. package/dist/src/API/Response.js.map +1 -0
  16. package/dist/src/API/Utils.d.ts +63 -0
  17. package/dist/src/API/Utils.js +104 -0
  18. package/dist/src/API/Utils.js.map +1 -0
  19. package/dist/src/BaseEvent/EventProcessor.d.ts +81 -0
  20. package/dist/src/BaseEvent/EventProcessor.js +182 -0
  21. package/dist/src/BaseEvent/EventProcessor.js.map +1 -0
  22. package/dist/src/BaseEvent/Process.d.ts +74 -0
  23. package/dist/src/BaseEvent/Process.js +142 -0
  24. package/dist/src/BaseEvent/Process.js.map +1 -0
  25. package/dist/src/BaseEvent/Transaction.d.ts +29 -0
  26. package/dist/src/BaseEvent/Transaction.js +244 -0
  27. package/dist/src/BaseEvent/Transaction.js.map +1 -0
  28. package/dist/src/Config/Configuration.d.ts +131 -0
  29. package/dist/src/Config/Configuration.js +153 -0
  30. package/dist/src/Config/Configuration.js.map +1 -0
  31. package/dist/src/Config/EnvironmentVar.d.ts +101 -0
  32. package/dist/src/Config/EnvironmentVar.js +213 -0
  33. package/dist/src/Config/EnvironmentVar.js.map +1 -0
  34. package/dist/src/Crypto/Crypto.d.ts +57 -0
  35. package/dist/src/Crypto/Crypto.js +126 -0
  36. package/dist/src/Crypto/Crypto.js.map +1 -0
  37. package/dist/src/Crypto/JWT.d.ts +64 -0
  38. package/dist/src/Crypto/JWT.js +74 -0
  39. package/dist/src/Crypto/JWT.js.map +1 -0
  40. package/dist/src/Globals.d.ts +161 -0
  41. package/dist/src/Globals.js +173 -0
  42. package/dist/src/Globals.js.map +1 -0
  43. package/dist/src/Logger/Logger.d.ts +180 -0
  44. package/dist/src/Logger/Logger.js +412 -0
  45. package/dist/src/Logger/Logger.js.map +1 -0
  46. package/dist/src/Mailer/Mailer.d.ts +107 -0
  47. package/dist/src/Mailer/Mailer.js +313 -0
  48. package/dist/src/Mailer/Mailer.js.map +1 -0
  49. package/dist/src/Publisher/Publisher.d.ts +47 -0
  50. package/dist/src/Publisher/Publisher.js +141 -0
  51. package/dist/src/Publisher/Publisher.js.map +1 -0
  52. package/dist/src/Server/RouteResolver.d.ts +41 -0
  53. package/dist/src/Server/RouteResolver.js +135 -0
  54. package/dist/src/Server/RouteResolver.js.map +1 -0
  55. package/dist/src/Server/Router.d.ts +104 -0
  56. package/dist/src/Server/Router.js +45 -0
  57. package/dist/src/Server/Router.js.map +1 -0
  58. package/dist/src/Server/lib/ContainerServer.d.ts +58 -0
  59. package/dist/src/Server/lib/ContainerServer.js +143 -0
  60. package/dist/src/Server/lib/ContainerServer.js.map +1 -0
  61. package/dist/src/Server/lib/Server.d.ts +60 -0
  62. package/dist/src/Server/lib/Server.js +137 -0
  63. package/dist/src/Server/lib/Server.js.map +1 -0
  64. package/dist/src/Server/lib/container/GenericHandler.d.ts +4 -0
  65. package/dist/src/Server/lib/container/GenericHandler.js +138 -0
  66. package/dist/src/Server/lib/container/GenericHandler.js.map +1 -0
  67. package/dist/src/Server/lib/container/GenericHandlerEvent.d.ts +67 -0
  68. package/dist/src/Server/lib/container/GenericHandlerEvent.js +189 -0
  69. package/dist/src/Server/lib/container/GenericHandlerEvent.js.map +1 -0
  70. package/dist/src/Server/lib/container/HealthHandler.d.ts +3 -0
  71. package/dist/src/Server/lib/container/HealthHandler.js +45 -0
  72. package/dist/src/Server/lib/container/HealthHandler.js.map +1 -0
  73. package/dist/src/Server/lib/container/Proxy.d.ts +95 -0
  74. package/dist/src/Server/lib/container/Proxy.js +201 -0
  75. package/dist/src/Server/lib/container/Proxy.js.map +1 -0
  76. package/dist/src/Server/lib/container/Utils.d.ts +18 -0
  77. package/dist/src/Server/lib/container/Utils.js +84 -0
  78. package/dist/src/Server/lib/container/Utils.js.map +1 -0
  79. package/dist/src/Validation/Validator.d.ts +21 -0
  80. package/dist/src/Validation/Validator.js +48 -0
  81. package/dist/src/Validation/Validator.js.map +1 -0
  82. package/jest.config.ts +1 -8
  83. package/package.json +3 -3
@@ -0,0 +1,256 @@
1
+ import type { Context } from 'aws-lambda';
2
+ import Transaction from '../BaseEvent/Transaction';
3
+ /**
4
+ * ${1:Description placeholder}
5
+ *
6
+ * @export
7
+ * @typedef {ResponseErrorType}
8
+ */
9
+ export type ResponseErrorType = {
10
+ err: string;
11
+ errCode?: string;
12
+ };
13
+ /**
14
+ * ${1:Description placeholder}
15
+ *
16
+ * @export
17
+ * @class Response
18
+ * @typedef {Response}
19
+ * @template [BodyType=null]
20
+ */
21
+ export default class Response<BodyType = null> {
22
+ /**
23
+ * ${1:Description placeholder}
24
+ *
25
+ * @private
26
+ * @type {number}
27
+ */
28
+ private _statusCode;
29
+ /**
30
+ * ${1:Description placeholder}
31
+ *
32
+ * @private
33
+ * @type {*}
34
+ */
35
+ private _body;
36
+ /**
37
+ * ${1:Description placeholder}
38
+ *
39
+ * @private
40
+ * @type {boolean}
41
+ */
42
+ private _isPipingOut;
43
+ /**
44
+ * ${1:Description placeholder}
45
+ *
46
+ * @private
47
+ * @type {object}
48
+ */
49
+ private _headers;
50
+ /**
51
+ * ${1:Description placeholder}
52
+ *
53
+ * @public
54
+ * @readonly
55
+ * @type {boolean}
56
+ */
57
+ readonly shouldStream: boolean;
58
+ /**
59
+ * ${1:Description placeholder}
60
+ *
61
+ * @public
62
+ * @readonly
63
+ * @type {boolean}
64
+ */
65
+ readonly rawBody: boolean;
66
+ /**
67
+ * ${1:Description placeholder}
68
+ *
69
+ * @public
70
+ * @readonly
71
+ * @type {boolean}
72
+ */
73
+ readonly throwOnErrors: boolean;
74
+ /**
75
+ * ${1:Description placeholder}
76
+ *
77
+ * @public
78
+ * @readonly
79
+ * @type {boolean}
80
+ */
81
+ readonly disableTransactionID: boolean;
82
+ /**
83
+ * Creates an instance of Response.
84
+ *
85
+ * @constructor
86
+ * @param {number} statusCode
87
+ * @param {BodyType} body
88
+ * @param {?(| {
89
+ * shouldStream?: boolean
90
+ * rawBody?: boolean
91
+ * throwOnErrors?: boolean
92
+ * disableTransactionID?: boolean
93
+ * }
94
+ * | undefined)\} [optBehaviour]
95
+ */
96
+ constructor(statusCode: number, body: BodyType, optBehaviour?: {
97
+ shouldStream?: boolean;
98
+ rawBody?: boolean;
99
+ throwOnErrors?: boolean;
100
+ disableTransactionID?: boolean;
101
+ } | undefined);
102
+ /**
103
+ * ${1:Description placeholder}
104
+ *
105
+ * @public
106
+ * @returns {number}
107
+ */
108
+ getCode(): number;
109
+ /**
110
+ * ${1:Description placeholder}
111
+ *
112
+ * @public
113
+ * @returns {BodyType}
114
+ */
115
+ getBody(): BodyType;
116
+ /**
117
+ * ${1:Description placeholder}
118
+ *
119
+ * @public
120
+ * @param {string} key
121
+ * @param {*} value
122
+ */
123
+ appendIntoBody(key: string, value: any): void;
124
+ /**
125
+ * ${1:Description placeholder}
126
+ *
127
+ * @public
128
+ * @param {string} key
129
+ * @param {*} value
130
+ */
131
+ appendHeader(key: string, value: any): void;
132
+ /**
133
+ * ${1:Description placeholder}
134
+ *
135
+ * @public
136
+ * @async
137
+ * @param {Context} context
138
+ * @param {Transaction<any, any, any>} transaction
139
+ * @param {boolean} _optDoNotCallContext
140
+ * @returns {Promise<void>}
141
+ */
142
+ build(context: Context, transaction: Transaction<any, any, any>, _optDoNotCallContext: boolean): Promise<void>;
143
+ /**
144
+ * ${1:Description placeholder}
145
+ *
146
+ * @private
147
+ * @param {Context} context
148
+ */
149
+ private _pipe;
150
+ /**
151
+ * ${1:Description placeholder}
152
+ *
153
+ * @private
154
+ * @param {Context} context
155
+ * @param {Transaction<null, BodyType>} transaction
156
+ */
157
+ private _rawContext;
158
+ /**
159
+ * ${1:Description placeholder}
160
+ *
161
+ * @public
162
+ * @static
163
+ * @param {string} paramName
164
+ * @returns {Response<ResponseErrorType>}
165
+ */
166
+ static MissingParamResponse(paramName: string): Response<ResponseErrorType>;
167
+ /**
168
+ * ${1:Description placeholder}
169
+ *
170
+ * @public
171
+ * @static
172
+ * @param {string} paramName
173
+ * @returns {Response<ResponseErrorType>}
174
+ */
175
+ static MissingQueryResponse(paramName: string): Response<ResponseErrorType>;
176
+ /**
177
+ * ${1:Description placeholder}
178
+ *
179
+ * @public
180
+ * @static
181
+ * @param {?string} [msg]
182
+ * @param {?string} [errCode]
183
+ * @param {?*} [optBody]
184
+ * @returns {Response<ResponseErrorType>}
185
+ */
186
+ static BadRequestResponse(msg?: string, errCode?: string, optBody?: any): Response<ResponseErrorType>;
187
+ /**
188
+ * ${1:Description placeholder}
189
+ *
190
+ * @public
191
+ * @static
192
+ * @param {string} msg
193
+ * @param {?string} [errCode]
194
+ * @param {?*} [optBody]
195
+ * @returns {Response<ResponseErrorType>}
196
+ */
197
+ static BadRequestResponseWithRollback(msg: string, errCode?: string, optBody?: any): Response<ResponseErrorType>;
198
+ /**
199
+ * ${1:Description placeholder}
200
+ *
201
+ * @public
202
+ * @static
203
+ * @param {string} msg
204
+ * @param {?string} [errCode]
205
+ * @returns {Response<ResponseErrorType>}
206
+ */
207
+ static UnauthorizedResponse(msg: string, errCode?: string): Response<ResponseErrorType>;
208
+ /**
209
+ * ${1:Description placeholder}
210
+ *
211
+ * @public
212
+ * @static
213
+ * @template BodyType
214
+ * @param {BodyType} body
215
+ * @returns {Response<BodyType>}
216
+ */
217
+ static SuccessResponse<BodyType>(body: BodyType): Response<BodyType>;
218
+ /**
219
+ * ${1:Description placeholder}
220
+ *
221
+ * @public
222
+ * @static
223
+ * @param {string} url
224
+ * @returns {Response<null>}
225
+ */
226
+ static RedirectResponse(url: string): Response<null>;
227
+ /**
228
+ * ${1:Description placeholder}
229
+ *
230
+ * @public
231
+ * @static
232
+ * @returns {Response<null>}
233
+ */
234
+ static SuccessNoContentResponse(): Response<null>;
235
+ /**
236
+ * ${1:Description placeholder}
237
+ *
238
+ * @public
239
+ * @static
240
+ * @param {*} stream
241
+ * @param {string} contentType
242
+ * @returns {Response}
243
+ */
244
+ static SuccessStreamResponse(stream: any, contentType: string): Response;
245
+ /**
246
+ * ${1:Description placeholder}
247
+ *
248
+ * @public
249
+ * @static
250
+ * @template BodyType
251
+ * @param {BodyType} body
252
+ * @param {?number} [optionalCode]
253
+ * @returns {Response<BodyType>}
254
+ */
255
+ static SimpleResponse<BodyType>(body: BodyType, optionalCode?: number): Response<BodyType>;
256
+ }
@@ -0,0 +1,398 @@
1
+ "use strict";
2
+ var __extends = (this && this.__extends) || (function () {
3
+ var extendStatics = function (d, b) {
4
+ extendStatics = Object.setPrototypeOf ||
5
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
+ return extendStatics(d, b);
8
+ };
9
+ return function (d, b) {
10
+ if (typeof b !== "function" && b !== null)
11
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
+ extendStatics(d, b);
13
+ function __() { this.constructor = d; }
14
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
+ };
16
+ })();
17
+ var __assign = (this && this.__assign) || function () {
18
+ __assign = Object.assign || function(t) {
19
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
20
+ s = arguments[i];
21
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
22
+ t[p] = s[p];
23
+ }
24
+ return t;
25
+ };
26
+ return __assign.apply(this, arguments);
27
+ };
28
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
29
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
30
+ return new (P || (P = Promise))(function (resolve, reject) {
31
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
32
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
33
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
34
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
35
+ });
36
+ };
37
+ var __generator = (this && this.__generator) || function (thisArg, body) {
38
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
39
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
40
+ function verb(n) { return function (v) { return step([n, v]); }; }
41
+ function step(op) {
42
+ if (f) throw new TypeError("Generator is already executing.");
43
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
44
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
45
+ if (y = 0, t) op = [op[0] & 2, t.value];
46
+ switch (op[0]) {
47
+ case 0: case 1: t = op; break;
48
+ case 4: _.label++; return { value: op[1], done: false };
49
+ case 5: _.label++; y = op[1]; op = [0]; continue;
50
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
51
+ default:
52
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
53
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
54
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
55
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
56
+ if (t[2]) _.ops.pop();
57
+ _.trys.pop(); continue;
58
+ }
59
+ op = body.call(thisArg, _);
60
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
61
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
62
+ }
63
+ };
64
+ Object.defineProperty(exports, "__esModule", { value: true });
65
+ var Globals_1 = require("../Globals");
66
+ //
67
+ /**
68
+ * ${1:Description placeholder}
69
+ *
70
+ * @class CustomError
71
+ * @typedef {CustomError}
72
+ * @extends {Error}
73
+ */
74
+ var CustomError = /** @class */ (function (_super) {
75
+ __extends(CustomError, _super);
76
+ /**
77
+ * Creates an instance of CustomError.
78
+ *
79
+ * @constructor
80
+ * @param {*} body
81
+ */
82
+ function CustomError(body) {
83
+ var _this = _super.call(this, body.message || 'Unknown error!') || this;
84
+ _this.name = body.error || 'UnknownError';
85
+ return _this;
86
+ }
87
+ return CustomError;
88
+ }(Error));
89
+ //
90
+ /**
91
+ * ${1:Description placeholder}
92
+ *
93
+ * @export
94
+ * @class Response
95
+ * @typedef {Response}
96
+ * @template [BodyType=null]
97
+ */
98
+ var Response = /** @class */ (function () {
99
+ //
100
+ /**
101
+ * Creates an instance of Response.
102
+ *
103
+ * @constructor
104
+ * @param {number} statusCode
105
+ * @param {BodyType} body
106
+ * @param {?(| {
107
+ * shouldStream?: boolean
108
+ * rawBody?: boolean
109
+ * throwOnErrors?: boolean
110
+ * disableTransactionID?: boolean
111
+ * }
112
+ * | undefined)\} [optBehaviour]
113
+ */
114
+ function Response(statusCode, body, optBehaviour) {
115
+ // response
116
+ this._statusCode = statusCode;
117
+ this._body = body;
118
+ this._headers = {
119
+ 'Access-Control-Allow-Origin': '*',
120
+ 'Access-Control-Allow-Credentials': true,
121
+ 'Content-Type': 'application/json',
122
+ };
123
+ // behaviour
124
+ this._isPipingOut = false; //internal -- flag to indicate streaming out has started and avoid double stream call
125
+ // options
126
+ this.shouldStream = !!(optBehaviour === null || optBehaviour === void 0 ? void 0 : optBehaviour.shouldStream); //
127
+ this.rawBody = !!(optBehaviour === null || optBehaviour === void 0 ? void 0 : optBehaviour.rawBody);
128
+ this.throwOnErrors = !!(optBehaviour === null || optBehaviour === void 0 ? void 0 : optBehaviour.throwOnErrors);
129
+ this.disableTransactionID = !!(optBehaviour === null || optBehaviour === void 0 ? void 0 : optBehaviour.disableTransactionID);
130
+ }
131
+ /**
132
+ * ${1:Description placeholder}
133
+ *
134
+ * @public
135
+ * @returns {number}
136
+ */
137
+ Response.prototype.getCode = function () {
138
+ return this._statusCode;
139
+ };
140
+ /**
141
+ * ${1:Description placeholder}
142
+ *
143
+ * @public
144
+ * @returns {BodyType}
145
+ */
146
+ Response.prototype.getBody = function () {
147
+ return this._body;
148
+ };
149
+ /**
150
+ * ${1:Description placeholder}
151
+ *
152
+ * @public
153
+ * @param {string} key
154
+ * @param {*} value
155
+ */
156
+ Response.prototype.appendIntoBody = function (key, value) {
157
+ this._body[key] = value;
158
+ };
159
+ /**
160
+ * ${1:Description placeholder}
161
+ *
162
+ * @public
163
+ * @param {string} key
164
+ * @param {*} value
165
+ */
166
+ Response.prototype.appendHeader = function (key, value) {
167
+ this._headers[key] = value;
168
+ };
169
+ /**
170
+ * ${1:Description placeholder}
171
+ *
172
+ * @public
173
+ * @async
174
+ * @param {Context} context
175
+ * @param {Transaction<any, any, any>} transaction
176
+ * @param {boolean} _optDoNotCallContext
177
+ * @returns {Promise<void>}
178
+ */
179
+ Response.prototype.build = function (context, transaction, _optDoNotCallContext) {
180
+ return __awaiter(this, void 0, void 0, function () {
181
+ var b;
182
+ return __generator(this, function (_a) {
183
+ switch (_a.label) {
184
+ case 0:
185
+ //Stream support
186
+ if (this._isPipingOut)
187
+ return [2 /*return*/];
188
+ if (this.shouldStream)
189
+ return [2 /*return*/, this._pipe(context)
190
+ //append default fields
191
+ ];
192
+ //append default fields
193
+ if (transaction.request.getRequestID() && this._body && !this.disableTransactionID)
194
+ this.appendIntoBody('transactionID', transaction.request.getRequestID()); //append transaction ID
195
+ //Raw response support
196
+ if (this.rawBody)
197
+ return [2 /*return*/, this._rawContext(context, transaction)
198
+ //build response
199
+ ];
200
+ b = __assign({ statusCode: this._statusCode, headers: this._headers }, (this._body ? { body: JSON.stringify(this._body) } : {}));
201
+ //log response and respond to context
202
+ transaction.logger.debug(b);
203
+ if (!transaction.responseProxy) return [3 /*break*/, 2];
204
+ return [4 /*yield*/, transaction.responseProxy(this)
205
+ //Batch does not succeed directly just on upper transaction (which will should be a batch)
206
+ ];
207
+ case 1:
208
+ _a.sent();
209
+ _a.label = 2;
210
+ case 2:
211
+ //Batch does not succeed directly just on upper transaction (which will should be a batch)
212
+ if (!_optDoNotCallContext)
213
+ context.succeed(b);
214
+ return [2 /*return*/];
215
+ }
216
+ });
217
+ });
218
+ };
219
+ /**
220
+ * ${1:Description placeholder}
221
+ *
222
+ * @private
223
+ * @param {Context} context
224
+ */
225
+ Response.prototype._pipe = function (context) {
226
+ //Check if not streaming
227
+ this._isPipingOut = true;
228
+ //build response
229
+ var b = {
230
+ statusCode: this._statusCode,
231
+ body: this._body,
232
+ headers: this._headers,
233
+ };
234
+ //log response and respond to context
235
+ context.succeed(b);
236
+ };
237
+ /**
238
+ * ${1:Description placeholder}
239
+ *
240
+ * @private
241
+ * @param {Context} context
242
+ * @param {Transaction<null, BodyType>} transaction
243
+ */
244
+ Response.prototype._rawContext = function (context, transaction) {
245
+ //log response and respond to context
246
+ transaction.logger.debug(this._body);
247
+ if (this.getCode() <= 200 && this.getCode() <= 299)
248
+ context.succeed(this._body);
249
+ else {
250
+ if (!this.throwOnErrors)
251
+ context.fail(new CustomError(this._body));
252
+ else
253
+ throw new CustomError(this._body);
254
+ }
255
+ };
256
+ /* Shortcuts */
257
+ /**
258
+ * ${1:Description placeholder}
259
+ *
260
+ * @public
261
+ * @static
262
+ * @param {string} paramName
263
+ * @returns {Response<ResponseErrorType>}
264
+ */
265
+ Response.MissingParamResponse = function (paramName) {
266
+ console.warn("Invalid request - Path parameter ".concat(paramName, " is missing."));
267
+ return new Response(400, {
268
+ err: "Invalid request. Path parameter ".concat(paramName, " is missing."),
269
+ errCode: Globals_1.default.ErrorCode_MissingParam,
270
+ });
271
+ };
272
+ /**
273
+ * ${1:Description placeholder}
274
+ *
275
+ * @public
276
+ * @static
277
+ * @param {string} paramName
278
+ * @returns {Response<ResponseErrorType>}
279
+ */
280
+ Response.MissingQueryResponse = function (paramName) {
281
+ console.warn("Invalid request - Query parameter ".concat(paramName, " is missing."));
282
+ return new Response(400, {
283
+ err: "Invalid request. Query parameter ".concat(paramName, " is missing."),
284
+ errCode: Globals_1.default.ErrorCode_MissingParam,
285
+ });
286
+ };
287
+ /**
288
+ * ${1:Description placeholder}
289
+ *
290
+ * @public
291
+ * @static
292
+ * @param {?string} [msg]
293
+ * @param {?string} [errCode]
294
+ * @param {?*} [optBody]
295
+ * @returns {Response<ResponseErrorType>}
296
+ */
297
+ Response.BadRequestResponse = function (msg, errCode, optBody) {
298
+ console.warn("Bad request - ".concat(msg));
299
+ return new Response(400, __assign(__assign({ err: msg }, (errCode ? { errCode: errCode } : {})), (optBody || {})));
300
+ };
301
+ /**
302
+ * ${1:Description placeholder}
303
+ *
304
+ * @public
305
+ * @static
306
+ * @param {string} msg
307
+ * @param {?string} [errCode]
308
+ * @param {?*} [optBody]
309
+ * @returns {Response<ResponseErrorType>}
310
+ */
311
+ Response.BadRequestResponseWithRollback = function (msg, errCode, optBody) {
312
+ console.warn("Bad request - ".concat(msg));
313
+ return new Response(400, __assign(__assign({ err: msg, rollback: true }, (errCode ? { errCode: errCode } : {})), (optBody || {})));
314
+ };
315
+ /**
316
+ * ${1:Description placeholder}
317
+ *
318
+ * @public
319
+ * @static
320
+ * @param {string} msg
321
+ * @param {?string} [errCode]
322
+ * @returns {Response<ResponseErrorType>}
323
+ */
324
+ Response.UnauthorizedResponse = function (msg, errCode) {
325
+ console.warn("Denying request - ".concat(msg));
326
+ return new Response(401, __assign({ err: msg }, (errCode ? { errCode: errCode } : {})));
327
+ };
328
+ /**
329
+ * ${1:Description placeholder}
330
+ *
331
+ * @public
332
+ * @static
333
+ * @template BodyType
334
+ * @param {BodyType} body
335
+ * @returns {Response<BodyType>}
336
+ */
337
+ Response.SuccessResponse = function (body) {
338
+ return new Response(200, (body ? body : {}));
339
+ };
340
+ /**
341
+ * ${1:Description placeholder}
342
+ *
343
+ * @public
344
+ * @static
345
+ * @param {string} url
346
+ * @returns {Response<null>}
347
+ */
348
+ Response.RedirectResponse = function (url) {
349
+ var resp = new Response(302, null);
350
+ resp.appendHeader('Location', url);
351
+ return resp;
352
+ };
353
+ /**
354
+ * ${1:Description placeholder}
355
+ *
356
+ * @public
357
+ * @static
358
+ * @returns {Response<null>}
359
+ */
360
+ Response.SuccessNoContentResponse = function () {
361
+ return new Response(204, null);
362
+ };
363
+ /**
364
+ * ${1:Description placeholder}
365
+ *
366
+ * @public
367
+ * @static
368
+ * @param {*} stream
369
+ * @param {string} contentType
370
+ * @returns {Response}
371
+ */
372
+ Response.SuccessStreamResponse = function (stream, contentType) {
373
+ var resp = new Response(200, stream, {
374
+ shouldStream: true,
375
+ });
376
+ resp.appendHeader('Connection', 'keep-alive');
377
+ if (contentType)
378
+ resp.appendHeader('Content-Type', contentType);
379
+ return resp;
380
+ };
381
+ /**
382
+ * ${1:Description placeholder}
383
+ *
384
+ * @public
385
+ * @static
386
+ * @template BodyType
387
+ * @param {BodyType} body
388
+ * @param {?number} [optionalCode]
389
+ * @returns {Response<BodyType>}
390
+ */
391
+ Response.SimpleResponse = function (body, optionalCode) {
392
+ var resp = new Response(optionalCode || 200, body);
393
+ return resp;
394
+ };
395
+ return Response;
396
+ }());
397
+ exports.default = Response;
398
+ //# sourceMappingURL=Response.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Response.js","sourceRoot":"","sources":["../../../src/API/Response.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAGA,sCAAgC;AAChC,EAAE;A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