@stacksjs/defaults 0.75.629 → 0.75.632

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -7,7 +7,7 @@ interface EnvironmentFileIssue {
7
7
  }
8
8
 
9
9
  interface EnvironmentFileState {
10
- path: '.env'
10
+ path: string
11
11
  content: string
12
12
  revision: string
13
13
  exists: boolean
@@ -19,11 +19,27 @@ interface EnvironmentFileState {
19
19
  }
20
20
  }
21
21
 
22
+ interface KeyReadElsewhere {
23
+ key: string
24
+ file: string
25
+ readable: boolean
26
+ }
27
+
22
28
  interface EnvironmentResponse {
23
29
  environment: EnvironmentFileState
30
+ files: string[]
31
+ readElsewhere: KeyReadElsewhere[]
24
32
  }
25
33
 
26
34
  const envValues = state('')
35
+ // The env file open in the editor, and every env file the app loads
36
+ // (stacksjs/stacks#3341). A key a later file sets again is read from there.
37
+ const file = state('.env')
38
+ const files = state<string[]>(['.env'])
39
+ const readElsewhere = state<KeyReadElsewhere[]>([])
40
+ const readElsewhereLabel = derived(() => readElsewhere()
41
+ .map(entry => entry.readable ? `${entry.key} (${entry.file})` : `${entry.key} (${entry.file}, encrypted, not readable here)`)
42
+ .join(', '))
27
43
  const revision = state('')
28
44
  const backupContent = state('')
29
45
  const backupUpdatedAt = state<string | null>(null)
@@ -58,7 +74,11 @@ const variableCount = derived(() => envValues().split('\n').filter((line) => {
58
74
  }).length)
59
75
  const dirty = derived(() => Boolean(revision()) && envValues() !== loadedContent())
60
76
 
