@10x-media/fields 0.1.0-beta.4 → 0.1.0-beta.5
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 +32 -0
- package/README.md +2 -0
- package/dist/exports/encrypted.d.ts +7 -4
- package/dist/exports/encrypted.js +6 -3
- 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/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/dist/translations/de.js +8 -1
- package/dist/translations/de.js.map +1 -1
- package/dist/translations/en.js +8 -1
- package/dist/translations/en.js.map +1 -1
- package/dist/translations/keys.d.ts +7 -0
- package/dist/translations/keys.js +8 -1
- package/dist/translations/keys.js.map +1 -1
- package/package.json +6 -6
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ProtectedField.js","names":[],"sources":["../../../../src/fields/encrypted/components/ProtectedField.tsx"],"sourcesContent":["'use client'\nimport {\n\tCheckboxField,\n\tCodeField,\n\tDateTimeField,\n\tEmailField,\n\tJSONField,\n\tNumberField,\n\tPointField,\n\tRadioGroupField,\n\tSelectField,\n\tTextareaField,\n\tTextField,\n\tuseFormFields,\n} from '@payloadcms/ui'\nimport type { TextFieldClientProps } from 'payload'\nimport type React from 'react'\nimport { useMemo, useState } from 'react'\nimport { clampMaskDots } from '../maskDots'\nimport type { EncryptedFieldPatch, EncryptedProtection } from '../types'\nimport { EncryptedInput } from './EncryptedInput'\nimport { EncryptedTextarea } from './EncryptedTextarea'\nimport type { EncryptedFieldConfig } from './placement'\nimport { placementFor } from './placement'\nimport { StructuralField } from './StructuralField'\nimport './ProtectedField.css'\n\n/**\n * Native components accept per-type client props; dispatch is by runtime\n * componentKey, so the map is typed at the erased component boundary.\n */\ntype AnyFieldComponent = React.ComponentType<Record<string, unknown>>\n\nconst NATIVE: Record<string, AnyFieldComponent> = {\n\tcheckbox: CheckboxField as AnyFieldComponent,\n\tcode: CodeField as AnyFieldComponent,\n\tdate: DateTimeField as AnyFieldComponent,\n\temail: EmailField as AnyFieldComponent,\n\tjson: JSONField as AnyFieldComponent,\n\tnumber: NumberField as AnyFieldComponent,\n\tpoint: PointField as AnyFieldComponent,\n\tradio: RadioGroupField as AnyFieldComponent,\n\tselect: SelectField as AnyFieldComponent,\n\ttext: TextField as AnyFieldComponent,\n\ttextarea: TextareaField as AnyFieldComponent,\n}\n\nexport interface ProtectedFieldProps extends TextFieldClientProps {\n\tcomponentKey: string\n\tfieldPatch: EncryptedFieldPatch\n\tmaskDots?: number\n\tprotection: EncryptedProtection\n}\n\n/**\n * A field with no stored content has nothing to conceal, so it renders unmasked\n * (the plain native control). Captured once at mount, so characters typed into a\n * field that started empty stay visible and the field never flips to masked\n * mid-entry; a field that already holds content is masked until revealed.\n */\nconst isEmptyValue = (value: unknown): boolean => {\n\tif (value == null || value === '') {\n\t\treturn true\n\t}\n\tif (Array.isArray(value)) {\n\t\treturn value.length === 0 || value.every((item) => item == null)\n\t}\n\treturn false\n}\n\n/**\n * Single admin dispatcher for scalar and structural encrypted fields (richText\n * is its own virtual-editor field pair, wired to ProtectedRichText). Each type\n * renders as its native variant with a fixed run of dots while concealed, and an\n * inline eye toggle that swaps to the real editable native component on reveal.\n * The fieldPatch restores type-specific config (options, hasMany, date admin) on\n * the revealed component.\n *\n * Masking is visual-only by design. afterRead decrypts server-side, so the\n * field's form value is already plaintext regardless of the mask, and no masked\n * facsimile binds to that value. Two accepted consequences: (a) the plaintext\n * reaches an authorized admin's browser, since that admin already has field read\n * access and masking only stops casual over-the-shoulder display; (b) saving an\n * unchanged document re-seals with a fresh IV (version churn), because the form\n * holds plaintext, not the stored ciphertext.\n */\nexport const ProtectedField: React.FC<ProtectedFieldProps> = (props) => {\n\tconst { componentKey, field, fieldPatch, path, protection } = props\n\tconst maskDots = clampMaskDots(props.maskDots)\n\tconst startedEmptyNow = useFormFields(([fields]) => isEmptyValue(fields?.[path]?.value))\n\tconst [startedEmpty] = useState(startedEmptyNow)\n\n\tconst patchedField = useMemo(\n\t\t() => ({\n\t\t\t...field,\n\t\t\t...fieldPatch,\n\t\t\tadmin: { ...field.admin, ...fieldPatch.admin },\n\t\t}),\n\t\t[field, fieldPatch]\n\t)\n\n\tconst Native = NATIVE[componentKey] ?? (TextField as AnyFieldComponent)\n\tconst nativeProps = { ...(props as unknown as Record<string, unknown>), field: patchedField }\n\n\tif (protection === 'none' || startedEmpty) {\n\t\treturn <Native {...nativeProps} />\n\t}\n\n\tconst faceField = patchedField as unknown as EncryptedFieldConfig\n\tconst hasMany = fieldPatch.hasMany === true\n\tconst placement = placementFor(componentKey, hasMany)\n\n\tif (placement === 'attached') {\n\t\treturn (\n\t\t\t<EncryptedInput\n\t\t\t\tfield={faceField}\n\t\t\t\tkind={componentKey as 'email' | 'number' | 'text'}\n\t\t\t\tmaskDots={maskDots}\n\t\t\t\tpath={path}\n\t\t\t/>\n\t\t)\n\t}\n\n\tif (placement === 'corner') {\n\t\treturn <EncryptedTextarea field={faceField} maskDots={maskDots} path={path} />\n\t}\n\n\treturn (\n\t\t<StructuralField\n\t\t\tcomponentKey={componentKey}\n\t\t\tfield={faceField}\n\t\t\tmaskDots={maskDots}\n\t\t\tNative={Native}\n\t\t\tnativeProps={nativeProps}\n\t\t\tpath={path}\n\t\t/>\n\t)\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"ProtectedField.js","names":[],"sources":["../../../../src/fields/encrypted/components/ProtectedField.tsx"],"sourcesContent":["'use client'\nimport {\n\tCheckboxField,\n\tCodeField,\n\tDateTimeField,\n\tEmailField,\n\tJSONField,\n\tNumberField,\n\tPointField,\n\tRadioGroupField,\n\tSelectField,\n\tTextareaField,\n\tTextField,\n\tuseFormFields,\n} from '@payloadcms/ui'\nimport type { TextFieldClientProps } from 'payload'\nimport type React from 'react'\nimport { useMemo, useState } from 'react'\nimport type { NormalizedGenerate } from '../generateSecret'\nimport { clampMaskDots } from '../maskDots'\nimport type { EncryptedFieldPatch, EncryptedProtection } from '../types'\nimport { EncryptedInput } from './EncryptedInput'\nimport { EncryptedTextarea } from './EncryptedTextarea'\nimport type { EncryptedFieldConfig } from './placement'\nimport { placementFor } from './placement'\nimport { StructuralField } from './StructuralField'\nimport { WriteOnlyField } from './WriteOnlyField'\nimport './ProtectedField.css'\n\n/**\n * Native components accept per-type client props; dispatch is by runtime\n * componentKey, so the map is typed at the erased component boundary.\n */\ntype AnyFieldComponent = React.ComponentType<Record<string, unknown>>\n\nconst NATIVE: Record<string, AnyFieldComponent> = {\n\tcheckbox: CheckboxField as AnyFieldComponent,\n\tcode: CodeField as AnyFieldComponent,\n\tdate: DateTimeField as AnyFieldComponent,\n\temail: EmailField as AnyFieldComponent,\n\tjson: JSONField as AnyFieldComponent,\n\tnumber: NumberField as AnyFieldComponent,\n\tpoint: PointField as AnyFieldComponent,\n\tradio: RadioGroupField as AnyFieldComponent,\n\tselect: SelectField as AnyFieldComponent,\n\ttext: TextField as AnyFieldComponent,\n\ttextarea: TextareaField as AnyFieldComponent,\n}\n\nexport interface ProtectedFieldProps extends TextFieldClientProps {\n\tclearable?: boolean\n\tcomponentKey: string\n\tfieldPatch: EncryptedFieldPatch\n\tgenerate?: NormalizedGenerate\n\tmaskDots?: number\n\tprotection: EncryptedProtection\n}\n\n/**\n * A field with no stored content has nothing to conceal, so it renders unmasked\n * (the plain native control). Captured once at mount, so characters typed into a\n * field that started empty stay visible and the field never flips to masked\n * mid-entry; a field that already holds content is masked until revealed.\n */\nconst isEmptyValue = (value: unknown): boolean => {\n\tif (value == null || value === '') {\n\t\treturn true\n\t}\n\tif (Array.isArray(value)) {\n\t\treturn value.length === 0 || value.every((item) => item == null)\n\t}\n\treturn false\n}\n\n/**\n * Single admin dispatcher for scalar and structural encrypted fields (richText\n * is its own virtual-editor field pair, wired to ProtectedRichText). Each type\n * renders as its native variant with a fixed run of dots while concealed, and an\n * inline eye toggle that swaps to the real editable native component on reveal.\n * The fieldPatch restores type-specific config (options, hasMany, date admin) on\n * the revealed component.\n *\n * Masking is visual-only by design. afterRead decrypts server-side, so the\n * field's form value is already plaintext regardless of the mask, and no masked\n * facsimile binds to that value. Two accepted consequences: (a) the plaintext\n * reaches an authorized admin's browser, since that admin already has field read\n * access and masking only stops casual over-the-shoulder display; (b) saving an\n * unchanged document re-seals with a fresh IV (version churn), because the form\n * holds plaintext, not the stored ciphertext.\n */\nexport const ProtectedField: React.FC<ProtectedFieldProps> = (props) => {\n\tconst { componentKey, field, fieldPatch, path, protection } = props\n\tconst maskDots = clampMaskDots(props.maskDots)\n\tconst startedEmptyNow = useFormFields(([fields]) => isEmptyValue(fields?.[path]?.value))\n\tconst [startedEmpty] = useState(startedEmptyNow)\n\n\tconst patchedField = useMemo(\n\t\t() => ({\n\t\t\t...field,\n\t\t\t...fieldPatch,\n\t\t\tadmin: { ...field.admin, ...fieldPatch.admin },\n\t\t}),\n\t\t[field, fieldPatch]\n\t)\n\n\tconst Native = NATIVE[componentKey] ?? (TextField as AnyFieldComponent)\n\tconst nativeProps = { ...(props as unknown as Record<string, unknown>), field: patchedField }\n\n\tif (protection === 'writeOnly') {\n\t\treturn (\n\t\t\t<WriteOnlyField\n\t\t\t\tclearable={props.clearable !== false}\n\t\t\t\tcomponentKey={componentKey}\n\t\t\t\tfield={patchedField as unknown as EncryptedFieldConfig}\n\t\t\t\tgenerate={props.generate}\n\t\t\t\thintPath={`${path}_hint`}\n\t\t\t\tmaskDots={maskDots}\n\t\t\t\tNative={Native}\n\t\t\t\tnativeProps={nativeProps}\n\t\t\t\tpath={path}\n\t\t\t\tplacement={placementFor(componentKey, fieldPatch.hasMany === true)}\n\t\t\t\tsetPath={`${path}_set`}\n\t\t\t/>\n\t\t)\n\t}\n\n\tif (protection === 'none' || startedEmpty) {\n\t\treturn <Native {...nativeProps} />\n\t}\n\n\tconst faceField = patchedField as unknown as EncryptedFieldConfig\n\tconst hasMany = fieldPatch.hasMany === true\n\tconst placement = placementFor(componentKey, hasMany)\n\n\tif (placement === 'attached') {\n\t\treturn (\n\t\t\t<EncryptedInput\n\t\t\t\tfield={faceField}\n\t\t\t\tkind={componentKey as 'email' | 'number' | 'text'}\n\t\t\t\tmaskDots={maskDots}\n\t\t\t\tpath={path}\n\t\t\t/>\n\t\t)\n\t}\n\n\tif (placement === 'corner') {\n\t\treturn <EncryptedTextarea field={faceField} maskDots={maskDots} path={path} />\n\t}\n\n\treturn (\n\t\t<StructuralField\n\t\t\tcomponentKey={componentKey}\n\t\t\tfield={faceField}\n\t\t\tmaskDots={maskDots}\n\t\t\tNative={Native}\n\t\t\tnativeProps={nativeProps}\n\t\t\tpath={path}\n\t\t/>\n\t)\n}\n"],"mappings":";;;;;;;;;;;;AAmCA,MAAM,SAA4C;CACjD,UAAU;CACV,MAAM;CACN,MAAM;CACN,OAAO;CACP,MAAM;CACN,QAAQ;CACR,OAAO;CACP,OAAO;CACP,QAAQ;CACR,MAAM;CACN,UAAU;AACX;;;;;;;AAiBA,MAAM,gBAAgB,UAA4B;CACjD,IAAI,SAAS,QAAQ,UAAU,IAC9B,OAAO;CAER,IAAI,MAAM,QAAQ,KAAK,GACtB,OAAO,MAAM,WAAW,KAAK,MAAM,OAAO,SAAS,QAAQ,IAAI;CAEhE,OAAO;AACR;;;;;;;;;;;;;;;;;AAkBA,MAAa,kBAAiD,UAAU;CACvE,MAAM,EAAE,cAAc,OAAO,YAAY,MAAM,eAAe;CAC9D,MAAM,WAAW,cAAc,MAAM,QAAQ;CAE7C,MAAM,CAAC,gBAAgB,SADC,eAAe,CAAC,YAAY,aAAa,SAAS,OAAO,KAAK,CACxC,CAAC;CAE/C,MAAM,eAAe,eACb;EACN,GAAG;EACH,GAAG;EACH,OAAO;GAAE,GAAG,MAAM;GAAO,GAAG,WAAW;EAAM;CAC9C,IACA,CAAC,OAAO,UAAU,CACnB;CAEA,MAAM,SAAS,OAAO,iBAAkB;CACxC,MAAM,cAAc;EAAE,GAAI;EAA8C,OAAO;CAAa;CAE5F,IAAI,eAAe,aAClB,OACC,oBAAC,gBAAD;EACC,WAAW,MAAM,cAAc;EACjB;EACd,OAAO;EACP,UAAU,MAAM;EAChB,UAAU,GAAG,KAAK;EACR;EACF;EACK;EACP;EACN,WAAW,aAAa,cAAc,WAAW,YAAY,IAAI;EACjE,SAAS,GAAG,KAAK;CACjB,CAAA;CAIH,IAAI,eAAe,UAAU,cAC5B,OAAO,oBAAC,QAAD,EAAQ,GAAI,YAAc,CAAA;CAGlC,MAAM,YAAY;CAElB,MAAM,YAAY,aAAa,cADf,WAAW,YAAY,IACa;CAEpD,IAAI,cAAc,YACjB,OACC,oBAAC,gBAAD;EACC,OAAO;EACP,MAAM;EACI;EACJ;CACN,CAAA;CAIH,IAAI,cAAc,UACjB,OAAO,oBAAC,mBAAD;EAAmB,OAAO;EAAqB;EAAgB;CAAO,CAAA;CAG9E,OACC,oBAAC,iBAAD;EACe;EACd,OAAO;EACG;EACF;EACK;EACP;CACN,CAAA;AAEH"}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { Button } from "@payloadcms/ui";
|
|
3
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
4
|
+
//#region src/fields/encrypted/components/WriteOnlyActions.tsx
|
|
5
|
+
/**
|
|
6
|
+
* Thin-stroke glyphs on the eye's 16x12 canvas, each drawn centered on
|
|
7
|
+
* (8, 6) so the mark sits in the middle of its clickable area, matching the
|
|
8
|
+
* eye beside which they render.
|
|
9
|
+
*/
|
|
10
|
+
const GLYPHS = {
|
|
11
|
+
clear: /* @__PURE__ */ jsx("path", {
|
|
12
|
+
className: "stroke",
|
|
13
|
+
d: "M4.5 2.5L11.5 9.5M11.5 2.5L4.5 9.5"
|
|
14
|
+
}),
|
|
15
|
+
edit: /* @__PURE__ */ jsx("path", {
|
|
16
|
+
className: "stroke",
|
|
17
|
+
d: "M3.2 11.5L3.7 9L10.2 2.5C10.75 1.95 11.65 1.95 12.2 2.5C12.75 3.05 12.75 3.95 12.2 4.5L5.7 11L3.2 11.5Z",
|
|
18
|
+
strokeLinejoin: "round"
|
|
19
|
+
}),
|
|
20
|
+
generate: /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("path", {
|
|
21
|
+
className: "stroke",
|
|
22
|
+
d: "M13 6A5 5 0 0 0 4.5 2.8M3 6A5 5 0 0 0 11.5 9.2"
|
|
23
|
+
}), /* @__PURE__ */ jsx("path", {
|
|
24
|
+
className: "stroke",
|
|
25
|
+
d: "M4.5 0.8V3H6.7M11.5 11.2V9H9.3",
|
|
26
|
+
strokeLinejoin: "round"
|
|
27
|
+
})] }),
|
|
28
|
+
undo: /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("path", {
|
|
29
|
+
className: "stroke",
|
|
30
|
+
d: "M3.5 3.75H9A3.5 3.5 0 0 1 9 10.75H5"
|
|
31
|
+
}), /* @__PURE__ */ jsx("path", {
|
|
32
|
+
className: "stroke",
|
|
33
|
+
d: "M6 1.25L3.5 3.75L6 6.25",
|
|
34
|
+
strokeLinejoin: "round"
|
|
35
|
+
})] })
|
|
36
|
+
};
|
|
37
|
+
/**
|
|
38
|
+
* One write-only action, rendered with the same Button shell, icon canvas, and
|
|
39
|
+
* (for attached placement) input-segment chrome as the reveal eye, so a row of
|
|
40
|
+
* actions reads as part of the input and never changes the field's height.
|
|
41
|
+
*/
|
|
42
|
+
const ActionButton = ({ attached, kind, label, onClick, pressed }) => /* @__PURE__ */ jsx(Button, {
|
|
43
|
+
"aria-label": label,
|
|
44
|
+
buttonStyle: "none",
|
|
45
|
+
className: [
|
|
46
|
+
"tenx-protected-field__eye",
|
|
47
|
+
attached ? "tenx-protected-field__eye--attached" : "tenx-protected-field__eye--floating",
|
|
48
|
+
"tenx-protected-field__action"
|
|
49
|
+
].filter(Boolean).join(" "),
|
|
50
|
+
extraButtonProps: pressed === void 0 ? void 0 : { "aria-pressed": pressed },
|
|
51
|
+
icon: /* @__PURE__ */ jsx("svg", {
|
|
52
|
+
"aria-hidden": "true",
|
|
53
|
+
className: "tenx-protected-field__eye-icon",
|
|
54
|
+
viewBox: "0 0 16 12",
|
|
55
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
56
|
+
children: GLYPHS[kind]
|
|
57
|
+
}),
|
|
58
|
+
margin: false,
|
|
59
|
+
onClick,
|
|
60
|
+
tooltip: label
|
|
61
|
+
});
|
|
62
|
+
//#endregion
|
|
63
|
+
export { ActionButton };
|
|
64
|
+
|
|
65
|
+
//# sourceMappingURL=WriteOnlyActions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"WriteOnlyActions.js","names":[],"sources":["../../../../src/fields/encrypted/components/WriteOnlyActions.tsx"],"sourcesContent":["'use client'\nimport { Button } from '@payloadcms/ui'\nimport type React from 'react'\n\nexport type ActionKind = 'clear' | 'edit' | 'generate' | 'undo'\n\n/**\n * Thin-stroke glyphs on the eye's 16x12 canvas, each drawn centered on\n * (8, 6) so the mark sits in the middle of its clickable area, matching the\n * eye beside which they render.\n */\nconst GLYPHS: Record<ActionKind, React.ReactNode> = {\n\t// × matching react-select's clear indicator.\n\tclear: <path className=\"stroke\" d=\"M4.5 2.5L11.5 9.5M11.5 2.5L4.5 9.5\" />,\n\t// Pencil.\n\tedit: (\n\t\t<path\n\t\t\tclassName=\"stroke\"\n\t\t\td=\"M3.2 11.5L3.7 9L10.2 2.5C10.75 1.95 11.65 1.95 12.2 2.5C12.75 3.05 12.75 3.95 12.2 4.5L5.7 11L3.2 11.5Z\"\n\t\t\tstrokeLinejoin=\"round\"\n\t\t/>\n\t),\n\t// Circular arrows, the rotate/regenerate convention.\n\tgenerate: (\n\t\t<>\n\t\t\t<path className=\"stroke\" d=\"M13 6A5 5 0 0 0 4.5 2.8M3 6A5 5 0 0 0 11.5 9.2\" />\n\t\t\t<path className=\"stroke\" d=\"M4.5 0.8V3H6.7M11.5 11.2V9H9.3\" strokeLinejoin=\"round\" />\n\t\t</>\n\t),\n\t// Counter-clockwise undo arrow.\n\tundo: (\n\t\t<>\n\t\t\t<path className=\"stroke\" d=\"M3.5 3.75H9A3.5 3.5 0 0 1 9 10.75H5\" />\n\t\t\t<path className=\"stroke\" d=\"M6 1.25L3.5 3.75L6 6.25\" strokeLinejoin=\"round\" />\n\t\t</>\n\t),\n}\n\n/**\n * One write-only action, rendered with the same Button shell, icon canvas, and\n * (for attached placement) input-segment chrome as the reveal eye, so a row of\n * actions reads as part of the input and never changes the field's height.\n */\nexport const ActionButton: React.FC<{\n\tattached?: boolean\n\tkind: ActionKind\n\tlabel: string\n\tonClick: () => void\n\tpressed?: boolean\n}> = ({ attached, kind, label, onClick, pressed }) => (\n\t<Button\n\t\taria-label={label}\n\t\tbuttonStyle=\"none\"\n\t\tclassName={[\n\t\t\t'tenx-protected-field__eye',\n\t\t\tattached ? 'tenx-protected-field__eye--attached' : 'tenx-protected-field__eye--floating',\n\t\t\t'tenx-protected-field__action',\n\t\t]\n\t\t\t.filter(Boolean)\n\t\t\t.join(' ')}\n\t\textraButtonProps={pressed === undefined ? undefined : { 'aria-pressed': pressed }}\n\t\ticon={\n\t\t\t<svg\n\t\t\t\taria-hidden=\"true\"\n\t\t\t\tclassName=\"tenx-protected-field__eye-icon\"\n\t\t\t\tviewBox=\"0 0 16 12\"\n\t\t\t\txmlns=\"http://www.w3.org/2000/svg\"\n\t\t\t>\n\t\t\t\t{GLYPHS[kind]}\n\t\t\t</svg>\n\t\t}\n\t\tmargin={false}\n\t\tonClick={onClick}\n\t\ttooltip={label}\n\t/>\n)\n"],"mappings":";;;;;;;;;AAWA,MAAM,SAA8C;CAEnD,OAAO,oBAAC,QAAD;EAAM,WAAU;EAAS,GAAE;CAAsC,CAAA;CAExE,MACC,oBAAC,QAAD;EACC,WAAU;EACV,GAAE;EACF,gBAAe;CACf,CAAA;CAGF,UACC,qBAAA,UAAA,EAAA,UAAA,CACC,oBAAC,QAAD;EAAM,WAAU;EAAS,GAAE;CAAkD,CAAA,GAC7E,oBAAC,QAAD;EAAM,WAAU;EAAS,GAAE;EAAiC,gBAAe;CAAS,CAAA,CACnF,EAAA,CAAA;CAGH,MACC,qBAAA,UAAA,EAAA,UAAA,CACC,oBAAC,QAAD;EAAM,WAAU;EAAS,GAAE;CAAuC,CAAA,GAClE,oBAAC,QAAD;EAAM,WAAU;EAAS,GAAE;EAA0B,gBAAe;CAAS,CAAA,CAC5E,EAAA,CAAA;AAEJ;;;;;;AAOA,MAAa,gBAMP,EAAE,UAAU,MAAM,OAAO,SAAS,cACvC,oBAAC,QAAD;CACC,cAAY;CACZ,aAAY;CACZ,WAAW;EACV;EACA,WAAW,wCAAwC;EACnD;CACD,EACE,OAAO,OAAO,EACd,KAAK,GAAG;CACV,kBAAkB,YAAY,KAAA,IAAY,KAAA,IAAY,EAAE,gBAAgB,QAAQ;CAChF,MACC,oBAAC,OAAD;EACC,eAAY;EACZ,WAAU;EACV,SAAQ;EACR,OAAM;YAEL,OAAO;CACJ,CAAA;CAEN,QAAQ;CACC;CACT,SAAS;AACT,CAAA"}
|
|
@@ -0,0 +1,286 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { formatHint } from "../hint.js";
|
|
3
|
+
import { keys } from "../../../translations/keys.js";
|
|
4
|
+
import { useTranslation as useTranslation$1 } from "../../../translations/useTranslation.js";
|
|
5
|
+
import { dotString } from "./MaskDots.js";
|
|
6
|
+
import { generateSecret } from "../generateSecret.js";
|
|
7
|
+
import { ActionButton } from "./WriteOnlyActions.js";
|
|
8
|
+
import { applyBlur, applyClear, applyInput, applySave, applyUndo } from "./writeOnlyIntent.js";
|
|
9
|
+
import { FieldDescription, FieldError, FieldLabel, useDocumentEvents, useField, useFormFields, useFormSubmitted } from "@payloadcms/ui";
|
|
10
|
+
import { mergeFieldStyles } from "@payloadcms/ui/shared";
|
|
11
|
+
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
|
12
|
+
import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
|
|
13
|
+
//#region src/fields/encrypted/components/WriteOnlyField.tsx
|
|
14
|
+
/**
|
|
15
|
+
* Editor for `protection: 'writeOnly'`. The plaintext never reaches the client
|
|
16
|
+
* (reads strip the field), so there is nothing to reveal and nothing to bind:
|
|
17
|
+
* the control is one always-editable input. A stored value shows as a
|
|
18
|
+
* placeholder (the identification hint when configured, dots otherwise), typing
|
|
19
|
+
* stages a replacement that stays visible until save (the reveal-once window
|
|
20
|
+
* for generated secrets), and emptying the input reverts to keeping the stored
|
|
21
|
+
* value. Clear is the isClearable × inside the input; an undo arrow follows a
|
|
22
|
+
* clear because the cleared secret cannot be retyped from memory. Every action
|
|
23
|
+
* lives inside the input row (or the label row for structural types), so the
|
|
24
|
+
* field never grows past its native height.
|
|
25
|
+
*/
|
|
26
|
+
const WriteOnlyField = (props) => {
|
|
27
|
+
if (props.placement === "label-row") return /* @__PURE__ */ jsx(StructuralWriteOnly, { ...props });
|
|
28
|
+
return /* @__PURE__ */ jsx(InlineWriteOnly, { ...props });
|
|
29
|
+
};
|
|
30
|
+
const InlineWriteOnly = ({ clearable, componentKey, field, generate, hintPath, maskDots, path, placement, setPath }) => {
|
|
31
|
+
const { t } = useTranslation$1();
|
|
32
|
+
const { setValue, value } = useField({ path });
|
|
33
|
+
const isSet = useFormFields(([fields]) => fields?.[setPath]?.value === true);
|
|
34
|
+
const hint = useFormFields(([fields]) => {
|
|
35
|
+
const stored = fields?.[hintPath]?.value;
|
|
36
|
+
return typeof stored === "string" && stored.length > 0 ? stored : void 0;
|
|
37
|
+
});
|
|
38
|
+
const submitted = useFormSubmitted();
|
|
39
|
+
const invalid = useFormFields(([fields]) => fields?.[path]?.valid === false);
|
|
40
|
+
const showFieldError = submitted && invalid;
|
|
41
|
+
const [cleared, setCleared] = useState(false);
|
|
42
|
+
const inputRef = useRef(null);
|
|
43
|
+
const { mostRecentUpdate } = useDocumentEvents();
|
|
44
|
+
const lastUpdateAt = useRef(mostRecentUpdate?.updatedAt);
|
|
45
|
+
useEffect(() => {
|
|
46
|
+
if (!mostRecentUpdate?.updatedAt || mostRecentUpdate.updatedAt === lastUpdateAt.current) return;
|
|
47
|
+
lastUpdateAt.current = mostRecentUpdate.updatedAt;
|
|
48
|
+
const resolved = applySave();
|
|
49
|
+
setValue(resolved.value, true);
|
|
50
|
+
setCleared(resolved.cleared);
|
|
51
|
+
}, [mostRecentUpdate?.updatedAt, setValue]);
|
|
52
|
+
const isNumber = componentKey === "number";
|
|
53
|
+
const typed = isNumber ? typeof value === "number" : typeof value === "string" && value !== "";
|
|
54
|
+
const commit = useCallback((outcome) => {
|
|
55
|
+
setValue(outcome.value);
|
|
56
|
+
setCleared(outcome.cleared);
|
|
57
|
+
}, [setValue]);
|
|
58
|
+
const handleChange = useCallback((event) => {
|
|
59
|
+
commit(applyInput(event.target.value, {
|
|
60
|
+
cleared,
|
|
61
|
+
isNumber
|
|
62
|
+
}));
|
|
63
|
+
}, [
|
|
64
|
+
cleared,
|
|
65
|
+
commit,
|
|
66
|
+
isNumber
|
|
67
|
+
]);
|
|
68
|
+
const handleBlur = useCallback(() => {
|
|
69
|
+
const outcome = applyBlur(value, {
|
|
70
|
+
cleared,
|
|
71
|
+
isNumber
|
|
72
|
+
});
|
|
73
|
+
if (outcome) commit(outcome);
|
|
74
|
+
}, [
|
|
75
|
+
cleared,
|
|
76
|
+
commit,
|
|
77
|
+
isNumber,
|
|
78
|
+
value
|
|
79
|
+
]);
|
|
80
|
+
const handleClear = useCallback(() => {
|
|
81
|
+
const outcome = applyClear({
|
|
82
|
+
cleared,
|
|
83
|
+
clearable,
|
|
84
|
+
isSet,
|
|
85
|
+
typed
|
|
86
|
+
});
|
|
87
|
+
if (outcome) commit(outcome);
|
|
88
|
+
}, [
|
|
89
|
+
cleared,
|
|
90
|
+
clearable,
|
|
91
|
+
commit,
|
|
92
|
+
isSet,
|
|
93
|
+
typed
|
|
94
|
+
]);
|
|
95
|
+
const handleUndo = useCallback(() => {
|
|
96
|
+
commit(applyUndo());
|
|
97
|
+
}, [commit]);
|
|
98
|
+
const runGenerate = useCallback(async () => {
|
|
99
|
+
if (!generate) return;
|
|
100
|
+
commit({
|
|
101
|
+
cleared: false,
|
|
102
|
+
value: await generateSecret(generate)
|
|
103
|
+
});
|
|
104
|
+
requestAnimationFrame(() => {
|
|
105
|
+
inputRef.current?.focus();
|
|
106
|
+
inputRef.current?.select?.();
|
|
107
|
+
});
|
|
108
|
+
}, [commit, generate]);
|
|
109
|
+
const placeholder = typed ? void 0 : cleared ? t(keys.clearedOnSave) : !isSet ? typeof field.admin?.placeholder === "string" ? field.admin.placeholder : void 0 : hint ? formatHint(hint, maskDots) : dotString(maskDots);
|
|
110
|
+
const showClear = typed || clearable && isSet && !cleared;
|
|
111
|
+
const inputId = `field-${path.replace(/\./g, "__")}`;
|
|
112
|
+
const displayValue = typed ? String(value) : "";
|
|
113
|
+
const actions = /* @__PURE__ */ jsxs(Fragment$1, { children: [generate ? /* @__PURE__ */ jsx(ActionButton, {
|
|
114
|
+
attached: placement === "attached",
|
|
115
|
+
kind: "generate",
|
|
116
|
+
label: t(keys.generateValue),
|
|
117
|
+
onClick: runGenerate
|
|
118
|
+
}) : null, cleared && !typed ? /* @__PURE__ */ jsx(ActionButton, {
|
|
119
|
+
attached: placement === "attached",
|
|
120
|
+
kind: "undo",
|
|
121
|
+
label: t(keys.undoClear),
|
|
122
|
+
onClick: handleUndo
|
|
123
|
+
}) : showClear ? /* @__PURE__ */ jsx(ActionButton, {
|
|
124
|
+
attached: placement === "attached",
|
|
125
|
+
kind: "clear",
|
|
126
|
+
label: t(keys.clearValue),
|
|
127
|
+
onClick: handleClear
|
|
128
|
+
}) : null] });
|
|
129
|
+
const styles = useMemo(() => mergeFieldStyles(field), [field]);
|
|
130
|
+
const isTextarea = componentKey === "textarea";
|
|
131
|
+
const inputProps = {
|
|
132
|
+
autoComplete: "off",
|
|
133
|
+
className: ["tenx-protected-field__wo-input", !typed && isSet && !cleared && "tenx-protected-field__wo-input--set"].filter(Boolean).join(" "),
|
|
134
|
+
id: inputId,
|
|
135
|
+
name: path,
|
|
136
|
+
onBlur: handleBlur,
|
|
137
|
+
onChange: handleChange,
|
|
138
|
+
placeholder,
|
|
139
|
+
value: displayValue
|
|
140
|
+
};
|
|
141
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
142
|
+
className: [
|
|
143
|
+
"field-type",
|
|
144
|
+
componentKey,
|
|
145
|
+
showFieldError && "error",
|
|
146
|
+
"tenx-protected-field",
|
|
147
|
+
placement === "attached" ? "tenx-protected-field--attached" : "tenx-protected-field--corner"
|
|
148
|
+
].filter(Boolean).join(" "),
|
|
149
|
+
style: styles,
|
|
150
|
+
children: [/* @__PURE__ */ jsx(FieldLabel, {
|
|
151
|
+
label: field.label,
|
|
152
|
+
localized: field.localized,
|
|
153
|
+
path,
|
|
154
|
+
required: field.required
|
|
155
|
+
}), /* @__PURE__ */ jsxs("div", {
|
|
156
|
+
className: "field-type__wrap",
|
|
157
|
+
children: [
|
|
158
|
+
/* @__PURE__ */ jsx(FieldError, { path }),
|
|
159
|
+
isTextarea ? /* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsx("textarea", {
|
|
160
|
+
...inputProps,
|
|
161
|
+
ref: (el) => {
|
|
162
|
+
inputRef.current = el;
|
|
163
|
+
},
|
|
164
|
+
rows: field.admin?.rows ?? 4
|
|
165
|
+
}), /* @__PURE__ */ jsx("div", {
|
|
166
|
+
className: "tenx-protected-field__eye-wrap tenx-protected-field__eye-wrap--corner tenx-protected-field__actions--corner",
|
|
167
|
+
children: actions
|
|
168
|
+
})] }) : /* @__PURE__ */ jsxs("div", {
|
|
169
|
+
className: "tenx-protected-field__attached-row",
|
|
170
|
+
children: [/* @__PURE__ */ jsx("input", {
|
|
171
|
+
...inputProps,
|
|
172
|
+
ref: (el) => {
|
|
173
|
+
inputRef.current = el;
|
|
174
|
+
},
|
|
175
|
+
inputMode: isNumber ? "decimal" : void 0,
|
|
176
|
+
type: isNumber ? "number" : componentKey === "email" && typed ? "email" : "text"
|
|
177
|
+
}), /* @__PURE__ */ jsx("div", {
|
|
178
|
+
className: "tenx-protected-field__eye-wrap tenx-protected-field__eye-wrap--attached",
|
|
179
|
+
children: actions
|
|
180
|
+
})]
|
|
181
|
+
}),
|
|
182
|
+
/* @__PURE__ */ jsx(FieldDescription, {
|
|
183
|
+
description: field.admin?.description,
|
|
184
|
+
path
|
|
185
|
+
})
|
|
186
|
+
]
|
|
187
|
+
})]
|
|
188
|
+
});
|
|
189
|
+
};
|
|
190
|
+
/**
|
|
191
|
+
* Label-row variant for structural types (date, select, checkbox, code, json,
|
|
192
|
+
* point, radio, and any hasMany surface): these have no single-line input to
|
|
193
|
+
* type into, so replace goes through a pencil that mounts the real native
|
|
194
|
+
* editor, with clear and undo beside it on the label line, exactly where the
|
|
195
|
+
* masked eye sits.
|
|
196
|
+
*/
|
|
197
|
+
const StructuralWriteOnly = ({ clearable, field, maskDots, Native, nativeProps, path, setPath }) => {
|
|
198
|
+
const { t } = useTranslation$1();
|
|
199
|
+
const { setValue, value } = useField({ path });
|
|
200
|
+
const isSet = useFormFields(([fields]) => fields?.[setPath]?.value === true);
|
|
201
|
+
const [mode, setMode] = useState("idle");
|
|
202
|
+
const styles = useMemo(() => mergeFieldStyles(field), [field]);
|
|
203
|
+
const { mostRecentUpdate } = useDocumentEvents();
|
|
204
|
+
const lastUpdateAt = useRef(mostRecentUpdate?.updatedAt);
|
|
205
|
+
useEffect(() => {
|
|
206
|
+
if (!mostRecentUpdate?.updatedAt || mostRecentUpdate.updatedAt === lastUpdateAt.current) return;
|
|
207
|
+
lastUpdateAt.current = mostRecentUpdate.updatedAt;
|
|
208
|
+
setValue(void 0, true);
|
|
209
|
+
setMode("idle");
|
|
210
|
+
}, [mostRecentUpdate?.updatedAt, setValue]);
|
|
211
|
+
const toggleEdit = useCallback(() => {
|
|
212
|
+
if (mode === "editing") {
|
|
213
|
+
if (value !== void 0) setValue(void 0);
|
|
214
|
+
setMode("idle");
|
|
215
|
+
return;
|
|
216
|
+
}
|
|
217
|
+
setMode("editing");
|
|
218
|
+
}, [
|
|
219
|
+
mode,
|
|
220
|
+
setValue,
|
|
221
|
+
value
|
|
222
|
+
]);
|
|
223
|
+
const clear = useCallback(() => {
|
|
224
|
+
setValue(null);
|
|
225
|
+
setMode("cleared");
|
|
226
|
+
}, [setValue]);
|
|
227
|
+
const undoClear = useCallback(() => {
|
|
228
|
+
setValue(void 0);
|
|
229
|
+
setMode("idle");
|
|
230
|
+
}, [setValue]);
|
|
231
|
+
if (!isSet) return /* @__PURE__ */ jsx(Native, { ...nativeProps });
|
|
232
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
233
|
+
className: "tenx-protected-field tenx-protected-field--label-row",
|
|
234
|
+
children: [mode === "editing" ? /* @__PURE__ */ jsx(Native, { ...nativeProps }) : /* @__PURE__ */ jsxs("div", {
|
|
235
|
+
className: "field-type tenx-protected-field__wo-face",
|
|
236
|
+
style: styles,
|
|
237
|
+
children: [/* @__PURE__ */ jsx(FieldLabel, {
|
|
238
|
+
label: field.label,
|
|
239
|
+
localized: field.localized,
|
|
240
|
+
path,
|
|
241
|
+
required: field.required
|
|
242
|
+
}), /* @__PURE__ */ jsxs("div", {
|
|
243
|
+
className: "field-type__wrap",
|
|
244
|
+
children: [
|
|
245
|
+
/* @__PURE__ */ jsx(FieldError, { path }),
|
|
246
|
+
/* @__PURE__ */ jsx("div", {
|
|
247
|
+
className: "tenx-protected-field__wo-face-box",
|
|
248
|
+
children: mode === "cleared" ? /* @__PURE__ */ jsx("span", {
|
|
249
|
+
className: "tenx-protected-field__wo-face-msg",
|
|
250
|
+
children: t(keys.clearedOnSave)
|
|
251
|
+
}) : /* @__PURE__ */ jsx("span", {
|
|
252
|
+
"aria-label": t(keys.writeOnlyValue),
|
|
253
|
+
className: "tenx-protected-field__dots",
|
|
254
|
+
role: "img",
|
|
255
|
+
children: dotString(maskDots)
|
|
256
|
+
})
|
|
257
|
+
}),
|
|
258
|
+
/* @__PURE__ */ jsx(FieldDescription, {
|
|
259
|
+
description: field.admin?.description,
|
|
260
|
+
path
|
|
261
|
+
})
|
|
262
|
+
]
|
|
263
|
+
})]
|
|
264
|
+
}), /* @__PURE__ */ jsx("div", {
|
|
265
|
+
className: "tenx-protected-field__eye-wrap tenx-protected-field__eye-wrap--label-row",
|
|
266
|
+
children: mode === "cleared" ? /* @__PURE__ */ jsx(ActionButton, {
|
|
267
|
+
kind: "undo",
|
|
268
|
+
label: t(keys.undoClear),
|
|
269
|
+
onClick: undoClear
|
|
270
|
+
}) : /* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsx(ActionButton, {
|
|
271
|
+
kind: "edit",
|
|
272
|
+
label: t(keys.replaceValue),
|
|
273
|
+
onClick: toggleEdit,
|
|
274
|
+
pressed: mode === "editing"
|
|
275
|
+
}), clearable && mode !== "editing" ? /* @__PURE__ */ jsx(ActionButton, {
|
|
276
|
+
kind: "clear",
|
|
277
|
+
label: t(keys.clearValue),
|
|
278
|
+
onClick: clear
|
|
279
|
+
}) : null] })
|
|
280
|
+
})]
|
|
281
|
+
});
|
|
282
|
+
};
|
|
283
|
+
//#endregion
|
|
284
|
+
export { WriteOnlyField };
|
|
285
|
+
|
|
286
|
+
//# sourceMappingURL=WriteOnlyField.js.map
|
|
@@ -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' ?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|
+
//#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
|