@learncard/network-brain-service 4.1.2 → 5.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (375) hide show
  1. package/.env.example +14 -0
  2. package/CHANGELOG.md +164 -0
  3. package/README.md +27 -1
  4. package/bootstrapLambda.test.ts +70 -32
  5. package/config/config.dev.json +1 -0
  6. package/config/config.example.json +2 -1
  7. package/config/config.production.json +1 -0
  8. package/config/config.scouts.dev.json +1 -0
  9. package/config/config.scouts.production.json +1 -0
  10. package/consentFlowDeadlineLambda.test.ts +108 -0
  11. package/consentFlowDeadlineLambda.ts +18 -0
  12. package/consentFlowDeadlineLambdaApp.ts +14 -0
  13. package/dist/accesslayer/boost/create.d.ts +8 -2
  14. package/dist/accesslayer/boost/create.d.ts.map +1 -1
  15. package/dist/accesslayer/campaign/audience.d.ts +4 -4
  16. package/dist/accesslayer/campaign/audience.d.ts.map +1 -1
  17. package/dist/accesslayer/campaign/create.d.ts +1 -1
  18. package/dist/accesslayer/campaign/create.d.ts.map +1 -1
  19. package/dist/accesslayer/campaign/delivery.d.ts +5 -0
  20. package/dist/accesslayer/campaign/delivery.d.ts.map +1 -0
  21. package/dist/accesslayer/campaign/dispatch.d.ts +5 -0
  22. package/dist/accesslayer/campaign/dispatch.d.ts.map +1 -0
  23. package/dist/accesslayer/campaign/dispatch.test.d.ts +2 -0
  24. package/dist/accesslayer/campaign/dispatch.test.d.ts.map +1 -0
  25. package/dist/accesslayer/campaign/email.d.ts +10 -0
  26. package/dist/accesslayer/campaign/email.d.ts.map +1 -0
  27. package/dist/accesslayer/campaign/email.test.d.ts +2 -0
  28. package/dist/accesslayer/campaign/email.test.d.ts.map +1 -0
  29. package/dist/accesslayer/campaign/preferences.d.ts +5 -0
  30. package/dist/accesslayer/campaign/preferences.d.ts.map +1 -0
  31. package/dist/accesslayer/campaign/read.d.ts.map +1 -1
  32. package/dist/accesslayer/campaign/test.d.ts +5 -0
  33. package/dist/accesslayer/campaign/test.d.ts.map +1 -0
  34. package/dist/accesslayer/campaign/test.test.d.ts +2 -0
  35. package/dist/accesslayer/campaign/test.test.d.ts.map +1 -0
  36. package/dist/accesslayer/campaign/update.d.ts.map +1 -1
  37. package/dist/accesslayer/consentflowcontract/create.d.ts.map +1 -1
  38. package/dist/accesslayer/consentflowcontract/delete.d.ts +1 -1
  39. package/dist/accesslayer/consentflowcontract/delete.d.ts.map +1 -1
  40. package/dist/accesslayer/consentflowcontract/read.d.ts.map +1 -1
  41. package/dist/accesslayer/consentflowcontract/relationships/create.d.ts +2 -1
  42. package/dist/accesslayer/consentflowcontract/relationships/create.d.ts.map +1 -1
  43. package/dist/accesslayer/consentflowcontract/relationships/read.d.ts +19 -4
  44. package/dist/accesslayer/consentflowcontract/relationships/read.d.ts.map +1 -1
  45. package/dist/accesslayer/consentflowcontract/relationships/update.d.ts +6 -1
  46. package/dist/accesslayer/consentflowcontract/relationships/update.d.ts.map +1 -1
  47. package/dist/accesslayer/consentflowcontract/versions.d.ts +68 -0
  48. package/dist/accesslayer/consentflowcontract/versions.d.ts.map +1 -0
  49. package/dist/accesslayer/credential/create.d.ts +3 -1
  50. package/dist/accesslayer/credential/create.d.ts.map +1 -1
  51. package/dist/accesslayer/credential/delete.d.ts +1 -0
  52. package/dist/accesslayer/credential/delete.d.ts.map +1 -1
  53. package/dist/accesslayer/credential/relationships/create.d.ts +15 -3
  54. package/dist/accesslayer/credential/relationships/create.d.ts.map +1 -1
  55. package/dist/accesslayer/credential/relationships/read.d.ts +2 -0
  56. package/dist/accesslayer/credential/relationships/read.d.ts.map +1 -1
  57. package/dist/accesslayer/credential/relationships/update.d.ts.map +1 -1
  58. package/dist/accesslayer/credential-refresh/read.d.ts +1 -0
  59. package/dist/accesslayer/credential-refresh/read.d.ts.map +1 -1
  60. package/dist/accesslayer/credential-refresh/update.d.ts.map +1 -1
  61. package/dist/accesslayer/inbox-credential/create.d.ts +1 -0
  62. package/dist/accesslayer/inbox-credential/create.d.ts.map +1 -1
  63. package/dist/accesslayer/inbox-credential/refresh.d.ts +7 -0
  64. package/dist/accesslayer/inbox-credential/refresh.d.ts.map +1 -1
  65. package/dist/app.d.ts +11 -1
  66. package/dist/app.d.ts.map +1 -1
  67. package/dist/cache/app-store.caches.d.ts +61 -1
  68. package/dist/cache/app-store.caches.d.ts.map +1 -1
  69. package/dist/campaign-unsubscribe.d.ts +7 -0
  70. package/dist/campaign-unsubscribe.d.ts.map +1 -0
  71. package/dist/campaign-unsubscribe.test.d.ts +2 -0
  72. package/dist/campaign-unsubscribe.test.d.ts.map +1 -0
  73. package/dist/config/environment.d.ts +42 -0
  74. package/dist/config/environment.d.ts.map +1 -1
  75. package/dist/config/stageConfig.d.ts +4 -0
  76. package/dist/config/stageConfig.d.ts.map +1 -1
  77. package/dist/credential-refresh.d.ts.map +1 -1
  78. package/dist/helpers/boost.helpers.d.ts +4 -1
  79. package/dist/helpers/boost.helpers.d.ts.map +1 -1
  80. package/dist/helpers/campaign-app-origin.helpers.d.ts +2 -0
  81. package/dist/helpers/campaign-app-origin.helpers.d.ts.map +1 -0
  82. package/dist/helpers/campaign-email.helpers.d.ts +13 -0
  83. package/dist/helpers/campaign-email.helpers.d.ts.map +1 -0
  84. package/dist/helpers/campaign-notifications.helpers.d.ts +7 -0
  85. package/dist/helpers/campaign-notifications.helpers.d.ts.map +1 -0
  86. package/dist/helpers/campaign-queue.helpers.d.ts +7 -0
  87. package/dist/helpers/campaign-queue.helpers.d.ts.map +1 -0
  88. package/dist/helpers/campaign-queue.helpers.test.d.ts +2 -0
  89. package/dist/helpers/campaign-queue.helpers.test.d.ts.map +1 -0
  90. package/dist/helpers/campaign-unsubscribe-page.d.ts +2 -0
  91. package/dist/helpers/campaign-unsubscribe-page.d.ts.map +1 -0
  92. package/dist/helpers/campaign-unsubscribe.helpers.d.ts +7 -0
  93. package/dist/helpers/campaign-unsubscribe.helpers.d.ts.map +1 -0
  94. package/dist/helpers/campaign-webhook.helpers.test.d.ts +2 -0
  95. package/dist/helpers/campaign-webhook.helpers.test.d.ts.map +1 -0
  96. package/dist/helpers/consentflow-deadline.helpers.d.ts +5 -0
  97. package/dist/helpers/consentflow-deadline.helpers.d.ts.map +1 -0
  98. package/dist/helpers/consentflow-legacy-migration.helpers.d.ts +2 -0
  99. package/dist/helpers/consentflow-legacy-migration.helpers.d.ts.map +1 -0
  100. package/dist/helpers/contract-events.helpers.d.ts.map +1 -1
  101. package/dist/helpers/contract.helpers.d.ts +1 -1
  102. package/dist/helpers/contract.helpers.d.ts.map +1 -1
  103. package/dist/helpers/credential-display.helpers.d.ts +5 -0
  104. package/dist/helpers/credential-display.helpers.d.ts.map +1 -0
  105. package/dist/helpers/credential-display.helpers.test.d.ts +2 -0
  106. package/dist/helpers/credential-display.helpers.test.d.ts.map +1 -0
  107. package/dist/helpers/credential-refresh-email.helpers.d.ts.map +1 -1
  108. package/dist/helpers/credential-refresh-materiality.helpers.d.ts +4 -0
  109. package/dist/helpers/credential-refresh-materiality.helpers.d.ts.map +1 -1
  110. package/dist/helpers/credential-refresh.helpers.d.ts +30 -1
  111. package/dist/helpers/credential-refresh.helpers.d.ts.map +1 -1
  112. package/dist/helpers/credential-status-mutation.helpers.d.ts +5 -0
  113. package/dist/helpers/credential-status-mutation.helpers.d.ts.map +1 -0
  114. package/dist/helpers/credential-status-mutation.helpers.test.d.ts +2 -0
  115. package/dist/helpers/credential-status-mutation.helpers.test.d.ts.map +1 -0
  116. package/dist/helpers/credential.helpers.d.ts +1 -1
  117. package/dist/helpers/credential.helpers.d.ts.map +1 -1
  118. package/dist/helpers/inbox-refresh.helpers.d.ts +4 -2
  119. package/dist/helpers/inbox-refresh.helpers.d.ts.map +1 -1
  120. package/dist/helpers/inbox.helpers.d.ts +1 -0
  121. package/dist/helpers/inbox.helpers.d.ts.map +1 -1
  122. package/dist/helpers/learnCard.helpers.d.ts +1 -0
  123. package/dist/helpers/learnCard.helpers.d.ts.map +1 -1
  124. package/dist/helpers/managed-status.helpers.d.ts +7 -0
  125. package/dist/helpers/managed-status.helpers.d.ts.map +1 -0
  126. package/dist/helpers/managed-status.helpers.test.d.ts +2 -0
  127. package/dist/helpers/managed-status.helpers.test.d.ts.map +1 -0
  128. package/dist/helpers/notification-delivery-boundary.helpers.test.d.ts +2 -0
  129. package/dist/helpers/notification-delivery-boundary.helpers.test.d.ts.map +1 -0
  130. package/dist/helpers/notification-webhook-fetch.helpers.d.ts +13 -0
  131. package/dist/helpers/notification-webhook-fetch.helpers.d.ts.map +1 -0
  132. package/dist/helpers/notification-webhook-fetch.helpers.test.d.ts +2 -0
  133. package/dist/helpers/notification-webhook-fetch.helpers.test.d.ts.map +1 -0
  134. package/dist/helpers/notificationQueue.helpers.d.ts.map +1 -1
  135. package/dist/helpers/notifications.helpers.d.ts.map +1 -1
  136. package/dist/helpers/refresh-send-intent.helpers.d.ts +13 -5
  137. package/dist/helpers/refresh-send-intent.helpers.d.ts.map +1 -1
  138. package/dist/helpers/refresh-send-intent.helpers.test.d.ts +2 -0
  139. package/dist/helpers/refresh-send-intent.helpers.test.d.ts.map +1 -0
  140. package/dist/helpers/send-contract.helpers.d.ts +11 -0
  141. package/dist/helpers/send-contract.helpers.d.ts.map +1 -0
  142. package/dist/helpers/status-list.helpers.d.ts +12 -1
  143. package/dist/helpers/status-list.helpers.d.ts.map +1 -1
  144. package/dist/index.js +2 -2
  145. package/dist/models/ConsentFlowContract.d.ts.map +1 -1
  146. package/dist/models/ConsentFlowContractVersion.d.ts +12 -0
  147. package/dist/models/ConsentFlowContractVersion.d.ts.map +1 -0
  148. package/dist/models/ConsentFlowTerms.d.ts.map +1 -1
  149. package/dist/models/Credential.d.ts +2 -0
  150. package/dist/models/Credential.d.ts.map +1 -1
  151. package/dist/models/CredentialRefresh.d.ts +5 -0
  152. package/dist/models/CredentialRefresh.d.ts.map +1 -1
  153. package/dist/models/Integration.d.ts +1 -1
  154. package/dist/models/Profile.d.ts.map +1 -1
  155. package/dist/models/campaign-constraints.d.ts.map +1 -1
  156. package/dist/models/index.d.ts +1 -0
  157. package/dist/models/index.d.ts.map +1 -1
  158. package/dist/openapi.d.ts.map +1 -1
  159. package/dist/publish-metafile.json +1 -1
  160. package/dist/routes/activity.d.ts +15 -5
  161. package/dist/routes/activity.d.ts.map +1 -1
  162. package/dist/routes/app-store.d.ts +15 -5
  163. package/dist/routes/app-store.d.ts.map +1 -1
  164. package/dist/routes/auth-grants.d.ts +12 -2
  165. package/dist/routes/auth-grants.d.ts.map +1 -1
  166. package/dist/routes/bench.d.ts +11 -1
  167. package/dist/routes/bench.d.ts.map +1 -1
  168. package/dist/routes/boosts.d.ts +70 -15
  169. package/dist/routes/boosts.d.ts.map +1 -1
  170. package/dist/routes/campaigns.d.ts +183 -51
  171. package/dist/routes/campaigns.d.ts.map +1 -1
  172. package/dist/routes/claim-hooks.d.ts +11 -1
  173. package/dist/routes/claim-hooks.d.ts.map +1 -1
  174. package/dist/routes/contact-methods.d.ts +11 -1
  175. package/dist/routes/contact-methods.d.ts.map +1 -1
  176. package/dist/routes/contracts.d.ts +374 -8
  177. package/dist/routes/contracts.d.ts.map +1 -1
  178. package/dist/routes/credential-input-privacy.test.d.ts +2 -0
  179. package/dist/routes/credential-input-privacy.test.d.ts.map +1 -0
  180. package/dist/routes/credential-refreshes.d.ts +210 -1
  181. package/dist/routes/credential-refreshes.d.ts.map +1 -1
  182. package/dist/routes/credential-share-previews.d.ts +11 -1
  183. package/dist/routes/credential-share-previews.d.ts.map +1 -1
  184. package/dist/routes/credentials.d.ts +132 -3
  185. package/dist/routes/credentials.d.ts.map +1 -1
  186. package/dist/routes/did-metadata.d.ts +11 -1
  187. package/dist/routes/did-metadata.d.ts.map +1 -1
  188. package/dist/routes/federation.d.ts +11 -1
  189. package/dist/routes/federation.d.ts.map +1 -1
  190. package/dist/routes/inbox.d.ts +54 -19
  191. package/dist/routes/inbox.d.ts.map +1 -1
  192. package/dist/routes/index.d.ts +100 -1
  193. package/dist/routes/index.d.ts.map +1 -1
  194. package/dist/routes/integrations.d.ts +14 -4
  195. package/dist/routes/integrations.d.ts.map +1 -1
  196. package/dist/routes/presentations.d.ts +11 -1
  197. package/dist/routes/presentations.d.ts.map +1 -1
  198. package/dist/routes/profile-manager.d.ts +11 -1
  199. package/dist/routes/profile-manager.d.ts.map +1 -1
  200. package/dist/routes/profiles.d.ts +11 -1
  201. package/dist/routes/profiles.d.ts.map +1 -1
  202. package/dist/routes/public-share-links.d.ts +22 -2
  203. package/dist/routes/public-share-links.d.ts.map +1 -1
  204. package/dist/routes/share-links.d.ts +36 -16
  205. package/dist/routes/share-links.d.ts.map +1 -1
  206. package/dist/routes/skill-frameworks.d.ts +11 -1
  207. package/dist/routes/skill-frameworks.d.ts.map +1 -1
  208. package/dist/routes/skills.d.ts +11 -1
  209. package/dist/routes/skills.d.ts.map +1 -1
  210. package/dist/routes/storage.d.ts +37 -23
  211. package/dist/routes/storage.d.ts.map +1 -1
  212. package/dist/routes/test.d.ts +79 -3
  213. package/dist/routes/test.d.ts.map +1 -1
  214. package/dist/routes/utilities.d.ts +11 -1
  215. package/dist/routes/utilities.d.ts.map +1 -1
  216. package/dist/routes/workflows.d.ts +11 -1
  217. package/dist/routes/workflows.d.ts.map +1 -1
  218. package/dist/services/delivery/adapters/postmark.adapter.d.ts +3 -0
  219. package/dist/services/delivery/adapters/postmark.adapter.d.ts.map +1 -1
  220. package/dist/services/delivery/delivery.service.d.ts +10 -0
  221. package/dist/services/delivery/delivery.service.d.ts.map +1 -1
  222. package/dist/types/activity.d.ts +3 -3
  223. package/dist/types/app-manifest.d.ts +10 -10
  224. package/dist/types/campaign.d.ts +13 -1
  225. package/dist/types/campaign.d.ts.map +1 -1
  226. package/dist/types/consentflowcontract.d.ts +175 -7
  227. package/dist/types/consentflowcontract.d.ts.map +1 -1
  228. package/dist/types/credential-refresh.d.ts +27 -0
  229. package/dist/types/credential-refresh.d.ts.map +1 -1
  230. package/dist/types/credential.d.ts +5 -0
  231. package/dist/types/credential.d.ts.map +1 -1
  232. package/dist/types/integration.d.ts +3 -3
  233. package/lambda.ts +44 -14
  234. package/lambdaApp.ts +20 -0
  235. package/package.json +20 -19
  236. package/project.json +5 -0
  237. package/scripts/migrate-consent-flow-versions.ts +9 -0
  238. package/scripts/report-send-template-exposure.ts +47 -0
  239. package/scripts/verify-python-contracts.ts +16 -1
  240. package/serverless-local.yml +15 -2
  241. package/serverless.function-env.cjs +4 -0
  242. package/serverless.local.yml +12 -0
  243. package/serverless.yml +48 -3
  244. package/src/accesslayer/boost/create.ts +62 -7
  245. package/src/accesslayer/campaign/README.md +275 -6
  246. package/src/accesslayer/campaign/audience.ts +39 -7
  247. package/src/accesslayer/campaign/create.ts +4 -2
  248. package/src/accesslayer/campaign/delivery.ts +66 -0
  249. package/src/accesslayer/campaign/dispatch.test.ts +59 -0
  250. package/src/accesslayer/campaign/dispatch.ts +172 -0
  251. package/src/accesslayer/campaign/email.test.ts +73 -0
  252. package/src/accesslayer/campaign/email.ts +91 -0
  253. package/src/accesslayer/campaign/preferences.ts +53 -0
  254. package/src/accesslayer/campaign/read.ts +3 -1
  255. package/src/accesslayer/campaign/state.ts +1 -1
  256. package/src/accesslayer/campaign/test.test.ts +31 -0
  257. package/src/accesslayer/campaign/test.ts +75 -0
  258. package/src/accesslayer/campaign/update.ts +15 -4
  259. package/src/accesslayer/consentflowcontract/create.ts +20 -1
  260. package/src/accesslayer/consentflowcontract/delete.ts +121 -3
  261. package/src/accesslayer/consentflowcontract/read.ts +15 -9
  262. package/src/accesslayer/consentflowcontract/relationships/create.ts +70 -36
  263. package/src/accesslayer/consentflowcontract/relationships/read.ts +305 -73
  264. package/src/accesslayer/consentflowcontract/relationships/smartResume.ts +1 -1
  265. package/src/accesslayer/consentflowcontract/relationships/update.ts +269 -98
  266. package/src/accesslayer/consentflowcontract/versions.ts +790 -0
  267. package/src/accesslayer/credential/create.ts +33 -9
  268. package/src/accesslayer/credential/delete.ts +45 -0
  269. package/src/accesslayer/credential/relationships/create.ts +102 -47
  270. package/src/accesslayer/credential/relationships/update.ts +8 -116
  271. package/src/accesslayer/credential-refresh/read.ts +26 -2
  272. package/src/accesslayer/credential-refresh/update.ts +6 -2
  273. package/src/accesslayer/inbox-credential/create.ts +7 -1
  274. package/src/accesslayer/inbox-credential/refresh.ts +14 -4
  275. package/src/campaign-unsubscribe.test.ts +158 -0
  276. package/src/campaign-unsubscribe.ts +86 -0
  277. package/src/config/environment.test.ts +52 -0
  278. package/src/config/environment.ts +58 -0
  279. package/src/config/serverlessFunctionEnv.test.ts +59 -0
  280. package/src/credential-refresh.ts +1 -0
  281. package/src/docker-entry.ts +26 -1
  282. package/src/helpers/boost-storage.helpers.test.ts +107 -41
  283. package/src/helpers/boost.helpers.ts +88 -40
  284. package/src/helpers/campaign-app-origin.helpers.ts +25 -0
  285. package/src/helpers/campaign-email.helpers.ts +113 -0
  286. package/src/helpers/campaign-notifications.helpers.ts +127 -0
  287. package/src/helpers/campaign-queue.helpers.test.ts +442 -0
  288. package/src/helpers/campaign-queue.helpers.ts +122 -0
  289. package/src/helpers/campaign-unsubscribe-page.ts +107 -0
  290. package/src/helpers/campaign-unsubscribe.helpers.ts +56 -0
  291. package/src/helpers/campaign-webhook.helpers.test.ts +137 -0
  292. package/src/helpers/consentflow-deadline.helpers.ts +22 -0
  293. package/src/helpers/consentflow-legacy-migration.helpers.ts +179 -0
  294. package/src/helpers/contract-events.helpers.ts +35 -3
  295. package/src/helpers/contract-requests.helpers.ts +1 -1
  296. package/src/helpers/contract.helpers.ts +5 -1
  297. package/src/helpers/credential-display.helpers.test.ts +68 -0
  298. package/src/helpers/credential-display.helpers.ts +15 -0
  299. package/src/helpers/credential-refresh-email.helpers.ts +5 -12
  300. package/src/helpers/credential-refresh-materiality.helpers.test.ts +138 -1
  301. package/src/helpers/credential-refresh-materiality.helpers.ts +62 -1
  302. package/src/helpers/credential-refresh-proof.helpers.test.ts +1 -1
  303. package/src/helpers/credential-refresh-proof.helpers.ts +2 -2
  304. package/src/helpers/credential-refresh.helpers.ts +1166 -376
  305. package/src/helpers/credential-status-mutation.helpers.test.ts +155 -0
  306. package/src/helpers/credential-status-mutation.helpers.ts +166 -0
  307. package/src/helpers/credential.helpers.ts +19 -11
  308. package/src/helpers/finalize-inbox.helpers.ts +1 -1
  309. package/src/helpers/inbox-refresh.helpers.ts +34 -8
  310. package/src/helpers/inbox.helpers.ts +2 -0
  311. package/src/helpers/learnCard.helpers.ts +23 -0
  312. package/src/helpers/managed-status.helpers.test.ts +101 -0
  313. package/src/helpers/managed-status.helpers.ts +147 -0
  314. package/src/helpers/notification-delivery-boundary.helpers.test.ts +114 -0
  315. package/src/helpers/notification-webhook-fetch.helpers.test.ts +228 -0
  316. package/src/helpers/notification-webhook-fetch.helpers.ts +166 -0
  317. package/src/helpers/notificationQueue.helpers.ts +5 -0
  318. package/src/helpers/notifications.helpers.ts +19 -12
  319. package/src/helpers/refresh-send-intent.helpers.test.ts +60 -0
  320. package/src/helpers/refresh-send-intent.helpers.ts +81 -18
  321. package/src/helpers/send-contract.helpers.ts +36 -0
  322. package/src/helpers/status-list.helpers.test.ts +29 -12
  323. package/src/helpers/status-list.helpers.ts +329 -20
  324. package/src/models/ConsentFlowContract.ts +3 -0
  325. package/src/models/ConsentFlowContractVersion.ts +50 -0
  326. package/src/models/ConsentFlowTerms.ts +4 -0
  327. package/src/models/Credential.ts +2 -0
  328. package/src/models/CredentialRefresh.ts +2 -0
  329. package/src/models/Profile.ts +2 -0
  330. package/src/models/campaign-constraints.ts +13 -8
  331. package/src/models/index.ts +2 -0
  332. package/src/openapi.ts +21 -0
  333. package/src/routes/app-store.ts +2 -1
  334. package/src/routes/boosts.ts +219 -137
  335. package/src/routes/campaigns.ts +98 -19
  336. package/src/routes/contracts.ts +433 -115
  337. package/src/routes/credential-input-privacy.test.ts +92 -0
  338. package/src/routes/credential-refreshes.ts +273 -2
  339. package/src/routes/federation.ts +7 -2
  340. package/src/routes/inbox.ts +6 -1
  341. package/src/routes/index.ts +31 -2
  342. package/src/routes/workflows.ts +61 -46
  343. package/src/services/delivery/adapters/postmark.adapter.test.ts +70 -1
  344. package/src/services/delivery/adapters/postmark.adapter.ts +84 -11
  345. package/src/services/delivery/delivery.service.ts +4 -0
  346. package/src/types/campaign.ts +14 -1
  347. package/src/types/consentflowcontract.ts +43 -2
  348. package/src/types/credential-refresh.ts +11 -1
  349. package/src/types/credential.ts +2 -0
  350. package/test/boost-status-cleanup.spec.ts +123 -0
  351. package/test/campaigns-email.unit.spec.ts +268 -0
  352. package/test/campaigns.spec.ts +804 -30
  353. package/test/consent-autoboost-idempotency.spec.ts +432 -0
  354. package/test/consent-data-boundaries.spec.ts +322 -26
  355. package/test/consent-legacy-migration.spec.ts +315 -0
  356. package/test/consent-recipients.spec.ts +7 -7
  357. package/test/consent-version-updates.spec.ts +761 -0
  358. package/test/consentflow.spec.ts +698 -226
  359. package/test/contract-requests.spec.ts +55 -9
  360. package/test/credential-refresh-allocation.spec.ts +212 -14
  361. package/test/credential-refresh-email.spec.ts +6 -10
  362. package/test/credential-refresh-endpoint.spec.ts +3 -0
  363. package/test/credential-refresh-publication.spec.ts +52 -15
  364. package/test/credential-storage.neo4j.spec.ts +33 -6
  365. package/test/helpers/legacy-autoboost.ts +48 -0
  366. package/test/holder-mode-send.spec.ts +710 -0
  367. package/test/inbox-refresh.spec.ts +105 -0
  368. package/test/inbox-security.e2e.ts +18 -22
  369. package/test/managed-status-revocation.spec.ts +970 -0
  370. package/test/notifications-worker.spec.ts +31 -25
  371. package/test/refresh-send.spec.ts +334 -5
  372. package/test/smart-resume-consent.spec.ts +1 -1
  373. package/test/verification/campaigns.ts +40 -0
  374. package/vitest.campaigns.config.ts +2 -0
  375. package/vitest.config.ts +14 -0
