oc 0.49.21 → 0.49.23
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/CHANGELOG.md +8 -0
- package/dist/cli/domain/get-mocked-plugins.js +2 -3
- package/dist/cli/domain/handle-dependencies/ensure-compiler-is-declared-as-devDependency.js +1 -2
- package/dist/cli/domain/local.d.ts +1 -1
- package/dist/cli/domain/registry.d.ts +1 -1
- package/dist/cli/programmatic-api.d.ts +2 -2
- package/dist/components/oc-client/_package/package.json +1 -1
- package/dist/components/oc-client/package.json +1 -1
- package/dist/registry/domain/components-cache/components-list.d.ts +3 -3
- package/dist/registry/domain/components-cache/components-list.js +28 -5
- package/dist/registry/domain/components-cache/index.js +27 -22
- package/dist/registry/domain/components-details.js +1 -2
- package/dist/registry/domain/events-handler.d.ts +3 -3
- package/dist/registry/domain/plugins-initialiser.d.ts +1 -1
- package/dist/registry/domain/repository.d.ts +1 -1
- package/dist/registry/domain/storage-adapter.d.ts +2 -2
- package/dist/registry/domain/url-builder.d.ts +1 -1
- package/dist/registry/domain/validators/node-version.d.ts +3 -3
- package/dist/registry/domain/validators/oc-cli-version.d.ts +3 -3
- package/dist/registry/domain/validators/plugins-requirements.d.ts +1 -1
- package/dist/registry/domain/validators/registry-configuration.d.ts +1 -1
- package/dist/registry/domain/validators/uploaded-package.d.ts +1 -1
- package/dist/registry/index.js +2 -3
- package/dist/registry/routes/helpers/get-available-dependencies.js +2 -3
- package/dist/registry/routes/helpers/get-component-fallback.d.ts +1 -1
- package/dist/registry/routes/helpers/is-url-discoverable.js +1 -2
- package/dist/registry/views/info.d.ts +1 -1
- package/dist/registry/views/partials/selected-checkbox.d.ts +1 -1
- package/dist/types.d.ts +3 -3
- package/dist/utils/is-template-legacy.d.ts +1 -1
- package/logintervals.md +1 -1
- package/package.json +20 -20
- package/tsconfig.json +1 -1
- package/src/cli/commands.ts +0 -178
- package/src/cli/domain/clean.ts +0 -21
- package/src/cli/domain/get-components-by-dir.ts +0 -47
- package/src/cli/domain/get-mocked-plugins.ts +0 -154
- package/src/cli/domain/handle-dependencies/ensure-compiler-is-declared-as-devDependency.ts +0 -17
- package/src/cli/domain/handle-dependencies/get-compiler.ts +0 -35
- package/src/cli/domain/handle-dependencies/get-missing-dependencies.ts +0 -17
- package/src/cli/domain/handle-dependencies/index.ts +0 -93
- package/src/cli/domain/handle-dependencies/install-compiler.ts +0 -43
- package/src/cli/domain/handle-dependencies/install-missing-dependencies.ts +0 -48
- package/src/cli/domain/handle-dependencies/link-missing-dependencies.ts +0 -45
- package/src/cli/domain/handle-dependencies/require-template.ts +0 -62
- package/src/cli/domain/init-template/index.ts +0 -26
- package/src/cli/domain/init-template/install-template.ts +0 -52
- package/src/cli/domain/init-template/scaffold.ts +0 -45
- package/src/cli/domain/local.ts +0 -77
- package/src/cli/domain/mock.ts +0 -40
- package/src/cli/domain/package-components.ts +0 -61
- package/src/cli/domain/registry.ts +0 -147
- package/src/cli/domain/url-parser.ts +0 -44
- package/src/cli/domain/watch.ts +0 -33
- package/src/cli/facade/clean.ts +0 -75
- package/src/cli/facade/dev.ts +0 -214
- package/src/cli/facade/init.ts +0 -50
- package/src/cli/facade/mock.ts +0 -20
- package/src/cli/facade/package.ts +0 -65
- package/src/cli/facade/preview.ts +0 -28
- package/src/cli/facade/publish.ts +0 -209
- package/src/cli/facade/registry-add.ts +0 -23
- package/src/cli/facade/registry-ls.ts +0 -36
- package/src/cli/facade/registry-remove.ts +0 -23
- package/src/cli/facade/registry.ts +0 -9
- package/src/cli/index.ts +0 -142
- package/src/cli/logger.ts +0 -38
- package/src/cli/programmatic-api.ts +0 -142
- package/src/cli/validate-command.ts +0 -18
- package/src/components/oc-client/_package/package.json +0 -1
- package/src/components/oc-client/_package/server.js +0 -1
- package/src/components/oc-client/_package/src/oc-client.min.js +0 -3
- package/src/components/oc-client/_package/src/oc-client.min.map +0 -1
- package/src/components/oc-client/_package/template.js +0 -1
- package/src/components/oc-client/package.json +0 -26
- package/src/components/oc-client/server.js +0 -6
- package/src/components/oc-client/src/oc-client.min.js +0 -3
- package/src/components/oc-client/src/oc-client.min.map +0 -1
- package/src/components/oc-client/template.js +0 -4
- package/src/globals.d.ts +0 -103
- package/src/index.ts +0 -3
- package/src/oc-cli.js +0 -3
- package/src/registry/app-start.ts +0 -75
- package/src/registry/domain/authentication.ts +0 -59
- package/src/registry/domain/components-cache/components-list.ts +0 -70
- package/src/registry/domain/components-cache/index.ts +0 -90
- package/src/registry/domain/components-details.ts +0 -96
- package/src/registry/domain/events-handler.ts +0 -86
- package/src/registry/domain/extract-package.ts +0 -45
- package/src/registry/domain/get-package-json-from-temp-dir.ts +0 -9
- package/src/registry/domain/nested-renderer.ts +0 -88
- package/src/registry/domain/options-sanitiser.ts +0 -118
- package/src/registry/domain/plugins-initialiser.ts +0 -127
- package/src/registry/domain/register-templates.ts +0 -41
- package/src/registry/domain/repository.ts +0 -390
- package/src/registry/domain/require-wrapper.ts +0 -39
- package/src/registry/domain/sanitiser.ts +0 -60
- package/src/registry/domain/storage-adapter.ts +0 -85
- package/src/registry/domain/url-builder.ts +0 -80
- package/src/registry/domain/validators/component-parameters.ts +0 -112
- package/src/registry/domain/validators/index.ts +0 -24
- package/src/registry/domain/validators/node-version.ts +0 -59
- package/src/registry/domain/validators/oc-cli-version.ts +0 -52
- package/src/registry/domain/validators/package-json-validator.ts +0 -35
- package/src/registry/domain/validators/plugins-requirements.ts +0 -39
- package/src/registry/domain/validators/registry-configuration.ts +0 -143
- package/src/registry/domain/validators/uploaded-package.ts +0 -49
- package/src/registry/domain/version-handler.ts +0 -25
- package/src/registry/index.ts +0 -117
- package/src/registry/middleware/base-url-handler.ts +0 -16
- package/src/registry/middleware/cors.ts +0 -18
- package/src/registry/middleware/discovery-handler.ts +0 -20
- package/src/registry/middleware/file-uploads.ts +0 -28
- package/src/registry/middleware/index.ts +0 -53
- package/src/registry/middleware/request-handler.ts +0 -30
- package/src/registry/router.ts +0 -85
- package/src/registry/routes/component-info.ts +0 -119
- package/src/registry/routes/component-preview.ts +0 -87
- package/src/registry/routes/component.ts +0 -53
- package/src/registry/routes/components.ts +0 -107
- package/src/registry/routes/dependencies.ts +0 -27
- package/src/registry/routes/helpers/apply-default-values.ts +0 -29
- package/src/registry/routes/helpers/get-available-dependencies.ts +0 -31
- package/src/registry/routes/helpers/get-component-fallback.ts +0 -139
- package/src/registry/routes/helpers/get-component-retrieving-info.ts +0 -44
- package/src/registry/routes/helpers/get-component.ts +0 -583
- package/src/registry/routes/helpers/get-components-history.ts +0 -40
- package/src/registry/routes/helpers/is-url-discoverable.ts +0 -18
- package/src/registry/routes/index.ts +0 -127
- package/src/registry/routes/plugins.ts +0 -19
- package/src/registry/routes/publish.ts +0 -89
- package/src/registry/routes/static-redirector.ts +0 -74
- package/src/registry/views/index.ts +0 -66
- package/src/registry/views/info.ts +0 -89
- package/src/registry/views/partials/component-author.ts +0 -32
- package/src/registry/views/partials/component-parameters.ts +0 -53
- package/src/registry/views/partials/component-state.ts +0 -14
- package/src/registry/views/partials/component-versions.ts +0 -16
- package/src/registry/views/partials/components-dependencies.ts +0 -26
- package/src/registry/views/partials/components-history.ts +0 -24
- package/src/registry/views/partials/components-list.ts +0 -65
- package/src/registry/views/partials/components-plugins.ts +0 -23
- package/src/registry/views/partials/components-templates.ts +0 -36
- package/src/registry/views/partials/layout.ts +0 -32
- package/src/registry/views/partials/property.ts +0 -17
- package/src/registry/views/partials/selected-checkbox.ts +0 -16
- package/src/registry/views/preview.ts +0 -37
- package/src/registry/views/static/index.ts +0 -92
- package/src/registry/views/static/info.ts +0 -43
- package/src/registry/views/static/style.ts +0 -277
- package/src/resources/index.ts +0 -279
- package/src/resources/settings.ts +0 -17
- package/src/types.ts +0 -251
- package/src/utils/clean-require.ts +0 -35
- package/src/utils/date-stringify.ts +0 -23
- package/src/utils/error-to-string.ts +0 -13
- package/src/utils/is-template-legacy.ts +0 -7
- package/src/utils/is-template-valid.ts +0 -19
- package/src/utils/module-exists.ts +0 -14
- package/src/utils/npm-utils.ts +0 -109
- package/src/utils/put.ts +0 -35
- package/src/utils/strip-version.ts +0 -6
package/src/globals.d.ts
DELETED
|
@@ -1,103 +0,0 @@
|
|
|
1
|
-
declare module 'oc-client';
|
|
2
|
-
declare module 'try-require';
|
|
3
|
-
declare module 'basic-auth-connect';
|
|
4
|
-
|
|
5
|
-
declare module 'universalify' {
|
|
6
|
-
export function fromCallback<
|
|
7
|
-
Arguments extends readonly unknown[],
|
|
8
|
-
ErrorValue,
|
|
9
|
-
ReturnValue
|
|
10
|
-
>(
|
|
11
|
-
fn: (
|
|
12
|
-
...arguments_: [
|
|
13
|
-
...Arguments,
|
|
14
|
-
(error: ErrorValue, value: ReturnValue) => void
|
|
15
|
-
]
|
|
16
|
-
) => void
|
|
17
|
-
): {
|
|
18
|
-
(...arguments_: Arguments): Promise<ReturnValue>;
|
|
19
|
-
(
|
|
20
|
-
...arguments_: [
|
|
21
|
-
...Arguments,
|
|
22
|
-
(error: ErrorValue, value: ReturnValue) => void
|
|
23
|
-
]
|
|
24
|
-
): void;
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
export function fromPromise<
|
|
28
|
-
Arguments extends readonly unknown[],
|
|
29
|
-
ReturnValue
|
|
30
|
-
>(
|
|
31
|
-
fn: (...arguments_: [...Arguments]) => Promise<ReturnValue>
|
|
32
|
-
): {
|
|
33
|
-
(...arguments_: Arguments): Promise<ReturnValue>;
|
|
34
|
-
(
|
|
35
|
-
...arguments_: [
|
|
36
|
-
...Arguments,
|
|
37
|
-
(error: unknown, value: ReturnValue) => void
|
|
38
|
-
]
|
|
39
|
-
): void;
|
|
40
|
-
};
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
declare module 'semver-extra' {
|
|
44
|
-
interface SemverExtra {
|
|
45
|
-
max(versions: string[]): string;
|
|
46
|
-
maxStable(versions: string[]): string;
|
|
47
|
-
maxPrerelase(versions: string[], preRelease?: string): string;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
const semverExtra: SemverExtra;
|
|
51
|
-
|
|
52
|
-
export = semverExtra;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
declare module 'require-package-name' {
|
|
56
|
-
function requirePackageName(name: string): string;
|
|
57
|
-
|
|
58
|
-
export = requirePackageName;
|
|
59
|
-
}
|
|
60
|
-
declare module 'getport' {
|
|
61
|
-
function getPort(
|
|
62
|
-
start: number,
|
|
63
|
-
cb: (err: unknown, data: number) => void
|
|
64
|
-
): void;
|
|
65
|
-
|
|
66
|
-
export = getPort;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
declare module 'nice-cache' {
|
|
70
|
-
class Cache {
|
|
71
|
-
constructor(opt: { refreshInterval?: number; verbose?: boolean });
|
|
72
|
-
|
|
73
|
-
get(type: string, key: string): any;
|
|
74
|
-
set(type: string, key: string, data: unknown): void;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
export = Cache;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
declare module 'minimal-request' {
|
|
81
|
-
function request<T>(
|
|
82
|
-
opts: {
|
|
83
|
-
method?: string;
|
|
84
|
-
body?: unknown;
|
|
85
|
-
url: string;
|
|
86
|
-
headers?: Record<string, string | null | undefined | string[]>;
|
|
87
|
-
json?: boolean;
|
|
88
|
-
},
|
|
89
|
-
cb: (
|
|
90
|
-
err: Error | number | null,
|
|
91
|
-
body: T,
|
|
92
|
-
details: {
|
|
93
|
-
response: {
|
|
94
|
-
headers: Record<string, string>;
|
|
95
|
-
};
|
|
96
|
-
}
|
|
97
|
-
) => void
|
|
98
|
-
): void;
|
|
99
|
-
|
|
100
|
-
const request: Request;
|
|
101
|
-
|
|
102
|
-
export = request;
|
|
103
|
-
}
|
package/src/index.ts
DELETED
package/src/oc-cli.js
DELETED
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
import colors from 'colors/safe';
|
|
2
|
-
import path from 'path';
|
|
3
|
-
import fs from 'fs-extra';
|
|
4
|
-
import type { Repository } from './domain/repository';
|
|
5
|
-
import { Config } from '../types';
|
|
6
|
-
|
|
7
|
-
const packageInfo = fs.readJsonSync(
|
|
8
|
-
path.join(
|
|
9
|
-
__dirname,
|
|
10
|
-
'..',
|
|
11
|
-
'components',
|
|
12
|
-
'oc-client',
|
|
13
|
-
'_package',
|
|
14
|
-
'package.json'
|
|
15
|
-
)
|
|
16
|
-
);
|
|
17
|
-
|
|
18
|
-
export default async function appStart(
|
|
19
|
-
repository: Repository,
|
|
20
|
-
options: Config
|
|
21
|
-
): Promise<void> {
|
|
22
|
-
if (options.local) {
|
|
23
|
-
return;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
27
|
-
const logger = options.verbosity ? console : { log: () => {} };
|
|
28
|
-
|
|
29
|
-
logger.log(
|
|
30
|
-
colors.yellow(
|
|
31
|
-
`Connecting to library: ${options.storage.options['bucket']}/${options.storage.options.componentsDir}`
|
|
32
|
-
)
|
|
33
|
-
);
|
|
34
|
-
|
|
35
|
-
try {
|
|
36
|
-
const componentInfo = await repository.getComponentVersions('oc-client');
|
|
37
|
-
|
|
38
|
-
logger.log(
|
|
39
|
-
colors.yellow(
|
|
40
|
-
`Ensuring oc-client@${packageInfo.version} is available on library...`
|
|
41
|
-
)
|
|
42
|
-
);
|
|
43
|
-
|
|
44
|
-
if (!componentInfo.includes(packageInfo.version)) {
|
|
45
|
-
logger.log(colors.yellow('Component not found. Publishing it...'));
|
|
46
|
-
|
|
47
|
-
const pkgInfo = {
|
|
48
|
-
outputFolder: path.resolve(
|
|
49
|
-
__dirname,
|
|
50
|
-
'../components/oc-client/_package'
|
|
51
|
-
),
|
|
52
|
-
packageJson: packageInfo
|
|
53
|
-
};
|
|
54
|
-
|
|
55
|
-
try {
|
|
56
|
-
await repository.publishComponent(
|
|
57
|
-
pkgInfo,
|
|
58
|
-
'oc-client',
|
|
59
|
-
packageInfo.version
|
|
60
|
-
);
|
|
61
|
-
logger.log(colors.green('Component published.'));
|
|
62
|
-
} catch (err) {
|
|
63
|
-
logger.log(
|
|
64
|
-
colors.red(`Component not published: ${(err as Error).message}`)
|
|
65
|
-
);
|
|
66
|
-
throw err;
|
|
67
|
-
}
|
|
68
|
-
} else {
|
|
69
|
-
logger.log(colors.green('Component is available on library.'));
|
|
70
|
-
}
|
|
71
|
-
} catch (err) {
|
|
72
|
-
logger.log(colors.red(String(err)));
|
|
73
|
-
throw err;
|
|
74
|
-
}
|
|
75
|
-
}
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
import basicAuth from 'basic-auth-connect';
|
|
2
|
-
import { RequestHandler } from 'express';
|
|
3
|
-
|
|
4
|
-
import strings from '../../resources/';
|
|
5
|
-
import { Authentication, PublishAuthConfig } from '../../types';
|
|
6
|
-
|
|
7
|
-
const basicAuthentication: Authentication<{
|
|
8
|
-
username: string;
|
|
9
|
-
password: string;
|
|
10
|
-
}> = {
|
|
11
|
-
validate(authConfig) {
|
|
12
|
-
const isValid = !!authConfig.username && !!authConfig.password;
|
|
13
|
-
|
|
14
|
-
return {
|
|
15
|
-
isValid,
|
|
16
|
-
message: isValid
|
|
17
|
-
? ''
|
|
18
|
-
: strings.errors.registry
|
|
19
|
-
.CONFIGURATION_PUBLISH_BASIC_AUTH_CREDENTIALS_MISSING
|
|
20
|
-
};
|
|
21
|
-
},
|
|
22
|
-
middleware(authConfig) {
|
|
23
|
-
return basicAuth(authConfig.username, authConfig.password);
|
|
24
|
-
}
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
const builtin: Record<string, Authentication> = {
|
|
28
|
-
basic: basicAuthentication
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
let scheme: Authentication;
|
|
32
|
-
|
|
33
|
-
export function validate(authConfig: PublishAuthConfig) {
|
|
34
|
-
if (typeof authConfig.type !== 'string') {
|
|
35
|
-
scheme = authConfig.type;
|
|
36
|
-
} else if (builtin[authConfig.type]) {
|
|
37
|
-
scheme = builtin[authConfig.type];
|
|
38
|
-
} else {
|
|
39
|
-
const moduleName = `oc-auth-${authConfig.type}`;
|
|
40
|
-
|
|
41
|
-
try {
|
|
42
|
-
scheme = require(moduleName);
|
|
43
|
-
} catch (err) {
|
|
44
|
-
return {
|
|
45
|
-
isValid: false,
|
|
46
|
-
message:
|
|
47
|
-
strings.errors.registry.CONFIGURATION_PUBLISH_AUTH_MODULE_NOT_FOUND(
|
|
48
|
-
moduleName
|
|
49
|
-
)
|
|
50
|
-
};
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
return scheme.validate(authConfig);
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
export function middleware(authConfig: unknown): RequestHandler {
|
|
58
|
-
return scheme.middleware(authConfig);
|
|
59
|
-
}
|
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
import semver from 'semver';
|
|
2
|
-
import pLimit from 'p-limit';
|
|
3
|
-
import getUnixUTCTimestamp from 'oc-get-unix-utc-timestamp';
|
|
4
|
-
import { ComponentsList, Config } from '../../../types';
|
|
5
|
-
import { StorageAdapter } from 'oc-storage-adapters-utils';
|
|
6
|
-
|
|
7
|
-
export default function componentsList(conf: Config, cdn: StorageAdapter) {
|
|
8
|
-
const filePath = (): string =>
|
|
9
|
-
`${conf.storage.options.componentsDir}/components.json`;
|
|
10
|
-
|
|
11
|
-
const componentsList = {
|
|
12
|
-
getFromJson: (): Promise<ComponentsList> => cdn.getJson(filePath(), true),
|
|
13
|
-
|
|
14
|
-
getFromDirectories: async (): Promise<ComponentsList> => {
|
|
15
|
-
const componentsInfo: Record<string, string[]> = {};
|
|
16
|
-
|
|
17
|
-
const getVersionsForComponent = async (
|
|
18
|
-
componentName: string
|
|
19
|
-
): Promise<string[]> => {
|
|
20
|
-
const versions = await cdn.listSubDirectories(
|
|
21
|
-
`${conf.storage.options.componentsDir}/${componentName}`
|
|
22
|
-
);
|
|
23
|
-
|
|
24
|
-
return versions.sort(semver.compare);
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
try {
|
|
28
|
-
const components = await cdn.listSubDirectories(
|
|
29
|
-
conf.storage.options.componentsDir
|
|
30
|
-
);
|
|
31
|
-
const limit = pLimit(cdn.maxConcurrentRequests);
|
|
32
|
-
|
|
33
|
-
const versions = await Promise.all(
|
|
34
|
-
components.map(component =>
|
|
35
|
-
limit(() => getVersionsForComponent(component))
|
|
36
|
-
)
|
|
37
|
-
);
|
|
38
|
-
|
|
39
|
-
components.forEach((component, i) => {
|
|
40
|
-
componentsInfo[component] = versions[i];
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
return {
|
|
44
|
-
lastEdit: getUnixUTCTimestamp(),
|
|
45
|
-
components: componentsInfo
|
|
46
|
-
};
|
|
47
|
-
} catch (err: any) {
|
|
48
|
-
if (err.code === 'dir_not_found') {
|
|
49
|
-
return {
|
|
50
|
-
lastEdit: getUnixUTCTimestamp(),
|
|
51
|
-
components: {}
|
|
52
|
-
};
|
|
53
|
-
}
|
|
54
|
-
throw err;
|
|
55
|
-
}
|
|
56
|
-
},
|
|
57
|
-
|
|
58
|
-
async refresh(): Promise<ComponentsList> {
|
|
59
|
-
const components = await componentsList.getFromDirectories();
|
|
60
|
-
await componentsList.save(components);
|
|
61
|
-
|
|
62
|
-
return components;
|
|
63
|
-
},
|
|
64
|
-
|
|
65
|
-
save: (data: ComponentsList): Promise<unknown> =>
|
|
66
|
-
cdn.putFileContent(JSON.stringify(data), filePath(), true)
|
|
67
|
-
};
|
|
68
|
-
|
|
69
|
-
return componentsList;
|
|
70
|
-
}
|
|
@@ -1,90 +0,0 @@
|
|
|
1
|
-
import _ from 'lodash';
|
|
2
|
-
import getComponentsList from './components-list';
|
|
3
|
-
import eventsHandler from '../events-handler';
|
|
4
|
-
import getUnixUTCTimestamp from 'oc-get-unix-utc-timestamp';
|
|
5
|
-
import { ComponentsList, Config } from '../../../types';
|
|
6
|
-
import { StorageAdapter } from 'oc-storage-adapters-utils';
|
|
7
|
-
|
|
8
|
-
export default function componentsCache(conf: Config, cdn: StorageAdapter) {
|
|
9
|
-
let cachedComponentsList: ComponentsList;
|
|
10
|
-
let refreshLoop: NodeJS.Timeout;
|
|
11
|
-
|
|
12
|
-
const componentsList = getComponentsList(conf, cdn);
|
|
13
|
-
|
|
14
|
-
const poll = () =>
|
|
15
|
-
setTimeout(async () => {
|
|
16
|
-
try {
|
|
17
|
-
const data = await componentsList.getFromJson();
|
|
18
|
-
|
|
19
|
-
eventsHandler.fire('cache-poll', getUnixUTCTimestamp());
|
|
20
|
-
|
|
21
|
-
if (data.lastEdit > cachedComponentsList.lastEdit) {
|
|
22
|
-
cachedComponentsList = data;
|
|
23
|
-
}
|
|
24
|
-
} catch (err: any) {
|
|
25
|
-
eventsHandler.fire('error', {
|
|
26
|
-
code: 'components_list_get',
|
|
27
|
-
message: err?.message || String(err)
|
|
28
|
-
});
|
|
29
|
-
}
|
|
30
|
-
refreshLoop = poll();
|
|
31
|
-
}, conf.pollingInterval * 1000);
|
|
32
|
-
|
|
33
|
-
const cacheDataAndStartPolling = (data: ComponentsList) => {
|
|
34
|
-
cachedComponentsList = data;
|
|
35
|
-
refreshLoop = poll();
|
|
36
|
-
|
|
37
|
-
return data;
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
const throwError = (code: string, message: any) => {
|
|
41
|
-
eventsHandler.fire('error', { code, message: message?.message ?? message });
|
|
42
|
-
throw code;
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
return {
|
|
46
|
-
get(): ComponentsList {
|
|
47
|
-
if (!cachedComponentsList) {
|
|
48
|
-
return throwError(
|
|
49
|
-
'components_cache_empty',
|
|
50
|
-
`The component's cache was empty`
|
|
51
|
-
);
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
return cachedComponentsList;
|
|
55
|
-
},
|
|
56
|
-
|
|
57
|
-
async load(): Promise<ComponentsList> {
|
|
58
|
-
const dirComponents = await componentsList
|
|
59
|
-
.getFromDirectories()
|
|
60
|
-
.catch(err => throwError('components_list_get', err));
|
|
61
|
-
const jsonComponents = await componentsList
|
|
62
|
-
.getFromJson()
|
|
63
|
-
.catch(() => null);
|
|
64
|
-
|
|
65
|
-
if (
|
|
66
|
-
!jsonComponents ||
|
|
67
|
-
!_.isEqual(dirComponents.components, jsonComponents.components)
|
|
68
|
-
) {
|
|
69
|
-
await componentsList
|
|
70
|
-
.save(dirComponents)
|
|
71
|
-
.catch(err => throwError('components_list_save', err));
|
|
72
|
-
}
|
|
73
|
-
cacheDataAndStartPolling(dirComponents);
|
|
74
|
-
|
|
75
|
-
return dirComponents;
|
|
76
|
-
},
|
|
77
|
-
|
|
78
|
-
async refresh(): Promise<ComponentsList> {
|
|
79
|
-
clearTimeout(refreshLoop);
|
|
80
|
-
try {
|
|
81
|
-
const components = await componentsList.refresh();
|
|
82
|
-
cacheDataAndStartPolling(components);
|
|
83
|
-
|
|
84
|
-
return components;
|
|
85
|
-
} catch (err) {
|
|
86
|
-
return throwError('components_cache_refresh', err);
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
};
|
|
90
|
-
}
|
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
import pLimit from 'p-limit';
|
|
2
|
-
import _ from 'lodash';
|
|
3
|
-
import eventsHandler from './events-handler';
|
|
4
|
-
import getUnixUTCTimestamp from 'oc-get-unix-utc-timestamp';
|
|
5
|
-
import {
|
|
6
|
-
Component,
|
|
7
|
-
ComponentsDetails,
|
|
8
|
-
ComponentsList,
|
|
9
|
-
Config
|
|
10
|
-
} from '../../types';
|
|
11
|
-
import { StorageAdapter } from 'oc-storage-adapters-utils';
|
|
12
|
-
|
|
13
|
-
export default function componentsDetails(conf: Config, cdn: StorageAdapter) {
|
|
14
|
-
const returnError = (code: string, message: string | Error) => {
|
|
15
|
-
eventsHandler.fire('error', {
|
|
16
|
-
code,
|
|
17
|
-
message: (message as Error)?.message ?? message
|
|
18
|
-
});
|
|
19
|
-
throw code;
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
const filePath = (): string =>
|
|
23
|
-
`${conf.storage.options.componentsDir}/components-details.json`;
|
|
24
|
-
|
|
25
|
-
const getFromJson = (): Promise<ComponentsDetails> =>
|
|
26
|
-
cdn.getJson(filePath(), true);
|
|
27
|
-
|
|
28
|
-
const getFromDirectories = async (options: {
|
|
29
|
-
componentsList: ComponentsList;
|
|
30
|
-
details?: ComponentsDetails;
|
|
31
|
-
}): Promise<ComponentsDetails> => {
|
|
32
|
-
const details = Object.assign({}, _.cloneDeep(options.details));
|
|
33
|
-
details.components = details.components || {};
|
|
34
|
-
|
|
35
|
-
const missing: Array<{ name: string; version: string }> = [];
|
|
36
|
-
_.each(options.componentsList.components, (versions, name) => {
|
|
37
|
-
details.components[name] = details.components[name] || {};
|
|
38
|
-
_.each(versions, version => {
|
|
39
|
-
if (!details.components[name][version]) {
|
|
40
|
-
missing.push({ name, version });
|
|
41
|
-
}
|
|
42
|
-
});
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
const limit = pLimit(cdn.maxConcurrentRequests);
|
|
46
|
-
|
|
47
|
-
await Promise.all(
|
|
48
|
-
missing.map(({ name, version }) =>
|
|
49
|
-
limit(async () => {
|
|
50
|
-
const content: Component = await cdn.getJson(
|
|
51
|
-
`${conf.storage.options.componentsDir}/${name}/${version}/package.json`,
|
|
52
|
-
true
|
|
53
|
-
);
|
|
54
|
-
details.components[name][version] = {
|
|
55
|
-
publishDate: content.oc.date || 0
|
|
56
|
-
};
|
|
57
|
-
})
|
|
58
|
-
)
|
|
59
|
-
);
|
|
60
|
-
|
|
61
|
-
return {
|
|
62
|
-
lastEdit: getUnixUTCTimestamp(),
|
|
63
|
-
components: details.components
|
|
64
|
-
};
|
|
65
|
-
};
|
|
66
|
-
|
|
67
|
-
const save = (data: ComponentsDetails): Promise<unknown> =>
|
|
68
|
-
cdn.putFileContent(JSON.stringify(data), filePath(), true);
|
|
69
|
-
|
|
70
|
-
const refresh = async (
|
|
71
|
-
componentsList: ComponentsList
|
|
72
|
-
): Promise<ComponentsDetails> => {
|
|
73
|
-
const jsonDetails = await getFromJson().catch(() => undefined);
|
|
74
|
-
const dirDetails = await getFromDirectories({
|
|
75
|
-
componentsList,
|
|
76
|
-
details: jsonDetails
|
|
77
|
-
}).catch(err => returnError('components_details_get', err));
|
|
78
|
-
|
|
79
|
-
if (
|
|
80
|
-
!jsonDetails ||
|
|
81
|
-
!_.isEqual(dirDetails.components, jsonDetails.components)
|
|
82
|
-
) {
|
|
83
|
-
await save(dirDetails).catch(err =>
|
|
84
|
-
returnError('components_details_save', err)
|
|
85
|
-
);
|
|
86
|
-
return dirDetails;
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
return jsonDetails;
|
|
90
|
-
};
|
|
91
|
-
|
|
92
|
-
return {
|
|
93
|
-
get: getFromJson,
|
|
94
|
-
refresh
|
|
95
|
-
};
|
|
96
|
-
}
|
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
import { IncomingHttpHeaders } from 'http';
|
|
2
|
-
import strings from '../../resources';
|
|
3
|
-
|
|
4
|
-
type Subscription<T = any> = (data: T) => void;
|
|
5
|
-
let subscriptions: Record<string, Array<Subscription>> = {};
|
|
6
|
-
|
|
7
|
-
export interface RequestData {
|
|
8
|
-
body: unknown;
|
|
9
|
-
duration: number;
|
|
10
|
-
headers: IncomingHttpHeaders;
|
|
11
|
-
method: string;
|
|
12
|
-
path: string;
|
|
13
|
-
relativeUrl: string;
|
|
14
|
-
query: Record<string, unknown>;
|
|
15
|
-
url: string;
|
|
16
|
-
statusCode: number;
|
|
17
|
-
errorDetails?: string;
|
|
18
|
-
errorCode?: string;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
type Events = {
|
|
22
|
-
error: { code: string; message: string };
|
|
23
|
-
start: unknown;
|
|
24
|
-
'cache-poll': number;
|
|
25
|
-
request: RequestData;
|
|
26
|
-
'component-retrieved': {
|
|
27
|
-
headers: IncomingHttpHeaders;
|
|
28
|
-
name: string;
|
|
29
|
-
parameters: IncomingHttpHeaders;
|
|
30
|
-
requestVersion: string;
|
|
31
|
-
duration: number;
|
|
32
|
-
};
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
type EventsHandler = {
|
|
36
|
-
fire<T extends keyof Events>(eventName: T, data: Events[T]): void;
|
|
37
|
-
on<T extends keyof Events>(
|
|
38
|
-
eventName: T,
|
|
39
|
-
listener: Subscription<Events[T]>
|
|
40
|
-
): void;
|
|
41
|
-
off<T extends keyof Events>(
|
|
42
|
-
eventName: T,
|
|
43
|
-
listener: Subscription<Events[T]>
|
|
44
|
-
): void;
|
|
45
|
-
reset(): void;
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
const eventsHandler: EventsHandler = {
|
|
49
|
-
fire(eventName: string, eventData: unknown): void {
|
|
50
|
-
if (subscriptions[eventName]) {
|
|
51
|
-
subscriptions[eventName].forEach(callback => {
|
|
52
|
-
callback(eventData);
|
|
53
|
-
});
|
|
54
|
-
}
|
|
55
|
-
},
|
|
56
|
-
|
|
57
|
-
on(eventName: string, callback: Subscription): void {
|
|
58
|
-
if (typeof callback !== 'function') {
|
|
59
|
-
throw strings.errors.registry.CONFIGURATION_ONREQUEST_MUST_BE_FUNCTION;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
if (!subscriptions[eventName]) {
|
|
63
|
-
subscriptions[eventName] = [];
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
subscriptions[eventName].push(callback);
|
|
67
|
-
},
|
|
68
|
-
|
|
69
|
-
off(eventName: string, callback: Subscription): void {
|
|
70
|
-
if (typeof callback !== 'function') {
|
|
71
|
-
throw strings.errors.registry.CONFIGURATION_OFFREQUEST_MUST_BE_FUNCTION;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
if (subscriptions[eventName]) {
|
|
75
|
-
subscriptions[eventName] = subscriptions[eventName].filter(
|
|
76
|
-
sub => sub !== callback
|
|
77
|
-
);
|
|
78
|
-
}
|
|
79
|
-
},
|
|
80
|
-
|
|
81
|
-
reset(): void {
|
|
82
|
-
subscriptions = {};
|
|
83
|
-
}
|
|
84
|
-
};
|
|
85
|
-
|
|
86
|
-
export default eventsHandler;
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import path from 'path';
|
|
2
|
-
import targz from 'targz';
|
|
3
|
-
import { promisify } from 'util';
|
|
4
|
-
|
|
5
|
-
import getPackageJsonFromTempDir from './get-package-json-from-temp-dir';
|
|
6
|
-
import { Component } from '../../types';
|
|
7
|
-
|
|
8
|
-
export default async function extractPackage(
|
|
9
|
-
files:
|
|
10
|
-
| Express.Multer.File[]
|
|
11
|
-
| {
|
|
12
|
-
[fieldname: string]: Express.Multer.File[];
|
|
13
|
-
},
|
|
14
|
-
tarExtractMode: number
|
|
15
|
-
): Promise<{
|
|
16
|
-
outputFolder: string;
|
|
17
|
-
packageJson: Component;
|
|
18
|
-
}> {
|
|
19
|
-
const packageFile = (files as Express.Multer.File[])[0];
|
|
20
|
-
const packagePath = path.resolve(packageFile.path);
|
|
21
|
-
const packageUntarOutput = path.resolve(
|
|
22
|
-
packageFile.path,
|
|
23
|
-
'..',
|
|
24
|
-
packageFile.filename.replace('.tar.gz', '')
|
|
25
|
-
);
|
|
26
|
-
const packageOutput = path.resolve(packageUntarOutput, '_package');
|
|
27
|
-
|
|
28
|
-
const decompress = promisify(targz.decompress);
|
|
29
|
-
|
|
30
|
-
await decompress({
|
|
31
|
-
src: packagePath,
|
|
32
|
-
dest: packageUntarOutput,
|
|
33
|
-
tar: {
|
|
34
|
-
dmode: tarExtractMode,
|
|
35
|
-
fmode: tarExtractMode
|
|
36
|
-
}
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
const packageJson = await getPackageJsonFromTempDir(packageOutput);
|
|
40
|
-
|
|
41
|
-
return {
|
|
42
|
-
outputFolder: packageOutput,
|
|
43
|
-
packageJson
|
|
44
|
-
};
|
|
45
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import fs from 'fs-extra';
|
|
2
|
-
import path from 'path';
|
|
3
|
-
import { Component } from '../../types';
|
|
4
|
-
|
|
5
|
-
export default function getPackageJsonFromTempDir(
|
|
6
|
-
tempDirPath: string
|
|
7
|
-
): Promise<Component> {
|
|
8
|
-
return fs.readJson(path.join(tempDirPath, 'package.json'));
|
|
9
|
-
}
|