oc 0.50.55 → 0.50.57-beta.0
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 +16 -18
- package/.turbo/turbo-lint.log +2 -2
- package/.turbo/turbo-test-silent.log +28 -46
- package/.turbo/turbo-test.log +17 -1627
- package/CHANGELOG.md +14 -0
- package/README.md +180 -0
- package/dist/cli/commands.d.ts +8 -0
- package/dist/cli/commands.js +8 -0
- package/dist/cli/facade/dev.d.ts +2 -2
- package/dist/cli/facade/registry-migrate-metadata.d.ts +20 -0
- package/dist/cli/facade/registry-migrate-metadata.js +105 -0
- package/dist/cli/index.js +2 -0
- package/dist/components/oc-client/_package/package.json +1 -38
- package/dist/components/oc-client/_package/server.js +1 -1
- package/dist/components/oc-client/package.json +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/registry/domain/components-cache/index.d.ts +3 -1
- package/dist/registry/domain/components-cache/index.js +28 -5
- package/dist/registry/domain/components-details.d.ts +3 -1
- package/dist/registry/domain/components-details.js +26 -5
- package/dist/registry/domain/extract-package.d.ts +3 -2
- package/dist/registry/domain/http-server/express-adapter.d.ts +2 -0
- package/dist/registry/domain/http-server/express-adapter.js +196 -0
- package/dist/registry/domain/http-server/types.d.ts +99 -0
- package/dist/registry/domain/http-server/types.js +2 -0
- package/dist/registry/domain/metadata-adapter-options.d.ts +6 -0
- package/dist/registry/domain/metadata-adapter-options.js +12 -0
- package/dist/registry/domain/metadata-index.d.ts +15 -0
- package/dist/registry/domain/metadata-index.js +132 -0
- package/dist/registry/domain/metadata-migration.d.ts +38 -0
- package/dist/registry/domain/metadata-migration.js +128 -0
- package/dist/registry/domain/options-sanitiser.js +13 -0
- package/dist/registry/domain/repository.d.ts +1 -0
- package/dist/registry/domain/repository.js +106 -7
- package/dist/registry/domain/server-adapter.d.ts +4 -0
- package/dist/registry/domain/server-adapter.js +20 -0
- package/dist/registry/domain/validators/registry-configuration.js +21 -0
- package/dist/registry/domain/validators/uploaded-package.d.ts +5 -4
- package/dist/registry/index.d.ts +3 -3
- package/dist/registry/index.js +19 -17
- 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 +39 -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 +3 -1
- 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 +1 -1
- 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/resources/index.d.ts +3 -0
- package/dist/resources/index.js +3 -0
- package/dist/types.d.ts +49 -1
- package/package.json +7 -6
- 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
|
@@ -41,11 +41,16 @@ const node_path_1 = __importDefault(require("node:path"));
|
|
|
41
41
|
const dotenv_1 = __importDefault(require("dotenv"));
|
|
42
42
|
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
43
43
|
const oc_get_unix_utc_timestamp_1 = __importDefault(require("oc-get-unix-utc-timestamp"));
|
|
44
|
+
const oc_metadata_adapters_utils_1 = require("oc-metadata-adapters-utils");
|
|
44
45
|
const resources_1 = __importDefault(require("../../resources"));
|
|
45
46
|
const settings_1 = __importDefault(require("../../resources/settings"));
|
|
46
47
|
const error_to_string_1 = __importDefault(require("../../utils/error-to-string"));
|
|
47
48
|
const components_cache_1 = __importDefault(require("./components-cache"));
|
|
48
49
|
const components_details_1 = __importDefault(require("./components-details"));
|
|
50
|
+
const events_handler_1 = __importDefault(require("./events-handler"));
|
|
51
|
+
const metadata_adapter_options_1 = __importDefault(require("./metadata-adapter-options"));
|
|
52
|
+
const metadata_index_1 = require("./metadata-index");
|
|
53
|
+
const metadata_migration_1 = require("./metadata-migration");
|
|
49
54
|
const register_templates_1 = __importDefault(require("./register-templates"));
|
|
50
55
|
const storage_adapter_1 = __importDefault(require("./storage-adapter"));
|
|
51
56
|
const validator = __importStar(require("./validators"));
|
|
@@ -58,10 +63,56 @@ function repository(conf) {
|
|
|
58
63
|
const repositorySource = conf.local
|
|
59
64
|
? 'local repository'
|
|
60
65
|
: cdn.adapterType + ' cdn';
|
|
61
|
-
const
|
|
62
|
-
|
|
66
|
+
const metadataStore = !conf.local && conf.metadata
|
|
67
|
+
? conf.metadata.adapter((0, metadata_adapter_options_1.default)(conf))
|
|
68
|
+
: undefined;
|
|
69
|
+
const metadataIndex = metadataStore
|
|
70
|
+
? (0, metadata_index_1.createMetadataIndex)(metadataStore)
|
|
71
|
+
: undefined;
|
|
72
|
+
const componentsCache = (0, components_cache_1.default)(conf, cdn, metadataIndex);
|
|
73
|
+
const componentsDetails = (0, components_details_1.default)(conf, cdn, metadataIndex);
|
|
74
|
+
let exportLegacyFilesLoop;
|
|
75
|
+
let closed = false;
|
|
63
76
|
const getFilePath = (component, version, filePath) => `${options.componentsDir}/${component}/${version}/${filePath}`;
|
|
77
|
+
const exportLegacyFiles = () => {
|
|
78
|
+
if (!metadataStore || !conf.metadata?.exportLegacyFiles) {
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
return (0, metadata_migration_1.exportLegacyMetadataFiles)({
|
|
82
|
+
metadataStore,
|
|
83
|
+
cdn,
|
|
84
|
+
componentsDir: options.componentsDir
|
|
85
|
+
}).catch((err) => events_handler_1.default.fire('error', {
|
|
86
|
+
code: 'metadata_legacy_files_export',
|
|
87
|
+
message: err?.message || String(err)
|
|
88
|
+
}));
|
|
89
|
+
};
|
|
90
|
+
// Run the DB→components.json export on a non-overlapping background timer
|
|
91
|
+
// instead of on the publish path, so a publish stays an O(1) append rather
|
|
92
|
+
// than triggering a full-registry scan + blob rewrite. The timer only runs
|
|
93
|
+
// when an interval is explicitly configured.
|
|
94
|
+
const scheduleLegacyFilesExport = () => {
|
|
95
|
+
const intervalSeconds = conf.metadata?.exportLegacyFilesInterval;
|
|
96
|
+
if (closed ||
|
|
97
|
+
!metadataStore ||
|
|
98
|
+
!conf.metadata?.exportLegacyFiles ||
|
|
99
|
+
!intervalSeconds) {
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
exportLegacyFilesLoop = setTimeout(async () => {
|
|
103
|
+
await exportLegacyFiles();
|
|
104
|
+
if (!closed) {
|
|
105
|
+
scheduleLegacyFilesExport();
|
|
106
|
+
}
|
|
107
|
+
}, intervalSeconds * 1000);
|
|
108
|
+
};
|
|
64
109
|
const { templatesHash, templatesInfo } = (0, register_templates_1.default)(conf.templates, conf.local);
|
|
110
|
+
const throwVersionAlreadyFound = (componentName, componentVersion) => {
|
|
111
|
+
throw {
|
|
112
|
+
code: resources_1.default.errors.registry.COMPONENT_VERSION_ALREADY_FOUND_CODE,
|
|
113
|
+
msg: resources_1.default.errors.registry.COMPONENT_VERSION_ALREADY_FOUND(componentName, componentVersion, repositorySource)
|
|
114
|
+
};
|
|
115
|
+
};
|
|
65
116
|
const local = {
|
|
66
117
|
components: undefined,
|
|
67
118
|
getCompiledView(componentName) {
|
|
@@ -222,8 +273,21 @@ function repository(conf) {
|
|
|
222
273
|
// when in local this won't get called
|
|
223
274
|
return;
|
|
224
275
|
}
|
|
276
|
+
if (metadataStore) {
|
|
277
|
+
await metadataStore.initialise();
|
|
278
|
+
if (conf.metadata?.reconcileFromStorage) {
|
|
279
|
+
await (0, metadata_migration_1.reconcileMetadataFromStorage)({
|
|
280
|
+
metadataStore,
|
|
281
|
+
cdn,
|
|
282
|
+
componentsDir: options.componentsDir
|
|
283
|
+
});
|
|
284
|
+
}
|
|
285
|
+
}
|
|
225
286
|
const componentsList = await componentsCache.load();
|
|
226
|
-
|
|
287
|
+
const details = await componentsDetails.refresh(componentsList);
|
|
288
|
+
void exportLegacyFiles();
|
|
289
|
+
scheduleLegacyFilesExport();
|
|
290
|
+
return details;
|
|
227
291
|
},
|
|
228
292
|
async publishComponent({ componentName, componentVersion, pkgDetails, user, dryRun = false }) {
|
|
229
293
|
if (conf.local) {
|
|
@@ -257,21 +321,56 @@ function repository(conf) {
|
|
|
257
321
|
}
|
|
258
322
|
const componentVersions = await repository.getComponentVersions(componentName);
|
|
259
323
|
if (!versionHandler.validateNewVersion(componentVersion, componentVersions)) {
|
|
260
|
-
|
|
261
|
-
code: resources_1.default.errors.registry.COMPONENT_VERSION_ALREADY_FOUND_CODE,
|
|
262
|
-
msg: resources_1.default.errors.registry.COMPONENT_VERSION_ALREADY_FOUND(componentName, componentVersion, repositorySource)
|
|
263
|
-
};
|
|
324
|
+
throwVersionAlreadyFound(componentName, componentVersion);
|
|
264
325
|
}
|
|
265
326
|
pkgDetails.packageJson.oc.date = (0, oc_get_unix_utc_timestamp_1.default)();
|
|
266
327
|
pkgDetails.packageJson.oc.publisher = user;
|
|
267
328
|
if (dryRun)
|
|
268
329
|
return;
|
|
269
330
|
await fs_extra_1.default.writeJson(node_path_1.default.join(pkgDetails.outputFolder, 'package.json'), pkgDetails.packageJson);
|
|
331
|
+
if (metadataStore) {
|
|
332
|
+
const componentRow = (0, metadata_index_1.getComponentRow)(componentName, componentVersion, pkgDetails.packageJson);
|
|
333
|
+
const { token } = await metadataStore
|
|
334
|
+
.reserveVersion(componentRow)
|
|
335
|
+
.catch((err) => {
|
|
336
|
+
if (err?.code === oc_metadata_adapters_utils_1.VERSION_ALREADY_EXISTS ||
|
|
337
|
+
err?.code === oc_metadata_adapters_utils_1.VERSION_PUBLISH_IN_PROGRESS ||
|
|
338
|
+
err?.code ===
|
|
339
|
+
resources_1.default.errors.registry.COMPONENT_VERSION_ALREADY_FOUND_CODE) {
|
|
340
|
+
throwVersionAlreadyFound(componentName, componentVersion);
|
|
341
|
+
}
|
|
342
|
+
throw err;
|
|
343
|
+
});
|
|
344
|
+
try {
|
|
345
|
+
await cdn.putDir(pkgDetails.outputFolder, `${options.componentsDir}/${componentName}/${componentVersion}`);
|
|
346
|
+
await metadataStore.commitVersion(componentName, componentVersion, token);
|
|
347
|
+
metadataIndex.add(componentRow);
|
|
348
|
+
}
|
|
349
|
+
catch (err) {
|
|
350
|
+
await metadataStore
|
|
351
|
+
.abortVersion(componentName, componentVersion, token)
|
|
352
|
+
.catch(() => undefined);
|
|
353
|
+
throw err;
|
|
354
|
+
}
|
|
355
|
+
return;
|
|
356
|
+
}
|
|
270
357
|
await cdn.putDir(pkgDetails.outputFolder, `${options.componentsDir}/${componentName}/${componentVersion}`);
|
|
271
358
|
void componentsCache
|
|
272
359
|
.refresh()
|
|
273
360
|
.then((componentsList) => componentsDetails.refresh(componentsList))
|
|
274
361
|
.catch(() => undefined);
|
|
362
|
+
},
|
|
363
|
+
async close() {
|
|
364
|
+
closed = true;
|
|
365
|
+
componentsCache.close?.();
|
|
366
|
+
componentsDetails.close?.();
|
|
367
|
+
if (exportLegacyFilesLoop) {
|
|
368
|
+
clearTimeout(exportLegacyFilesLoop);
|
|
369
|
+
exportLegacyFilesLoop = undefined;
|
|
370
|
+
}
|
|
371
|
+
if (metadataStore?.close) {
|
|
372
|
+
await metadataStore.close();
|
|
373
|
+
}
|
|
275
374
|
}
|
|
276
375
|
};
|
|
277
376
|
return repository;
|
|
@@ -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
|
+
}
|
|
@@ -39,6 +39,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
39
39
|
exports.default = registryConfiguration;
|
|
40
40
|
const resources_1 = __importDefault(require("../../../resources"));
|
|
41
41
|
const auth = __importStar(require("../authentication"));
|
|
42
|
+
const metadata_adapter_options_1 = __importDefault(require("../metadata-adapter-options"));
|
|
42
43
|
function registryConfiguration(conf) {
|
|
43
44
|
const returnError = (message) => {
|
|
44
45
|
return {
|
|
@@ -111,6 +112,26 @@ function registryConfiguration(conf) {
|
|
|
111
112
|
}
|
|
112
113
|
}
|
|
113
114
|
}
|
|
115
|
+
if (!conf.local && conf.metadata) {
|
|
116
|
+
if (!conf.metadata.adapter) {
|
|
117
|
+
return returnError(resources_1.default.errors.registry.CONFIGURATION_METADATA_NOT_VALID('metadata'));
|
|
118
|
+
}
|
|
119
|
+
if (typeof conf.metadata.exportLegacyFilesInterval !== 'undefined') {
|
|
120
|
+
if (!Number.isFinite(conf.metadata.exportLegacyFilesInterval) ||
|
|
121
|
+
conf.metadata.exportLegacyFilesInterval <= 0) {
|
|
122
|
+
return returnError(resources_1.default.errors.registry
|
|
123
|
+
.CONFIGURATION_METADATA_EXPORT_INTERVAL_NOT_VALID);
|
|
124
|
+
}
|
|
125
|
+
if (conf.metadata.exportLegacyFiles !== true) {
|
|
126
|
+
return returnError(resources_1.default.errors.registry
|
|
127
|
+
.CONFIGURATION_METADATA_EXPORT_INTERVAL_WITHOUT_EXPORT_NOT_VALID);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
const metadataStore = conf.metadata.adapter((0, metadata_adapter_options_1.default)(conf));
|
|
131
|
+
if (!metadataStore.isValid()) {
|
|
132
|
+
return returnError(resources_1.default.errors.registry.CONFIGURATION_METADATA_NOT_VALID(metadataStore.adapterType));
|
|
133
|
+
}
|
|
134
|
+
}
|
|
114
135
|
if (conf.customHeadersToSkipOnWeakVersion) {
|
|
115
136
|
if (!Array.isArray(conf.customHeadersToSkipOnWeakVersion)) {
|
|
116
137
|
return returnError(resources_1.default.errors.registry
|
|
@@ -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 {};
|
package/dist/registry/index.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import http from 'node:http';
|
|
2
|
-
import express from 'express';
|
|
1
|
+
import type http from 'node:http';
|
|
2
|
+
import type express from 'express';
|
|
3
3
|
import type { Plugin } from '../types';
|
|
4
4
|
import { RegistryOptions } from './domain/options-sanitiser';
|
|
5
5
|
export { RegistryOptions };
|
|
6
6
|
export default function registry<T = any>(inputOptions: RegistryOptions<T>): {
|
|
7
|
-
close: (callback: (err?: Error | undefined | string) => void) => void
|
|
7
|
+
close: (callback: (err?: Error | undefined | string) => void) => void;
|
|
8
8
|
on: <T_1 extends keyof {
|
|
9
9
|
error: {
|
|
10
10
|
code: string;
|
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,14 +54,18 @@ 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
|
-
|
|
63
|
-
|
|
61
|
+
const closeMetadataStore = () => Promise.resolve(repository.close?.()).catch(() => undefined);
|
|
62
|
+
if (adapter.isListening()) {
|
|
63
|
+
adapter.close((err) => {
|
|
64
|
+
void closeMetadataStore().finally(() => callback(err));
|
|
65
|
+
});
|
|
66
|
+
return;
|
|
64
67
|
}
|
|
65
|
-
|
|
68
|
+
void closeMetadataStore().finally(() => callback('not opened'));
|
|
66
69
|
};
|
|
67
70
|
const register = (plugin, callback) => {
|
|
68
71
|
plugins.push(Object.assign(plugin, { callback }));
|
|
@@ -71,30 +74,29 @@ function registry(inputOptions) {
|
|
|
71
74
|
const ok = (msg) => console.log(safe_1.default.green(msg));
|
|
72
75
|
try {
|
|
73
76
|
options.plugins = await pluginsInitialiser.init(plugins);
|
|
74
|
-
(0, router_1.create)(
|
|
77
|
+
(0, router_1.create)(adapter, options, repository);
|
|
75
78
|
const componentsInfo = await repository.init();
|
|
76
79
|
await (0, app_start_1.default)(repository, options);
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
}
|
|
82
|
-
server.listen(options.port, (err) => {
|
|
80
|
+
adapter.listen({
|
|
81
|
+
port: options.port,
|
|
82
|
+
timeout: options.timeout,
|
|
83
|
+
keepAliveTimeout: options.keepAliveTimeout
|
|
84
|
+
}, (err) => {
|
|
83
85
|
if (err) {
|
|
84
86
|
return callback(err);
|
|
85
87
|
}
|
|
86
88
|
events_handler_1.default.fire('start', {});
|
|
87
89
|
if (options.verbosity) {
|
|
88
|
-
ok(`Registry started at port http://localhost:${
|
|
90
|
+
ok(`Registry started at port http://localhost:${options.port}${options.prefix}`);
|
|
89
91
|
if (componentsInfo) {
|
|
90
92
|
const componentsNumber = Object.keys(componentsInfo.components).length;
|
|
91
93
|
const componentsReleases = Object.values(componentsInfo.components).reduce((acc, component) => acc + Object.keys(component).length, 0);
|
|
92
94
|
ok(`Registry serving ${componentsNumber} components for a total of ${componentsReleases} releases.`);
|
|
93
95
|
}
|
|
94
96
|
}
|
|
95
|
-
callback(null, { app, server });
|
|
97
|
+
callback(null, { app, server: adapter.httpServer() });
|
|
96
98
|
});
|
|
97
|
-
|
|
99
|
+
adapter.onServerError((error) => {
|
|
98
100
|
events_handler_1.default.fire('error', {
|
|
99
101
|
code: 'EXPRESS_ERROR',
|
|
100
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,57 @@ 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
|
+
const data = {
|
|
18
|
+
body: req.body,
|
|
19
|
+
duration: time,
|
|
20
|
+
headers: req.headers,
|
|
21
|
+
method: req.method,
|
|
22
|
+
path: req.path,
|
|
23
|
+
relativeUrl: req.originalUrl,
|
|
24
|
+
query: req.query,
|
|
25
|
+
url: req.protocol + '://' + req.get('host') + req.originalUrl,
|
|
26
|
+
statusCode: res.statusCode
|
|
27
|
+
};
|
|
28
|
+
if (res.errorDetails) {
|
|
29
|
+
data.errorDetails = res.errorDetails;
|
|
30
|
+
}
|
|
31
|
+
if (res.errorCode) {
|
|
32
|
+
data.errorCode = res.errorCode;
|
|
33
|
+
}
|
|
34
|
+
events_handler_1.default.fire('request', data);
|
|
35
|
+
});
|
|
36
|
+
adapter.enableCookies();
|
|
37
|
+
adapter.enableBodyParser({ limit: options.postRequestPayloadSize });
|
|
38
|
+
adapter.use(cors_1.default);
|
|
39
|
+
if (!options.local) {
|
|
40
|
+
adapter.enableFileUploads({
|
|
41
|
+
tempDir: options.tempDir,
|
|
42
|
+
filename: (originalName) => `${normaliseFileName(originalName)}-${Date.now()}.tar.gz`
|
|
43
|
+
});
|
|
37
44
|
}
|
|
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);
|
|
45
|
+
adapter.use(base_url_handler_1.default);
|
|
46
|
+
adapter.use(discovery_handler_1.default);
|
|
44
47
|
if (options.verbosity) {
|
|
45
|
-
|
|
48
|
+
adapter.enableLogging({
|
|
46
49
|
skip: (req, res) => {
|
|
47
50
|
// Hide logging development console calls
|
|
48
|
-
return req.url.startsWith(`${res.conf
|
|
51
|
+
return req.url.startsWith(`${res.conf?.prefix ?? ''}~actions/$$__oc__server___console__$$`);
|
|
49
52
|
}
|
|
50
|
-
})
|
|
53
|
+
});
|
|
51
54
|
}
|
|
52
55
|
if (options.local) {
|
|
53
|
-
|
|
56
|
+
adapter.enableErrorHandler();
|
|
54
57
|
}
|
|
55
|
-
return
|
|
58
|
+
return adapter;
|
|
56
59
|
};
|
|
57
60
|
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
|
}
|