@redocly/openapi-core 1.10.1 → 1.10.2
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 +6 -0
- package/lib/bundle.js +2 -2
- package/lib/config/config.d.ts +0 -6
- package/lib/config/config.js +1 -19
- package/lib/config/load.js +2 -2
- package/lib/decorators/common/registry-dependencies.js +2 -2
- package/lib/index.d.ts +3 -2
- package/lib/index.js +17 -2
- package/lib/redocly/domains.d.ts +14 -0
- package/lib/redocly/domains.js +41 -0
- package/lib/redocly/index.d.ts +1 -2
- package/lib/redocly/index.js +14 -24
- package/lib/redocly/registry-api.d.ts +2 -2
- package/lib/redocly/registry-api.js +9 -9
- package/lib/utils.d.ts +2 -0
- package/lib/utils.js +7 -1
- package/package.json +4 -2
- package/src/bundle.ts +1 -1
- package/src/config/config.ts +1 -23
- package/src/config/load.ts +2 -1
- package/src/decorators/common/registry-dependencies.ts +1 -1
- package/src/index.ts +11 -2
- package/src/redocly/__tests__/domains.test.ts +52 -0
- package/src/redocly/__tests__/redocly-client.test.ts +5 -3
- package/src/redocly/domains.ts +48 -0
- package/src/redocly/index.ts +14 -24
- package/src/redocly/registry-api.ts +25 -31
- package/src/utils.ts +7 -1
- package/tsconfig.tsbuildinfo +1 -1
package/CHANGELOG.md
CHANGED
package/lib/bundle.js
CHANGED
|
@@ -20,7 +20,7 @@ const ref_utils_1 = require("./ref-utils");
|
|
|
20
20
|
const rules_1 = require("./config/rules");
|
|
21
21
|
const no_unresolved_refs_1 = require("./rules/no-unresolved-refs");
|
|
22
22
|
const utils_1 = require("./utils");
|
|
23
|
-
const
|
|
23
|
+
const domains_1 = require("./redocly/domains");
|
|
24
24
|
const remove_unused_components_1 = require("./decorators/oas2/remove-unused-components");
|
|
25
25
|
const remove_unused_components_2 = require("./decorators/oas3/remove-unused-components");
|
|
26
26
|
const redocly_yaml_1 = require("./types/redocly-yaml");
|
|
@@ -234,7 +234,7 @@ function makeBundleVisitor(version, dereference, skipRedoclyRegistryRefs, rootDo
|
|
|
234
234
|
return;
|
|
235
235
|
}
|
|
236
236
|
// do not bundle registry URL before push, otherwise we can't record dependencies
|
|
237
|
-
if (skipRedoclyRegistryRefs && (0,
|
|
237
|
+
if (skipRedoclyRegistryRefs && (0, domains_1.isRedoclyRegistryURL)(node.$ref)) {
|
|
238
238
|
return;
|
|
239
239
|
}
|
|
240
240
|
if (keepUrlRefs && (0, ref_utils_1.isAbsoluteUrl)(node.$ref)) {
|
package/lib/config/config.d.ts
CHANGED
|
@@ -3,12 +3,6 @@ import { SpecVersion, SpecMajorVersion, Oas2RuleSet, Oas3RuleSet, Async2RuleSet
|
|
|
3
3
|
import type { NodeType } from '../types';
|
|
4
4
|
import type { DecoratorConfig, Plugin, PreprocessorConfig, Region, ResolveConfig, ResolvedApi, ResolvedConfig, ResolvedStyleguideConfig, RuleConfig, RuleSettings, Telemetry, ThemeRawConfig } from './types';
|
|
5
5
|
export declare const IGNORE_FILE = ".redocly.lint-ignore.yaml";
|
|
6
|
-
export declare const DEFAULT_REGION = "us";
|
|
7
|
-
export declare const DOMAINS: {
|
|
8
|
-
us: string;
|
|
9
|
-
eu: string;
|
|
10
|
-
};
|
|
11
|
-
export declare const AVAILABLE_REGIONS: Region[];
|
|
12
6
|
export declare class StyleguideConfig {
|
|
13
7
|
rawConfig: ResolvedStyleguideConfig;
|
|
14
8
|
configFile?: string | undefined;
|
package/lib/config/config.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Config = exports.StyleguideConfig = exports.
|
|
3
|
+
exports.Config = exports.StyleguideConfig = exports.IGNORE_FILE = void 0;
|
|
4
4
|
const fs = require("fs");
|
|
5
5
|
const path = require("path");
|
|
6
6
|
const js_yaml_1 = require("../js-yaml");
|
|
@@ -12,22 +12,6 @@ const ref_utils_1 = require("../ref-utils");
|
|
|
12
12
|
exports.IGNORE_FILE = '.redocly.lint-ignore.yaml';
|
|
13
13
|
const IGNORE_BANNER = `# This file instructs Redocly's linter to ignore the rules contained for specific parts of your API.\n` +
|
|
14
14
|
`# See https://redoc.ly/docs/cli/ for more information.\n`;
|
|
15
|
-
exports.DEFAULT_REGION = 'us';
|
|
16
|
-
function getDomains() {
|
|
17
|
-
const domains = {
|
|
18
|
-
us: 'redocly.com',
|
|
19
|
-
eu: 'eu.redocly.com',
|
|
20
|
-
};
|
|
21
|
-
// FIXME: temporary fix for our lab environments
|
|
22
|
-
const domain = env_1.env.REDOCLY_DOMAIN;
|
|
23
|
-
if (domain === null || domain === void 0 ? void 0 : domain.endsWith('.redocly.host')) {
|
|
24
|
-
domains[domain.split('.')[0]] = domain;
|
|
25
|
-
}
|
|
26
|
-
if (domain === 'redoc.online') {
|
|
27
|
-
domains[domain] = domain;
|
|
28
|
-
}
|
|
29
|
-
return domains;
|
|
30
|
-
}
|
|
31
15
|
function getIgnoreFilePath(configFile) {
|
|
32
16
|
if (configFile) {
|
|
33
17
|
return (0, utils_1.doesYamlFileExist)(configFile)
|
|
@@ -38,8 +22,6 @@ function getIgnoreFilePath(configFile) {
|
|
|
38
22
|
return env_1.isBrowser ? undefined : path.join(process.cwd(), exports.IGNORE_FILE);
|
|
39
23
|
}
|
|
40
24
|
}
|
|
41
|
-
exports.DOMAINS = getDomains();
|
|
42
|
-
exports.AVAILABLE_REGIONS = Object.keys(exports.DOMAINS);
|
|
43
25
|
class StyleguideConfig {
|
|
44
26
|
constructor(rawConfig, configFile) {
|
|
45
27
|
this.rawConfig = rawConfig;
|
package/lib/config/load.js
CHANGED
|
@@ -15,10 +15,10 @@ const path = require("path");
|
|
|
15
15
|
const redocly_1 = require("../redocly");
|
|
16
16
|
const utils_1 = require("../utils");
|
|
17
17
|
const js_yaml_1 = require("../js-yaml");
|
|
18
|
-
const config_1 = require("./config");
|
|
19
18
|
const utils_2 = require("./utils");
|
|
20
19
|
const config_resolvers_1 = require("./config-resolvers");
|
|
21
20
|
const bundle_1 = require("../bundle");
|
|
21
|
+
const domains_1 = require("../redocly/domains");
|
|
22
22
|
function addConfigMetadata({ rawConfig, customExtends, configPath, tokens, files, region, }) {
|
|
23
23
|
var _a;
|
|
24
24
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -36,7 +36,7 @@ function addConfigMetadata({ rawConfig, customExtends, configPath, tokens, files
|
|
|
36
36
|
rawConfig.resolve.http = {};
|
|
37
37
|
rawConfig.resolve.http.headers = [...((_a = rawConfig.resolve.http.headers) !== null && _a !== void 0 ? _a : [])];
|
|
38
38
|
for (const item of tokens) {
|
|
39
|
-
const domain =
|
|
39
|
+
const domain = domains_1.DOMAINS[item.region];
|
|
40
40
|
rawConfig.resolve.http.headers.push({
|
|
41
41
|
matches: `https://api.${domain}/registry/**`,
|
|
42
42
|
name: 'Authorization',
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.RegistryDependencies = void 0;
|
|
4
|
-
const
|
|
4
|
+
const domains_1 = require("../../redocly/domains");
|
|
5
5
|
const RegistryDependencies = () => {
|
|
6
6
|
const registryDependencies = new Set();
|
|
7
7
|
return {
|
|
@@ -14,7 +14,7 @@ const RegistryDependencies = () => {
|
|
|
14
14
|
ref(node) {
|
|
15
15
|
if (node.$ref) {
|
|
16
16
|
const link = node.$ref.split('#/')[0];
|
|
17
|
-
if ((0,
|
|
17
|
+
if ((0, domains_1.isRedoclyRegistryURL)(link)) {
|
|
18
18
|
registryDependencies.add(link);
|
|
19
19
|
}
|
|
20
20
|
}
|
package/lib/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { BundleOutputFormat, readFileFromUrl, slash, doesYamlFileExist, isTruthy } from './utils';
|
|
1
|
+
export { BundleOutputFormat, readFileFromUrl, slash, doesYamlFileExist, isTruthy, getProxyAgent, } from './utils';
|
|
2
2
|
export { Oas3_1Types } from './types/oas3_1';
|
|
3
3
|
export { Oas3Types } from './types/oas3';
|
|
4
4
|
export { Oas2Types } from './types/oas2';
|
|
@@ -10,7 +10,8 @@ export type { StatsAccumulator, StatsName } from './typings/common';
|
|
|
10
10
|
export { normalizeTypes } from './types';
|
|
11
11
|
export { Stats } from './rules/other/stats';
|
|
12
12
|
export { Config, StyleguideConfig, RawConfig, RawUniversalConfig, IGNORE_FILE, Region, getMergedConfig, transformConfig, loadConfig, getConfig, findConfig, CONFIG_FILE_NAMES, RuleSeverity, createConfig, ResolvedApi, } from './config';
|
|
13
|
-
export { RedoclyClient
|
|
13
|
+
export { RedoclyClient } from './redocly';
|
|
14
|
+
export * from './redocly/domains';
|
|
14
15
|
export { Source, BaseResolver, Document, resolveDocument, ResolveError, YamlParseError, makeDocumentFromString, } from './resolve';
|
|
15
16
|
export { parseYaml, stringifyYaml } from './js-yaml';
|
|
16
17
|
export { unescapePointer, isRef, isAbsoluteUrl } from './ref-utils';
|
package/lib/index.js
CHANGED
|
@@ -1,12 +1,27 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
2
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.lintConfig = exports.lintFromString = exports.lintDocument = exports.validate = exports.lint = exports.getTotals = exports.formatProblems = exports.getLineColLocation = exports.getAstNodeByPointer = exports.walkDocument = exports.normalizeVisitors = exports.getTypes = exports.detectSpec = exports.SpecVersion = exports.getMajorSpecVersion = exports.SpecMajorVersion = exports.isAbsoluteUrl = exports.isRef = exports.unescapePointer = exports.stringifyYaml = exports.parseYaml = exports.makeDocumentFromString = exports.YamlParseError = exports.ResolveError = exports.resolveDocument = exports.BaseResolver = exports.Source = exports.
|
|
17
|
+
exports.lintConfig = exports.lintFromString = exports.lintDocument = exports.validate = exports.lint = exports.getTotals = exports.formatProblems = exports.getLineColLocation = exports.getAstNodeByPointer = exports.walkDocument = exports.normalizeVisitors = exports.getTypes = exports.detectSpec = exports.SpecVersion = exports.getMajorSpecVersion = exports.SpecMajorVersion = exports.isAbsoluteUrl = exports.isRef = exports.unescapePointer = exports.stringifyYaml = exports.parseYaml = exports.makeDocumentFromString = exports.YamlParseError = exports.ResolveError = exports.resolveDocument = exports.BaseResolver = exports.Source = exports.RedoclyClient = exports.createConfig = exports.CONFIG_FILE_NAMES = exports.findConfig = exports.getConfig = exports.loadConfig = exports.transformConfig = exports.getMergedConfig = exports.IGNORE_FILE = exports.StyleguideConfig = exports.Config = exports.Stats = exports.normalizeTypes = exports.ConfigTypes = exports.AsyncApi2Types = exports.Oas2Types = exports.Oas3Types = exports.Oas3_1Types = exports.getProxyAgent = exports.isTruthy = exports.doesYamlFileExist = exports.slash = exports.readFileFromUrl = void 0;
|
|
4
18
|
exports.bundleFromString = exports.mapTypeToComponent = exports.bundleDocument = exports.bundle = void 0;
|
|
5
19
|
var utils_1 = require("./utils");
|
|
6
20
|
Object.defineProperty(exports, "readFileFromUrl", { enumerable: true, get: function () { return utils_1.readFileFromUrl; } });
|
|
7
21
|
Object.defineProperty(exports, "slash", { enumerable: true, get: function () { return utils_1.slash; } });
|
|
8
22
|
Object.defineProperty(exports, "doesYamlFileExist", { enumerable: true, get: function () { return utils_1.doesYamlFileExist; } });
|
|
9
23
|
Object.defineProperty(exports, "isTruthy", { enumerable: true, get: function () { return utils_1.isTruthy; } });
|
|
24
|
+
Object.defineProperty(exports, "getProxyAgent", { enumerable: true, get: function () { return utils_1.getProxyAgent; } });
|
|
10
25
|
var oas3_1_1 = require("./types/oas3_1");
|
|
11
26
|
Object.defineProperty(exports, "Oas3_1Types", { enumerable: true, get: function () { return oas3_1_1.Oas3_1Types; } });
|
|
12
27
|
var oas3_1 = require("./types/oas3");
|
|
@@ -34,7 +49,7 @@ Object.defineProperty(exports, "CONFIG_FILE_NAMES", { enumerable: true, get: fun
|
|
|
34
49
|
Object.defineProperty(exports, "createConfig", { enumerable: true, get: function () { return config_1.createConfig; } });
|
|
35
50
|
var redocly_1 = require("./redocly");
|
|
36
51
|
Object.defineProperty(exports, "RedoclyClient", { enumerable: true, get: function () { return redocly_1.RedoclyClient; } });
|
|
37
|
-
|
|
52
|
+
__exportStar(require("./redocly/domains"), exports);
|
|
38
53
|
var resolve_1 = require("./resolve");
|
|
39
54
|
Object.defineProperty(exports, "Source", { enumerable: true, get: function () { return resolve_1.Source; } });
|
|
40
55
|
Object.defineProperty(exports, "BaseResolver", { enumerable: true, get: function () { return resolve_1.BaseResolver; } });
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Region } from '../config/types';
|
|
2
|
+
export declare const DEFAULT_REGION = "us";
|
|
3
|
+
export declare const DOMAINS: {
|
|
4
|
+
us: string;
|
|
5
|
+
eu: string;
|
|
6
|
+
};
|
|
7
|
+
export declare const AVAILABLE_REGIONS: Region[];
|
|
8
|
+
export declare function getDomains(): {
|
|
9
|
+
us: string;
|
|
10
|
+
eu: string;
|
|
11
|
+
};
|
|
12
|
+
export declare function setRedoclyDomain(domain: string): void;
|
|
13
|
+
export declare function getRedoclyDomain(): string;
|
|
14
|
+
export declare function isRedoclyRegistryURL(link: string): boolean;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isRedoclyRegistryURL = exports.getRedoclyDomain = exports.setRedoclyDomain = exports.getDomains = exports.AVAILABLE_REGIONS = exports.DOMAINS = exports.DEFAULT_REGION = void 0;
|
|
4
|
+
let redoclyDomain = 'redocly.com';
|
|
5
|
+
exports.DEFAULT_REGION = 'us';
|
|
6
|
+
exports.DOMAINS = getDomains();
|
|
7
|
+
exports.AVAILABLE_REGIONS = Object.keys(exports.DOMAINS);
|
|
8
|
+
function getDomains() {
|
|
9
|
+
const domains = {
|
|
10
|
+
us: 'redocly.com',
|
|
11
|
+
eu: 'eu.redocly.com',
|
|
12
|
+
};
|
|
13
|
+
// FIXME: temporary fix for our lab environments
|
|
14
|
+
const domain = redoclyDomain;
|
|
15
|
+
if (domain === null || domain === void 0 ? void 0 : domain.endsWith('.redocly.host')) {
|
|
16
|
+
domains[domain.split('.')[0]] = domain;
|
|
17
|
+
}
|
|
18
|
+
if (domain === 'redoc.online') {
|
|
19
|
+
domains[domain] = domain;
|
|
20
|
+
}
|
|
21
|
+
return domains;
|
|
22
|
+
}
|
|
23
|
+
exports.getDomains = getDomains;
|
|
24
|
+
function setRedoclyDomain(domain) {
|
|
25
|
+
redoclyDomain = domain;
|
|
26
|
+
}
|
|
27
|
+
exports.setRedoclyDomain = setRedoclyDomain;
|
|
28
|
+
function getRedoclyDomain() {
|
|
29
|
+
return redoclyDomain;
|
|
30
|
+
}
|
|
31
|
+
exports.getRedoclyDomain = getRedoclyDomain;
|
|
32
|
+
function isRedoclyRegistryURL(link) {
|
|
33
|
+
const domain = getRedoclyDomain() || exports.DOMAINS[exports.DEFAULT_REGION];
|
|
34
|
+
const legacyDomain = domain === 'redocly.com' ? 'redoc.ly' : domain;
|
|
35
|
+
if (!link.startsWith(`https://api.${domain}/registry/`) &&
|
|
36
|
+
!link.startsWith(`https://api.${legacyDomain}/registry/`)) {
|
|
37
|
+
return false;
|
|
38
|
+
}
|
|
39
|
+
return true;
|
|
40
|
+
}
|
|
41
|
+
exports.isRedoclyRegistryURL = isRedoclyRegistryURL;
|
package/lib/redocly/index.d.ts
CHANGED
|
@@ -21,11 +21,10 @@ export declare class RedoclyClient {
|
|
|
21
21
|
isAuthorizedWithRedoclyByRegion(): Promise<boolean>;
|
|
22
22
|
isAuthorizedWithRedocly(): Promise<boolean>;
|
|
23
23
|
readCredentialsFile(credentialsPath: string): any;
|
|
24
|
-
verifyToken(accessToken: string,
|
|
24
|
+
verifyToken(accessToken: string, verbose?: boolean): Promise<{
|
|
25
25
|
viewerId: string;
|
|
26
26
|
organizations: string[];
|
|
27
27
|
}>;
|
|
28
28
|
login(accessToken: string, verbose?: boolean): Promise<void>;
|
|
29
29
|
logout(): void;
|
|
30
30
|
}
|
|
31
|
-
export declare function isRedoclyRegistryURL(link: string): boolean;
|
package/lib/redocly/index.js
CHANGED
|
@@ -9,33 +9,33 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.
|
|
12
|
+
exports.RedoclyClient = exports.TOKEN_FILENAME = void 0;
|
|
13
13
|
const fs_1 = require("fs");
|
|
14
14
|
const path_1 = require("path");
|
|
15
15
|
const os_1 = require("os");
|
|
16
16
|
const registry_api_1 = require("./registry-api");
|
|
17
|
-
const config_1 = require("../config/config");
|
|
18
17
|
const env_1 = require("../env");
|
|
19
18
|
const utils_1 = require("../utils");
|
|
20
19
|
const logger_1 = require("../logger");
|
|
20
|
+
const domains_1 = require("./domains");
|
|
21
21
|
exports.TOKEN_FILENAME = '.redocly-config.json';
|
|
22
22
|
class RedoclyClient {
|
|
23
23
|
constructor(region) {
|
|
24
24
|
this.accessTokens = {};
|
|
25
25
|
this.region = this.loadRegion(region);
|
|
26
26
|
this.loadTokens();
|
|
27
|
-
this.domain = region ?
|
|
28
|
-
|
|
27
|
+
this.domain = region ? domains_1.DOMAINS[region] : env_1.env.REDOCLY_DOMAIN || domains_1.DOMAINS[domains_1.DEFAULT_REGION];
|
|
28
|
+
(0, domains_1.setRedoclyDomain)(this.domain);
|
|
29
29
|
this.registryApi = new registry_api_1.RegistryApi(this.accessTokens, this.region);
|
|
30
30
|
}
|
|
31
31
|
loadRegion(region) {
|
|
32
|
-
if (region && !
|
|
32
|
+
if (region && !domains_1.DOMAINS[region]) {
|
|
33
33
|
throw new Error(`Invalid argument: region in config file.\nGiven: ${logger_1.colorize.green(region)}, choices: "us", "eu".`);
|
|
34
34
|
}
|
|
35
|
-
if (
|
|
36
|
-
return (
|
|
35
|
+
if ((0, domains_1.getRedoclyDomain)()) {
|
|
36
|
+
return (domains_1.AVAILABLE_REGIONS.find((region) => domains_1.DOMAINS[region] === (0, domains_1.getRedoclyDomain)()) || domains_1.DEFAULT_REGION);
|
|
37
37
|
}
|
|
38
|
-
return region ||
|
|
38
|
+
return region || domains_1.DEFAULT_REGION;
|
|
39
39
|
}
|
|
40
40
|
getRegion() {
|
|
41
41
|
return this.region;
|
|
@@ -71,13 +71,13 @@ class RedoclyClient {
|
|
|
71
71
|
}
|
|
72
72
|
getAllTokens() {
|
|
73
73
|
return Object.entries(this.accessTokens)
|
|
74
|
-
.filter(([region]) =>
|
|
74
|
+
.filter(([region]) => domains_1.AVAILABLE_REGIONS.includes(region))
|
|
75
75
|
.map(([region, token]) => ({ region, token }));
|
|
76
76
|
}
|
|
77
77
|
getValidTokens() {
|
|
78
78
|
return __awaiter(this, void 0, void 0, function* () {
|
|
79
79
|
const allTokens = this.getAllTokens();
|
|
80
|
-
const verifiedTokens = yield Promise.allSettled(allTokens.map(({ token
|
|
80
|
+
const verifiedTokens = yield Promise.allSettled(allTokens.map(({ token }) => this.verifyToken(token)));
|
|
81
81
|
return allTokens
|
|
82
82
|
.filter((_, index) => verifiedTokens[index].status === 'fulfilled')
|
|
83
83
|
.map(({ token, region }) => ({ token, region, valid: true }));
|
|
@@ -98,7 +98,7 @@ class RedoclyClient {
|
|
|
98
98
|
return false;
|
|
99
99
|
}
|
|
100
100
|
try {
|
|
101
|
-
yield this.verifyToken(accessToken
|
|
101
|
+
yield this.verifyToken(accessToken);
|
|
102
102
|
return true;
|
|
103
103
|
}
|
|
104
104
|
catch (err) {
|
|
@@ -114,16 +114,16 @@ class RedoclyClient {
|
|
|
114
114
|
readCredentialsFile(credentialsPath) {
|
|
115
115
|
return (0, fs_1.existsSync)(credentialsPath) ? JSON.parse((0, fs_1.readFileSync)(credentialsPath, 'utf-8')) : {};
|
|
116
116
|
}
|
|
117
|
-
verifyToken(accessToken,
|
|
117
|
+
verifyToken(accessToken, verbose = false) {
|
|
118
118
|
return __awaiter(this, void 0, void 0, function* () {
|
|
119
|
-
return this.registryApi.authStatus(accessToken,
|
|
119
|
+
return this.registryApi.authStatus(accessToken, verbose);
|
|
120
120
|
});
|
|
121
121
|
}
|
|
122
122
|
login(accessToken, verbose = false) {
|
|
123
123
|
return __awaiter(this, void 0, void 0, function* () {
|
|
124
124
|
const credentialsPath = (0, path_1.resolve)((0, os_1.homedir)(), exports.TOKEN_FILENAME);
|
|
125
125
|
try {
|
|
126
|
-
yield this.verifyToken(accessToken,
|
|
126
|
+
yield this.verifyToken(accessToken, verbose);
|
|
127
127
|
}
|
|
128
128
|
catch (err) {
|
|
129
129
|
throw new Error('Authorization failed. Please check if you entered a valid API key.');
|
|
@@ -142,13 +142,3 @@ class RedoclyClient {
|
|
|
142
142
|
}
|
|
143
143
|
}
|
|
144
144
|
exports.RedoclyClient = RedoclyClient;
|
|
145
|
-
function isRedoclyRegistryURL(link) {
|
|
146
|
-
const domain = env_1.env.REDOCLY_DOMAIN || config_1.DOMAINS[config_1.DEFAULT_REGION];
|
|
147
|
-
const legacyDomain = domain === 'redocly.com' ? 'redoc.ly' : domain;
|
|
148
|
-
if (!link.startsWith(`https://api.${domain}/registry/`) &&
|
|
149
|
-
!link.startsWith(`https://api.${legacyDomain}/registry/`)) {
|
|
150
|
-
return false;
|
|
151
|
-
}
|
|
152
|
-
return true;
|
|
153
|
-
}
|
|
154
|
-
exports.isRedoclyRegistryURL = isRedoclyRegistryURL;
|
|
@@ -5,10 +5,10 @@ export declare class RegistryApi {
|
|
|
5
5
|
private region;
|
|
6
6
|
constructor(accessTokens: AccessTokens, region: Region);
|
|
7
7
|
get accessToken(): string | false | undefined;
|
|
8
|
-
getBaseUrl(
|
|
8
|
+
getBaseUrl(): string;
|
|
9
9
|
setAccessTokens(accessTokens: AccessTokens): this;
|
|
10
10
|
private request;
|
|
11
|
-
authStatus(accessToken: string,
|
|
11
|
+
authStatus(accessToken: string, verbose?: boolean): Promise<{
|
|
12
12
|
viewerId: string;
|
|
13
13
|
organizations: string[];
|
|
14
14
|
}>;
|
|
@@ -11,8 +11,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.RegistryApi = void 0;
|
|
13
13
|
const node_fetch_1 = require("node-fetch");
|
|
14
|
-
const config_1 = require("../config/config");
|
|
15
14
|
const utils_1 = require("../utils");
|
|
15
|
+
const domains_1 = require("./domains");
|
|
16
16
|
const version = require('../../package.json').version;
|
|
17
17
|
class RegistryApi {
|
|
18
18
|
constructor(accessTokens, region) {
|
|
@@ -22,14 +22,14 @@ class RegistryApi {
|
|
|
22
22
|
get accessToken() {
|
|
23
23
|
return (0, utils_1.isNotEmptyObject)(this.accessTokens) && this.accessTokens[this.region];
|
|
24
24
|
}
|
|
25
|
-
getBaseUrl(
|
|
26
|
-
return `https://api.${
|
|
25
|
+
getBaseUrl() {
|
|
26
|
+
return `https://api.${(0, domains_1.getRedoclyDomain)()}/registry`;
|
|
27
27
|
}
|
|
28
28
|
setAccessTokens(accessTokens) {
|
|
29
29
|
this.accessTokens = accessTokens;
|
|
30
30
|
return this;
|
|
31
31
|
}
|
|
32
|
-
request(path = '', options = {}
|
|
32
|
+
request(path = '', options = {}) {
|
|
33
33
|
var _a, _b;
|
|
34
34
|
return __awaiter(this, void 0, void 0, function* () {
|
|
35
35
|
const currentCommand = typeof process !== 'undefined' ? ((_a = process.env) === null || _a === void 0 ? void 0 : _a.REDOCLY_CLI_COMMAND) || '' : '';
|
|
@@ -41,7 +41,7 @@ class RegistryApi {
|
|
|
41
41
|
if (!headers.hasOwnProperty('authorization')) {
|
|
42
42
|
throw new Error('Unauthorized');
|
|
43
43
|
}
|
|
44
|
-
const response = yield (0, node_fetch_1.default)(`${this.getBaseUrl(
|
|
44
|
+
const response = yield (0, node_fetch_1.default)(`${this.getBaseUrl()}${path}`, Object.assign({}, options, { headers, agent: (0, utils_1.getProxyAgent)() }));
|
|
45
45
|
if (response.status === 401) {
|
|
46
46
|
throw new Error('Unauthorized');
|
|
47
47
|
}
|
|
@@ -52,10 +52,10 @@ class RegistryApi {
|
|
|
52
52
|
return response;
|
|
53
53
|
});
|
|
54
54
|
}
|
|
55
|
-
authStatus(accessToken,
|
|
55
|
+
authStatus(accessToken, verbose = false) {
|
|
56
56
|
return __awaiter(this, void 0, void 0, function* () {
|
|
57
57
|
try {
|
|
58
|
-
const response = yield this.request('', { headers: { authorization: accessToken } }
|
|
58
|
+
const response = yield this.request('', { headers: { authorization: accessToken } });
|
|
59
59
|
return yield response.json();
|
|
60
60
|
}
|
|
61
61
|
catch (error) {
|
|
@@ -79,7 +79,7 @@ class RegistryApi {
|
|
|
79
79
|
filename,
|
|
80
80
|
isUpsert,
|
|
81
81
|
}),
|
|
82
|
-
}
|
|
82
|
+
});
|
|
83
83
|
if (response.ok) {
|
|
84
84
|
return response.json();
|
|
85
85
|
}
|
|
@@ -103,7 +103,7 @@ class RegistryApi {
|
|
|
103
103
|
batchId,
|
|
104
104
|
batchSize,
|
|
105
105
|
}),
|
|
106
|
-
}
|
|
106
|
+
});
|
|
107
107
|
if (response.ok) {
|
|
108
108
|
return;
|
|
109
109
|
}
|
package/lib/utils.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { UserContext } from './walk';
|
|
2
2
|
import { HttpResolveConfig } from './config';
|
|
3
|
+
import { HttpsProxyAgent } from 'https-proxy-agent';
|
|
3
4
|
export { parseYaml, stringifyYaml } from './js-yaml';
|
|
4
5
|
export type StackFrame<T> = {
|
|
5
6
|
prev: StackFrame<T> | null;
|
|
@@ -50,3 +51,4 @@ export declare function identity<T>(value: T): T;
|
|
|
50
51
|
export declare function keysOf<T>(obj: T): (keyof T)[];
|
|
51
52
|
export declare function pickDefined<T extends Record<string, unknown>>(obj?: T): Record<string, unknown> | undefined;
|
|
52
53
|
export declare function nextTick(): void;
|
|
54
|
+
export declare function getProxyAgent(): HttpsProxyAgent<string> | undefined;
|
package/lib/utils.js
CHANGED
|
@@ -9,7 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.nextTick = exports.pickDefined = exports.keysOf = exports.identity = exports.isTruthy = exports.showErrorForDeprecatedField = exports.showWarningForDeprecatedField = exports.doesYamlFileExist = exports.isCustomRuleId = exports.getMatchingStatusCodeRange = exports.assignExisting = exports.isNotString = exports.isString = exports.isNotEmptyObject = exports.slash = exports.isPathParameter = exports.yamlAndJsonSyncReader = exports.readFileAsStringSync = exports.isSingular = exports.validateMimeTypeOAS3 = exports.validateMimeType = exports.splitCamelCaseIntoWords = exports.omitObjectProps = exports.pickObjectProps = exports.readFileFromUrl = exports.isEmptyArray = exports.isEmptyObject = exports.isPlainObject = exports.isDefined = exports.loadYaml = exports.popStack = exports.pushStack = exports.stringifyYaml = exports.parseYaml = void 0;
|
|
12
|
+
exports.getProxyAgent = exports.nextTick = exports.pickDefined = exports.keysOf = exports.identity = exports.isTruthy = exports.showErrorForDeprecatedField = exports.showWarningForDeprecatedField = exports.doesYamlFileExist = exports.isCustomRuleId = exports.getMatchingStatusCodeRange = exports.assignExisting = exports.isNotString = exports.isString = exports.isNotEmptyObject = exports.slash = exports.isPathParameter = exports.yamlAndJsonSyncReader = exports.readFileAsStringSync = exports.isSingular = exports.validateMimeTypeOAS3 = exports.validateMimeType = exports.splitCamelCaseIntoWords = exports.omitObjectProps = exports.pickObjectProps = exports.readFileFromUrl = exports.isEmptyArray = exports.isEmptyObject = exports.isPlainObject = exports.isDefined = exports.loadYaml = exports.popStack = exports.pushStack = exports.stringifyYaml = exports.parseYaml = void 0;
|
|
13
13
|
const fs = require("fs");
|
|
14
14
|
const path_1 = require("path");
|
|
15
15
|
const minimatch = require("minimatch");
|
|
@@ -18,6 +18,7 @@ const pluralize = require("pluralize");
|
|
|
18
18
|
const js_yaml_1 = require("./js-yaml");
|
|
19
19
|
const env_1 = require("./env");
|
|
20
20
|
const logger_1 = require("./logger");
|
|
21
|
+
const https_proxy_agent_1 = require("https-proxy-agent");
|
|
21
22
|
var js_yaml_2 = require("./js-yaml");
|
|
22
23
|
Object.defineProperty(exports, "parseYaml", { enumerable: true, get: function () { return js_yaml_2.parseYaml; } });
|
|
23
24
|
Object.defineProperty(exports, "stringifyYaml", { enumerable: true, get: function () { return js_yaml_2.stringifyYaml; } });
|
|
@@ -239,3 +240,8 @@ exports.nextTick = nextTick;
|
|
|
239
240
|
function getUpdatedFieldName(updatedField, updatedObject) {
|
|
240
241
|
return `${typeof updatedObject !== 'undefined' ? `${updatedObject}.` : ''}${updatedField}`;
|
|
241
242
|
}
|
|
243
|
+
function getProxyAgent() {
|
|
244
|
+
const proxy = process.env.HTTPS_PROXY || process.env.HTTP_PROXY;
|
|
245
|
+
return proxy ? new https_proxy_agent_1.HttpsProxyAgent(proxy) : undefined;
|
|
246
|
+
}
|
|
247
|
+
exports.getProxyAgent = getProxyAgent;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@redocly/openapi-core",
|
|
3
|
-
"version": "1.10.
|
|
3
|
+
"version": "1.10.2",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"engines": {
|
|
@@ -18,7 +18,8 @@
|
|
|
18
18
|
"path": "path-browserify",
|
|
19
19
|
"os": false,
|
|
20
20
|
"node-fetch": false,
|
|
21
|
-
"colorette": false
|
|
21
|
+
"colorette": false,
|
|
22
|
+
"https-proxy-agent": false
|
|
22
23
|
},
|
|
23
24
|
"homepage": "https://github.com/Redocly/redocly-cli",
|
|
24
25
|
"keywords": [
|
|
@@ -36,6 +37,7 @@
|
|
|
36
37
|
"dependencies": {
|
|
37
38
|
"@redocly/ajv": "^8.11.0",
|
|
38
39
|
"colorette": "^1.2.0",
|
|
40
|
+
"https-proxy-agent": "^7.0.4",
|
|
39
41
|
"js-levenshtein": "^1.1.6",
|
|
40
42
|
"js-yaml": "^4.1.0",
|
|
41
43
|
"lodash.isequal": "^4.5.0",
|
package/src/bundle.ts
CHANGED
|
@@ -14,7 +14,7 @@ import { isAbsoluteUrl, isRef, Location, refBaseName } from './ref-utils';
|
|
|
14
14
|
import { initRules } from './config/rules';
|
|
15
15
|
import { reportUnresolvedRef } from './rules/no-unresolved-refs';
|
|
16
16
|
import { isPlainObject, isTruthy } from './utils';
|
|
17
|
-
import { isRedoclyRegistryURL } from './redocly';
|
|
17
|
+
import { isRedoclyRegistryURL } from './redocly/domains';
|
|
18
18
|
import { RemoveUnusedComponents as RemoveUnusedComponentsOas2 } from './decorators/oas2/remove-unused-components';
|
|
19
19
|
import { RemoveUnusedComponents as RemoveUnusedComponentsOas3 } from './decorators/oas3/remove-unused-components';
|
|
20
20
|
import { ConfigTypes } from './types/redocly-yaml';
|
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
|
|
13
|
+
import { isBrowser } from '../env';
|
|
14
14
|
|
|
15
15
|
import type { NodeType } from '../types';
|
|
16
16
|
import type {
|
|
@@ -35,25 +35,6 @@ 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
|
-
|
|
57
38
|
function getIgnoreFilePath(configFile?: string): string | undefined {
|
|
58
39
|
if (configFile) {
|
|
59
40
|
return doesYamlFileExist(configFile)
|
|
@@ -64,9 +45,6 @@ function getIgnoreFilePath(configFile?: string): string | undefined {
|
|
|
64
45
|
}
|
|
65
46
|
}
|
|
66
47
|
|
|
67
|
-
export const DOMAINS = getDomains();
|
|
68
|
-
export const AVAILABLE_REGIONS = Object.keys(DOMAINS) as Region[];
|
|
69
|
-
|
|
70
48
|
export class StyleguideConfig {
|
|
71
49
|
plugins: Plugin[];
|
|
72
50
|
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
|
|
6
|
+
import { Config } from './config';
|
|
7
7
|
import { ConfigValidationError, transformConfig } from './utils';
|
|
8
8
|
import { resolveConfig, resolveConfigFileAndRefs } from './config-resolvers';
|
|
9
9
|
import { bundleConfig } from '../bundle';
|
|
@@ -12,6 +12,7 @@ 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';
|
|
15
16
|
|
|
16
17
|
async function addConfigMetadata({
|
|
17
18
|
rawConfig,
|
package/src/index.ts
CHANGED
|
@@ -1,4 +1,11 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export {
|
|
2
|
+
BundleOutputFormat,
|
|
3
|
+
readFileFromUrl,
|
|
4
|
+
slash,
|
|
5
|
+
doesYamlFileExist,
|
|
6
|
+
isTruthy,
|
|
7
|
+
getProxyAgent,
|
|
8
|
+
} from './utils';
|
|
2
9
|
export { Oas3_1Types } from './types/oas3_1';
|
|
3
10
|
export { Oas3Types } from './types/oas3';
|
|
4
11
|
export { Oas2Types } from './types/oas2';
|
|
@@ -41,7 +48,9 @@ export {
|
|
|
41
48
|
ResolvedApi,
|
|
42
49
|
} from './config';
|
|
43
50
|
|
|
44
|
-
export { RedoclyClient
|
|
51
|
+
export { RedoclyClient } from './redocly';
|
|
52
|
+
|
|
53
|
+
export * from './redocly/domains';
|
|
45
54
|
|
|
46
55
|
export {
|
|
47
56
|
Source,
|