@quazardous/qdadm 2.49.0 → 2.50.0

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@quazardous/qdadm",
3
- "version": "2.49.0",
3
+ "version": "2.50.0",
4
4
  "description": "Vue 3 framework for admin dashboards with PrimeVue",
5
5
  "author": "quazardous",
6
6
  "license": "MIT",
@@ -0,0 +1,163 @@
1
+ <script setup lang="ts">
2
+ /**
3
+ * QdRevealOnce - the values a create revealed once (#5319)
4
+ *
5
+ * A key's token, a generated password: the API hands it back once and keeps
6
+ * only its hash. This dialog shows each value with a copy button and a
7
+ * warning, and closes only on "I have copied it". It keeps nothing: the
8
+ * values live in its props, and whoever gives them clears them on `confirm`.
9
+ *
10
+ * FormPage renders it after a create whose entity declares `revealOnce`.
11
+ * A custom page binds it to the form's `revealed` / `confirmRevealed`:
12
+ *
13
+ * <QdRevealOnce :revealed="form.revealed.value" @confirm="form.confirmRevealed" />
14
+ *
15
+ * Labels: `entities.<entity>.reveal.<key>`, else the key.
16
+ */
17
+ import { computed, inject, ref, watch } from 'vue'
18
+ import Dialog from 'primevue/dialog'
19
+ import QdButton from '../base/QdButton.vue'
20
+ import QdMessage from '../base/QdMessage.vue'
21
+ import { useI18n } from '../../i18n/useI18n'
22
+ import { copyText } from '../../utils/clipboard'
23
+ import type { RevealedValues } from '../../composables/useEntityItemFormPage.types'
24
+
25
+ const props = defineProps<{
26
+ revealed: RevealedValues | null
27
+ }>()
28
+
29
+ const emit = defineEmits<{
30
+ confirm: []
31
+ }>()
32
+
33
+ const { t, tOr } = useI18n()
34
+ const orchestrator = inject<{ get: (name: string) => { label?: string } | null } | null>('qdadmOrchestrator', null)
35
+
36
+ const rows = computed(() => {
37
+ const r = props.revealed
38
+ if (!r) return []
39
+ return Object.entries(r.values).map(([key, value]) => ({
40
+ key,
41
+ label: tOr(`entities.${r.entity}.reveal.${key}`, key),
42
+ text: typeof value === 'string' ? value : JSON.stringify(value),
43
+ }))
44
+ })
45
+
46
+ const title = computed(() => {
47
+ const r = props.revealed
48
+ if (!r) return ''
49
+ let label: string = r.entity
50
+ try {
51
+ label = orchestrator?.get(r.entity)?.label || r.entity
52
+ } catch {
53
+ // An entity the orchestrator does not know: its name will do
54
+ }
55
+ return t('core.revealOnce.title', { entity: label })
56
+ })
57
+
58
+ /** Per key: what the last copy said */
59
+ const status = ref<Record<string, { ok: boolean; text: string }>>({})
60
+ watch(
61
+ () => props.revealed,
62
+ () => (status.value = {})
63
+ )
64
+
65
+ async function copy(key: string, text: string): Promise<void> {
66
+ try {
67
+ await copyText(text)
68
+ status.value = { ...status.value, [key]: { ok: true, text: t('core.revealOnce.copied') } }
69
+ } catch (err) {
70
+ status.value = {
71
+ ...status.value,
72
+ [key]: { ok: false, text: t('core.revealOnce.copyFailed', { error: (err as Error)?.message ?? String(err) }) },
73
+ }
74
+ }
75
+ }
76
+
77
+ function confirm(): void {
78
+ status.value = {}
79
+ emit('confirm')
80
+ }
81
+ </script>
82
+
83
+ <template>
84
+ <Dialog
85
+ :visible="!!revealed"
86
+ :header="title"
87
+ modal
88
+ :closable="false"
89
+ :closeOnEscape="false"
90
+ :dismissableMask="false"
91
+ :style="{ width: '560px', maxWidth: '95vw' }"
92
+ class="qd-reveal-once"
93
+ >
94
+ <QdMessage severity="warn" :closable="false" class="qd-reveal-once-warning">
95
+ {{ t('core.revealOnce.warning') }}
96
+ </QdMessage>
97
+ <div v-for="row in rows" :key="row.key" class="qd-reveal-once-row">
98
+ <div class="qd-reveal-once-label">{{ row.label }}</div>
99
+ <div class="qd-reveal-once-value-line">
100
+ <code class="qd-reveal-once-value" :data-key="row.key">{{ row.text }}</code>
101
+ <QdButton
102
+ :label="t('core.revealOnce.copy')"
103
+ icon="pi pi-copy"
104
+ size="small"
105
+ severity="secondary"
106
+ class="qd-reveal-once-copy"
107
+ @click="copy(row.key, row.text)"
108
+ />
109
+ </div>
110
+ <div
111
+ v-if="status[row.key]"
112
+ class="qd-reveal-once-status"
113
+ :class="status[row.key]?.ok ? 'qd-reveal-once-status--ok' : 'qd-reveal-once-status--failed'"
114
+ role="status"
115
+ >
116
+ {{ status[row.key]?.text }}
117
+ </div>
118
+ </div>
119
+ <template #footer>
120
+ <QdButton :label="t('core.revealOnce.confirm')" icon="pi pi-check" class="qd-reveal-once-confirm" @click="confirm" />
121
+ </template>
122
+ </Dialog>
123
+ </template>
124
+
125
+ <style scoped>
126
+ .qd-reveal-once-warning {
127
+ margin: 0 0 1rem;
128
+ }
129
+ .qd-reveal-once-row + .qd-reveal-once-row {
130
+ margin-top: 1rem;
131
+ }
132
+ .qd-reveal-once-label {
133
+ font-weight: 600;
134
+ margin-bottom: 0.35rem;
135
+ }
136
+ .qd-reveal-once-value-line {
137
+ display: flex;
138
+ gap: 0.5rem;
139
+ align-items: center;
140
+ }
141
+ .qd-reveal-once-value {
142
+ flex: 1;
143
+ min-width: 0;
144
+ padding: 0.5rem 0.65rem;
145
+ border: 1px solid var(--p-content-border-color, #d1d5db);
146
+ border-radius: 6px;
147
+ background: var(--p-content-hover-background, #f3f4f6);
148
+ font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
149
+ font-size: 0.875rem;
150
+ word-break: break-all;
151
+ user-select: all;
152
+ }
153
+ .qd-reveal-once-status {
154
+ margin-top: 0.3rem;
155
+ font-size: 0.8125rem;
156
+ }
157
+ .qd-reveal-once-status--ok {
158
+ color: var(--p-green-600, #16a34a);
159
+ }
160
+ .qd-reveal-once-status--failed {
161
+ color: var(--p-red-600, #dc2626);
162
+ }
163
+ </style>
@@ -24,6 +24,7 @@ import InputText from 'primevue/inputtext'
24
24
  import QdButton from '../base/QdButton.vue'
25
25
  import { useI18n } from '../../i18n/useI18n'
26
26
  import { ansiStyleToCss } from '../../utils/ansi'
27
+ import { copyText } from '../../utils/clipboard'
27
28
  import { useLogStream, type LogLine, type LogSource, type UseLogStreamReturn } from '../../composables/useLogStream'
28
29
  import { linesOfPhase } from '../../tasks/taskPhases'
29
30
 
@@ -298,40 +299,13 @@ function download(): void {
298
299
  const copyStatus = ref<{ ok: boolean; text: string } | null>(null)
299
300
  let copyTimer: ReturnType<typeof setTimeout> | null = null
300
301
 
301
- /** Without navigator.clipboard (a page served over plain http): a selected textarea */
302
- function copyByCommand(text: string): void {
303
- const area = document.createElement('textarea')
304
- area.value = text
305
- area.setAttribute('readonly', '')
306
- area.style.position = 'fixed'
307
- area.style.opacity = '0'
308
- document.body.appendChild(area)
309
- const focused = document.activeElement as HTMLElement | null
310
- area.select()
311
- try {
312
- if (!document.execCommand?.('copy')) throw new Error('the browser refused to copy')
313
- } finally {
314
- area.remove()
315
- focused?.focus?.()
316
- }
317
- }
318
-
319
302
  /** Every line received at this moment, as plain text; resolves to the line count. */
320
303
  async function copy(): Promise<number> {
321
304
  // Taken now: lines streaming in during the write are not part of it
322
305
  const lines = log.lines.value.map((l) => l.text)
323
306
  const text = lines.join('\n')
324
307
  try {
325
- try {
326
- if (!navigator.clipboard?.writeText) throw new Error('no clipboard on this page (it needs HTTPS)')
327
- await navigator.clipboard.writeText(text)
328
- } catch (err) {
329
- try {
330
- copyByCommand(text)
331
- } catch {
332
- throw err
333
- }
334
- }
308
+ await copyText(text)
335
309
  copyStatus.value = { ok: true, text: t('core.log.copied', { count: lines.length }) }
336
310
  } catch (err) {
337
311
  copyStatus.value = { ok: false, text: t('core.log.copyFailed', { error: (err as Error)?.message ?? String(err) }) }
@@ -37,11 +37,12 @@ import { GUARD_DIALOG_HOST } from '../../composables/useGuardStore'
37
37
  import PageHeader from '../layout/PageHeader.vue'
38
38
  import FormActions from './FormActions.vue'
39
39
  import UnsavedChangesDialog from '../dialogs/UnsavedChangesDialog.vue'
40
+ import QdRevealOnce from '../dialogs/QdRevealOnce.vue'
40
41
  import CardShell from '../layout/CardShell.vue'
41
42
  import { formatFetchError } from '../../utils/errors'
42
43
  import QdButton from '../base/QdButton.vue'
43
44
  import QdMessage from '../base/QdMessage.vue'
44
- import type { ResolvedAction, ResolvedFieldConfig } from '../../composables/useEntityItemFormPage'
45
+ import type { ResolvedAction, ResolvedFieldConfig, RevealedValues } from '../../composables/useEntityItemFormPage'
45
46
  import type { GuardDialogState } from '../../composables/useUnsavedChangesGuard'
46
47
 
47
48
  /**
@@ -99,6 +100,9 @@ const props = defineProps({
99
100
  // Guard dialog (from useUnsavedChangesGuard)
100
101
  guardDialog: { type: Object as PropType<GuardDialogState | null>, default: null },
101
102
 
103
+ // Values a create revealed once (#5319), shown until confirmed
104
+ revealed: { type: Object as PropType<RevealedValues | null>, default: null },
105
+
102
106
  // Error for fetch failures (separate from validation errors)
103
107
  fetchError: { type: [String, Object] as PropType<string | FetchError | null>, default: null },
104
108
 
@@ -113,6 +117,7 @@ const emit = defineEmits<{
113
117
  (e: 'saveAndClose'): void
114
118
  (e: 'cancel'): void
115
119
  (e: 'delete'): void
120
+ (e: 'revealConfirmed'): void
116
121
  }>()
117
122
 
118
123
  // Header actions: all actions except save, delete, cancel (those go in footer)
@@ -238,5 +243,8 @@ function onGuardStay(): void {
238
243
  @leave="onGuardLeave"
239
244
  @stay="onGuardStay"
240
245
  />
246
+
247
+ <!-- Values a create revealed once (#5319) -->
248
+ <QdRevealOnce :revealed="revealed" @confirm="emit('revealConfirmed')" />
241
249
  </div>
242
250
  </template>
@@ -67,6 +67,7 @@ export { default as SimpleDialog } from './dialogs/SimpleDialog.vue'
67
67
  export { default as MultiStepDialog } from './dialogs/MultiStepDialog.vue'
68
68
  export { default as BulkStatusDialog } from './dialogs/BulkStatusDialog.vue'
69
69
  export { default as UnsavedChangesDialog } from './dialogs/UnsavedChangesDialog.vue'
70
+ export { default as QdRevealOnce } from './dialogs/QdRevealOnce.vue'
70
71
 
71
72
  // Display
72
73
  export { default as CardsGrid } from './display/CardsGrid.vue'
@@ -69,6 +69,7 @@ export type {
69
69
  ResolvedAction,
70
70
  FormPageProps,
71
71
  FormPageEvents,
72
+ RevealedValues,
72
73
  UseEntityItemFormPageOptions,
73
74
  UseEntityItemFormPageReturn,
74
75
  GenerateFieldsOptions,
@@ -86,6 +87,7 @@ import type {
86
87
  ResolvedAction,
87
88
  FormPageProps,
88
89
  FormPageEvents,
90
+ RevealedValues,
89
91
  UseEntityItemFormPageOptions,
90
92
  UseEntityItemFormPageReturn,
91
93
  GenerateFieldsOptions,
@@ -358,7 +360,13 @@ export function useEntityItemFormPage<T extends Record<string, unknown> = Record
358
360
  parentConfig.value && parentId.value
359
361
  ? { parentChain: [{ entity: parentConfig.value.entity, id: parentId.value }] }
360
362
  : undefined
361
- responseData = await manager.create(payload, context)
363
+ if (manager.revealOnce && manager.createRevealing) {
364
+ const { entity: created, revealed: values } = await manager.createRevealing(payload, context)
365
+ responseData = created
366
+ if (Object.keys(values).length) pendingReveal = values
367
+ } else {
368
+ responseData = await manager.create(payload, context)
369
+ }
362
370
  }
363
371
 
364
372
  toast.add({
@@ -374,6 +382,17 @@ export function useEntityItemFormPage<T extends Record<string, unknown> = Record
374
382
  originalData.value = deepClone(savedData)
375
383
  takeSnapshot()
376
384
 
385
+ // Values shown once (#5319): held here only, until the user says they copied them
386
+ if (pendingReveal) {
387
+ const values = pendingReveal
388
+ pendingReveal = null
389
+ saving.value = false
390
+ await new Promise<void>((resolve) => {
391
+ revealResolve = resolve
392
+ revealed.value = { entity, values }
393
+ })
394
+ }
395
+
377
396
  if (onSaveSuccess) {
378
397
  await onSaveSuccess(responseData, andClose)
379
398
  }
@@ -410,6 +429,25 @@ export function useEntityItemFormPage<T extends Record<string, unknown> = Record
410
429
  }
411
430
  }
412
431
 
432
+ // ============ VALUES SHOWN ONCE (#5319) ============
433
+
434
+ // Component memory only: never in data, the snapshot, a payload or a store
435
+ const revealed = ref<RevealedValues | null>(null)
436
+ let pendingReveal: Record<string, unknown> | null = null
437
+ let revealResolve: (() => void) | null = null
438
+
439
+ function confirmRevealed(): void {
440
+ revealed.value = null
441
+ const resolve = revealResolve
442
+ revealResolve = null
443
+ resolve?.()
444
+ }
445
+
446
+ onUnmounted(() => {
447
+ revealed.value = null
448
+ revealResolve = null
449
+ })
450
+
413
451
  // ============ DELETE ============
414
452
 
415
453
  async function remove(): Promise<void> {
@@ -855,6 +893,7 @@ export function useEntityItemFormPage<T extends Record<string, unknown> = Record
855
893
  errorSummary: showErrorSummary ? errorSummary.value : null,
856
894
  submitted: submitted.value,
857
895
  guardDialog,
896
+ revealed: revealed.value,
858
897
  }))
859
898
 
860
899
  const formEvents: FormPageEvents = {
@@ -862,6 +901,7 @@ export function useEntityItemFormPage<T extends Record<string, unknown> = Record
862
901
  saveAndClose: () => submit(true),
863
902
  cancel,
864
903
  delete: confirmDelete,
904
+ revealConfirmed: confirmRevealed,
865
905
  }
866
906
 
867
907
  // ============ BUILDER API ============
@@ -958,6 +998,10 @@ export function useEntityItemFormPage<T extends Record<string, unknown> = Record
958
998
  // Guard dialog
959
999
  guardDialog,
960
1000
 
1001
+ // Values shown once (#5319)
1002
+ revealed,
1003
+ confirmRevealed,
1004
+
961
1005
  // Title helpers
962
1006
  entityLabel,
963
1007
  pageTitle,
@@ -129,6 +129,14 @@ export interface FormPageProps {
129
129
  errorSummary: ErrorSummaryItem[] | null
130
130
  submitted: boolean
131
131
  guardDialog: GuardDialogState | null
132
+ /** The values a create revealed once (#5319), shown until confirmed; null otherwise */
133
+ revealed: RevealedValues | null
134
+ }
135
+
136
+ /** The values a create response revealed once (#5319): the entity's name, and the values by key */
137
+ export interface RevealedValues {
138
+ entity: string
139
+ values: Record<string, unknown>
132
140
  }
133
141
 
134
142
  /**
@@ -139,6 +147,8 @@ export interface FormPageEvents {
139
147
  saveAndClose: () => Promise<unknown>
140
148
  cancel: () => void
141
149
  delete: () => void
150
+ /** The user copied the values shown once (#5319) */
151
+ revealConfirmed: () => void
142
152
  }
143
153
 
144
154
  /**
@@ -358,6 +368,11 @@ export interface UseEntityItemFormPageReturn<T extends Record<string, unknown> =
358
368
  // Guard dialog (for UnsavedChangesDialog - pass to PageLayout)
359
369
  guardDialog: GuardDialogState | null
360
370
 
371
+ // Values shown once (#5319): set after a create whose response revealed some,
372
+ // until confirmRevealed(); submit() waits for it before navigating
373
+ revealed: Ref<RevealedValues | null>
374
+ confirmRevealed: () => void
375
+
361
376
  // Title helpers
362
377
  entityLabel: ComputedRef<string>
363
378
  pageTitle: ComputedRef<string>
@@ -377,10 +377,19 @@ export function useNavContext(_options: UseNavContextOptions = {}): UseNavContex
377
377
  return route.params[parentConfig.value.param]
378
378
  })
379
379
 
380
+ // A page of a tabbed item (#4963): the frame's tabs are its navigation, so
381
+ // the breadcrumb's sibling links would only repeat them (#4978). The frame
382
+ // is a matched record, which the breadcrumb (rendered above it) can read.
383
+ const inItemTabs = computed(() => {
384
+ const parent = parentConfig.value?.entity
385
+ if (!parent) return false
386
+ return route.matched.some((r) => (r.meta?.itemTabs as { entity?: string } | undefined)?.entity === parent)
387
+ })
388
+
380
389
  const navlinks = computed(() => {
381
390
  void i18nLocale.value // "Details" label re-resolves on locale change
382
391
 
383
- if (!parentConfig.value) return []
392
+ if (!parentConfig.value || inItemTabs.value) return []
384
393
 
385
394
  const { entity: parentEntity, param, itemRoute } = parentConfig.value
386
395
  const parentManager = getManager(parentEntity)
@@ -523,7 +532,9 @@ export function useNavContext(_options: UseNavContextOptions = {}): UseNavContex
523
532
  const manager = getManager(parentConfig.value.entity)
524
533
  if (!manager?.routePrefix) return []
525
534
 
526
- return (['show', 'edit'] as const)
535
+ // In a tabbed item the Details tab is the View link; Edit has no tab
536
+ const targets = inItemTabs.value ? (['edit'] as const) : (['show', 'edit'] as const)
537
+ return targets
527
538
  .map((target) => buildModeLink(manager, target, parentId.value, entityData.value))
528
539
  .filter((link): link is BreadcrumbModeToggle => link !== null)
529
540
  })
@@ -414,6 +414,20 @@ export function applyCrudMethods(EntityManagerClass: { prototype: any }): void {
414
414
  data: Partial<any>,
415
415
  context?: RoutingContext
416
416
  ): Promise<any> {
417
+ // The values shown once are dropped here: a caller wanting them uses createRevealing()
418
+ return (await this.createRevealing(data, context)).entity
419
+ }
420
+
421
+ /**
422
+ * Create a new entity, and hand back the values its response reveals once
423
+ * (#5319, `revealOnce`). They are taken out of the response before the
424
+ * cache, the postsave hooks and the signals see it.
425
+ */
426
+ proto.createRevealing = async function (
427
+ this: Self,
428
+ data: Partial<any>,
429
+ context?: RoutingContext
430
+ ): Promise<{ entity: any; revealed: Record<string, unknown> }> {
417
431
  const { storage, endpoint } = this._normalizeResolveResult(
418
432
  this.resolveStorage('create', context),
419
433
  context
@@ -428,16 +442,17 @@ export function applyCrudMethods(EntityManagerClass: { prototype: any }): void {
428
442
  await this._invokeHook('presave', presaveContext as unknown as Record<string, unknown>)
429
443
 
430
444
  // Use request() with endpoint for multi-storage routing, otherwise use create()
431
- let result: any
445
+ let response: any
432
446
  if (endpoint && storage.request) {
433
- const response = (await storage.request('POST', endpoint, {
447
+ const raw = (await storage.request('POST', endpoint, {
434
448
  data: presaveContext.record,
435
449
  context,
436
450
  })) as { data?: any }
437
- result = (response.data ?? response)
451
+ response = (raw.data ?? raw)
438
452
  } else {
439
- result = await storage.create(presaveContext.record)
453
+ response = await storage.create(presaveContext.record)
440
454
  }
455
+ const { entity: result, revealed } = splitRevealed(response, this.revealOnce)
441
456
  this.invalidateCache()
442
457
 
443
458
  // Invoke postsave hooks (for side effects)
@@ -450,7 +465,7 @@ export function applyCrudMethods(EntityManagerClass: { prototype: any }): void {
450
465
  id: result?.[this.idField],
451
466
  })
452
467
  this._emitDataInvalidate('created', result?.[this.idField] as string | number | undefined)
453
- return result
468
+ return { entity: result, revealed }
454
469
  }
455
470
  throw new Error(`[EntityManager:${this.name}] create() not implemented`)
456
471
  }
@@ -626,3 +641,31 @@ export function applyCrudMethods(EntityManagerClass: { prototype: any }): void {
626
641
  this._orchestrator = orchestrator
627
642
  }
628
643
  }
644
+
645
+ /**
646
+ * Take the values shown once out of a create response (#5319): the entity is
647
+ * `response[item]` when the config names one, else the response without them.
648
+ */
649
+ export function splitRevealed(
650
+ response: unknown,
651
+ config: { keys: string[]; item?: string } | null
652
+ ): { entity: any; revealed: Record<string, unknown> } {
653
+ if (!config || !response || typeof response !== 'object') return { entity: response, revealed: {} }
654
+ const source = response as Record<string, unknown>
655
+ const revealed: Record<string, unknown> = {}
656
+ for (const key of config.keys) {
657
+ if (source[key] !== undefined && source[key] !== null) revealed[key] = source[key]
658
+ }
659
+ if (config.item) {
660
+ const item = source[config.item]
661
+ if (item && typeof item === 'object') {
662
+ // The item itself never carries a revealed key either
663
+ const entity = { ...(item as Record<string, unknown>) }
664
+ for (const key of config.keys) delete entity[key]
665
+ return { entity, revealed }
666
+ }
667
+ }
668
+ const entity = { ...source }
669
+ for (const key of config.keys) delete entity[key]
670
+ return { entity, revealed }
671
+ }
@@ -115,6 +115,10 @@ export interface EntityManagerCrud<T = unknown> extends EntityManagerRead<T> {
115
115
  // getFieldConfig inherited (required) from EntityManagerRead since #1253
116
116
  resolveReferenceOptions: (fieldName: string) => Promise<unknown[]>
117
117
  create: (data: unknown, context?: unknown) => Promise<T>
118
+ /** What a create response reveals once (#5319), or null */
119
+ revealOnce?: { keys: string[]; item?: string } | null
120
+ /** create(), and the values its response reveals once (#5319) */
121
+ createRevealing?: (data: unknown, context?: unknown) => Promise<{ entity: T; revealed: Record<string, unknown> }>
118
122
  update: (id: string | number, data: unknown, context?: unknown) => Promise<T>
119
123
  patch: (id: string | number, data: unknown, context?: unknown) => Promise<T>
120
124
  // Optional BY DESIGN (#1253): the severity/badge presentation capability —
@@ -50,6 +50,8 @@ export type {
50
50
  SeverityMap,
51
51
  EntityManagerOptions,
52
52
  GetOptions,
53
+ RevealOnceConfig,
54
+ CreateRevealingResult,
53
55
  } from './EntityManager.types'
54
56
 
55
57
  // Import concrete types needed in method signatures
@@ -67,6 +69,8 @@ import type {
67
69
  SeverityDescriptor,
68
70
  EntityManagerOptions,
69
71
  LiveEntityPolicy,
72
+ RevealOnceConfig,
73
+ CreateRevealingResult,
70
74
  } from './EntityManager.types'
71
75
 
72
76
  /**
@@ -102,6 +106,7 @@ export class EntityManager<T extends EntityRecord = EntityRecord> {
102
106
  protected _detailCacheMaxSize: number
103
107
  protected _detailInflight: Map<string, Promise<T>> = new Map()
104
108
  protected _readOnly: boolean
109
+ protected _revealOnce: RevealOnceConfig | null
105
110
  protected _warmup: boolean
106
111
  protected _authSensitive: boolean
107
112
  /** Reaction policy for changes made outside this session (#1888). */
@@ -175,6 +180,7 @@ export class EntityManager<T extends EntityRecord = EntityRecord> {
175
180
  detailCacheTtlMs = 0,
176
181
  detailCacheMaxSize = 0,
177
182
  readOnly = false,
183
+ revealOnce = null,
178
184
  warmup = true,
179
185
  authSensitive,
180
186
  live,
@@ -209,6 +215,7 @@ export class EntityManager<T extends EntityRecord = EntityRecord> {
209
215
  this._detailCacheTtlMs = detailCacheTtlMs
210
216
  this._detailCacheMaxSize = detailCacheMaxSize
211
217
  this._readOnly = readOnly
218
+ this._revealOnce = revealOnce?.keys?.length ? revealOnce : null
212
219
  this._warmup = warmup
213
220
  this._authSensitive = authSensitive ?? this._getStorageRequiresAuth()
214
221
  // Pre-wired defaults: the common case declares nothing.
@@ -673,6 +680,11 @@ export class EntityManager<T extends EntityRecord = EntityRecord> {
673
680
  return this._readOnly
674
681
  }
675
682
 
683
+ /** What a create response reveals once (#5319), or null */
684
+ get revealOnce(): RevealOnceConfig | null {
685
+ return this._revealOnce
686
+ }
687
+
676
688
  /**
677
689
  * Whether this entity is one the framework provides (roles, users). Owned
678
690
  * by qdadm — see `EntityManagerOptions.system`.
@@ -1032,6 +1044,7 @@ export interface EntityManager<T extends EntityRecord = EntityRecord> {
1032
1044
  get(id: string | number, context?: RoutingContext, options?: GetOptions): Promise<T>
1033
1045
  getMany(ids: Array<string | number>, context?: RoutingContext): Promise<T[]>
1034
1046
  create(data: Partial<T>, context?: RoutingContext): Promise<T>
1047
+ createRevealing(data: Partial<T>, context?: RoutingContext): Promise<CreateRevealingResult<T>>
1035
1048
  update(id: string | number, data: Partial<T>, context?: RoutingContext): Promise<T>
1036
1049
  patch(id: string | number, data: Partial<T>, context?: RoutingContext): Promise<T>
1037
1050
  delete(id: string | number, context?: RoutingContext): Promise<void>
@@ -264,6 +264,26 @@ export interface LiveRefreshPolicy {
264
264
  /** The notification entry `LiveEntityPolicy.describeUpdate` asks for (#2685). */
265
265
  export type LiveUpdateEntry = Omit<NewNotification, 'severity'> & Partial<Pick<NewNotification, 'severity'>>
266
266
 
267
+ /**
268
+ * What a create response reveals once (#5319).
269
+ *
270
+ * POST /keys → { key: { name, scopes, … }, token: 'sbx_…' }
271
+ * revealOnce: { keys: ['token'], item: 'key' }
272
+ */
273
+ export interface RevealOnceConfig {
274
+ /** The response keys shown once and never kept */
275
+ keys: string[]
276
+ /** Where the entity sits in the response; the rest of it when absent */
277
+ item?: string
278
+ }
279
+
280
+ /** What `createRevealing()` returns: the entity, and the values shown once */
281
+ export interface CreateRevealingResult<T> {
282
+ entity: T
283
+ /** The revealed values, by key; empty when the response carried none */
284
+ revealed: Record<string, unknown>
285
+ }
286
+
267
287
  /**
268
288
  * EntityManager constructor options
269
289
  */
@@ -302,6 +322,14 @@ export interface EntityManagerOptions<T extends EntityRecord = EntityRecord> {
302
322
  /** Detail cache max size (0=unlimited (default), >0=max items). Oldest entries are evicted when exceeded. Only used when asymmetric=true. */
303
323
  detailCacheMaxSize?: number
304
324
  readOnly?: boolean
325
+ /**
326
+ * Values the create response carries once and that are never kept (#5319):
327
+ * a key's token, a generated password. `create()` takes them out of the
328
+ * response before anything else sees it (the cache, the signals, the
329
+ * postsave hooks); `createRevealing()` hands them to the caller, and the
330
+ * create form shows them once.
331
+ */
332
+ revealOnce?: RevealOnceConfig
305
333
  warmup?: boolean
306
334
  authSensitive?: boolean
307
335
  /**
@@ -363,6 +363,14 @@ export default `core:
363
363
  moreKeys: "+{count} more"
364
364
  takeTheirs: Load their version
365
365
  keepMine: Keep mine and save over it
366
+ # Values a create reveals once: a key's token (QdRevealOnce, #5319)
367
+ revealOnce:
368
+ title: "{entity} created"
369
+ warning: Copy it now. It is shown only this once and cannot be read again.
370
+ copy: Copy
371
+ copied: Copied
372
+ copyFailed: "Copy failed: {error}"
373
+ confirm: I have copied it
366
374
  # NotFoundPage
367
375
  notFound:
368
376
  title: Page not found
@@ -361,6 +361,14 @@ core:
361
361
  moreKeys: "+{count} more"
362
362
  takeTheirs: Load their version
363
363
  keepMine: Keep mine and save over it
364
+ # Values a create reveals once: a key's token (QdRevealOnce, #5319)
365
+ revealOnce:
366
+ title: "{entity} created"
367
+ warning: Copy it now. It is shown only this once and cannot be read again.
368
+ copy: Copy
369
+ copied: Copied
370
+ copyFailed: "Copy failed: {error}"
371
+ confirm: I have copied it
364
372
  # NotFoundPage
365
373
  notFound:
366
374
  title: Page not found
@@ -363,6 +363,14 @@ export default `core:
363
363
  moreKeys: "+{count} autres"
364
364
  takeTheirs: Charger sa version
365
365
  keepMine: Garder la mienne et l'enregistrer par-dessus
366
+ # Values a create reveals once: a key's token (QdRevealOnce, #5319)
367
+ revealOnce:
368
+ title: "{entity} : création réussie"
369
+ warning: Copiez-la maintenant. Elle n'est montrée que cette fois et ne pourra plus être relue.
370
+ copy: Copier
371
+ copied: Copié
372
+ copyFailed: "Échec de la copie : {error}"
373
+ confirm: J'ai copié
366
374
  # NotFoundPage
367
375
  notFound:
368
376
  title: Page introuvable
@@ -361,6 +361,14 @@ core:
361
361
  moreKeys: "+{count} autres"
362
362
  takeTheirs: Charger sa version
363
363
  keepMine: Garder la mienne et l'enregistrer par-dessus
364
+ # Values a create reveals once: a key's token (QdRevealOnce, #5319)
365
+ revealOnce:
366
+ title: "{entity} : création réussie"
367
+ warning: Copiez-la maintenant. Elle n'est montrée que cette fois et ne pourra plus être relue.
368
+ copy: Copier
369
+ copied: Copié
370
+ copyFailed: "Échec de la copie : {error}"
371
+ confirm: J'ai copié
364
372
  # NotFoundPage
365
373
  notFound:
366
374
  title: Page introuvable
package/src/index.ts CHANGED
@@ -41,7 +41,7 @@ export { SSEBridge, createSSEBridge, SSE_SIGNALS } from './kernel/SSEBridge'
41
41
  export type { SSEBridgeOptions } from './kernel/SSEBridge'
42
42
  export { useLiveEntity } from './composables/useLiveEntity'
43
43
  export type { UseLiveEntityOptions } from './composables/useLiveEntity'
44
- export type { LiveEntityPolicy, LiveUpdateEntry, LiveRefreshRule, LiveRefreshPolicy } from './entity/EntityManager.types'
44
+ export type { LiveEntityPolicy, LiveUpdateEntry, LiveRefreshRule, LiveRefreshPolicy, RevealOnceConfig, CreateRevealingResult } from './entity/EntityManager.types'
45
45
  export { LiveEntityRouter, createLiveEntityRouter } from './kernel/LiveEntityRouter'
46
46
  export type {
47
47
  LiveEntityRouterOptions,
@@ -0,0 +1,36 @@
1
+ /**
2
+ * Put text on the clipboard: `navigator.clipboard` when the page has it, a
3
+ * selected textarea otherwise (a page served over plain http has none).
4
+ * Throws when neither works.
5
+ */
6
+ export async function copyText(text: string): Promise<void> {
7
+ try {
8
+ if (!navigator.clipboard?.writeText) throw new Error('no clipboard on this page (it needs HTTPS)')
9
+ await navigator.clipboard.writeText(text)
10
+ } catch (err) {
11
+ try {
12
+ copyByCommand(text)
13
+ } catch {
14
+ throw err
15
+ }
16
+ }
17
+ }
18
+
19
+ function copyByCommand(text: string): void {
20
+ const area = document.createElement('textarea')
21
+ area.value = text
22
+ area.setAttribute('readonly', '')
23
+ area.style.position = 'fixed'
24
+ area.style.opacity = '0'
25
+ document.body.appendChild(area)
26
+ const focused = document.activeElement as HTMLElement | null
27
+ area.select()
28
+ try {
29
+ if (!document.execCommand?.('copy')) throw new Error('the browser refused to copy')
30
+ } finally {
31
+ // The textarea held the value: it goes at once
32
+ area.value = ''
33
+ area.remove()
34
+ focused?.focus?.()
35
+ }
36
+ }