@datocms/cli-utils
Advanced tools
Comparing version 0.1.8 to 0.1.9
import { Client, ClientConfigOptions, LogLevel } from '@datocms/cma-client-node'; | ||
import { DatoProjectConfigCommand } from './dato-project-config-command'; | ||
import { DatoProfileConfigCommand } from './dato-profile-config-command'; | ||
export declare const logLevelMap: { | ||
@@ -11,3 +11,3 @@ readonly NONE: LogLevel.NONE; | ||
export declare const logLevelOptions: ("NONE" | "BASIC" | "BODY" | "BODY_AND_HEADERS")[]; | ||
export declare abstract class CmaClientCommand<T extends typeof CmaClientCommand.flags> extends DatoProjectConfigCommand<T> { | ||
export declare abstract class CmaClientCommand<T extends typeof CmaClientCommand.flags> extends DatoProfileConfigCommand<T> { | ||
static flags: { | ||
@@ -17,3 +17,3 @@ 'api-token': import("@oclif/core/lib/interfaces").OptionFlag<string | undefined>; | ||
'base-url': import("@oclif/core/lib/interfaces").OptionFlag<string | undefined>; | ||
project: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined>; | ||
profile: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined>; | ||
'config-file': import("@oclif/core/lib/interfaces").OptionFlag<string>; | ||
@@ -20,0 +20,0 @@ }; |
@@ -6,3 +6,3 @@ "use strict"; | ||
const core_1 = require("@oclif/core"); | ||
const dato_project_config_command_1 = require("./dato-project-config-command"); | ||
const dato_profile_config_command_1 = require("./dato-profile-config-command"); | ||
const chalk = require("chalk"); | ||
@@ -16,3 +16,3 @@ exports.logLevelMap = { | ||
exports.logLevelOptions = Object.keys(exports.logLevelMap); | ||
class CmaClientCommand extends dato_project_config_command_1.DatoProjectConfigCommand { | ||
class CmaClientCommand extends dato_profile_config_command_1.DatoProfileConfigCommand { | ||
async init() { | ||
@@ -23,6 +23,9 @@ await super.init(); | ||
buildBaseClientInitializationOptions() { | ||
var _a, _b, _c; | ||
const apiToken = this.parsedFlags['api-token'] || ((_a = this.datoProjectConfig) === null || _a === void 0 ? void 0 : _a.apiToken); | ||
const baseUrl = this.parsedFlags['base-url'] || ((_b = this.datoProjectConfig) === null || _b === void 0 ? void 0 : _b.baseUrl); | ||
const logLevelCode = this.parsedFlags['log-level'] || ((_c = this.datoProjectConfig) === null || _c === void 0 ? void 0 : _c.logLevel); | ||
var _a, _b; | ||
const apiTokenEnvName = this.profileId === 'default' | ||
? `DATOCMS_API_TOKEN` | ||
: `DATOCMS_${this.profileId.toUpperCase()}_PROFILE_API_TOKEN`; | ||
const apiToken = this.parsedFlags['api-token'] || process.env[apiTokenEnvName]; | ||
const baseUrl = this.parsedFlags['base-url'] || ((_a = this.datoProfileConfig) === null || _a === void 0 ? void 0 : _a.baseUrl); | ||
const logLevelCode = this.parsedFlags['log-level'] || ((_b = this.datoProfileConfig) === null || _b === void 0 ? void 0 : _b.logLevel); | ||
const logLevel = this.parsedFlags.json || this.parsedFlags.output || !logLevelCode | ||
@@ -35,5 +38,4 @@ ? cma_client_node_1.LogLevel.NONE | ||
`The API token to use is determined by looking at: | ||
* The --apiToken flag | ||
* The DATOCMS_API_TOKEN environment variable | ||
* Config file at "${this.datoConfigRelativePath}" (run "${this.config.bin} config:set" to setup)`, | ||
* The --api-token flag | ||
* The ${apiTokenEnvName} environment variable (we look inside a local ".env" file too)`, | ||
], | ||
@@ -76,6 +78,5 @@ }); | ||
CmaClientCommand.flags = { | ||
...dato_project_config_command_1.DatoProjectConfigCommand.flags, | ||
...dato_profile_config_command_1.DatoProfileConfigCommand.flags, | ||
'api-token': core_1.Flags.string({ | ||
description: 'Specify a custom API key to access a project', | ||
env: 'DATOCMS_API_TOKEN', | ||
description: 'Specify a custom API key to access a DatoCMS project', | ||
}), | ||
@@ -82,0 +83,0 @@ 'log-level': core_1.Flags.enum({ |
@@ -1,3 +0,2 @@ | ||
export declare type ProjectConfig = { | ||
apiToken?: string; | ||
export declare type ProfileConfig = { | ||
baseUrl?: string; | ||
@@ -12,4 +11,4 @@ logLevel?: 'NONE' | 'BASIC' | 'BODY' | 'BODY_AND_HEADERS'; | ||
export declare type Config = { | ||
projects: Record<string, ProjectConfig>; | ||
profiles: Record<string, ProfileConfig>; | ||
}; | ||
export declare function readConfig(fullPath: string): Promise<Config | undefined>; |
@@ -6,3 +6,3 @@ "use strict"; | ||
const lodash_1 = require("lodash"); | ||
function isProjectConfig(thing) { | ||
function isProfileConfig(thing) { | ||
if (typeof thing !== 'object' || !thing) { | ||
@@ -29,10 +29,10 @@ return false; | ||
} | ||
if (!('projects' in thing)) { | ||
if (!('profiles' in thing)) { | ||
return false; | ||
} | ||
const { projects } = thing; | ||
if (typeof projects !== 'object' || !projects) { | ||
const { profiles } = thing; | ||
if (typeof profiles !== 'object' || !profiles) { | ||
return false; | ||
} | ||
if (Object.values(projects).some((projectConfig) => !isProjectConfig(projectConfig))) { | ||
if (Object.values(profiles).some((profileConfig) => !isProfileConfig(profileConfig))) { | ||
return false; | ||
@@ -39,0 +39,0 @@ } |
@@ -20,3 +20,3 @@ "use strict"; | ||
suggestions: [ | ||
`Configure a local project with "${this.config.bin} config:set"`, | ||
`Configure a local configuration profile with "${this.config.bin} profile:set"`, | ||
], | ||
@@ -23,0 +23,0 @@ }); |
@@ -0,7 +1,8 @@ | ||
import 'dotenv/config'; | ||
export * from './base-command'; | ||
export * from './cma-client-command'; | ||
export * from './dato-config-command'; | ||
export * from './dato-project-config-command'; | ||
export * from './dato-profile-config-command'; | ||
export * from './config'; | ||
export * as CmaClient from '@datocms/cma-client-node'; | ||
export * as oclif from '@oclif/core'; |
@@ -5,8 +5,9 @@ "use strict"; | ||
const tslib_1 = require("tslib"); | ||
require("dotenv/config"); | ||
tslib_1.__exportStar(require("./base-command"), exports); | ||
tslib_1.__exportStar(require("./cma-client-command"), exports); | ||
tslib_1.__exportStar(require("./dato-config-command"), exports); | ||
tslib_1.__exportStar(require("./dato-project-config-command"), exports); | ||
tslib_1.__exportStar(require("./dato-profile-config-command"), exports); | ||
tslib_1.__exportStar(require("./config"), exports); | ||
exports.CmaClient = require("@datocms/cma-client-node"); | ||
exports.oclif = require("@oclif/core"); |
{ | ||
"name": "@datocms/cli-utils", | ||
"version": "0.1.8", | ||
"version": "0.1.9", | ||
"description": "Utils for DatoCMS CLI", | ||
@@ -21,5 +21,6 @@ "author": "Stefano Verna <s.verna@datocms.com>", | ||
"dependencies": { | ||
"@datocms/cma-client-node": "^0.1.5", | ||
"@datocms/cma-client-node": "^1", | ||
"@oclif/core": "^1", | ||
"chalk": "^4", | ||
"dotenv": "^16.0.1", | ||
"lodash": "^4.17.21" | ||
@@ -31,3 +32,3 @@ }, | ||
}, | ||
"gitHead": "2b40a70f6d9b04815f1eb04ef8f79059efced1fa" | ||
"gitHead": "87e3d15970872370177943224b32ed9f41c3c1c1" | ||
} |
@@ -9,3 +9,3 @@ import { | ||
import { Flags } from '@oclif/core'; | ||
import { DatoProjectConfigCommand } from './dato-project-config-command'; | ||
import { DatoProfileConfigCommand } from './dato-profile-config-command'; | ||
import * as chalk from 'chalk'; | ||
@@ -25,8 +25,7 @@ | ||
T extends typeof CmaClientCommand.flags, | ||
> extends DatoProjectConfigCommand<T> { | ||
> extends DatoProfileConfigCommand<T> { | ||
static flags = { | ||
...DatoProjectConfigCommand.flags, | ||
...DatoProfileConfigCommand.flags, | ||
'api-token': Flags.string({ | ||
description: 'Specify a custom API key to access a project', | ||
env: 'DATOCMS_API_TOKEN', | ||
description: 'Specify a custom API key to access a DatoCMS project', | ||
}), | ||
@@ -52,10 +51,15 @@ 'log-level': Flags.enum<LogLevelFlagEnum>({ | ||
} { | ||
const apiTokenEnvName = | ||
this.profileId === 'default' | ||
? `DATOCMS_API_TOKEN` | ||
: `DATOCMS_${this.profileId.toUpperCase()}_PROFILE_API_TOKEN`; | ||
const apiToken = | ||
this.parsedFlags['api-token'] || this.datoProjectConfig?.apiToken; | ||
this.parsedFlags['api-token'] || process.env[apiTokenEnvName]; | ||
const baseUrl = | ||
this.parsedFlags['base-url'] || this.datoProjectConfig?.baseUrl; | ||
this.parsedFlags['base-url'] || this.datoProfileConfig?.baseUrl; | ||
const logLevelCode = | ||
this.parsedFlags['log-level'] || this.datoProjectConfig?.logLevel; | ||
this.parsedFlags['log-level'] || this.datoProfileConfig?.logLevel; | ||
@@ -71,5 +75,4 @@ const logLevel = | ||
`The API token to use is determined by looking at: | ||
* The --apiToken flag | ||
* The DATOCMS_API_TOKEN environment variable | ||
* Config file at "${this.datoConfigRelativePath}" (run "${this.config.bin} config:set" to setup)`, | ||
* The --api-token flag | ||
* The ${apiTokenEnvName} environment variable (we look inside a local ".env" file too)`, | ||
], | ||
@@ -76,0 +79,0 @@ }); |
import { access, readFile } from 'fs/promises'; | ||
import { get } from 'lodash'; | ||
export type ProjectConfig = { | ||
apiToken?: string; | ||
export type ProfileConfig = { | ||
baseUrl?: string; | ||
@@ -16,6 +15,6 @@ logLevel?: 'NONE' | 'BASIC' | 'BODY' | 'BODY_AND_HEADERS'; | ||
export type Config = { | ||
projects: Record<string, ProjectConfig>; | ||
profiles: Record<string, ProfileConfig>; | ||
}; | ||
function isProjectConfig(thing: any): thing is ProjectConfig { | ||
function isProfileConfig(thing: any): thing is ProfileConfig { | ||
if (typeof thing !== 'object' || !thing) { | ||
@@ -46,9 +45,9 @@ return false; | ||
if (!('projects' in thing)) { | ||
if (!('profiles' in thing)) { | ||
return false; | ||
} | ||
const { projects } = thing; | ||
const { profiles } = thing; | ||
if (typeof projects !== 'object' || !projects) { | ||
if (typeof profiles !== 'object' || !profiles) { | ||
return false; | ||
@@ -58,4 +57,4 @@ } | ||
if ( | ||
Object.values(projects).some( | ||
(projectConfig) => !isProjectConfig(projectConfig), | ||
Object.values(profiles).some( | ||
(profileConfig) => !isProfileConfig(profileConfig), | ||
) | ||
@@ -62,0 +61,0 @@ ) { |
@@ -40,3 +40,3 @@ import { Flags } from '@oclif/core'; | ||
suggestions: [ | ||
`Configure a local project with "${this.config.bin} config:set"`, | ||
`Configure a local configuration profile with "${this.config.bin} profile:set"`, | ||
], | ||
@@ -43,0 +43,0 @@ }); |
@@ -0,7 +1,9 @@ | ||
import 'dotenv/config'; | ||
export * from './base-command'; | ||
export * from './cma-client-command'; | ||
export * from './dato-config-command'; | ||
export * from './dato-project-config-command'; | ||
export * from './dato-profile-config-command'; | ||
export * from './config'; | ||
export * as CmaClient from '@datocms/cma-client-node'; | ||
export * as oclif from '@oclif/core'; |
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
28877
767
5
4
+ Addeddotenv@^16.0.1
+ Added@datocms/cma-client@1.3.5(transitive)
+ Added@datocms/cma-client-node@1.3.5(transitive)
+ Added@datocms/rest-client-utils@1.3.3(transitive)
+ Added@fastify/busboy@2.1.1(transitive)
+ Added@peculiar/asn1-schema@2.3.15(transitive)
+ Added@peculiar/json-schema@1.1.12(transitive)
+ Added@peculiar/webcrypto@1.5.0(transitive)
+ Added@sindresorhus/is@4.6.0(transitive)
+ Added@whatwg-node/fetch@0.5.4(transitive)
+ Addedabort-controller@3.0.0(transitive)
+ Addedasn1js@3.0.5(transitive)
+ Addedbusboy@1.6.0(transitive)
+ Addedcacheable-lookup@5.0.4(transitive)
+ Addeddecompress-response@6.0.0(transitive)
+ Addeddotenv@16.4.7(transitive)
+ Addedevent-target-shim@5.0.1(transitive)
+ Addedform-data-encoder@1.9.0(transitive)
+ Addedformdata-node@4.4.1(transitive)
+ Addedgot@11.8.6(transitive)
+ Addedhttp2-wrapper@1.0.3(transitive)
+ Addedmimic-response@3.1.0(transitive)
+ Addednode-domexception@1.0.0(transitive)
+ Addedpvtsutils@1.3.6(transitive)
+ Addedpvutils@1.1.3(transitive)
+ Addedquick-lru@5.1.1(transitive)
+ Addedresolve-alpn@1.2.1(transitive)
+ Addedstreamsearch@1.1.0(transitive)
+ Addedundici@5.28.5(transitive)
+ Addedweb-streams-polyfill@3.3.34.0.0-beta.3(transitive)
+ Addedwebcrypto-core@1.8.1(transitive)
- Removed@datocms/cma-client@0.1.8(transitive)
- Removed@datocms/cma-client-node@0.1.8(transitive)
- Removed@datocms/rest-client-utils@0.1.8(transitive)
- Removed@sindresorhus/is@2.1.1(transitive)
- Removedcacheable-lookup@2.0.1(transitive)
- Removedcall-bind-apply-helpers@1.0.1(transitive)
- Removedcall-bound@1.0.3(transitive)
- Removedcross-fetch@3.2.0(transitive)
- Removeddecompress-response@5.0.0(transitive)
- Removeddunder-proto@1.0.1(transitive)
- Removedduplexer3@0.1.5(transitive)
- Removedes-define-property@1.0.1(transitive)
- Removedes-errors@1.3.0(transitive)
- Removedes-object-atoms@1.1.1(transitive)
- Removedfunction-bind@1.1.2(transitive)
- Removedget-intrinsic@1.2.7(transitive)
- Removedget-proto@1.0.1(transitive)
- Removedgopd@1.2.0(transitive)
- Removedgot@10.7.0(transitive)
- Removedhas-symbols@1.1.0(transitive)
- Removedhasown@2.0.2(transitive)
- Removedmath-intrinsics@1.1.0(transitive)
- Removedmimic-response@2.1.0(transitive)
- Removedobject-inspect@1.13.4(transitive)
- Removedp-event@4.2.0(transitive)
- Removedp-finally@1.0.0(transitive)
- Removedp-timeout@3.2.0(transitive)
- Removedqs@6.14.0(transitive)
- Removedside-channel@1.1.0(transitive)
- Removedside-channel-list@1.0.0(transitive)
- Removedside-channel-map@1.0.1(transitive)
- Removedside-channel-weakmap@1.0.2(transitive)
- Removedto-readable-stream@2.1.0(transitive)
- Removedtype-fest@0.10.0(transitive)
Updated@datocms/cma-client-node@^1