@furystack/rest-service 7.0.0 → 7.0.2
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/{types → esm}/actions/error-action.d.ts +1 -1
- package/{types → esm}/actions/error-action.d.ts.map +1 -1
- package/esm/actions/error-action.js +25 -0
- package/esm/actions/error-action.js.map +1 -0
- package/{types → esm}/actions/get-current-user.d.ts +1 -1
- package/{types → esm}/actions/get-current-user.d.ts.map +1 -1
- package/esm/actions/get-current-user.js +12 -0
- package/esm/actions/get-current-user.js.map +1 -0
- package/esm/actions/index.d.ts +7 -0
- package/esm/actions/index.d.ts.map +1 -0
- package/esm/actions/index.js +7 -0
- package/esm/actions/index.js.map +1 -0
- package/{types → esm}/actions/is-authenticated.d.ts +1 -1
- package/{types → esm}/actions/is-authenticated.d.ts.map +1 -1
- package/esm/actions/is-authenticated.js +13 -0
- package/esm/actions/is-authenticated.js.map +1 -0
- package/{types → esm}/actions/login.d.ts +2 -2
- package/esm/actions/login.d.ts.map +1 -0
- package/esm/actions/login.js +22 -0
- package/esm/actions/login.js.map +1 -0
- package/{types → esm}/actions/logout.d.ts +1 -1
- package/{types → esm}/actions/logout.d.ts.map +1 -1
- package/esm/actions/logout.js +15 -0
- package/esm/actions/logout.js.map +1 -0
- package/{types → esm}/actions/not-found-action.d.ts +1 -1
- package/{types → esm}/actions/not-found-action.d.ts.map +1 -1
- package/esm/actions/not-found-action.js +10 -0
- package/esm/actions/not-found-action.js.map +1 -0
- package/{types → esm}/api-manager.d.ts +4 -4
- package/{types → esm}/api-manager.d.ts.map +1 -1
- package/esm/api-manager.js +153 -0
- package/esm/api-manager.js.map +1 -0
- package/{types → esm}/authenticate.d.ts +1 -1
- package/{types → esm}/authenticate.d.ts.map +1 -1
- package/esm/authenticate.js +16 -0
- package/esm/authenticate.js.map +1 -0
- package/{types → esm}/authorize.d.ts +1 -1
- package/{types → esm}/authorize.d.ts.map +1 -1
- package/esm/authorize.js +19 -0
- package/esm/authorize.js.map +1 -0
- package/{types → esm}/endpoint-generators/create-delete-endpoint.d.ts +1 -1
- package/{types → esm}/endpoint-generators/create-delete-endpoint.d.ts.map +1 -1
- package/esm/endpoint-generators/create-delete-endpoint.js +20 -0
- package/esm/endpoint-generators/create-delete-endpoint.js.map +1 -0
- package/{types → esm}/endpoint-generators/create-get-collection-endpoint.d.ts +1 -1
- package/{types → esm}/endpoint-generators/create-get-collection-endpoint.d.ts.map +1 -1
- package/esm/endpoint-generators/create-get-collection-endpoint.js +22 -0
- package/esm/endpoint-generators/create-get-collection-endpoint.js.map +1 -0
- package/{types → esm}/endpoint-generators/create-get-entity-endpoint.d.ts +1 -1
- package/{types → esm}/endpoint-generators/create-get-entity-endpoint.d.ts.map +1 -1
- package/esm/endpoint-generators/create-get-entity-endpoint.js +25 -0
- package/esm/endpoint-generators/create-get-entity-endpoint.js.map +1 -0
- package/{types → esm}/endpoint-generators/create-patch-endpoint.d.ts +1 -1
- package/{types → esm}/endpoint-generators/create-patch-endpoint.d.ts.map +1 -1
- package/esm/endpoint-generators/create-patch-endpoint.js +22 -0
- package/esm/endpoint-generators/create-patch-endpoint.js.map +1 -0
- package/{types → esm}/endpoint-generators/create-post-endpoint.d.ts +1 -1
- package/{types → esm}/endpoint-generators/create-post-endpoint.d.ts.map +1 -1
- package/esm/endpoint-generators/create-post-endpoint.js +25 -0
- package/esm/endpoint-generators/create-post-endpoint.js.map +1 -0
- package/esm/endpoint-generators/index.d.ts +6 -0
- package/{types → esm}/endpoint-generators/index.d.ts.map +1 -1
- package/esm/endpoint-generators/index.js +6 -0
- package/esm/endpoint-generators/index.js.map +1 -0
- package/esm/endpoint-generators/utils.js +23 -0
- package/esm/endpoint-generators/utils.js.map +1 -0
- package/{types → esm}/helpers.d.ts +4 -4
- package/esm/helpers.d.ts.map +1 -0
- package/esm/helpers.js +28 -0
- package/esm/helpers.js.map +1 -0
- package/{types → esm}/http-authentication-settings.d.ts +1 -1
- package/{types → esm}/http-authentication-settings.d.ts.map +1 -1
- package/esm/http-authentication-settings.js +26 -0
- package/esm/http-authentication-settings.js.map +1 -0
- package/{types → esm}/http-user-context.d.ts +2 -2
- package/{types → esm}/http-user-context.d.ts.map +1 -1
- package/esm/http-user-context.js +168 -0
- package/esm/http-user-context.js.map +1 -0
- package/esm/incoming-message-extensions.js +11 -0
- package/esm/incoming-message-extensions.js.map +1 -0
- package/esm/index.d.ts +19 -0
- package/esm/index.d.ts.map +1 -0
- package/esm/index.js +19 -0
- package/esm/index.js.map +1 -0
- package/esm/mime-types.js +333 -0
- package/esm/mime-types.js.map +1 -0
- package/esm/models/cors-options.js +2 -0
- package/esm/models/cors-options.js.map +1 -0
- package/esm/models/default-session.js +6 -0
- package/esm/models/default-session.js.map +1 -0
- package/esm/models/index.d.ts +3 -0
- package/esm/models/index.d.ts.map +1 -0
- package/esm/models/index.js +3 -0
- package/esm/models/index.js.map +1 -0
- package/esm/request-action-implementation.js +34 -0
- package/esm/request-action-implementation.js.map +1 -0
- package/esm/schema-validator/index.d.ts +3 -0
- package/{types → esm}/schema-validator/index.d.ts.map +1 -1
- package/esm/schema-validator/index.js +3 -0
- package/esm/schema-validator/index.js.map +1 -0
- package/esm/schema-validator/schema-validation-error.js +11 -0
- package/esm/schema-validator/schema-validation-error.js.map +1 -0
- package/esm/schema-validator/schema-validator.js +31 -0
- package/esm/schema-validator/schema-validator.js.map +1 -0
- package/esm/schema-validator/validate-examples.js +26 -0
- package/esm/schema-validator/validate-examples.js.map +1 -0
- package/{types → esm}/server-manager.d.ts +1 -1
- package/esm/server-manager.js +73 -0
- package/esm/server-manager.js.map +1 -0
- package/{types → esm}/server-response-extensions.d.ts +1 -1
- package/{types → esm}/server-response-extensions.d.ts.map +1 -1
- package/esm/server-response-extensions.js +12 -0
- package/esm/server-response-extensions.js.map +1 -0
- package/{types → esm}/static-server-manager.d.ts +1 -1
- package/esm/static-server-manager.js +68 -0
- package/esm/static-server-manager.js.map +1 -0
- package/{types → esm}/utils.d.ts +1 -1
- package/{types → esm}/utils.d.ts.map +1 -1
- package/esm/utils.js +70 -0
- package/esm/utils.js.map +1 -0
- package/{types → esm}/validate.d.ts +1 -1
- package/{types → esm}/validate.d.ts.map +1 -1
- package/esm/validate.integration.schema.js +2 -0
- package/esm/validate.integration.schema.js.map +1 -0
- package/esm/validate.integration.spec.schema.json +903 -0
- package/esm/validate.js +43 -0
- package/esm/validate.js.map +1 -0
- package/package.json +11 -20
- package/src/actions/error-action.ts +3 -3
- package/src/actions/get-current-user.ts +3 -3
- package/src/actions/index.ts +6 -6
- package/src/actions/is-authenticated.ts +2 -2
- package/src/actions/login.ts +4 -4
- package/src/actions/logout.ts +3 -3
- package/src/actions/not-found-action.ts +2 -2
- package/src/api-manager.ts +10 -9
- package/src/authenticate.ts +3 -3
- package/src/authorize.ts +2 -2
- package/src/endpoint-generators/create-delete-endpoint.ts +2 -2
- package/src/endpoint-generators/create-get-collection-endpoint.ts +2 -2
- package/src/endpoint-generators/create-get-entity-endpoint.ts +2 -2
- package/src/endpoint-generators/create-patch-endpoint.ts +2 -2
- package/src/endpoint-generators/create-post-endpoint.ts +2 -2
- package/src/endpoint-generators/index.ts +5 -5
- package/src/endpoint-generators/utils.ts +1 -1
- package/src/helpers.ts +6 -6
- package/src/http-authentication-settings.ts +1 -1
- package/src/http-user-context.ts +2 -2
- package/src/incoming-message-extensions.ts +1 -1
- package/src/index.ts +18 -18
- package/src/models/index.ts +2 -2
- package/src/schema-validator/index.ts +2 -2
- package/src/schema-validator/schema-validator.ts +3 -3
- package/src/server-response-extensions.ts +1 -1
- package/src/static-server-manager.ts +2 -2
- package/src/utils.ts +1 -1
- package/src/validate.ts +2 -2
- package/types/actions/index.d.ts +0 -7
- package/types/actions/index.d.ts.map +0 -1
- package/types/actions/login.d.ts.map +0 -1
- package/types/endpoint-generators/index.d.ts +0 -6
- package/types/helpers.d.ts.map +0 -1
- package/types/index.d.ts +0 -19
- package/types/index.d.ts.map +0 -1
- package/types/models/index.d.ts +0 -3
- package/types/models/index.d.ts.map +0 -1
- package/types/schema-validator/index.d.ts +0 -3
- /package/{types → esm}/endpoint-generators/utils.d.ts +0 -0
- /package/{types → esm}/endpoint-generators/utils.d.ts.map +0 -0
- /package/{types → esm}/incoming-message-extensions.d.ts +0 -0
- /package/{types → esm}/incoming-message-extensions.d.ts.map +0 -0
- /package/{types → esm}/mime-types.d.ts +0 -0
- /package/{types → esm}/mime-types.d.ts.map +0 -0
- /package/{types → esm}/models/cors-options.d.ts +0 -0
- /package/{types → esm}/models/cors-options.d.ts.map +0 -0
- /package/{types → esm}/models/default-session.d.ts +0 -0
- /package/{types → esm}/models/default-session.d.ts.map +0 -0
- /package/{types → esm}/request-action-implementation.d.ts +0 -0
- /package/{types → esm}/request-action-implementation.d.ts.map +0 -0
- /package/{types → esm}/schema-validator/schema-validation-error.d.ts +0 -0
- /package/{types → esm}/schema-validator/schema-validation-error.d.ts.map +0 -0
- /package/{types → esm}/schema-validator/schema-validator.d.ts +0 -0
- /package/{types → esm}/schema-validator/schema-validator.d.ts.map +0 -0
- /package/{types → esm}/schema-validator/validate-examples.d.ts +0 -0
- /package/{types → esm}/schema-validator/validate-examples.d.ts.map +0 -0
- /package/{types → esm}/server-manager.d.ts.map +0 -0
- /package/{types → esm}/static-server-manager.d.ts.map +0 -0
- /package/{types → esm}/validate.integration.schema.d.ts +0 -0
- /package/{types → esm}/validate.integration.schema.d.ts.map +0 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server-response-extensions.d.ts","sourceRoot":"","sources":["../src/server-response-extensions.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"server-response-extensions.d.ts","sourceRoot":"","sources":["../src/server-response-extensions.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oCAAoC,CAAA;AAEtE,MAAM,WAAW,eAAe,CAAC,CAAC;IAChC,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,IAAI,EAAE,CAAC,CAAA;IACP,OAAO,CAAC,EAAE;QAAE,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAAA;KAAE,CAAA;CAClC;AACD,MAAM,WAAW,oBAAoB;IACnC,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,IAAI,EAAE,MAAM,CAAA;IACZ,OAAO,CAAC,EAAE;QAAE,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAAA;KAAE,CAAA;CAClC;AAED,OAAO,QAAQ,MAAM,CAAC;IACpB,UAAiB,cAAc;QAC7B,gBAAgB,EAAE,CAAC,CAAC,EAAE,MAAM,EAAE,YAAY,CAAC,CAAC,CAAC,KAAK,IAAI,CAAA;KACvD;CACF"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import http from 'http';
|
|
2
|
+
http.ServerResponse.prototype.sendActionResult = function (options) {
|
|
3
|
+
if (typeof options.chunk === 'object') {
|
|
4
|
+
options.chunk = JSON.stringify(options.chunk);
|
|
5
|
+
}
|
|
6
|
+
if (typeof options.chunk === 'string' && options.chunk === 'BypassResult') {
|
|
7
|
+
return;
|
|
8
|
+
}
|
|
9
|
+
this.writeHead(options.statusCode, options.headers);
|
|
10
|
+
this.end(options.chunk);
|
|
11
|
+
};
|
|
12
|
+
//# sourceMappingURL=server-response-extensions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server-response-extensions.js","sourceRoot":"","sources":["../src/server-response-extensions.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAA;AAoBvB,IAAI,CAAC,cAAc,CAAC,SAAS,CAAC,gBAAgB,GAAG,UAAa,OAAwB;IACpF,IAAI,OAAO,OAAO,CAAC,KAAK,KAAK,QAAQ,EAAE;QACrC,OAAO,CAAC,KAAK,GAAG,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,KAAK,CAAQ,CAAA;KACrD;IACD,IAAI,OAAO,OAAO,CAAC,KAAK,KAAK,QAAQ,IAAI,OAAO,CAAC,KAAK,KAAK,cAAc,EAAE;QACzE,OAAM;KACP;IACD,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,UAAU,EAAE,OAAO,CAAC,OAAO,CAAC,CAAA;IACnD,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,KAAK,CAAC,CAAA;AACzB,CAAC,CAAA"}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
8
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
|
+
};
|
|
10
|
+
import { Injectable, Injected } from '@furystack/inject';
|
|
11
|
+
import { createReadStream } from 'fs';
|
|
12
|
+
import { stat } from 'fs/promises';
|
|
13
|
+
import { getMimeForFile } from './mime-types.js';
|
|
14
|
+
import { join, normalize, sep } from 'path';
|
|
15
|
+
import { ServerManager } from './server-manager.js';
|
|
16
|
+
let StaticServerManager = class StaticServerManager {
|
|
17
|
+
constructor() {
|
|
18
|
+
this.shouldExec = (baseUrl) => ({ req }) => req.url &&
|
|
19
|
+
req.method?.toUpperCase() === 'GET' &&
|
|
20
|
+
(req.url === baseUrl || req.url.startsWith(baseUrl[baseUrl.length - 1] === '/' ? baseUrl : `${baseUrl}/`))
|
|
21
|
+
? true
|
|
22
|
+
: false;
|
|
23
|
+
this.onRequest = ({ path, baseUrl, fallback, headers, }) => {
|
|
24
|
+
return async ({ req, res }) => {
|
|
25
|
+
const filePath = req.url.substring(baseUrl.length - 1).replaceAll('/', sep);
|
|
26
|
+
const fullPath = normalize(join(path, filePath));
|
|
27
|
+
try {
|
|
28
|
+
await this.sendFile({ fullPath, res, headers });
|
|
29
|
+
}
|
|
30
|
+
catch (error) {
|
|
31
|
+
if (fallback) {
|
|
32
|
+
await this.sendFile({ fullPath: join(path, fallback), res, headers });
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
res.writeHead(404, { 'Content-Type': 'text/plain' });
|
|
36
|
+
res.end('Not found');
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
async sendFile({ fullPath, headers, res, }) {
|
|
43
|
+
const { size } = await stat(fullPath);
|
|
44
|
+
const head = {
|
|
45
|
+
...headers,
|
|
46
|
+
'Content-Length': size,
|
|
47
|
+
'Content-Type': getMimeForFile(fullPath),
|
|
48
|
+
};
|
|
49
|
+
res.writeHead(200, head);
|
|
50
|
+
await new Promise((resolve, reject) => createReadStream(fullPath, { autoClose: true }).once('finish', resolve).once('error', reject).pipe(res));
|
|
51
|
+
}
|
|
52
|
+
async addStaticSite(options) {
|
|
53
|
+
const server = await this.serverManager.getOrCreate({ hostName: options.hostName, port: options.port });
|
|
54
|
+
server.apis.push({
|
|
55
|
+
shouldExec: this.shouldExec(options.baseUrl),
|
|
56
|
+
onRequest: this.onRequest({ ...options }),
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
__decorate([
|
|
61
|
+
Injected(ServerManager),
|
|
62
|
+
__metadata("design:type", ServerManager)
|
|
63
|
+
], StaticServerManager.prototype, "serverManager", void 0);
|
|
64
|
+
StaticServerManager = __decorate([
|
|
65
|
+
Injectable({ lifetime: 'singleton' })
|
|
66
|
+
], StaticServerManager);
|
|
67
|
+
export { StaticServerManager };
|
|
68
|
+
//# sourceMappingURL=static-server-manager.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"static-server-manager.js","sourceRoot":"","sources":["../src/static-server-manager.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAA;AACxD,OAAO,EAAE,gBAAgB,EAAE,MAAM,IAAI,CAAA;AACrC,OAAO,EAAE,IAAI,EAAE,MAAM,aAAa,CAAA;AAElC,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAA;AAChD,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,GAAG,EAAE,MAAM,MAAM,CAAA;AAC3C,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAA;AAYnD,IAAa,mBAAmB,GAAhC,MAAa,mBAAmB;IAAhC;QA2BS,eAAU,GACf,CAAC,OAAe,EAAE,EAAE,CACpB,CAAC,EAAE,GAAG,EAAoD,EAAE,EAAE,CAC5D,GAAG,CAAC,GAAG;YACP,GAAG,CAAC,MAAM,EAAE,WAAW,EAAE,KAAK,KAAK;YACnC,CAAC,GAAG,CAAC,GAAG,KAAK,OAAO,IAAI,GAAG,CAAC,GAAG,CAAC,UAAU,CAAC,OAAO,CAAC,OAAO,CAAC,MAAM,GAAG,CAAC,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,GAAG,CAAC,CAAC;YACxG,CAAC,CAAC,IAAI;YACN,CAAC,CAAC,KAAK,CAAA;QAEL,cAAS,GAAG,CAAC,EACnB,IAAI,EACJ,OAAO,EACP,QAAQ,EACR,OAAO,GAMR,EAAE,EAAE;YACH,OAAO,KAAK,EAAE,EAAE,GAAG,EAAE,GAAG,EAAiD,EAAE,EAAE;gBAC3E,MAAM,QAAQ,GAAI,GAAG,CAAC,GAAc,CAAC,SAAS,CAAC,OAAO,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,UAAU,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;IAuCM,KAAK,CAAC,aAAa,CAAC,OAA4B;QACrD,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,aAAa,CAAC,WAAW,CAAC,EAAE,QAAQ,EAAE,OAAO,CAAC,QAAQ,EAAE,IAAI,EAAE,OAAO,CAAC,IAAI,EAAE,CAAC,CAAA;QAEvG,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC;YACf,UAAU,EAAE,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,OAAO,CAAC;YAC5C,SAAS,EAAE,IAAI,CAAC,SAAS,CAAC,EAAE,GAAG,OAAO,EAAE,CAAC;SAC1C,CAAC,CAAA;IACJ,CAAC;CACF,CAAA;AAtEkB;IADhB,QAAQ,CAAC,aAAa,CAAC;8BACS,aAAa;0DAAA;AAFnC,mBAAmB;IAD/B,UAAU,CAAC,EAAE,QAAQ,EAAE,WAAW,EAAE,CAAC;GACzB,mBAAmB,CAwE/B;SAxEY,mBAAmB"}
|
package/{types → esm}/utils.d.ts
RENAMED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,MAAM,CAAA;AAE3D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,MAAM,CAAA;AAE3D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAA;AAE3D;;GAEG;AACH,qBACa,KAAK;IACH,eAAe,CAAC,eAAe,EAAE,eAAe;IAuB7D;;;;OAIG;IACU,YAAY,CAAC,CAAC,EAAE,eAAe,EAAE,eAAe,GAAG,OAAO,CAAC,CAAC,CAAC;IAM1E;;;;;OAKG;IACI,cAAc,CAAC,OAAO,EAAE,WAAW,EAAE,eAAe,EAAE,eAAe,EAAE,cAAc,EAAE,cAAc;CAkB7G"}
|
package/esm/utils.js
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
import { Injectable } from '@furystack/inject';
|
|
8
|
+
/**
|
|
9
|
+
* A collection of various HTTP API related utilities
|
|
10
|
+
*/
|
|
11
|
+
let Utils = class Utils {
|
|
12
|
+
async readPostBodyRaw(incomingMessage) {
|
|
13
|
+
if (!incomingMessage.readable) {
|
|
14
|
+
throw Error('Incoming message is not readable');
|
|
15
|
+
}
|
|
16
|
+
let body = '';
|
|
17
|
+
await new Promise((resolve, reject) => {
|
|
18
|
+
incomingMessage.on('readable', () => {
|
|
19
|
+
const data = incomingMessage.read();
|
|
20
|
+
if (data) {
|
|
21
|
+
body += data;
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
incomingMessage.on('end', () => {
|
|
25
|
+
resolve();
|
|
26
|
+
});
|
|
27
|
+
incomingMessage.on('error', (err) => {
|
|
28
|
+
reject(err);
|
|
29
|
+
});
|
|
30
|
+
});
|
|
31
|
+
return body;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Reads the post's body and returns a promise with a parsed value
|
|
35
|
+
* @param incomingMessage The incoming message instance
|
|
36
|
+
* @returns the parsed object from the post body
|
|
37
|
+
*/
|
|
38
|
+
async readPostBody(incomingMessage) {
|
|
39
|
+
const body = incomingMessage.postBody || JSON.parse(await this.readPostBodyRaw(incomingMessage));
|
|
40
|
+
incomingMessage.postBody = body;
|
|
41
|
+
return body;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Adds the specified CORS headers to the response
|
|
45
|
+
* @param options The CORS Options object
|
|
46
|
+
* @param incomingMessage The incoming message instance
|
|
47
|
+
* @param serverResponse The outgoing response instance
|
|
48
|
+
*/
|
|
49
|
+
addCorsHeaders(options, incomingMessage, serverResponse) {
|
|
50
|
+
if (incomingMessage.headers &&
|
|
51
|
+
incomingMessage.headers.origin !== incomingMessage.headers.host &&
|
|
52
|
+
options.origins.some((origin) => origin === incomingMessage.headers.origin)) {
|
|
53
|
+
serverResponse.setHeader('Access-Control-Allow-Origin', incomingMessage.headers.origin);
|
|
54
|
+
if (options.credentials) {
|
|
55
|
+
serverResponse.setHeader('Access-Control-Allow-Credentials', 'true');
|
|
56
|
+
}
|
|
57
|
+
if (options.headers && options.headers.length) {
|
|
58
|
+
serverResponse.setHeader('Access-Control-Allow-Headers', options.headers.join(', '));
|
|
59
|
+
}
|
|
60
|
+
if (options.methods && options.methods.length) {
|
|
61
|
+
serverResponse.setHeader('Access-Control-Allow-Methods', options.methods.join(', '));
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
Utils = __decorate([
|
|
67
|
+
Injectable({ lifetime: 'transient' })
|
|
68
|
+
], Utils);
|
|
69
|
+
export { Utils };
|
|
70
|
+
//# sourceMappingURL=utils.js.map
|
package/esm/utils.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":";;;;;;AACA,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAA;AAG9C;;GAEG;AAEH,IAAa,KAAK,GAAlB,MAAa,KAAK;IACT,KAAK,CAAC,eAAe,CAAC,eAAgC;QAC3D,IAAI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AAC,SAAS,CAAC,6BAA6B,EAAE,eAAe,CAAC,OAAO,CAAC,MAAgB,CAAC,CAAA;YACjG,IAAI,OAAO,CAAC,WAAW,EAAE;gBACvB,cAAc,CAAC,SAAS,CAAC,kCAAkC,EAAE,MAAM,CAAC,CAAA;aACrE;YACD,IAAI,OAAO,CAAC,OAAO,IAAI,OAAO,CAAC,OAAO,CAAC,MAAM,EAAE;gBAC7C,cAAc,CAAC,SAAS,CAAC,8BAA8B,EAAE,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAA;aACrF;YACD,IAAI,OAAO,CAAC,OAAO,IAAI,OAAO,CAAC,OAAO,CAAC,MAAM,EAAE;gBAC7C,cAAc,CAAC,SAAS,CAAC,8BAA8B,EAAE,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAA;aACrF;SACF;IACH,CAAC;CACF,CAAA;AA3DY,KAAK;IADjB,UAAU,CAAC,EAAE,QAAQ,EAAE,WAAW,EAAE,CAAC;GACzB,KAAK,CA2DjB;SA3DY,KAAK"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validate.d.ts","sourceRoot":"","sources":["../src/validate.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAgB,aAAa,EAAwB,MAAM,
|
|
1
|
+
{"version":3,"file":"validate.d.ts","sourceRoot":"","sources":["../src/validate.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAgB,aAAa,EAAwB,MAAM,oCAAoC,CAAA;AAG3G,eAAO,MAAM,QAAQ;;;;;IAEjB;;OAEG;;IAEH;;OAEG;;;YAGgB,GAAG;gDA6CvB,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validate.integration.schema.js","sourceRoot":"","sources":["../src/validate.integration.schema.ts"],"names":[],"mappings":""}
|