@10x-media/fields 0.1.0-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (299) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/LICENSE +21 -0
  3. package/README.md +62 -0
  4. package/dist/exports/client.d.ts +7 -0
  5. package/dist/exports/client.js +8 -0
  6. package/dist/exports/color-utils.d.ts +9 -0
  7. package/dist/exports/color-utils.js +7 -0
  8. package/dist/exports/color.d.ts +6 -0
  9. package/dist/exports/color.js +5 -0
  10. package/dist/exports/encrypted.d.ts +12 -0
  11. package/dist/exports/encrypted.js +10 -0
  12. package/dist/exports/i18n.d.ts +3 -0
  13. package/dist/exports/i18n.js +3 -0
  14. package/dist/exports/icon-adapters/lucide.d.ts +5 -0
  15. package/dist/exports/icon-adapters/lucide.js +4 -0
  16. package/dist/exports/icon-adapters/radix.d.ts +5 -0
  17. package/dist/exports/icon-adapters/radix.js +4 -0
  18. package/dist/exports/icon-adapters/tabler.d.ts +5 -0
  19. package/dist/exports/icon-adapters/tabler.js +4 -0
  20. package/dist/exports/icon-codegen.d.ts +4 -0
  21. package/dist/exports/icon-codegen.js +2 -0
  22. package/dist/exports/icon-react.d.ts +4 -0
  23. package/dist/exports/icon-react.js +3 -0
  24. package/dist/exports/icon.d.ts +8 -0
  25. package/dist/exports/icon.js +7 -0
  26. package/dist/exports/rsc.d.ts +10 -0
  27. package/dist/exports/rsc.js +9 -0
  28. package/dist/exports/types.d.ts +4 -0
  29. package/dist/exports/types.js +1 -0
  30. package/dist/fields/color/client/ColorField.d.ts +13 -0
  31. package/dist/fields/color/client/ColorField.js +321 -0
  32. package/dist/fields/color/client/ColorField.js.map +1 -0
  33. package/dist/fields/color/client/ColorPickerPanel.d.ts +29 -0
  34. package/dist/fields/color/client/ColorPickerPanel.js +233 -0
  35. package/dist/fields/color/client/ColorPickerPanel.js.map +1 -0
  36. package/dist/fields/color/client/colorField.css +411 -0
  37. package/dist/fields/color/client/icons.js +38 -0
  38. package/dist/fields/color/client/icons.js.map +1 -0
  39. package/dist/fields/color/colorField.d.ts +20 -0
  40. package/dist/fields/color/colorField.js +102 -0
  41. package/dist/fields/color/colorField.js.map +1 -0
  42. package/dist/fields/color/commitValue.js +29 -0
  43. package/dist/fields/color/commitValue.js.map +1 -0
  44. package/dist/fields/color/engine/contrast.d.ts +10 -0
  45. package/dist/fields/color/engine/contrast.js +25 -0
  46. package/dist/fields/color/engine/contrast.js.map +1 -0
  47. package/dist/fields/color/engine/convert.d.ts +28 -0
  48. package/dist/fields/color/engine/convert.js +232 -0
  49. package/dist/fields/color/engine/convert.js.map +1 -0
  50. package/dist/fields/color/engine/format.d.ts +15 -0
  51. package/dist/fields/color/engine/format.js +53 -0
  52. package/dist/fields/color/engine/format.js.map +1 -0
  53. package/dist/fields/color/engine/index.d.ts +8 -0
  54. package/dist/fields/color/engine/namedColors.d.ts +9 -0
  55. package/dist/fields/color/engine/namedColors.js +159 -0
  56. package/dist/fields/color/engine/namedColors.js.map +1 -0
  57. package/dist/fields/color/engine/parse.d.ts +12 -0
  58. package/dist/fields/color/engine/parse.js +151 -0
  59. package/dist/fields/color/engine/parse.js.map +1 -0
  60. package/dist/fields/color/engine/salvage.d.ts +13 -0
  61. package/dist/fields/color/engine/salvage.js +75 -0
  62. package/dist/fields/color/engine/salvage.js.map +1 -0
  63. package/dist/fields/color/engine/types.d.ts +34 -0
  64. package/dist/fields/color/options.d.ts +55 -0
  65. package/dist/fields/color/options.js +8 -0
  66. package/dist/fields/color/options.js.map +1 -0
  67. package/dist/fields/color/presetChip.js +27 -0
  68. package/dist/fields/color/presetChip.js.map +1 -0
  69. package/dist/fields/color/presetsFromDoc.d.ts +27 -0
  70. package/dist/fields/color/presetsFromDoc.js +74 -0
  71. package/dist/fields/color/presetsFromDoc.js.map +1 -0
  72. package/dist/fields/color/resolveFormat.js +16 -0
  73. package/dist/fields/color/resolveFormat.js.map +1 -0
  74. package/dist/fields/color/resolvePresets.d.ts +29 -0
  75. package/dist/fields/color/resolvePresets.js +39 -0
  76. package/dist/fields/color/resolvePresets.js.map +1 -0
  77. package/dist/fields/color/server/ColorCell.d.ts +6 -0
  78. package/dist/fields/color/server/ColorCell.js +34 -0
  79. package/dist/fields/color/server/ColorCell.js.map +1 -0
  80. package/dist/fields/color/server/ColorFieldServer.d.ts +18 -0
  81. package/dist/fields/color/server/ColorFieldServer.js +69 -0
  82. package/dist/fields/color/server/ColorFieldServer.js.map +1 -0
  83. package/dist/fields/color/server/colorCell.css +32 -0
  84. package/dist/fields/encrypted/boot.d.ts +14 -0
  85. package/dist/fields/encrypted/boot.js +22 -0
  86. package/dist/fields/encrypted/boot.js.map +1 -0
  87. package/dist/fields/encrypted/components/EncryptedInput.js +89 -0
  88. package/dist/fields/encrypted/components/EncryptedInput.js.map +1 -0
  89. package/dist/fields/encrypted/components/EncryptedTextarea.js +86 -0
  90. package/dist/fields/encrypted/components/EncryptedTextarea.js.map +1 -0
  91. package/dist/fields/encrypted/components/EyeToggle.js +51 -0
  92. package/dist/fields/encrypted/components/EyeToggle.js.map +1 -0
  93. package/dist/fields/encrypted/components/MaskDots.js +20 -0
  94. package/dist/fields/encrypted/components/MaskDots.js.map +1 -0
  95. package/dist/fields/encrypted/components/ProtectedCell.d.ts +19 -0
  96. package/dist/fields/encrypted/components/ProtectedCell.js +44 -0
  97. package/dist/fields/encrypted/components/ProtectedCell.js.map +1 -0
  98. package/dist/fields/encrypted/components/ProtectedField.css +180 -0
  99. package/dist/fields/encrypted/components/ProtectedField.d.ts +30 -0
  100. package/dist/fields/encrypted/components/ProtectedField.js +95 -0
  101. package/dist/fields/encrypted/components/ProtectedField.js.map +1 -0
  102. package/dist/fields/encrypted/components/ProtectedRichText.d.ts +21 -0
  103. package/dist/fields/encrypted/components/ProtectedRichText.js +35 -0
  104. package/dist/fields/encrypted/components/ProtectedRichText.js.map +1 -0
  105. package/dist/fields/encrypted/components/RichTextRevealGate.d.ts +24 -0
  106. package/dist/fields/encrypted/components/RichTextRevealGate.js +87 -0
  107. package/dist/fields/encrypted/components/RichTextRevealGate.js.map +1 -0
  108. package/dist/fields/encrypted/components/StructuralField.js +64 -0
  109. package/dist/fields/encrypted/components/StructuralField.js.map +1 -0
  110. package/dist/fields/encrypted/components/facsimiles.js +219 -0
  111. package/dist/fields/encrypted/components/facsimiles.js.map +1 -0
  112. package/dist/fields/encrypted/components/placement.js +21 -0
  113. package/dist/fields/encrypted/components/placement.js.map +1 -0
  114. package/dist/fields/encrypted/crypto/aad.js +29 -0
  115. package/dist/fields/encrypted/crypto/aad.js.map +1 -0
  116. package/dist/fields/encrypted/crypto/bidx.js +26 -0
  117. package/dist/fields/encrypted/crypto/bidx.js.map +1 -0
  118. package/dist/fields/encrypted/crypto/keys.d.ts +31 -0
  119. package/dist/fields/encrypted/crypto/keys.js +113 -0
  120. package/dist/fields/encrypted/crypto/keys.js.map +1 -0
  121. package/dist/fields/encrypted/crypto/wire.d.ts +23 -0
  122. package/dist/fields/encrypted/crypto/wire.js +135 -0
  123. package/dist/fields/encrypted/crypto/wire.js.map +1 -0
  124. package/dist/fields/encrypted/encryptedField.d.ts +15 -0
  125. package/dist/fields/encrypted/encryptedField.js +187 -0
  126. package/dist/fields/encrypted/encryptedField.js.map +1 -0
  127. package/dist/fields/encrypted/hooks.d.ts +21 -0
  128. package/dist/fields/encrypted/hooks.js +326 -0
  129. package/dist/fields/encrypted/hooks.js.map +1 -0
  130. package/dist/fields/encrypted/maskDots.js +16 -0
  131. package/dist/fields/encrypted/maskDots.js.map +1 -0
  132. package/dist/fields/encrypted/plaintextStash.js +57 -0
  133. package/dist/fields/encrypted/plaintextStash.js.map +1 -0
  134. package/dist/fields/encrypted/queryRewrite.d.ts +12 -0
  135. package/dist/fields/encrypted/queryRewrite.js +134 -0
  136. package/dist/fields/encrypted/queryRewrite.js.map +1 -0
  137. package/dist/fields/encrypted/scan.js +36 -0
  138. package/dist/fields/encrypted/scan.js.map +1 -0
  139. package/dist/fields/encrypted/types.d.ts +35 -0
  140. package/dist/fields/encrypted/types.js +12 -0
  141. package/dist/fields/encrypted/types.js.map +1 -0
  142. package/dist/fields/encrypted/typescriptSchema.js +41 -0
  143. package/dist/fields/encrypted/typescriptSchema.js.map +1 -0
  144. package/dist/fields/encrypted/utils/decryptAllData.d.ts +17 -0
  145. package/dist/fields/encrypted/utils/decryptAllData.js +98 -0
  146. package/dist/fields/encrypted/utils/decryptAllData.js.map +1 -0
  147. package/dist/fields/encrypted/utils/encryptExistingData.d.ts +14 -0
  148. package/dist/fields/encrypted/utils/encryptExistingData.js +72 -0
  149. package/dist/fields/encrypted/utils/encryptExistingData.js.map +1 -0
  150. package/dist/fields/encrypted/utils/pageThrough.js +42 -0
  151. package/dist/fields/encrypted/utils/pageThrough.js.map +1 -0
  152. package/dist/fields/encrypted/utils/rotateEncryptedFields.d.ts +27 -0
  153. package/dist/fields/encrypted/utils/rotateEncryptedFields.js +92 -0
  154. package/dist/fields/encrypted/utils/rotateEncryptedFields.js.map +1 -0
  155. package/dist/fields/encrypted/validators.js +111 -0
  156. package/dist/fields/encrypted/validators.js.map +1 -0
  157. package/dist/fields/icon/adapters/lucide/adapter.d.ts +8 -0
  158. package/dist/fields/icon/adapters/lucide/adapter.js +15 -0
  159. package/dist/fields/icon/adapters/lucide/adapter.js.map +1 -0
  160. package/dist/fields/icon/adapters/lucide/client.d.ts +10 -0
  161. package/dist/fields/icon/adapters/lucide/client.js +41 -0
  162. package/dist/fields/icon/adapters/lucide/client.js.map +1 -0
  163. package/dist/fields/icon/adapters/lucide/generated/manifest.js +23338 -0
  164. package/dist/fields/icon/adapters/lucide/generated/manifest.js.map +1 -0
  165. package/dist/fields/icon/adapters/lucide/generated/nodes.js +14296 -0
  166. package/dist/fields/icon/adapters/lucide/generated/nodes.js.map +1 -0
  167. package/dist/fields/icon/adapters/lucide/renderer.d.ts +7 -0
  168. package/dist/fields/icon/adapters/lucide/renderer.js +13 -0
  169. package/dist/fields/icon/adapters/lucide/renderer.js.map +1 -0
  170. package/dist/fields/icon/adapters/radix/adapter.d.ts +8 -0
  171. package/dist/fields/icon/adapters/radix/adapter.js +14 -0
  172. package/dist/fields/icon/adapters/radix/adapter.js.map +1 -0
  173. package/dist/fields/icon/adapters/radix/client.d.ts +8 -0
  174. package/dist/fields/icon/adapters/radix/client.js +20 -0
  175. package/dist/fields/icon/adapters/radix/client.js.map +1 -0
  176. package/dist/fields/icon/adapters/radix/generated/imports.js +324 -0
  177. package/dist/fields/icon/adapters/radix/generated/imports.js.map +1 -0
  178. package/dist/fields/icon/adapters/radix/generated/manifest.js +1805 -0
  179. package/dist/fields/icon/adapters/radix/generated/manifest.js.map +1 -0
  180. package/dist/fields/icon/adapters/radix/renderer.d.ts +7 -0
  181. package/dist/fields/icon/adapters/radix/renderer.js +23 -0
  182. package/dist/fields/icon/adapters/radix/renderer.js.map +1 -0
  183. package/dist/fields/icon/adapters/tabler/adapter.d.ts +8 -0
  184. package/dist/fields/icon/adapters/tabler/adapter.js +15 -0
  185. package/dist/fields/icon/adapters/tabler/adapter.js.map +1 -0
  186. package/dist/fields/icon/adapters/tabler/client.d.ts +9 -0
  187. package/dist/fields/icon/adapters/tabler/client.js +18 -0
  188. package/dist/fields/icon/adapters/tabler/client.js.map +1 -0
  189. package/dist/fields/icon/adapters/tabler/generated/imports.js +4942 -0
  190. package/dist/fields/icon/adapters/tabler/generated/imports.js.map +1 -0
  191. package/dist/fields/icon/adapters/tabler/generated/manifest.js +61269 -0
  192. package/dist/fields/icon/adapters/tabler/generated/manifest.js.map +1 -0
  193. package/dist/fields/icon/adapters/tabler/generated/nodes.js +26749 -0
  194. package/dist/fields/icon/adapters/tabler/generated/nodes.js.map +1 -0
  195. package/dist/fields/icon/adapters/tabler/renderer.d.ts +7 -0
  196. package/dist/fields/icon/adapters/tabler/renderer.js +13 -0
  197. package/dist/fields/icon/adapters/tabler/renderer.js.map +1 -0
  198. package/dist/fields/icon/client/DrawerGlyph.js +32 -0
  199. package/dist/fields/icon/client/DrawerGlyph.js.map +1 -0
  200. package/dist/fields/icon/client/IconDrawerContent.js +294 -0
  201. package/dist/fields/icon/client/IconDrawerContent.js.map +1 -0
  202. package/dist/fields/icon/client/IconFieldClient.d.ts +19 -0
  203. package/dist/fields/icon/client/IconFieldClient.js +245 -0
  204. package/dist/fields/icon/client/IconFieldClient.js.map +1 -0
  205. package/dist/fields/icon/client/IconLibrarySelect.d.ts +14 -0
  206. package/dist/fields/icon/client/IconLibrarySelect.js +36 -0
  207. package/dist/fields/icon/client/IconLibrarySelect.js.map +1 -0
  208. package/dist/fields/icon/client/availableLibraries.js +25 -0
  209. package/dist/fields/icon/client/availableLibraries.js.map +1 -0
  210. package/dist/fields/icon/client/generatedAdapter.js +88 -0
  211. package/dist/fields/icon/client/generatedAdapter.js.map +1 -0
  212. package/dist/fields/icon/client/icon-field.css +524 -0
  213. package/dist/fields/icon/client/useRecentIcons.js +32 -0
  214. package/dist/fields/icon/client/useRecentIcons.js.map +1 -0
  215. package/dist/fields/icon/codegen/emit.js +81 -0
  216. package/dist/fields/icon/codegen/emit.js.map +1 -0
  217. package/dist/fields/icon/codegen/generate.d.ts +10 -0
  218. package/dist/fields/icon/codegen/generate.js +59 -0
  219. package/dist/fields/icon/codegen/generate.js.map +1 -0
  220. package/dist/fields/icon/codegen/sources/lucide.js +52 -0
  221. package/dist/fields/icon/codegen/sources/lucide.js.map +1 -0
  222. package/dist/fields/icon/codegen/sources/radix.js +33 -0
  223. package/dist/fields/icon/codegen/sources/radix.js.map +1 -0
  224. package/dist/fields/icon/codegen/sources/tabler.js +31 -0
  225. package/dist/fields/icon/codegen/sources/tabler.js.map +1 -0
  226. package/dist/fields/icon/codegen/types.d.ts +36 -0
  227. package/dist/fields/icon/defineIconAdapter.d.ts +8 -0
  228. package/dist/fields/icon/defineIconAdapter.js +10 -0
  229. package/dist/fields/icon/defineIconAdapter.js.map +1 -0
  230. package/dist/fields/icon/plugin.js +55 -0
  231. package/dist/fields/icon/plugin.js.map +1 -0
  232. package/dist/fields/icon/react/createIcon.d.ts +15 -0
  233. package/dist/fields/icon/react/createIcon.js +47 -0
  234. package/dist/fields/icon/react/createIcon.js.map +1 -0
  235. package/dist/fields/icon/react/createRscIcon.d.ts +12 -0
  236. package/dist/fields/icon/react/createRscIcon.js +27 -0
  237. package/dist/fields/icon/react/createRscIcon.js.map +1 -0
  238. package/dist/fields/icon/react/types.d.ts +24 -0
  239. package/dist/fields/icon/rsc/IconCell.d.ts +14 -0
  240. package/dist/fields/icon/rsc/IconCell.js +32 -0
  241. package/dist/fields/icon/rsc/IconCell.js.map +1 -0
  242. package/dist/fields/icon/rsc/IconFieldServer.d.ts +24 -0
  243. package/dist/fields/icon/rsc/IconFieldServer.js +74 -0
  244. package/dist/fields/icon/rsc/IconFieldServer.js.map +1 -0
  245. package/dist/fields/icon/rsc/IconLibrarySelectServer.d.ts +13 -0
  246. package/dist/fields/icon/rsc/IconLibrarySelectServer.js +24 -0
  247. package/dist/fields/icon/rsc/IconLibrarySelectServer.js.map +1 -0
  248. package/dist/fields/icon/rsc/resolveStaticLabel.js +16 -0
  249. package/dist/fields/icon/rsc/resolveStaticLabel.js.map +1 -0
  250. package/dist/fields/icon/server/availability.d.ts +32 -0
  251. package/dist/fields/icon/server/availability.js +58 -0
  252. package/dist/fields/icon/server/availability.js.map +1 -0
  253. package/dist/fields/icon/server/iconField.d.ts +32 -0
  254. package/dist/fields/icon/server/iconField.js +48 -0
  255. package/dist/fields/icon/server/iconField.js.map +1 -0
  256. package/dist/fields/icon/server/iconLibraryField.d.ts +23 -0
  257. package/dist/fields/icon/server/iconLibraryField.js +50 -0
  258. package/dist/fields/icon/server/iconLibraryField.js.map +1 -0
  259. package/dist/fields/icon/server/libraryOptions.d.ts +12 -0
  260. package/dist/fields/icon/server/libraryOptions.js +13 -0
  261. package/dist/fields/icon/server/libraryOptions.js.map +1 -0
  262. package/dist/fields/icon/server/manifestCache.js +17 -0
  263. package/dist/fields/icon/server/manifestCache.js.map +1 -0
  264. package/dist/fields/icon/server/validate.js +37 -0
  265. package/dist/fields/icon/server/validate.js.map +1 -0
  266. package/dist/fields/icon/shared/adapterComponents.d.ts +23 -0
  267. package/dist/fields/icon/shared/formatIconLabel.js +16 -0
  268. package/dist/fields/icon/shared/formatIconLabel.js.map +1 -0
  269. package/dist/fields/icon/shared/search.js +58 -0
  270. package/dist/fields/icon/shared/search.js.map +1 -0
  271. package/dist/fields/icon/shared/value.d.ts +16 -0
  272. package/dist/fields/icon/shared/value.js +27 -0
  273. package/dist/fields/icon/shared/value.js.map +1 -0
  274. package/dist/index.d.ts +39 -0
  275. package/dist/index.js +41 -0
  276. package/dist/index.js.map +1 -0
  277. package/dist/plugin/registerTranslations.js +19 -0
  278. package/dist/plugin/registerTranslations.js.map +1 -0
  279. package/dist/plugin/registry.d.ts +9 -0
  280. package/dist/plugin/registry.js +14 -0
  281. package/dist/plugin/registry.js.map +1 -0
  282. package/dist/translations/de.js +49 -0
  283. package/dist/translations/de.js.map +1 -0
  284. package/dist/translations/en.js +49 -0
  285. package/dist/translations/en.js.map +1 -0
  286. package/dist/translations/index.d.ts +15 -0
  287. package/dist/translations/index.js +30 -0
  288. package/dist/translations/index.js.map +1 -0
  289. package/dist/translations/keys.d.ts +48 -0
  290. package/dist/translations/keys.js +48 -0
  291. package/dist/translations/keys.js.map +1 -0
  292. package/dist/translations/server.js +13 -0
  293. package/dist/translations/server.js.map +1 -0
  294. package/dist/translations/useTranslation.js +12 -0
  295. package/dist/translations/useTranslation.js.map +1 -0
  296. package/dist/types.d.ts +105 -0
  297. package/dist/utils/memoForRequest.js +25 -0
  298. package/dist/utils/memoForRequest.js.map +1 -0
  299. package/package.json +196 -0
