@10x-media/fields 0.1.0-beta.9 → 4.0.0-alpha.2

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.
Files changed (76) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/README.md +9 -4
  3. package/dist/fields/color/client/ColorInput.js +17 -6
  4. package/dist/fields/color/client/ColorInput.js.map +1 -1
  5. package/dist/fields/color/client/ColorPickerPanel.js +18 -12
  6. package/dist/fields/color/client/ColorPickerPanel.js.map +1 -1
  7. package/dist/fields/color/client/colorField.css +131 -178
  8. package/dist/fields/color/client/icons.js +17 -24
  9. package/dist/fields/color/client/icons.js.map +1 -1
  10. package/dist/fields/color/colorField.js +5 -3
  11. package/dist/fields/color/colorField.js.map +1 -1
  12. package/dist/fields/color/server/colorCell.css +8 -9
  13. package/dist/fields/encrypted/components/EncryptedInput.js +44 -26
  14. package/dist/fields/encrypted/components/EncryptedInput.js.map +1 -1
  15. package/dist/fields/encrypted/components/EncryptedTextarea.js +29 -29
  16. package/dist/fields/encrypted/components/EncryptedTextarea.js.map +1 -1
  17. package/dist/fields/encrypted/components/EyeToggle.js +14 -35
  18. package/dist/fields/encrypted/components/EyeToggle.js.map +1 -1
  19. package/dist/fields/encrypted/components/ProtectedField.css +107 -159
  20. package/dist/fields/encrypted/components/ProtectedField.js +6 -2
  21. package/dist/fields/encrypted/components/ProtectedField.js.map +1 -1
  22. package/dist/fields/encrypted/components/RichTextRevealGate.js +3 -3
  23. package/dist/fields/encrypted/components/RichTextRevealGate.js.map +1 -1
  24. package/dist/fields/encrypted/components/WriteOnlyActions.js +58 -53
  25. package/dist/fields/encrypted/components/WriteOnlyActions.js.map +1 -1
  26. package/dist/fields/encrypted/components/WriteOnlyField.js +39 -21
  27. package/dist/fields/encrypted/components/WriteOnlyField.js.map +1 -1
  28. package/dist/fields/encrypted/components/facsimiles.js +70 -79
  29. package/dist/fields/encrypted/components/facsimiles.js.map +1 -1
  30. package/dist/fields/encrypted/components/placement.js.map +1 -1
  31. package/dist/fields/encrypted/encryptedField.js +25 -12
  32. package/dist/fields/encrypted/encryptedField.js.map +1 -1
  33. package/dist/fields/encrypted/{typescriptSchema.js → jsonSchema.js} +4 -4
  34. package/dist/fields/encrypted/jsonSchema.js.map +1 -0
  35. package/dist/fields/encrypted/queryRewrite.js +20 -0
  36. package/dist/fields/encrypted/queryRewrite.js.map +1 -1
  37. package/dist/fields/encrypted/validators.js +1 -1
  38. package/dist/fields/encrypted/validators.js.map +1 -1
  39. package/dist/fields/icon/adapters/tabler/generated/nodes.js +1 -1
  40. package/dist/fields/icon/adapters/tabler/generated/nodes.js.map +1 -1
  41. package/dist/fields/icon/client/IconDrawerContent.js +8 -6
  42. package/dist/fields/icon/client/IconDrawerContent.js.map +1 -1
  43. package/dist/fields/icon/client/IconFieldClient.js +15 -37
  44. package/dist/fields/icon/client/IconFieldClient.js.map +1 -1
  45. package/dist/fields/icon/client/icon-field.css +137 -233
  46. package/dist/fields/icon/codegen/sources/tabler.js +25 -6
  47. package/dist/fields/icon/codegen/sources/tabler.js.map +1 -1
  48. package/dist/fields/icon/layers/upload.js +3 -0
  49. package/dist/fields/icon/layers/upload.js.map +1 -1
  50. package/dist/fields/icon/react/createIcon.js +4 -4
  51. package/dist/fields/icon/react/createIcon.js.map +1 -1
  52. package/dist/fields/measurement/client/MeasurementInput.js +18 -32
  53. package/dist/fields/measurement/client/MeasurementInput.js.map +1 -1
  54. package/dist/fields/measurement/client/editModel.js +12 -3
  55. package/dist/fields/measurement/client/editModel.js.map +1 -1
  56. package/dist/fields/measurement/client/measurementField.css +58 -105
  57. package/dist/fields/measurement/server/getUserUnits.js +2 -1
  58. package/dist/fields/measurement/server/getUserUnits.js.map +1 -1
  59. package/dist/fields/phoneNumber/client/CountryPicker.js +14 -9
  60. package/dist/fields/phoneNumber/client/CountryPicker.js.map +1 -1
  61. package/dist/fields/phoneNumber/client/PhoneNumberField.d.ts +1 -1
  62. package/dist/fields/phoneNumber/client/PhoneNumberField.js +22 -4
  63. package/dist/fields/phoneNumber/client/PhoneNumberField.js.map +1 -1
  64. package/dist/fields/phoneNumber/client/phoneNumberField.css +109 -142
  65. package/dist/fields/phoneNumber/phoneNumberField.js +1 -1
  66. package/dist/fields/phoneNumber/phoneNumberField.js.map +1 -1
  67. package/dist/fields/phoneNumber/server/PhoneNumberCellServer.js +2 -1
  68. package/dist/fields/phoneNumber/server/PhoneNumberCellServer.js.map +1 -1
  69. package/dist/index.d.ts +3 -2
  70. package/dist/index.js +5 -4
  71. package/dist/index.js.map +1 -1
  72. package/dist/plugin/companionSelect.d.ts +12 -0
  73. package/dist/plugin/companionSelect.js +107 -0
  74. package/dist/plugin/companionSelect.js.map +1 -0
  75. package/package.json +15 -15
  76. package/dist/fields/encrypted/typescriptSchema.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"encryptedField.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,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;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"}
1
+ {"version":3,"file":"encryptedField.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 { jsonSchemaFor } from './jsonSchema'\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 { makeComposedValidate, makeEffectiveValidator } from './validators'\n\n/** Adds `filter` to a field's `admin.disabled`, keeping whatever the source already disabled. */\nconst withFilterDisabled = (\n\tdisabled: NonNullable<TextField['admin']>['disabled']\n): NonNullable<TextField['admin']>['disabled'] =>\n\tdisabled === true ? true : { ...(disabled || {}), filter: true }\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: { disabled: { column: true, filter: 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/jsonSchema/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\tjsonSchema: _jsonSchema,\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 ? {} : { disabled: withFilterDisabled(sourceAdmin?.disabled) }),\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\tjsonSchema: jsonSchemaFor(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: { disabled: { column: true, filter: 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: { disabled: { column: true, filter: 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: { disabled: { column: true, filter: 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,sBACL,aAEA,aAAa,OAAO,OAAO;CAAE,GAAI,YAAY,CAAC;CAAI,QAAQ;AAAK;;AAGhE,MAAM,mBAAmB;CACxB;CACA;CACA;CACA;CACA;CACA;CACA;AACD;;;;;;;AA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Q;KAAM,QAAQ;IAAK;IAAG,QAAQ;GAAK;GAChE,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,UAAU;IAAE,QAAQ;IAAM,QAAQ;GAAK;GAAG,QAAQ;EAAK;EAChE,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"}
@@ -1,4 +1,4 @@
1
- //#region src/fields/encrypted/typescriptSchema.ts
1
+ //#region src/fields/encrypted/jsonSchema.ts
2
2
  const optionValues = (source) => "options" in source ? source.options.map((option) => typeof option === "string" ? option : option.value) : [];
