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
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { HttpServerAdapter } from './http-server/types';
|
|
2
|
+
type HttpServerAdapterFactory<T = unknown> = (options?: T) => HttpServerAdapter;
|
|
3
|
+
export default function getHttpServerAdapter<T = unknown>(adapter: HttpServerAdapter | HttpServerAdapterFactory<T>, options?: T): HttpServerAdapter;
|
|
4
|
+
export {};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.default = getHttpServerAdapter;
|
|
4
|
+
function isHttpServerAdapter(adapter) {
|
|
5
|
+
return (!!adapter &&
|
|
6
|
+
typeof adapter === 'object' &&
|
|
7
|
+
typeof adapter.native === 'function' &&
|
|
8
|
+
typeof adapter.listen === 'function' &&
|
|
9
|
+
typeof adapter.httpServer === 'function');
|
|
10
|
+
}
|
|
11
|
+
function getHttpServerAdapter(adapter, options) {
|
|
12
|
+
if (isHttpServerAdapter(adapter)) {
|
|
13
|
+
return adapter;
|
|
14
|
+
}
|
|
15
|
+
const instance = adapter(options);
|
|
16
|
+
if (!isHttpServerAdapter(instance)) {
|
|
17
|
+
throw new Error('Invalid HTTP server adapter');
|
|
18
|
+
}
|
|
19
|
+
return instance;
|
|
20
|
+
}
|
|
@@ -5,5 +5,5 @@ type ValidationResult = {
|
|
|
5
5
|
isValid: false;
|
|
6
6
|
missing: string[];
|
|
7
7
|
};
|
|
8
|
-
export default function pluginsRequirements(componentRequirements: Record<string, (...args: unknown[]) => unknown> | string[] | null | undefined, registryPlugins: Config['plugins']): ValidationResult;
|
|
8
|
+
export default function pluginsRequirements(componentRequirements: Record<string, (...args: unknown[]) => unknown> | string[] | null | undefined, registryPlugins: Config['plugins'] | ReadonlySet<string>): ValidationResult;
|
|
9
9
|
export {};
|
|
@@ -6,9 +6,11 @@ function pluginsRequirements(componentRequirements, registryPlugins) {
|
|
|
6
6
|
const requiredPlugins = Array.isArray(componentRequirements)
|
|
7
7
|
? componentRequirements
|
|
8
8
|
: Object.keys(componentRequirements || {});
|
|
9
|
+
const registryPluginNames = registryPlugins instanceof Set
|
|
10
|
+
? registryPlugins
|
|
11
|
+
: new Set(Object.keys(registryPlugins || {}));
|
|
9
12
|
for (const requiredPlugin of requiredPlugins) {
|
|
10
|
-
if (!
|
|
11
|
-
!Object.keys(registryPlugins).includes(requiredPlugin)) {
|
|
13
|
+
if (!registryPluginNames.has(requiredPlugin)) {
|
|
12
14
|
missing.push(requiredPlugin);
|
|
13
15
|
}
|
|
14
16
|
}
|
|
@@ -1,13 +1,14 @@
|
|
|
1
|
+
import type { UploadedFile } from '../http-server/types';
|
|
1
2
|
type ValidationResponse = {
|
|
2
3
|
isValid: true;
|
|
3
|
-
files:
|
|
4
|
-
[fieldname: string]:
|
|
4
|
+
files: UploadedFile[] | {
|
|
5
|
+
[fieldname: string]: UploadedFile[];
|
|
5
6
|
};
|
|
6
7
|
} | {
|
|
7
8
|
isValid: false;
|
|
8
9
|
message: string;
|
|
9
10
|
};
|
|
10
|
-
export default function uploadedPackage(input?:
|
|
11
|
-
[fieldname: string]:
|
|
11
|
+
export default function uploadedPackage(input?: UploadedFile[] | {
|
|
12
|
+
[fieldname: string]: UploadedFile[];
|
|
12
13
|
}): ValidationResponse;
|
|
13
14
|
export {};
|
|
@@ -8,13 +8,15 @@ exports.validateNewVersion = validateNewVersion;
|
|
|
8
8
|
const semver_1 = __importDefault(require("semver"));
|
|
9
9
|
const semver_extra_1 = __importDefault(require("semver-extra"));
|
|
10
10
|
function getAvailableVersion(requestedVersion, availableVersions) {
|
|
11
|
-
if (
|
|
12
|
-
|
|
11
|
+
if (!requestedVersion) {
|
|
12
|
+
return (semver_1.default.maxSatisfying(availableVersions, '') ||
|
|
13
|
+
semver_extra_1.default.max(availableVersions) ||
|
|
14
|
+
undefined);
|
|
13
15
|
}
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
return
|
|
16
|
+
if (availableVersions.includes(requestedVersion)) {
|
|
17
|
+
return requestedVersion;
|
|
18
|
+
}
|
|
19
|
+
return semver_1.default.maxSatisfying(availableVersions, requestedVersion) || undefined;
|
|
18
20
|
}
|
|
19
21
|
function validateNewVersion(requestedVersion, availableVersions) {
|
|
20
22
|
return !availableVersions.includes(requestedVersion);
|
package/dist/registry/index.d.ts
CHANGED
|
@@ -1,75 +1,17 @@
|
|
|
1
|
-
import http from 'node:http';
|
|
2
|
-
import express from 'express';
|
|
1
|
+
import type http from 'node:http';
|
|
3
2
|
import type { Plugin } from '../types';
|
|
3
|
+
import eventsHandler from './domain/events-handler';
|
|
4
|
+
import type { HttpServerAdapterFactory, NativeApp } from './domain/http-server/types';
|
|
4
5
|
import { RegistryOptions } from './domain/options-sanitiser';
|
|
5
6
|
export { RegistryOptions };
|
|
6
|
-
export
|
|
7
|
+
export interface RegistryType<TApp = NativeApp<HttpServerAdapterFactory>> {
|
|
7
8
|
close: (callback: (err?: Error | undefined | string) => void) => void;
|
|
8
|
-
on:
|
|
9
|
-
|
|
10
|
-
code: string;
|
|
11
|
-
message: string;
|
|
12
|
-
};
|
|
13
|
-
start: unknown;
|
|
14
|
-
'cache-poll': number;
|
|
15
|
-
request: import("./domain/events-handler").RequestData;
|
|
16
|
-
'component-retrieved': {
|
|
17
|
-
headers: http.IncomingHttpHeaders;
|
|
18
|
-
name: string;
|
|
19
|
-
parameters: http.IncomingHttpHeaders;
|
|
20
|
-
requestVersion: string;
|
|
21
|
-
duration: number;
|
|
22
|
-
};
|
|
23
|
-
'data-provider-error': {
|
|
24
|
-
name: string;
|
|
25
|
-
version: string;
|
|
26
|
-
parameters: Record<string, string | boolean | number>;
|
|
27
|
-
requestVersion: string;
|
|
28
|
-
status: number;
|
|
29
|
-
error: Error;
|
|
30
|
-
};
|
|
31
|
-
'component-published': {
|
|
32
|
-
componentName: string;
|
|
33
|
-
componentVersion: string;
|
|
34
|
-
packageJson: import("../types").Component;
|
|
35
|
-
componentFolder: string;
|
|
36
|
-
user?: string;
|
|
37
|
-
};
|
|
38
|
-
}>(eventName: T_1, listener: (data: {
|
|
39
|
-
error: {
|
|
40
|
-
code: string;
|
|
41
|
-
message: string;
|
|
42
|
-
};
|
|
43
|
-
start: unknown;
|
|
44
|
-
'cache-poll': number;
|
|
45
|
-
request: import("./domain/events-handler").RequestData;
|
|
46
|
-
'component-retrieved': {
|
|
47
|
-
headers: http.IncomingHttpHeaders;
|
|
48
|
-
name: string;
|
|
49
|
-
parameters: http.IncomingHttpHeaders;
|
|
50
|
-
requestVersion: string;
|
|
51
|
-
duration: number;
|
|
52
|
-
};
|
|
53
|
-
'data-provider-error': {
|
|
54
|
-
name: string;
|
|
55
|
-
version: string;
|
|
56
|
-
parameters: Record<string, string | boolean | number>;
|
|
57
|
-
requestVersion: string;
|
|
58
|
-
status: number;
|
|
59
|
-
error: Error;
|
|
60
|
-
};
|
|
61
|
-
'component-published': {
|
|
62
|
-
componentName: string;
|
|
63
|
-
componentVersion: string;
|
|
64
|
-
packageJson: import("../types").Component;
|
|
65
|
-
componentFolder: string;
|
|
66
|
-
user?: string;
|
|
67
|
-
};
|
|
68
|
-
}[T_1]) => void) => void;
|
|
69
|
-
register: <T_1 = any>(plugin: Plugin<T_1>, callback?: (...args: any[]) => void) => void;
|
|
9
|
+
on: typeof eventsHandler.on;
|
|
10
|
+
register: <T = any>(plugin: Plugin<T>, callback?: (...args: any[]) => void) => void;
|
|
70
11
|
start: (callback: (err: unknown, data?: {
|
|
71
|
-
app:
|
|
12
|
+
app: TApp;
|
|
72
13
|
server: http.Server;
|
|
73
14
|
}) => void) => Promise<void>;
|
|
74
|
-
app:
|
|
75
|
-
}
|
|
15
|
+
app: TApp;
|
|
16
|
+
}
|
|
17
|
+
export default function registry<T = any, TServerAdapter extends HttpServerAdapterFactory = HttpServerAdapterFactory, TApp = NativeApp<TServerAdapter>>(inputOptions: RegistryOptions<T, TServerAdapter>): RegistryType<TApp>;
|
package/dist/registry/index.js
CHANGED
|
@@ -37,14 +37,13 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
37
37
|
};
|
|
38
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
39
|
exports.default = registry;
|
|
40
|
-
const node_http_1 = __importDefault(require("node:http"));
|
|
41
40
|
const safe_1 = __importDefault(require("colors/safe"));
|
|
42
|
-
const express_1 = __importDefault(require("express"));
|
|
43
41
|
const app_start_1 = __importDefault(require("./app-start"));
|
|
44
42
|
const events_handler_1 = __importDefault(require("./domain/events-handler"));
|
|
45
43
|
const options_sanitiser_1 = __importDefault(require("./domain/options-sanitiser"));
|
|
46
44
|
const pluginsInitialiser = __importStar(require("./domain/plugins-initialiser"));
|
|
47
45
|
const repository_1 = __importDefault(require("./domain/repository"));
|
|
46
|
+
const server_adapter_1 = __importDefault(require("./domain/server-adapter"));
|
|
48
47
|
const validator = __importStar(require("./domain/validators"));
|
|
49
48
|
const middleware = __importStar(require("./middleware"));
|
|
50
49
|
const router_1 = require("./router");
|
|
@@ -55,13 +54,13 @@ function registry(inputOptions) {
|
|
|
55
54
|
}
|
|
56
55
|
const options = (0, options_sanitiser_1.default)(inputOptions);
|
|
57
56
|
const plugins = [];
|
|
58
|
-
const
|
|
59
|
-
|
|
57
|
+
const adapter = middleware.bind((0, server_adapter_1.default)(options.server.adapter, options.server.options), options);
|
|
58
|
+
const app = adapter.native();
|
|
60
59
|
const repository = (0, repository_1.default)(options);
|
|
61
60
|
const close = (callback) => {
|
|
62
61
|
const closeMetadataStore = () => Promise.resolve(repository.close?.()).catch(() => undefined);
|
|
63
|
-
if (
|
|
64
|
-
|
|
62
|
+
if (adapter.isListening()) {
|
|
63
|
+
adapter.close((err) => {
|
|
65
64
|
void closeMetadataStore().finally(() => callback(err));
|
|
66
65
|
});
|
|
67
66
|
return;
|
|
@@ -75,30 +74,29 @@ function registry(inputOptions) {
|
|
|
75
74
|
const ok = (msg) => console.log(safe_1.default.green(msg));
|
|
76
75
|
try {
|
|
77
76
|
options.plugins = await pluginsInitialiser.init(plugins);
|
|
78
|
-
(0, router_1.create)(
|
|
77
|
+
(0, router_1.create)(adapter, options, repository);
|
|
79
78
|
const componentsInfo = await repository.init();
|
|
80
79
|
await (0, app_start_1.default)(repository, options);
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
}
|
|
86
|
-
server.listen(options.port, (err) => {
|
|
80
|
+
adapter.listen({
|
|
81
|
+
port: options.port,
|
|
82
|
+
timeout: options.timeout,
|
|
83
|
+
keepAliveTimeout: options.keepAliveTimeout
|
|
84
|
+
}, (err) => {
|
|
87
85
|
if (err) {
|
|
88
86
|
return callback(err);
|
|
89
87
|
}
|
|
90
88
|
events_handler_1.default.fire('start', {});
|
|
91
89
|
if (options.verbosity) {
|
|
92
|
-
ok(`Registry started at port http://localhost:${
|
|
90
|
+
ok(`Registry started at port http://localhost:${options.port}${options.prefix}`);
|
|
93
91
|
if (componentsInfo) {
|
|
94
92
|
const componentsNumber = Object.keys(componentsInfo.components).length;
|
|
95
93
|
const componentsReleases = Object.values(componentsInfo.components).reduce((acc, component) => acc + Object.keys(component).length, 0);
|
|
96
94
|
ok(`Registry serving ${componentsNumber} components for a total of ${componentsReleases} releases.`);
|
|
97
95
|
}
|
|
98
96
|
}
|
|
99
|
-
callback(null, { app, server });
|
|
97
|
+
callback(null, { app, server: adapter.httpServer() });
|
|
100
98
|
});
|
|
101
|
-
|
|
99
|
+
adapter.onServerError((error) => {
|
|
102
100
|
events_handler_1.default.fire('error', {
|
|
103
101
|
code: 'EXPRESS_ERROR',
|
|
104
102
|
message: error?.message ?? String(error)
|
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
|
|
1
|
+
import type { OcHandler } from '../domain/http-server/types';
|
|
2
|
+
declare const baseUrlHandler: OcHandler;
|
|
3
|
+
export default baseUrlHandler;
|
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
|
|
4
|
-
function baseUrlHandler(req, res, next) {
|
|
3
|
+
const baseUrlHandler = (req, res) => {
|
|
5
4
|
if (res.conf.baseUrlFunc) {
|
|
6
5
|
res.conf.baseUrl = res.conf.baseUrlFunc({
|
|
7
6
|
host: req.headers.host,
|
|
8
7
|
secure: req.secure
|
|
9
8
|
});
|
|
10
9
|
}
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
};
|
|
11
|
+
exports.default = baseUrlHandler;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { OcRequest, OcResponse } from '../domain/http-server/types';
|
|
2
2
|
export default function compress(data: {
|
|
3
3
|
uncompressed: string;
|
|
4
4
|
brotli: Buffer;
|
|
5
5
|
gzip: Buffer;
|
|
6
|
-
}, req:
|
|
6
|
+
}, req: OcRequest, res: OcResponse): void;
|
|
@@ -9,7 +9,7 @@ function compress(data, req, res) {
|
|
|
9
9
|
res.send(data.uncompressed);
|
|
10
10
|
return;
|
|
11
11
|
}
|
|
12
|
-
res.
|
|
12
|
+
res.set('Content-Encoding', encoding);
|
|
13
13
|
const compressed = encoding === 'br' ? data.brotli : data.gzip;
|
|
14
14
|
res.send(compressed);
|
|
15
15
|
}
|
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
|
|
1
|
+
import type { OcHandler } from '../domain/http-server/types';
|
|
2
|
+
declare const cors: OcHandler;
|
|
3
|
+
export default cors;
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
|
|
4
|
-
function cors(_req, res, next) {
|
|
3
|
+
const cors = (_req, res) => {
|
|
5
4
|
res.removeHeader('X-Powered-By');
|
|
6
|
-
res.
|
|
7
|
-
res.
|
|
8
|
-
res.
|
|
9
|
-
res.
|
|
10
|
-
|
|
11
|
-
|
|
5
|
+
res.set('Access-Control-Allow-Credentials', 'true');
|
|
6
|
+
res.set('Access-Control-Allow-Origin', '*');
|
|
7
|
+
res.set('Access-Control-Allow-Headers', 'Origin, X-Requested-With, Content-Type, Accept, traceparent');
|
|
8
|
+
res.set('Access-Control-Allow-Methods', 'GET, OPTIONS, PUT, POST');
|
|
9
|
+
};
|
|
10
|
+
exports.default = cors;
|
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
|
|
1
|
+
import type { OcHandler } from '../domain/http-server/types';
|
|
2
|
+
declare const discoveryHandler: OcHandler;
|
|
3
|
+
export default discoveryHandler;
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
|
|
4
|
-
function discoveryHandler(req, res, next) {
|
|
3
|
+
const discoveryHandler = (req, res) => {
|
|
5
4
|
res.conf.discoveryFunc =
|
|
6
5
|
res.conf.discoveryFunc ||
|
|
7
6
|
(typeof res.conf.discovery === 'function' ? res.conf.discovery : undefined);
|
|
@@ -11,5 +10,5 @@ function discoveryHandler(req, res, next) {
|
|
|
11
10
|
secure: req.secure
|
|
12
11
|
});
|
|
13
12
|
}
|
|
14
|
-
|
|
15
|
-
|
|
13
|
+
};
|
|
14
|
+
exports.default = discoveryHandler;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { type Express } from 'express';
|
|
2
1
|
import type { Config } from '../../types';
|
|
3
|
-
|
|
2
|
+
import type { HttpServerAdapter } from '../domain/http-server/types';
|
|
3
|
+
export declare const bind: (adapter: HttpServerAdapter, options: Config) => HttpServerAdapter;
|
|
@@ -4,54 +4,60 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.bind = void 0;
|
|
7
|
-
const
|
|
8
|
-
const errorhandler_1 = __importDefault(require("errorhandler"));
|
|
9
|
-
const express_1 = __importDefault(require("express"));
|
|
10
|
-
const morgan_1 = __importDefault(require("morgan"));
|
|
7
|
+
const events_handler_1 = __importDefault(require("../domain/events-handler"));
|
|
11
8
|
const base_url_handler_1 = __importDefault(require("./base-url-handler"));
|
|
12
9
|
const cors_1 = __importDefault(require("./cors"));
|
|
13
10
|
const discovery_handler_1 = __importDefault(require("./discovery-handler"));
|
|
14
|
-
const
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
inflate: true
|
|
18
|
-
};
|
|
19
|
-
const bodyParserUrlEncodedArgument = {
|
|
20
|
-
extended: true
|
|
21
|
-
};
|
|
22
|
-
const bind = (app, options) => {
|
|
23
|
-
app.set('port', options.port);
|
|
24
|
-
app.set('json spaces', 0);
|
|
25
|
-
app.set('etag', 'strong');
|
|
26
|
-
app.use((_req, res, next) => {
|
|
11
|
+
const normaliseFileName = (x) => x.replace('.tar.gz', '').replace(/\W+/g, '-').toLowerCase();
|
|
12
|
+
const bind = (adapter, options) => {
|
|
13
|
+
adapter.use((_req, res) => {
|
|
27
14
|
res.conf = options;
|
|
28
|
-
next();
|
|
29
15
|
});
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
16
|
+
adapter.enableRequestTiming((req, res, time) => {
|
|
17
|
+
if (!events_handler_1.default.hasListeners('request')) {
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
const data = {
|
|
21
|
+
body: req.body,
|
|
22
|
+
duration: time,
|
|
23
|
+
headers: req.headers,
|
|
24
|
+
method: req.method,
|
|
25
|
+
path: req.path,
|
|
26
|
+
relativeUrl: req.originalUrl,
|
|
27
|
+
query: req.query,
|
|
28
|
+
url: req.protocol + '://' + req.get('host') + req.originalUrl,
|
|
29
|
+
statusCode: res.statusCode
|
|
30
|
+
};
|
|
31
|
+
if (res.errorDetails) {
|
|
32
|
+
data.errorDetails = res.errorDetails;
|
|
33
|
+
}
|
|
34
|
+
if (res.errorCode) {
|
|
35
|
+
data.errorCode = res.errorCode;
|
|
36
|
+
}
|
|
37
|
+
events_handler_1.default.fire('request', data);
|
|
38
|
+
});
|
|
39
|
+
adapter.enableCookies();
|
|
40
|
+
adapter.enableBodyParser({ limit: options.postRequestPayloadSize });
|
|
41
|
+
adapter.use(cors_1.default);
|
|
42
|
+
if (!options.local) {
|
|
43
|
+
adapter.enableFileUploads({
|
|
44
|
+
tempDir: options.tempDir,
|
|
45
|
+
filename: (originalName) => `${normaliseFileName(originalName)}-${Date.now()}.tar.gz`
|
|
46
|
+
});
|
|
37
47
|
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
app.use(cors_1.default);
|
|
41
|
-
app.use(file_uploads_1.default);
|
|
42
|
-
app.use(base_url_handler_1.default);
|
|
43
|
-
app.use(discovery_handler_1.default);
|
|
48
|
+
adapter.use(base_url_handler_1.default);
|
|
49
|
+
adapter.use(discovery_handler_1.default);
|
|
44
50
|
if (options.verbosity) {
|
|
45
|
-
|
|
51
|
+
adapter.enableLogging({
|
|
46
52
|
skip: (req, res) => {
|
|
47
53
|
// Hide logging development console calls
|
|
48
|
-
return req.url.startsWith(`${res.conf
|
|
54
|
+
return req.url.startsWith(`${res.conf?.prefix ?? ''}~actions/$$__oc__server___console__$$`);
|
|
49
55
|
}
|
|
50
|
-
})
|
|
56
|
+
});
|
|
51
57
|
}
|
|
52
58
|
if (options.local) {
|
|
53
|
-
|
|
59
|
+
adapter.enableErrorHandler();
|
|
54
60
|
}
|
|
55
|
-
return
|
|
61
|
+
return adapter;
|
|
56
62
|
};
|
|
57
63
|
exports.bind = bind;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Express } from 'express';
|
|
2
1
|
import type { Repository } from '../registry/domain/repository';
|
|
3
2
|
import type { Config } from '../types';
|
|
4
|
-
|
|
3
|
+
import type { HttpServerAdapter } from './domain/http-server/types';
|
|
4
|
+
export declare function create(adapter: HttpServerAdapter, conf: Config, repository: Repository): void;
|
package/dist/registry/router.js
CHANGED
|
@@ -16,7 +16,8 @@ const plugins_1 = __importDefault(require("./routes/plugins"));
|
|
|
16
16
|
const publish_1 = __importDefault(require("./routes/publish"));
|
|
17
17
|
const static_redirector_1 = __importDefault(require("./routes/static-redirector"));
|
|
18
18
|
const validate_1 = __importDefault(require("./routes/validate"));
|
|
19
|
-
function create(
|
|
19
|
+
function create(adapter, conf, repository) {
|
|
20
|
+
const route = (method, path, id, ...handlers) => adapter.route(method, path, id, handlers);
|
|
20
21
|
const routes = {
|
|
21
22
|
component: (0, component_1.default)(conf, repository),
|
|
22
23
|
components: (0, components_1.default)(conf, repository),
|
|
@@ -24,7 +25,12 @@ function create(app, conf, repository) {
|
|
|
24
25
|
componentPreview: (0, component_preview_1.default)(conf, repository),
|
|
25
26
|
index: (0, routes_1.default)(repository),
|
|
26
27
|
publish: (0, publish_1.default)(repository),
|
|
27
|
-
staticRedirector:
|
|
28
|
+
staticRedirector: {
|
|
29
|
+
client: (0, static_redirector_1.default)(repository, 'client'),
|
|
30
|
+
devClient: (0, static_redirector_1.default)(repository, 'dev-client'),
|
|
31
|
+
clientMap: (0, static_redirector_1.default)(repository, 'client-map'),
|
|
32
|
+
localStatic: (0, static_redirector_1.default)(repository, 'local-static')
|
|
33
|
+
},
|
|
28
34
|
plugins: (0, plugins_1.default)(conf),
|
|
29
35
|
dependencies: (0, dependencies_1.default)(conf),
|
|
30
36
|
history: (0, history_1.default)(repository),
|
|
@@ -33,42 +39,42 @@ function create(app, conf, repository) {
|
|
|
33
39
|
const prefix = conf.prefix;
|
|
34
40
|
const definedBaseRoute = conf.routes?.find((route) => route.route === '/');
|
|
35
41
|
if (prefix !== '/' && !definedBaseRoute) {
|
|
36
|
-
|
|
37
|
-
|
|
42
|
+
route('get', '/', 'root-redirect', (_req, res) => res.redirect(prefix));
|
|
43
|
+
route('get', prefix.substring(0, prefix.length - 1), 'prefix-index', routes.index);
|
|
38
44
|
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
+
route('get', `${prefix}oc-client/client.js`, 'client', routes.staticRedirector.client);
|
|
46
|
+
route('get', `${prefix}oc-client/client.dev.js`, 'dev-client', routes.staticRedirector.devClient);
|
|
47
|
+
route('get', `${prefix}oc-client/oc-client.min.map`, 'client-map', routes.staticRedirector.clientMap);
|
|
48
|
+
route('get', `${prefix}~registry/plugins`, 'plugins', routes.plugins);
|
|
49
|
+
route('get', `${prefix}~registry/dependencies`, 'dependencies', routes.dependencies);
|
|
50
|
+
route('get', `${prefix}~registry/history`, 'history', routes.history);
|
|
45
51
|
if (conf.discovery.validate) {
|
|
46
|
-
|
|
52
|
+
route('post', `${prefix}~registry/validate`, 'validate', routes.validate);
|
|
47
53
|
}
|
|
48
54
|
if (conf.local) {
|
|
49
|
-
|
|
55
|
+
route('get', `${prefix}:componentName/:componentVersion/${settings_1.default.registry.localStaticRedirectorPath}*splat`, 'local-static', routes.staticRedirector.localStatic);
|
|
50
56
|
}
|
|
51
57
|
else {
|
|
52
|
-
|
|
58
|
+
route('put', `${prefix}:componentName/:componentVersion`, 'publish', adapter.fromConnect(conf.beforePublish), routes.publish);
|
|
53
59
|
}
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
60
|
+
route('get', prefix, 'index', routes.index);
|
|
61
|
+
route('post', prefix, 'components', routes.components);
|
|
62
|
+
route('get', `${prefix}:componentName/:componentVersion${settings_1.default.registry.componentInfoPath}`, 'component-version-info', routes.componentInfo);
|
|
63
|
+
route('get', `${prefix}:componentName${settings_1.default.registry.componentInfoPath}`, 'component-info', routes.componentInfo);
|
|
64
|
+
route('get', `${prefix}:componentName/:componentVersion${settings_1.default.registry.componentPreviewPath}`, 'component-version-preview', routes.componentPreview);
|
|
65
|
+
route('get', `${prefix}:componentName${settings_1.default.registry.componentPreviewPath}`, 'component-preview', routes.componentPreview);
|
|
66
|
+
route('get', `${prefix}:componentName/:componentVersion`, 'component-version', routes.component);
|
|
67
|
+
route('get', `${prefix}:componentName`, 'component', routes.component);
|
|
68
|
+
route('post', `${prefix}~actions/:action/:componentName/:componentVersion`, 'component-version-action', routes.component);
|
|
69
|
+
route('post', `${prefix}~actions/:action/:componentName`, 'component-action', routes.component);
|
|
64
70
|
if (conf.routes) {
|
|
65
|
-
for (const
|
|
71
|
+
for (const routeConfig of conf.routes) {
|
|
66
72
|
// Ensure handler is a function (should be converted by options-sanitiser)
|
|
67
|
-
if (typeof
|
|
68
|
-
|
|
73
|
+
if (typeof routeConfig.handler === 'function') {
|
|
74
|
+
route(routeConfig.method.toLowerCase(), routeConfig.route, routeConfig.route, adapter.fromConnect(routeConfig.handler));
|
|
69
75
|
}
|
|
70
76
|
else {
|
|
71
|
-
console.warn(`Warning: Route handler for "${
|
|
77
|
+
console.warn(`Warning: Route handler for "${routeConfig.route}" is not a function. Skipping route.`);
|
|
72
78
|
}
|
|
73
79
|
}
|
|
74
80
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Request, Response } from 'express';
|
|
2
1
|
import type { Config } from '../../types';
|
|
2
|
+
import type { OcHandler } from '../domain/http-server/types';
|
|
3
3
|
import type { Repository } from '../domain/repository';
|
|
4
|
-
export default function componentInfoRoute(conf: Config, repository: Repository):
|
|
4
|
+
export default function componentInfoRoute(conf: Config, repository: Repository): OcHandler;
|
|
@@ -84,7 +84,7 @@ function componentInfo(err, req, res, component, componentDetail) {
|
|
|
84
84
|
href = `//${req.headers.host}${res.conf.prefix}`;
|
|
85
85
|
}
|
|
86
86
|
// Get theme from cookie or default to dark
|
|
87
|
-
const theme = req.cookies?.['oc-theme']
|
|
87
|
+
const theme = req.cookies?.['oc-theme'] === 'light' ? 'light' : 'dark';
|
|
88
88
|
res.send((0, info_1.default)({
|
|
89
89
|
component,
|
|
90
90
|
componentDetail,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Request, Response } from 'express';
|
|
2
1
|
import type { Config } from '../../types';
|
|
2
|
+
import type { OcHandler } from '../domain/http-server/types';
|
|
3
3
|
import type { Repository } from '../domain/repository';
|
|
4
|
-
export default function componentPreviewRoute(conf: Config, repository: Repository):
|
|
4
|
+
export default function componentPreviewRoute(conf: Config, repository: Repository): OcHandler;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { RequestHandler } from 'express';
|
|
2
1
|
import type { Config } from '../../types';
|
|
2
|
+
import type { OcHandler } from '../domain/http-server/types';
|
|
3
3
|
import type { Repository } from '../domain/repository';
|
|
4
|
-
export default function component(conf: Config, repository: Repository):
|
|
4
|
+
export default function component(conf: Config, repository: Repository): OcHandler;
|
|
@@ -70,7 +70,7 @@ function component(conf, repository) {
|
|
|
70
70
|
res.errorDetails = result.response.error;
|
|
71
71
|
}
|
|
72
72
|
try {
|
|
73
|
-
if (Object.keys(result.headers
|
|
73
|
+
if (result.headers && Object.keys(result.headers).length) {
|
|
74
74
|
res.set(result.headers);
|
|
75
75
|
}
|
|
76
76
|
if (Array.isArray(result.cookies) && result.cookies.length > 0) {
|
|
@@ -89,10 +89,8 @@ function component(conf, repository) {
|
|
|
89
89
|
nodeStream.on('error', (err) => {
|
|
90
90
|
res.status(500).end(String(err));
|
|
91
91
|
});
|
|
92
|
-
res.
|
|
93
|
-
|
|
94
|
-
res.end();
|
|
95
|
-
});
|
|
92
|
+
res.set('Content-Type', 'x-text/stream');
|
|
93
|
+
res.stream(nodeStream);
|
|
96
94
|
}
|
|
97
95
|
else {
|
|
98
96
|
res.status(result.status).json(result.response);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { RequestHandler } from 'express';
|
|
2
1
|
import type { Config } from '../../types';
|
|
2
|
+
import type { OcHandler } from '../domain/http-server/types';
|
|
3
3
|
import type { Repository } from '../domain/repository';
|
|
4
|
-
export default function components(conf: Config, repository: Repository):
|
|
4
|
+
export default function components(conf: Config, repository: Repository): OcHandler;
|