@redocly/openapi-core 0.0.0-snapshot.1737554067
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 +268 -0
- package/lib/benchmark/benches/lint-with-many-rules.bench.d.ts +4 -0
- package/lib/benchmark/benches/lint-with-many-rules.bench.js +38 -0
- package/lib/benchmark/benches/lint-with-nested-rule.bench.d.ts +4 -0
- package/lib/benchmark/benches/lint-with-nested-rule.bench.js +44 -0
- package/lib/benchmark/benches/lint-with-no-rules.bench.d.ts +4 -0
- package/lib/benchmark/benches/lint-with-no-rules.bench.js +25 -0
- package/lib/benchmark/benches/lint-with-top-level-rule-report.bench.d.ts +4 -0
- package/lib/benchmark/benches/lint-with-top-level-rule-report.bench.js +37 -0
- package/lib/benchmark/benches/lint-with-top-level-rule.bench.d.ts +4 -0
- package/lib/benchmark/benches/lint-with-top-level-rule.bench.js +36 -0
- package/lib/benchmark/benches/recommended-oas3.bench.d.ts +3 -0
- package/lib/benchmark/benches/recommended-oas3.bench.js +21 -0
- package/lib/benchmark/benches/resolve-with-no-external.bench.d.ts +3 -0
- package/lib/benchmark/benches/resolve-with-no-external.bench.js +22 -0
- package/lib/benchmark/utils.d.ts +6 -0
- package/lib/benchmark/utils.js +34 -0
- package/lib/bundle.d.ts +50 -0
- package/lib/bundle.js +385 -0
- package/lib/config/all.d.ts +3 -0
- package/lib/config/all.js +227 -0
- package/lib/config/builtIn.d.ts +3 -0
- package/lib/config/builtIn.js +53 -0
- package/lib/config/config-resolvers.d.ts +30 -0
- package/lib/config/config-resolvers.js +447 -0
- package/lib/config/config.d.ts +53 -0
- package/lib/config/config.js +320 -0
- package/lib/config/index.d.ts +7 -0
- package/lib/config/index.js +23 -0
- package/lib/config/load.d.ts +38 -0
- package/lib/config/load.js +140 -0
- package/lib/config/minimal.d.ts +3 -0
- package/lib/config/minimal.js +203 -0
- package/lib/config/recommended-strict.d.ts +3 -0
- package/lib/config/recommended-strict.js +203 -0
- package/lib/config/recommended.d.ts +3 -0
- package/lib/config/recommended.js +203 -0
- package/lib/config/rules.d.ts +10 -0
- package/lib/config/rules.js +37 -0
- package/lib/config/spec.d.ts +3 -0
- package/lib/config/spec.js +29 -0
- package/lib/config/types.d.ts +189 -0
- package/lib/config/types.js +2 -0
- package/lib/config/utils.d.ts +19 -0
- package/lib/config/utils.js +308 -0
- package/lib/decorators/arazzo/index.d.ts +1 -0
- package/lib/decorators/arazzo/index.js +4 -0
- package/lib/decorators/async2/index.d.ts +1 -0
- package/lib/decorators/async2/index.js +4 -0
- package/lib/decorators/async3/index.d.ts +1 -0
- package/lib/decorators/async3/index.js +4 -0
- package/lib/decorators/common/filters/filter-helper.d.ts +3 -0
- package/lib/decorators/common/filters/filter-helper.js +66 -0
- package/lib/decorators/common/filters/filter-in.d.ts +2 -0
- package/lib/decorators/common/filters/filter-in.js +17 -0
- package/lib/decorators/common/filters/filter-out.d.ts +2 -0
- package/lib/decorators/common/filters/filter-out.js +17 -0
- package/lib/decorators/common/info-description-override.d.ts +2 -0
- package/lib/decorators/common/info-description-override.js +24 -0
- package/lib/decorators/common/info-override.d.ts +2 -0
- package/lib/decorators/common/info-override.js +17 -0
- package/lib/decorators/common/media-type-examples-override.d.ts +2 -0
- package/lib/decorators/common/media-type-examples-override.js +59 -0
- package/lib/decorators/common/operation-description-override.d.ts +2 -0
- package/lib/decorators/common/operation-description-override.js +29 -0
- package/lib/decorators/common/registry-dependencies.d.ts +2 -0
- package/lib/decorators/common/registry-dependencies.js +24 -0
- package/lib/decorators/common/remove-x-internal.d.ts +2 -0
- package/lib/decorators/common/remove-x-internal.js +69 -0
- package/lib/decorators/common/tag-description-override.d.ts +2 -0
- package/lib/decorators/common/tag-description-override.js +25 -0
- package/lib/decorators/oas2/index.d.ts +11 -0
- package/lib/decorators/oas2/index.js +21 -0
- package/lib/decorators/oas2/remove-unused-components.d.ts +2 -0
- package/lib/decorators/oas2/remove-unused-components.js +89 -0
- package/lib/decorators/oas3/index.d.ts +12 -0
- package/lib/decorators/oas3/index.js +23 -0
- package/lib/decorators/oas3/remove-unused-components.d.ts +2 -0
- package/lib/decorators/oas3/remove-unused-components.js +100 -0
- package/lib/env.d.ts +2 -0
- package/lib/env.js +7 -0
- package/lib/format/codeframes.d.ts +22 -0
- package/lib/format/codeframes.js +185 -0
- package/lib/format/format.d.ts +20 -0
- package/lib/format/format.js +365 -0
- package/lib/index.d.ts +26 -0
- package/lib/index.js +98 -0
- package/lib/js-yaml/index.d.ts +3 -0
- package/lib/js-yaml/index.js +15 -0
- package/lib/lint.d.ts +32 -0
- package/lib/lint.js +118 -0
- package/lib/logger.d.ts +10 -0
- package/lib/logger.js +31 -0
- package/lib/oas-types.d.ts +36 -0
- package/lib/oas-types.js +92 -0
- package/lib/output.d.ts +3 -0
- package/lib/output.js +9 -0
- package/lib/redocly/domains.d.ts +14 -0
- package/lib/redocly/domains.js +41 -0
- package/lib/redocly/index.d.ts +30 -0
- package/lib/redocly/index.js +131 -0
- package/lib/redocly/redocly-client-types.d.ts +8 -0
- package/lib/redocly/redocly-client-types.js +2 -0
- package/lib/redocly/registry-api-types.d.ts +29 -0
- package/lib/redocly/registry-api-types.js +2 -0
- package/lib/redocly/registry-api.d.ts +17 -0
- package/lib/redocly/registry-api.js +96 -0
- package/lib/ref-utils.d.ts +27 -0
- package/lib/ref-utils.js +85 -0
- package/lib/resolve.d.ts +66 -0
- package/lib/resolve.js +342 -0
- package/lib/rules/ajv.d.ts +10 -0
- package/lib/rules/ajv.js +82 -0
- package/lib/rules/arazzo/criteria-unique.d.ts +2 -0
- package/lib/rules/arazzo/criteria-unique.js +71 -0
- package/lib/rules/arazzo/index.d.ts +3 -0
- package/lib/rules/arazzo/index.js +36 -0
- package/lib/rules/arazzo/parameters-unique.d.ts +2 -0
- package/lib/rules/arazzo/parameters-unique.js +32 -0
- package/lib/rules/arazzo/requestBody-replacements-unique.d.ts +2 -0
- package/lib/rules/arazzo/requestBody-replacements-unique.js +28 -0
- package/lib/rules/arazzo/sourceDescription-type.d.ts +2 -0
- package/lib/rules/arazzo/sourceDescription-type.js +22 -0
- package/lib/rules/arazzo/sourceDescriptions-name-unique.d.ts +2 -0
- package/lib/rules/arazzo/sourceDescriptions-name-unique.js +24 -0
- package/lib/rules/arazzo/sourceDescriptions-not-empty.d.ts +2 -0
- package/lib/rules/arazzo/sourceDescriptions-not-empty.js +18 -0
- package/lib/rules/arazzo/step-onFailure-unique.d.ts +2 -0
- package/lib/rules/arazzo/step-onFailure-unique.js +32 -0
- package/lib/rules/arazzo/step-onSuccess-unique.d.ts +2 -0
- package/lib/rules/arazzo/step-onSuccess-unique.js +32 -0
- package/lib/rules/arazzo/stepId-unique.d.ts +2 -0
- package/lib/rules/arazzo/stepId-unique.js +26 -0
- package/lib/rules/arazzo/workflow-dependsOn.d.ts +2 -0
- package/lib/rules/arazzo/workflow-dependsOn.js +56 -0
- package/lib/rules/arazzo/workflowId-unique.d.ts +2 -0
- package/lib/rules/arazzo/workflowId-unique.js +22 -0
- package/lib/rules/async2/channels-kebab-case.d.ts +2 -0
- package/lib/rules/async2/channels-kebab-case.js +19 -0
- package/lib/rules/async2/index.d.ts +3 -0
- package/lib/rules/async2/index.js +27 -0
- package/lib/rules/async2/no-channel-trailing-slash.d.ts +2 -0
- package/lib/rules/async2/no-channel-trailing-slash.js +16 -0
- package/lib/rules/async3/channels-kebab-case.d.ts +2 -0
- package/lib/rules/async3/channels-kebab-case.js +19 -0
- package/lib/rules/async3/index.d.ts +3 -0
- package/lib/rules/async3/index.js +27 -0
- package/lib/rules/async3/no-channel-trailing-slash.d.ts +2 -0
- package/lib/rules/async3/no-channel-trailing-slash.js +16 -0
- package/lib/rules/common/assertions/asserts.d.ts +30 -0
- package/lib/rules/common/assertions/asserts.js +281 -0
- package/lib/rules/common/assertions/index.d.ts +27 -0
- package/lib/rules/common/assertions/index.js +24 -0
- package/lib/rules/common/assertions/utils.d.ts +28 -0
- package/lib/rules/common/assertions/utils.js +226 -0
- package/lib/rules/common/info-contact.d.ts +2 -0
- package/lib/rules/common/info-contact.js +17 -0
- package/lib/rules/common/info-license-strict.d.ts +2 -0
- package/lib/rules/common/info-license-strict.js +26 -0
- package/lib/rules/common/info-license-url.d.ts +2 -0
- package/lib/rules/common/info-license-url.js +12 -0
- package/lib/rules/common/info-license.d.ts +2 -0
- package/lib/rules/common/info-license.js +17 -0
- package/lib/rules/common/no-ambiguous-paths.d.ts +2 -0
- package/lib/rules/common/no-ambiguous-paths.js +45 -0
- package/lib/rules/common/no-enum-type-mismatch.d.ts +2 -0
- package/lib/rules/common/no-enum-type-mismatch.js +41 -0
- package/lib/rules/common/no-http-verbs-in-paths.d.ts +2 -0
- package/lib/rules/common/no-http-verbs-in-paths.js +33 -0
- package/lib/rules/common/no-identical-paths.d.ts +2 -0
- package/lib/rules/common/no-identical-paths.js +24 -0
- package/lib/rules/common/no-invalid-parameter-examples.d.ts +1 -0
- package/lib/rules/common/no-invalid-parameter-examples.js +24 -0
- package/lib/rules/common/no-invalid-schema-examples.d.ts +1 -0
- package/lib/rules/common/no-invalid-schema-examples.js +22 -0
- package/lib/rules/common/no-path-trailing-slash.d.ts +2 -0
- package/lib/rules/common/no-path-trailing-slash.js +16 -0
- package/lib/rules/common/no-required-schema-properties-undefined.d.ts +2 -0
- package/lib/rules/common/no-required-schema-properties-undefined.js +36 -0
- package/lib/rules/common/operation-2xx-response.d.ts +2 -0
- package/lib/rules/common/operation-2xx-response.js +23 -0
- package/lib/rules/common/operation-4xx-response.d.ts +2 -0
- package/lib/rules/common/operation-4xx-response.js +23 -0
- package/lib/rules/common/operation-description.d.ts +2 -0
- package/lib/rules/common/operation-description.js +12 -0
- package/lib/rules/common/operation-operationId-unique.d.ts +2 -0
- package/lib/rules/common/operation-operationId-unique.js +20 -0
- package/lib/rules/common/operation-operationId-url-safe.d.ts +2 -0
- package/lib/rules/common/operation-operationId-url-safe.js +18 -0
- package/lib/rules/common/operation-operationId.d.ts +2 -0
- package/lib/rules/common/operation-operationId.js +16 -0
- package/lib/rules/common/operation-parameters-unique.d.ts +2 -0
- package/lib/rules/common/operation-parameters-unique.js +40 -0
- package/lib/rules/common/operation-singular-tag.d.ts +2 -0
- package/lib/rules/common/operation-singular-tag.js +16 -0
- package/lib/rules/common/operation-summary.d.ts +2 -0
- package/lib/rules/common/operation-summary.js +12 -0
- package/lib/rules/common/operation-tag-defined.d.ts +2 -0
- package/lib/rules/common/operation-tag-defined.js +24 -0
- package/lib/rules/common/parameter-description.d.ts +2 -0
- package/lib/rules/common/parameter-description.js +22 -0
- package/lib/rules/common/path-declaration-must-exist.d.ts +2 -0
- package/lib/rules/common/path-declaration-must-exist.js +16 -0
- package/lib/rules/common/path-excludes-patterns.d.ts +2 -0
- package/lib/rules/common/path-excludes-patterns.js +22 -0
- package/lib/rules/common/path-http-verbs-order.d.ts +2 -0
- package/lib/rules/common/path-http-verbs-order.js +26 -0
- package/lib/rules/common/path-not-include-query.d.ts +2 -0
- package/lib/rules/common/path-not-include-query.js +18 -0
- package/lib/rules/common/path-params-defined.d.ts +2 -0
- package/lib/rules/common/path-params-defined.js +58 -0
- package/lib/rules/common/path-segment-plural.d.ts +2 -0
- package/lib/rules/common/path-segment-plural.js +33 -0
- package/lib/rules/common/paths-kebab-case.d.ts +2 -0
- package/lib/rules/common/paths-kebab-case.js +20 -0
- package/lib/rules/common/required-string-property-missing-min-length.d.ts +2 -0
- package/lib/rules/common/required-string-property-missing-min-length.js +37 -0
- package/lib/rules/common/response-contains-header.d.ts +2 -0
- package/lib/rules/common/response-contains-header.js +29 -0
- package/lib/rules/common/scalar-property-missing-example.d.ts +2 -0
- package/lib/rules/common/scalar-property-missing-example.js +42 -0
- package/lib/rules/common/security-defined.d.ts +2 -0
- package/lib/rules/common/security-defined.js +65 -0
- package/lib/rules/common/spec-strict-refs.d.ts +2 -0
- package/lib/rules/common/spec-strict-refs.js +30 -0
- package/lib/rules/common/struct.d.ts +2 -0
- package/lib/rules/common/struct.js +158 -0
- package/lib/rules/common/tag-description.d.ts +2 -0
- package/lib/rules/common/tag-description.js +12 -0
- package/lib/rules/common/tags-alphabetical.d.ts +2 -0
- package/lib/rules/common/tags-alphabetical.js +23 -0
- package/lib/rules/no-unresolved-refs.d.ts +5 -0
- package/lib/rules/no-unresolved-refs.js +46 -0
- package/lib/rules/oas2/boolean-parameter-prefixes.d.ts +5 -0
- package/lib/rules/oas2/boolean-parameter-prefixes.js +22 -0
- package/lib/rules/oas2/index.d.ts +3 -0
- package/lib/rules/oas2/index.js +98 -0
- package/lib/rules/oas2/request-mime-type.d.ts +2 -0
- package/lib/rules/oas2/request-mime-type.js +17 -0
- package/lib/rules/oas2/response-contains-property.d.ts +2 -0
- package/lib/rules/oas2/response-contains-property.js +37 -0
- package/lib/rules/oas2/response-mime-type.d.ts +2 -0
- package/lib/rules/oas2/response-mime-type.js +17 -0
- package/lib/rules/oas3/array-parameter-serialization.d.ts +5 -0
- package/lib/rules/oas3/array-parameter-serialization.js +29 -0
- package/lib/rules/oas3/boolean-parameter-prefixes.d.ts +5 -0
- package/lib/rules/oas3/boolean-parameter-prefixes.js +24 -0
- package/lib/rules/oas3/component-name-unique.d.ts +2 -0
- package/lib/rules/oas3/component-name-unique.js +133 -0
- package/lib/rules/oas3/index.d.ts +3 -0
- package/lib/rules/oas3/index.js +122 -0
- package/lib/rules/oas3/no-empty-servers.d.ts +2 -0
- package/lib/rules/oas3/no-empty-servers.js +23 -0
- package/lib/rules/oas3/no-example-value-and-externalValue.d.ts +2 -0
- package/lib/rules/oas3/no-example-value-and-externalValue.js +16 -0
- package/lib/rules/oas3/no-invalid-media-type-examples.d.ts +2 -0
- package/lib/rules/oas3/no-invalid-media-type-examples.js +39 -0
- package/lib/rules/oas3/no-server-example.com.d.ts +2 -0
- package/lib/rules/oas3/no-server-example.com.js +18 -0
- package/lib/rules/oas3/no-server-trailing-slash.d.ts +2 -0
- package/lib/rules/oas3/no-server-trailing-slash.js +18 -0
- package/lib/rules/oas3/no-server-variables-empty-enum.d.ts +2 -0
- package/lib/rules/oas3/no-server-variables-empty-enum.js +66 -0
- package/lib/rules/oas3/no-undefined-server-variable.d.ts +2 -0
- package/lib/rules/oas3/no-undefined-server-variable.js +31 -0
- package/lib/rules/oas3/no-unused-components.d.ts +2 -0
- package/lib/rules/oas3/no-unused-components.js +73 -0
- package/lib/rules/oas3/operation-4xx-problem-details-rfc7807.d.ts +5 -0
- package/lib/rules/oas3/operation-4xx-problem-details-rfc7807.js +36 -0
- package/lib/rules/oas3/request-mime-type.d.ts +2 -0
- package/lib/rules/oas3/request-mime-type.js +31 -0
- package/lib/rules/oas3/response-contains-property.d.ts +2 -0
- package/lib/rules/oas3/response-contains-property.js +39 -0
- package/lib/rules/oas3/response-mime-type.d.ts +2 -0
- package/lib/rules/oas3/response-mime-type.js +31 -0
- package/lib/rules/oas3/spec-components-invalid-map-name.d.ts +2 -0
- package/lib/rules/oas3/spec-components-invalid-map-name.js +62 -0
- package/lib/rules/other/stats.d.ts +41 -0
- package/lib/rules/other/stats.js +75 -0
- package/lib/rules/spot/no-criteria-xpath.d.ts +2 -0
- package/lib/rules/spot/no-criteria-xpath.js +21 -0
- package/lib/rules/spot/spot-supported-versions.d.ts +2 -0
- package/lib/rules/spot/spot-supported-versions.js +21 -0
- package/lib/rules/utils.d.ts +22 -0
- package/lib/rules/utils.js +183 -0
- package/lib/types/arazzo.d.ts +2 -0
- package/lib/types/arazzo.js +311 -0
- package/lib/types/asyncapi2.d.ts +17 -0
- package/lib/types/asyncapi2.js +1008 -0
- package/lib/types/asyncapi3.d.ts +2 -0
- package/lib/types/asyncapi3.js +347 -0
- package/lib/types/index.d.ts +57 -0
- package/lib/types/index.js +94 -0
- package/lib/types/json-schema-adapter.d.ts +3 -0
- package/lib/types/json-schema-adapter.js +159 -0
- package/lib/types/oas2.d.ts +3 -0
- package/lib/types/oas2.js +456 -0
- package/lib/types/oas3.d.ts +7 -0
- package/lib/types/oas3.js +554 -0
- package/lib/types/oas3_1.d.ts +6 -0
- package/lib/types/oas3_1.js +285 -0
- package/lib/types/redocly-yaml.d.ts +26 -0
- package/lib/types/redocly-yaml.js +1126 -0
- package/lib/typings/arazzo.d.ts +131 -0
- package/lib/typings/arazzo.js +5 -0
- package/lib/typings/asyncapi.d.ts +21 -0
- package/lib/typings/asyncapi.js +2 -0
- package/lib/typings/asyncapi3.d.ts +53 -0
- package/lib/typings/asyncapi3.js +2 -0
- package/lib/typings/common.d.ts +8 -0
- package/lib/typings/common.js +2 -0
- package/lib/typings/openapi.d.ts +355 -0
- package/lib/typings/openapi.js +2 -0
- package/lib/typings/swagger.d.ts +217 -0
- package/lib/typings/swagger.js +2 -0
- package/lib/utils.d.ts +70 -0
- package/lib/utils.js +301 -0
- package/lib/visitors.d.ts +229 -0
- package/lib/visitors.js +176 -0
- package/lib/walk.d.ts +78 -0
- package/lib/walk.js +290 -0
- package/package.json +59 -0
|
@@ -0,0 +1,131 @@
|
|
|
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;
|
|
@@ -0,0 +1,29 @@
|
|
|
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 {};
|
|
@@ -0,0 +1,17 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RegistryApi = void 0;
|
|
4
|
+
const node_fetch_1 = require("node-fetch");
|
|
5
|
+
const utils_1 = require("../utils");
|
|
6
|
+
const domains_1 = require("./domains");
|
|
7
|
+
const version = require('../../package.json').version;
|
|
8
|
+
class RegistryApi {
|
|
9
|
+
constructor(accessTokens, region) {
|
|
10
|
+
this.accessTokens = accessTokens;
|
|
11
|
+
this.region = region;
|
|
12
|
+
}
|
|
13
|
+
get accessToken() {
|
|
14
|
+
return (0, utils_1.isNotEmptyObject)(this.accessTokens) && this.accessTokens[this.region];
|
|
15
|
+
}
|
|
16
|
+
getBaseUrl() {
|
|
17
|
+
return `https://api.${(0, domains_1.getRedoclyDomain)()}/registry`;
|
|
18
|
+
}
|
|
19
|
+
setAccessTokens(accessTokens) {
|
|
20
|
+
this.accessTokens = accessTokens;
|
|
21
|
+
return this;
|
|
22
|
+
}
|
|
23
|
+
async request(path = '', options = {}) {
|
|
24
|
+
const currentCommand = typeof process !== 'undefined' ? process.env?.REDOCLY_CLI_COMMAND || '' : '';
|
|
25
|
+
const redoclyEnv = typeof process !== 'undefined' ? process.env?.REDOCLY_ENVIRONMENT || '' : '';
|
|
26
|
+
const headers = Object.assign({}, options.headers || {}, {
|
|
27
|
+
'x-redocly-cli-version': version,
|
|
28
|
+
'user-agent': `redocly-cli / ${version} ${currentCommand} ${redoclyEnv}`,
|
|
29
|
+
});
|
|
30
|
+
if (!headers.hasOwnProperty('authorization')) {
|
|
31
|
+
throw new Error('Unauthorized');
|
|
32
|
+
}
|
|
33
|
+
const response = await (0, node_fetch_1.default)(`${this.getBaseUrl()}${path}`, Object.assign({}, options, { headers, agent: (0, utils_1.getProxyAgent)() }));
|
|
34
|
+
if (response.status === 401) {
|
|
35
|
+
throw new Error('Unauthorized');
|
|
36
|
+
}
|
|
37
|
+
if (response.status === 404) {
|
|
38
|
+
const body = await response.json();
|
|
39
|
+
throw new Error(body.code);
|
|
40
|
+
}
|
|
41
|
+
return response;
|
|
42
|
+
}
|
|
43
|
+
async authStatus(accessToken, verbose = false) {
|
|
44
|
+
try {
|
|
45
|
+
const response = await this.request('', { headers: { authorization: accessToken } });
|
|
46
|
+
return await response.json();
|
|
47
|
+
}
|
|
48
|
+
catch (error) {
|
|
49
|
+
if (verbose) {
|
|
50
|
+
console.log(error);
|
|
51
|
+
}
|
|
52
|
+
throw error;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
async prepareFileUpload({ organizationId, name, version, filesHash, filename, isUpsert, }) {
|
|
56
|
+
const response = await this.request(`/${organizationId}/${name}/${version}/prepare-file-upload`, {
|
|
57
|
+
method: 'POST',
|
|
58
|
+
headers: {
|
|
59
|
+
'content-type': 'application/json',
|
|
60
|
+
authorization: this.accessToken,
|
|
61
|
+
},
|
|
62
|
+
body: JSON.stringify({
|
|
63
|
+
filesHash,
|
|
64
|
+
filename,
|
|
65
|
+
isUpsert,
|
|
66
|
+
}),
|
|
67
|
+
});
|
|
68
|
+
if (response.ok) {
|
|
69
|
+
return response.json();
|
|
70
|
+
}
|
|
71
|
+
throw new Error('Could not prepare file upload');
|
|
72
|
+
}
|
|
73
|
+
async pushApi({ organizationId, name, version, rootFilePath, filePaths, branch, isUpsert, isPublic, batchId, batchSize, }) {
|
|
74
|
+
const response = await this.request(`/${organizationId}/${name}/${version}`, {
|
|
75
|
+
method: 'PUT',
|
|
76
|
+
headers: {
|
|
77
|
+
'content-type': 'application/json',
|
|
78
|
+
authorization: this.accessToken,
|
|
79
|
+
},
|
|
80
|
+
body: JSON.stringify({
|
|
81
|
+
rootFilePath,
|
|
82
|
+
filePaths,
|
|
83
|
+
branch,
|
|
84
|
+
isUpsert,
|
|
85
|
+
isPublic,
|
|
86
|
+
batchId,
|
|
87
|
+
batchSize,
|
|
88
|
+
}),
|
|
89
|
+
});
|
|
90
|
+
if (response.ok) {
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
throw new Error('Could not push api');
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
exports.RegistryApi = RegistryApi;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { Source } from './resolve';
|
|
2
|
+
import type { OasRef } from './typings/openapi';
|
|
3
|
+
export declare function joinPointer(base: string, key: string | number): string;
|
|
4
|
+
export declare function isRef(node: unknown): node is OasRef;
|
|
5
|
+
export declare function isExternalValue(node: unknown): boolean;
|
|
6
|
+
export declare class Location {
|
|
7
|
+
source: Source;
|
|
8
|
+
pointer: string;
|
|
9
|
+
constructor(source: Source, pointer: string);
|
|
10
|
+
child(components: (string | number)[] | string | number): Location;
|
|
11
|
+
key(): this & {
|
|
12
|
+
reportOnKey: boolean;
|
|
13
|
+
};
|
|
14
|
+
get absolutePointer(): string;
|
|
15
|
+
}
|
|
16
|
+
export declare function unescapePointer(fragment: string): string;
|
|
17
|
+
export declare function escapePointer<T extends string | number>(fragment: T): T;
|
|
18
|
+
export declare function parseRef(ref: string): {
|
|
19
|
+
uri: string | null;
|
|
20
|
+
pointer: string[];
|
|
21
|
+
};
|
|
22
|
+
export declare function parsePointer(pointer: string): string[];
|
|
23
|
+
export declare function pointerBaseName(pointer: string): string;
|
|
24
|
+
export declare function refBaseName(ref: string): string;
|
|
25
|
+
export declare function isAbsoluteUrl(ref: string): boolean;
|
|
26
|
+
export declare function isMappingRef(mapping: string): boolean;
|
|
27
|
+
export declare function isAnchor(ref: string): boolean;
|
package/lib/ref-utils.js
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Location = void 0;
|
|
4
|
+
exports.joinPointer = joinPointer;
|
|
5
|
+
exports.isRef = isRef;
|
|
6
|
+
exports.isExternalValue = isExternalValue;
|
|
7
|
+
exports.unescapePointer = unescapePointer;
|
|
8
|
+
exports.escapePointer = escapePointer;
|
|
9
|
+
exports.parseRef = parseRef;
|
|
10
|
+
exports.parsePointer = parsePointer;
|
|
11
|
+
exports.pointerBaseName = pointerBaseName;
|
|
12
|
+
exports.refBaseName = refBaseName;
|
|
13
|
+
exports.isAbsoluteUrl = isAbsoluteUrl;
|
|
14
|
+
exports.isMappingRef = isMappingRef;
|
|
15
|
+
exports.isAnchor = isAnchor;
|
|
16
|
+
const utils_1 = require("./utils");
|
|
17
|
+
function joinPointer(base, key) {
|
|
18
|
+
if (base === '')
|
|
19
|
+
base = '#/';
|
|
20
|
+
return base[base.length - 1] === '/' ? base + key : base + '/' + key;
|
|
21
|
+
}
|
|
22
|
+
function isRef(node) {
|
|
23
|
+
return (0, utils_1.isPlainObject)(node) && typeof node.$ref === 'string';
|
|
24
|
+
}
|
|
25
|
+
function isExternalValue(node) {
|
|
26
|
+
return (0, utils_1.isPlainObject)(node) && typeof node.externalValue === 'string';
|
|
27
|
+
}
|
|
28
|
+
class Location {
|
|
29
|
+
constructor(source, pointer) {
|
|
30
|
+
this.source = source;
|
|
31
|
+
this.pointer = pointer;
|
|
32
|
+
}
|
|
33
|
+
child(components) {
|
|
34
|
+
return new Location(this.source, joinPointer(this.pointer, (Array.isArray(components) ? components : [components]).map(escapePointer).join('/')));
|
|
35
|
+
}
|
|
36
|
+
key() {
|
|
37
|
+
return { ...this, reportOnKey: true };
|
|
38
|
+
}
|
|
39
|
+
get absolutePointer() {
|
|
40
|
+
return this.source.absoluteRef + (this.pointer === '#/' ? '' : this.pointer);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
exports.Location = Location;
|
|
44
|
+
function unescapePointer(fragment) {
|
|
45
|
+
return decodeURIComponent(fragment.replace(/~1/g, '/').replace(/~0/g, '~'));
|
|
46
|
+
}
|
|
47
|
+
function escapePointer(fragment) {
|
|
48
|
+
if (typeof fragment === 'number')
|
|
49
|
+
return fragment;
|
|
50
|
+
return fragment.replace(/~/g, '~0').replace(/\//g, '~1');
|
|
51
|
+
}
|
|
52
|
+
function parseRef(ref) {
|
|
53
|
+
const [uri, pointer = ''] = ref.split('#/');
|
|
54
|
+
return {
|
|
55
|
+
uri: (uri.endsWith('#') ? uri.slice(0, -1) : uri) || null,
|
|
56
|
+
pointer: parsePointer(pointer),
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
function parsePointer(pointer) {
|
|
60
|
+
return pointer.split('/').map(unescapePointer).filter(utils_1.isTruthy);
|
|
61
|
+
}
|
|
62
|
+
function pointerBaseName(pointer) {
|
|
63
|
+
const parts = pointer.split('/');
|
|
64
|
+
return parts[parts.length - 1];
|
|
65
|
+
}
|
|
66
|
+
function refBaseName(ref) {
|
|
67
|
+
// eslint-disable-next-line no-useless-escape
|
|
68
|
+
const parts = ref.split(/[\/\\]/); // split by '\' and '/'
|
|
69
|
+
return parts[parts.length - 1].replace(/\.[^.]+$/, ''); // replace extension with empty string
|
|
70
|
+
}
|
|
71
|
+
function isAbsoluteUrl(ref) {
|
|
72
|
+
return ref.startsWith('http://') || ref.startsWith('https://');
|
|
73
|
+
}
|
|
74
|
+
function isMappingRef(mapping) {
|
|
75
|
+
// TODO: proper detection of mapping refs
|
|
76
|
+
return (mapping.startsWith('#') ||
|
|
77
|
+
mapping.startsWith('https://') ||
|
|
78
|
+
mapping.startsWith('http://') ||
|
|
79
|
+
mapping.startsWith('./') ||
|
|
80
|
+
mapping.startsWith('../') ||
|
|
81
|
+
mapping.indexOf('/') > -1);
|
|
82
|
+
}
|
|
83
|
+
function isAnchor(ref) {
|
|
84
|
+
return /^#[A-Za-z][A-Za-z0-9\-_:.]*$/.test(ref);
|
|
85
|
+
}
|
package/lib/resolve.d.ts
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import type { YAMLNode, LoadOptions } from 'yaml-ast-parser';
|
|
2
|
+
import type { NormalizedNodeType } from './types';
|
|
3
|
+
import type { ResolveConfig } from './config/types';
|
|
4
|
+
export type CollectedRefs = Map<string, Document>;
|
|
5
|
+
export declare class Source {
|
|
6
|
+
absoluteRef: string;
|
|
7
|
+
body: string;
|
|
8
|
+
mimeType?: string | undefined;
|
|
9
|
+
constructor(absoluteRef: string, body: string, mimeType?: string | undefined);
|
|
10
|
+
private _ast;
|
|
11
|
+
private _lines;
|
|
12
|
+
getAst(safeLoad: (input: string, options?: LoadOptions | undefined) => YAMLNode): YAMLNode;
|
|
13
|
+
getLines(): string[];
|
|
14
|
+
}
|
|
15
|
+
export declare class ResolveError extends Error {
|
|
16
|
+
originalError: Error;
|
|
17
|
+
constructor(originalError: Error);
|
|
18
|
+
}
|
|
19
|
+
export declare class YamlParseError extends Error {
|
|
20
|
+
originalError: Error;
|
|
21
|
+
source: Source;
|
|
22
|
+
col: number;
|
|
23
|
+
line: number;
|
|
24
|
+
constructor(originalError: Error, source: Source);
|
|
25
|
+
}
|
|
26
|
+
export type Document = {
|
|
27
|
+
source: Source;
|
|
28
|
+
parsed: any;
|
|
29
|
+
};
|
|
30
|
+
export declare function makeRefId(absoluteRef: string, pointer: string): string;
|
|
31
|
+
export declare function makeDocumentFromString(sourceString: string, absoluteRef: string): {
|
|
32
|
+
source: Source;
|
|
33
|
+
parsed: unknown;
|
|
34
|
+
};
|
|
35
|
+
export declare class BaseResolver {
|
|
36
|
+
protected config: ResolveConfig;
|
|
37
|
+
cache: Map<string, Promise<Document | ResolveError>>;
|
|
38
|
+
constructor(config?: ResolveConfig);
|
|
39
|
+
getFiles(): Set<string>;
|
|
40
|
+
resolveExternalRef(base: string | null, ref: string): string;
|
|
41
|
+
loadExternalRef(absoluteRef: string): Promise<Source>;
|
|
42
|
+
parseDocument(source: Source, isRoot?: boolean): Document;
|
|
43
|
+
resolveDocument(base: string | null, ref: string, isRoot?: boolean): Promise<Document | ResolveError | YamlParseError>;
|
|
44
|
+
}
|
|
45
|
+
export type ResolvedRef = {
|
|
46
|
+
resolved: false;
|
|
47
|
+
isRemote: boolean;
|
|
48
|
+
nodePointer?: string;
|
|
49
|
+
document?: Document;
|
|
50
|
+
source?: Source;
|
|
51
|
+
error?: ResolveError | YamlParseError;
|
|
52
|
+
node?: any;
|
|
53
|
+
} | {
|
|
54
|
+
resolved: true;
|
|
55
|
+
node: any;
|
|
56
|
+
document: Document;
|
|
57
|
+
nodePointer: string;
|
|
58
|
+
isRemote: boolean;
|
|
59
|
+
error?: undefined;
|
|
60
|
+
};
|
|
61
|
+
export type ResolvedRefMap = Map<string, ResolvedRef>;
|
|
62
|
+
export declare function resolveDocument(opts: {
|
|
63
|
+
rootDocument: Document;
|
|
64
|
+
externalRefResolver: BaseResolver;
|
|
65
|
+
rootType: NormalizedNodeType;
|
|
66
|
+
}): Promise<ResolvedRefMap>;
|