@redocly/cli 1.34.3 → 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 +15 -16
- package/CHANGELOG.md +0 -770
- 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,337 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const colorette_1 = require("colorette");
|
|
4
|
-
const api_client_1 = require("../api-client");
|
|
5
|
-
const originalFetch = global.fetch;
|
|
6
|
-
beforeAll(() => {
|
|
7
|
-
// Reset fetch mock before each test
|
|
8
|
-
global.fetch = jest.fn();
|
|
9
|
-
});
|
|
10
|
-
afterAll(() => {
|
|
11
|
-
// Restore original fetch after each test
|
|
12
|
-
global.fetch = originalFetch;
|
|
13
|
-
});
|
|
14
|
-
function mockFetchResponse(response) {
|
|
15
|
-
global.fetch.mockResolvedValue(response);
|
|
16
|
-
}
|
|
17
|
-
describe('ApiClient', () => {
|
|
18
|
-
const testToken = 'test-token';
|
|
19
|
-
const testDomain = 'test-domain.com';
|
|
20
|
-
const testOrg = 'test-org';
|
|
21
|
-
const testProject = 'test-project';
|
|
22
|
-
const version = '1.0.0';
|
|
23
|
-
const command = 'push';
|
|
24
|
-
const expectedUserAgent = `redocly-cli/${version} ${command}`;
|
|
25
|
-
describe('getDefaultBranch()', () => {
|
|
26
|
-
let apiClient;
|
|
27
|
-
beforeEach(() => {
|
|
28
|
-
apiClient = new api_client_1.ReuniteApi({ domain: testDomain, apiKey: testToken, version, command });
|
|
29
|
-
});
|
|
30
|
-
it('should get default project branch', async () => {
|
|
31
|
-
mockFetchResponse({
|
|
32
|
-
ok: true,
|
|
33
|
-
json: jest.fn().mockResolvedValue({
|
|
34
|
-
branchName: 'test-branch',
|
|
35
|
-
}),
|
|
36
|
-
});
|
|
37
|
-
const result = await apiClient.remotes.getDefaultBranch(testOrg, testProject);
|
|
38
|
-
expect(global.fetch).toHaveBeenCalledWith(`${testDomain}/api/orgs/${testOrg}/projects/${testProject}/source`, {
|
|
39
|
-
method: 'GET',
|
|
40
|
-
headers: {
|
|
41
|
-
'Content-Type': 'application/json',
|
|
42
|
-
Authorization: `Bearer ${testToken}`,
|
|
43
|
-
'user-agent': expectedUserAgent,
|
|
44
|
-
},
|
|
45
|
-
signal: expect.any(Object),
|
|
46
|
-
});
|
|
47
|
-
expect(result).toEqual('test-branch');
|
|
48
|
-
});
|
|
49
|
-
it('should throw parsed error if response is not ok', async () => {
|
|
50
|
-
mockFetchResponse({
|
|
51
|
-
ok: false,
|
|
52
|
-
json: jest.fn().mockResolvedValue({
|
|
53
|
-
type: 'about:blank',
|
|
54
|
-
title: 'Project source not found',
|
|
55
|
-
status: 404,
|
|
56
|
-
detail: 'Not Found',
|
|
57
|
-
object: 'problem',
|
|
58
|
-
}),
|
|
59
|
-
});
|
|
60
|
-
await expect(apiClient.remotes.getDefaultBranch(testOrg, testProject)).rejects.toThrow(new api_client_1.ReuniteApiError('Failed to fetch default branch. Project source not found.', 404));
|
|
61
|
-
});
|
|
62
|
-
it('should throw statusText error if response is not ok', async () => {
|
|
63
|
-
mockFetchResponse({
|
|
64
|
-
ok: false,
|
|
65
|
-
statusText: 'Not found',
|
|
66
|
-
json: jest.fn().mockResolvedValue({
|
|
67
|
-
unknownField: 'unknown-error',
|
|
68
|
-
}),
|
|
69
|
-
});
|
|
70
|
-
await expect(apiClient.remotes.getDefaultBranch(testOrg, testProject)).rejects.toThrow(new api_client_1.ReuniteApiError('Failed to fetch default branch. Not found.', 404));
|
|
71
|
-
});
|
|
72
|
-
});
|
|
73
|
-
describe('upsert()', () => {
|
|
74
|
-
const remotePayload = {
|
|
75
|
-
mountBranchName: 'remote-mount-branch-name',
|
|
76
|
-
mountPath: 'remote-mount-path',
|
|
77
|
-
};
|
|
78
|
-
const responseMock = {
|
|
79
|
-
id: 'remote-id',
|
|
80
|
-
type: 'CICD',
|
|
81
|
-
mountPath: 'remote-mount-path',
|
|
82
|
-
mountBranchName: 'remote-mount-branch-name',
|
|
83
|
-
organizationId: testOrg,
|
|
84
|
-
projectId: testProject,
|
|
85
|
-
};
|
|
86
|
-
let apiClient;
|
|
87
|
-
beforeEach(() => {
|
|
88
|
-
apiClient = new api_client_1.ReuniteApi({ domain: testDomain, apiKey: testToken, version, command });
|
|
89
|
-
});
|
|
90
|
-
it('should upsert remote', async () => {
|
|
91
|
-
mockFetchResponse({
|
|
92
|
-
ok: true,
|
|
93
|
-
json: jest.fn().mockResolvedValue(responseMock),
|
|
94
|
-
});
|
|
95
|
-
const result = await apiClient.remotes.upsert(testOrg, testProject, remotePayload);
|
|
96
|
-
expect(global.fetch).toHaveBeenCalledWith(`${testDomain}/api/orgs/${testOrg}/projects/${testProject}/remotes`, {
|
|
97
|
-
method: 'POST',
|
|
98
|
-
headers: {
|
|
99
|
-
'Content-Type': 'application/json',
|
|
100
|
-
Authorization: `Bearer ${testToken}`,
|
|
101
|
-
'user-agent': expectedUserAgent,
|
|
102
|
-
},
|
|
103
|
-
body: JSON.stringify({
|
|
104
|
-
mountPath: remotePayload.mountPath,
|
|
105
|
-
mountBranchName: remotePayload.mountBranchName,
|
|
106
|
-
type: 'CICD',
|
|
107
|
-
autoMerge: true,
|
|
108
|
-
}),
|
|
109
|
-
signal: expect.any(Object),
|
|
110
|
-
agent: undefined,
|
|
111
|
-
});
|
|
112
|
-
expect(result).toEqual(responseMock);
|
|
113
|
-
});
|
|
114
|
-
it('should throw parsed error if response is not ok', async () => {
|
|
115
|
-
mockFetchResponse({
|
|
116
|
-
ok: false,
|
|
117
|
-
json: jest.fn().mockResolvedValue({
|
|
118
|
-
type: 'about:blank',
|
|
119
|
-
title: 'Not allowed to mount remote outside of project content path: /docs',
|
|
120
|
-
status: 403,
|
|
121
|
-
detail: 'Forbidden',
|
|
122
|
-
object: 'problem',
|
|
123
|
-
}),
|
|
124
|
-
});
|
|
125
|
-
await expect(apiClient.remotes.upsert(testOrg, testProject, remotePayload)).rejects.toThrow(new api_client_1.ReuniteApiError('Failed to upsert remote. Not allowed to mount remote outside of project content path: /docs.', 403));
|
|
126
|
-
});
|
|
127
|
-
it('should throw statusText error if response is not ok', async () => {
|
|
128
|
-
mockFetchResponse({
|
|
129
|
-
ok: false,
|
|
130
|
-
status: 404,
|
|
131
|
-
statusText: 'Not found',
|
|
132
|
-
json: jest.fn().mockResolvedValue({
|
|
133
|
-
unknownField: 'unknown-error',
|
|
134
|
-
}),
|
|
135
|
-
});
|
|
136
|
-
await expect(apiClient.remotes.upsert(testOrg, testProject, remotePayload)).rejects.toThrow(new api_client_1.ReuniteApiError('Failed to upsert remote. Not found.', 404));
|
|
137
|
-
});
|
|
138
|
-
});
|
|
139
|
-
describe('push()', () => {
|
|
140
|
-
const testRemoteId = 'test-remote-id';
|
|
141
|
-
const pushPayload = {
|
|
142
|
-
remoteId: testRemoteId,
|
|
143
|
-
commit: {
|
|
144
|
-
message: 'test-message',
|
|
145
|
-
author: {
|
|
146
|
-
name: 'test-name',
|
|
147
|
-
email: 'test-email',
|
|
148
|
-
},
|
|
149
|
-
branchName: 'test-branch-name',
|
|
150
|
-
},
|
|
151
|
-
};
|
|
152
|
-
const filesMock = [{ path: 'some-file.yaml', stream: Buffer.from('fefef') }];
|
|
153
|
-
const responseMock = {
|
|
154
|
-
branchName: 'rem/cicd/rem_01he7sr6ys2agb7w0g9t7978fn-main',
|
|
155
|
-
hasChanges: true,
|
|
156
|
-
files: [
|
|
157
|
-
{
|
|
158
|
-
type: 'file',
|
|
159
|
-
name: 'some-file.yaml',
|
|
160
|
-
path: 'docs/remotes/some-file.yaml',
|
|
161
|
-
lastModified: 1698925132394.2993,
|
|
162
|
-
mimeType: 'text/yaml',
|
|
163
|
-
},
|
|
164
|
-
],
|
|
165
|
-
commitSha: 'bb23a2f8e012ac0b7b9961b57fb40d8686b21b43',
|
|
166
|
-
outdated: false,
|
|
167
|
-
};
|
|
168
|
-
let apiClient;
|
|
169
|
-
beforeEach(() => {
|
|
170
|
-
apiClient = new api_client_1.ReuniteApi({ domain: testDomain, apiKey: testToken, version, command });
|
|
171
|
-
});
|
|
172
|
-
it('should push to remote', async () => {
|
|
173
|
-
let passedFormData = new FormData();
|
|
174
|
-
fetch.mockImplementationOnce(async (_, options) => {
|
|
175
|
-
passedFormData = options.body;
|
|
176
|
-
return {
|
|
177
|
-
ok: true,
|
|
178
|
-
json: jest.fn().mockResolvedValue(responseMock),
|
|
179
|
-
};
|
|
180
|
-
});
|
|
181
|
-
const formData = new globalThis.FormData();
|
|
182
|
-
formData.append('remoteId', testRemoteId);
|
|
183
|
-
formData.append('commit[message]', pushPayload.commit.message);
|
|
184
|
-
formData.append('commit[author][name]', pushPayload.commit.author.name);
|
|
185
|
-
formData.append('commit[author][email]', pushPayload.commit.author.email);
|
|
186
|
-
formData.append('commit[branchName]', pushPayload.commit.branchName);
|
|
187
|
-
formData.append('files[some-file.yaml]', new Blob([filesMock[0].stream]));
|
|
188
|
-
const result = await apiClient.remotes.push(testOrg, testProject, pushPayload, filesMock);
|
|
189
|
-
expect(fetch).toHaveBeenCalledWith(`${testDomain}/api/orgs/${testOrg}/projects/${testProject}/pushes`, expect.objectContaining({
|
|
190
|
-
method: 'POST',
|
|
191
|
-
headers: {
|
|
192
|
-
Authorization: `Bearer ${testToken}`,
|
|
193
|
-
'user-agent': expectedUserAgent,
|
|
194
|
-
},
|
|
195
|
-
}));
|
|
196
|
-
expect(passedFormData).toEqual(formData);
|
|
197
|
-
expect(result).toEqual(responseMock);
|
|
198
|
-
});
|
|
199
|
-
it('should throw parsed error if response is not ok', async () => {
|
|
200
|
-
mockFetchResponse({
|
|
201
|
-
ok: false,
|
|
202
|
-
json: jest.fn().mockResolvedValue({
|
|
203
|
-
type: 'about:blank',
|
|
204
|
-
title: 'Cannot push to remote',
|
|
205
|
-
status: 403,
|
|
206
|
-
detail: 'Forbidden',
|
|
207
|
-
object: 'problem',
|
|
208
|
-
}),
|
|
209
|
-
});
|
|
210
|
-
await expect(apiClient.remotes.push(testOrg, testProject, pushPayload, filesMock)).rejects.toThrow(new api_client_1.ReuniteApiError('Failed to push. Cannot push to remote.', 403));
|
|
211
|
-
});
|
|
212
|
-
it('should throw statusText error if response is not ok', async () => {
|
|
213
|
-
mockFetchResponse({
|
|
214
|
-
ok: false,
|
|
215
|
-
status: 404,
|
|
216
|
-
statusText: 'Not found',
|
|
217
|
-
json: jest.fn().mockResolvedValue({
|
|
218
|
-
unknownField: 'unknown-error',
|
|
219
|
-
}),
|
|
220
|
-
});
|
|
221
|
-
await expect(apiClient.remotes.push(testOrg, testProject, pushPayload, filesMock)).rejects.toThrow(new api_client_1.ReuniteApiError('Failed to push. Not found.', 404));
|
|
222
|
-
});
|
|
223
|
-
});
|
|
224
|
-
describe('Sunset header', () => {
|
|
225
|
-
const upsertRemoteMock = {
|
|
226
|
-
requestFn: () => apiClient.remotes.upsert(testOrg, testProject, {
|
|
227
|
-
mountBranchName: 'remote-mount-branch-name',
|
|
228
|
-
mountPath: 'remote-mount-path',
|
|
229
|
-
}),
|
|
230
|
-
responseBody: {
|
|
231
|
-
id: 'remote-id',
|
|
232
|
-
type: 'CICD',
|
|
233
|
-
mountPath: 'remote-mount-path',
|
|
234
|
-
mountBranchName: 'remote-mount-branch-name',
|
|
235
|
-
organizationId: testOrg,
|
|
236
|
-
projectId: testProject,
|
|
237
|
-
},
|
|
238
|
-
};
|
|
239
|
-
const getDefaultBranchMock = {
|
|
240
|
-
requestFn: () => apiClient.remotes.getDefaultBranch(testOrg, testProject),
|
|
241
|
-
responseBody: {
|
|
242
|
-
branchName: 'test-branch',
|
|
243
|
-
},
|
|
244
|
-
};
|
|
245
|
-
const pushMock = {
|
|
246
|
-
requestFn: () => apiClient.remotes.push(testOrg, testProject, {
|
|
247
|
-
remoteId: 'test-remote-id',
|
|
248
|
-
commit: {
|
|
249
|
-
message: 'test-message',
|
|
250
|
-
author: {
|
|
251
|
-
name: 'test-name',
|
|
252
|
-
email: 'test-email',
|
|
253
|
-
},
|
|
254
|
-
branchName: 'test-branch-name',
|
|
255
|
-
},
|
|
256
|
-
}, [{ path: 'some-file.yaml', stream: Buffer.from('text content') }]),
|
|
257
|
-
responseBody: {
|
|
258
|
-
branchName: 'rem/cicd/rem_01he7sr6ys2agb7w0g9t7978fn-main',
|
|
259
|
-
hasChanges: true,
|
|
260
|
-
files: [
|
|
261
|
-
{
|
|
262
|
-
type: 'file',
|
|
263
|
-
name: 'some-file.yaml',
|
|
264
|
-
path: 'docs/remotes/some-file.yaml',
|
|
265
|
-
lastModified: 1698925132394.2993,
|
|
266
|
-
mimeType: 'text/yaml',
|
|
267
|
-
},
|
|
268
|
-
],
|
|
269
|
-
commitSha: 'bb23a2f8e012ac0b7b9961b57fb40d8686b21b43',
|
|
270
|
-
outdated: false,
|
|
271
|
-
},
|
|
272
|
-
};
|
|
273
|
-
const endpointMocks = [upsertRemoteMock, getDefaultBranchMock, pushMock];
|
|
274
|
-
let apiClient;
|
|
275
|
-
beforeEach(() => {
|
|
276
|
-
apiClient = new api_client_1.ReuniteApi({ domain: testDomain, apiKey: testToken, version, command });
|
|
277
|
-
});
|
|
278
|
-
it.each(endpointMocks)('should report endpoint sunset in the past', async ({ responseBody, requestFn }) => {
|
|
279
|
-
jest.spyOn(process.stdout, 'write').mockImplementationOnce(() => true);
|
|
280
|
-
const sunsetDate = new Date('2024-09-06T12:30:32.456Z');
|
|
281
|
-
mockFetchResponse({
|
|
282
|
-
ok: true,
|
|
283
|
-
json: jest.fn().mockResolvedValue(responseBody),
|
|
284
|
-
headers: new Headers({
|
|
285
|
-
Sunset: sunsetDate.toISOString(),
|
|
286
|
-
}),
|
|
287
|
-
});
|
|
288
|
-
await requestFn();
|
|
289
|
-
apiClient.reportSunsetWarnings();
|
|
290
|
-
expect(process.stdout.write).toHaveBeenCalledWith((0, colorette_1.red)(`The "push" command is not compatible with your version of Redocly CLI. Update to the latest version by running "npm install @redocly/cli@latest".\n\n`));
|
|
291
|
-
});
|
|
292
|
-
it.each(endpointMocks)('should report endpoint sunset in the future', async ({ responseBody, requestFn }) => {
|
|
293
|
-
jest.spyOn(process.stdout, 'write').mockImplementationOnce(() => true);
|
|
294
|
-
const sunsetDate = new Date(Date.now() + 1000 * 60 * 60 * 24);
|
|
295
|
-
mockFetchResponse({
|
|
296
|
-
ok: true,
|
|
297
|
-
json: jest.fn().mockResolvedValue(responseBody),
|
|
298
|
-
headers: new Headers({
|
|
299
|
-
Sunset: sunsetDate.toISOString(),
|
|
300
|
-
}),
|
|
301
|
-
});
|
|
302
|
-
await requestFn();
|
|
303
|
-
apiClient.reportSunsetWarnings();
|
|
304
|
-
expect(process.stdout.write).toHaveBeenCalledWith((0, colorette_1.yellow)(`The "push" command will be incompatible with your version of Redocly CLI after ${sunsetDate.toLocaleString()}. Update to the latest version by running "npm install @redocly/cli@latest".\n\n`));
|
|
305
|
-
});
|
|
306
|
-
it('should report only expired resource', async () => {
|
|
307
|
-
jest.spyOn(process.stdout, 'write').mockImplementationOnce(() => true);
|
|
308
|
-
mockFetchResponse({
|
|
309
|
-
ok: true,
|
|
310
|
-
json: jest.fn().mockResolvedValue(upsertRemoteMock.responseBody),
|
|
311
|
-
headers: new Headers({
|
|
312
|
-
Sunset: new Date('2024-08-06T12:30:32.456Z').toISOString(),
|
|
313
|
-
}),
|
|
314
|
-
});
|
|
315
|
-
await upsertRemoteMock.requestFn();
|
|
316
|
-
mockFetchResponse({
|
|
317
|
-
ok: true,
|
|
318
|
-
json: jest.fn().mockResolvedValue(getDefaultBranchMock.responseBody),
|
|
319
|
-
headers: new Headers({
|
|
320
|
-
Sunset: new Date(Date.now() + 1000 * 60 * 60 * 24).toISOString(),
|
|
321
|
-
}),
|
|
322
|
-
});
|
|
323
|
-
await getDefaultBranchMock.requestFn();
|
|
324
|
-
mockFetchResponse({
|
|
325
|
-
ok: true,
|
|
326
|
-
json: jest.fn().mockResolvedValue(pushMock.responseBody),
|
|
327
|
-
headers: new Headers({
|
|
328
|
-
Sunset: new Date('2024-08-06T12:30:32.456Z').toISOString(),
|
|
329
|
-
}),
|
|
330
|
-
});
|
|
331
|
-
await pushMock.requestFn();
|
|
332
|
-
apiClient.reportSunsetWarnings();
|
|
333
|
-
expect(process.stdout.write).toHaveBeenCalledTimes(1);
|
|
334
|
-
expect(process.stdout.write).toHaveBeenCalledWith((0, colorette_1.red)(`The "push" command is not compatible with your version of Redocly CLI. Update to the latest version by running "npm install @redocly/cli@latest".\n\n`));
|
|
335
|
-
});
|
|
336
|
-
});
|
|
337
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const domains_1 = require("../domains");
|
|
4
|
-
const domains_2 = require("../domains");
|
|
5
|
-
describe('getDomain()', () => {
|
|
6
|
-
afterEach(() => {
|
|
7
|
-
delete process.env.REDOCLY_DOMAIN;
|
|
8
|
-
});
|
|
9
|
-
it('should return the domain from environment variable', () => {
|
|
10
|
-
process.env.REDOCLY_DOMAIN = 'test-domain';
|
|
11
|
-
expect((0, domains_1.getDomain)()).toBe('test-domain');
|
|
12
|
-
});
|
|
13
|
-
it('should return the default domain if no domain provided', () => {
|
|
14
|
-
process.env.REDOCLY_DOMAIN = '';
|
|
15
|
-
expect((0, domains_1.getDomain)()).toBe('https://app.cloud.redocly.com');
|
|
16
|
-
});
|
|
17
|
-
});
|
|
18
|
-
describe('getReuniteUrl()', () => {
|
|
19
|
-
it('should return US API URL when US region specified', () => {
|
|
20
|
-
expect((0, domains_2.getReuniteUrl)('us')).toBe('https://app.cloud.redocly.com/api');
|
|
21
|
-
});
|
|
22
|
-
it('should return EU API URL when EU region specified', () => {
|
|
23
|
-
expect((0, domains_2.getReuniteUrl)('eu')).toBe('https://app.cloud.eu.redocly.com/api');
|
|
24
|
-
});
|
|
25
|
-
it('should return custom domain API URL when custom domain specified', () => {
|
|
26
|
-
const customDomain = 'https://custom.domain.com';
|
|
27
|
-
expect((0, domains_2.getReuniteUrl)(customDomain)).toBe('https://custom.domain.com/api');
|
|
28
|
-
});
|
|
29
|
-
it('should return US API URL when no region specified', () => {
|
|
30
|
-
expect((0, domains_2.getReuniteUrl)()).toBe('https://app.cloud.redocly.com/api');
|
|
31
|
-
});
|
|
32
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|