@@ -0,0 +1,326 @@
1
+ import { resolveKeys } from "./crypto/keys.js";
2
+ import { ENCRYPTED_CONTEXT_KEY } from "./types.js";
3
+ import { computeBidx } from "./crypto/bidx.js";
4
+ import { getFieldsRegistry } from "../../plugin/registry.js";
5
+ import { buildAad } from "./crypto/aad.js";
6
+ import { isSealed, parseWire, seal, unseal } from "./crypto/wire.js";
7
+ import { sealedArrayKey, stashPlaintext } from "./plaintextStash.js";
8
+ //#region src/fields/encrypted/hooks.ts
9
+ /** Raised on read when decryption fails and the policy is 'throw'. */
10
+ var DecryptFailedError = class extends Error {
11
+ constructor({ cause, field, keyId, slug }) {
12
+ const keyInfo = keyId ? ` (keyId '${keyId}')` : "";
13
+ super(`@10x-media/fields: failed to decrypt ${slug}.${field}${keyInfo}: ${cause instanceof Error ? cause.name : "unknown error"}`);
14
+ this.name = "DecryptFailedError";
15
+ this.cause = cause;
16
+ }
17
+ };
18
+ const ringForRequest = (req, marker) => {
19
+ const registry = getFieldsRegistry(req.payload.config);
20
+ return resolveKeys(marker.keys ?? registry?.encrypted?.keys, req.payload.config.secret);
21
+ };
22
+ const aadSlug = (collection, global) => collection?.slug ?? global?.slug ?? "";
23
+ const defaultLocale = (config) => config.localization ? config.localization.defaultLocale : "en";
24
+ /** Mirrors beforeChange/promise.ts: the locale a write applies to. */
25
+ const operationLocale = (req) => {
26
+ const locale = req.locale;
27
+ if (!locale || locale === "all") return defaultLocale(req.payload.config);
28
+ return locale;
29
+ };
30
+ /**
31
+ * AAD binds a ciphertext to its `${slug}.${field}[.${locale}]` slot via
32
+ * buildAad, which rejects any dotted component so the joined data stays
33
+ * unambiguous (a dotted slug/locale would blur the cross-field binding).
34
+ */
35
+ const sealAad = (marker, slug, req) => buildAad(marker.localized ? [
36
+ slug,
37
+ marker.fieldName,
38
+ operationLocale(req)
39
+ ] : [slug, marker.fieldName]);
40
+ /**
41
+ * Read-side AAD candidates. Localized fields try the request locale first,
42
+ * then every configured locale: fallbackLocale hoisting and locale=all hook
43
+ * execution mean the hook cannot know which locale sealed the value.
44
+ */
45
+ const readAadCandidates = (marker, slug, req) => {
46
+ if (!marker.localized) return [buildAad([slug, marker.fieldName])];
47
+ const codes = req.payload.config.localization ? req.payload.config.localization.localeCodes : [defaultLocale(req.payload.config)];
48
+ const first = operationLocale(req);
49
+ return [first, ...codes.filter((code) => code !== first)].map((code) => buildAad([
50
+ slug,
51
+ marker.fieldName,
52
+ code
53
+ ]));
54
+ };
55
+ /**
56
+ * The active utility mode from the request context, or undefined for a normal
57
+ * operation (including a missing context, which reads as normal). Reused by the
58
+ * response stripper so bulk utilities (which read in `raw` mode) still see the
59
+ * ciphertext and blind-index siblings, while a normal read strips them.
60
+ */
61
+ const contextMode = (context) => {
62
+ const mode = context?.[ENCRYPTED_CONTEXT_KEY];
63
+ return mode === "decrypt" || mode === "raw" || mode === "rotate" ? mode : void 0;
64
+ };
65
+ /** A locale=all write hands the hook a `{ [locale]: value }` map, not a scalar. */
66
+ const isLocaleMap = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
67
+ /** Seal one locale's value, passing already-sealed items through unchanged. */
68
+ const sealValueForLocale = (value, args) => {
69
+ if (value == null) return value;
70
+ const sealItem = (item) => isSealed(item) ? item : seal({
71
+ aad: args.aad,
72
+ key: args.key,
73
+ keyId: args.keyId,
74
+ plaintext: item
75
+ });
76
+ return args.hasMany && Array.isArray(value) ? value.map(sealItem) : sealItem(value);
77
+ };
78
+ const makeBeforeChangeHook = (marker) => {
79
+ return async (args) => {
80
+ const { collection, global, req, siblingData, value } = args;
81
+ const mode = contextMode(req.context);
82
+ if (mode === "raw") return value;
83
+ if (mode === "decrypt") {
84
+ if (marker.queryable && marker.bidxName) siblingData[marker.bidxName] = null;
85
+ return value;
86
+ }
87
+ const slug = aadSlug(collection, global);
88
+ const ring = await ringForRequest(req, marker);
89
+ const activeKey = ring.dataKeys.get(ring.activeId);
90
+ if (mode === "rotate") {
91
+ const candidates = readAadCandidates(marker, slug, req);
92
+ const writeAad = sealAad(marker, slug, req);
93
+ const rotateOne = (item) => {
94
+ if (!isSealed(item)) return item;
95
+ if (parseWire(item).keyId === ring.activeId) return item;
96
+ const plaintext = unseal(item, ring.dataKeys, candidates);
97
+ if (marker.queryable && marker.bidxName) siblingData[marker.bidxName] = computeBidx(plaintext, ring.indexKey, marker.normalize);
98
+ return seal({
99
+ aad: writeAad,
100
+ key: activeKey,
101
+ keyId: ring.activeId,
102
+ plaintext
103
+ });
104
+ };
105
+ return marker.hasMany && Array.isArray(value) ? value.map(rotateOne) : rotateOne(value);
106
+ }
107
+ if (value === void 0) return;
108
+ if (value === null) {
109
+ if (marker.queryable && marker.bidxName) siblingData[marker.bidxName] = null;
110
+ return null;
111
+ }
112
+ if (marker.localized && req.locale === "all" && isLocaleMap(value)) {
113
+ const sealedMap = {};
114
+ for (const [locale, localeValue] of Object.entries(value)) sealedMap[locale] = sealValueForLocale(localeValue, {
115
+ aad: buildAad([
116
+ slug,
117
+ marker.fieldName,
118
+ locale
119
+ ]),
120
+ hasMany: marker.hasMany,
121
+ key: activeKey,
122
+ keyId: ring.activeId
123
+ });
124
+ return sealedMap;
125
+ }
126
+ const aad = sealAad(marker, slug, req);
127
+ const sealOne = (item) => seal({
128
+ aad,
129
+ key: activeKey,
130
+ keyId: ring.activeId,
131
+ plaintext: item
132
+ });
133
+ if (marker.hasMany) {
134
+ if (!Array.isArray(value)) return value;
135
+ const sealedArray = value.map((item) => isSealed(item) ? item : sealOne(item));
136
+ if (!value.some(isSealed)) stashPlaintext(req, sealedArrayKey(sealedArray), value);
137
+ return sealedArray;
138
+ }
139
+ if (isSealed(value)) return value;
140
+ const sealed = sealOne(value);
141
+ stashPlaintext(req, sealed, value);
142
+ if (marker.queryable && marker.bidxName) siblingData[marker.bidxName] = computeBidx(value, ring.indexKey, marker.normalize);
143
+ return sealed;
144
+ };
145
+ };
146
+ const applyPolicy = ({ error, marker, policy, raw, slug }) => {
147
+ if (policy === "null") return null;
148
+ if (policy === "passthrough") return raw;
149
+ if (typeof policy === "function") return policy({
150
+ collection: slug,
151
+ error,
152
+ field: marker.fieldName,
153
+ value: typeof raw === "string" ? raw : String(raw)
154
+ });
155
+ const keyId = isSealed(raw) ? raw.split(".")[1] : void 0;
156
+ throw new DecryptFailedError({
157
+ cause: error,
158
+ field: marker.fieldName,
159
+ keyId,
160
+ slug
161
+ });
162
+ };
163
+ /**
164
+ * Unseals one value, applying the decrypt-failure policy on a non-sealed item
165
+ * (plaintext at rest is pre-adoption data; passthrough is the lazy-migration
166
+ * mode) or a failed unseal. Shared by the scalar afterRead hook and the
167
+ * richText decrypt hook.
168
+ */
169
+ const openSealed = (item, args) => {
170
+ const { candidates, marker, policy, ring, slug } = args;
171
+ if (!isSealed(item)) return applyPolicy({
172
+ error: /* @__PURE__ */ new Error("value is not sealed"),
173
+ marker,
174
+ policy,
175
+ raw: item,
176
+ slug
177
+ });
178
+ try {
179
+ return unseal(item, ring.dataKeys, candidates);
180
+ } catch (error) {
181
+ return applyPolicy({
182
+ error,
183
+ marker,
184
+ policy,
185
+ raw: item,
186
+ slug
187
+ });
188
+ }
189
+ };
190
+ const resolvePolicy = (req, marker) => {
191
+ const registry = getFieldsRegistry(req.payload.config);
192
+ return marker.onDecryptFailure ?? registry?.encrypted?.onDecryptFailure ?? "throw";
193
+ };
194
+ const makeAfterReadHook = (marker) => {
195
+ return async (args) => {
196
+ const { collection, context, global, req, value } = args;
197
+ if (value === void 0 || value === null) return value;
198
+ if (contextMode(context)) return value;
199
+ const slug = aadSlug(collection, global);
200
+ const ring = await ringForRequest(req, marker);
201
+ const openArgs = {
202
+ candidates: readAadCandidates(marker, slug, req),
203
+ marker,
204
+ policy: resolvePolicy(req, marker),
205
+ ring,
206
+ slug
207
+ };
208
+ const openOne = (item) => openSealed(item, openArgs);
209
+ return marker.hasMany && Array.isArray(value) ? value.map(openOne) : openOne(value);
210
+ };
211
+ };
212
+ /**
213
+ * afterRead on the virtual richText field: decrypts the ciphertext sibling into
214
+ * a SerializedEditorState. The virtual field is never persisted, so its own
215
+ * value is always undefined and the ciphertext SIBLING is the source. The
216
+ * ciphertext field has no afterRead, so that sibling holds raw ciphertext for
217
+ * the whole phase, making this the single deterministic reader. Runs before the
218
+ * editor's own afterRead, which then populates upload/relationship nodes on the
219
+ * decrypted object.
220
+ */
221
+ const makeRichTextDecryptHook = (marker, storedName) => {
222
+ return async (args) => {
223
+ const { collection, context, global, req, siblingData } = args;
224
+ if (contextMode(context)) return args.value;
225
+ const ciphertext = siblingData[storedName];
226
+ if (ciphertext === void 0 || ciphertext === null) return ciphertext;
227
+ const slug = aadSlug(collection, global);
228
+ const ring = await ringForRequest(req, marker);
229
+ return openSealed(ciphertext, {
230
+ candidates: readAadCandidates(marker, slug, req),
231
+ marker,
232
+ policy: resolvePolicy(req, marker),
233
+ ring,
234
+ slug
235
+ });
236
+ };
237
+ };
238
+ /**
239
+ * beforeChange on the virtual richText field: seals the submitted
240
+ * SerializedEditorState into the ciphertext sibling and returns the plaintext
241
+ * unchanged (Payload drops it at the DB write since the field is virtual). The
242
+ * sole normal-mode writer of the ciphertext slot. Utility flows (rotate/decrypt/
243
+ * raw) pass through untouched; the ciphertext field's own hook handles rotation.
244
+ * An absent value (partial write) preserves the existing ciphertext.
245
+ */
246
+ const makeRichTextSealHook = (marker, storedName) => {
247
+ return async (args) => {
248
+ const { collection, global, req, siblingData, value } = args;
249
+ if (contextMode(req.context)) return value;
250
+ if (value === void 0) return;
251
+ const sibling = siblingData;
252
+ if (value === null) {
253
+ sibling[storedName] = null;
254
+ return null;
255
+ }
256
+ const slug = aadSlug(collection, global);
257
+ const ring = await ringForRequest(req, marker);
258
+ const activeKey = ring.dataKeys.get(ring.activeId);
259
+ if (marker.localized && req.locale === "all" && isLocaleMap(value)) {
260
+ const sealedMap = {};
261
+ for (const [locale, localeValue] of Object.entries(value)) sealedMap[locale] = localeValue == null || isSealed(localeValue) ? localeValue : seal({
262
+ aad: buildAad([
263
+ slug,
264
+ marker.fieldName,
265
+ locale
266
+ ]),
267
+ key: activeKey,
268
+ keyId: ring.activeId,
269
+ plaintext: localeValue
270
+ });
271
+ sibling[storedName] = sealedMap;
272
+ return value;
273
+ }
274
+ sibling[storedName] = isSealed(value) ? value : seal({
275
+ aad: sealAad(marker, slug, req),
276
+ key: activeKey,
277
+ keyId: ring.activeId,
278
+ plaintext: value
279
+ });
280
+ return value;
281
+ };
282
+ };
283
+ /**
284
+ * beforeChange on the hidden ciphertext field. A no-op in every mode except
285
+ * rotate (the virtual field's seal hook is the sole normal-mode producer of this
286
+ * slot). Under rotate it unseals with the stale key and reseals with the active
287
+ * key so rotateEncryptedFields round-trips, mirroring the scalar rotate branch.
288
+ */
289
+ const makeRichTextCiphertextHook = (marker) => {
290
+ return async (args) => {
291
+ const { collection, global, req, value } = args;
292
+ if (contextMode(req.context) !== "rotate") return;
293
+ if (!isSealed(value)) return value;
294
+ const ring = await ringForRequest(req, marker);
295
+ if (parseWire(value).keyId === ring.activeId) return value;
296
+ const slug = aadSlug(collection, global);
297
+ const plaintext = unseal(value, ring.dataKeys, readAadCandidates(marker, slug, req));
298
+ const activeKey = ring.dataKeys.get(ring.activeId);
299
+ return seal({
300
+ aad: sealAad(marker, slug, req),
301
+ key: activeKey,
302
+ keyId: ring.activeId,
303
+ plaintext
304
+ });
305
+ };
306
+ };
307
+ /**
308
+ * Validate for the virtual richText field. Delegates to the editor's own
309
+ * validate (required + node-level validation) for full parity with a native
310
+ * richText field. Skips utility flows and absent values: rotate/decrypt patch
311
+ * only the ciphertext sibling, so the virtual value is undefined then, and a
312
+ * required check must not trip on that.
313
+ */
314
+ const makeRichTextValidate = () => {
315
+ return (value, options) => {
316
+ if (contextMode(options.req.context)) return true;
317
+ if (value === void 0) return true;
318
+ const { editor } = options;
319
+ if (!editor || typeof editor === "function" || typeof editor.validate !== "function") return true;
320
+ return editor.validate(value, options);
321
+ };
322
+ };
323
+ //#endregion
324
+ export { DecryptFailedError, contextMode, makeAfterReadHook, makeBeforeChangeHook, makeRichTextCiphertextHook, makeRichTextDecryptHook, makeRichTextSealHook, makeRichTextValidate, ringForRequest };
325
+
326
+ //# sourceMappingURL=hooks.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hooks.js","names":[],"sources":["../../../src/fields/encrypted/hooks.ts"],"sourcesContent":["import type { FieldHook, PayloadRequest, RichTextField, SanitizedConfig, Validate } from 'payload'\nimport { getFieldsRegistry } from '../../plugin/registry'\nimport type { DecryptFailurePolicy } from '../../types'\nimport { buildAad } from './crypto/aad'\nimport { computeBidx } from './crypto/bidx'\nimport { type KeyRing, resolveKeys } from './crypto/keys'\nimport { isSealed, parseWire, seal, unseal } from './crypto/wire'\nimport { sealedArrayKey, stashPlaintext } from './plaintextStash'\nimport {\n\tENCRYPTED_CONTEXT_KEY,\n\ttype EncryptedContextMode,\n\ttype EncryptedFieldMarker,\n} from './types'\n\nexport interface DecryptFailedArgs {\n\tcause: unknown\n\tfield: string\n\tkeyId: string | undefined\n\tslug: string\n}\n\n/** Raised on read when decryption fails and the policy is 'throw'. */\nexport class DecryptFailedError extends Error {\n\tconstructor({ cause, field, keyId, slug }: DecryptFailedArgs) {\n\t\tconst keyInfo = keyId ? ` (keyId '${keyId}')` : ''\n\t\tsuper(\n\t\t\t`@10x-media/fields: failed to decrypt ${slug}.${field}${keyInfo}: ${cause instanceof Error ? cause.name : 'unknown error'}`\n\t\t)\n\t\tthis.name = 'DecryptFailedError'\n\t\tthis.cause = cause\n\t}\n}\n\nexport const ringForRequest = (\n\treq: PayloadRequest,\n\tmarker: EncryptedFieldMarker\n): Promise<KeyRing> => {\n\tconst registry = getFieldsRegistry(req.payload.config)\n\treturn resolveKeys(marker.keys ?? registry?.encrypted?.keys, req.payload.config.secret)\n}\n\ntype SlugHolder = { slug: string } | null | undefined\n\nconst aadSlug = (collection: SlugHolder, global: SlugHolder): string =>\n\tcollection?.slug ?? global?.slug ?? ''\n\nconst defaultLocale = (config: SanitizedConfig): string =>\n\tconfig.localization ? config.localization.defaultLocale : 'en'\n\n/** Mirrors beforeChange/promise.ts: the locale a write applies to. */\nconst operationLocale = (req: PayloadRequest): string => {\n\tconst locale = req.locale\n\tif (!locale || locale === 'all') {\n\t\treturn defaultLocale(req.payload.config)\n\t}\n\treturn locale\n}\n\n/**\n * AAD binds a ciphertext to its `${slug}.${field}[.${locale}]` slot via\n * buildAad, which rejects any dotted component so the joined data stays\n * unambiguous (a dotted slug/locale would blur the cross-field binding).\n */\nexport const sealAad = (marker: EncryptedFieldMarker, slug: string, req: PayloadRequest): string =>\n\tbuildAad(\n\t\tmarker.localized ? [slug, marker.fieldName, operationLocale(req)] : [slug, marker.fieldName]\n\t)\n\n/**\n * Read-side AAD candidates. Localized fields try the request locale first,\n * then every configured locale: fallbackLocale hoisting and locale=all hook\n * execution mean the hook cannot know which locale sealed the value.\n */\nexport const readAadCandidates = (\n\tmarker: EncryptedFieldMarker,\n\tslug: string,\n\treq: PayloadRequest\n): string[] => {\n\tif (!marker.localized) {\n\t\treturn [buildAad([slug, marker.fieldName])]\n\t}\n\tconst codes = req.payload.config.localization\n\t\t? req.payload.config.localization.localeCodes\n\t\t: [defaultLocale(req.payload.config)]\n\tconst first = operationLocale(req)\n\tconst ordered = [first, ...codes.filter((code) => code !== first)]\n\treturn ordered.map((code) => buildAad([slug, marker.fieldName, code]))\n}\n\n/**\n * The active utility mode from the request context, or undefined for a normal\n * operation (including a missing context, which reads as normal). Reused by the\n * response stripper so bulk utilities (which read in `raw` mode) still see the\n * ciphertext and blind-index siblings, while a normal read strips them.\n */\nexport const contextMode = (\n\tcontext: Record<string, unknown> | undefined\n): EncryptedContextMode | undefined => {\n\tconst mode = context?.[ENCRYPTED_CONTEXT_KEY]\n\treturn mode === 'decrypt' || mode === 'raw' || mode === 'rotate' ? mode : undefined\n}\n\n/** A locale=all write hands the hook a `{ [locale]: value }` map, not a scalar. */\nconst isLocaleMap = (value: unknown): value is Record<string, unknown> =>\n\ttypeof value === 'object' && value !== null && !Array.isArray(value)\n\ninterface SealForLocaleArgs {\n\taad: string\n\thasMany: boolean\n\tkey: Buffer\n\tkeyId: string\n}\n\n/** Seal one locale's value, passing already-sealed items through unchanged. */\nconst sealValueForLocale = (value: unknown, args: SealForLocaleArgs): unknown => {\n\tif (value == null) {\n\t\treturn value\n\t}\n\tconst sealItem = (item: unknown): unknown =>\n\t\tisSealed(item)\n\t\t\t? item\n\t\t\t: seal({ aad: args.aad, key: args.key, keyId: args.keyId, plaintext: item })\n\treturn args.hasMany && Array.isArray(value) ? value.map(sealItem) : sealItem(value)\n}\n\nexport const makeBeforeChangeHook = (marker: EncryptedFieldMarker): FieldHook => {\n\treturn async (args) => {\n\t\tconst { collection, global, req, siblingData, value } = args\n\t\tconst mode = contextMode(req.context as Record<string, unknown>)\n\n\t\t// Utilities read ciphertext untouched.\n\t\tif (mode === 'raw') {\n\t\t\treturn value\n\t\t}\n\t\t// Removal path: store incoming plaintext without sealing, drop the now\n\t\t// meaningless blind index.\n\t\tif (mode === 'decrypt') {\n\t\t\tif (marker.queryable && marker.bidxName) {\n\t\t\t\tsiblingData[marker.bidxName] = null\n\t\t\t}\n\t\t\treturn value\n\t\t}\n\n\t\tconst slug = aadSlug(collection, global)\n\t\tconst ring = await ringForRequest(req, marker)\n\t\tconst activeKey = ring.dataKeys.get(ring.activeId) as Buffer\n\n\t\tif (mode === 'rotate') {\n\t\t\tconst candidates = readAadCandidates(marker, slug, req)\n\t\t\tconst writeAad = sealAad(marker, slug, req)\n\t\t\tconst rotateOne = (item: unknown): unknown => {\n\t\t\t\tif (!isSealed(item)) {\n\t\t\t\t\treturn item\n\t\t\t\t}\n\t\t\t\tif (parseWire(item).keyId === ring.activeId) {\n\t\t\t\t\treturn item\n\t\t\t\t}\n\t\t\t\tconst plaintext = unseal(item, ring.dataKeys, candidates)\n\t\t\t\tif (marker.queryable && marker.bidxName) {\n\t\t\t\t\tsiblingData[marker.bidxName] = computeBidx(plaintext, ring.indexKey, marker.normalize)\n\t\t\t\t}\n\t\t\t\treturn seal({ aad: writeAad, key: activeKey, keyId: ring.activeId, plaintext })\n\t\t\t}\n\t\t\treturn marker.hasMany && Array.isArray(value) ? value.map(rotateOne) : rotateOne(value)\n\t\t}\n\n\t\tif (value === undefined) {\n\t\t\treturn undefined\n\t\t}\n\t\tif (value === null) {\n\t\t\tif (marker.queryable && marker.bidxName) {\n\t\t\t\tsiblingData[marker.bidxName] = null\n\t\t\t}\n\t\t\treturn null\n\t\t}\n\n\t\t// locale=all write: value is a `{ [locale]: value }` map. Seal each locale\n\t\t// under its own locale AAD so afterRead's per-locale unseal opens it (a\n\t\t// single blob sealed under the default-locale AAD would not). Plaintext\n\t\t// validation and blind-index maintenance for bulk all-locales writes are\n\t\t// deferred to per-locale writes (covered by Batch E int tests).\n\t\tif (marker.localized && req.locale === 'all' && isLocaleMap(value)) {\n\t\t\tconst sealedMap: Record<string, unknown> = {}\n\t\t\tfor (const [locale, localeValue] of Object.entries(value)) {\n\t\t\t\tsealedMap[locale] = sealValueForLocale(localeValue, {\n\t\t\t\t\taad: buildAad([slug, marker.fieldName, locale]),\n\t\t\t\t\thasMany: marker.hasMany,\n\t\t\t\t\tkey: activeKey,\n\t\t\t\t\tkeyId: ring.activeId,\n\t\t\t\t})\n\t\t\t}\n\t\t\treturn sealedMap\n\t\t}\n\n\t\tconst aad = sealAad(marker, slug, req)\n\t\tconst sealOne = (item: unknown): string =>\n\t\t\tseal({ aad, key: activeKey, keyId: ring.activeId, plaintext: item })\n\n\t\tif (marker.hasMany) {\n\t\t\tif (!Array.isArray(value)) {\n\t\t\t\treturn value\n\t\t\t}\n\t\t\t// Seal PER ITEM so an already-sealed item (a passthrough from a prior\n\t\t\t// read, e.g. a mixed array) is never wrapped in a second GCM layer.\n\t\t\tconst sealedArray = value.map((item) => (isSealed(item) ? item : sealOne(item)))\n\t\t\t// Stash the plaintext for the composed validate, keyed by the sealed\n\t\t\t// output (unique per write), only for a fresh all-plaintext write. A\n\t\t\t// mixed/passthrough array is not stashed; its already-sealed items were\n\t\t\t// validated when first written, so their re-validation is deferred.\n\t\t\tif (!value.some(isSealed)) {\n\t\t\t\tstashPlaintext(req, sealedArrayKey(sealedArray), value)\n\t\t\t}\n\t\t\treturn sealedArray\n\t\t}\n\n\t\t// Single value already sealed: a resubmitted read or unchanged sibling;\n\t\t// passthrough without re-sealing (no plaintext to stash).\n\t\tif (isSealed(value)) {\n\t\t\treturn value\n\t\t}\n\t\t// Stash the plaintext for the composed validate, keyed by the sealed value\n\t\t// (unique per write); do not validate/throw here.\n\t\tconst sealed = sealOne(value)\n\t\tstashPlaintext(req, sealed, value)\n\t\tif (marker.queryable && marker.bidxName) {\n\t\t\tsiblingData[marker.bidxName] = computeBidx(value, ring.indexKey, marker.normalize)\n\t\t}\n\t\treturn sealed\n\t}\n}\n\ninterface ApplyPolicyArgs {\n\terror: unknown\n\tmarker: EncryptedFieldMarker\n\tpolicy: DecryptFailurePolicy\n\traw: unknown\n\tslug: string\n}\n\nconst applyPolicy = ({ error, marker, policy, raw, slug }: ApplyPolicyArgs): unknown => {\n\tif (policy === 'null') {\n\t\treturn null\n\t}\n\tif (policy === 'passthrough') {\n\t\treturn raw\n\t}\n\tif (typeof policy === 'function') {\n\t\treturn policy({\n\t\t\tcollection: slug,\n\t\t\terror,\n\t\t\tfield: marker.fieldName,\n\t\t\tvalue: typeof raw === 'string' ? raw : String(raw),\n\t\t})\n\t}\n\tconst keyId = isSealed(raw) ? (raw as string).split('.')[1] : undefined\n\tthrow new DecryptFailedError({ cause: error, field: marker.fieldName, keyId, slug })\n}\n\ninterface OpenSealedArgs {\n\tcandidates: string[]\n\tmarker: EncryptedFieldMarker\n\tpolicy: DecryptFailurePolicy\n\tring: KeyRing\n\tslug: string\n}\n\n/**\n * Unseals one value, applying the decrypt-failure policy on a non-sealed item\n * (plaintext at rest is pre-adoption data; passthrough is the lazy-migration\n * mode) or a failed unseal. Shared by the scalar afterRead hook and the\n * richText decrypt hook.\n */\nconst openSealed = (item: unknown, args: OpenSealedArgs): unknown => {\n\tconst { candidates, marker, policy, ring, slug } = args\n\tif (!isSealed(item)) {\n\t\treturn applyPolicy({ error: new Error('value is not sealed'), marker, policy, raw: item, slug })\n\t}\n\ttry {\n\t\treturn unseal(item, ring.dataKeys, candidates)\n\t} catch (error) {\n\t\treturn applyPolicy({ error, marker, policy, raw: item, slug })\n\t}\n}\n\nconst resolvePolicy = (req: PayloadRequest, marker: EncryptedFieldMarker): DecryptFailurePolicy => {\n\tconst registry = getFieldsRegistry(req.payload.config)\n\treturn marker.onDecryptFailure ?? registry?.encrypted?.onDecryptFailure ?? 'throw'\n}\n\nexport const makeAfterReadHook = (marker: EncryptedFieldMarker): FieldHook => {\n\treturn async (args) => {\n\t\tconst { collection, context, global, req, value } = args\n\t\tif (value === undefined || value === null) {\n\t\t\treturn value\n\t\t}\n\t\tif (contextMode(context)) {\n\t\t\treturn value\n\t\t}\n\t\tconst slug = aadSlug(collection, global)\n\t\tconst ring = await ringForRequest(req, marker)\n\t\tconst openArgs: OpenSealedArgs = {\n\t\t\tcandidates: readAadCandidates(marker, slug, req),\n\t\t\tmarker,\n\t\t\tpolicy: resolvePolicy(req, marker),\n\t\t\tring,\n\t\t\tslug,\n\t\t}\n\t\tconst openOne = (item: unknown): unknown => openSealed(item, openArgs)\n\t\treturn marker.hasMany && Array.isArray(value) ? value.map(openOne) : openOne(value)\n\t}\n}\n\n/**\n * afterRead on the virtual richText field: decrypts the ciphertext sibling into\n * a SerializedEditorState. The virtual field is never persisted, so its own\n * value is always undefined and the ciphertext SIBLING is the source. The\n * ciphertext field has no afterRead, so that sibling holds raw ciphertext for\n * the whole phase, making this the single deterministic reader. Runs before the\n * editor's own afterRead, which then populates upload/relationship nodes on the\n * decrypted object.\n */\nexport const makeRichTextDecryptHook = (\n\tmarker: EncryptedFieldMarker,\n\tstoredName: string\n): FieldHook => {\n\treturn async (args) => {\n\t\tconst { collection, context, global, req, siblingData } = args\n\t\tif (contextMode(context)) {\n\t\t\treturn args.value\n\t\t}\n\t\tconst ciphertext = (siblingData as Record<string, unknown>)[storedName]\n\t\tif (ciphertext === undefined || ciphertext === null) {\n\t\t\treturn ciphertext\n\t\t}\n\t\tconst slug = aadSlug(collection, global)\n\t\tconst ring = await ringForRequest(req, marker)\n\t\treturn openSealed(ciphertext, {\n\t\t\tcandidates: readAadCandidates(marker, slug, req),\n\t\t\tmarker,\n\t\t\tpolicy: resolvePolicy(req, marker),\n\t\t\tring,\n\t\t\tslug,\n\t\t})\n\t}\n}\n\n/**\n * beforeChange on the virtual richText field: seals the submitted\n * SerializedEditorState into the ciphertext sibling and returns the plaintext\n * unchanged (Payload drops it at the DB write since the field is virtual). The\n * sole normal-mode writer of the ciphertext slot. Utility flows (rotate/decrypt/\n * raw) pass through untouched; the ciphertext field's own hook handles rotation.\n * An absent value (partial write) preserves the existing ciphertext.\n */\nexport const makeRichTextSealHook = (\n\tmarker: EncryptedFieldMarker,\n\tstoredName: string\n): FieldHook => {\n\treturn async (args) => {\n\t\tconst { collection, global, req, siblingData, value } = args\n\t\tif (contextMode(req.context as Record<string, unknown>)) {\n\t\t\treturn value\n\t\t}\n\t\tif (value === undefined) {\n\t\t\treturn undefined\n\t\t}\n\t\tconst sibling = siblingData as Record<string, unknown>\n\t\tif (value === null) {\n\t\t\tsibling[storedName] = null\n\t\t\treturn null\n\t\t}\n\t\tconst slug = aadSlug(collection, global)\n\t\tconst ring = await ringForRequest(req, marker)\n\t\tconst activeKey = ring.dataKeys.get(ring.activeId) as Buffer\n\t\t// locale=all write: value is a `{ [locale]: SerializedEditorState }` map.\n\t\t// Seal each locale under its own locale AAD so the per-locale decrypt opens\n\t\t// it, mirroring the scalar hook's locale-map handling.\n\t\tif (marker.localized && req.locale === 'all' && isLocaleMap(value)) {\n\t\t\tconst sealedMap: Record<string, unknown> = {}\n\t\t\tfor (const [locale, localeValue] of Object.entries(value)) {\n\t\t\t\tsealedMap[locale] =\n\t\t\t\t\tlocaleValue == null || isSealed(localeValue)\n\t\t\t\t\t\t? localeValue\n\t\t\t\t\t\t: seal({\n\t\t\t\t\t\t\t\taad: buildAad([slug, marker.fieldName, locale]),\n\t\t\t\t\t\t\t\tkey: activeKey,\n\t\t\t\t\t\t\t\tkeyId: ring.activeId,\n\t\t\t\t\t\t\t\tplaintext: localeValue,\n\t\t\t\t\t\t\t})\n\t\t\t}\n\t\t\tsibling[storedName] = sealedMap\n\t\t\treturn value\n\t\t}\n\t\tsibling[storedName] = isSealed(value)\n\t\t\t? value\n\t\t\t: seal({\n\t\t\t\t\taad: sealAad(marker, slug, req),\n\t\t\t\t\tkey: activeKey,\n\t\t\t\t\tkeyId: ring.activeId,\n\t\t\t\t\tplaintext: value,\n\t\t\t\t})\n\t\treturn value\n\t}\n}\n\n/**\n * beforeChange on the hidden ciphertext field. A no-op in every mode except\n * rotate (the virtual field's seal hook is the sole normal-mode producer of this\n * slot). Under rotate it unseals with the stale key and reseals with the active\n * key so rotateEncryptedFields round-trips, mirroring the scalar rotate branch.\n */\nexport const makeRichTextCiphertextHook = (marker: EncryptedFieldMarker): FieldHook => {\n\treturn async (args) => {\n\t\tconst { collection, global, req, value } = args\n\t\tif (contextMode(req.context as Record<string, unknown>) !== 'rotate') {\n\t\t\treturn undefined\n\t\t}\n\t\tif (!isSealed(value)) {\n\t\t\treturn value\n\t\t}\n\t\tconst ring = await ringForRequest(req, marker)\n\t\tif (parseWire(value).keyId === ring.activeId) {\n\t\t\treturn value\n\t\t}\n\t\tconst slug = aadSlug(collection, global)\n\t\tconst plaintext = unseal(value, ring.dataKeys, readAadCandidates(marker, slug, req))\n\t\tconst activeKey = ring.dataKeys.get(ring.activeId) as Buffer\n\t\treturn seal({\n\t\t\taad: sealAad(marker, slug, req),\n\t\t\tkey: activeKey,\n\t\t\tkeyId: ring.activeId,\n\t\t\tplaintext,\n\t\t})\n\t}\n}\n\n/**\n * Validate for the virtual richText field. Delegates to the editor's own\n * validate (required + node-level validation) for full parity with a native\n * richText field. Skips utility flows and absent values: rotate/decrypt patch\n * only the ciphertext sibling, so the virtual value is undefined then, and a\n * required check must not trip on that.\n */\nexport const makeRichTextValidate = (): Validate<unknown, unknown, unknown, RichTextField> => {\n\treturn (value, options) => {\n\t\tif (contextMode(options.req.context as Record<string, unknown>)) {\n\t\t\treturn true\n\t\t}\n\t\tif (value === undefined) {\n\t\t\treturn true\n\t\t}\n\t\tconst { editor } = options\n\t\tif (!editor || typeof editor === 'function' || typeof editor.validate !== 'function') {\n\t\t\treturn true\n\t\t}\n\t\treturn editor.validate(value, options)\n\t}\n}\n"],"mappings":";;;;;;;;;AAsBA,IAAa,qBAAb,cAAwC,MAAM;CAC7C,YAAY,EAAE,OAAO,OAAO,OAAO,QAA2B;EAC7D,MAAM,UAAU,QAAQ,YAAY,MAAM,MAAM;EAChD,MACC,wCAAwC,KAAK,GAAG,QAAQ,QAAQ,IAAI,iBAAiB,QAAQ,MAAM,OAAO,iBAC3G;EACA,KAAK,OAAO;EACZ,KAAK,QAAQ;CACd;AACD;AAEA,MAAa,kBACZ,KACA,WACsB;CACtB,MAAM,WAAW,kBAAkB,IAAI,QAAQ,MAAM;CACrD,OAAO,YAAY,OAAO,QAAQ,UAAU,WAAW,MAAM,IAAI,QAAQ,OAAO,MAAM;AACvF;AAIA,MAAM,WAAW,YAAwB,WACxC,YAAY,QAAQ,QAAQ,QAAQ;AAErC,MAAM,iBAAiB,WACtB,OAAO,eAAe,OAAO,aAAa,gBAAgB;;AAG3D,MAAM,mBAAmB,QAAgC;CACxD,MAAM,SAAS,IAAI;CACnB,IAAI,CAAC,UAAU,WAAW,OACzB,OAAO,cAAc,IAAI,QAAQ,MAAM;CAExC,OAAO;AACR;;;;;;AAOA,MAAa,WAAW,QAA8B,MAAc,QACnE,SACC,OAAO,YAAY;CAAC;CAAM,OAAO;CAAW,gBAAgB,GAAG;AAAC,IAAI,CAAC,MAAM,OAAO,SAAS,CAC5F;;;;;;AAOD,MAAa,qBACZ,QACA,MACA,QACc;CACd,IAAI,CAAC,OAAO,WACX,OAAO,CAAC,SAAS,CAAC,MAAM,OAAO,SAAS,CAAC,CAAC;CAE3C,MAAM,QAAQ,IAAI,QAAQ,OAAO,eAC9B,IAAI,QAAQ,OAAO,aAAa,cAChC,CAAC,cAAc,IAAI,QAAQ,MAAM,CAAC;CACrC,MAAM,QAAQ,gBAAgB,GAAG;CAEjC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,aAAa,YACzE,OAAO;EAER,OAAO,OAAO,SAAS,OAAO,OAAO;CACtC;AACD"}
@@ -0,0 +1,16 @@
1
+ const MIN_MASK_DOTS = 1;
2
+ const MAX_MASK_DOTS = 64;
3
+ /**
4
+ * Normalizes a factory `maskDots` option to an integer in [1, 64]. The count is
5
+ * purely cosmetic (it is decoupled from the real value length, which is unknown
6
+ * until reveal), so an out-of-range or non-integer value is clamped rather than
7
+ * rejected. `undefined` and `NaN` fall back to the default.
8
+ */
9
+ const clampMaskDots = (value) => {
10
+ if (value === void 0 || Number.isNaN(value)) return 8;
11
+ return Math.min(MAX_MASK_DOTS, Math.max(MIN_MASK_DOTS, Math.trunc(value)));
12
+ };
13
+ //#endregion
14
+ export { clampMaskDots };
15
+
16
+ //# sourceMappingURL=maskDots.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"maskDots.js","names":[],"sources":["../../../src/fields/encrypted/maskDots.ts"],"sourcesContent":["/** Cosmetic dot count shown while an encrypted field is concealed. */\nexport const DEFAULT_MASK_DOTS = 8\n\nconst MIN_MASK_DOTS = 1\nconst MAX_MASK_DOTS = 64\n\n/**\n * Normalizes a factory `maskDots` option to an integer in [1, 64]. The count is\n * purely cosmetic (it is decoupled from the real value length, which is unknown\n * until reveal), so an out-of-range or non-integer value is clamped rather than\n * rejected. `undefined` and `NaN` fall back to the default.\n */\nexport const clampMaskDots = (value?: number): number => {\n\tif (value === undefined || Number.isNaN(value)) {\n\t\treturn DEFAULT_MASK_DOTS\n\t}\n\treturn Math.min(MAX_MASK_DOTS, Math.max(MIN_MASK_DOTS, Math.trunc(value)))\n}\n"],"mappings":"AAGA,MAAM,gBAAgB;AACtB,MAAM,gBAAgB;;;;;;;AAQtB,MAAa,iBAAiB,UAA2B;CACxD,IAAI,UAAU,KAAA,KAAa,OAAO,MAAM,KAAK,GAC5C,OAAA;CAED,OAAO,KAAK,IAAI,eAAe,KAAK,IAAI,eAAe,KAAK,MAAM,KAAK,CAAC,CAAC;AAC1E"}
@@ -0,0 +1,57 @@
1
+ //#region src/fields/encrypted/plaintextStash.ts
2
+ /**
3
+ * Payload runs field `beforeChange` hooks BEFORE `validate`, so by the time
4
+ * validate runs the value is already sealed. The seal hook stashes the pre-seal
5
+ * plaintext on `req.context` and the composed validate reads it back, so
6
+ * plaintext validation runs in Payload's native validate pass. That pass honors
7
+ * `skipValidation` (drafts/autosave) and aggregates field errors with the right
8
+ * path and `req.t`, none of which a throw from the hook can do.
9
+ *
10
+ * The stash is keyed by the SEALED VALUE the hook just produced, never the field
11
+ * path. `req.context` is shared across the documents of a bulk/concurrent write
12
+ * (`payload.update({ where, data })` runs docs.map + Promise.all with one req),
13
+ * so a path key ('ssn' is identical for every document) would collide: one
14
+ * document's validate would consume another's plaintext, or none. A sealed value
15
+ * is unique per write (fresh IV), so the key is collision-free across documents,
16
+ * requests, and paths.
17
+ *
18
+ * Kept free of node:crypto: this also runs on the validate path.
19
+ */
20
+ const STASH_KEY = "__tenxFieldsEncryptedPlaintext";
21
+ const stashOf = (req) => {
22
+ const context = req.context;
23
+ let stash = context[STASH_KEY];
24
+ if (!stash) {
25
+ stash = {};
26
+ context[STASH_KEY] = stash;
27
+ }
28
+ return stash;
29
+ };
30
+ /**
31
+ * Stash key for a hasMany write: each sealed item is unique per IV, so their
32
+ * join is unique per write. The separator is absent from the base64url wire
33
+ * format, so it never merges two distinct arrays into one key.
34
+ */
35
+ const sealedArrayKey = (sealedItems) => sealedItems.join("\n");
36
+ const stashPlaintext = (req, sealedKey, plaintext) => {
37
+ stashOf(req)[sealedKey] = plaintext;
38
+ };
39
+ const takePlaintext = (req, sealedKey) => {
40
+ const stash = req.context?.[STASH_KEY];
41
+ if (stash && Object.hasOwn(stash, sealedKey)) {
42
+ const plaintext = stash[sealedKey];
43
+ delete stash[sealedKey];
44
+ return {
45
+ found: true,
46
+ plaintext
47
+ };
48
+ }
49
+ return {
50
+ found: false,
51
+ plaintext: void 0
52
+ };
53
+ };
54
+ //#endregion
55
+ export { sealedArrayKey, stashPlaintext, takePlaintext };
56
+
57
+ //# sourceMappingURL=plaintextStash.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plaintextStash.js","names":[],"sources":["../../../src/fields/encrypted/plaintextStash.ts"],"sourcesContent":["import type { PayloadRequest } from 'payload'\n\n/**\n * Payload runs field `beforeChange` hooks BEFORE `validate`, so by the time\n * validate runs the value is already sealed. The seal hook stashes the pre-seal\n * plaintext on `req.context` and the composed validate reads it back, so\n * plaintext validation runs in Payload's native validate pass. That pass honors\n * `skipValidation` (drafts/autosave) and aggregates field errors with the right\n * path and `req.t`, none of which a throw from the hook can do.\n *\n * The stash is keyed by the SEALED VALUE the hook just produced, never the field\n * path. `req.context` is shared across the documents of a bulk/concurrent write\n * (`payload.update({ where, data })` runs docs.map + Promise.all with one req),\n * so a path key ('ssn' is identical for every document) would collide: one\n * document's validate would consume another's plaintext, or none. A sealed value\n * is unique per write (fresh IV), so the key is collision-free across documents,\n * requests, and paths.\n *\n * Kept free of node:crypto: this also runs on the validate path.\n */\nconst STASH_KEY = '__tenxFieldsEncryptedPlaintext'\n\ntype Stash = Record<string, unknown>\n\nconst stashOf = (req: PayloadRequest): Stash => {\n\tconst context = req.context as Record<string, unknown>\n\tlet stash = context[STASH_KEY] as Stash | undefined\n\tif (!stash) {\n\t\tstash = {}\n\t\tcontext[STASH_KEY] = stash\n\t}\n\treturn stash\n}\n\n/**\n * Stash key for a hasMany write: each sealed item is unique per IV, so their\n * join is unique per write. The separator is absent from the base64url wire\n * format, so it never merges two distinct arrays into one key.\n */\nexport const sealedArrayKey = (sealedItems: readonly string[]): string => sealedItems.join('\\n')\n\nexport const stashPlaintext = (\n\treq: PayloadRequest,\n\tsealedKey: string,\n\tplaintext: unknown\n): void => {\n\tstashOf(req)[sealedKey] = plaintext\n}\n\nexport const takePlaintext = (\n\treq: PayloadRequest,\n\tsealedKey: string\n): { found: boolean; plaintext: unknown } => {\n\tconst context = req.context as Record<string, unknown> | undefined\n\tconst stash = context?.[STASH_KEY] as Stash | undefined\n\tif (stash && Object.hasOwn(stash, sealedKey)) {\n\t\tconst plaintext = stash[sealedKey]\n\t\tdelete stash[sealedKey]\n\t\treturn { found: true, plaintext }\n\t}\n\treturn { found: false, plaintext: undefined }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAoBA,MAAM,YAAY;AAIlB,MAAM,WAAW,QAA+B;CAC/C,MAAM,UAAU,IAAI;CACpB,IAAI,QAAQ,QAAQ;CACpB,IAAI,CAAC,OAAO;EACX,QAAQ,CAAC;EACT,QAAQ,aAAa;CACtB;CACA,OAAO;AACR;;;;;;AAOA,MAAa,kBAAkB,gBAA2C,YAAY,KAAK,IAAI;AAE/F,MAAa,kBACZ,KACA,WACA,cACU;CACV,QAAQ,GAAG,EAAE,aAAa;AAC3B;AAEA,MAAa,iBACZ,KACA,cAC4C;CAE5C,MAAM,QADU,IAAI,UACI;CACxB,IAAI,SAAS,OAAO,OAAO,OAAO,SAAS,GAAG;EAC7C,MAAM,YAAY,MAAM;EACxB,OAAO,MAAM;EACb,OAAO;GAAE,OAAO;GAAM;EAAU;CACjC;CACA,OAAO;EAAE,OAAO;EAAO,WAAW,KAAA;CAAU;AAC7C"}
@@ -0,0 +1,12 @@
1
+ import { CollectionConfig } from "payload";
2
+
3
+ //#region src/fields/encrypted/queryRewrite.d.ts
4
+ /**
5
+ * Attaches the blind-index where-rewrite and response stripper to a collection.
6
+ * The fields() plugin applies this to every collection automatically; call it
7
+ * directly only when using encryptedField() standalone without the plugin.
8
+ */
9
+ declare const withEncryptedQueryRewrite: (collection: CollectionConfig) => CollectionConfig;
10
+ //#endregion
11
+ export { withEncryptedQueryRewrite };
12
+ //# sourceMappingURL=queryRewrite.d.ts.map
@@ -0,0 +1,134 @@
1
+ import { queryableOnly, scanEncryptedFields } from "./scan.js";
2
+ import { computeBidx } from "./crypto/bidx.js";
3
+ import { contextMode, ringForRequest } from "./hooks.js";
4
+ const isPlainObject = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
5
+ const rewriteConstraint = async (args) => {
6
+ const { constraint, marker, ringFor, warn } = args;
7
+ const ring = await ringFor(marker);
8
+ const toBidx = (value) => value === null ? null : computeBidx(value, ring.indexKey, marker.normalize);
9
+ const toBidxArray = (value) => {
10
+ return (Array.isArray(value) ? value : typeof value === "string" ? value.split(",").map((item) => item.trim()) : []).map(toBidx);
11
+ };
12
+ const rewritten = {};
13
+ for (const [operator, operand] of Object.entries(constraint)) switch (operator) {
14
+ case "equals":
15
+ rewritten.equals = toBidx(operand);
16
+ break;
17
+ case "not_equals":
18
+ rewritten.not_equals = toBidx(operand);
19
+ break;
20
+ case "in":
21
+ rewritten.in = toBidxArray(operand);
22
+ break;
23
+ case "not_in":
24
+ rewritten.not_in = toBidxArray(operand);
25
+ break;
26
+ case "exists":
27
+ rewritten.exists = operand;
28
+ break;
29
+ default:
30
+ warn(operator);
31
+ return { equals: " " };
32
+ }
33
+ return rewritten;
34
+ };
35
+ /** Recursively rewrites queryable encrypted paths to their blind-index siblings. */
36
+ const rewriteWhereForMarkers = async (args) => {
37
+ const { markers, ringFor, warn = () => {}, where } = args;
38
+ const out = {};
39
+ for (const [key, value] of Object.entries(where)) {
40
+ if ((key === "and" || key === "or") && Array.isArray(value)) {
41
+ out[key] = await Promise.all(value.map((nested) => rewriteWhereForMarkers({
42
+ markers,
43
+ ringFor,
44
+ warn,
45
+ where: nested
46
+ })));
47
+ continue;
48
+ }
49
+ const marker = markers.get(key);
50
+ if (marker?.bidxName && isPlainObject(value)) {
51
+ const rewritten = await rewriteConstraint({
52
+ constraint: value,
53
+ marker,
54
+ ringFor,
55
+ warn: (operator) => warn(key, operator)
56
+ });
57
+ const bidxPath = key.includes(".") ? `${key.slice(0, key.lastIndexOf(".") + 1)}${marker.bidxName}` : marker.bidxName;
58
+ out[bidxPath] = {
59
+ ...out[bidxPath],
60
+ ...rewritten
61
+ };
62
+ continue;
63
+ }
64
+ out[key] = value;
65
+ }
66
+ return out;
67
+ };
68
+ const makeHook = (markers) => {
69
+ return async ({ args, req }) => {
70
+ if (isPlainObject(args) && "where" in args && isPlainObject(args.where)) {
71
+ const payloadReq = req;
72
+ const where = await rewriteWhereForMarkers({
73
+ markers,
74
+ ringFor: (marker) => ringForRequest(payloadReq, marker),
75
+ warn: (path, operator) => payloadReq.payload?.logger?.warn?.(`@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.`),
76
+ where: args.where
77
+ });
78
+ return {
79
+ ...args,
80
+ where
81
+ };
82
+ }
83
+ return args;
84
+ };
85
+ };
86
+ const bidxPathFor = (path, bidxName) => path.includes(".") ? `${path.slice(0, path.lastIndexOf(".") + 1)}${bidxName}` : bidxName;
87
+ const deleteAtPath = (doc, path) => {
88
+ const segments = path.split(".");
89
+ let node = doc;
90
+ for (const segment of segments.slice(0, -1)) {
91
+ const next = node[segment];
92
+ if (!next || typeof next !== "object") return;
93
+ node = next;
94
+ }
95
+ delete node[segments[segments.length - 1]];
96
+ };
97
+ /**
98
+ * Removes server-only encrypted paths from read results: blind-index hashes (so
99
+ * the keyed index value never leaves the server) and richText ciphertext
100
+ * siblings (opaque strings the virtual editor field replaces). `admin.hidden`
101
+ * keeps both readable by the plugin's own hooks but, unlike top-level `hidden`,
102
+ * does not strip them from responses.
103
+ */
104
+ const makeStripPathsHook = (paths) => {
105
+ return ({ context, doc }) => {
106
+ if (contextMode(context)) return doc;
107
+ for (const path of paths) deleteAtPath(doc, path);
108
+ return doc;
109
+ };
110
+ };
111
+ /**
112
+ * Attaches the blind-index where-rewrite and response stripper to a collection.
113
+ * The fields() plugin applies this to every collection automatically; call it
114
+ * directly only when using encryptedField() standalone without the plugin.
115
+ */
116
+ const withEncryptedQueryRewrite = (collection) => {
117
+ const allMarkers = scanEncryptedFields(collection.fields);
118
+ const queryableMarkers = queryableOnly(allMarkers);
119
+ const bidxPaths = [...queryableMarkers].map(([path, marker]) => bidxPathFor(path, marker.bidxName));
120
+ const ciphertextPaths = [...allMarkers].filter(([, marker]) => marker.sourceType === "richText").map(([path]) => path);
121
+ const stripPaths = [...bidxPaths, ...ciphertextPaths];
122
+ if (queryableMarkers.size === 0 && stripPaths.length === 0) return collection;
123
+ const hooks = { ...collection.hooks };
124
+ if (stripPaths.length > 0) hooks.afterRead = [...collection.hooks?.afterRead ?? [], makeStripPathsHook(stripPaths)];
125
+ if (queryableMarkers.size > 0) hooks.beforeOperation = [makeHook(queryableMarkers), ...collection.hooks?.beforeOperation ?? []];
126
+ return {
127
+ ...collection,
128
+ hooks
129
+ };
130
+ };
131
+ //#endregion
132
+ export { withEncryptedQueryRewrite };
133
+
134
+ //# sourceMappingURL=queryRewrite.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"queryRewrite.js","names":[],"sources":["../../../src/fields/encrypted/queryRewrite.ts"],"sourcesContent":["import type {\n\tCollectionAfterReadHook,\n\tCollectionBeforeOperationHook,\n\tCollectionConfig,\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: Map<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 = (markers: Map<string, EncryptedFieldMarker>): 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) and richText ciphertext\n * siblings (opaque strings the virtual editor field replaces). `admin.hidden`\n * keeps both readable by the plugin's own hooks but, unlike top-level `hidden`,\n * does not strip them from responses.\n */\nconst makeStripPathsHook = (paths: string[]): CollectionAfterReadHook => {\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/**\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 bidxPaths = [...queryableMarkers].map(([path, marker]) =>\n\t\tbidxPathFor(path, marker.bidxName as string)\n\t)\n\t// richText stores its ciphertext under the marker's own scan path\n\t// (`${name}_encrypted`); strip it so the opaque string never surfaces in a\n\t// response, mirroring the bidx strip.\n\tconst ciphertextPaths = [...allMarkers]\n\t\t.filter(([, marker]) => marker.sourceType === 'richText')\n\t\t.map(([path]) => path)\n\tconst stripPaths = [...bidxPaths, ...ciphertextPaths]\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"],"mappings":";;;AAwBA,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,SA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