@useoptic/cli-config
Advanced tools
Comparing version 10.0.1-alpha.1 to 10.0.1-beta.0
@@ -12,4 +12,13 @@ "use strict"; | ||
name: ${escapeIt(apiName)} | ||
# Start your api with Optic by running 'api run <taskname>' | ||
tasks: | ||
${buildInitialTask(flags, taskName)}`.trimLeft(); | ||
${buildInitialTask(flags, taskName)} | ||
# Capture traffic from a deployed api by running 'api intercept <environment-name>' | ||
# pass '--chrome' to capture from your browser's network tab | ||
environments: | ||
production: | ||
host: https://api.github.com # the hostname of the API we should record traffic from | ||
webUI: https://api.github.com/repos/opticdev/optic # the url that should open when a browser flag is passed | ||
`.trimLeft(); | ||
return config; | ||
@@ -16,0 +25,0 @@ } |
@@ -38,4 +38,11 @@ import { parseRule, parseIgnore, IIgnoreRunnable } from './helpers/ignore-parser'; | ||
}; | ||
environments?: IEnvironmentsConfig; | ||
ignoreRequests?: string[]; | ||
} | ||
export interface IEnvironmentsConfig { | ||
[key: string]: { | ||
host: string; | ||
webUI?: string; | ||
}; | ||
} | ||
export declare function readApiConfig(configPath: string): Promise<IApiCliConfig>; | ||
@@ -98,2 +105,3 @@ export declare function readTestingConfig(testingConfigPath: string): Promise<ITestingConfig>; | ||
} | ||
export declare function randomLowerBound(): number; | ||
export declare function isTestTask(aliasedTask: IOpticTaskAliased): boolean; | ||
@@ -100,0 +108,0 @@ export declare function isRecommendedTask(aliasedTask: IOpticTaskAliased): boolean; |
@@ -25,3 +25,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.parseRule = exports.parseIgnore = exports.Modes = exports.createFileTree = exports.getPathsRelativeToCwd = exports.pathsFromCwd = exports.getPathsRelativeToConfig = exports.TaskToStartConfig = exports.isManualTask = exports.isRecommendedTask = exports.isTestTask = exports.RunsWithTaskNotFoundError = exports.TaskNotFoundError = exports.TargetPortUnavailableError = exports.CommandExecutionFailure = exports.OpticConfigurationLocationFailure = exports.InvalidOpticConfigurationSyntaxError = exports.readTestingConfig = exports.readApiConfig = void 0; | ||
exports.parseRule = exports.parseIgnore = exports.Modes = exports.createFileTree = exports.getPathsRelativeToCwd = exports.pathsFromCwd = exports.getPathsRelativeToConfig = exports.TaskToStartConfig = exports.isManualTask = exports.isRecommendedTask = exports.isTestTask = exports.randomLowerBound = exports.RunsWithTaskNotFoundError = exports.TaskNotFoundError = exports.TargetPortUnavailableError = exports.CommandExecutionFailure = exports.OpticConfigurationLocationFailure = exports.InvalidOpticConfigurationSyntaxError = exports.readTestingConfig = exports.readApiConfig = void 0; | ||
const fs_extra_1 = __importDefault(require("fs-extra")); | ||
@@ -81,2 +81,3 @@ const path_1 = __importDefault(require("path")); | ||
} | ||
exports.randomLowerBound = randomLowerBound; | ||
function isTestTask(aliasedTask) { | ||
@@ -83,0 +84,0 @@ return Boolean(aliasedTask.useTask && aliasedTask.command); |
@@ -6,5 +6,7 @@ export declare const opticrcPath: string; | ||
anonymousId: string; | ||
source: string; | ||
} | ||
export declare function getCurrentStorage(): Promise<IUserStorage | undefined>; | ||
export declare function getOrCreateAnonId(): Promise<string>; | ||
export declare function getOrCreateSource(): Promise<string>; | ||
//# sourceMappingURL=optic-rc.d.ts.map |
@@ -6,13 +6,13 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.getOrCreateAnonId = exports.getCurrentStorage = exports.defaultStorage = exports.opticrcPath = void 0; | ||
exports.getOrCreateSource = exports.getOrCreateAnonId = exports.getCurrentStorage = exports.defaultStorage = exports.opticrcPath = void 0; | ||
const fs_extra_1 = __importDefault(require("fs-extra")); | ||
const path_1 = __importDefault(require("path")); | ||
const os_1 = __importDefault(require("os")); | ||
//@ts-ignore | ||
const human_readable_ids_1 = require("human-readable-ids"); | ||
exports.opticrcPath = path_1.default.resolve(os_1.default.homedir(), '.opticrc'); | ||
const getSourceFromEnv = () => process.env.__OPTIC_SOURCE || 'user'; | ||
function defaultStorage() { | ||
return { | ||
idToken: undefined, | ||
anonymousId: human_readable_ids_1.hri.random(), | ||
source: getSourceFromEnv(), | ||
}; | ||
@@ -31,20 +31,27 @@ } | ||
exports.getCurrentStorage = getCurrentStorage; | ||
async function getOrCreateAnonId() { | ||
async function getOrCreateKey(key, defaultValue) { | ||
const storage = await getCurrentStorage(); | ||
if (storage && storage.anonymousId) { | ||
return storage.anonymousId; | ||
if (storage && storage[key]) { | ||
return storage[key]; | ||
} | ||
else if (storage) { | ||
const storeValue = Object.assign(Object.assign({}, storage), { anonymousId: human_readable_ids_1.hri.random() }); | ||
const storeValue = Object.assign(Object.assign({}, storage), { [key]: defaultValue() }); | ||
await fs_extra_1.default.ensureFile(exports.opticrcPath); | ||
await fs_extra_1.default.writeFile(exports.opticrcPath, JSON.stringify(storeValue)); | ||
return storeValue.anonymousId; | ||
return storage[key]; | ||
} | ||
else { | ||
const storeValue = defaultStorage(); | ||
const storeValue = Object.assign(Object.assign({}, defaultStorage()), { [key]: defaultValue() }); | ||
await fs_extra_1.default.ensureFile(exports.opticrcPath); | ||
await fs_extra_1.default.writeFile(exports.opticrcPath, JSON.stringify(storeValue)); | ||
return storeValue.anonymousId; | ||
return storeValue[key]; | ||
} | ||
} | ||
function getOrCreateAnonId() { | ||
return getOrCreateKey('anonymousId', human_readable_ids_1.hri.random); | ||
} | ||
exports.getOrCreateAnonId = getOrCreateAnonId; | ||
function getOrCreateSource() { | ||
return getOrCreateKey('source', getSourceFromEnv); | ||
} | ||
exports.getOrCreateSource = getOrCreateSource; |
{ | ||
"name": "@useoptic/cli-config", | ||
"version": "10.0.1-alpha.1", | ||
"version": "10.0.1-beta.0", | ||
"scripts": { | ||
@@ -5,0 +5,0 @@ "ws:test": "jest", |
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
36846
776
5