oc 0.49.3 → 0.49.7
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/.github/workflows/node.js.yml +1 -1
- package/CHANGELOG.md +25 -0
- package/dist/cli/commands.d.ts +8 -0
- package/dist/cli/commands.js +8 -0
- package/dist/cli/domain/clean.d.ts +2 -2
- package/dist/cli/domain/get-components-by-dir.d.ts +1 -1
- package/dist/cli/domain/get-components-by-dir.js +10 -1
- package/dist/cli/domain/get-mocked-plugins.js +1 -1
- package/dist/cli/domain/handle-dependencies/ensure-compiler-is-declared-as-devDependency.d.ts +1 -1
- package/dist/cli/domain/handle-dependencies/get-compiler.d.ts +3 -2
- package/dist/cli/domain/handle-dependencies/index.d.ts +2 -2
- package/dist/cli/domain/handle-dependencies/install-compiler.d.ts +2 -1
- package/dist/cli/domain/handle-dependencies/install-compiler.js +1 -1
- package/dist/cli/domain/handle-dependencies/install-missing-dependencies.d.ts +1 -1
- package/dist/cli/domain/handle-dependencies/install-missing-dependencies.js +6 -3
- package/dist/cli/domain/handle-dependencies/link-missing-dependencies.d.ts +1 -1
- package/dist/cli/domain/handle-dependencies/require-template.d.ts +1 -1
- package/dist/cli/domain/init-template/index.d.ts +2 -2
- package/dist/cli/domain/init-template/install-template.d.ts +2 -2
- package/dist/cli/domain/init-template/scaffold.d.ts +2 -2
- package/dist/cli/domain/mock.js +1 -1
- package/dist/cli/domain/package-components.d.ts +1 -1
- package/dist/cli/domain/registry.js +2 -2
- package/dist/cli/facade/dev.d.ts +2 -1
- package/dist/cli/facade/dev.js +8 -8
- package/dist/cli/facade/init.d.ts +1 -1
- package/dist/cli/facade/package.d.ts +1 -1
- package/dist/cli/facade/preview.d.ts +1 -1
- package/dist/cli/facade/publish.d.ts +1 -0
- package/dist/cli/facade/publish.js +10 -5
- package/dist/cli/facade/registry-add.d.ts +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-remove.d.ts +1 -1
- package/dist/cli/facade/registry.d.ts +1 -1
- package/dist/cli/facade/registry.js +1 -1
- package/dist/cli/logger.d.ts +4 -4
- package/dist/cli/logger.js +5 -5
- package/dist/cli/programmatic-api.d.ts +2 -0
- package/dist/components/oc-client/_package/package.json +1 -1
- package/dist/components/oc-client/_package/server.js +1 -1
- package/dist/components/oc-client/_package/src/oc-client.min.js +2 -2
- package/dist/components/oc-client/_package/src/oc-client.min.map +1 -1
- package/dist/components/oc-client/_package/template.js +1 -1
- package/dist/components/oc-client/package.json +1 -1
- package/dist/components/oc-client/src/oc-client.min.js +2 -2
- package/dist/components/oc-client/src/oc-client.min.map +1 -1
- package/dist/registry/app-start.d.ts +1 -1
- package/dist/registry/app-start.js +1 -1
- package/dist/registry/domain/authentication.d.ts +2 -3
- package/dist/registry/domain/authentication.js +4 -4
- package/dist/registry/domain/components-cache/components-list.d.ts +4 -4
- package/dist/registry/domain/components-cache/index.d.ts +3 -3
- package/dist/registry/domain/components-cache/index.js +4 -23
- package/dist/registry/domain/components-details.d.ts +2 -2
- package/dist/registry/domain/components-details.js +6 -21
- package/dist/registry/domain/events-handler.d.ts +39 -5
- package/dist/registry/domain/events-handler.js +29 -31
- package/dist/registry/domain/extract-package.d.ts +2 -2
- package/dist/registry/domain/get-package-json-from-temp-dir.d.ts +1 -1
- package/dist/registry/domain/nested-renderer.d.ts +3 -3
- package/dist/registry/domain/options-sanitiser.js +15 -15
- package/dist/registry/domain/plugins-initialiser.d.ts +1 -1
- package/dist/registry/domain/plugins-initialiser.js +3 -3
- package/dist/registry/domain/register-templates.d.ts +1 -1
- package/dist/registry/domain/repository.js +18 -17
- package/dist/registry/domain/sanitiser.d.ts +1 -1
- package/dist/registry/domain/url-builder.d.ts +2 -2
- package/dist/registry/domain/validators/component-parameters.d.ts +3 -3
- package/dist/registry/domain/validators/registry-configuration.js +4 -4
- package/dist/registry/index.d.ts +33 -4
- package/dist/registry/index.js +10 -6
- package/dist/registry/middleware/cors.d.ts +1 -1
- package/dist/registry/middleware/cors.js +1 -1
- package/dist/registry/middleware/file-uploads.js +1 -1
- package/dist/registry/middleware/index.js +1 -1
- package/dist/registry/middleware/request-handler.js +2 -21
- package/dist/registry/router.js +1 -1
- package/dist/registry/routes/component-info.js +5 -4
- package/dist/registry/routes/component-preview.js +5 -4
- package/dist/registry/routes/component.js +2 -2
- package/dist/registry/routes/components.js +6 -6
- package/dist/registry/routes/dependencies.d.ts +1 -1
- package/dist/registry/routes/dependencies.js +1 -1
- package/dist/registry/routes/helpers/apply-default-values.d.ts +1 -1
- package/dist/registry/routes/helpers/get-component-fallback.d.ts +2 -2
- package/dist/registry/routes/helpers/get-component-fallback.js +2 -2
- package/dist/registry/routes/helpers/get-component.d.ts +2 -2
- package/dist/registry/routes/helpers/get-component.js +9 -9
- package/dist/registry/routes/helpers/is-url-discoverable.d.ts +2 -2
- package/dist/registry/routes/helpers/is-url-discoverable.js +1 -1
- package/dist/registry/routes/index.js +3 -2
- package/dist/registry/routes/plugins.d.ts +1 -1
- package/dist/registry/routes/plugins.js +1 -1
- package/dist/registry/routes/publish.js +5 -6
- package/dist/registry/routes/static-redirector.js +4 -4
- package/dist/registry/views/info.js +5 -2
- package/dist/registry/views/static/info.d.ts +1 -1
- package/dist/registry/views/static/info.js +12 -1
- package/dist/resources/index.d.ts +1 -1
- package/dist/resources/index.js +1 -1
- package/dist/types.d.ts +52 -41
- package/dist/utils/clean-require.d.ts +16 -4
- package/dist/utils/date-stringify.js +8 -9
- package/dist/utils/npm-utils.d.ts +4 -4
- package/dist/utils/put.d.ts +1 -1
- package/logintervals.md +1 -1
- package/package.json +34 -35
- package/src/cli/commands.ts +10 -0
- package/src/cli/domain/clean.ts +12 -4
- package/src/cli/domain/get-components-by-dir.ts +21 -1
- package/src/cli/domain/get-mocked-plugins.ts +4 -4
- package/src/cli/domain/handle-dependencies/ensure-compiler-is-declared-as-devDependency.ts +1 -1
- package/src/cli/domain/handle-dependencies/get-compiler.ts +4 -3
- package/src/cli/domain/handle-dependencies/index.ts +21 -17
- package/src/cli/domain/handle-dependencies/install-compiler.ts +5 -4
- package/src/cli/domain/handle-dependencies/install-missing-dependencies.ts +7 -4
- package/src/cli/domain/handle-dependencies/link-missing-dependencies.ts +1 -1
- package/src/cli/domain/handle-dependencies/require-template.ts +1 -1
- package/src/cli/domain/init-template/index.ts +1 -1
- package/src/cli/domain/init-template/install-template.ts +1 -1
- package/src/cli/domain/init-template/scaffold.ts +1 -1
- package/src/cli/domain/mock.ts +1 -1
- package/src/cli/domain/package-components.ts +4 -1
- package/src/cli/domain/registry.ts +8 -8
- package/src/cli/facade/dev.ts +100 -97
- package/src/cli/facade/init.ts +1 -1
- package/src/cli/facade/package.ts +1 -1
- package/src/cli/facade/preview.ts +1 -1
- package/src/cli/facade/publish.ts +25 -10
- package/src/cli/facade/registry-add.ts +4 -1
- package/src/cli/facade/registry-ls.ts +4 -1
- package/src/cli/facade/registry-remove.ts +4 -1
- package/src/cli/facade/registry.ts +1 -1
- package/src/cli/index.ts +1 -1
- package/src/cli/logger.ts +10 -10
- package/src/components/oc-client/_package/package.json +1 -1
- package/src/components/oc-client/_package/server.js +1 -1
- package/src/components/oc-client/_package/src/oc-client.min.js +2 -2
- package/src/components/oc-client/_package/src/oc-client.min.map +1 -1
- package/src/components/oc-client/_package/template.js +1 -1
- package/src/components/oc-client/package.json +1 -1
- package/src/components/oc-client/src/oc-client.min.js +2 -2
- package/src/components/oc-client/src/oc-client.min.map +1 -1
- package/src/globals.d.ts +6 -12
- package/src/registry/app-start.ts +2 -2
- package/src/registry/domain/authentication.ts +6 -18
- package/src/registry/domain/components-cache/components-list.ts +11 -7
- package/src/registry/domain/components-cache/index.ts +5 -5
- package/src/registry/domain/components-details.ts +14 -8
- package/src/registry/domain/events-handler.ts +73 -27
- package/src/registry/domain/extract-package.ts +7 -4
- package/src/registry/domain/get-package-json-from-temp-dir.ts +1 -1
- package/src/registry/domain/nested-renderer.ts +3 -3
- package/src/registry/domain/options-sanitiser.ts +15 -15
- package/src/registry/domain/plugins-initialiser.ts +8 -5
- package/src/registry/domain/register-templates.ts +2 -2
- package/src/registry/domain/repository.ts +50 -40
- package/src/registry/domain/sanitiser.ts +4 -4
- package/src/registry/domain/url-builder.ts +2 -2
- package/src/registry/domain/validators/component-parameters.ts +4 -4
- package/src/registry/domain/validators/registry-configuration.ts +4 -4
- package/src/registry/index.ts +20 -10
- package/src/registry/middleware/cors.ts +1 -1
- package/src/registry/middleware/file-uploads.ts +1 -1
- package/src/registry/middleware/index.ts +1 -1
- package/src/registry/middleware/request-handler.ts +6 -21
- package/src/registry/router.ts +1 -1
- package/src/registry/routes/component-info.ts +7 -6
- package/src/registry/routes/component-preview.ts +6 -5
- package/src/registry/routes/component.ts +2 -2
- package/src/registry/routes/components.ts +7 -7
- package/src/registry/routes/dependencies.ts +1 -1
- package/src/registry/routes/helpers/apply-default-values.ts +3 -3
- package/src/registry/routes/helpers/get-component-fallback.ts +7 -7
- package/src/registry/routes/helpers/get-component.ts +16 -13
- package/src/registry/routes/helpers/is-url-discoverable.ts +2 -2
- package/src/registry/routes/index.ts +3 -2
- package/src/registry/routes/plugins.ts +1 -1
- package/src/registry/routes/publish.ts +6 -7
- package/src/registry/routes/static-redirector.ts +4 -4
- package/src/registry/views/info.ts +5 -2
- package/src/registry/views/static/info.ts +12 -1
- package/src/resources/index.ts +2 -2
- package/src/types.ts +85 -41
- package/src/utils/clean-require.ts +17 -1
- package/src/utils/date-stringify.ts +8 -6
- package/src/utils/npm-utils.ts +2 -2
- package/src/utils/put.ts +4 -2
- package/tsconfig.json +3 -3
- package/dist/utils/pad-zero.d.ts +0 -1
- package/dist/utils/pad-zero.js +0 -6
- package/src/utils/pad-zero.ts +0 -3
|
@@ -10,10 +10,13 @@ export default function extractPackage(
|
|
|
10
10
|
| {
|
|
11
11
|
[fieldname: string]: Express.Multer.File[];
|
|
12
12
|
},
|
|
13
|
-
callback:
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
13
|
+
callback: (
|
|
14
|
+
err: Error | null,
|
|
15
|
+
data: {
|
|
16
|
+
outputFolder: string;
|
|
17
|
+
packageJson: PackageJson;
|
|
18
|
+
}
|
|
19
|
+
) => void
|
|
17
20
|
): void {
|
|
18
21
|
const packageFile: Express.Multer.File = (files as any)[0];
|
|
19
22
|
const packagePath = path.resolve(packageFile.path);
|
|
@@ -4,7 +4,7 @@ import { PackageJson } from 'type-fest';
|
|
|
4
4
|
|
|
5
5
|
export default function getPackageJsonFromTempDir(
|
|
6
6
|
tempDirPath: string,
|
|
7
|
-
callback:
|
|
7
|
+
callback: (err: Error | null, data: PackageJson) => void
|
|
8
8
|
): void {
|
|
9
9
|
return fs.readJson(path.join(tempDirPath, 'package.json'), callback);
|
|
10
10
|
}
|
|
@@ -5,12 +5,12 @@ import settings from '../../resources/settings';
|
|
|
5
5
|
import strings from '../../resources';
|
|
6
6
|
import { Config } from '../../types';
|
|
7
7
|
|
|
8
|
-
type Cb =
|
|
8
|
+
type Cb = (err: string | null, data: string) => void;
|
|
9
9
|
type Options = {
|
|
10
10
|
version?: string;
|
|
11
11
|
name?: string;
|
|
12
|
-
headers?:
|
|
13
|
-
parameters?:
|
|
12
|
+
headers?: Record<string, string>;
|
|
13
|
+
parameters?: Record<string, string>;
|
|
14
14
|
};
|
|
15
15
|
type Params = {
|
|
16
16
|
components: Options[];
|
|
@@ -13,7 +13,7 @@ export default function optionsSanitiser(input: Input): Config {
|
|
|
13
13
|
const options = _.clone(input);
|
|
14
14
|
|
|
15
15
|
if (!options.publishAuth) {
|
|
16
|
-
(options as Config).beforePublish = (
|
|
16
|
+
(options as Config).beforePublish = (_req, _res, next) => next();
|
|
17
17
|
} else {
|
|
18
18
|
(options as Config).beforePublish = auth.middleware(options.publishAuth);
|
|
19
19
|
}
|
|
@@ -37,28 +37,28 @@ export default function optionsSanitiser(input: Input): Config {
|
|
|
37
37
|
options.tempDir = settings.registry.defaultTempPath;
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
-
if (
|
|
40
|
+
if (typeof options.hotReloading !== 'boolean') {
|
|
41
41
|
options.hotReloading = !!options.local;
|
|
42
42
|
}
|
|
43
43
|
|
|
44
|
-
if (
|
|
44
|
+
if (!options.verbosity) {
|
|
45
45
|
options.verbosity = 0;
|
|
46
46
|
}
|
|
47
47
|
|
|
48
|
-
if (
|
|
48
|
+
if (typeof options.discovery === 'undefined') {
|
|
49
49
|
options.discovery = true;
|
|
50
50
|
}
|
|
51
51
|
|
|
52
|
-
if (
|
|
52
|
+
if (typeof options.pollingInterval === 'undefined') {
|
|
53
53
|
options.pollingInterval = 5;
|
|
54
54
|
}
|
|
55
55
|
|
|
56
|
-
if (
|
|
56
|
+
if (!options.templates) {
|
|
57
57
|
options.templates = [];
|
|
58
58
|
}
|
|
59
59
|
|
|
60
60
|
if (
|
|
61
|
-
|
|
61
|
+
typeof options.fallbackRegistryUrl !== 'undefined' &&
|
|
62
62
|
_.last(options.fallbackRegistryUrl) !== '/'
|
|
63
63
|
) {
|
|
64
64
|
options.fallbackRegistryUrl += '/';
|
|
@@ -68,7 +68,7 @@ export default function optionsSanitiser(input: Input): Config {
|
|
|
68
68
|
options.customHeadersToSkipOnWeakVersion || []
|
|
69
69
|
).map(s => s.toLowerCase());
|
|
70
70
|
|
|
71
|
-
options.port =
|
|
71
|
+
options.port = options.port || process.env['PORT'] || 3000;
|
|
72
72
|
options.timeout = options.timeout || 1000 * 60 * 2;
|
|
73
73
|
options.keepAliveTimeout =
|
|
74
74
|
options.keepAliveTimeout || DEFAULT_NODE_KEEPALIVE_MS;
|
|
@@ -85,22 +85,22 @@ export default function optionsSanitiser(input: Input): Config {
|
|
|
85
85
|
}
|
|
86
86
|
|
|
87
87
|
if (options.refreshInterval && options.storage) {
|
|
88
|
-
options.storage.options
|
|
88
|
+
options.storage.options['refreshInterval'] = options.refreshInterval;
|
|
89
89
|
}
|
|
90
90
|
|
|
91
91
|
if (options.verbosity && options.storage) {
|
|
92
|
-
options.storage.options
|
|
92
|
+
options.storage.options['verbosity'] = options.verbosity;
|
|
93
93
|
}
|
|
94
94
|
|
|
95
95
|
if (
|
|
96
96
|
options.storage &&
|
|
97
97
|
options.storage.options &&
|
|
98
|
-
options.storage.options
|
|
98
|
+
options.storage.options['path']
|
|
99
99
|
) {
|
|
100
|
-
options.storage.options
|
|
101
|
-
options.storage.options
|
|
102
|
-
? options.storage.options
|
|
103
|
-
: `https:${options.storage.options
|
|
100
|
+
options.storage.options['path'] =
|
|
101
|
+
options.storage.options['path'].indexOf('http') === 0
|
|
102
|
+
? options.storage.options['path']
|
|
103
|
+
: `https:${options.storage.options['path']}`;
|
|
104
104
|
}
|
|
105
105
|
|
|
106
106
|
if (!options.env) {
|
|
@@ -12,9 +12,9 @@ function validatePlugins(plugins: unknown[]): asserts plugins is Plugin[] {
|
|
|
12
12
|
c++;
|
|
13
13
|
if (
|
|
14
14
|
!_.isObject((plugin as Plugin).register) ||
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
15
|
+
typeof (plugin as Plugin).register.register !== 'function' ||
|
|
16
|
+
typeof (plugin as Plugin).register.execute !== 'function' ||
|
|
17
|
+
typeof (plugin as Plugin).name !== 'string'
|
|
18
18
|
) {
|
|
19
19
|
throw new Error(
|
|
20
20
|
strings.errors.registry.PLUGIN_NOT_VALID(
|
|
@@ -55,9 +55,12 @@ const defer = function (plugin: Plugin, cb: (err?: Error) => void) {
|
|
|
55
55
|
|
|
56
56
|
export function init(
|
|
57
57
|
pluginsToRegister: unknown[],
|
|
58
|
-
callback:
|
|
58
|
+
callback: (
|
|
59
|
+
err: unknown,
|
|
60
|
+
data: Record<string, (...args: unknown[]) => void>
|
|
61
|
+
) => void
|
|
59
62
|
): void {
|
|
60
|
-
const registered:
|
|
63
|
+
const registered: Record<string, (...args: unknown[]) => void> = {};
|
|
61
64
|
|
|
62
65
|
try {
|
|
63
66
|
validatePlugins(pluginsToRegister);
|
|
@@ -5,7 +5,7 @@ import { Template, TemplateInfo } from '../../types';
|
|
|
5
5
|
import _ from 'lodash';
|
|
6
6
|
|
|
7
7
|
export default function registerTemplates(extraTemplates: Template[]): {
|
|
8
|
-
templatesHash:
|
|
8
|
+
templatesHash: Record<string, Template>;
|
|
9
9
|
templatesInfo: TemplateInfo[];
|
|
10
10
|
} {
|
|
11
11
|
const coreTemplates: Template[] = [
|
|
@@ -18,7 +18,7 @@ export default function registerTemplates(extraTemplates: Template[]): {
|
|
|
18
18
|
const type = template.getInfo().type;
|
|
19
19
|
hash[type] = template;
|
|
20
20
|
return hash;
|
|
21
|
-
}, {} as
|
|
21
|
+
}, {} as Record<string, Template>);
|
|
22
22
|
|
|
23
23
|
const templatesInfo = templates.map(template => {
|
|
24
24
|
return template.getInfo();
|
|
@@ -58,23 +58,25 @@ export default function repository(conf: Config): Repository {
|
|
|
58
58
|
.toString();
|
|
59
59
|
},
|
|
60
60
|
getComponents(): string[] {
|
|
61
|
-
const validComponents =
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
61
|
+
const validComponents =
|
|
62
|
+
conf.components ||
|
|
63
|
+
fs.readdirSync(conf.path).filter(file => {
|
|
64
|
+
const isDir = fs.lstatSync(path.join(conf.path, file)).isDirectory();
|
|
65
|
+
const isValidComponent = isDir
|
|
66
|
+
? fs
|
|
67
|
+
.readdirSync(path.join(conf.path, file))
|
|
68
|
+
.filter(file => file === '_package').length === 1
|
|
69
|
+
: false;
|
|
70
|
+
|
|
71
|
+
return isValidComponent;
|
|
72
|
+
});
|
|
71
73
|
|
|
72
74
|
validComponents.push('oc-client');
|
|
73
75
|
return validComponents;
|
|
74
76
|
},
|
|
75
77
|
getComponentVersions(
|
|
76
78
|
componentName: string,
|
|
77
|
-
callback:
|
|
79
|
+
callback: (err: string | null, data: string[]) => void
|
|
78
80
|
) {
|
|
79
81
|
if (componentName === 'oc-client') {
|
|
80
82
|
return callback(null, [
|
|
@@ -116,7 +118,7 @@ export default function repository(conf: Config): Repository {
|
|
|
116
118
|
getCompiledView(
|
|
117
119
|
componentName: string,
|
|
118
120
|
componentVersion: string,
|
|
119
|
-
callback:
|
|
121
|
+
callback: (err: Error | null, data: string) => void
|
|
120
122
|
) {
|
|
121
123
|
if (conf.local) {
|
|
122
124
|
return callback(null, local.getCompiledView(componentName));
|
|
@@ -129,19 +131,19 @@ export default function repository(conf: Config): Repository {
|
|
|
129
131
|
},
|
|
130
132
|
getComponent(
|
|
131
133
|
componentName: string,
|
|
132
|
-
componentVersionOrCallback:
|
|
133
|
-
|
|
134
|
+
componentVersionOrCallback:
|
|
135
|
+
| string
|
|
136
|
+
| ((err: string | null, data: Component) => void),
|
|
137
|
+
callbackMaybe?: (err: string | null, data: Component) => void
|
|
134
138
|
) {
|
|
135
|
-
const componentVersion: string | undefined =
|
|
136
|
-
componentVersionOrCallback
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
? (componentVersionOrCallback as any)
|
|
144
|
-
: callbackMaybe!;
|
|
139
|
+
const componentVersion: string | undefined =
|
|
140
|
+
typeof componentVersionOrCallback === 'function'
|
|
141
|
+
? undefined
|
|
142
|
+
: (componentVersionOrCallback as any);
|
|
143
|
+
const callback: (err: string | null, data: Component) => void =
|
|
144
|
+
typeof componentVersionOrCallback === 'function'
|
|
145
|
+
? (componentVersionOrCallback as any)
|
|
146
|
+
: callbackMaybe!;
|
|
145
147
|
|
|
146
148
|
repository.getComponentVersions(componentName, (err, allVersions) => {
|
|
147
149
|
if (err) {
|
|
@@ -184,7 +186,7 @@ export default function repository(conf: Config): Repository {
|
|
|
184
186
|
null as any
|
|
185
187
|
);
|
|
186
188
|
}
|
|
187
|
-
callback(null,
|
|
189
|
+
callback(null, Object.assign(component, { allVersions }));
|
|
188
190
|
}
|
|
189
191
|
);
|
|
190
192
|
});
|
|
@@ -192,7 +194,7 @@ export default function repository(conf: Config): Repository {
|
|
|
192
194
|
getComponentInfo(
|
|
193
195
|
componentName: string,
|
|
194
196
|
componentVersion: string,
|
|
195
|
-
callback:
|
|
197
|
+
callback: (err: string | null, data: Component) => void
|
|
196
198
|
) {
|
|
197
199
|
if (conf.local) {
|
|
198
200
|
let componentInfo;
|
|
@@ -225,10 +227,10 @@ export default function repository(conf: Config): Repository {
|
|
|
225
227
|
getComponentPath(componentName: string, componentVersion: string) {
|
|
226
228
|
const prefix = conf.local
|
|
227
229
|
? conf.baseUrl
|
|
228
|
-
: `${options
|
|
230
|
+
: `${options!['path']}${options!.componentsDir}/`;
|
|
229
231
|
return `${prefix}${componentName}/${componentVersion}/`;
|
|
230
232
|
},
|
|
231
|
-
getComponents(callback:
|
|
233
|
+
getComponents(callback: (err: Error | null, data: string[]) => void) {
|
|
232
234
|
if (conf.local) {
|
|
233
235
|
return callback(null, local.getComponents());
|
|
234
236
|
}
|
|
@@ -237,7 +239,9 @@ export default function repository(conf: Config): Repository {
|
|
|
237
239
|
callback(err, res ? Object.keys(res.components) : (null as any))
|
|
238
240
|
);
|
|
239
241
|
},
|
|
240
|
-
getComponentsDetails(
|
|
242
|
+
getComponentsDetails(
|
|
243
|
+
callback: (err: string | null, data: ComponentsDetails) => void
|
|
244
|
+
) {
|
|
241
245
|
if (conf.local) {
|
|
242
246
|
return (callback as any)();
|
|
243
247
|
}
|
|
@@ -246,7 +250,7 @@ export default function repository(conf: Config): Repository {
|
|
|
246
250
|
},
|
|
247
251
|
getComponentVersions(
|
|
248
252
|
componentName: string,
|
|
249
|
-
callback:
|
|
253
|
+
callback: (err: string | null, data: string[]) => void
|
|
250
254
|
) {
|
|
251
255
|
if (conf.local) {
|
|
252
256
|
return local.getComponentVersions(componentName, callback);
|
|
@@ -264,10 +268,13 @@ export default function repository(conf: Config): Repository {
|
|
|
264
268
|
getDataProvider(
|
|
265
269
|
componentName: string,
|
|
266
270
|
componentVersion: string,
|
|
267
|
-
callback:
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
+
callback: (
|
|
272
|
+
err: Error | null,
|
|
273
|
+
data: {
|
|
274
|
+
content: string;
|
|
275
|
+
filePath: string;
|
|
276
|
+
}
|
|
277
|
+
) => void
|
|
271
278
|
) {
|
|
272
279
|
if (conf.local) {
|
|
273
280
|
return callback(null, local.getDataProvider(componentName));
|
|
@@ -284,14 +291,14 @@ export default function repository(conf: Config): Repository {
|
|
|
284
291
|
);
|
|
285
292
|
},
|
|
286
293
|
getStaticClientPath: () =>
|
|
287
|
-
`${options
|
|
294
|
+
`${options!['path']}${getFilePath(
|
|
288
295
|
'oc-client',
|
|
289
296
|
packageInfo.version,
|
|
290
297
|
'src/oc-client.min.js'
|
|
291
298
|
)}`,
|
|
292
299
|
|
|
293
300
|
getStaticClientMapPath: () =>
|
|
294
|
-
`${options
|
|
301
|
+
`${options!['path']}${getFilePath(
|
|
295
302
|
'oc-client',
|
|
296
303
|
packageInfo.version,
|
|
297
304
|
'src/oc-client.min.map'
|
|
@@ -309,7 +316,7 @@ export default function repository(conf: Config): Repository {
|
|
|
309
316
|
getTemplatesInfo: () => templatesInfo,
|
|
310
317
|
getTemplate: (type: string) => templatesHash[type],
|
|
311
318
|
|
|
312
|
-
init(callback:
|
|
319
|
+
init(callback: (err: Error | null, data: ComponentsList | string) => void) {
|
|
313
320
|
if (conf.local) {
|
|
314
321
|
return callback(null, 'ok');
|
|
315
322
|
}
|
|
@@ -327,7 +334,10 @@ export default function repository(conf: Config): Repository {
|
|
|
327
334
|
pkgDetails: any,
|
|
328
335
|
componentName: string,
|
|
329
336
|
componentVersion: string,
|
|
330
|
-
callback:
|
|
337
|
+
callback: (
|
|
338
|
+
err: { code: string; msg: string } | null,
|
|
339
|
+
data: ComponentsDetails
|
|
340
|
+
) => void
|
|
331
341
|
) {
|
|
332
342
|
if (conf.local) {
|
|
333
343
|
return callback(
|
|
@@ -362,7 +372,7 @@ export default function repository(conf: Config): Repository {
|
|
|
362
372
|
}
|
|
363
373
|
|
|
364
374
|
const validationResult = validator.validatePackageJson(
|
|
365
|
-
|
|
375
|
+
Object.assign(pkgDetails, {
|
|
366
376
|
componentName,
|
|
367
377
|
customValidator: conf.publishValidation
|
|
368
378
|
})
|
|
@@ -382,7 +392,7 @@ export default function repository(conf: Config): Repository {
|
|
|
382
392
|
|
|
383
393
|
repository.getComponentVersions(
|
|
384
394
|
componentName,
|
|
385
|
-
(
|
|
395
|
+
(_err, componentVersions) => {
|
|
386
396
|
if (
|
|
387
397
|
!versionHandler.validateNewVersion(
|
|
388
398
|
componentVersion,
|
|
@@ -34,10 +34,10 @@ const sanitise = {
|
|
|
34
34
|
const toRemove = ['__ocAcceptLanguage'];
|
|
35
35
|
|
|
36
36
|
export function sanitiseComponentParameters(
|
|
37
|
-
requestParameters:
|
|
38
|
-
expectedParameters:
|
|
39
|
-
):
|
|
40
|
-
const result:
|
|
37
|
+
requestParameters: Record<string, string | number | boolean>,
|
|
38
|
+
expectedParameters: Record<string, OcParameter>
|
|
39
|
+
): Record<string, string | number | boolean> {
|
|
40
|
+
const result: Record<string, string | number | boolean> = {};
|
|
41
41
|
|
|
42
42
|
for (const [requestParameterName, requestParameter] of Object.entries(
|
|
43
43
|
requestParameters
|
|
@@ -4,7 +4,7 @@ import url from 'url';
|
|
|
4
4
|
type Component = {
|
|
5
5
|
name: string;
|
|
6
6
|
version?: string;
|
|
7
|
-
parameters?:
|
|
7
|
+
parameters?: Record<string, string>;
|
|
8
8
|
};
|
|
9
9
|
|
|
10
10
|
function componentForType(
|
|
@@ -61,7 +61,7 @@ export function componentPreview(
|
|
|
61
61
|
|
|
62
62
|
return href;
|
|
63
63
|
}
|
|
64
|
-
export function queryString(parameters:
|
|
64
|
+
export function queryString(parameters: Record<string, string> = {}): string {
|
|
65
65
|
let qs = '';
|
|
66
66
|
|
|
67
67
|
if (Object.keys(parameters).length > 0) {
|
|
@@ -21,15 +21,15 @@ const validateParameter = function (
|
|
|
21
21
|
interface ValidationResult {
|
|
22
22
|
isValid: boolean;
|
|
23
23
|
errors: {
|
|
24
|
-
mandatory?:
|
|
25
|
-
types?:
|
|
24
|
+
mandatory?: Record<string, string>;
|
|
25
|
+
types?: Record<string, string>;
|
|
26
26
|
message?: string;
|
|
27
27
|
};
|
|
28
28
|
}
|
|
29
29
|
|
|
30
30
|
export default function componentParameters(
|
|
31
|
-
requestParameters:
|
|
32
|
-
expectedParameters:
|
|
31
|
+
requestParameters: Record<string, string | number | boolean>,
|
|
32
|
+
expectedParameters: Record<string, OcParameter> = {}
|
|
33
33
|
): ValidationResult {
|
|
34
34
|
const result: ValidationResult = { isValid: true, errors: {} };
|
|
35
35
|
const mandatoryParameters: string[] = [];
|
|
@@ -105,10 +105,10 @@ export default function registryConfiguration(
|
|
|
105
105
|
const cdn = conf.storage.adapter(conf.storage.options);
|
|
106
106
|
if (cdn.adapterType === 's3') {
|
|
107
107
|
if (
|
|
108
|
-
!conf.storage.options
|
|
109
|
-
!conf.storage.options
|
|
110
|
-
(conf.storage.options
|
|
111
|
-
(!conf.storage.options
|
|
108
|
+
!conf.storage.options['bucket'] ||
|
|
109
|
+
!conf.storage.options['region'] ||
|
|
110
|
+
(conf.storage.options['key'] && !conf.storage.options['secret']) ||
|
|
111
|
+
(!conf.storage.options['key'] && conf.storage.options['secret'])
|
|
112
112
|
) {
|
|
113
113
|
return returnError(
|
|
114
114
|
strings.errors.registry.CONFIGURATION_STORAGE_NOT_VALID(
|
package/src/registry/index.ts
CHANGED
|
@@ -5,7 +5,7 @@ import http from 'http';
|
|
|
5
5
|
import _ from 'lodash';
|
|
6
6
|
|
|
7
7
|
import appStart from './app-start';
|
|
8
|
-
import
|
|
8
|
+
import eventsHandler from './domain/events-handler';
|
|
9
9
|
import * as middleware from './middleware';
|
|
10
10
|
import * as pluginsInitialiser from './domain/plugins-initialiser';
|
|
11
11
|
import Repository from './domain/repository';
|
|
@@ -46,7 +46,10 @@ export default function registry(inputOptions: Input) {
|
|
|
46
46
|
};
|
|
47
47
|
|
|
48
48
|
const start = (
|
|
49
|
-
callback:
|
|
49
|
+
callback: (
|
|
50
|
+
err: Error | null,
|
|
51
|
+
data: { app: express.Express; server: http.Server }
|
|
52
|
+
) => void
|
|
50
53
|
) => {
|
|
51
54
|
// eslint-disable-next-line no-console
|
|
52
55
|
const ok = (msg: string) => console.log(colors.green(msg));
|
|
@@ -56,12 +59,16 @@ export default function registry(inputOptions: Input) {
|
|
|
56
59
|
router.create(app, options, repository);
|
|
57
60
|
async.waterfall(
|
|
58
61
|
[
|
|
59
|
-
(
|
|
60
|
-
|
|
62
|
+
(
|
|
63
|
+
cb: (
|
|
64
|
+
err: unknown,
|
|
65
|
+
data: Record<string, (...args: unknown[]) => unknown>
|
|
66
|
+
) => void
|
|
67
|
+
) => pluginsInitialiser.init(plugins, cb),
|
|
61
68
|
|
|
62
69
|
(
|
|
63
|
-
plugins:
|
|
64
|
-
cb:
|
|
70
|
+
plugins: Record<string, (...args: unknown[]) => void>,
|
|
71
|
+
cb: (err: Error | null, data: ComponentsList | string) => void
|
|
65
72
|
) => {
|
|
66
73
|
options.plugins = plugins;
|
|
67
74
|
repository.init(cb);
|
|
@@ -69,7 +76,7 @@ export default function registry(inputOptions: Input) {
|
|
|
69
76
|
|
|
70
77
|
(
|
|
71
78
|
componentsInfo: ComponentsList,
|
|
72
|
-
cb:
|
|
79
|
+
cb: (err: string | null, data: ComponentsList) => void
|
|
73
80
|
) => {
|
|
74
81
|
appStart(repository, options, (err: any) =>
|
|
75
82
|
cb(err ? err.msg : null, componentsInfo)
|
|
@@ -117,9 +124,12 @@ export default function registry(inputOptions: Input) {
|
|
|
117
124
|
callback(null, { app, server });
|
|
118
125
|
});
|
|
119
126
|
|
|
120
|
-
server.on('error',
|
|
121
|
-
eventsHandler.fire('error', {
|
|
122
|
-
|
|
127
|
+
server.on('error', error => {
|
|
128
|
+
eventsHandler.fire('error', {
|
|
129
|
+
code: 'EXPRESS_ERROR',
|
|
130
|
+
message: error?.message ?? String(error)
|
|
131
|
+
});
|
|
132
|
+
callback(error, undefined as any);
|
|
123
133
|
});
|
|
124
134
|
}
|
|
125
135
|
);
|
|
@@ -19,7 +19,7 @@ export default function fileUpload(
|
|
|
19
19
|
},
|
|
20
20
|
storage: multer.diskStorage({
|
|
21
21
|
destination: res.conf.tempDir,
|
|
22
|
-
filename: (
|
|
22
|
+
filename: (_req, file, cb) =>
|
|
23
23
|
cb(null, `${normaliseFileName(file.originalname)}-${Date.now()}.tar.gz`)
|
|
24
24
|
})
|
|
25
25
|
});
|
|
@@ -1,26 +1,11 @@
|
|
|
1
1
|
import { Request, RequestHandler, Response } from 'express';
|
|
2
|
-
import { IncomingHttpHeaders } from 'http';
|
|
3
2
|
import responseTime from 'response-time';
|
|
4
3
|
|
|
5
|
-
import
|
|
6
|
-
|
|
7
|
-
interface ResponseTimeData {
|
|
8
|
-
body: any;
|
|
9
|
-
duration: number;
|
|
10
|
-
headers: IncomingHttpHeaders;
|
|
11
|
-
method: string;
|
|
12
|
-
path: string;
|
|
13
|
-
relativeUrl: string;
|
|
14
|
-
query: Record<string, any>;
|
|
15
|
-
url: string;
|
|
16
|
-
statusCode: number;
|
|
17
|
-
errorDetails?: string;
|
|
18
|
-
errorCode?: string;
|
|
19
|
-
}
|
|
4
|
+
import eventsHandler, { RequestData } from '../domain/events-handler';
|
|
20
5
|
|
|
21
6
|
export default function requestHandler(): RequestHandler {
|
|
22
7
|
return responseTime((req: Request, res: Response, time) => {
|
|
23
|
-
const data:
|
|
8
|
+
const data: RequestData = {
|
|
24
9
|
body: req.body,
|
|
25
10
|
duration: parseInt(String(time * 1000)),
|
|
26
11
|
headers: req.headers,
|
|
@@ -32,12 +17,12 @@ export default function requestHandler(): RequestHandler {
|
|
|
32
17
|
statusCode: res.statusCode
|
|
33
18
|
};
|
|
34
19
|
|
|
35
|
-
if (
|
|
36
|
-
data.errorDetails =
|
|
20
|
+
if (res.errorDetails) {
|
|
21
|
+
data.errorDetails = res.errorDetails;
|
|
37
22
|
}
|
|
38
23
|
|
|
39
|
-
if (
|
|
40
|
-
data.errorCode =
|
|
24
|
+
if (res.errorCode) {
|
|
25
|
+
data.errorCode = res.errorCode;
|
|
41
26
|
}
|
|
42
27
|
|
|
43
28
|
eventsHandler.fire('request', data);
|
package/src/registry/router.ts
CHANGED
|
@@ -31,7 +31,7 @@ export function create(
|
|
|
31
31
|
const prefix = conf.prefix;
|
|
32
32
|
|
|
33
33
|
if (prefix !== '/') {
|
|
34
|
-
app.get('/', (
|
|
34
|
+
app.get('/', (_req, res) => res.redirect(prefix));
|
|
35
35
|
app.get(prefix.substr(0, prefix.length - 1), routes.index);
|
|
36
36
|
}
|
|
37
37
|
|
|
@@ -43,10 +43,11 @@ function componentInfo(
|
|
|
43
43
|
req: Request,
|
|
44
44
|
res: Response,
|
|
45
45
|
component: Component
|
|
46
|
-
) {
|
|
46
|
+
): void {
|
|
47
47
|
if (err) {
|
|
48
48
|
res.errorDetails = (err as any).registryError || err;
|
|
49
|
-
|
|
49
|
+
res.status(404).json(err);
|
|
50
|
+
return;
|
|
50
51
|
}
|
|
51
52
|
|
|
52
53
|
const isHtmlRequest =
|
|
@@ -63,7 +64,7 @@ function componentInfo(
|
|
|
63
64
|
typeof component.repository === 'string' ? component.repository : null
|
|
64
65
|
);
|
|
65
66
|
|
|
66
|
-
isUrlDiscoverable(href, (
|
|
67
|
+
isUrlDiscoverable(href, (_err, result) => {
|
|
67
68
|
if (!result.isDiscoverable) {
|
|
68
69
|
href = `//${req.headers.host}${res.conf.prefix}`;
|
|
69
70
|
}
|
|
@@ -83,7 +84,7 @@ function componentInfo(
|
|
|
83
84
|
} else {
|
|
84
85
|
res.status(200).json(
|
|
85
86
|
Object.assign(component, {
|
|
86
|
-
requestVersion: req.params
|
|
87
|
+
requestVersion: req.params['componentVersion'] || ''
|
|
87
88
|
})
|
|
88
89
|
);
|
|
89
90
|
}
|
|
@@ -95,8 +96,8 @@ export default function componentInfoRoute(
|
|
|
95
96
|
) {
|
|
96
97
|
return function (req: Request, res: Response): void {
|
|
97
98
|
repository.getComponent(
|
|
98
|
-
req.params
|
|
99
|
-
req.params
|
|
99
|
+
req.params['componentName'],
|
|
100
|
+
req.params['componentVersion'],
|
|
100
101
|
(registryError, component) => {
|
|
101
102
|
if (registryError && conf.fallbackRegistryUrl) {
|
|
102
103
|
return getComponentFallback.getComponentInfo(
|