3
3
  const baseSchema = (source) => {
4
4
  switch (source.type) {
@@ -27,7 +27,7 @@ const baseSchema = (source) => {
27
27
  * The stored field is text, but generated TypeScript must keep the source
28
28
  * type's shape (number stays number, checkbox stays boolean, ...).
29
29
  */
30
- const typescriptSchemaFor = (source) => {
30
+ const jsonSchemaFor = (source) => {
31
31
  const single = baseSchema(source);
32
32
  const schema = "hasMany" in source && source.hasMany === true ? {
33
33
  items: single,
@@ -36,6 +36,6 @@ const typescriptSchemaFor = (source) => {
36
36
  return [() => schema];
37
37
  };
38
38
  //#endregion
39
- export { typescriptSchemaFor };
39
+ export { jsonSchemaFor };
40
40
 
41
- //# sourceMappingURL=typescriptSchema.js.map
41
+ //# sourceMappingURL=jsonSchema.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"jsonSchema.js","names":[],"sources":["../../../src/fields/encrypted/jsonSchema.ts"],"sourcesContent":["import type { JSONSchema4 } from 'json-schema'\nimport type { TextField } from 'payload'\nimport type { EncryptedSourceField } from './types'\n\nconst optionValues = (source: EncryptedSourceField): string[] =>\n\t'options' in source\n\t\t? source.options.map((option) => (typeof option === 'string' ? option : option.value))\n\t\t: []\n\nconst baseSchema = (source: EncryptedSourceField): JSONSchema4 => {\n\tswitch (source.type) {\n\t\tcase 'checkbox':\n\t\t\treturn { type: 'boolean' }\n\t\tcase 'number':\n\t\t\treturn { type: 'number' }\n\t\tcase 'json':\n\t\tcase 'richText':\n\t\t\treturn { additionalProperties: true, type: 'object' }\n\t\tcase 'point':\n\t\t\treturn { items: { type: 'number' }, maxItems: 2, minItems: 2, type: 'array' }\n\t\tcase 'radio':\n\t\tcase 'select':\n\t\t\treturn { enum: optionValues(source), type: 'string' }\n\t\tdefault:\n\t\t\treturn { type: 'string' }\n\t}\n}\n\n/**\n * The stored field is text, but generated TypeScript must keep the source\n * type's shape (number stays number, checkbox stays boolean, ...).\n */\nexport const jsonSchemaFor = (\n\tsource: EncryptedSourceField\n): NonNullable<TextField['jsonSchema']> => {\n\tconst single = baseSchema(source)\n\tconst schema: JSONSchema4 =\n\t\t'hasMany' in source && source.hasMany === true ? { items: single, type: 'array' } : single\n\treturn [() => schema]\n}\n"],"mappings":";AAIA,MAAM,gBAAgB,WACrB,aAAa,SACV,OAAO,QAAQ,KAAK,WAAY,OAAO,WAAW,WAAW,SAAS,OAAO,KAAM,IACnF,CAAC;AAEL,MAAM,cAAc,WAA8C;CACjE,QAAQ,OAAO,MAAf;EACC,KAAK,YACJ,OAAO,EAAE,MAAM,UAAU;EAC1B,KAAK,UACJ,OAAO,EAAE,MAAM,SAAS;EACzB,KAAK;EACL,KAAK,YACJ,OAAO;GAAE,sBAAsB;GAAM,MAAM;EAAS;EACrD,KAAK,SACJ,OAAO;GAAE,OAAO,EAAE,MAAM,SAAS;GAAG,UAAU;GAAG,UAAU;GAAG,MAAM;EAAQ;EAC7E,KAAK;EACL,KAAK,UACJ,OAAO;GAAE,MAAM,aAAa,MAAM;GAAG,MAAM;EAAS;EACrD,SACC,OAAO,EAAE,MAAM,SAAS;CAC1B;AACD;;;;;AAMA,MAAa,iBACZ,WAC0C;CAC1C,MAAM,SAAS,WAAW,MAAM;CAChC,MAAM,SACL,aAAa,UAAU,OAAO,YAAY,OAAO;EAAE,OAAO;EAAQ,MAAM;CAAQ,IAAI;CACrF,OAAO,OAAO,MAAM;AACrB"}
@@ -1,4 +1,5 @@
1
1
  import { queryableOnly, scanEncryptedFields } from "./scan.js";
2
+ import { companionSelect, siblingPath } from "../../plugin/companionSelect.js";
2
3
  import { computeBidx } from "./crypto/bidx.js";
3
4
  import { contextMode, ringForRequest } from "./hooks.js";
4
5
  const isPlainObject = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
@@ -118,6 +119,19 @@ const stripPathsFor = (markers) => {
118
119
  }
119
120
  return paths;
120
121
  };
122
+ /** Each stored write-only field with the virtual siblings that report on it. */
123
+ const writeOnlySiblingsFor = (markers) => {
124
+ const out = [];
125
+ for (const [path, marker] of markers) {
126
+ if (!marker.writeOnly) continue;
127
+ const siblings = [marker.setName, marker.hintName].filter((name) => Boolean(name)).map((name) => siblingPath(path, name));
128
+ if (siblings.length > 0) out.push({
129
+ path,
130
+ siblings
131
+ });
132
+ }
133
+ return out;
134
+ };
121
135
  /**
122
136
  * Attaches the blind-index where-rewrite and response stripper to a collection.
123
137
  * The fields() plugin applies this to every collection automatically; call it
@@ -131,6 +145,12 @@ const withEncryptedQueryRewrite = (collection) => {
131
145
  const hooks = { ...collection.hooks };
132
146
  if (stripPaths.length > 0) hooks.afterRead = [...collection.hooks?.afterRead ?? [], makeStripPathsHook(stripPaths)];
133
147
  if (queryableMarkers.size > 0) hooks.beforeOperation = [makeHook(queryableMarkers), ...collection.hooks?.beforeOperation ?? []];
148
+ const writeOnly = writeOnlySiblingsFor(allMarkers);
149
+ if (writeOnly.length > 0) return {
150
+ ...collection,
151
+ hooks,
152
+ select: companionSelect(writeOnly, collection.select)
153
+ };
134
154
  return {
135
155
  ...collection,
136
156
  hooks
@@ -1 +1 @@
1
- {"version":3,"file":"queryRewrite.js","names":[],"sources":["../../../src/fields/encrypted/queryRewrite.ts"],"sourcesContent":["import type {\n\tCollectionAfterReadHook,\n\tCollectionBeforeOperationHook,\n\tCollectionConfig,\n\tGlobalAfterReadHook,\n\tGlobalConfig,\n\tPayloadRequest,\n\tWhere,\n} from 'payload'\nimport { computeBidx } from './crypto/bidx'\nimport type { KeyRing } from './crypto/keys'\nimport { contextMode, ringForRequest } from './hooks'\nimport { queryableOnly, scanEncryptedFields } from './scan'\nimport type { EncryptedFieldMarker } from './types'\n\ntype RingResolver = (marker: EncryptedFieldMarker) => Promise<KeyRing>\n\ntype UnsupportedWarn = (path: string, operator: string) => void\n\n/**\n * A blind index answers exact-match only. An unsupported operator is rewritten\n * to this sentinel so the query matches nothing: every real index value is a\n * 24-char base64url string, and a single space is not one. Exported for tests.\n */\nexport const BIDX_NO_MATCH = ' '\n\nconst isPlainObject = (value: unknown): value is Record<string, unknown> =>\n\ttypeof value === 'object' && value !== null && !Array.isArray(value)\n\nconst rewriteConstraint = async (args: {\n\tconstraint: Record<string, unknown>\n\tmarker: EncryptedFieldMarker\n\tringFor: RingResolver\n\twarn: (operator: string) => void\n}): Promise<Record<string, unknown>> => {\n\tconst { constraint, marker, ringFor, warn } = args\n\tconst ring = await ringFor(marker)\n\tconst toBidx = (value: unknown): unknown =>\n\t\tvalue === null ? null : computeBidx(value, ring.indexKey, marker.normalize)\n\t// Payload's REST layer delivers `in`/`not_in` as a comma-joined string, the\n\t// admin and Local API as an array; hash each element under either shape.\n\tconst toBidxArray = (value: unknown): unknown[] => {\n\t\tconst items = Array.isArray(value)\n\t\t\t? value\n\t\t\t: typeof value === 'string'\n\t\t\t\t? value.split(',').map((item) => item.trim())\n\t\t\t\t: []\n\t\treturn items.map(toBidx)\n\t}\n\tconst rewritten: Record<string, unknown> = {}\n\tfor (const [operator, operand] of Object.entries(constraint)) {\n\t\tswitch (operator) {\n\t\t\tcase 'equals':\n\t\t\t\trewritten.equals = toBidx(operand)\n\t\t\t\tbreak\n\t\t\tcase 'not_equals':\n\t\t\t\trewritten.not_equals = toBidx(operand)\n\t\t\t\tbreak\n\t\t\tcase 'in':\n\t\t\t\trewritten.in = toBidxArray(operand)\n\t\t\t\tbreak\n\t\t\tcase 'not_in':\n\t\t\t\trewritten.not_in = toBidxArray(operand)\n\t\t\t\tbreak\n\t\t\tcase 'exists':\n\t\t\t\t// The blind index is written iff the source has a value, so its\n\t\t\t\t// existence tracks the source's. The boolean passes through unhashed.\n\t\t\t\trewritten.exists = operand\n\t\t\t\tbreak\n\t\t\tdefault:\n\t\t\t\t// Substring, range, comparison, and geo operators cannot run over a\n\t\t\t\t// blind index. Match nothing rather than querying the ciphertext\n\t\t\t\t// column, which would read as a working filter while returning junk.\n\t\t\t\twarn(operator)\n\t\t\t\treturn { equals: BIDX_NO_MATCH }\n\t\t}\n\t}\n\treturn rewritten\n}\n\n/** Recursively rewrites queryable encrypted paths to their blind-index siblings. */\nexport const rewriteWhereForMarkers = async (args: {\n\tmarkers: ReadonlyMap<string, EncryptedFieldMarker>\n\tringFor: RingResolver\n\twarn?: UnsupportedWarn\n\twhere: Where\n}): Promise<Where> => {\n\tconst { markers, ringFor, warn = () => {}, where } = args\n\tconst out: Where = {}\n\tfor (const [key, value] of Object.entries(where)) {\n\t\tif ((key === 'and' || key === 'or') && Array.isArray(value)) {\n\t\t\tout[key] = await Promise.all(\n\t\t\t\tvalue.map((nested) =>\n\t\t\t\t\trewriteWhereForMarkers({ markers, ringFor, warn, where: nested as Where })\n\t\t\t\t)\n\t\t\t)\n\t\t\tcontinue\n\t\t}\n\t\tconst marker = markers.get(key)\n\t\tif (marker?.bidxName && isPlainObject(value)) {\n\t\t\tconst rewritten = await rewriteConstraint({\n\t\t\t\tconstraint: value,\n\t\t\t\tmarker,\n\t\t\t\tringFor,\n\t\t\t\twarn: (operator) => warn(key, operator),\n\t\t\t})\n\t\t\tconst bidxPath = key.includes('.')\n\t\t\t\t? `${key.slice(0, key.lastIndexOf('.') + 1)}${marker.bidxName}`\n\t\t\t\t: marker.bidxName\n\t\t\tout[bidxPath] = { ...(out[bidxPath] as Record<string, unknown>), ...rewritten }\n\t\t\tcontinue\n\t\t}\n\t\tout[key] = value as Where[string]\n\t}\n\treturn out\n}\n\nconst makeHook = (\n\tmarkers: ReadonlyMap<string, EncryptedFieldMarker>\n): CollectionBeforeOperationHook => {\n\treturn async ({ args, req }) => {\n\t\tif (isPlainObject(args) && 'where' in args && isPlainObject(args.where)) {\n\t\t\tconst payloadReq = req as PayloadRequest\n\t\t\tconst where = await rewriteWhereForMarkers({\n\t\t\t\tmarkers,\n\t\t\t\tringFor: (marker) => ringForRequest(payloadReq, marker),\n\t\t\t\twarn: (path, operator) =>\n\t\t\t\t\tpayloadReq.payload?.logger?.warn?.(\n\t\t\t\t\t\t`@10x-media/fields: operator '${operator}' cannot run on the encrypted field '${path}'. Blind-index filtering supports exact match only (equals, not_equals, in, not_in, exists); this constraint will match nothing.`\n\t\t\t\t\t),\n\t\t\t\twhere: args.where as Where,\n\t\t\t})\n\t\t\treturn { ...args, where }\n\t\t}\n\t\treturn args\n\t}\n}\n\nconst bidxPathFor = (path: string, bidxName: string): string =>\n\tpath.includes('.') ? `${path.slice(0, path.lastIndexOf('.') + 1)}${bidxName}` : bidxName\n\nconst deleteAtPath = (doc: Record<string, unknown>, path: string): void => {\n\tconst segments = path.split('.')\n\tlet node: Record<string, unknown> = doc\n\tfor (const segment of segments.slice(0, -1)) {\n\t\tconst next = node[segment]\n\t\tif (!next || typeof next !== 'object') {\n\t\t\treturn\n\t\t}\n\t\tnode = next as Record<string, unknown>\n\t}\n\tdelete node[segments[segments.length - 1] as string]\n}\n\n/**\n * Removes server-only encrypted paths from read results: blind-index hashes (so\n * the keyed index value never leaves the server), richText ciphertext siblings\n * (opaque strings the virtual editor field replaces), and write-only fields\n * (whose sealed value passes afterRead untouched and must not surface at all).\n * `admin.hidden` keeps the siblings readable by the plugin's own hooks but,\n * unlike top-level `hidden`, does not strip them from responses.\n */\nconst makeStripPathsHook = (paths: string[]): CollectionAfterReadHook & GlobalAfterReadHook => {\n\treturn ({ context, doc }) => {\n\t\t// Bulk utilities (rotate/adopt/remove) read via pageThrough in `raw`\n\t\t// context and need the ciphertext + blind-index siblings; stripping them\n\t\t// here would make key rotation silently skip every richText field. Only\n\t\t// strip on normal reads.\n\t\tif (contextMode(context as Record<string, unknown>)) {\n\t\t\treturn doc\n\t\t}\n\t\tfor (const path of paths) {\n\t\t\tdeleteAtPath(doc as Record<string, unknown>, path)\n\t\t}\n\t\treturn doc\n\t}\n}\n\n/** Response paths a normal read must not surface, per marker kind. */\nconst stripPathsFor = (markers: ReadonlyMap<string, EncryptedFieldMarker>): string[] => {\n\tconst paths: string[] = []\n\tfor (const [path, marker] of markers) {\n\t\tif (marker.queryable && marker.bidxName) {\n\t\t\tpaths.push(bidxPathFor(path, marker.bidxName))\n\t\t}\n\t\t// richText stores its ciphertext under the marker's own scan path\n\t\t// (`${name}_encrypted`); the write-only path IS the stored field itself.\n\t\tif (marker.sourceType === 'richText' || marker.writeOnly) {\n\t\t\tpaths.push(path)\n\t\t}\n\t}\n\treturn paths\n}\n\n/**\n * Attaches the blind-index where-rewrite and response stripper to a collection.\n * The fields() plugin applies this to every collection automatically; call it\n * directly only when using encryptedField() standalone without the plugin.\n */\nexport const withEncryptedQueryRewrite = (collection: CollectionConfig): CollectionConfig => {\n\tconst allMarkers = scanEncryptedFields(collection.fields)\n\tconst queryableMarkers = queryableOnly(allMarkers)\n\tconst stripPaths = stripPathsFor(allMarkers)\n\tif (queryableMarkers.size === 0 && stripPaths.length === 0) {\n\t\treturn collection\n\t}\n\tconst hooks: NonNullable<CollectionConfig['hooks']> = { ...collection.hooks }\n\tif (stripPaths.length > 0) {\n\t\thooks.afterRead = [...(collection.hooks?.afterRead ?? []), makeStripPathsHook(stripPaths)]\n\t}\n\tif (queryableMarkers.size > 0) {\n\t\thooks.beforeOperation = [\n\t\t\tmakeHook(queryableMarkers),\n\t\t\t...(collection.hooks?.beforeOperation ?? []),\n\t\t]\n\t}\n\treturn { ...collection, hooks }\n}\n\n/**\n * Attaches the response stripper to a global. Globals take no `where`, so this\n * is the strip alone: blind-index hashes, richText ciphertext siblings, and\n * write-only fields never surface in a read result. The fields() plugin applies\n * this to every global automatically; call it directly only when using\n * encryptedField() standalone without the plugin.\n */\nexport const withEncryptedResponseStrip = (global: GlobalConfig): GlobalConfig => {\n\tconst stripPaths = stripPathsFor(scanEncryptedFields(global.fields))\n\tif (stripPaths.length === 0) {\n\t\treturn global\n\t}\n\treturn {\n\t\t...global,\n\t\thooks: {\n\t\t\t...global.hooks,\n\t\t\tafterRead: [...(global.hooks?.afterRead ?? []), makeStripPathsHook(stripPaths)],\n\t\t},\n\t}\n}\n"],"mappings":";;;AA0BA,MAAM,iBAAiB,UACtB,OAAO,UAAU,YAAY,UAAU,QAAQ,CAAC,MAAM,QAAQ,KAAK;AAEpE,MAAM,oBAAoB,OAAO,SAKO;CACvC,MAAM,EAAE,YAAY,QAAQ,SAAS,SAAS;CAC9C,MAAM,OAAO,MAAM,QAAQ,MAAM;CACjC,MAAM,UAAU,UACf,UAAU,OAAO,OAAO,YAAY,OAAO,KAAK,UAAU,OAAO,SAAS;CAG3E,MAAM,eAAe,UAA8B;EAMlD,QALc,MAAM,QAAQ,KAAK,IAC9B,QACA,OAAO,UAAU,WAChB,MAAM,MAAM,GAAG,EAAE,KAAK,SAAS,KAAK,KAAK,CAAC,IAC1C,CAAC,GACQ,IAAI,MAAM;CACxB;CACA,MAAM,YAAqC,CAAC;CAC5C,KAAK,MAAM,CAAC,UAAU,YAAY,OAAO,QAAQ,UAAU,GAC1D,QAAQ,UAAR;EACC,KAAK;GACJ,UAAU,SAAS,OAAO,OAAO;GACjC;EACD,KAAK;GACJ,UAAU,aAAa,OAAO,OAAO;GACrC;EACD,KAAK;GACJ,UAAU,KAAK,YAAY,OAAO;GAClC;EACD,KAAK;GACJ,UAAU,SAAS,YAAY,O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AAU,CAAC;CAE1F,IAAI,iBAAiB,OAAO,GAC3B,MAAM,kBAAkB,CACvB,SAAS,gBAAgB,GACzB,GAAI,WAAW,OAAO,mBAAmB,CAAC,CAC3C;CAED,OAAO;EAAE,GAAG;EAAY;CAAM;AAC/B;;;;;;;;AASA,MAAa,8BAA8B,WAAuC;CACjF,MAAM,aAAa,cAAc,oBAAoB,OAAO,MAAM,CAAC;CACnE,IAAI,WAAW,WAAW,GACzB,OAAO;CAER,OAAO;EACN,GAAG;EACH,OAAO;GACN,GAAG,OAAO;GACV,WAAW,CAAC,GAAI,OAAO,OAAO,aAAa,CAAC,GAAI,mBAAmB,UAAU,CAAC;EAC/E;CACD;AACD"}
1
+ {"version":3,"file":"queryRewrite.js","names":[],"sources":["../../../src/fields/encrypted/queryRewrite.ts"],"sourcesContent":["import type {\n\tCollectionAfterReadHook,\n\tCollectionBeforeOperationHook,\n\tCollectionConfig,\n\tGlobalAfterReadHook,\n\tGlobalConfig,\n\tPayloadRequest,\n\tWhere,\n} from 'payload'\nimport { type CompanionEntry, companionSelect, siblingPath } from '../../plugin/companionSelect'\nimport { computeBidx } from './crypto/bidx'\nimport type { KeyRing } from './crypto/keys'\nimport { contextMode, ringForRequest } from './hooks'\nimport { queryableOnly, scanEncryptedFields } from './scan'\nimport type { EncryptedFieldMarker } from './types'\n\ntype RingResolver = (marker: EncryptedFieldMarker) => Promise<KeyRing>\n\ntype UnsupportedWarn = (path: string, operator: string) => void\n\n/**\n * A blind index answers exact-match only. An unsupported operator is rewritten\n * to this sentinel so the query matches nothing: every real index value is a\n * 24-char base64url string, and a single space is not one. Exported for tests.\n */\nexport const BIDX_NO_MATCH = ' '\n\nconst isPlainObject = (value: unknown): value is Record<string, unknown> =>\n\ttypeof value === 'object' && value !== null && !Array.isArray(value)\n\nconst rewriteConstraint = async (args: {\n\tconstraint: Record<string, unknown>\n\tmarker: EncryptedFieldMarker\n\tringFor: RingResolver\n\twarn: (operator: string) => void\n}): Promise<Record<string, unknown>> => {\n\tconst { constraint, marker, ringFor, warn } = args\n\tconst ring = await ringFor(marker)\n\tconst toBidx = (value: unknown): unknown =>\n\t\tvalue === null ? null : computeBidx(value, ring.indexKey, marker.normalize)\n\t// Payload's REST layer delivers `in`/`not_in` as a comma-joined string, the\n\t// admin and Local API as an array; hash each element under either shape.\n\tconst toBidxArray = (value: unknown): unknown[] => {\n\t\tconst items = Array.isArray(value)\n\t\t\t? value\n\t\t\t: typeof value === 'string'\n\t\t\t\t? value.split(',').map((item) => item.trim())\n\t\t\t\t: []\n\t\treturn items.map(toBidx)\n\t}\n\tconst rewritten: Record<string, unknown> = {}\n\tfor (const [operator, operand] of Object.entries(constraint)) {\n\t\tswitch (operator) {\n\t\t\tcase 'equals':\n\t\t\t\trewritten.equals = toBidx(operand)\n\t\t\t\tbreak\n\t\t\tcase 'not_equals':\n\t\t\t\trewritten.not_equals = toBidx(operand)\n\t\t\t\tbreak\n\t\t\tcase 'in':\n\t\t\t\trewritten.in = toBidxArray(operand)\n\t\t\t\tbreak\n\t\t\tcase 'not_in':\n\t\t\t\trewritten.not_in = toBidxArray(operand)\n\t\t\t\tbreak\n\t\t\tcase 'exists':\n\t\t\t\t// The blind index is written iff the source has a value, so its\n\t\t\t\t// existence tracks the source's. The boolean passes through unhashed.\n\t\t\t\trewritten.exists = operand\n\t\t\t\tbreak\n\t\t\tdefault:\n\t\t\t\t// Substring, range, comparison, and geo operators cannot run over a\n\t\t\t\t// blind index. Match nothing rather than querying the ciphertext\n\t\t\t\t// column, which would read as a working filter while returning junk.\n\t\t\t\twarn(operator)\n\t\t\t\treturn { equals: BIDX_NO_MATCH }\n\t\t}\n\t}\n\treturn rewritten\n}\n\n/** Recursively rewrites queryable encrypted paths to their blind-index siblings. */\nexport const rewriteWhereForMarkers = async (args: {\n\tmarkers: ReadonlyMap<string, EncryptedFieldMarker>\n\tringFor: RingResolver\n\twarn?: UnsupportedWarn\n\twhere: Where\n}): Promise<Where> => {\n\tconst { markers, ringFor, warn = () => {}, where } = args\n\tconst out: Where = {}\n\tfor (const [key, value] of Object.entries(where)) {\n\t\tif ((key === 'and' || key === 'or') && Array.isArray(value)) {\n\t\t\tout[key] = await Promise.all(\n\t\t\t\tvalue.map((nested) =>\n\t\t\t\t\trewriteWhereForMarkers({ markers, ringFor, warn, where: nested as Where })\n\t\t\t\t)\n\t\t\t)\n\t\t\tcontinue\n\t\t}\n\t\tconst marker = markers.get(key)\n\t\tif (marker?.bidxName && isPlainObject(value)) {\n\t\t\tconst rewritten = await rewriteConstraint({\n\t\t\t\tconstraint: value,\n\t\t\t\tmarker,\n\t\t\t\tringFor,\n\t\t\t\twarn: (operator) => warn(key, operator),\n\t\t\t})\n\t\t\tconst bidxPath = key.includes('.')\n\t\t\t\t? `${key.slice(0, key.lastIndexOf('.') + 1)}${marker.bidxName}`\n\t\t\t\t: marker.bidxName\n\t\t\tout[bidxPath] = { ...(out[bidxPath] as Record<string, unknown>), ...rewritten }\n\t\t\tcontinue\n\t\t}\n\t\tout[key] = value as Where[string]\n\t}\n\treturn out\n}\n\nconst makeHook = (\n\tmarkers: ReadonlyMap<string, EncryptedFieldMarker>\n): CollectionBeforeOperationHook => {\n\treturn async ({ args, req }) => {\n\t\tif (isPlainObject(args) && 'where' in args && isPlainObject(args.where)) {\n\t\t\tconst payloadReq = req as PayloadRequest\n\t\t\tconst where = await rewriteWhereForMarkers({\n\t\t\t\tmarkers,\n\t\t\t\tringFor: (marker) => ringForRequest(payloadReq, marker),\n\t\t\t\twarn: (path, operator) =>\n\t\t\t\t\tpayloadReq.payload?.logger?.warn?.(\n\t\t\t\t\t\t`@10x-media/fields: operator '${operator}' cannot run on the encrypted field '${path}'. Blind-index filtering supports exact match only (equals, not_equals, in, not_in, exists); this constraint will match nothing.`\n\t\t\t\t\t),\n\t\t\t\twhere: args.where as Where,\n\t\t\t})\n\t\t\treturn { ...args, where }\n\t\t}\n\t\treturn args\n\t}\n}\n\nconst bidxPathFor = (path: string, bidxName: string): string =>\n\tpath.includes('.') ? `${path.slice(0, path.lastIndexOf('.') + 1)}${bidxName}` : bidxName\n\nconst deleteAtPath = (doc: Record<string, unknown>, path: string): void => {\n\tconst segments = path.split('.')\n\tlet node: Record<string, unknown> = doc\n\tfor (const segment of segments.slice(0, -1)) {\n\t\tconst next = node[segment]\n\t\tif (!next || typeof next !== 'object') {\n\t\t\treturn\n\t\t}\n\t\tnode = next as Record<string, unknown>\n\t}\n\tdelete node[segments[segments.length - 1] as string]\n}\n\n/**\n * Removes server-only encrypted paths from read results: blind-index hashes (so\n * the keyed index value never leaves the server), richText ciphertext siblings\n * (opaque strings the virtual editor field replaces), and write-only fields\n * (whose sealed value passes afterRead untouched and must not surface at all).\n * `admin.hidden` keeps the siblings readable by the plugin's own hooks but,\n * unlike top-level `hidden`, does not strip them from responses.\n */\nconst makeStripPathsHook = (paths: string[]): CollectionAfterReadHook & GlobalAfterReadHook => {\n\treturn ({ context, doc }) => {\n\t\t// Bulk utilities (rotate/adopt/remove) read via pageThrough in `raw`\n\t\t// context and need the ciphertext + blind-index siblings; stripping them\n\t\t// here would make key rotation silently skip every richText field. Only\n\t\t// strip on normal reads.\n\t\tif (contextMode(context as Record<string, unknown>)) {\n\t\t\treturn doc\n\t\t}\n\t\tfor (const path of paths) {\n\t\t\tdeleteAtPath(doc as Record<string, unknown>, path)\n\t\t}\n\t\treturn doc\n\t}\n}\n\n/** Response paths a normal read must not surface, per marker kind. */\nconst stripPathsFor = (markers: ReadonlyMap<string, EncryptedFieldMarker>): string[] => {\n\tconst paths: string[] = []\n\tfor (const [path, marker] of markers) {\n\t\tif (marker.queryable && marker.bidxName) {\n\t\t\tpaths.push(bidxPathFor(path, marker.bidxName))\n\t\t}\n\t\t// richText stores its ciphertext under the marker's own scan path\n\t\t// (`${name}_encrypted`); the write-only path IS the stored field itself.\n\t\tif (marker.sourceType === 'richText' || marker.writeOnly) {\n\t\t\tpaths.push(path)\n\t\t}\n\t}\n\treturn paths\n}\n\n/** Each stored write-only field with the virtual siblings that report on it. */\nconst writeOnlySiblingsFor = (\n\tmarkers: ReadonlyMap<string, EncryptedFieldMarker>\n): CompanionEntry[] => {\n\tconst out: CompanionEntry[] = []\n\tfor (const [path, marker] of markers) {\n\t\tif (!marker.writeOnly) continue\n\t\tconst siblings = [marker.setName, marker.hintName]\n\t\t\t.filter((name): name is string => Boolean(name))\n\t\t\t.map((name) => siblingPath(path, name))\n\t\tif (siblings.length > 0) out.push({ path, siblings })\n\t}\n\treturn out\n}\n\n/**\n * Attaches the blind-index where-rewrite and response stripper to a collection.\n * The fields() plugin applies this to every collection automatically; call it\n * directly only when using encryptedField() standalone without the plugin.\n */\nexport const withEncryptedQueryRewrite = (collection: CollectionConfig): CollectionConfig => {\n\tconst allMarkers = scanEncryptedFields(collection.fields)\n\tconst queryableMarkers = queryableOnly(allMarkers)\n\tconst stripPaths = stripPathsFor(allMarkers)\n\tif (queryableMarkers.size === 0 && stripPaths.length === 0) {\n\t\treturn collection\n\t}\n\tconst hooks: NonNullable<CollectionConfig['hooks']> = { ...collection.hooks }\n\tif (stripPaths.length > 0) {\n\t\thooks.afterRead = [...(collection.hooks?.afterRead ?? []), makeStripPathsHook(stripPaths)]\n\t}\n\tif (queryableMarkers.size > 0) {\n\t\thooks.beforeOperation = [\n\t\t\tmakeHook(queryableMarkers),\n\t\t\t...(collection.hooks?.beforeOperation ?? []),\n\t\t]\n\t}\n\tconst writeOnly = writeOnlySiblingsFor(allMarkers)\n\tif (writeOnly.length > 0) {\n\t\t// The list view selects only visible columns; the write-only cell reads set-ness and\n\t\t// the hint from these siblings, since the stored value never leaves the server.\n\t\treturn { ...collection, hooks, select: companionSelect(writeOnly, collection.select) }\n\t}\n\treturn { ...collection, hooks }\n}\n\n/**\n * Attaches the response stripper to a global. Globals take no `where`, so this\n * is the strip alone: blind-index hashes, richText ciphertext siblings, and\n * write-only fields never surface in a read result. The fields() plugin applies\n * this to every global automatically; call it directly only when using\n * encryptedField() standalone without the plugin.\n */\nexport const withEncryptedResponseStrip = (global: GlobalConfig): GlobalConfig => {\n\tconst stripPaths = stripPathsFor(scanEncryptedFields(global.fields))\n\tif (stripPaths.length === 0) {\n\t\treturn global\n\t}\n\treturn {\n\t\t...global,\n\t\thooks: {\n\t\t\t...global.hooks,\n\t\t\tafterRead: [...(global.hooks?.afterRead ?? []), makeStripPathsHook(stripPaths)],\n\t\t},\n\t}\n}\n"],"mappings":";;;;AA2BA,MAAM,iBAAiB,UACtB,OAAO,UAAU,YAAY,UAAU,QAAQ,CAAC,MAAM,QAAQ,KAAK;AAEpE,MAAM,oBAAoB,OAAO,SAKO;CACvC,MAAM,EAAE,YAAY,QAAQ,SAAS,SAAS;CAC9C,MAAM,OAAO,MAAM,QAAQ,MAAM;CACjC,MAAM,UAAU,UACf,UAAU,OAAO,OAAO,YAAY,OAAO,KAAK,UAAU,OAAO,SAAS;CAG3E,MAAM,eAAe,UAA8B;EAMlD,QALc,MAAM,QAAQ,KAAK,IAC9B,QACA,OAAO,UAAU,WAChB,MAAM,MAAM,GAAG,EAAE,KAAK,SAAS,KAAK,KAAK,CAAC,IAC1C,CAAC,GACQ,IAAI,MAAM;CACxB;CACA,MAAM,YAAqC,CAAC;CAC5C,KAAK,MAAM,CAAC,UAAU,YAAY,OAAO,QAAQ,UAAU,GAC1D,QAAQ,UAAR;EACC,KAAK;GACJ,UAAU,SAAS,OAAO,OAAO;GACjC;EACD,KAAK;GACJ,UAAU,aAAa,OAAO,OAAO;GACrC;EACD,KAAK;GACJ,UAAU,KAAK,YAAY,OAAO;GAClC;EACD,KAAK;GACJ,UAAU,SAAS,YAAY,OAAO;GACtC;EACD,KAAK;GAGJ,UAAU,SAAS;GACnB;EACD;GAIC,KAAK,QAAQ;GACb,OAAO,EAAE,QAAA,IAAsB;CACjC;CAED,OAAO;AACR;;AAGA,MAAa,yBAAyB,OAAO,SAKvB;CACrB,MAAM,EAAE,SAAS,SAAS,aAAa,CAAC,GAAG,UAAU;CACrD,MAAM,MAAa,CAAC;CACpB,KAAK,MA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CAC5E,IAAI,WAAW,SAAS,GACvB,MAAM,YAAY,CAAC,GAAI,WAAW,OAAO,aAAa,CAAC,GAAI,mBAAmB,UAAU,CAAC;CAE1F,IAAI,iBAAiB,OAAO,GAC3B,MAAM,kBAAkB,CACvB,SAAS,gBAAgB,GACzB,GAAI,WAAW,OAAO,mBAAmB,CAAC,CAC3C;CAED,MAAM,YAAY,qBAAqB,UAAU;CACjD,IAAI,UAAU,SAAS,GAGtB,OAAO;EAAE,GAAG;EAAY;EAAO,QAAQ,gBAAgB,WAAW,WAAW,MAAM;CAAE;CAEtF,OAAO;EAAE,GAAG;EAAY;CAAM;AAC/B;;;;;;;;AASA,MAAa,8BAA8B,WAAuC;CACjF,MAAM,aAAa,cAAc,oBAAoB,OAAO,MAAM,CAAC;CACnE,IAAI,WAAW,WAAW,GACzB,OAAO;CAER,OAAO;EACN,GAAG;EACH,OAAO;GACN,GAAG,OAAO;GACV,WAAW,CAAC,GAAI,OAAO,OAAO,aAAa,CAAC,GAAI,mBAAmB,UAAU,CAAC;EAC/E;CACD;AACD"}
@@ -31,7 +31,7 @@ const makeEffectiveValidator = (source) => {
31
31
  return true;
32
32
  };
33
33
  const stock = stockValidators[source.type];
34
- return (value, options) => stock(value, {
34
+ return (value, { jsonSchema: _storedJsonSchema, ...options }) => stock(value, {
35
35
  ...options,
36
36
  ...source
37
37
  });
@@ -1 +1 @@
1
- {"version":3,"file":"validators.js","names":[],"sources":["../../../src/fields/encrypted/validators.ts"],"sourcesContent":["import type { PayloadRequest, Validate } from 'payload'\nimport {\n\tcheckbox,\n\tcode,\n\tdate,\n\temail,\n\tjson,\n\tnumber,\n\tpoint,\n\tradio,\n\tselect,\n\ttext,\n\ttextarea,\n} from 'payload/shared'\nimport { sealedArrayKey, takePlaintext } from './plaintextStash'\nimport type { EncryptedSourceField, EncryptedSourceType } from './types'\n\n/**\n * Erasure signature at the stock-validator boundary. Payload types each\n * validator against its own field config; we dispatch by source type at\n * runtime, so the per-type generics are intentionally widened here.\n */\nexport type PlaintextValidator = (\n\tvalue: unknown,\n\toptions: Record<string, unknown> & { req: PayloadRequest }\n) => Promise<string | true> | string | true\n\nconst stockValidators: Partial<Record<EncryptedSourceType, unknown>> = {\n\tcheckbox,\n\tcode,\n\tdate,\n\temail,\n\tjson,\n\tnumber,\n\tpoint,\n\tradio,\n\tselect,\n\ttext,\n\ttextarea,\n}\n\n/**\n * The validator that must see PLAINTEXT: the user's own validate when given,\n * else the stock validator matching the ORIGINAL field type with the original\n * constraints (required, options, hasMany, min/max, ...) overlaid onto the\n * options Payload builds for the text-backed stored field.\n *\n * richText: payload/shared's richText validator calls the resolved editor,\n * which a text-backed field does not have; enforce required only.\n */\nexport const makeEffectiveValidator = (source: EncryptedSourceField): PlaintextValidator => {\n\tconst userValidate = 'validate' in source ? source.validate : undefined\n\tif (typeof userValidate === 'function') {\n\t\treturn userValidate as PlaintextValidator\n\t}\n\tif (source.type === 'richText') {\n\t\treturn (value, options) => {\n\t\t\tif ('required' in source && source.required === true && value == null) {\n\t\t\t\treturn options.req.t('validation:required')\n\t\t\t}\n\t\t\treturn true\n\t\t}\n\t}\n\tconst stock = stockValidators[source.type] as PlaintextValidator\n\treturn (value, options) => stock(value, { ...options, ...(source as Record<string, unknown>) })\n}\n\nconst WIRE_PREFIX = 'pfe1'\nconst WIRE_SEGMENT = /^[A-Za-z0-9_-]+$/\nconst IV_BYTES = 12\nconst TAG_BYTES = 16\n\n/**\n * Structural wire check kept in sync with crypto/wire.ts parseWire (prefix, 5\n * base64url segments, IV/tag byte lengths). Deliberately duplicated so this\n * module, which runs inside Payload's validate pass, never imports node:crypto;\n * Buffer is a Node global and validate only runs server-side. A string merely\n * shaped like `pfe1.a.b.c.d` must not be treated as sealed, or its plaintext\n * validation would be skipped.\n */\nconst isSealedString = (value: unknown): boolean => {\n\tif (typeof value !== 'string') {\n\t\treturn false\n\t}\n\tconst segments = value.split('.')\n\tif (segments.length !== 5 || segments[0] !== WIRE_PREFIX) {\n\t\treturn false\n\t}\n\tconst [, keyId, iv, ct, tag] = segments as [string, string, string, string, string]\n\tif (![keyId, iv, ct, tag].every((segment) => WIRE_SEGMENT.test(segment))) {\n\t\treturn false\n\t}\n\treturn (\n\t\tBuffer.from(iv, 'base64url').length === IV_BYTES &&\n\t\tBuffer.from(tag, 'base64url').length === TAG_BYTES &&\n\t\tBuffer.from(ct, 'base64url').length > 0\n\t)\n}\n\n/** A `{ [locale]: sealed }` map produced by a locale=all write (M3). */\nconst isSealedLocaleMap = (value: unknown): boolean => {\n\tif (typeof value !== 'object' || value === null || Array.isArray(value)) {\n\t\treturn false\n\t}\n\tconst entries = Object.values(value as Record<string, unknown>)\n\tif (entries.length === 0) {\n\t\treturn false\n\t}\n\treturn entries.every(\n\t\t(entry) =>\n\t\t\tentry == null ||\n\t\t\tisSealedString(entry) ||\n\t\t\t(Array.isArray(entry) && entry.length > 0 && entry.some(isSealedString))\n\t)\n}\n\n/**\n * The stash key for a value that is a sealed single string or an all-sealed\n * array, else undefined. Payload hands validate exactly the value the seal hook\n * returned, so this recomputes the same key the hook stashed under.\n */\nconst sealedStashKey = (value: unknown): string | undefined => {\n\tif (isSealedString(value)) {\n\t\treturn value as string\n\t}\n\tif (Array.isArray(value) && value.length > 0 && value.every(isSealedString)) {\n\t\treturn sealedArrayKey(value as string[])\n\t}\n\treturn undefined\n}\n\n/**\n * The stored field's validate. The seal hook runs first (field beforeChange\n * hooks precede validate) and stashes the pre-seal plaintext on req.context\n * keyed by the sealed value, so validation happens HERE, natively: this honors\n * skipValidation (drafts) and aggregates errors with the right path and req.t,\n * which a throw from the hook cannot. Order:\n * 1. a sealed value/array whose plaintext is stashed -> validate the plaintext\n * (fresh write); no stash -> skip (resubmitted/already-sealed, or a mixed\n * passthrough array, already validated when first written);\n * 2. a sealed locale=all map -> skip (per-locale validation deferred);\n * 3. otherwise validate the incoming value directly (admin form state that\n * never ran the hook, null/undefined/required).\n */\nexport const makeComposedValidate = (effective: PlaintextValidator): Validate => {\n\treturn (value, options) => {\n\t\tconst opts = options as Record<string, unknown> & { req?: PayloadRequest }\n\t\tconst sealedKey = sealedStashKey(value)\n\t\tif (sealedKey !== undefined) {\n\t\t\tif (opts.req) {\n\t\t\t\tconst taken = takePlaintext(opts.req, sealedKey)\n\t\t\t\tif (taken.found) {\n\t\t\t\t\treturn effective(\n\t\t\t\t\t\ttaken.plaintext,\n\t\t\t\t\t\topts as Record<string, unknown> & { req: PayloadRequest }\n\t\t\t\t\t)\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn true\n\t\t}\n\t\tif (value != null && isSealedLocaleMap(value)) {\n\t\t\treturn true\n\t\t}\n\t\treturn effective(value, opts as Record<string, unknown> & { req: PayloadRequest })\n\t}\n}\n"],"mappings":";;;AA2BA,MAAM,kBAAiE;CACtE;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACD;;;;;;;;;;AAWA,MAAa,0BAA0B,WAAqD;CAC3F,MAAM,eAAe,cAAc,SAAS,OAAO,WAAW,KAAA;CAC9D,IAAI,OAAO,iBAAiB,YAC3B,OAAO;CAER,IAAI,OAAO,SAAS,YACnB,QAAQ,OAAO,YAAY;EAC1B,IAAI,cAAc,UAAU,OAAO,aAAa,QAAQ,SAAS,MAChE,OAAO,QAAQ,IAAI,EAAE,qBAAqB;EAE3C,OAAO;CACR;CAED,MAAM,QAAQ,gBAAgB,OAAO;CACrC,QAAQ,OAAO,YAAY,MAAM,OAAO;EAAE,GAAG;EAAS,GAAI;CAAmC,CAAC;AAC/F;AAEA,MAAM,cAAc;AACpB,MAAM,eAAe;AACrB,MAAM,WAAW;AACjB,MAAM,YAAY;;;;;;;;;AAUlB,MAAM,kBAAkB,UAA4B;CACnD,IAAI,OAAO,UAAU,UACpB,OAAO;CAER,MAAM,WAAW,MAAM,MAAM,GAAG;CAChC,IAAI,SAAS,WAAW,KAAK,SAAS,OAAO,aAC5C,OAAO;CAER,MAAM,GAAG,OAAO,IAAI,IAAI,OAAO;CAC/B,IAAI,CAAC;EAAC;EAAO;EAAI;EAAI;CAAG,EAAE,OAAO,YAAY,aAAa,KAAK,OAAO,CAAC,GACtE,OAAO;CAER,OACC,OAAO,KAAK,IAAI,WAAW,EAAE,WAAW,YACxC,OAAO,KAAK,KAAK,WAAW,EAAE,WAAW,aACzC,OAAO,KAAK,IAAI,WAAW,EAAE,SAAS;AAExC;;AAGA,MAAM,qBAAqB,UAA4B;CACtD,IAAI,OAAO,UAAU,YAAY,UAAU,QAAQ,MAAM,QAAQ,KAAK,GACrE,OAAO;CAER,MAAM,UAAU,OAAO,OAAO,KAAgC;CAC9D,IAAI,QAAQ,WAAW,GACtB,OAAO;CAER,OAAO,QAAQ,OACb,UACA,SAAS,QACT,eAAe,KAAK,KACnB,MAAM,QAAQ,KAAK,KAAK,MAAM,SAAS,KAAK,MAAM,KAAK,cAAc,CACxE;AACD;;;;;;AAOA,MAAM,kBAAkB,UAAuC;CAC9D,IAAI,eAAe,KAAK,GACvB,OAAO;CAER,IAAI,MAAM,QAAQ,KAAK,KAAK,MAAM,SAAS,KAAK,MAAM,MAAM,cAAc,GACzE,OAAO,eAAe,KAAiB;AAGzC;;;;;;;;;;;;;;AAeA,MAAa,wBAAwB,cAA4C;CAChF,QAAQ,OAAO,YAAY;EAC1B,MAAM,OAAO;EACb,MAAM,YAAY,eAAe,KAAK;EACtC,IAAI,cAAc,KAAA,GAAW;GAC5B,IAAI,KAAK,KAAK;IACb,MAAM,QAAQ,cAAc,KAAK,KAAK,SAAS;IAC/C,IAAI,MAAM,OACT,OAAO,UACN,MAAM,WACN,IACD;GAEF;GACA,OAAO;EACR;EACA,IAAI,SAAS,QAAQ,kBAAkB,KAAK,GAC3C,OAAO;EAER,OAAO,UAAU,OAAO,IAAyD;CAClF;AACD"}
1
+ {"version":3,"file":"validators.js","names":[],"sources":["../../../src/fields/encrypted/validators.ts"],"sourcesContent":["import type { PayloadRequest, Validate } from 'payload'\nimport {\n\tcheckbox,\n\tcode,\n\tdate,\n\temail,\n\tjson,\n\tnumber,\n\tpoint,\n\tradio,\n\tselect,\n\ttext,\n\ttextarea,\n} from 'payload/shared'\nimport { sealedArrayKey, takePlaintext } from './plaintextStash'\nimport type { EncryptedSourceField, EncryptedSourceType } from './types'\n\n/**\n * Erasure signature at the stock-validator boundary. Payload types each\n * validator against its own field config; we dispatch by source type at\n * runtime, so the per-type generics are intentionally widened here.\n */\nexport type PlaintextValidator = (\n\tvalue: unknown,\n\toptions: Record<string, unknown> & { req: PayloadRequest }\n) => Promise<string | true> | string | true\n\nconst stockValidators: Partial<Record<EncryptedSourceType, unknown>> = {\n\tcheckbox,\n\tcode,\n\tdate,\n\temail,\n\tjson,\n\tnumber,\n\tpoint,\n\tradio,\n\tselect,\n\ttext,\n\ttextarea,\n}\n\n/**\n * The validator that must see PLAINTEXT: the user's own validate when given,\n * else the stock validator matching the ORIGINAL field type with the original\n * constraints (required, options, hasMany, min/max, ...) overlaid onto the\n * options Payload builds for the text-backed stored field.\n *\n * richText: payload/shared's richText validator calls the resolved editor,\n * which a text-backed field does not have; enforce required only.\n */\nexport const makeEffectiveValidator = (source: EncryptedSourceField): PlaintextValidator => {\n\tconst userValidate = 'validate' in source ? source.validate : undefined\n\tif (typeof userValidate === 'function') {\n\t\treturn userValidate as PlaintextValidator\n\t}\n\tif (source.type === 'richText') {\n\t\treturn (value, options) => {\n\t\t\tif ('required' in source && source.required === true && value == null) {\n\t\t\t\treturn options.req.t('validation:required')\n\t\t\t}\n\t\t\treturn true\n\t\t}\n\t}\n\tconst stock = stockValidators[source.type] as PlaintextValidator\n\t// `options` carries the stored text field's `jsonSchema`, an array of type\n\t// transforms; the stock json validator reads the same key as `{ schema, uri }`\n\t// and fetches `uri`. Drop it so only the source's own (json) schema applies.\n\treturn (value, { jsonSchema: _storedJsonSchema, ...options }) =>\n\t\tstock(value, { ...options, ...(source as Record<string, unknown>) } as typeof options)\n}\n\nconst WIRE_PREFIX = 'pfe1'\nconst WIRE_SEGMENT = /^[A-Za-z0-9_-]+$/\nconst IV_BYTES = 12\nconst TAG_BYTES = 16\n\n/**\n * Structural wire check kept in sync with crypto/wire.ts parseWire (prefix, 5\n * base64url segments, IV/tag byte lengths). Deliberately duplicated so this\n * module, which runs inside Payload's validate pass, never imports node:crypto;\n * Buffer is a Node global and validate only runs server-side. A string merely\n * shaped like `pfe1.a.b.c.d` must not be treated as sealed, or its plaintext\n * validation would be skipped.\n */\nconst isSealedString = (value: unknown): boolean => {\n\tif (typeof value !== 'string') {\n\t\treturn false\n\t}\n\tconst segments = value.split('.')\n\tif (segments.length !== 5 || segments[0] !== WIRE_PREFIX) {\n\t\treturn false\n\t}\n\tconst [, keyId, iv, ct, tag] = segments as [string, string, string, string, string]\n\tif (![keyId, iv, ct, tag].every((segment) => WIRE_SEGMENT.test(segment))) {\n\t\treturn false\n\t}\n\treturn (\n\t\tBuffer.from(iv, 'base64url').length === IV_BYTES &&\n\t\tBuffer.from(tag, 'base64url').length === TAG_BYTES &&\n\t\tBuffer.from(ct, 'base64url').length > 0\n\t)\n}\n\n/** A `{ [locale]: sealed }` map produced by a locale=all write (M3). */\nconst isSealedLocaleMap = (value: unknown): boolean => {\n\tif (typeof value !== 'object' || value === null || Array.isArray(value)) {\n\t\treturn false\n\t}\n\tconst entries = Object.values(value as Record<string, unknown>)\n\tif (entries.length === 0) {\n\t\treturn false\n\t}\n\treturn entries.every(\n\t\t(entry) =>\n\t\t\tentry == null ||\n\t\t\tisSealedString(entry) ||\n\t\t\t(Array.isArray(entry) && entry.length > 0 && entry.some(isSealedString))\n\t)\n}\n\n/**\n * The stash key for a value that is a sealed single string or an all-sealed\n * array, else undefined. Payload hands validate exactly the value the seal hook\n * returned, so this recomputes the same key the hook stashed under.\n */\nconst sealedStashKey = (value: unknown): string | undefined => {\n\tif (isSealedString(value)) {\n\t\treturn value as string\n\t}\n\tif (Array.isArray(value) && value.length > 0 && value.every(isSealedString)) {\n\t\treturn sealedArrayKey(value as string[])\n\t}\n\treturn undefined\n}\n\n/**\n * The stored field's validate. The seal hook runs first (field beforeChange\n * hooks precede validate) and stashes the pre-seal plaintext on req.context\n * keyed by the sealed value, so validation happens HERE, natively: this honors\n * skipValidation (drafts) and aggregates errors with the right path and req.t,\n * which a throw from the hook cannot. Order:\n * 1. a sealed value/array whose plaintext is stashed -> validate the plaintext\n * (fresh write); no stash -> skip (resubmitted/already-sealed, or a mixed\n * passthrough array, already validated when first written);\n * 2. a sealed locale=all map -> skip (per-locale validation deferred);\n * 3. otherwise validate the incoming value directly (admin form state that\n * never ran the hook, null/undefined/required).\n */\nexport const makeComposedValidate = (effective: PlaintextValidator): Validate => {\n\treturn (value, options) => {\n\t\tconst opts = options as Record<string, unknown> & { req?: PayloadRequest }\n\t\tconst sealedKey = sealedStashKey(value)\n\t\tif (sealedKey !== undefined) {\n\t\t\tif (opts.req) {\n\t\t\t\tconst taken = takePlaintext(opts.req, sealedKey)\n\t\t\t\tif (taken.found) {\n\t\t\t\t\treturn effective(\n\t\t\t\t\t\ttaken.plaintext,\n\t\t\t\t\t\topts as Record<string, unknown> & { req: PayloadRequest }\n\t\t\t\t\t)\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn true\n\t\t}\n\t\tif (value != null && isSealedLocaleMap(value)) {\n\t\t\treturn true\n\t\t}\n\t\treturn effective(value, opts as Record<string, unknown> & { req: PayloadRequest })\n\t}\n}\n"],"mappings":";;;AA2BA,MAAM,kBAAiE;CACtE;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACD;;;;;;;;;;AAWA,MAAa,0BAA0B,WAAqD;CAC3F,MAAM,eAAe,cAAc,SAAS,OAAO,WAAW,KAAA;CAC9D,IAAI,OAAO,iBAAiB,YAC3B,OAAO;CAER,IAAI,OAAO,SAAS,YACnB,QAAQ,OAAO,YAAY;EAC1B,IAAI,cAAc,UAAU,OAAO,aAAa,QAAQ,SAAS,MAChE,OAAO,QAAQ,IAAI,EAAE,qBAAqB;EAE3C,OAAO;CACR;CAED,MAAM,QAAQ,gBA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AAK;EACtC,IAAI,cAAc,KAAA,GAAW;GAC5B,IAAI,KAAK,KAAK;IACb,MAAM,QAAQ,cAAc,KAAK,KAAK,SAAS;IAC/C,IAAI,MAAM,OACT,OAAO,UACN,MAAM,WACN,IACD;GAEF;GACA,OAAO;EACR;EACA,IAAI,SAAS,QAAQ,kBAAkB,KAAK,GAC3C,OAAO;EAER,OAAO,UAAU,OAAO,IAAyD;CAClF;AACD"}
@@ -4359,7 +4359,7 @@ const nodes = {
4359
4359
  ["path", { "d": "M14 10l-2 2.5l2 2.5" }],
4360
4360
  ["path", { "d": "M12 4c4.97 0 9 3.358 9 7.5c0 4.142 -4.03 7.5 -9 7.5c-.67 0 -1.323 -.061 -1.95 -.177l-3.05 2.177l.592 -2.962c-2.741 -1.284 -4.592 -3.73 -4.592 -6.538c0 -4.142 4.03 -7.5 9 -7.5z" }]
4361
4361
  ],
4362
- "brand-kbin": [["g", { "stroke-width": "1.838" }]],
4362
+ "brand-kbin": [["g", { "strokeWidth": "1.838" }]],
4363
4363
  "brand-kick": [["path", { "d": "M4 4h5v4h3v-2h2v-2h6v4h-2v2h-2v4h2v2h2v4h-6v-2h-2v-2h-3v4h-5z" }]],
4364
4364
  "brand-kickstarter": [["path", { "d": "M11 9l2.975 -4.65c.615 -.9 1.405 -1.35 2.377 -1.35c.79 0 1.474 .286 2.054 .858c.576 .574 .866 1.256 .866 2.054c0 .588 -.153 1.109 -.46 1.559l-2.812 4.029l3.465 4.912c.356 .46 .535 1 .535 1.613a2.92 2.92 0 0 1 -.843 2.098c-.561 .584 -1.242 .877 -2.04 .877c-.876 0 -1.545 -.29 -2 -.87l-4.112 -5.697v3.067c0 .876 -.313 1.69 -.611 2.175c-.543 .883 -1.35 1.325 -2.389 1.325c-.944 0 -1.753 -.327 -2.271 -.974c-.486 -.6 -.729 -1.392 -.729 -2.38v-11.371c0 -.934 .247 -1.706 .74 -2.313c.512 -.641 1.347 -.962 2.26 -.962c.868 0 1.821 .321 2.4 .962c.323 .356 .515 .714 .6 1.08c.052 .224 0 .643 0 1.26v2.698z" }]],
4365
4365
  "brand-kotlin": [