61
- function applyEnvironment(environment: EnvironmentFileState): void {
77
+ function applyEnvironment(result: EnvironmentResponse): void {
78
+ const { environment } = result
79
+ file.set(environment.path)
80
+ files.set(result.files)
81
+ readElsewhere.set(result.readElsewhere)
62
82
  envValues.set(environment.content)
63
83
  loadedContent.set(environment.content)
64
84
  revision.set(environment.revision)
@@ -74,8 +94,8 @@ async function loadEnvironment(): Promise<void> {
74
94
  isLoading.set(true)
75
95
  loadError.set('')
76
96
  try {
77
- const result = await dashboardApi<EnvironmentResponse>('/api/dashboard/environment')
78
- applyEnvironment(result.environment)
97
+ const result = await dashboardApi<EnvironmentResponse>(`/api/dashboard/environment?file=${encodeURIComponent(file())}`)
98
+ applyEnvironment(result)
79
99
  }
80
100
  catch (error) {
81
101
  loadError.set(describeError(error, 'The environment file could not be loaded.'))
@@ -85,6 +105,17 @@ async function loadEnvironment(): Promise<void> {
85
105
  }
86
106
  }
87
107
 
108
+ /** Open another env file. Unsaved edits keep the current one open until they are saved. */
109
+ function openFile(name: string): void {
110
+ if (isBusy() || dirty() || name === file())
111
+ return
112
+ successMessage.set('')
113
+ saveError.set('')
114
+ validationIssues.set([])
115
+ file.set(name)
116
+ void loadEnvironment()
117
+ }
118
+
88
119
  function openAddModal(): void {
89
120
  newVarKey.set('')
90
121
  newVarValue.set('')
@@ -155,11 +186,12 @@ async function handleSave(): Promise<void> {
155
186
  const result = await dashboardApi<EnvironmentResponse & { success: true }>('/api/dashboard/environment', {
156
187
  method: 'PUT',
157
188
  body: {
189
+ file: file(),
158
190
  content: envValues(),
159
191
  revision: revision(),
160
192
  },
161
193
  })
162
- applyEnvironment(result.environment)
194
+ applyEnvironment(result)
163
195
  successMessage.set('Environment file saved. Restart long-running processes to load changed values.')
164
196
  }
165
197
  catch (error) {
@@ -198,7 +230,7 @@ onMount(() => void loadEnvironment())
198
230
  <div class="flex flex-col gap-6 mx-auto pb-12 pt-6 px-4 sm:px-6 lg:px-8 max-w-7xl">
199
231
  <PageHeader
200
232
  title="Environment Variables"
201
- description="Edit the project .env file with validation, conflict protection, and an automatic backup."
233
+ description="Edit the env files the app loads, with validation, conflict protection, and an automatic backup."
202
234
  >
203
235
  <template #actions>
204
236
  <div class="flex gap-2 items-center">
@@ -217,7 +249,7 @@ onMount(() => void loadEnvironment())
217
249
  <div class="grid gap-3 sm:grid-cols-3">
218
250
  <div class="p-4 bg-white dark:bg-neutral-900 border border-stone-200 rounded-xl dark:border-neutral-700">
219
251
  <p class="font-medium text-stone-500 text-xs tracking-wide uppercase dark:text-neutral-400">File</p>
220
- <p class="mt-1 font-mono text-sm text-stone-900 dark:text-white">.env</p>
252
+ <p class="mt-1 font-mono text-sm text-stone-900 dark:text-white" :text="file()"></p>
221
253
  </div>
222
254
  <div class="p-4 bg-white dark:bg-neutral-900 border border-stone-200 rounded-xl dark:border-neutral-700">
223
255
  <p class="font-medium text-stone-500 text-xs tracking-wide uppercase dark:text-neutral-400">Variables</p>
@@ -229,6 +261,26 @@ onMount(() => void loadEnvironment())
229
261
  </div>
230
262
  </div>
231
263
 
264
+ <div :if="files().length > 1" class="flex flex-wrap gap-2 items-center" role="group" aria-label="Env file">
265
+ <button
266
+ :for="name in files"
267
+ type="button"
268
+ class="px-3 py-1.5 font-mono text-sm border rounded-lg disabled:opacity-60 transition-colors"
269
+ :class="name === file() ? 'text-white bg-stone-900 border-stone-900 dark:text-neutral-900 dark:bg-white dark:border-white' : 'text-stone-700 bg-white border-stone-200 hover:bg-stone-50 dark:text-neutral-200 dark:bg-neutral-900 dark:border-neutral-700 dark:hover:bg-neutral-800'"
270
+ :aria-pressed="String(name === file())"
271
+ :disabled="isBusy() || (dirty() && name !== file())"
272
+ @click="openFile(name)"
273
+ :text="name"
274
+ ></button>
275
+ <span :if="dirty()" class="text-stone-500 text-xs dark:text-neutral-400">Save your edits before opening another file.</span>
276
+ </div>
277
+
278
+ <div :if="readElsewhere().length" class="p-4 text-amber-800 text-sm dark:text-amber-200 bg-amber-50 dark:bg-amber-950/30 border border-amber-200 rounded-xl dark:border-amber-900" role="note" data-env-read-elsewhere>
279
+ <p class="font-medium">Some keys here are set again in a file the app loads later.</p>
280
+ <p class="mt-1">Wherever the app can read that later value, it uses it instead of this file's, so change them there:</p>
281
+ <p class="mt-1 font-mono text-xs" :text="readElsewhereLabel()"></p>
282
+ </div>
283
+
232
284
  <div :if="loadError()" class="p-4 text-red-700 text-sm dark:text-red-300 bg-red-50 dark:bg-red-950/30 border border-red-200 rounded-xl dark:border-red-900" role="alert">
233
285
  <p :text="loadError()"></p>
234
286
  <Button class="mt-3" size="sm" variant="secondary" @click="loadEnvironment">Try again</Button>
@@ -246,7 +298,7 @@ onMount(() => void loadEnvironment())
246
298
  <div :if="!loadError()">
247
299
  <CodeEditor
248
300
  v-model:value="envValues"
249
- label=".env"
301
+ :label="file()"
250
302
  language="env"
251
303
  :loading="isLoading()"
252
304
  @save="handleSave"
@@ -5,6 +5,8 @@ type MailDriver = 'log' | 'smtp' | 'ses' | 'sendgrid' | 'mailgun' | 'mailtrap' |
5
5
 
6
6
  interface MailSettings {
7
7
  revision: string
8
+ sources: string[]
9
+ overridden: Array<{ key: string, file: string }>
8
10
  driver: MailDriver
9
11
  fromName: string
10
12
  fromAddress: string
@@ -55,6 +57,8 @@ const encryptionOptions = [
55
57
  ]
56
58
 
57
59
  const revision = state('')
60
+ const sources = state<string[]>(['.env'])
61
+ const overridden = state<Array<{ key: string, file: string }>>([])
58
62
  const driver = state<MailDriver>('log')
59
63
  const fromName = state('')
60
64
  const fromAddress = state('')
@@ -178,6 +182,8 @@ function resetSecrets(): void {
178
182
 
179
183
  function applySettings(settings: MailSettings): void {
180
184
  revision.set(settings.revision)
185
+ sources.set(settings.sources)
186
+ overridden.set(settings.overridden)
181
187
  driver.set(settings.driver)
182
188
  fromName.set(settings.fromName)
183
189
  fromAddress.set(settings.fromAddress)
@@ -310,7 +316,7 @@ onMount(() => void loadSettings())
310
316
  </div>
311
317
  <div class="p-4 bg-white dark:bg-neutral-900 border border-stone-200 rounded-xl dark:border-neutral-700">
312
318
  <p class="font-medium text-stone-500 text-xs tracking-wide uppercase dark:text-neutral-400">Source</p>
313
- <p class="mt-1 font-mono text-sm text-stone-900 dark:text-white">.env</p>
319
+ <p class="mt-1 font-mono text-sm text-stone-900 dark:text-white" :text="sources().join(', ')"></p>
314
320
  </div>
315
321
  <div class="p-4 bg-white dark:bg-neutral-900 border border-stone-200 rounded-xl dark:border-neutral-700">
316
322
  <p class="font-medium text-stone-500 text-xs tracking-wide uppercase dark:text-neutral-400">Configuration</p>
@@ -323,6 +329,12 @@ onMount(() => void loadSettings())
323
329
  <Button :if="isLoading() === false && !revision()" class="mt-3" size="sm" variant="secondary" @click="loadSettings">Try again</Button>
324
330
  </div>
325
331
 
332
+ <div :if="overridden().length" class="p-4 text-amber-800 text-sm dark:text-amber-200 bg-amber-50 dark:bg-amber-950/30 border border-amber-200 rounded-xl dark:border-amber-900" role="note" data-mail-overridden>
333
+ <p class="font-medium">Some values are also set, encrypted, in a file this server cannot decrypt.</p>
334
+ <p class="mt-1">This server uses the values shown here. Where that file's private key is present, its values apply instead, whatever is saved here:</p>
335
+ <p class="mt-1 font-mono text-xs" :text="overridden().map(entry => entry.key + ' in ' + entry.file).join(', ')"></p>
336
+ </div>
337
+
326
338
  <div :if="successMessage()" class="p-4 text-emerald-700 text-sm dark:text-emerald-300 bg-emerald-50 dark:bg-emerald-950/30 border border-emerald-200 rounded-xl dark:border-emerald-900" role="status" :text="successMessage()"></div>
327
339
 
328
340
  <form :if="revision()" class="space-y-6" @submit.prevent="saveSettings">
@@ -501,7 +513,7 @@ onMount(() => void loadSettings())
501
513
  </section>
502
514
 
503
515
  <div class="flex flex-col gap-3 items-start justify-between sm:flex-row sm:items-center">
504
- <p class="text-stone-500 text-xs dark:text-neutral-400">Saving creates a machine-local backup of the previous .env content.</p>
516
+ <p class="text-stone-500 text-xs dark:text-neutral-400">Saving writes each value to the file it comes from, and keeps a machine-local backup of the previous .env content.</p>
505
517
  <Button type="submit" :loading="isSaving()" :disabled="isBusy() || !isDirty()">Save mail settings</Button>
506
518
  </div>
507
519
  </form>