@redocly/openapi-core 0.0.0-snapshot.1741951669 → 0.0.0-snapshot.1742384755
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/lib/bundle.d.ts +0 -2
- package/lib/bundle.js +3 -8
- package/lib/config/builtIn.js +0 -3
- package/lib/config/config-resolvers.js +13 -7
- package/lib/config/config.d.ts +1 -4
- package/lib/config/config.js +4 -7
- package/lib/config/load.d.ts +1 -5
- package/lib/config/load.js +4 -43
- package/lib/config/types.d.ts +0 -8
- package/lib/config/utils.js +2 -1
- package/lib/decorators/oas2/index.d.ts +0 -1
- package/lib/decorators/oas2/index.js +0 -2
- package/lib/decorators/oas3/index.d.ts +0 -1
- package/lib/decorators/oas3/index.js +0 -2
- package/lib/index.d.ts +1 -3
- package/lib/index.js +2 -19
- package/lib/rules/async3/no-channel-trailing-slash.js +1 -1
- package/lib/types/redocly-yaml.js +2 -16
- package/lib/utils.js +7 -8
- package/package.json +8 -5
- package/lib/decorators/common/registry-dependencies.d.ts +0 -2
- package/lib/decorators/common/registry-dependencies.js +0 -24
- package/lib/redocly/domains.d.ts +0 -14
- package/lib/redocly/domains.js +0 -41
- package/lib/redocly/index.d.ts +0 -30
- package/lib/redocly/index.js +0 -131
- package/lib/redocly/redocly-client-types.d.ts +0 -8
- package/lib/redocly/redocly-client-types.js +0 -2
- package/lib/redocly/registry-api-types.d.ts +0 -29
- package/lib/redocly/registry-api-types.js +0 -2
- package/lib/redocly/registry-api.d.ts +0 -17
- package/lib/redocly/registry-api.js +0 -100
package/lib/bundle.d.ts
CHANGED
|
@@ -15,7 +15,6 @@ export type BundleOptions = {
|
|
|
15
15
|
config: Config;
|
|
16
16
|
dereference?: boolean;
|
|
17
17
|
base?: string | null;
|
|
18
|
-
skipRedoclyRegistryRefs?: boolean;
|
|
19
18
|
removeUnusedComponents?: boolean;
|
|
20
19
|
keepUrlRefs?: boolean;
|
|
21
20
|
};
|
|
@@ -43,7 +42,6 @@ export declare function bundleDocument(opts: {
|
|
|
43
42
|
customTypes?: Record<string, NodeType>;
|
|
44
43
|
externalRefResolver: BaseResolver;
|
|
45
44
|
dereference?: boolean;
|
|
46
|
-
skipRedoclyRegistryRefs?: boolean;
|
|
47
45
|
removeUnusedComponents?: boolean;
|
|
48
46
|
keepUrlRefs?: boolean;
|
|
49
47
|
}): Promise<BundleResult>;
|
package/lib/bundle.js
CHANGED
|
@@ -15,7 +15,6 @@ const ref_utils_1 = require("./ref-utils");
|
|
|
15
15
|
const rules_1 = require("./config/rules");
|
|
16
16
|
const no_unresolved_refs_1 = require("./rules/no-unresolved-refs");
|
|
17
17
|
const utils_1 = require("./utils");
|
|
18
|
-
const domains_1 = require("./redocly/domains");
|
|
19
18
|
const remove_unused_components_1 = require("./decorators/oas2/remove-unused-components");
|
|
20
19
|
const remove_unused_components_2 = require("./decorators/oas3/remove-unused-components");
|
|
21
20
|
const redocly_yaml_1 = require("./types/redocly-yaml");
|
|
@@ -83,7 +82,7 @@ async function bundleFromString(opts) {
|
|
|
83
82
|
});
|
|
84
83
|
}
|
|
85
84
|
async function bundleDocument(opts) {
|
|
86
|
-
const { document, config, customTypes, externalRefResolver, dereference = false,
|
|
85
|
+
const { document, config, customTypes, externalRefResolver, dereference = false, removeUnusedComponents = false, keepUrlRefs = false, } = opts;
|
|
87
86
|
const specVersion = (0, oas_types_1.detectSpec)(document.parsed);
|
|
88
87
|
const specMajorVersion = (0, oas_types_1.getMajorSpecVersion)(specVersion);
|
|
89
88
|
const rules = config.getRulesForSpecVersion(specMajorVersion);
|
|
@@ -129,7 +128,7 @@ async function bundleDocument(opts) {
|
|
|
129
128
|
{
|
|
130
129
|
severity: 'error',
|
|
131
130
|
ruleId: 'bundler',
|
|
132
|
-
visitor: makeBundleVisitor(specMajorVersion, dereference,
|
|
131
|
+
visitor: makeBundleVisitor(specMajorVersion, dereference, document, resolvedRefMap, keepUrlRefs),
|
|
133
132
|
},
|
|
134
133
|
...decorators,
|
|
135
134
|
], types);
|
|
@@ -231,7 +230,7 @@ function replaceRef(ref, resolved, ctx) {
|
|
|
231
230
|
}
|
|
232
231
|
}
|
|
233
232
|
// function oas3Move
|
|
234
|
-
function makeBundleVisitor(version, dereference,
|
|
233
|
+
function makeBundleVisitor(version, dereference, rootDocument, resolvedRefMap, keepUrlRefs) {
|
|
235
234
|
let components;
|
|
236
235
|
let rootLocation;
|
|
237
236
|
const visitor = {
|
|
@@ -247,10 +246,6 @@ function makeBundleVisitor(version, dereference, skipRedoclyRegistryRefs, rootDo
|
|
|
247
246
|
!dereference) {
|
|
248
247
|
return;
|
|
249
248
|
}
|
|
250
|
-
// do not bundle registry URL before push, otherwise we can't record dependencies
|
|
251
|
-
if (skipRedoclyRegistryRefs && (0, domains_1.isRedoclyRegistryURL)(node.$ref)) {
|
|
252
|
-
return;
|
|
253
|
-
}
|
|
254
249
|
if (keepUrlRefs && (0, ref_utils_1.isAbsoluteUrl)(node.$ref)) {
|
|
255
250
|
return;
|
|
256
251
|
}
|
package/lib/config/builtIn.js
CHANGED
|
@@ -24,9 +24,6 @@ exports.builtInConfigs = {
|
|
|
24
24
|
minimal: minimal_1.default,
|
|
25
25
|
all: all_1.default,
|
|
26
26
|
spec: spec_1.default,
|
|
27
|
-
'redocly-registry': {
|
|
28
|
-
decorators: { 'registry-dependencies': 'on' },
|
|
29
|
-
},
|
|
30
27
|
};
|
|
31
28
|
exports.defaultPlugin = {
|
|
32
29
|
id: '', // default plugin doesn't have id
|
|
@@ -91,18 +91,24 @@ async function resolvePlugins(plugins, configDir = '') {
|
|
|
91
91
|
if (!pluginsCache.has(absolutePluginPath)) {
|
|
92
92
|
let requiredPlugin;
|
|
93
93
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
94
|
-
// @ts-ignore
|
|
94
|
+
// @ts-ignore FIXME: remove?
|
|
95
95
|
if (typeof __webpack_require__ === 'function') {
|
|
96
96
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
97
|
-
// @ts-ignore
|
|
97
|
+
// @ts-ignore FIXME: remove?
|
|
98
98
|
requiredPlugin = __non_webpack_require__(absolutePluginPath);
|
|
99
99
|
}
|
|
100
100
|
else {
|
|
101
|
-
//
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
101
|
+
// FIXME: fix this mess after we migrate to ESM
|
|
102
|
+
try {
|
|
103
|
+
// Workaround for dynamic imports being transpiled to require by Typescript: https://github.com/microsoft/TypeScript/issues/43329#issuecomment-811606238
|
|
104
|
+
const _importDynamic = new Function('modulePath', 'return import(modulePath)');
|
|
105
|
+
const mod = await _importDynamic((0, url_1.pathToFileURL)(absolutePluginPath).href);
|
|
106
|
+
requiredPlugin = mod.default || mod;
|
|
107
|
+
}
|
|
108
|
+
catch (e) {
|
|
109
|
+
const mod = await Promise.resolve(`${(0, url_1.pathToFileURL)(absolutePluginPath).href}`).then(s => require(s));
|
|
110
|
+
requiredPlugin = mod.default || mod;
|
|
111
|
+
}
|
|
106
112
|
}
|
|
107
113
|
const pluginCreatorOptions = { contentDir: configDir };
|
|
108
114
|
const pluginModule = (0, utils_2.isDeprecatedPluginFormat)(requiredPlugin)
|
package/lib/config/config.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { SpecVersion, SpecMajorVersion } from '../oas-types';
|
|
|
2
2
|
import type { NormalizedProblem } from '../walk';
|
|
3
3
|
import type { Oas2RuleSet, Oas3RuleSet, Async3RuleSet, Arazzo1RuleSet, Overlay1RuleSet } from '../oas-types';
|
|
4
4
|
import type { NodeType } from '../types';
|
|
5
|
-
import type { DecoratorConfig, Plugin, PreprocessorConfig,
|
|
5
|
+
import type { DecoratorConfig, Plugin, PreprocessorConfig, ResolveConfig, ResolvedApi, ResolvedConfig, ResolvedStyleguideConfig, RuleConfig, RuleSettings, Telemetry, ThemeRawConfig } from './types';
|
|
6
6
|
export declare const IGNORE_FILE = ".redocly.lint-ignore.yaml";
|
|
7
7
|
export declare class StyleguideConfig {
|
|
8
8
|
rawConfig: ResolvedStyleguideConfig;
|
|
@@ -44,10 +44,7 @@ export declare class Config {
|
|
|
44
44
|
styleguide: StyleguideConfig;
|
|
45
45
|
resolve: ResolveConfig;
|
|
46
46
|
licenseKey?: string;
|
|
47
|
-
region?: Region;
|
|
48
47
|
theme: ThemeRawConfig;
|
|
49
|
-
organization?: string;
|
|
50
|
-
files: string[];
|
|
51
48
|
telemetry?: Telemetry;
|
|
52
49
|
constructor(rawConfig: ResolvedConfig, configFile?: string | undefined);
|
|
53
50
|
}
|
package/lib/config/config.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Config = exports.StyleguideConfig = exports.IGNORE_FILE = void 0;
|
|
4
|
-
const fs = require("fs");
|
|
5
|
-
const path = require("path");
|
|
4
|
+
const fs = require("node:fs");
|
|
5
|
+
const path = require("node:path");
|
|
6
6
|
const js_yaml_1 = require("../js-yaml");
|
|
7
7
|
const utils_1 = require("../utils");
|
|
8
8
|
const oas_types_1 = require("../oas-types");
|
|
@@ -79,7 +79,7 @@ class StyleguideConfig {
|
|
|
79
79
|
return;
|
|
80
80
|
this.ignore =
|
|
81
81
|
(0, js_yaml_1.parseYaml)(fs.readFileSync(ignoreFile, 'utf-8')) || {};
|
|
82
|
-
replaceSpecWithStruct(Object.keys(this.ignore), this.ignore);
|
|
82
|
+
replaceSpecWithStruct(Object.keys(this.ignore), this.ignore); // FIXME: remove this
|
|
83
83
|
// resolve ignore paths
|
|
84
84
|
for (const fileName of Object.keys(this.ignore)) {
|
|
85
85
|
this.ignore[(0, ref_utils_1.isAbsoluteUrl)(fileName) ? fileName : path.resolve(path.dirname(ignoreFile), fileName)] = this.ignore[fileName];
|
|
@@ -325,11 +325,8 @@ class Config {
|
|
|
325
325
|
this.configFile = configFile;
|
|
326
326
|
this.apis = rawConfig.apis || {};
|
|
327
327
|
this.styleguide = new StyleguideConfig(rawConfig.styleguide || {}, configFile);
|
|
328
|
-
this.theme = rawConfig.theme || {};
|
|
328
|
+
this.theme = rawConfig.theme || {}; // FIXME: theme is deprecated
|
|
329
329
|
this.resolve = (0, utils_2.getResolveConfig)(rawConfig?.resolve);
|
|
330
|
-
this.region = rawConfig.region;
|
|
331
|
-
this.organization = rawConfig.organization;
|
|
332
|
-
this.files = rawConfig.files || [];
|
|
333
330
|
this.telemetry = rawConfig.telemetry;
|
|
334
331
|
}
|
|
335
332
|
}
|
package/lib/config/load.d.ts
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { BaseResolver } from '../resolve';
|
|
2
2
|
import type { Config } from './config';
|
|
3
3
|
import type { Document, ResolvedRefMap } from '../resolve';
|
|
4
|
-
import type {
|
|
5
|
-
import type { RawConfig, RawUniversalConfig, Region } from './types';
|
|
4
|
+
import type { RawConfig, RawUniversalConfig } from './types';
|
|
6
5
|
export type RawConfigProcessor = (params: {
|
|
7
6
|
document: Document;
|
|
8
7
|
resolvedRefMap: ResolvedRefMap;
|
|
@@ -14,8 +13,6 @@ export declare function loadConfig(options?: {
|
|
|
14
13
|
customExtends?: string[];
|
|
15
14
|
processRawConfig?: RawConfigProcessor;
|
|
16
15
|
externalRefResolver?: BaseResolver;
|
|
17
|
-
files?: string[];
|
|
18
|
-
region?: Region;
|
|
19
16
|
}): Promise<Config>;
|
|
20
17
|
export declare const CONFIG_FILE_NAMES: string[];
|
|
21
18
|
export declare function findConfig(dir?: string): string | undefined;
|
|
@@ -30,7 +27,6 @@ export declare function getConfig(options?: {
|
|
|
30
27
|
}>;
|
|
31
28
|
type CreateConfigOptions = {
|
|
32
29
|
extends?: string[];
|
|
33
|
-
tokens?: RegionalTokenWithValidity[];
|
|
34
30
|
configPath?: string;
|
|
35
31
|
externalRefResolver?: BaseResolver;
|
|
36
32
|
};
|
package/lib/config/load.js
CHANGED
|
@@ -7,16 +7,13 @@ exports.getConfig = getConfig;
|
|
|
7
7
|
exports.createConfig = createConfig;
|
|
8
8
|
const fs = require("fs");
|
|
9
9
|
const path = require("path");
|
|
10
|
-
const redocly_1 = require("../redocly");
|
|
11
10
|
const utils_1 = require("../utils");
|
|
12
11
|
const js_yaml_1 = require("../js-yaml");
|
|
13
12
|
const utils_2 = require("./utils");
|
|
14
13
|
const config_resolvers_1 = require("./config-resolvers");
|
|
15
14
|
const bundle_1 = require("../bundle");
|
|
16
15
|
const resolve_1 = require("../resolve");
|
|
17
|
-
|
|
18
|
-
const domains_1 = require("../redocly/domains");
|
|
19
|
-
async function addConfigMetadata({ rawConfig, customExtends, configPath, tokens, files, region, externalRefResolver, }) {
|
|
16
|
+
async function addConfigMetadata({ rawConfig, customExtends, configPath, externalRefResolver, }) {
|
|
20
17
|
if (customExtends !== undefined) {
|
|
21
18
|
rawConfig.styleguide = rawConfig.styleguide || {};
|
|
22
19
|
rawConfig.styleguide.extends = customExtends;
|
|
@@ -24,58 +21,22 @@ async function addConfigMetadata({ rawConfig, customExtends, configPath, tokens,
|
|
|
24
21
|
else if ((0, utils_1.isEmptyObject)(rawConfig)) {
|
|
25
22
|
rawConfig.styleguide = { extends: ['recommended'], recommendedFallback: true };
|
|
26
23
|
}
|
|
27
|
-
if (tokens?.length) {
|
|
28
|
-
if (!rawConfig.resolve)
|
|
29
|
-
rawConfig.resolve = {};
|
|
30
|
-
if (!rawConfig.resolve.http)
|
|
31
|
-
rawConfig.resolve.http = {};
|
|
32
|
-
rawConfig.resolve.http.headers = [...(rawConfig.resolve.http.headers ?? [])];
|
|
33
|
-
for (const item of tokens) {
|
|
34
|
-
const domain = domains_1.DOMAINS[item.region];
|
|
35
|
-
rawConfig.resolve.http.headers.push({
|
|
36
|
-
matches: `https://api.${domain}/registry/**`,
|
|
37
|
-
name: 'Authorization',
|
|
38
|
-
envVariable: undefined,
|
|
39
|
-
value: item.token,
|
|
40
|
-
},
|
|
41
|
-
//support redocly.com domain for future compatibility
|
|
42
|
-
...(item.region === 'us'
|
|
43
|
-
? [
|
|
44
|
-
{
|
|
45
|
-
matches: `https://api.redoc.ly/registry/**`,
|
|
46
|
-
name: 'Authorization',
|
|
47
|
-
envVariable: undefined,
|
|
48
|
-
value: item.token,
|
|
49
|
-
},
|
|
50
|
-
]
|
|
51
|
-
: []));
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
24
|
return (0, config_resolvers_1.resolveConfig)({
|
|
55
|
-
rawConfig
|
|
56
|
-
...rawConfig,
|
|
57
|
-
files: files ?? rawConfig.files,
|
|
58
|
-
region: region ?? rawConfig.region,
|
|
59
|
-
},
|
|
25
|
+
rawConfig,
|
|
60
26
|
configPath,
|
|
61
27
|
externalRefResolver,
|
|
62
28
|
});
|
|
63
29
|
}
|
|
64
30
|
async function loadConfig(options = {}) {
|
|
65
|
-
const { configPath = findConfig(), customExtends, processRawConfig,
|
|
31
|
+
const { configPath = findConfig(), customExtends, processRawConfig, externalRefResolver, } = options;
|
|
66
32
|
const { rawConfig, document, parsed, resolvedRefMap } = await getConfig({
|
|
67
33
|
configPath,
|
|
68
34
|
externalRefResolver,
|
|
69
35
|
});
|
|
70
|
-
const redoclyClient = env_1.isBrowser ? undefined : new redocly_1.RedoclyClient();
|
|
71
|
-
const tokens = redoclyClient && redoclyClient.hasTokens() ? redoclyClient.getAllTokens() : [];
|
|
72
36
|
const config = await addConfigMetadata({
|
|
73
37
|
rawConfig,
|
|
74
38
|
customExtends,
|
|
75
39
|
configPath,
|
|
76
|
-
tokens,
|
|
77
|
-
files,
|
|
78
|
-
region,
|
|
79
40
|
externalRefResolver,
|
|
80
41
|
});
|
|
81
42
|
if (document && parsed && resolvedRefMap && typeof processRawConfig === 'function') {
|
|
@@ -98,7 +59,7 @@ async function loadConfig(options = {}) {
|
|
|
98
59
|
}
|
|
99
60
|
exports.CONFIG_FILE_NAMES = ['redocly.yaml', 'redocly.yml', '.redocly.yaml', '.redocly.yml'];
|
|
100
61
|
function findConfig(dir) {
|
|
101
|
-
if (!fs?.
|
|
62
|
+
if (!fs?.existsSync)
|
|
102
63
|
return;
|
|
103
64
|
const existingConfigFiles = exports.CONFIG_FILE_NAMES.map((name) => dir ? path.resolve(dir, name) : name).filter(fs.existsSync);
|
|
104
65
|
if (existingConfigFiles.length > 1) {
|
package/lib/config/types.d.ts
CHANGED
|
@@ -137,11 +137,7 @@ export type HttpResolveConfig = {
|
|
|
137
137
|
export type ResolveConfig = {
|
|
138
138
|
http: HttpResolveConfig;
|
|
139
139
|
};
|
|
140
|
-
export type Region = 'us' | 'eu';
|
|
141
140
|
export type Telemetry = 'on' | 'off';
|
|
142
|
-
export type AccessTokens = {
|
|
143
|
-
[region in Region]?: string;
|
|
144
|
-
};
|
|
145
141
|
export type DeprecatedInRawConfig = {
|
|
146
142
|
apiDefinitions?: Record<string, string>;
|
|
147
143
|
lint?: StyleguideRawConfig;
|
|
@@ -159,15 +155,11 @@ export type DeprecatedInApi = {
|
|
|
159
155
|
} & DeprecatedFeaturesConfig;
|
|
160
156
|
export type ResolvedApi = Omit<Api, 'styleguide'> & {
|
|
161
157
|
styleguide: ResolvedStyleguideConfig;
|
|
162
|
-
files?: string[];
|
|
163
158
|
};
|
|
164
159
|
export type RawConfig = {
|
|
165
160
|
apis?: Record<string, Api>;
|
|
166
161
|
styleguide?: StyleguideRawConfig;
|
|
167
162
|
resolve?: RawResolveConfig;
|
|
168
|
-
region?: Region;
|
|
169
|
-
organization?: string;
|
|
170
|
-
files?: string[];
|
|
171
163
|
telemetry?: Telemetry;
|
|
172
164
|
} & ThemeConfig;
|
|
173
165
|
export type RawUniversalConfig = Omit<RawConfig, 'styleguide'> & StyleguideRawConfig;
|
package/lib/config/utils.js
CHANGED
|
@@ -206,11 +206,11 @@ function getMergedConfig(config, apiName) {
|
|
|
206
206
|
extendPaths,
|
|
207
207
|
pluginPaths,
|
|
208
208
|
},
|
|
209
|
+
// FIXME: theme is deprecated
|
|
209
210
|
theme: {
|
|
210
211
|
...config.rawConfig.theme,
|
|
211
212
|
...config.apis[apiName]?.theme,
|
|
212
213
|
},
|
|
213
|
-
files: [...config.files, ...(config.apis?.[apiName]?.files ?? [])],
|
|
214
214
|
// TODO: merge everything else here
|
|
215
215
|
}, config.configFile)
|
|
216
216
|
: config;
|
|
@@ -255,6 +255,7 @@ function transformConfig(rawConfig) {
|
|
|
255
255
|
const { apis, apiDefinitions, referenceDocs, lint, ...rest } = rawConfig;
|
|
256
256
|
const { styleguideConfig, rawConfigRest } = extractFlatConfig(rest);
|
|
257
257
|
const transformedConfig = {
|
|
258
|
+
// FIXME: ? theme is deprecated
|
|
258
259
|
theme: {
|
|
259
260
|
openapi: {
|
|
260
261
|
...referenceDocs,
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import type { Oas2Decorator } from '../../visitors';
|
|
2
2
|
export declare const decorators: {
|
|
3
|
-
'registry-dependencies': Oas2Decorator;
|
|
4
3
|
'operation-description-override': Oas2Decorator;
|
|
5
4
|
'tag-description-override': Oas2Decorator;
|
|
6
5
|
'info-description-override': Oas2Decorator;
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.decorators = void 0;
|
|
4
|
-
const registry_dependencies_1 = require("../common/registry-dependencies");
|
|
5
4
|
const operation_description_override_1 = require("../common/operation-description-override");
|
|
6
5
|
const tag_description_override_1 = require("../common/tag-description-override");
|
|
7
6
|
const info_description_override_1 = require("../common/info-description-override");
|
|
@@ -10,7 +9,6 @@ const remove_x_internal_1 = require("../common/remove-x-internal");
|
|
|
10
9
|
const filter_in_1 = require("../common/filters/filter-in");
|
|
11
10
|
const filter_out_1 = require("../common/filters/filter-out");
|
|
12
11
|
exports.decorators = {
|
|
13
|
-
'registry-dependencies': registry_dependencies_1.RegistryDependencies,
|
|
14
12
|
'operation-description-override': operation_description_override_1.OperationDescriptionOverride,
|
|
15
13
|
'tag-description-override': tag_description_override_1.TagDescriptionOverride,
|
|
16
14
|
'info-description-override': info_description_override_1.InfoDescriptionOverride,
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import type { Oas3Decorator } from '../../visitors';
|
|
2
2
|
export declare const decorators: {
|
|
3
|
-
'registry-dependencies': Oas3Decorator;
|
|
4
3
|
'operation-description-override': Oas3Decorator;
|
|
5
4
|
'tag-description-override': Oas3Decorator;
|
|
6
5
|
'info-description-override': Oas3Decorator;
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.decorators = void 0;
|
|
4
|
-
const registry_dependencies_1 = require("../common/registry-dependencies");
|
|
5
4
|
const operation_description_override_1 = require("../common/operation-description-override");
|
|
6
5
|
const tag_description_override_1 = require("../common/tag-description-override");
|
|
7
6
|
const info_description_override_1 = require("../common/info-description-override");
|
|
@@ -11,7 +10,6 @@ const filter_in_1 = require("../common/filters/filter-in");
|
|
|
11
10
|
const filter_out_1 = require("../common/filters/filter-out");
|
|
12
11
|
const media_type_examples_override_1 = require("../common/media-type-examples-override");
|
|
13
12
|
exports.decorators = {
|
|
14
|
-
'registry-dependencies': registry_dependencies_1.RegistryDependencies,
|
|
15
13
|
'operation-description-override': operation_description_override_1.OperationDescriptionOverride,
|
|
16
14
|
'tag-description-override': tag_description_override_1.TagDescriptionOverride,
|
|
17
15
|
'info-description-override': info_description_override_1.InfoDescriptionOverride,
|
package/lib/index.d.ts
CHANGED
|
@@ -11,9 +11,7 @@ export type { Oas2Definition } from './typings/swagger';
|
|
|
11
11
|
export type { StatsAccumulator, StatsName } from './typings/common';
|
|
12
12
|
export { normalizeTypes } from './types';
|
|
13
13
|
export { Stats } from './rules/other/stats';
|
|
14
|
-
export { Config, StyleguideConfig, RawConfig, RawUniversalConfig, IGNORE_FILE,
|
|
15
|
-
export { RedoclyClient } from './redocly';
|
|
16
|
-
export * from './redocly/domains';
|
|
14
|
+
export { Config, StyleguideConfig, RawConfig, RawUniversalConfig, IGNORE_FILE, getMergedConfig, transformConfig, loadConfig, getConfig, findConfig, CONFIG_FILE_NAMES, RuleSeverity, createConfig, ResolvedApi, } from './config';
|
|
17
15
|
export { Source, BaseResolver, Document, resolveDocument, ResolveError, YamlParseError, makeDocumentFromString, } from './resolve';
|
|
18
16
|
export { parseYaml, stringifyYaml } from './js-yaml';
|
|
19
17
|
export { unescapePointer, isRef, isAbsoluteUrl } from './ref-utils';
|
package/lib/index.js
CHANGED
|
@@ -1,21 +1,7 @@
|
|
|
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
|
-
};
|
|
16
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
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.
|
|
18
|
-
exports.bundleFromString = exports.mapTypeToComponent = exports.bundleDocument = exports.bundle = exports.lintConfig = exports.lintFromString =
|
|
3
|
+
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.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.AsyncApi3Types = exports.AsyncApi2Types = exports.Oas2Types = exports.Oas3Types = exports.Arazzo1Types = exports.Oas3_1Types = exports.pause = exports.getProxyAgent = exports.isTruthy = exports.doesYamlFileExist = exports.slash = exports.readFileFromUrl = void 0;
|
|
4
|
+
exports.bundleFromString = exports.mapTypeToComponent = exports.bundleDocument = exports.bundle = exports.lintConfig = exports.lintFromString = void 0;
|
|
19
5
|
var utils_1 = require("./utils");
|
|
20
6
|
Object.defineProperty(exports, "readFileFromUrl", { enumerable: true, get: function () { return utils_1.readFileFromUrl; } });
|
|
21
7
|
Object.defineProperty(exports, "slash", { enumerable: true, get: function () { return utils_1.slash; } });
|
|
@@ -52,9 +38,6 @@ Object.defineProperty(exports, "getConfig", { enumerable: true, get: function ()
|
|
|
52
38
|
Object.defineProperty(exports, "findConfig", { enumerable: true, get: function () { return config_1.findConfig; } });
|
|
53
39
|
Object.defineProperty(exports, "CONFIG_FILE_NAMES", { enumerable: true, get: function () { return config_1.CONFIG_FILE_NAMES; } });
|
|
54
40
|
Object.defineProperty(exports, "createConfig", { enumerable: true, get: function () { return config_1.createConfig; } });
|
|
55
|
-
var redocly_1 = require("./redocly");
|
|
56
|
-
Object.defineProperty(exports, "RedoclyClient", { enumerable: true, get: function () { return redocly_1.RedoclyClient; } });
|
|
57
|
-
__exportStar(require("./redocly/domains"), exports);
|
|
58
41
|
var resolve_1 = require("./resolve");
|
|
59
42
|
Object.defineProperty(exports, "Source", { enumerable: true, get: function () { return resolve_1.Source; } });
|
|
60
43
|
Object.defineProperty(exports, "BaseResolver", { enumerable: true, get: function () { return resolve_1.BaseResolver; } });
|
|
@@ -4,7 +4,7 @@ exports.NoChannelTrailingSlash = void 0;
|
|
|
4
4
|
const NoChannelTrailingSlash = () => {
|
|
5
5
|
return {
|
|
6
6
|
Channel(channel, { report, location }) {
|
|
7
|
-
if (channel
|
|
7
|
+
if (channel?.address?.endsWith('/') && channel?.address !== '/') {
|
|
8
8
|
report({
|
|
9
9
|
message: `\`${channel.address}\` should not have a trailing slash.`,
|
|
10
10
|
location: location.key(),
|
|
@@ -307,8 +307,6 @@ const createConfigRoot = (nodeTypes) => ({
|
|
|
307
307
|
apis: 'ConfigApis', // Override apis with internal format
|
|
308
308
|
'features.openapi': 'ConfigReferenceDocs', // deprecated
|
|
309
309
|
'features.mockServer': 'ConfigMockServer', // deprecated
|
|
310
|
-
organization: { type: 'string' },
|
|
311
|
-
region: { enum: ['us', 'eu'] },
|
|
312
310
|
telemetry: { enum: ['on', 'off'] },
|
|
313
311
|
resolve: {
|
|
314
312
|
properties: {
|
|
@@ -316,12 +314,6 @@ const createConfigRoot = (nodeTypes) => ({
|
|
|
316
314
|
doNotResolveExamples: { type: 'boolean' },
|
|
317
315
|
},
|
|
318
316
|
},
|
|
319
|
-
files: {
|
|
320
|
-
type: 'array',
|
|
321
|
-
items: {
|
|
322
|
-
type: 'string',
|
|
323
|
-
},
|
|
324
|
-
},
|
|
325
317
|
},
|
|
326
318
|
});
|
|
327
319
|
const ConfigApis = {
|
|
@@ -341,12 +333,6 @@ const createConfigApisProperties = (nodeTypes) => ({
|
|
|
341
333
|
...ConfigStyleguide.properties,
|
|
342
334
|
'features.openapi': 'ConfigReferenceDocs', // deprecated
|
|
343
335
|
'features.mockServer': 'ConfigMockServer', // deprecated
|
|
344
|
-
files: {
|
|
345
|
-
type: 'array',
|
|
346
|
-
items: {
|
|
347
|
-
type: 'string',
|
|
348
|
-
},
|
|
349
|
-
},
|
|
350
336
|
},
|
|
351
337
|
});
|
|
352
338
|
const ConfigHTTP = {
|
|
@@ -474,7 +460,7 @@ const AssertionDefinitionAssertions = {
|
|
|
474
460
|
},
|
|
475
461
|
additionalProperties: (_value, key) => {
|
|
476
462
|
if (/^\w+\/\w+$/.test(key))
|
|
477
|
-
return {
|
|
463
|
+
return {};
|
|
478
464
|
return;
|
|
479
465
|
},
|
|
480
466
|
};
|
|
@@ -925,7 +911,7 @@ const GenerateCodeSamples = {
|
|
|
925
911
|
// TODO: deprecated
|
|
926
912
|
const ConfigReferenceDocs = {
|
|
927
913
|
properties: {
|
|
928
|
-
theme: 'ConfigTheme',
|
|
914
|
+
theme: 'ConfigTheme', // FIXME: ? theme is deprecated
|
|
929
915
|
corsProxyUrl: { type: 'string' },
|
|
930
916
|
ctrlFHijack: { type: 'boolean' },
|
|
931
917
|
defaultSampleLanguage: { type: 'string' },
|
package/lib/utils.js
CHANGED
|
@@ -37,14 +37,15 @@ exports.nextTick = nextTick;
|
|
|
37
37
|
exports.pause = pause;
|
|
38
38
|
exports.getProxyAgent = getProxyAgent;
|
|
39
39
|
exports.dequal = dequal;
|
|
40
|
-
const fs = require("fs");
|
|
41
|
-
const
|
|
42
|
-
const
|
|
40
|
+
const fs = require("node:fs");
|
|
41
|
+
const node_path_1 = require("node:path");
|
|
42
|
+
const minimatch_1 = require("minimatch");
|
|
43
43
|
const js_yaml_1 = require("./js-yaml");
|
|
44
44
|
const env_1 = require("./env");
|
|
45
45
|
const logger_1 = require("./logger");
|
|
46
46
|
const https_proxy_agent_1 = require("https-proxy-agent");
|
|
47
|
-
const
|
|
47
|
+
const pluralize1 = require("pluralize"); // FIXME: use correct import after migration to ESM
|
|
48
|
+
const pluralizeOne = pluralize1.default || pluralize1; // FIXME: use correct import after migration to ESM
|
|
48
49
|
var js_yaml_2 = require("./js-yaml");
|
|
49
50
|
Object.defineProperty(exports, "parseYaml", { enumerable: true, get: function () { return js_yaml_2.parseYaml; } });
|
|
50
51
|
Object.defineProperty(exports, "stringifyYaml", { enumerable: true, get: function () { return js_yaml_2.stringifyYaml; } });
|
|
@@ -103,7 +104,7 @@ function match(url, pattern) {
|
|
|
103
104
|
// if pattern doesn't specify protocol directly, do not match against it
|
|
104
105
|
url = url.replace(/^https?:\/\//, '');
|
|
105
106
|
}
|
|
106
|
-
return minimatch(url, pattern);
|
|
107
|
+
return (0, minimatch_1.minimatch)(url, pattern);
|
|
107
108
|
}
|
|
108
109
|
function pickObjectProps(object, keys) {
|
|
109
110
|
return Object.fromEntries(keys.filter((key) => key in object).map((key) => [key, object[key]]));
|
|
@@ -213,9 +214,7 @@ function isCustomRuleId(id) {
|
|
|
213
214
|
return id.includes('/');
|
|
214
215
|
}
|
|
215
216
|
function doesYamlFileExist(filePath) {
|
|
216
|
-
return (((0,
|
|
217
|
-
fs?.hasOwnProperty?.('existsSync') &&
|
|
218
|
-
fs.existsSync(filePath));
|
|
217
|
+
return (((0, node_path_1.extname)(filePath) === '.yaml' || (0, node_path_1.extname)(filePath) === '.yml') && !!fs?.existsSync?.(filePath));
|
|
219
218
|
}
|
|
220
219
|
function showWarningForDeprecatedField(deprecatedField, updatedField, updatedObject, link) {
|
|
221
220
|
const readMoreText = link ? `Read more about this change: ${link}` : '';
|
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@redocly/openapi-core",
|
|
3
|
-
"version": "0.0.0-snapshot.
|
|
3
|
+
"version": "0.0.0-snapshot.1742384755",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"engines": {
|
|
7
|
-
"node": ">=18.
|
|
8
|
-
"npm": ">=
|
|
7
|
+
"node": ">=18.20.7",
|
|
8
|
+
"npm": ">=10.8.2"
|
|
9
9
|
},
|
|
10
10
|
"engineStrict": true,
|
|
11
11
|
"license": "MIT",
|
|
@@ -17,6 +17,9 @@
|
|
|
17
17
|
"fs": false,
|
|
18
18
|
"path": "path-browserify",
|
|
19
19
|
"os": false,
|
|
20
|
+
"node:fs": false,
|
|
21
|
+
"node:path": "path-browserify",
|
|
22
|
+
"node:os": false,
|
|
20
23
|
"colorette": false,
|
|
21
24
|
"https-proxy-agent": false
|
|
22
25
|
},
|
|
@@ -41,14 +44,14 @@
|
|
|
41
44
|
"https-proxy-agent": "^7.0.5",
|
|
42
45
|
"js-levenshtein": "^1.1.6",
|
|
43
46
|
"js-yaml": "^4.1.0",
|
|
44
|
-
"minimatch": "^
|
|
47
|
+
"minimatch": "^10.0.1",
|
|
45
48
|
"pluralize": "^8.0.0",
|
|
46
49
|
"yaml-ast-parser": "0.0.43"
|
|
47
50
|
},
|
|
48
51
|
"devDependencies": {
|
|
49
52
|
"@types/js-levenshtein": "^1.1.0",
|
|
50
53
|
"@types/js-yaml": "^4.0.3",
|
|
51
|
-
"@types/minimatch": "^
|
|
54
|
+
"@types/minimatch": "^5.1.2",
|
|
52
55
|
"@types/pluralize": "^0.0.29",
|
|
53
56
|
"json-schema-to-ts": "^3.1.0",
|
|
54
57
|
"typescript": "5.5.3"
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.RegistryDependencies = void 0;
|
|
4
|
-
const domains_1 = require("../../redocly/domains");
|
|
5
|
-
const RegistryDependencies = () => {
|
|
6
|
-
const registryDependencies = new Set();
|
|
7
|
-
return {
|
|
8
|
-
Root: {
|
|
9
|
-
leave(_, ctx) {
|
|
10
|
-
const data = ctx.getVisitorData();
|
|
11
|
-
data.links = Array.from(registryDependencies);
|
|
12
|
-
},
|
|
13
|
-
},
|
|
14
|
-
ref(node) {
|
|
15
|
-
if (node.$ref) {
|
|
16
|
-
const link = node.$ref.split('#/')[0];
|
|
17
|
-
if ((0, domains_1.isRedoclyRegistryURL)(link)) {
|
|
18
|
-
registryDependencies.add(link);
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
},
|
|
22
|
-
};
|
|
23
|
-
};
|
|
24
|
-
exports.RegistryDependencies = RegistryDependencies;
|
package/lib/redocly/domains.d.ts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import type { 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;
|
package/lib/redocly/domains.js
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.AVAILABLE_REGIONS = exports.DOMAINS = exports.DEFAULT_REGION = void 0;
|
|
4
|
-
exports.getDomains = getDomains;
|
|
5
|
-
exports.setRedoclyDomain = setRedoclyDomain;
|
|
6
|
-
exports.getRedoclyDomain = getRedoclyDomain;
|
|
7
|
-
exports.isRedoclyRegistryURL = isRedoclyRegistryURL;
|
|
8
|
-
let redoclyDomain = 'redocly.com';
|
|
9
|
-
exports.DEFAULT_REGION = 'us';
|
|
10
|
-
exports.DOMAINS = getDomains();
|
|
11
|
-
exports.AVAILABLE_REGIONS = Object.keys(exports.DOMAINS);
|
|
12
|
-
function getDomains() {
|
|
13
|
-
const domains = {
|
|
14
|
-
us: 'redocly.com',
|
|
15
|
-
eu: 'eu.redocly.com',
|
|
16
|
-
};
|
|
17
|
-
// FIXME: temporary fix for our lab environments
|
|
18
|
-
const domain = redoclyDomain;
|
|
19
|
-
if (domain?.endsWith('.redocly.host')) {
|
|
20
|
-
domains[domain.split('.')[0]] = domain;
|
|
21
|
-
}
|
|
22
|
-
if (domain === 'redoc.online') {
|
|
23
|
-
domains[domain] = domain;
|
|
24
|
-
}
|
|
25
|
-
return domains;
|
|
26
|
-
}
|
|
27
|
-
function setRedoclyDomain(domain) {
|
|
28
|
-
redoclyDomain = domain;
|
|
29
|
-
}
|
|
30
|
-
function getRedoclyDomain() {
|
|
31
|
-
return redoclyDomain;
|
|
32
|
-
}
|
|
33
|
-
function isRedoclyRegistryURL(link) {
|
|
34
|
-
const domain = getRedoclyDomain() || exports.DOMAINS[exports.DEFAULT_REGION];
|
|
35
|
-
const legacyDomain = domain === 'redocly.com' ? 'redoc.ly' : domain;
|
|
36
|
-
if (!link.startsWith(`https://api.${domain}/registry/`) &&
|
|
37
|
-
!link.startsWith(`https://api.${legacyDomain}/registry/`)) {
|
|
38
|
-
return false;
|
|
39
|
-
}
|
|
40
|
-
return true;
|
|
41
|
-
}
|
package/lib/redocly/index.d.ts
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import { RegistryApi } from './registry-api';
|
|
2
|
-
import type { RegionalToken, RegionalTokenWithValidity } from './redocly-client-types';
|
|
3
|
-
import type { AccessTokens, Region } from '../config/types';
|
|
4
|
-
export declare const TOKEN_FILENAME = ".redocly-config.json";
|
|
5
|
-
export declare class RedoclyClient {
|
|
6
|
-
private accessTokens;
|
|
7
|
-
private region;
|
|
8
|
-
domain: string;
|
|
9
|
-
registryApi: RegistryApi;
|
|
10
|
-
constructor(region?: Region);
|
|
11
|
-
loadRegion(region?: Region): Region;
|
|
12
|
-
getRegion(): Region;
|
|
13
|
-
hasTokens(): boolean;
|
|
14
|
-
hasToken(): boolean;
|
|
15
|
-
getAuthorizationHeader(): Promise<string | undefined>;
|
|
16
|
-
setAccessTokens(accessTokens: AccessTokens): void;
|
|
17
|
-
loadTokens(): void;
|
|
18
|
-
getAllTokens(): RegionalToken[];
|
|
19
|
-
getValidTokens(): Promise<RegionalTokenWithValidity[]>;
|
|
20
|
-
getTokens(): Promise<RegionalTokenWithValidity[]>;
|
|
21
|
-
isAuthorizedWithRedoclyByRegion(): Promise<boolean>;
|
|
22
|
-
isAuthorizedWithRedocly(): Promise<boolean>;
|
|
23
|
-
readCredentialsFile(credentialsPath: string): any;
|
|
24
|
-
verifyToken(accessToken: string, verbose?: boolean): Promise<{
|
|
25
|
-
viewerId: string;
|
|
26
|
-
organizations: string[];
|
|
27
|
-
}>;
|
|
28
|
-
login(accessToken: string, verbose?: boolean): Promise<void>;
|
|
29
|
-
logout(): void;
|
|
30
|
-
}
|
package/lib/redocly/index.js
DELETED
|
@@ -1,131 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.RedoclyClient = exports.TOKEN_FILENAME = void 0;
|
|
4
|
-
const fs_1 = require("fs");
|
|
5
|
-
const path_1 = require("path");
|
|
6
|
-
const os_1 = require("os");
|
|
7
|
-
const registry_api_1 = require("./registry-api");
|
|
8
|
-
const env_1 = require("../env");
|
|
9
|
-
const utils_1 = require("../utils");
|
|
10
|
-
const logger_1 = require("../logger");
|
|
11
|
-
const domains_1 = require("./domains");
|
|
12
|
-
exports.TOKEN_FILENAME = '.redocly-config.json';
|
|
13
|
-
class RedoclyClient {
|
|
14
|
-
constructor(region) {
|
|
15
|
-
this.accessTokens = {};
|
|
16
|
-
this.region = this.loadRegion(region);
|
|
17
|
-
this.loadTokens();
|
|
18
|
-
this.domain = region ? domains_1.DOMAINS[region] : env_1.env.REDOCLY_DOMAIN || domains_1.DOMAINS[domains_1.DEFAULT_REGION];
|
|
19
|
-
(0, domains_1.setRedoclyDomain)(this.domain);
|
|
20
|
-
this.registryApi = new registry_api_1.RegistryApi(this.accessTokens, this.region);
|
|
21
|
-
}
|
|
22
|
-
loadRegion(region) {
|
|
23
|
-
if (region && !domains_1.DOMAINS[region]) {
|
|
24
|
-
throw new Error(`Invalid argument: region in config file.\nGiven: ${logger_1.colorize.green(region)}, choices: "us", "eu".`);
|
|
25
|
-
}
|
|
26
|
-
if ((0, domains_1.getRedoclyDomain)()) {
|
|
27
|
-
return (domains_1.AVAILABLE_REGIONS.find((region) => domains_1.DOMAINS[region] === (0, domains_1.getRedoclyDomain)()) || domains_1.DEFAULT_REGION);
|
|
28
|
-
}
|
|
29
|
-
return region || domains_1.DEFAULT_REGION;
|
|
30
|
-
}
|
|
31
|
-
getRegion() {
|
|
32
|
-
return this.region;
|
|
33
|
-
}
|
|
34
|
-
hasTokens() {
|
|
35
|
-
return (0, utils_1.isNotEmptyObject)(this.accessTokens);
|
|
36
|
-
}
|
|
37
|
-
// <backward compatibility: old versions of portal>
|
|
38
|
-
hasToken() {
|
|
39
|
-
return !!this.accessTokens[this.region];
|
|
40
|
-
}
|
|
41
|
-
async getAuthorizationHeader() {
|
|
42
|
-
return this.accessTokens[this.region];
|
|
43
|
-
}
|
|
44
|
-
// </backward compatibility: portal>
|
|
45
|
-
setAccessTokens(accessTokens) {
|
|
46
|
-
this.accessTokens = accessTokens;
|
|
47
|
-
}
|
|
48
|
-
loadTokens() {
|
|
49
|
-
const credentialsPath = (0, path_1.resolve)((0, os_1.homedir)(), exports.TOKEN_FILENAME);
|
|
50
|
-
const credentials = this.readCredentialsFile(credentialsPath);
|
|
51
|
-
if ((0, utils_1.isNotEmptyObject)(credentials)) {
|
|
52
|
-
this.setAccessTokens({
|
|
53
|
-
...credentials,
|
|
54
|
-
...(credentials.token &&
|
|
55
|
-
!credentials[this.region] && {
|
|
56
|
-
[this.region]: credentials.token,
|
|
57
|
-
}),
|
|
58
|
-
});
|
|
59
|
-
}
|
|
60
|
-
if (env_1.env.REDOCLY_AUTHORIZATION) {
|
|
61
|
-
this.setAccessTokens({
|
|
62
|
-
...this.accessTokens,
|
|
63
|
-
[this.region]: env_1.env.REDOCLY_AUTHORIZATION,
|
|
64
|
-
});
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
getAllTokens() {
|
|
68
|
-
return Object.entries(this.accessTokens)
|
|
69
|
-
.filter(([region]) => domains_1.AVAILABLE_REGIONS.includes(region))
|
|
70
|
-
.map(([region, token]) => ({ region, token }));
|
|
71
|
-
}
|
|
72
|
-
async getValidTokens() {
|
|
73
|
-
const allTokens = this.getAllTokens();
|
|
74
|
-
const verifiedTokens = await Promise.allSettled(allTokens.map(({ token }) => this.verifyToken(token)));
|
|
75
|
-
return allTokens
|
|
76
|
-
.filter((_, index) => verifiedTokens[index].status === 'fulfilled')
|
|
77
|
-
.map(({ token, region }) => ({ token, region, valid: true }));
|
|
78
|
-
}
|
|
79
|
-
async getTokens() {
|
|
80
|
-
return this.hasTokens() ? await this.getValidTokens() : [];
|
|
81
|
-
}
|
|
82
|
-
async isAuthorizedWithRedoclyByRegion() {
|
|
83
|
-
if (!this.hasTokens()) {
|
|
84
|
-
return false;
|
|
85
|
-
}
|
|
86
|
-
const accessToken = this.accessTokens[this.region];
|
|
87
|
-
if (!accessToken) {
|
|
88
|
-
return false;
|
|
89
|
-
}
|
|
90
|
-
try {
|
|
91
|
-
await this.verifyToken(accessToken);
|
|
92
|
-
return true;
|
|
93
|
-
}
|
|
94
|
-
catch (err) {
|
|
95
|
-
return false;
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
async isAuthorizedWithRedocly() {
|
|
99
|
-
return this.hasTokens() && (0, utils_1.isNotEmptyArray)(await this.getValidTokens());
|
|
100
|
-
}
|
|
101
|
-
readCredentialsFile(credentialsPath) {
|
|
102
|
-
return (0, fs_1.existsSync)(credentialsPath) ? JSON.parse((0, fs_1.readFileSync)(credentialsPath, 'utf-8')) : {};
|
|
103
|
-
}
|
|
104
|
-
async verifyToken(accessToken, verbose = false) {
|
|
105
|
-
return this.registryApi.authStatus(accessToken, verbose);
|
|
106
|
-
}
|
|
107
|
-
async login(accessToken, verbose = false) {
|
|
108
|
-
const credentialsPath = (0, path_1.resolve)((0, os_1.homedir)(), exports.TOKEN_FILENAME);
|
|
109
|
-
try {
|
|
110
|
-
await this.verifyToken(accessToken, verbose);
|
|
111
|
-
}
|
|
112
|
-
catch (err) {
|
|
113
|
-
throw new Error('Authorization failed. Please check if you entered a valid API key.');
|
|
114
|
-
}
|
|
115
|
-
const credentials = {
|
|
116
|
-
...this.readCredentialsFile(credentialsPath),
|
|
117
|
-
[this.region]: accessToken,
|
|
118
|
-
token: accessToken, // FIXME: backward compatibility, remove on 1.0.0
|
|
119
|
-
};
|
|
120
|
-
this.accessTokens = credentials;
|
|
121
|
-
this.registryApi.setAccessTokens(credentials);
|
|
122
|
-
(0, fs_1.writeFileSync)(credentialsPath, JSON.stringify(credentials, null, 2));
|
|
123
|
-
}
|
|
124
|
-
logout() {
|
|
125
|
-
const credentialsPath = (0, path_1.resolve)((0, os_1.homedir)(), exports.TOKEN_FILENAME);
|
|
126
|
-
if ((0, fs_1.existsSync)(credentialsPath)) {
|
|
127
|
-
(0, fs_1.unlinkSync)(credentialsPath);
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
exports.RedoclyClient = RedoclyClient;
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
interface VersionParams {
|
|
2
|
-
organizationId: string;
|
|
3
|
-
name: string;
|
|
4
|
-
version: string;
|
|
5
|
-
}
|
|
6
|
-
export interface PrepareFileuploadParams extends VersionParams {
|
|
7
|
-
filesHash: string;
|
|
8
|
-
filename: string;
|
|
9
|
-
isUpsert?: boolean;
|
|
10
|
-
}
|
|
11
|
-
export interface PushApiParams extends VersionParams {
|
|
12
|
-
rootFilePath: string;
|
|
13
|
-
filePaths: string[];
|
|
14
|
-
branch?: string;
|
|
15
|
-
isUpsert?: boolean;
|
|
16
|
-
isPublic?: boolean;
|
|
17
|
-
batchId?: string;
|
|
18
|
-
batchSize?: number;
|
|
19
|
-
}
|
|
20
|
-
export interface PrepareFileuploadOKResponse {
|
|
21
|
-
filePath: string;
|
|
22
|
-
signedUploadUrl: string;
|
|
23
|
-
}
|
|
24
|
-
export interface NotFoundProblemResponse {
|
|
25
|
-
status: 404;
|
|
26
|
-
title: 'Not Found';
|
|
27
|
-
code: 'ORGANIZATION_NOT_FOUND' | 'API_VERSION_NOT_FOUND';
|
|
28
|
-
}
|
|
29
|
-
export {};
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import type { PrepareFileuploadOKResponse, PrepareFileuploadParams, PushApiParams } from './registry-api-types';
|
|
2
|
-
import type { AccessTokens, Region } from '../config/types';
|
|
3
|
-
export declare class RegistryApi {
|
|
4
|
-
private accessTokens;
|
|
5
|
-
private region;
|
|
6
|
-
constructor(accessTokens: AccessTokens, region: Region);
|
|
7
|
-
get accessToken(): string | false | undefined;
|
|
8
|
-
getBaseUrl(): string;
|
|
9
|
-
setAccessTokens(accessTokens: AccessTokens): this;
|
|
10
|
-
private request;
|
|
11
|
-
authStatus(accessToken: string, verbose?: boolean): Promise<{
|
|
12
|
-
viewerId: string;
|
|
13
|
-
organizations: string[];
|
|
14
|
-
}>;
|
|
15
|
-
prepareFileUpload({ organizationId, name, version, filesHash, filename, isUpsert, }: PrepareFileuploadParams): Promise<PrepareFileuploadOKResponse>;
|
|
16
|
-
pushApi({ organizationId, name, version, rootFilePath, filePaths, branch, isUpsert, isPublic, batchId, batchSize, }: PushApiParams): Promise<void>;
|
|
17
|
-
}
|
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.RegistryApi = void 0;
|
|
4
|
-
const utils_1 = require("../utils");
|
|
5
|
-
const domains_1 = require("./domains");
|
|
6
|
-
const version = require('../../package.json').version;
|
|
7
|
-
class RegistryApi {
|
|
8
|
-
constructor(accessTokens, region) {
|
|
9
|
-
this.accessTokens = accessTokens;
|
|
10
|
-
this.region = region;
|
|
11
|
-
}
|
|
12
|
-
get accessToken() {
|
|
13
|
-
return (0, utils_1.isNotEmptyObject)(this.accessTokens) && this.accessTokens[this.region];
|
|
14
|
-
}
|
|
15
|
-
getBaseUrl() {
|
|
16
|
-
return `https://api.${(0, domains_1.getRedoclyDomain)()}/registry`;
|
|
17
|
-
}
|
|
18
|
-
setAccessTokens(accessTokens) {
|
|
19
|
-
this.accessTokens = accessTokens;
|
|
20
|
-
return this;
|
|
21
|
-
}
|
|
22
|
-
async request(path = '', options = {}) {
|
|
23
|
-
const currentCommand = typeof process !== 'undefined' ? process.env?.REDOCLY_CLI_COMMAND || '' : '';
|
|
24
|
-
const redoclyEnv = typeof process !== 'undefined' ? process.env?.REDOCLY_ENVIRONMENT || '' : '';
|
|
25
|
-
const headers = Object.assign({}, options.headers || {}, {
|
|
26
|
-
'x-redocly-cli-version': version,
|
|
27
|
-
'user-agent': `redocly-cli / ${version} ${currentCommand} ${redoclyEnv}`,
|
|
28
|
-
});
|
|
29
|
-
if (!headers.hasOwnProperty('authorization')) {
|
|
30
|
-
throw new Error('Unauthorized');
|
|
31
|
-
}
|
|
32
|
-
const requestOptions = {
|
|
33
|
-
...options,
|
|
34
|
-
headers,
|
|
35
|
-
agent: (0, utils_1.getProxyAgent)(),
|
|
36
|
-
};
|
|
37
|
-
const response = await fetch(`${this.getBaseUrl()}${path}`, requestOptions);
|
|
38
|
-
if (response.status === 401) {
|
|
39
|
-
throw new Error('Unauthorized');
|
|
40
|
-
}
|
|
41
|
-
if (response.status === 404) {
|
|
42
|
-
const body = await response.json();
|
|
43
|
-
throw new Error(body.code);
|
|
44
|
-
}
|
|
45
|
-
return response;
|
|
46
|
-
}
|
|
47
|
-
async authStatus(accessToken, verbose = false) {
|
|
48
|
-
try {
|
|
49
|
-
const response = await this.request('', { headers: { authorization: accessToken } });
|
|
50
|
-
return await response.json();
|
|
51
|
-
}
|
|
52
|
-
catch (error) {
|
|
53
|
-
if (verbose) {
|
|
54
|
-
console.log(error);
|
|
55
|
-
}
|
|
56
|
-
throw error;
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
async prepareFileUpload({ organizationId, name, version, filesHash, filename, isUpsert, }) {
|
|
60
|
-
const response = await this.request(`/${organizationId}/${name}/${version}/prepare-file-upload`, {
|
|
61
|
-
method: 'POST',
|
|
62
|
-
headers: {
|
|
63
|
-
'content-type': 'application/json',
|
|
64
|
-
authorization: this.accessToken,
|
|
65
|
-
},
|
|
66
|
-
body: JSON.stringify({
|
|
67
|
-
filesHash,
|
|
68
|
-
filename,
|
|
69
|
-
isUpsert,
|
|
70
|
-
}),
|
|
71
|
-
});
|
|
72
|
-
if (response.ok) {
|
|
73
|
-
return response.json();
|
|
74
|
-
}
|
|
75
|
-
throw new Error('Could not prepare file upload');
|
|
76
|
-
}
|
|
77
|
-
async pushApi({ organizationId, name, version, rootFilePath, filePaths, branch, isUpsert, isPublic, batchId, batchSize, }) {
|
|
78
|
-
const response = await this.request(`/${organizationId}/${name}/${version}`, {
|
|
79
|
-
method: 'PUT',
|
|
80
|
-
headers: {
|
|
81
|
-
'content-type': 'application/json',
|
|
82
|
-
authorization: this.accessToken,
|
|
83
|
-
},
|
|
84
|
-
body: JSON.stringify({
|
|
85
|
-
rootFilePath,
|
|
86
|
-
filePaths,
|
|
87
|
-
branch,
|
|
88
|
-
isUpsert,
|
|
89
|
-
isPublic,
|
|
90
|
-
batchId,
|
|
91
|
-
batchSize,
|
|
92
|
-
}),
|
|
93
|
-
});
|
|
94
|
-
if (response.ok) {
|
|
95
|
-
return;
|
|
96
|
-
}
|
|
97
|
-
throw new Error('Could not push api');
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
exports.RegistryApi = RegistryApi;
|