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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (320) hide show
  1. package/CHANGELOG.md +173 -0
  2. package/README.md +8 -4
  3. package/dist/exports/client.d.ts +10 -1
  4. package/dist/exports/client.js +9 -1
  5. package/dist/exports/color-utils.d.ts +4 -2
  6. package/dist/exports/color-utils.js +3 -1
  7. package/dist/exports/color.d.ts +5 -2
  8. package/dist/exports/color.js +4 -1
  9. package/dist/exports/encrypted.d.ts +7 -4
  10. package/dist/exports/encrypted.js +6 -3
  11. package/dist/exports/icon-adapters/radix.d.ts +2 -2
  12. package/dist/exports/icon-adapters/radix.js +2 -2
  13. package/dist/exports/icon-react.d.ts +2 -2
  14. package/dist/exports/icon.d.ts +6 -2
  15. package/dist/exports/icon.js +6 -2
  16. package/dist/exports/measurement-utils.d.ts +9 -0
  17. package/dist/exports/measurement-utils.js +8 -0
  18. package/dist/exports/measurement.d.ts +11 -0
  19. package/dist/exports/measurement.js +10 -0
  20. package/dist/exports/phone-utils.d.ts +4 -0
  21. package/dist/exports/phone-utils.js +4 -0
  22. package/dist/exports/phone.d.ts +6 -0
  23. package/dist/exports/phone.js +3 -0
  24. package/dist/exports/rsc.d.ts +5 -1
  25. package/dist/exports/rsc.js +5 -1
  26. package/dist/exports/types.d.ts +3 -2
  27. package/dist/fields/color/client/ColorField.d.ts +2 -0
  28. package/dist/fields/color/client/ColorField.js +35 -288
  29. package/dist/fields/color/client/ColorField.js.map +1 -1
  30. package/dist/fields/color/client/ColorInput.d.ts +44 -0
  31. package/dist/fields/color/client/ColorInput.js +374 -0
  32. package/dist/fields/color/client/ColorInput.js.map +1 -0
  33. package/dist/fields/color/client/ColorPickerPanel.d.ts +3 -1
  34. package/dist/fields/color/client/ColorPickerPanel.js +31 -5
  35. package/dist/fields/color/client/ColorPickerPanel.js.map +1 -1
  36. package/dist/fields/color/client/colorField.css +30 -0
  37. package/dist/fields/color/colorField.d.ts +9 -2
  38. package/dist/fields/color/colorField.js +68 -15
  39. package/dist/fields/color/colorField.js.map +1 -1
  40. package/dist/fields/color/engine/index.d.ts +2 -1
  41. package/dist/fields/color/engine/scheme.d.ts +13 -0
  42. package/dist/fields/color/engine/scheme.js +12 -0
  43. package/dist/fields/color/engine/scheme.js.map +1 -0
  44. package/dist/fields/color/options.d.ts +5 -4
  45. package/dist/fields/color/options.js.map +1 -1
  46. package/dist/fields/color/paths.d.ts +1 -0
  47. package/dist/fields/color/paths.js +32 -0
  48. package/dist/fields/color/paths.js.map +1 -0
  49. package/dist/fields/color/presetChip.js +10 -9
  50. package/dist/fields/color/presetChip.js.map +1 -1
  51. package/dist/fields/color/presetReference.d.ts +13 -0
  52. package/dist/fields/color/presetReference.js +94 -0
  53. package/dist/fields/color/presetReference.js.map +1 -0
  54. package/dist/fields/color/presetsFromArray.d.ts +30 -0
  55. package/dist/fields/color/presetsFromArray.js +58 -0
  56. package/dist/fields/color/presetsFromArray.js.map +1 -0
  57. package/dist/fields/color/presetsFromDoc.js +1 -23
  58. package/dist/fields/color/presetsFromDoc.js.map +1 -1
  59. package/dist/fields/color/resolvePresets.d.ts +2 -2
  60. package/dist/fields/color/resolvePresets.js +38 -8
  61. package/dist/fields/color/resolvePresets.js.map +1 -1
  62. package/dist/fields/color/schemeValue.js +30 -0
  63. package/dist/fields/color/schemeValue.js.map +1 -0
  64. package/dist/fields/color/server/ColorCell.js +9 -3
  65. package/dist/fields/color/server/ColorCell.js.map +1 -1
  66. package/dist/fields/color/server/colorCell.css +5 -0
  67. package/dist/fields/color/valueIssue.js +23 -0
  68. package/dist/fields/color/valueIssue.js.map +1 -0
  69. package/dist/fields/encrypted/boot.js +2 -1
  70. package/dist/fields/encrypted/boot.js.map +1 -1
  71. package/dist/fields/encrypted/components/EncryptedInput.js +4 -1
  72. package/dist/fields/encrypted/components/EncryptedInput.js.map +1 -1
  73. package/dist/fields/encrypted/components/EncryptedTextarea.js +6 -2
  74. package/dist/fields/encrypted/components/EncryptedTextarea.js.map +1 -1
  75. package/dist/fields/encrypted/components/ProtectedCell.d.ts +15 -6
  76. package/dist/fields/encrypted/components/ProtectedCell.js +37 -8
  77. package/dist/fields/encrypted/components/ProtectedCell.js.map +1 -1
  78. package/dist/fields/encrypted/components/ProtectedField.css +134 -39
  79. package/dist/fields/encrypted/components/ProtectedField.d.ts +3 -0
  80. package/dist/fields/encrypted/components/ProtectedField.js +14 -0
  81. package/dist/fields/encrypted/components/ProtectedField.js.map +1 -1
  82. package/dist/fields/encrypted/components/WriteOnlyActions.js +65 -0
  83. package/dist/fields/encrypted/components/WriteOnlyActions.js.map +1 -0
  84. package/dist/fields/encrypted/components/WriteOnlyField.js +286 -0
  85. package/dist/fields/encrypted/components/WriteOnlyField.js.map +1 -0
  86. package/dist/fields/encrypted/components/writeOnlyIntent.js +69 -0
  87. package/dist/fields/encrypted/components/writeOnlyIntent.js.map +1 -0
  88. package/dist/fields/encrypted/crypto/wire.d.ts +10 -1
  89. package/dist/fields/encrypted/crypto/wire.js +1 -1
  90. package/dist/fields/encrypted/encryptedField.js +63 -6
  91. package/dist/fields/encrypted/encryptedField.js.map +1 -1
  92. package/dist/fields/encrypted/generateSecret.d.ts +10 -0
  93. package/dist/fields/encrypted/generateSecret.js +41 -0
  94. package/dist/fields/encrypted/generateSecret.js.map +1 -0
  95. package/dist/fields/encrypted/hint.js +67 -0
  96. package/dist/fields/encrypted/hint.js.map +1 -0
  97. package/dist/fields/encrypted/hooks.js +59 -31
  98. package/dist/fields/encrypted/hooks.js.map +1 -1
  99. package/dist/fields/encrypted/queryRewrite.d.ts +10 -2
  100. package/dist/fields/encrypted/queryRewrite.js +34 -8
  101. package/dist/fields/encrypted/queryRewrite.js.map +1 -1
  102. package/dist/fields/encrypted/rawRead.d.ts +24 -0
  103. package/dist/fields/encrypted/rawRead.js +40 -0
  104. package/dist/fields/encrypted/rawRead.js.map +1 -0
  105. package/dist/fields/encrypted/scan.js +21 -4
  106. package/dist/fields/encrypted/scan.js.map +1 -1
  107. package/dist/fields/encrypted/types.d.ts +67 -2
  108. package/dist/fields/encrypted/types.js +8 -1
  109. package/dist/fields/encrypted/types.js.map +1 -1
  110. package/dist/fields/encrypted/utils/decryptAllData.js +2 -2
  111. package/dist/fields/encrypted/utils/decryptAllData.js.map +1 -1
  112. package/dist/fields/encrypted/utils/decryptFieldValue.d.ts +30 -0
  113. package/dist/fields/encrypted/utils/decryptFieldValue.js +56 -0
  114. package/dist/fields/encrypted/utils/decryptFieldValue.js.map +1 -0
  115. package/dist/fields/encrypted/utils/readEncryptedField.d.ts +51 -0
  116. package/dist/fields/encrypted/utils/readEncryptedField.js +96 -0
  117. package/dist/fields/encrypted/utils/readEncryptedField.js.map +1 -0
  118. package/dist/fields/icon/adapters/lucide/generated/manifest.js.map +1 -1
  119. package/dist/fields/icon/adapters/lucide/generated/nodes.js.map +1 -1
  120. package/dist/fields/icon/adapters/radix/adapter.js +7 -0
  121. package/dist/fields/icon/adapters/radix/adapter.js.map +1 -1
  122. package/dist/fields/icon/adapters/radix/client.d.ts +3 -2
  123. package/dist/fields/icon/adapters/radix/client.js +3 -2
  124. package/dist/fields/icon/adapters/radix/client.js.map +1 -1
  125. package/dist/fields/icon/adapters/radix/generated/manifest.js.map +1 -1
  126. package/dist/fields/icon/adapters/radix/generated/nodes.js +3625 -0
  127. package/dist/fields/icon/adapters/radix/generated/nodes.js.map +1 -0
  128. package/dist/fields/icon/adapters/tabler/generated/manifest.js.map +1 -1
  129. package/dist/fields/icon/adapters/tabler/generated/nodes.js.map +1 -1
  130. package/dist/fields/icon/client/DrawerGlyph.js +34 -17
  131. package/dist/fields/icon/client/DrawerGlyph.js.map +1 -1
  132. package/dist/fields/icon/client/IconDrawerContent.js +9 -45
  133. package/dist/fields/icon/client/IconDrawerContent.js.map +1 -1
  134. package/dist/fields/icon/client/IconFieldClient.d.ts +7 -0
  135. package/dist/fields/icon/client/IconFieldClient.js +15 -7
  136. package/dist/fields/icon/client/IconFieldClient.js.map +1 -1
  137. package/dist/fields/icon/client/IconGridCell.js +67 -0
  138. package/dist/fields/icon/client/IconGridCell.js.map +1 -0
  139. package/dist/fields/icon/client/icon-field.css +12 -2
  140. package/dist/fields/icon/codegen/emit.js +5 -4
  141. package/dist/fields/icon/codegen/emit.js.map +1 -1
  142. package/dist/fields/icon/codegen/generate.js +32 -6
  143. package/dist/fields/icon/codegen/generate.js.map +1 -1
  144. package/dist/fields/icon/layers/coalesce.js +41 -0
  145. package/dist/fields/icon/layers/coalesce.js.map +1 -0
  146. package/dist/fields/icon/layers/manifestCache.d.ts +6 -0
  147. package/dist/fields/icon/layers/manifestCache.js +49 -0
  148. package/dist/fields/icon/layers/manifestCache.js.map +1 -0
  149. package/dist/fields/icon/layers/resolve.d.ts +20 -0
  150. package/dist/fields/icon/layers/resolve.js +63 -0
  151. package/dist/fields/icon/layers/resolve.js.map +1 -0
  152. package/dist/fields/icon/layers/upload.d.ts +52 -0
  153. package/dist/fields/icon/layers/upload.js +116 -0
  154. package/dist/fields/icon/layers/upload.js.map +1 -0
  155. package/dist/fields/icon/plugin.js +24 -0
  156. package/dist/fields/icon/plugin.js.map +1 -1
  157. package/dist/fields/icon/react/createIcon.d.ts +5 -0
  158. package/dist/fields/icon/react/createIcon.js +22 -4
  159. package/dist/fields/icon/react/createIcon.js.map +1 -1
  160. package/dist/fields/icon/react/createRscIcon.js +22 -1
  161. package/dist/fields/icon/react/createRscIcon.js.map +1 -1
  162. package/dist/fields/icon/react/resolveRendered.js +21 -0
  163. package/dist/fields/icon/react/resolveRendered.js.map +1 -0
  164. package/dist/fields/icon/react/types.d.ts +15 -1
  165. package/dist/fields/icon/rsc/IconCell.d.ts +2 -2
  166. package/dist/fields/icon/rsc/IconCell.js +12 -5
  167. package/dist/fields/icon/rsc/IconCell.js.map +1 -1
  168. package/dist/fields/icon/rsc/IconFieldServer.js +16 -2
  169. package/dist/fields/icon/rsc/IconFieldServer.js.map +1 -1
  170. package/dist/fields/icon/rsc/IconLibrarySelectServer.js +1 -1
  171. package/dist/fields/icon/rsc/IconLibrarySelectServer.js.map +1 -1
  172. package/dist/fields/icon/server/endpoint.d.ts +12 -0
  173. package/dist/fields/icon/server/endpoint.js +52 -0
  174. package/dist/fields/icon/server/endpoint.js.map +1 -0
  175. package/dist/fields/icon/server/manifestCache.js +9 -4
  176. package/dist/fields/icon/server/manifestCache.js.map +1 -1
  177. package/dist/fields/icon/server/resolveIconMeta.js +31 -0
  178. package/dist/fields/icon/server/resolveIconMeta.js.map +1 -0
  179. package/dist/fields/icon/server/validate.js +5 -2
  180. package/dist/fields/icon/server/validate.js.map +1 -1
  181. package/dist/fields/icon/shared/adapterComponents.d.ts +3 -2
  182. package/dist/fields/icon/shared/iconLabel.js +26 -0
  183. package/dist/fields/icon/shared/iconLabel.js.map +1 -0
  184. package/dist/fields/measurement/client/MeasurementCell.d.ts +18 -0
  185. package/dist/fields/measurement/client/MeasurementCell.js +47 -0
  186. package/dist/fields/measurement/client/MeasurementCell.js.map +1 -0
  187. package/dist/fields/measurement/client/MeasurementField.d.ts +13 -0
  188. package/dist/fields/measurement/client/MeasurementField.js +70 -0
  189. package/dist/fields/measurement/client/MeasurementField.js.map +1 -0
  190. package/dist/fields/measurement/client/MeasurementInput.d.ts +42 -0
  191. package/dist/fields/measurement/client/MeasurementInput.js +327 -0
  192. package/dist/fields/measurement/client/MeasurementInput.js.map +1 -0
  193. package/dist/fields/measurement/client/MeasurementUnitsProvider.d.ts +24 -0
  194. package/dist/fields/measurement/client/MeasurementUnitsProvider.js +61 -0
  195. package/dist/fields/measurement/client/MeasurementUnitsProvider.js.map +1 -0
  196. package/dist/fields/measurement/client/editModel.js +124 -0
  197. package/dist/fields/measurement/client/editModel.js.map +1 -0
  198. package/dist/fields/measurement/client/measurementCell.css +4 -0
  199. package/dist/fields/measurement/client/measurementField.css +215 -0
  200. package/dist/fields/measurement/client/useMeasurementModel.d.ts +19 -0
  201. package/dist/fields/measurement/client/useMeasurementModel.js +85 -0
  202. package/dist/fields/measurement/client/useMeasurementModel.js.map +1 -0
  203. package/dist/fields/measurement/engine/convert.d.ts +8 -0
  204. package/dist/fields/measurement/engine/convert.js +21 -0
  205. package/dist/fields/measurement/engine/convert.js.map +1 -0
  206. package/dist/fields/measurement/engine/format.d.ts +37 -0
  207. package/dist/fields/measurement/engine/format.js +156 -0
  208. package/dist/fields/measurement/engine/format.js.map +1 -0
  209. package/dist/fields/measurement/engine/locale.d.ts +25 -0
  210. package/dist/fields/measurement/engine/locale.js +79 -0
  211. package/dist/fields/measurement/engine/locale.js.map +1 -0
  212. package/dist/fields/measurement/engine/precision.d.ts +34 -0
  213. package/dist/fields/measurement/engine/precision.js +63 -0
  214. package/dist/fields/measurement/engine/precision.js.map +1 -0
  215. package/dist/fields/measurement/engine/registry.d.ts +55 -0
  216. package/dist/fields/measurement/engine/registry.js +117 -0
  217. package/dist/fields/measurement/engine/registry.js.map +1 -0
  218. package/dist/fields/measurement/engine/units.d.ts +178 -0
  219. package/dist/fields/measurement/engine/units.js +198 -0
  220. package/dist/fields/measurement/engine/units.js.map +1 -0
  221. package/dist/fields/measurement/measurementField.d.ts +17 -0
  222. package/dist/fields/measurement/measurementField.js +139 -0
  223. package/dist/fields/measurement/measurementField.js.map +1 -0
  224. package/dist/fields/measurement/options.d.ts +76 -0
  225. package/dist/fields/measurement/options.js +9 -0
  226. package/dist/fields/measurement/options.js.map +1 -0
  227. package/dist/fields/measurement/presets.d.ts +117 -0
  228. package/dist/fields/measurement/presets.js +136 -0
  229. package/dist/fields/measurement/presets.js.map +1 -0
  230. package/dist/fields/measurement/server/MeasurementCellServer.d.ts +21 -0
  231. package/dist/fields/measurement/server/MeasurementCellServer.js +53 -0
  232. package/dist/fields/measurement/server/MeasurementCellServer.js.map +1 -0
  233. package/dist/fields/measurement/server/MeasurementFieldServer.d.ts +16 -0
  234. package/dist/fields/measurement/server/MeasurementFieldServer.js +45 -0
  235. package/dist/fields/measurement/server/MeasurementFieldServer.js.map +1 -0
  236. package/dist/fields/measurement/server/getUserUnits.js +39 -0
  237. package/dist/fields/measurement/server/getUserUnits.js.map +1 -0
  238. package/dist/fields/measurement/server/resolvePrecisionSafe.js +24 -0
  239. package/dist/fields/measurement/server/resolvePrecisionSafe.js.map +1 -0
  240. package/dist/fields/measurement/server/resolveRegistryDefault.js +26 -0
  241. package/dist/fields/measurement/server/resolveRegistryDefault.js.map +1 -0
  242. package/dist/fields/phoneNumber/client/CountryFlag.d.ts +16 -0
  243. package/dist/fields/phoneNumber/client/CountryFlag.js +40 -0
  244. package/dist/fields/phoneNumber/client/CountryFlag.js.map +1 -0
  245. package/dist/fields/phoneNumber/client/CountryPicker.d.ts +21 -0
  246. package/dist/fields/phoneNumber/client/CountryPicker.js +255 -0
  247. package/dist/fields/phoneNumber/client/CountryPicker.js.map +1 -0
  248. package/dist/fields/phoneNumber/client/PhoneNumberField.d.ts +26 -0
  249. package/dist/fields/phoneNumber/client/PhoneNumberField.js +318 -0
  250. package/dist/fields/phoneNumber/client/PhoneNumberField.js.map +1 -0
  251. package/dist/fields/phoneNumber/client/editModel.js +86 -0
  252. package/dist/fields/phoneNumber/client/editModel.js.map +1 -0
  253. package/dist/fields/phoneNumber/client/phoneNumberField.css +305 -0
  254. package/dist/fields/phoneNumber/engine/countries.d.ts +36 -0
  255. package/dist/fields/phoneNumber/engine/countries.js +68 -0
  256. package/dist/fields/phoneNumber/engine/countries.js.map +1 -0
  257. package/dist/fields/phoneNumber/engine/draft.d.ts +13 -0
  258. package/dist/fields/phoneNumber/engine/draft.js +72 -0
  259. package/dist/fields/phoneNumber/engine/draft.js.map +1 -0
  260. package/dist/fields/phoneNumber/engine/metadata.d.ts +11 -0
  261. package/dist/fields/phoneNumber/engine/metadata.js +32 -0
  262. package/dist/fields/phoneNumber/engine/metadata.js.map +1 -0
  263. package/dist/fields/phoneNumber/engine/phone.d.ts +37 -0
  264. package/dist/fields/phoneNumber/engine/phone.js +59 -0
  265. package/dist/fields/phoneNumber/engine/phone.js.map +1 -0
  266. package/dist/fields/phoneNumber/options.d.ts +72 -0
  267. package/dist/fields/phoneNumber/options.js +37 -0
  268. package/dist/fields/phoneNumber/options.js.map +1 -0
  269. package/dist/fields/phoneNumber/phoneNumberField.d.ts +14 -0
  270. package/dist/fields/phoneNumber/phoneNumberField.js +167 -0
  271. package/dist/fields/phoneNumber/phoneNumberField.js.map +1 -0
  272. package/dist/fields/phoneNumber/server/PhoneNumberCellServer.d.ts +19 -0
  273. package/dist/fields/phoneNumber/server/PhoneNumberCellServer.js +73 -0
  274. package/dist/fields/phoneNumber/server/PhoneNumberCellServer.js.map +1 -0
  275. package/dist/fields/phoneNumber/server/PhoneNumberFieldServer.d.ts +16 -0
  276. package/dist/fields/phoneNumber/server/PhoneNumberFieldServer.js +57 -0
  277. package/dist/fields/phoneNumber/server/PhoneNumberFieldServer.js.map +1 -0
  278. package/dist/fields/phoneNumber/server/flagsEndpoint.js +51 -0
  279. package/dist/fields/phoneNumber/server/flagsEndpoint.js.map +1 -0
  280. package/dist/fields/phoneNumber/server/readPhoneOptions.js +18 -0
  281. package/dist/fields/phoneNumber/server/readPhoneOptions.js.map +1 -0
  282. package/dist/fields/phoneNumber/server/resolvePhoneOptionsSafe.js +33 -0
  283. package/dist/fields/phoneNumber/server/resolvePhoneOptionsSafe.js.map +1 -0
  284. package/dist/index.d.ts +5 -3
  285. package/dist/index.js +35 -1
  286. package/dist/index.js.map +1 -1
  287. package/dist/translations/ar.js +62 -0
  288. package/dist/translations/ar.js.map +1 -0
  289. package/dist/translations/de.js +19 -1
  290. package/dist/translations/de.js.map +1 -1
  291. package/dist/translations/en.js +19 -1
  292. package/dist/translations/en.js.map +1 -1
  293. package/dist/translations/es.js +62 -0
  294. package/dist/translations/es.js.map +1 -0
  295. package/dist/translations/fr.js +62 -0
  296. package/dist/translations/fr.js.map +1 -0
  297. package/dist/translations/id.js +62 -0
  298. package/dist/translations/id.js.map +1 -0
  299. package/dist/translations/index.d.ts +10 -1
  300. package/dist/translations/index.js +19 -1
  301. package/dist/translations/index.js.map +1 -1
  302. package/dist/translations/keys.d.ts +19 -1
  303. package/dist/translations/keys.js +20 -2
  304. package/dist/translations/keys.js.map +1 -1
  305. package/dist/translations/ko.js +62 -0
  306. package/dist/translations/ko.js.map +1 -0
  307. package/dist/translations/pt.js +62 -0
  308. package/dist/translations/pt.js.map +1 -0
  309. package/dist/translations/ru.js +62 -0
  310. package/dist/translations/ru.js.map +1 -0
  311. package/dist/translations/uk.js +62 -0
  312. package/dist/translations/uk.js.map +1 -0
  313. package/dist/translations/zh.js +62 -0
  314. package/dist/translations/zh.js.map +1 -0
  315. package/dist/types.d.ts +165 -8
  316. package/dist/utils/resolveStaticLabel.js +13 -0
  317. package/dist/utils/resolveStaticLabel.js.map +1 -0
  318. package/package.json +31 -7
  319. package/dist/fields/icon/rsc/resolveStaticLabel.js +0 -16
  320. package/dist/fields/icon/rsc/resolveStaticLabel.js.map +0 -1
