-
Notifications
You must be signed in to change notification settings - Fork 361
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: updates to typescript w/n the env command #6905
base: main
Are you sure you want to change the base?
Changes from 14 commits
e7447a2
76fab2b
8a30660
113cf8b
0a5a07e
a7a8f40
8267aa5
54f664f
0a23af1
2fecfa3
796367f
c4c60fd
c06b36e
f0fecd4
80e88e6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,224 @@ | ||
import type { NetlifyAPI } from 'netlify' | ||
|
||
import { Context } from './types.d.ts' | ||
|
||
type ApiContext = Context | 'branch' | ||
|
||
// Define the structure for the 'updated_by' field | ||
interface UpdatedBy { | ||
// Add specific properties here if known | ||
// For now, we'll keep it generic | ||
id: string; | ||
full_name: string; | ||
email: string; | ||
avatar_url: string; | ||
} | ||
|
||
export type Value = Pick<EnvVarValue, 'value' | 'context' | 'context_parameter'> | ||
// Define the structure for each item in the array | ||
|
||
interface EnvVarValue { | ||
value: string, | ||
context: ApiContext, | ||
context_parameter?: string, | ||
id?: string, | ||
} | ||
|
||
export interface EnvVar { | ||
key: string; | ||
scopes: Scope[]; | ||
values: EnvVarValue[]; | ||
is_secret?: boolean; | ||
updated_at?: string; | ||
updated_by?: UpdatedBy; | ||
} | ||
|
||
interface GetEnvParams { | ||
accountId: string, | ||
siteId?: string, | ||
context?: Context, | ||
scope?: EnvironmentVariableScope | ||
} | ||
|
||
interface DeleteEnvVarValueParams { | ||
accountId: string, | ||
key: string, | ||
id?: string, | ||
siteId?: string | ||
} | ||
|
||
interface SetEnvVarValueBody { | ||
context: string, | ||
value: string, | ||
contextParameter?: string, | ||
} | ||
|
||
interface SetEnvVarValueParams { | ||
accountId: string, | ||
key: string, | ||
siteId?: string, | ||
body: SetEnvVarValueBody | ||
} | ||
|
||
interface UpdateEnvVarBody { | ||
key: string, | ||
scopes: string[], | ||
values: EnvVar[] | ||
is_secret: boolean | ||
} | ||
|
||
interface UpdateEnvVarParams { | ||
accountId: string, | ||
key: string, | ||
siteId?: string | ||
body: EnvVar | ||
} | ||
|
||
interface createEnvVarParams { | ||
accountId: string, | ||
key?: string, | ||
siteId?: string, | ||
body: EnvVar[] | ||
} | ||
|
||
// Top-Level Interface | ||
interface SiteInfo { | ||
id: string; | ||
state: string; | ||
plan: string; | ||
name: string; | ||
custom_domain: string | null; | ||
domain_aliases: string[]; | ||
branch_deploy_custom_domain: string | null; | ||
deploy_preview_custom_domain: string | null; | ||
password: string | null; | ||
notification_email: string | null; | ||
url: string; | ||
ssl_url: string; | ||
admin_url: string; | ||
screenshot_url: string; | ||
created_at: string; | ||
updated_at: string; | ||
user_id: string; | ||
session_id: string; | ||
ssl: boolean; | ||
force_ssl: boolean | null; | ||
managed_dns: boolean; | ||
deploy_url: string; | ||
published_deploy: PublishedDeploy; | ||
account_id: string; | ||
account_name: string; | ||
account_slug: string; | ||
git_provider?: string; | ||
deploy_hook: string; | ||
capabilities: Capabilities; | ||
processing_settings: ProcessingSettings; | ||
build_settings: BuildSettings; | ||
id_domain: string; | ||
default_hooks_data?: DefaultHooksData; | ||
build_image: string; | ||
prerender: string | null; | ||
functions_region: string; | ||
feature_flags: FeatureFlags; | ||
} | ||
|
||
// Published Deploy Interface | ||
interface PublishedDeploy { | ||
id: string; | ||
site_id: string; | ||
user_id: string; | ||
build_id: string; | ||
state: string; | ||
name: string; | ||
url: string; | ||
ssl_url: string; | ||
admin_url: string; | ||
deploy_url: string; | ||
deploy_ssl_url: string; | ||
screenshot_url: string; | ||
review_id: number | null; | ||
draft: boolean; | ||
required: string[]; | ||
required_functions: string[]; | ||
error_message: string; | ||
branch: string; | ||
commit_ref: string; | ||
commit_url: string; | ||
skipped: boolean | null; | ||
created_at: string; | ||
updated_at: string; | ||
published_at: string; | ||
title: string; | ||
context: string; | ||
locked: boolean | null; | ||
review_url: string | null; | ||
framework: string; | ||
function_schedules: FunctionSchedule[] | []; | ||
} | ||
|
||
// Function Schedule Interface | ||
interface FunctionSchedule { | ||
name: string; | ||
cron: string; | ||
} | ||
|
||
// Capabilities Interface | ||
interface Capabilities { | ||
[key: string]: Record<string, unknown>; | ||
} | ||
|
||
// Processing Settings Interface | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You don't need all these comments, they're all basically just saying the name of the interfaces are |
||
interface ProcessingSettings { | ||
html: HTMLProcessingSettings; | ||
} | ||
|
||
// HTML Processing Settings Interface | ||
interface HTMLProcessingSettings { | ||
pretty_urls: boolean; | ||
} | ||
|
||
// Build Settings Interface | ||
interface BuildSettings { | ||
id: number; | ||
provider: string; | ||
deploy_key_id: string; | ||
repo_path: string; | ||
repo_branch: string; | ||
dir: string; | ||
functions_dir: string; | ||
cmd: string; | ||
allowed_branches: string[]; | ||
public_repo: boolean; | ||
private_logs: boolean; | ||
repo_url: string; | ||
env: EnvVariables; | ||
installation_id: number; | ||
stop_builds: boolean; | ||
} | ||
|
||
// Environment Variables Interface | ||
interface EnvVariables { | ||
[key: string]: string; | ||
} | ||
|
||
// Default Hooks Data Interface | ||
interface DefaultHooksData { | ||
access_token: string; | ||
} | ||
|
||
interface GetSiteParams { | ||
siteId?: string, | ||
feature_flags?: string | ||
site_id?: string | ||
} | ||
|
||
export interface ExtendedNetlifyAPI extends NetlifyAPI { | ||
getEnvVar(params: GetEnvVarParams): Promise<EnvVar> | ||
getEnvVars( params: GetEnvParams): Promise<EnvVar[]> | ||
deleteEnvVarValue( params: DeleteEnvVarValueParams ): Promise<void> | ||
setEnvVarValue( params: SetEnvVarValueParams): Promise<EnvVar> | ||
deleteEnvVar(params: DeleteEnvVarValueParams): Promise<void> | ||
updateEnvVar(params: UpdateEnvVarParams): Promise<EnvVar> | ||
createEnvVars(params: createEnvVarParams): Promise<EnvVar[]> | ||
getSite(params: GetSiteParams): Promise<SiteInfo> | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
import { OptionValues } from 'commander' | ||
|
||
import { chalk, log, logJson } from '../../utils/command-helpers.js' | ||
import { AVAILABLE_CONTEXTS, getEnvelopeEnv } from '../../utils/env/index.js' | ||
import BaseCommand from '../base-command.js' | ||
|
||
export const envGet = async (name: string, options: OptionValues, command: BaseCommand) => { | ||
import { EnvOptions } from './types.js' | ||
|
||
export const envGet = async (name: string, options: EnvOptions, command: BaseCommand) => { | ||
const { context, scope } = options | ||
const { api, cachedConfig, site } = command.netlify | ||
const siteId = site.id | ||
|
@@ -15,6 +15,7 @@ export const envGet = async (name: string, options: OptionValues, command: BaseC | |
} | ||
|
||
const { siteInfo } = cachedConfig | ||
|
||
const env = await getEnvelopeEnv({ api, context, env: cachedConfig.env, key: name, scope, siteInfo }) | ||
|
||
const { value } = env[name] || {} | ||
|
@@ -26,7 +27,7 @@ export const envGet = async (name: string, options: OptionValues, command: BaseC | |
} | ||
|
||
if (!value) { | ||
const contextType = AVAILABLE_CONTEXTS.includes(context) ? 'context' : 'branch' | ||
const contextType = context === undefined ? 'branch' : AVAILABLE_CONTEXTS.includes(context) | ||
const withContext = `in the ${chalk.magenta(context)} ${contextType}` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why was this changed? It now returns a boolean instead of a string |
||
const withScope = scope === 'any' ? '' : ` and the ${chalk.magenta(scope)} scope` | ||
log(`No value set ${withContext}${withScope} for environment variable ${chalk.yellow(name)}`) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This has been updated