@redocly/openapi-core 1.10.2 → 1.10.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +13 -0
- package/lib/bundle.d.ts +1 -1
- package/lib/bundle.js +2 -2
- package/lib/config/config.d.ts +6 -0
- package/lib/config/config.js +19 -1
- package/lib/config/load.js +2 -2
- package/lib/config/types.d.ts +0 -10
- package/lib/config/types.js +0 -13
- package/lib/decorators/common/registry-dependencies.js +2 -2
- package/lib/env.js +3 -1
- package/lib/index.d.ts +2 -3
- package/lib/index.js +2 -17
- package/lib/oas-types.d.ts +1 -1
- package/lib/redocly/index.d.ts +2 -1
- package/lib/redocly/index.js +24 -14
- package/lib/redocly/registry-api.d.ts +2 -2
- package/lib/redocly/registry-api.js +9 -9
- package/lib/types/redocly-yaml.js +3 -3
- package/lib/utils.d.ts +0 -2
- package/lib/utils.js +1 -7
- package/package.json +3 -4
- package/src/__tests__/lint.test.ts +2 -30
- package/src/bundle.ts +1 -1
- package/src/config/config.ts +23 -1
- package/src/config/load.ts +1 -2
- package/src/config/types.ts +0 -13
- package/src/decorators/common/registry-dependencies.ts +1 -1
- package/src/env.ts +3 -1
- package/src/index.ts +2 -11
- package/src/redocly/__tests__/redocly-client.test.ts +3 -5
- package/src/redocly/index.ts +24 -14
- package/src/redocly/registry-api.ts +31 -25
- package/src/types/redocly-yaml.ts +2 -2
- package/src/utils.ts +1 -7
- package/tsconfig.tsbuildinfo +1 -1
- package/lib/redocly/domains.d.ts +0 -14
- package/lib/redocly/domains.js +0 -41
- package/lib/types/portal-config-schema.d.ts +0 -5299
- package/lib/types/portal-config-schema.js +0 -338
- package/lib/types/theme-config.d.ts +0 -2541
- package/lib/types/theme-config.js +0 -637
- package/src/redocly/__tests__/domains.test.ts +0 -52
- package/src/redocly/domains.ts +0 -48
- package/src/types/portal-config-schema.ts +0 -416
- package/src/types/theme-config.ts +0 -781
package/src/config/config.ts
CHANGED
|
@@ -10,7 +10,7 @@ import {
|
|
|
10
10
|
Oas3RuleSet,
|
|
11
11
|
Async2RuleSet,
|
|
12
12
|
} from '../oas-types';
|
|
13
|
-
import { isBrowser } from '../env';
|
|
13
|
+
import { isBrowser, env } from '../env';
|
|
14
14
|
|
|
15
15
|
import type { NodeType } from '../types';
|
|
16
16
|
import type {
|
|
@@ -35,6 +35,25 @@ const IGNORE_BANNER =
|
|
|
35
35
|
`# This file instructs Redocly's linter to ignore the rules contained for specific parts of your API.\n` +
|
|
36
36
|
`# See https://redoc.ly/docs/cli/ for more information.\n`;
|
|
37
37
|
|
|
38
|
+
export const DEFAULT_REGION = 'us';
|
|
39
|
+
|
|
40
|
+
function getDomains() {
|
|
41
|
+
const domains: { [region in Region]: string } = {
|
|
42
|
+
us: 'redocly.com',
|
|
43
|
+
eu: 'eu.redocly.com',
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
// FIXME: temporary fix for our lab environments
|
|
47
|
+
const domain = env.REDOCLY_DOMAIN;
|
|
48
|
+
if (domain?.endsWith('.redocly.host')) {
|
|
49
|
+
domains[domain.split('.')[0] as Region] = domain;
|
|
50
|
+
}
|
|
51
|
+
if (domain === 'redoc.online') {
|
|
52
|
+
domains[domain as Region] = domain;
|
|
53
|
+
}
|
|
54
|
+
return domains;
|
|
55
|
+
}
|
|
56
|
+
|
|
38
57
|
function getIgnoreFilePath(configFile?: string): string | undefined {
|
|
39
58
|
if (configFile) {
|
|
40
59
|
return doesYamlFileExist(configFile)
|
|
@@ -45,6 +64,9 @@ function getIgnoreFilePath(configFile?: string): string | undefined {
|
|
|
45
64
|
}
|
|
46
65
|
}
|
|
47
66
|
|
|
67
|
+
export const DOMAINS = getDomains();
|
|
68
|
+
export const AVAILABLE_REGIONS = Object.keys(DOMAINS) as Region[];
|
|
69
|
+
|
|
48
70
|
export class StyleguideConfig {
|
|
49
71
|
plugins: Plugin[];
|
|
50
72
|
ignore: Record<string, Record<string, Set<string>>> = {};
|
package/src/config/load.ts
CHANGED
|
@@ -3,7 +3,7 @@ import * as path from 'path';
|
|
|
3
3
|
import { RedoclyClient } from '../redocly';
|
|
4
4
|
import { isEmptyObject, doesYamlFileExist } from '../utils';
|
|
5
5
|
import { parseYaml } from '../js-yaml';
|
|
6
|
-
import { Config } from './config';
|
|
6
|
+
import { Config, DOMAINS } from './config';
|
|
7
7
|
import { ConfigValidationError, transformConfig } from './utils';
|
|
8
8
|
import { resolveConfig, resolveConfigFileAndRefs } from './config-resolvers';
|
|
9
9
|
import { bundleConfig } from '../bundle';
|
|
@@ -12,7 +12,6 @@ import type { Document } from '../resolve';
|
|
|
12
12
|
import type { RegionalTokenWithValidity } from '../redocly/redocly-client-types';
|
|
13
13
|
import type { RawConfig, RawUniversalConfig, Region } from './types';
|
|
14
14
|
import type { BaseResolver, ResolvedRefMap } from '../resolve';
|
|
15
|
-
import { DOMAINS } from '../redocly/domains';
|
|
16
15
|
|
|
17
16
|
async function addConfigMetadata({
|
|
18
17
|
rawConfig,
|
package/src/config/types.ts
CHANGED
|
@@ -243,16 +243,3 @@ export type RulesFields =
|
|
|
243
243
|
| 'oas3_0Decorators'
|
|
244
244
|
| 'oas3_1Decorators'
|
|
245
245
|
| 'async2Decorators';
|
|
246
|
-
|
|
247
|
-
export enum AuthProviderType {
|
|
248
|
-
OIDC = 'OIDC',
|
|
249
|
-
SAML2 = 'SAML2',
|
|
250
|
-
BASIC = 'BASIC',
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
export enum ApigeeDevOnboardingIntegrationAuthType {
|
|
254
|
-
SERVICE_ACCOUNT = 'SERVICE_ACCOUNT',
|
|
255
|
-
OAUTH2 = 'OAUTH2',
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
export const DEFAULT_TEAM_CLAIM_NAME = 'https://redocly.com/sso/teams';
|
package/src/env.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
export const isBrowser =
|
|
2
2
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
3
3
|
// @ts-ignore
|
|
4
|
-
typeof window !== 'undefined' ||
|
|
4
|
+
typeof window !== 'undefined' ||
|
|
5
|
+
typeof process === 'undefined' ||
|
|
6
|
+
(process?.platform as any) === 'browser'; // main and worker thread
|
|
5
7
|
export const env = isBrowser ? {} : process.env || {};
|
package/src/index.ts
CHANGED
|
@@ -1,11 +1,4 @@
|
|
|
1
|
-
export {
|
|
2
|
-
BundleOutputFormat,
|
|
3
|
-
readFileFromUrl,
|
|
4
|
-
slash,
|
|
5
|
-
doesYamlFileExist,
|
|
6
|
-
isTruthy,
|
|
7
|
-
getProxyAgent,
|
|
8
|
-
} from './utils';
|
|
1
|
+
export { BundleOutputFormat, readFileFromUrl, slash, doesYamlFileExist, isTruthy } from './utils';
|
|
9
2
|
export { Oas3_1Types } from './types/oas3_1';
|
|
10
3
|
export { Oas3Types } from './types/oas3';
|
|
11
4
|
export { Oas2Types } from './types/oas2';
|
|
@@ -48,9 +41,7 @@ export {
|
|
|
48
41
|
ResolvedApi,
|
|
49
42
|
} from './config';
|
|
50
43
|
|
|
51
|
-
export { RedoclyClient } from './redocly';
|
|
52
|
-
|
|
53
|
-
export * from './redocly/domains';
|
|
44
|
+
export { RedoclyClient, isRedoclyRegistryURL } from './redocly';
|
|
54
45
|
|
|
55
46
|
export {
|
|
56
47
|
Source,
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { setRedoclyDomain } from '../domains';
|
|
2
1
|
import { RedoclyClient } from '../index';
|
|
3
2
|
|
|
4
3
|
jest.mock('node-fetch', () => ({
|
|
@@ -17,7 +16,6 @@ describe('RedoclyClient', () => {
|
|
|
17
16
|
|
|
18
17
|
afterEach(() => {
|
|
19
18
|
delete process.env.REDOCLY_DOMAIN;
|
|
20
|
-
setRedoclyDomain('');
|
|
21
19
|
});
|
|
22
20
|
|
|
23
21
|
it('should resolve the US domain by default', () => {
|
|
@@ -42,19 +40,19 @@ describe('RedoclyClient', () => {
|
|
|
42
40
|
});
|
|
43
41
|
|
|
44
42
|
it('should resolve domain by EU region prioritizing flag over env variable', () => {
|
|
45
|
-
|
|
43
|
+
process.env.REDOCLY_DOMAIN = testRedoclyDomain;
|
|
46
44
|
const client = new RedoclyClient('eu');
|
|
47
45
|
expect(client.domain).toBe(REDOCLY_DOMAIN_EU);
|
|
48
46
|
});
|
|
49
47
|
|
|
50
48
|
it('should resolve domain by US region prioritizing flag over env variable', () => {
|
|
51
|
-
|
|
49
|
+
process.env.REDOCLY_DOMAIN = testRedoclyDomain;
|
|
52
50
|
const client = new RedoclyClient('us');
|
|
53
51
|
expect(client.domain).toBe(REDOCLY_DOMAIN_US);
|
|
54
52
|
});
|
|
55
53
|
|
|
56
54
|
it('should resolve domain by US region when REDOCLY_DOMAIN consists EU domain', () => {
|
|
57
|
-
|
|
55
|
+
process.env.REDOCLY_DOMAIN = REDOCLY_DOMAIN_EU;
|
|
58
56
|
const client = new RedoclyClient();
|
|
59
57
|
expect(client.getRegion()).toBe('eu');
|
|
60
58
|
});
|
package/src/redocly/index.ts
CHANGED
|
@@ -2,19 +2,13 @@ import { existsSync, readFileSync, writeFileSync, unlinkSync } from 'fs';
|
|
|
2
2
|
import { resolve } from 'path';
|
|
3
3
|
import { homedir } from 'os';
|
|
4
4
|
import { RegistryApi } from './registry-api';
|
|
5
|
+
import { DEFAULT_REGION, DOMAINS, AVAILABLE_REGIONS } from '../config/config';
|
|
5
6
|
import { env } from '../env';
|
|
6
7
|
import { RegionalToken, RegionalTokenWithValidity } from './redocly-client-types';
|
|
7
8
|
import { isNotEmptyObject } from '../utils';
|
|
8
9
|
import { colorize } from '../logger';
|
|
9
10
|
|
|
10
11
|
import type { AccessTokens, Region } from '../config/types';
|
|
11
|
-
import {
|
|
12
|
-
AVAILABLE_REGIONS,
|
|
13
|
-
DEFAULT_REGION,
|
|
14
|
-
DOMAINS,
|
|
15
|
-
getRedoclyDomain,
|
|
16
|
-
setRedoclyDomain,
|
|
17
|
-
} from './domains';
|
|
18
12
|
|
|
19
13
|
export const TOKEN_FILENAME = '.redocly-config.json';
|
|
20
14
|
|
|
@@ -29,7 +23,7 @@ export class RedoclyClient {
|
|
|
29
23
|
this.loadTokens();
|
|
30
24
|
this.domain = region ? DOMAINS[region] : env.REDOCLY_DOMAIN || DOMAINS[DEFAULT_REGION];
|
|
31
25
|
|
|
32
|
-
|
|
26
|
+
env.REDOCLY_DOMAIN = this.domain; // isRedoclyRegistryURL depends on the value to be set
|
|
33
27
|
this.registryApi = new RegistryApi(this.accessTokens, this.region);
|
|
34
28
|
}
|
|
35
29
|
|
|
@@ -42,9 +36,9 @@ export class RedoclyClient {
|
|
|
42
36
|
);
|
|
43
37
|
}
|
|
44
38
|
|
|
45
|
-
if (
|
|
39
|
+
if (env.REDOCLY_DOMAIN) {
|
|
46
40
|
return (AVAILABLE_REGIONS.find(
|
|
47
|
-
(region) => DOMAINS[region as Region] ===
|
|
41
|
+
(region) => DOMAINS[region as Region] === env.REDOCLY_DOMAIN
|
|
48
42
|
) || DEFAULT_REGION) as Region;
|
|
49
43
|
}
|
|
50
44
|
return region || DEFAULT_REGION;
|
|
@@ -102,7 +96,7 @@ export class RedoclyClient {
|
|
|
102
96
|
const allTokens = this.getAllTokens();
|
|
103
97
|
|
|
104
98
|
const verifiedTokens = await Promise.allSettled(
|
|
105
|
-
allTokens.map(({ token }) => this.verifyToken(token))
|
|
99
|
+
allTokens.map(({ token, region }) => this.verifyToken(token, region))
|
|
106
100
|
);
|
|
107
101
|
|
|
108
102
|
return allTokens
|
|
@@ -126,7 +120,7 @@ export class RedoclyClient {
|
|
|
126
120
|
}
|
|
127
121
|
|
|
128
122
|
try {
|
|
129
|
-
await this.verifyToken(accessToken);
|
|
123
|
+
await this.verifyToken(accessToken, this.region);
|
|
130
124
|
|
|
131
125
|
return true;
|
|
132
126
|
} catch (err) {
|
|
@@ -144,16 +138,17 @@ export class RedoclyClient {
|
|
|
144
138
|
|
|
145
139
|
async verifyToken(
|
|
146
140
|
accessToken: string,
|
|
141
|
+
region: Region,
|
|
147
142
|
verbose: boolean = false
|
|
148
143
|
): Promise<{ viewerId: string; organizations: string[] }> {
|
|
149
|
-
return this.registryApi.authStatus(accessToken, verbose);
|
|
144
|
+
return this.registryApi.authStatus(accessToken, region, verbose);
|
|
150
145
|
}
|
|
151
146
|
|
|
152
147
|
async login(accessToken: string, verbose: boolean = false) {
|
|
153
148
|
const credentialsPath = resolve(homedir(), TOKEN_FILENAME);
|
|
154
149
|
|
|
155
150
|
try {
|
|
156
|
-
await this.verifyToken(accessToken, verbose);
|
|
151
|
+
await this.verifyToken(accessToken, this.region, verbose);
|
|
157
152
|
} catch (err) {
|
|
158
153
|
throw new Error('Authorization failed. Please check if you entered a valid API key.');
|
|
159
154
|
}
|
|
@@ -175,3 +170,18 @@ export class RedoclyClient {
|
|
|
175
170
|
}
|
|
176
171
|
}
|
|
177
172
|
}
|
|
173
|
+
|
|
174
|
+
export function isRedoclyRegistryURL(link: string): boolean {
|
|
175
|
+
const domain = env.REDOCLY_DOMAIN || DOMAINS[DEFAULT_REGION];
|
|
176
|
+
|
|
177
|
+
const legacyDomain = domain === 'redocly.com' ? 'redoc.ly' : domain;
|
|
178
|
+
|
|
179
|
+
if (
|
|
180
|
+
!link.startsWith(`https://api.${domain}/registry/`) &&
|
|
181
|
+
!link.startsWith(`https://api.${legacyDomain}/registry/`)
|
|
182
|
+
) {
|
|
183
|
+
return false;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
return true;
|
|
187
|
+
}
|
|
@@ -6,8 +6,8 @@ import type {
|
|
|
6
6
|
PushApiParams,
|
|
7
7
|
} from './registry-api-types';
|
|
8
8
|
import type { AccessTokens, Region } from '../config/types';
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
9
|
+
import { DEFAULT_REGION, DOMAINS } from '../config/config';
|
|
10
|
+
import { isNotEmptyObject } from '../utils';
|
|
11
11
|
|
|
12
12
|
const version = require('../../package.json').version;
|
|
13
13
|
|
|
@@ -18,8 +18,8 @@ export class RegistryApi {
|
|
|
18
18
|
return isNotEmptyObject(this.accessTokens) && this.accessTokens[this.region];
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
-
getBaseUrl() {
|
|
22
|
-
return `https://api.${
|
|
21
|
+
getBaseUrl(region: Region = DEFAULT_REGION) {
|
|
22
|
+
return `https://api.${DOMAINS[region]}/registry`;
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
setAccessTokens(accessTokens: AccessTokens) {
|
|
@@ -27,7 +27,7 @@ export class RegistryApi {
|
|
|
27
27
|
return this;
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
-
private async request(path = '', options: RequestInit = {}) {
|
|
30
|
+
private async request(path = '', options: RequestInit = {}, region?: Region) {
|
|
31
31
|
const currentCommand =
|
|
32
32
|
typeof process !== 'undefined' ? process.env?.REDOCLY_CLI_COMMAND || '' : '';
|
|
33
33
|
const redoclyEnv = typeof process !== 'undefined' ? process.env?.REDOCLY_ENVIRONMENT || '' : '';
|
|
@@ -42,8 +42,8 @@ export class RegistryApi {
|
|
|
42
42
|
}
|
|
43
43
|
|
|
44
44
|
const response = await fetch(
|
|
45
|
-
`${this.getBaseUrl()}${path}`,
|
|
46
|
-
Object.assign({}, options, { headers
|
|
45
|
+
`${this.getBaseUrl(region)}${path}`,
|
|
46
|
+
Object.assign({}, options, { headers })
|
|
47
47
|
);
|
|
48
48
|
|
|
49
49
|
if (response.status === 401) {
|
|
@@ -60,10 +60,11 @@ export class RegistryApi {
|
|
|
60
60
|
|
|
61
61
|
async authStatus(
|
|
62
62
|
accessToken: string,
|
|
63
|
+
region: Region,
|
|
63
64
|
verbose = false
|
|
64
65
|
): Promise<{ viewerId: string; organizations: string[] }> {
|
|
65
66
|
try {
|
|
66
|
-
const response = await this.request('', { headers: { authorization: accessToken } });
|
|
67
|
+
const response = await this.request('', { headers: { authorization: accessToken } }, region);
|
|
67
68
|
|
|
68
69
|
return await response.json();
|
|
69
70
|
} catch (error) {
|
|
@@ -96,7 +97,8 @@ export class RegistryApi {
|
|
|
96
97
|
filename,
|
|
97
98
|
isUpsert,
|
|
98
99
|
}),
|
|
99
|
-
}
|
|
100
|
+
},
|
|
101
|
+
this.region
|
|
100
102
|
);
|
|
101
103
|
|
|
102
104
|
if (response.ok) {
|
|
@@ -118,22 +120,26 @@ export class RegistryApi {
|
|
|
118
120
|
batchId,
|
|
119
121
|
batchSize,
|
|
120
122
|
}: PushApiParams) {
|
|
121
|
-
const response = await this.request(
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
123
|
+
const response = await this.request(
|
|
124
|
+
`/${organizationId}/${name}/${version}`,
|
|
125
|
+
{
|
|
126
|
+
method: 'PUT',
|
|
127
|
+
headers: {
|
|
128
|
+
'content-type': 'application/json',
|
|
129
|
+
authorization: this.accessToken,
|
|
130
|
+
} as HeadersInit,
|
|
131
|
+
body: JSON.stringify({
|
|
132
|
+
rootFilePath,
|
|
133
|
+
filePaths,
|
|
134
|
+
branch,
|
|
135
|
+
isUpsert,
|
|
136
|
+
isPublic,
|
|
137
|
+
batchId,
|
|
138
|
+
batchSize,
|
|
139
|
+
}),
|
|
140
|
+
},
|
|
141
|
+
this.region
|
|
142
|
+
);
|
|
137
143
|
|
|
138
144
|
if (response.ok) {
|
|
139
145
|
return;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { rootRedoclyConfigSchema } from '
|
|
1
|
+
import { rootRedoclyConfigSchema } from '@redocly/config';
|
|
2
2
|
import { listOf } from '.';
|
|
3
3
|
import { omitObjectProps, pickObjectProps, isCustomRuleId } from '../utils';
|
|
4
4
|
import { getNodeTypesFromJSONSchema } from './json-schema-adapter';
|
|
@@ -1050,7 +1050,7 @@ const ConfigReferenceDocs: NodeType = {
|
|
|
1050
1050
|
preserveOriginalExtensionsName: { type: 'boolean' },
|
|
1051
1051
|
markdownHeadingsAnchorLevel: { type: 'number' },
|
|
1052
1052
|
},
|
|
1053
|
-
additionalProperties: {
|
|
1053
|
+
additionalProperties: {},
|
|
1054
1054
|
};
|
|
1055
1055
|
|
|
1056
1056
|
const ConfigMockServer: NodeType = {
|
package/src/utils.ts
CHANGED
|
@@ -5,10 +5,9 @@ import fetch from 'node-fetch';
|
|
|
5
5
|
import * as pluralize from 'pluralize';
|
|
6
6
|
import { parseYaml } from './js-yaml';
|
|
7
7
|
import { UserContext } from './walk';
|
|
8
|
+
import { HttpResolveConfig } from './config';
|
|
8
9
|
import { env } from './env';
|
|
9
10
|
import { logger, colorize } from './logger';
|
|
10
|
-
import { HttpResolveConfig } from './config';
|
|
11
|
-
import { HttpsProxyAgent } from 'https-proxy-agent';
|
|
12
11
|
|
|
13
12
|
export { parseYaml, stringifyYaml } from './js-yaml';
|
|
14
13
|
|
|
@@ -275,8 +274,3 @@ export function nextTick() {
|
|
|
275
274
|
function getUpdatedFieldName(updatedField: string, updatedObject?: string) {
|
|
276
275
|
return `${typeof updatedObject !== 'undefined' ? `${updatedObject}.` : ''}${updatedField}`;
|
|
277
276
|
}
|
|
278
|
-
|
|
279
|
-
export function getProxyAgent() {
|
|
280
|
-
const proxy = process.env.HTTPS_PROXY || process.env.HTTP_PROXY;
|
|
281
|
-
return proxy ? new HttpsProxyAgent(proxy) : undefined;
|
|
282
|
-
}
|