@10x-media/fields 0.1.0-beta.0 → 0.1.0-beta.10
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/CHANGELOG.md +173 -0
- package/README.md +8 -4
- package/dist/exports/client.d.ts +10 -1
- package/dist/exports/client.js +9 -1
- package/dist/exports/color-utils.d.ts +4 -2
- package/dist/exports/color-utils.js +3 -1
- package/dist/exports/color.d.ts +5 -2
- package/dist/exports/color.js +4 -1
- package/dist/exports/encrypted.d.ts +7 -4
- package/dist/exports/encrypted.js +6 -3
- package/dist/exports/icon-adapters/radix.d.ts +2 -2
- package/dist/exports/icon-adapters/radix.js +2 -2
- package/dist/exports/icon-react.d.ts +2 -2
- package/dist/exports/icon.d.ts +6 -2
- package/dist/exports/icon.js +6 -2
- package/dist/exports/measurement-utils.d.ts +9 -0
- package/dist/exports/measurement-utils.js +8 -0
- package/dist/exports/measurement.d.ts +11 -0
- package/dist/exports/measurement.js +10 -0
- package/dist/exports/phone-utils.d.ts +4 -0
- package/dist/exports/phone-utils.js +4 -0
- package/dist/exports/phone.d.ts +6 -0
- package/dist/exports/phone.js +3 -0
- package/dist/exports/rsc.d.ts +5 -1
- package/dist/exports/rsc.js +5 -1
- package/dist/exports/types.d.ts +3 -2
- package/dist/fields/color/client/ColorField.d.ts +2 -0
- package/dist/fields/color/client/ColorField.js +35 -288
- package/dist/fields/color/client/ColorField.js.map +1 -1
- package/dist/fields/color/client/ColorInput.d.ts +44 -0
- package/dist/fields/color/client/ColorInput.js +374 -0
- package/dist/fields/color/client/ColorInput.js.map +1 -0
- package/dist/fields/color/client/ColorPickerPanel.d.ts +3 -1
- package/dist/fields/color/client/ColorPickerPanel.js +31 -5
- package/dist/fields/color/client/ColorPickerPanel.js.map +1 -1
- package/dist/fields/color/client/colorField.css +30 -0
- package/dist/fields/color/colorField.d.ts +9 -2
- package/dist/fields/color/colorField.js +68 -15
- package/dist/fields/color/colorField.js.map +1 -1
- package/dist/fields/color/engine/index.d.ts +2 -1
- package/dist/fields/color/engine/scheme.d.ts +13 -0
- package/dist/fields/color/engine/scheme.js +12 -0
- package/dist/fields/color/engine/scheme.js.map +1 -0
- package/dist/fields/color/options.d.ts +5 -4
- package/dist/fields/color/options.js.map +1 -1
- package/dist/fields/color/paths.d.ts +1 -0
- package/dist/fields/color/paths.js +32 -0
- package/dist/fields/color/paths.js.map +1 -0
- package/dist/fields/color/presetChip.js +10 -9
- package/dist/fields/color/presetChip.js.map +1 -1
- package/dist/fields/color/presetReference.d.ts +13 -0
- package/dist/fields/color/presetReference.js +94 -0
- package/dist/fields/color/presetReference.js.map +1 -0
- package/dist/fields/color/presetsFromArray.d.ts +30 -0
- package/dist/fields/color/presetsFromArray.js +58 -0
- package/dist/fields/color/presetsFromArray.js.map +1 -0
- package/dist/fields/color/presetsFromDoc.js +1 -23
- package/dist/fields/color/presetsFromDoc.js.map +1 -1
- package/dist/fields/color/resolvePresets.d.ts +2 -2
- package/dist/fields/color/resolvePresets.js +38 -8
- package/dist/fields/color/resolvePresets.js.map +1 -1
- package/dist/fields/color/schemeValue.js +30 -0
- package/dist/fields/color/schemeValue.js.map +1 -0
- package/dist/fields/color/server/ColorCell.js +9 -3
- package/dist/fields/color/server/ColorCell.js.map +1 -1
- package/dist/fields/color/server/colorCell.css +5 -0
- package/dist/fields/color/valueIssue.js +23 -0
- package/dist/fields/color/valueIssue.js.map +1 -0
- package/dist/fields/encrypted/boot.js +2 -1
- package/dist/fields/encrypted/boot.js.map +1 -1
- package/dist/fields/encrypted/components/EncryptedInput.js +4 -1
- package/dist/fields/encrypted/components/EncryptedInput.js.map +1 -1
- package/dist/fields/encrypted/components/EncryptedTextarea.js +6 -2
- package/dist/fields/encrypted/components/EncryptedTextarea.js.map +1 -1
- package/dist/fields/encrypted/components/ProtectedCell.d.ts +15 -6
- package/dist/fields/encrypted/components/ProtectedCell.js +37 -8
- package/dist/fields/encrypted/components/ProtectedCell.js.map +1 -1
- package/dist/fields/encrypted/components/ProtectedField.css +134 -39
- package/dist/fields/encrypted/components/ProtectedField.d.ts +3 -0
- package/dist/fields/encrypted/components/ProtectedField.js +14 -0
- package/dist/fields/encrypted/components/ProtectedField.js.map +1 -1
- package/dist/fields/encrypted/components/WriteOnlyActions.js +65 -0
- package/dist/fields/encrypted/components/WriteOnlyActions.js.map +1 -0
- package/dist/fields/encrypted/components/WriteOnlyField.js +286 -0
- package/dist/fields/encrypted/components/WriteOnlyField.js.map +1 -0
- package/dist/fields/encrypted/components/writeOnlyIntent.js +69 -0
- package/dist/fields/encrypted/components/writeOnlyIntent.js.map +1 -0
- package/dist/fields/encrypted/crypto/wire.d.ts +10 -1
- package/dist/fields/encrypted/crypto/wire.js +1 -1
- package/dist/fields/encrypted/encryptedField.js +63 -6
- package/dist/fields/encrypted/encryptedField.js.map +1 -1
- package/dist/fields/encrypted/generateSecret.d.ts +10 -0
- package/dist/fields/encrypted/generateSecret.js +41 -0
- package/dist/fields/encrypted/generateSecret.js.map +1 -0
- package/dist/fields/encrypted/hint.js +67 -0
- package/dist/fields/encrypted/hint.js.map +1 -0
- package/dist/fields/encrypted/hooks.js +59 -31
- package/dist/fields/encrypted/hooks.js.map +1 -1
- package/dist/fields/encrypted/queryRewrite.d.ts +10 -2
- package/dist/fields/encrypted/queryRewrite.js +34 -8
- package/dist/fields/encrypted/queryRewrite.js.map +1 -1
- package/dist/fields/encrypted/rawRead.d.ts +24 -0
- package/dist/fields/encrypted/rawRead.js +40 -0
- package/dist/fields/encrypted/rawRead.js.map +1 -0
- package/dist/fields/encrypted/scan.js +21 -4
- package/dist/fields/encrypted/scan.js.map +1 -1
- package/dist/fields/encrypted/types.d.ts +67 -2
- package/dist/fields/encrypted/types.js +8 -1
- package/dist/fields/encrypted/types.js.map +1 -1
- package/dist/fields/encrypted/utils/decryptAllData.js +2 -2
- package/dist/fields/encrypted/utils/decryptAllData.js.map +1 -1
- package/dist/fields/encrypted/utils/decryptFieldValue.d.ts +30 -0
- package/dist/fields/encrypted/utils/decryptFieldValue.js +56 -0
- package/dist/fields/encrypted/utils/decryptFieldValue.js.map +1 -0
- package/dist/fields/encrypted/utils/readEncryptedField.d.ts +51 -0
- package/dist/fields/encrypted/utils/readEncryptedField.js +96 -0
- package/dist/fields/encrypted/utils/readEncryptedField.js.map +1 -0
- package/dist/fields/icon/adapters/lucide/generated/manifest.js.map +1 -1
- package/dist/fields/icon/adapters/lucide/generated/nodes.js.map +1 -1
- package/dist/fields/icon/adapters/radix/adapter.js +7 -0
- package/dist/fields/icon/adapters/radix/adapter.js.map +1 -1
- package/dist/fields/icon/adapters/radix/client.d.ts +3 -2
- package/dist/fields/icon/adapters/radix/client.js +3 -2
- package/dist/fields/icon/adapters/radix/client.js.map +1 -1
- package/dist/fields/icon/adapters/radix/generated/manifest.js.map +1 -1
- package/dist/fields/icon/adapters/radix/generated/nodes.js +3625 -0
- package/dist/fields/icon/adapters/radix/generated/nodes.js.map +1 -0
- package/dist/fields/icon/adapters/tabler/generated/manifest.js.map +1 -1
- package/dist/fields/icon/adapters/tabler/generated/nodes.js.map +1 -1
- package/dist/fields/icon/client/DrawerGlyph.js +34 -17
- package/dist/fields/icon/client/DrawerGlyph.js.map +1 -1
- package/dist/fields/icon/client/IconDrawerContent.js +9 -45
- package/dist/fields/icon/client/IconDrawerContent.js.map +1 -1
- package/dist/fields/icon/client/IconFieldClient.d.ts +7 -0
- package/dist/fields/icon/client/IconFieldClient.js +15 -7
- package/dist/fields/icon/client/IconFieldClient.js.map +1 -1
- package/dist/fields/icon/client/IconGridCell.js +67 -0
- package/dist/fields/icon/client/IconGridCell.js.map +1 -0
- package/dist/fields/icon/client/icon-field.css +12 -2
- package/dist/fields/icon/codegen/emit.js +5 -4
- package/dist/fields/icon/codegen/emit.js.map +1 -1
- package/dist/fields/icon/codegen/generate.js +32 -6
- package/dist/fields/icon/codegen/generate.js.map +1 -1
- package/dist/fields/icon/layers/coalesce.js +41 -0
- package/dist/fields/icon/layers/coalesce.js.map +1 -0
- package/dist/fields/icon/layers/manifestCache.d.ts +6 -0
- package/dist/fields/icon/layers/manifestCache.js +49 -0
- package/dist/fields/icon/layers/manifestCache.js.map +1 -0
- package/dist/fields/icon/layers/resolve.d.ts +20 -0
- package/dist/fields/icon/layers/resolve.js +63 -0
- package/dist/fields/icon/layers/resolve.js.map +1 -0
- package/dist/fields/icon/layers/upload.d.ts +52 -0
- package/dist/fields/icon/layers/upload.js +116 -0
- package/dist/fields/icon/layers/upload.js.map +1 -0
- package/dist/fields/icon/plugin.js +24 -0
- package/dist/fields/icon/plugin.js.map +1 -1
- package/dist/fields/icon/react/createIcon.d.ts +5 -0
- package/dist/fields/icon/react/createIcon.js +22 -4
- package/dist/fields/icon/react/createIcon.js.map +1 -1
- package/dist/fields/icon/react/createRscIcon.js +22 -1
- package/dist/fields/icon/react/createRscIcon.js.map +1 -1
- package/dist/fields/icon/react/resolveRendered.js +21 -0
- package/dist/fields/icon/react/resolveRendered.js.map +1 -0
- package/dist/fields/icon/react/types.d.ts +15 -1
- package/dist/fields/icon/rsc/IconCell.d.ts +2 -2
- package/dist/fields/icon/rsc/IconCell.js +12 -5
- package/dist/fields/icon/rsc/IconCell.js.map +1 -1
- package/dist/fields/icon/rsc/IconFieldServer.js +16 -2
- package/dist/fields/icon/rsc/IconFieldServer.js.map +1 -1
- package/dist/fields/icon/rsc/IconLibrarySelectServer.js +1 -1
- package/dist/fields/icon/rsc/IconLibrarySelectServer.js.map +1 -1
- package/dist/fields/icon/server/endpoint.d.ts +12 -0
- package/dist/fields/icon/server/endpoint.js +52 -0
- package/dist/fields/icon/server/endpoint.js.map +1 -0
- package/dist/fields/icon/server/manifestCache.js +9 -4
- package/dist/fields/icon/server/manifestCache.js.map +1 -1
- package/dist/fields/icon/server/resolveIconMeta.js +31 -0
- package/dist/fields/icon/server/resolveIconMeta.js.map +1 -0
- package/dist/fields/icon/server/validate.js +5 -2
- package/dist/fields/icon/server/validate.js.map +1 -1
- package/dist/fields/icon/shared/adapterComponents.d.ts +3 -2
- package/dist/fields/icon/shared/iconLabel.js +26 -0
- package/dist/fields/icon/shared/iconLabel.js.map +1 -0
- package/dist/fields/measurement/client/MeasurementCell.d.ts +18 -0
- package/dist/fields/measurement/client/MeasurementCell.js +47 -0
- package/dist/fields/measurement/client/MeasurementCell.js.map +1 -0
- package/dist/fields/measurement/client/MeasurementField.d.ts +13 -0
- package/dist/fields/measurement/client/MeasurementField.js +70 -0
- package/dist/fields/measurement/client/MeasurementField.js.map +1 -0
- package/dist/fields/measurement/client/MeasurementInput.d.ts +42 -0
- package/dist/fields/measurement/client/MeasurementInput.js +327 -0
- package/dist/fields/measurement/client/MeasurementInput.js.map +1 -0
- package/dist/fields/measurement/client/MeasurementUnitsProvider.d.ts +24 -0
- package/dist/fields/measurement/client/MeasurementUnitsProvider.js +61 -0
- package/dist/fields/measurement/client/MeasurementUnitsProvider.js.map +1 -0
- package/dist/fields/measurement/client/editModel.js +124 -0
- package/dist/fields/measurement/client/editModel.js.map +1 -0
- package/dist/fields/measurement/client/measurementCell.css +4 -0
- package/dist/fields/measurement/client/measurementField.css +215 -0
- package/dist/fields/measurement/client/useMeasurementModel.d.ts +19 -0
- package/dist/fields/measurement/client/useMeasurementModel.js +85 -0
- package/dist/fields/measurement/client/useMeasurementModel.js.map +1 -0
- package/dist/fields/measurement/engine/convert.d.ts +8 -0
- package/dist/fields/measurement/engine/convert.js +21 -0
- package/dist/fields/measurement/engine/convert.js.map +1 -0
- package/dist/fields/measurement/engine/format.d.ts +37 -0
- package/dist/fields/measurement/engine/format.js +156 -0
- package/dist/fields/measurement/engine/format.js.map +1 -0
- package/dist/fields/measurement/engine/locale.d.ts +25 -0
- package/dist/fields/measurement/engine/locale.js +79 -0
- package/dist/fields/measurement/engine/locale.js.map +1 -0
- package/dist/fields/measurement/engine/precision.d.ts +34 -0
- package/dist/fields/measurement/engine/precision.js +63 -0
- package/dist/fields/measurement/engine/precision.js.map +1 -0
- package/dist/fields/measurement/engine/registry.d.ts +55 -0
- package/dist/fields/measurement/engine/registry.js +117 -0
- package/dist/fields/measurement/engine/registry.js.map +1 -0
- package/dist/fields/measurement/engine/units.d.ts +178 -0
- package/dist/fields/measurement/engine/units.js +198 -0
- package/dist/fields/measurement/engine/units.js.map +1 -0
- package/dist/fields/measurement/measurementField.d.ts +17 -0
- package/dist/fields/measurement/measurementField.js +139 -0
- package/dist/fields/measurement/measurementField.js.map +1 -0
- package/dist/fields/measurement/options.d.ts +76 -0
- package/dist/fields/measurement/options.js +9 -0
- package/dist/fields/measurement/options.js.map +1 -0
- package/dist/fields/measurement/presets.d.ts +117 -0
- package/dist/fields/measurement/presets.js +136 -0
- package/dist/fields/measurement/presets.js.map +1 -0
- package/dist/fields/measurement/server/MeasurementCellServer.d.ts +21 -0
- package/dist/fields/measurement/server/MeasurementCellServer.js +53 -0
- package/dist/fields/measurement/server/MeasurementCellServer.js.map +1 -0
- package/dist/fields/measurement/server/MeasurementFieldServer.d.ts +16 -0
- package/dist/fields/measurement/server/MeasurementFieldServer.js +45 -0
- package/dist/fields/measurement/server/MeasurementFieldServer.js.map +1 -0
- package/dist/fields/measurement/server/getUserUnits.js +39 -0
- package/dist/fields/measurement/server/getUserUnits.js.map +1 -0
- package/dist/fields/measurement/server/resolvePrecisionSafe.js +24 -0
- package/dist/fields/measurement/server/resolvePrecisionSafe.js.map +1 -0
- package/dist/fields/measurement/server/resolveRegistryDefault.js +26 -0
- package/dist/fields/measurement/server/resolveRegistryDefault.js.map +1 -0
- package/dist/fields/phoneNumber/client/CountryFlag.d.ts +16 -0
- package/dist/fields/phoneNumber/client/CountryFlag.js +40 -0
- package/dist/fields/phoneNumber/client/CountryFlag.js.map +1 -0
- package/dist/fields/phoneNumber/client/CountryPicker.d.ts +21 -0
- package/dist/fields/phoneNumber/client/CountryPicker.js +255 -0
- package/dist/fields/phoneNumber/client/CountryPicker.js.map +1 -0
- package/dist/fields/phoneNumber/client/PhoneNumberField.d.ts +26 -0
- package/dist/fields/phoneNumber/client/PhoneNumberField.js +318 -0
- package/dist/fields/phoneNumber/client/PhoneNumberField.js.map +1 -0
- package/dist/fields/phoneNumber/client/editModel.js +86 -0
- package/dist/fields/phoneNumber/client/editModel.js.map +1 -0
- package/dist/fields/phoneNumber/client/phoneNumberField.css +305 -0
- package/dist/fields/phoneNumber/engine/countries.d.ts +36 -0
- package/dist/fields/phoneNumber/engine/countries.js +68 -0
- package/dist/fields/phoneNumber/engine/countries.js.map +1 -0
- package/dist/fields/phoneNumber/engine/draft.d.ts +13 -0
- package/dist/fields/phoneNumber/engine/draft.js +72 -0
- package/dist/fields/phoneNumber/engine/draft.js.map +1 -0
- package/dist/fields/phoneNumber/engine/metadata.d.ts +11 -0
- package/dist/fields/phoneNumber/engine/metadata.js +32 -0
- package/dist/fields/phoneNumber/engine/metadata.js.map +1 -0
- package/dist/fields/phoneNumber/engine/phone.d.ts +37 -0
- package/dist/fields/phoneNumber/engine/phone.js +59 -0
- package/dist/fields/phoneNumber/engine/phone.js.map +1 -0
- package/dist/fields/phoneNumber/options.d.ts +72 -0
- package/dist/fields/phoneNumber/options.js +37 -0
- package/dist/fields/phoneNumber/options.js.map +1 -0
- package/dist/fields/phoneNumber/phoneNumberField.d.ts +14 -0
- package/dist/fields/phoneNumber/phoneNumberField.js +167 -0
- package/dist/fields/phoneNumber/phoneNumberField.js.map +1 -0
- package/dist/fields/phoneNumber/server/PhoneNumberCellServer.d.ts +19 -0
- package/dist/fields/phoneNumber/server/PhoneNumberCellServer.js +73 -0
- package/dist/fields/phoneNumber/server/PhoneNumberCellServer.js.map +1 -0
- package/dist/fields/phoneNumber/server/PhoneNumberFieldServer.d.ts +16 -0
- package/dist/fields/phoneNumber/server/PhoneNumberFieldServer.js +57 -0
- package/dist/fields/phoneNumber/server/PhoneNumberFieldServer.js.map +1 -0
- package/dist/fields/phoneNumber/server/flagsEndpoint.js +51 -0
- package/dist/fields/phoneNumber/server/flagsEndpoint.js.map +1 -0
- package/dist/fields/phoneNumber/server/readPhoneOptions.js +18 -0
- package/dist/fields/phoneNumber/server/readPhoneOptions.js.map +1 -0
- package/dist/fields/phoneNumber/server/resolvePhoneOptionsSafe.js +33 -0
- package/dist/fields/phoneNumber/server/resolvePhoneOptionsSafe.js.map +1 -0
- package/dist/index.d.ts +5 -3
- package/dist/index.js +35 -1
- package/dist/index.js.map +1 -1
- package/dist/translations/ar.js +62 -0
- package/dist/translations/ar.js.map +1 -0
- package/dist/translations/de.js +19 -1
- package/dist/translations/de.js.map +1 -1
- package/dist/translations/en.js +19 -1
- package/dist/translations/en.js.map +1 -1
- package/dist/translations/es.js +62 -0
- package/dist/translations/es.js.map +1 -0
- package/dist/translations/fr.js +62 -0
- package/dist/translations/fr.js.map +1 -0
- package/dist/translations/id.js +62 -0
- package/dist/translations/id.js.map +1 -0
- package/dist/translations/index.d.ts +10 -1
- package/dist/translations/index.js +19 -1
- package/dist/translations/index.js.map +1 -1
- package/dist/translations/keys.d.ts +19 -1
- package/dist/translations/keys.js +20 -2
- package/dist/translations/keys.js.map +1 -1
- package/dist/translations/ko.js +62 -0
- package/dist/translations/ko.js.map +1 -0
- package/dist/translations/pt.js +62 -0
- package/dist/translations/pt.js.map +1 -0
- package/dist/translations/ru.js +62 -0
- package/dist/translations/ru.js.map +1 -0
- package/dist/translations/uk.js +62 -0
- package/dist/translations/uk.js.map +1 -0
- package/dist/translations/zh.js +62 -0
- package/dist/translations/zh.js.map +1 -0
- package/dist/types.d.ts +165 -8
- package/dist/utils/resolveStaticLabel.js +13 -0
- package/dist/utils/resolveStaticLabel.js.map +1 -0
- package/package.json +31 -7
- package/dist/fields/icon/rsc/resolveStaticLabel.js +0 -16
- package/dist/fields/icon/rsc/resolveStaticLabel.js.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"WriteOnlyField.js","names":["useTranslation"],"sources":["../../../../src/fields/encrypted/components/WriteOnlyField.tsx"],"sourcesContent":["'use client'\nimport {\n\tFieldDescription,\n\tFieldError,\n\tFieldLabel,\n\tuseDocumentEvents,\n\tuseField,\n\tuseFormFields,\n\tuseFormSubmitted,\n} from '@payloadcms/ui'\nimport { mergeFieldStyles } from '@payloadcms/ui/shared'\nimport type React from 'react'\nimport { useCallback, useEffect, useMemo, useRef, useState } from 'react'\nimport { keys } from '../../../translations/keys'\nimport { useTranslation } from '../../../translations/useTranslation'\nimport { generateSecret, type NormalizedGenerate } from '../generateSecret'\nimport { formatHint } from '../hint'\nimport { dotString } from './MaskDots'\nimport type { EncryptedFieldConfig, Placement } from './placement'\nimport { ActionButton } from './WriteOnlyActions'\nimport { applyBlur, applyClear, applyInput, applySave, applyUndo } from './writeOnlyIntent'\n\ntype NativeComponent = React.ComponentType<Record<string, unknown>>\n\nexport interface WriteOnlyFieldProps {\n\tclearable: boolean\n\tcomponentKey: string\n\tfield: EncryptedFieldConfig\n\tgenerate?: NormalizedGenerate\n\thintPath: string\n\tmaskDots: number\n\tNative: NativeComponent\n\tnativeProps: Record<string, unknown>\n\tpath: string\n\tplacement: Placement\n\tsetPath: string\n}\n\n/**\n * Editor for `protection: 'writeOnly'`. The plaintext never reaches the client\n * (reads strip the field), so there is nothing to reveal and nothing to bind:\n * the control is one always-editable input. A stored value shows as a\n * placeholder (the identification hint when configured, dots otherwise), typing\n * stages a replacement that stays visible until save (the reveal-once window\n * for generated secrets), and emptying the input reverts to keeping the stored\n * value. Clear is the isClearable × inside the input; an undo arrow follows a\n * clear because the cleared secret cannot be retyped from memory. Every action\n * lives inside the input row (or the label row for structural types), so the\n * field never grows past its native height.\n */\nexport const WriteOnlyField: React.FC<WriteOnlyFieldProps> = (props) => {\n\tif (props.placement === 'label-row') {\n\t\treturn <StructuralWriteOnly {...props} />\n\t}\n\treturn <InlineWriteOnly {...props} />\n}\n\nconst InlineWriteOnly: React.FC<WriteOnlyFieldProps> = ({\n\tclearable,\n\tcomponentKey,\n\tfield,\n\tgenerate,\n\thintPath,\n\tmaskDots,\n\tpath,\n\tplacement,\n\tsetPath,\n}) => {\n\tconst { t } = useTranslation()\n\tconst { setValue, value } = useField<unknown>({ path })\n\tconst isSet = useFormFields(([fields]) => fields?.[setPath]?.value === true)\n\tconst hint = useFormFields(([fields]) => {\n\t\tconst stored = fields?.[hintPath]?.value\n\t\treturn typeof stored === 'string' && stored.length > 0 ? stored : undefined\n\t})\n\tconst submitted = useFormSubmitted()\n\tconst invalid = useFormFields(([fields]) => fields?.[path]?.valid === false)\n\tconst showFieldError = submitted && invalid\n\tconst [cleared, setCleared] = useState(false)\n\tconst inputRef = useRef<HTMLInputElement | HTMLTextAreaElement | null>(null)\n\n\t// A successful save ends the reveal-once window: the staged plaintext (typed\n\t// or generated) is dropped and the field returns to its concealed face\n\t// immediately, not on the next page load. The edit view fires reportUpdate\n\t// only on success, so a failed save keeps the user's input. This write is\n\t// housekeeping, not an edit: disableModifyingForm keeps it from re-dirtying\n\t// the form Payload just marked clean, which would resurrect the\n\t// leave-without-saving warning on every navigation after a save.\n\tconst { mostRecentUpdate } = useDocumentEvents()\n\tconst lastUpdateAt = useRef(mostRecentUpdate?.updatedAt)\n\tuseEffect(() => {\n\t\tif (!mostRecentUpdate?.updatedAt || mostRecentUpdate.updatedAt === lastUpdateAt.current) {\n\t\t\treturn\n\t\t}\n\t\tlastUpdateAt.current = mostRecentUpdate.updatedAt\n\t\tconst resolved = applySave()\n\t\tsetValue(resolved.value, true)\n\t\tsetCleared(resolved.cleared)\n\t}, [mostRecentUpdate?.updatedAt, setValue])\n\n\tconst isNumber = componentKey === 'number'\n\tconst typed = isNumber ? typeof value === 'number' : typeof value === 'string' && value !== ''\n\n\tconst commit = useCallback(\n\t\t(outcome: { cleared: boolean; value: unknown }) => {\n\t\t\tsetValue(outcome.value)\n\t\t\tsetCleared(outcome.cleared)\n\t\t},\n\t\t[setValue]\n\t)\n\n\tconst handleChange = useCallback(\n\t\t(event: React.ChangeEvent<HTMLInputElement | HTMLTextAreaElement>) => {\n\t\t\tcommit(applyInput(event.target.value, { cleared, isNumber }))\n\t\t},\n\t\t[cleared, commit, isNumber]\n\t)\n\n\tconst handleBlur = useCallback(() => {\n\t\tconst outcome = applyBlur(value, { cleared, isNumber })\n\t\tif (outcome) {\n\t\t\tcommit(outcome)\n\t\t}\n\t}, [cleared, commit, isNumber, value])\n\n\tconst handleClear = useCallback(() => {\n\t\tconst outcome = applyClear({ cleared, clearable, isSet, typed })\n\t\tif (outcome) {\n\t\t\tcommit(outcome)\n\t\t}\n\t}, [cleared, clearable, commit, isSet, typed])\n\n\tconst handleUndo = useCallback(() => {\n\t\tcommit(applyUndo())\n\t}, [commit])\n\n\tconst runGenerate = useCallback(async () => {\n\t\tif (!generate) return\n\t\tcommit({ cleared: false, value: await generateSecret(generate) })\n\t\t// Select the fresh secret so the reveal-once window is one Cmd+C away.\n\t\trequestAnimationFrame(() => {\n\t\t\tinputRef.current?.focus()\n\t\t\tinputRef.current?.select?.()\n\t\t})\n\t}, [commit, generate])\n\n\t// Three unmistakable staged states: concealed face (text-colored hint/dots)\n\t// means keep, visible plaintext means replace, and the muted removal notice\n\t// means clear. Erasing typed text returns to whichever of the first and\n\t// last the user was in when they started typing.\n\tconst placeholder = typed\n\t\t? undefined\n\t\t: cleared\n\t\t\t? t(keys.clearedOnSave)\n\t\t\t: !isSet\n\t\t\t\t? typeof field.admin?.placeholder === 'string'\n\t\t\t\t\t? field.admin.placeholder\n\t\t\t\t\t: undefined\n\t\t\t\t: hint\n\t\t\t\t\t? formatHint(hint, maskDots)\n\t\t\t\t\t: dotString(maskDots)\n\n\tconst showClear = typed || (clearable && isSet && !cleared)\n\tconst inputId = `field-${path.replace(/\\./g, '__')}`\n\tconst displayValue = typed ? String(value) : ''\n\n\tconst actions = (\n\t\t<>\n\t\t\t{generate ? (\n\t\t\t\t<ActionButton\n\t\t\t\t\tattached={placement === 'attached'}\n\t\t\t\t\tkind=\"generate\"\n\t\t\t\t\tlabel={t(keys.generateValue)}\n\t\t\t\t\tonClick={runGenerate}\n\t\t\t\t/>\n\t\t\t) : null}\n\t\t\t{cleared && !typed ? (\n\t\t\t\t<ActionButton\n\t\t\t\t\tattached={placement === 'attached'}\n\t\t\t\t\tkind=\"undo\"\n\t\t\t\t\tlabel={t(keys.undoClear)}\n\t\t\t\t\tonClick={handleUndo}\n\t\t\t\t/>\n\t\t\t) : showClear ? (\n\t\t\t\t<ActionButton\n\t\t\t\t\tattached={placement === 'attached'}\n\t\t\t\t\tkind=\"clear\"\n\t\t\t\t\tlabel={t(keys.clearValue)}\n\t\t\t\t\tonClick={handleClear}\n\t\t\t\t/>\n\t\t\t) : null}\n\t\t</>\n\t)\n\n\t// A custom Field component short-circuits the path where Payload applies\n\t// admin.width and admin.style, so the field has to carry them itself.\n\tconst styles = useMemo(() => mergeFieldStyles(field), [field])\n\tconst isTextarea = componentKey === 'textarea'\n\tconst inputProps = {\n\t\tautoComplete: 'off',\n\t\tclassName: [\n\t\t\t'tenx-protected-field__wo-input',\n\t\t\t!typed && isSet && !cleared && 'tenx-protected-field__wo-input--set',\n\t\t]\n\t\t\t.filter(Boolean)\n\t\t\t.join(' '),\n\t\tid: inputId,\n\t\tname: path,\n\t\tonBlur: handleBlur,\n\t\tonChange: handleChange,\n\t\tplaceholder,\n\t\tvalue: displayValue,\n\t}\n\n\treturn (\n\t\t<div\n\t\t\tclassName={[\n\t\t\t\t'field-type',\n\t\t\t\tcomponentKey,\n\t\t\t\tshowFieldError && 'error',\n\t\t\t\t'tenx-protected-field',\n\t\t\t\tplacement === 'attached'\n\t\t\t\t\t? 'tenx-protected-field--attached'\n\t\t\t\t\t: 'tenx-protected-field--corner',\n\t\t\t]\n\t\t\t\t.filter(Boolean)\n\t\t\t\t.join(' ')}\n\t\t\tstyle={styles}\n\t\t>\n\t\t\t<FieldLabel\n\t\t\t\tlabel={field.label}\n\t\t\t\tlocalized={field.localized}\n\t\t\t\tpath={path}\n\t\t\t\trequired={field.required}\n\t\t\t/>\n\t\t\t<div className=\"field-type__wrap\">\n\t\t\t\t<FieldError path={path} />\n\t\t\t\t{isTextarea ? (\n\t\t\t\t\t<>\n\t\t\t\t\t\t<textarea\n\t\t\t\t\t\t\t{...inputProps}\n\t\t\t\t\t\t\tref={(el) => {\n\t\t\t\t\t\t\t\tinputRef.current = el\n\t\t\t\t\t\t\t}}\n\t\t\t\t\t\t\trows={field.admin?.rows ?? 4}\n\t\t\t\t\t\t/>\n\t\t\t\t\t\t<div className=\"tenx-protected-field__eye-wrap tenx-protected-field__eye-wrap--corner tenx-protected-field__actions--corner\">\n\t\t\t\t\t\t\t{actions}\n\t\t\t\t\t\t</div>\n\t\t\t\t\t</>\n\t\t\t\t) : (\n\t\t\t\t\t<div className=\"tenx-protected-field__attached-row\">\n\t\t\t\t\t\t<input\n\t\t\t\t\t\t\t{...inputProps}\n\t\t\t\t\t\t\tref={(el) => {\n\t\t\t\t\t\t\t\tinputRef.current = el\n\t\t\t\t\t\t\t}}\n\t\t\t\t\t\t\tinputMode={isNumber ? 'decimal' : undefined}\n\t\t\t\t\t\t\ttype={isNumber ? 'number' : componentKey === 'email' && typed ? 'email' : 'text'}\n\t\t\t\t\t\t/>\n\t\t\t\t\t\t<div className=\"tenx-protected-field__eye-wrap tenx-protected-field__eye-wrap--attached\">\n\t\t\t\t\t\t\t{actions}\n\t\t\t\t\t\t</div>\n\t\t\t\t\t</div>\n\t\t\t\t)}\n\t\t\t\t<FieldDescription description={field.admin?.description} path={path} />\n\t\t\t</div>\n\t\t</div>\n\t)\n}\n\n/**\n * Label-row variant for structural types (date, select, checkbox, code, json,\n * point, radio, and any hasMany surface): these have no single-line input to\n * type into, so replace goes through a pencil that mounts the real native\n * editor, with clear and undo beside it on the label line, exactly where the\n * masked eye sits.\n */\nconst StructuralWriteOnly: React.FC<WriteOnlyFieldProps> = ({\n\tclearable,\n\tfield,\n\tmaskDots,\n\tNative,\n\tnativeProps,\n\tpath,\n\tsetPath,\n}) => {\n\tconst { t } = useTranslation()\n\tconst { setValue, value } = useField<unknown>({ path })\n\tconst isSet = useFormFields(([fields]) => fields?.[setPath]?.value === true)\n\tconst [mode, setMode] = useState<'cleared' | 'editing' | 'idle'>('idle')\n\t// The concealed face stands in for the native field, so it has to carry the\n\t// same width; without it the field would change width as the mode changes.\n\tconst styles = useMemo(() => mergeFieldStyles(field), [field])\n\n\t// Mirror of the inline variant's save-conceal: a successful save drops any\n\t// staged edit and folds the field back to its concealed face, without\n\t// re-dirtying the form Payload just marked clean (disableModifyingForm).\n\tconst { mostRecentUpdate } = useDocumentEvents()\n\tconst lastUpdateAt = useRef(mostRecentUpdate?.updatedAt)\n\tuseEffect(() => {\n\t\tif (!mostRecentUpdate?.updatedAt || mostRecentUpdate.updatedAt === lastUpdateAt.current) {\n\t\t\treturn\n\t\t}\n\t\tlastUpdateAt.current = mostRecentUpdate.updatedAt\n\t\tsetValue(undefined, true)\n\t\tsetMode('idle')\n\t}, [mostRecentUpdate?.updatedAt, setValue])\n\n\tconst toggleEdit = useCallback(() => {\n\t\tif (mode === 'editing') {\n\t\t\t// Discard only what was staged: cancelling an untouched editor must not\n\t\t\t// mark the form modified.\n\t\t\tif (value !== undefined) {\n\t\t\t\tsetValue(undefined)\n\t\t\t}\n\t\t\tsetMode('idle')\n\t\t\treturn\n\t\t}\n\t\tsetMode('editing')\n\t}, [mode, setValue, value])\n\n\tconst clear = useCallback(() => {\n\t\tsetValue(null)\n\t\tsetMode('cleared')\n\t}, [setValue])\n\n\tconst undoClear = useCallback(() => {\n\t\tsetValue(undefined)\n\t\tsetMode('idle')\n\t}, [setValue])\n\n\tif (!isSet) {\n\t\treturn <Native {...nativeProps} />\n\t}\n\n\treturn (\n\t\t<div className=\"tenx-protected-field tenx-protected-field--label-row\">\n\t\t\t{mode === 'editing' ? (\n\t\t\t\t<Native {...nativeProps} />\n\t\t\t) : (\n\t\t\t\t<div className=\"field-type tenx-protected-field__wo-face\" style={styles}>\n\t\t\t\t\t<FieldLabel\n\t\t\t\t\t\tlabel={field.label}\n\t\t\t\t\t\tlocalized={field.localized}\n\t\t\t\t\t\tpath={path}\n\t\t\t\t\t\trequired={field.required}\n\t\t\t\t\t/>\n\t\t\t\t\t<div className=\"field-type__wrap\">\n\t\t\t\t\t\t<FieldError path={path} />\n\t\t\t\t\t\t<div className=\"tenx-protected-field__wo-face-box\">\n\t\t\t\t\t\t\t{mode === 'cleared' ? (\n\t\t\t\t\t\t\t\t<span className=\"tenx-protected-field__wo-face-msg\">{t(keys.clearedOnSave)}</span>\n\t\t\t\t\t\t\t) : (\n\t\t\t\t\t\t\t\t<span\n\t\t\t\t\t\t\t\t\taria-label={t(keys.writeOnlyValue)}\n\t\t\t\t\t\t\t\t\tclassName=\"tenx-protected-field__dots\"\n\t\t\t\t\t\t\t\t\trole=\"img\"\n\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t{dotString(maskDots)}\n\t\t\t\t\t\t\t\t</span>\n\t\t\t\t\t\t\t)}\n\t\t\t\t\t\t</div>\n\t\t\t\t\t\t<FieldDescription description={field.admin?.description} path={path} />\n\t\t\t\t\t</div>\n\t\t\t\t</div>\n\t\t\t)}\n\t\t\t<div className=\"tenx-protected-field__eye-wrap tenx-protected-field__eye-wrap--label-row\">\n\t\t\t\t{mode === 'cleared' ? (\n\t\t\t\t\t<ActionButton kind=\"undo\" label={t(keys.undoClear)} onClick={undoClear} />\n\t\t\t\t) : (\n\t\t\t\t\t<>\n\t\t\t\t\t\t<ActionButton\n\t\t\t\t\t\t\tkind=\"edit\"\n\t\t\t\t\t\t\tlabel={t(keys.replaceValue)}\n\t\t\t\t\t\t\tonClick={toggleEdit}\n\t\t\t\t\t\t\tpressed={mode === 'editing'}\n\t\t\t\t\t\t/>\n\t\t\t\t\t\t{clearable && mode !== 'editing' ? (\n\t\t\t\t\t\t\t<ActionButton kind=\"clear\" label={t(keys.clearValue)} onClick={clear} />\n\t\t\t\t\t\t) : null}\n\t\t\t\t\t</>\n\t\t\t\t)}\n\t\t\t</div>\n\t\t</div>\n\t)\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAkDA,MAAa,kBA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;YAAf,CACE,SAAS,YACT,oBAAC,QAAD,EAAQ,GAAI,YAAc,CAAA,IAE1B,qBAAC,OAAD;GAAK,WAAU;GAA2C,OAAO;aAAjE,CACC,oBAAC,YAAD;IACC,OAAO,MAAM;IACb,WAAW,MAAM;IACX;IACN,UAAU,MAAM;GAChB,CAAA,GACD,qBAAC,OAAD;IAAK,WAAU;cAAf;KACC,oBAAC,YAAD,EAAkB,KAAO,CAAA;KACzB,oBAAC,OAAD;MAAK,WAAU;gBACb,SAAS,YACT,oBAAC,QAAD;OAAM,WAAU;iBAAqC,EAAE,KAAK,aAAa;MAAQ,CAAA,IAEjF,oBAAC,QAAD;OACC,cAAY,EAAE,KAAK,cAAc;OACjC,WAAU;OACV,MAAK;iBAEJ,UAAU,QAAQ;MACd,CAAA;KAEH,CAAA;KACL,oBAAC,kBAAD;MAAkB,aAAa,MAAM,OAAO;MAAmB;KAAO,CAAA;IAClE;KACD;MAEN,oBAAC,OAAD;GAAK,WAAU;aACb,SAAS,YACT,oBAAC,cAAD;IAAc,MAAK;IAAO,OAAO,EAAE,KAAK,SAAS;IAAG,SAAS;GAAY,CAAA,IAEzE,qBAAA,YAAA,EAAA,UAAA,CACC,oBAAC,cAAD;IACC,MAAK;IACL,OAAO,EAAE,KAAK,YAAY;IAC1B,SAAS;IACT,SAAS,SAAS;GAClB,CAAA,GACA,aAAa,SAAS,YACtB,oBAAC,cAAD;IAAc,MAAK;IAAQ,OAAO,EAAE,KAAK,UAAU;IAAG,SAAS;GAAQ,CAAA,IACpE,IACH,EAAA,CAAA;EAEC,CAAA,CACD;;AAEP"}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
//#region src/fields/encrypted/components/writeOnlyIntent.ts
|
|
2
|
+
/** The staged form value after the input's text changes. */
|
|
3
|
+
const applyInput = (text, { cleared, isNumber }) => {
|
|
4
|
+
if (text === "") return {
|
|
5
|
+
cleared,
|
|
6
|
+
value: cleared ? null : void 0
|
|
7
|
+
};
|
|
8
|
+
if (isNumber) {
|
|
9
|
+
const parsed = Number.parseFloat(text);
|
|
10
|
+
return {
|
|
11
|
+
cleared,
|
|
12
|
+
value: Number.isNaN(parsed) ? cleared ? null : void 0 : parsed
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
return {
|
|
16
|
+
cleared,
|
|
17
|
+
value: text
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* The × action clears what is "in" the control: staged text first (returning
|
|
22
|
+
* to the lineage state), then the stored value (entering the undoable cleared
|
|
23
|
+
* state). Returns null when the action does not apply (nothing typed and
|
|
24
|
+
* nothing clearable to clear).
|
|
25
|
+
*/
|
|
26
|
+
const applyClear = ({ cleared, clearable, isSet, typed }) => {
|
|
27
|
+
if (typed) return {
|
|
28
|
+
cleared,
|
|
29
|
+
value: cleared ? null : void 0
|
|
30
|
+
};
|
|
31
|
+
if (clearable && isSet && !cleared) return {
|
|
32
|
+
cleared: true,
|
|
33
|
+
value: null
|
|
34
|
+
};
|
|
35
|
+
return null;
|
|
36
|
+
};
|
|
37
|
+
/** Undo leaves the cleared state, back to keeping the stored value. */
|
|
38
|
+
const applyUndo = () => ({
|
|
39
|
+
cleared: false,
|
|
40
|
+
value: void 0
|
|
41
|
+
});
|
|
42
|
+
/**
|
|
43
|
+
* Blur trims staged text: a pasted credential's trailing newline or space
|
|
44
|
+
* would otherwise be sealed into a broken secret nobody can ever read back to
|
|
45
|
+
* debug. Whitespace-only input counts as emptied. Returns null when nothing
|
|
46
|
+
* changes (numbers, untyped states, already-trimmed text).
|
|
47
|
+
*/
|
|
48
|
+
const applyBlur = (value, { cleared, isNumber }) => {
|
|
49
|
+
if (isNumber || typeof value !== "string" || value === "") return null;
|
|
50
|
+
const trimmed = value.trim();
|
|
51
|
+
if (trimmed === value) return null;
|
|
52
|
+
if (trimmed === "") return {
|
|
53
|
+
cleared,
|
|
54
|
+
value: cleared ? null : void 0
|
|
55
|
+
};
|
|
56
|
+
return {
|
|
57
|
+
cleared,
|
|
58
|
+
value: trimmed
|
|
59
|
+
};
|
|
60
|
+
};
|
|
61
|
+
/** A successful save resolves every staged intent; the server state is now truth. */
|
|
62
|
+
const applySave = () => ({
|
|
63
|
+
cleared: false,
|
|
64
|
+
value: void 0
|
|
65
|
+
});
|
|
66
|
+
//#endregion
|
|
67
|
+
export { applyBlur, applyClear, applyInput, applySave, applyUndo };
|
|
68
|
+
|
|
69
|
+
//# sourceMappingURL=writeOnlyIntent.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"writeOnlyIntent.js","names":[],"sources":["../../../../src/fields/encrypted/components/writeOnlyIntent.ts"],"sourcesContent":["/**\n * Intent state machine for the write-only editor, kept pure so every\n * transition is unit-testable. A write-only form value means:\n *\n * undefined keep the stored value (concealed face shows dots/hint)\n * null clear the stored value on save (\"will be removed\" face)\n * string replace the stored value with this plaintext (visible)\n *\n * `cleared` is the lineage flag: it survives typing, so erasing a half-typed\n * replacement returns the field to the state the user was in when they\n * started typing (keep, or their explicitly chosen clear), never silently\n * cancelling a clear.\n */\n\nexport interface WriteOnlyOutcome {\n\tcleared: boolean\n\tvalue: null | number | string | undefined\n}\n\nexport interface InputContext {\n\tcleared: boolean\n\tisNumber: boolean\n}\n\n/** The staged form value after the input's text changes. */\nexport const applyInput = (text: string, { cleared, isNumber }: InputContext): WriteOnlyOutcome => {\n\tif (text === '') {\n\t\t// Emptied input returns to the lineage state: a prior explicit clear\n\t\t// stays a clear; otherwise the stored value stays kept.\n\t\treturn { cleared, value: cleared ? null : undefined }\n\t}\n\tif (isNumber) {\n\t\tconst parsed = Number.parseFloat(text)\n\t\treturn { cleared, value: Number.isNaN(parsed) ? (cleared ? null : undefined) : parsed }\n\t}\n\treturn { cleared, value: text }\n}\n\nexport interface ClearContext {\n\tcleared: boolean\n\tclearable: boolean\n\tisSet: boolean\n\ttyped: boolean\n}\n\n/**\n * The × action clears what is \"in\" the control: staged text first (returning\n * to the lineage state), then the stored value (entering the undoable cleared\n * state). Returns null when the action does not apply (nothing typed and\n * nothing clearable to clear).\n */\nexport const applyClear = ({\n\tcleared,\n\tclearable,\n\tisSet,\n\ttyped,\n}: ClearContext): null | WriteOnlyOutcome => {\n\tif (typed) {\n\t\treturn { cleared, value: cleared ? null : undefined }\n\t}\n\tif (clearable && isSet && !cleared) {\n\t\treturn { cleared: true, value: null }\n\t}\n\treturn null\n}\n\n/** Undo leaves the cleared state, back to keeping the stored value. */\nexport const applyUndo = (): WriteOnlyOutcome => ({ cleared: false, value: undefined })\n\n/**\n * Blur trims staged text: a pasted credential's trailing newline or space\n * would otherwise be sealed into a broken secret nobody can ever read back to\n * debug. Whitespace-only input counts as emptied. Returns null when nothing\n * changes (numbers, untyped states, already-trimmed text).\n */\nexport const applyBlur = (\n\tvalue: unknown,\n\t{ cleared, isNumber }: InputContext\n): null | WriteOnlyOutcome => {\n\tif (isNumber || typeof value !== 'string' || value === '') {\n\t\treturn null\n\t}\n\tconst trimmed = value.trim()\n\tif (trimmed === value) {\n\t\treturn null\n\t}\n\tif (trimmed === '') {\n\t\treturn { cleared, value: cleared ? null : undefined }\n\t}\n\treturn { cleared, value: trimmed }\n}\n\n/** A successful save resolves every staged intent; the server state is now truth. */\nexport const applySave = (): WriteOnlyOutcome => ({ cleared: false, value: undefined })\n"],"mappings":";;AAyBA,MAAa,cAAc,MAAc,EAAE,SAAS,eAA+C;CAClG,IAAI,SAAS,IAGZ,OAAO;EAAE;EAAS,OAAO,UAAU,OAAO,KAAA;CAAU;CAErD,IAAI,UAAU;EACb,MAAM,SAAS,OAAO,WAAW,IAAI;EACrC,OAAO;GAAE;GAAS,OAAO,OAAO,MAAM,MAAM,IAAK,UAAU,OAAO,KAAA,IAAa;EAAO;CACvF;CACA,OAAO;EAAE;EAAS,OAAO;CAAK;AAC/B;;;;;;;AAeA,MAAa,cAAc,EAC1B,SACA,WACA,OACA,YAC4C;CAC5C,IAAI,OACH,OAAO;EAAE;EAAS,OAAO,UAAU,OAAO,KAAA;CAAU;CAErD,IAAI,aAAa,SAAS,CAAC,SAC1B,OAAO;EAAE,SAAS;EAAM,OAAO;CAAK;CAErC,OAAO;AACR;;AAGA,MAAa,mBAAqC;CAAE,SAAS;CAAO,OAAO,KAAA;AAAU;;;;;;;AAQrF,MAAa,aACZ,OACA,EAAE,SAAS,eACkB;CAC7B,IAAI,YAAY,OAAO,UAAU,YAAY,UAAU,IACtD,OAAO;CAER,MAAM,UAAU,MAAM,KAAK;CAC3B,IAAI,YAAY,OACf,OAAO;CAER,IAAI,YAAY,IACf,OAAO;EAAE;EAAS,OAAO,UAAU,OAAO,KAAA;CAAU;CAErD,OAAO;EAAE;EAAS,OAAO;CAAQ;AAClC;;AAGA,MAAa,mBAAqC;CAAE,SAAS;CAAO,OAAO,KAAA;AAAU"}
|
|
@@ -10,6 +10,15 @@ declare class AuthenticationFailedError extends Error {
|
|
|
10
10
|
readonly keyId: string;
|
|
11
11
|
constructor(keyId: string);
|
|
12
12
|
}
|
|
13
|
+
/**
|
|
14
|
+
* The ciphertext authenticated (correct key + AAD + tag) but the decrypted
|
|
15
|
+
* bytes are not valid JSON. Distinct from AuthenticationFailedError: auth
|
|
16
|
+
* succeeded, so this is non-retryable corruption, not a wrong key or AAD.
|
|
17
|
+
*/
|
|
18
|
+
declare class CorruptPlaintextError extends Error {
|
|
19
|
+
readonly keyId: string;
|
|
20
|
+
constructor(keyId: string, cause: unknown);
|
|
21
|
+
}
|
|
13
22
|
/**
|
|
14
23
|
* True only for a structurally valid wire string: prefix, 5 segments, base64url
|
|
15
24
|
* charset, and correct IV/tag byte lengths (a full parseWire, minus the GCM
|
|
@@ -19,5 +28,5 @@ declare class AuthenticationFailedError extends Error {
|
|
|
19
28
|
*/
|
|
20
29
|
declare const isSealed: (value: unknown) => value is string;
|
|
21
30
|
//#endregion
|
|
22
|
-
export { AuthenticationFailedError, MalformedCiphertextError, UnknownKeyIdError, isSealed };
|
|
31
|
+
export { AuthenticationFailedError, CorruptPlaintextError, MalformedCiphertextError, UnknownKeyIdError, isSealed };
|
|
23
32
|
//# sourceMappingURL=wire.d.ts.map
|
|
@@ -130,6 +130,6 @@ const unseal = (value, dataKeys, aadCandidates) => {
|
|
|
130
130
|
throw new AuthenticationFailedError(keyId);
|
|
131
131
|
};
|
|
132
132
|
//#endregion
|
|
133
|
-
export { AuthenticationFailedError, MalformedCiphertextError, UnknownKeyIdError, isSealed, parseWire, seal, unseal };
|
|
133
|
+
export { AuthenticationFailedError, CorruptPlaintextError, MalformedCiphertextError, UnknownKeyIdError, isSealed, parseWire, seal, unseal };
|
|
134
134
|
|
|
135
135
|
//# sourceMappingURL=wire.js.map
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { validateKeysConfig } from "./crypto/keys.js";
|
|
2
2
|
import { FIELDS_CUSTOM_KEY } from "./types.js";
|
|
3
|
-
import {
|
|
3
|
+
import { normalizeHint } from "./hint.js";
|
|
4
|
+
import { makeAfterReadHook, makeBeforeChangeHook, makeRichTextCiphertextHook, makeRichTextDecryptHook, makeRichTextSealHook, makeRichTextValidate, makeSetIndicatorHook } from "./hooks.js";
|
|
4
5
|
import { clampMaskDots } from "./maskDots.js";
|
|
6
|
+
import { normalizeGenerate } from "./generateSecret.js";
|
|
5
7
|
import { typescriptSchemaFor } from "./typescriptSchema.js";
|
|
6
8
|
import { makeComposedValidate, makeEffectiveValidator } from "./validators.js";
|
|
7
9
|
//#region src/fields/encrypted/encryptedField.ts
|
|
@@ -101,15 +103,29 @@ const buildRichTextFields = (args) => {
|
|
|
101
103
|
* `[virtualEditorField, ciphertextField]`. Spread into `fields: [...]`.
|
|
102
104
|
*/
|
|
103
105
|
const encryptedField = (source, options = {}) => {
|
|
104
|
-
const { keys, maskDots: maskDotsOption, onDecryptFailure, overrides, protection = "masked", queryable = false } = options;
|
|
106
|
+
const { aadScope, clearable, generate, hint, keys, maskDots: maskDotsOption, onDecryptFailure, overrides, protection = "masked", queryable = false } = options;
|
|
105
107
|
const maskDots = clampMaskDots(maskDotsOption);
|
|
108
|
+
const writeOnly = protection === "writeOnly";
|
|
106
109
|
if (keys) validateKeysConfig(keys);
|
|
110
|
+
if (aadScope !== void 0 && (aadScope === "" || aadScope.includes("."))) throw new Error(`@10x-media/fields: encryptedField '${source.name}': aadScope must be a non-empty string without '.' ('.' separates AAD components, so a dotted scope would make the binding ambiguous)`);
|
|
107
111
|
const hasMany = "hasMany" in source && source.hasMany === true;
|
|
108
112
|
const unique = "unique" in source && source.unique === true;
|
|
113
|
+
const required = "required" in source && source.required === true;
|
|
114
|
+
if (!writeOnly && (hint || generate || clearable !== void 0)) throw new Error(`@10x-media/fields: encryptedField '${source.name}': hint, generate, and clearable require protection 'writeOnly'`);
|
|
115
|
+
if (hint && hasMany) throw new Error(`@10x-media/fields: encryptedField '${source.name}': hint is not supported with hasMany (one hint cannot identify many values)`);
|
|
116
|
+
if (hint && source.type !== "text" && source.type !== "email") throw new Error(`@10x-media/fields: encryptedField '${source.name}': hint is only supported for text and email fields (a hint slices leading/trailing characters)`);
|
|
117
|
+
if (generate && source.type !== "text") throw new Error(`@10x-media/fields: encryptedField '${source.name}': generate is only supported for text fields`);
|
|
118
|
+
if (clearable === true && required) throw new Error(`@10x-media/fields: encryptedField '${source.name}': clearable cannot be enabled on a required field (clearing it could never save)`);
|
|
119
|
+
const normalizedHint = hint ? normalizeHint(hint, source.name) : void 0;
|
|
120
|
+
const normalizedGenerate = generate ? normalizeGenerate(generate, source.name) : void 0;
|
|
121
|
+
const resolvedClearable = writeOnly ? clearable ?? !required : false;
|
|
122
|
+
if (writeOnly && queryable) throw new Error(`@10x-media/fields: encryptedField '${source.name}': protection 'writeOnly' cannot be combined with queryable (the blind index is an equality oracle: anyone with list access could probe guesses of the secret)`);
|
|
123
|
+
if (writeOnly && source.type === "richText") throw new Error(`@10x-media/fields: encryptedField '${source.name}': protection 'writeOnly' is not supported for richText (editing rich text requires the client to see it; use 'masked' instead)`);
|
|
109
124
|
if (queryable && hasMany) throw new Error(`@10x-media/fields: encryptedField '${source.name}': queryable is not supported with hasMany`);
|
|
110
125
|
if (queryable && !QUERYABLE_SOURCE_TYPES.has(source.type)) throw new Error(`@10x-media/fields: encryptedField '${source.name}': queryable is only supported for text, email, and number fields (the blind index requires a scalar value; '${source.type}' is not scalar)`);
|
|
111
126
|
if (unique && !queryable) throw new Error(`@10x-media/fields: encryptedField '${source.name}': unique requires queryable: true (uniqueness is enforced on the blind index; every ciphertext is unique by construction)`);
|
|
112
127
|
const marker = {
|
|
128
|
+
aadScope,
|
|
113
129
|
bidxName: queryable ? `${source.name}_bidx` : void 0,
|
|
114
130
|
fieldName: source.name,
|
|
115
131
|
hasMany,
|
|
@@ -118,7 +134,11 @@ const encryptedField = (source, options = {}) => {
|
|
|
118
134
|
normalize: source.type === "email" ? "email" : "standard",
|
|
119
135
|
onDecryptFailure,
|
|
120
136
|
queryable,
|
|
121
|
-
|
|
137
|
+
setName: writeOnly ? `${source.name}_set` : void 0,
|
|
138
|
+
hint: normalizedHint,
|
|
139
|
+
hintName: normalizedHint ? `${source.name}_hint` : void 0,
|
|
140
|
+
sourceType: source.type,
|
|
141
|
+
writeOnly
|
|
122
142
|
};
|
|
123
143
|
if (source.type === "richText") return buildRichTextFields({
|
|
124
144
|
marker,
|
|
@@ -143,12 +163,20 @@ const encryptedField = (source, options = {}) => {
|
|
|
143
163
|
componentKey: source.type,
|
|
144
164
|
fieldPatch,
|
|
145
165
|
maskDots,
|
|
146
|
-
protection
|
|
166
|
+
protection,
|
|
167
|
+
...writeOnly ? {
|
|
168
|
+
clearable: resolvedClearable,
|
|
169
|
+
...normalizedGenerate ? { generate: normalizedGenerate } : {}
|
|
170
|
+
} : {}
|
|
147
171
|
},
|
|
148
172
|
path: "@10x-media/fields/client#ProtectedField"
|
|
149
173
|
},
|
|
150
|
-
...protection
|
|
151
|
-
clientProps: {
|
|
174
|
+
...protection !== "none" ? { Cell: {
|
|
175
|
+
clientProps: {
|
|
176
|
+
maskDots,
|
|
177
|
+
...writeOnly ? { setName: marker.setName } : {},
|
|
178
|
+
...marker.hintName ? { hintName: marker.hintName } : {}
|
|
179
|
+
},
|
|
152
180
|
path: "@10x-media/fields/rsc#ProtectedCell"
|
|
153
181
|
} } : {}
|
|
154
182
|
}
|
|
@@ -166,6 +194,35 @@ const encryptedField = (source, options = {}) => {
|
|
|
166
194
|
validate: makeComposedValidate(effective)
|
|
167
195
|
};
|
|
168
196
|
if (overrides) stored = overrides({ field: stored });
|
|
197
|
+
if (writeOnly) {
|
|
198
|
+
const setField = {
|
|
199
|
+
name: marker.setName,
|
|
200
|
+
type: "checkbox",
|
|
201
|
+
admin: {
|
|
202
|
+
disableListColumn: true,
|
|
203
|
+
disableListFilter: true,
|
|
204
|
+
hidden: true
|
|
205
|
+
},
|
|
206
|
+
hooks: { afterRead: [makeSetIndicatorHook(marker.fieldName)] },
|
|
207
|
+
virtual: true
|
|
208
|
+
};
|
|
209
|
+
if (!marker.hintName) return [stored, setField];
|
|
210
|
+
const hintField = {
|
|
211
|
+
name: marker.hintName,
|
|
212
|
+
type: "text",
|
|
213
|
+
admin: {
|
|
214
|
+
disableListColumn: true,
|
|
215
|
+
disableListFilter: true,
|
|
216
|
+
hidden: true
|
|
217
|
+
},
|
|
218
|
+
...marker.localized ? { localized: true } : {}
|
|
219
|
+
};
|
|
220
|
+
return [
|
|
221
|
+
stored,
|
|
222
|
+
setField,
|
|
223
|
+
hintField
|
|
224
|
+
];
|
|
225
|
+
}
|
|
169
226
|
if (!queryable) return [stored];
|
|
170
227
|
const bidx = {
|
|
171
228
|
name: marker.bidxName,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"encryptedField.js","names":[],"sources":["../../../src/fields/encrypted/encryptedField.ts"],"sourcesContent":["import type { Field, RichTextField, TextField } from 'payload'\nimport { validateKeysConfig } from './crypto/keys'\nimport {\n\tmakeAfterReadHook,\n\tmakeBeforeChangeHook,\n\tmakeRichTextCiphertextHook,\n\tmakeRichTextDecryptHook,\n\tmakeRichTextSealHook,\n\tmakeRichTextValidate,\n} from './hooks'\nimport { clampMaskDots } from './maskDots'\nimport {\n\ttype EncryptedFieldMarker,\n\ttype EncryptedFieldOptions,\n\ttype EncryptedFieldPatch,\n\ttype EncryptedProtection,\n\ttype EncryptedSourceField,\n\ttype EncryptedSourceType,\n\tFIELDS_CUSTOM_KEY,\n} from './types'\nimport { typescriptSchemaFor } from './typescriptSchema'\nimport { makeComposedValidate, makeEffectiveValidator } from './validators'\n\n/** Admin keys forwarded to the client patch so native components render correctly. */\nconst PATCH_ADMIN_KEYS = [\n\t'autoComplete',\n\t'date',\n\t'editorOptions',\n\t'language',\n\t'placeholder',\n\t'rows',\n\t'step',\n] as const\n\n/**\n * Field types whose plaintext is a single scalar the blind index can key on.\n * Blind indexes HMAC a normalized string/number; non-scalar values (objects,\n * tuples, arrays, booleans) have no meaningful equality index, so queryable is\n * rejected for them at the factory (complements the crypto-layer bidx guard).\n */\nconst QUERYABLE_SOURCE_TYPES: ReadonlySet<EncryptedSourceType> = new Set([\n\t'email',\n\t'number',\n\t'text',\n])\n\nconst buildFieldPatch = (source: EncryptedSourceField): EncryptedFieldPatch => {\n\tconst patch: EncryptedFieldPatch = { admin: {}, type: source.type }\n\tif ('hasMany' in source && source.hasMany === true) {\n\t\tpatch.hasMany = true\n\t}\n\tif ('options' in source) {\n\t\tpatch.options = source.options.map((option) => {\n\t\t\tif (typeof option === 'string') {\n\t\t\t\treturn { label: option, value: option }\n\t\t\t}\n\t\t\tif (typeof option.label !== 'string') {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`@10x-media/fields: encryptedField '${source.name}': option labels must be plain strings (labels travel to the admin client via clientProps)`\n\t\t\t\t)\n\t\t\t}\n\t\t\treturn { label: option.label, value: option.value }\n\t\t})\n\t}\n\tconst admin = (source.admin ?? {}) as Record<string, unknown>\n\tfor (const key of PATCH_ADMIN_KEYS) {\n\t\tif (admin[key] !== undefined) {\n\t\t\t;(patch.admin as Record<string, unknown>)[key] = admin[key]\n\t\t}\n\t}\n\treturn patch\n}\n\n/**\n * Emits the two-field pair for an encrypted richText source: a real, virtual\n * (never persisted) richText field carrying the app's full editor for editing,\n * synced by hooks to a hidden ciphertext text sibling that holds the data at\n * rest. A `type:'text'` field cannot trigger Payload's richText schema/import-map\n * pipeline, so a real richText field is required for full node parity; `virtual`\n * keeps its plaintext out of both DB adapters (they skip virtual fields).\n */\nconst buildRichTextFields = (args: {\n\tmarker: EncryptedFieldMarker\n\tprotection: EncryptedProtection\n\tsource: RichTextField\n}): Field[] => {\n\tconst { marker, protection, source } = args\n\tconst storedName = `${source.name}_encrypted`\n\tconst sourceAdmin = source.admin ?? {}\n\tconst virtual: RichTextField = {\n\t\t...source,\n\t\t// editor is inherited from config.editor (or source.editor if pinned) so the\n\t\t// app's complete node set mounts; readOnly:false is required or sanitize\n\t\t// forces a virtual affectsData field readOnly.\n\t\tadmin: {\n\t\t\t...sourceAdmin,\n\t\t\tcomponents: {\n\t\t\t\t...sourceAdmin.components,\n\t\t\t\t...(protection === 'masked'\n\t\t\t\t\t? {\n\t\t\t\t\t\t\tField: {\n\t\t\t\t\t\t\t\tpath: '@10x-media/fields/rsc#ProtectedRichText',\n\t\t\t\t\t\t\t\tserverProps: { protection },\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t}\n\t\t\t\t\t: {}),\n\t\t\t},\n\t\t\treadOnly: false,\n\t\t},\n\t\thooks: {\n\t\t\t...source.hooks,\n\t\t\tafterRead: [makeRichTextDecryptHook(marker, storedName), ...(source.hooks?.afterRead ?? [])],\n\t\t\tbeforeChange: [\n\t\t\t\t...(source.hooks?.beforeChange ?? []),\n\t\t\t\tmakeRichTextSealHook(marker, storedName),\n\t\t\t],\n\t\t},\n\t\ttype: 'richText',\n\t\tvalidate: makeRichTextValidate(),\n\t\tvirtual: true,\n\t}\n\tconst ciphertext: TextField = {\n\t\tname: storedName,\n\t\ttype: 'text',\n\t\t// admin.hidden (not top-level hidden) keeps the value readable by the virtual\n\t\t// field's decrypt hook; top-level hidden strips it early in afterRead and\n\t\t// races the decrypt read.\n\t\tadmin: { disableListColumn: true, disableListFilter: true, hidden: true },\n\t\tcustom: { [FIELDS_CUSTOM_KEY]: { encrypted: marker } },\n\t\thooks: { beforeChange: [makeRichTextCiphertextHook(marker)] },\n\t\t...(marker.localized ? { localized: true } : {}),\n\t}\n\treturn [virtual, ciphertext]\n}\n\n/**\n * Wraps a Payload field config (text, textarea, email, number, checkbox,\n * date, select, radio, code, json, point, richText) in transparent AES-256-GCM\n * encryption at rest. Returns `[storedField]`, or `[storedField, bidxField]`\n * when `queryable` adds a blind-index sibling; richText returns\n * `[virtualEditorField, ciphertextField]`. Spread into `fields: [...]`.\n */\nexport const encryptedField = (\n\tsource: EncryptedSourceField,\n\toptions: EncryptedFieldOptions = {}\n): Field[] => {\n\tconst {\n\t\tkeys,\n\t\tmaskDots: maskDotsOption,\n\t\tonDecryptFailure,\n\t\toverrides,\n\t\tprotection = 'masked',\n\t\tqueryable = false,\n\t} = options\n\tconst maskDots = clampMaskDots(maskDotsOption)\n\tif (keys) {\n\t\tvalidateKeysConfig(keys)\n\t}\n\tconst hasMany = 'hasMany' in source && source.hasMany === true\n\tconst unique = 'unique' in source && source.unique === true\n\tif (queryable && hasMany) {\n\t\tthrow new Error(\n\t\t\t`@10x-media/fields: encryptedField '${source.name}': queryable is not supported with hasMany`\n\t\t)\n\t}\n\tif (queryable && !QUERYABLE_SOURCE_TYPES.has(source.type)) {\n\t\tthrow new Error(\n\t\t\t`@10x-media/fields: encryptedField '${source.name}': queryable is only supported for text, email, and number fields (the blind index requires a scalar value; '${source.type}' is not scalar)`\n\t\t)\n\t}\n\tif (unique && !queryable) {\n\t\tthrow new Error(\n\t\t\t`@10x-media/fields: encryptedField '${source.name}': unique requires queryable: true (uniqueness is enforced on the blind index; every ciphertext is unique by construction)`\n\t\t)\n\t}\n\n\tconst marker: EncryptedFieldMarker = {\n\t\tbidxName: queryable ? `${source.name}_bidx` : undefined,\n\t\tfieldName: source.name,\n\t\thasMany,\n\t\tkeys,\n\t\tlocalized: 'localized' in source && source.localized === true,\n\t\tnormalize: source.type === 'email' ? 'email' : 'standard',\n\t\tonDecryptFailure,\n\t\tqueryable,\n\t\tsourceType: source.type,\n\t}\n\n\t// richText returns a virtual editor field plus a hidden ciphertext sibling.\n\t// `overrides` targets the scalar stored text column shape, so it does not apply\n\t// to the richText editor field and is intentionally skipped here.\n\tif (source.type === 'richText') {\n\t\treturn buildRichTextFields({ marker, protection, source })\n\t}\n\n\tconst effective = makeEffectiveValidator(source)\n\tconst fieldPatch = buildFieldPatch(source)\n\t// `source` is a union of 12 field types, so `source.admin` (and its\n\t// `components`) carries the union of every field's admin shape. Narrow to the\n\t// stored text field's admin type once here so the passthrough spreads below\n\t// typecheck against the correct target instead of the incompatible union.\n\tconst sourceAdmin = source.admin as TextField['admin']\n\n\t// Spread keeps admin passthrough (description, width, condition, readOnly,\n\t// position, custom labels) and access control on the stored field. Stripped:\n\t// hooks/validate/typescriptSchema/index/unique/editor (rebuilt or moved to the\n\t// bidx sibling); defaultValue (a static default emits a PLAINTEXT column\n\t// default in drizzle, i.e. plaintext at rest on an INSERT that omits the\n\t// column); and source-type-only constraints (options/min/max/min-maxLength)\n\t// which are inert on a text column and already enforced on plaintext by the\n\t// effective validator.\n\tconst {\n\t\tdefaultValue: _defaultValue,\n\t\teditor: _editor,\n\t\thooks: sourceHooks,\n\t\tindex: _index,\n\t\tmax: _max,\n\t\tmaxLength: _maxLength,\n\t\tmin: _min,\n\t\tminLength: _minLength,\n\t\toptions: _options,\n\t\ttypescriptSchema: _ts,\n\t\tunique: _unique,\n\t\tvalidate: _validate,\n\t\t...rest\n\t} = source as EncryptedSourceField & Record<string, unknown>\n\n\tlet stored: TextField = {\n\t\t...(rest as unknown as TextField),\n\t\ttype: 'text',\n\t\t...(hasMany ? { hasMany: true } : {}),\n\t\tadmin: {\n\t\t\t...sourceAdmin,\n\t\t\t// A non-queryable encrypted field can only ever filter its ciphertext\n\t\t\t// column (matching nothing), so keep it out of the list filter UI. A\n\t\t\t// queryable field stays filterable; the where-rewrite maps it to the\n\t\t\t// blind index.\n\t\t\t...(queryable ? {} : { disableListFilter: true }),\n\t\t\tcomponents: {\n\t\t\t\t...(sourceAdmin?.components ?? {}),\n\t\t\t\tField: {\n\t\t\t\t\tclientProps: { componentKey: source.type, fieldPatch, maskDots, protection },\n\t\t\t\t\tpath: '@10x-media/fields/client#ProtectedField',\n\t\t\t\t},\n\t\t\t\t...(protection === 'masked'\n\t\t\t\t\t? { Cell: { clientProps: { maskDots }, path: '@10x-media/fields/rsc#ProtectedCell' } }\n\t\t\t\t\t: {}),\n\t\t\t},\n\t\t},\n\t\tcustom: { ...source.custom, [FIELDS_CUSTOM_KEY]: { encrypted: marker } },\n\t\thooks: {\n\t\t\t...sourceHooks,\n\t\t\tafterRead: [makeAfterReadHook(marker), ...(sourceHooks?.afterRead ?? [])],\n\t\t\tbeforeChange: [...(sourceHooks?.beforeChange ?? []), makeBeforeChangeHook(marker)],\n\t\t},\n\t\ttypescriptSchema: typescriptSchemaFor(source),\n\t\tvalidate: makeComposedValidate(effective),\n\t}\n\n\tif (overrides) {\n\t\tstored = overrides({ field: stored })\n\t}\n\n\tif (!queryable) {\n\t\treturn [stored]\n\t}\n\n\t// admin.hidden (not top-level `hidden: true`) keeps the blind index in the\n\t// flattened schema so Payload's query-path validation grants it read\n\t// permission and the where-rewrite can target it; top-level hidden makes a\n\t// rewritten `equals` query fail with a 403. The keyed hash is stripped from\n\t// API responses by the plugin's collection afterRead (see withEncryptedQueryRewrite)\n\t// so the index value never leaves the server; exposing it lets a reader see\n\t// which rows share a value.\n\tconst bidx: TextField = {\n\t\tname: marker.bidxName as string,\n\t\ttype: 'text',\n\t\tadmin: { disableListColumn: true, disableListFilter: true, hidden: true },\n\t\tindex: true,\n\t\t...(marker.localized ? { localized: true } : {}),\n\t\t...(unique ? { unique: true } : {}),\n\t}\n\treturn [stored, bidx]\n}\n"],"mappings":";;;;;;;;AAw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js","names":[],"sources":["../../../src/fields/encrypted/encryptedField.ts"],"sourcesContent":["import type { CheckboxField, Field, RichTextField, TextField } from 'payload'\nimport { validateKeysConfig } from './crypto/keys'\nimport { normalizeGenerate } from './generateSecret'\nimport { normalizeHint } from './hint'\nimport {\n\tmakeAfterReadHook,\n\tmakeBeforeChangeHook,\n\tmakeRichTextCiphertextHook,\n\tmakeRichTextDecryptHook,\n\tmakeRichTextSealHook,\n\tmakeRichTextValidate,\n\tmakeSetIndicatorHook,\n} from './hooks'\nimport { clampMaskDots } from './maskDots'\nimport {\n\ttype EncryptedFieldMarker,\n\ttype EncryptedFieldOptions,\n\ttype EncryptedFieldPatch,\n\ttype EncryptedProtection,\n\ttype EncryptedSourceField,\n\ttype EncryptedSourceType,\n\tFIELDS_CUSTOM_KEY,\n} from './types'\nimport { typescriptSchemaFor } from './typescriptSchema'\nimport { makeComposedValidate, makeEffectiveValidator } from './validators'\n\n/** Admin keys forwarded to the client patch so native components render correctly. */\nconst PATCH_ADMIN_KEYS = [\n\t'autoComplete',\n\t'date',\n\t'editorOptions',\n\t'language',\n\t'placeholder',\n\t'rows',\n\t'step',\n] as const\n\n/**\n * Field types whose plaintext is a single scalar the blind index can key on.\n * Blind indexes HMAC a normalized string/number; non-scalar values (objects,\n * tuples, arrays, booleans) have no meaningful equality index, so queryable is\n * rejected for them at the factory (complements the crypto-layer bidx guard).\n */\nconst QUERYABLE_SOURCE_TYPES: ReadonlySet<EncryptedSourceType> = new Set([\n\t'email',\n\t'number',\n\t'text',\n])\n\nconst buildFieldPatch = (source: EncryptedSourceField): EncryptedFieldPatch => {\n\tconst patch: EncryptedFieldPatch = { admin: {}, type: source.type }\n\tif ('hasMany' in source && source.hasMany === true) {\n\t\tpatch.hasMany = true\n\t}\n\tif ('options' in source) {\n\t\tpatch.options = source.options.map((option) => {\n\t\t\tif (typeof option === 'string') {\n\t\t\t\treturn { label: option, value: option }\n\t\t\t}\n\t\t\tif (typeof option.label !== 'string') {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`@10x-media/fields: encryptedField '${source.name}': option labels must be plain strings (labels travel to the admin client via clientProps)`\n\t\t\t\t)\n\t\t\t}\n\t\t\treturn { label: option.label, value: option.value }\n\t\t})\n\t}\n\tconst admin = (source.admin ?? {}) as Record<string, unknown>\n\tfor (const key of PATCH_ADMIN_KEYS) {\n\t\tif (admin[key] !== undefined) {\n\t\t\t;(patch.admin as Record<string, unknown>)[key] = admin[key]\n\t\t}\n\t}\n\treturn patch\n}\n\n/**\n * Emits the two-field pair for an encrypted richText source: a real, virtual\n * (never persisted) richText field carrying the app's full editor for editing,\n * synced by hooks to a hidden ciphertext text sibling that holds the data at\n * rest. A `type:'text'` field cannot trigger Payload's richText schema/import-map\n * pipeline, so a real richText field is required for full node parity; `virtual`\n * keeps its plaintext out of both DB adapters (they skip virtual fields).\n */\nconst buildRichTextFields = (args: {\n\tmarker: EncryptedFieldMarker\n\tprotection: EncryptedProtection\n\tsource: RichTextField\n}): Field[] => {\n\tconst { marker, protection, source } = args\n\tconst storedName = `${source.name}_encrypted`\n\tconst sourceAdmin = source.admin ?? {}\n\tconst virtual: RichTextField = {\n\t\t...source,\n\t\t// editor is inherited from config.editor (or source.editor if pinned) so the\n\t\t// app's complete node set mounts; readOnly:false is required or sanitize\n\t\t// forces a virtual affectsData field readOnly.\n\t\tadmin: {\n\t\t\t...sourceAdmin,\n\t\t\tcomponents: {\n\t\t\t\t...sourceAdmin.components,\n\t\t\t\t...(protection === 'masked'\n\t\t\t\t\t? {\n\t\t\t\t\t\t\tField: {\n\t\t\t\t\t\t\t\tpath: '@10x-media/fields/rsc#ProtectedRichText',\n\t\t\t\t\t\t\t\tserverProps: { protection },\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t}\n\t\t\t\t\t: {}),\n\t\t\t},\n\t\t\treadOnly: false,\n\t\t},\n\t\thooks: {\n\t\t\t...source.hooks,\n\t\t\tafterRead: [makeRichTextDecryptHook(marker, storedName), ...(source.hooks?.afterRead ?? [])],\n\t\t\tbeforeChange: [\n\t\t\t\t...(source.hooks?.beforeChange ?? []),\n\t\t\t\tmakeRichTextSealHook(marker, storedName),\n\t\t\t],\n\t\t},\n\t\ttype: 'richText',\n\t\tvalidate: makeRichTextValidate(),\n\t\tvirtual: true,\n\t}\n\tconst ciphertext: TextField = {\n\t\tname: storedName,\n\t\ttype: 'text',\n\t\t// admin.hidden (not top-level hidden) keeps the value readable by the virtual\n\t\t// field's decrypt hook; top-level hidden strips it early in afterRead and\n\t\t// races the decrypt read.\n\t\tadmin: { disableListColumn: true, disableListFilter: true, hidden: true },\n\t\tcustom: { [FIELDS_CUSTOM_KEY]: { encrypted: marker } },\n\t\thooks: { beforeChange: [makeRichTextCiphertextHook(marker)] },\n\t\t...(marker.localized ? { localized: true } : {}),\n\t}\n\treturn [virtual, ciphertext]\n}\n\n/**\n * Wraps a Payload field config (text, textarea, email, number, checkbox,\n * date, select, radio, code, json, point, richText) in transparent AES-256-GCM\n * encryption at rest. Returns `[storedField]`, or `[storedField, bidxField]`\n * when `queryable` adds a blind-index sibling; richText returns\n * `[virtualEditorField, ciphertextField]`. Spread into `fields: [...]`.\n */\nexport const encryptedField = (\n\tsource: EncryptedSourceField,\n\toptions: EncryptedFieldOptions = {}\n): Field[] => {\n\tconst {\n\t\taadScope,\n\t\tclearable,\n\t\tgenerate,\n\t\thint,\n\t\tkeys,\n\t\tmaskDots: maskDotsOption,\n\t\tonDecryptFailure,\n\t\toverrides,\n\t\tprotection = 'masked',\n\t\tqueryable = false,\n\t} = options\n\tconst maskDots = clampMaskDots(maskDotsOption)\n\tconst writeOnly = protection === 'writeOnly'\n\tif (keys) {\n\t\tvalidateKeysConfig(keys)\n\t}\n\t// Checked here rather than at first write: buildAad rejects a dotted\n\t// component at seal time, and an empty scope would silently fall back to the\n\t// slug the option exists to escape.\n\tif (aadScope !== undefined && (aadScope === '' || aadScope.includes('.'))) {\n\t\tthrow new Error(\n\t\t\t`@10x-media/fields: encryptedField '${source.name}': aadScope must be a non-empty string without '.' ('.' separates AAD components, so a dotted scope would make the binding ambiguous)`\n\t\t)\n\t}\n\tconst hasMany = 'hasMany' in source && source.hasMany === true\n\tconst unique = 'unique' in source && source.unique === true\n\tconst required = 'required' in source && source.required === true\n\tif (!writeOnly && (hint || generate || clearable !== undefined)) {\n\t\tthrow new Error(\n\t\t\t`@10x-media/fields: encryptedField '${source.name}': hint, generate, and clearable require protection 'writeOnly'`\n\t\t)\n\t}\n\tif (hint && hasMany) {\n\t\tthrow new Error(\n\t\t\t`@10x-media/fields: encryptedField '${source.name}': hint is not supported with hasMany (one hint cannot identify many values)`\n\t\t)\n\t}\n\tif (hint && source.type !== 'text' && source.type !== 'email') {\n\t\tthrow new Error(\n\t\t\t`@10x-media/fields: encryptedField '${source.name}': hint is only supported for text and email fields (a hint slices leading/trailing characters)`\n\t\t)\n\t}\n\tif (generate && source.type !== 'text') {\n\t\tthrow new Error(\n\t\t\t`@10x-media/fields: encryptedField '${source.name}': generate is only supported for text fields`\n\t\t)\n\t}\n\tif (clearable === true && required) {\n\t\tthrow new Error(\n\t\t\t`@10x-media/fields: encryptedField '${source.name}': clearable cannot be enabled on a required field (clearing it could never save)`\n\t\t)\n\t}\n\tconst normalizedHint = hint ? normalizeHint(hint, source.name) : undefined\n\tconst normalizedGenerate = generate ? normalizeGenerate(generate, source.name) : undefined\n\tconst resolvedClearable = writeOnly ? (clearable ?? !required) : false\n\tif (writeOnly && queryable) {\n\t\tthrow new Error(\n\t\t\t`@10x-media/fields: encryptedField '${source.name}': protection 'writeOnly' cannot be combined with queryable (the blind index is an equality oracle: anyone with list access could probe guesses of the secret)`\n\t\t)\n\t}\n\tif (writeOnly && source.type === 'richText') {\n\t\tthrow new Error(\n\t\t\t`@10x-media/fields: encryptedField '${source.name}': protection 'writeOnly' is not supported for richText (editing rich text requires the client to see it; use 'masked' instead)`\n\t\t)\n\t}\n\tif (queryable && hasMany) {\n\t\tthrow new Error(\n\t\t\t`@10x-media/fields: encryptedField '${source.name}': queryable is not supported with hasMany`\n\t\t)\n\t}\n\tif (queryable && !QUERYABLE_SOURCE_TYPES.has(source.type)) {\n\t\tthrow new Error(\n\t\t\t`@10x-media/fields: encryptedField '${source.name}': queryable is only supported for text, email, and number fields (the blind index requires a scalar value; '${source.type}' is not scalar)`\n\t\t)\n\t}\n\tif (unique && !queryable) {\n\t\tthrow new Error(\n\t\t\t`@10x-media/fields: encryptedField '${source.name}': unique requires queryable: true (uniqueness is enforced on the blind index; every ciphertext is unique by construction)`\n\t\t)\n\t}\n\n\tconst marker: EncryptedFieldMarker = {\n\t\taadScope,\n\t\tbidxName: queryable ? `${source.name}_bidx` : undefined,\n\t\tfieldName: source.name,\n\t\thasMany,\n\t\tkeys,\n\t\tlocalized: 'localized' in source && source.localized === true,\n\t\tnormalize: source.type === 'email' ? 'email' : 'standard',\n\t\tonDecryptFailure,\n\t\tqueryable,\n\t\tsetName: writeOnly ? `${source.name}_set` : undefined,\n\t\thint: normalizedHint,\n\t\thintName: normalizedHint ? `${source.name}_hint` : undefined,\n\t\tsourceType: source.type,\n\t\twriteOnly,\n\t}\n\n\t// richText returns a virtual editor field plus a hidden ciphertext sibling.\n\t// `overrides` targets the scalar stored text column shape, so it does not apply\n\t// to the richText editor field and is intentionally skipped here.\n\tif (source.type === 'richText') {\n\t\treturn buildRichTextFields({ marker, protection, source })\n\t}\n\n\tconst effective = makeEffectiveValidator(source)\n\tconst fieldPatch = buildFieldPatch(source)\n\t// `source` is a union of 12 field types, so `source.admin` (and its\n\t// `components`) carries the union of every field's admin shape. Narrow to the\n\t// stored text field's admin type once here so the passthrough spreads below\n\t// typecheck against the correct target instead of the incompatible union.\n\tconst sourceAdmin = source.admin as TextField['admin']\n\n\t// Spread keeps admin passthrough (description, width, condition, readOnly,\n\t// position, custom labels) and access control on the stored field. Stripped:\n\t// hooks/validate/typescriptSchema/index/unique/editor (rebuilt or moved to the\n\t// bidx sibling); defaultValue (a static default emits a PLAINTEXT column\n\t// default in drizzle, i.e. plaintext at rest on an INSERT that omits the\n\t// column); and source-type-only constraints (options/min/max/min-maxLength)\n\t// which are inert on a text column and already enforced on plaintext by the\n\t// effective validator.\n\tconst {\n\t\tdefaultValue: _defaultValue,\n\t\teditor: _editor,\n\t\thooks: sourceHooks,\n\t\tindex: _index,\n\t\tmax: _max,\n\t\tmaxLength: _maxLength,\n\t\tmin: _min,\n\t\tminLength: _minLength,\n\t\toptions: _options,\n\t\ttypescriptSchema: _ts,\n\t\tunique: _unique,\n\t\tvalidate: _validate,\n\t\t...rest\n\t} = source as EncryptedSourceField & Record<string, unknown>\n\n\tlet stored: TextField = {\n\t\t...(rest as unknown as TextField),\n\t\ttype: 'text',\n\t\t...(hasMany ? { hasMany: true } : {}),\n\t\tadmin: {\n\t\t\t...sourceAdmin,\n\t\t\t// A non-queryable encrypted field can only ever filter its ciphertext\n\t\t\t// column (matching nothing), so keep it out of the list filter UI. A\n\t\t\t// queryable field stays filterable; the where-rewrite maps it to the\n\t\t\t// blind index.\n\t\t\t...(queryable ? {} : { disableListFilter: true }),\n\t\t\tcomponents: {\n\t\t\t\t...(sourceAdmin?.components ?? {}),\n\t\t\t\tField: {\n\t\t\t\t\tclientProps: {\n\t\t\t\t\t\tcomponentKey: source.type,\n\t\t\t\t\t\tfieldPatch,\n\t\t\t\t\t\tmaskDots,\n\t\t\t\t\t\tprotection,\n\t\t\t\t\t\t...(writeOnly\n\t\t\t\t\t\t\t? {\n\t\t\t\t\t\t\t\t\tclearable: resolvedClearable,\n\t\t\t\t\t\t\t\t\t...(normalizedGenerate ? { generate: normalizedGenerate } : {}),\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t: {}),\n\t\t\t\t\t},\n\t\t\t\t\tpath: '@10x-media/fields/client#ProtectedField',\n\t\t\t\t},\n\t\t\t\t...(protection !== 'none'\n\t\t\t\t\t? {\n\t\t\t\t\t\t\tCell: {\n\t\t\t\t\t\t\t\tclientProps: {\n\t\t\t\t\t\t\t\t\tmaskDots,\n\t\t\t\t\t\t\t\t\t...(writeOnly ? { setName: marker.setName } : {}),\n\t\t\t\t\t\t\t\t\t...(marker.hintName ? { hintName: marker.hintName } : {}),\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\tpath: '@10x-media/fields/rsc#ProtectedCell',\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t}\n\t\t\t\t\t: {}),\n\t\t\t},\n\t\t},\n\t\tcustom: { ...source.custom, [FIELDS_CUSTOM_KEY]: { encrypted: marker } },\n\t\thooks: {\n\t\t\t...sourceHooks,\n\t\t\tafterRead: [makeAfterReadHook(marker), ...(sourceHooks?.afterRead ?? [])],\n\t\t\tbeforeChange: [...(sourceHooks?.beforeChange ?? []), makeBeforeChangeHook(marker)],\n\t\t},\n\t\ttypescriptSchema: typescriptSchemaFor(source),\n\t\tvalidate: makeComposedValidate(effective),\n\t}\n\n\tif (overrides) {\n\t\tstored = overrides({ field: stored })\n\t}\n\n\t// Write-only reads strip the stored field from every response, so the admin\n\t// (and any API consumer) learns set-ness from this virtual sibling instead: a\n\t// never-persisted checkbox computed from the sealed sibling's presence. This\n\t// is the mode's one deliberate leak, existence only. admin.hidden keeps it in\n\t// form state (Payload renders it as a hidden input) without displaying it.\n\tif (writeOnly) {\n\t\tconst setField: CheckboxField = {\n\t\t\tname: marker.setName as string,\n\t\t\ttype: 'checkbox',\n\t\t\tadmin: { disableListColumn: true, disableListFilter: true, hidden: true },\n\t\t\thooks: { afterRead: [makeSetIndicatorHook(marker.fieldName)] },\n\t\t\tvirtual: true,\n\t\t}\n\t\tif (!marker.hintName) {\n\t\t\treturn [stored, setField]\n\t\t}\n\t\t// The hint is real stored data (derived at seal time in the same\n\t\t// beforeChange that encrypts, so the two can never drift) and is the\n\t\t// identification surface API consumers and the admin read; it is\n\t\t// deliberately NOT stripped from responses.\n\t\tconst hintField: TextField = {\n\t\t\tname: marker.hintName,\n\t\t\ttype: 'text',\n\t\t\tadmin: { disableListColumn: true, disableListFilter: true, hidden: true },\n\t\t\t...(marker.localized ? { localized: true } : {}),\n\t\t}\n\t\treturn [stored, setField, hintField]\n\t}\n\n\tif (!queryable) {\n\t\treturn [stored]\n\t}\n\n\t// admin.hidden (not top-level `hidden: true`) keeps the blind index in the\n\t// flattened schema so Payload's query-path validation grants it read\n\t// permission and the where-rewrite can target it; top-level hidden makes a\n\t// rewritten `equals` query fail with a 403. The keyed hash is stripped from\n\t// API responses by the plugin's collection afterRead (see withEncryptedQueryRewrite)\n\t// so the index value never leaves the server; exposing it lets a reader see\n\t// which rows share a value.\n\tconst bidx: TextField = {\n\t\tname: marker.bidxName as string,\n\t\ttype: 'text',\n\t\tadmin: { disableListColumn: true, disableListFilter: true, hidden: true },\n\t\tindex: true,\n\t\t...(marker.localized ? { localized: true } : {}),\n\t\t...(unique ? { unique: true } : {}),\n\t}\n\treturn [stored, bidx]\n}\n"],"mappings":";;;;;;;;;;AA2BA,MAAM,mBAAmB;CACxB;CACA;CACA;CACA;CACA;CACA;CACA;AACD;;;;;;;AAQA,MAAM,yBAA2D,IAAI,IAAI;CACxE;CACA;CACA;AACD,CAAC;AAED,MAAM,mBAAmB,WAAsD;CAC9E,MAAM,QAA6B;EAAE,OAAO,CAAC;EAAG,MAAM,OAAO;CAAK;CAClE,IAAI,aAAa,UAAU,OAAO,YAAY,MAC7C,MAAM,UAAU;CAEjB,IAAI,aAAa,QAChB,MAAM,UAAU,OAAO,QAAQ,KAAK,WAAW;EAC9C,IAAI,OAAO,WAAW,UACrB,OAAO;GAAE,OAAO;GAAQ,OAAO;EAAO;EAEvC,IAAI,OAAO,OAAO,UAAU,UAC3B,MAAM,IAAI,MACT,sCAAsC,OAAO,KAAK,2FACnD;EAED,OAAO;GAAE,OAAO,OAAO;GAAO,OAAO,OAAO;EAAM;CACnD,CAAC;CAEF,MAAM,QAAS,OAAO,SAAS,CAAC;CAChC,KAAK,MAAM,OAAO,kBACjB,IAAI,MAAM,SAAS,KAAA,GACjB,MAAO,MAAkC,OAAO,MAAM;CAGzD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kB,MAAM,GAAG,GAAI,aAAa,aAAa,CAAC,CAAE;GACxE,cAAc,CAAC,GAAI,aAAa,gBAAgB,CAAC,GAAI,qBAAqB,MAAM,CAAC;EAClF;EACA,kBAAkB,oBAAoB,MAAM;EAC5C,UAAU,qBAAqB,SAAS;CACzC;CAEA,IAAI,WACH,SAAS,UAAU,EAAE,OAAO,OAAO,CAAC;CAQrC,IAAI,WAAW;EACd,MAAM,WAA0B;GAC/B,MAAM,OAAO;GACb,MAAM;GACN,OAAO;IAAE,mBAAmB;IAAM,mBAAmB;IAAM,QAAQ;GAAK;GACxE,OAAO,EAAE,WAAW,CAAC,qBAAqB,OAAO,SAAS,CAAC,EAAE;GAC7D,SAAS;EACV;EACA,IAAI,CAAC,OAAO,UACX,OAAO,CAAC,QAAQ,QAAQ;EAMzB,MAAM,YAAuB;GAC5B,MAAM,OAAO;GACb,MAAM;GACN,OAAO;IAAE,mBAAmB;IAAM,mBAAmB;IAAM,QAAQ;GAAK;GACxE,GAAI,OAAO,YAAY,EAAE,WAAW,KAAK,IAAI,CAAC;EAC/C;EACA,OAAO;GAAC;GAAQ;GAAU;EAAS;CACpC;CAEA,IAAI,CAAC,WACJ,OAAO,CAAC,MAAM;CAUf,MAAM,OAAkB;EACvB,MAAM,OAAO;EACb,MAAM;EACN,OAAO;GAAE,mBAAmB;GAAM,mBAAmB;GAAM,QAAQ;EAAK;EACxE,OAAO;EACP,GAAI,OAAO,YAAY,EAAE,WAAW,KAAK,IAAI,CAAC;EAC9C,GAAI,SAAS,EAAE,QAAQ,KAAK,IAAI,CAAC;CAClC;CACA,OAAO,CAAC,QAAQ,IAAI;AACrB"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
//#region src/fields/encrypted/generateSecret.d.ts
|
|
2
|
+
interface NormalizedGenerate {
|
|
3
|
+
/** Deduplicated code points, so sampling is uniform and never splits a surrogate pair. */
|
|
4
|
+
charset: string[];
|
|
5
|
+
length: number;
|
|
6
|
+
prefix: string;
|
|
7
|
+
}
|
|
8
|
+
//#endregion
|
|
9
|
+
export { NormalizedGenerate };
|
|
10
|
+
//# sourceMappingURL=generateSecret.d.ts.map
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
//#region src/fields/encrypted/generateSecret.ts
|
|
2
|
+
const DEFAULT_CHARSET = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
|
|
3
|
+
const MIN_LENGTH = 8;
|
|
4
|
+
const MAX_LENGTH = 128;
|
|
5
|
+
const MIN_CHARSET = 10;
|
|
6
|
+
/** Byte-based rejection sampling can address at most 256 symbols. */
|
|
7
|
+
const MAX_CHARSET = 256;
|
|
8
|
+
/** Validates and normalizes a generate config; throws with the field name on misuse. */
|
|
9
|
+
const normalizeGenerate = (config, fieldName) => {
|
|
10
|
+
const given = config === true ? {} : config;
|
|
11
|
+
const length = given.length ?? 32;
|
|
12
|
+
if (!Number.isInteger(length) || length < MIN_LENGTH || length > MAX_LENGTH) throw new Error(`@10x-media/fields: encryptedField '${fieldName}': generate.length must be an integer in [${MIN_LENGTH}, ${MAX_LENGTH}]`);
|
|
13
|
+
const charset = [...new Set(given.charset ?? DEFAULT_CHARSET)];
|
|
14
|
+
if (charset.length < MIN_CHARSET || charset.length > MAX_CHARSET) throw new Error(`@10x-media/fields: encryptedField '${fieldName}': generate.charset needs ${MIN_CHARSET} to ${MAX_CHARSET} distinct characters`);
|
|
15
|
+
return {
|
|
16
|
+
charset,
|
|
17
|
+
length,
|
|
18
|
+
prefix: given.prefix ?? ""
|
|
19
|
+
};
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* Crypto-random secret for the admin Generate action. Rejection sampling over
|
|
23
|
+
* the deduplicated code-point array keeps the distribution uniform (the
|
|
24
|
+
* charset cap guarantees a non-zero acceptance window). Async so a future
|
|
25
|
+
* custom source (server-issued keys, a KMS) can slot in behind the same call
|
|
26
|
+
* site.
|
|
27
|
+
*/
|
|
28
|
+
const generateSecret = async ({ charset, length, prefix }) => {
|
|
29
|
+
const chars = [];
|
|
30
|
+
const limit = 256 - 256 % charset.length;
|
|
31
|
+
while (chars.length < length) {
|
|
32
|
+
const batch = new Uint8Array(length * 2);
|
|
33
|
+
globalThis.crypto.getRandomValues(batch);
|
|
34
|
+
for (const byte of batch) if (byte < limit && chars.length < length) chars.push(charset[byte % charset.length]);
|
|
35
|
+
}
|
|
36
|
+
return `${prefix}${chars.join("")}`;
|
|
37
|
+
};
|
|
38
|
+
//#endregion
|
|
39
|
+
export { generateSecret, normalizeGenerate };
|
|
40
|
+
|
|
41
|
+
//# sourceMappingURL=generateSecret.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generateSecret.js","names":[],"sources":["../../../src/fields/encrypted/generateSecret.ts"],"sourcesContent":["import type { EncryptedGenerateConfig } from './types'\n\nconst DEFAULT_CHARSET = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'\nconst MIN_LENGTH = 8\nconst MAX_LENGTH = 128\nconst MIN_CHARSET = 10\n/** Byte-based rejection sampling can address at most 256 symbols. */\nconst MAX_CHARSET = 256\n\nexport interface NormalizedGenerate {\n\t/** Deduplicated code points, so sampling is uniform and never splits a surrogate pair. */\n\tcharset: string[]\n\tlength: number\n\tprefix: string\n}\n\n/** Validates and normalizes a generate config; throws with the field name on misuse. */\nexport const normalizeGenerate = (\n\tconfig: true | EncryptedGenerateConfig,\n\tfieldName: string\n): NormalizedGenerate => {\n\tconst given = config === true ? {} : config\n\tconst length = given.length ?? 32\n\tif (!Number.isInteger(length) || length < MIN_LENGTH || length > MAX_LENGTH) {\n\t\tthrow new Error(\n\t\t\t`@10x-media/fields: encryptedField '${fieldName}': generate.length must be an integer in [${MIN_LENGTH}, ${MAX_LENGTH}]`\n\t\t)\n\t}\n\tconst charset = [...new Set(given.charset ?? DEFAULT_CHARSET)]\n\tif (charset.length < MIN_CHARSET || charset.length > MAX_CHARSET) {\n\t\tthrow new Error(\n\t\t\t`@10x-media/fields: encryptedField '${fieldName}': generate.charset needs ${MIN_CHARSET} to ${MAX_CHARSET} distinct characters`\n\t\t)\n\t}\n\treturn { charset, length, prefix: given.prefix ?? '' }\n}\n\n/**\n * Crypto-random secret for the admin Generate action. Rejection sampling over\n * the deduplicated code-point array keeps the distribution uniform (the\n * charset cap guarantees a non-zero acceptance window). Async so a future\n * custom source (server-issued keys, a KMS) can slot in behind the same call\n * site.\n */\nexport const generateSecret = async ({\n\tcharset,\n\tlength,\n\tprefix,\n}: NormalizedGenerate): Promise<string> => {\n\tconst chars: string[] = []\n\tconst limit = 256 - (256 % charset.length)\n\twhile (chars.length < length) {\n\t\tconst batch = new Uint8Array(length * 2)\n\t\tglobalThis.crypto.getRandomValues(batch)\n\t\tfor (const byte of batch) {\n\t\t\tif (byte < limit && chars.length < length) {\n\t\t\t\tchars.push(charset[byte % charset.length] as string)\n\t\t\t}\n\t\t}\n\t}\n\treturn `${prefix}${chars.join('')}`\n}\n"],"mappings":";AAEA,MAAM,kBAAkB;AACxB,MAAM,aAAa;AACnB,MAAM,aAAa;AACnB,MAAM,cAAc;;AAEpB,MAAM,cAAc;;AAUpB,MAAa,qBACZ,QACA,cACwB;CACxB,MAAM,QAAQ,WAAW,OAAO,CAAC,IAAI;CACrC,MAAM,SAAS,MAAM,UAAU;CAC/B,IAAI,CAAC,OAAO,UAAU,MAAM,KAAK,SAAS,cAAc,SAAS,YAChE,MAAM,IAAI,MACT,sCAAsC,UAAU,4CAA4C,WAAW,IAAI,WAAW,EACvH;CAED,MAAM,UAAU,CAAC,GAAG,IAAI,IAAI,MAAM,WAAW,eAAe,CAAC;CAC7D,IAAI,QAAQ,SAAS,eAAe,QAAQ,SAAS,aACpD,MAAM,IAAI,MACT,sCAAsC,UAAU,4BAA4B,YAAY,MAAM,YAAY,qBAC3G;CAED,OAAO;EAAE;EAAS;EAAQ,QAAQ,MAAM,UAAU;CAAG;AACtD;;;;;;;;AASA,MAAa,iBAAiB,OAAO,EACpC,SACA,QACA,aAC0C;CAC1C,MAAM,QAAkB,CAAC;CACzB,MAAM,QAAQ,MAAO,MAAM,QAAQ;CACnC,OAAO,MAAM,SAAS,QAAQ;EAC7B,MAAM,QAAQ,IAAI,WAAW,SAAS,CAAC;EACvC,WAAW,OAAO,gBAAgB,KAAK;EACvC,KAAK,MAAM,QAAQ,OAClB,IAAI,OAAO,SAAS,MAAM,SAAS,QAClC,MAAM,KAAK,QAAQ,OAAO,QAAQ,OAAiB;CAGtD;CACA,OAAO,GAAG,SAAS,MAAM,KAAK,EAAE;AACjC"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Canonical gap marker in the STORED hint (`sk_d····9d3f`). Storage stays
|
|
3
|
+
* compact and length-neutral; display layers swap it for the field's
|
|
4
|
+
* `maskDots` run via `formatHint` so the concealed span matches the masked
|
|
5
|
+
* aesthetic everywhere.
|
|
6
|
+
*/
|
|
7
|
+
const HINT_GAP = "····";
|
|
8
|
+
/** Validates and normalizes a hint config; throws with the field name on misuse. */
|
|
9
|
+
const normalizeHint = (config, fieldName) => {
|
|
10
|
+
const prefix = config.prefix ?? 0;
|
|
11
|
+
const suffix = config.suffix ?? 0;
|
|
12
|
+
const valid = (n) => Number.isInteger(n) && n >= 0;
|
|
13
|
+
if (!valid(prefix) || !valid(suffix) || prefix + suffix === 0) throw new Error(`@10x-media/fields: encryptedField '${fieldName}': hint needs non-negative integer prefix/suffix with at least one character`);
|
|
14
|
+
if (prefix + suffix > 32) throw new Error(`@10x-media/fields: encryptedField '${fieldName}': hint may expose at most 32 characters (got prefix ${prefix} + suffix ${suffix})`);
|
|
15
|
+
return {
|
|
16
|
+
prefix,
|
|
17
|
+
suffix
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* The stored identification hint for one plaintext, e.g. `sk_l····9d3f`, or
|
|
22
|
+
* null when the value is not a string, too short to hint without giving most
|
|
23
|
+
* of it away, or its exposed ends contain the gap glyph themselves (a `·` in
|
|
24
|
+
* the exposed text would blur where the concealed span starts, so such values
|
|
25
|
+
* store no hint; real credentials never contain U+00B7). Computed at seal
|
|
26
|
+
* time only; reads never touch the plaintext.
|
|
27
|
+
*
|
|
28
|
+
* Two length guards, because a hint's safety is a property of the value it
|
|
29
|
+
* slices rather than of the config that asks for the slice. The hidden
|
|
30
|
+
* remainder must be at least as long as the exposed ends, so a config sized
|
|
31
|
+
* for long tokens degrades to no hint on a short value instead of exposing
|
|
32
|
+
* half of it; and it must clear an absolute floor, since a short value stays
|
|
33
|
+
* guessable at any ratio. A config within the old 8-character ceiling can
|
|
34
|
+
* never fail the ratio it did not have to satisfy before: it already had to
|
|
35
|
+
* leave `HINT_MIN_HIDDEN` hidden, which was the same 8.
|
|
36
|
+
*/
|
|
37
|
+
const makeHint = (plaintext, hint) => {
|
|
38
|
+
if (typeof plaintext !== "string") return null;
|
|
39
|
+
const chars = [...plaintext];
|
|
40
|
+
const exposed = hint.prefix + hint.suffix;
|
|
41
|
+
const hidden = chars.length - exposed;
|
|
42
|
+
if (hidden < 8 || hidden < exposed) return null;
|
|
43
|
+
const start = hint.prefix > 0 ? chars.slice(0, hint.prefix).join("") : "";
|
|
44
|
+
const end = hint.suffix > 0 ? chars.slice(-hint.suffix).join("") : "";
|
|
45
|
+
if (start.includes("·") || end.includes("·")) return null;
|
|
46
|
+
return `${start}${HINT_GAP}${end}`;
|
|
47
|
+
};
|
|
48
|
+
/**
|
|
49
|
+
* Renders a stored hint for display: the canonical gap becomes the `maskDots`
|
|
50
|
+
* bullet run, so `sk_d····9d3f` with maskDots 8 shows as `sk_d••••••••9d3f`.
|
|
51
|
+
*
|
|
52
|
+
* The run is additive: the hint's ends wrap the exact bullet run a hint-less
|
|
53
|
+
* concealed value shows, never fewer. One count everywhere is what makes the
|
|
54
|
+
* bullets legible as "concealed" rather than as information, and it keeps the
|
|
55
|
+
* count a pure presentation choice, decided by `maskDots` alone. A hint too
|
|
56
|
+
* wide for its container is the container's problem, and both the input and
|
|
57
|
+
* the list cell clamp with an ellipsis rather than letting the run absorb it.
|
|
58
|
+
*/
|
|
59
|
+
const formatHint = (hint, dots) => {
|
|
60
|
+
const index = hint.indexOf(HINT_GAP);
|
|
61
|
+
if (index === -1) return hint;
|
|
62
|
+
return `${hint.slice(0, index)}${"•".repeat(Math.max(1, Math.trunc(dots)))}${hint.slice(index + 4)}`;
|
|
63
|
+
};
|
|
64
|
+
//#endregion
|
|
65
|
+
export { formatHint, makeHint, normalizeHint };
|
|
66
|
+
|
|
67
|
+
//# sourceMappingURL=hint.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hint.js","names":[],"sources":["../../../src/fields/encrypted/hint.ts"],"sourcesContent":["import type { EncryptedHintConfig } from './types'\n\n/**\n * Ceiling on the plaintext characters a hint may expose across both ends.\n *\n * A ceiling alone is a poor safety control, because what makes a hint safe is\n * how much of the value stays hidden, not how much shows: 32 characters of a\n * 128-character token is nothing, and 32 of a 40-character one is most of it.\n * `makeHint` enforces the ratio, and this is the blunt upper bound on top of\n * it, high enough for the prefixed formats credentials actually use\n * (`sk_live_`, `whsec_`, `ghp_`, `xoxb-`), where a fixed budget would be spent\n * on a constant that identifies nothing.\n */\nexport const HINT_MAX_CHARS = 32\n/**\n * Floor on the characters a hint must leave hidden, whatever the ratio allows.\n * Below this a short value is guessable however small a fraction is exposed.\n */\nexport const HINT_MIN_HIDDEN = 8\n\n/**\n * Canonical gap marker in the STORED hint (`sk_d····9d3f`). Storage stays\n * compact and length-neutral; display layers swap it for the field's\n * `maskDots` run via `formatHint` so the concealed span matches the masked\n * aesthetic everywhere.\n */\nexport const HINT_GAP = '····'\n\nexport interface NormalizedHint {\n\tprefix: number\n\tsuffix: number\n}\n\n/** Validates and normalizes a hint config; throws with the field name on misuse. */\nexport const normalizeHint = (config: EncryptedHintConfig, fieldName: string): NormalizedHint => {\n\tconst prefix = config.prefix ?? 0\n\tconst suffix = config.suffix ?? 0\n\tconst valid = (n: number) => Number.isInteger(n) && n >= 0\n\tif (!valid(prefix) || !valid(suffix) || prefix + suffix === 0) {\n\t\tthrow new Error(\n\t\t\t`@10x-media/fields: encryptedField '${fieldName}': hint needs non-negative integer prefix/suffix with at least one character`\n\t\t)\n\t}\n\tif (prefix + suffix > HINT_MAX_CHARS) {\n\t\tthrow new Error(\n\t\t\t`@10x-media/fields: encryptedField '${fieldName}': hint may expose at most ${HINT_MAX_CHARS} characters (got prefix ${prefix} + suffix ${suffix})`\n\t\t)\n\t}\n\treturn { prefix, suffix }\n}\n\n/**\n * The stored identification hint for one plaintext, e.g. `sk_l····9d3f`, or\n * null when the value is not a string, too short to hint without giving most\n * of it away, or its exposed ends contain the gap glyph themselves (a `·` in\n * the exposed text would blur where the concealed span starts, so such values\n * store no hint; real credentials never contain U+00B7). Computed at seal\n * time only; reads never touch the plaintext.\n *\n * Two length guards, because a hint's safety is a property of the value it\n * slices rather than of the config that asks for the slice. The hidden\n * remainder must be at least as long as the exposed ends, so a config sized\n * for long tokens degrades to no hint on a short value instead of exposing\n * half of it; and it must clear an absolute floor, since a short value stays\n * guessable at any ratio. A config within the old 8-character ceiling can\n * never fail the ratio it did not have to satisfy before: it already had to\n * leave `HINT_MIN_HIDDEN` hidden, which was the same 8.\n */\nexport const makeHint = (plaintext: unknown, hint: NormalizedHint): string | null => {\n\tif (typeof plaintext !== 'string') {\n\t\treturn null\n\t}\n\t// Code points, not UTF-16 units: slicing units can split a surrogate pair\n\t// into an unpaired half, and unit counts make an astral-character value look\n\t// twice as long as it is, overstating what the guards think stays hidden.\n\tconst chars = [...plaintext]\n\tconst exposed = hint.prefix + hint.suffix\n\tconst hidden = chars.length - exposed\n\tif (hidden < HINT_MIN_HIDDEN || hidden < exposed) {\n\t\treturn null\n\t}\n\tconst start = hint.prefix > 0 ? chars.slice(0, hint.prefix).join('') : ''\n\tconst end = hint.suffix > 0 ? chars.slice(-hint.suffix).join('') : ''\n\tif (start.includes('·') || end.includes('·')) {\n\t\treturn null\n\t}\n\treturn `${start}${HINT_GAP}${end}`\n}\n\n/**\n * Renders a stored hint for display: the canonical gap becomes the `maskDots`\n * bullet run, so `sk_d····9d3f` with maskDots 8 shows as `sk_d••••••••9d3f`.\n *\n * The run is additive: the hint's ends wrap the exact bullet run a hint-less\n * concealed value shows, never fewer. One count everywhere is what makes the\n * bullets legible as \"concealed\" rather than as information, and it keeps the\n * count a pure presentation choice, decided by `maskDots` alone. A hint too\n * wide for its container is the container's problem, and both the input and\n * the list cell clamp with an ellipsis rather than letting the run absorb it.\n */\nexport const formatHint = (hint: string, dots: number): string => {\n\tconst index = hint.indexOf(HINT_GAP)\n\tif (index === -1) {\n\t\treturn hint\n\t}\n\treturn `${hint.slice(0, index)}${'•'.repeat(Math.max(1, Math.trunc(dots)))}${hint.slice(index + HINT_GAP.length)}`\n}\n"],"mappings":";;;;;;AA0BA,MAAa,WAAW;;AAQxB,MAAa,iBAAiB,QAA6B,cAAsC;CAChG,MAAM,SAAS,OAAO,UAAU;CAChC,MAAM,SAAS,OAAO,UAAU;CAChC,MAAM,SAAS,MAAc,OAAO,UAAU,CAAC,KAAK,KAAK;CACzD,IAAI,CAAC,MAAM,MAAM,KAAK,CAAC,MAAM,MAAM,KAAK,SAAS,WAAW,GAC3D,MAAM,IAAI,MACT,sCAAsC,UAAU,6EACjD;CAED,IAAI,SAAS,SAAA,IACZ,MAAM,IAAI,MACT,sCAAsC,UAAU,uDAAsE,OAAO,YAAY,OAAO,EACjJ;CAED,OAAO;EAAE;EAAQ;CAAO;AACzB;;;;;;;;;;;;;;;;;;AAmBA,MAAa,YAAY,WAAoB,SAAwC;CACpF,IAAI,OAAO,cAAc,UACxB,OAAO;CAKR,MAAM,QAAQ,CAAC,GAAG,SAAS;CAC3B,MAAM,UAAU,KAAK,SAAS,KAAK;CACnC,MAAM,SAAS,MAAM,SAAS;CAC9B,IAAI,SAAA,KAA4B,SAAS,SACxC,OAAO;CAER,MAAM,QAAQ,KAAK,SA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