@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.
@@ -0,0 +1,71 @@
1
+ import { afterEach, describe, expect, test } from 'bun:test'
2
+ import { existsSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs'
3
+ import { tmpdir } from 'node:os'
4
+ import { join } from 'node:path'
5
+ import { encryptValue, generateKeypair } from '@stacksjs/env'
6
+ import { readEnvironmentPage, saveEnvironmentPage } from './environment-page'
7
+
8
+ /**
9
+ * The Environment page opens any env file the app loads, says which of its
10
+ * keys the app reads from a later file, and keeps a backup per file
11
+ * (stacksjs/stacks#3341).
12
+ */
13
+ const directories: string[] = []
14
+
15
+ /** A project in a temp folder, read as `staging`; every backup goes in its own `runtime/`, never the checkout's. */
16
+ function project(files: Record<string, string>) {
17
+ const cwd = mkdtempSync(join(tmpdir(), 'stacks-env-page-'))
18
+ directories.push(cwd)
19
+ for (const [name, content] of Object.entries(files))
20
+ writeFileSync(join(cwd, name), content)
21
+ return { cwd, env: 'staging', privateKey: null, backupPathFor: (file: string) => join(cwd, 'runtime', `${file}.backup`) }
22
+ }
23
+
24
+ afterEach(() => {
25
+ for (const directory of directories.splice(0))
26
+ rmSync(directory, { recursive: true, force: true })
27
+ })
28
+
29
+ describe('the Environment page', () => {
30
+ test('opens .env by default, and lists every env file the app loads', async () => {
31
+ const options = project({ '.env': 'APP_NAME=Base\n', '.env.staging': 'APP_NAME=Staging\n', '.env.production': 'APP_NAME=Production\n' })
32
+ const page = await readEnvironmentPage(undefined, options)
33
+ expect(page?.environment).toMatchObject({ path: '.env', content: 'APP_NAME=Base\n' })
34
+ // `.env.production` is not loaded as staging, so it is not offered.
35
+ expect(page?.files).toEqual(['.env', '.env.staging'])
36
+ })
37
+
38
+ test('names the keys a later file sets again', async () => {
39
+ const { publicKey } = generateKeypair()
40
+ const options = project({
41
+ '.env': 'APP_NAME=Base\nAPP_URL=base.test\nAPP_KEY=base-key\n',
42
+ '.env.local': `APP_URL=local.test\nAPP_KEY="${encryptValue('local-key', publicKey)}"\n`,
43
+ })
44
+ expect((await readEnvironmentPage('.env', options))?.readElsewhere).toEqual([
45
+ { key: 'APP_URL', file: '.env.local', readable: true },
46
+ { key: 'APP_KEY', file: '.env.local', readable: false },
47
+ ])
48
+ expect((await readEnvironmentPage('.env.local', options))?.readElsewhere).toEqual([])
49
+ })
50
+
51
+ test('opens only an env file the app loads', async () => {
52
+ const options = project({ '.env': 'APP_NAME=Base\n', '.env.production': 'APP_NAME=Production\n' })
53
+ for (const requested of ['.env.production', '../.env', '/etc/passwd', 'config/app.ts', 42])
54
+ expect(await readEnvironmentPage(requested, options)).toBeNull()
55
+ expect(await saveEnvironmentPage('.env.production', 'APP_NAME=Changed\n', '0'.repeat(64), options)).toEqual({ unknownFile: true })
56
+ expect(readFileSync(join(options.cwd, '.env.production'), 'utf8')).toBe('APP_NAME=Production\n')
57
+ })
58
+
59
+ test('saves the file it opened, and keeps that file\'s own backup', async () => {
60
+ const options = project({ '.env': 'APP_NAME=Base\n', '.env.staging': 'APP_NAME=Staging\n' })
61
+ const page = await readEnvironmentPage('.env.staging', options)
62
+
63
+ const saved = await saveEnvironmentPage('.env.staging', 'APP_NAME=Saved\n', page!.environment.revision, options)
64
+ expect(saved.page?.environment).toMatchObject({ path: '.env.staging', content: 'APP_NAME=Saved\n' })
65
+ expect(saved.page?.environment.backup.content).toBe('APP_NAME=Staging\n')
66
+ expect(readFileSync(join(options.cwd, '.env.staging'), 'utf8')).toBe('APP_NAME=Saved\n')
67
+ expect(readFileSync(join(options.cwd, 'runtime/.env.staging.backup'), 'utf8')).toBe('APP_NAME=Staging\n')
68
+ expect(readFileSync(join(options.cwd, '.env'), 'utf8')).toBe('APP_NAME=Base\n')
69
+ expect(existsSync(join(options.cwd, 'runtime/.env.backup'))).toBe(false)
70
+ })
71
+ })
@@ -0,0 +1,69 @@
1
+ import { join } from 'node:path'
2
+ import { projectPath } from '@stacksjs/path'
3
+ import { environmentBackupPath, readEnvironmentFile, updateEnvironmentFile } from './environment-file'
4
+ import type { EnvironmentFileIssue, EnvironmentFileState } from './environment-file'
5
+ import { editableEnvironmentFiles, keysReadElsewhere, readEnvironmentLayers } from './environment-layers'
6
+ import type { EnvironmentLayersOptions, KeyReadElsewhere } from './environment-layers'
7
+
8
+ /**
9
+ * What the Environment page shows: one env file, every env file the app
10
+ * loads, and the keys in this one whose value the app takes from a later
11
+ * file (stacksjs/stacks#3341).
12
+ *
13
+ * The page edited `.env` alone. A key set again in `.env.<env>` kept that
14
+ * file's value, so an edit to it in `.env` was saved and changed nothing the
15
+ * app read, and the file that did set it could not be opened.
16
+ */
17
+ export interface EnvironmentPage {
18
+ environment: EnvironmentFileState
19
+ /** The files the page can open, in the order the app loads them. */
20
+ files: string[]
21
+ readElsewhere: KeyReadElsewhere[]
22
+ }
23
+
24
+ /** The file a request names, if it is one of the env files the app loads; `.env` when it names none. */
25
+ function editableFile(requested: unknown, files: string[]): string | null {
26
+ const file = requested === undefined || requested === null || requested === '' ? '.env' : requested
27
+ return typeof file === 'string' && files.includes(file) ? file : null
28
+ }
29
+
30
+ function fileOptions(file: string, options: EnvironmentLayersOptions) {
31
+ return {
32
+ name: file,
33
+ envPath: join(options.cwd ?? projectPath(), file),
34
+ backupPath: (options.backupPathFor ?? environmentBackupPath)(file),
35
+ }
36
+ }
37
+
38
+ /** The page for one env file, or null when the request names a file the app does not load. */
39
+ export async function readEnvironmentPage(requested: unknown, options: EnvironmentLayersOptions = {}): Promise<EnvironmentPage | null> {
40
+ const layers = await readEnvironmentLayers(options)
41
+ const files = editableEnvironmentFiles(layers)
42
+ const file = editableFile(requested, files)
43
+ if (!file)
44
+ return null
45
+
46
+ return {
47
+ environment: await readEnvironmentFile(fileOptions(file, options)),
48
+ files,
49
+ readElsewhere: keysReadElsewhere(layers, file),
50
+ }
51
+ }
52
+
53
+ /** Replace one env file's content, as `updateEnvironmentFile` does, and return its page. */
54
+ export async function saveEnvironmentPage(
55
+ requested: unknown,
56
+ content: string,
57
+ revision: string,
58
+ options: EnvironmentLayersOptions = {},
59
+ ): Promise<{ page?: EnvironmentPage, issues?: EnvironmentFileIssue[], conflict?: boolean, unknownFile?: true }> {
60
+ const file = editableFile(requested, editableEnvironmentFiles(await readEnvironmentLayers(options)))
61
+ if (!file)
62
+ return { unknownFile: true }
63
+
64
+ const result = await updateEnvironmentFile(content, revision, fileOptions(file, options))
65
+ if (result.issues || result.conflict)
66
+ return result
67
+
68
+ return { page: (await readEnvironmentPage(file, options))! }
69
+ }
@@ -4,13 +4,22 @@ import { join } from 'node:path'
4
4
  import { describe, expect, test } from 'bun:test'
5
5
  import { readMailSettings, updateMailSettings } from './mail-settings'
6
6
 
7
- async function fixture(content: string): Promise<{ envPath: string, backupPath: string }> {
8
- const root = await mkdtemp(join(tmpdir(), 'stacks-dashboard-mail-'))
7
+ interface Fixture { cwd: string, env: string, privateKey: null, backupPathFor: (file: string) => string, envPath: string }
8
+
9
+ /** A project with `.env` and, optionally, more env files, read as the `staging` environment with no private key. */
10
+ async function fixture(content: string, more: Record<string, string> = {}): Promise<Fixture> {
11
+ const cwd = await mkdtemp(join(tmpdir(), 'stacks-dashboard-mail-'))
9
12
  const options = {
10
- envPath: join(root, '.env'),
11
- backupPath: join(root, 'runtime', 'environment.backup'),
13
+ cwd,
14
+ env: 'staging',
15
+ privateKey: null,
16
+ // Every backup in the fixture's own folder, never the checkout's.
17
+ backupPathFor: (file: string) => join(cwd, 'runtime', `${file}.backup`),
18
+ envPath: join(cwd, '.env'),
12
19
  }
13
20
  await writeFile(options.envPath, content)
21
+ for (const [file, text] of Object.entries(more))
22
+ await writeFile(join(cwd, file), text)
14
23
  return options
15
24
  }
16
25
 
@@ -77,7 +86,7 @@ describe('dashboard mail settings', () => {
77
86
  expect(content).toContain('MAIL_PASSWORD=keep-this')
78
87
  expect(content).toContain('APP_KEY=untouched')
79
88
  expect(content).toContain('MAIL_HOST=smtp.example.com')
80
- expect(await readFile(options.backupPath, 'utf8')).toContain('MAIL_MAILER=log')
89
+ expect(await readFile(options.backupPathFor('.env'), 'utf8')).toContain('MAIL_MAILER=log')
81
90
  })
82
91
 
83
92
  test('requires provider credentials without returning stored secrets', async () => {
@@ -150,6 +159,38 @@ describe('dashboard mail settings', () => {
150
159
  await expect(readMailSettings(invalidEncryption)).rejects.toThrow('MAIL_ENCRYPTION must be empty, tls, or ssl')
151
160
 
152
161
  const malformedEnvironment = await fixture('MAIL_MAILER=log\nMAIL_MAILER=smtp\n')
153
- await expect(readMailSettings(malformedEnvironment)).rejects.toThrow('environment file is invalid on line 2')
162
+ await expect(readMailSettings(malformedEnvironment)).rejects.toThrow('environment file is invalid on line 2 of .env')
163
+ })
164
+
165
+ test('reads a value from the env file the app reads it from, and saves it there (stacksjs/stacks#3340)', async () => {
166
+ const options = await fixture('MAIL_MAILER=log\nMAIL_FROM_ADDRESS=hello@example.com\nMAIL_HOST=base.example.com\n', {
167
+ '.env.staging': 'MAIL_MAILER=smtp\nMAIL_HOST=staging.example.com\n',
168
+ })
169
+ const current = await readMailSettings(options)
170
+ expect(current).toMatchObject({ driver: 'smtp', sources: ['.env', '.env.staging'], overridden: [] })
171
+ expect(current.smtp.host).toBe('staging.example.com')
172
+
173
+ const result = await updateMailSettings({
174
+ revision: current.revision,
175
+ driver: 'smtp',
176
+ fromName: 'Stacks',
177
+ fromAddress: 'hello@example.com',
178
+ smtp: { host: 'saved.example.com', port: '587', username: '', encryption: '', password: '' },
179
+ }, options)
180
+ expect('state' in result && result.state.smtp.host).toBe('saved.example.com')
181
+ const staging = await readFile(join(options.cwd, '.env.staging'), 'utf8')
182
+ expect(staging).toContain('MAIL_HOST=saved.example.com')
183
+ expect(staging).toContain('MAIL_MAILER=smtp')
184
+ expect(await readFile(options.envPath, 'utf8')).toContain('MAIL_HOST=base.example.com')
185
+ })
186
+
187
+ test('names the mail keys a later file keeps encrypted beyond this server\'s reach', async () => {
188
+ const options = await fixture('MAIL_MAILER=log\nMAIL_FROM_ADDRESS=hello@example.com\n', {
189
+ '.env.staging': 'MAIL_MAILER="encrypted:not-readable-here"\n',
190
+ })
191
+ const current = await readMailSettings(options)
192
+ expect(current.driver).toBe('log')
193
+ expect(current.sources).toEqual(['.env'])
194
+ expect(current.overridden).toEqual([{ key: 'MAIL_MAILER', file: '.env.staging' }])
154
195
  })
155
196
  })
@@ -1,11 +1,5 @@
1
- import { encryptValue } from '@stacksjs/env'
2
- import {
3
- parseEnvironmentEntries,
4
- readEnvironmentFile,
5
- updateEnvironmentEntries,
6
- validateEnvironmentFile,
7
- } from '../Infrastructure/environment-file'
8
- import type { EnvironmentFileOptions } from '../Infrastructure/environment-file'
1
+ import { environmentLayerIssues, readEnvironmentLayers, updateEnvironmentLayers } from '../Infrastructure/environment-layers'
2
+ import type { EnvironmentLayersOptions } from '../Infrastructure/environment-layers'
9
3
 
10
4
  export const MAIL_DRIVERS = [
11
5
  'log',
@@ -21,6 +15,19 @@ export type MailDriver = typeof MAIL_DRIVERS[number]
21
15
 
22
16
  export interface MailSettingsState {
23
17
  revision: string
18
+ /**
19
+ * The env files the shown values come from, in the order the app loads
20
+ * them; `.env` when none sets any. A save writes each value back to the
21
+ * file it came from (stacksjs/stacks#3340).
22
+ */
23
+ sources: string[]
24
+ /**
25
+ * Mail keys a later env file sets with ciphertext this server cannot
26
+ * decrypt. The app skips those entries here, so the values shown are the
27
+ * ones in use; wherever that file's key is present, its values apply
28
+ * instead of what is saved.
29
+ */
30
+ overridden: Array<{ key: string, file: string }>
24
31
  driver: MailDriver
25
32
  fromName: string
26
33
  fromAddress: string
@@ -88,6 +95,49 @@ const SECRET_KEYS = [
88
95
  'MAILTRAP_TOKEN',
89
96
  ] as const
90
97
 
98
+ /** The form field each written key is entered in, so a refusal about it shows there. */
99
+ const KEY_FIELDS: Record<string, string> = {
100
+ MAIL_MAILER: 'driver',
101
+ MAIL_FROM_NAME: 'fromName',
102
+ MAIL_FROM_ADDRESS: 'fromAddress',
103
+ MAIL_HOST: 'smtp.host',
104
+ MAIL_PORT: 'smtp.port',
105
+ MAIL_USERNAME: 'smtp.username',
106
+ MAIL_ENCRYPTION: 'smtp.encryption',
107
+ AWS_SES_REGION: 'ses.region',
108
+ AWS_ACCESS_KEY_ID: 'ses.accessKeyId',
109
+ MAILGUN_DOMAIN: 'mailgun.domain',
110
+ MAILGUN_ENDPOINT: 'mailgun.endpoint',
111
+ MAILTRAP_HOST: 'mailtrap.host',
112
+ MAILTRAP_INBOX_ID: 'mailtrap.inboxId',
113
+ MAIL_PASSWORD: 'smtp.password',
114
+ AWS_SECRET_ACCESS_KEY: 'ses.secretAccessKey',
115
+ SENDGRID_API_KEY: 'sendgrid.apiKey',
116
+ MAILGUN_API_KEY: 'mailgun.apiKey',
117
+ MAILTRAP_TOKEN: 'mailtrap.token',
118
+ }
119
+
120
+ /** Every env key the page reads. */
121
+ const MAIL_KEYS = [
122
+ 'APP_NAME',
123
+ 'MAIL_MAILER',
124
+ 'MAIL_DRIVER',
125
+ 'MAIL_FROM_NAME',
126
+ 'MAIL_FROM_ADDRESS',
127
+ 'MAIL_HOST',
128
+ 'MAIL_PORT',
129
+ 'MAIL_USERNAME',
130
+ 'MAIL_ENCRYPTION',
131
+ 'AWS_SES_REGION',
132
+ 'AWS_DEFAULT_REGION',
133
+ 'AWS_ACCESS_KEY_ID',
134
+ 'MAILGUN_DOMAIN',
135
+ 'MAILGUN_ENDPOINT',
136
+ 'MAILTRAP_HOST',
137
+ 'MAILTRAP_INBOX_ID',
138
+ ...SECRET_KEYS,
139
+ ] as const
140
+
91
141
  function stringValue(value: unknown): string {
92
142
  return typeof value === 'string' ? value.trim() : ''
93
143
  }
@@ -125,18 +175,23 @@ function portValue(value: string | undefined): number {
125
175
  return parsed
126
176
  }
127
177
 
128
- export async function readMailSettings(options: EnvironmentFileOptions = {}): Promise<MailSettingsState> {
129
- const environment = await readEnvironmentFile(options)
130
- const environmentIssues = validateEnvironmentFile(environment.content)
178
+ export async function readMailSettings(options: EnvironmentLayersOptions = {}): Promise<MailSettingsState> {
179
+ const layers = await readEnvironmentLayers(options)
180
+ const environmentIssues = environmentLayerIssues(layers)
131
181
  if (environmentIssues.length) {
132
182
  const issue = environmentIssues[0]!
133
- const location = issue.line > 0 ? ` on line ${issue.line}` : ''
183
+ const location = issue.line > 0 ? ` on line ${issue.line} of ${issue.file}` : ` (${issue.file})`
134
184
  throw new TypeError(`The environment file is invalid${location}: ${issue.message}`)
135
185
  }
136
- const entries = parseEnvironmentEntries(environment.content)
186
+ const { entries } = layers
187
+ const read = MAIL_KEYS.filter(key => layers.sources[key])
188
+ const sources = layers.layers.map(layer => layer.file).filter(file => read.some(key => layers.sources[key] === file))
189
+ const overridden = MAIL_KEYS.flatMap(key => layers.unreadable[key] ? [{ key, file: layers.unreadable[key]! }] : [])
137
190
 
138
191
  return {
139
- revision: environment.revision,
192
+ revision: layers.revision,
193
+ sources: sources.length ? sources : ['.env'],
194
+ overridden,
140
195
  driver: normalizedDriver(entries.MAIL_MAILER ?? entries.MAIL_DRIVER),
141
196
  fromName: entries.MAIL_FROM_NAME ?? entries.APP_NAME ?? 'Stacks',
142
197
  fromAddress: entries.MAIL_FROM_ADDRESS ?? '',
@@ -179,38 +234,16 @@ function validateSecret(value: unknown, field: string, fields: Record<string, st
179
234
  return secret
180
235
  }
181
236
 
182
- function secretUpdate(
183
- entries: Record<string, string>,
184
- key: typeof SECRET_KEYS[number],
185
- value: string,
186
- clear: boolean,
187
- fields: Record<string, string>,
188
- ): string | undefined {
189
- if (value) {
190
- const encryptedFile = Object.values(entries).some(entry =>
191
- entry.startsWith('encrypted:') || entry.startsWith('enc:'),
192
- )
193
- if (!encryptedFile)
194
- return value
195
-
196
- const publicKey = entries.DOTENV_PUBLIC_KEY
197
- if (!publicKey) {
198
- fields[key] = 'The encrypted environment file has no public key. Repair it before changing secrets.'
199
- return undefined
200
- }
201
-
202
- try {
203
- return encryptValue(value, publicKey)
204
- }
205
- catch {
206
- fields[key] = 'The secret could not be encrypted with the environment public key.'
207
- return undefined
208
- }
209
- }
210
-
237
+ /**
238
+ * What to write for a secret: a new value, an empty one to clear it, or
239
+ * nothing to keep the stored one. Encrypting it, where its file is encrypted,
240
+ * is `updateEnvironmentLayers`'s job, under that file's own public key.
241
+ */
242
+ function secretUpdate(value: string, clear: boolean): string | undefined {
243
+ if (value)
244
+ return value
211
245
  if (clear)
212
246
  return ''
213
-
214
247
  return undefined
215
248
  }
216
249
 
@@ -224,7 +257,7 @@ function validHost(value: string): boolean {
224
257
 
225
258
  export async function updateMailSettings(
226
259
  input: MailSettingsInput,
227
- options: EnvironmentFileOptions = {},
260
+ options: EnvironmentLayersOptions = {},
228
261
  ): Promise<MailSettingsUpdateResult> {
229
262
  const fields: Record<string, string> = {}
230
263
  const revision = stringValue(input.revision)
@@ -241,11 +274,11 @@ export async function updateMailSettings(
241
274
  if (!validEmail(fromAddress))
242
275
  fields.fromAddress = 'Enter a valid sender email address.'
243
276
 
244
- const currentEnvironment = await readEnvironmentFile(options)
245
- if (currentEnvironment.revision !== revision)
277
+ const currentLayers = await readEnvironmentLayers(options)
278
+ if (currentLayers.revision !== revision)
246
279
  return { conflict: true }
247
280
 
248
- const currentEntries = parseEnvironmentEntries(currentEnvironment.content)
281
+ const currentEntries = currentLayers.entries
249
282
  const updates: Record<string, string> = {
250
283
  MAIL_MAILER: driver,
251
284
  MAIL_FROM_NAME: fromName,
@@ -258,13 +291,7 @@ export async function updateMailSettings(
258
291
  const username = stringValue(input.smtp?.username)
259
292
  const encryption = stringValue(input.smtp?.encryption)
260
293
  const password = validateSecret(input.smtp?.password, 'smtp.password', fields)
261
- const nextPassword = secretUpdate(
262
- currentEntries,
263
- 'MAIL_PASSWORD',
264
- password,
265
- input.smtp?.clearPassword === true,
266
- fields,
267
- )
294
+ const nextPassword = secretUpdate(password, input.smtp?.clearPassword === true)
268
295
 
269
296
  if (!validHost(host))
270
297
  fields['smtp.host'] = 'Enter a valid SMTP host.'
@@ -284,13 +311,7 @@ export async function updateMailSettings(
284
311
  const region = stringValue(input.ses?.region)
285
312
  const accessKeyId = stringValue(input.ses?.accessKeyId)
286
313
  const secret = validateSecret(input.ses?.secretAccessKey, 'ses.secretAccessKey', fields)
287
- const nextSecret = secretUpdate(
288
- currentEntries,
289
- 'AWS_SECRET_ACCESS_KEY',
290
- secret,
291
- input.ses?.clearSecretAccessKey === true,
292
- fields,
293
- )
314
+ const nextSecret = secretUpdate(secret, input.ses?.clearSecretAccessKey === true)
294
315
 
295
316
  if (!/^[a-z]{2}(?:-gov)?-[a-z]+-\d$/.test(region))
296
317
  fields['ses.region'] = 'Enter a valid AWS region, such as us-east-1.'
@@ -302,13 +323,7 @@ export async function updateMailSettings(
302
323
  }
303
324
  else if (driver === 'sendgrid') {
304
325
  const apiKey = validateSecret(input.sendgrid?.apiKey, 'sendgrid.apiKey', fields)
305
- const nextApiKey = secretUpdate(
306
- currentEntries,
307
- 'SENDGRID_API_KEY',
308
- apiKey,
309
- input.sendgrid?.clearApiKey === true,
310
- fields,
311
- )
326
+ const nextApiKey = secretUpdate(apiKey, input.sendgrid?.clearApiKey === true)
312
327
 
313
328
  if (!apiKey && input.sendgrid?.clearApiKey !== true && !configured(currentEntries.SENDGRID_API_KEY))
314
329
  fields['sendgrid.apiKey'] = 'Enter a SendGrid API key.'
@@ -321,13 +336,7 @@ export async function updateMailSettings(
321
336
  const domain = stringValue(input.mailgun?.domain)
322
337
  const endpoint = stringValue(input.mailgun?.endpoint)
323
338
  const apiKey = validateSecret(input.mailgun?.apiKey, 'mailgun.apiKey', fields)
324
- const nextApiKey = secretUpdate(
325
- currentEntries,
326
- 'MAILGUN_API_KEY',
327
- apiKey,
328
- input.mailgun?.clearApiKey === true,
329
- fields,
330
- )
339
+ const nextApiKey = secretUpdate(apiKey, input.mailgun?.clearApiKey === true)
331
340
 
332
341
  if (!validHost(domain))
333
342
  fields['mailgun.domain'] = 'Enter the verified Mailgun domain.'
@@ -347,13 +356,7 @@ export async function updateMailSettings(
347
356
  const host = stringValue(input.mailtrap?.host)
348
357
  const inboxId = stringValue(input.mailtrap?.inboxId)
349
358
  const token = validateSecret(input.mailtrap?.token, 'mailtrap.token', fields)
350
- const nextToken = secretUpdate(
351
- currentEntries,
352
- 'MAILTRAP_TOKEN',
353
- token,
354
- input.mailtrap?.clearToken === true,
355
- fields,
356
- )
359
+ const nextToken = secretUpdate(token, input.mailtrap?.clearToken === true)
357
360
 
358
361
  // Both optional, as in the driver: an inbox id captures mail in that
359
362
  // sandbox inbox, no inbox id delivers it through the Sending API, and a
@@ -386,14 +389,16 @@ export async function updateMailSettings(
386
389
  if (Object.keys(fields).length)
387
390
  return { validation: { fields } }
388
391
 
389
- const result = await updateEnvironmentEntries(updates, revision, options)
392
+ // Each value goes back to the env file the app reads it from, encrypted
393
+ // where that file keeps it encrypted (stacksjs/stacks#3340).
394
+ const result = await updateEnvironmentLayers(updates, revision, { ...options, secrets: SECRET_KEYS })
390
395
  if (result.conflict)
391
396
  return { conflict: true }
392
397
  if (result.issues?.length) {
393
398
  return {
394
399
  validation: {
395
- fields: Object.fromEntries(result.issues.map((issue, index) => [
396
- issue.line ? String(issue.line) : `file-${index}`,
400
+ fields: Object.fromEntries(result.issues.map(issue => [
401
+ KEY_FIELDS[issue.key] ?? issue.key,
397
402
  issue.message,
398
403
  ])),
399
404
  },
@@ -2,7 +2,7 @@
2
2
  "publisher": "Stacks",
3
3
  "name": "vscode-stacks",
4
4
  "displayName": "Stacks",
5
- "version": "0.75.629",
5
+ "version": "0.75.632",
6
6
  "description": "Stacks, built into VS Code: stx templates, pickier linting and formatting, encrypted env files, the dev server preview and every buddy command. No other extensions required.",
7
7
  "license": "MIT",
8
8
  "funding": "https://github.com/sponsors/chrisbbreuer",
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@stacksjs/defaults",
3
3
  "type": "module",
4
4
  "sideEffects": false,
5
- "version": "0.75.629",
5
+ "version": "0.75.632",
6
6
  "repository": {
7
7
  "type": "git",
8
8
  "url": "git+https://github.com/stacksjs/stacks.git",
@@ -45,14 +45,14 @@
45
45
  "dependencies": {
46
46
  "@iconify-json/f7": "^1.2.2",
47
47
  "@iconify-json/hugeicons": "^1.2.35",
48
- "@stacksjs/mobile": "0.75.629",
48
+ "@stacksjs/mobile": "0.75.632",
49
49
  "@stacksjs/sanitizer": "^0.2.908",
50
50
  "@stacksjs/stx": "^0.2.908",
51
- "@stacksjs/strings": "0.75.629",
51
+ "@stacksjs/strings": "0.75.632",
52
52
  "@xterm/addon-fit": "^0.11.0",
53
53
  "@xterm/xterm": "^6.0.0",
54
54
  "ts-qr-codes": "^0.1.8",
55
- "@stacksjs/support": "0.75.629",
56
- "@stacksjs/browser": "0.75.629"
55
+ "@stacksjs/support": "0.75.632",
56
+ "@stacksjs/browser": "0.75.632"
57
57
  }
58
58
  }