oc 0.50.64 → 0.50.66
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 +5 -5
- package/.turbo/turbo-lint.log +3 -3
- package/.turbo/turbo-test-silent.log +5 -11
- package/CHANGELOG.md +25 -0
- package/dist/cli/domain/get-mocked-plugins.js +1 -3
- package/dist/cli/domain/handle-dependencies/index.js +2 -2
- package/dist/cli/domain/init-template/install-template.js +1 -1
- package/dist/cli/domain/local.js +2 -11
- package/dist/cli/domain/url-parser.js +3 -4
- package/dist/cli/facade/clean.d.ts +1 -1
- package/dist/cli/facade/clean.js +1 -1
- package/dist/cli/facade/dev.d.ts +1 -1
- package/dist/cli/facade/dev.js +4 -5
- package/dist/cli/facade/init.d.ts +1 -1
- package/dist/cli/facade/init.js +1 -1
- package/dist/cli/facade/mock.d.ts +1 -1
- package/dist/cli/facade/mock.js +1 -1
- package/dist/cli/facade/package.d.ts +1 -1
- package/dist/cli/facade/package.js +1 -1
- package/dist/cli/facade/preview.d.ts +1 -1
- package/dist/cli/facade/preview.js +1 -1
- package/dist/cli/facade/publish.d.ts +1 -1
- package/dist/cli/facade/publish.js +1 -1
- package/dist/cli/facade/registry-add.d.ts +1 -1
- package/dist/cli/facade/registry-add.js +1 -1
- package/dist/cli/facade/registry-ls.d.ts +1 -1
- package/dist/cli/facade/registry-ls.js +1 -1
- package/dist/cli/facade/registry-migrate-metadata.d.ts +1 -1
- package/dist/cli/facade/registry-migrate-metadata.js +1 -1
- package/dist/cli/facade/registry-remove.d.ts +1 -1
- package/dist/cli/facade/registry-remove.js +1 -1
- package/dist/cli/facade/registry.d.ts +1 -1
- package/dist/cli/facade/registry.js +1 -1
- package/dist/cli/facade/validate.d.ts +1 -1
- package/dist/cli/facade/validate.js +1 -1
- 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/src/oc-client.js +2 -2
- package/dist/components/oc-client/_package/src/oc-client.min.js +1 -1
- package/dist/components/oc-client/package-lock.json +34 -34
- package/dist/components/oc-client/package.json +1 -1
- package/dist/components/oc-client/src/oc-client.js +2 -2
- package/dist/components/oc-client/src/oc-client.min.js +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/registry/domain/components-cache/components-list.js +3 -3
- package/dist/registry/domain/components-cache/index.js +4 -4
- package/dist/registry/domain/components-details.js +5 -5
- package/dist/registry/domain/extract-package.js +2 -11
- package/dist/registry/domain/metadata-index.js +1 -1
- package/dist/registry/domain/plugins-initialiser.js +18 -10
- package/dist/registry/domain/repository.d.ts +1 -0
- package/dist/registry/domain/repository.js +9 -3
- package/dist/registry/domain/require-wrapper.js +5 -5
- package/dist/registry/domain/storage-adapter.js +1 -1
- package/dist/registry/domain/url-builder.js +21 -3
- package/dist/registry/domain/validators/registry-configuration.js +5 -0
- package/dist/registry/domain/version-handler.d.ts +1 -0
- package/dist/registry/domain/version-handler.js +13 -4
- package/dist/registry/routes/component-info.js +2 -2
- package/dist/registry/routes/component-preview.js +1 -1
- package/dist/registry/routes/component.js +2 -2
- package/dist/registry/routes/helpers/get-available-dependencies.js +2 -2
- package/dist/registry/routes/helpers/get-component.js +73 -6
- package/dist/registry/routes/index.js +1 -1
- package/dist/resources/index.d.ts +3 -0
- package/dist/resources/index.js +3 -0
- package/dist/types.d.ts +40 -0
- package/dist/utils/accept-language.d.ts +7 -0
- package/dist/utils/accept-language.js +21 -0
- package/dist/utils/clean-require.js +3 -5
- package/dist/utils/core-modules.d.ts +2 -0
- package/dist/utils/core-modules.js +7 -0
- package/dist/utils/get-port.d.ts +1 -0
- package/dist/utils/get-port.js +21 -0
- package/dist/utils/is-equal.d.ts +1 -0
- package/dist/utils/is-equal.js +17 -0
- package/dist/utils/module-exists.js +1 -1
- package/dist/utils/parse-author.d.ts +6 -0
- package/dist/utils/parse-author.js +27 -0
- package/dist/utils/put.js +4 -5
- package/dist/utils/serialize-error.d.ts +1 -0
- package/dist/utils/serialize-error.js +66 -0
- package/dist/utils/targz.d.ts +2 -0
- package/dist/utils/targz.js +56 -0
- package/dist/utils/try-require.d.ts +5 -0
- package/dist/utils/try-require.js +16 -0
- package/dist/utils/universalify.d.ts +10 -0
- package/dist/utils/universalify.js +25 -0
- package/dist/utils/unix-utc-timestamp.d.ts +1 -0
- package/dist/utils/unix-utc-timestamp.js +7 -0
- package/package.json +23 -45
|
@@ -8,12 +8,30 @@ exports.componentInfo = componentInfo;
|
|
|
8
8
|
exports.componentPreview = componentPreview;
|
|
9
9
|
exports.queryString = queryString;
|
|
10
10
|
const node_querystring_1 = __importDefault(require("node:querystring"));
|
|
11
|
-
const
|
|
11
|
+
const resolveUrl = (baseUrl, path) => {
|
|
12
|
+
const hasProtocol = /^[a-z][a-z\d+.-]*:/i;
|
|
13
|
+
if (hasProtocol.test(baseUrl)) {
|
|
14
|
+
return new URL(path, baseUrl).toString();
|
|
15
|
+
}
|
|
16
|
+
// WHATWG URLs need an absolute base; discard the synthetic origin afterward.
|
|
17
|
+
const base = new URL(baseUrl, 'http://relative.invalid/');
|
|
18
|
+
const resolved = new URL(path, base);
|
|
19
|
+
if (hasProtocol.test(path)) {
|
|
20
|
+
return resolved.toString();
|
|
21
|
+
}
|
|
22
|
+
if (baseUrl.startsWith('//') || path.startsWith('//')) {
|
|
23
|
+
return resolved.toString().slice(resolved.protocol.length);
|
|
24
|
+
}
|
|
25
|
+
const relative = resolved.pathname + resolved.search + resolved.hash;
|
|
26
|
+
return baseUrl.startsWith('/') || path.startsWith('/')
|
|
27
|
+
? relative
|
|
28
|
+
: relative.slice(1);
|
|
29
|
+
};
|
|
12
30
|
function componentForType(component, baseUrl, type) {
|
|
13
31
|
if (typeof component === 'string') {
|
|
14
32
|
component = { name: component };
|
|
15
33
|
}
|
|
16
|
-
let href =
|
|
34
|
+
let href = resolveUrl(baseUrl, component.name) + '/';
|
|
17
35
|
if (component.version) {
|
|
18
36
|
href += component.version + '/';
|
|
19
37
|
}
|
|
@@ -24,7 +42,7 @@ function component(component, baseUrl) {
|
|
|
24
42
|
if (typeof component === 'string') {
|
|
25
43
|
component = { name: component };
|
|
26
44
|
}
|
|
27
|
-
let componentUrl =
|
|
45
|
+
let componentUrl = resolveUrl(baseUrl, component.name);
|
|
28
46
|
if (component.version) {
|
|
29
47
|
componentUrl += '/' + component.version;
|
|
30
48
|
}
|
|
@@ -148,5 +148,10 @@ function registryConfiguration(conf) {
|
|
|
148
148
|
.CONFIGURATION_HEADERS_TO_SKIP_MUST_BE_STRING_ARRAY);
|
|
149
149
|
}
|
|
150
150
|
}
|
|
151
|
+
if (conf.onComponentRequest !== undefined &&
|
|
152
|
+
typeof conf.onComponentRequest !== 'function') {
|
|
153
|
+
return returnError(resources_1.default.errors.registry
|
|
154
|
+
.CONFIGURATION_ON_COMPONENT_REQUEST_MUST_BE_FUNCTION);
|
|
155
|
+
}
|
|
151
156
|
return { isValid: true };
|
|
152
157
|
}
|
|
@@ -1,2 +1,3 @@
|
|
|
1
|
+
export declare function getLatestVersion(availableVersions: readonly string[]): string | undefined;
|
|
1
2
|
export declare function getAvailableVersion(requestedVersion: string | undefined, availableVersions: string[]): string | undefined;
|
|
2
3
|
export declare function validateNewVersion(requestedVersion: string, availableVersions: string[]): boolean;
|
|
@@ -3,15 +3,24 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.getLatestVersion = getLatestVersion;
|
|
6
7
|
exports.getAvailableVersion = getAvailableVersion;
|
|
7
8
|
exports.validateNewVersion = validateNewVersion;
|
|
8
9
|
const semver_1 = __importDefault(require("semver"));
|
|
9
|
-
const
|
|
10
|
+
const latestVersions = new WeakMap();
|
|
11
|
+
function getLatestVersion(availableVersions) {
|
|
12
|
+
if (latestVersions.has(availableVersions)) {
|
|
13
|
+
return latestVersions.get(availableVersions);
|
|
14
|
+
}
|
|
15
|
+
const latest = semver_1.default.maxSatisfying(availableVersions, '') ||
|
|
16
|
+
[...availableVersions].sort(semver_1.default.rcompare)[0] ||
|
|
17
|
+
undefined;
|
|
18
|
+
latestVersions.set(availableVersions, latest);
|
|
19
|
+
return latest;
|
|
20
|
+
}
|
|
10
21
|
function getAvailableVersion(requestedVersion, availableVersions) {
|
|
11
22
|
if (!requestedVersion) {
|
|
12
|
-
return (
|
|
13
|
-
semver_extra_1.default.max(availableVersions) ||
|
|
14
|
-
undefined);
|
|
23
|
+
return getLatestVersion(availableVersions);
|
|
15
24
|
}
|
|
16
25
|
if (availableVersions.includes(requestedVersion)) {
|
|
17
26
|
return requestedVersion;
|
|
@@ -37,8 +37,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
37
37
|
};
|
|
38
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
39
|
exports.default = componentInfoRoute;
|
|
40
|
-
const parse_author_1 = __importDefault(require("parse-author"));
|
|
41
|
-
const universalify_1 = require("universalify");
|
|
40
|
+
const parse_author_1 = __importDefault(require("../../utils/parse-author"));
|
|
41
|
+
const universalify_1 = require("../../utils/universalify");
|
|
42
42
|
const urlBuilder = __importStar(require("../domain/url-builder"));
|
|
43
43
|
const info_1 = __importDefault(require("../views/info"));
|
|
44
44
|
const getComponentFallback = __importStar(require("./helpers/get-component-fallback"));
|
|
@@ -37,8 +37,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
37
37
|
};
|
|
38
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
39
|
exports.default = componentPreviewRoute;
|
|
40
|
-
const universalify_1 = require("universalify");
|
|
41
40
|
const ocConfig_1 = require("../../cli/domain/ocConfig");
|
|
41
|
+
const universalify_1 = require("../../utils/universalify");
|
|
42
42
|
const urlBuilder = __importStar(require("../domain/url-builder"));
|
|
43
43
|
const preview_1 = __importDefault(require("../views/preview"));
|
|
44
44
|
const getComponentFallback = __importStar(require("./helpers/get-component-fallback"));
|
|
@@ -39,8 +39,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
39
39
|
exports.default = component;
|
|
40
40
|
const node_stream_1 = require("node:stream");
|
|
41
41
|
const turbo_stream_1 = require("@rdevis/turbo-stream");
|
|
42
|
-
const serialize_error_1 = require("serialize-error");
|
|
43
42
|
const resources_1 = __importDefault(require("../../resources"));
|
|
43
|
+
const serialize_error_1 = __importDefault(require("../../utils/serialize-error"));
|
|
44
44
|
const get_component_1 = __importStar(require("./helpers/get-component"));
|
|
45
45
|
function component(conf, repository, getComponent = (0, get_component_1.default)(conf, repository)) {
|
|
46
46
|
return (req, res) => {
|
|
@@ -63,7 +63,7 @@ function component(conf, repository, getComponent = (0, get_component_1.default)
|
|
|
63
63
|
if (result.response.error) {
|
|
64
64
|
if (Object.prototype.toString.call(result.response.error) ===
|
|
65
65
|
'[object Error]') {
|
|
66
|
-
result.response.error = (0, serialize_error_1.
|
|
66
|
+
result.response.error = (0, serialize_error_1.default)(result.response.error);
|
|
67
67
|
}
|
|
68
68
|
res.errorCode = result.response.code;
|
|
69
69
|
res.errorDetails = result.response.error;
|
|
@@ -4,12 +4,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.default = getAvailableDependencies;
|
|
7
|
-
const
|
|
7
|
+
const core_modules_1 = __importDefault(require("../../../utils/core-modules"));
|
|
8
8
|
const require_wrapper_1 = __importDefault(require("../../domain/require-wrapper"));
|
|
9
9
|
function getAvailableDependencies(dependencies) {
|
|
10
10
|
return dependencies.map((dependency) => {
|
|
11
11
|
const requirer = (0, require_wrapper_1.default)(dependencies);
|
|
12
|
-
const core =
|
|
12
|
+
const core = core_modules_1.default.includes(dependency);
|
|
13
13
|
const packageJson = !core
|
|
14
14
|
? requirer(`${dependency}/package.json`)
|
|
15
15
|
: undefined;
|
|
@@ -41,14 +41,15 @@ exports.default = getComponent;
|
|
|
41
41
|
const node_crypto_1 = require("node:crypto");
|
|
42
42
|
const node_domain_1 = __importDefault(require("node:domain"));
|
|
43
43
|
const node_vm_1 = __importDefault(require("node:vm"));
|
|
44
|
-
const accept_language_parser_1 = __importDefault(require("accept-language-parser"));
|
|
45
44
|
const oc_client_1 = __importDefault(require("oc-client"));
|
|
46
45
|
const oc_empty_response_handler_1 = __importDefault(require("oc-empty-response-handler"));
|
|
47
|
-
const universalify_1 = require("universalify");
|
|
48
46
|
const resources_1 = __importDefault(require("../../../resources"));
|
|
49
47
|
const settings_1 = __importDefault(require("../../../resources/settings"));
|
|
48
|
+
const accept_language_1 = require("../../../utils/accept-language");
|
|
50
49
|
const bounded_cache_1 = __importDefault(require("../../../utils/bounded-cache"));
|
|
50
|
+
const error_to_string_1 = __importDefault(require("../../../utils/error-to-string"));
|
|
51
51
|
const is_template_legacy_1 = __importDefault(require("../../../utils/is-template-legacy"));
|
|
52
|
+
const universalify_1 = require("../../../utils/universalify");
|
|
52
53
|
const events_handler_1 = __importDefault(require("../../domain/events-handler"));
|
|
53
54
|
const nested_renderer_1 = __importDefault(require("../../domain/nested-renderer"));
|
|
54
55
|
const require_wrapper_1 = __importDefault(require("../../domain/require-wrapper"));
|
|
@@ -58,6 +59,12 @@ const validators_1 = require("../../domain/validators");
|
|
|
58
59
|
const component_parameter_processor_1 = require("./component-parameter-processor");
|
|
59
60
|
const format_error_stack_1 = require("./format-error-stack");
|
|
60
61
|
const getComponentFallback = __importStar(require("./get-component-fallback"));
|
|
62
|
+
class ComponentRequestRejected {
|
|
63
|
+
result;
|
|
64
|
+
constructor(result) {
|
|
65
|
+
this.result = result;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
61
68
|
exports.stream = Symbol('stream');
|
|
62
69
|
const MAX_ARTIFACT_CACHE_ENTRIES = 1000;
|
|
63
70
|
const noop = () => { };
|
|
@@ -207,6 +214,62 @@ function getComponent(conf, repository) {
|
|
|
207
214
|
// keep the original error stack when local diagnostics fail
|
|
208
215
|
}
|
|
209
216
|
};
|
|
217
|
+
const resolveComponent = (name, version, options, cb) => {
|
|
218
|
+
getComponentCb(name, version, (err, component) => {
|
|
219
|
+
const hook = options.conf.onComponentRequest;
|
|
220
|
+
if (err || !hook) {
|
|
221
|
+
return cb(err, component);
|
|
222
|
+
}
|
|
223
|
+
const decide = (rejection) => rejection
|
|
224
|
+
? cb(new ComponentRequestRejected({
|
|
225
|
+
status: rejection.status ?? 403,
|
|
226
|
+
response: {
|
|
227
|
+
code: rejection.code ?? 'COMPONENT_REQUEST_REJECTED',
|
|
228
|
+
error: rejection.error ??
|
|
229
|
+
resources_1.default.errors.registry.COMPONENT_REQUEST_REJECTED
|
|
230
|
+
}
|
|
231
|
+
}), component)
|
|
232
|
+
: cb(null, component);
|
|
233
|
+
const fail = (hookErr) => {
|
|
234
|
+
const message = (0, error_to_string_1.default)(hookErr);
|
|
235
|
+
events_handler_1.default.fire('error', {
|
|
236
|
+
code: 'COMPONENT_REQUEST_HOOK_FAILED',
|
|
237
|
+
message
|
|
238
|
+
});
|
|
239
|
+
cb(new ComponentRequestRejected({
|
|
240
|
+
status: 500,
|
|
241
|
+
response: {
|
|
242
|
+
code: 'COMPONENT_REQUEST_HOOK_FAILED',
|
|
243
|
+
error: resources_1.default.errors.registry.COMPONENT_REQUEST_HOOK_FAILED(message)
|
|
244
|
+
}
|
|
245
|
+
}), component);
|
|
246
|
+
};
|
|
247
|
+
let decision;
|
|
248
|
+
try {
|
|
249
|
+
decision = hook({
|
|
250
|
+
name,
|
|
251
|
+
requestedVersion: version,
|
|
252
|
+
version: component.version,
|
|
253
|
+
get latestVersion() {
|
|
254
|
+
return repository.getLatestVersion(component);
|
|
255
|
+
},
|
|
256
|
+
component,
|
|
257
|
+
headers: options.headers,
|
|
258
|
+
parameters: options.parameters,
|
|
259
|
+
action: options.action
|
|
260
|
+
});
|
|
261
|
+
}
|
|
262
|
+
catch (hookErr) {
|
|
263
|
+
return fail(hookErr);
|
|
264
|
+
}
|
|
265
|
+
if (decision instanceof Promise) {
|
|
266
|
+
decision.then(decide, fail);
|
|
267
|
+
}
|
|
268
|
+
else {
|
|
269
|
+
decide(decision);
|
|
270
|
+
}
|
|
271
|
+
});
|
|
272
|
+
};
|
|
210
273
|
const renderer = (options, cb) => {
|
|
211
274
|
const retrievalStart = process.hrtime.bigint();
|
|
212
275
|
let retrievedHref;
|
|
@@ -260,7 +323,10 @@ function getComponent(conf, repository) {
|
|
|
260
323
|
version: options.version || '',
|
|
261
324
|
parameters: options.parameters
|
|
262
325
|
};
|
|
263
|
-
|
|
326
|
+
resolveComponent(requestedComponent.name, requestedComponent.version, options, (err, component) => {
|
|
327
|
+
if (err instanceof ComponentRequestRejected) {
|
|
328
|
+
return callback(err.result);
|
|
329
|
+
}
|
|
264
330
|
// check route exist for component and version
|
|
265
331
|
if (err) {
|
|
266
332
|
if (conf.fallbackRegistryUrl) {
|
|
@@ -394,7 +460,8 @@ function getComponent(conf, repository) {
|
|
|
394
460
|
err =
|
|
395
461
|
err ||
|
|
396
462
|
new Error(resources_1.default.errors.registry.DATA_OBJECT_IS_UNDEFINED);
|
|
397
|
-
|
|
463
|
+
// `statusCode` is what oc-server's ServerError sets.
|
|
464
|
+
const status = Number(err.status ?? err.statusCode) || 500;
|
|
398
465
|
events_handler_1.default.fire('data-provider-error', {
|
|
399
466
|
status,
|
|
400
467
|
name: component.name,
|
|
@@ -407,7 +474,7 @@ function getComponent(conf, repository) {
|
|
|
407
474
|
status,
|
|
408
475
|
response: {
|
|
409
476
|
code: 'GENERIC_ERROR',
|
|
410
|
-
error: resources_1.default.errors.registry.COMPONENT_EXECUTION_ERROR(err.message || ''),
|
|
477
|
+
error: resources_1.default.errors.registry.COMPONENT_EXECUTION_ERROR(err.message || (typeof err === 'string' ? err : '')),
|
|
411
478
|
details: {
|
|
412
479
|
message: err.message,
|
|
413
480
|
stack: err.stack,
|
|
@@ -539,7 +606,7 @@ function getComponent(conf, repository) {
|
|
|
539
606
|
const contextObj = {
|
|
540
607
|
action: options.action,
|
|
541
608
|
get acceptLanguage() {
|
|
542
|
-
parsedAcceptLanguage ??=
|
|
609
|
+
parsedAcceptLanguage ??= (0, accept_language_1.parseAcceptLanguage)(getLanguage());
|
|
543
610
|
return parsedAcceptLanguage;
|
|
544
611
|
},
|
|
545
612
|
baseUrl: conf.baseUrl,
|
|
@@ -6,8 +6,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.default = default_1;
|
|
7
7
|
const node_path_1 = __importDefault(require("node:path"));
|
|
8
8
|
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
9
|
-
const parse_author_1 = __importDefault(require("parse-author"));
|
|
10
9
|
const date_stringify_1 = __importDefault(require("../../utils/date-stringify"));
|
|
10
|
+
const parse_author_1 = __importDefault(require("../../utils/parse-author"));
|
|
11
11
|
const views_1 = __importDefault(require("../views"));
|
|
12
12
|
const get_available_dependencies_1 = __importDefault(require("./helpers/get-available-dependencies"));
|
|
13
13
|
const urlBuilder = require("../domain/url-builder");
|
|
@@ -26,6 +26,8 @@ declare const _default: {
|
|
|
26
26
|
COMPONENT_VERSION_NOT_VALID_CODE: string;
|
|
27
27
|
COMPONENT_SET_HEADER_PARAMETERS_NOT_VALID: string;
|
|
28
28
|
COMPONENT_SET_COOKIE_PARAMETERS_NOT_VALID: string;
|
|
29
|
+
COMPONENT_REQUEST_HOOK_FAILED: (message: string) => string;
|
|
30
|
+
COMPONENT_REQUEST_REJECTED: string;
|
|
29
31
|
CONFIGURATION_DEPENDENCIES_MUST_BE_ARRAY: string;
|
|
30
32
|
CONFIGURATION_CORS_MUST_BE_OBJECT: string;
|
|
31
33
|
CONFIGURATION_CORS_ORIGIN_MUST_BE_STRING: string;
|
|
@@ -48,6 +50,7 @@ declare const _default: {
|
|
|
48
50
|
CONFIGURATION_ROUTES_ROUTE_CONTAINS_PREFIX: (prefix: string) => string;
|
|
49
51
|
CONFIGURATION_STORAGE_NOT_VALID: (storage: string) => string;
|
|
50
52
|
CONFIGURATION_HEADERS_TO_SKIP_MUST_BE_STRING_ARRAY: string;
|
|
53
|
+
CONFIGURATION_ON_COMPONENT_REQUEST_MUST_BE_FUNCTION: string;
|
|
51
54
|
DATA_OBJECT_IS_UNDEFINED: string;
|
|
52
55
|
DEPENDENCY_NOT_FOUND: (dependencies: string) => string;
|
|
53
56
|
DEPENDENCY_NOT_FOUND_CODE: string;
|
package/dist/resources/index.js
CHANGED
|
@@ -75,6 +75,8 @@ exports.default = {
|
|
|
75
75
|
COMPONENT_VERSION_NOT_VALID_CODE: 'version_not_valid',
|
|
76
76
|
COMPONENT_SET_HEADER_PARAMETERS_NOT_VALID: 'context.setHeader parameters must be strings',
|
|
77
77
|
COMPONENT_SET_COOKIE_PARAMETERS_NOT_VALID: 'context.setCookie parameters are not valid',
|
|
78
|
+
COMPONENT_REQUEST_HOOK_FAILED: (message) => `onComponentRequest hook failed: ${message}`,
|
|
79
|
+
COMPONENT_REQUEST_REJECTED: 'Component request rejected by the registry',
|
|
78
80
|
CONFIGURATION_DEPENDENCIES_MUST_BE_ARRAY: 'Registry configuration is not valid: dependencies must be an array',
|
|
79
81
|
CONFIGURATION_CORS_MUST_BE_OBJECT: 'Registry configuration is not valid: cors must be an object',
|
|
80
82
|
CONFIGURATION_CORS_ORIGIN_MUST_BE_STRING: 'Registry configuration is not valid: cors.origin must be a non-empty string',
|
|
@@ -97,6 +99,7 @@ exports.default = {
|
|
|
97
99
|
CONFIGURATION_ROUTES_ROUTE_CONTAINS_PREFIX: (prefix) => `Registry configuration is not valid: route url can't contain "${prefix}"`,
|
|
98
100
|
CONFIGURATION_STORAGE_NOT_VALID: (storage) => `Registry configuration is not valid: ${storage} configuration is not valid`,
|
|
99
101
|
CONFIGURATION_HEADERS_TO_SKIP_MUST_BE_STRING_ARRAY: 'Registry configuration is not valid: customHeadersToSkipOnWeakVersion must be an array of strings',
|
|
102
|
+
CONFIGURATION_ON_COMPONENT_REQUEST_MUST_BE_FUNCTION: 'Registry configuration is not valid: onComponentRequest must be a function',
|
|
100
103
|
DATA_OBJECT_IS_UNDEFINED: 'data object is undefined',
|
|
101
104
|
DEPENDENCY_NOT_FOUND: (dependencies) => `Component is trying to use unavailable dependencies: ${dependencies}`,
|
|
102
105
|
DEPENDENCY_NOT_FOUND_CODE: 'DEPENDENCY_MISSING_FROM_REGISTRY',
|
package/dist/types.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { IncomingHttpHeaders } from 'node:http';
|
|
1
2
|
import type { NextFunction, Request, Response } from 'express';
|
|
2
3
|
import type { MetadataStore as MetadataStoreType } from 'oc-metadata-adapters-utils';
|
|
3
4
|
import type { StorageAdapter } from 'oc-storage-adapters-utils';
|
|
@@ -154,6 +155,30 @@ export interface Component extends PackageJson {
|
|
|
154
155
|
oc: OcConfiguration;
|
|
155
156
|
version: string;
|
|
156
157
|
}
|
|
158
|
+
export interface ComponentRequestContext {
|
|
159
|
+
/** Name of the requested component. */
|
|
160
|
+
name: string;
|
|
161
|
+
/** Version requested by the consumer (exact, semver range or empty for latest). */
|
|
162
|
+
requestedVersion: string;
|
|
163
|
+
/** Version the registry resolved the request to and is about to serve. */
|
|
164
|
+
version: string;
|
|
165
|
+
/** Latest published version of the component, as resolved for an unversioned request. */
|
|
166
|
+
latestVersion: string;
|
|
167
|
+
/** package.json of the resolved component, including `allVersions`. */
|
|
168
|
+
component: Readonly<Component>;
|
|
169
|
+
headers: IncomingHttpHeaders;
|
|
170
|
+
parameters: Record<string, string>;
|
|
171
|
+
/** Name of the action being invoked, if any. */
|
|
172
|
+
action?: string;
|
|
173
|
+
}
|
|
174
|
+
export interface ComponentRequestRejection {
|
|
175
|
+
/** @default 403 */
|
|
176
|
+
status?: number;
|
|
177
|
+
/** @default "COMPONENT_REQUEST_REJECTED" */
|
|
178
|
+
code?: string;
|
|
179
|
+
error?: string;
|
|
180
|
+
}
|
|
181
|
+
export type ComponentRequestHook = (context: ComponentRequestContext) => ComponentRequestRejection | undefined | Promise<ComponentRequestRejection | undefined>;
|
|
157
182
|
export interface ParsedComponent extends Omit<Component, 'author'> {
|
|
158
183
|
author: Author;
|
|
159
184
|
}
|
|
@@ -434,6 +459,21 @@ export interface Config<T = any, TServerAdapter extends HttpServerAdapterFactory
|
|
|
434
459
|
isValid: boolean;
|
|
435
460
|
error?: string;
|
|
436
461
|
} | boolean;
|
|
462
|
+
/**
|
|
463
|
+
* Hook executed for every component request once the requested version has
|
|
464
|
+
* been resolved, before the component is rendered or its info returned.
|
|
465
|
+
* Return (or resolve to) a {@link ComponentRequestRejection} to reject the
|
|
466
|
+
* request, or nothing to let it through. Throwing or rejecting responds with
|
|
467
|
+
* a 500 error.
|
|
468
|
+
*
|
|
469
|
+
* @example
|
|
470
|
+
* onComponentRequest: ({ version, latestVersion }) => {
|
|
471
|
+
* if (semver.major(version) < semver.major(latestVersion)) {
|
|
472
|
+
* return { status: 410, code: 'VERSION_TOO_OLD', error: `Use ${latestVersion}` };
|
|
473
|
+
* }
|
|
474
|
+
* }
|
|
475
|
+
*/
|
|
476
|
+
onComponentRequest?: ComponentRequestHook;
|
|
437
477
|
/**
|
|
438
478
|
* Seconds between each refresh of the internal component list cache.
|
|
439
479
|
*/
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.parseAcceptLanguage = parseAcceptLanguage;
|
|
4
|
+
const regex = /((([a-zA-Z]+(-[a-zA-Z0-9]+){0,2})|\*)(;q=[0-1](\.[0-9]+)?)?)*/g;
|
|
5
|
+
function parseAcceptLanguage(al) {
|
|
6
|
+
return (al || '')
|
|
7
|
+
.match(regex)
|
|
8
|
+
.filter(Boolean)
|
|
9
|
+
.map((m) => {
|
|
10
|
+
const bits = m.split(';');
|
|
11
|
+
const ietf = bits[0].split('-');
|
|
12
|
+
const hasScript = ietf.length === 3;
|
|
13
|
+
return {
|
|
14
|
+
code: ietf[0],
|
|
15
|
+
script: hasScript ? ietf[1] : null,
|
|
16
|
+
region: hasScript ? ietf[2] : ietf[1],
|
|
17
|
+
quality: bits[1] ? Number.parseFloat(bits[1].split('=')[1]) : 1.0
|
|
18
|
+
};
|
|
19
|
+
})
|
|
20
|
+
.sort((a, b) => b.quality - a.quality);
|
|
21
|
+
}
|
|
@@ -4,15 +4,13 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.default = cleanRequire;
|
|
7
|
-
const try_require_1 = __importDefault(require("try-require"));
|
|
7
|
+
const try_require_1 = __importDefault(require("./try-require"));
|
|
8
8
|
function cleanRequire(path, { justTry = false, resolve = false }) {
|
|
9
9
|
const shouldThrow = !justTry;
|
|
10
10
|
if (require.cache?.[path]) {
|
|
11
11
|
delete require.cache[path];
|
|
12
12
|
}
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
action = action.resolve;
|
|
16
|
-
}
|
|
13
|
+
const requirer = shouldThrow ? require : try_require_1.default;
|
|
14
|
+
const action = resolve ? requirer.resolve : requirer;
|
|
17
15
|
return action(path);
|
|
18
16
|
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const node_module_1 = require("node:module");
|
|
4
|
+
const coreModules = node_module_1.builtinModules
|
|
5
|
+
.filter((x) => !/^_|^(internal|v8|node-inspect)\/|\//.test(x) && x !== 'sys')
|
|
6
|
+
.sort();
|
|
7
|
+
exports.default = coreModules;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function getPort(start?: number, end?: number): Promise<number>;
|
|
@@ -0,0 +1,21 @@
|
|
|
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 = getPort;
|
|
7
|
+
const node_net_1 = __importDefault(require("node:net"));
|
|
8
|
+
function getPort(start = 2000, end = 60000) {
|
|
9
|
+
return new Promise((resolve, reject) => {
|
|
10
|
+
const tryPort = (port) => {
|
|
11
|
+
if (port >= end)
|
|
12
|
+
return reject(new Error('out of ports :('));
|
|
13
|
+
const socket = node_net_1.default.connect({ port }, () => {
|
|
14
|
+
socket.destroy();
|
|
15
|
+
tryPort(port + 1);
|
|
16
|
+
});
|
|
17
|
+
socket.on('error', () => resolve(port));
|
|
18
|
+
};
|
|
19
|
+
tryPort(start);
|
|
20
|
+
});
|
|
21
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function isEqual(a: unknown, b: unknown): boolean;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.default = isEqual;
|
|
4
|
+
function isEqual(a, b) {
|
|
5
|
+
if (a === b)
|
|
6
|
+
return true;
|
|
7
|
+
if (!a || !b || typeof a !== 'object' || typeof b !== 'object') {
|
|
8
|
+
return Number.isNaN(a) && Number.isNaN(b);
|
|
9
|
+
}
|
|
10
|
+
if (Array.isArray(a) !== Array.isArray(b))
|
|
11
|
+
return false;
|
|
12
|
+
const keysA = Object.keys(a);
|
|
13
|
+
if (keysA.length !== Object.keys(b).length)
|
|
14
|
+
return false;
|
|
15
|
+
return keysA.every((key) => Object.hasOwn(b, key) &&
|
|
16
|
+
isEqual(a[key], b[key]));
|
|
17
|
+
}
|
|
@@ -5,7 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.default = moduleExists;
|
|
7
7
|
const node_path_1 = __importDefault(require("node:path"));
|
|
8
|
-
const try_require_1 = __importDefault(require("try-require"));
|
|
8
|
+
const try_require_1 = __importDefault(require("./try-require"));
|
|
9
9
|
function moduleExists(moduleName) {
|
|
10
10
|
const packageModulePath = node_path_1.default.join(moduleName, 'package.json');
|
|
11
11
|
if (require.cache?.[packageModulePath]) {
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.default = parseAuthor;
|
|
4
|
+
const authorRegex = /^\s*([^<(]*?)\s*([<(]([^>)]*?)[>)])?\s*([<(]([^>)]*?)[>)])*\s*$/;
|
|
5
|
+
function parseAuthor(str) {
|
|
6
|
+
if (typeof str !== 'string') {
|
|
7
|
+
throw new TypeError('expected author to be a string');
|
|
8
|
+
}
|
|
9
|
+
const author = {};
|
|
10
|
+
const match = authorRegex.exec(str);
|
|
11
|
+
if (!/\w/.test(str) || !match)
|
|
12
|
+
return author;
|
|
13
|
+
if (match[1])
|
|
14
|
+
author.name = match[1];
|
|
15
|
+
for (let i = 2; i < match.length; i++) {
|
|
16
|
+
const val = match[i];
|
|
17
|
+
if (i % 2 === 0 && val && match[i + 1]) {
|
|
18
|
+
if (val.charAt(0) === '<') {
|
|
19
|
+
author.email = match[++i];
|
|
20
|
+
}
|
|
21
|
+
else if (val.charAt(0) === '(') {
|
|
22
|
+
author.url = match[++i];
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
return author;
|
|
27
|
+
}
|
package/dist/utils/put.js
CHANGED
|
@@ -3,25 +3,24 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const node_fs_1 = require("node:fs");
|
|
6
7
|
const node_path_1 = __importDefault(require("node:path"));
|
|
7
|
-
const form_data_1 = __importDefault(require("form-data"));
|
|
8
|
-
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
9
8
|
const undici_1 = require("undici");
|
|
10
9
|
// undici v8 enables HTTP/2 by default when the TLS server negotiates it via
|
|
11
10
|
// ALPN. Some gateways/proxies reset large multipart uploads over h2, surfacing
|
|
12
11
|
// as "Premature close". Force HTTP/1.1 for the publish upload to avoid this.
|
|
13
12
|
const dispatcher = new undici_1.Agent({ allowH2: false });
|
|
14
13
|
async function put(urlPath, files, headers) {
|
|
15
|
-
const form = new
|
|
14
|
+
const form = new undici_1.FormData();
|
|
16
15
|
if (!Array.isArray(files)) {
|
|
17
16
|
files = [files];
|
|
18
17
|
}
|
|
19
18
|
for (const file of files) {
|
|
20
19
|
const fileName = node_path_1.default.basename(file);
|
|
21
|
-
form.append(fileName,
|
|
20
|
+
form.append(fileName, await (0, node_fs_1.openAsBlob)(file, { type: 'application/gzip' }), fileName);
|
|
22
21
|
}
|
|
23
22
|
const res = await (0, undici_1.request)(urlPath, {
|
|
24
|
-
headers
|
|
23
|
+
headers,
|
|
25
24
|
method: 'PUT',
|
|
26
25
|
body: form,
|
|
27
26
|
dispatcher
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function serializeError(value: unknown): unknown;
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.default = serializeError;
|
|
4
|
+
const errorProperties = [
|
|
5
|
+
'name',
|
|
6
|
+
'message',
|
|
7
|
+
'stack',
|
|
8
|
+
'code',
|
|
9
|
+
'cause',
|
|
10
|
+
'errors'
|
|
11
|
+
];
|
|
12
|
+
const toJsonWasCalled = new WeakSet();
|
|
13
|
+
const isErrorLike = (value) => !!value &&
|
|
14
|
+
typeof value === 'object' &&
|
|
15
|
+
typeof value.name === 'string' &&
|
|
16
|
+
typeof value.message === 'string' &&
|
|
17
|
+
typeof value.stack === 'string';
|
|
18
|
+
function destroyCircular(from, seen) {
|
|
19
|
+
seen.push(from);
|
|
20
|
+
if (typeof from.toJSON === 'function' && !toJsonWasCalled.has(from)) {
|
|
21
|
+
toJsonWasCalled.add(from);
|
|
22
|
+
try {
|
|
23
|
+
return from.toJSON();
|
|
24
|
+
}
|
|
25
|
+
finally {
|
|
26
|
+
toJsonWasCalled.delete(from);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
const to = Array.isArray(from) ? [] : {};
|
|
30
|
+
const next = (value) => destroyCircular(value, [...seen]);
|
|
31
|
+
for (const [key, value] of Object.entries(from)) {
|
|
32
|
+
if (typeof value === 'function')
|
|
33
|
+
continue;
|
|
34
|
+
if (value instanceof Uint8Array && value.constructor.name === 'Buffer') {
|
|
35
|
+
to[key] = '[object Buffer]';
|
|
36
|
+
}
|
|
37
|
+
else if (value !== null &&
|
|
38
|
+
typeof value === 'object' &&
|
|
39
|
+
typeof value.pipe === 'function') {
|
|
40
|
+
to[key] = '[object Stream]';
|
|
41
|
+
}
|
|
42
|
+
else if (!value || typeof value !== 'object') {
|
|
43
|
+
to[key] = value;
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
to[key] = seen.includes(value) ? '[Circular]' : next(value);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
for (const property of errorProperties) {
|
|
50
|
+
const value = from[property];
|
|
51
|
+
if (value !== undefined && value !== null) {
|
|
52
|
+
to[property] =
|
|
53
|
+
isErrorLike(value) || Array.isArray(value) ? next(value) : value;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
return to;
|
|
57
|
+
}
|
|
58
|
+
function serializeError(value) {
|
|
59
|
+
if (typeof value === 'object' && value !== null) {
|
|
60
|
+
return destroyCircular(value, []);
|
|
61
|
+
}
|
|
62
|
+
if (typeof value === 'function') {
|
|
63
|
+
return `[Function: ${value.name || 'anonymous'}]`;
|
|
64
|
+
}
|
|
65
|
+
return value;
|
|
66
|
+
}
|