@@ -4,8 +4,63 @@ import { CheckboxField, CodeField, DateField, EmailField, JSONField, NumberField
4
4
  //#region src/fields/encrypted/types.d.ts
5
5
  type EncryptedSourceField = CheckboxField | CodeField | DateField | EmailField | JSONField | NumberField | PointField | RadioField | RichTextField | SelectField | TextareaField | TextField;
6
6
  type EncryptedSourceType = EncryptedSourceField['type'];
7
- type EncryptedProtection = 'masked' | 'none';
7
+ /**
8
+ * Confidentiality ladder for the admin and API surface. `'none'` renders the
9
+ * native component with the value visible; `'masked'` (default) conceals behind
10
+ * dots with a reveal toggle; `'writeOnly'` additionally strips the field from
11
+ * every read result (REST, GraphQL, Local API) so the plaintext never leaves
12
+ * the server. Write-only values are read deliberately via `readEncryptedField`
13
+ * or `decryptFieldValue`.
14
+ */
15
+ type EncryptedProtection = 'masked' | 'none' | 'writeOnly';
16
+ /**
17
+ * Identification hint for a write-only field: how many leading and trailing
18
+ * plaintext characters to store beside the ciphertext at seal time (never
19
+ * derived by decrypting on read). `prefix + suffix` is capped at 32, enough to
20
+ * carry a constant format prefix (`sk_live_`, `whsec_`) and still say which
21
+ * key this is.
22
+ *
23
+ * The cap is the blunt guard. What decides whether a hint is stored at all is
24
+ * the value being sliced: it must keep at least as many characters hidden as
25
+ * the hint exposes, and at least 8 either way. So one config can sit on a
26
+ * collection holding both long tokens and short ones, hinting the first and
27
+ * silently declining the second, rather than exposing half of it.
28
+ */
29
+ interface EncryptedHintConfig {
30
+ prefix?: number;
31
+ suffix?: number;
32
+ }
33
+ /**
34
+ * Generator for a write-only field's admin Generate action. `true` uses the
35
+ * default: 32 chars of crypto-random base62. Values are generated client-side
36
+ * in the form, so a generated secret is visible and copyable exactly until
37
+ * save, then never again.
38
+ */
39
+ interface EncryptedGenerateConfig {
40
+ /** Generated length excluding the prefix. Integer in [8, 128], rejected otherwise; default 32. */
41
+ length?: number;
42
+ /** Literal prefix, e.g. 'whsec_'. Counts toward the hint but not `length`. */
43
+ prefix?: string;
44
+ /** Alphabet to sample from: 10 to 256 distinct code points (duplicates collapse). Default base62. */
45
+ charset?: string;
46
+ }
8
47
  interface EncryptedFieldOptions {
48
+ /**
49
+ * Pins the first component of the ciphertext's AAD binding, which otherwise
50
+ * is the collection or global slug. For a field on a collection whose slug a
51
+ * consumer can configure (a plugin-owned collection), the slug is a poor
52
+ * binding: renaming it makes every stored value fail authentication, and no
53
+ * utility can recover them because reads resolve the binding from the
54
+ * current slug too. A pinned scope survives the rename.
55
+ *
56
+ * Must not contain `.` (the AAD component separator) and must be unique per
57
+ * logical schema: two fields of the same name sharing a scope share a
58
+ * binding, which widens the documented same-field ciphertext portability
59
+ * across their collections. Decide it before data exists; changing it later
60
+ * is a re-keying event, and stored values become unreadable exactly as a
61
+ * slug rename would have made them.
62
+ */
63
+ aadScope?: string;
9
64
  keys?: KeysConfig;
10
65
  /**
11
66
  * Cosmetic number of dots shown while the field is concealed in the admin.
@@ -19,6 +74,16 @@ interface EncryptedFieldOptions {
19
74
  }) => TextField;
20
75
  protection?: EncryptedProtection;
21
76
  queryable?: boolean;
77
+ /**
78
+ * Write-only fields only: whether the admin offers the clear (×) action.
79
+ * Defaults to `true` for optional fields and is forced off for `required`
80
+ * ones (clearing a required secret could never save).
81
+ */
82
+ clearable?: boolean;
83
+ /** Write-only text/email fields only: store an identification hint. */
84
+ hint?: EncryptedHintConfig;
85
+ /** Write-only text fields only: enable the admin Generate action. */
86
+ generate?: true | EncryptedGenerateConfig;
22
87
  }
23
88
  /** Serializable subset shipped to ProtectedField via clientProps. */
24
89
  interface EncryptedFieldPatch {
@@ -31,5 +96,5 @@ interface EncryptedFieldPatch {
31
96
  type: EncryptedSourceType;
32
97
  }
33
98
  //#endregion
34
- export { EncryptedFieldOptions, EncryptedFieldPatch, EncryptedProtection, EncryptedSourceField };
99
+ export { EncryptedFieldOptions, EncryptedFieldPatch, EncryptedGenerateConfig, EncryptedHintConfig, EncryptedProtection, EncryptedSourceField };
35
100
  //# sourceMappingURL=types.d.ts.map
@@ -2,11 +2,18 @@
2
2
  /** Request-context modes the encrypted hooks respect (utilities set them). */
3
3
  const ENCRYPTED_CONTEXT_KEY = "tenxFieldsEncrypted";
4
4
  const FIELDS_CUSTOM_KEY = "@10x-media/fields";
5
+ /**
6
+ * The AAD's first component for one marker: the pinned scope when the field
7
+ * declares one, else the schema slug the caller resolved. Every construction
8
+ * site goes through this so a pinned scope cannot be honoured on seal and
9
+ * missed on read.
10
+ */
11
+ const aadScopeOf = (marker, slug) => marker.aadScope ?? slug;
5
12
  const getEncryptedMarker = (field) => {
6
13
  const entry = field.custom?.[FIELDS_CUSTOM_KEY];
7
14
  if (entry && typeof entry === "object" && "encrypted" in entry) return entry.encrypted;
8
15
  };
9
16
  //#endregion
10
- export { ENCRYPTED_CONTEXT_KEY, FIELDS_CUSTOM_KEY, getEncryptedMarker };
17
+ export { ENCRYPTED_CONTEXT_KEY, FIELDS_CUSTOM_KEY, aadScopeOf, getEncryptedMarker };
11
18
 
12
19
  //# sourceMappingURL=types.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","names":[],"sources":["../../../src/fields/encrypted/types.ts"],"sourcesContent":["import type {\n\tCheckboxField,\n\tCodeField,\n\tDateField,\n\tEmailField,\n\tJSONField,\n\tNumberField,\n\tPointField,\n\tRadioField,\n\tRichTextField,\n\tSelectField,\n\tTextareaField,\n\tTextField,\n} from 'payload'\nimport type { DecryptFailurePolicy, KeysConfig } from '../../types'\nimport type { BidxNormalize } from './crypto/bidx'\n\nexport type EncryptedSourceField =\n\t| CheckboxField\n\t| CodeField\n\t| DateField\n\t| EmailField\n\t| JSONField\n\t| NumberField\n\t| PointField\n\t| RadioField\n\t| RichTextField\n\t| SelectField\n\t| TextareaField\n\t| TextField\n\nexport type EncryptedSourceType = EncryptedSourceField['type']\n\nexport type EncryptedProtection = 'masked' | 'none'\n\nexport interface EncryptedFieldOptions {\n\tkeys?: KeysConfig\n\t/**\n\t * Cosmetic number of dots shown while the field is concealed in the admin.\n\t * Decoupled from the real value length (unknown until reveal). Clamped to\n\t * [1, 64] at the factory; defaults to 8. Ignored by the checkbox facsimile.\n\t */\n\tmaskDots?: number\n\tonDecryptFailure?: DecryptFailurePolicy\n\toverrides?: (args: { field: TextField }) => TextField\n\tprotection?: EncryptedProtection\n\tqueryable?: boolean\n}\n\n/** Request-context modes the encrypted hooks respect (utilities set them). */\nexport const ENCRYPTED_CONTEXT_KEY = 'tenxFieldsEncrypted'\nexport type EncryptedContextMode = 'decrypt' | 'raw' | 'rotate'\n\nexport const FIELDS_CUSTOM_KEY = '@10x-media/fields'\n\n/**\n * Server-side marker the factory stamps on `field.custom`. `custom` is in\n * Payload's serverOnlyFieldProperties list, so KeysConfig functions never\n * reach the client. Consumed by the query rewrite, boot check, and utilities.\n */\nexport interface EncryptedFieldMarker {\n\tbidxName?: string\n\tfieldName: string\n\thasMany: boolean\n\tkeys?: KeysConfig\n\tlocalized: boolean\n\tnormalize: BidxNormalize\n\tonDecryptFailure?: DecryptFailurePolicy\n\tqueryable: boolean\n\tsourceType: EncryptedSourceType\n}\n\n/** Serializable subset shipped to ProtectedField via clientProps. */\nexport interface EncryptedFieldPatch {\n\tadmin?: Record<string, unknown>\n\thasMany?: boolean\n\toptions?: { label: string; value: string }[]\n\ttype: EncryptedSourceType\n}\n\nexport const getEncryptedMarker = (field: {\n\tcustom?: Record<string, unknown>\n}): EncryptedFieldMarker | undefined => {\n\tconst entry = field.custom?.[FIELDS_CUSTOM_KEY]\n\tif (entry && typeof entry === 'object' && 'encrypted' in entry) {\n\t\treturn (entry as { encrypted: EncryptedFieldMarker }).encrypted\n\t}\n\treturn undefined\n}\n"],"mappings":";;AAkDA,MAAa,wBAAwB;AAGrC,MAAa,oBAAoB;AA2BjC,MAAa,sBAAsB,UAEK;CACvC,MAAM,QAAQ,MAAM,SAAS;CAC7B,IAAI,SAAS,OAAO,UAAU,YAAY,eAAe,OACxD,OAAQ,MAA8C;AAGxD"}
1
+ {"version":3,"file":"types.js","names":[],"sources":["../../../src/fields/encrypted/types.ts"],"sourcesContent":["import type {\n\tCheckboxField,\n\tCodeField,\n\tDateField,\n\tEmailField,\n\tJSONField,\n\tNumberField,\n\tPointField,\n\tRadioField,\n\tRichTextField,\n\tSelectField,\n\tTextareaField,\n\tTextField,\n} from 'payload'\nimport type { DecryptFailurePolicy, KeysConfig } from '../../types'\nimport type { BidxNormalize } from './crypto/bidx'\n\nexport type EncryptedSourceField =\n\t| CheckboxField\n\t| CodeField\n\t| DateField\n\t| EmailField\n\t| JSONField\n\t| NumberField\n\t| PointField\n\t| RadioField\n\t| RichTextField\n\t| SelectField\n\t| TextareaField\n\t| TextField\n\nexport type EncryptedSourceType = EncryptedSourceField['type']\n\n/**\n * Confidentiality ladder for the admin and API surface. `'none'` renders the\n * native component with the value visible; `'masked'` (default) conceals behind\n * dots with a reveal toggle; `'writeOnly'` additionally strips the field from\n * every read result (REST, GraphQL, Local API) so the plaintext never leaves\n * the server. Write-only values are read deliberately via `readEncryptedField`\n * or `decryptFieldValue`.\n */\nexport type EncryptedProtection = 'masked' | 'none' | 'writeOnly'\n\n/**\n * Identification hint for a write-only field: how many leading and trailing\n * plaintext characters to store beside the ciphertext at seal time (never\n * derived by decrypting on read). `prefix + suffix` is capped at 32, enough to\n * carry a constant format prefix (`sk_live_`, `whsec_`) and still say which\n * key this is.\n *\n * The cap is the blunt guard. What decides whether a hint is stored at all is\n * the value being sliced: it must keep at least as many characters hidden as\n * the hint exposes, and at least 8 either way. So one config can sit on a\n * collection holding both long tokens and short ones, hinting the first and\n * silently declining the second, rather than exposing half of it.\n */\nexport interface EncryptedHintConfig {\n\tprefix?: number\n\tsuffix?: number\n}\n\n/**\n * Generator for a write-only field's admin Generate action. `true` uses the\n * default: 32 chars of crypto-random base62. Values are generated client-side\n * in the form, so a generated secret is visible and copyable exactly until\n * save, then never again.\n */\nexport interface EncryptedGenerateConfig {\n\t/** Generated length excluding the prefix. Integer in [8, 128], rejected otherwise; default 32. */\n\tlength?: number\n\t/** Literal prefix, e.g. 'whsec_'. Counts toward the hint but not `length`. */\n\tprefix?: string\n\t/** Alphabet to sample from: 10 to 256 distinct code points (duplicates collapse). Default base62. */\n\tcharset?: string\n}\n\nexport interface EncryptedFieldOptions {\n\t/**\n\t * Pins the first component of the ciphertext's AAD binding, which otherwise\n\t * is the collection or global slug. For a field on a collection whose slug a\n\t * consumer can configure (a plugin-owned collection), the slug is a poor\n\t * binding: renaming it makes every stored value fail authentication, and no\n\t * utility can recover them because reads resolve the binding from the\n\t * current slug too. A pinned scope survives the rename.\n\t *\n\t * Must not contain `.` (the AAD component separator) and must be unique per\n\t * logical schema: two fields of the same name sharing a scope share a\n\t * binding, which widens the documented same-field ciphertext portability\n\t * across their collections. Decide it before data exists; changing it later\n\t * is a re-keying event, and stored values become unreadable exactly as a\n\t * slug rename would have made them.\n\t */\n\taadScope?: string\n\tkeys?: KeysConfig\n\t/**\n\t * Cosmetic number of dots shown while the field is concealed in the admin.\n\t * Decoupled from the real value length (unknown until reveal). Clamped to\n\t * [1, 64] at the factory; defaults to 8. Ignored by the checkbox facsimile.\n\t */\n\tmaskDots?: number\n\tonDecryptFailure?: DecryptFailurePolicy\n\toverrides?: (args: { field: TextField }) => TextField\n\tprotection?: EncryptedProtection\n\tqueryable?: boolean\n\t/**\n\t * Write-only fields only: whether the admin offers the clear (×) action.\n\t * Defaults to `true` for optional fields and is forced off for `required`\n\t * ones (clearing a required secret could never save).\n\t */\n\tclearable?: boolean\n\t/** Write-only text/email fields only: store an identification hint. */\n\thint?: EncryptedHintConfig\n\t/** Write-only text fields only: enable the admin Generate action. */\n\tgenerate?: true | EncryptedGenerateConfig\n}\n\n/** Request-context modes the encrypted hooks respect (utilities set them). */\nexport const ENCRYPTED_CONTEXT_KEY = 'tenxFieldsEncrypted'\nexport type EncryptedContextMode = 'decrypt' | 'raw' | 'rotate'\n\nexport const FIELDS_CUSTOM_KEY = '@10x-media/fields'\n\n/**\n * Server-side marker the factory stamps on `field.custom`. `custom` is in\n * Payload's serverOnlyFieldProperties list, so KeysConfig functions never\n * reach the client. Consumed by the query rewrite, boot check, and utilities.\n */\nexport interface EncryptedFieldMarker {\n\t/** Pinned AAD scope; the schema slug when absent. See EncryptedFieldOptions. */\n\taadScope?: string\n\tbidxName?: string\n\tfieldName: string\n\thasMany: boolean\n\tkeys?: KeysConfig\n\tlocalized: boolean\n\tnormalize: BidxNormalize\n\tonDecryptFailure?: DecryptFailurePolicy\n\tqueryable: boolean\n\t/** Name of the virtual set-indicator sibling; present only when `writeOnly`. */\n\tsetName?: string\n\t/** Normalized hint config; present only when `writeOnly` with a hint. */\n\thint?: { prefix: number; suffix: number }\n\t/** Name of the stored hint sibling; present only when `hint` is. */\n\thintName?: string\n\tsourceType: EncryptedSourceType\n\twriteOnly: boolean\n}\n\n/** Serializable subset shipped to ProtectedField via clientProps. */\nexport interface EncryptedFieldPatch {\n\tadmin?: Record<string, unknown>\n\thasMany?: boolean\n\toptions?: { label: string; value: string }[]\n\ttype: EncryptedSourceType\n}\n\n/**\n * The AAD's first component for one marker: the pinned scope when the field\n * declares one, else the schema slug the caller resolved. Every construction\n * site goes through this so a pinned scope cannot be honoured on seal and\n * missed on read.\n */\nexport const aadScopeOf = (marker: EncryptedFieldMarker, slug: string): string =>\n\tmarker.aadScope ?? slug\n\nexport const getEncryptedMarker = (field: {\n\tcustom?: Record<string, unknown>\n}): EncryptedFieldMarker | undefined => {\n\tconst entry = field.custom?.[FIELDS_CUSTOM_KEY]\n\tif (entry && typeof entry === 'object' && 'encrypted' in entry) {\n\t\treturn (entry as { encrypted: EncryptedFieldMarker }).encrypted\n\t}\n\treturn undefined\n}\n"],"mappings":";;AAqHA,MAAa,wBAAwB;AAGrC,MAAa,oBAAoB;;;;;;;AA0CjC,MAAa,cAAc,QAA8B,SACxD,OAAO,YAAY;AAEpB,MAAa,sBAAsB,UAEK;CACvC,MAAM,QAAQ,MAAM,SAAS;CAC7B,IAAI,SAAS,OAAO,UAAU,YAAY,eAAe,OACxD,OAAQ,MAA8C;AAGxD"}
@@ -1,5 +1,5 @@
1
1
  import { resolveKeys } from "../crypto/keys.js";
2
- import { ENCRYPTED_CONTEXT_KEY } from "../types.js";
2
+ import { ENCRYPTED_CONTEXT_KEY, aadScopeOf } from "../types.js";
3
3
  import { scanEncryptedFields } from "../scan.js";
4
4
  import { getFieldsRegistry } from "../../../plugin/registry.js";
5
5
  import { isSealed, unseal } from "../crypto/wire.js";
@@ -30,7 +30,7 @@ const decryptAllData = async (payload, options = {}) => {
30
30
  report.collections[collection.slug] = stats;
31
31
  const openValue = async ({ locale, marker, slug, value }) => {
32
32
  const ring = await resolveKeys(marker.keys ?? registry?.encrypted?.keys, payload.config.secret);
33
- const base = `${slug}.${marker.fieldName}`;
33
+ const base = `${aadScopeOf(marker, slug)}.${marker.fieldName}`;
34
34
  const candidates = marker.localized ? [...locale ? [`${base}.${locale}`] : [], ...localeCodes.map((code) => `${base}.${code}`)] : [base];
35
35
  const openOne = (item) => {
36
36
  if (!isSealed(item)) return item;
@@ -1 +1 @@
1
- {"version":3,"file":"decryptAllData.js","names":[],"sources":["../../../../src/fields/encrypted/utils/decryptAllData.ts"],"sourcesContent":["import type { Payload } from 'payload'\nimport { getFieldsRegistry } from '../../../plugin/registry'\nimport { resolveKeys } from '../crypto/keys'\nimport { isSealed, unseal } from '../crypto/wire'\nimport { scanEncryptedFields } from '../scan'\nimport { ENCRYPTED_CONTEXT_KEY, type EncryptedFieldMarker } from '../types'\nimport { getAtPath, pageThrough, setAtPath } from './pageThrough'\nimport type { RotateOptions, RotateReport } from './rotateEncryptedFields'\n\ninterface OpenValueArgs {\n\tlocale?: string\n\tmarker: EncryptedFieldMarker\n\tslug: string\n\tvalue: unknown\n}\n\n/**\n * Removal path: unseals every sealed value and stores it as plaintext, with\n * hooks in 'decrypt' mode so nothing re-seals. Non-string plaintexts are\n * stored JSON-stringified (the backing column is text); swapping the field\n * back to its native type afterwards is a schema migration the consumer owns\n * (documented in the removal guide). The decrypt-mode beforeChange hook nulls\n * each blind-index sibling at its own container scope, so this never writes the\n * index by hand (a flat write would mis-scope a nested field's index).\n */\nexport const decryptAllData = async (\n\tpayload: Payload,\n\toptions: RotateOptions = {}\n): Promise<RotateReport> => {\n\tconst { batchSize = 100, collections, dryRun = false } = options\n\tconst report: RotateReport = { collections: {} }\n\tconst registry = getFieldsRegistry(payload.config)\n\tconst localeCodes = payload.config.localization ? payload.config.localization.localeCodes : []\n\n\tfor (const collection of payload.config.collections) {\n\t\tif (collections && !collections.includes(collection.slug)) {\n\t\t\tcontinue\n\t\t}\n\t\tconst markers = scanEncryptedFields(collection.fields)\n\t\tif (markers.size === 0) {\n\t\t\tcontinue\n\t\t}\n\t\tconst stats = { rotated: 0, scanned: 0 }\n\t\treport.collections[collection.slug] = stats\n\n\t\tconst openValue = async ({ locale, marker, slug, value }: OpenValueArgs): Promise<unknown> => {\n\t\t\tconst ring = await resolveKeys(\n\t\t\t\tmarker.keys ?? registry?.encrypted?.keys,\n\t\t\t\tpayload.config.secret\n\t\t\t)\n\t\t\tconst base = `${slug}.${marker.fieldName}`\n\t\t\tconst candidates = marker.localized\n\t\t\t\t? [\n\t\t\t\t\t\t...(locale ? [`${base}.${locale}`] : []),\n\t\t\t\t\t\t...localeCodes.map((code) => `${base}.${code}`),\n\t\t\t\t\t]\n\t\t\t\t: [base]\n\t\t\tconst openOne = (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\tconst plaintext = unseal(item, ring.dataKeys, candidates)\n\t\t\t\treturn typeof plaintext === 'string' ? plaintext : JSON.stringify(plaintext)\n\t\t\t}\n\t\t\treturn Array.isArray(value) ? value.map(openOne) : openOne(value)\n\t\t}\n\n\t\tfor await (const docs of pageThrough({ batchSize, collection: collection.slug, payload })) {\n\t\t\tfor (const doc of docs) {\n\t\t\t\tstats.scanned += 1\n\t\t\t\tconst patch: Record<string, unknown> = {}\n\t\t\t\tconst localePatches = new Map<string, Record<string, unknown>>()\n\t\t\t\tfor (const [path, marker] of markers) {\n\t\t\t\t\tconst value = getAtPath(doc, path)\n\t\t\t\t\tif (value === undefined || value === null) {\n\t\t\t\t\t\tcontinue\n\t\t\t\t\t}\n\t\t\t\t\tif (marker.localized && typeof value === 'object' && !Array.isArray(value)) {\n\t\t\t\t\t\tfor (const locale of localeCodes) {\n\t\t\t\t\t\t\tconst localeValue = (value as Record<string, unknown>)[locale]\n\t\t\t\t\t\t\tif (localeValue === undefined || localeValue === null) {\n\t\t\t\t\t\t\t\tcontinue\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tconst localePatch = localePatches.get(locale) ?? {}\n\t\t\t\t\t\t\tsetAtPath(\n\t\t\t\t\t\t\t\tlocalePatch,\n\t\t\t\t\t\t\t\tpath,\n\t\t\t\t\t\t\t\tawait openValue({ locale, marker, slug: collection.slug, value: localeValue })\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\tlocalePatches.set(locale, localePatch)\n\t\t\t\t\t\t}\n\t\t\t\t\t} else {\n\t\t\t\t\t\tsetAtPath(patch, path, await openValue({ marker, slug: collection.slug, value }))\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tconst hasWork = Object.keys(patch).length > 0 || localePatches.size > 0\n\t\t\t\tif (!hasWork) {\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t\tstats.rotated += 1\n\t\t\t\tif (dryRun) {\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t\tif (Object.keys(patch).length > 0) {\n\t\t\t\t\tawait payload.update({\n\t\t\t\t\t\tcollection: collection.slug,\n\t\t\t\t\t\tcontext: { [ENCRYPTED_CONTEXT_KEY]: 'decrypt' },\n\t\t\t\t\t\tdata: patch,\n\t\t\t\t\t\tdepth: 0,\n\t\t\t\t\t\tid: doc.id as string | number,\n\t\t\t\t\t\toverrideAccess: true,\n\t\t\t\t\t})\n\t\t\t\t}\n\t\t\t\tfor (const [locale, localePatch] of localePatches) {\n\t\t\t\t\tawait payload.update({\n\t\t\t\t\t\tcollection: collection.slug,\n\t\t\t\t\t\tcontext: { [ENCRYPTED_CONTEXT_KEY]: 'decrypt' },\n\t\t\t\t\t\tdata: localePatch,\n\t\t\t\t\t\tdepth: 0,\n\t\t\t\t\t\tid: doc.id as string | number,\n\t\t\t\t\t\tlocale: locale as never,\n\t\t\t\t\t\toverrideAccess: true,\n\t\t\t\t\t})\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\treturn report\n}\n"],"mappings":"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"}
1
+ {"version":3,"file":"decryptAllData.js","names":[],"sources":["../../../../src/fields/encrypted/utils/decryptAllData.ts"],"sourcesContent":["import type { Payload } from 'payload'\nimport { getFieldsRegistry } from '../../../plugin/registry'\nimport { resolveKeys } from '../crypto/keys'\nimport { isSealed, unseal } from '../crypto/wire'\nimport { scanEncryptedFields } from '../scan'\nimport { aadScopeOf, ENCRYPTED_CONTEXT_KEY, type EncryptedFieldMarker } from '../types'\nimport { getAtPath, pageThrough, setAtPath } from './pageThrough'\nimport type { RotateOptions, RotateReport } from './rotateEncryptedFields'\n\ninterface OpenValueArgs {\n\tlocale?: string\n\tmarker: EncryptedFieldMarker\n\tslug: string\n\tvalue: unknown\n}\n\n/**\n * Removal path: unseals every sealed value and stores it as plaintext, with\n * hooks in 'decrypt' mode so nothing re-seals. Non-string plaintexts are\n * stored JSON-stringified (the backing column is text); swapping the field\n * back to its native type afterwards is a schema migration the consumer owns\n * (documented in the removal guide). The decrypt-mode beforeChange hook nulls\n * each blind-index sibling at its own container scope, so this never writes the\n * index by hand (a flat write would mis-scope a nested field's index).\n */\nexport const decryptAllData = async (\n\tpayload: Payload,\n\toptions: RotateOptions = {}\n): Promise<RotateReport> => {\n\tconst { batchSize = 100, collections, dryRun = false } = options\n\tconst report: RotateReport = { collections: {} }\n\tconst registry = getFieldsRegistry(payload.config)\n\tconst localeCodes = payload.config.localization ? payload.config.localization.localeCodes : []\n\n\tfor (const collection of payload.config.collections) {\n\t\tif (collections && !collections.includes(collection.slug)) {\n\t\t\tcontinue\n\t\t}\n\t\tconst markers = scanEncryptedFields(collection.fields)\n\t\tif (markers.size === 0) {\n\t\t\tcontinue\n\t\t}\n\t\tconst stats = { rotated: 0, scanned: 0 }\n\t\treport.collections[collection.slug] = stats\n\n\t\tconst openValue = async ({ locale, marker, slug, value }: OpenValueArgs): Promise<unknown> => {\n\t\t\tconst ring = await resolveKeys(\n\t\t\t\tmarker.keys ?? registry?.encrypted?.keys,\n\t\t\t\tpayload.config.secret\n\t\t\t)\n\t\t\tconst base = `${aadScopeOf(marker, slug)}.${marker.fieldName}`\n\t\t\tconst candidates = marker.localized\n\t\t\t\t? [\n\t\t\t\t\t\t...(locale ? [`${base}.${locale}`] : []),\n\t\t\t\t\t\t...localeCodes.map((code) => `${base}.${code}`),\n\t\t\t\t\t]\n\t\t\t\t: [base]\n\t\t\tconst openOne = (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\tconst plaintext = unseal(item, ring.dataKeys, candidates)\n\t\t\t\treturn typeof plaintext === 'string' ? plaintext : JSON.stringify(plaintext)\n\t\t\t}\n\t\t\treturn Array.isArray(value) ? value.map(openOne) : openOne(value)\n\t\t}\n\n\t\tfor await (const docs of pageThrough({ batchSize, collection: collection.slug, payload })) {\n\t\t\tfor (const doc of docs) {\n\t\t\t\tstats.scanned += 1\n\t\t\t\tconst patch: Record<string, unknown> = {}\n\t\t\t\tconst localePatches = new Map<string, Record<string, unknown>>()\n\t\t\t\tfor (const [path, marker] of markers) {\n\t\t\t\t\tconst value = getAtPath(doc, path)\n\t\t\t\t\tif (value === undefined || value === null) {\n\t\t\t\t\t\tcontinue\n\t\t\t\t\t}\n\t\t\t\t\tif (marker.localized && typeof value === 'object' && !Array.isArray(value)) {\n\t\t\t\t\t\tfor (const locale of localeCodes) {\n\t\t\t\t\t\t\tconst localeValue = (value as Record<string, unknown>)[locale]\n\t\t\t\t\t\t\tif (localeValue === undefined || localeValue === null) {\n\t\t\t\t\t\t\t\tcontinue\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tconst localePatch = localePatches.get(locale) ?? {}\n\t\t\t\t\t\t\tsetAtPath(\n\t\t\t\t\t\t\t\tlocalePatch,\n\t\t\t\t\t\t\t\tpath,\n\t\t\t\t\t\t\t\tawait openValue({ locale, marker, slug: collection.slug, value: localeValue })\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\tlocalePatches.set(locale, localePatch)\n\t\t\t\t\t\t}\n\t\t\t\t\t} else {\n\t\t\t\t\t\tsetAtPath(patch, path, await openValue({ marker, slug: collection.slug, value }))\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tconst hasWork = Object.keys(patch).length > 0 || localePatches.size > 0\n\t\t\t\tif (!hasWork) {\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t\tstats.rotated += 1\n\t\t\t\tif (dryRun) {\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t\tif (Object.keys(patch).length > 0) {\n\t\t\t\t\tawait payload.update({\n\t\t\t\t\t\tcollection: collection.slug,\n\t\t\t\t\t\tcontext: { [ENCRYPTED_CONTEXT_KEY]: 'decrypt' },\n\t\t\t\t\t\tdata: patch,\n\t\t\t\t\t\tdepth: 0,\n\t\t\t\t\t\tid: doc.id as string | number,\n\t\t\t\t\t\toverrideAccess: true,\n\t\t\t\t\t})\n\t\t\t\t}\n\t\t\t\tfor (const [locale, localePatch] of localePatches) {\n\t\t\t\t\tawait payload.update({\n\t\t\t\t\t\tcollection: collection.slug,\n\t\t\t\t\t\tcontext: { [ENCRYPTED_CONTEXT_KEY]: 'decrypt' },\n\t\t\t\t\t\tdata: localePatch,\n\t\t\t\t\t\tdepth: 0,\n\t\t\t\t\t\tid: doc.id as string | number,\n\t\t\t\t\t\tlocale: locale as never,\n\t\t\t\t\t\toverrideAccess: true,\n\t\t\t\t\t})\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\treturn report\n}\n"],"mappings":"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"}
@@ -0,0 +1,30 @@
1
+ import { Payload } from "payload";
2
+
3
+ //#region src/fields/encrypted/utils/decryptFieldValue.d.ts
4
+ /** Which document schema an encrypted field lives in: a collection or a global. */
5
+ interface EncryptedFieldTarget {
6
+ collection?: string;
7
+ global?: string;
8
+ /** Dot path of the encrypted field within the schema, e.g. `smtp.password`. */
9
+ path: string;
10
+ /** Locale of a localized value. Omitted, every configured locale is tried. */
11
+ locale?: string;
12
+ }
13
+ interface DecryptFieldValueArgs extends EncryptedFieldTarget {
14
+ /** The raw stored wire string (`pfe1.…`), e.g. cached from `readEncryptedField`. */
15
+ value: string;
16
+ }
17
+ /**
18
+ * Decrypts one stored encrypted value outside a document read, given only its
19
+ * field path and the raw wire string. Keys and AAD resolve from the config, so
20
+ * a ciphertext cached earlier (e.g. via `readEncryptedField().ciphertext`)
21
+ * decrypts on demand without plaintext ever sitting in the cache. A non-sealed
22
+ * value (pre-adoption plaintext at rest) is returned as-is.
23
+ *
24
+ * Server-only and access-unchecked by design: calling it is the deliberate act.
25
+ * Guard call sites accordingly, and never forward the result to a client.
26
+ */
27
+ declare const decryptFieldValue: (payload: Payload, args: DecryptFieldValueArgs) => Promise<unknown>;
28
+ //#endregion
29
+ export { DecryptFieldValueArgs, EncryptedFieldTarget, decryptFieldValue };
30
+ //# sourceMappingURL=decryptFieldValue.d.ts.map
@@ -0,0 +1,56 @@
1
+ import { resolveKeys } from "../crypto/keys.js";
2
+ import { aadScopeOf } from "../types.js";
3
+ import { scanEncryptedFields } from "../scan.js";
4
+ import { getFieldsRegistry } from "../../../plugin/registry.js";
5
+ import { buildAad } from "../crypto/aad.js";
6
+ import { isSealed, unseal } from "../crypto/wire.js";
7
+ //#region src/fields/encrypted/utils/decryptFieldValue.ts
8
+ /** Resolves a target's schema slug and encrypted-field marker, or throws with the reason. */
9
+ const resolveEncryptedField = (payload, target) => {
10
+ const { collection, global, path } = target;
11
+ if (collection && global || !collection && !global) throw new Error(`@10x-media/fields: pass exactly one of 'collection' or 'global' for encrypted field '${path}'`);
12
+ const slug = collection ?? global;
13
+ const fields = collection ? payload.config.collections.find((entry) => entry.slug === collection)?.fields : payload.config.globals.find((entry) => entry.slug === global)?.fields;
14
+ if (!fields) throw new Error(`@10x-media/fields: no ${collection ? "collection" : "global"} with slug '${slug}'`);
15
+ const marker = scanEncryptedFields(fields).get(path);
16
+ if (!marker) throw new Error(`@10x-media/fields: '${slug}.${path}' is not an encrypted field`);
17
+ return {
18
+ marker,
19
+ slug
20
+ };
21
+ };
22
+ /** Read-side AAD candidates for a marker outside a document read (mirrors decryptAllData). */
23
+ const aadCandidatesFor = (payload, { locale, marker, slug }) => {
24
+ const scope = aadScopeOf(marker, slug);
25
+ if (!marker.localized) return [buildAad([scope, marker.fieldName])];
26
+ const codes = payload.config.localization ? payload.config.localization.localeCodes : [];
27
+ return (locale ? [locale, ...codes.filter((code) => code !== locale)] : codes).map((code) => buildAad([
28
+ scope,
29
+ marker.fieldName,
30
+ code
31
+ ]));
32
+ };
33
+ /**
34
+ * Decrypts one stored encrypted value outside a document read, given only its
35
+ * field path and the raw wire string. Keys and AAD resolve from the config, so
36
+ * a ciphertext cached earlier (e.g. via `readEncryptedField().ciphertext`)
37
+ * decrypts on demand without plaintext ever sitting in the cache. A non-sealed
38
+ * value (pre-adoption plaintext at rest) is returned as-is.
39
+ *
40
+ * Server-only and access-unchecked by design: calling it is the deliberate act.
41
+ * Guard call sites accordingly, and never forward the result to a client.
42
+ */
43
+ const decryptFieldValue = async (payload, args) => {
44
+ const { locale, value } = args;
45
+ const resolved = resolveEncryptedField(payload, args);
46
+ if (!isSealed(value)) return value;
47
+ const registry = getFieldsRegistry(payload.config);
48
+ return unseal(value, (await resolveKeys(resolved.marker.keys ?? registry?.encrypted?.keys, payload.config.secret)).dataKeys, aadCandidatesFor(payload, {
49
+ ...resolved,
50
+ locale
51
+ }));
52
+ };
53
+ //#endregion
54
+ export { decryptFieldValue, resolveEncryptedField };
55
+
56
+ //# sourceMappingURL=decryptFieldValue.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"decryptFieldValue.js","names":[],"sources":["../../../../src/fields/encrypted/utils/decryptFieldValue.ts"],"sourcesContent":["import type { Payload } from 'payload'\nimport { getFieldsRegistry } from '../../../plugin/registry'\nimport { buildAad } from '../crypto/aad'\nimport { resolveKeys } from '../crypto/keys'\nimport { isSealed, unseal } from '../crypto/wire'\nimport { scanEncryptedFields } from '../scan'\nimport { aadScopeOf, type EncryptedFieldMarker } from '../types'\n\n/** Which document schema an encrypted field lives in: a collection or a global. */\nexport interface EncryptedFieldTarget {\n\tcollection?: string\n\tglobal?: string\n\t/** Dot path of the encrypted field within the schema, e.g. `smtp.password`. */\n\tpath: string\n\t/** Locale of a localized value. Omitted, every configured locale is tried. */\n\tlocale?: string\n}\n\nexport interface DecryptFieldValueArgs extends EncryptedFieldTarget {\n\t/** The raw stored wire string (`pfe1.…`), e.g. cached from `readEncryptedField`. */\n\tvalue: string\n}\n\nexport interface ResolvedEncryptedField {\n\tmarker: EncryptedFieldMarker\n\tslug: string\n}\n\n/** Resolves a target's schema slug and encrypted-field marker, or throws with the reason. */\nexport const resolveEncryptedField = (\n\tpayload: Payload,\n\ttarget: Pick<EncryptedFieldTarget, 'collection' | 'global' | 'path'>\n): ResolvedEncryptedField => {\n\tconst { collection, global, path } = target\n\tif ((collection && global) || (!collection && !global)) {\n\t\tthrow new Error(\n\t\t\t`@10x-media/fields: pass exactly one of 'collection' or 'global' for encrypted field '${path}'`\n\t\t)\n\t}\n\tconst slug = (collection ?? global) as string\n\tconst fields = collection\n\t\t? payload.config.collections.find((entry) => entry.slug === collection)?.fields\n\t\t: payload.config.globals.find((entry) => entry.slug === global)?.fields\n\tif (!fields) {\n\t\tthrow new Error(\n\t\t\t`@10x-media/fields: no ${collection ? 'collection' : 'global'} with slug '${slug}'`\n\t\t)\n\t}\n\tconst marker = scanEncryptedFields(fields).get(path)\n\tif (!marker) {\n\t\tthrow new Error(`@10x-media/fields: '${slug}.${path}' is not an encrypted field`)\n\t}\n\treturn { marker, slug }\n}\n\n/** Read-side AAD candidates for a marker outside a document read (mirrors decryptAllData). */\nexport const aadCandidatesFor = (\n\tpayload: Payload,\n\t{ locale, marker, slug }: ResolvedEncryptedField & { locale?: string }\n): string[] => {\n\tconst scope = aadScopeOf(marker, slug)\n\tif (!marker.localized) {\n\t\treturn [buildAad([scope, marker.fieldName])]\n\t}\n\tconst codes = payload.config.localization ? payload.config.localization.localeCodes : []\n\tconst ordered = locale ? [locale, ...codes.filter((code) => code !== locale)] : codes\n\treturn ordered.map((code) => buildAad([scope, marker.fieldName, code]))\n}\n\n/**\n * Decrypts one stored encrypted value outside a document read, given only its\n * field path and the raw wire string. Keys and AAD resolve from the config, so\n * a ciphertext cached earlier (e.g. via `readEncryptedField().ciphertext`)\n * decrypts on demand without plaintext ever sitting in the cache. A non-sealed\n * value (pre-adoption plaintext at rest) is returned as-is.\n *\n * Server-only and access-unchecked by design: calling it is the deliberate act.\n * Guard call sites accordingly, and never forward the result to a client.\n */\nexport const decryptFieldValue = async (\n\tpayload: Payload,\n\targs: DecryptFieldValueArgs\n): Promise<unknown> => {\n\tconst { locale, value } = args\n\tconst resolved = resolveEncryptedField(payload, args)\n\tif (!isSealed(value)) {\n\t\treturn value\n\t}\n\tconst registry = getFieldsRegistry(payload.config)\n\tconst ring = await resolveKeys(\n\t\tresolved.marker.keys ?? registry?.encrypted?.keys,\n\t\tpayload.config.secret\n\t)\n\treturn unseal(value, ring.dataKeys, aadCandidatesFor(payload, { ...resolved, locale }))\n}\n"],"mappings":";;;;;;;;AA6BA,MAAa,yBACZ,SACA,WAC4B;CAC5B,MAAM,EAAE,YAAY,QAAQ,SAAS;CACrC,IAAK,cAAc,UAAY,CAAC,cAAc,CAAC,QAC9C,MAAM,IAAI,MACT,wFAAwF,KAAK,EAC9F;CAED,MAAM,OAAQ,cAAc;CAC5B,MAAM,SAAS,aACZ,QAAQ,OAAO,YAAY,MAAM,UAAU,MAAM,SAAS,UAAU,GAAG,SACvE,QAAQ,OAAO,QAAQ,MAAM,UAAU,MAAM,SAAS,MAAM,GAAG;CAClE,IAAI,CAAC,QACJ,MAAM,IAAI,MACT,yBAAyB,aAAa,eAAe,SAAS,cAAc,KAAK,EAClF;CAED,MAAM,SAAS,oBAAoB,MAAM,EAAE,IAAI,IAAI;CACnD,IAAI,CAAC,QACJ,MAAM,IAAI,MAAM,uBAAuB,KAAK,GAAG,KAAK,4BAA4B;CAEjF,OAAO;EAAE;EAAQ;CAAK;AACvB;;AAGA,MAAa,oBACZ,SACA,EAAE,QAAQ,QAAQ,WACJ;CACd,MAAM,QAAQ,WAAW,QAAQ,IAAI;CACrC,IAAI,CAAC,OAAO,WACX,OAAO,CAAC,SAAS,CAAC,OAAO,OAAO,SAAS,CAAC,CAAC;CAE5C,MAAM,QAAQ,QAAQ,OAAO,eAAe,QAAQ,OAAO,aAAa,cAAc,CAAC;CAEvF,QADgB,SAAS,CAAC,QAAQ,GAAG,MAAM,QAAQ,SAAS,SAAS,MAAM,CAAC,IAAI,OACjE,KAAK,SAAS,SAAS;EAAC;EAAO,OAAO;EAAW;CAAI,CAAC,CAAC;AACvE;;;;;;;;;;;AAYA,MAAa,oBAAoB,OAChC,SACA,SACsB;CACtB,MAAM,EAAE,QAAQ,UAAU;CAC1B,MAAM,WAAW,sBAAsB,SAAS,IAAI;CACpD,IAAI,CAAC,SAAS,KAAK,GAClB,OAAO;CAER,MAAM,WAAW,kBAAkB,QAAQ,MAAM;CAKjD,OAAO,OAAO,QAAO,MAJF,YAClB,SAAS,OAAO,QAAQ,UAAU,WAAW,MAC7C,QAAQ,OAAO,MAChB,GAC0B,UAAU,iBAAiB,SAAS;EAAE,GAAG;EAAU;CAAO,CAAC,CAAC;AACvF"}
@@ -0,0 +1,51 @@
1
+ import { EncryptedFieldTarget } from "./decryptFieldValue.js";
2
+ import { Payload, PayloadRequest } from "payload";
3
+
4
+ //#region src/fields/encrypted/utils/readEncryptedField.d.ts
5
+ interface ReadEncryptedFieldArgs extends EncryptedFieldTarget {
6
+ /** Document id; required with `collection`, ignored with `global`. */
7
+ id?: number | string;
8
+ /**
9
+ * Request to read on. Given one, the read joins its transaction and sees the
10
+ * caller's uncommitted writes, which is what a secret written and used inside
11
+ * the same operation needs. Omitted, the read runs on its own request and
12
+ * therefore outside any transaction in progress. The request comes back as
13
+ * it went in, except that one with no `context` at all gains an empty one,
14
+ * which the raw window needs to carry its mode.
15
+ */
16
+ req?: PayloadRequest;
17
+ }
18
+ /**
19
+ * A deliberately read encrypted value. `ciphertext` is the raw stored wire
20
+ * string (an array for `hasMany` fields), safe to hold in a cache; `decrypt()`
21
+ * resolves keys at call time, so plaintext exists only for the moment it is
22
+ * used. Rehydrate a persisted ciphertext later via `decryptFieldValue`.
23
+ */
24
+ interface EncryptedFieldHandle {
25
+ ciphertext: string | string[];
26
+ decrypt(): Promise<unknown>;
27
+ }
28
+ /**
29
+ * Fetches one encrypted field's stored ciphertext by path, bypassing the
30
+ * decrypt-on-read pipeline (and the write-only response strip). Returns null
31
+ * when the field holds no value, and throws when the document itself is
32
+ * missing. This is THE supported way to use a `protection: 'writeOnly'` secret
33
+ * server-side:
34
+ *
35
+ * ```ts
36
+ * const secret = await readEncryptedField(payload, { global: 'settings', path: 'smtp.password' })
37
+ * const password = await secret?.decrypt()
38
+ * ```
39
+ *
40
+ * One document per call. To recover a field across many documents, run your own
41
+ * query inside `withRawEncrypted` and pass each stored value to
42
+ * `decryptFieldValue`; that keeps it to a single query and gives you the rest of
43
+ * each document as well.
44
+ *
45
+ * Server-only and access-unchecked by design: calling it is the deliberate
46
+ * act. Guard call sites accordingly, and never forward the result to a client.
47
+ */
48
+ declare const readEncryptedField: (payload: Payload, args: ReadEncryptedFieldArgs) => Promise<EncryptedFieldHandle | null>;
49
+ //#endregion
50
+ export { EncryptedFieldHandle, ReadEncryptedFieldArgs, readEncryptedField };
51
+ //# sourceMappingURL=readEncryptedField.d.ts.map
@@ -0,0 +1,96 @@
1
+ import { ENCRYPTED_CONTEXT_KEY } from "../types.js";
2
+ import { withRawEncrypted } from "../rawRead.js";
3
+ import { getAtPath } from "./pageThrough.js";
4
+ import { decryptFieldValue, resolveEncryptedField } from "./decryptFieldValue.js";
5
+ //#region src/fields/encrypted/utils/readEncryptedField.ts
6
+ /**
7
+ * Which locale this read resolves at. An explicit argument wins, then the
8
+ * request's, since the read joins it.
9
+ *
10
+ * `all` is not a locale but a request for every locale at once, which hands
11
+ * back a `{ [locale]: value }` map where a handle addresses a single value. It
12
+ * falls back to the default locale, which is what this helper reads with no
13
+ * request at all: passing a `req` picks the transaction to read in, never which
14
+ * value comes back.
15
+ */
16
+ const readLocale = (payload, locale, req) => {
17
+ if (locale) return locale;
18
+ if (!req?.locale) return;
19
+ if (req.locale !== "all") return req.locale;
20
+ return payload.config.localization ? payload.config.localization.defaultLocale : void 0;
21
+ };
22
+ /**
23
+ * Fetches one encrypted field's stored ciphertext by path, bypassing the
24
+ * decrypt-on-read pipeline (and the write-only response strip). Returns null
25
+ * when the field holds no value, and throws when the document itself is
26
+ * missing. This is THE supported way to use a `protection: 'writeOnly'` secret
27
+ * server-side:
28
+ *
29
+ * ```ts
30
+ * const secret = await readEncryptedField(payload, { global: 'settings', path: 'smtp.password' })
31
+ * const password = await secret?.decrypt()
32
+ * ```
33
+ *
34
+ * One document per call. To recover a field across many documents, run your own
35
+ * query inside `withRawEncrypted` and pass each stored value to
36
+ * `decryptFieldValue`; that keeps it to a single query and gives you the rest of
37
+ * each document as well.
38
+ *
39
+ * Server-only and access-unchecked by design: calling it is the deliberate
40
+ * act. Guard call sites accordingly, and never forward the result to a client.
41
+ */
42
+ const readEncryptedField = async (payload, args) => {
43
+ const { collection, global, id, locale, path, req } = args;
44
+ resolveEncryptedField(payload, args);
45
+ if (collection && id == null) throw new Error(`@10x-media/fields: readEncryptedField needs an 'id' to read '${collection}.${path}'`);
46
+ const resolvedLocale = readLocale(payload, locale, req);
47
+ const localeArg = resolvedLocale ? { locale: resolvedLocale } : {};
48
+ const modeArg = req ? {} : { context: { [ENCRYPTED_CONTEXT_KEY]: "raw" } };
49
+ const read = () => collection ? payload.findByID({
50
+ collection,
51
+ depth: 0,
52
+ id,
53
+ overrideAccess: true,
54
+ req,
55
+ ...modeArg,
56
+ ...localeArg
57
+ }) : payload.findGlobal({
58
+ depth: 0,
59
+ overrideAccess: true,
60
+ req,
61
+ slug: global,
62
+ ...modeArg,
63
+ ...localeArg
64
+ });
65
+ const value = getAtPath(req ? await withRawEncrypted(req, read) : await read(), path);
66
+ if (value == null) return null;
67
+ const target = {
68
+ collection,
69
+ global,
70
+ locale: resolvedLocale,
71
+ path
72
+ };
73
+ if (Array.isArray(value)) {
74
+ const items = value.filter((item) => typeof item === "string");
75
+ if (items.length === 0) return null;
76
+ return {
77
+ ciphertext: items,
78
+ decrypt: () => Promise.all(items.map((item) => decryptFieldValue(payload, {
79
+ ...target,
80
+ value: item
81
+ })))
82
+ };
83
+ }
84
+ if (typeof value !== "string") throw new Error(`@10x-media/fields: expected a stored wire string at '${collection ?? global}.${path}', got ${typeof value}`);
85
+ return {
86
+ ciphertext: value,
87
+ decrypt: () => decryptFieldValue(payload, {
88
+ ...target,
89
+ value
90
+ })
91
+ };
92
+ };
93
+ //#endregion
94
+ export { readEncryptedField };
95
+
96
+ //# sourceMappingURL=readEncryptedField.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"readEncryptedField.js","names":[],"sources":["../../../../src/fields/encrypted/utils/readEncryptedField.ts"],"sourcesContent":["import type { Payload, PayloadRequest } from 'payload'\nimport { withRawEncrypted } from '../rawRead'\nimport { ENCRYPTED_CONTEXT_KEY } from '../types'\nimport {\n\tdecryptFieldValue,\n\ttype EncryptedFieldTarget,\n\tresolveEncryptedField,\n} from './decryptFieldValue'\nimport { getAtPath } from './pageThrough'\n\nexport interface ReadEncryptedFieldArgs extends EncryptedFieldTarget {\n\t/** Document id; required with `collection`, ignored with `global`. */\n\tid?: number | string\n\t/**\n\t * Request to read on. Given one, the read joins its transaction and sees the\n\t * caller's uncommitted writes, which is what a secret written and used inside\n\t * the same operation needs. Omitted, the read runs on its own request and\n\t * therefore outside any transaction in progress. The request comes back as\n\t * it went in, except that one with no `context` at all gains an empty one,\n\t * which the raw window needs to carry its mode.\n\t */\n\treq?: PayloadRequest\n}\n\n/**\n * A deliberately read encrypted value. `ciphertext` is the raw stored wire\n * string (an array for `hasMany` fields), safe to hold in a cache; `decrypt()`\n * resolves keys at call time, so plaintext exists only for the moment it is\n * used. Rehydrate a persisted ciphertext later via `decryptFieldValue`.\n */\nexport interface EncryptedFieldHandle {\n\tciphertext: string | string[]\n\tdecrypt(): Promise<unknown>\n}\n\n/**\n * Which locale this read resolves at. An explicit argument wins, then the\n * request's, since the read joins it.\n *\n * `all` is not a locale but a request for every locale at once, which hands\n * back a `{ [locale]: value }` map where a handle addresses a single value. It\n * falls back to the default locale, which is what this helper reads with no\n * request at all: passing a `req` picks the transaction to read in, never which\n * value comes back.\n */\nconst readLocale = (\n\tpayload: Payload,\n\tlocale: string | undefined,\n\treq: PayloadRequest | undefined\n): string | undefined => {\n\tif (locale) {\n\t\treturn locale\n\t}\n\tif (!req?.locale) {\n\t\treturn undefined\n\t}\n\tif (req.locale !== 'all') {\n\t\treturn req.locale\n\t}\n\treturn payload.config.localization ? payload.config.localization.defaultLocale : undefined\n}\n\n/**\n * Fetches one encrypted field's stored ciphertext by path, bypassing the\n * decrypt-on-read pipeline (and the write-only response strip). Returns null\n * when the field holds no value, and throws when the document itself is\n * missing. This is THE supported way to use a `protection: 'writeOnly'` secret\n * server-side:\n *\n * ```ts\n * const secret = await readEncryptedField(payload, { global: 'settings', path: 'smtp.password' })\n * const password = await secret?.decrypt()\n * ```\n *\n * One document per call. To recover a field across many documents, run your own\n * query inside `withRawEncrypted` and pass each stored value to\n * `decryptFieldValue`; that keeps it to a single query and gives you the rest of\n * each document as well.\n *\n * Server-only and access-unchecked by design: calling it is the deliberate\n * act. Guard call sites accordingly, and never forward the result to a client.\n */\nexport const readEncryptedField = async (\n\tpayload: Payload,\n\targs: ReadEncryptedFieldArgs\n): Promise<EncryptedFieldHandle | null> => {\n\tconst { collection, global, id, locale, path, req } = args\n\tresolveEncryptedField(payload, args)\n\tif (collection && id == null) {\n\t\tthrow new Error(\n\t\t\t`@10x-media/fields: readEncryptedField needs an 'id' to read '${collection}.${path}'`\n\t\t)\n\t}\n\tconst resolvedLocale = readLocale(payload, locale, req)\n\tconst localeArg = resolvedLocale ? { locale: resolvedLocale as never } : {}\n\t// Without a request there is nothing to restore, so the mode rides on the\n\t// operation and Payload's own throwaway request carries it.\n\tconst modeArg = req ? {} : { context: { [ENCRYPTED_CONTEXT_KEY]: 'raw' } }\n\tconst read = () =>\n\t\tcollection\n\t\t\t? payload.findByID({\n\t\t\t\t\tcollection: collection as never,\n\t\t\t\t\tdepth: 0,\n\t\t\t\t\tid: id as number | string,\n\t\t\t\t\toverrideAccess: true,\n\t\t\t\t\treq,\n\t\t\t\t\t...modeArg,\n\t\t\t\t\t...localeArg,\n\t\t\t\t})\n\t\t\t: payload.findGlobal({\n\t\t\t\t\tdepth: 0,\n\t\t\t\t\toverrideAccess: true,\n\t\t\t\t\treq,\n\t\t\t\t\tslug: global as never,\n\t\t\t\t\t...modeArg,\n\t\t\t\t\t...localeArg,\n\t\t\t\t})\n\tconst doc = req ? await withRawEncrypted(req, read) : await read()\n\tconst value = getAtPath(doc as unknown as Record<string, unknown>, path)\n\tif (value == null) {\n\t\treturn null\n\t}\n\tconst target: EncryptedFieldTarget = { collection, global, locale: resolvedLocale, path }\n\tif (Array.isArray(value)) {\n\t\tconst items = value.filter((item): item is string => typeof item === 'string')\n\t\tif (items.length === 0) {\n\t\t\treturn null\n\t\t}\n\t\treturn {\n\t\t\tciphertext: items,\n\t\t\tdecrypt: () =>\n\t\t\t\tPromise.all(items.map((item) => decryptFieldValue(payload, { ...target, value: item }))),\n\t\t}\n\t}\n\tif (typeof value !== 'string') {\n\t\tthrow new Error(\n\t\t\t`@10x-media/fields: expected a stored wire string at '${(collection ?? global) as string}.${path}', got ${typeof value}`\n\t\t)\n\t}\n\treturn {\n\t\tciphertext: value,\n\t\tdecrypt: () => decryptFieldValue(payload, { ...target, value }),\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;AA6CA,MAAM,cACL,SACA,QACA,QACwB;CACxB,IAAI,QACH,OAAO;CAER,IAAI,CAAC,KAAK,QACT;CAED,IAAI,IAAI,WAAW,OAClB,OAAO,IAAI;CAEZ,OAAO,QAAQ,OAAO,eAAe,QAAQ,OAAO,aAAa,gBAAgB,KAAA;AAClF;;;;;;;;;;;;;;;;;;;;;AAsBA,MAAa,qBAAqB,OACjC,SACA,SAC0C;CAC1C,MAAM,EAAE,YAAY,QAAQ,IAAI,QAAQ,MAAM,QAAQ;CACtD,sBAAsB,SAAS,IAAI;CACnC,IAAI,cAAc,MAAM,MACvB,MAAM,IAAI,MACT,gEAAgE,WAAW,GAAG,KAAK,EACpF;CAED,MAAM,iBAAiB,WAAW,SAAS,QAAQ,GAAG;CACtD,MAAM,YAAY,iBAAiB,EAAE,QAAQ,eAAwB,IAAI,CAAC;CAG1E,MAAM,UAAU,MAAM,CAAC,IAAI,EAAE,SAAS,GAAG,wBAAwB,MAAM,EAAE;CACzE,MAAM,aACL,aACG,QAAQ,SAAS;EACL;EACZ,OAAO;EACH;EACJ,gBAAgB;EAChB;EACA,GAAG;EACH,GAAG;CACJ,CAAC,IACA,QAAQ,WAAW;EACnB,OAAO;EACP,gBAAgB;EAChB;EACA,MAAM;EACN,GAAG;EACH,GAAG;CACJ,CAAC;CAEJ,MAAM,QAAQ,UADF,MAAM,MAAM,iBAAiB,KAAK,IAAI,IAAI,MAAM,KAAK,GACE,IAAI;CACvE,IAAI,SAAS,MACZ,OAAO;CAER,MAAM,SAA+B;EAAE;EAAY;EAAQ,QAAQ;EAAgB;CAAK;CACxF,IAAI,MAAM,QAAQ,KAAK,GAAG;EACzB,MAAM,QAAQ,MAAM,QAAQ,SAAyB,OAAO,SAAS,QAAQ;EAC7E,IAAI,MAAM,WAAW,GACpB,OAAO;EAER,OAAO;GACN,YAAY;GACZ,eACC,QAAQ,IAAI,MAAM,KAAK,SAAS,kBAAkB,SAAS;IAAE,GAAG;IAAQ,OAAO;GAAK,CAAC,CAAC,CAAC;EACzF;CACD;CACA,IAAI,OAAO,UAAU,UACpB,MAAM,IAAI,MACT,wDAAyD,cAAc,OAAkB,GAAG,KAAK,SAAS,OAAO,OAClH;CAED,OAAO;EACN,YAAY;EACZ,eAAe,kBAAkB,SAAS;GAAE,GAAG;GAAQ;EAAM,CAAC;CAC/D;AACD"}