@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,381 +0,0 @@
|
|
|
1
|
-
import { yellow, red } from 'colorette';
|
|
2
|
-
import fetchWithTimeout, {
|
|
3
|
-
type FetchWithTimeoutOptions,
|
|
4
|
-
DEFAULT_FETCH_TIMEOUT,
|
|
5
|
-
} from '../../utils/fetch-with-timeout';
|
|
6
|
-
|
|
7
|
-
import type { ReadStream } from 'fs';
|
|
8
|
-
import type { Readable } from 'node:stream';
|
|
9
|
-
import type {
|
|
10
|
-
ListRemotesResponse,
|
|
11
|
-
ProjectSourceResponse,
|
|
12
|
-
PushResponse,
|
|
13
|
-
UpsertRemoteResponse,
|
|
14
|
-
} from './types';
|
|
15
|
-
|
|
16
|
-
interface BaseApiClient {
|
|
17
|
-
request(url: string, options: FetchWithTimeoutOptions): Promise<Response>;
|
|
18
|
-
}
|
|
19
|
-
type CommandOption = 'push' | 'push-status';
|
|
20
|
-
export type SunsetWarning = { sunsetDate: Date; isSunsetExpired: boolean };
|
|
21
|
-
export type SunsetWarningsBuffer = SunsetWarning[];
|
|
22
|
-
|
|
23
|
-
export class ReuniteApiError extends Error {
|
|
24
|
-
constructor(message: string, public status: number) {
|
|
25
|
-
super(message);
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
export class ReuniteApiClient implements BaseApiClient {
|
|
30
|
-
public sunsetWarnings: SunsetWarningsBuffer = [];
|
|
31
|
-
|
|
32
|
-
constructor(protected version: string, protected command: string) {}
|
|
33
|
-
|
|
34
|
-
public async request(url: string, options: FetchWithTimeoutOptions) {
|
|
35
|
-
const headers = {
|
|
36
|
-
...options.headers,
|
|
37
|
-
'user-agent': `redocly-cli/${this.version.trim()} ${this.command}`,
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
const response = await fetchWithTimeout(url, {
|
|
41
|
-
...options,
|
|
42
|
-
headers,
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
this.collectSunsetWarning(response);
|
|
46
|
-
|
|
47
|
-
return response;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
private collectSunsetWarning(response: Response) {
|
|
51
|
-
const sunsetTime = this.getSunsetDate(response);
|
|
52
|
-
|
|
53
|
-
if (!sunsetTime) return;
|
|
54
|
-
|
|
55
|
-
const sunsetDate = new Date(sunsetTime);
|
|
56
|
-
|
|
57
|
-
if (sunsetTime > Date.now()) {
|
|
58
|
-
this.sunsetWarnings.push({
|
|
59
|
-
sunsetDate,
|
|
60
|
-
isSunsetExpired: false,
|
|
61
|
-
});
|
|
62
|
-
} else {
|
|
63
|
-
this.sunsetWarnings.push({
|
|
64
|
-
sunsetDate,
|
|
65
|
-
isSunsetExpired: true,
|
|
66
|
-
});
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
private getSunsetDate(response: Response): number | undefined {
|
|
71
|
-
const { headers } = response;
|
|
72
|
-
|
|
73
|
-
if (!headers) {
|
|
74
|
-
return;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
const sunsetDate = headers.get('sunset') || headers.get('Sunset');
|
|
78
|
-
|
|
79
|
-
if (!sunsetDate) {
|
|
80
|
-
return;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
return Date.parse(sunsetDate);
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
class RemotesApi {
|
|
88
|
-
constructor(
|
|
89
|
-
private client: BaseApiClient,
|
|
90
|
-
private readonly domain: string,
|
|
91
|
-
private readonly apiKey: string
|
|
92
|
-
) {}
|
|
93
|
-
|
|
94
|
-
protected async getParsedResponse<T>(response: Response): Promise<T> {
|
|
95
|
-
const responseBody = await response.json();
|
|
96
|
-
|
|
97
|
-
if (response.ok) {
|
|
98
|
-
return responseBody as T;
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
throw new ReuniteApiError(
|
|
102
|
-
`${responseBody.title || response.statusText || 'Unknown error'}.`,
|
|
103
|
-
response.status
|
|
104
|
-
);
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
async getDefaultBranch(organizationId: string, projectId: string) {
|
|
108
|
-
try {
|
|
109
|
-
const response = await this.client.request(
|
|
110
|
-
`${this.domain}/api/orgs/${organizationId}/projects/${projectId}/source`,
|
|
111
|
-
{
|
|
112
|
-
timeout: DEFAULT_FETCH_TIMEOUT,
|
|
113
|
-
method: 'GET',
|
|
114
|
-
headers: {
|
|
115
|
-
'Content-Type': 'application/json',
|
|
116
|
-
Authorization: `Bearer ${this.apiKey}`,
|
|
117
|
-
},
|
|
118
|
-
}
|
|
119
|
-
);
|
|
120
|
-
|
|
121
|
-
const source = await this.getParsedResponse<ProjectSourceResponse>(response);
|
|
122
|
-
|
|
123
|
-
return source.branchName;
|
|
124
|
-
} catch (err) {
|
|
125
|
-
const message = `Failed to fetch default branch. ${err.message}`;
|
|
126
|
-
|
|
127
|
-
if (err instanceof ReuniteApiError) {
|
|
128
|
-
throw new ReuniteApiError(message, err.status);
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
throw new Error(message);
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
async upsert(
|
|
136
|
-
organizationId: string,
|
|
137
|
-
projectId: string,
|
|
138
|
-
remote: {
|
|
139
|
-
mountPath: string;
|
|
140
|
-
mountBranchName: string;
|
|
141
|
-
}
|
|
142
|
-
): Promise<UpsertRemoteResponse> {
|
|
143
|
-
try {
|
|
144
|
-
const response = await this.client.request(
|
|
145
|
-
`${this.domain}/api/orgs/${organizationId}/projects/${projectId}/remotes`,
|
|
146
|
-
{
|
|
147
|
-
timeout: DEFAULT_FETCH_TIMEOUT,
|
|
148
|
-
method: 'POST',
|
|
149
|
-
headers: {
|
|
150
|
-
'Content-Type': 'application/json',
|
|
151
|
-
Authorization: `Bearer ${this.apiKey}`,
|
|
152
|
-
},
|
|
153
|
-
body: JSON.stringify({
|
|
154
|
-
mountPath: remote.mountPath,
|
|
155
|
-
mountBranchName: remote.mountBranchName,
|
|
156
|
-
type: 'CICD',
|
|
157
|
-
autoMerge: true,
|
|
158
|
-
}),
|
|
159
|
-
}
|
|
160
|
-
);
|
|
161
|
-
|
|
162
|
-
return await this.getParsedResponse<UpsertRemoteResponse>(response);
|
|
163
|
-
} catch (err) {
|
|
164
|
-
const message = `Failed to upsert remote. ${err.message}`;
|
|
165
|
-
|
|
166
|
-
if (err instanceof ReuniteApiError) {
|
|
167
|
-
throw new ReuniteApiError(message, err.status);
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
throw new Error(message);
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
async push(
|
|
175
|
-
organizationId: string,
|
|
176
|
-
projectId: string,
|
|
177
|
-
payload: PushPayload,
|
|
178
|
-
files: { path: string; stream: ReadStream | Buffer }[]
|
|
179
|
-
): Promise<PushResponse> {
|
|
180
|
-
const formData = new globalThis.FormData();
|
|
181
|
-
|
|
182
|
-
formData.append('remoteId', payload.remoteId);
|
|
183
|
-
formData.append('commit[message]', payload.commit.message);
|
|
184
|
-
formData.append('commit[author][name]', payload.commit.author.name);
|
|
185
|
-
formData.append('commit[author][email]', payload.commit.author.email);
|
|
186
|
-
formData.append('commit[branchName]', payload.commit.branchName);
|
|
187
|
-
payload.commit.url && formData.append('commit[url]', payload.commit.url);
|
|
188
|
-
payload.commit.namespace && formData.append('commit[namespaceId]', payload.commit.namespace);
|
|
189
|
-
payload.commit.sha && formData.append('commit[sha]', payload.commit.sha);
|
|
190
|
-
payload.commit.repository && formData.append('commit[repositoryId]', payload.commit.repository);
|
|
191
|
-
payload.commit.createdAt && formData.append('commit[createdAt]', payload.commit.createdAt);
|
|
192
|
-
|
|
193
|
-
for (const file of files) {
|
|
194
|
-
const blob = Buffer.isBuffer(file.stream)
|
|
195
|
-
? new Blob([file.stream])
|
|
196
|
-
: new Blob([await streamToBuffer(file.stream)]);
|
|
197
|
-
formData.append(`files[${file.path}]`, blob, file.path);
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
payload.isMainBranch && formData.append('isMainBranch', 'true');
|
|
201
|
-
try {
|
|
202
|
-
const response = await this.client.request(
|
|
203
|
-
`${this.domain}/api/orgs/${organizationId}/projects/${projectId}/pushes`,
|
|
204
|
-
{
|
|
205
|
-
method: 'POST',
|
|
206
|
-
headers: {
|
|
207
|
-
Authorization: `Bearer ${this.apiKey}`,
|
|
208
|
-
},
|
|
209
|
-
body: formData,
|
|
210
|
-
}
|
|
211
|
-
);
|
|
212
|
-
|
|
213
|
-
return await this.getParsedResponse<PushResponse>(response);
|
|
214
|
-
} catch (err) {
|
|
215
|
-
const message = `Failed to push. ${err.message}`;
|
|
216
|
-
|
|
217
|
-
if (err instanceof ReuniteApiError) {
|
|
218
|
-
throw new ReuniteApiError(message, err.status);
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
throw new Error(message);
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
async getRemotesList({
|
|
226
|
-
organizationId,
|
|
227
|
-
projectId,
|
|
228
|
-
mountPath,
|
|
229
|
-
}: {
|
|
230
|
-
organizationId: string;
|
|
231
|
-
projectId: string;
|
|
232
|
-
mountPath: string;
|
|
233
|
-
}) {
|
|
234
|
-
try {
|
|
235
|
-
const response = await this.client.request(
|
|
236
|
-
`${this.domain}/api/orgs/${organizationId}/projects/${projectId}/remotes?filter=mountPath:/${mountPath}/`,
|
|
237
|
-
{
|
|
238
|
-
timeout: DEFAULT_FETCH_TIMEOUT,
|
|
239
|
-
method: 'GET',
|
|
240
|
-
headers: {
|
|
241
|
-
'Content-Type': 'application/json',
|
|
242
|
-
Authorization: `Bearer ${this.apiKey}`,
|
|
243
|
-
},
|
|
244
|
-
}
|
|
245
|
-
);
|
|
246
|
-
|
|
247
|
-
return await this.getParsedResponse<ListRemotesResponse>(response);
|
|
248
|
-
} catch (err) {
|
|
249
|
-
const message = `Failed to get remote list. ${err.message}`;
|
|
250
|
-
|
|
251
|
-
if (err instanceof ReuniteApiError) {
|
|
252
|
-
throw new ReuniteApiError(message, err.status);
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
throw new Error(message);
|
|
256
|
-
}
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
async getPush({
|
|
260
|
-
organizationId,
|
|
261
|
-
projectId,
|
|
262
|
-
pushId,
|
|
263
|
-
}: {
|
|
264
|
-
organizationId: string;
|
|
265
|
-
projectId: string;
|
|
266
|
-
pushId: string;
|
|
267
|
-
}) {
|
|
268
|
-
try {
|
|
269
|
-
const response = await this.client.request(
|
|
270
|
-
`${this.domain}/api/orgs/${organizationId}/projects/${projectId}/pushes/${pushId}`,
|
|
271
|
-
{
|
|
272
|
-
timeout: DEFAULT_FETCH_TIMEOUT,
|
|
273
|
-
method: 'GET',
|
|
274
|
-
headers: {
|
|
275
|
-
'Content-Type': 'application/json',
|
|
276
|
-
Authorization: `Bearer ${this.apiKey}`,
|
|
277
|
-
},
|
|
278
|
-
}
|
|
279
|
-
);
|
|
280
|
-
|
|
281
|
-
return await this.getParsedResponse<PushResponse>(response);
|
|
282
|
-
} catch (err) {
|
|
283
|
-
const message = `Failed to get push status. ${err.message}`;
|
|
284
|
-
|
|
285
|
-
if (err instanceof ReuniteApiError) {
|
|
286
|
-
throw new ReuniteApiError(message, err.status);
|
|
287
|
-
}
|
|
288
|
-
|
|
289
|
-
throw new Error(message);
|
|
290
|
-
}
|
|
291
|
-
}
|
|
292
|
-
}
|
|
293
|
-
|
|
294
|
-
export class ReuniteApi {
|
|
295
|
-
private apiClient: ReuniteApiClient;
|
|
296
|
-
private version: string;
|
|
297
|
-
private command: CommandOption;
|
|
298
|
-
|
|
299
|
-
public remotes: RemotesApi;
|
|
300
|
-
|
|
301
|
-
constructor({
|
|
302
|
-
domain,
|
|
303
|
-
apiKey,
|
|
304
|
-
version,
|
|
305
|
-
command,
|
|
306
|
-
}: {
|
|
307
|
-
domain: string;
|
|
308
|
-
apiKey: string;
|
|
309
|
-
version: string;
|
|
310
|
-
command: CommandOption;
|
|
311
|
-
}) {
|
|
312
|
-
this.command = command;
|
|
313
|
-
this.version = version;
|
|
314
|
-
this.apiClient = new ReuniteApiClient(this.version, this.command);
|
|
315
|
-
|
|
316
|
-
this.remotes = new RemotesApi(this.apiClient, domain, apiKey);
|
|
317
|
-
}
|
|
318
|
-
|
|
319
|
-
public reportSunsetWarnings(): void {
|
|
320
|
-
const sunsetWarnings = this.apiClient.sunsetWarnings;
|
|
321
|
-
|
|
322
|
-
if (sunsetWarnings.length) {
|
|
323
|
-
const [{ isSunsetExpired, sunsetDate }] = sunsetWarnings.sort(
|
|
324
|
-
(a: SunsetWarning, b: SunsetWarning) => {
|
|
325
|
-
// First, prioritize by expiration status
|
|
326
|
-
if (a.isSunsetExpired !== b.isSunsetExpired) {
|
|
327
|
-
return a.isSunsetExpired ? -1 : 1;
|
|
328
|
-
}
|
|
329
|
-
|
|
330
|
-
// If both are either expired or not, sort by sunset date
|
|
331
|
-
return a.sunsetDate > b.sunsetDate ? 1 : -1;
|
|
332
|
-
}
|
|
333
|
-
);
|
|
334
|
-
|
|
335
|
-
const updateVersionMessage = `Update to the latest version by running "npm install @redocly/cli@latest".`;
|
|
336
|
-
|
|
337
|
-
if (isSunsetExpired) {
|
|
338
|
-
process.stdout.write(
|
|
339
|
-
red(
|
|
340
|
-
`The "${this.command}" command is not compatible with your version of Redocly CLI. ${updateVersionMessage}\n\n`
|
|
341
|
-
)
|
|
342
|
-
);
|
|
343
|
-
} else {
|
|
344
|
-
process.stdout.write(
|
|
345
|
-
yellow(
|
|
346
|
-
`The "${
|
|
347
|
-
this.command
|
|
348
|
-
}" command will be incompatible with your version of Redocly CLI after ${sunsetDate.toLocaleString()}. ${updateVersionMessage}\n\n`
|
|
349
|
-
)
|
|
350
|
-
);
|
|
351
|
-
}
|
|
352
|
-
}
|
|
353
|
-
}
|
|
354
|
-
}
|
|
355
|
-
|
|
356
|
-
export type PushPayload = {
|
|
357
|
-
remoteId: string;
|
|
358
|
-
commit: {
|
|
359
|
-
message: string;
|
|
360
|
-
branchName: string;
|
|
361
|
-
sha?: string;
|
|
362
|
-
url?: string;
|
|
363
|
-
createdAt?: string;
|
|
364
|
-
namespace?: string;
|
|
365
|
-
repository?: string;
|
|
366
|
-
author: {
|
|
367
|
-
name: string;
|
|
368
|
-
email: string;
|
|
369
|
-
image?: string;
|
|
370
|
-
};
|
|
371
|
-
};
|
|
372
|
-
isMainBranch?: boolean;
|
|
373
|
-
};
|
|
374
|
-
|
|
375
|
-
export async function streamToBuffer(stream: ReadStream | Readable): Promise<Buffer> {
|
|
376
|
-
const chunks: Buffer[] = [];
|
|
377
|
-
for await (const chunk of stream) {
|
|
378
|
-
chunks.push(chunk);
|
|
379
|
-
}
|
|
380
|
-
return Buffer.concat(chunks);
|
|
381
|
-
}
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { resolve } from 'path';
|
|
2
|
-
import { homedir } from 'os';
|
|
3
|
-
import { existsSync, readFileSync } from 'fs';
|
|
4
|
-
import { isNotEmptyObject } from '@redocly/openapi-core/lib/utils';
|
|
5
|
-
import { TOKEN_FILENAME } from '@redocly/openapi-core/lib/redocly';
|
|
6
|
-
|
|
7
|
-
function readCredentialsFile(credentialsPath: string) {
|
|
8
|
-
return existsSync(credentialsPath) ? JSON.parse(readFileSync(credentialsPath, 'utf-8')) : {};
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export function getApiKeys(domain: string) {
|
|
12
|
-
const apiKey = process.env.REDOCLY_AUTHORIZATION;
|
|
13
|
-
|
|
14
|
-
if (apiKey) {
|
|
15
|
-
return apiKey;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
const credentialsPath = resolve(homedir(), TOKEN_FILENAME);
|
|
19
|
-
const credentials = readCredentialsFile(credentialsPath);
|
|
20
|
-
|
|
21
|
-
if (isNotEmptyObject(credentials) && credentials[domain]) {
|
|
22
|
-
return credentials[domain];
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
throw new Error('No api key provided, please use environment variable REDOCLY_AUTHORIZATION.');
|
|
26
|
-
}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import type { Region } from '@redocly/openapi-core';
|
|
2
|
-
|
|
3
|
-
export const REUNITE_URLS: Record<Region, string> = {
|
|
4
|
-
us: 'https://app.cloud.redocly.com',
|
|
5
|
-
eu: 'https://app.cloud.eu.redocly.com',
|
|
6
|
-
} as const;
|
|
7
|
-
|
|
8
|
-
export function getDomain(): string {
|
|
9
|
-
return process.env.REDOCLY_DOMAIN || REUNITE_URLS.us;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export function getReuniteUrl(residency?: string) {
|
|
13
|
-
if (!residency) residency = 'us';
|
|
14
|
-
|
|
15
|
-
let reuniteUrl: string = REUNITE_URLS[residency as Region];
|
|
16
|
-
|
|
17
|
-
if (!reuniteUrl) {
|
|
18
|
-
reuniteUrl = residency;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
const url = new URL('/api', reuniteUrl).toString();
|
|
22
|
-
return url;
|
|
23
|
-
}
|
package/src/reunite/api/index.ts
DELETED
package/src/reunite/api/types.ts
DELETED
|
@@ -1,108 +0,0 @@
|
|
|
1
|
-
export type ProjectSourceResponse = {
|
|
2
|
-
branchName: string;
|
|
3
|
-
contentPath: string;
|
|
4
|
-
isInternal: boolean;
|
|
5
|
-
};
|
|
6
|
-
|
|
7
|
-
export type UpsertRemoteResponse = {
|
|
8
|
-
id: string;
|
|
9
|
-
type: 'CICD';
|
|
10
|
-
mountPath: string;
|
|
11
|
-
mountBranchName: string;
|
|
12
|
-
organizationId: string;
|
|
13
|
-
projectId: string;
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
export type ListRemotesResponse = {
|
|
17
|
-
object: 'list';
|
|
18
|
-
page: {
|
|
19
|
-
endCursor: string;
|
|
20
|
-
startCursor: string;
|
|
21
|
-
haxNextPage: boolean;
|
|
22
|
-
hasPrevPage: boolean;
|
|
23
|
-
limit: number;
|
|
24
|
-
total: number;
|
|
25
|
-
};
|
|
26
|
-
items: Remote[];
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
export type Remote = {
|
|
30
|
-
mountPath: string;
|
|
31
|
-
type: string;
|
|
32
|
-
autoSync: boolean;
|
|
33
|
-
autoMerge: boolean;
|
|
34
|
-
createdAt: string;
|
|
35
|
-
updatedAt: string;
|
|
36
|
-
providerType: string;
|
|
37
|
-
namespaceId: string;
|
|
38
|
-
repositoryId: string;
|
|
39
|
-
projectId: string;
|
|
40
|
-
mountBranchName: string;
|
|
41
|
-
contentPath: string;
|
|
42
|
-
credentialId: string;
|
|
43
|
-
branchName: string;
|
|
44
|
-
contentType: string;
|
|
45
|
-
id: string;
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
export type PushResponse = {
|
|
49
|
-
id: string;
|
|
50
|
-
remoteId: string;
|
|
51
|
-
isMainBranch: boolean;
|
|
52
|
-
isOutdated: boolean;
|
|
53
|
-
hasChanges: boolean;
|
|
54
|
-
replace: boolean;
|
|
55
|
-
scoutJobId: string | null;
|
|
56
|
-
uploadedFiles: Array<{ path: string; mimeType: string }>;
|
|
57
|
-
commit: {
|
|
58
|
-
branchName: string;
|
|
59
|
-
message: string;
|
|
60
|
-
createdAt: string | null;
|
|
61
|
-
namespaceId: string | null;
|
|
62
|
-
repositoryId: string | null;
|
|
63
|
-
url: string | null;
|
|
64
|
-
sha: string | null;
|
|
65
|
-
author: {
|
|
66
|
-
name: string;
|
|
67
|
-
email: string;
|
|
68
|
-
image: string | null;
|
|
69
|
-
};
|
|
70
|
-
statuses: Array<{
|
|
71
|
-
name: string;
|
|
72
|
-
description: string;
|
|
73
|
-
status: 'pending' | 'running' | 'success' | 'failed';
|
|
74
|
-
url: string | null;
|
|
75
|
-
}>;
|
|
76
|
-
};
|
|
77
|
-
remote: {
|
|
78
|
-
commits: {
|
|
79
|
-
sha: string;
|
|
80
|
-
branchName: string;
|
|
81
|
-
}[];
|
|
82
|
-
};
|
|
83
|
-
status: PushStatusResponse;
|
|
84
|
-
};
|
|
85
|
-
|
|
86
|
-
export type DeploymentStatusResponse = {
|
|
87
|
-
deploy: {
|
|
88
|
-
url: string | null;
|
|
89
|
-
status: DeploymentStatus;
|
|
90
|
-
};
|
|
91
|
-
scorecard: ScorecardItem[];
|
|
92
|
-
};
|
|
93
|
-
|
|
94
|
-
export type PushStatusResponse = {
|
|
95
|
-
preview: DeploymentStatusResponse;
|
|
96
|
-
production: DeploymentStatusResponse;
|
|
97
|
-
};
|
|
98
|
-
|
|
99
|
-
export type ScorecardItem = {
|
|
100
|
-
name: string;
|
|
101
|
-
status: PushStatusBase;
|
|
102
|
-
description: string;
|
|
103
|
-
url: string;
|
|
104
|
-
};
|
|
105
|
-
|
|
106
|
-
export type PushStatusBase = 'pending' | 'success' | 'running' | 'failed';
|
|
107
|
-
|
|
108
|
-
export type DeploymentStatus = 'skipped' | PushStatusBase;
|