@ddd-ts-kit/audit 0.0.0-stage → 0.1.1

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 (338) hide show
  1. package/README.md +559 -2
  2. package/dist/chain/audit-checkpoint.d.ts +7 -0
  3. package/dist/chain/audit-checkpoint.d.ts.map +1 -0
  4. package/dist/chain/audit-checkpoint.js +2 -0
  5. package/dist/chain/audit-checkpoint.js.map +1 -0
  6. package/dist/chain/canonicalize.d.ts +8 -0
  7. package/dist/chain/canonicalize.d.ts.map +1 -0
  8. package/dist/chain/canonicalize.js +26 -0
  9. package/dist/chain/canonicalize.js.map +1 -0
  10. package/dist/chain/chain-head.d.ts +8 -0
  11. package/dist/chain/chain-head.d.ts.map +1 -0
  12. package/dist/chain/chain-head.js +2 -0
  13. package/dist/chain/chain-head.js.map +1 -0
  14. package/dist/chain/chain-of-tenant.d.ts +9 -0
  15. package/dist/chain/chain-of-tenant.d.ts.map +1 -0
  16. package/dist/chain/chain-of-tenant.js +10 -0
  17. package/dist/chain/chain-of-tenant.js.map +1 -0
  18. package/dist/chain/empty-chain.d.ts +3 -0
  19. package/dist/chain/empty-chain.d.ts.map +1 -0
  20. package/dist/chain/empty-chain.js +5 -0
  21. package/dist/chain/empty-chain.js.map +1 -0
  22. package/dist/chain/genesis-hash.d.ts +3 -0
  23. package/dist/chain/genesis-hash.d.ts.map +1 -0
  24. package/dist/chain/genesis-hash.js +3 -0
  25. package/dist/chain/genesis-hash.js.map +1 -0
  26. package/dist/chain/hash-of.d.ts +5 -0
  27. package/dist/chain/hash-of.d.ts.map +1 -0
  28. package/dist/chain/hash-of.js +8 -0
  29. package/dist/chain/hash-of.js.map +1 -0
  30. package/dist/chain/head-after.d.ts +4 -0
  31. package/dist/chain/head-after.d.ts.map +1 -0
  32. package/dist/chain/head-after.js +4 -0
  33. package/dist/chain/head-after.js.map +1 -0
  34. package/dist/chain/seal-checkpoint.d.ts +4 -0
  35. package/dist/chain/seal-checkpoint.d.ts.map +1 -0
  36. package/dist/chain/seal-checkpoint.js +7 -0
  37. package/dist/chain/seal-checkpoint.js.map +1 -0
  38. package/dist/chain/seal.d.ts +5 -0
  39. package/dist/chain/seal.d.ts.map +1 -0
  40. package/dist/chain/seal.js +13 -0
  41. package/dist/chain/seal.js.map +1 -0
  42. package/dist/chain/sealing-options.d.ts +12 -0
  43. package/dist/chain/sealing-options.d.ts.map +1 -0
  44. package/dist/chain/sealing-options.js +2 -0
  45. package/dist/chain/sealing-options.js.map +1 -0
  46. package/dist/drizzle/audit-chains-table.d.ts +61 -0
  47. package/dist/drizzle/audit-chains-table.d.ts.map +1 -0
  48. package/dist/drizzle/audit-chains-table.js +12 -0
  49. package/dist/drizzle/audit-chains-table.js.map +1 -0
  50. package/dist/drizzle/audit-entries-table.d.ts +424 -0
  51. package/dist/drizzle/audit-entries-table.d.ts.map +1 -0
  52. package/dist/drizzle/audit-entries-table.js +44 -0
  53. package/dist/drizzle/audit-entries-table.js.map +1 -0
  54. package/dist/drizzle/audit-guard-statements.d.ts +7 -0
  55. package/dist/drizzle/audit-guard-statements.d.ts.map +1 -0
  56. package/dist/drizzle/audit-guard-statements.js +10 -0
  57. package/dist/drizzle/audit-guard-statements.js.map +1 -0
  58. package/dist/drizzle/drizzle-audit-context.d.ts +7 -0
  59. package/dist/drizzle/drizzle-audit-context.d.ts.map +1 -0
  60. package/dist/drizzle/drizzle-audit-context.js +2 -0
  61. package/dist/drizzle/drizzle-audit-context.js.map +1 -0
  62. package/dist/drizzle/drizzle-audit-trail.d.ts +17 -0
  63. package/dist/drizzle/drizzle-audit-trail.d.ts.map +1 -0
  64. package/dist/drizzle/drizzle-audit-trail.js +28 -0
  65. package/dist/drizzle/drizzle-audit-trail.js.map +1 -0
  66. package/dist/drizzle/table-in.d.ts +4 -0
  67. package/dist/drizzle/table-in.d.ts.map +1 -0
  68. package/dist/drizzle/table-in.js +6 -0
  69. package/dist/drizzle/table-in.js.map +1 -0
  70. package/dist/drizzle.d.ts +6 -0
  71. package/dist/drizzle.d.ts.map +1 -0
  72. package/dist/drizzle.js +5 -0
  73. package/dist/drizzle.js.map +1 -0
  74. package/dist/index.d.ts +36 -0
  75. package/dist/index.d.ts.map +1 -0
  76. package/dist/index.js +18 -0
  77. package/dist/index.js.map +1 -0
  78. package/dist/knex/create-audit-tables.d.ts +9 -0
  79. package/dist/knex/create-audit-tables.d.ts.map +1 -0
  80. package/dist/knex/create-audit-tables.js +12 -0
  81. package/dist/knex/create-audit-tables.js.map +1 -0
  82. package/dist/knex/drop-audit-tables.d.ts +5 -0
  83. package/dist/knex/drop-audit-tables.d.ts.map +1 -0
  84. package/dist/knex/drop-audit-tables.js +8 -0
  85. package/dist/knex/drop-audit-tables.js.map +1 -0
  86. package/dist/knex/knex-audit-context.d.ts +6 -0
  87. package/dist/knex/knex-audit-context.d.ts.map +1 -0
  88. package/dist/knex/knex-audit-context.js +2 -0
  89. package/dist/knex/knex-audit-context.js.map +1 -0
  90. package/dist/knex/knex-audit-trail.d.ts +14 -0
  91. package/dist/knex/knex-audit-trail.d.ts.map +1 -0
  92. package/dist/knex/knex-audit-trail.js +22 -0
  93. package/dist/knex/knex-audit-trail.js.map +1 -0
  94. package/dist/knex.d.ts +6 -0
  95. package/dist/knex.d.ts.map +1 -0
  96. package/dist/knex.js +4 -0
  97. package/dist/knex.js.map +1 -0
  98. package/dist/redaction/audit-masker.d.ts +8 -0
  99. package/dist/redaction/audit-masker.d.ts.map +1 -0
  100. package/dist/redaction/audit-masker.js +5 -0
  101. package/dist/redaction/audit-masker.js.map +1 -0
  102. package/dist/redaction/audit-projection.d.ts +13 -0
  103. package/dist/redaction/audit-projection.d.ts.map +1 -0
  104. package/dist/redaction/audit-projection.js +2 -0
  105. package/dist/redaction/audit-projection.js.map +1 -0
  106. package/dist/redaction/audited-field.d.ts +3 -0
  107. package/dist/redaction/audited-field.d.ts.map +1 -0
  108. package/dist/redaction/audited-field.js +2 -0
  109. package/dist/redaction/audited-field.js.map +1 -0
  110. package/dist/redaction/audited-fields.d.ts +16 -0
  111. package/dist/redaction/audited-fields.d.ts.map +1 -0
  112. package/dist/redaction/audited-fields.js +24 -0
  113. package/dist/redaction/audited-fields.js.map +1 -0
  114. package/dist/redaction/audited-message.d.ts +9 -0
  115. package/dist/redaction/audited-message.d.ts.map +1 -0
  116. package/dist/redaction/audited-message.js +2 -0
  117. package/dist/redaction/audited-message.js.map +1 -0
  118. package/dist/redaction/audited-projection.d.ts +10 -0
  119. package/dist/redaction/audited-projection.d.ts.map +1 -0
  120. package/dist/redaction/audited-projection.js +9 -0
  121. package/dist/redaction/audited-projection.js.map +1 -0
  122. package/dist/redaction/changes-of.d.ts +11 -0
  123. package/dist/redaction/changes-of.d.ts.map +1 -0
  124. package/dist/redaction/changes-of.js +37 -0
  125. package/dist/redaction/changes-of.js.map +1 -0
  126. package/dist/redaction/hmac-masker.d.ts +12 -0
  127. package/dist/redaction/hmac-masker.d.ts.map +1 -0
  128. package/dist/redaction/hmac-masker.js +14 -0
  129. package/dist/redaction/hmac-masker.js.map +1 -0
  130. package/dist/redaction/masked-field.d.ts +6 -0
  131. package/dist/redaction/masked-field.d.ts.map +1 -0
  132. package/dist/redaction/masked-field.js +2 -0
  133. package/dist/redaction/masked-field.js.map +1 -0
  134. package/dist/redaction/masked.d.ts +3 -0
  135. package/dist/redaction/masked.d.ts.map +1 -0
  136. package/dist/redaction/masked.js +4 -0
  137. package/dist/redaction/masked.js.map +1 -0
  138. package/dist/redaction/masking-subject.d.ts +9 -0
  139. package/dist/redaction/masking-subject.d.ts.map +1 -0
  140. package/dist/redaction/masking-subject.js +2 -0
  141. package/dist/redaction/masking-subject.js.map +1 -0
  142. package/dist/redaction/missing-masker-error.d.ts +5 -0
  143. package/dist/redaction/missing-masker-error.d.ts.map +1 -0
  144. package/dist/redaction/missing-masker-error.js +8 -0
  145. package/dist/redaction/missing-masker-error.js.map +1 -0
  146. package/dist/search/comparing.d.ts +8 -0
  147. package/dist/search/comparing.d.ts.map +1 -0
  148. package/dist/search/comparing.js +23 -0
  149. package/dist/search/comparing.js.map +1 -0
  150. package/dist/search/cursor-position.d.ts +7 -0
  151. package/dist/search/cursor-position.d.ts.map +1 -0
  152. package/dist/search/cursor-position.js +2 -0
  153. package/dist/search/cursor-position.js.map +1 -0
  154. package/dist/search/decode-cursor.d.ts +3 -0
  155. package/dist/search/decode-cursor.d.ts.map +1 -0
  156. package/dist/search/decode-cursor.js +21 -0
  157. package/dist/search/decode-cursor.js.map +1 -0
  158. package/dist/search/encode-cursor.d.ts +3 -0
  159. package/dist/search/encode-cursor.d.ts.map +1 -0
  160. package/dist/search/encode-cursor.js +5 -0
  161. package/dist/search/encode-cursor.js.map +1 -0
  162. package/dist/search/matches.d.ts +5 -0
  163. package/dist/search/matches.d.ts.map +1 -0
  164. package/dist/search/matches.js +34 -0
  165. package/dist/search/matches.js.map +1 -0
  166. package/dist/search/order-of.d.ts +4 -0
  167. package/dist/search/order-of.d.ts.map +1 -0
  168. package/dist/search/order-of.js +5 -0
  169. package/dist/search/order-of.js.map +1 -0
  170. package/dist/search/search-order.d.ts +6 -0
  171. package/dist/search/search-order.d.ts.map +1 -0
  172. package/dist/search/search-order.js +2 -0
  173. package/dist/search/search-order.js.map +1 -0
  174. package/dist/sources/allowed-reads.d.ts +9 -0
  175. package/dist/sources/allowed-reads.d.ts.map +1 -0
  176. package/dist/sources/allowed-reads.js +2 -0
  177. package/dist/sources/allowed-reads.js.map +1 -0
  178. package/dist/sources/audit-decisions.d.ts +19 -0
  179. package/dist/sources/audit-decisions.d.ts.map +1 -0
  180. package/dist/sources/audit-decisions.js +48 -0
  181. package/dist/sources/audit-decisions.js.map +1 -0
  182. package/dist/sources/audit-fact.d.ts +4 -0
  183. package/dist/sources/audit-fact.d.ts.map +1 -0
  184. package/dist/sources/audit-fact.js +2 -0
  185. package/dist/sources/audit-fact.js.map +1 -0
  186. package/dist/sources/audit-integration-events.d.ts +23 -0
  187. package/dist/sources/audit-integration-events.d.ts.map +1 -0
  188. package/dist/sources/audit-integration-events.js +59 -0
  189. package/dist/sources/audit-integration-events.js.map +1 -0
  190. package/dist/sources/audit-middleware.d.ts +33 -0
  191. package/dist/sources/audit-middleware.d.ts.map +1 -0
  192. package/dist/sources/audit-middleware.js +113 -0
  193. package/dist/sources/audit-middleware.js.map +1 -0
  194. package/dist/sources/audit-record-of.d.ts +10 -0
  195. package/dist/sources/audit-record-of.d.ts.map +1 -0
  196. package/dist/sources/audit-record-of.js +10 -0
  197. package/dist/sources/audit-record-of.js.map +1 -0
  198. package/dist/sources/audit-source.d.ts +8 -0
  199. package/dist/sources/audit-source.d.ts.map +1 -0
  200. package/dist/sources/audit-source.js +2 -0
  201. package/dist/sources/audit-source.js.map +1 -0
  202. package/dist/sources/audit-subscription.d.ts +7 -0
  203. package/dist/sources/audit-subscription.d.ts.map +1 -0
  204. package/dist/sources/audit-subscription.js +2 -0
  205. package/dist/sources/audit-subscription.js.map +1 -0
  206. package/dist/sources/audited-events.d.ts +7 -0
  207. package/dist/sources/audited-events.d.ts.map +1 -0
  208. package/dist/sources/audited-events.js +2 -0
  209. package/dist/sources/audited-events.js.map +1 -0
  210. package/dist/sources/authorization-decision.d.ts +21 -0
  211. package/dist/sources/authorization-decision.d.ts.map +1 -0
  212. package/dist/sources/authorization-decision.js +2 -0
  213. package/dist/sources/authorization-decision.js.map +1 -0
  214. package/dist/sources/record-in.d.ts +5 -0
  215. package/dist/sources/record-in.d.ts.map +1 -0
  216. package/dist/sources/record-in.js +19 -0
  217. package/dist/sources/record-in.js.map +1 -0
  218. package/dist/sql/audit-chains-table-name.d.ts +2 -0
  219. package/dist/sql/audit-chains-table-name.d.ts.map +1 -0
  220. package/dist/sql/audit-chains-table-name.js +2 -0
  221. package/dist/sql/audit-chains-table-name.js.map +1 -0
  222. package/dist/sql/audit-entries-table-name.d.ts +2 -0
  223. package/dist/sql/audit-entries-table-name.d.ts.map +1 -0
  224. package/dist/sql/audit-entries-table-name.js +2 -0
  225. package/dist/sql/audit-entries-table-name.js.map +1 -0
  226. package/dist/sql/audit-guard-sql.d.ts +8 -0
  227. package/dist/sql/audit-guard-sql.d.ts.map +1 -0
  228. package/dist/sql/audit-guard-sql.js +17 -0
  229. package/dist/sql/audit-guard-sql.js.map +1 -0
  230. package/dist/sql/audit-tables-options.d.ts +5 -0
  231. package/dist/sql/audit-tables-options.d.ts.map +1 -0
  232. package/dist/sql/audit-tables-options.js +2 -0
  233. package/dist/sql/audit-tables-options.js.map +1 -0
  234. package/dist/sql/audit-tables-sql.d.ts +7 -0
  235. package/dist/sql/audit-tables-sql.d.ts.map +1 -0
  236. package/dist/sql/audit-tables-sql.js +48 -0
  237. package/dist/sql/audit-tables-sql.js.map +1 -0
  238. package/dist/sql/audit-tables.d.ts +8 -0
  239. package/dist/sql/audit-tables.d.ts.map +1 -0
  240. package/dist/sql/audit-tables.js +7 -0
  241. package/dist/sql/audit-tables.js.map +1 -0
  242. package/dist/sql/drop-audit-tables-sql.d.ts +4 -0
  243. package/dist/sql/drop-audit-tables-sql.d.ts.map +1 -0
  244. package/dist/sql/drop-audit-tables-sql.js +12 -0
  245. package/dist/sql/drop-audit-tables-sql.js.map +1 -0
  246. package/dist/sql/entry-of.d.ts +5 -0
  247. package/dist/sql/entry-of.d.ts.map +1 -0
  248. package/dist/sql/entry-of.js +109 -0
  249. package/dist/sql/entry-of.js.map +1 -0
  250. package/dist/sql/insert-of.d.ts +4 -0
  251. package/dist/sql/insert-of.d.ts.map +1 -0
  252. package/dist/sql/insert-of.js +51 -0
  253. package/dist/sql/insert-of.js.map +1 -0
  254. package/dist/sql/named.d.ts +3 -0
  255. package/dist/sql/named.d.ts.map +1 -0
  256. package/dist/sql/named.js +6 -0
  257. package/dist/sql/named.js.map +1 -0
  258. package/dist/sql/postgres-audit-trail.d.ts +25 -0
  259. package/dist/sql/postgres-audit-trail.d.ts.map +1 -0
  260. package/dist/sql/postgres-audit-trail.js +111 -0
  261. package/dist/sql/postgres-audit-trail.js.map +1 -0
  262. package/dist/sql/qualified.d.ts +3 -0
  263. package/dist/sql/qualified.d.ts.map +1 -0
  264. package/dist/sql/qualified.js +5 -0
  265. package/dist/sql/qualified.js.map +1 -0
  266. package/dist/sql/rows-of.d.ts +4 -0
  267. package/dist/sql/rows-of.d.ts.map +1 -0
  268. package/dist/sql/rows-of.js +14 -0
  269. package/dist/sql/rows-of.js.map +1 -0
  270. package/dist/sql/sql-row.d.ts +2 -0
  271. package/dist/sql/sql-row.d.ts.map +1 -0
  272. package/dist/sql/sql-row.js +2 -0
  273. package/dist/sql/sql-row.js.map +1 -0
  274. package/dist/sql/sql-session.d.ts +9 -0
  275. package/dist/sql/sql-session.d.ts.map +1 -0
  276. package/dist/sql/sql-session.js +2 -0
  277. package/dist/sql/sql-session.js.map +1 -0
  278. package/dist/sql/sql.d.ts +12 -0
  279. package/dist/sql/sql.d.ts.map +1 -0
  280. package/dist/sql/sql.js +35 -0
  281. package/dist/sql/sql.js.map +1 -0
  282. package/dist/testing/audit-trail-contract.d.ts +16 -0
  283. package/dist/testing/audit-trail-contract.d.ts.map +1 -0
  284. package/dist/testing/audit-trail-contract.js +208 -0
  285. package/dist/testing/audit-trail-contract.js.map +1 -0
  286. package/dist/testing/audit-trail-under-contract.d.ts +4 -0
  287. package/dist/testing/audit-trail-under-contract.d.ts.map +1 -0
  288. package/dist/testing/audit-trail-under-contract.js +2 -0
  289. package/dist/testing/audit-trail-under-contract.js.map +1 -0
  290. package/dist/testing/records/a-record.d.ts +3 -0
  291. package/dist/testing/records/a-record.d.ts.map +1 -0
  292. package/dist/testing/records/a-record.js +14 -0
  293. package/dist/testing/records/a-record.js.map +1 -0
  294. package/dist/testing/records/full-record.d.ts +3 -0
  295. package/dist/testing/records/full-record.d.ts.map +1 -0
  296. package/dist/testing/records/full-record.js +16 -0
  297. package/dist/testing/records/full-record.js.map +1 -0
  298. package/dist/testing/records/in-tenant.d.ts +3 -0
  299. package/dist/testing/records/in-tenant.d.ts.map +1 -0
  300. package/dist/testing/records/in-tenant.js +5 -0
  301. package/dist/testing/records/in-tenant.js.map +1 -0
  302. package/dist/testing/records/journal.d.ts +4 -0
  303. package/dist/testing/records/journal.d.ts.map +1 -0
  304. package/dist/testing/records/journal.js +32 -0
  305. package/dist/testing/records/journal.js.map +1 -0
  306. package/dist/testing/records/later.d.ts +4 -0
  307. package/dist/testing/records/later.d.ts.map +1 -0
  308. package/dist/testing/records/later.js +6 -0
  309. package/dist/testing/records/later.js.map +1 -0
  310. package/dist/testing.d.ts +3 -0
  311. package/dist/testing.d.ts.map +1 -0
  312. package/dist/testing.js +2 -0
  313. package/dist/testing.js.map +1 -0
  314. package/dist/trail/audit-trail-options.d.ts +8 -0
  315. package/dist/trail/audit-trail-options.d.ts.map +1 -0
  316. package/dist/trail/audit-trail-options.js +2 -0
  317. package/dist/trail/audit-trail-options.js.map +1 -0
  318. package/dist/trail/in-memory-audit-trail.d.ts +16 -0
  319. package/dist/trail/in-memory-audit-trail.d.ts.map +1 -0
  320. package/dist/trail/in-memory-audit-trail.js +48 -0
  321. package/dist/trail/in-memory-audit-trail.js.map +1 -0
  322. package/dist/verify/chain-break-kind.d.ts +8 -0
  323. package/dist/verify/chain-break-kind.d.ts.map +1 -0
  324. package/dist/verify/chain-break-kind.js +2 -0
  325. package/dist/verify/chain-break-kind.js.map +1 -0
  326. package/dist/verify/chain-break.d.ts +12 -0
  327. package/dist/verify/chain-break.d.ts.map +1 -0
  328. package/dist/verify/chain-break.js +2 -0
  329. package/dist/verify/chain-break.js.map +1 -0
  330. package/dist/verify/chain-verification.d.ts +10 -0
  331. package/dist/verify/chain-verification.d.ts.map +1 -0
  332. package/dist/verify/chain-verification.js +2 -0
  333. package/dist/verify/chain-verification.js.map +1 -0
  334. package/dist/verify/verify-chain.d.ts +20 -0
  335. package/dist/verify/verify-chain.d.ts.map +1 -0
  336. package/dist/verify/verify-chain.js +110 -0
  337. package/dist/verify/verify-chain.js.map +1 -0
  338. package/package.json +70 -4