@@ -0,0 +1,432 @@
1
+ import { Boost, Credential, Profile } from '@models';
2
+ import { createContractCredentialRelationships } from '@accesslayer/credential/relationships/create';
3
+ import type { DbTermsType } from 'types/consentflowcontract';
4
+ import type { ProfileType } from 'types/profile';
5
+ import { minimalContract, minimalTerms, normalContract, normalFullTerms } from './helpers/contract';
6
+ import { testUnsignedBoost } from './helpers/send';
7
+ import { getUser } from './helpers/getClient';
8
+ import {
9
+ getContractTermsByUri,
10
+ getTransactionsForTerms,
11
+ } from '@accesslayer/consentflowcontract/relationships/read';
12
+ import {
13
+ getConsentFlowContractVersionRecord,
14
+ updateConsentFlowContractVersion,
15
+ } from '@accesslayer/consentflowcontract/versions';
16
+ import { getIdFromUri } from '@helpers/uri.helpers';
17
+ import { afterEach, describe, expect, it, vi } from 'vitest';
18
+ import { randomBytes, randomUUID } from 'node:crypto';
19
+ import { neogma } from '@instance';
20
+ import * as boostHelpers from '@helpers/boost.helpers';
21
+ import {
22
+ claimAutoBoostTransaction,
23
+ completeAutoBoostTransaction,
24
+ } from '@accesslayer/consentflowcontract/relationships/update';
25
+ describe('consent autoboost transaction claims', () => {
26
+ it('retains an initial delivery claim after sending begins and the outcome is unknown', async () => {
27
+ const owner = await getUser(randomBytes(32).toString('hex'));
28
+ const learner = await getUser(randomBytes(32).toString('hex'));
29
+ const ownerId = `ambiguous-owner-${randomBytes(5).toString('hex')}`;
30
+ const learnerId = `ambiguous-user-${randomBytes(5).toString('hex')}`;
31
+ profileIds.push(ownerId, learnerId);
32
+ await owner.clients.fullAuth.profile.createProfile({ profileId: ownerId });
33
+ await learner.clients.fullAuth.profile.createProfile({ profileId: learnerId });
34
+ await owner.clients.fullAuth.profile.registerSigningAuthority({
35
+ endpoint: 'http://localhost:5000/api',
36
+ name: 'mysa',
37
+ did: 'did:key:z6MkitsQTk2GDNYXAFckVcQHtC68S9j9ruVFYWrixM6RG5Mw',
38
+ });
39
+ const boostUri = await owner.clients.fullAuth.boost.createBoost({
40
+ credential: testUnsignedBoost,
41
+ category: 'Achievement',
42
+ name: 'Ambiguous delivery',
43
+ });
44
+ const boostId = getIdFromUri(boostUri);
45
+ boostIds.push(boostId);
46
+ const uri = await owner.clients.fullAuth.contracts.createConsentFlowContract({
47
+ name: 'Initial delivery claim',
48
+ contract: normalContract,
49
+ autoboosts: [
50
+ {
51
+ boostUri,
52
+ signingAuthority: { endpoint: 'http://localhost:5000/api', name: 'mysa' },
53
+ },
54
+ ],
55
+ });
56
+ const contractId = getIdFromUri(uri);
57
+ contractIds.push(contractId);
58
+ const sending = vi
59
+ .spyOn(boostHelpers, 'sendBoost')
60
+ .mockRejectedValueOnce(new Error('Delivery response was lost'));
61
+ try {
62
+ const { termsUri } = await learner.clients.fullAuth.contracts.consentToContract({
63
+ contractUri: uri,
64
+ terms: normalFullTerms,
65
+ });
66
+ const termsId = getIdFromUri(termsUri);
67
+ termsIds.push(termsId);
68
+ const claims = await neogma.queryRunner.run(
69
+ `MATCH (claim:ConsentFlowAutoBoostClaim {termsId:$termsId,boostId:$boostId})
70
+ RETURN claim.id AS id`,
71
+ { termsId, boostId }
72
+ );
73
+ expect(claims.records.map(record => record.get('id'))).toEqual([expect.any(String)]);
74
+ expect(await claimAutoBoostTransaction(contractId, termsId, boostId)).toBeNull();
75
+ expect(
76
+ (await getTransactionsForTerms(termsId, { limit: 25 })).filter(
77
+ tx => tx.action === 'write'
78
+ )
79
+ ).toEqual([]);
80
+ } finally {
81
+ sending.mockRestore();
82
+ }
83
+ });
84
+
85
+ const fixtureMarkers: string[] = [];
86
+ const contractIds: string[] = [];
87
+ const profileIds: string[] = [];
88
+ const termsIds: string[] = [];
89
+ const boostIds: string[] = [];
90
+
91
+ afterEach(async () => {
92
+ await neogma.queryRunner.run(
93
+ `MATCH (node) WHERE node.lcConsentTest IN $markers DETACH DELETE node`,
94
+ { markers: fixtureMarkers.splice(0) }
95
+ );
96
+ await neogma.queryRunner.run(
97
+ `MATCH (claim:ConsentFlowAutoBoostClaim) WHERE claim.termsId IN $ids DETACH DELETE claim`,
98
+ { ids: termsIds }
99
+ );
100
+ const ids = contractIds.splice(0);
101
+ await neogma.queryRunner.run(
102
+ `MATCH (event:ConsentFlowEvent) WHERE event.contractId IN $ids DETACH DELETE event`,
103
+ { ids }
104
+ );
105
+ await neogma.queryRunner.run(
106
+ `MATCH (contract:ConsentFlowContract) WHERE contract.id IN $ids
107
+ OPTIONAL MATCH (terms:ConsentFlowTerms)-[:CONSENTS_TO]->(contract)
108
+ OPTIONAL MATCH (terms)<-[:IS_FOR]-(transaction:ConsentFlowTransaction)
109
+ DETACH DELETE transaction, terms, contract`,
110
+ { ids }
111
+ );
112
+ termsIds.splice(0);
113
+ await neogma.queryRunner.run(
114
+ `MATCH (profile:Profile) WHERE profile.profileId IN $ids DETACH DELETE profile`,
115
+ { ids: profileIds.splice(0) }
116
+ );
117
+ await neogma.queryRunner.run(
118
+ `MATCH (boost:Boost) WHERE boost.id IN $ids
119
+ OPTIONAL MATCH (credential:Credential)-[:INSTANCE_OF]->(boost)
120
+ DETACH DELETE credential, boost`,
121
+ { ids: ['boost-identity', ...boostIds.splice(0)] }
122
+ );
123
+ });
124
+
125
+ const createConsent = async (
126
+ status: string,
127
+ version: number,
128
+ consentedVersion: number,
129
+ oneTime = false
130
+ ) => {
131
+ const contractId = randomUUID();
132
+ const termsId = randomUUID();
133
+ contractIds.push(contractId);
134
+ termsIds.push(termsId);
135
+ await neogma.queryRunner.run(
136
+ `CREATE (contract:ConsentFlowContract {id:$contractId, currentVersion:$version})
137
+ CREATE (terms:ConsentFlowTerms {id:$termsId, status:$status, consentedVersion:$consentedVersion, oneTime:$oneTime})
138
+ CREATE (terms)-[:CONSENTS_TO]->(contract)`,
139
+ { contractId, termsId, status, version, consentedVersion, oneTime }
140
+ );
141
+ return { contractId, termsId };
142
+ };
143
+
144
+ it('claims a terms/boost identity once under concurrency and records a write only after send', async () => {
145
+ const { contractId, termsId } = await createConsent('live', 1, 1);
146
+ const claims = await Promise.all(
147
+ Array.from({ length: 8 }, () =>
148
+ claimAutoBoostTransaction(contractId, termsId, 'boost-identity')
149
+ )
150
+ );
151
+ expect(claims.filter(Boolean)).toHaveLength(1);
152
+ const claimId = claims.find(Boolean)!;
153
+
154
+ const beforeCompletion = await neogma.queryRunner.run(
155
+ `MATCH (:ConsentFlowTerms {id:$termsId})<-[:IS_FOR]-(transaction:ConsentFlowTransaction)
156
+ RETURN count(transaction) AS count`,
157
+ { termsId }
158
+ );
159
+ expect(Number(beforeCompletion.records[0]?.get('count'))).toBe(0);
160
+ await neogma.queryRunner.run(
161
+ `CREATE (boost:Boost {id:'boost-identity'})
162
+ CREATE (credential:Credential {id:$credentialId, credential:'{}'})
163
+ CREATE (transaction:ConsentFlowTransaction {id:$transactionId, action:'write', date:'2026-01-01T00:00:00.000Z'})
164
+ WITH boost, credential, transaction
165
+ MATCH (terms:ConsentFlowTerms {id:$termsId})
166
+ CREATE (transaction)-[:IS_FOR]->(terms)
167
+ CREATE (credential)-[:ISSUED_VIA_TRANSACTION]->(transaction)
168
+ CREATE (credential)-[:INSTANCE_OF]->(boost)`,
169
+ { termsId, credentialId: randomUUID(), transactionId: randomUUID() }
170
+ );
171
+
172
+ await completeAutoBoostTransaction(claimId, termsId, 'boost-identity');
173
+ expect(await claimAutoBoostTransaction(contractId, termsId, 'boost-identity')).toBeNull();
174
+ const afterCompletion = await neogma.queryRunner.run(
175
+ `MATCH (:ConsentFlowTerms {id:$termsId})<-[:IS_FOR]-(transaction:ConsentFlowTransaction {boostId:'boost-identity'})
176
+ RETURN count(transaction) AS count`,
177
+ { termsId }
178
+ );
179
+ expect(Number(afterCompletion.records[0]?.get('count'))).toBe(1);
180
+ });
181
+
182
+ it.each(['needs_reconsent', 'suspended', 'consumed'] as const)(
183
+ 'does not claim autoboosts for %s consent',
184
+ async status => {
185
+ const { contractId, termsId } = await createConsent(status, 2, 1);
186
+ await expect(
187
+ claimAutoBoostTransaction(contractId, termsId, 'boost-identity')
188
+ ).resolves.toBeNull();
189
+ }
190
+ );
191
+ it.each(['update', 'reconsent'] as const)(
192
+ 'delivers a newly enabled one-time AutoBoost once through explicit %s',
193
+ async path => {
194
+ const owner = await getUser(randomBytes(32).toString('hex'));
195
+ const learner = await getUser(randomBytes(32).toString('hex'));
196
+ const ownerId = `autoboost-owner-${randomBytes(5).toString('hex')}`;
197
+ const learnerId = `autoboost-user-${randomBytes(5).toString('hex')}`;
198
+ profileIds.push(ownerId, learnerId);
199
+ await owner.clients.fullAuth.profile.createProfile({ profileId: ownerId });
200
+ await learner.clients.fullAuth.profile.createProfile({ profileId: learnerId });
201
+ await owner.clients.fullAuth.profile.registerSigningAuthority({
202
+ endpoint: 'http://localhost:5000/api',
203
+ name: 'mysa',
204
+ did: 'did:key:z6MkitsQTk2GDNYXAFckVcQHtC68S9j9ruVFYWrixM6RG5Mw',
205
+ });
206
+ const boostUri = await owner.clients.fullAuth.boost.createBoost({
207
+ credential: testUnsignedBoost,
208
+ category: 'Achievement',
209
+ name: 'One-time QA',
210
+ });
211
+ boostIds.push(getIdFromUri(boostUri));
212
+ const uri = await owner.clients.fullAuth.contracts.createConsentFlowContract({
213
+ name: 'One-time access QA',
214
+ contract: normalContract,
215
+ autoboosts: [
216
+ {
217
+ boostUri,
218
+ signingAuthority: { endpoint: 'http://localhost:5000/api', name: 'mysa' },
219
+ },
220
+ ],
221
+ });
222
+ contractIds.push(getIdFromUri(uri));
223
+ const initialTerms = structuredClone(normalFullTerms);
224
+ initialTerms.write.credentials.categories.Achievement = false;
225
+ const { termsUri } = await learner.clients.fullAuth.contracts.consentToContract({
226
+ contractUri: uri,
227
+ terms: initialTerms,
228
+ oneTime: path === 'reconsent',
229
+ });
230
+ termsIds.push(getIdFromUri(termsUri));
231
+ expect(
232
+ (await learner.clients.fullAuth.contracts.getCredentialsForContract({ termsUri }))
233
+ .records
234
+ ).toEqual([]);
235
+ for (let attempt = 0; attempt < 2; attempt += 1) {
236
+ if (path === 'update') {
237
+ const update = learner.clients.fullAuth.contracts.updateConsentedContractTerms({
238
+ uri: termsUri,
239
+ terms: normalFullTerms,
240
+ oneTime: true,
241
+ });
242
+ if (attempt === 0) await update;
243
+ else await expect(update).rejects.toMatchObject({ code: 'FORBIDDEN' });
244
+ } else {
245
+ const response = await learner.clients.fullAuth.contracts.consentToContract({
246
+ contractUri: uri,
247
+ terms: normalFullTerms,
248
+ oneTime: true,
249
+ });
250
+ expect(response.termsUri).toBe(termsUri);
251
+ }
252
+ const received = await learner.clients.fullAuth.contracts.getCredentialsForContract(
253
+ { termsUri }
254
+ );
255
+ expect(received.records.map(record => getIdFromUri(record.boostUri))).toEqual([
256
+ getIdFromUri(boostUri),
257
+ ]);
258
+ expect((await getContractTermsByUri(termsUri))?.terms.status).toBe('consumed');
259
+ }
260
+ const transactions =
261
+ await learner.clients.fullAuth.contracts.getTermsTransactionHistory({
262
+ uri: termsUri,
263
+ });
264
+ expect(
265
+ transactions.records.filter(transaction => transaction.action === 'write')
266
+ ).toHaveLength(1);
267
+ }
268
+ );
269
+
270
+ it('does not deliver a credential signed for v1 after consent becomes pending at v2', async () => {
271
+ const marker = randomUUID();
272
+ fixtureMarkers.push(marker);
273
+ const contractId = randomUUID();
274
+ const termsId = randomUUID();
275
+ const ownerId = randomUUID();
276
+ const recipientId = randomUUID();
277
+ const credentialId = randomUUID();
278
+ const boostId = randomUUID();
279
+ contractIds.push(contractId);
280
+ termsIds.push(termsId);
281
+
282
+ await neogma.queryRunner.run(
283
+ `CREATE (owner:Profile {profileId:$ownerId, lcConsentTest:$marker})
284
+ CREATE (recipient:Profile {profileId:$recipientId, lcConsentTest:$marker})
285
+ CREATE (contract:ConsentFlowContract {
286
+ id:$contractId, currentVersion:2, status:'active', lcConsentTest:$marker
287
+ })
288
+ CREATE (terms:ConsentFlowTerms {
289
+ id:$termsId, status:'needs_reconsent', consentedVersion:1,
290
+ expiresAt:'', \`terms.deniedWriters\`:[], lcConsentTest:$marker
291
+ })
292
+ CREATE (credential:Credential {id:$credentialId, credential:'{}', lcConsentTest:$marker})
293
+ CREATE (boost:Boost {id:$boostId, category:null, lcConsentTest:$marker})
294
+ CREATE (contract)-[:CREATED_BY]->(owner)
295
+ CREATE (contract)-[:CAN_WRITE]->(owner)
296
+ CREATE (recipient)-[:CREATED_BY]->(terms)
297
+ CREATE (terms)-[:CONSENTS_TO]->(contract)`,
298
+ { marker, contractId, termsId, ownerId, recipientId, credentialId, boostId }
299
+ );
300
+
301
+ const [owner, recipient, credential, boost] = await Promise.all([
302
+ Profile.findOne({ where: { profileId: ownerId } }),
303
+ Profile.findOne({ where: { profileId: recipientId } }),
304
+ Credential.findOne({ where: { id: credentialId } }),
305
+ Boost.findOne({ where: { id: boostId } }),
306
+ ]);
307
+ if (!owner || !recipient || !credential || !boost) {
308
+ throw new Error('Could not load persisted contract delivery fixtures');
309
+ }
310
+
311
+ await expect(
312
+ createContractCredentialRelationships({
313
+ // The fixture profile nodes only supply fields used by this helper.
314
+ issuer: { type: 'profile', profile: owner.dataValues as unknown as ProfileType },
315
+ writerProfileId: ownerId,
316
+ recipient: recipient.dataValues as unknown as ProfileType,
317
+ credential,
318
+ boost,
319
+ terms: { id: termsId, consentedVersion: 1 } as unknown as DbTermsType,
320
+ })
321
+ ).rejects.toMatchObject({ code: 'FORBIDDEN' });
322
+
323
+ const result = await neogma.queryRunner.run(
324
+ `MATCH (credential:Credential {id:$credentialId})
325
+ OPTIONAL MATCH (owner:Profile)-[sent:CREDENTIAL_SENT]->(credential)
326
+ OPTIONAL MATCH (credential)-[:INSTANCE_OF]->(boost:Boost)
327
+ OPTIONAL MATCH (credential)-[:ISSUED_VIA_TRANSACTION]->(transaction:ConsentFlowTransaction)
328
+ RETURN count(DISTINCT sent) AS sent, count(DISTINCT boost) AS instances,
329
+ count(DISTINCT transaction) AS transactions`,
330
+ { credentialId }
331
+ );
332
+ expect(Number(result.records[0]?.get('sent'))).toBe(0);
333
+ expect(Number(result.records[0]?.get('instances'))).toBe(0);
334
+ expect(Number(result.records[0]?.get('transactions'))).toBe(0);
335
+ await neogma.queryRunner.run(
336
+ `MATCH (terms:ConsentFlowTerms {id:$termsId})
337
+ SET terms.status = 'live', terms.consentedVersion = 2`,
338
+ { termsId }
339
+ );
340
+ await createContractCredentialRelationships({
341
+ issuer: { type: 'profile', profile: owner.dataValues as unknown as ProfileType },
342
+ writerProfileId: ownerId,
343
+ recipient: recipient.dataValues as unknown as ProfileType,
344
+ credential,
345
+ boost,
346
+ terms: { id: termsId, consentedVersion: 2 } as unknown as DbTermsType,
347
+ });
348
+ const delivered = await neogma.queryRunner.run(
349
+ `MATCH (:Profile {profileId:$ownerId})-[sent:CREDENTIAL_SENT]->(credential:Credential {id:$credentialId})
350
+ MATCH (credential)-[:INSTANCE_OF]->(:Boost {id:$boostId})
351
+ MATCH (credential)-[:ISSUED_VIA_TRANSACTION]->(transaction:ConsentFlowTransaction {action:'write'})
352
+ RETURN count(sent) AS deliveries, count(transaction) AS writes`,
353
+ { ownerId, credentialId, boostId }
354
+ );
355
+ expect(Number(delivered.records[0]?.get('deliveries'))).toBe(1);
356
+ expect(Number(delivered.records[0]?.get('writes'))).toBe(1);
357
+ });
358
+ it('advances guardian approval only for a quiet live migration and preserves its history', async () => {
359
+ const actor = await getUser(randomUUID().replaceAll('-', '').repeat(2));
360
+ const holder = await getUser(randomUUID().replaceAll('-', '').repeat(2));
361
+ const ownerProfileId = randomUUID();
362
+ const holderProfileId = randomUUID();
363
+ profileIds.push(ownerProfileId, holderProfileId);
364
+ await actor.clients.fullAuth.profile.createProfile({ profileId: ownerProfileId });
365
+ await holder.clients.fullAuth.profile.createProfile({ profileId: holderProfileId });
366
+ const uri = await actor.clients.fullAuth.contracts.createConsentFlowContract({
367
+ contract: minimalContract,
368
+ name: 'Guardian quiet migration regression',
369
+ });
370
+ const contractId = getIdFromUri(uri);
371
+ contractIds.push(contractId);
372
+ const { termsUri } = await holder.clients.fullAuth.contracts.consentToContract({
373
+ contractUri: uri,
374
+ terms: minimalTerms,
375
+ });
376
+ const relationship = await getContractTermsByUri(termsUri);
377
+ if (!relationship) throw new Error('Could not load persisted consent fixture');
378
+ const termsId = relationship.terms.id;
379
+ termsIds.push(termsId);
380
+ const version1 = await getConsentFlowContractVersionRecord(contractId, 1);
381
+ if (!version1) throw new Error('Could not load initial contract version');
382
+ const approval = {
383
+ guardianProfileId: randomUUID(),
384
+ guardianDid: `did:example:${randomUUID()}`,
385
+ approvedAt: new Date().toISOString(),
386
+ contractUpdatedAt: version1.createdAt,
387
+ };
388
+ await neogma.queryRunner.run(
389
+ `MATCH (terms:ConsentFlowTerms {id:$termsId})
390
+ SET terms['guardianApproval.guardianProfileId']=$guardianProfileId,
391
+ terms['guardianApproval.guardianDid']=$guardianDid,
392
+ terms['guardianApproval.approvedAt']=$approvedAt,
393
+ terms['guardianApproval.contractUpdatedAt']=$contractUpdatedAt
394
+ WITH terms
395
+ MATCH (transaction:ConsentFlowTransaction)-[:IS_FOR]->(terms)
396
+ WHERE transaction.action='consent'
397
+ SET transaction['guardianApproval.guardianProfileId']=$guardianProfileId,
398
+ transaction['guardianApproval.guardianDid']=$guardianDid,
399
+ transaction['guardianApproval.approvedAt']=$approvedAt,
400
+ transaction['guardianApproval.contractUpdatedAt']=$contractUpdatedAt`,
401
+ { termsId, ...approval }
402
+ );
403
+ const optionalCategoryContract = {
404
+ ...minimalContract,
405
+ write: {
406
+ ...minimalContract.write,
407
+ credentials: {
408
+ ...minimalContract.write.credentials,
409
+ categories: { OptionalAddition: { required: false } },
410
+ },
411
+ },
412
+ };
413
+ const updated = await updateConsentFlowContractVersion(
414
+ { uri, changes: { contract: optionalCategoryContract } },
415
+ ownerProfileId,
416
+ 'localhost'
417
+ );
418
+ expect(updated).toMatchObject({ version: 2, kind: 'expanded_optional' });
419
+ const version2 = await getConsentFlowContractVersionRecord(contractId, 2);
420
+ const after = await getContractTermsByUri(termsUri);
421
+ expect(after?.terms.status).toBe('live');
422
+ expect(after?.terms.guardianApproval).toEqual({
423
+ ...approval,
424
+ contractUpdatedAt: version2?.createdAt,
425
+ });
426
+ const history = await getTransactionsForTerms(termsId, { limit: 10 });
427
+ expect(
428
+ history.find(transaction => transaction.action === 'consent')?.guardianApproval
429
+ ).toEqual(approval);
430
+ expect(history.some(transaction => transaction.action === 'update')).toBe(true);
431
+ });
432
+ });