@redocly/openapi-core 0.0.0-snapshot.1740665575 → 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/README.md +2 -2
- package/lib/bundle.d.ts +0 -2
- package/lib/bundle.js +8 -8
- package/lib/config/all.js +3 -0
- package/lib/config/builtIn.js +5 -3
- package/lib/config/config-resolvers.js +47 -13
- package/lib/config/config.d.ts +3 -6
- package/lib/config/config.js +20 -7
- package/lib/config/load.d.ts +1 -5
- package/lib/config/load.js +4 -43
- package/lib/config/minimal.js +3 -0
- package/lib/config/recommended-strict.js +3 -0
- package/lib/config/recommended.js +3 -0
- package/lib/config/rules.d.ts +2 -2
- package/lib/config/spec.js +3 -0
- package/lib/config/types.d.ts +8 -10
- package/lib/config/utils.js +15 -2
- 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/decorators/overlay1/index.d.ts +1 -0
- package/lib/{redocly/redocly-client-types.js → decorators/overlay1/index.js} +2 -0
- package/lib/index.d.ts +1 -3
- package/lib/index.js +2 -19
- package/lib/oas-types.d.ts +9 -4
- package/lib/oas-types.js +10 -0
- package/lib/rules/async3/no-channel-trailing-slash.js +1 -1
- package/lib/rules/common/assertions/index.d.ts +2 -2
- package/lib/rules/common/no-invalid-schema-examples.d.ts +2 -1
- package/lib/rules/common/no-invalid-schema-examples.js +10 -3
- package/lib/rules/common/struct.d.ts +2 -2
- package/lib/rules/overlay1/index.d.ts +3 -0
- package/lib/rules/overlay1/index.js +12 -0
- package/lib/rules/respect/respect-supported-versions.js +1 -1
- package/lib/types/oas2.js +1 -1
- package/lib/types/oas3.js +1 -1
- package/lib/types/redocly-yaml.d.ts +2 -0
- package/lib/types/redocly-yaml.js +4 -16
- package/lib/typings/openapi.d.ts +2 -2
- package/lib/utils.js +7 -8
- package/lib/visitors.d.ts +11 -0
- package/package.json +9 -6
- 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/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/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/lib/visitors.d.ts
CHANGED
|
@@ -7,6 +7,7 @@ import type { Oas2Definition, Oas2Tag, Oas2ExternalDocs, Oas2SecurityRequirement
|
|
|
7
7
|
import type { Async2Definition } from './typings/asyncapi';
|
|
8
8
|
import type { Async3Definition } from './typings/asyncapi3';
|
|
9
9
|
import type { ArazzoDefinition, ArazzoSourceDescription, CriteriaObject, ExtendedOperation, InfoObject, OnFailureObject, OnSuccessObject, OpenAPISourceDescription, Parameter, Replacement, RequestBody, SourceDescription, Step, Workflow } from './typings/arazzo';
|
|
10
|
+
import type { Overlay1Definition } from './typings/overlay';
|
|
10
11
|
export type SkipFunctionContext = Pick<UserContext, 'location' | 'rawNode' | 'resolve' | 'rawLocation'>;
|
|
11
12
|
export type VisitFunction<T> = (node: T, ctx: UserContext & {
|
|
12
13
|
ignoreNextVisitorsOnNode: () => void;
|
|
@@ -164,6 +165,9 @@ type ArazzoFlatVisitor = {
|
|
|
164
165
|
Workflow?: VisitFunctionOrObject<Workflow>;
|
|
165
166
|
Workflows?: VisitFunctionOrObject<Workflow[]>;
|
|
166
167
|
};
|
|
168
|
+
type Overlay1FlatVisitor = {
|
|
169
|
+
Root?: VisitFunctionOrObject<Overlay1Definition>;
|
|
170
|
+
};
|
|
167
171
|
type Oas3NestedVisitor = {
|
|
168
172
|
[T in keyof Oas3FlatVisitor]: Oas3FlatVisitor[T] extends Function ? Oas3FlatVisitor[T] : Oas3FlatVisitor[T] & NestedVisitor<Oas3NestedVisitor>;
|
|
169
173
|
};
|
|
@@ -179,11 +183,15 @@ type Async3NestedVisitor = {
|
|
|
179
183
|
type ArazzoNestedVisitor = {
|
|
180
184
|
[T in keyof ArazzoFlatVisitor]: ArazzoFlatVisitor[T] extends Function ? ArazzoFlatVisitor[T] : ArazzoFlatVisitor[T] & NestedVisitor<ArazzoNestedVisitor>;
|
|
181
185
|
};
|
|
186
|
+
type Overlay1NestedVisitor = {
|
|
187
|
+
[T in keyof Overlay1FlatVisitor]: Overlay1FlatVisitor[T] extends Function ? Overlay1FlatVisitor[T] : Overlay1FlatVisitor[T] & NestedVisitor<Overlay1NestedVisitor>;
|
|
188
|
+
};
|
|
182
189
|
export type Oas3Visitor = BaseVisitor & Oas3NestedVisitor & Record<string, VisitFunction<any> | NestedVisitObject<any, Oas3NestedVisitor>>;
|
|
183
190
|
export type Oas2Visitor = BaseVisitor & Oas2NestedVisitor & Record<string, VisitFunction<any> | NestedVisitObject<any, Oas2NestedVisitor>>;
|
|
184
191
|
export type Async2Visitor = BaseVisitor & Async2NestedVisitor & Record<string, VisitFunction<any> | NestedVisitObject<any, Async2NestedVisitor>>;
|
|
185
192
|
export type Async3Visitor = BaseVisitor & Async3NestedVisitor & Record<string, VisitFunction<any> | NestedVisitObject<any, Async3NestedVisitor>>;
|
|
186
193
|
export type Arazzo1Visitor = BaseVisitor & ArazzoNestedVisitor & Record<string, VisitFunction<any> | NestedVisitObject<any, ArazzoNestedVisitor>>;
|
|
194
|
+
export type Overlay1Visitor = BaseVisitor & Overlay1NestedVisitor & Record<string, VisitFunction<any> | NestedVisitObject<any, Overlay1NestedVisitor>>;
|
|
187
195
|
export type NestedVisitor<T> = Exclude<T, 'any' | 'ref' | 'Root'>;
|
|
188
196
|
export type NormalizedOasVisitors<T extends BaseVisitor> = {
|
|
189
197
|
[V in keyof T]-?: {
|
|
@@ -205,16 +213,19 @@ export type Oas2Rule = (options: Record<string, any>) => Oas2Visitor | Oas2Visit
|
|
|
205
213
|
export type Async2Rule = (options: Record<string, any>) => Async2Visitor | Async2Visitor[];
|
|
206
214
|
export type Async3Rule = (options: Record<string, any>) => Async3Visitor | Async3Visitor[];
|
|
207
215
|
export type Arazzo1Rule = (options: Record<string, any>) => Arazzo1Visitor | Arazzo1Visitor[];
|
|
216
|
+
export type Overlay1Rule = (options: Record<string, any>) => Overlay1Visitor | Overlay1Visitor[];
|
|
208
217
|
export type Oas3Preprocessor = (options: Record<string, any>) => Oas3Visitor;
|
|
209
218
|
export type Oas2Preprocessor = (options: Record<string, any>) => Oas2Visitor;
|
|
210
219
|
export type Async2Preprocessor = (options: Record<string, any>) => Async2Visitor;
|
|
211
220
|
export type Async3Preprocessor = (options: Record<string, any>) => Async3Visitor;
|
|
212
221
|
export type Arazzo1Preprocessor = (options: Record<string, any>) => Arazzo1Visitor;
|
|
222
|
+
export type Overlay1Preprocessor = (options: Record<string, any>) => Overlay1Visitor;
|
|
213
223
|
export type Oas3Decorator = (options: Record<string, any>) => Oas3Visitor;
|
|
214
224
|
export type Oas2Decorator = (options: Record<string, any>) => Oas2Visitor;
|
|
215
225
|
export type Async2Decorator = (options: Record<string, any>) => Async2Visitor;
|
|
216
226
|
export type Async3Decorator = (options: Record<string, any>) => Async3Visitor;
|
|
217
227
|
export type Arazzo1Decorator = (options: Record<string, any>) => Arazzo1Visitor;
|
|
228
|
+
export type Overlay1Decorator = (options: Record<string, any>) => Overlay1Visitor;
|
|
218
229
|
export type OasRule = Oas3Rule;
|
|
219
230
|
export type OasPreprocessor = Oas3Preprocessor;
|
|
220
231
|
export type OasDecorator = Oas3Decorator;
|
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
|
},
|
|
@@ -36,19 +39,19 @@
|
|
|
36
39
|
],
|
|
37
40
|
"dependencies": {
|
|
38
41
|
"@redocly/ajv": "^8.11.2",
|
|
39
|
-
"@redocly/config": "^0.
|
|
42
|
+
"@redocly/config": "^0.22.0",
|
|
40
43
|
"colorette": "^1.2.0",
|
|
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;
|