oc 0.50.57 → 0.50.58
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.turbo/turbo-build.log +4 -4
- package/.turbo/turbo-test-silent.log +8 -8
- package/CHANGELOG.md +12 -0
- package/dist/cli/facade/dev.d.ts +2 -140
- package/dist/components/oc-client/_package/package.json +4 -4
- package/dist/components/oc-client/_package/server.js +1 -1
- package/dist/components/oc-client/package.json +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/registry/domain/extract-package.d.ts +3 -2
- package/dist/registry/domain/http-server/express-adapter.d.ts +3 -0
- package/dist/registry/domain/http-server/express-adapter.js +196 -0
- package/dist/registry/domain/http-server/types.d.ts +108 -0
- package/dist/registry/domain/http-server/types.js +2 -0
- package/dist/registry/domain/options-sanitiser.d.ts +3 -2
- package/dist/registry/domain/options-sanitiser.js +13 -0
- package/dist/registry/domain/server-adapter.d.ts +4 -0
- package/dist/registry/domain/server-adapter.js +20 -0
- package/dist/registry/domain/validators/uploaded-package.d.ts +5 -4
- package/dist/registry/index.d.ts +10 -68
- package/dist/registry/index.js +14 -16
- package/dist/registry/middleware/base-url-handler.d.ts +3 -2
- package/dist/registry/middleware/base-url-handler.js +3 -4
- package/dist/registry/middleware/compression.d.ts +2 -2
- package/dist/registry/middleware/compression.js +1 -1
- package/dist/registry/middleware/cors.d.ts +3 -2
- package/dist/registry/middleware/cors.js +7 -8
- package/dist/registry/middleware/discovery-handler.d.ts +3 -2
- package/dist/registry/middleware/discovery-handler.js +3 -4
- package/dist/registry/middleware/index.d.ts +2 -2
- package/dist/registry/middleware/index.js +39 -36
- package/dist/registry/router.d.ts +2 -2
- package/dist/registry/router.js +33 -27
- package/dist/registry/routes/component-info.d.ts +2 -2
- package/dist/registry/routes/component-info.js +1 -1
- package/dist/registry/routes/component-preview.d.ts +2 -2
- package/dist/registry/routes/component.d.ts +2 -2
- package/dist/registry/routes/component.js +3 -5
- package/dist/registry/routes/components.d.ts +2 -2
- package/dist/registry/routes/components.js +3 -1
- package/dist/registry/routes/dependencies.d.ts +2 -2
- package/dist/registry/routes/helpers/get-component-fallback.d.ts +3 -3
- package/dist/registry/routes/helpers/get-component.d.ts +1 -1
- package/dist/registry/routes/history.d.ts +2 -2
- package/dist/registry/routes/history.js +1 -1
- package/dist/registry/routes/index.d.ts +2 -2
- package/dist/registry/routes/plugins.d.ts +2 -2
- package/dist/registry/routes/publish.d.ts +2 -2
- package/dist/registry/routes/static-redirector.d.ts +3 -2
- package/dist/registry/routes/static-redirector.js +8 -12
- package/dist/registry/routes/validate.d.ts +2 -2
- package/dist/types.d.ts +9 -1
- package/package.json +7 -7
- package/dist/registry/middleware/file-uploads.d.ts +0 -2
- package/dist/registry/middleware/file-uploads.js +0 -23
- package/dist/registry/middleware/request-handler.d.ts +0 -2
- package/dist/registry/middleware/request-handler.js +0 -30
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import type http from 'node:http';
|
|
2
|
+
import type { IncomingHttpHeaders } from 'node:http';
|
|
3
|
+
import type express from 'express';
|
|
4
|
+
import type { Config } from '../../../types';
|
|
5
|
+
export interface CookieOptions {
|
|
6
|
+
domain?: string;
|
|
7
|
+
encode?: (value: string) => string;
|
|
8
|
+
expires?: Date;
|
|
9
|
+
httpOnly?: boolean;
|
|
10
|
+
maxAge?: number;
|
|
11
|
+
partitioned?: boolean;
|
|
12
|
+
path?: string;
|
|
13
|
+
priority?: 'low' | 'medium' | 'high';
|
|
14
|
+
sameSite?: boolean | 'lax' | 'strict' | 'none';
|
|
15
|
+
secure?: boolean;
|
|
16
|
+
signed?: boolean;
|
|
17
|
+
}
|
|
18
|
+
export type Method = 'get' | 'post' | 'put' | 'patch' | 'head' | 'delete';
|
|
19
|
+
export interface UploadedFile {
|
|
20
|
+
fieldname: string;
|
|
21
|
+
originalname: string;
|
|
22
|
+
encoding: string;
|
|
23
|
+
mimetype: string;
|
|
24
|
+
size: number;
|
|
25
|
+
destination: string;
|
|
26
|
+
filename: string;
|
|
27
|
+
path: string;
|
|
28
|
+
buffer?: Buffer;
|
|
29
|
+
stream?: NodeJS.ReadableStream;
|
|
30
|
+
truncated?: boolean;
|
|
31
|
+
}
|
|
32
|
+
export interface OcRequest {
|
|
33
|
+
method: string;
|
|
34
|
+
url: string;
|
|
35
|
+
path: string;
|
|
36
|
+
originalUrl: string;
|
|
37
|
+
protocol: string;
|
|
38
|
+
secure: boolean;
|
|
39
|
+
ip: string;
|
|
40
|
+
headers: IncomingHttpHeaders;
|
|
41
|
+
params: Record<string, string>;
|
|
42
|
+
query: Record<string, unknown>;
|
|
43
|
+
body: any;
|
|
44
|
+
cookies: Record<string, string>;
|
|
45
|
+
files?: UploadedFile[] | Record<string, UploadedFile[]>;
|
|
46
|
+
user?: string;
|
|
47
|
+
routeId: string;
|
|
48
|
+
get(header: string): string | undefined;
|
|
49
|
+
raw: http.IncomingMessage;
|
|
50
|
+
}
|
|
51
|
+
export interface OcResponse {
|
|
52
|
+
conf: Config;
|
|
53
|
+
errorCode?: string;
|
|
54
|
+
errorDetails?: string;
|
|
55
|
+
statusCode: number;
|
|
56
|
+
status(code: number): this;
|
|
57
|
+
json(body: unknown): void;
|
|
58
|
+
send(body: unknown): void;
|
|
59
|
+
set(field: string | Record<string, string>, value?: string): this;
|
|
60
|
+
header(name: string, value: string): this;
|
|
61
|
+
setHeader(name: string, value: string): this;
|
|
62
|
+
removeHeader(name: string): this;
|
|
63
|
+
type(mime: string): this;
|
|
64
|
+
cookie(name: string, value: string, opts?: CookieOptions): this;
|
|
65
|
+
redirect(url: string): void;
|
|
66
|
+
end(chunk?: unknown): void;
|
|
67
|
+
stream(readable: NodeJS.ReadableStream): void;
|
|
68
|
+
raw: http.ServerResponse;
|
|
69
|
+
}
|
|
70
|
+
export type OcHandler = (req: OcRequest, res: OcResponse) => void | Promise<void>;
|
|
71
|
+
export type ExpressMiddleware = (req: any, res: any, next: (err?: unknown) => void) => void;
|
|
72
|
+
export type HttpServerAdapterFactory<TOptions = unknown, TNative = unknown> = {
|
|
73
|
+
(options?: unknown): HttpServerAdapter<TNative>;
|
|
74
|
+
readonly __serverAdapterOptions?: TOptions;
|
|
75
|
+
};
|
|
76
|
+
export type HttpServerAdapterOptions<TAdapter> = TAdapter extends {
|
|
77
|
+
readonly __serverAdapterOptions?: infer TOptions;
|
|
78
|
+
} ? TOptions : TAdapter extends (options?: infer TOptions) => HttpServerAdapter ? TOptions : unknown;
|
|
79
|
+
export type NativeApp<TAdapter> = TAdapter extends (...args: any[]) => HttpServerAdapter<infer TNative> ? unknown extends TNative ? express.Express : TNative : TAdapter extends HttpServerAdapter<infer TNative> ? unknown extends TNative ? express.Express : TNative : express.Express;
|
|
80
|
+
export interface HttpServerAdapter<TNative = unknown> {
|
|
81
|
+
name: string;
|
|
82
|
+
enableBodyParser(opts: {
|
|
83
|
+
limit?: number | string;
|
|
84
|
+
}): void;
|
|
85
|
+
enableCookies(): void;
|
|
86
|
+
enableFileUploads(opts: {
|
|
87
|
+
tempDir: string;
|
|
88
|
+
filename: (originalName: string) => string;
|
|
89
|
+
}): void;
|
|
90
|
+
enableRequestTiming(onDone: (req: OcRequest, res: OcResponse, ms: number) => void): void;
|
|
91
|
+
enableLogging(opts: {
|
|
92
|
+
skip: (req: OcRequest, res: OcResponse) => boolean;
|
|
93
|
+
}): void;
|
|
94
|
+
enableErrorHandler(): void;
|
|
95
|
+
use(handler: OcHandler): void;
|
|
96
|
+
route(method: Method, path: string, id: string, handlers: OcHandler[]): void;
|
|
97
|
+
fromConnect(handler: ExpressMiddleware): OcHandler;
|
|
98
|
+
listen(opts: {
|
|
99
|
+
port: number | string;
|
|
100
|
+
timeout: number;
|
|
101
|
+
keepAliveTimeout?: number;
|
|
102
|
+
}, cb: (err?: Error) => void): void;
|
|
103
|
+
onServerError(cb: (err: Error) => void): void;
|
|
104
|
+
close(cb: (err?: Error) => void): void;
|
|
105
|
+
isListening(): boolean;
|
|
106
|
+
native(): TNative;
|
|
107
|
+
httpServer(): http.Server;
|
|
108
|
+
}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { compileSync } from 'oc-client-browser';
|
|
2
2
|
import type { Config } from '../../types';
|
|
3
|
+
import type { HttpServerAdapterFactory } from './http-server/types';
|
|
3
4
|
type CompileOptions = Omit<Exclude<Parameters<typeof compileSync>[0], undefined>, 'templates'>;
|
|
4
|
-
export interface RegistryOptions<T = any> extends Partial<Omit<Config<T>, 'beforePublish' | 'discovery' | 'plugins'>> {
|
|
5
|
+
export interface RegistryOptions<T = any, TServerAdapter extends HttpServerAdapterFactory = HttpServerAdapterFactory> extends Partial<Omit<Config<T, TServerAdapter>, 'beforePublish' | 'discovery' | 'plugins'>> {
|
|
5
6
|
/**
|
|
6
7
|
* Configuration object to enable/disable the HTML discovery page and the API
|
|
7
8
|
*
|
|
@@ -28,5 +29,5 @@ export interface RegistryOptions<T = any> extends Partial<Omit<Config<T>, 'befor
|
|
|
28
29
|
*/
|
|
29
30
|
compileClient?: boolean | CompileOptions;
|
|
30
31
|
}
|
|
31
|
-
export default function optionsSanitiser(input: RegistryOptions): Config;
|
|
32
|
+
export default function optionsSanitiser<T = any, TServerAdapter extends HttpServerAdapterFactory = HttpServerAdapterFactory>(input: RegistryOptions<T, TServerAdapter>): Config;
|
|
32
33
|
export {};
|
|
@@ -41,6 +41,7 @@ const node_zlib_1 = __importDefault(require("node:zlib"));
|
|
|
41
41
|
const oc_client_browser_1 = require("oc-client-browser");
|
|
42
42
|
const settings_1 = __importDefault(require("../../resources/settings"));
|
|
43
43
|
const auth = __importStar(require("./authentication"));
|
|
44
|
+
const express_adapter_1 = __importDefault(require("./http-server/express-adapter"));
|
|
44
45
|
const DEFAULT_NODE_KEEPALIVE_MS = 5000;
|
|
45
46
|
function optionsSanitiser(input) {
|
|
46
47
|
const options = { ...input };
|
|
@@ -165,6 +166,18 @@ function optionsSanitiser(input) {
|
|
|
165
166
|
options.timeout = options.timeout || 1000 * 60 * 2;
|
|
166
167
|
options.keepAliveTimeout =
|
|
167
168
|
options.keepAliveTimeout || DEFAULT_NODE_KEEPALIVE_MS;
|
|
169
|
+
if (!options.server) {
|
|
170
|
+
options.server = {
|
|
171
|
+
adapter: express_adapter_1.default,
|
|
172
|
+
options: { port: options.port }
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
if (!options.server.adapter) {
|
|
176
|
+
options.server.adapter = express_adapter_1.default;
|
|
177
|
+
}
|
|
178
|
+
if (typeof options.server.options === 'undefined') {
|
|
179
|
+
options.server.options = { port: options.port };
|
|
180
|
+
}
|
|
168
181
|
if (options.s3) {
|
|
169
182
|
options.storage = {
|
|
170
183
|
adapter: require('oc-s3-storage-adapter'),
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { HttpServerAdapter } from './http-server/types';
|
|
2
|
+
type HttpServerAdapterFactory<T = unknown> = (options?: T) => HttpServerAdapter;
|
|
3
|
+
export default function getHttpServerAdapter<T = unknown>(adapter: HttpServerAdapter | HttpServerAdapterFactory<T>, options?: T): HttpServerAdapter;
|
|
4
|
+
export {};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.default = getHttpServerAdapter;
|
|
4
|
+
function isHttpServerAdapter(adapter) {
|
|
5
|
+
return (!!adapter &&
|
|
6
|
+
typeof adapter === 'object' &&
|
|
7
|
+
typeof adapter.native === 'function' &&
|
|
8
|
+
typeof adapter.listen === 'function' &&
|
|
9
|
+
typeof adapter.httpServer === 'function');
|
|
10
|
+
}
|
|
11
|
+
function getHttpServerAdapter(adapter, options) {
|
|
12
|
+
if (isHttpServerAdapter(adapter)) {
|
|
13
|
+
return adapter;
|
|
14
|
+
}
|
|
15
|
+
const instance = adapter(options);
|
|
16
|
+
if (!isHttpServerAdapter(instance)) {
|
|
17
|
+
throw new Error('Invalid HTTP server adapter');
|
|
18
|
+
}
|
|
19
|
+
return instance;
|
|
20
|
+
}
|
|
@@ -1,13 +1,14 @@
|
|
|
1
|
+
import type { UploadedFile } from '../http-server/types';
|
|
1
2
|
type ValidationResponse = {
|
|
2
3
|
isValid: true;
|
|
3
|
-
files:
|
|
4
|
-
[fieldname: string]:
|
|
4
|
+
files: UploadedFile[] | {
|
|
5
|
+
[fieldname: string]: UploadedFile[];
|
|
5
6
|
};
|
|
6
7
|
} | {
|
|
7
8
|
isValid: false;
|
|
8
9
|
message: string;
|
|
9
10
|
};
|
|
10
|
-
export default function uploadedPackage(input?:
|
|
11
|
-
[fieldname: string]:
|
|
11
|
+
export default function uploadedPackage(input?: UploadedFile[] | {
|
|
12
|
+
[fieldname: string]: UploadedFile[];
|
|
12
13
|
}): ValidationResponse;
|
|
13
14
|
export {};
|
package/dist/registry/index.d.ts
CHANGED
|
@@ -1,75 +1,17 @@
|
|
|
1
|
-
import http from 'node:http';
|
|
2
|
-
import express from 'express';
|
|
1
|
+
import type http from 'node:http';
|
|
3
2
|
import type { Plugin } from '../types';
|
|
3
|
+
import eventsHandler from './domain/events-handler';
|
|
4
|
+
import type { HttpServerAdapterFactory, NativeApp } from './domain/http-server/types';
|
|
4
5
|
import { RegistryOptions } from './domain/options-sanitiser';
|
|
5
6
|
export { RegistryOptions };
|
|
6
|
-
export
|
|
7
|
+
export interface RegistryType<TApp = NativeApp<HttpServerAdapterFactory>> {
|
|
7
8
|
close: (callback: (err?: Error | undefined | string) => void) => void;
|
|
8
|
-
on:
|
|
9
|
-
|
|
10
|
-
code: string;
|
|
11
|
-
message: string;
|
|
12
|
-
};
|
|
13
|
-
start: unknown;
|
|
14
|
-
'cache-poll': number;
|
|
15
|
-
request: import("./domain/events-handler").RequestData;
|
|
16
|
-
'component-retrieved': {
|
|
17
|
-
headers: http.IncomingHttpHeaders;
|
|
18
|
-
name: string;
|
|
19
|
-
parameters: http.IncomingHttpHeaders;
|
|
20
|
-
requestVersion: string;
|
|
21
|
-
duration: number;
|
|
22
|
-
};
|
|
23
|
-
'data-provider-error': {
|
|
24
|
-
name: string;
|
|
25
|
-
version: string;
|
|
26
|
-
parameters: Record<string, string | boolean | number>;
|
|
27
|
-
requestVersion: string;
|
|
28
|
-
status: number;
|
|
29
|
-
error: Error;
|
|
30
|
-
};
|
|
31
|
-
'component-published': {
|
|
32
|
-
componentName: string;
|
|
33
|
-
componentVersion: string;
|
|
34
|
-
packageJson: import("../types").Component;
|
|
35
|
-
componentFolder: string;
|
|
36
|
-
user?: string;
|
|
37
|
-
};
|
|
38
|
-
}>(eventName: T_1, listener: (data: {
|
|
39
|
-
error: {
|
|
40
|
-
code: string;
|
|
41
|
-
message: string;
|
|
42
|
-
};
|
|
43
|
-
start: unknown;
|
|
44
|
-
'cache-poll': number;
|
|
45
|
-
request: import("./domain/events-handler").RequestData;
|
|
46
|
-
'component-retrieved': {
|
|
47
|
-
headers: http.IncomingHttpHeaders;
|
|
48
|
-
name: string;
|
|
49
|
-
parameters: http.IncomingHttpHeaders;
|
|
50
|
-
requestVersion: string;
|
|
51
|
-
duration: number;
|
|
52
|
-
};
|
|
53
|
-
'data-provider-error': {
|
|
54
|
-
name: string;
|
|
55
|
-
version: string;
|
|
56
|
-
parameters: Record<string, string | boolean | number>;
|
|
57
|
-
requestVersion: string;
|
|
58
|
-
status: number;
|
|
59
|
-
error: Error;
|
|
60
|
-
};
|
|
61
|
-
'component-published': {
|
|
62
|
-
componentName: string;
|
|
63
|
-
componentVersion: string;
|
|
64
|
-
packageJson: import("../types").Component;
|
|
65
|
-
componentFolder: string;
|
|
66
|
-
user?: string;
|
|
67
|
-
};
|
|
68
|
-
}[T_1]) => void) => void;
|
|
69
|
-
register: <T_1 = any>(plugin: Plugin<T_1>, callback?: (...args: any[]) => void) => void;
|
|
9
|
+
on: typeof eventsHandler.on;
|
|
10
|
+
register: <T = any>(plugin: Plugin<T>, callback?: (...args: any[]) => void) => void;
|
|
70
11
|
start: (callback: (err: unknown, data?: {
|
|
71
|
-
app:
|
|
12
|
+
app: TApp;
|
|
72
13
|
server: http.Server;
|
|
73
14
|
}) => void) => Promise<void>;
|
|
74
|
-
app:
|
|
75
|
-
}
|
|
15
|
+
app: TApp;
|
|
16
|
+
}
|
|
17
|
+
export default function registry<T = any, TServerAdapter extends HttpServerAdapterFactory = HttpServerAdapterFactory, TApp = NativeApp<TServerAdapter>>(inputOptions: RegistryOptions<T, TServerAdapter>): RegistryType<TApp>;
|
package/dist/registry/index.js
CHANGED
|
@@ -37,14 +37,13 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
37
37
|
};
|
|
38
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
39
|
exports.default = registry;
|
|
40
|
-
const node_http_1 = __importDefault(require("node:http"));
|
|
41
40
|
const safe_1 = __importDefault(require("colors/safe"));
|
|
42
|
-
const express_1 = __importDefault(require("express"));
|
|
43
41
|
const app_start_1 = __importDefault(require("./app-start"));
|
|
44
42
|
const events_handler_1 = __importDefault(require("./domain/events-handler"));
|
|
45
43
|
const options_sanitiser_1 = __importDefault(require("./domain/options-sanitiser"));
|
|
46
44
|
const pluginsInitialiser = __importStar(require("./domain/plugins-initialiser"));
|
|
47
45
|
const repository_1 = __importDefault(require("./domain/repository"));
|
|
46
|
+
const server_adapter_1 = __importDefault(require("./domain/server-adapter"));
|
|
48
47
|
const validator = __importStar(require("./domain/validators"));
|
|
49
48
|
const middleware = __importStar(require("./middleware"));
|
|
50
49
|
const router_1 = require("./router");
|
|
@@ -55,13 +54,13 @@ function registry(inputOptions) {
|
|
|
55
54
|
}
|
|
56
55
|
const options = (0, options_sanitiser_1.default)(inputOptions);
|
|
57
56
|
const plugins = [];
|
|
58
|
-
const
|
|
59
|
-
|
|
57
|
+
const adapter = middleware.bind((0, server_adapter_1.default)(options.server.adapter, options.server.options), options);
|
|
58
|
+
const app = adapter.native();
|
|
60
59
|
const repository = (0, repository_1.default)(options);
|
|
61
60
|
const close = (callback) => {
|
|
62
61
|
const closeMetadataStore = () => Promise.resolve(repository.close?.()).catch(() => undefined);
|
|
63
|
-
if (
|
|
64
|
-
|
|
62
|
+
if (adapter.isListening()) {
|
|
63
|
+
adapter.close((err) => {
|
|
65
64
|
void closeMetadataStore().finally(() => callback(err));
|
|
66
65
|
});
|
|
67
66
|
return;
|
|
@@ -75,30 +74,29 @@ function registry(inputOptions) {
|
|
|
75
74
|
const ok = (msg) => console.log(safe_1.default.green(msg));
|
|
76
75
|
try {
|
|
77
76
|
options.plugins = await pluginsInitialiser.init(plugins);
|
|
78
|
-
(0, router_1.create)(
|
|
77
|
+
(0, router_1.create)(adapter, options, repository);
|
|
79
78
|
const componentsInfo = await repository.init();
|
|
80
79
|
await (0, app_start_1.default)(repository, options);
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
}
|
|
86
|
-
server.listen(options.port, (err) => {
|
|
80
|
+
adapter.listen({
|
|
81
|
+
port: options.port,
|
|
82
|
+
timeout: options.timeout,
|
|
83
|
+
keepAliveTimeout: options.keepAliveTimeout
|
|
84
|
+
}, (err) => {
|
|
87
85
|
if (err) {
|
|
88
86
|
return callback(err);
|
|
89
87
|
}
|
|
90
88
|
events_handler_1.default.fire('start', {});
|
|
91
89
|
if (options.verbosity) {
|
|
92
|
-
ok(`Registry started at port http://localhost:${
|
|
90
|
+
ok(`Registry started at port http://localhost:${options.port}${options.prefix}`);
|
|
93
91
|
if (componentsInfo) {
|
|
94
92
|
const componentsNumber = Object.keys(componentsInfo.components).length;
|
|
95
93
|
const componentsReleases = Object.values(componentsInfo.components).reduce((acc, component) => acc + Object.keys(component).length, 0);
|
|
96
94
|
ok(`Registry serving ${componentsNumber} components for a total of ${componentsReleases} releases.`);
|
|
97
95
|
}
|
|
98
96
|
}
|
|
99
|
-
callback(null, { app, server });
|
|
97
|
+
callback(null, { app, server: adapter.httpServer() });
|
|
100
98
|
});
|
|
101
|
-
|
|
99
|
+
adapter.onServerError((error) => {
|
|
102
100
|
events_handler_1.default.fire('error', {
|
|
103
101
|
code: 'EXPRESS_ERROR',
|
|
104
102
|
message: error?.message ?? String(error)
|
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
|
|
1
|
+
import type { OcHandler } from '../domain/http-server/types';
|
|
2
|
+
declare const baseUrlHandler: OcHandler;
|
|
3
|
+
export default baseUrlHandler;
|
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
|
|
4
|
-
function baseUrlHandler(req, res, next) {
|
|
3
|
+
const baseUrlHandler = (req, res) => {
|
|
5
4
|
if (res.conf.baseUrlFunc) {
|
|
6
5
|
res.conf.baseUrl = res.conf.baseUrlFunc({
|
|
7
6
|
host: req.headers.host,
|
|
8
7
|
secure: req.secure
|
|
9
8
|
});
|
|
10
9
|
}
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
};
|
|
11
|
+
exports.default = baseUrlHandler;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { OcRequest, OcResponse } from '../domain/http-server/types';
|
|
2
2
|
export default function compress(data: {
|
|
3
3
|
uncompressed: string;
|
|
4
4
|
brotli: Buffer;
|
|
5
5
|
gzip: Buffer;
|
|
6
|
-
}, req:
|
|
6
|
+
}, req: OcRequest, res: OcResponse): void;
|
|
@@ -9,7 +9,7 @@ function compress(data, req, res) {
|
|
|
9
9
|
res.send(data.uncompressed);
|
|
10
10
|
return;
|
|
11
11
|
}
|
|
12
|
-
res.
|
|
12
|
+
res.set('Content-Encoding', encoding);
|
|
13
13
|
const compressed = encoding === 'br' ? data.brotli : data.gzip;
|
|
14
14
|
res.send(compressed);
|
|
15
15
|
}
|
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
|
|
1
|
+
import type { OcHandler } from '../domain/http-server/types';
|
|
2
|
+
declare const cors: OcHandler;
|
|
3
|
+
export default cors;
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
|
|
4
|
-
function cors(_req, res, next) {
|
|
3
|
+
const cors = (_req, res) => {
|
|
5
4
|
res.removeHeader('X-Powered-By');
|
|
6
|
-
res.
|
|
7
|
-
res.
|
|
8
|
-
res.
|
|
9
|
-
res.
|
|
10
|
-
|
|
11
|
-
|
|
5
|
+
res.set('Access-Control-Allow-Credentials', 'true');
|
|
6
|
+
res.set('Access-Control-Allow-Origin', '*');
|
|
7
|
+
res.set('Access-Control-Allow-Headers', 'Origin, X-Requested-With, Content-Type, Accept, traceparent');
|
|
8
|
+
res.set('Access-Control-Allow-Methods', 'GET, OPTIONS, PUT, POST');
|
|
9
|
+
};
|
|
10
|
+
exports.default = cors;
|
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
|
|
1
|
+
import type { OcHandler } from '../domain/http-server/types';
|
|
2
|
+
declare const discoveryHandler: OcHandler;
|
|
3
|
+
export default discoveryHandler;
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
|
|
4
|
-
function discoveryHandler(req, res, next) {
|
|
3
|
+
const discoveryHandler = (req, res) => {
|
|
5
4
|
res.conf.discoveryFunc =
|
|
6
5
|
res.conf.discoveryFunc ||
|
|
7
6
|
(typeof res.conf.discovery === 'function' ? res.conf.discovery : undefined);
|
|
@@ -11,5 +10,5 @@ function discoveryHandler(req, res, next) {
|
|
|
11
10
|
secure: req.secure
|
|
12
11
|
});
|
|
13
12
|
}
|
|
14
|
-
|
|
15
|
-
|
|
13
|
+
};
|
|
14
|
+
exports.default = discoveryHandler;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { type Express } from 'express';
|
|
2
1
|
import type { Config } from '../../types';
|
|
3
|
-
|
|
2
|
+
import type { HttpServerAdapter } from '../domain/http-server/types';
|
|
3
|
+
export declare const bind: (adapter: HttpServerAdapter, options: Config) => HttpServerAdapter;
|
|
@@ -4,54 +4,57 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.bind = void 0;
|
|
7
|
-
const
|
|
8
|
-
const errorhandler_1 = __importDefault(require("errorhandler"));
|
|
9
|
-
const express_1 = __importDefault(require("express"));
|
|
10
|
-
const morgan_1 = __importDefault(require("morgan"));
|
|
7
|
+
const events_handler_1 = __importDefault(require("../domain/events-handler"));
|
|
11
8
|
const base_url_handler_1 = __importDefault(require("./base-url-handler"));
|
|
12
9
|
const cors_1 = __importDefault(require("./cors"));
|
|
13
10
|
const discovery_handler_1 = __importDefault(require("./discovery-handler"));
|
|
14
|
-
const
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
inflate: true
|
|
18
|
-
};
|
|
19
|
-
const bodyParserUrlEncodedArgument = {
|
|
20
|
-
extended: true
|
|
21
|
-
};
|
|
22
|
-
const bind = (app, options) => {
|
|
23
|
-
app.set('port', options.port);
|
|
24
|
-
app.set('json spaces', 0);
|
|
25
|
-
app.set('etag', 'strong');
|
|
26
|
-
app.use((_req, res, next) => {
|
|
11
|
+
const normaliseFileName = (x) => x.replace('.tar.gz', '').replace(/\W+/g, '-').toLowerCase();
|
|
12
|
+
const bind = (adapter, options) => {
|
|
13
|
+
adapter.use((_req, res) => {
|
|
27
14
|
res.conf = options;
|
|
28
|
-
next();
|
|
29
15
|
});
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
16
|
+
adapter.enableRequestTiming((req, res, time) => {
|
|
17
|
+
const data = {
|
|
18
|
+
body: req.body,
|
|
19
|
+
duration: time,
|
|
20
|
+
headers: req.headers,
|
|
21
|
+
method: req.method,
|
|
22
|
+
path: req.path,
|
|
23
|
+
relativeUrl: req.originalUrl,
|
|
24
|
+
query: req.query,
|
|
25
|
+
url: req.protocol + '://' + req.get('host') + req.originalUrl,
|
|
26
|
+
statusCode: res.statusCode
|
|
27
|
+
};
|
|
28
|
+
if (res.errorDetails) {
|
|
29
|
+
data.errorDetails = res.errorDetails;
|
|
30
|
+
}
|
|
31
|
+
if (res.errorCode) {
|
|
32
|
+
data.errorCode = res.errorCode;
|
|
33
|
+
}
|
|
34
|
+
events_handler_1.default.fire('request', data);
|
|
35
|
+
});
|
|
36
|
+
adapter.enableCookies();
|
|
37
|
+
adapter.enableBodyParser({ limit: options.postRequestPayloadSize });
|
|
38
|
+
adapter.use(cors_1.default);
|
|
39
|
+
if (!options.local) {
|
|
40
|
+
adapter.enableFileUploads({
|
|
41
|
+
tempDir: options.tempDir,
|
|
42
|
+
filename: (originalName) => `${normaliseFileName(originalName)}-${Date.now()}.tar.gz`
|
|
43
|
+
});
|
|
37
44
|
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
app.use(cors_1.default);
|
|
41
|
-
app.use(file_uploads_1.default);
|
|
42
|
-
app.use(base_url_handler_1.default);
|
|
43
|
-
app.use(discovery_handler_1.default);
|
|
45
|
+
adapter.use(base_url_handler_1.default);
|
|
46
|
+
adapter.use(discovery_handler_1.default);
|
|
44
47
|
if (options.verbosity) {
|
|
45
|
-
|
|
48
|
+
adapter.enableLogging({
|
|
46
49
|
skip: (req, res) => {
|
|
47
50
|
// Hide logging development console calls
|
|
48
|
-
return req.url.startsWith(`${res.conf
|
|
51
|
+
return req.url.startsWith(`${res.conf?.prefix ?? ''}~actions/$$__oc__server___console__$$`);
|
|
49
52
|
}
|
|
50
|
-
})
|
|
53
|
+
});
|
|
51
54
|
}
|
|
52
55
|
if (options.local) {
|
|
53
|
-
|
|
56
|
+
adapter.enableErrorHandler();
|
|
54
57
|
}
|
|
55
|
-
return
|
|
58
|
+
return adapter;
|
|
56
59
|
};
|
|
57
60
|
exports.bind = bind;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Express } from 'express';
|
|
2
1
|
import type { Repository } from '../registry/domain/repository';
|
|
3
2
|
import type { Config } from '../types';
|
|
4
|
-
|
|
3
|
+
import type { HttpServerAdapter } from './domain/http-server/types';
|
|
4
|
+
export declare function create(adapter: HttpServerAdapter, conf: Config, repository: Repository): void;
|