oc 0.50.57 → 0.50.59
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/.turbo/turbo-build.log +4 -4
- package/.turbo/turbo-test-silent.log +7 -7
- package/.turbo/turbo-test.log +1750 -1748
- package/CHANGELOG.md +20 -0
- package/dist/cli/facade/dev.d.ts +2 -140
- package/dist/components/oc-client/_package/package.json +4 -4
- package/dist/components/oc-client/_package/server.js +1 -1
- package/dist/components/oc-client/package.json +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/registry/domain/events-handler.d.ts +1 -0
- package/dist/registry/domain/events-handler.js +3 -0
- package/dist/registry/domain/extract-package.d.ts +3 -2
- package/dist/registry/domain/http-server/express-adapter.d.ts +3 -0
- package/dist/registry/domain/http-server/express-adapter.js +202 -0
- package/dist/registry/domain/http-server/types.d.ts +108 -0
- package/dist/registry/domain/http-server/types.js +2 -0
- package/dist/registry/domain/nested-renderer.js +16 -16
- package/dist/registry/domain/options-sanitiser.d.ts +3 -2
- package/dist/registry/domain/options-sanitiser.js +13 -0
- package/dist/registry/domain/server-adapter.d.ts +4 -0
- package/dist/registry/domain/server-adapter.js +20 -0
- package/dist/registry/domain/validators/plugins-requirements.d.ts +1 -1
- package/dist/registry/domain/validators/plugins-requirements.js +4 -2
- package/dist/registry/domain/validators/uploaded-package.d.ts +5 -4
- package/dist/registry/domain/version-handler.js +8 -6
- package/dist/registry/index.d.ts +10 -68
- package/dist/registry/index.js +14 -16
- package/dist/registry/middleware/base-url-handler.d.ts +3 -2
- package/dist/registry/middleware/base-url-handler.js +3 -4
- package/dist/registry/middleware/compression.d.ts +2 -2
- package/dist/registry/middleware/compression.js +1 -1
- package/dist/registry/middleware/cors.d.ts +3 -2
- package/dist/registry/middleware/cors.js +7 -8
- package/dist/registry/middleware/discovery-handler.d.ts +3 -2
- package/dist/registry/middleware/discovery-handler.js +3 -4
- package/dist/registry/middleware/index.d.ts +2 -2
- package/dist/registry/middleware/index.js +42 -36
- package/dist/registry/router.d.ts +2 -2
- package/dist/registry/router.js +33 -27
- package/dist/registry/routes/component-info.d.ts +2 -2
- package/dist/registry/routes/component-info.js +1 -1
- package/dist/registry/routes/component-preview.d.ts +2 -2
- package/dist/registry/routes/component.d.ts +2 -2
- package/dist/registry/routes/component.js +3 -5
- package/dist/registry/routes/components.d.ts +2 -2
- package/dist/registry/routes/components.js +23 -22
- package/dist/registry/routes/dependencies.d.ts +2 -2
- package/dist/registry/routes/helpers/get-component-fallback.d.ts +3 -3
- package/dist/registry/routes/helpers/get-component.d.ts +2 -1
- package/dist/registry/routes/helpers/get-component.js +121 -62
- package/dist/registry/routes/history.d.ts +2 -2
- package/dist/registry/routes/history.js +1 -1
- package/dist/registry/routes/index.d.ts +2 -2
- package/dist/registry/routes/plugins.d.ts +2 -2
- package/dist/registry/routes/publish.d.ts +2 -2
- package/dist/registry/routes/static-redirector.d.ts +3 -2
- package/dist/registry/routes/static-redirector.js +8 -12
- package/dist/registry/routes/validate.d.ts +2 -2
- package/dist/types.d.ts +9 -1
- package/package.json +7 -7
- package/dist/registry/middleware/file-uploads.d.ts +0 -2
- package/dist/registry/middleware/file-uploads.js +0 -23
- package/dist/registry/middleware/request-handler.d.ts +0 -2
- package/dist/registry/middleware/request-handler.js +0 -30
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,25 @@
|
|
|
1
1
|
## Change Log
|
|
2
2
|
|
|
3
|
+
## 0.50.59
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- adae2e2: remove final slash on oc.build
|
|
8
|
+
- Updated dependencies [adae2e2]
|
|
9
|
+
- oc-client-browser@2.1.12
|
|
10
|
+
|
|
11
|
+
## 0.50.58
|
|
12
|
+
|
|
13
|
+
### Patch Changes
|
|
14
|
+
|
|
15
|
+
- 7a8173d: update oc-client-browser
|
|
16
|
+
|
|
17
|
+
## 0.50.57
|
|
18
|
+
|
|
19
|
+
### Patch Changes
|
|
20
|
+
|
|
21
|
+
- e3dce96: export types for http adapters
|
|
22
|
+
|
|
3
23
|
## 0.50.56
|
|
4
24
|
|
|
5
25
|
### Patch Changes
|
package/dist/cli/facade/dev.d.ts
CHANGED
|
@@ -17,76 +17,7 @@ declare const dev: ({ local, logger }: {
|
|
|
17
17
|
watch?: boolean;
|
|
18
18
|
verbose?: boolean;
|
|
19
19
|
production?: boolean;
|
|
20
|
-
}): Promise<
|
|
21
|
-
close: (callback: (err?: Error | undefined | string) => void) => void;
|
|
22
|
-
on: <T extends keyof {
|
|
23
|
-
error: {
|
|
24
|
-
code: string;
|
|
25
|
-
message: string;
|
|
26
|
-
};
|
|
27
|
-
start: unknown;
|
|
28
|
-
'cache-poll': number;
|
|
29
|
-
request: import("../../registry/domain/events-handler").RequestData;
|
|
30
|
-
'component-retrieved': {
|
|
31
|
-
headers: import("node:http").IncomingHttpHeaders;
|
|
32
|
-
name: string;
|
|
33
|
-
parameters: import("node:http").IncomingHttpHeaders;
|
|
34
|
-
requestVersion: string;
|
|
35
|
-
duration: number;
|
|
36
|
-
};
|
|
37
|
-
'data-provider-error': {
|
|
38
|
-
name: string;
|
|
39
|
-
version: string;
|
|
40
|
-
parameters: Record<string, string | boolean | number>;
|
|
41
|
-
requestVersion: string;
|
|
42
|
-
status: number;
|
|
43
|
-
error: Error;
|
|
44
|
-
};
|
|
45
|
-
'component-published': {
|
|
46
|
-
componentName: string;
|
|
47
|
-
componentVersion: string;
|
|
48
|
-
packageJson: import("../../types").Component;
|
|
49
|
-
componentFolder: string;
|
|
50
|
-
user?: string;
|
|
51
|
-
};
|
|
52
|
-
}>(eventName: T, listener: (data: {
|
|
53
|
-
error: {
|
|
54
|
-
code: string;
|
|
55
|
-
message: string;
|
|
56
|
-
};
|
|
57
|
-
start: unknown;
|
|
58
|
-
'cache-poll': number;
|
|
59
|
-
request: import("../../registry/domain/events-handler").RequestData;
|
|
60
|
-
'component-retrieved': {
|
|
61
|
-
headers: import("node:http").IncomingHttpHeaders;
|
|
62
|
-
name: string;
|
|
63
|
-
parameters: import("node:http").IncomingHttpHeaders;
|
|
64
|
-
requestVersion: string;
|
|
65
|
-
duration: number;
|
|
66
|
-
};
|
|
67
|
-
'data-provider-error': {
|
|
68
|
-
name: string;
|
|
69
|
-
version: string;
|
|
70
|
-
parameters: Record<string, string | boolean | number>;
|
|
71
|
-
requestVersion: string;
|
|
72
|
-
status: number;
|
|
73
|
-
error: Error;
|
|
74
|
-
};
|
|
75
|
-
'component-published': {
|
|
76
|
-
componentName: string;
|
|
77
|
-
componentVersion: string;
|
|
78
|
-
packageJson: import("../../types").Component;
|
|
79
|
-
componentFolder: string;
|
|
80
|
-
user?: string;
|
|
81
|
-
};
|
|
82
|
-
}[T]) => void) => void;
|
|
83
|
-
register: <T = any>(plugin: oc.Plugin<T>, callback?: ((...args: any[]) => void) | undefined) => void;
|
|
84
|
-
start: (callback: (err: unknown, data?: {
|
|
85
|
-
app: import("express").Express;
|
|
86
|
-
server: import("node:http").Server;
|
|
87
|
-
} | undefined) => void) => Promise<void>;
|
|
88
|
-
app: import("express").Express;
|
|
89
|
-
}>;
|
|
20
|
+
}): Promise<oc.RegistryType<unknown>>;
|
|
90
21
|
(opts: {
|
|
91
22
|
prefix: string;
|
|
92
23
|
dirPath: string;
|
|
@@ -99,75 +30,6 @@ declare const dev: ({ local, logger }: {
|
|
|
99
30
|
watch?: boolean;
|
|
100
31
|
verbose?: boolean;
|
|
101
32
|
production?: boolean;
|
|
102
|
-
}, arguments__1: (error: unknown, value:
|
|
103
|
-
close: (callback: (err?: Error | undefined | string) => void) => void;
|
|
104
|
-
on: <T extends keyof {
|
|
105
|
-
error: {
|
|
106
|
-
code: string;
|
|
107
|
-
message: string;
|
|
108
|
-
};
|
|
109
|
-
start: unknown;
|
|
110
|
-
'cache-poll': number;
|
|
111
|
-
request: import("../../registry/domain/events-handler").RequestData;
|
|
112
|
-
'component-retrieved': {
|
|
113
|
-
headers: import("node:http").IncomingHttpHeaders;
|
|
114
|
-
name: string;
|
|
115
|
-
parameters: import("node:http").IncomingHttpHeaders;
|
|
116
|
-
requestVersion: string;
|
|
117
|
-
duration: number;
|
|
118
|
-
};
|
|
119
|
-
'data-provider-error': {
|
|
120
|
-
name: string;
|
|
121
|
-
version: string;
|
|
122
|
-
parameters: Record<string, string | boolean | number>;
|
|
123
|
-
requestVersion: string;
|
|
124
|
-
status: number;
|
|
125
|
-
error: Error;
|
|
126
|
-
};
|
|
127
|
-
'component-published': {
|
|
128
|
-
componentName: string;
|
|
129
|
-
componentVersion: string;
|
|
130
|
-
packageJson: import("../../types").Component;
|
|
131
|
-
componentFolder: string;
|
|
132
|
-
user?: string;
|
|
133
|
-
};
|
|
134
|
-
}>(eventName: T, listener: (data: {
|
|
135
|
-
error: {
|
|
136
|
-
code: string;
|
|
137
|
-
message: string;
|
|
138
|
-
};
|
|
139
|
-
start: unknown;
|
|
140
|
-
'cache-poll': number;
|
|
141
|
-
request: import("../../registry/domain/events-handler").RequestData;
|
|
142
|
-
'component-retrieved': {
|
|
143
|
-
headers: import("node:http").IncomingHttpHeaders;
|
|
144
|
-
name: string;
|
|
145
|
-
parameters: import("node:http").IncomingHttpHeaders;
|
|
146
|
-
requestVersion: string;
|
|
147
|
-
duration: number;
|
|
148
|
-
};
|
|
149
|
-
'data-provider-error': {
|
|
150
|
-
name: string;
|
|
151
|
-
version: string;
|
|
152
|
-
parameters: Record<string, string | boolean | number>;
|
|
153
|
-
requestVersion: string;
|
|
154
|
-
status: number;
|
|
155
|
-
error: Error;
|
|
156
|
-
};
|
|
157
|
-
'component-published': {
|
|
158
|
-
componentName: string;
|
|
159
|
-
componentVersion: string;
|
|
160
|
-
packageJson: import("../../types").Component;
|
|
161
|
-
componentFolder: string;
|
|
162
|
-
user?: string;
|
|
163
|
-
};
|
|
164
|
-
}[T]) => void) => void;
|
|
165
|
-
register: <T = any>(plugin: oc.Plugin<T>, callback?: ((...args: any[]) => void) | undefined) => void;
|
|
166
|
-
start: (callback: (err: unknown, data?: {
|
|
167
|
-
app: import("express").Express;
|
|
168
|
-
server: import("node:http").Server;
|
|
169
|
-
} | undefined) => void) => Promise<void>;
|
|
170
|
-
app: import("express").Express;
|
|
171
|
-
}) => void): void;
|
|
33
|
+
}, arguments__1: (error: unknown, value: oc.RegistryType<unknown>) => void): void;
|
|
172
34
|
};
|
|
173
35
|
export default dev;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "oc-client",
|
|
3
3
|
"description": "The OpenComponents client-side javascript client",
|
|
4
|
-
"version": "0.50.
|
|
4
|
+
"version": "0.50.59",
|
|
5
5
|
"repository": "https://github.com/opencomponents/oc/tree/master/components/oc-client",
|
|
6
6
|
"author": "Matteo Figus <matteofigus@gmail.com>",
|
|
7
7
|
"oc": {
|
|
@@ -23,14 +23,14 @@
|
|
|
23
23
|
],
|
|
24
24
|
"dataProvider": {
|
|
25
25
|
"type": "node.js",
|
|
26
|
-
"hashKey": "
|
|
26
|
+
"hashKey": "5ab7cad2df725598783ffb4c946d9db3fd1e65d4",
|
|
27
27
|
"src": "server.js",
|
|
28
28
|
"size": 644
|
|
29
29
|
}
|
|
30
30
|
},
|
|
31
|
-
"version": "0.50.
|
|
31
|
+
"version": "0.50.59",
|
|
32
32
|
"packaged": true,
|
|
33
|
-
"date":
|
|
33
|
+
"date": 1784820712757
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
36
|
"oc-template-es6-compiler": "^8.0.0"
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=(t,s)=>{const{staticPath:e,templates:a}=t;return s(null,{staticPath:e,templates:a})},r=(t,s)=>{o(t,(e,a,i={})=>{if(e)return s(e);if(a==null)return s(null,{__oc_emptyResponse:!0});const n=t.action?a:Object.assign({},a,{_staticPath:t.staticPath,_baseUrl:t.baseUrl,_componentName:"oc-client",_componentVersion:"0.50.
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=(t,s)=>{const{staticPath:e,templates:a}=t;return s(null,{staticPath:e,templates:a})},r=(t,s)=>{o(t,(e,a,i={})=>{if(e)return s(e);if(a==null)return s(null,{__oc_emptyResponse:!0});const n=t.action?a:Object.assign({},a,{_staticPath:t.staticPath,_baseUrl:t.baseUrl,_componentName:"oc-client",_componentVersion:"0.50.59"}),c=t.staticPath.indexOf("http")===0?t.staticPath:"https:"+t.staticPath;return s(null,Object.assign({},{component:{key:"c4abb6bf4dc6657fb718a45b64bd6b2cb92e874a",src:c+"template.js",props:n,esm:!1,development:void 0}}))})};exports.data=r;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "oc-client",
|
|
3
3
|
"description": "The OpenComponents client-side javascript client",
|
|
4
|
-
"version": "0.50.
|
|
4
|
+
"version": "0.50.59",
|
|
5
5
|
"repository": "https://github.com/opencomponents/oc/tree/master/components/oc-client",
|
|
6
6
|
"author": "Matteo Figus <matteofigus@gmail.com>",
|
|
7
7
|
"oc": {
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
export { default as Client } from 'oc-client';
|
|
2
2
|
export { default as cli } from './cli/programmatic-api';
|
|
3
|
+
export type { RegistryType } from './registry';
|
|
3
4
|
export { default as Registry, RegistryOptions } from './registry';
|
|
5
|
+
export type { CookieOptions, ExpressMiddleware, HttpServerAdapter, HttpServerAdapterFactory, Method, NativeApp, OcHandler, OcRequest, OcResponse, UploadedFile } from './registry/domain/http-server/types';
|
|
4
6
|
export type { Plugin, PluginContext } from './types';
|
|
@@ -47,6 +47,7 @@ type Events = {
|
|
|
47
47
|
};
|
|
48
48
|
type EventsHandler = {
|
|
49
49
|
fire<T extends keyof Events>(eventName: T, data: Events[T]): void;
|
|
50
|
+
hasListeners<T extends keyof Events>(eventName: T): boolean;
|
|
50
51
|
on<T extends keyof Events>(eventName: T, listener: Subscription<Events[T]>): void;
|
|
51
52
|
off<T extends keyof Events>(eventName: T, listener: Subscription<Events[T]>): void;
|
|
52
53
|
reset(): void;
|
|
@@ -13,6 +13,9 @@ const eventsHandler = {
|
|
|
13
13
|
}
|
|
14
14
|
}
|
|
15
15
|
},
|
|
16
|
+
hasListeners(eventName) {
|
|
17
|
+
return Boolean(subscriptions[eventName]?.length);
|
|
18
|
+
},
|
|
16
19
|
on(eventName, callback) {
|
|
17
20
|
if (typeof callback !== 'function') {
|
|
18
21
|
throw resources_1.default.errors.registry.CONFIGURATION_ONREQUEST_MUST_BE_FUNCTION;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { Component } from '../../types';
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
import type { UploadedFile } from './http-server/types';
|
|
3
|
+
export default function extractPackage(files: UploadedFile[] | {
|
|
4
|
+
[fieldname: string]: UploadedFile[];
|
|
4
5
|
}, tarExtractMode: number): Promise<{
|
|
5
6
|
outputFolder: string;
|
|
6
7
|
packageJson: Component;
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
"use strict";
|
|
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.default = createExpressAdapter;
|
|
7
|
+
const node_http_1 = __importDefault(require("node:http"));
|
|
8
|
+
const cookie_parser_1 = __importDefault(require("cookie-parser"));
|
|
9
|
+
const errorhandler_1 = __importDefault(require("errorhandler"));
|
|
10
|
+
const express_1 = __importDefault(require("express"));
|
|
11
|
+
const morgan_1 = __importDefault(require("morgan"));
|
|
12
|
+
const multer_1 = __importDefault(require("multer"));
|
|
13
|
+
const response_time_1 = __importDefault(require("response-time"));
|
|
14
|
+
const expressMiddleware = Symbol('expressMiddleware');
|
|
15
|
+
const ocResponseSym = Symbol('ocResponse');
|
|
16
|
+
const ocParamsSym = Symbol('ocParams');
|
|
17
|
+
function stream(readable) {
|
|
18
|
+
readable.pipe(this.raw);
|
|
19
|
+
}
|
|
20
|
+
function normaliseParams(raw) {
|
|
21
|
+
const params = { ...raw };
|
|
22
|
+
const splat = raw['splat'];
|
|
23
|
+
if (Array.isArray(splat)) {
|
|
24
|
+
params['splat'] = splat.join('/');
|
|
25
|
+
}
|
|
26
|
+
return params;
|
|
27
|
+
}
|
|
28
|
+
function createExpressAdapter(options) {
|
|
29
|
+
const adapterOptions = options;
|
|
30
|
+
return new ExpressHttpServerAdapter(typeof adapterOptions === 'object' ? adapterOptions.port : adapterOptions);
|
|
31
|
+
}
|
|
32
|
+
class ExpressHttpServerAdapter {
|
|
33
|
+
name = 'express';
|
|
34
|
+
app;
|
|
35
|
+
server;
|
|
36
|
+
serverErrorHandlers = [];
|
|
37
|
+
constructor(port) {
|
|
38
|
+
this.app = (0, express_1.default)();
|
|
39
|
+
if (typeof port !== 'undefined') {
|
|
40
|
+
this.app.set('port', port);
|
|
41
|
+
}
|
|
42
|
+
this.app.set('json spaces', 0);
|
|
43
|
+
this.app.set('etag', 'strong');
|
|
44
|
+
}
|
|
45
|
+
enableBodyParser(opts) {
|
|
46
|
+
this.app.use(express_1.default.json({
|
|
47
|
+
inflate: true,
|
|
48
|
+
limit: opts.limit
|
|
49
|
+
}));
|
|
50
|
+
this.app.use(express_1.default.urlencoded({
|
|
51
|
+
extended: true,
|
|
52
|
+
limit: opts.limit
|
|
53
|
+
}));
|
|
54
|
+
}
|
|
55
|
+
enableCookies() {
|
|
56
|
+
this.app.use((0, cookie_parser_1.default)());
|
|
57
|
+
}
|
|
58
|
+
enableFileUploads(opts) {
|
|
59
|
+
const upload = (0, multer_1.default)({
|
|
60
|
+
limits: {
|
|
61
|
+
fieldSize: 10
|
|
62
|
+
},
|
|
63
|
+
storage: multer_1.default.diskStorage({
|
|
64
|
+
destination: opts.tempDir,
|
|
65
|
+
filename: (_req, file, cb) => cb(null, opts.filename(file.originalname))
|
|
66
|
+
})
|
|
67
|
+
});
|
|
68
|
+
const parseUpload = upload.any();
|
|
69
|
+
this.app.use((req, res, next) => {
|
|
70
|
+
if (req.method !== 'PUT') {
|
|
71
|
+
return next();
|
|
72
|
+
}
|
|
73
|
+
parseUpload(req, res, next);
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
enableRequestTiming(onDone) {
|
|
77
|
+
this.app.use((0, response_time_1.default)((req, res, time) => {
|
|
78
|
+
onDone(this.toOcRequest(req), this.toOcResponse(res), time);
|
|
79
|
+
}));
|
|
80
|
+
}
|
|
81
|
+
enableLogging(opts) {
|
|
82
|
+
this.app.use((0, morgan_1.default)('dev', {
|
|
83
|
+
skip: (req, res) => opts.skip(this.toOcRequest(req), this.toOcResponse(res))
|
|
84
|
+
}));
|
|
85
|
+
}
|
|
86
|
+
enableErrorHandler() {
|
|
87
|
+
this.app.use((0, errorhandler_1.default)());
|
|
88
|
+
}
|
|
89
|
+
use(handler) {
|
|
90
|
+
this.app.use(this.toExpressHandler(handler, true));
|
|
91
|
+
}
|
|
92
|
+
route(method, path, id, handlers) {
|
|
93
|
+
const setRouteId = (req, _res, next) => {
|
|
94
|
+
req.routeId = id;
|
|
95
|
+
next();
|
|
96
|
+
};
|
|
97
|
+
this.app[method](path, setRouteId, ...handlers.map((handler) => this.toExpressHandler(handler)));
|
|
98
|
+
}
|
|
99
|
+
fromConnect(handler) {
|
|
100
|
+
const wrapped = (req, res) => new Promise((resolve, reject) => {
|
|
101
|
+
handler(req.raw ?? req, res.raw ?? res, (err) => {
|
|
102
|
+
if (err) {
|
|
103
|
+
reject(err);
|
|
104
|
+
}
|
|
105
|
+
else {
|
|
106
|
+
resolve();
|
|
107
|
+
}
|
|
108
|
+
});
|
|
109
|
+
});
|
|
110
|
+
wrapped[expressMiddleware] = handler;
|
|
111
|
+
return wrapped;
|
|
112
|
+
}
|
|
113
|
+
listen(opts, cb) {
|
|
114
|
+
this.server = node_http_1.default.createServer(this.app);
|
|
115
|
+
this.server.timeout = opts.timeout;
|
|
116
|
+
if (opts.keepAliveTimeout) {
|
|
117
|
+
this.server.keepAliveTimeout = opts.keepAliveTimeout;
|
|
118
|
+
}
|
|
119
|
+
for (const handler of this.serverErrorHandlers) {
|
|
120
|
+
this.server.on('error', handler);
|
|
121
|
+
}
|
|
122
|
+
this.server.listen(opts.port, cb);
|
|
123
|
+
}
|
|
124
|
+
onServerError(cb) {
|
|
125
|
+
this.serverErrorHandlers.push(cb);
|
|
126
|
+
this.server?.on('error', cb);
|
|
127
|
+
}
|
|
128
|
+
close(cb) {
|
|
129
|
+
this.server?.close(cb);
|
|
130
|
+
}
|
|
131
|
+
isListening() {
|
|
132
|
+
return !!this.server?.listening;
|
|
133
|
+
}
|
|
134
|
+
native() {
|
|
135
|
+
return this.app;
|
|
136
|
+
}
|
|
137
|
+
httpServer() {
|
|
138
|
+
if (!this.server) {
|
|
139
|
+
throw new Error('HTTP server has not been started');
|
|
140
|
+
}
|
|
141
|
+
return this.server;
|
|
142
|
+
}
|
|
143
|
+
toExpressHandler(handler, continueWhenNotSent = false) {
|
|
144
|
+
const native = handler[expressMiddleware];
|
|
145
|
+
if (native) {
|
|
146
|
+
return native;
|
|
147
|
+
}
|
|
148
|
+
return (req, res, next) => {
|
|
149
|
+
let result;
|
|
150
|
+
try {
|
|
151
|
+
result = handler(this.toOcRequest(req), this.toOcResponse(res));
|
|
152
|
+
}
|
|
153
|
+
catch (err) {
|
|
154
|
+
next(err);
|
|
155
|
+
return;
|
|
156
|
+
}
|
|
157
|
+
if (result && typeof result.then === 'function') {
|
|
158
|
+
result
|
|
159
|
+
.then(() => {
|
|
160
|
+
if (continueWhenNotSent && !res.headersSent) {
|
|
161
|
+
next();
|
|
162
|
+
}
|
|
163
|
+
})
|
|
164
|
+
.catch(next);
|
|
165
|
+
}
|
|
166
|
+
else if (continueWhenNotSent && !res.headersSent) {
|
|
167
|
+
next();
|
|
168
|
+
}
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
toOcRequest(req) {
|
|
172
|
+
const memo = req[ocParamsSym];
|
|
173
|
+
const current = (req.params ?? {});
|
|
174
|
+
if (memo && memo.source === current) {
|
|
175
|
+
return req;
|
|
176
|
+
}
|
|
177
|
+
if (!memo) {
|
|
178
|
+
Object.assign(req, {
|
|
179
|
+
raw: req,
|
|
180
|
+
routeId: req.routeId ?? ''
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
const normalized = normaliseParams(current);
|
|
184
|
+
Object.assign(req, { params: normalized });
|
|
185
|
+
req[ocParamsSym] = {
|
|
186
|
+
source: normalized
|
|
187
|
+
};
|
|
188
|
+
return req;
|
|
189
|
+
}
|
|
190
|
+
toOcResponse(res) {
|
|
191
|
+
const cached = res[ocResponseSym];
|
|
192
|
+
if (cached) {
|
|
193
|
+
return cached;
|
|
194
|
+
}
|
|
195
|
+
const ocRes = Object.assign(res, {
|
|
196
|
+
raw: res,
|
|
197
|
+
stream
|
|
198
|
+
});
|
|
199
|
+
res[ocResponseSym] = ocRes;
|
|
200
|
+
return ocRes;
|
|
201
|
+
}
|
|
202
|
+
}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import type http from 'node:http';
|
|
2
|
+
import type { IncomingHttpHeaders } from 'node:http';
|
|
3
|
+
import type express from 'express';
|
|
4
|
+
import type { Config } from '../../../types';
|
|
5
|
+
export interface CookieOptions {
|
|
6
|
+
domain?: string;
|
|
7
|
+
encode?: (value: string) => string;
|
|
8
|
+
expires?: Date;
|
|
9
|
+
httpOnly?: boolean;
|
|
10
|
+
maxAge?: number;
|
|
11
|
+
partitioned?: boolean;
|
|
12
|
+
path?: string;
|
|
13
|
+
priority?: 'low' | 'medium' | 'high';
|
|
14
|
+
sameSite?: boolean | 'lax' | 'strict' | 'none';
|
|
15
|
+
secure?: boolean;
|
|
16
|
+
signed?: boolean;
|
|
17
|
+
}
|
|
18
|
+
export type Method = 'get' | 'post' | 'put' | 'patch' | 'head' | 'delete';
|
|
19
|
+
export interface UploadedFile {
|
|
20
|
+
fieldname: string;
|
|
21
|
+
originalname: string;
|
|
22
|
+
encoding: string;
|
|
23
|
+
mimetype: string;
|
|
24
|
+
size: number;
|
|
25
|
+
destination: string;
|
|
26
|
+
filename: string;
|
|
27
|
+
path: string;
|
|
28
|
+
buffer?: Buffer;
|
|
29
|
+
stream?: NodeJS.ReadableStream;
|
|
30
|
+
truncated?: boolean;
|
|
31
|
+
}
|
|
32
|
+
export interface OcRequest {
|
|
33
|
+
method: string;
|
|
34
|
+
url: string;
|
|
35
|
+
path: string;
|
|
36
|
+
originalUrl: string;
|
|
37
|
+
protocol: string;
|
|
38
|
+
secure: boolean;
|
|
39
|
+
ip: string;
|
|
40
|
+
headers: IncomingHttpHeaders;
|
|
41
|
+
params: Record<string, string>;
|
|
42
|
+
query: Record<string, unknown>;
|
|
43
|
+
body: any;
|
|
44
|
+
cookies: Record<string, string>;
|
|
45
|
+
files?: UploadedFile[] | Record<string, UploadedFile[]>;
|
|
46
|
+
user?: string;
|
|
47
|
+
routeId: string;
|
|
48
|
+
get(header: string): string | undefined;
|
|
49
|
+
raw: http.IncomingMessage;
|
|
50
|
+
}
|
|
51
|
+
export interface OcResponse {
|
|
52
|
+
conf: Config;
|
|
53
|
+
errorCode?: string;
|
|
54
|
+
errorDetails?: string;
|
|
55
|
+
statusCode: number;
|
|
56
|
+
status(code: number): this;
|
|
57
|
+
json(body: unknown): void;
|
|
58
|
+
send(body: unknown): void;
|
|
59
|
+
set(field: string | Record<string, string>, value?: string): this;
|
|
60
|
+
header(name: string, value: string): this;
|
|
61
|
+
setHeader(name: string, value: string): this;
|
|
62
|
+
removeHeader(name: string): this;
|
|
63
|
+
type(mime: string): this;
|
|
64
|
+
cookie(name: string, value: string, opts?: CookieOptions): this;
|
|
65
|
+
redirect(url: string): void;
|
|
66
|
+
end(chunk?: unknown): void;
|
|
67
|
+
stream(readable: NodeJS.ReadableStream): void;
|
|
68
|
+
raw: http.ServerResponse;
|
|
69
|
+
}
|
|
70
|
+
export type OcHandler = (req: OcRequest, res: OcResponse) => void | Promise<void>;
|
|
71
|
+
export type ExpressMiddleware = (req: any, res: any, next: (err?: unknown) => void) => void;
|
|
72
|
+
export type HttpServerAdapterFactory<TOptions = unknown, TNative = unknown> = {
|
|
73
|
+
(options?: unknown): HttpServerAdapter<TNative>;
|
|
74
|
+
readonly __serverAdapterOptions?: TOptions;
|
|
75
|
+
};
|
|
76
|
+
export type HttpServerAdapterOptions<TAdapter> = TAdapter extends {
|
|
77
|
+
readonly __serverAdapterOptions?: infer TOptions;
|
|
78
|
+
} ? TOptions : TAdapter extends (options?: infer TOptions) => HttpServerAdapter ? TOptions : unknown;
|
|
79
|
+
export type NativeApp<TAdapter> = TAdapter extends (...args: any[]) => HttpServerAdapter<infer TNative> ? unknown extends TNative ? express.Express : TNative : TAdapter extends HttpServerAdapter<infer TNative> ? unknown extends TNative ? express.Express : TNative : express.Express;
|
|
80
|
+
export interface HttpServerAdapter<TNative = unknown> {
|
|
81
|
+
name: string;
|
|
82
|
+
enableBodyParser(opts: {
|
|
83
|
+
limit?: number | string;
|
|
84
|
+
}): void;
|
|
85
|
+
enableCookies(): void;
|
|
86
|
+
enableFileUploads(opts: {
|
|
87
|
+
tempDir: string;
|
|
88
|
+
filename: (originalName: string) => string;
|
|
89
|
+
}): void;
|
|
90
|
+
enableRequestTiming(onDone: (req: OcRequest, res: OcResponse, ms: number) => void): void;
|
|
91
|
+
enableLogging(opts: {
|
|
92
|
+
skip: (req: OcRequest, res: OcResponse) => boolean;
|
|
93
|
+
}): void;
|
|
94
|
+
enableErrorHandler(): void;
|
|
95
|
+
use(handler: OcHandler): void;
|
|
96
|
+
route(method: Method, path: string, id: string, handlers: OcHandler[]): void;
|
|
97
|
+
fromConnect(handler: ExpressMiddleware): OcHandler;
|
|
98
|
+
listen(opts: {
|
|
99
|
+
port: number | string;
|
|
100
|
+
timeout: number;
|
|
101
|
+
keepAliveTimeout?: number;
|
|
102
|
+
}, cb: (err?: Error) => void): void;
|
|
103
|
+
onServerError(cb: (err: Error) => void): void;
|
|
104
|
+
close(cb: (err?: Error) => void): void;
|
|
105
|
+
isListening(): boolean;
|
|
106
|
+
native(): TNative;
|
|
107
|
+
httpServer(): http.Server;
|
|
108
|
+
}
|
|
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.default = nestedRenderer;
|
|
7
7
|
const resources_1 = __importDefault(require("../../resources"));
|
|
8
8
|
const settings_1 = __importDefault(require("../../resources/settings"));
|
|
9
|
+
const pLimit_1 = __importDefault(require("../../utils/pLimit"));
|
|
9
10
|
function nestedRenderer(rendererWithCallback, conf) {
|
|
10
11
|
const renderer = (options) => new Promise((res, rej) => {
|
|
11
12
|
rendererWithCallback(options, (result) => {
|
|
@@ -38,22 +39,21 @@ function nestedRenderer(rendererWithCallback, conf) {
|
|
|
38
39
|
if (!components?.length) {
|
|
39
40
|
throw new Error(resources_1.default.errors.registry.NESTED_RENDERER_COMPONENTS_IS_NOT_VALID);
|
|
40
41
|
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
}));
|
|
42
|
+
const limit = (0, pLimit_1.default)(10);
|
|
43
|
+
return Promise.all(components.map((component) => limit(() => renderer({
|
|
44
|
+
conf: conf,
|
|
45
|
+
headers: {
|
|
46
|
+
...options.headers,
|
|
47
|
+
accept: settings_1.default.registry.acceptRenderedHeader
|
|
48
|
+
},
|
|
49
|
+
ip: component.ip || '',
|
|
50
|
+
name: component.name,
|
|
51
|
+
parameters: {
|
|
52
|
+
...options.parameters,
|
|
53
|
+
...component.parameters
|
|
54
|
+
},
|
|
55
|
+
version: component.version || ''
|
|
56
|
+
}).catch((err) => new Error(err)))));
|
|
57
57
|
}
|
|
58
58
|
};
|
|
59
59
|
}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { compileSync } from 'oc-client-browser';
|
|
2
2
|
import type { Config } from '../../types';
|
|
3
|
+
import type { HttpServerAdapterFactory } from './http-server/types';
|
|
3
4
|
type CompileOptions = Omit<Exclude<Parameters<typeof compileSync>[0], undefined>, 'templates'>;
|
|
4
|
-
export interface RegistryOptions<T = any> extends Partial<Omit<Config<T>, 'beforePublish' | 'discovery' | 'plugins'>> {
|
|
5
|
+
export interface RegistryOptions<T = any, TServerAdapter extends HttpServerAdapterFactory = HttpServerAdapterFactory> extends Partial<Omit<Config<T, TServerAdapter>, 'beforePublish' | 'discovery' | 'plugins'>> {
|
|
5
6
|
/**
|
|
6
7
|
* Configuration object to enable/disable the HTML discovery page and the API
|
|
7
8
|
*
|
|
@@ -28,5 +29,5 @@ export interface RegistryOptions<T = any> extends Partial<Omit<Config<T>, 'befor
|
|
|
28
29
|
*/
|
|
29
30
|
compileClient?: boolean | CompileOptions;
|
|
30
31
|
}
|
|
31
|
-
export default function optionsSanitiser(input: RegistryOptions): Config;
|
|
32
|
+
export default function optionsSanitiser<T = any, TServerAdapter extends HttpServerAdapterFactory = HttpServerAdapterFactory>(input: RegistryOptions<T, TServerAdapter>): Config;
|
|
32
33
|
export {};
|
|
@@ -41,6 +41,7 @@ const node_zlib_1 = __importDefault(require("node:zlib"));
|
|
|
41
41
|
const oc_client_browser_1 = require("oc-client-browser");
|
|
42
42
|
const settings_1 = __importDefault(require("../../resources/settings"));
|
|
43
43
|
const auth = __importStar(require("./authentication"));
|
|
44
|
+
const express_adapter_1 = __importDefault(require("./http-server/express-adapter"));
|
|
44
45
|
const DEFAULT_NODE_KEEPALIVE_MS = 5000;
|
|
45
46
|
function optionsSanitiser(input) {
|
|
46
47
|
const options = { ...input };
|
|
@@ -165,6 +166,18 @@ function optionsSanitiser(input) {
|
|
|
165
166
|
options.timeout = options.timeout || 1000 * 60 * 2;
|
|
166
167
|
options.keepAliveTimeout =
|
|
167
168
|
options.keepAliveTimeout || DEFAULT_NODE_KEEPALIVE_MS;
|
|
169
|
+
if (!options.server) {
|
|
170
|
+
options.server = {
|
|
171
|
+
adapter: express_adapter_1.default,
|
|
172
|
+
options: { port: options.port }
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
if (!options.server.adapter) {
|
|
176
|
+
options.server.adapter = express_adapter_1.default;
|
|
177
|
+
}
|
|
178
|
+
if (typeof options.server.options === 'undefined') {
|
|
179
|
+
options.server.options = { port: options.port };
|
|
180
|
+
}
|
|
168
181
|
if (options.s3) {
|
|
169
182
|
options.storage = {
|
|
170
183
|
adapter: require('oc-s3-storage-adapter'),
|