@redocly/openapi-core
Advanced tools
Comparing version 1.0.0-beta.96 to 1.0.0-beta.97
@@ -11,3 +11,3 @@ import { BaseResolver } from '../resolve'; | ||
}): Promise<Record<string, ResolvedApi>>; | ||
export declare function resolveLint({ lintConfig, configPath, resolver, }: { | ||
export declare function resolveLint(lintOpts: { | ||
lintConfig?: LintRawConfig; | ||
@@ -14,0 +14,0 @@ configPath?: string; |
@@ -144,3 +144,3 @@ "use strict"; | ||
exports.resolveApis = resolveApis; | ||
function resolveLint({ lintConfig, configPath = '', resolver = new resolve_1.BaseResolver(), }, parentConfigPaths = [], extendPaths = []) { | ||
function resolveAndMergeNestedLint({ lintConfig, configPath = '', resolver = new resolve_1.BaseResolver(), }, parentConfigPaths = [], extendPaths = []) { | ||
var _a, _b, _c; | ||
@@ -166,3 +166,3 @@ return __awaiter(this, void 0, void 0, function* () { | ||
const extendedLintConfig = yield loadExtendLintConfig(pathItem, resolver); | ||
return yield resolveLint({ | ||
return yield resolveAndMergeNestedLint({ | ||
lintConfig: extendedLintConfig, | ||
@@ -180,2 +180,8 @@ configPath: pathItem, | ||
} | ||
function resolveLint(lintOpts, parentConfigPaths = [], extendPaths = []) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const resolvedLint = yield resolveAndMergeNestedLint(lintOpts, parentConfigPaths, extendPaths); | ||
return Object.assign(Object.assign({}, resolvedLint), { rules: resolvedLint.rules && groupLintAssertionRules(resolvedLint.rules) }); | ||
}); | ||
} | ||
exports.resolveLint = resolveLint; | ||
@@ -217,1 +223,24 @@ function resolvePreset(presetName, plugins) { | ||
} | ||
function groupLintAssertionRules(rules) { | ||
if (!rules) { | ||
return rules; | ||
} | ||
// Create a new record to avoid mutating original | ||
const transformedRules = {}; | ||
// Collect assertion rules | ||
const assertions = []; | ||
for (const [ruleKey, rule] of Object.entries(rules)) { | ||
if (ruleKey.startsWith('assert/') && typeof rule === 'object' && rule !== null) { | ||
const assertion = rule; | ||
assertions.push(Object.assign(Object.assign({}, assertion), { assertionId: ruleKey.replace('assert/', '') })); | ||
} | ||
else { | ||
// If it's not an assertion, keep it as is | ||
transformedRules[ruleKey] = rule; | ||
} | ||
} | ||
if (assertions.length > 0) { | ||
transformedRules.assertions = assertions; | ||
} | ||
return transformedRules; | ||
} |
@@ -0,1 +1,2 @@ | ||
/// <reference types="node" /> | ||
import { NormalizedProblem } from '../walk'; | ||
@@ -5,6 +6,8 @@ import { OasVersion, OasMajorVersion, Oas2RuleSet, Oas3RuleSet } from '../oas-types'; | ||
import type { DecoratorConfig, Plugin, PreprocessorConfig, Region, ResolveConfig, ResolvedApi, ResolvedConfig, ResolvedLintConfig, RuleConfig } from './types'; | ||
export declare const env: NodeJS.ProcessEnv; | ||
export declare const IGNORE_FILE = ".redocly.lint-ignore.yaml"; | ||
export declare const DEFAULT_REGION = "us"; | ||
export declare const DOMAINS: { | ||
[region in Region]: string; | ||
us: string; | ||
eu: string; | ||
}; | ||
@@ -11,0 +14,0 @@ export declare const AVAILABLE_REGIONS: Region[]; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.Config = exports.LintConfig = exports.AVAILABLE_REGIONS = exports.DOMAINS = exports.DEFAULT_REGION = exports.IGNORE_FILE = void 0; | ||
exports.Config = exports.LintConfig = exports.AVAILABLE_REGIONS = exports.DOMAINS = exports.DEFAULT_REGION = exports.IGNORE_FILE = exports.env = void 0; | ||
const fs = require("fs"); | ||
@@ -10,2 +10,4 @@ const path = require("path"); | ||
const utils_2 = require("./utils"); | ||
// Alias environment here so this file can work in browser environments too. | ||
exports.env = typeof process !== 'undefined' ? process.env || {} : {}; | ||
exports.IGNORE_FILE = '.redocly.lint-ignore.yaml'; | ||
@@ -15,14 +17,18 @@ const IGNORE_BANNER = `# This file instructs Redocly's linter to ignore the rules contained for specific parts of your API.\n` + | ||
exports.DEFAULT_REGION = 'us'; | ||
const REDOCLY_DOMAIN = process.env.REDOCLY_DOMAIN; | ||
exports.DOMAINS = { | ||
us: 'redocly.com', | ||
eu: 'eu.redocly.com', | ||
}; | ||
// FIXME: temporary fix for our lab environments | ||
if (REDOCLY_DOMAIN === null || REDOCLY_DOMAIN === void 0 ? void 0 : REDOCLY_DOMAIN.endsWith('.redocly.host')) { | ||
exports.DOMAINS[REDOCLY_DOMAIN.split('.')[0]] = REDOCLY_DOMAIN; | ||
function getDomains() { | ||
const domains = { | ||
us: 'redocly.com', | ||
eu: 'eu.redocly.com', | ||
}; | ||
// FIXME: temporary fix for our lab environments | ||
const domain = exports.env.REDOCLY_DOMAIN; | ||
if (domain === null || domain === void 0 ? void 0 : domain.endsWith('.redocly.host')) { | ||
domains[domain.split('.')[0]] = domain; | ||
} | ||
if (domain === 'redoc.online') { | ||
domains[domain] = domain; | ||
} | ||
return domains; | ||
} | ||
if (REDOCLY_DOMAIN === 'redoc.online') { | ||
exports.DOMAINS[REDOCLY_DOMAIN] = REDOCLY_DOMAIN; | ||
} | ||
exports.DOMAINS = getDomains(); | ||
exports.AVAILABLE_REGIONS = Object.keys(exports.DOMAINS); | ||
@@ -29,0 +35,0 @@ class LintConfig { |
@@ -8,2 +8,3 @@ "use strict"; | ||
const codeframes_1 = require("./codeframes"); | ||
const config_1 = require("../config"); | ||
const ERROR_MESSAGE = { | ||
@@ -135,3 +136,3 @@ INVALID_SEVERITY_LEVEL: 'Invalid severity level; accepted values: error or warn', | ||
} }) : undefined }); | ||
if (process.env.FORMAT_JSON_WITH_CODEFRAMES) { | ||
if (config_1.env.FORMAT_JSON_WITH_CODEFRAMES) { | ||
const location = p.location[0]; // TODO: support multiple locations | ||
@@ -138,0 +139,0 @@ const loc = codeframes_1.getLineColLocation(location); |
@@ -21,3 +21,2 @@ "use strict"; | ||
const TOKEN_FILENAME = '.redocly-config.json'; | ||
let REDOCLY_DOMAIN; // workaround for the isRedoclyRegistryURL, see more below | ||
class RedoclyClient { | ||
@@ -28,8 +27,4 @@ constructor(region) { | ||
this.loadTokens(); | ||
this.domain = region ? config_1.DOMAINS[region] : process.env.REDOCLY_DOMAIN || config_1.DOMAINS[config_1.DEFAULT_REGION]; | ||
/* | ||
* We can't use process.env here because it is replaced by a const in some client-side bundles, | ||
* which breaks assignment. | ||
*/ | ||
REDOCLY_DOMAIN = this.domain; // isRedoclyRegistryURL depends on the value to be set | ||
this.domain = region ? config_1.DOMAINS[region] : config_1.env.REDOCLY_DOMAIN || config_1.DOMAINS[config_1.DEFAULT_REGION]; | ||
config_1.env.REDOCLY_DOMAIN = this.domain; // isRedoclyRegistryURL depends on the value to be set | ||
this.registryApi = new registry_api_1.RegistryApi(this.accessTokens, this.region); | ||
@@ -39,7 +34,6 @@ } | ||
if (region && !config_1.DOMAINS[region]) { | ||
process.stdout.write(colorette_1.red(`Invalid argument: region in config file.\nGiven: ${colorette_1.green(region)}, choices: "us", "eu".\n`)); | ||
process.exit(1); | ||
throw new Error(`Invalid argument: region in config file.\nGiven: ${colorette_1.green(region)}, choices: "us", "eu".`); | ||
} | ||
if (process.env.REDOCLY_DOMAIN) { | ||
return (config_1.AVAILABLE_REGIONS.find((region) => config_1.DOMAINS[region] === process.env.REDOCLY_DOMAIN) || config_1.DEFAULT_REGION); | ||
if (config_1.env.REDOCLY_DOMAIN) { | ||
return (config_1.AVAILABLE_REGIONS.find((region) => config_1.DOMAINS[region] === config_1.env.REDOCLY_DOMAIN) || config_1.DEFAULT_REGION); | ||
} | ||
@@ -60,9 +54,3 @@ return region || config_1.DEFAULT_REGION; | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const token = this.accessTokens[this.region]; | ||
// print this only if there is token but invalid | ||
if (token && !this.isAuthorizedWithRedoclyByRegion()) { | ||
process.stderr.write(`${colorette_1.yellow('Warning:')} invalid Redocly API key. Use "npx @redocly/cli login" to provide your API key\n`); | ||
return undefined; | ||
} | ||
return token; | ||
return this.accessTokens[this.region]; | ||
}); | ||
@@ -83,4 +71,4 @@ } | ||
} | ||
if (process.env.REDOCLY_AUTHORIZATION) { | ||
this.setAccessTokens(Object.assign(Object.assign({}, this.accessTokens), { [this.region]: process.env.REDOCLY_AUTHORIZATION })); | ||
if (config_1.env.REDOCLY_AUTHORIZATION) { | ||
this.setAccessTokens(Object.assign(Object.assign({}, this.accessTokens), { [this.region]: config_1.env.REDOCLY_AUTHORIZATION })); | ||
} | ||
@@ -141,3 +129,2 @@ } | ||
const credentialsPath = path_1.resolve(os_1.homedir(), TOKEN_FILENAME); | ||
process.stdout.write(colorette_1.gray('\n Logging in...\n')); | ||
try { | ||
@@ -147,4 +134,3 @@ yield this.verifyToken(accessToken, this.region, verbose); | ||
catch (err) { | ||
process.stdout.write(colorette_1.red('Authorization failed. Please check if you entered a valid API key.\n')); | ||
process.exit(1); | ||
throw new Error('Authorization failed. Please check if you entered a valid API key.'); | ||
} | ||
@@ -155,3 +141,2 @@ const credentials = Object.assign(Object.assign({}, this.readCredentialsFile(credentialsPath)), { [this.region]: accessToken, token: accessToken }); | ||
fs_1.writeFileSync(credentialsPath, JSON.stringify(credentials, null, 2)); | ||
process.stdout.write(colorette_1.green(' Authorization confirmed. ✅\n\n')); | ||
}); | ||
@@ -164,3 +149,2 @@ } | ||
} | ||
process.stdout.write('Logged out from the Redocly account. ✋\n'); | ||
} | ||
@@ -170,3 +154,3 @@ } | ||
function isRedoclyRegistryURL(link) { | ||
const domain = REDOCLY_DOMAIN || process.env.REDOCLY_DOMAIN || config_1.DOMAINS[config_1.DEFAULT_REGION]; | ||
const domain = config_1.env.REDOCLY_DOMAIN || config_1.DOMAINS[config_1.DEFAULT_REGION]; | ||
const legacyDomain = domain === 'redocly.com' ? 'redoc.ly' : domain; | ||
@@ -173,0 +157,0 @@ if (!link.startsWith(`https://api.${domain}/registry/`) && |
@@ -17,2 +17,3 @@ export declare namespace RegistryApiTypes { | ||
isUpsert?: boolean; | ||
isPublic?: boolean; | ||
} | ||
@@ -19,0 +20,0 @@ export interface PrepareFileuploadOKResponse { |
@@ -16,3 +16,3 @@ import { RegistryApiTypes } from './registry-api-types'; | ||
prepareFileUpload({ organizationId, name, version, filesHash, filename, isUpsert, }: RegistryApiTypes.PrepareFileuploadParams): Promise<RegistryApiTypes.PrepareFileuploadOKResponse>; | ||
pushApi({ organizationId, name, version, rootFilePath, filePaths, branch, isUpsert, }: RegistryApiTypes.PushApiParams): Promise<void>; | ||
pushApi({ organizationId, name, version, rootFilePath, filePaths, branch, isUpsert, isPublic, }: RegistryApiTypes.PushApiParams): Promise<void>; | ||
} |
@@ -83,3 +83,3 @@ "use strict"; | ||
} | ||
pushApi({ organizationId, name, version, rootFilePath, filePaths, branch, isUpsert, }) { | ||
pushApi({ organizationId, name, version, rootFilePath, filePaths, branch, isUpsert, isPublic, }) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
@@ -97,2 +97,3 @@ const response = yield this.request(`/${organizationId}/${name}/${version}`, { | ||
isUpsert, | ||
isPublic, | ||
}), | ||
@@ -99,0 +100,0 @@ }, this.region); |
@@ -25,3 +25,2 @@ import { UserContext } from './walk'; | ||
}>; | ||
export declare function match(url: string, pattern: string): boolean; | ||
export declare function pickObjectProps<T extends Record<string, unknown>>(object: T, keys: Array<string>): T; | ||
@@ -28,0 +27,0 @@ export declare function omitObjectProps<T extends Record<string, unknown>>(object: T, keys: Array<string>): T; |
@@ -12,3 +12,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.assignExisting = exports.isNotString = exports.isString = exports.isNotEmptyObject = exports.slash = exports.isPathParameter = exports.readFileAsStringSync = exports.isSingular = exports.validateMimeTypeOAS3 = exports.validateMimeType = exports.splitCamelCaseIntoWords = exports.omitObjectProps = exports.pickObjectProps = exports.match = exports.readFileFromUrl = exports.isEmptyArray = exports.isEmptyObject = exports.isPlainObject = exports.notUndefined = exports.loadYaml = exports.popStack = exports.pushStack = exports.stringifyYaml = exports.parseYaml = void 0; | ||
exports.assignExisting = exports.isNotString = exports.isString = exports.isNotEmptyObject = exports.slash = exports.isPathParameter = exports.readFileAsStringSync = exports.isSingular = exports.validateMimeTypeOAS3 = exports.validateMimeType = exports.splitCamelCaseIntoWords = exports.omitObjectProps = exports.pickObjectProps = exports.readFileFromUrl = exports.isEmptyArray = exports.isEmptyObject = exports.isPlainObject = exports.notUndefined = exports.loadYaml = exports.popStack = exports.pushStack = exports.stringifyYaml = exports.parseYaml = void 0; | ||
const fs = require("fs"); | ||
@@ -19,2 +19,3 @@ const minimatch = require("minimatch"); | ||
const js_yaml_1 = require("./js-yaml"); | ||
const config_1 = require("./config"); | ||
var js_yaml_2 = require("./js-yaml"); | ||
@@ -61,3 +62,3 @@ Object.defineProperty(exports, "parseYaml", { enumerable: true, get: function () { return js_yaml_2.parseYaml; } }); | ||
headers[header.name] = | ||
header.envVariable !== undefined ? process.env[header.envVariable] || '' : header.value; | ||
header.envVariable !== undefined ? config_1.env[header.envVariable] || '' : header.value; | ||
} | ||
@@ -82,3 +83,2 @@ } | ||
} | ||
exports.match = match; | ||
function pickObjectProps(object, keys) { | ||
@@ -85,0 +85,0 @@ return Object.fromEntries(keys.filter((key) => key in object).map((key) => [key, object[key]])); |
{ | ||
"name": "@redocly/openapi-core", | ||
"version": "1.0.0-beta.96", | ||
"version": "1.0.0-beta.97", | ||
"description": "", | ||
@@ -42,3 +42,3 @@ "main": "lib/index.js", | ||
"lodash.isequal": "^4.5.0", | ||
"minimatch": "^3.0.4", | ||
"minimatch": "^5.0.1", | ||
"node-fetch": "^2.6.1", | ||
@@ -52,3 +52,3 @@ "pluralize": "^8.0.0", | ||
"@types/lodash.isequal": "^4.5.5", | ||
"@types/minimatch": "^3.0.3", | ||
"@types/minimatch": "^3.0.5", | ||
"@types/node-fetch": "^2.5.7", | ||
@@ -55,0 +55,0 @@ "@types/pluralize": "^0.0.29", |
@@ -133,2 +133,33 @@ import { resolveLint, resolveApis, resolveConfig } from '../config-resolvers'; | ||
it('should correctly merge assertions from nested config', async () => { | ||
const lintConfig = { | ||
extends: ['local-config-with-file.yaml'], | ||
}; | ||
const lint = await resolveLint({ | ||
lintConfig, | ||
configPath, | ||
}); | ||
expect(Array.isArray(lint.rules?.assertions)).toEqual(true); | ||
expect(lint.rules?.assertions).toMatchObject( [ | ||
{ | ||
subject: 'PathItem', | ||
property: 'get', | ||
message: 'Every path item must have a GET operation.', | ||
defined: true, | ||
assertionId: 'path-item-get-defined' | ||
}, | ||
{ | ||
subject: 'Tag', | ||
property: 'description', | ||
message: 'Tag description must be at least 13 characters and end with a full stop.', | ||
severity: 'error', | ||
minLength: 13, | ||
pattern: '/\\.$/', | ||
assertionId: 'tag-description' | ||
} | ||
]) | ||
}); | ||
it('should resolve extends with url file config witch contains path to nested config', async () => { | ||
@@ -135,0 +166,0 @@ const lintConfig = { |
@@ -14,3 +14,10 @@ import * as path from 'path'; | ||
} from './utils'; | ||
import type { LintRawConfig, Plugin, RawConfig, ResolvedApi, ResolvedLintConfig } from './types'; | ||
import type { | ||
LintRawConfig, | ||
Plugin, | ||
RawConfig, | ||
ResolvedApi, | ||
ResolvedLintConfig, | ||
RuleConfig, | ||
} from './types'; | ||
import { isNotString, isString, notUndefined, parseYaml } from '../utils'; | ||
@@ -179,3 +186,3 @@ import { Config } from './config'; | ||
export async function resolveLint( | ||
async function resolveAndMergeNestedLint( | ||
{ | ||
@@ -218,3 +225,3 @@ lintConfig, | ||
const extendedLintConfig = await loadExtendLintConfig(pathItem, resolver); | ||
return await resolveLint( | ||
return await resolveAndMergeNestedLint( | ||
{ | ||
@@ -251,2 +258,19 @@ lintConfig: extendedLintConfig, | ||
export async function resolveLint( | ||
lintOpts: { | ||
lintConfig?: LintRawConfig; | ||
configPath?: string; | ||
resolver?: BaseResolver; | ||
}, | ||
parentConfigPaths: string[] = [], | ||
extendPaths: string[] = [], | ||
): Promise<ResolvedLintConfig> { | ||
const resolvedLint = await resolveAndMergeNestedLint(lintOpts, parentConfigPaths, extendPaths); | ||
return { | ||
...resolvedLint, | ||
rules: resolvedLint.rules && groupLintAssertionRules(resolvedLint.rules), | ||
}; | ||
} | ||
export function resolvePreset(presetName: string, plugins: Plugin[]): ResolvedLintConfig { | ||
@@ -309,1 +333,32 @@ const { pluginId, configName } = parsePresetName(presetName); | ||
} | ||
function groupLintAssertionRules( | ||
rules: Record<string, RuleConfig> | undefined, | ||
): Record<string, RuleConfig> | undefined { | ||
if (!rules) { | ||
return rules; | ||
} | ||
// Create a new record to avoid mutating original | ||
const transformedRules: Record<string, RuleConfig> = {}; | ||
// Collect assertion rules | ||
const assertions = []; | ||
for (const [ruleKey, rule] of Object.entries(rules)) { | ||
if (ruleKey.startsWith('assert/') && typeof rule === 'object' && rule !== null) { | ||
const assertion = rule; | ||
assertions.push({ | ||
...assertion, | ||
assertionId: ruleKey.replace('assert/', ''), | ||
}); | ||
} else { | ||
// If it's not an assertion, keep it as is | ||
transformedRules[ruleKey] = rule; | ||
} | ||
} | ||
if (assertions.length > 0) { | ||
transformedRules.assertions = assertions; | ||
} | ||
return transformedRules; | ||
} |
@@ -22,2 +22,5 @@ import * as fs from 'fs'; | ||
// Alias environment here so this file can work in browser environments too. | ||
export const env = typeof process !== 'undefined' ? process.env || {} : {}; | ||
export const IGNORE_FILE = '.redocly.lint-ignore.yaml'; | ||
@@ -29,15 +32,21 @@ const IGNORE_BANNER = | ||
export const DEFAULT_REGION = 'us'; | ||
const REDOCLY_DOMAIN = process.env.REDOCLY_DOMAIN; | ||
export const DOMAINS: { [region in Region]: string } = { | ||
us: 'redocly.com', | ||
eu: 'eu.redocly.com', | ||
}; | ||
// FIXME: temporary fix for our lab environments | ||
if (REDOCLY_DOMAIN?.endsWith('.redocly.host')) { | ||
DOMAINS[REDOCLY_DOMAIN.split('.')[0] as Region] = REDOCLY_DOMAIN; | ||
function getDomains() { | ||
const domains: { [region in Region]: string } = { | ||
us: 'redocly.com', | ||
eu: 'eu.redocly.com', | ||
}; | ||
// FIXME: temporary fix for our lab environments | ||
const domain = env.REDOCLY_DOMAIN; | ||
if (domain?.endsWith('.redocly.host')) { | ||
domains[domain.split('.')[0] as Region] = domain; | ||
} | ||
if (domain === 'redoc.online') { | ||
domains[domain as Region] = domain; | ||
} | ||
return domains; | ||
} | ||
if (REDOCLY_DOMAIN === 'redoc.online') { | ||
DOMAINS[REDOCLY_DOMAIN as Region] = REDOCLY_DOMAIN; | ||
} | ||
export const DOMAINS = getDomains(); | ||
export const AVAILABLE_REGIONS = Object.keys(DOMAINS) as Region[]; | ||
@@ -44,0 +53,0 @@ |
@@ -17,2 +17,3 @@ import * as path from 'path'; | ||
import { getCodeframe, getLineColLocation } from './codeframes'; | ||
import { env } from "../config"; | ||
@@ -206,3 +207,3 @@ export type Totals = { | ||
if (process.env.FORMAT_JSON_WITH_CODEFRAMES) { | ||
if (env.FORMAT_JSON_WITH_CODEFRAMES) { | ||
const location = p.location[0]; // TODO: support multiple locations | ||
@@ -209,0 +210,0 @@ const loc = getLineColLocation(location); |
import { existsSync, readFileSync, writeFileSync, unlinkSync } from 'fs'; | ||
import { resolve } from 'path'; | ||
import { homedir } from 'os'; | ||
import { red, green, gray, yellow } from 'colorette'; | ||
import { green } from 'colorette'; | ||
import { RegistryApi } from './registry-api'; | ||
import { DEFAULT_REGION, DOMAINS, AVAILABLE_REGIONS } from '../config/config'; | ||
import { DEFAULT_REGION, DOMAINS, AVAILABLE_REGIONS, env } from '../config/config'; | ||
import { RegionalToken, RegionalTokenWithValidity } from './redocly-client-types'; | ||
@@ -14,3 +14,2 @@ import { isNotEmptyObject } from '../utils'; | ||
let REDOCLY_DOMAIN: string; // workaround for the isRedoclyRegistryURL, see more below | ||
export class RedoclyClient { | ||
@@ -25,9 +24,5 @@ private accessTokens: AccessTokens = {}; | ||
this.loadTokens(); | ||
this.domain = region ? DOMAINS[region] : process.env.REDOCLY_DOMAIN || DOMAINS[DEFAULT_REGION]; | ||
this.domain = region ? DOMAINS[region] : env.REDOCLY_DOMAIN || DOMAINS[DEFAULT_REGION]; | ||
/* | ||
* We can't use process.env here because it is replaced by a const in some client-side bundles, | ||
* which breaks assignment. | ||
*/ | ||
REDOCLY_DOMAIN = this.domain; // isRedoclyRegistryURL depends on the value to be set | ||
env.REDOCLY_DOMAIN = this.domain; // isRedoclyRegistryURL depends on the value to be set | ||
this.registryApi = new RegistryApi(this.accessTokens, this.region); | ||
@@ -38,15 +33,8 @@ } | ||
if (region && !DOMAINS[region]) { | ||
process.stdout.write( | ||
red( | ||
`Invalid argument: region in config file.\nGiven: ${green( | ||
region, | ||
)}, choices: "us", "eu".\n`, | ||
), | ||
); | ||
process.exit(1); | ||
throw new Error(`Invalid argument: region in config file.\nGiven: ${green(region)}, choices: "us", "eu".`); | ||
} | ||
if (process.env.REDOCLY_DOMAIN) { | ||
if (env.REDOCLY_DOMAIN) { | ||
return (AVAILABLE_REGIONS.find( | ||
(region) => DOMAINS[region as Region] === process.env.REDOCLY_DOMAIN, | ||
(region) => DOMAINS[region as Region] === env.REDOCLY_DOMAIN, | ||
) || DEFAULT_REGION) as Region; | ||
@@ -71,14 +59,3 @@ } | ||
async getAuthorizationHeader(): Promise<string | undefined> { | ||
const token = this.accessTokens[this.region]; | ||
// print this only if there is token but invalid | ||
if (token && !this.isAuthorizedWithRedoclyByRegion()) { | ||
process.stderr.write( | ||
`${yellow( | ||
'Warning:', | ||
)} invalid Redocly API key. Use "npx @redocly/cli login" to provide your API key\n`, | ||
); | ||
return undefined; | ||
} | ||
return token; | ||
return this.accessTokens[this.region]; | ||
} | ||
@@ -103,6 +80,6 @@ // </backward compatibility: portal> | ||
} | ||
if (process.env.REDOCLY_AUTHORIZATION) { | ||
if (env.REDOCLY_AUTHORIZATION) { | ||
this.setAccessTokens({ | ||
...this.accessTokens, | ||
[this.region]: process.env.REDOCLY_AUTHORIZATION, | ||
[this.region]: env.REDOCLY_AUTHORIZATION, | ||
}); | ||
@@ -172,3 +149,2 @@ } | ||
const credentialsPath = resolve(homedir(), TOKEN_FILENAME); | ||
process.stdout.write(gray('\n Logging in...\n')); | ||
@@ -178,6 +154,3 @@ try { | ||
} catch (err) { | ||
process.stdout.write( | ||
red('Authorization failed. Please check if you entered a valid API key.\n'), | ||
); | ||
process.exit(1); | ||
throw new Error('Authorization failed. Please check if you entered a valid API key.'); | ||
} | ||
@@ -193,3 +166,2 @@ | ||
writeFileSync(credentialsPath, JSON.stringify(credentials, null, 2)); | ||
process.stdout.write(green(' Authorization confirmed. ✅\n\n')); | ||
} | ||
@@ -202,3 +174,2 @@ | ||
} | ||
process.stdout.write('Logged out from the Redocly account. ✋\n'); | ||
} | ||
@@ -208,3 +179,3 @@ } | ||
export function isRedoclyRegistryURL(link: string): boolean { | ||
const domain = REDOCLY_DOMAIN || process.env.REDOCLY_DOMAIN || DOMAINS[DEFAULT_REGION]; | ||
const domain = env.REDOCLY_DOMAIN || DOMAINS[DEFAULT_REGION]; | ||
@@ -211,0 +182,0 @@ const legacyDomain = domain === 'redocly.com' ? 'redoc.ly' : domain; |
@@ -19,2 +19,3 @@ export namespace RegistryApiTypes { | ||
isUpsert?: boolean; | ||
isPublic?: boolean; | ||
} | ||
@@ -21,0 +22,0 @@ |
@@ -107,2 +107,3 @@ import fetch, { RequestInit, HeadersInit } from 'node-fetch'; | ||
isUpsert, | ||
isPublic, | ||
}: RegistryApiTypes.PushApiParams) { | ||
@@ -122,2 +123,3 @@ const response = await this.request( | ||
isUpsert, | ||
isPublic, | ||
}), | ||
@@ -124,0 +126,0 @@ }, |
@@ -8,2 +8,3 @@ import * as fs from 'fs'; | ||
import type { HttpResolveConfig } from './config'; | ||
import { env } from "./config"; | ||
@@ -55,3 +56,3 @@ export { parseYaml, stringifyYaml } from './js-yaml'; | ||
headers[header.name] = | ||
header.envVariable !== undefined ? process.env[header.envVariable] || '' : header.value; | ||
header.envVariable !== undefined ? env[header.envVariable] || '' : header.value; | ||
} | ||
@@ -71,3 +72,3 @@ } | ||
export function match(url: string, pattern: string) { | ||
function match(url: string, pattern: string) { | ||
if (!pattern.match(/^https?:\/\//)) { | ||
@@ -74,0 +75,0 @@ // if pattern doesn't specify protocol directly, do not match against it |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 4 instances in 1 package
2113016
28522
17
+ Addedbrace-expansion@2.0.1(transitive)
+ Addedminimatch@5.1.6(transitive)
- Removedbrace-expansion@1.1.11(transitive)
- Removedconcat-map@0.0.1(transitive)
- Removedminimatch@3.1.2(transitive)
Updatedminimatch@^5.0.1