Open rechenberger opened 2 years ago
Here is a revised idea for the config and extension files:
// --- EnvConfig: gitenvs.config.json --- //
export type PointerOrValue =
| {
type: 'pointer'
fileId: string
stage: string
key: string
}
| {
type: 'value'
value: string
encrypted: boolean
}
export type EnvVar = {
// BASICS:
fileId: string
stage: string
key: string
// Just for DTO. All pointers resolved, funcs have been run & values are decrypted
_value?: string
} & (
| {
type: 'func'
func: {
name: string
params?: Record<string, PointerOrValue | PointerOrValue[]>
}
}
| {
type: 'content'
content: PointerOrValue
}
)
export type EnvFile = {
fileId: string
name: string
path: string
type:
| 'dotenv'
| 'typescript'
// Can be used as a collection of variables. These variables can be reused in real files
// `path` will be ignored.` TODO: Maybe we need better naming
| 'variables'
// Can be extended by extension file -> fileWriters
| string
}
export type EnvStage = {
name: string
publicKey: string
encryptedPrivateKey: string
}
export type EnvConfig = {
version: 1
envVars: EnvVar[]
files: EnvFile[]
stages: EnvStage[]
// extensionsPath: string
}
// --- Extension File: gitenvs.extensions.js --- //
export type FuncContext<Params = Record<string, string | string[]>> = {
params: Params
currentEnvVar: EnvVar
}
export type Func<Input> = (options: {
input: Input
context: FuncContext
}) => Promise<string>
export type EnvFileWriter = (options: { TODO: any }) => Promise<string>
export type ExtensionFile = {
funcs: {
[funcName: string]: Func<any>
}
writers: {
[writerName: string]: EnvFileWriter
}
}
Some infos why the functions are designed how they are:
func
you can't have a pointer
or a value
. But you get params
that can contain multiple pointer
or a value
getIPAddr
: Return the current IP address. Does not depend on params
getJWTSecretForHasura
: Hasura needs the secret in a JSON with additional info. params
would be:
{
"jwtSecret": [{"type": "pointer", "fileId"...}],
}
joinEnvVars
: Gets a list of env files and joins them with a user defined symbol. Useful for something like: API_KEYS=[multiple_api_keys_comma_separated_that_are_used_in_other_env_vars_too]
. params
would be:
{
"envVarsToJoin": [{"type": "pointer", "fileId"...}],
"separator": { "type": "value", "value": ",", "encrypted": false }
}
Nice thing about params for functions is that
GitEnv 2.0
UI
.gitenv.config.json
JS
gitenv.config.js
?Tech Stack
https://github.com/t3-oss/create-t3-app