@redocly/cli 1.34.4 → 2.0.0-next.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +34 -3
- package/bin/cli.js +1 -1
- package/lib/auth/device-flow.d.ts +1 -0
- package/lib/auth/device-flow.d.ts.map +1 -0
- package/lib/auth/device-flow.js +15 -17
- package/lib/auth/device-flow.js.map +1 -0
- package/lib/auth/oauth-client.d.ts +1 -0
- package/lib/auth/oauth-client.d.ts.map +1 -0
- package/lib/auth/oauth-client.js +21 -23
- package/lib/auth/oauth-client.js.map +1 -0
- package/lib/commands/auth.d.ts +3 -5
- package/lib/commands/auth.d.ts.map +1 -0
- package/lib/commands/auth.js +19 -44
- package/lib/commands/auth.js.map +1 -0
- package/lib/commands/build-docs/index.d.ts +4 -3
- package/lib/commands/build-docs/index.d.ts.map +1 -0
- package/lib/commands/build-docs/index.js +23 -24
- package/lib/commands/build-docs/index.js.map +1 -0
- package/lib/commands/build-docs/types.d.ts +2 -1
- package/lib/commands/build-docs/types.d.ts.map +1 -0
- package/lib/commands/build-docs/types.js +2 -2
- package/lib/commands/build-docs/types.js.map +1 -0
- package/lib/commands/build-docs/utils.d.ts +3 -2
- package/lib/commands/build-docs/utils.d.ts.map +1 -0
- package/lib/commands/build-docs/utils.js +35 -37
- package/lib/commands/build-docs/utils.js.map +1 -0
- package/lib/commands/bundle.d.ts +6 -3
- package/lib/commands/bundle.d.ts.map +1 -0
- package/lib/commands/bundle.js +34 -38
- package/lib/commands/bundle.js.map +1 -0
- package/lib/commands/eject.d.ts +3 -2
- package/lib/commands/eject.d.ts.map +1 -0
- package/lib/commands/eject.js +11 -13
- package/lib/commands/eject.js.map +1 -0
- package/lib/commands/join.d.ts +4 -3
- package/lib/commands/join.d.ts.map +1 -0
- package/lib/commands/join.js +79 -81
- package/lib/commands/join.js.map +1 -0
- package/lib/commands/lint.d.ts +8 -6
- package/lib/commands/lint.d.ts.map +1 -0
- package/lib/commands/lint.js +53 -62
- package/lib/commands/lint.js.map +1 -0
- package/lib/commands/preview-project/constants.d.ts +2 -1
- package/lib/commands/preview-project/constants.d.ts.map +1 -0
- package/lib/commands/preview-project/constants.js +4 -6
- package/lib/commands/preview-project/constants.js.map +1 -0
- package/lib/commands/preview-project/index.d.ts +3 -2
- package/lib/commands/preview-project/index.d.ts.map +1 -0
- package/lib/commands/preview-project/index.js +21 -23
- package/lib/commands/preview-project/index.js.map +1 -0
- package/lib/commands/preview-project/types.d.ts +3 -2
- package/lib/commands/preview-project/types.d.ts.map +1 -0
- package/lib/commands/preview-project/types.js +2 -2
- package/lib/commands/preview-project/types.js.map +1 -0
- package/lib/commands/split/index.d.ts +4 -3
- package/lib/commands/split/index.d.ts.map +1 -0
- package/lib/commands/split/index.js +53 -57
- package/lib/commands/split/index.js.map +1 -0
- package/lib/commands/split/types.d.ts +2 -2
- package/lib/commands/split/types.d.ts.map +1 -0
- package/lib/commands/split/types.js +11 -13
- package/lib/commands/split/types.js.map +1 -0
- package/lib/commands/stats.d.ts +3 -2
- package/lib/commands/stats.d.ts.map +1 -0
- package/lib/commands/stats.js +21 -24
- package/lib/commands/stats.js.map +1 -0
- package/lib/commands/translations.d.ts +3 -2
- package/lib/commands/translations.d.ts.map +1 -0
- package/lib/commands/translations.js +11 -13
- package/lib/commands/translations.js.map +1 -0
- package/lib/index.d.ts +2 -1
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +109 -239
- package/lib/index.js.map +1 -0
- package/lib/otel.d.ts +2 -1
- package/lib/otel.d.ts.map +1 -0
- package/lib/otel.js +22 -23
- package/lib/otel.js.map +1 -0
- package/lib/reunite/api/api-client.d.ts +4 -3
- package/lib/reunite/api/api-client.d.ts.map +1 -0
- package/lib/reunite/api/api-client.js +14 -20
- package/lib/reunite/api/api-client.js.map +1 -0
- package/lib/reunite/api/api-keys.d.ts +2 -1
- package/lib/reunite/api/api-keys.d.ts.map +1 -0
- package/lib/reunite/api/api-keys.js +4 -20
- package/lib/reunite/api/api-keys.js.map +1 -0
- package/lib/reunite/api/domains.d.ts +5 -2
- package/lib/reunite/api/domains.d.ts.map +1 -0
- package/lib/reunite/api/domains.js +6 -15
- package/lib/reunite/api/domains.js.map +1 -0
- package/lib/reunite/api/index.d.ts +4 -3
- package/lib/reunite/api/index.d.ts.map +1 -0
- package/lib/reunite/api/index.js +4 -19
- package/lib/reunite/api/index.js.map +1 -0
- package/lib/reunite/api/types.d.ts +1 -0
- package/lib/reunite/api/types.d.ts.map +1 -0
- package/lib/reunite/api/types.js +2 -2
- package/lib/reunite/api/types.js.map +1 -0
- package/lib/reunite/commands/push-status.d.ts +6 -5
- package/lib/reunite/commands/push-status.d.ts.map +1 -0
- package/lib/reunite/commands/push-status.js +31 -37
- package/lib/reunite/commands/push-status.js.map +1 -0
- package/lib/reunite/commands/push.d.ts +6 -6
- package/lib/reunite/commands/push.d.ts.map +1 -0
- package/lib/reunite/commands/push.js +31 -40
- package/lib/reunite/commands/push.js.map +1 -0
- package/lib/reunite/commands/utils.d.ts +4 -3
- package/lib/reunite/commands/utils.d.ts.map +1 -0
- package/lib/reunite/commands/utils.js +9 -12
- package/lib/reunite/commands/utils.js.map +1 -0
- package/lib/reunite/utils.d.ts +1 -0
- package/lib/reunite/utils.d.ts.map +1 -0
- package/lib/reunite/utils.js +2 -5
- package/lib/reunite/utils.js.map +1 -0
- package/lib/types.d.ts +15 -27
- package/lib/types.d.ts.map +1 -0
- package/lib/types.js +2 -5
- package/lib/types.js.map +1 -0
- package/lib/utils/assert-node-version.d.ts +1 -0
- package/lib/utils/assert-node-version.d.ts.map +1 -0
- package/lib/utils/assert-node-version.js +8 -10
- package/lib/utils/assert-node-version.js.map +1 -0
- package/lib/utils/error.d.ts +4 -0
- package/lib/utils/error.d.ts.map +1 -0
- package/lib/utils/error.js +8 -0
- package/lib/utils/error.js.map +1 -0
- package/lib/utils/fetch-with-timeout.d.ts +1 -0
- package/lib/utils/fetch-with-timeout.d.ts.map +1 -0
- package/lib/utils/fetch-with-timeout.js +6 -8
- package/lib/utils/fetch-with-timeout.js.map +1 -0
- package/lib/utils/{getCommandNameFromArgs.d.ts → get-command-name-from-args.d.ts} +1 -0
- package/lib/utils/get-command-name-from-args.d.ts.map +1 -0
- package/lib/utils/get-command-name-from-args.js +4 -0
- package/lib/utils/get-command-name-from-args.js.map +1 -0
- package/lib/utils/js-utils.d.ts +1 -0
- package/lib/utils/js-utils.d.ts.map +1 -0
- package/lib/utils/js-utils.js +8 -12
- package/lib/utils/js-utils.js.map +1 -0
- package/lib/utils/miscellaneous.d.ts +9 -48
- package/lib/utils/miscellaneous.d.ts.map +1 -0
- package/lib/utils/miscellaneous.js +131 -269
- package/lib/utils/miscellaneous.js.map +1 -0
- package/lib/utils/package.d.ts +2 -0
- package/lib/utils/package.d.ts.map +1 -0
- package/lib/utils/package.js +4 -0
- package/lib/utils/package.js.map +1 -0
- package/lib/utils/platform.d.ts +1 -0
- package/lib/utils/platform.d.ts.map +1 -0
- package/lib/utils/platform.js +5 -9
- package/lib/utils/platform.js.map +1 -0
- package/lib/utils/proxy-agent.d.ts +3 -0
- package/lib/utils/proxy-agent.d.ts.map +1 -0
- package/lib/utils/proxy-agent.js +6 -0
- package/lib/utils/proxy-agent.js.map +1 -0
- package/lib/utils/spinner.d.ts +1 -0
- package/lib/utils/spinner.d.ts.map +1 -0
- package/lib/utils/spinner.js +8 -10
- package/lib/utils/spinner.js.map +1 -0
- package/lib/utils/telemetry.d.ts +40 -0
- package/lib/utils/telemetry.d.ts.map +1 -0
- package/lib/utils/telemetry.js +138 -0
- package/lib/utils/telemetry.js.map +1 -0
- package/lib/utils/update-version-notifier.d.ts +1 -1
- package/lib/utils/update-version-notifier.d.ts.map +1 -0
- package/lib/utils/update-version-notifier.js +35 -38
- package/lib/utils/update-version-notifier.js.map +1 -0
- package/lib/utils/validate-positive-number.d.ts +2 -0
- package/lib/utils/validate-positive-number.d.ts.map +1 -0
- package/lib/utils/validate-positive-number.js +13 -0
- package/lib/utils/validate-positive-number.js.map +1 -0
- package/lib/wrapper.d.ts +3 -3
- package/lib/wrapper.d.ts.map +1 -0
- package/lib/wrapper.js +39 -26
- package/lib/wrapper.js.map +1 -0
- package/package.json +16 -17
- package/CHANGELOG.md +0 -777
- package/lib/__mocks__/@redocly/openapi-core.d.ts +0 -99
- package/lib/__mocks__/@redocly/openapi-core.js +0 -84
- package/lib/__mocks__/documents.d.ts +0 -150
- package/lib/__mocks__/documents.js +0 -123
- package/lib/__mocks__/fs.d.ts +0 -8
- package/lib/__mocks__/fs.js +0 -9
- package/lib/__mocks__/perf_hooks.d.ts +0 -3
- package/lib/__mocks__/perf_hooks.js +0 -6
- package/lib/__mocks__/redoc.d.ts +0 -6
- package/lib/__mocks__/redoc.js +0 -5
- package/lib/__tests__/commands/build-docs.test.d.ts +0 -1
- package/lib/__tests__/commands/build-docs.test.js +0 -54
- package/lib/__tests__/commands/bundle.test.d.ts +0 -1
- package/lib/__tests__/commands/bundle.test.js +0 -235
- package/lib/__tests__/commands/join.test.d.ts +0 -1
- package/lib/__tests__/commands/join.test.js +0 -274
- package/lib/__tests__/commands/lint.test.d.ts +0 -1
- package/lib/__tests__/commands/lint.test.js +0 -149
- package/lib/__tests__/commands/push-region.test.d.ts +0 -1
- package/lib/__tests__/commands/push-region.test.js +0 -90
- package/lib/__tests__/commands/push.test.d.ts +0 -1
- package/lib/__tests__/commands/push.test.js +0 -496
- package/lib/__tests__/fetch-with-timeout.test.d.ts +0 -1
- package/lib/__tests__/fetch-with-timeout.test.js +0 -64
- package/lib/__tests__/fixtures/config.d.ts +0 -21
- package/lib/__tests__/fixtures/config.js +0 -24
- package/lib/__tests__/spinner.test.d.ts +0 -1
- package/lib/__tests__/spinner.test.js +0 -43
- package/lib/__tests__/utils.test.d.ts +0 -1
- package/lib/__tests__/utils.test.js +0 -651
- package/lib/__tests__/wrapper.test.d.ts +0 -1
- package/lib/__tests__/wrapper.test.js +0 -76
- package/lib/auth/__tests__/device-flow.test.d.ts +0 -1
- package/lib/auth/__tests__/device-flow.test.js +0 -62
- package/lib/auth/__tests__/oauth-client.test.d.ts +0 -1
- package/lib/auth/__tests__/oauth-client.test.js +0 -93
- package/lib/commands/preview-docs/index.d.ts +0 -12
- package/lib/commands/preview-docs/index.js +0 -127
- package/lib/commands/preview-docs/preview-server/default.hbs +0 -24
- package/lib/commands/preview-docs/preview-server/hot.js +0 -59
- package/lib/commands/preview-docs/preview-server/oauth2-redirect.html +0 -21
- package/lib/commands/preview-docs/preview-server/preview-server.d.ts +0 -5
- package/lib/commands/preview-docs/preview-server/preview-server.js +0 -113
- package/lib/commands/preview-docs/preview-server/server.d.ts +0 -22
- package/lib/commands/preview-docs/preview-server/server.js +0 -85
- package/lib/commands/push.d.ts +0 -44
- package/lib/commands/push.js +0 -301
- package/lib/commands/split/__tests__/index.test.d.ts +0 -1
- package/lib/commands/split/__tests__/index.test.js +0 -91
- package/lib/reunite/api/__tests__/api-keys.test.d.ts +0 -1
- package/lib/reunite/api/__tests__/api-keys.test.js +0 -26
- package/lib/reunite/api/__tests__/api.client.test.d.ts +0 -1
- package/lib/reunite/api/__tests__/api.client.test.js +0 -337
- package/lib/reunite/api/__tests__/domains.test.d.ts +0 -1
- package/lib/reunite/api/__tests__/domains.test.js +0 -32
- package/lib/reunite/commands/__tests__/push-status.test.d.ts +0 -1
- package/lib/reunite/commands/__tests__/push-status.test.js +0 -563
- package/lib/reunite/commands/__tests__/push.test.d.ts +0 -1
- package/lib/reunite/commands/__tests__/push.test.js +0 -315
- package/lib/reunite/commands/__tests__/utils.test.d.ts +0 -1
- package/lib/reunite/commands/__tests__/utils.test.js +0 -51
- package/lib/utils/__mocks__/miscellaneous.d.ts +0 -43
- package/lib/utils/__mocks__/miscellaneous.js +0 -24
- package/lib/utils/getCommandNameFromArgs.js +0 -6
- package/src/__mocks__/@redocly/openapi-core.ts +0 -88
- package/src/__mocks__/documents.ts +0 -124
- package/src/__mocks__/fs.ts +0 -6
- package/src/__mocks__/perf_hooks.ts +0 -3
- package/src/__mocks__/redoc.ts +0 -2
- package/src/__tests__/commands/build-docs.test.ts +0 -59
- package/src/__tests__/commands/bundle.test.ts +0 -285
- package/src/__tests__/commands/join.test.ts +0 -334
- package/src/__tests__/commands/lint.test.ts +0 -190
- package/src/__tests__/commands/push-region.test.ts +0 -104
- package/src/__tests__/commands/push.test.ts +0 -553
- package/src/__tests__/fetch-with-timeout.test.ts +0 -81
- package/src/__tests__/fixtures/config.ts +0 -21
- package/src/__tests__/fixtures/openapi.json +0 -0
- package/src/__tests__/fixtures/openapi.yaml +0 -0
- package/src/__tests__/fixtures/redocly.yaml +0 -0
- package/src/__tests__/spinner.test.ts +0 -51
- package/src/__tests__/utils.test.ts +0 -781
- package/src/__tests__/wrapper.test.ts +0 -91
- package/src/auth/__tests__/device-flow.test.ts +0 -73
- package/src/auth/__tests__/oauth-client.test.ts +0 -117
- package/src/auth/device-flow.ts +0 -175
- package/src/auth/oauth-client.ts +0 -111
- package/src/commands/auth.ts +0 -66
- package/src/commands/build-docs/index.ts +0 -55
- package/src/commands/build-docs/template.hbs +0 -23
- package/src/commands/build-docs/types.ts +0 -25
- package/src/commands/build-docs/utils.ts +0 -110
- package/src/commands/bundle.ts +0 -154
- package/src/commands/eject.ts +0 -42
- package/src/commands/join.ts +0 -794
- package/src/commands/lint.ts +0 -169
- package/src/commands/preview-docs/index.ts +0 -183
- package/src/commands/preview-docs/preview-server/default.hbs +0 -24
- package/src/commands/preview-docs/preview-server/hot.js +0 -59
- package/src/commands/preview-docs/preview-server/oauth2-redirect.html +0 -21
- package/src/commands/preview-docs/preview-server/preview-server.ts +0 -159
- package/src/commands/preview-docs/preview-server/server.ts +0 -92
- package/src/commands/preview-project/constants.ts +0 -23
- package/src/commands/preview-project/index.ts +0 -71
- package/src/commands/preview-project/types.ts +0 -12
- package/src/commands/push.ts +0 -470
- package/src/commands/split/__tests__/fixtures/samples.json +0 -61
- package/src/commands/split/__tests__/fixtures/spec.json +0 -70
- package/src/commands/split/__tests__/fixtures/webhooks.json +0 -85
- package/src/commands/split/__tests__/index.test.ts +0 -156
- package/src/commands/split/index.ts +0 -397
- package/src/commands/split/types.ts +0 -60
- package/src/commands/stats.ts +0 -140
- package/src/commands/translations.ts +0 -32
- package/src/custom.d.ts +0 -1
- package/src/index.ts +0 -970
- package/src/otel.ts +0 -59
- package/src/reunite/api/__tests__/api-keys.test.ts +0 -37
- package/src/reunite/api/__tests__/api.client.test.ts +0 -452
- package/src/reunite/api/__tests__/domains.test.ts +0 -41
- package/src/reunite/api/api-client.ts +0 -381
- package/src/reunite/api/api-keys.ts +0 -26
- package/src/reunite/api/domains.ts +0 -23
- package/src/reunite/api/index.ts +0 -3
- package/src/reunite/api/types.ts +0 -108
- package/src/reunite/commands/__tests__/push-status.test.ts +0 -653
- package/src/reunite/commands/__tests__/push.test.ts +0 -385
- package/src/reunite/commands/__tests__/utils.test.ts +0 -62
- package/src/reunite/commands/push-status.ts +0 -325
- package/src/reunite/commands/push.ts +0 -235
- package/src/reunite/commands/utils.ts +0 -66
- package/src/reunite/utils.ts +0 -1
- package/src/types.ts +0 -64
- package/src/utils/__mocks__/miscellaneous.ts +0 -24
- package/src/utils/assert-node-version.ts +0 -19
- package/src/utils/fetch-with-timeout.ts +0 -30
- package/src/utils/getCommandNameFromArgs.ts +0 -5
- package/src/utils/js-utils.ts +0 -24
- package/src/utils/miscellaneous.ts +0 -729
- package/src/utils/platform.ts +0 -31
- package/src/utils/spinner.ts +0 -50
- package/src/utils/update-version-notifier.ts +0 -115
- package/src/wrapper.ts +0 -77
- package/tsconfig.json +0 -9
- package/tsconfig.tsbuildinfo +0 -1
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const miscellaneous_1 = require("../utils/miscellaneous");
|
|
4
|
-
const process = require("process");
|
|
5
|
-
const wrapper_1 = require("../wrapper");
|
|
6
|
-
const lint_1 = require("../commands/lint");
|
|
7
|
-
const push_1 = require("../commands/push");
|
|
8
|
-
const openapi_core_1 = require("@redocly/openapi-core");
|
|
9
|
-
const mockFetch = jest.fn();
|
|
10
|
-
const originalFetch = global.fetch;
|
|
11
|
-
jest.mock('../utils/miscellaneous', () => ({
|
|
12
|
-
sendTelemetry: jest.fn(),
|
|
13
|
-
loadConfigAndHandleErrors: jest.fn(),
|
|
14
|
-
}));
|
|
15
|
-
beforeAll(() => {
|
|
16
|
-
global.fetch = mockFetch;
|
|
17
|
-
});
|
|
18
|
-
afterAll(() => {
|
|
19
|
-
jest.resetAllMocks();
|
|
20
|
-
global.fetch = originalFetch;
|
|
21
|
-
});
|
|
22
|
-
jest.mock('../commands/lint', () => ({
|
|
23
|
-
handleLint: jest.fn().mockImplementation(({ collectSpecData }) => {
|
|
24
|
-
collectSpecData({ openapi: '3.1.0' });
|
|
25
|
-
}),
|
|
26
|
-
lintConfigCallback: jest.fn(),
|
|
27
|
-
}));
|
|
28
|
-
describe('commandWrapper', () => {
|
|
29
|
-
it('should send telemetry if there is "telemetry: on" in the config', async () => {
|
|
30
|
-
miscellaneous_1.loadConfigAndHandleErrors.mockImplementation(() => {
|
|
31
|
-
return { telemetry: 'on', styleguide: { recommendedFallback: true } };
|
|
32
|
-
});
|
|
33
|
-
openapi_core_1.detectSpec.mockImplementationOnce(() => {
|
|
34
|
-
return 'oas3_1';
|
|
35
|
-
});
|
|
36
|
-
process.env.REDOCLY_TELEMETRY = 'on';
|
|
37
|
-
const wrappedHandler = (0, wrapper_1.commandWrapper)(lint_1.handleLint);
|
|
38
|
-
await wrappedHandler({});
|
|
39
|
-
expect(lint_1.handleLint).toHaveBeenCalledTimes(1);
|
|
40
|
-
expect(miscellaneous_1.sendTelemetry).toHaveBeenCalledTimes(1);
|
|
41
|
-
expect(miscellaneous_1.sendTelemetry).toHaveBeenCalledWith({}, 0, false, 'oas3_1', 'openapi', '3.1.0');
|
|
42
|
-
});
|
|
43
|
-
it('should not collect spec version if the file is not parsed to json', async () => {
|
|
44
|
-
miscellaneous_1.loadConfigAndHandleErrors.mockImplementation(() => {
|
|
45
|
-
return { telemetry: 'on', styleguide: { recommendedFallback: true } };
|
|
46
|
-
});
|
|
47
|
-
lint_1.handleLint.mockImplementation(({ collectSpecData }) => {
|
|
48
|
-
collectSpecData();
|
|
49
|
-
});
|
|
50
|
-
process.env.REDOCLY_TELEMETRY = 'on';
|
|
51
|
-
const wrappedHandler = (0, wrapper_1.commandWrapper)(lint_1.handleLint);
|
|
52
|
-
await wrappedHandler({});
|
|
53
|
-
expect(lint_1.handleLint).toHaveBeenCalledTimes(1);
|
|
54
|
-
expect(miscellaneous_1.sendTelemetry).toHaveBeenCalledTimes(1);
|
|
55
|
-
expect(miscellaneous_1.sendTelemetry).toHaveBeenCalledWith({}, 0, false, undefined, undefined, undefined);
|
|
56
|
-
});
|
|
57
|
-
it('should NOT send telemetry if there is "telemetry: off" in the config', async () => {
|
|
58
|
-
miscellaneous_1.loadConfigAndHandleErrors.mockImplementation(() => {
|
|
59
|
-
return { telemetry: 'off', styleguide: { recommendedFallback: true } };
|
|
60
|
-
});
|
|
61
|
-
process.env.REDOCLY_TELEMETRY = 'on';
|
|
62
|
-
const wrappedHandler = (0, wrapper_1.commandWrapper)(lint_1.handleLint);
|
|
63
|
-
await wrappedHandler({});
|
|
64
|
-
expect(lint_1.handleLint).toHaveBeenCalledTimes(1);
|
|
65
|
-
expect(miscellaneous_1.sendTelemetry).toHaveBeenCalledTimes(0);
|
|
66
|
-
});
|
|
67
|
-
it('should pass files from arguments to config', async () => {
|
|
68
|
-
const filesToPush = ['test1.yaml', 'test2.yaml'];
|
|
69
|
-
const loadConfigMock = miscellaneous_1.loadConfigAndHandleErrors;
|
|
70
|
-
const argv = {
|
|
71
|
-
files: filesToPush,
|
|
72
|
-
};
|
|
73
|
-
await (0, wrapper_1.commandWrapper)(push_1.handlePush)(argv);
|
|
74
|
-
expect(loadConfigMock).toHaveBeenCalledWith(expect.objectContaining({ files: filesToPush }));
|
|
75
|
-
});
|
|
76
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const device_flow_1 = require("../device-flow");
|
|
4
|
-
jest.mock('child_process');
|
|
5
|
-
describe('RedoclyOAuthDeviceFlow', () => {
|
|
6
|
-
const mockBaseUrl = 'https://test.redocly.com';
|
|
7
|
-
const mockClientName = 'test-client';
|
|
8
|
-
const mockVersion = '1.0.0';
|
|
9
|
-
let flow;
|
|
10
|
-
beforeEach(() => {
|
|
11
|
-
flow = new device_flow_1.RedoclyOAuthDeviceFlow(mockBaseUrl, mockClientName, mockVersion);
|
|
12
|
-
jest.resetAllMocks();
|
|
13
|
-
});
|
|
14
|
-
describe('verifyToken', () => {
|
|
15
|
-
it('returns true for valid token', async () => {
|
|
16
|
-
jest.spyOn(flow['apiClient'], 'request').mockResolvedValue({
|
|
17
|
-
json: () => Promise.resolve({ user: { id: '123' } }),
|
|
18
|
-
});
|
|
19
|
-
const result = await flow.verifyToken('valid-token');
|
|
20
|
-
expect(result).toBe(true);
|
|
21
|
-
});
|
|
22
|
-
it('returns false for invalid token', async () => {
|
|
23
|
-
jest.spyOn(flow['apiClient'], 'request').mockRejectedValue(new Error('Invalid token'));
|
|
24
|
-
const result = await flow.verifyToken('invalid-token');
|
|
25
|
-
expect(result).toBe(false);
|
|
26
|
-
});
|
|
27
|
-
});
|
|
28
|
-
describe('verifyApiKey', () => {
|
|
29
|
-
it('returns true for valid API key', async () => {
|
|
30
|
-
jest.spyOn(flow['apiClient'], 'request').mockResolvedValue({
|
|
31
|
-
json: () => Promise.resolve({ success: true }),
|
|
32
|
-
});
|
|
33
|
-
const result = await flow.verifyApiKey('valid-key');
|
|
34
|
-
expect(result).toBe(true);
|
|
35
|
-
});
|
|
36
|
-
it('returns false for invalid API key', async () => {
|
|
37
|
-
jest.spyOn(flow['apiClient'], 'request').mockRejectedValue(new Error('Invalid API key'));
|
|
38
|
-
const result = await flow.verifyApiKey('invalid-key');
|
|
39
|
-
expect(result).toBe(false);
|
|
40
|
-
});
|
|
41
|
-
});
|
|
42
|
-
describe('refreshToken', () => {
|
|
43
|
-
it('successfully refreshes token', async () => {
|
|
44
|
-
const mockResponse = {
|
|
45
|
-
access_token: 'new-token',
|
|
46
|
-
refresh_token: 'new-refresh',
|
|
47
|
-
expires_in: 3600,
|
|
48
|
-
};
|
|
49
|
-
jest.spyOn(flow['apiClient'], 'request').mockResolvedValue({
|
|
50
|
-
json: () => Promise.resolve(mockResponse),
|
|
51
|
-
});
|
|
52
|
-
const result = await flow.refreshToken('old-refresh-token');
|
|
53
|
-
expect(result).toEqual(mockResponse);
|
|
54
|
-
});
|
|
55
|
-
it('throws error when refresh fails', async () => {
|
|
56
|
-
jest.spyOn(flow['apiClient'], 'request').mockResolvedValue({
|
|
57
|
-
json: () => Promise.resolve({}),
|
|
58
|
-
});
|
|
59
|
-
await expect(flow.refreshToken('invalid-refresh')).rejects.toThrow('Failed to refresh token');
|
|
60
|
-
});
|
|
61
|
-
});
|
|
62
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const oauth_client_1 = require("../oauth-client");
|
|
4
|
-
const device_flow_1 = require("../device-flow");
|
|
5
|
-
const fs = require("node:fs");
|
|
6
|
-
const path = require("node:path");
|
|
7
|
-
const os = require("node:os");
|
|
8
|
-
jest.mock('node:fs');
|
|
9
|
-
jest.mock('node:os');
|
|
10
|
-
jest.mock('../device-flow');
|
|
11
|
-
describe('RedoclyOAuthClient', () => {
|
|
12
|
-
const mockClientName = 'test-client';
|
|
13
|
-
const mockVersion = '1.0.0';
|
|
14
|
-
const mockBaseUrl = 'https://test.redocly.com';
|
|
15
|
-
const mockHomeDir = '/mock/home/dir';
|
|
16
|
-
const mockRedoclyDir = path.join(mockHomeDir, '.redocly');
|
|
17
|
-
let client;
|
|
18
|
-
beforeEach(() => {
|
|
19
|
-
jest.resetAllMocks();
|
|
20
|
-
os.homedir.mockReturnValue(mockHomeDir);
|
|
21
|
-
process.env.HOME = mockHomeDir;
|
|
22
|
-
client = new oauth_client_1.RedoclyOAuthClient(mockClientName, mockVersion);
|
|
23
|
-
});
|
|
24
|
-
describe('login', () => {
|
|
25
|
-
it('successfully logs in and saves token', async () => {
|
|
26
|
-
const mockToken = { access_token: 'test-token' };
|
|
27
|
-
const mockDeviceFlow = {
|
|
28
|
-
run: jest.fn().mockResolvedValue(mockToken),
|
|
29
|
-
};
|
|
30
|
-
device_flow_1.RedoclyOAuthDeviceFlow.mockImplementation(() => mockDeviceFlow);
|
|
31
|
-
await client.login(mockBaseUrl);
|
|
32
|
-
expect(mockDeviceFlow.run).toHaveBeenCalled();
|
|
33
|
-
expect(fs.writeFileSync).toHaveBeenCalled();
|
|
34
|
-
});
|
|
35
|
-
it('throws error when login fails', async () => {
|
|
36
|
-
const mockDeviceFlow = {
|
|
37
|
-
run: jest.fn().mockResolvedValue(null),
|
|
38
|
-
};
|
|
39
|
-
device_flow_1.RedoclyOAuthDeviceFlow.mockImplementation(() => mockDeviceFlow);
|
|
40
|
-
await expect(client.login(mockBaseUrl)).rejects.toThrow('Failed to login');
|
|
41
|
-
});
|
|
42
|
-
});
|
|
43
|
-
describe('logout', () => {
|
|
44
|
-
it('removes token file if it exists', async () => {
|
|
45
|
-
fs.existsSync.mockReturnValue(true);
|
|
46
|
-
await client.logout();
|
|
47
|
-
expect(fs.rmSync).toHaveBeenCalledWith(path.join(mockRedoclyDir, 'auth.json'));
|
|
48
|
-
});
|
|
49
|
-
it('silently fails if token file does not exist', async () => {
|
|
50
|
-
fs.existsSync.mockReturnValue(false);
|
|
51
|
-
await expect(client.logout()).resolves.not.toThrow();
|
|
52
|
-
expect(fs.rmSync).not.toHaveBeenCalled();
|
|
53
|
-
});
|
|
54
|
-
});
|
|
55
|
-
describe('isAuthorized', () => {
|
|
56
|
-
it('verifies API key if provided', async () => {
|
|
57
|
-
const mockDeviceFlow = {
|
|
58
|
-
verifyApiKey: jest.fn().mockResolvedValue(true),
|
|
59
|
-
};
|
|
60
|
-
device_flow_1.RedoclyOAuthDeviceFlow.mockImplementation(() => mockDeviceFlow);
|
|
61
|
-
const result = await client.isAuthorized(mockBaseUrl, 'test-api-key');
|
|
62
|
-
expect(result).toBe(true);
|
|
63
|
-
expect(mockDeviceFlow.verifyApiKey).toHaveBeenCalledWith('test-api-key');
|
|
64
|
-
});
|
|
65
|
-
it('verifies access token if no API key provided', async () => {
|
|
66
|
-
const mockToken = { access_token: 'test-token' };
|
|
67
|
-
const mockDeviceFlow = {
|
|
68
|
-
verifyToken: jest.fn().mockResolvedValue(true),
|
|
69
|
-
};
|
|
70
|
-
device_flow_1.RedoclyOAuthDeviceFlow.mockImplementation(() => mockDeviceFlow);
|
|
71
|
-
fs.readFileSync.mockReturnValue(client['cipher'].update(JSON.stringify(mockToken), 'utf8', 'hex') +
|
|
72
|
-
client['cipher'].final('hex'));
|
|
73
|
-
const result = await client.isAuthorized(mockBaseUrl);
|
|
74
|
-
expect(result).toBe(true);
|
|
75
|
-
expect(mockDeviceFlow.verifyToken).toHaveBeenCalledWith('test-token');
|
|
76
|
-
});
|
|
77
|
-
it('returns false if token refresh fails', async () => {
|
|
78
|
-
const mockToken = {
|
|
79
|
-
access_token: 'old-token',
|
|
80
|
-
refresh_token: 'refresh-token',
|
|
81
|
-
};
|
|
82
|
-
const mockDeviceFlow = {
|
|
83
|
-
verifyToken: jest.fn().mockResolvedValue(false),
|
|
84
|
-
refreshToken: jest.fn().mockRejectedValue(new Error('Refresh failed')),
|
|
85
|
-
};
|
|
86
|
-
device_flow_1.RedoclyOAuthDeviceFlow.mockImplementation(() => mockDeviceFlow);
|
|
87
|
-
fs.readFileSync.mockReturnValue(client['cipher'].update(JSON.stringify(mockToken), 'utf8', 'hex') +
|
|
88
|
-
client['cipher'].final('hex'));
|
|
89
|
-
const result = await client.isAuthorized(mockBaseUrl);
|
|
90
|
-
expect(result).toBe(false);
|
|
91
|
-
});
|
|
92
|
-
});
|
|
93
|
-
});
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import type { Skips, VerifyConfigOptions } from '../../types';
|
|
2
|
-
import type { CommandArgs } from '../../wrapper';
|
|
3
|
-
export type PreviewDocsOptions = {
|
|
4
|
-
port: number;
|
|
5
|
-
host: string;
|
|
6
|
-
'use-community-edition'?: boolean;
|
|
7
|
-
config?: string;
|
|
8
|
-
api?: string;
|
|
9
|
-
force?: boolean;
|
|
10
|
-
} & Omit<Skips, 'skip-rule'> & VerifyConfigOptions;
|
|
11
|
-
export declare function previewDocs({ argv, config: configFromFile, }: CommandArgs<PreviewDocsOptions>): Promise<void>;
|
|
12
|
-
export declare function debounce(func: Function, wait: number, immediate?: boolean): (...args: any[]) => void;
|
|
@@ -1,127 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.previewDocs = previewDocs;
|
|
4
|
-
exports.debounce = debounce;
|
|
5
|
-
const colorette = require("colorette");
|
|
6
|
-
const chockidar = require("chokidar");
|
|
7
|
-
const openapi_core_1 = require("@redocly/openapi-core");
|
|
8
|
-
const miscellaneous_1 = require("../../utils/miscellaneous");
|
|
9
|
-
const preview_server_1 = require("./preview-server/preview-server");
|
|
10
|
-
async function previewDocs({ argv, config: configFromFile, }) {
|
|
11
|
-
let isAuthorizedWithRedocly = false;
|
|
12
|
-
let redocOptions = {};
|
|
13
|
-
let config = await reloadConfig(configFromFile);
|
|
14
|
-
const apis = await (0, miscellaneous_1.getFallbackApisOrExit)(argv.api ? [argv.api] : [], config);
|
|
15
|
-
const api = apis[0];
|
|
16
|
-
let cachedBundle;
|
|
17
|
-
const deps = new Set();
|
|
18
|
-
async function getBundle() {
|
|
19
|
-
return cachedBundle;
|
|
20
|
-
}
|
|
21
|
-
async function updateBundle() {
|
|
22
|
-
process.stdout.write('\nBundling...\n\n');
|
|
23
|
-
try {
|
|
24
|
-
const { bundle: openapiBundle, problems, fileDependencies, } = await (0, openapi_core_1.bundle)({
|
|
25
|
-
ref: api.path,
|
|
26
|
-
config,
|
|
27
|
-
});
|
|
28
|
-
const removed = [...deps].filter((x) => !fileDependencies.has(x));
|
|
29
|
-
watcher.unwatch(removed);
|
|
30
|
-
watcher.add([...fileDependencies]);
|
|
31
|
-
deps.clear();
|
|
32
|
-
fileDependencies.forEach(deps.add, deps);
|
|
33
|
-
const fileTotals = (0, openapi_core_1.getTotals)(problems);
|
|
34
|
-
if (fileTotals.errors === 0) {
|
|
35
|
-
process.stdout.write(fileTotals.errors === 0
|
|
36
|
-
? `Created a bundle for ${api.alias || api.path} ${fileTotals.warnings > 0 ? 'with warnings' : 'successfully'}\n`
|
|
37
|
-
: colorette.yellow(`Created a bundle for ${api.alias || api.path} with errors. Docs may be broken or not accurate\n`));
|
|
38
|
-
}
|
|
39
|
-
return openapiBundle.parsed;
|
|
40
|
-
}
|
|
41
|
-
catch (e) {
|
|
42
|
-
(0, miscellaneous_1.handleError)(e, api.path);
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
setImmediate(() => {
|
|
46
|
-
cachedBundle = updateBundle();
|
|
47
|
-
}); // initial cache
|
|
48
|
-
const isAuthorized = isAuthorizedWithRedocly || redocOptions.licenseKey;
|
|
49
|
-
if (!isAuthorized) {
|
|
50
|
-
process.stderr.write(`Using Redoc community edition.\nLogin with redocly ${colorette.blue('login')} or use an enterprise license key to preview with the premium docs.\n\n`);
|
|
51
|
-
}
|
|
52
|
-
const hotClients = await (0, preview_server_1.default)(argv.port, argv.host, {
|
|
53
|
-
getBundle,
|
|
54
|
-
getOptions: () => redocOptions,
|
|
55
|
-
useRedocPro: isAuthorized && !redocOptions.useCommunityEdition,
|
|
56
|
-
});
|
|
57
|
-
const watchPaths = [api.path, config.configFile].filter((e) => !!e);
|
|
58
|
-
const watcher = chockidar.watch(watchPaths, {
|
|
59
|
-
disableGlobbing: true,
|
|
60
|
-
ignoreInitial: true,
|
|
61
|
-
});
|
|
62
|
-
const debouncedUpdatedBundle = debounce(async () => {
|
|
63
|
-
cachedBundle = updateBundle();
|
|
64
|
-
await cachedBundle;
|
|
65
|
-
hotClients.broadcast('{"type": "reload", "bundle": true}');
|
|
66
|
-
}, 2000);
|
|
67
|
-
const changeHandler = async (type, file) => {
|
|
68
|
-
process.stdout.write(`${colorette.green('watch')} ${type} ${colorette.blue(file)}\n`);
|
|
69
|
-
if (file === config.configFile) {
|
|
70
|
-
config = await reloadConfig();
|
|
71
|
-
hotClients.broadcast(JSON.stringify({ type: 'reload' }));
|
|
72
|
-
return;
|
|
73
|
-
}
|
|
74
|
-
debouncedUpdatedBundle();
|
|
75
|
-
};
|
|
76
|
-
watcher.on('change', changeHandler.bind(undefined, 'changed'));
|
|
77
|
-
watcher.on('add', changeHandler.bind(undefined, 'added'));
|
|
78
|
-
watcher.on('unlink', changeHandler.bind(undefined, 'removed'));
|
|
79
|
-
watcher.on('ready', () => {
|
|
80
|
-
process.stdout.write(`\n 👀 Watching ${colorette.blue(api.path)} and all related resources for changes\n\n`);
|
|
81
|
-
});
|
|
82
|
-
async function reloadConfig(config) {
|
|
83
|
-
if (!config) {
|
|
84
|
-
try {
|
|
85
|
-
config = (await (0, miscellaneous_1.loadConfigAndHandleErrors)({ configPath: argv.config }));
|
|
86
|
-
}
|
|
87
|
-
catch (err) {
|
|
88
|
-
config = new openapi_core_1.Config({ apis: {}, styleguide: {} });
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
const redoclyClient = new openapi_core_1.RedoclyClient();
|
|
92
|
-
isAuthorizedWithRedocly = await redoclyClient.isAuthorizedWithRedocly();
|
|
93
|
-
const resolvedConfig = (0, openapi_core_1.getMergedConfig)(config, argv.api);
|
|
94
|
-
const { styleguide } = resolvedConfig;
|
|
95
|
-
styleguide.skipPreprocessors(argv['skip-preprocessor']);
|
|
96
|
-
styleguide.skipDecorators(argv['skip-decorator']);
|
|
97
|
-
const referenceDocs = resolvedConfig.theme?.openapi;
|
|
98
|
-
redocOptions = {
|
|
99
|
-
...referenceDocs,
|
|
100
|
-
useCommunityEdition: argv['use-community-edition'] || referenceDocs?.useCommunityEdition,
|
|
101
|
-
licenseKey: process.env.REDOCLY_LICENSE_KEY || referenceDocs?.licenseKey,
|
|
102
|
-
whiteLabel: true,
|
|
103
|
-
};
|
|
104
|
-
return resolvedConfig;
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
108
|
-
function debounce(func, wait, immediate) {
|
|
109
|
-
let timeout;
|
|
110
|
-
return function executedFunction(...args) {
|
|
111
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
112
|
-
// @ts-ignore
|
|
113
|
-
// eslint-disable-next-line @typescript-eslint/no-this-alias
|
|
114
|
-
const context = this;
|
|
115
|
-
const later = () => {
|
|
116
|
-
timeout = null;
|
|
117
|
-
if (!immediate)
|
|
118
|
-
func.apply(context, args);
|
|
119
|
-
};
|
|
120
|
-
const callNow = immediate && !timeout;
|
|
121
|
-
if (timeout)
|
|
122
|
-
clearTimeout(timeout);
|
|
123
|
-
timeout = setTimeout(later, wait);
|
|
124
|
-
if (callNow)
|
|
125
|
-
func.apply(context, args);
|
|
126
|
-
};
|
|
127
|
-
}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
<!DOCTYPE html>
|
|
3
|
-
<html>
|
|
4
|
-
|
|
5
|
-
<head>
|
|
6
|
-
<meta charset="utf8" />
|
|
7
|
-
<title>{{title}}</title>
|
|
8
|
-
<!-- needed for adaptive design -->
|
|
9
|
-
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
10
|
-
<style>
|
|
11
|
-
body {
|
|
12
|
-
padding: 0;
|
|
13
|
-
margin: 0;
|
|
14
|
-
}
|
|
15
|
-
</style>
|
|
16
|
-
{{{redocHead}}}
|
|
17
|
-
<link href="https://fonts.googleapis.com/css?family=Montserrat:300,400,700|Roboto:300,400,700" rel="stylesheet">
|
|
18
|
-
</head>
|
|
19
|
-
|
|
20
|
-
<body>
|
|
21
|
-
{{{redocHTML}}}
|
|
22
|
-
</body>
|
|
23
|
-
|
|
24
|
-
</html>
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
(function run() {
|
|
2
|
-
const Socket = window.SimpleWebsocket;
|
|
3
|
-
const port = window.__OPENAPI_CLI_WS_PORT;
|
|
4
|
-
const host = window.__OPENAPI_CLI_WS_HOST;
|
|
5
|
-
|
|
6
|
-
let socket;
|
|
7
|
-
|
|
8
|
-
reconnect();
|
|
9
|
-
|
|
10
|
-
function getFormattedHost() {
|
|
11
|
-
// Use localhost when bound to all interfaces
|
|
12
|
-
if (host === '::' || host === '0.0.0.0') {
|
|
13
|
-
return 'localhost';
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
// Other IPv6 addresses must be wrapped in brackets
|
|
17
|
-
if (host.includes('::')) {
|
|
18
|
-
return `[${host}]`;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
// Otherwise return as-is
|
|
22
|
-
return host;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
function reconnect() {
|
|
26
|
-
socket = new Socket(`ws://${getFormattedHost()}:${port}`);
|
|
27
|
-
socket.on('connect', () => {
|
|
28
|
-
socket.send('{"type": "ping"}');
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
socket.on('data', (data) => {
|
|
32
|
-
const message = JSON.parse(data);
|
|
33
|
-
switch (message.type) {
|
|
34
|
-
case 'pong':
|
|
35
|
-
console.log('[hot] hot reloading connected');
|
|
36
|
-
break;
|
|
37
|
-
case 'reload':
|
|
38
|
-
console.log('[hot] full page reload');
|
|
39
|
-
window.location.reload();
|
|
40
|
-
break;
|
|
41
|
-
default:
|
|
42
|
-
console.log(`[hot] ${message.type} received`);
|
|
43
|
-
}
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
socket.on('close', () => {
|
|
47
|
-
socket.destroy();
|
|
48
|
-
console.log('[hot] Connection lost, trying to reconnect in 4s');
|
|
49
|
-
setTimeout(() => {
|
|
50
|
-
reconnect();
|
|
51
|
-
}, 4000);
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
socket.on('error', () => {
|
|
55
|
-
console.log('[hot] Error connecting to hot reloading server');
|
|
56
|
-
socket.destroy();
|
|
57
|
-
});
|
|
58
|
-
}
|
|
59
|
-
})();
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
<!DOCTYPE html>
|
|
2
|
-
<html lang="en">
|
|
3
|
-
<head>
|
|
4
|
-
<meta charset="utf-8" />
|
|
5
|
-
<meta name="viewport" content="width=device-width,initial-scale=1,shrink-to-fit=no" />
|
|
6
|
-
<title>Redocly Reference Docs: OAuth2 Redirect</title>
|
|
7
|
-
<style>
|
|
8
|
-
.user-info {
|
|
9
|
-
margin: 150px auto auto;
|
|
10
|
-
width: 50%;
|
|
11
|
-
background-color: whitesmoke;
|
|
12
|
-
padding: 20px;
|
|
13
|
-
text-align: center;
|
|
14
|
-
}
|
|
15
|
-
</style>
|
|
16
|
-
</head>
|
|
17
|
-
<body>
|
|
18
|
-
<script src="https://cdn.redocly.com/reference-docs/latest/oauth2-redirect.js"></script>
|
|
19
|
-
<noscript>You need to enable JavaScript to run this app.</noscript>
|
|
20
|
-
</body>
|
|
21
|
-
</html>
|
|
@@ -1,113 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.default = startPreviewServer;
|
|
4
|
-
const handlebars_1 = require("handlebars");
|
|
5
|
-
const colorette = require("colorette");
|
|
6
|
-
const get_port_please_1 = require("get-port-please");
|
|
7
|
-
const fs_1 = require("fs");
|
|
8
|
-
const path = require("path");
|
|
9
|
-
const server_1 = require("./server");
|
|
10
|
-
const miscellaneous_1 = require("../../../utils/miscellaneous");
|
|
11
|
-
function getPageHTML(htmlTemplate, redocOptions = {}, useRedocPro, wsPort, host) {
|
|
12
|
-
let templateSrc = (0, fs_1.readFileSync)(htmlTemplate, 'utf-8');
|
|
13
|
-
// fix template for backward compatibility
|
|
14
|
-
templateSrc = templateSrc
|
|
15
|
-
.replace(/{?{{redocHead}}}?/, '{{{redocHead}}}')
|
|
16
|
-
.replace('{{redocBody}}', '{{{redocHTML}}}');
|
|
17
|
-
const template = (0, handlebars_1.compile)(templateSrc);
|
|
18
|
-
return template({
|
|
19
|
-
redocHead: `
|
|
20
|
-
<script>
|
|
21
|
-
window.__REDOC_EXPORT = '${useRedocPro ? 'RedoclyReferenceDocs' : 'Redoc'}';
|
|
22
|
-
window.__OPENAPI_CLI_WS_PORT = ${wsPort};
|
|
23
|
-
window.__OPENAPI_CLI_WS_HOST = "${host}";
|
|
24
|
-
</script>
|
|
25
|
-
<script src="/simplewebsocket.min.js"></script>
|
|
26
|
-
<script src="/hot.js"></script>
|
|
27
|
-
<script src="${useRedocPro
|
|
28
|
-
? 'https://cdn.redocly.com/reference-docs/latest/redocly-reference-docs.min.js'
|
|
29
|
-
: 'https://cdn.redocly.com/redoc/latest/bundles/redoc.standalone.js'}"></script>
|
|
30
|
-
`,
|
|
31
|
-
redocHTML: `
|
|
32
|
-
<div id="redoc"></div>
|
|
33
|
-
<script>
|
|
34
|
-
var container = document.getElementById('redoc');
|
|
35
|
-
${useRedocPro
|
|
36
|
-
? "window[window.__REDOC_EXPORT].setPublicPath('https://cdn.redocly.com/reference-docs/latest/');"
|
|
37
|
-
: ''}
|
|
38
|
-
window[window.__REDOC_EXPORT].init("/openapi.json", ${JSON.stringify(redocOptions)}, container)
|
|
39
|
-
</script>`,
|
|
40
|
-
});
|
|
41
|
-
}
|
|
42
|
-
async function startPreviewServer(port, host, { getBundle, getOptions, useRedocPro, }) {
|
|
43
|
-
const defaultTemplate = path.join(__dirname, 'default.hbs');
|
|
44
|
-
const handler = async (request, response) => {
|
|
45
|
-
console.time(colorette.dim(`GET ${request.url}`));
|
|
46
|
-
const { htmlTemplate } = getOptions() || {};
|
|
47
|
-
if (request.url?.endsWith('/') || path.extname(request.url) === '') {
|
|
48
|
-
(0, server_1.respondWithGzip)(getPageHTML(htmlTemplate || defaultTemplate, getOptions(), useRedocPro, wsPort, host), request, response, {
|
|
49
|
-
'Content-Type': 'text/html',
|
|
50
|
-
});
|
|
51
|
-
}
|
|
52
|
-
else if (request.url === '/openapi.json') {
|
|
53
|
-
const bundle = await getBundle();
|
|
54
|
-
if (bundle === undefined) {
|
|
55
|
-
(0, server_1.respondWithGzip)(JSON.stringify({
|
|
56
|
-
openapi: '3.0.0',
|
|
57
|
-
info: {
|
|
58
|
-
description: '<code> Failed to generate bundle: check out console output for more details </code>',
|
|
59
|
-
},
|
|
60
|
-
paths: {},
|
|
61
|
-
}), request, response, {
|
|
62
|
-
'Content-Type': 'application/json',
|
|
63
|
-
});
|
|
64
|
-
}
|
|
65
|
-
else {
|
|
66
|
-
(0, server_1.respondWithGzip)(JSON.stringify(bundle), request, response, {
|
|
67
|
-
'Content-Type': 'application/json',
|
|
68
|
-
});
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
else {
|
|
72
|
-
let filePath =
|
|
73
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
74
|
-
// @ts-ignore
|
|
75
|
-
{
|
|
76
|
-
'/hot.js': path.join(__dirname, 'hot.js'),
|
|
77
|
-
'/oauth2-redirect.html': path.join(__dirname, 'oauth2-redirect.html'),
|
|
78
|
-
'/simplewebsocket.min.js': require.resolve('simple-websocket/simplewebsocket.min.js'),
|
|
79
|
-
}[request.url || ''];
|
|
80
|
-
if (!filePath) {
|
|
81
|
-
const basePath = htmlTemplate ? path.dirname(htmlTemplate) : process.cwd();
|
|
82
|
-
filePath = path.resolve(basePath, `.${request.url}`);
|
|
83
|
-
if (!(0, miscellaneous_1.isSubdir)(basePath, filePath)) {
|
|
84
|
-
(0, server_1.respondWithGzip)('404 Not Found', request, response, { 'Content-Type': 'text/html' }, 404);
|
|
85
|
-
console.timeEnd(colorette.dim(`GET ${request.url}`));
|
|
86
|
-
return;
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
const extname = String(path.extname(filePath)).toLowerCase();
|
|
90
|
-
const contentType = server_1.mimeTypes[extname] || 'application/octet-stream';
|
|
91
|
-
try {
|
|
92
|
-
(0, server_1.respondWithGzip)(await fs_1.promises.readFile(filePath), request, response, {
|
|
93
|
-
'Content-Type': contentType,
|
|
94
|
-
});
|
|
95
|
-
}
|
|
96
|
-
catch (e) {
|
|
97
|
-
if (e.code === 'ENOENT') {
|
|
98
|
-
(0, server_1.respondWithGzip)('404 Not Found', request, response, { 'Content-Type': 'text/html' }, 404);
|
|
99
|
-
}
|
|
100
|
-
else {
|
|
101
|
-
(0, server_1.respondWithGzip)(`Something went wrong: ${e.code || e.message}...\n`, request, response, {}, 500);
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
console.timeEnd(colorette.dim(`GET ${request.url}`));
|
|
106
|
-
};
|
|
107
|
-
const wsPort = await (0, get_port_please_1.getPort)({ port: 32201, portRange: [32201, 32301], host });
|
|
108
|
-
const server = (0, server_1.startHttpServer)(port, host, handler);
|
|
109
|
-
server.on('listening', () => {
|
|
110
|
-
process.stdout.write(`\n 🔎 Preview server running at ${colorette.blue(`http://${host}:${port}\n`)}`);
|
|
111
|
-
});
|
|
112
|
-
return (0, server_1.startWsServer)(wsPort, host);
|
|
113
|
-
}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import * as http from 'http';
|
|
2
|
-
import type { ReadStream } from 'fs';
|
|
3
|
-
export declare const mimeTypes: {
|
|
4
|
-
'.html': string;
|
|
5
|
-
'.js': string;
|
|
6
|
-
'.css': string;
|
|
7
|
-
'.json': string;
|
|
8
|
-
'.png': string;
|
|
9
|
-
'.jpg': string;
|
|
10
|
-
'.gif': string;
|
|
11
|
-
'.svg': string;
|
|
12
|
-
'.wav': string;
|
|
13
|
-
'.mp4': string;
|
|
14
|
-
'.woff': string;
|
|
15
|
-
'.ttf': string;
|
|
16
|
-
'.eot': string;
|
|
17
|
-
'.otf': string;
|
|
18
|
-
'.wasm': string;
|
|
19
|
-
};
|
|
20
|
-
export declare function respondWithGzip(contents: string | Buffer | ReadStream, request: http.IncomingMessage, response: http.ServerResponse, headers?: {}, code?: number): void;
|
|
21
|
-
export declare function startHttpServer(port: number, host: string, handler: http.RequestListener): http.Server<typeof http.IncomingMessage, typeof http.ServerResponse>;
|
|
22
|
-
export declare function startWsServer(port: number, host: string): any;
|