@@ -0,0 +1,23 @@
1
+ /**
2
+ * The comparison of an order, between two entries or between an entry and the position a
3
+ * cursor names: negative when `left` comes first in that order.
4
+ */
5
+ export function comparing(order) {
6
+ const sign = order.direction === 'asc' ? 1 : -1;
7
+ return (left, right) => sign * compareKeys(sortKeyOf(left, order.field), sortKeyOf(right, order.field));
8
+ }
9
+ function sortKeyOf(position, field) {
10
+ const inChain = [position.chain, position.sequence];
11
+ return field === 'occurredAt' ? [position.occurredAt.getTime(), ...inChain] : inChain;
12
+ }
13
+ function compareKeys(left, right) {
14
+ for (const [index, value] of left.entries()) {
15
+ const other = right[index];
16
+ if (other === undefined || value === other) {
17
+ continue;
18
+ }
19
+ return value < other ? -1 : 1;
20
+ }
21
+ return 0;
22
+ }
23
+ //# sourceMappingURL=comparing.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"comparing.js","sourceRoot":"","sources":["../../src/search/comparing.ts"],"names":[],"mappings":"AAMA;;;GAGG;AACH,MAAM,UAAU,SAAS,CAAC,KAAkB;IAC1C,MAAM,IAAI,GAAG,KAAK,CAAC,SAAS,KAAK,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IAEhD,OAAO,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC,IAAI,GAAG,WAAW,CAAC,SAAS,CAAC,IAAI,EAAE,KAAK,CAAC,KAAK,CAAC,EAAE,SAAS,CAAC,KAAK,EAAE,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC;AAC1G,CAAC;AAED,SAAS,SAAS,CAAC,QAAwB,EAAE,KAAqB;IAChE,MAAM,OAAO,GAAG,CAAC,QAAQ,CAAC,KAAK,EAAE,QAAQ,CAAC,QAAQ,CAAC,CAAC;IAEpD,OAAO,KAAK,KAAK,YAAY,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,UAAU,CAAC,OAAO,EAAE,EAAE,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC;AACxF,CAAC;AAED,SAAS,WAAW,CAAC,IAAa,EAAE,KAAc;IAChD,KAAK,MAAM,CAAC,KAAK,EAAE,KAAK,CAAC,IAAI,IAAI,CAAC,OAAO,EAAE,EAAE,CAAC;QAC5C,MAAM,KAAK,GAAG,KAAK,CAAC,KAAK,CAAC,CAAC;QAE3B,IAAI,KAAK,KAAK,SAAS,IAAI,KAAK,KAAK,KAAK,EAAE,CAAC;YAC3C,SAAS;QACX,CAAC;QAED,OAAO,KAAK,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IAChC,CAAC;IAED,OAAO,CAAC,CAAC;AACX,CAAC"}
@@ -0,0 +1,7 @@
1
+ /** Where a page ended: enough to resume in either order, whatever the store. */
2
+ export interface CursorPosition {
3
+ readonly occurredAt: Date;
4
+ readonly chain: string;
5
+ readonly sequence: number;
6
+ }
7
+ //# sourceMappingURL=cursor-position.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cursor-position.d.ts","sourceRoot":"","sources":["../../src/search/cursor-position.ts"],"names":[],"mappings":"AAAA,gFAAgF;AAChF,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,UAAU,EAAE,IAAI,CAAC;IAC1B,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;CAC3B"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=cursor-position.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cursor-position.js","sourceRoot":"","sources":["../../src/search/cursor-position.ts"],"names":[],"mappings":""}
@@ -0,0 +1,3 @@
1
+ import type { CursorPosition } from './cursor-position.js';
2
+ export declare function decodeCursor(cursor: string): CursorPosition;
3
+ //# sourceMappingURL=decode-cursor.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"decode-cursor.d.ts","sourceRoot":"","sources":["../../src/search/decode-cursor.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAE3D,wBAAgB,YAAY,CAAC,MAAM,EAAE,MAAM,GAAG,cAAc,CAQ3D"}
@@ -0,0 +1,21 @@
1
+ import { InvalidPageRequestError } from '@ddd-ts-kit/kernel';
2
+ export function decodeCursor(cursor) {
3
+ const [occurredAt, chain, sequence] = parsed(Buffer.from(cursor, 'base64url').toString('utf8'));
4
+ if (typeof occurredAt !== 'string' || typeof chain !== 'string' || typeof sequence !== 'number') {
5
+ throw new InvalidPageRequestError('The cursor of a page is not one this list gave');
6
+ }
7
+ return { occurredAt: new Date(occurredAt), chain, sequence };
8
+ }
9
+ function parsed(text) {
10
+ try {
11
+ const value = JSON.parse(text);
12
+ return isList(value) ? value : [];
13
+ }
14
+ catch {
15
+ return [];
16
+ }
17
+ }
18
+ function isList(value) {
19
+ return Array.isArray(value);
20
+ }
21
+ //# sourceMappingURL=decode-cursor.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"decode-cursor.js","sourceRoot":"","sources":["../../src/search/decode-cursor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uBAAuB,EAAE,MAAM,oBAAoB,CAAC;AAG7D,MAAM,UAAU,YAAY,CAAC,MAAc;IACzC,MAAM,CAAC,UAAU,EAAE,KAAK,EAAE,QAAQ,CAAC,GAAG,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC;IAEhG,IAAI,OAAO,UAAU,KAAK,QAAQ,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,OAAO,QAAQ,KAAK,QAAQ,EAAE,CAAC;QAChG,MAAM,IAAI,uBAAuB,CAAC,gDAAgD,CAAC,CAAC;IACtF,CAAC;IAED,OAAO,EAAE,UAAU,EAAE,IAAI,IAAI,CAAC,UAAU,CAAC,EAAE,KAAK,EAAE,QAAQ,EAAE,CAAC;AAC/D,CAAC;AAED,SAAS,MAAM,CAAC,IAAY;IAC1B,IAAI,CAAC;QACH,MAAM,KAAK,GAAY,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QAExC,OAAO,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC;IACpC,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,EAAE,CAAC;IACZ,CAAC;AACH,CAAC;AAED,SAAS,MAAM,CAAC,KAAc;IAC5B,OAAO,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;AAC9B,CAAC"}
@@ -0,0 +1,3 @@
1
+ import type { CursorPosition } from './cursor-position.js';
2
+ export declare function encodeCursor(last: CursorPosition): string;
3
+ //# sourceMappingURL=encode-cursor.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"encode-cursor.d.ts","sourceRoot":"","sources":["../../src/search/encode-cursor.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAE3D,wBAAgB,YAAY,CAAC,IAAI,EAAE,cAAc,GAAG,MAAM,CAIzD"}
@@ -0,0 +1,5 @@
1
+ export function encodeCursor(last) {
2
+ const position = [last.occurredAt.toISOString(), last.chain, last.sequence];
3
+ return Buffer.from(JSON.stringify(position), 'utf8').toString('base64url');
4
+ }
5
+ //# sourceMappingURL=encode-cursor.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"encode-cursor.js","sourceRoot":"","sources":["../../src/search/encode-cursor.ts"],"names":[],"mappings":"AAEA,MAAM,UAAU,YAAY,CAAC,IAAoB;IAC/C,MAAM,QAAQ,GAAG,CAAC,IAAI,CAAC,UAAU,CAAC,WAAW,EAAE,EAAE,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC;IAE5E,OAAO,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAC;AAC7E,CAAC"}
@@ -0,0 +1,5 @@
1
+ import type { AuditEntry, AuditFilter } from '@ddd-ts-kit/kernel';
2
+ type EntryTest = (entry: AuditEntry) => boolean;
3
+ export declare function matches(filter: AuditFilter): EntryTest;
4
+ export {};
5
+ //# sourceMappingURL=matches.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"matches.d.ts","sourceRoot":"","sources":["../../src/search/matches.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAElE,KAAK,SAAS,GAAG,CAAC,KAAK,EAAE,UAAU,KAAK,OAAO,CAAC;AAEhD,wBAAgB,OAAO,CAAC,MAAM,EAAE,WAAW,GAAG,SAAS,CAItD"}
@@ -0,0 +1,34 @@
1
+ export function matches(filter) {
2
+ const tests = [...identityTests(filter), ...resourceTests(filter), ...rangeTests(filter)];
3
+ return (entry) => tests.every((test) => test(entry));
4
+ }
5
+ function identityTests(filter) {
6
+ const expected = [
7
+ [filter.chain, (entry) => entry.chain],
8
+ [filter.tenantId, (entry) => entry.tenantId],
9
+ [filter.actorId, (entry) => entry.actor.id],
10
+ [filter.action, (entry) => entry.action],
11
+ [filter.category, (entry) => entry.category],
12
+ [filter.outcome, (entry) => entry.outcome],
13
+ [filter.correlationId, (entry) => entry.correlationId],
14
+ ];
15
+ return expected.flatMap(([value, read]) => value === undefined ? [] : [(entry) => read(entry) === value]);
16
+ }
17
+ function resourceTests({ resource }) {
18
+ if (resource === undefined) {
19
+ return [];
20
+ }
21
+ return [
22
+ (entry) => entry.resource?.type === resource.type && (resource.id === undefined || entry.resource.id === resource.id),
23
+ ];
24
+ }
25
+ function rangeTests(filter) {
26
+ const { from, to, fromSequence, toSequence } = filter;
27
+ return [
28
+ ...(from === undefined ? [] : [(entry) => entry.occurredAt.getTime() >= from.getTime()]),
29
+ ...(to === undefined ? [] : [(entry) => entry.occurredAt.getTime() < to.getTime()]),
30
+ ...(fromSequence === undefined ? [] : [(entry) => entry.sequence >= fromSequence]),
31
+ ...(toSequence === undefined ? [] : [(entry) => entry.sequence <= toSequence]),
32
+ ];
33
+ }
34
+ //# sourceMappingURL=matches.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"matches.js","sourceRoot":"","sources":["../../src/search/matches.ts"],"names":[],"mappings":"AAIA,MAAM,UAAU,OAAO,CAAC,MAAmB;IACzC,MAAM,KAAK,GAAG,CAAC,GAAG,aAAa,CAAC,MAAM,CAAC,EAAE,GAAG,aAAa,CAAC,MAAM,CAAC,EAAE,GAAG,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC;IAE1F,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC;AACvD,CAAC;AAED,SAAS,aAAa,CAAC,MAAmB;IACxC,MAAM,QAAQ,GAA0F;QACtG,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC;QACtC,CAAC,MAAM,CAAC,QAAQ,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,QAAQ,CAAC;QAC5C,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE,CAAC;QAC3C,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,MAAM,CAAC;QACxC,CAAC,MAAM,CAAC,QAAQ,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,QAAQ,CAAC;QAC5C,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC;QAC1C,CAAC,MAAM,CAAC,aAAa,EAAE,CAAC,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AC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,KAAiB,EAAE,EAAE,CAAC,KAAK,CAAC,QAAQ,IAAI,YAAY,CAAC,CAAC;QAC9F,GAAG,CAAC,UAAU,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,KAAiB,EAAE,EAAE,CAAC,KAAK,CAAC,QAAQ,IAAI,UAAU,CAAC,CAAC;KAC3F,CAAC;AACJ,CAAC"}
@@ -0,0 +1,4 @@
1
+ import type { AuditSortField, PageRequest } from '@ddd-ts-kit/kernel';
2
+ import type { SearchOrder } from './search-order.js';
3
+ export declare function orderOf(page: PageRequest<AuditSortField>): SearchOrder;
4
+ //# sourceMappingURL=order-of.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"order-of.d.ts","sourceRoot":"","sources":["../../src/search/order-of.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACtE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAErD,wBAAgB,OAAO,CAAC,IAAI,EAAE,WAAW,CAAC,cAAc,CAAC,GAAG,WAAW,CAItE"}
@@ -0,0 +1,5 @@
1
+ export function orderOf(page) {
2
+ const [first] = page.sort;
3
+ return { field: first?.field ?? 'occurredAt', direction: first?.direction ?? 'asc' };
4
+ }
5
+ //# sourceMappingURL=order-of.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"order-of.js","sourceRoot":"","sources":["../../src/search/order-of.ts"],"names":[],"mappings":"AAGA,MAAM,UAAU,OAAO,CAAC,IAAiC;IACvD,MAAM,CAAC,KAAK,CAAC,GAAG,IAAI,CAAC,IAAI,CAAC;IAE1B,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,IAAI,YAAY,EAAE,SAAS,EAAE,KAAK,EAAE,SAAS,IAAI,KAAK,EAAE,CAAC;AACvF,CAAC"}
@@ -0,0 +1,6 @@
1
+ import type { AuditSortField, SortDirection } from '@ddd-ts-kit/kernel';
2
+ export interface SearchOrder {
3
+ readonly field: AuditSortField;
4
+ readonly direction: SortDirection;
5
+ }
6
+ //# sourceMappingURL=search-order.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"search-order.d.ts","sourceRoot":"","sources":["../../src/search/search-order.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAExE,MAAM,WAAW,WAAW;IAC1B,QAAQ,CAAC,KAAK,EAAE,cAAc,CAAC;IAC/B,QAAQ,CAAC,SAAS,EAAE,aAAa,CAAC;CACnC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=search-order.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"search-order.js","sourceRoot":"","sources":["../../src/search/search-order.ts"],"names":[],"mappings":""}
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Which allowed decisions about reads are recorded, next to those of sensitive permissions:
3
+ * none (`sensitive`), every one (`all`), or a share of them between 0 and 1.
4
+ */
5
+ export type AllowedReads = 'sensitive' | 'all' | {
6
+ readonly sample: number;
7
+ readonly random?: () => number;
8
+ };
9
+ //# sourceMappingURL=allowed-reads.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"allowed-reads.d.ts","sourceRoot":"","sources":["../../src/sources/allowed-reads.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,MAAM,YAAY,GAAG,WAAW,GAAG,KAAK,GAAG;IAAE,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,MAAM,CAAA;CAAE,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=allowed-reads.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"allowed-reads.js","sourceRoot":"","sources":["../../src/sources/allowed-reads.ts"],"names":[],"mappings":""}
@@ -0,0 +1,19 @@
1
+ import type { AuditTrail } from '@ddd-ts-kit/kernel';
2
+ import type { AllowedReads } from './allowed-reads.js';
3
+ import type { AuditSource } from './audit-source.js';
4
+ import type { AuthorizationDecision } from './authorization-decision.js';
5
+ export interface AuditDecisionsOptions extends AuditSource {
6
+ /** Says that a decision concerns a read. Default: its `kind` is `query`, as the bus that carried it says. */
7
+ readonly isRead?: (decision: AuthorizationDecision) => boolean;
8
+ /** Ids of the permissions whose allowed reads are always recorded. */
9
+ readonly sensitivePermissions?: readonly string[];
10
+ /** Default `sensitive`. */
11
+ readonly allowedReads?: AllowedReads;
12
+ }
13
+ /**
14
+ * The `onDecision` hook of the authorization middleware. A refusal is always recorded, and so
15
+ * is an allowed decision about anything that is not a read. An allowed read is recorded when
16
+ * its permission is sensitive: recording every list and every page view drowns the trail.
17
+ */
18
+ export declare function auditDecisions(trail: AuditTrail, options: AuditDecisionsOptions): (decision: AuthorizationDecision) => Promise<void>;
19
+ //# sourceMappingURL=audit-decisions.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"audit-decisions.d.ts","sourceRoot":"","sources":["../../src/sources/audit-decisions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAEvD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AACrD,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,6BAA6B,CAAC;AAEzE,MAAM,WAAW,qBAAsB,SAAQ,WAAW;IACxD,6GAA6G;IAC7G,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC,QAAQ,EAAE,qBAAqB,KAAK,OAAO,CAAC;IAE/D,sEAAsE;IACtE,QAAQ,CAAC,oBAAoB,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IAElD,2BAA2B;IAC3B,QAAQ,CAAC,YAAY,CAAC,EAAE,YAAY,CAAC;CACtC;AAED;;;;GAIG;AACH,wBAAgB,cAAc,CAC5B,KAAK,EAAE,UAAU,EACjB,OAAO,EAAE,qBAAqB,GAC7B,CAAC,QAAQ,EAAE,qBAAqB,KAAK,OAAO,CAAC,IAAI,CAAC,CAmBpD"}
@@ -0,0 +1,48 @@
1
+ import { auditRecordOf } from './audit-record-of.js';
2
+ /**
3
+ * The `onDecision` hook of the authorization middleware. A refusal is always recorded, and so
4
+ * is an allowed decision about anything that is not a read. An allowed read is recorded when
5
+ * its permission is sensitive: recording every list and every page view drowns the trail.
6
+ */
7
+ export function auditDecisions(trail, options) {
8
+ return async (decision) => {
9
+ if (!isRecorded(decision, options)) {
10
+ return;
11
+ }
12
+ const record = auditRecordOf(options, {
13
+ category: 'authorization',
14
+ action: decision.permissionId,
15
+ outcome: decision.decision.allowed ? 'allowed' : 'denied',
16
+ ...(decision.decision.allowed ? {} : { reason: decision.decision.reason }),
17
+ ...(decision.resource === undefined ? {} : { resource: decision.resource }),
18
+ ...contextOf(decision.permissionId),
19
+ });
20
+ const itself = record.actor.id === decision.actorId;
21
+ await trail.record(itself ? record : { ...record, actor: { id: decision.actorId, type: 'unknown' } });
22
+ };
23
+ }
24
+ function isRecorded(decision, options) {
25
+ if (!decision.decision.allowed) {
26
+ return true;
27
+ }
28
+ if (!(options.isRead ?? isAboutAQuery)(decision)) {
29
+ return true;
30
+ }
31
+ if (options.sensitivePermissions?.includes(decision.permissionId) === true) {
32
+ return true;
33
+ }
34
+ const allowedReads = options.allowedReads ?? 'sensitive';
35
+ if (typeof allowedReads === 'string') {
36
+ return allowedReads === 'all';
37
+ }
38
+ return (allowedReads.random ?? Math.random)() < allowedReads.sample;
39
+ }
40
+ function isAboutAQuery(decision) {
41
+ return decision.kind === 'query';
42
+ }
43
+ /** A permission id is `<context>:<name>`. */
44
+ function contextOf(permissionId) {
45
+ const separator = permissionId.indexOf(':');
46
+ return separator > 0 ? { context: permissionId.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AAI,EAAE,SAAS,EAAE,EAAE,CAAC,CAAC;IACxG,CAAC,CAAC;AACJ,CAAC;AAED,SAAS,UAAU,CAAC,QAA+B,EAAE,OAA8B;IACjF,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,OAAO,EAAE,CAAC;QAC/B,OAAO,IAAI,CAAC;IACd,CAAC;IAED,IAAI,CAAC,CAAC,OAAO,CAAC,MAAM,IAAI,aAAa,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC;QACjD,OAAO,IAAI,CAAC;IACd,CAAC;IAED,IAAI,OAAO,CAAC,oBAAoB,EAAE,QAAQ,CAAC,QAAQ,CAAC,YAAY,CAAC,KAAK,IAAI,EAAE,CAAC;QAC3E,OAAO,IAAI,CAAC;IACd,CAAC;IAED,MAAM,YAAY,GAAG,OAAO,CAAC,YAAY,IAAI,WAAW,CAAC;IAEzD,IAAI,OAAO,YAAY,KAAK,QAAQ,EAAE,CAAC;QACrC,OAAO,YAAY,KAAK,KAAK,CAAC;IAChC,CAAC;IAED,OAAO,CAAC,YAAY,CAAC,MAAM,IAAI,IAAI,CAAC,MAAM,CAAC,EAAE,GAAG,YAAY,CAAC,MAAM,CAAC;AACtE,CAAC;AAED,SAAS,aAAa,CAAC,QAA+B;IACpD,OAAO,QAAQ,CAAC,IAAI,KAAK,OAAO,CAAC;AACnC,CAAC;AAED,6CAA6C;AAC7C,SAAS,SAAS,CAAC,YAAoB;IACrC,MAAM,SAAS,GAAG,YAAY,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;IAE5C,OAAO,SAAS,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,YAAY,CAAC,KAAK,CAAC,CAAC,EAAE,SAAS,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;AAC5E,CAAC"}
@@ -0,0 +1,4 @@
1
+ import type { AuditEntry } from '@ddd-ts-kit/kernel';
2
+ /** What happened. Who, in which session and under which correlation come from the scope. */
3
+ export type AuditFact = Pick<AuditEntry, 'category' | 'action' | 'outcome'> & Partial<Pick<AuditEntry, 'reason' | 'resource' | 'context' | 'changes' | 'extensions'>>;
4
+ //# sourceMappingURL=audit-fact.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"audit-fact.d.ts","sourceRoot":"","sources":["../../src/sources/audit-fact.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAErD,4FAA4F;AAC5F,MAAM,MAAM,SAAS,GAAG,IAAI,CAAC,UAAU,EAAE,UAAU,GAAG,QAAQ,GAAG,SAAS,CAAC,GACzE,OAAO,CAAC,IAAI,CAAC,UAAU,EAAE,QAAQ,GAAG,UAAU,GAAG,SAAS,GAAG,SAAS,GAAG,YAAY,CAAC,CAAC,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=audit-fact.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"audit-fact.js","sourceRoot":"","sources":["../../src/sources/audit-fact.ts"],"names":[],"mappings":""}
@@ -0,0 +1,23 @@
1
+ import { type AuditTrail, type Clock, type ExecutionScope, type IdGenerator, type ProcessedEventStore, type UnitOfWork } from '@ddd-ts-kit/kernel';
2
+ import type { AuditSubscription } from './audit-subscription.js';
3
+ import type { AuditedEvents } from './audited-events.js';
4
+ export interface AuditIntegrationEventsOptions {
5
+ readonly registry: AuditedEvents;
6
+ readonly clock: Clock;
7
+ readonly ids: IdGenerator;
8
+ /** At-least-once delivery is the rule: an event redelivered is recorded once. */
9
+ readonly processed: ProcessedEventStore;
10
+ /** When given, the mark and the entry commit together. */
11
+ readonly unitOfWork?: UnitOfWork;
12
+ /** When the consumer boundary opens an execution context, its actor and session are kept. */
13
+ readonly scope?: ExecutionScope;
14
+ /** The idempotency scope, and the name of the system actor. Default `audit`. */
15
+ readonly consumer?: string;
16
+ }
17
+ /**
18
+ * One subscription per event type of the registry, each recording that the event happened.
19
+ * Only the envelope is read (type, id, correlation), never the payload: the trail says that
20
+ * `billing.invoice.issued` occurred and under which correlation, not what it contained.
21
+ */
22
+ export declare function auditIntegrationEvents(trail: AuditTrail, options: AuditIntegrationEventsOptions): AuditSubscription[];
23
+ //# sourceMappingURL=audit-integration-events.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"audit-integration-events.d.ts","sourceRoot":"","sources":["../../src/sources/audit-integration-events.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,KAAK,UAAU,EACf,KAAK,KAAK,EAEV,KAAK,cAAc,EACnB,KAAK,WAAW,EAEhB,KAAK,mBAAmB,EACxB,KAAK,UAAU,EAChB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AACjE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAGzD,MAAM,WAAW,6BAA6B;IAC5C,QAAQ,CAAC,QAAQ,EAAE,aAAa,CAAC;IAEjC,QAAQ,CAAC,KAAK,EAAE,KAAK,CAAC;IAEtB,QAAQ,CAAC,GAAG,EAAE,WAAW,CAAC;IAE1B,iFAAiF;IACjF,QAAQ,CAAC,SAAS,EAAE,mBAAmB,CAAC;IAExC,0DAA0D;IAC1D,QAAQ,CAAC,UAAU,CAAC,EAAE,UAAU,CAAC;IAEjC,6FAA6F;IAC7F,QAAQ,CAAC,KAAK,CAAC,EAAE,cAAc,CAAC;IAEhC,gFAAgF;IAChF,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;CAC5B;AAED;;;;GAIG;AACH,wBAAgB,sBAAsB,CAAC,KAAK,EAAE,UAAU,EAAE,OAAO,EAAE,6BAA6B,GAAG,iBAAiB,EAAE,CAIrH"}
@@ -0,0 +1,59 @@
1
+ import { executionContext, systemActor, } from '@ddd-ts-kit/kernel';
2
+ import { recordIn } from './record-in.js';
3
+ /**
4
+ * One subscription per event type of the registry, each recording that the event happened.
5
+ * Only the envelope is read (type, id, correlation), never the payload: the trail says that
6
+ * `billing.invoice.issued` occurred and under which correlation, not what it contained.
7
+ */
8
+ export function auditIntegrationEvents(trail, options) {
9
+ const types = [...new Set(options.registry.all().map((definition) => definition.type))];
10
+ return types.map((type) => ({ type, handler: (event) => recordOnce(trail, options, event) }));
11
+ }
12
+ const WITHOUT_TRANSACTION = { run: (work) => work() };
13
+ async function recordOnce(trail, options, event) {
14
+ const { processed, consumer = 'audit' } = options;
15
+ const mark = { taken: false };
16
+ try {
17
+ await (options.unitOfWork ?? WITHOUT_TRANSACTION).run(async () => {
18
+ mark.taken = await processed.markProcessed(consumer, event.id);
19
+ if (mark.taken) {
20
+ await trail.record(recordOfEvent(event, options));
21
+ }
22
+ });
23
+ }
24
+ catch (error) {
25
+ // Only a mark taken by this delivery, and only where no rollback already removed it.
26
+ if (mark.taken) {
27
+ await processed.release?.(consumer, event.id);
28
+ }
29
+ throw error;
30
+ }
31
+ }
32
+ function recordOfEvent(event, options) {
33
+ const fact = {
34
+ category: 'integration-event',
35
+ action: event.type,
36
+ outcome: 'succeeded',
37
+ ...contextOf(event.type),
38
+ };
39
+ return recordIn(contextOfDelivery(event, options), options, fact);
40
+ }
41
+ function contextOfDelivery(event, options) {
42
+ const current = options.scope?.current();
43
+ const correlationId = event.correlationId ?? current?.correlationId ?? event.id;
44
+ if (current !== undefined) {
45
+ return { ...current, correlationId, causationId: event.id };
46
+ }
47
+ return executionContext({
48
+ correlationId,
49
+ causationId: event.id,
50
+ actor: systemActor(options.consumer ?? 'audit'),
51
+ origin: 'event',
52
+ });
53
+ }
54
+ /** An event type is `<context>.<aggregate>.<fact>`. */
55
+ function contextOf(type) {
56
+ const separator = type.indexOf('.');
57
+ return separator > 0 ? { context: type.slice(0, separator) } : {};
58
+ }
59
+ //# sourceMappingURL=audit-integration-events.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"audit-integration-events.js","sourceRoot":"","sources":["../../src/sources/audit-integration-events.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,gBAAgB,E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C,OAAO,SAAS,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,SAAS,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;AACpE,CAAC"}
@@ -0,0 +1,33 @@
1
+ import { type AuditRecord, type AuditTrail, type BusMiddleware, type Message, type MessageType, type UnitOfWork } from '@ddd-ts-kit/kernel';
2
+ import type { AuditMasker } from '../redaction/audit-masker.js';
3
+ import type { AuditedMessage } from '../redaction/audited-message.js';
4
+ import type { AuditSource } from './audit-source.js';
5
+ /** The reason of a failure that is not a `DomainError`: its class and message stay out of the trail. */
6
+ export declare const UNEXPECTED_ERROR = "UNEXPECTED_ERROR";
7
+ export interface AuditMiddlewareOptions extends AuditSource {
8
+ /**
9
+ * The unit of work of the commands. Given, the entry of a command that succeeded is written
10
+ * in its transaction and exists only if it commits, and the entry of one that failed is
11
+ * written after the rollback. Install this middleware before `unitOfWorkMiddleware`, which
12
+ * then joins the transaction opened here.
13
+ */
14
+ readonly unitOfWork?: UnitOfWork;
15
+ /** What may go into `changes`, per message. A message without a declaration carries none. */
16
+ readonly fields?: readonly AuditedMessage[];
17
+ /** The queries to record. Default `none`: commands only. */
18
+ readonly queries?: 'none' | 'all' | readonly MessageType<Message>[];
19
+ /** Required as soon as one declaration masks a field. */
20
+ readonly masker?: AuditMasker;
21
+ /**
22
+ * Told when the entry of a failure could not be written. The failure of the use case is
23
+ * what the caller receives, never the failure of its audit.
24
+ */
25
+ readonly onLostRecord?: (error: unknown, record: AuditRecord | undefined) => void;
26
+ }
27
+ /**
28
+ * Records every command, and the queries asked for, with its outcome and the `code` of the
29
+ * domain error as reason. No use case knows: the middleware reads the message, the scope and
30
+ * the declarations of `auditedFields`.
31
+ */
32
+ export declare function auditMiddleware(trail: AuditTrail, options: AuditMiddlewareOptions): BusMiddleware;
33
+ //# sourceMappingURL=audit-middleware.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"audit-middleware.d.ts","sourceRoot":"","sources":["../../src/sources/audit-middleware.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,KAAK,WAAW,EAChB,KAAK,UAAU,EACf,KAAK,aAAa,EAClB,KAAK,OAAO,EAEZ,KAAK,WAAW,EAChB,KAAK,UAAU,EAChB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,8BAA8B,CAAC;AAChE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,iCAAiC,CAAC;AAItE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAErD,wGAAwG;AACxG,eAAO,MAAM,gBAAgB,qBAAqB,CAAC;AAEnD,MAAM,WAAW,sBAAuB,SAAQ,WAAW;IACzD;;;;;OAKG;IACH,QAAQ,CAAC,UAAU,CAAC,EAAE,UAAU,CAAC;IAEjC,6FAA6F;IAC7F,QAAQ,CAAC,MAAM,CAAC,EAAE,SAAS,cAAc,EAAE,CAAC;IAE5C,4DAA4D;IAC5D,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,GAAG,KAAK,GAAG,SAAS,WAAW,CAAC,OAAO,CAAC,EAAE,CAAC;IAEpE,yDAAyD;IACzD,QAAQ,CAAC,MAAM,CAAC,EAAE,WAAW,CAAC;IAE9B;;;OAGG;IACH,QAAQ,CAAC,YAAY,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,WAAW,GAAG,SAAS,KAAK,IAAI,CAAC;CACnF;AAED;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,UAAU,EAAE,OAAO,EAAE,sBAAsB,GAAG,aAAa,CAoBjG"}
@@ -0,0 +1,113 @@
1
+ import { DomainError, } from '@ddd-ts-kit/kernel';
2
+ import { changesOf } from '../redaction/changes-of.js';
3
+ import { MissingMaskerError } from '../redaction/missing-masker-error.js';
4
+ import { auditRecordOf } from './audit-record-of.js';
5
+ /** The reason of a failure that is not a `DomainError`: its class and message stay out of the trail. */
6
+ export const UNEXPECTED_ERROR = 'UNEXPECTED_ERROR';
7
+ /**
8
+ * Records every command, and the queries asked for, with its outcome and the `code` of the
9
+ * domain error as reason. No use case knows: the middleware reads the message, the scope and
10
+ * the declarations of `auditedFields`.
11
+ */
12
+ export function auditMiddleware(trail, options) {
13
+ const declarations = new Map((options.fields ?? []).map((declaration) => [declaration.type, declaration]));
14
+ assertMaskerGiven(options);
15
+ return (message, next, info) => {
16
+ if (!isRecorded(message, info, options)) {
17
+ return next();
18
+ }
19
+ const audit = new MessageAudit(trail, options, {
20
+ message,
21
+ info,
22
+ declaration: declarations.get(message.constructor),
23
+ });
24
+ return audit.around(next);
25
+ };
26
+ }
27
+ function assertMaskerGiven(options) {
28
+ const masking = options.masker === undefined ? options.fields?.find((declaration) => declaration.masks) : undefined;
29
+ if (masking !== undefined) {
30
+ throw new MissingMaskerError(masking.type.name);
31
+ }
32
+ }
33
+ function isRecorded(message, info, { queries = 'none' }) {
34
+ if (info.kind === 'command') {
35
+ return true;
36
+ }
37
+ return typeof queries === 'string' ? queries === 'all' : queries.some((type) => message instanceof type);
38
+ }
39
+ class MessageAudit {
40
+ trail;
41
+ options;
42
+ sending;
43
+ constructor(trail, options, sending) {
44
+ this.trail = trail;
45
+ this.options = options;
46
+ this.sending = sending;
47
+ }
48
+ around(next) {
49
+ const { unitOfWork } = this.options;
50
+ if (unitOfWork === undefined || this.sending.info.kind === 'query') {
51
+ return this.afterwards(next);
52
+ }
53
+ return this.orRecordFailure(() => unitOfWork.run(() => this.thenRecordSuccess(next)));
54
+ }
55
+ async afterwards(next) {
56
+ const result = await this.orRecordFailure(next);
57
+ await this.record('succeeded');
58
+ return result;
59
+ }
60
+ async orRecordFailure(work) {
61
+ try {
62
+ return await work();
63
+ }
64
+ catch (error) {
65
+ await this.recordFailure(error);
66
+ throw error;
67
+ }
68
+ }
69
+ async recordFailure(failure) {
70
+ const reason = failure instanceof DomainError ? failure.code : UNEXPECTED_ERROR;
71
+ let record;
72
+ try {
73
+ record = await this.recordOf('failed', reason);
74
+ await this.trail.record(record);
75
+ }
76
+ catch (error) {
77
+ this.options.onLostRecord?.(error, record);
78
+ }
79
+ }
80
+ async thenRecordSuccess(next) {
81
+ const result = await next();
82
+ await this.record('succeeded');
83
+ return result;
84
+ }
85
+ async record(outcome) {
86
+ await this.trail.record(await this.recordOf(outcome));
87
+ }
88
+ async recordOf(outcome, reason) {
89
+ const { message, info, declaration } = this.sending;
90
+ const projection = declaration?.project(message) ?? {};
91
+ const { resource, context } = projection;
92
+ const who = this.options.scope.require();
93
+ const subject = {
94
+ actorId: who.actor.id,
95
+ ...(who.tenantId === undefined ? {} : { tenantId: who.tenantId }),
96
+ ...(resource === undefined ? {} : { resource }),
97
+ };
98
+ const changes = await changesOf(projection, {
99
+ subject,
100
+ ...(this.options.masker === undefined ? {} : { masker: this.options.masker }),
101
+ });
102
+ return auditRecordOf(this.options, {
103
+ category: info.kind,
104
+ action: info.name,
105
+ outcome,
106
+ ...(reason === undefined ? {} : { reason }),
107
+ ...(resource === undefined ? {} : { resource }),
108
+ ...(context === undefined ? {} : { context }),
109
+ ...(changes === undefined ? {} : { changes }),
110
+ });
111
+ }
112
+ }
113
+ //# sourceMappingURL=audit-middleware.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"audit-middleware.js","sourceRoot":"","sources":["../../src/sources/audit-middleware.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,WAAW,GASZ,MAAM,oBAAoB,CAAC;AAG5B,OAAO,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAC;AACvD,OAAO,EAAE,kBAAkB,EAAE,MAAM,sCAAsC,CAAC;AAC1E,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAGrD,wGAAwG;AACxG,MAAM,CAAC,MAAM,gBAAgB,GAAG,kBAAkB,CAAC;AA2BnD;;;;GAIG;AACH,MAAM,UAAU,eAAe,CAAC,KAAiB,EAAE,OAA+B;IAChF,MA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,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,GAAG,CAAC,QAAQ,EAAE,CAAC;YACjE,GAAG,CAAC,QAAQ,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,CAAC;SAChD,CAAC;QAEF,MAAM,OAAO,GAAG,MAAM,SAAS,CAAC,UAAU,EAAE;YAC1C,OAAO;YACP,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,CAAC;SAC9E,CAAC,CAAC;QAEH,OAAO,aAAa,CAAC,IAAI,CAAC,OAAO,EAAE;YACjC,QAAQ,EAAE,IAAI,CAAC,IAAI;YACnB,MAAM,EAAE,IAAI,CAAC,IAAI;YACjB,OAAO;YACP,GAAG,CAAC,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC;YAC3C,GAAG,CAAC,QAAQ,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,CAAC;YAC/C,GAAG,CAAC,OAAO,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC;YAC7C,GAAG,CAAC,OAAO,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC;SAC9C,CAAC,CAAC;IACL,CAAC;CACF"}
@@ -0,0 +1,10 @@
1
+ import type { AuditRecord } from '@ddd-ts-kit/kernel';
2
+ import type { AuditFact } from './audit-fact.js';
3
+ import type { AuditSource } from './audit-source.js';
4
+ /**
5
+ * The record of a fact that happened in the work in progress. Sources use it, and so does
6
+ * infrastructure writing a `data-access` entry by hand. Throws `NoExecutionContextError`
7
+ * outside of `ExecutionScope.run`.
8
+ */
9
+ export declare function auditRecordOf(source: AuditSource, fact: AuditFact): AuditRecord;
10
+ //# sourceMappingURL=audit-record-of.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"audit-record-of.d.ts","sourceRoot":"","sources":["../../src/sources/audit-record-of.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAGrD;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,MAAM,EAAE,WAAW,EAAE,IAAI,EAAE,SAAS,GAAG,WAAW,CAE/E"}
@@ -0,0 +1,10 @@
1
+ import { recordIn } from './record-in.js';
2
+ /**
3
+ * The record of a fact that happened in the work in progress. Sources use it, and so does
4
+ * infrastructure writing a `data-access` entry by hand. Throws `NoExecutionContextError`
5
+ * outside of `ExecutionScope.run`.
6
+ */
7
+ export function auditRecordOf(source, fact) {
8
+ return recordIn(source.scope.require(), source, fact);
9
+ }
10
+ //# sourceMappingURL=audit-record-of.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"audit-record-of.js","sourceRoot":"","sources":["../../src/sources/audit-record-of.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAE1C;;;;GAIG;AACH,MAAM,UAAU,aAAa,CAAC,MAAmB,EAAE,IAAe;IAChE,OAAO,QAAQ,CAAC,MAAM,CAAC,KAAK,CAAC,OAAO,EAAE,EAAE,MAAM,EAAE,IAAI,CAAC,CAAC;AACxD,CAAC"}
@@ -0,0 +1,8 @@
1
+ import type { Clock, ExecutionScope, IdGenerator } from '@ddd-ts-kit/kernel';
2
+ /** What every source reads instead of being handed parameters by the use cases. */
3
+ export interface AuditSource {
4
+ readonly scope: ExecutionScope;
5
+ readonly clock: Clock;
6
+ readonly ids: IdGenerator;
7
+ }
8
+ //# sourceMappingURL=audit-source.d.ts.map