@wildo-ai/saas-backend-lib 1.1.1 → 1.1.3

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 (972) hide show
  1. package/dist/esm/applications/services/worker-remote-client-factory.backend.service.d.ts.map +1 -1
  2. package/dist/esm/applications/services/worker-remote-client-factory.backend.service.js +19 -1
  3. package/dist/esm/applications/services/worker-remote-client-factory.backend.service.js.map +1 -1
  4. package/dist/esm/base-classes/models/manual-controllers.backend.definition.d.ts.map +1 -1
  5. package/dist/esm/base-classes/models/manual-controllers.backend.definition.js +4 -0
  6. package/dist/esm/base-classes/models/manual-controllers.backend.definition.js.map +1 -1
  7. package/dist/esm/base-classes/services/batches/child-lifecycle-teardown.batch.backend.service.d.ts +35 -0
  8. package/dist/esm/base-classes/services/batches/child-lifecycle-teardown.batch.backend.service.d.ts.map +1 -0
  9. package/dist/esm/base-classes/services/batches/child-lifecycle-teardown.batch.backend.service.js +111 -0
  10. package/dist/esm/base-classes/services/batches/child-lifecycle-teardown.batch.backend.service.js.map +1 -0
  11. package/dist/esm/base-classes/services/batches/credential-expiry-sweep.batch.backend.service.d.ts +50 -0
  12. package/dist/esm/base-classes/services/batches/credential-expiry-sweep.batch.backend.service.d.ts.map +1 -0
  13. package/dist/esm/base-classes/services/batches/credential-expiry-sweep.batch.backend.service.js +199 -0
  14. package/dist/esm/base-classes/services/batches/credential-expiry-sweep.batch.backend.service.js.map +1 -0
  15. package/dist/esm/base-classes/services/batches/engine-custom-batch-manifests.d.ts +111 -0
  16. package/dist/esm/base-classes/services/batches/engine-custom-batch-manifests.d.ts.map +1 -1
  17. package/dist/esm/base-classes/services/batches/engine-custom-batch-manifests.js +140 -0
  18. package/dist/esm/base-classes/services/batches/engine-custom-batch-manifests.js.map +1 -1
  19. package/dist/esm/base-classes/services/controllers/controller-resource.backend.service.d.ts +14 -3
  20. package/dist/esm/base-classes/services/controllers/controller-resource.backend.service.d.ts.map +1 -1
  21. package/dist/esm/base-classes/services/controllers/controller-resource.backend.service.js +138 -24
  22. package/dist/esm/base-classes/services/controllers/controller-resource.backend.service.js.map +1 -1
  23. package/dist/esm/base-classes/services/controllers/controllers-registry-handler.backend.service.d.ts +3 -1
  24. package/dist/esm/base-classes/services/controllers/controllers-registry-handler.backend.service.d.ts.map +1 -1
  25. package/dist/esm/base-classes/services/controllers/controllers-registry-handler.backend.service.js +8 -3
  26. package/dist/esm/base-classes/services/controllers/controllers-registry-handler.backend.service.js.map +1 -1
  27. package/dist/esm/base-classes/services/repositories/field-clearing-partition.backend.d.ts +11 -0
  28. package/dist/esm/base-classes/services/repositories/field-clearing-partition.backend.d.ts.map +1 -1
  29. package/dist/esm/base-classes/services/repositories/field-clearing-partition.backend.js +11 -2
  30. package/dist/esm/base-classes/services/repositories/field-clearing-partition.backend.js.map +1 -1
  31. package/dist/esm/base-classes/services/repositories/http-api/http-api-provider-access.backend.d.ts +124 -13
  32. package/dist/esm/base-classes/services/repositories/http-api/http-api-provider-access.backend.d.ts.map +1 -1
  33. package/dist/esm/base-classes/services/repositories/http-api/http-api-provider-access.backend.js +207 -21
  34. package/dist/esm/base-classes/services/repositories/http-api/http-api-provider-access.backend.js.map +1 -1
  35. package/dist/esm/base-classes/services/repositories/http-api/http-api-read-client.backend.d.ts +60 -8
  36. package/dist/esm/base-classes/services/repositories/http-api/http-api-read-client.backend.d.ts.map +1 -1
  37. package/dist/esm/base-classes/services/repositories/http-api/http-api-read-client.backend.js +174 -26
  38. package/dist/esm/base-classes/services/repositories/http-api/http-api-read-client.backend.js.map +1 -1
  39. package/dist/esm/base-classes/services/repositories/http-api/http-api-resource-repository.backend.service.d.ts +48 -4
  40. package/dist/esm/base-classes/services/repositories/http-api/http-api-resource-repository.backend.service.d.ts.map +1 -1
  41. package/dist/esm/base-classes/services/repositories/http-api/http-api-resource-repository.backend.service.js +102 -30
  42. package/dist/esm/base-classes/services/repositories/http-api/http-api-resource-repository.backend.service.js.map +1 -1
  43. package/dist/esm/base-classes/services/repositories/http-api/http-api-rest-operation-reference.backend.d.ts +55 -0
  44. package/dist/esm/base-classes/services/repositories/http-api/http-api-rest-operation-reference.backend.d.ts.map +1 -0
  45. package/dist/esm/base-classes/services/repositories/http-api/http-api-rest-operation-reference.backend.js +114 -0
  46. package/dist/esm/base-classes/services/repositories/http-api/http-api-rest-operation-reference.backend.js.map +1 -0
  47. package/dist/esm/base-classes/services/repositories/http-api/http-api-transport.backend.d.ts +89 -14
  48. package/dist/esm/base-classes/services/repositories/http-api/http-api-transport.backend.d.ts.map +1 -1
  49. package/dist/esm/base-classes/services/repositories/http-api/http-api-transport.backend.js +84 -11
  50. package/dist/esm/base-classes/services/repositories/http-api/http-api-transport.backend.js.map +1 -1
  51. package/dist/esm/base-classes/services/repositories/http-api/odata-query-compiler.backend.d.ts.map +1 -1
  52. package/dist/esm/base-classes/services/repositories/http-api/odata-query-compiler.backend.js +16 -0
  53. package/dist/esm/base-classes/services/repositories/http-api/odata-query-compiler.backend.js.map +1 -1
  54. package/dist/esm/base-classes/services/repositories/infrastructure-tier-contract.backend.d.ts +20 -6
  55. package/dist/esm/base-classes/services/repositories/infrastructure-tier-contract.backend.d.ts.map +1 -1
  56. package/dist/esm/base-classes/services/repositories/infrastructure-tier-contract.backend.js +96 -32
  57. package/dist/esm/base-classes/services/repositories/infrastructure-tier-contract.backend.js.map +1 -1
  58. package/dist/esm/base-classes/services/repositories/introspection/introspection-resource-repository.backend.service.d.ts +3 -1
  59. package/dist/esm/base-classes/services/repositories/introspection/introspection-resource-repository.backend.service.d.ts.map +1 -1
  60. package/dist/esm/base-classes/services/repositories/introspection/introspection-resource-repository.backend.service.js +32 -7
  61. package/dist/esm/base-classes/services/repositories/introspection/introspection-resource-repository.backend.service.js.map +1 -1
  62. package/dist/esm/base-classes/services/repositories/introspection/introspection-resource-source.backend.port.d.ts +8 -5
  63. package/dist/esm/base-classes/services/repositories/introspection/introspection-resource-source.backend.port.d.ts.map +1 -1
  64. package/dist/esm/base-classes/services/repositories/introspection/introspection-resource-source.backend.port.js.map +1 -1
  65. package/dist/esm/base-classes/services/repositories/postgresql-resource-repository.backend.service.d.ts +80 -0
  66. package/dist/esm/base-classes/services/repositories/postgresql-resource-repository.backend.service.d.ts.map +1 -1
  67. package/dist/esm/base-classes/services/repositories/postgresql-resource-repository.backend.service.js +298 -23
  68. package/dist/esm/base-classes/services/repositories/postgresql-resource-repository.backend.service.js.map +1 -1
  69. package/dist/esm/base-classes/services/repositories/repositories-registry-handler.backend.service.d.ts +71 -1
  70. package/dist/esm/base-classes/services/repositories/repositories-registry-handler.backend.service.d.ts.map +1 -1
  71. package/dist/esm/base-classes/services/repositories/repositories-registry-handler.backend.service.js +85 -5
  72. package/dist/esm/base-classes/services/repositories/repositories-registry-handler.backend.service.js.map +1 -1
  73. package/dist/esm/base-classes/services/repositories/repository-resource.backend.service.d.ts +21 -0
  74. package/dist/esm/base-classes/services/repositories/repository-resource.backend.service.d.ts.map +1 -1
  75. package/dist/esm/base-classes/services/repositories/repository-resource.backend.service.js +146 -4
  76. package/dist/esm/base-classes/services/repositories/repository-resource.backend.service.js.map +1 -1
  77. package/dist/esm/base-classes/services/services/resource-operation-custom-implementation-base.backend.service.d.ts +22 -0
  78. package/dist/esm/base-classes/services/services/resource-operation-custom-implementation-base.backend.service.d.ts.map +1 -1
  79. package/dist/esm/base-classes/services/services/resource-operation-custom-implementation-base.backend.service.js.map +1 -1
  80. package/dist/esm/base-classes/services/services/resource-operation-implementation-coverage.backend.utils.d.ts +3 -26
  81. package/dist/esm/base-classes/services/services/resource-operation-implementation-coverage.backend.utils.d.ts.map +1 -1
  82. package/dist/esm/base-classes/services/services/resource-operation-implementation-coverage.backend.utils.js +3 -68
  83. package/dist/esm/base-classes/services/services/resource-operation-implementation-coverage.backend.utils.js.map +1 -1
  84. package/dist/esm/base-classes/services/services/resource-status-transition.custom-impl.backend.service.d.ts.map +1 -1
  85. package/dist/esm/base-classes/services/services/resource-status-transition.custom-impl.backend.service.js +4 -1
  86. package/dist/esm/base-classes/services/services/resource-status-transition.custom-impl.backend.service.js.map +1 -1
  87. package/dist/esm/base-classes/services/services/resource-status-transition.definitions.backend.d.ts +11 -0
  88. package/dist/esm/base-classes/services/services/resource-status-transition.definitions.backend.d.ts.map +1 -1
  89. package/dist/esm/base-classes/services/services/resource-status-transition.definitions.backend.js +39 -5
  90. package/dist/esm/base-classes/services/services/resource-status-transition.definitions.backend.js.map +1 -1
  91. package/dist/esm/base-classes/services/services/services-registry-handler.backend.service.d.ts +181 -2
  92. package/dist/esm/base-classes/services/services/services-registry-handler.backend.service.d.ts.map +1 -1
  93. package/dist/esm/base-classes/services/services/services-registry-handler.backend.service.js +533 -43
  94. package/dist/esm/base-classes/services/services/services-registry-handler.backend.service.js.map +1 -1
  95. package/dist/esm/base-classes/services/services/system-access.backend.service.d.ts +36 -3
  96. package/dist/esm/base-classes/services/services/system-access.backend.service.d.ts.map +1 -1
  97. package/dist/esm/base-classes/services/services/system-access.backend.service.js +70 -8
  98. package/dist/esm/base-classes/services/services/system-access.backend.service.js.map +1 -1
  99. package/dist/esm/billing/batches/billing-reconciliation.batch.backend.service.d.ts +28 -0
  100. package/dist/esm/billing/batches/billing-reconciliation.batch.backend.service.d.ts.map +1 -0
  101. package/dist/esm/billing/batches/billing-reconciliation.batch.backend.service.js +90 -0
  102. package/dist/esm/billing/batches/billing-reconciliation.batch.backend.service.js.map +1 -0
  103. package/dist/esm/billing/batches/usage-flush.batch.backend.service.d.ts +44 -0
  104. package/dist/esm/billing/batches/usage-flush.batch.backend.service.d.ts.map +1 -0
  105. package/dist/esm/billing/batches/usage-flush.batch.backend.service.js +99 -0
  106. package/dist/esm/billing/batches/usage-flush.batch.backend.service.js.map +1 -0
  107. package/dist/esm/billing/models/billing-provider-event-settlement.backend.schemas.d.ts +91 -0
  108. package/dist/esm/billing/models/billing-provider-event-settlement.backend.schemas.d.ts.map +1 -0
  109. package/dist/esm/billing/models/billing-provider-event-settlement.backend.schemas.js +152 -0
  110. package/dist/esm/billing/models/billing-provider-event-settlement.backend.schemas.js.map +1 -0
  111. package/dist/esm/billing/services/back-office/billing-reconciliation.backend.service.d.ts +186 -0
  112. package/dist/esm/billing/services/back-office/billing-reconciliation.backend.service.d.ts.map +1 -0
  113. package/dist/esm/billing/services/back-office/billing-reconciliation.backend.service.js +474 -0
  114. package/dist/esm/billing/services/back-office/billing-reconciliation.backend.service.js.map +1 -0
  115. package/dist/esm/billing/services/back-office/product-catalog-sync.backend.service.d.ts +100 -0
  116. package/dist/esm/billing/services/back-office/product-catalog-sync.backend.service.d.ts.map +1 -1
  117. package/dist/esm/billing/services/back-office/product-catalog-sync.backend.service.js +209 -6
  118. package/dist/esm/billing/services/back-office/product-catalog-sync.backend.service.js.map +1 -1
  119. package/dist/esm/billing/services/back-office/usage-metering.backend.service.d.ts +200 -4
  120. package/dist/esm/billing/services/back-office/usage-metering.backend.service.d.ts.map +1 -1
  121. package/dist/esm/billing/services/back-office/usage-metering.backend.service.js +593 -64
  122. package/dist/esm/billing/services/back-office/usage-metering.backend.service.js.map +1 -1
  123. package/dist/esm/billing/services/billing-adapter-registry.backend.d.ts +36 -0
  124. package/dist/esm/billing/services/billing-adapter-registry.backend.d.ts.map +1 -0
  125. package/dist/esm/billing/services/billing-adapter-registry.backend.js +83 -0
  126. package/dist/esm/billing/services/billing-adapter-registry.backend.js.map +1 -0
  127. package/dist/esm/billing/services/billing-checkout-metadata.backend.utils.d.ts +9 -0
  128. package/dist/esm/billing/services/billing-checkout-metadata.backend.utils.d.ts.map +1 -1
  129. package/dist/esm/billing/services/billing-checkout-metadata.backend.utils.js +11 -1
  130. package/dist/esm/billing/services/billing-checkout-metadata.backend.utils.js.map +1 -1
  131. package/dist/esm/billing/services/custom-impl/billing-account.mutations.custom-impl.backend.service.d.ts.map +1 -1
  132. package/dist/esm/billing/services/custom-impl/billing-account.mutations.custom-impl.backend.service.js +54 -13
  133. package/dist/esm/billing/services/custom-impl/billing-account.mutations.custom-impl.backend.service.js.map +1 -1
  134. package/dist/esm/billing/services/custom-impl/billing-custom-impl-utils.backend.d.ts +38 -1
  135. package/dist/esm/billing/services/custom-impl/billing-custom-impl-utils.backend.d.ts.map +1 -1
  136. package/dist/esm/billing/services/custom-impl/billing-custom-impl-utils.backend.js +67 -2
  137. package/dist/esm/billing/services/custom-impl/billing-custom-impl-utils.backend.js.map +1 -1
  138. package/dist/esm/billing/services/custom-impl/billing-custom-implementations.backend.d.ts +30 -1
  139. package/dist/esm/billing/services/custom-impl/billing-custom-implementations.backend.d.ts.map +1 -1
  140. package/dist/esm/billing/services/custom-impl/billing-custom-implementations.backend.js +43 -1
  141. package/dist/esm/billing/services/custom-impl/billing-custom-implementations.backend.js.map +1 -1
  142. package/dist/esm/billing/services/custom-impl/promotion.custom-ops.custom-impl.backend.service.d.ts +11 -3
  143. package/dist/esm/billing/services/custom-impl/promotion.custom-ops.custom-impl.backend.service.d.ts.map +1 -1
  144. package/dist/esm/billing/services/custom-impl/promotion.custom-ops.custom-impl.backend.service.js +30 -16
  145. package/dist/esm/billing/services/custom-impl/promotion.custom-ops.custom-impl.backend.service.js.map +1 -1
  146. package/dist/esm/billing/services/custom-impl/subscription.mutations.custom-impl.backend.service.d.ts.map +1 -1
  147. package/dist/esm/billing/services/custom-impl/subscription.mutations.custom-impl.backend.service.js +104 -25
  148. package/dist/esm/billing/services/custom-impl/subscription.mutations.custom-impl.backend.service.js.map +1 -1
  149. package/dist/esm/billing/services/stripe-standard-billing-provider.backend.service.d.ts +18 -1
  150. package/dist/esm/billing/services/stripe-standard-billing-provider.backend.service.d.ts.map +1 -1
  151. package/dist/esm/billing/services/stripe-standard-billing-provider.backend.service.js +106 -2
  152. package/dist/esm/billing/services/stripe-standard-billing-provider.backend.service.js.map +1 -1
  153. package/dist/esm/billing/services/webhooks/__tests__/settlement-ledger.test-double.d.ts +52 -0
  154. package/dist/esm/billing/services/webhooks/__tests__/settlement-ledger.test-double.d.ts.map +1 -0
  155. package/dist/esm/billing/services/webhooks/__tests__/settlement-ledger.test-double.js +74 -0
  156. package/dist/esm/billing/services/webhooks/__tests__/settlement-ledger.test-double.js.map +1 -0
  157. package/dist/esm/billing/services/webhooks/billing-webhook-event-router.backend.service.d.ts +104 -11
  158. package/dist/esm/billing/services/webhooks/billing-webhook-event-router.backend.service.d.ts.map +1 -1
  159. package/dist/esm/billing/services/webhooks/billing-webhook-event-router.backend.service.js +260 -26
  160. package/dist/esm/billing/services/webhooks/billing-webhook-event-router.backend.service.js.map +1 -1
  161. package/dist/esm/billing/testing/mock-billing-provider.d.ts +30 -1
  162. package/dist/esm/billing/testing/mock-billing-provider.d.ts.map +1 -1
  163. package/dist/esm/billing/testing/mock-billing-provider.js +25 -0
  164. package/dist/esm/billing/testing/mock-billing-provider.js.map +1 -1
  165. package/dist/esm/compliance/audit-trails/batches/audit-logs-archive.batch.backend.service.js +11 -4
  166. package/dist/esm/compliance/audit-trails/batches/audit-logs-archive.batch.backend.service.js.map +1 -1
  167. package/dist/esm/compliance/audit-trails/services/audit-event-dispatcher.backend.service.d.ts +263 -13
  168. package/dist/esm/compliance/audit-trails/services/audit-event-dispatcher.backend.service.d.ts.map +1 -1
  169. package/dist/esm/compliance/audit-trails/services/audit-event-dispatcher.backend.service.js +376 -58
  170. package/dist/esm/compliance/audit-trails/services/audit-event-dispatcher.backend.service.js.map +1 -1
  171. package/dist/esm/compliance/audit-trails/services/audit-logs.backend.service.d.ts +264 -7
  172. package/dist/esm/compliance/audit-trails/services/audit-logs.backend.service.d.ts.map +1 -1
  173. package/dist/esm/compliance/audit-trails/services/audit-logs.backend.service.js +414 -5
  174. package/dist/esm/compliance/audit-trails/services/audit-logs.backend.service.js.map +1 -1
  175. package/dist/esm/compliance/audit-trails/services/composite-audit-log-sink.backend.d.ts.map +1 -1
  176. package/dist/esm/compliance/audit-trails/services/composite-audit-log-sink.backend.js +7 -1
  177. package/dist/esm/compliance/audit-trails/services/composite-audit-log-sink.backend.js.map +1 -1
  178. package/dist/esm/compliance/audit-trails/services/siem-export-config-cache-invalidation.custom-impl.backend.service.d.ts +16 -0
  179. package/dist/esm/compliance/audit-trails/services/siem-export-config-cache-invalidation.custom-impl.backend.service.d.ts.map +1 -0
  180. package/dist/esm/compliance/audit-trails/services/siem-export-config-cache-invalidation.custom-impl.backend.service.js +140 -0
  181. package/dist/esm/compliance/audit-trails/services/siem-export-config-cache-invalidation.custom-impl.backend.service.js.map +1 -0
  182. package/dist/esm/compliance/audit-trails/services/siem-webhook-delivery.backend.service.d.ts +42 -0
  183. package/dist/esm/compliance/audit-trails/services/siem-webhook-delivery.backend.service.d.ts.map +1 -1
  184. package/dist/esm/compliance/audit-trails/services/siem-webhook-delivery.backend.service.js +65 -6
  185. package/dist/esm/compliance/audit-trails/services/siem-webhook-delivery.backend.service.js.map +1 -1
  186. package/dist/esm/compliance/audit-trails/services/utils/leased-value-cache.backend.utils.d.ts +110 -0
  187. package/dist/esm/compliance/audit-trails/services/utils/leased-value-cache.backend.utils.d.ts.map +1 -0
  188. package/dist/esm/compliance/audit-trails/services/utils/leased-value-cache.backend.utils.js +192 -0
  189. package/dist/esm/compliance/audit-trails/services/utils/leased-value-cache.backend.utils.js.map +1 -0
  190. package/dist/esm/compliance/audit-trails/services/utils/ocsf-activity-mapping.backend.utils.d.ts.map +1 -1
  191. package/dist/esm/compliance/audit-trails/services/utils/ocsf-activity-mapping.backend.utils.js +45 -0
  192. package/dist/esm/compliance/audit-trails/services/utils/ocsf-activity-mapping.backend.utils.js.map +1 -1
  193. package/dist/esm/config/bootstrap/application-runtime-profile.backend.d.ts +5 -0
  194. package/dist/esm/config/bootstrap/application-runtime-profile.backend.d.ts.map +1 -1
  195. package/dist/esm/config/bootstrap/application-runtime-profile.backend.js +6 -0
  196. package/dist/esm/config/bootstrap/application-runtime-profile.backend.js.map +1 -1
  197. package/dist/esm/config/custom/application-config-controller.backend.service.d.ts.map +1 -1
  198. package/dist/esm/config/custom/application-config-controller.backend.service.js +7 -1
  199. package/dist/esm/config/custom/application-config-controller.backend.service.js.map +1 -1
  200. package/dist/esm/config/models/app-config.backend.schemas.d.ts +146 -46
  201. package/dist/esm/config/models/app-config.backend.schemas.d.ts.map +1 -1
  202. package/dist/esm/config/models/app-config.backend.schemas.js +121 -12
  203. package/dist/esm/config/models/app-config.backend.schemas.js.map +1 -1
  204. package/dist/esm/config/models/provider-runtime-artifact.backend.schemas.d.ts +38 -15
  205. package/dist/esm/config/models/provider-runtime-artifact.backend.schemas.d.ts.map +1 -1
  206. package/dist/esm/config/models/provider-runtime-artifact.backend.schemas.js +17 -2
  207. package/dist/esm/config/models/provider-runtime-artifact.backend.schemas.js.map +1 -1
  208. package/dist/esm/config/services/app-configuration-loader.backend.service.d.ts +0 -1
  209. package/dist/esm/config/services/app-configuration-loader.backend.service.d.ts.map +1 -1
  210. package/dist/esm/config/services/app-configuration-loader.backend.service.js +68 -76
  211. package/dist/esm/config/services/app-configuration-loader.backend.service.js.map +1 -1
  212. package/dist/esm/config/services/app-configuration.backend.service.d.ts.map +1 -1
  213. package/dist/esm/config/services/app-configuration.backend.service.js +23 -1
  214. package/dist/esm/config/services/app-configuration.backend.service.js.map +1 -1
  215. package/dist/esm/config/services/app-configuration.backend.utils.d.ts +43 -1
  216. package/dist/esm/config/services/app-configuration.backend.utils.d.ts.map +1 -1
  217. package/dist/esm/config/services/app-configuration.backend.utils.js +52 -3
  218. package/dist/esm/config/services/app-configuration.backend.utils.js.map +1 -1
  219. package/dist/esm/config/services/application-startup-config-validator.backend.service.d.ts +25 -0
  220. package/dist/esm/config/services/application-startup-config-validator.backend.service.d.ts.map +1 -1
  221. package/dist/esm/config/services/application-startup-config-validator.backend.service.js +41 -1
  222. package/dist/esm/config/services/application-startup-config-validator.backend.service.js.map +1 -1
  223. package/dist/esm/data-seeding/services/shared/data-seed-scope-iteration.shared.utils.d.ts +2 -2
  224. package/dist/esm/data-seeding/services/shared/data-seed-scope-iteration.shared.utils.js +2 -2
  225. package/dist/esm/data-seeding/services/shared/data-seed-scope-iteration.shared.utils.js.map +1 -1
  226. package/dist/esm/databases/models/filter.backend.schemas.js +2 -2
  227. package/dist/esm/databases/models/filter.backend.schemas.js.map +1 -1
  228. package/dist/esm/databases/services/aggregation/aggregation-authorization.backend.service.d.ts.map +1 -1
  229. package/dist/esm/databases/services/aggregation/aggregation-authorization.backend.service.js +20 -1
  230. package/dist/esm/databases/services/aggregation/aggregation-authorization.backend.service.js.map +1 -1
  231. package/dist/esm/databases/services/postgresql-schema-plan-diff.backend.d.ts.map +1 -1
  232. package/dist/esm/databases/services/postgresql-schema-plan-diff.backend.js +48 -0
  233. package/dist/esm/databases/services/postgresql-schema-plan-diff.backend.js.map +1 -1
  234. package/dist/esm/databases/services/redis.service.d.ts +27 -0
  235. package/dist/esm/databases/services/redis.service.d.ts.map +1 -1
  236. package/dist/esm/databases/services/redis.service.js +29 -0
  237. package/dist/esm/databases/services/redis.service.js.map +1 -1
  238. package/dist/esm/errors/services/error-builder.backend.service.d.ts +13 -1
  239. package/dist/esm/errors/services/error-builder.backend.service.d.ts.map +1 -1
  240. package/dist/esm/errors/services/error-builder.backend.service.js +13 -1
  241. package/dist/esm/errors/services/error-builder.backend.service.js.map +1 -1
  242. package/dist/esm/errors/services/error-handler.backend.service.d.ts +70 -7
  243. package/dist/esm/errors/services/error-handler.backend.service.d.ts.map +1 -1
  244. package/dist/esm/errors/services/error-handler.backend.service.js +134 -8
  245. package/dist/esm/errors/services/error-handler.backend.service.js.map +1 -1
  246. package/dist/esm/errors/services/rate-limit.backend.service.d.ts +66 -0
  247. package/dist/esm/errors/services/rate-limit.backend.service.d.ts.map +1 -1
  248. package/dist/esm/errors/services/rate-limit.backend.service.js +102 -25
  249. package/dist/esm/errors/services/rate-limit.backend.service.js.map +1 -1
  250. package/dist/esm/errors/utils/error-log-level-classification.backend.utils.d.ts +5 -0
  251. package/dist/esm/errors/utils/error-log-level-classification.backend.utils.d.ts.map +1 -1
  252. package/dist/esm/errors/utils/error-log-level-classification.backend.utils.js +25 -0
  253. package/dist/esm/errors/utils/error-log-level-classification.backend.utils.js.map +1 -1
  254. package/dist/esm/errors/utils/rate-limit-environment-relaxation.backend.utils.d.ts +33 -0
  255. package/dist/esm/errors/utils/rate-limit-environment-relaxation.backend.utils.d.ts.map +1 -1
  256. package/dist/esm/errors/utils/rate-limit-environment-relaxation.backend.utils.js +40 -0
  257. package/dist/esm/errors/utils/rate-limit-environment-relaxation.backend.utils.js.map +1 -1
  258. package/dist/esm/external-data/controllers/external-data-admin.backend.contracts.d.ts +41 -0
  259. package/dist/esm/external-data/controllers/external-data-admin.backend.contracts.d.ts.map +1 -0
  260. package/dist/esm/external-data/controllers/external-data-admin.backend.contracts.js +40 -0
  261. package/dist/esm/external-data/controllers/external-data-admin.backend.contracts.js.map +1 -0
  262. package/dist/esm/external-data/controllers/external-data-admin.backend.controller.d.ts +64 -0
  263. package/dist/esm/external-data/controllers/external-data-admin.backend.controller.d.ts.map +1 -0
  264. package/dist/esm/external-data/controllers/external-data-admin.backend.controller.js +193 -0
  265. package/dist/esm/external-data/controllers/external-data-admin.backend.controller.js.map +1 -0
  266. package/dist/esm/external-data/external-data-pipeline-run.backend.service.d.ts +72 -4
  267. package/dist/esm/external-data/external-data-pipeline-run.backend.service.d.ts.map +1 -1
  268. package/dist/esm/external-data/external-data-pipeline-run.backend.service.js +60 -19
  269. package/dist/esm/external-data/external-data-pipeline-run.backend.service.js.map +1 -1
  270. package/dist/esm/external-data/external-data-transform.backend.d.ts.map +1 -1
  271. package/dist/esm/external-data/external-data-transform.backend.js +7 -1
  272. package/dist/esm/external-data/external-data-transform.backend.js.map +1 -1
  273. package/dist/esm/external-data/models/external-data-pipeline-state.backend.schemas.d.ts +2 -0
  274. package/dist/esm/external-data/models/external-data-pipeline-state.backend.schemas.d.ts.map +1 -1
  275. package/dist/esm/external-data/models/external-data-pipeline-state.backend.schemas.js +13 -0
  276. package/dist/esm/external-data/models/external-data-pipeline-state.backend.schemas.js.map +1 -1
  277. package/dist/esm/external-providers/models/provider-selection-resolution-evidence.backend.definitions.d.ts +4 -2
  278. package/dist/esm/external-providers/models/provider-selection-resolution-evidence.backend.definitions.d.ts.map +1 -1
  279. package/dist/esm/external-providers/models/provider-selection-resolution-evidence.backend.definitions.js.map +1 -1
  280. package/dist/esm/external-providers/operations/provider-operation-executor.backend.service.d.ts +256 -0
  281. package/dist/esm/external-providers/operations/provider-operation-executor.backend.service.d.ts.map +1 -0
  282. package/dist/esm/external-providers/operations/provider-operation-executor.backend.service.js +333 -0
  283. package/dist/esm/external-providers/operations/provider-operation-executor.backend.service.js.map +1 -0
  284. package/dist/esm/external-providers/operations/provider-operation-request.backend.d.ts +56 -0
  285. package/dist/esm/external-providers/operations/provider-operation-request.backend.d.ts.map +1 -0
  286. package/dist/esm/external-providers/operations/provider-operation-request.backend.js +211 -0
  287. package/dist/esm/external-providers/operations/provider-operation-request.backend.js.map +1 -0
  288. package/dist/esm/external-providers/operations/provider-request-signing.backend.d.ts +45 -0
  289. package/dist/esm/external-providers/operations/provider-request-signing.backend.d.ts.map +1 -0
  290. package/dist/esm/external-providers/operations/provider-request-signing.backend.js +216 -0
  291. package/dist/esm/external-providers/operations/provider-request-signing.backend.js.map +1 -0
  292. package/dist/esm/external-providers/operations/provider-rest-call-client.backend.d.ts +56 -0
  293. package/dist/esm/external-providers/operations/provider-rest-call-client.backend.d.ts.map +1 -0
  294. package/dist/esm/external-providers/operations/provider-rest-call-client.backend.js +78 -0
  295. package/dist/esm/external-providers/operations/provider-rest-call-client.backend.js.map +1 -0
  296. package/dist/esm/external-providers/services/__tests__/mock-external-providers-registry.service.d.ts +1 -1
  297. package/dist/esm/external-providers/services/__tests__/mock-external-providers-registry.service.d.ts.map +1 -1
  298. package/dist/esm/external-providers/services/__tests__/mock-external-providers-registry.service.js +2 -2
  299. package/dist/esm/external-providers/services/__tests__/mock-external-providers-registry.service.js.map +1 -1
  300. package/dist/esm/external-providers/services/backend-provider-loader.backend.service.d.ts +89 -0
  301. package/dist/esm/external-providers/services/backend-provider-loader.backend.service.d.ts.map +1 -0
  302. package/dist/esm/external-providers/services/backend-provider-loader.backend.service.js +164 -0
  303. package/dist/esm/external-providers/services/backend-provider-loader.backend.service.js.map +1 -0
  304. package/dist/esm/external-providers/services/backend-provider-registry.backend.service.d.ts +26 -27
  305. package/dist/esm/external-providers/services/backend-provider-registry.backend.service.d.ts.map +1 -1
  306. package/dist/esm/external-providers/services/backend-provider-registry.backend.service.js +50 -64
  307. package/dist/esm/external-providers/services/backend-provider-registry.backend.service.js.map +1 -1
  308. package/dist/esm/external-providers/services/document-extraction.backend.service.d.ts.map +1 -1
  309. package/dist/esm/external-providers/services/document-extraction.backend.service.js +3 -3
  310. package/dist/esm/external-providers/services/document-extraction.backend.service.js.map +1 -1
  311. package/dist/esm/external-providers/services/embeddings.backend.service.d.ts.map +1 -1
  312. package/dist/esm/external-providers/services/embeddings.backend.service.js +4 -4
  313. package/dist/esm/external-providers/services/embeddings.backend.service.js.map +1 -1
  314. package/dist/esm/external-providers/services/external-providers-registry.backend.service.d.ts +306 -7
  315. package/dist/esm/external-providers/services/external-providers-registry.backend.service.d.ts.map +1 -1
  316. package/dist/esm/external-providers/services/external-providers-registry.backend.service.js +539 -45
  317. package/dist/esm/external-providers/services/external-providers-registry.backend.service.js.map +1 -1
  318. package/dist/esm/external-providers/services/frontend-bootstrap.backend.service.d.ts.map +1 -1
  319. package/dist/esm/external-providers/services/frontend-bootstrap.backend.service.js +25 -2
  320. package/dist/esm/external-providers/services/frontend-bootstrap.backend.service.js.map +1 -1
  321. package/dist/esm/files/controllers/file.controller.d.ts +24 -1
  322. package/dist/esm/files/controllers/file.controller.d.ts.map +1 -1
  323. package/dist/esm/files/controllers/file.controller.js +83 -11
  324. package/dist/esm/files/controllers/file.controller.js.map +1 -1
  325. package/dist/esm/files/handlers/file-upload-route-locals.backend.types.d.ts +17 -0
  326. package/dist/esm/files/handlers/file-upload-route-locals.backend.types.d.ts.map +1 -0
  327. package/dist/esm/files/handlers/file-upload-route-locals.backend.types.js +1 -0
  328. package/dist/esm/files/handlers/file-upload-route-locals.backend.types.js.map +1 -0
  329. package/dist/esm/files/handlers/resource-file-upload-handler.backend.service.d.ts +5 -1
  330. package/dist/esm/files/handlers/resource-file-upload-handler.backend.service.d.ts.map +1 -1
  331. package/dist/esm/files/handlers/resource-file-upload-handler.backend.service.js +76 -13
  332. package/dist/esm/files/handlers/resource-file-upload-handler.backend.service.js.map +1 -1
  333. package/dist/esm/files/services/file-operation-handler.backend.service.d.ts +18 -0
  334. package/dist/esm/files/services/file-operation-handler.backend.service.d.ts.map +1 -1
  335. package/dist/esm/files/services/file-operation-handler.backend.service.js +36 -28
  336. package/dist/esm/files/services/file-operation-handler.backend.service.js.map +1 -1
  337. package/dist/esm/files/services/file-scanning.backend.service.d.ts +94 -9
  338. package/dist/esm/files/services/file-scanning.backend.service.d.ts.map +1 -1
  339. package/dist/esm/files/services/file-scanning.backend.service.js +197 -17
  340. package/dist/esm/files/services/file-scanning.backend.service.js.map +1 -1
  341. package/dist/esm/files/services/file-text-extraction.backend.service.d.ts +60 -1
  342. package/dist/esm/files/services/file-text-extraction.backend.service.d.ts.map +1 -1
  343. package/dist/esm/files/services/file-text-extraction.backend.service.js +167 -8
  344. package/dist/esm/files/services/file-text-extraction.backend.service.js.map +1 -1
  345. package/dist/esm/files/services/file-upload-grant.backend.service.d.ts +214 -0
  346. package/dist/esm/files/services/file-upload-grant.backend.service.d.ts.map +1 -0
  347. package/dist/esm/files/services/file-upload-grant.backend.service.js +566 -0
  348. package/dist/esm/files/services/file-upload-grant.backend.service.js.map +1 -0
  349. package/dist/esm/files/services/files.backend.service.d.ts +87 -0
  350. package/dist/esm/files/services/files.backend.service.d.ts.map +1 -1
  351. package/dist/esm/files/services/files.backend.service.js +252 -19
  352. package/dist/esm/files/services/files.backend.service.js.map +1 -1
  353. package/dist/esm/files/storage/application-storage-key.backend.utils.d.ts +109 -0
  354. package/dist/esm/files/storage/application-storage-key.backend.utils.d.ts.map +1 -0
  355. package/dist/esm/files/storage/application-storage-key.backend.utils.js +123 -0
  356. package/dist/esm/files/storage/application-storage-key.backend.utils.js.map +1 -0
  357. package/dist/esm/files/storage/file-storage-provider.types.d.ts +16 -10
  358. package/dist/esm/files/storage/file-storage-provider.types.d.ts.map +1 -1
  359. package/dist/esm/files/storage/file-storage-provider.types.js.map +1 -1
  360. package/dist/esm/files/storage/local-directory-storage-provider.backend.service.d.ts +67 -8
  361. package/dist/esm/files/storage/local-directory-storage-provider.backend.service.d.ts.map +1 -1
  362. package/dist/esm/files/storage/local-directory-storage-provider.backend.service.js +101 -28
  363. package/dist/esm/files/storage/local-directory-storage-provider.backend.service.js.map +1 -1
  364. package/dist/esm/files/storage/wildo-managed-storage-provider.backend.service.d.ts.map +1 -1
  365. package/dist/esm/files/storage/wildo-managed-storage-provider.backend.service.js +8 -55
  366. package/dist/esm/files/storage/wildo-managed-storage-provider.backend.service.js.map +1 -1
  367. package/dist/esm/files/utils/file-field-schema-path.backend.utils.d.ts.map +1 -1
  368. package/dist/esm/files/utils/file-field-schema-path.backend.utils.js +20 -0
  369. package/dist/esm/files/utils/file-field-schema-path.backend.utils.js.map +1 -1
  370. package/dist/esm/files/utils/file-uploader.utils.d.ts.map +1 -1
  371. package/dist/esm/files/utils/file-uploader.utils.js +12 -0
  372. package/dist/esm/files/utils/file-uploader.utils.js.map +1 -1
  373. package/dist/esm/files/utils/office-document-text-extraction.backend.utils.d.ts +86 -0
  374. package/dist/esm/files/utils/office-document-text-extraction.backend.utils.d.ts.map +1 -0
  375. package/dist/esm/files/utils/office-document-text-extraction.backend.utils.js +288 -0
  376. package/dist/esm/files/utils/office-document-text-extraction.backend.utils.js.map +1 -0
  377. package/dist/esm/flows-actors/a2a/batches/a2a-abandoned-task-sweep.batch.backend.service.d.ts +15 -0
  378. package/dist/esm/flows-actors/a2a/batches/a2a-abandoned-task-sweep.batch.backend.service.d.ts.map +1 -1
  379. package/dist/esm/flows-actors/a2a/batches/a2a-abandoned-task-sweep.batch.backend.service.js +76 -5
  380. package/dist/esm/flows-actors/a2a/batches/a2a-abandoned-task-sweep.batch.backend.service.js.map +1 -1
  381. package/dist/esm/flows-actors/a2a/controllers/a2a.controller.d.ts.map +1 -1
  382. package/dist/esm/flows-actors/a2a/controllers/a2a.controller.js +6 -1
  383. package/dist/esm/flows-actors/a2a/controllers/a2a.controller.js.map +1 -1
  384. package/dist/esm/flows-actors/a2a/models/a2a.backend.schemas.d.ts +60 -0
  385. package/dist/esm/flows-actors/a2a/models/a2a.backend.schemas.d.ts.map +1 -1
  386. package/dist/esm/flows-actors/a2a/models/a2a.backend.schemas.js +63 -0
  387. package/dist/esm/flows-actors/a2a/models/a2a.backend.schemas.js.map +1 -1
  388. package/dist/esm/flows-actors/a2a/services/a2a-task-cancellation.backend.service.d.ts +74 -0
  389. package/dist/esm/flows-actors/a2a/services/a2a-task-cancellation.backend.service.d.ts.map +1 -1
  390. package/dist/esm/flows-actors/a2a/services/a2a-task-cancellation.backend.service.js +200 -44
  391. package/dist/esm/flows-actors/a2a/services/a2a-task-cancellation.backend.service.js.map +1 -1
  392. package/dist/esm/flows-actors/a2a/services/a2a-task.backend.service.d.ts +7 -1
  393. package/dist/esm/flows-actors/a2a/services/a2a-task.backend.service.d.ts.map +1 -1
  394. package/dist/esm/flows-actors/a2a/services/a2a-task.backend.service.js +53 -1
  395. package/dist/esm/flows-actors/a2a/services/a2a-task.backend.service.js.map +1 -1
  396. package/dist/esm/flows-actors/a2a/services/a2a-token-budget.backend.service.d.ts +18 -0
  397. package/dist/esm/flows-actors/a2a/services/a2a-token-budget.backend.service.d.ts.map +1 -1
  398. package/dist/esm/flows-actors/a2a/services/a2a-token-budget.backend.service.js +18 -0
  399. package/dist/esm/flows-actors/a2a/services/a2a-token-budget.backend.service.js.map +1 -1
  400. package/dist/esm/flows-actors/a2a/services/a2a.backend.service.d.ts +12 -7
  401. package/dist/esm/flows-actors/a2a/services/a2a.backend.service.d.ts.map +1 -1
  402. package/dist/esm/flows-actors/a2a/services/a2a.backend.service.js.map +1 -1
  403. package/dist/esm/flows-actors/models/agent-catalogs.backend.definitions.d.ts +0 -13
  404. package/dist/esm/flows-actors/models/agent-catalogs.backend.definitions.d.ts.map +1 -1
  405. package/dist/esm/flows-actors/models/agent-catalogs.backend.definitions.js +14 -22
  406. package/dist/esm/flows-actors/models/agent-catalogs.backend.definitions.js.map +1 -1
  407. package/dist/esm/flows-actors/models/core-facets.backend.definitions.d.ts +8 -3
  408. package/dist/esm/flows-actors/models/core-facets.backend.definitions.d.ts.map +1 -1
  409. package/dist/esm/flows-actors/models/core-facets.backend.definitions.js +25 -15
  410. package/dist/esm/flows-actors/models/core-facets.backend.definitions.js.map +1 -1
  411. package/dist/esm/flows-actors/models/flows-actors.backend.schemas.d.ts +13 -1
  412. package/dist/esm/flows-actors/models/flows-actors.backend.schemas.d.ts.map +1 -1
  413. package/dist/esm/flows-actors/models/flows-actors.backend.schemas.js.map +1 -1
  414. package/dist/esm/flows-actors/models/function-tools.backend.definitions.d.ts +88 -8
  415. package/dist/esm/flows-actors/models/function-tools.backend.definitions.d.ts.map +1 -1
  416. package/dist/esm/flows-actors/models/function-tools.backend.definitions.js +333 -31
  417. package/dist/esm/flows-actors/models/function-tools.backend.definitions.js.map +1 -1
  418. package/dist/esm/flows-actors/models/market-generation.actors-system.backend.definitions.d.ts.map +1 -1
  419. package/dist/esm/flows-actors/models/market-generation.actors-system.backend.definitions.js +4 -2
  420. package/dist/esm/flows-actors/models/market-generation.actors-system.backend.definitions.js.map +1 -1
  421. package/dist/esm/flows-actors/models/mcp-client.backend.definitions.d.ts +113 -0
  422. package/dist/esm/flows-actors/models/mcp-client.backend.definitions.d.ts.map +1 -0
  423. package/dist/esm/flows-actors/models/mcp-client.backend.definitions.js +62 -0
  424. package/dist/esm/flows-actors/models/mcp-client.backend.definitions.js.map +1 -0
  425. package/dist/esm/flows-actors/services/actors-system.backend.service.d.ts.map +1 -1
  426. package/dist/esm/flows-actors/services/actors-system.backend.service.js +0 -2
  427. package/dist/esm/flows-actors/services/actors-system.backend.service.js.map +1 -1
  428. package/dist/esm/flows-actors/services/agents.backend.service.d.ts +107 -1
  429. package/dist/esm/flows-actors/services/agents.backend.service.d.ts.map +1 -1
  430. package/dist/esm/flows-actors/services/agents.backend.service.js +519 -56
  431. package/dist/esm/flows-actors/services/agents.backend.service.js.map +1 -1
  432. package/dist/esm/flows-actors/services/conversational-execution.backend.service.d.ts +5 -1
  433. package/dist/esm/flows-actors/services/conversational-execution.backend.service.d.ts.map +1 -1
  434. package/dist/esm/flows-actors/services/conversational-execution.backend.service.js +79 -16
  435. package/dist/esm/flows-actors/services/conversational-execution.backend.service.js.map +1 -1
  436. package/dist/esm/flows-actors/services/flows-actors-registry.service.d.ts +34 -5
  437. package/dist/esm/flows-actors/services/flows-actors-registry.service.d.ts.map +1 -1
  438. package/dist/esm/flows-actors/services/flows-actors-registry.service.js +154 -20
  439. package/dist/esm/flows-actors/services/flows-actors-registry.service.js.map +1 -1
  440. package/dist/esm/flows-actors/services/flows.backend.services.d.ts.map +1 -1
  441. package/dist/esm/flows-actors/services/flows.backend.services.js +27 -23
  442. package/dist/esm/flows-actors/services/flows.backend.services.js.map +1 -1
  443. package/dist/esm/flows-actors/services/llm-observability-agent-call-trace-sink.backend.d.ts.map +1 -1
  444. package/dist/esm/flows-actors/services/llm-observability-agent-call-trace-sink.backend.js +7 -1
  445. package/dist/esm/flows-actors/services/llm-observability-agent-call-trace-sink.backend.js.map +1 -1
  446. package/dist/esm/flows-actors/services/mcp-client.backend.service.d.ts +90 -0
  447. package/dist/esm/flows-actors/services/mcp-client.backend.service.d.ts.map +1 -0
  448. package/dist/esm/flows-actors/services/mcp-client.backend.service.js +368 -0
  449. package/dist/esm/flows-actors/services/mcp-client.backend.service.js.map +1 -0
  450. package/dist/esm/flows-actors/services/prompt-compiler.backend.service.d.ts +9 -5
  451. package/dist/esm/flows-actors/services/prompt-compiler.backend.service.d.ts.map +1 -1
  452. package/dist/esm/flows-actors/services/prompt-compiler.backend.service.js +12 -17
  453. package/dist/esm/flows-actors/services/prompt-compiler.backend.service.js.map +1 -1
  454. package/dist/esm/flows-actors/utils/acp-session-runner.backend.utils.d.ts +151 -41
  455. package/dist/esm/flows-actors/utils/acp-session-runner.backend.utils.d.ts.map +1 -1
  456. package/dist/esm/flows-actors/utils/acp-session-runner.backend.utils.js +308 -143
  457. package/dist/esm/flows-actors/utils/acp-session-runner.backend.utils.js.map +1 -1
  458. package/dist/esm/flows-actors/utils/meta-workflow-canonical-json.backend.utils.d.ts +0 -207
  459. package/dist/esm/flows-actors/utils/meta-workflow-canonical-json.backend.utils.d.ts.map +1 -1
  460. package/dist/esm/flows-actors/utils/meta-workflow-canonical-json.backend.utils.js +8 -243
  461. package/dist/esm/flows-actors/utils/meta-workflow-canonical-json.backend.utils.js.map +1 -1
  462. package/dist/esm/flows-actors/utils/meta-workflow-structured-generation-plan.backend.utils.d.ts.map +1 -1
  463. package/dist/esm/flows-actors/utils/meta-workflow-structured-generation-plan.backend.utils.js.map +1 -1
  464. package/dist/esm/guidance/services/milestone-evaluator.backend.service.d.ts +9 -14
  465. package/dist/esm/guidance/services/milestone-evaluator.backend.service.d.ts.map +1 -1
  466. package/dist/esm/guidance/services/milestone-evaluator.backend.service.js +18 -89
  467. package/dist/esm/guidance/services/milestone-evaluator.backend.service.js.map +1 -1
  468. package/dist/esm/guidance/services/progression-state-store.backend.service.d.ts +86 -0
  469. package/dist/esm/guidance/services/progression-state-store.backend.service.d.ts.map +1 -0
  470. package/dist/esm/guidance/services/progression-state-store.backend.service.js +155 -0
  471. package/dist/esm/guidance/services/progression-state-store.backend.service.js.map +1 -0
  472. package/dist/esm/i18n/controllers/i18n-controller.backend.service.d.ts +10 -0
  473. package/dist/esm/i18n/controllers/i18n-controller.backend.service.d.ts.map +1 -1
  474. package/dist/esm/i18n/controllers/i18n-controller.backend.service.js +55 -5
  475. package/dist/esm/i18n/controllers/i18n-controller.backend.service.js.map +1 -1
  476. package/dist/esm/index.d.ts +15 -5
  477. package/dist/esm/index.d.ts.map +1 -1
  478. package/dist/esm/index.js +45 -5
  479. package/dist/esm/index.js.map +1 -1
  480. package/dist/esm/inject/models/container.d.ts.map +1 -1
  481. package/dist/esm/inject/models/container.js +82 -10
  482. package/dist/esm/inject/models/container.js.map +1 -1
  483. package/dist/esm/inject/models/service-types.d.ts +20 -3
  484. package/dist/esm/inject/models/service-types.d.ts.map +1 -1
  485. package/dist/esm/inject/models/service-types.js +21 -3
  486. package/dist/esm/inject/models/service-types.js.map +1 -1
  487. package/dist/esm/mcp/controllers/mcp.controller.d.ts.map +1 -1
  488. package/dist/esm/mcp/controllers/mcp.controller.js +32 -4
  489. package/dist/esm/mcp/controllers/mcp.controller.js.map +1 -1
  490. package/dist/esm/mcp/models/mcp-tool.backend.schemas.d.ts +34 -0
  491. package/dist/esm/mcp/models/mcp-tool.backend.schemas.d.ts.map +1 -1
  492. package/dist/esm/mcp/models/mcp-tool.backend.schemas.js +42 -0
  493. package/dist/esm/mcp/models/mcp-tool.backend.schemas.js.map +1 -1
  494. package/dist/esm/mcp/services/mcp-server.backend.service.d.ts +84 -1
  495. package/dist/esm/mcp/services/mcp-server.backend.service.d.ts.map +1 -1
  496. package/dist/esm/mcp/services/mcp-server.backend.service.js +235 -11
  497. package/dist/esm/mcp/services/mcp-server.backend.service.js.map +1 -1
  498. package/dist/esm/mcp/services/mcp-tool-adapter.backend.service.d.ts +64 -2
  499. package/dist/esm/mcp/services/mcp-tool-adapter.backend.service.d.ts.map +1 -1
  500. package/dist/esm/mcp/services/mcp-tool-adapter.backend.service.js +152 -6
  501. package/dist/esm/mcp/services/mcp-tool-adapter.backend.service.js.map +1 -1
  502. package/dist/esm/monitoring/analytics/controllers/analytics.backend.controller.d.ts.map +1 -1
  503. package/dist/esm/monitoring/analytics/controllers/analytics.backend.controller.js +49 -4
  504. package/dist/esm/monitoring/analytics/controllers/analytics.backend.controller.js.map +1 -1
  505. package/dist/esm/monitoring/analytics/services/value-moment-definition-registry.backend.service.d.ts +66 -0
  506. package/dist/esm/monitoring/analytics/services/value-moment-definition-registry.backend.service.d.ts.map +1 -0
  507. package/dist/esm/monitoring/analytics/services/value-moment-definition-registry.backend.service.js +199 -0
  508. package/dist/esm/monitoring/analytics/services/value-moment-definition-registry.backend.service.js.map +1 -0
  509. package/dist/esm/monitoring/analytics/services/value-moment-engine.backend.service.d.ts +149 -13
  510. package/dist/esm/monitoring/analytics/services/value-moment-engine.backend.service.d.ts.map +1 -1
  511. package/dist/esm/monitoring/analytics/services/value-moment-engine.backend.service.js +411 -19
  512. package/dist/esm/monitoring/analytics/services/value-moment-engine.backend.service.js.map +1 -1
  513. package/dist/esm/monitoring/analytics/services/value-moment-handler-registry.backend.service.d.ts +11 -2
  514. package/dist/esm/monitoring/analytics/services/value-moment-handler-registry.backend.service.d.ts.map +1 -1
  515. package/dist/esm/monitoring/analytics/services/value-moment-handler-registry.backend.service.js.map +1 -1
  516. package/dist/esm/monitoring/logger/models/logger.backend.schemas.d.ts +28 -9
  517. package/dist/esm/monitoring/logger/models/logger.backend.schemas.d.ts.map +1 -1
  518. package/dist/esm/monitoring/logger/models/logger.backend.schemas.js +30 -10
  519. package/dist/esm/monitoring/logger/models/logger.backend.schemas.js.map +1 -1
  520. package/dist/esm/monitoring/logger/services/logger.service.d.ts +12 -0
  521. package/dist/esm/monitoring/logger/services/logger.service.d.ts.map +1 -1
  522. package/dist/esm/monitoring/logger/services/logger.service.js +52 -11
  523. package/dist/esm/monitoring/logger/services/logger.service.js.map +1 -1
  524. package/dist/esm/monitoring/logger/utils/log-severity-floor.backend.utils.d.ts +62 -0
  525. package/dist/esm/monitoring/logger/utils/log-severity-floor.backend.utils.d.ts.map +1 -0
  526. package/dist/esm/monitoring/logger/utils/log-severity-floor.backend.utils.js +78 -0
  527. package/dist/esm/monitoring/logger/utils/log-severity-floor.backend.utils.js.map +1 -0
  528. package/dist/esm/monitoring/observability/audit-observation-emission.backend.d.ts +309 -0
  529. package/dist/esm/monitoring/observability/audit-observation-emission.backend.d.ts.map +1 -0
  530. package/dist/esm/monitoring/observability/audit-observation-emission.backend.js +385 -0
  531. package/dist/esm/monitoring/observability/audit-observation-emission.backend.js.map +1 -0
  532. package/dist/esm/monitoring/observability/models/observability.backend.schemas.d.ts +1 -0
  533. package/dist/esm/monitoring/observability/models/observability.backend.schemas.d.ts.map +1 -1
  534. package/dist/esm/monitoring/observability/models/observability.backend.schemas.js.map +1 -1
  535. package/dist/esm/monitoring/observability/services/metrics.service.d.ts +21 -0
  536. package/dist/esm/monitoring/observability/services/metrics.service.d.ts.map +1 -1
  537. package/dist/esm/monitoring/observability/services/metrics.service.js +38 -0
  538. package/dist/esm/monitoring/observability/services/metrics.service.js.map +1 -1
  539. package/dist/esm/notifications/email/models/email-context-provider.interface.d.ts +0 -80
  540. package/dist/esm/notifications/email/models/email-context-provider.interface.d.ts.map +0 -1
  541. package/dist/esm/notifications/email/models/email-context-provider.interface.js +0 -25
  542. package/dist/esm/notifications/email/models/email-context-provider.interface.js.map +0 -1
  543. package/dist/esm/notifications/email/services/email-context-provider-registry.backend.service.d.ts +0 -49
  544. package/dist/esm/notifications/email/services/email-context-provider-registry.backend.service.d.ts.map +0 -1
  545. package/dist/esm/notifications/email/services/email-context-provider-registry.backend.service.js +0 -141
  546. package/dist/esm/notifications/email/services/email-context-provider-registry.backend.service.js.map +0 -1
  547. package/dist/esm/notifications/email/services/email-template-compiler.backend.service.d.ts +0 -37
  548. package/dist/esm/notifications/email/services/email-template-compiler.backend.service.d.ts.map +0 -1
  549. package/dist/esm/notifications/email/services/email-template-compiler.backend.service.js +0 -121
  550. package/dist/esm/notifications/email/services/email-template-compiler.backend.service.js.map +0 -1
  551. package/dist/esm/notifications/email/services/email-template-registry.backend.service.d.ts +66 -1
  552. package/dist/esm/notifications/email/services/email-template-registry.backend.service.d.ts.map +1 -1
  553. package/dist/esm/notifications/email/services/email-template-registry.backend.service.js +105 -10
  554. package/dist/esm/notifications/email/services/email-template-registry.backend.service.js.map +1 -1
  555. package/dist/esm/notifications/email/services/email-template-sandbox.backend.service.d.ts +0 -58
  556. package/dist/esm/notifications/email/services/email-template-sandbox.backend.service.d.ts.map +0 -1
  557. package/dist/esm/notifications/email/services/email-template-sandbox.backend.service.js +0 -223
  558. package/dist/esm/notifications/email/services/email-template-sandbox.backend.service.js.map +0 -1
  559. package/dist/esm/notifications/email/services/email-template-validator.backend.service.d.ts.map +1 -1
  560. package/dist/esm/notifications/email/services/email-template-validator.backend.service.js +10 -1
  561. package/dist/esm/notifications/email/services/email-template-validator.backend.service.js.map +1 -1
  562. package/dist/esm/notifications/email/services/email.backend.service.d.ts +60 -4
  563. package/dist/esm/notifications/email/services/email.backend.service.d.ts.map +1 -1
  564. package/dist/esm/notifications/email/services/email.backend.service.js +145 -43
  565. package/dist/esm/notifications/email/services/email.backend.service.js.map +1 -1
  566. package/dist/esm/notifications/email/utils/color-conversion.utils.d.ts +0 -1
  567. package/dist/esm/notifications/email/utils/color-conversion.utils.d.ts.map +1 -1
  568. package/dist/esm/notifications/email/utils/color-conversion.utils.js.map +1 -1
  569. package/dist/esm/notifications/services/notification-badge.backend.service.d.ts +142 -21
  570. package/dist/esm/notifications/services/notification-badge.backend.service.d.ts.map +1 -1
  571. package/dist/esm/notifications/services/notification-badge.backend.service.js +283 -58
  572. package/dist/esm/notifications/services/notification-badge.backend.service.js.map +1 -1
  573. package/dist/esm/notifications/services/notifications-dispatcher.backend.service.d.ts +108 -13
  574. package/dist/esm/notifications/services/notifications-dispatcher.backend.service.d.ts.map +1 -1
  575. package/dist/esm/notifications/services/notifications-dispatcher.backend.service.js +432 -101
  576. package/dist/esm/notifications/services/notifications-dispatcher.backend.service.js.map +1 -1
  577. package/dist/esm/notifications/sms/services/sms.backend.service.d.ts +2 -2
  578. package/dist/esm/notifications/sms/services/sms.backend.service.d.ts.map +1 -1
  579. package/dist/esm/notifications/sms/services/sms.backend.service.js +5 -5
  580. package/dist/esm/notifications/sms/services/sms.backend.service.js.map +1 -1
  581. package/dist/esm/notifications/webhooks/controllers/webhook-auto-controller.backend.service.d.ts +117 -5
  582. package/dist/esm/notifications/webhooks/controllers/webhook-auto-controller.backend.service.d.ts.map +1 -1
  583. package/dist/esm/notifications/webhooks/controllers/webhook-auto-controller.backend.service.js +164 -6
  584. package/dist/esm/notifications/webhooks/controllers/webhook-auto-controller.backend.service.js.map +1 -1
  585. package/dist/esm/notifications/webhooks/outbound/batches/m2m-webhook-delivery.batch.backend.service.d.ts +0 -6
  586. package/dist/esm/notifications/webhooks/outbound/batches/m2m-webhook-delivery.batch.backend.service.d.ts.map +1 -1
  587. package/dist/esm/notifications/webhooks/outbound/batches/m2m-webhook-delivery.batch.backend.service.js +54 -7
  588. package/dist/esm/notifications/webhooks/outbound/batches/m2m-webhook-delivery.batch.backend.service.js.map +1 -1
  589. package/dist/esm/notifications/webhooks/outbound/batches/m2m-webhook-delivery.batch.utils.d.ts +5 -5
  590. package/dist/esm/notifications/webhooks/outbound/batches/m2m-webhook-delivery.batch.utils.d.ts.map +1 -1
  591. package/dist/esm/notifications/webhooks/outbound/batches/m2m-webhook-delivery.batch.utils.js +14 -13
  592. package/dist/esm/notifications/webhooks/outbound/batches/m2m-webhook-delivery.batch.utils.js.map +1 -1
  593. package/dist/esm/notifications/webhooks/outbound/m2m-webhook-signed-request.backend.utils.d.ts +2 -1
  594. package/dist/esm/notifications/webhooks/outbound/m2m-webhook-signed-request.backend.utils.d.ts.map +1 -1
  595. package/dist/esm/notifications/webhooks/outbound/m2m-webhook-signed-request.backend.utils.js +18 -8
  596. package/dist/esm/notifications/webhooks/outbound/m2m-webhook-signed-request.backend.utils.js.map +1 -1
  597. package/dist/esm/notifications/webhooks/outbound/services/webhook-config-test-endpoint.custom-impl.backend.service.d.ts.map +1 -1
  598. package/dist/esm/notifications/webhooks/outbound/services/webhook-config-test-endpoint.custom-impl.backend.service.js +20 -18
  599. package/dist/esm/notifications/webhooks/outbound/services/webhook-config-test-endpoint.custom-impl.backend.service.js.map +1 -1
  600. package/dist/esm/notifications/webhooks/services/webhook-handler.backend.service.d.ts +16 -0
  601. package/dist/esm/notifications/webhooks/services/webhook-handler.backend.service.d.ts.map +1 -1
  602. package/dist/esm/notifications/webhooks/services/webhook-handler.backend.service.js +18 -0
  603. package/dist/esm/notifications/webhooks/services/webhook-handler.backend.service.js.map +1 -1
  604. package/dist/esm/organizations/batches/organization-purge.batch.backend.service.d.ts +2 -2
  605. package/dist/esm/organizations/batches/organization-purge.batch.backend.service.js +2 -2
  606. package/dist/esm/organizations/batches/organization-purge.batch.backend.service.js.map +1 -1
  607. package/dist/esm/organizations/services/organization-custom-implementation.backend.service.d.ts.map +1 -1
  608. package/dist/esm/organizations/services/organization-custom-implementation.backend.service.js +63 -2
  609. package/dist/esm/organizations/services/organization-custom-implementation.backend.service.js.map +1 -1
  610. package/dist/esm/organizations/services/organization-unit-custom-implementation.backend.service.d.ts.map +1 -1
  611. package/dist/esm/organizations/services/organization-unit-custom-implementation.backend.service.js +4 -1
  612. package/dist/esm/organizations/services/organization-unit-custom-implementation.backend.service.js.map +1 -1
  613. package/dist/esm/queue/adapters/in-memory-queue-adapter.backend.service.d.ts +66 -0
  614. package/dist/esm/queue/adapters/in-memory-queue-adapter.backend.service.d.ts.map +1 -0
  615. package/dist/esm/queue/adapters/in-memory-queue-adapter.backend.service.js +257 -0
  616. package/dist/esm/queue/adapters/in-memory-queue-adapter.backend.service.js.map +1 -0
  617. package/dist/esm/queue/adapters/queue-adapter.backend.binding.d.ts +12 -0
  618. package/dist/esm/queue/adapters/queue-adapter.backend.binding.d.ts.map +1 -0
  619. package/dist/esm/queue/adapters/queue-adapter.backend.binding.js +47 -0
  620. package/dist/esm/queue/adapters/queue-adapter.backend.binding.js.map +1 -0
  621. package/dist/esm/queue/adapters/queue-adapter.backend.interface.d.ts +87 -0
  622. package/dist/esm/queue/adapters/queue-adapter.backend.interface.d.ts.map +1 -0
  623. package/dist/esm/queue/adapters/queue-adapter.backend.interface.js +1 -0
  624. package/dist/esm/queue/adapters/queue-adapter.backend.interface.js.map +1 -0
  625. package/dist/esm/queue/adapters/queue-adapter.backend.options.d.ts +31 -0
  626. package/dist/esm/queue/adapters/queue-adapter.backend.options.d.ts.map +1 -0
  627. package/dist/esm/queue/adapters/queue-adapter.backend.options.js +13 -0
  628. package/dist/esm/queue/adapters/queue-adapter.backend.options.js.map +1 -0
  629. package/dist/esm/queue/adapters/rabbitmq-adapter.backend.service.d.ts +19 -25
  630. package/dist/esm/queue/adapters/rabbitmq-adapter.backend.service.d.ts.map +1 -1
  631. package/dist/esm/queue/adapters/rabbitmq-adapter.backend.service.js +33 -0
  632. package/dist/esm/queue/adapters/rabbitmq-adapter.backend.service.js.map +1 -1
  633. package/dist/esm/queue/domain-queue-consumer.backend.service.d.ts +2 -2
  634. package/dist/esm/queue/domain-queue-consumer.backend.service.d.ts.map +1 -1
  635. package/dist/esm/queue/domain-queue-consumer.backend.service.js +1 -4
  636. package/dist/esm/queue/domain-queue-consumer.backend.service.js.map +1 -1
  637. package/dist/esm/queue/job-consumer.backend.service.d.ts +2 -2
  638. package/dist/esm/queue/job-consumer.backend.service.d.ts.map +1 -1
  639. package/dist/esm/queue/job-consumer.backend.service.js +1 -4
  640. package/dist/esm/queue/job-consumer.backend.service.js.map +1 -1
  641. package/dist/esm/queue/job-executor.backend.service.d.ts +2 -2
  642. package/dist/esm/queue/job-executor.backend.service.d.ts.map +1 -1
  643. package/dist/esm/queue/job-executor.backend.service.js +1 -4
  644. package/dist/esm/queue/job-executor.backend.service.js.map +1 -1
  645. package/dist/esm/queue/queue-monitoring.backend.service.d.ts +8 -4
  646. package/dist/esm/queue/queue-monitoring.backend.service.d.ts.map +1 -1
  647. package/dist/esm/queue/queue-monitoring.backend.service.js +25 -17
  648. package/dist/esm/queue/queue-monitoring.backend.service.js.map +1 -1
  649. package/dist/esm/queue/queue-worker-initializer.backend.service.d.ts +16 -1
  650. package/dist/esm/queue/queue-worker-initializer.backend.service.d.ts.map +1 -1
  651. package/dist/esm/queue/queue-worker-initializer.backend.service.js +16 -1
  652. package/dist/esm/queue/queue-worker-initializer.backend.service.js.map +1 -1
  653. package/dist/esm/queue/queue.backend.service.d.ts +3 -3
  654. package/dist/esm/queue/queue.backend.service.d.ts.map +1 -1
  655. package/dist/esm/queue/queue.backend.service.js +26 -4
  656. package/dist/esm/queue/queue.backend.service.js.map +1 -1
  657. package/dist/esm/queue/worker-shutdown-manager.backend.service.d.ts +2 -2
  658. package/dist/esm/queue/worker-shutdown-manager.backend.service.d.ts.map +1 -1
  659. package/dist/esm/queue/worker-shutdown-manager.backend.service.js +18 -3
  660. package/dist/esm/queue/worker-shutdown-manager.backend.service.js.map +1 -1
  661. package/dist/esm/rag/utils/rag-chunking.backend.utils.d.ts +50 -25
  662. package/dist/esm/rag/utils/rag-chunking.backend.utils.d.ts.map +1 -1
  663. package/dist/esm/rag/utils/rag-chunking.backend.utils.js +147 -39
  664. package/dist/esm/rag/utils/rag-chunking.backend.utils.js.map +1 -1
  665. package/dist/esm/rag/utils/rag-context-assembly.backend.utils.d.ts +12 -3
  666. package/dist/esm/rag/utils/rag-context-assembly.backend.utils.d.ts.map +1 -1
  667. package/dist/esm/rag/utils/rag-context-assembly.backend.utils.js +12 -3
  668. package/dist/esm/rag/utils/rag-context-assembly.backend.utils.js.map +1 -1
  669. package/dist/esm/requests/service/websocket.service.d.ts +9 -0
  670. package/dist/esm/requests/service/websocket.service.d.ts.map +1 -1
  671. package/dist/esm/requests/service/websocket.service.js +88 -15
  672. package/dist/esm/requests/service/websocket.service.js.map +1 -1
  673. package/dist/esm/resources/models/custom-service-implementations.backend.definition.d.ts.map +1 -1
  674. package/dist/esm/resources/models/custom-service-implementations.backend.definition.js +16 -2
  675. package/dist/esm/resources/models/custom-service-implementations.backend.definition.js.map +1 -1
  676. package/dist/esm/resources/models/resources-operations.backend.definitions.d.ts.map +1 -1
  677. package/dist/esm/resources/models/resources-operations.backend.definitions.js +2 -0
  678. package/dist/esm/resources/models/resources-operations.backend.definitions.js.map +1 -1
  679. package/dist/esm/resources/models/resources-relationships.backend.definitions.d.ts.map +1 -1
  680. package/dist/esm/resources/models/resources-relationships.backend.definitions.js +14 -0
  681. package/dist/esm/resources/models/resources-relationships.backend.definitions.js.map +1 -1
  682. package/dist/esm/resources/models/resources-types.backend.schemas.d.ts +2 -1
  683. package/dist/esm/resources/models/resources-types.backend.schemas.d.ts.map +1 -1
  684. package/dist/esm/resources/models/resources-types.backend.schemas.js +8 -0
  685. package/dist/esm/resources/models/resources-types.backend.schemas.js.map +1 -1
  686. package/dist/esm/resources/services/resource-id.backend.service.js +3 -3
  687. package/dist/esm/resources/services/resource-id.backend.service.js.map +1 -1
  688. package/dist/esm/resources/services/resources-registry.backend.service.d.ts +60 -5
  689. package/dist/esm/resources/services/resources-registry.backend.service.d.ts.map +1 -1
  690. package/dist/esm/resources/services/resources-registry.backend.service.js +91 -7
  691. package/dist/esm/resources/services/resources-registry.backend.service.js.map +1 -1
  692. package/dist/esm/runtime/controllers/health-controller.backend.service.d.ts +36 -3
  693. package/dist/esm/runtime/controllers/health-controller.backend.service.d.ts.map +1 -1
  694. package/dist/esm/runtime/controllers/health-controller.backend.service.js +32 -10
  695. package/dist/esm/runtime/controllers/health-controller.backend.service.js.map +1 -1
  696. package/dist/esm/runtime/domain-module.backend.definitions.d.ts +24 -0
  697. package/dist/esm/runtime/domain-module.backend.definitions.d.ts.map +1 -1
  698. package/dist/esm/runtime/domain-module.backend.definitions.js +24 -0
  699. package/dist/esm/runtime/domain-module.backend.definitions.js.map +1 -1
  700. package/dist/esm/runtime/services/execution-context-creator.backend.service.d.ts.map +1 -1
  701. package/dist/esm/runtime/services/execution-context-creator.backend.service.js +13 -7
  702. package/dist/esm/runtime/services/execution-context-creator.backend.service.js.map +1 -1
  703. package/dist/esm/runtime/services/health-readiness-contributor.backend.interface.d.ts +51 -0
  704. package/dist/esm/runtime/services/health-readiness-contributor.backend.interface.d.ts.map +1 -1
  705. package/dist/esm/runtime/services/health-readiness-contributor.backend.interface.js.map +1 -1
  706. package/dist/esm/runtime/services/http-server.backend.service.d.ts +26 -0
  707. package/dist/esm/runtime/services/http-server.backend.service.d.ts.map +1 -1
  708. package/dist/esm/runtime/services/http-server.backend.service.js +181 -1
  709. package/dist/esm/runtime/services/http-server.backend.service.js.map +1 -1
  710. package/dist/esm/runtime/services/start-application.backend.service.d.ts +47 -1
  711. package/dist/esm/runtime/services/start-application.backend.service.d.ts.map +1 -1
  712. package/dist/esm/runtime/services/start-application.backend.service.js +343 -77
  713. package/dist/esm/runtime/services/start-application.backend.service.js.map +1 -1
  714. package/dist/esm/security/api-keys/api-keys.custom-impl.backend.service.d.ts +15 -0
  715. package/dist/esm/security/api-keys/api-keys.custom-impl.backend.service.d.ts.map +1 -1
  716. package/dist/esm/security/api-keys/api-keys.custom-impl.backend.service.js +28 -0
  717. package/dist/esm/security/api-keys/api-keys.custom-impl.backend.service.js.map +1 -1
  718. package/dist/esm/security/authentications/batches/anonymous-session-cleanup.batch.backend.service.d.ts +5 -1
  719. package/dist/esm/security/authentications/batches/anonymous-session-cleanup.batch.backend.service.d.ts.map +1 -1
  720. package/dist/esm/security/authentications/batches/anonymous-session-cleanup.batch.backend.service.js +24 -4
  721. package/dist/esm/security/authentications/batches/anonymous-session-cleanup.batch.backend.service.js.map +1 -1
  722. package/dist/esm/security/authentications/controllers/authentication-controller.backend.service.d.ts.map +1 -1
  723. package/dist/esm/security/authentications/controllers/authentication-controller.backend.service.js +29 -4
  724. package/dist/esm/security/authentications/controllers/authentication-controller.backend.service.js.map +1 -1
  725. package/dist/esm/security/authentications/controllers/oauth-provider-controller.backend.service.d.ts +114 -0
  726. package/dist/esm/security/authentications/controllers/oauth-provider-controller.backend.service.d.ts.map +1 -1
  727. package/dist/esm/security/authentications/controllers/oauth-provider-controller.backend.service.js +354 -3
  728. package/dist/esm/security/authentications/controllers/oauth-provider-controller.backend.service.js.map +1 -1
  729. package/dist/esm/security/authentications/models/cimd.backend.schemas.d.ts +1 -0
  730. package/dist/esm/security/authentications/models/cimd.backend.schemas.d.ts.map +1 -1
  731. package/dist/esm/security/authentications/models/cimd.backend.schemas.js +22 -0
  732. package/dist/esm/security/authentications/models/cimd.backend.schemas.js.map +1 -1
  733. package/dist/esm/security/authentications/models/jwt.backend.schemas.d.ts +3 -23
  734. package/dist/esm/security/authentications/models/jwt.backend.schemas.d.ts.map +1 -1
  735. package/dist/esm/security/authentications/models/jwt.backend.schemas.js +20 -45
  736. package/dist/esm/security/authentications/models/jwt.backend.schemas.js.map +1 -1
  737. package/dist/esm/security/authentications/models/oauth2-connection.backend.schemas.d.ts +15 -0
  738. package/dist/esm/security/authentications/models/oauth2-connection.backend.schemas.d.ts.map +1 -1
  739. package/dist/esm/security/authentications/models/oauth2-connection.backend.schemas.js.map +1 -1
  740. package/dist/esm/security/authentications/services/admin-config/auth-organization-configuration.service.d.ts +0 -2
  741. package/dist/esm/security/authentications/services/admin-config/auth-organization-configuration.service.d.ts.map +1 -1
  742. package/dist/esm/security/authentications/services/admin-config/auth-organization-configuration.service.js +23 -14
  743. package/dist/esm/security/authentications/services/admin-config/auth-organization-configuration.service.js.map +1 -1
  744. package/dist/esm/security/authentications/services/admin-config/domain-to-org-lookup.backend.service.d.ts +0 -1
  745. package/dist/esm/security/authentications/services/admin-config/domain-to-org-lookup.backend.service.d.ts.map +1 -1
  746. package/dist/esm/security/authentications/services/admin-config/domain-to-org-lookup.backend.service.js +15 -12
  747. package/dist/esm/security/authentications/services/admin-config/domain-to-org-lookup.backend.service.js.map +1 -1
  748. package/dist/esm/security/authentications/services/admin-config/domain-verification.backend.service.d.ts +113 -3
  749. package/dist/esm/security/authentications/services/admin-config/domain-verification.backend.service.d.ts.map +1 -1
  750. package/dist/esm/security/authentications/services/admin-config/domain-verification.backend.service.js +207 -30
  751. package/dist/esm/security/authentications/services/admin-config/domain-verification.backend.service.js.map +1 -1
  752. package/dist/esm/security/authentications/services/admin-config/enterprise-user-provisioning.backend.service.d.ts +95 -2
  753. package/dist/esm/security/authentications/services/admin-config/enterprise-user-provisioning.backend.service.d.ts.map +1 -1
  754. package/dist/esm/security/authentications/services/admin-config/enterprise-user-provisioning.backend.service.js +153 -9
  755. package/dist/esm/security/authentications/services/admin-config/enterprise-user-provisioning.backend.service.js.map +1 -1
  756. package/dist/esm/security/authentications/services/anonymous-session.backend.service.d.ts +190 -0
  757. package/dist/esm/security/authentications/services/anonymous-session.backend.service.d.ts.map +1 -1
  758. package/dist/esm/security/authentications/services/anonymous-session.backend.service.js +377 -53
  759. package/dist/esm/security/authentications/services/anonymous-session.backend.service.js.map +1 -1
  760. package/dist/esm/security/authentications/services/auth-methods/auth-method-management.backend.service.d.ts +9 -1
  761. package/dist/esm/security/authentications/services/auth-methods/auth-method-management.backend.service.d.ts.map +1 -1
  762. package/dist/esm/security/authentications/services/auth-methods/auth-method-management.backend.service.js +77 -2
  763. package/dist/esm/security/authentications/services/auth-methods/auth-method-management.backend.service.js.map +1 -1
  764. package/dist/esm/security/authentications/services/auth-methods/auth-mfa.backend.service.d.ts.map +1 -1
  765. package/dist/esm/security/authentications/services/auth-methods/auth-mfa.backend.service.js +5 -3
  766. package/dist/esm/security/authentications/services/auth-methods/auth-mfa.backend.service.js.map +1 -1
  767. package/dist/esm/security/authentications/services/auth-methods/auth-registration.backend.service.d.ts +41 -0
  768. package/dist/esm/security/authentications/services/auth-methods/auth-registration.backend.service.d.ts.map +1 -1
  769. package/dist/esm/security/authentications/services/auth-methods/auth-registration.backend.service.js +202 -23
  770. package/dist/esm/security/authentications/services/auth-methods/auth-registration.backend.service.js.map +1 -1
  771. package/dist/esm/security/authentications/services/auth-methods/oauth2-authentication.backend.service.d.ts.map +1 -1
  772. package/dist/esm/security/authentications/services/auth-methods/oauth2-authentication.backend.service.js +42 -1
  773. package/dist/esm/security/authentications/services/auth-methods/oauth2-authentication.backend.service.js.map +1 -1
  774. package/dist/esm/security/authentications/services/auth-methods/oauth2-connection-resolver.backend.service.d.ts.map +1 -1
  775. package/dist/esm/security/authentications/services/auth-methods/oauth2-connection-resolver.backend.service.js +34 -4
  776. package/dist/esm/security/authentications/services/auth-methods/oauth2-connection-resolver.backend.service.js.map +1 -1
  777. package/dist/esm/security/authentications/services/auth-methods/webauthn.backend.service.d.ts +29 -5
  778. package/dist/esm/security/authentications/services/auth-methods/webauthn.backend.service.d.ts.map +1 -1
  779. package/dist/esm/security/authentications/services/auth-methods/webauthn.backend.service.js +77 -5
  780. package/dist/esm/security/authentications/services/auth-methods/webauthn.backend.service.js.map +1 -1
  781. package/dist/esm/security/authentications/services/auth-token-issuer.backend.service.d.ts +41 -1
  782. package/dist/esm/security/authentications/services/auth-token-issuer.backend.service.d.ts.map +1 -1
  783. package/dist/esm/security/authentications/services/auth-token-issuer.backend.service.js +87 -4
  784. package/dist/esm/security/authentications/services/auth-token-issuer.backend.service.js.map +1 -1
  785. package/dist/esm/security/authentications/services/authentication-orchestrator.backend.service.d.ts +43 -1
  786. package/dist/esm/security/authentications/services/authentication-orchestrator.backend.service.d.ts.map +1 -1
  787. package/dist/esm/security/authentications/services/authentication-orchestrator.backend.service.js +277 -97
  788. package/dist/esm/security/authentications/services/authentication-orchestrator.backend.service.js.map +1 -1
  789. package/dist/esm/security/authentications/services/cimd-client-metadata.backend.service.d.ts +28 -5
  790. package/dist/esm/security/authentications/services/cimd-client-metadata.backend.service.d.ts.map +1 -1
  791. package/dist/esm/security/authentications/services/cimd-client-metadata.backend.service.js +72 -12
  792. package/dist/esm/security/authentications/services/cimd-client-metadata.backend.service.js.map +1 -1
  793. package/dist/esm/security/authentications/services/custom-impls/auth-custom-implementations.backend.d.ts.map +1 -1
  794. package/dist/esm/security/authentications/services/custom-impls/auth-custom-implementations.backend.js +3 -0
  795. package/dist/esm/security/authentications/services/custom-impls/auth-custom-implementations.backend.js.map +1 -1
  796. package/dist/esm/security/authentications/services/custom-impls/sso-config-domain-verification.custom-impl.backend.service.d.ts +28 -0
  797. package/dist/esm/security/authentications/services/custom-impls/sso-config-domain-verification.custom-impl.backend.service.d.ts.map +1 -0
  798. package/dist/esm/security/authentications/services/custom-impls/sso-config-domain-verification.custom-impl.backend.service.js +283 -0
  799. package/dist/esm/security/authentications/services/custom-impls/sso-config-domain-verification.custom-impl.backend.service.js.map +1 -0
  800. package/dist/esm/security/authentications/services/custom-impls/sso-config.custom-impl.backend.service.d.ts +4 -3
  801. package/dist/esm/security/authentications/services/custom-impls/sso-config.custom-impl.backend.service.d.ts.map +1 -1
  802. package/dist/esm/security/authentications/services/custom-impls/sso-config.custom-impl.backend.service.js +4 -3
  803. package/dist/esm/security/authentications/services/custom-impls/sso-config.custom-impl.backend.service.js.map +1 -1
  804. package/dist/esm/security/authentications/services/oauth-provider-token.backend.service.d.ts +35 -0
  805. package/dist/esm/security/authentications/services/oauth-provider-token.backend.service.d.ts.map +1 -1
  806. package/dist/esm/security/authentications/services/oauth-provider-token.backend.service.js +111 -21
  807. package/dist/esm/security/authentications/services/oauth-provider-token.backend.service.js.map +1 -1
  808. package/dist/esm/security/authentications/services/oidc-authorization-code.backend.service.d.ts +14 -1
  809. package/dist/esm/security/authentications/services/oidc-authorization-code.backend.service.d.ts.map +1 -1
  810. package/dist/esm/security/authentications/services/oidc-authorization-code.backend.service.js +49 -8
  811. package/dist/esm/security/authentications/services/oidc-authorization-code.backend.service.js.map +1 -1
  812. package/dist/esm/security/authentications/services/utils/auth-policy-resolution.backend.utils.d.ts.map +1 -1
  813. package/dist/esm/security/authentications/services/utils/auth-policy-resolution.backend.utils.js +4 -0
  814. package/dist/esm/security/authentications/services/utils/auth-policy-resolution.backend.utils.js.map +1 -1
  815. package/dist/esm/security/authentications/services/utils/auth-user-lookup.backend.service.d.ts.map +1 -1
  816. package/dist/esm/security/authentications/services/utils/auth-user-lookup.backend.service.js +6 -0
  817. package/dist/esm/security/authentications/services/utils/auth-user-lookup.backend.service.js.map +1 -1
  818. package/dist/esm/security/authentications/services/utils/external-turn-rate-limit.backend.utils.d.ts +37 -1
  819. package/dist/esm/security/authentications/services/utils/external-turn-rate-limit.backend.utils.d.ts.map +1 -1
  820. package/dist/esm/security/authentications/services/utils/external-turn-rate-limit.backend.utils.js +51 -0
  821. package/dist/esm/security/authentications/services/utils/external-turn-rate-limit.backend.utils.js.map +1 -1
  822. package/dist/esm/security/authentications/utils/enterprise-sso-enforcement.backend.utils.d.ts +41 -0
  823. package/dist/esm/security/authentications/utils/enterprise-sso-enforcement.backend.utils.d.ts.map +1 -1
  824. package/dist/esm/security/authentications/utils/enterprise-sso-enforcement.backend.utils.js +45 -0
  825. package/dist/esm/security/authentications/utils/enterprise-sso-enforcement.backend.utils.js.map +1 -1
  826. package/dist/esm/security/authorizations/cross-tenant-read-observation.backend.d.ts +116 -0
  827. package/dist/esm/security/authorizations/cross-tenant-read-observation.backend.d.ts.map +1 -0
  828. package/dist/esm/security/authorizations/cross-tenant-read-observation.backend.js +162 -0
  829. package/dist/esm/security/authorizations/cross-tenant-read-observation.backend.js.map +1 -0
  830. package/dist/esm/security/authorizations/initiator-organization-confinement.backend.d.ts.map +1 -1
  831. package/dist/esm/security/authorizations/initiator-organization-confinement.backend.js +24 -1
  832. package/dist/esm/security/authorizations/initiator-organization-confinement.backend.js.map +1 -1
  833. package/dist/esm/security/authorizations/organization-owner-floor.backend.utils.d.ts +20 -20
  834. package/dist/esm/security/authorizations/organization-owner-floor.backend.utils.d.ts.map +1 -1
  835. package/dist/esm/security/authorizations/organization-owner-floor.backend.utils.js +27 -28
  836. package/dist/esm/security/authorizations/organization-owner-floor.backend.utils.js.map +1 -1
  837. package/dist/esm/security/authorizations/platform-access-grant-custom-implementation.backend.service.d.ts.map +1 -1
  838. package/dist/esm/security/authorizations/platform-access-grant-custom-implementation.backend.service.js +77 -3
  839. package/dist/esm/security/authorizations/platform-access-grant-custom-implementation.backend.service.js.map +1 -1
  840. package/dist/esm/security/authorizations/privileged-access-review.backend.utils.d.ts +117 -0
  841. package/dist/esm/security/authorizations/privileged-access-review.backend.utils.d.ts.map +1 -0
  842. package/dist/esm/security/authorizations/privileged-access-review.backend.utils.js +104 -0
  843. package/dist/esm/security/authorizations/privileged-access-review.backend.utils.js.map +1 -0
  844. package/dist/esm/security/authorizations/role-ceiling.backend.utils.d.ts +4 -0
  845. package/dist/esm/security/authorizations/role-ceiling.backend.utils.d.ts.map +1 -1
  846. package/dist/esm/security/authorizations/role-ceiling.backend.utils.js +4 -0
  847. package/dist/esm/security/authorizations/role-ceiling.backend.utils.js.map +1 -1
  848. package/dist/esm/security/authorizations/role-conferral.backend.utils.d.ts +93 -0
  849. package/dist/esm/security/authorizations/role-conferral.backend.utils.d.ts.map +1 -0
  850. package/dist/esm/security/authorizations/role-conferral.backend.utils.js +95 -0
  851. package/dist/esm/security/authorizations/role-conferral.backend.utils.js.map +1 -0
  852. package/dist/esm/security/authorizations/scope-root-collection-confinement.backend.d.ts +124 -1
  853. package/dist/esm/security/authorizations/scope-root-collection-confinement.backend.d.ts.map +1 -1
  854. package/dist/esm/security/authorizations/scope-root-collection-confinement.backend.js +142 -5
  855. package/dist/esm/security/authorizations/scope-root-collection-confinement.backend.js.map +1 -1
  856. package/dist/esm/security/authorizations/services/authorizations.backend.service.d.ts +175 -14
  857. package/dist/esm/security/authorizations/services/authorizations.backend.service.d.ts.map +1 -1
  858. package/dist/esm/security/authorizations/services/authorizations.backend.service.js +385 -49
  859. package/dist/esm/security/authorizations/services/authorizations.backend.service.js.map +1 -1
  860. package/dist/esm/security/authorizations/super-admin-floor.backend.utils.d.ts +6 -14
  861. package/dist/esm/security/authorizations/super-admin-floor.backend.utils.d.ts.map +1 -1
  862. package/dist/esm/security/authorizations/super-admin-floor.backend.utils.js +13 -22
  863. package/dist/esm/security/authorizations/super-admin-floor.backend.utils.js.map +1 -1
  864. package/dist/esm/security/connected-accounts/connection-target-authorization.backend.d.ts +60 -0
  865. package/dist/esm/security/connected-accounts/connection-target-authorization.backend.d.ts.map +1 -0
  866. package/dist/esm/security/connected-accounts/connection-target-authorization.backend.js +79 -0
  867. package/dist/esm/security/connected-accounts/connection-target-authorization.backend.js.map +1 -0
  868. package/dist/esm/security/connected-accounts/controllers/provider-connection.controller.backend.service.d.ts +161 -0
  869. package/dist/esm/security/connected-accounts/controllers/provider-connection.controller.backend.service.d.ts.map +1 -0
  870. package/dist/esm/security/connected-accounts/controllers/provider-connection.controller.backend.service.js +512 -0
  871. package/dist/esm/security/connected-accounts/controllers/provider-connection.controller.backend.service.js.map +1 -0
  872. package/dist/esm/security/connected-accounts/organization-provider-credential-resolver.port.d.ts +59 -0
  873. package/dist/esm/security/connected-accounts/organization-provider-credential-resolver.port.d.ts.map +1 -0
  874. package/dist/esm/security/connected-accounts/organization-provider-credential-resolver.port.js +22 -0
  875. package/dist/esm/security/connected-accounts/organization-provider-credential-resolver.port.js.map +1 -0
  876. package/dist/esm/security/connected-accounts/provider-oauth2-refresher.port.d.ts +44 -0
  877. package/dist/esm/security/connected-accounts/provider-oauth2-refresher.port.d.ts.map +1 -0
  878. package/dist/esm/security/connected-accounts/provider-oauth2-refresher.port.js +20 -0
  879. package/dist/esm/security/connected-accounts/provider-oauth2-refresher.port.js.map +1 -0
  880. package/dist/esm/security/connected-accounts/services/organization-provider-credential-store.backend.service.d.ts +191 -0
  881. package/dist/esm/security/connected-accounts/services/organization-provider-credential-store.backend.service.d.ts.map +1 -0
  882. package/dist/esm/security/connected-accounts/services/organization-provider-credential-store.backend.service.js +385 -0
  883. package/dist/esm/security/connected-accounts/services/organization-provider-credential-store.backend.service.js.map +1 -0
  884. package/dist/esm/security/connected-accounts/services/organization-provider-credentials.custom-impl.backend.service.d.ts +41 -0
  885. package/dist/esm/security/connected-accounts/services/organization-provider-credentials.custom-impl.backend.service.d.ts.map +1 -0
  886. package/dist/esm/security/connected-accounts/services/organization-provider-credentials.custom-impl.backend.service.js +358 -0
  887. package/dist/esm/security/connected-accounts/services/organization-provider-credentials.custom-impl.backend.service.js.map +1 -0
  888. package/dist/esm/security/connected-accounts/services/provider-oauth2-exchange.backend.d.ts +160 -0
  889. package/dist/esm/security/connected-accounts/services/provider-oauth2-exchange.backend.d.ts.map +1 -0
  890. package/dist/esm/security/connected-accounts/services/provider-oauth2-exchange.backend.js +266 -0
  891. package/dist/esm/security/connected-accounts/services/provider-oauth2-exchange.backend.js.map +1 -0
  892. package/dist/esm/security/connected-accounts/services/provider-oauth2-pending-authorization.backend.service.d.ts +111 -0
  893. package/dist/esm/security/connected-accounts/services/provider-oauth2-pending-authorization.backend.service.d.ts.map +1 -0
  894. package/dist/esm/security/connected-accounts/services/provider-oauth2-pending-authorization.backend.service.js +107 -0
  895. package/dist/esm/security/connected-accounts/services/provider-oauth2-pending-authorization.backend.service.js.map +1 -0
  896. package/dist/esm/security/connected-accounts/services/provider-oauth2-refresher.backend.service.d.ts +54 -0
  897. package/dist/esm/security/connected-accounts/services/provider-oauth2-refresher.backend.service.d.ts.map +1 -0
  898. package/dist/esm/security/connected-accounts/services/provider-oauth2-refresher.backend.service.js +153 -0
  899. package/dist/esm/security/connected-accounts/services/provider-oauth2-refresher.backend.service.js.map +1 -0
  900. package/dist/esm/security/connected-accounts/services/user-provider-credential-store.backend.service.d.ts +195 -0
  901. package/dist/esm/security/connected-accounts/services/user-provider-credential-store.backend.service.d.ts.map +1 -0
  902. package/dist/esm/security/connected-accounts/services/user-provider-credential-store.backend.service.js +387 -0
  903. package/dist/esm/security/connected-accounts/services/user-provider-credential-store.backend.service.js.map +1 -0
  904. package/dist/esm/security/connected-accounts/services/user-provider-credentials.custom-impl.backend.service.d.ts +45 -0
  905. package/dist/esm/security/connected-accounts/services/user-provider-credentials.custom-impl.backend.service.d.ts.map +1 -0
  906. package/dist/esm/security/connected-accounts/services/user-provider-credentials.custom-impl.backend.service.js +291 -0
  907. package/dist/esm/security/connected-accounts/services/user-provider-credentials.custom-impl.backend.service.js.map +1 -0
  908. package/dist/esm/security/connected-accounts/user-provider-credential-resolver.port.d.ts +62 -0
  909. package/dist/esm/security/connected-accounts/user-provider-credential-resolver.port.d.ts.map +1 -0
  910. package/dist/esm/security/connected-accounts/user-provider-credential-resolver.port.js +29 -0
  911. package/dist/esm/security/connected-accounts/user-provider-credential-resolver.port.js.map +1 -0
  912. package/dist/esm/security/connected-accounts/utils/provider-credential-envelope.backend.utils.d.ts +127 -0
  913. package/dist/esm/security/connected-accounts/utils/provider-credential-envelope.backend.utils.d.ts.map +1 -0
  914. package/dist/esm/security/connected-accounts/utils/provider-credential-envelope.backend.utils.js +277 -0
  915. package/dist/esm/security/connected-accounts/utils/provider-credential-envelope.backend.utils.js.map +1 -0
  916. package/dist/esm/security/connected-accounts/utils/stored-credential-value.backend.utils.d.ts +66 -0
  917. package/dist/esm/security/connected-accounts/utils/stored-credential-value.backend.utils.d.ts.map +1 -0
  918. package/dist/esm/security/connected-accounts/utils/stored-credential-value.backend.utils.js +75 -0
  919. package/dist/esm/security/connected-accounts/utils/stored-credential-value.backend.utils.js.map +1 -0
  920. package/dist/esm/security/consumable-tokens/batches/consumable-tokens-cleanup.batch.backend.service.d.ts +18 -1
  921. package/dist/esm/security/consumable-tokens/batches/consumable-tokens-cleanup.batch.backend.service.d.ts.map +1 -1
  922. package/dist/esm/security/consumable-tokens/batches/consumable-tokens-cleanup.batch.backend.service.js +110 -74
  923. package/dist/esm/security/consumable-tokens/batches/consumable-tokens-cleanup.batch.backend.service.js.map +1 -1
  924. package/dist/esm/security/consumable-tokens/consumable-token-models.exports.d.ts +22 -0
  925. package/dist/esm/security/consumable-tokens/consumable-token-models.exports.d.ts.map +1 -0
  926. package/dist/esm/security/consumable-tokens/consumable-token-models.exports.js +22 -0
  927. package/dist/esm/security/consumable-tokens/consumable-token-models.exports.js.map +1 -0
  928. package/dist/esm/security/consumable-tokens/models/consumable-tokens.backend.resources-config.schemas.d.ts +17 -3
  929. package/dist/esm/security/consumable-tokens/models/consumable-tokens.backend.resources-config.schemas.d.ts.map +1 -1
  930. package/dist/esm/security/consumable-tokens/models/consumable-tokens.backend.resources-config.schemas.js +12 -0
  931. package/dist/esm/security/consumable-tokens/models/consumable-tokens.backend.resources-config.schemas.js.map +1 -1
  932. package/dist/esm/security/consumable-tokens/services/consumable-token.backend.service.d.ts +41 -3
  933. package/dist/esm/security/consumable-tokens/services/consumable-token.backend.service.d.ts.map +1 -1
  934. package/dist/esm/security/consumable-tokens/services/consumable-token.backend.service.js +83 -20
  935. package/dist/esm/security/consumable-tokens/services/consumable-token.backend.service.js.map +1 -1
  936. package/dist/esm/security/credential-rotation-grace.backend.utils.d.ts +9 -4
  937. package/dist/esm/security/credential-rotation-grace.backend.utils.d.ts.map +1 -1
  938. package/dist/esm/security/credential-rotation-grace.backend.utils.js +9 -4
  939. package/dist/esm/security/credential-rotation-grace.backend.utils.js.map +1 -1
  940. package/dist/esm/security/jwt/services/jwt.backend.service.d.ts.map +1 -1
  941. package/dist/esm/security/jwt/services/jwt.backend.service.js +1 -18
  942. package/dist/esm/security/jwt/services/jwt.backend.service.js.map +1 -1
  943. package/dist/esm/security/oauth-clients/oauth-client-generation.backend.utils.d.ts +26 -0
  944. package/dist/esm/security/oauth-clients/oauth-client-generation.backend.utils.d.ts.map +1 -1
  945. package/dist/esm/security/oauth-clients/oauth-client-generation.backend.utils.js +43 -0
  946. package/dist/esm/security/oauth-clients/oauth-client-generation.backend.utils.js.map +1 -1
  947. package/dist/esm/security/oauth-clients/oauth-clients.custom-impl.backend.service.d.ts +8 -1
  948. package/dist/esm/security/oauth-clients/oauth-clients.custom-impl.backend.service.d.ts.map +1 -1
  949. package/dist/esm/security/oauth-clients/oauth-clients.custom-impl.backend.service.js +49 -0
  950. package/dist/esm/security/oauth-clients/oauth-clients.custom-impl.backend.service.js.map +1 -1
  951. package/dist/esm/security/scim/controllers/scim.backend.controller.d.ts.map +1 -1
  952. package/dist/esm/security/scim/controllers/scim.backend.controller.js +17 -5
  953. package/dist/esm/security/scim/controllers/scim.backend.controller.js.map +1 -1
  954. package/dist/esm/security/scim/models/scim-protocol.backend.schemas.d.ts +67 -29
  955. package/dist/esm/security/scim/models/scim-protocol.backend.schemas.d.ts.map +1 -1
  956. package/dist/esm/security/scim/models/scim-protocol.backend.schemas.js +47 -25
  957. package/dist/esm/security/scim/models/scim-protocol.backend.schemas.js.map +1 -1
  958. package/dist/esm/security/ssrf/outbound-target-guard.backend.utils.d.ts +10 -2
  959. package/dist/esm/security/ssrf/outbound-target-guard.backend.utils.d.ts.map +1 -1
  960. package/dist/esm/security/ssrf/outbound-target-guard.backend.utils.js +10 -2
  961. package/dist/esm/security/ssrf/outbound-target-guard.backend.utils.js.map +1 -1
  962. package/dist/esm/security/ssrf/pinned-outbound-fetch.backend.utils.d.ts +143 -0
  963. package/dist/esm/security/ssrf/pinned-outbound-fetch.backend.utils.d.ts.map +1 -0
  964. package/dist/esm/security/ssrf/pinned-outbound-fetch.backend.utils.js +258 -0
  965. package/dist/esm/security/ssrf/pinned-outbound-fetch.backend.utils.js.map +1 -0
  966. package/dist/esm/users/services/user-read-retained.custom-impl.backend.service.d.ts +39 -0
  967. package/dist/esm/users/services/user-read-retained.custom-impl.backend.service.d.ts.map +1 -0
  968. package/dist/esm/users/services/user-read-retained.custom-impl.backend.service.js +159 -0
  969. package/dist/esm/users/services/user-read-retained.custom-impl.backend.service.js.map +1 -0
  970. package/dist/tsconfig.build.tsbuildinfo +1 -1
  971. package/package.json +17 -9
  972. package/dist/esm/.builder.pid +0 -9
@@ -1 +1 @@
1
- {"version":3,"file":"billing-custom-impl-utils.backend.js","sourceRoot":"","sources":["../../../../../../src/billing/services/custom-impl/billing-custom-impl-utils.backend.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EACL,qBAAqB,EACrB,gBAAgB,EAChB,oBAAoB,EACpB,SAAS,EACT,2BAA2B,EAC3B,kBAAkB,EAClB,8BAA8B,GAC/B,MAAM,uBAAuB,CAAC;AAK/B,uEAAuE;AAEvE,6DAA6D;AAC7D,MAAM,CAAC,MAAM,yBAAyB,GAAG;IACvC,gBAAgB,CAAC,yBAAyB;IAC1C,gBAAgB,CAAC,iBAAiB;CAC1B,CA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CAAC,KAAK,EAAE,IAAS,EAAE,EAAE;QAC5B,MAAM,KAAK,GAAG,MAAM,aAAa,CAAC,IAAI,CAAC,OAAO,EAAE,gBAAgB,EAAE,KAAK,CAAC,CAAC;QACzE,OAAO;YACL,0BAA0B,EAAE,IAAI,CAAC,0BAA0B;YAC3D,eAAe,EAAE,KAAK,CAAC,eAAe,IAAI,IAAI,CAAC,OAAO;YACtD,QAAQ,EAAE,IAAI,CAAC,QAAQ;SACxB,CAAC;IACJ,CAAC,CAAC,CACH,CAAC;AACJ,CAAC","sourcesContent":["/**\n * Shared helpers for billing custom implementations.\n *\n * Used by subscription and billing account custom impl factories,\n * the webhook event router, and the feature sync service\n * for cross-resource reads, provider validation, variant resolution,\n * and feature sync.\n */\n\nimport {\n CoreResourceOperation,\n CoreResourceType,\n ResourcePrimaryScope,\n ErrorType,\n ErrorCustomMessageReference,\n RelationshipNature,\n coreSharedResourceRelationship,\n} from '@wildo-ai/saas-models';\nimport type { ResourceType } from '@wildo-ai/saas-models';\nimport type { ResourceOperation_CustomImplementation_Utils } from '~wildo-backend-lib/base-classes/services/services/resource-operation-custom-implementation-base.backend.service';\nimport type { ExecutionContext } from '~wildo-backend-lib/runtime/models/execution-context.backend.schemas';\n\n// ── Credit Pool Variant Types ───────────────────────────────────────\n\n/** All credit pool polymorphic variant types (org, user). */\nexport const CREDIT_POOL_VARIANT_TYPES = [\n CoreResourceType.ORGANIZATION_CREDIT_POOLS,\n CoreResourceType.USER_CREDIT_POOLS,\n] as const;\n\n// ── Polymorphic Variant Resolution ──────────────────────────────────\n\n/**\n * Resolved billing polymorphic variant context.\n *\n * Provides the concrete resource types and FK field names for a specific\n * billing scope (organization or user). Used by the webhook\n * router, custom implementation postfix handlers, and the feature sync service\n * to query the correct polymorphic collections with the correct field names.\n */\nexport interface BillingResolvedVariants {\n /** The scope key on ExecutionContext that identifies this variant ('organizationId' | 'userId') */\n scopeKey: string;\n /**\n * The scope entity FK field name as it appears on variant DOCUMENTS.\n * May differ from `scopeKey` for some variants.\n */\n scopeEntityDocField: string;\n /** The corresponding ResourcePrimaryScope value for features resource resolution */\n scopeType: ResourcePrimaryScope;\n /** The polymorphic FK field name on child resources (e.g., 'organizationBillingAccountId') */\n billingAccountFkField: string;\n /** The billing account variant resource type */\n billingAccount: string;\n /** The subscription variant resource type */\n subscription: string;\n /** The invoice ref variant resource type */\n invoiceRef: string;\n /** The credit pool variant resource type */\n creditPool: string;\n /** The usage record variant resource type */\n usageRecord: string;\n}\n\n/**\n * Deterministic mapping from execution context scope key to billing polymorphic variants.\n * All billing child resources share the same scope prefix per variant.\n */\nexport const BILLING_SCOPE_TO_VARIANTS: Record<string, Omit<BillingResolvedVariants, 'scopeKey'>> = {\n organizationId: {\n scopeEntityDocField: 'organizationId',\n scopeType: ResourcePrimaryScope.ORGANIZATIONS,\n billingAccountFkField: 'organizationBillingAccountId',\n billingAccount: CoreResourceType.ORGANIZATION_BILLING_ACCOUNTS,\n subscription: CoreResourceType.ORGANIZATION_SUBSCRIPTIONS,\n invoiceRef: CoreResourceType.ORGANIZATION_INVOICE_REFS,\n creditPool: CoreResourceType.ORGANIZATION_CREDIT_POOLS,\n usageRecord: CoreResourceType.ORGANIZATION_USAGE_RECORDS,\n },\n userId: {\n scopeEntityDocField: 'userId',\n scopeType: ResourcePrimaryScope.USER_SELF,\n billingAccountFkField: 'userBillingAccountId',\n billingAccount: CoreResourceType.USER_BILLING_ACCOUNTS,\n subscription: CoreResourceType.USER_SUBSCRIPTIONS,\n invoiceRef: CoreResourceType.USER_INVOICE_REFS,\n creditPool: CoreResourceType.USER_CREDIT_POOLS,\n usageRecord: CoreResourceType.USER_USAGE_RECORDS,\n },\n};\n\n/**\n * Resolve billing variants from an execution context's scope IDs.\n * Returns null for APPLICATION-scoped events (no entity scope).\n */\nexport function resolveBillingVariants(execCtx: ExecutionContext<any>): BillingResolvedVariants | null {\n if (execCtx.organizationId) return { scopeKey: 'organizationId', ...BILLING_SCOPE_TO_VARIANTS.organizationId };\n if (execCtx.userId) return { scopeKey: 'userId', ...BILLING_SCOPE_TO_VARIANTS.userId };\n return null;\n}\n\n/**\n * Resolve billing variants from a known variant resource type.\n * Used by custom implementation factories that know their variant at registration time.\n */\nconst VARIANT_TO_SCOPE_KEY: Record<string, string> = {\n [CoreResourceType.ORGANIZATION_BILLING_ACCOUNTS]: 'organizationId',\n [CoreResourceType.USER_BILLING_ACCOUNTS]: 'userId',\n [CoreResourceType.ORGANIZATION_SUBSCRIPTIONS]: 'organizationId',\n [CoreResourceType.USER_SUBSCRIPTIONS]: 'userId',\n [CoreResourceType.ORGANIZATION_CREDIT_POOLS]: 'organizationId',\n [CoreResourceType.USER_CREDIT_POOLS]: 'userId',\n [CoreResourceType.ORGANIZATION_INVOICE_REFS]: 'organizationId',\n [CoreResourceType.USER_INVOICE_REFS]: 'userId',\n [CoreResourceType.ORGANIZATION_USAGE_RECORDS]: 'organizationId',\n [CoreResourceType.USER_USAGE_RECORDS]: 'userId',\n};\n\nexport function resolveBillingVariantsFromResourceType(variantResourceType: string): BillingResolvedVariants | null {\n const scopeKey = VARIANT_TO_SCOPE_KEY[variantResourceType];\n if (!scopeKey) return null;\n return { scopeKey, ...BILLING_SCOPE_TO_VARIANTS[scopeKey] };\n}\n\n/**\n * Reverse mapping: ResourcePrimaryScope → scope key for BILLING_SCOPE_TO_VARIANTS.\n */\nconst SCOPE_TYPE_TO_SCOPE_KEY: Record<string, string> = {\n [ResourcePrimaryScope.ORGANIZATIONS]: 'organizationId',\n [ResourcePrimaryScope.USER_SELF]: 'userId',\n};\n\n/**\n * Resolve billing variants from a ResourcePrimaryScope value.\n * Used by the billing state endpoint where the caller provides scopeType directly.\n */\nexport function resolveBillingVariantsFromScopeType(scopeType: ResourcePrimaryScope): BillingResolvedVariants | null {\n const scopeKey = SCOPE_TYPE_TO_SCOPE_KEY[scopeType];\n if (!scopeKey || !BILLING_SCOPE_TO_VARIANTS[scopeKey]) return null;\n return { scopeKey, ...BILLING_SCOPE_TO_VARIANTS[scopeKey] };\n}\n\n// ── Product / Price repository reads ────────────────────────────────\n\n/**\n * Build the read context for an APPLICATION-scoped catalog resource (products, prices, promotions).\n *\n * ## The correction this encodes\n *\n * These readers used to pass the CALLER's execution context straight to the repository, under a\n * comment that read \"Products are APPLICATION-scoped — no org/user scope filtering applies\". That\n * statement is true about the RESOURCE and false about the READ, and the gap between the two was a\n * live 500.\n *\n * `PRODUCTS` / `PRICES` / `PROMOTIONS` are indeed APPLICATION-primary-scoped and model neither\n * `organizationId` nor `userId`. But the repository does not filter by the TARGET's scoping model —\n * it applies whatever the CALLER's context carries, and it is fail-closed on a field the target does\n * not model: it THROWS `CONFIGURATION` / `context_filter` rather than skipping it. So \"no scope\n * filtering applies\" describes the intent and inverts the consequence.\n *\n * It fires for real. Every caller here is a `BILLING_ACCOUNTS` / `SUBSCRIPTIONS` custom impl, and both\n * are polymorphic resources whose organization variant injects `organizationId` into the operation\n * context — so an org-scoped purchase or plan change reached a catalog read with an `organizationId`\n * the catalog has no column for.\n *\n * The sub-call context narrows the inherited context to fields the target actually models, which for\n * these resources is none of the caller's scope FKs — giving the unfiltered catalog read the original\n * comment assumed it already had.\n */\nasync function createCatalogReadContext(\n resourceType: ResourceType,\n executionContext: ExecutionContext<any>,\n utils: ResourceOperation_CustomImplementation_Utils,\n): Promise<ExecutionContext<any>> {\n return utils.executionContextCreator.createForSubCall(\n executionContext,\n resourceType,\n CoreResourceOperation.READ,\n utils.serviceOptions,\n );\n}\n\n/**\n * Read a product from the repository by key.\n *\n * Products are APPLICATION-scoped, so no org/user scoping is MEANT to apply — which is precisely why\n * the read must not inherit the caller's scope context. See {@link createCatalogReadContext}.\n */\nexport async function readProductByKey(\n key: string,\n executionContext: ExecutionContext<any>,\n utils: ResourceOperation_CustomImplementation_Utils,\n): Promise<any> {\n const productRepo = utils.repositoriesRegistry.getRepository(CoreResourceType.PRODUCTS);\n if (!productRepo) {\n throw utils.errorBuilder.buildError(ErrorType.CONFIGURATION, executionContext, {\n customMessageReference: ErrorCustomMessageReference.BILLING_PRODUCT_NOT_FOUND,\n context: { productKey: key },\n });\n }\n const product = await productRepo.read(await createCatalogReadContext(CoreResourceType.PRODUCTS, executionContext, utils), { key });\n if (!product) {\n throw utils.errorBuilder.buildError(ErrorType.NOT_FOUND, executionContext, {\n customMessageReference: ErrorCustomMessageReference.BILLING_PRODUCT_NOT_FOUND,\n context: { productKey: key },\n });\n }\n return product;\n}\n\n/**\n * Read a product from the repository by ID.\n */\nexport async function readProductById(\n productId: string,\n executionContext: ExecutionContext<any>,\n utils: ResourceOperation_CustomImplementation_Utils,\n): Promise<any> {\n const productRepo = utils.repositoriesRegistry.getRepository(CoreResourceType.PRODUCTS);\n if (!productRepo) {\n throw utils.errorBuilder.buildError(ErrorType.CONFIGURATION, executionContext, {\n customMessageReference: ErrorCustomMessageReference.BILLING_PRODUCT_NOT_FOUND,\n context: { productId },\n });\n }\n const product = await productRepo.read(await createCatalogReadContext(CoreResourceType.PRODUCTS, executionContext, utils), productId);\n if (!product) {\n throw utils.errorBuilder.buildError(ErrorType.NOT_FOUND, executionContext, {\n customMessageReference: ErrorCustomMessageReference.BILLING_PRODUCT_NOT_FOUND,\n context: { productId },\n });\n }\n return product;\n}\n\n/**\n * Read a price from the repository by ID.\n *\n * APPLICATION-scoped like products, and read on a sub-call context for the same reason — see\n * {@link createCatalogReadContext}.\n *\n * ## Use {@link readPriceForProduct} whenever a product is also in play\n *\n * This reader answers \"what is price X\", nothing more. It is correct for resolving the price of an\n * ALREADY-PERSISTED subscription item, where the product↔price pairing was decided (and validated)\n * when the item was written. It is NOT correct for a purchase path where the caller names a product\n * and a price in the same request: there the pairing is the thing an attacker controls, and reading\n * the two independently is precisely the defect {@link assertPriceBelongsToProduct} closes.\n */\nexport async function readPriceById(\n priceId: string,\n executionContext: ExecutionContext<any>,\n utils: ResourceOperation_CustomImplementation_Utils,\n): Promise<any> {\n const priceRepo = utils.repositoriesRegistry.getRepository(CoreResourceType.PRICES);\n if (!priceRepo) {\n throw utils.errorBuilder.buildError(ErrorType.CONFIGURATION, executionContext, {\n customMessageReference: ErrorCustomMessageReference.BILLING_PRICE_NOT_FOUND,\n context: { priceId },\n });\n }\n const price = await priceRepo.read(await createCatalogReadContext(CoreResourceType.PRICES, executionContext, utils), priceId);\n if (!price) {\n throw utils.errorBuilder.buildError(ErrorType.NOT_FOUND, executionContext, {\n customMessageReference: ErrorCustomMessageReference.BILLING_PRICE_NOT_FOUND,\n context: { priceId },\n });\n }\n return price;\n}\n\n/**\n * Refuse a price that does not belong to the product it is being purchased against.\n *\n * ## Why this has to exist\n *\n * `Price.productId` is a declared foreign key — every price already knows its product. Every\n * purchase path nevertheless resolved the two INDEPENDENTLY (product by key, price by id) and\n * checked only that the price had a `providerPriceId`. The FK was never consulted.\n *\n * The consequence is a split between what is CHARGED and what is GRANTED. The provider is billed\n * `price.providerPriceId`, while the local subscription item records `productId: product._id`, and\n * entitlements (feature sync, plan tier, credit pack size) derive from the ITEM's product. So a\n * caller who pairs the premium product key with a cheap product's price id is billed the cheap\n * price and entitled at the premium product — an authorization outcome purchased at the wrong\n * amount, with both sides internally consistent and nothing downstream able to notice.\n *\n * ## Why a combined reader rather than a check at each site\n *\n * The three purchase paths (OPEN_CHECKOUT, CHANGE_PLAN, ADD_ADDON) are edited in different sessions\n * and each had the same omission. {@link readPriceForProduct} is the shape that makes the invariant\n * unbypassable for the next one: resolving a price in a product context and validating the pairing\n * are one call, so a new purchase path cannot obtain the price without the check having run.\n *\n * @param price - The price row, as read from the catalog.\n * @param product - The product row the purchase names.\n * @throws `VALIDATION` (400, `BILLING_PRICE_PRODUCT_MISMATCH`) when `price.productId !== product._id`.\n */\nexport function assertPriceBelongsToProduct(\n price: any,\n product: any,\n executionContext: ExecutionContext<any>,\n utils: ResourceOperation_CustomImplementation_Utils,\n): void {\n if (price?.productId === product?._id) return;\n\n throw utils.errorBuilder.buildError(ErrorType.VALIDATION, executionContext, {\n customMessageReference: ErrorCustomMessageReference.BILLING_PRICE_PRODUCT_MISMATCH,\n context: {\n priceId: price?._id,\n priceProductId: price?.productId ?? null,\n productId: product?._id,\n productKey: product?.key,\n },\n });\n}\n\n/**\n * Read a price and prove it belongs to the given product, in one step.\n *\n * The safe reader for every path where the caller names a product AND a price. See\n * {@link assertPriceBelongsToProduct} for what goes wrong when the two are resolved independently.\n */\nexport async function readPriceForProduct(\n priceId: string,\n product: any,\n executionContext: ExecutionContext<any>,\n utils: ResourceOperation_CustomImplementation_Utils,\n): Promise<any> {\n const price = await readPriceById(priceId, executionContext, utils);\n assertPriceBelongsToProduct(price, product, executionContext, utils);\n return price;\n}\n\n// ── Promotion resolution ────────────────────────────────────────────\n\n/**\n * Read an active promotion from the repository by its user-facing code.\n * Returns null if no active promotion with that code exists.\n */\nexport async function readPromotionByCode(\n code: string,\n executionContext: ExecutionContext<any>,\n utils: ResourceOperation_CustomImplementation_Utils,\n): Promise<any> {\n const promoRepo = utils.repositoriesRegistry.getRepository(CoreResourceType.PROMOTIONS);\n if (!promoRepo) return null;\n const promotion = await promoRepo.read(await createCatalogReadContext(CoreResourceType.PROMOTIONS, executionContext, utils), { code, isActive: true });\n return promotion ?? null;\n}\n\n// ── Billing account dependent scan (hard-delete guard) ──────────────\n\n/**\n * The retained financial child families that pin a billing account in place.\n *\n * Typed against `BillingResolvedVariants` so a rename of any variant field breaks the build\n * here rather than silently dropping a family from the guard.\n */\nexport type BillingAccountDependentFamily = Extract<\n keyof BillingResolvedVariants,\n 'subscription' | 'invoiceRef' | 'usageRecord' | 'creditPool'\n>;\n\n/**\n * Canonical ORDER of the billing child families. Order only — membership is derived below.\n *\n * Kept as an explicit tuple so the guard's scan order (and the report a human reads when a delete\n * is refused) is stable and mirrors the registry's declaration order, rather than depending on\n * however the relationship array happens to be arranged.\n */\nconst BILLING_ACCOUNT_DEPENDENT_FAMILY_ORDER: readonly BillingAccountDependentFamily[] = [\n 'subscription',\n 'invoiceRef',\n 'usageRecord',\n 'creditPool',\n] as const;\n\n/**\n * Every child family whose rows are RETAINED when their billing account is deleted.\n *\n * DERIVED from the registry, not restated. This used to be a hand-maintained list with a comment\n * asking a human to keep it in lock-step with `resources-registry.shared.core.definitions.ts` — the\n * exact coupling that rots, because the two live in different packages and nothing failed when they\n * disagreed. A family whose cascade is re-ENABLED now drops out of this list automatically (it is\n * no longer retained, so it no longer pins the account), and a family that stops being declared\n * disappears with it.\n *\n * The derivation asks the registry one question: for each `BillingAccounts → <child>` COMPOSITION\n * edge, is `onParentDelete` disabled? Disabled means \"these rows survive their parent\", which is\n * precisely what makes them a dependent that blocks a hard delete.\n *\n * Note this reads the BILLING-ACCOUNT edges specifically, not the scope edges. Both are disabled by\n * the same decision, but it is the account-parent edge that this guard is about.\n */\nexport const BILLING_ACCOUNT_DEPENDENT_FAMILIES: readonly BillingAccountDependentFamily[] =\n deriveRetainedBillingAccountDependentFamilies();\n\nfunction deriveRetainedBillingAccountDependentFamilies(): readonly BillingAccountDependentFamily[] {\n const billingAccountResourceTypes = new Set<string>(\n Object.values(BILLING_SCOPE_TO_VARIANTS).map((variants) => variants.billingAccount as string),\n );\n\n // child resource type → family key, across BOTH scope variants.\n const childResourceTypeToFamily = new Map<string, BillingAccountDependentFamily>();\n for (const variants of Object.values(BILLING_SCOPE_TO_VARIANTS)) {\n for (const family of BILLING_ACCOUNT_DEPENDENT_FAMILY_ORDER) {\n childResourceTypeToFamily.set(variants[family] as string, family);\n }\n }\n\n const retained = new Set<BillingAccountDependentFamily>();\n for (const relationship of coreSharedResourceRelationship) {\n if (relationship.nature !== RelationshipNature.COMPOSITION) continue;\n if (!billingAccountResourceTypes.has(relationship.resourceType1 as string)) continue;\n // Disabled (or absent) cascade == the child survives its parent == a retained dependent.\n if (relationship.childOperations?.lifecycle?.onParentDelete?.enabled === true) continue;\n\n const family = childResourceTypeToFamily.get(relationship.resourceType2 as string);\n if (family) retained.add(family);\n }\n\n return BILLING_ACCOUNT_DEPENDENT_FAMILY_ORDER.filter((family) => retained.has(family));\n}\n\n/**\n * Refuse hard removal of a billing account while retained financial children still reference it.\n *\n * ## Why this guard exists\n *\n * The billing-retention decision (2026-07-29) disabled `onParentDelete` on all 18 billing\n * cascades, so subscriptions / invoice refs / usage records / credit pools SURVIVE the deletion\n * of their scope and of their billing account. That made a direct hard delete of the account the\n * only remaining way to strand those retained rows behind a dangling FK.\n *\n * The damage is not merely referential: `providerCustomerId` is `.isBackendOnly()` and lives ONLY\n * on the account row. The children carry `providerInvoiceId` / `providerSubscriptionId` but NOT\n * the provider CUSTOMER id — so deleting the account destroys the only local key that maps a\n * retained invoice back to the customer it was billed to. A financial record that cannot be\n * reconciled against the provider defeats the purpose of retaining it. Nothing provider-side is\n * cleaned up on delete either, so the provider record lives on regardless.\n *\n * ## Why it fails closed\n *\n * The operation is `riskLevel: CRITICAL` and guards a compliance obligation, so \"cannot verify\"\n * must never read as \"nothing found\". A missing child repository raises `CONFIGURATION` rather\n * than being skipped, and any scope-filter failure inside the reads propagates instead of being\n * swallowed.\n *\n * The product off-boarding path is the soft retire (`isActive: false`), which this does not touch.\n *\n * Detection uses `read()` rather than `count()` deliberately: none of the four child families\n * declares a `COUNT` core operation, so `repository.count()` would throw INTERNAL. All four\n * declare `READ`. Each read is a single indexed hit on the billing-account FK, and the FK is\n * globally unique, so the result is correct regardless of how the execution context scopes it.\n *\n * @param billingAccountId - The account row about to be hard-deleted.\n * @param variants - Resolved polymorphic variants for the account's scope (org or user).\n * @throws `CONFLICT` (409, `BILLING_ACCOUNT_HAS_DEPENDENTS`) listing every blocking family.\n * @throws `CONFIGURATION` when a child family's repository is not registered (unverifiable).\n */\nexport async function assertNoBillingAccountDependents(\n billingAccountId: string,\n variants: BillingResolvedVariants,\n executionContext: ExecutionContext<any>,\n utils: ResourceOperation_CustomImplementation_Utils,\n): Promise<void> {\n const dependentFilter = { [variants.billingAccountFkField]: billingAccountId };\n\n const blockingFamilies = (\n await Promise.all(\n BILLING_ACCOUNT_DEPENDENT_FAMILIES.map(async (family) => {\n const childResourceType = variants[family];\n const childRepository = utils.repositoriesRegistry.getRepository(childResourceType);\n\n // Fail closed: an unregistered child repository means we cannot prove the family is\n // empty. Skipping it would silently downgrade the guard to \"nothing found\".\n if (!childRepository) {\n throw utils.errorBuilder.buildError(ErrorType.CONFIGURATION, executionContext, {\n customMessageReference: ErrorCustomMessageReference.CONFIGURATION,\n context: {\n message: 'Cannot verify billing-account dependents: child repository is not registered',\n billingAccountId,\n dependentFamily: family,\n childResourceType,\n },\n });\n }\n\n const existingChild = await childRepository.read(executionContext, dependentFilter);\n return existingChild ? family : undefined;\n }),\n )\n ).filter((family): family is BillingAccountDependentFamily => family !== undefined);\n\n if (blockingFamilies.length > 0) {\n throw utils.errorBuilder.buildError(ErrorType.CONFLICT, executionContext, {\n customMessageReference: ErrorCustomMessageReference.BILLING_ACCOUNT_HAS_DEPENDENTS,\n context: {\n billingAccountId,\n blockingDependentFamilies: blockingFamilies,\n blockingResourceTypes: blockingFamilies.map((family) => variants[family]),\n },\n });\n }\n}\n\n// ── Provider validation ─────────────────────────────────────────────\n\n/**\n * Validate that a subscription has a provider subscription ID.\n */\nexport function validateProviderSubscription(\n subscription: any,\n subscriptionId: string,\n executionContext: ExecutionContext<any>,\n utils: ResourceOperation_CustomImplementation_Utils,\n): void {\n if (!subscription?.providerSubscriptionId) {\n throw utils.errorBuilder.buildError(ErrorType.BUSINESS_RULE, executionContext, {\n customMessageReference: ErrorCustomMessageReference.BILLING_NO_PROVIDER_SUBSCRIPTION,\n context: { subscriptionId },\n });\n }\n}\n\n// ── Provider item resolution ────────────────────────────────────────\n\n/**\n * Resolve the providerPriceId for each subscription item by reading prices.\n */\nexport async function resolveProviderItems(\n items: any[],\n executionContext: ExecutionContext<any>,\n utils: ResourceOperation_CustomImplementation_Utils,\n): Promise<Array<{ providerSubscriptionItemId?: string; providerPriceId: string; quantity: number }>> {\n return Promise.all(\n items.map(async (item: any) => {\n const price = await readPriceById(item.priceId, executionContext, utils);\n return {\n providerSubscriptionItemId: item.providerSubscriptionItemId,\n providerPriceId: price.providerPriceId || item.priceId,\n quantity: item.quantity,\n };\n }),\n );\n}\n"]}
1
+ {"version":3,"file":"billing-custom-impl-utils.backend.js","sourceRoot":"","sources":["../../../../../../src/billing/services/custom-impl/billing-custom-impl-utils.backend.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EACL,qBAAqB,EACrB,gBAAgB,EAChB,oBAAoB,EACpB,SAAS,EACT,2BAA2B,EAC3B,kBAAkB,EAClB,8BAA8B,GAC/B,MAAM,uBAAuB,CAAC;AAK/B,uEAAuE;AAEvE,6DAA6D;AAC7D,MAAM,CAAC,MAAM,yBAAyB,GAAG;IACvC,gBAAgB,CAAC,yBAAyB;IAC1C,gBAAgB,CAAC,iBAAiB;CAC1B,CAAC;AAoCX;;;GAGG;AACH,MAAM,CAAC,MAAM,yBAAyB,GAA8D;IAClG,cAAc,EAAE;QACd,mBAAmB,EAAE,gBAAgB;QACrC,SAAS,EAAE,oBAAoB,CAAC,aAAa;QAC7C,qBAAqB,EAAE,8BAA8B;QACrD,cAAc,EAAE,gBAAgB,CAAC,6BAA6B;QAC9D,YAAY,EAAE,gBAAgB,CAAC,0BAA0B;QACzD,UAAU,EAAE,gBAAgB,CAAC,yBAAyB;QACtD,UAAU,EAAE,gBAAgB,CAAC,yBAAyB;QACtD,WAAW,EAAE,gBAAgB,CAAC,0BAA0B;KACzD;IACD,MAAM,EAAE;QACN,mBAAmB,EAAE,QAAQ;QAC7B,SAAS,EAAE,oBAAoB,CAAC,SAAS;QACzC,qBAAqB,EAAE,sBAAsB;QAC7C,cAAc,EAAE,gBAAgB,CAAC,qBAAqB;QACtD,YAAY,EAAE,gBAAgB,CAAC,kBAAkB;QACjD,UAAU,EAAE,gBAAgB,CAAC,iBAAiB;QAC9C,UAAU,EAAE,gBAAgB,CAAC,iBAAiB;QAC9C,WAAW,EAAE,gBAAgB,CAAC,kBAAkB;KACjD;CACF,CAAC;AAEF;;;GAGG;AACH,MAAM,U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5B,CAAC,CAAC;IACL,CAAC;AACH,CAAC;AAED,uEAAuE;AAEvE;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,oBAAoB,CACxC,KAAY,EACZ,gBAAuC,EACvC,KAAmD;IAEnD,OAAO,OAAO,CAAC,GAAG,CAChB,KAAK,CAAC,GAAG,CAAC,KAAK,EAAE,IAAS,EAAE,EAAE;QAC5B,MAAM,KAAK,GAAG,MAAM,aAAa,CAAC,IAAI,CAAC,OAAO,EAAE,gBAAgB,EAAE,KAAK,CAAC,CAAC;QACzE,OAAO;YACL,0BAA0B,EAAE,IAAI,CAAC,0BAA0B;YAC3D,eAAe,EAAE,KAAK,CAAC,eAAe,IAAI,IAAI,CAAC,OAAO;YACtD,QAAQ,EAAE,IAAI,CAAC,QAAQ;SACxB,CAAC;IACJ,CAAC,CAAC,CACH,CAAC;AACJ,CAAC","sourcesContent":["/**\n * Shared helpers for billing custom implementations.\n *\n * Used by subscription and billing account custom impl factories,\n * the webhook event router, and the feature sync service\n * for cross-resource reads, provider validation, variant resolution,\n * and feature sync.\n */\n\nimport {\n CoreResourceOperation,\n CoreResourceType,\n ResourcePrimaryScope,\n ErrorType,\n ErrorCustomMessageReference,\n RelationshipNature,\n coreSharedResourceRelationship,\n} from '@wildo-ai/saas-models';\nimport type { ResourceType } from '@wildo-ai/saas-models';\nimport type { ResourceOperation_CustomImplementation_Utils } from '~wildo-backend-lib/base-classes/services/services/resource-operation-custom-implementation-base.backend.service';\nimport type { ExecutionContext } from '~wildo-backend-lib/runtime/models/execution-context.backend.schemas';\n\n// ── Credit Pool Variant Types ───────────────────────────────────────\n\n/** All credit pool polymorphic variant types (org, user). */\nexport const CREDIT_POOL_VARIANT_TYPES = [\n CoreResourceType.ORGANIZATION_CREDIT_POOLS,\n CoreResourceType.USER_CREDIT_POOLS,\n] as const;\n\n// ── Polymorphic Variant Resolution ──────────────────────────────────\n\n/**\n * Resolved billing polymorphic variant context.\n *\n * Provides the concrete resource types and FK field names for a specific\n * billing scope (organization or user). Used by the webhook\n * router, custom implementation postfix handlers, and the feature sync service\n * to query the correct polymorphic collections with the correct field names.\n */\nexport interface BillingResolvedVariants {\n /** The scope key on ExecutionContext that identifies this variant ('organizationId' | 'userId') */\n scopeKey: string;\n /**\n * The scope entity FK field name as it appears on variant DOCUMENTS.\n * May differ from `scopeKey` for some variants.\n */\n scopeEntityDocField: string;\n /** The corresponding ResourcePrimaryScope value for features resource resolution */\n scopeType: ResourcePrimaryScope;\n /** The polymorphic FK field name on child resources (e.g., 'organizationBillingAccountId') */\n billingAccountFkField: string;\n /** The billing account variant resource type */\n billingAccount: string;\n /** The subscription variant resource type */\n subscription: string;\n /** The invoice ref variant resource type */\n invoiceRef: string;\n /** The credit pool variant resource type */\n creditPool: string;\n /** The usage record variant resource type */\n usageRecord: string;\n}\n\n/**\n * Deterministic mapping from execution context scope key to billing polymorphic variants.\n * All billing child resources share the same scope prefix per variant.\n */\nexport const BILLING_SCOPE_TO_VARIANTS: Record<string, Omit<BillingResolvedVariants, 'scopeKey'>> = {\n organizationId: {\n scopeEntityDocField: 'organizationId',\n scopeType: ResourcePrimaryScope.ORGANIZATIONS,\n billingAccountFkField: 'organizationBillingAccountId',\n billingAccount: CoreResourceType.ORGANIZATION_BILLING_ACCOUNTS,\n subscription: CoreResourceType.ORGANIZATION_SUBSCRIPTIONS,\n invoiceRef: CoreResourceType.ORGANIZATION_INVOICE_REFS,\n creditPool: CoreResourceType.ORGANIZATION_CREDIT_POOLS,\n usageRecord: CoreResourceType.ORGANIZATION_USAGE_RECORDS,\n },\n userId: {\n scopeEntityDocField: 'userId',\n scopeType: ResourcePrimaryScope.USER_SELF,\n billingAccountFkField: 'userBillingAccountId',\n billingAccount: CoreResourceType.USER_BILLING_ACCOUNTS,\n subscription: CoreResourceType.USER_SUBSCRIPTIONS,\n invoiceRef: CoreResourceType.USER_INVOICE_REFS,\n creditPool: CoreResourceType.USER_CREDIT_POOLS,\n usageRecord: CoreResourceType.USER_USAGE_RECORDS,\n },\n};\n\n/**\n * Resolve billing variants from an execution context's scope IDs.\n * Returns null for APPLICATION-scoped events (no entity scope).\n */\nexport function resolveBillingVariants(execCtx: ExecutionContext<any>): BillingResolvedVariants | null {\n if (execCtx.organizationId) return { scopeKey: 'organizationId', ...BILLING_SCOPE_TO_VARIANTS.organizationId };\n if (execCtx.userId) return { scopeKey: 'userId', ...BILLING_SCOPE_TO_VARIANTS.userId };\n return null;\n}\n\n/**\n * Resolve billing variants from a known variant resource type.\n * Used by custom implementation factories that know their variant at registration time.\n */\nconst VARIANT_TO_SCOPE_KEY: Record<string, string> = {\n [CoreResourceType.ORGANIZATION_BILLING_ACCOUNTS]: 'organizationId',\n [CoreResourceType.USER_BILLING_ACCOUNTS]: 'userId',\n [CoreResourceType.ORGANIZATION_SUBSCRIPTIONS]: 'organizationId',\n [CoreResourceType.USER_SUBSCRIPTIONS]: 'userId',\n [CoreResourceType.ORGANIZATION_CREDIT_POOLS]: 'organizationId',\n [CoreResourceType.USER_CREDIT_POOLS]: 'userId',\n [CoreResourceType.ORGANIZATION_INVOICE_REFS]: 'organizationId',\n [CoreResourceType.USER_INVOICE_REFS]: 'userId',\n [CoreResourceType.ORGANIZATION_USAGE_RECORDS]: 'organizationId',\n [CoreResourceType.USER_USAGE_RECORDS]: 'userId',\n};\n\nexport function resolveBillingVariantsFromResourceType(variantResourceType: string): BillingResolvedVariants | null {\n const scopeKey = VARIANT_TO_SCOPE_KEY[variantResourceType];\n if (!scopeKey) return null;\n return { scopeKey, ...BILLING_SCOPE_TO_VARIANTS[scopeKey] };\n}\n\n/**\n * Reverse mapping: ResourcePrimaryScope → scope key for BILLING_SCOPE_TO_VARIANTS.\n */\nconst SCOPE_TYPE_TO_SCOPE_KEY: Record<string, string> = {\n [ResourcePrimaryScope.ORGANIZATIONS]: 'organizationId',\n [ResourcePrimaryScope.USER_SELF]: 'userId',\n};\n\n/**\n * Resolve billing variants from a ResourcePrimaryScope value.\n * Used by the billing state endpoint where the caller provides scopeType directly.\n */\nexport function resolveBillingVariantsFromScopeType(scopeType: ResourcePrimaryScope): BillingResolvedVariants | null {\n const scopeKey = SCOPE_TYPE_TO_SCOPE_KEY[scopeType];\n if (!scopeKey || !BILLING_SCOPE_TO_VARIANTS[scopeKey]) return null;\n return { scopeKey, ...BILLING_SCOPE_TO_VARIANTS[scopeKey] };\n}\n\n// ── Product / Price repository reads ────────────────────────────────\n\n/**\n * Build the read context for an APPLICATION-scoped catalog resource (products, prices, promotions).\n *\n * ## The correction this encodes\n *\n * These readers used to pass the CALLER's execution context straight to the repository, under a\n * comment that read \"Products are APPLICATION-scoped — no org/user scope filtering applies\". That\n * statement is true about the RESOURCE and false about the READ, and the gap between the two was a\n * live 500.\n *\n * `PRODUCTS` / `PRICES` / `PROMOTIONS` are indeed APPLICATION-primary-scoped and model neither\n * `organizationId` nor `userId`. But the repository does not filter by the TARGET's scoping model —\n * it applies whatever the CALLER's context carries, and it is fail-closed on a field the target does\n * not model: it THROWS `CONFIGURATION` / `context_filter` rather than skipping it. So \"no scope\n * filtering applies\" describes the intent and inverts the consequence.\n *\n * It fires for real. Every caller here is a `BILLING_ACCOUNTS` / `SUBSCRIPTIONS` custom impl, and both\n * are polymorphic resources whose organization variant injects `organizationId` into the operation\n * context — so an org-scoped purchase or plan change reached a catalog read with an `organizationId`\n * the catalog has no column for.\n *\n * The sub-call context narrows the inherited context to fields the target actually models, which for\n * these resources is none of the caller's scope FKs — giving the unfiltered catalog read the original\n * comment assumed it already had.\n */\nasync function createCatalogReadContext(\n resourceType: ResourceType,\n executionContext: ExecutionContext<any>,\n utils: ResourceOperation_CustomImplementation_Utils,\n): Promise<ExecutionContext<any>> {\n return utils.executionContextCreator.createForSubCall(\n executionContext,\n resourceType,\n CoreResourceOperation.READ,\n utils.serviceOptions,\n );\n}\n\n/**\n * Why a catalog row is being read — and therefore whether a RETIRED row may be returned.\n *\n * ## Why this is a required parameter rather than a check at the sites that need it\n *\n * `Product.isActive` is the declared off-boarding path (`assertNoBillingAccountDependents` calls\n * the soft retire exactly that), and no purchase path consulted it: `readProductByKey` handed back\n * a retired product exactly like a live one, so \"retired\" was a label with no behaviour behind it\n * and the catalogue-retirement reconciliation below would have been cosmetic.\n *\n * The gate is a REQUIRED argument on the reader — the same shape, and for the same reason, as\n * {@link readPriceForProduct} making the price→product FK check unbypassable: the four call sites\n * are edited in different sessions, three of them must refuse and one must NOT, and a separate\n * `assertProductIsPurchasable` helper is exactly the thing the fourth session forgets. Making the\n * distinction unrepresentable-by-omission costs one argument and removes the whole failure mode.\n *\n * The enumeration, so a fifth site can see which company it is in:\n * - OPEN_CHECKOUT (`billing-account.mutations`) — ACQUIRE.\n * - CHANGE_PLAN target product (`subscription.mutations`) — ACQUIRE.\n * - ADD_ADDON product (`subscription.mutations`) — ACQUIRE.\n * - REMOVE_ADDON product (`subscription.mutations`) — **REFERENCE, deliberately.** A customer\n * holding a retired add-on must be able to drop it; refusing here would trap them on the very\n * product the catalogue withdrew.\n */\nexport enum BillingCatalogReadIntent {\n /**\n * The caller is about to BUY this, or move a subscription onto it. A retired row is refused with\n * `CONFLICT` / `BILLING_PRODUCT_RETIRED`.\n */\n ACQUIRE = 'acquire',\n /**\n * The caller is naming a row that a subscription ALREADY points at — to display it, to remove it,\n * to rebuild a provider item list. A retired row is returned normally, because refusing would\n * break the paths a customer on a retired product needs most.\n */\n REFERENCE = 'reference',\n}\n\n/**\n * Read a product from the repository by key.\n *\n * Products are APPLICATION-scoped, so no org/user scoping is MEANT to apply — which is precisely why\n * the read must not inherit the caller's scope context. See {@link createCatalogReadContext}.\n */\nexport async function readProductByKey(\n key: string,\n intent: BillingCatalogReadIntent,\n executionContext: ExecutionContext<any>,\n utils: ResourceOperation_CustomImplementation_Utils,\n): Promise<any> {\n const productRepo = utils.repositoriesRegistry.getRepository(CoreResourceType.PRODUCTS);\n if (!productRepo) {\n throw utils.errorBuilder.buildError(ErrorType.CONFIGURATION, executionContext, {\n customMessageReference: ErrorCustomMessageReference.BILLING_PRODUCT_NOT_FOUND,\n context: { productKey: key },\n });\n }\n const product = await productRepo.read(await createCatalogReadContext(CoreResourceType.PRODUCTS, executionContext, utils), { key });\n if (!product) {\n throw utils.errorBuilder.buildError(ErrorType.NOT_FOUND, executionContext, {\n customMessageReference: ErrorCustomMessageReference.BILLING_PRODUCT_NOT_FOUND,\n context: { productKey: key },\n });\n }\n const productRow = product as any;\n if (intent === BillingCatalogReadIntent.ACQUIRE && productRow.isActive === false) {\n throw utils.errorBuilder.buildError(ErrorType.CONFLICT, executionContext, {\n customMessageReference: ErrorCustomMessageReference.BILLING_PRODUCT_RETIRED,\n context: { productKey: key, productId: productRow._id },\n });\n }\n return productRow;\n}\n\n/**\n * Read a product from the repository by ID.\n */\nexport async function readProductById(\n productId: string,\n executionContext: ExecutionContext<any>,\n utils: ResourceOperation_CustomImplementation_Utils,\n): Promise<any> {\n const productRepo = utils.repositoriesRegistry.getRepository(CoreResourceType.PRODUCTS);\n if (!productRepo) {\n throw utils.errorBuilder.buildError(ErrorType.CONFIGURATION, executionContext, {\n customMessageReference: ErrorCustomMessageReference.BILLING_PRODUCT_NOT_FOUND,\n context: { productId },\n });\n }\n const product = await productRepo.read(await createCatalogReadContext(CoreResourceType.PRODUCTS, executionContext, utils), productId);\n if (!product) {\n throw utils.errorBuilder.buildError(ErrorType.NOT_FOUND, executionContext, {\n customMessageReference: ErrorCustomMessageReference.BILLING_PRODUCT_NOT_FOUND,\n context: { productId },\n });\n }\n return product;\n}\n\n/**\n * Read a price from the repository by ID.\n *\n * APPLICATION-scoped like products, and read on a sub-call context for the same reason — see\n * {@link createCatalogReadContext}.\n *\n * ## Use {@link readPriceForProduct} whenever a product is also in play\n *\n * This reader answers \"what is price X\", nothing more. It is correct for resolving the price of an\n * ALREADY-PERSISTED subscription item, where the product↔price pairing was decided (and validated)\n * when the item was written. It is NOT correct for a purchase path where the caller names a product\n * and a price in the same request: there the pairing is the thing an attacker controls, and reading\n * the two independently is precisely the defect {@link assertPriceBelongsToProduct} closes.\n */\nexport async function readPriceById(\n priceId: string,\n executionContext: ExecutionContext<any>,\n utils: ResourceOperation_CustomImplementation_Utils,\n): Promise<any> {\n const priceRepo = utils.repositoriesRegistry.getRepository(CoreResourceType.PRICES);\n if (!priceRepo) {\n throw utils.errorBuilder.buildError(ErrorType.CONFIGURATION, executionContext, {\n customMessageReference: ErrorCustomMessageReference.BILLING_PRICE_NOT_FOUND,\n context: { priceId },\n });\n }\n const price = await priceRepo.read(await createCatalogReadContext(CoreResourceType.PRICES, executionContext, utils), priceId);\n if (!price) {\n throw utils.errorBuilder.buildError(ErrorType.NOT_FOUND, executionContext, {\n customMessageReference: ErrorCustomMessageReference.BILLING_PRICE_NOT_FOUND,\n context: { priceId },\n });\n }\n return price;\n}\n\n/**\n * Refuse a price that does not belong to the product it is being purchased against.\n *\n * ## Why this has to exist\n *\n * `Price.productId` is a declared foreign key — every price already knows its product. Every\n * purchase path nevertheless resolved the two INDEPENDENTLY (product by key, price by id) and\n * checked only that the price had a `providerPriceId`. The FK was never consulted.\n *\n * The consequence is a split between what is CHARGED and what is GRANTED. The provider is billed\n * `price.providerPriceId`, while the local subscription item records `productId: product._id`, and\n * entitlements (feature sync, plan tier, credit pack size) derive from the ITEM's product. So a\n * caller who pairs the premium product key with a cheap product's price id is billed the cheap\n * price and entitled at the premium product — an authorization outcome purchased at the wrong\n * amount, with both sides internally consistent and nothing downstream able to notice.\n *\n * ## Why a combined reader rather than a check at each site\n *\n * The three purchase paths (OPEN_CHECKOUT, CHANGE_PLAN, ADD_ADDON) are edited in different sessions\n * and each had the same omission. {@link readPriceForProduct} is the shape that makes the invariant\n * unbypassable for the next one: resolving a price in a product context and validating the pairing\n * are one call, so a new purchase path cannot obtain the price without the check having run.\n *\n * @param price - The price row, as read from the catalog.\n * @param product - The product row the purchase names.\n * @throws `VALIDATION` (400, `BILLING_PRICE_PRODUCT_MISMATCH`) when `price.productId !== product._id`.\n */\nexport function assertPriceBelongsToProduct(\n price: any,\n product: any,\n executionContext: ExecutionContext<any>,\n utils: ResourceOperation_CustomImplementation_Utils,\n): void {\n if (price?.productId === product?._id) return;\n\n throw utils.errorBuilder.buildError(ErrorType.VALIDATION, executionContext, {\n customMessageReference: ErrorCustomMessageReference.BILLING_PRICE_PRODUCT_MISMATCH,\n context: {\n priceId: price?._id,\n priceProductId: price?.productId ?? null,\n productId: product?._id,\n productKey: product?.key,\n },\n });\n}\n\n/**\n * Read a price and prove it belongs to the given product, in one step.\n *\n * The safe reader for every path where the caller names a product AND a price. See\n * {@link assertPriceBelongsToProduct} for what goes wrong when the two are resolved independently.\n */\nexport async function readPriceForProduct(\n priceId: string,\n product: any,\n executionContext: ExecutionContext<any>,\n utils: ResourceOperation_CustomImplementation_Utils,\n): Promise<any> {\n const price = await readPriceById(priceId, executionContext, utils);\n assertPriceBelongsToProduct(price, product, executionContext, utils);\n /*\n * A retired PRICE is refused here and nowhere else, and that placement is the whole argument.\n *\n * All three callers of this reader are acquisitions (OPEN_CHECKOUT, CHANGE_PLAN, ADD_ADDON) —\n * that is what the reader is FOR, per its own doc above — so the gate needs no intent argument\n * and cannot be reached by a reference read. `readPriceById`, which resolves the price of an\n * already-persisted subscription item, is deliberately left ungated: a subscriber on a retired\n * plan rebuilds their provider item list through it on every add-on change, and refusing there\n * would break the customer the retirement was supposed to leave alone.\n *\n * The catalogue-retirement sweep deactivates a retired product's prices alongside the product, so\n * in practice this fires together with the product gate; it is separate because an operator may\n * also retire a single price (a currency, an interval) while the product stays on sale.\n */\n if (price?.isActive === false) {\n throw utils.errorBuilder.buildError(ErrorType.CONFLICT, executionContext, {\n customMessageReference: ErrorCustomMessageReference.BILLING_PRODUCT_RETIRED,\n context: { priceId, productId: product?._id, productKey: product?.key },\n });\n }\n return price;\n}\n\n// ── Promotion resolution ────────────────────────────────────────────\n\n/**\n * Read an active promotion from the repository by its user-facing code.\n * Returns null if no active promotion with that code exists.\n */\nexport async function readPromotionByCode(\n code: string,\n executionContext: ExecutionContext<any>,\n utils: ResourceOperation_CustomImplementation_Utils,\n): Promise<any> {\n const promoRepo = utils.repositoriesRegistry.getRepository(CoreResourceType.PROMOTIONS);\n if (!promoRepo) return null;\n const promotion = await promoRepo.read(await createCatalogReadContext(CoreResourceType.PROMOTIONS, executionContext, utils), { code, isActive: true });\n return promotion ?? null;\n}\n\n// ── Billing account dependent scan (hard-delete guard) ──────────────\n\n/**\n * The retained financial child families that pin a billing account in place.\n *\n * Typed against `BillingResolvedVariants` so a rename of any variant field breaks the build\n * here rather than silently dropping a family from the guard.\n */\nexport type BillingAccountDependentFamily = Extract<\n keyof BillingResolvedVariants,\n 'subscription' | 'invoiceRef' | 'usageRecord' | 'creditPool'\n>;\n\n/**\n * Canonical ORDER of the billing child families. Order only — membership is derived below.\n *\n * Kept as an explicit tuple so the guard's scan order (and the report a human reads when a delete\n * is refused) is stable and mirrors the registry's declaration order, rather than depending on\n * however the relationship array happens to be arranged.\n */\nconst BILLING_ACCOUNT_DEPENDENT_FAMILY_ORDER: readonly BillingAccountDependentFamily[] = [\n 'subscription',\n 'invoiceRef',\n 'usageRecord',\n 'creditPool',\n] as const;\n\n/**\n * Every child family whose rows are RETAINED when their billing account is deleted.\n *\n * DERIVED from the registry, not restated. This used to be a hand-maintained list with a comment\n * asking a human to keep it in lock-step with `resources-registry.shared.core.definitions.ts` — the\n * exact coupling that rots, because the two live in different packages and nothing failed when they\n * disagreed. A family whose cascade is re-ENABLED now drops out of this list automatically (it is\n * no longer retained, so it no longer pins the account), and a family that stops being declared\n * disappears with it.\n *\n * The derivation asks the registry one question: for each `BillingAccounts → <child>` COMPOSITION\n * edge, is `onParentDelete` disabled? Disabled means \"these rows survive their parent\", which is\n * precisely what makes them a dependent that blocks a hard delete.\n *\n * Note this reads the BILLING-ACCOUNT edges specifically, not the scope edges. Both are disabled by\n * the same decision, but it is the account-parent edge that this guard is about.\n */\nexport const BILLING_ACCOUNT_DEPENDENT_FAMILIES: readonly BillingAccountDependentFamily[] =\n deriveRetainedBillingAccountDependentFamilies();\n\nfunction deriveRetainedBillingAccountDependentFamilies(): readonly BillingAccountDependentFamily[] {\n const billingAccountResourceTypes = new Set<string>(\n Object.values(BILLING_SCOPE_TO_VARIANTS).map((variants) => variants.billingAccount as string),\n );\n\n // child resource type → family key, across BOTH scope variants.\n const childResourceTypeToFamily = new Map<string, BillingAccountDependentFamily>();\n for (const variants of Object.values(BILLING_SCOPE_TO_VARIANTS)) {\n for (const family of BILLING_ACCOUNT_DEPENDENT_FAMILY_ORDER) {\n childResourceTypeToFamily.set(variants[family] as string, family);\n }\n }\n\n const retained = new Set<BillingAccountDependentFamily>();\n for (const relationship of coreSharedResourceRelationship) {\n if (relationship.nature !== RelationshipNature.COMPOSITION) continue;\n if (!billingAccountResourceTypes.has(relationship.resourceType1 as string)) continue;\n // Disabled (or absent) cascade == the child survives its parent == a retained dependent.\n if (relationship.childOperations?.lifecycle?.onParentDelete?.enabled === true) continue;\n\n const family = childResourceTypeToFamily.get(relationship.resourceType2 as string);\n if (family) retained.add(family);\n }\n\n return BILLING_ACCOUNT_DEPENDENT_FAMILY_ORDER.filter((family) => retained.has(family));\n}\n\n/**\n * Refuse hard removal of a billing account while retained financial children still reference it.\n *\n * ## Why this guard exists\n *\n * The billing-retention decision (2026-07-29) disabled `onParentDelete` on all 18 billing\n * cascades, so subscriptions / invoice refs / usage records / credit pools SURVIVE the deletion\n * of their scope and of their billing account. That made a direct hard delete of the account the\n * only remaining way to strand those retained rows behind a dangling FK.\n *\n * The damage is not merely referential: `providerCustomerId` is `.isBackendOnly()` and lives ONLY\n * on the account row. The children carry `providerInvoiceId` / `providerSubscriptionId` but NOT\n * the provider CUSTOMER id — so deleting the account destroys the only local key that maps a\n * retained invoice back to the customer it was billed to. A financial record that cannot be\n * reconciled against the provider defeats the purpose of retaining it. Nothing provider-side is\n * cleaned up on delete either, so the provider record lives on regardless.\n *\n * ## Why it fails closed\n *\n * The operation is `riskLevel: CRITICAL` and guards a compliance obligation, so \"cannot verify\"\n * must never read as \"nothing found\". A missing child repository raises `CONFIGURATION` rather\n * than being skipped, and any scope-filter failure inside the reads propagates instead of being\n * swallowed.\n *\n * The product off-boarding path is the soft retire (`isActive: false`), which this does not touch.\n *\n * Detection uses `read()` rather than `count()` deliberately: none of the four child families\n * declares a `COUNT` core operation, so `repository.count()` would throw INTERNAL. All four\n * declare `READ`. Each read is a single indexed hit on the billing-account FK, and the FK is\n * globally unique, so the result is correct regardless of how the execution context scopes it.\n *\n * @param billingAccountId - The account row about to be hard-deleted.\n * @param variants - Resolved polymorphic variants for the account's scope (org or user).\n * @throws `CONFLICT` (409, `BILLING_ACCOUNT_HAS_DEPENDENTS`) listing every blocking family.\n * @throws `CONFIGURATION` when a child family's repository is not registered (unverifiable).\n */\nexport async function assertNoBillingAccountDependents(\n billingAccountId: string,\n variants: BillingResolvedVariants,\n executionContext: ExecutionContext<any>,\n utils: ResourceOperation_CustomImplementation_Utils,\n): Promise<void> {\n const dependentFilter = { [variants.billingAccountFkField]: billingAccountId };\n\n const blockingFamilies = (\n await Promise.all(\n BILLING_ACCOUNT_DEPENDENT_FAMILIES.map(async (family) => {\n const childResourceType = variants[family];\n const childRepository = utils.repositoriesRegistry.getRepository(childResourceType);\n\n // Fail closed: an unregistered child repository means we cannot prove the family is\n // empty. Skipping it would silently downgrade the guard to \"nothing found\".\n if (!childRepository) {\n throw utils.errorBuilder.buildError(ErrorType.CONFIGURATION, executionContext, {\n customMessageReference: ErrorCustomMessageReference.CONFIGURATION,\n context: {\n message: 'Cannot verify billing-account dependents: child repository is not registered',\n billingAccountId,\n dependentFamily: family,\n childResourceType,\n },\n });\n }\n\n const existingChild = await childRepository.read(executionContext, dependentFilter);\n return existingChild ? family : undefined;\n }),\n )\n ).filter((family): family is BillingAccountDependentFamily => family !== undefined);\n\n if (blockingFamilies.length > 0) {\n throw utils.errorBuilder.buildError(ErrorType.CONFLICT, executionContext, {\n customMessageReference: ErrorCustomMessageReference.BILLING_ACCOUNT_HAS_DEPENDENTS,\n context: {\n billingAccountId,\n blockingDependentFamilies: blockingFamilies,\n blockingResourceTypes: blockingFamilies.map((family) => variants[family]),\n },\n });\n }\n}\n\n// ── Provider validation ─────────────────────────────────────────────\n\n/**\n * Validate that a subscription has a provider subscription ID.\n */\nexport function validateProviderSubscription(\n subscription: any,\n subscriptionId: string,\n executionContext: ExecutionContext<any>,\n utils: ResourceOperation_CustomImplementation_Utils,\n): void {\n if (!subscription?.providerSubscriptionId) {\n throw utils.errorBuilder.buildError(ErrorType.BUSINESS_RULE, executionContext, {\n customMessageReference: ErrorCustomMessageReference.BILLING_NO_PROVIDER_SUBSCRIPTION,\n context: { subscriptionId },\n });\n }\n}\n\n// ── Provider item resolution ────────────────────────────────────────\n\n/**\n * Resolve the providerPriceId for each subscription item by reading prices.\n */\nexport async function resolveProviderItems(\n items: any[],\n executionContext: ExecutionContext<any>,\n utils: ResourceOperation_CustomImplementation_Utils,\n): Promise<Array<{ providerSubscriptionItemId?: string; providerPriceId: string; quantity: number }>> {\n return Promise.all(\n items.map(async (item: any) => {\n const price = await readPriceById(item.priceId, executionContext, utils);\n return {\n providerSubscriptionItemId: item.providerSubscriptionItemId,\n providerPriceId: price.providerPriceId || item.priceId,\n quantity: item.quantity,\n };\n }),\n );\n}\n"]}
@@ -23,11 +23,31 @@ import type { BillingStateBackendService } from '../../../billing/services/back-
23
23
  * Called from start-application after the billing provider is resolved.
24
24
  * Must be called before any billing custom operation executes.
25
25
  */
26
- export declare function initializeBillingCustomImplementations(provider: StandardBilling_Interface, featureSyncService: BillingFeatureSyncBackendService, billingStateService: BillingStateBackendService, billingConfig: BillingConfiguration, errorBuilder: ErrorBuilderBackendService): void;
26
+ export declare function initializeBillingCustomImplementations(provider: StandardBilling_Interface, featureSyncService: BillingFeatureSyncBackendService, billingStateService: BillingStateBackendService, billingConfig: BillingConfiguration, errorBuilder: ErrorBuilderBackendService, providerRef: string): void;
27
27
  /**
28
28
  * Set the WebSocket service for credit pool post-op event emission.
29
29
  * Called from start-application after WebSocket service is resolved.
30
30
  */
31
+ /**
32
+ * Publish the usage-metering service for the post-operation usage hook (#415).
33
+ *
34
+ * A module-level seam rather than a DI edge, deliberately and for the same reason the WebSocket
35
+ * service beside it uses one: `UsageMeteringBackendService` injects
36
+ * `ServicesRegistryHandlerService`, and the hook lives ON that handler — so injecting the metering
37
+ * service there would be a container cycle.
38
+ *
39
+ * It also gives the right behaviour for free: an application with no billing configured never calls
40
+ * this, `getUsageMeteringService()` returns `null`, and the hook costs one null check per write
41
+ * instead of resolving a service that would refuse anyway.
42
+ */
43
+ export declare function setUsageMeteringService(usageMeteringService: import('../../../billing/services/back-office/usage-metering.backend.service').UsageMeteringBackendService): void;
44
+ /**
45
+ * The usage-metering service, or `null` when billing is not configured.
46
+ *
47
+ * `null` rather than a throw, unlike `getBillingProvider()`: a write on a resource that declares no
48
+ * metered usage must not be able to fail because billing is absent, and the caller checks.
49
+ */
50
+ export declare function getUsageMeteringService(): import('../../../billing/services/back-office/usage-metering.backend.service').UsageMeteringBackendService | null;
31
51
  export declare function setBillingWebSocketService(webSocketService: import('../../../requests/service/websocket.service').WebSocketService): void;
32
52
  /**
33
53
  * Get the WebSocket service (optional — returns null if not initialized).
@@ -38,6 +58,15 @@ export declare function getWebSocketService(): import('../../../requests/service
38
58
  * @throws if initializeBillingCustomImplementations() has not been called
39
59
  */
40
60
  export declare function getBillingProvider(): StandardBilling_Interface;
61
+ /**
62
+ * The provider ref the billing adapter was resolved under. Rows that record which provider
63
+ * owns a customer (`providerRef` on billing accounts) take it from HERE — never from a literal
64
+ * default: `config.providerRef || 'stripe'` stood at that site until 2026-09-05 (#327), a branch
65
+ * on a provider ref that the guard test could not see and that would have stamped every row
66
+ * 'stripe' under any other billing adapter.
67
+ * @throws if initializeBillingCustomImplementations() has not been called
68
+ */
69
+ export declare function getBillingProviderRef(): string;
41
70
  /**
42
71
  * Get the feature sync service (lazy — resolved at operation execution time).
43
72
  * @throws if initializeBillingCustomImplementations() has not been called
@@ -1 +1 @@
1
- {"version":3,"file":"billing-custom-implementations.backend.d.ts","sourceRoot":"","sources":["../../../../../../src/billing/services/custom-impl/billing-custom-implementations.backend.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,sCAAsC,CAAC;AAEtF,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,uBAAuB,CAAC;AAClE,OAAO,KAAK,EAAE,qCAAqC,EAAE,MAAM,6FAA6F,CAAC;AAEzJ,OAAO,KAAK,EAAE,0CAA0C,EAAE,MAAM,4GAA4G,CAAC;AAC7K,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,kEAAkE,CAAC;AACnH,OAAO,KAAK,EAAE,gCAAgC,EAAE,MAAM,sFAAsF,CAAC;AAC7I,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,+EAA+E,CAAC;AA8ChI;;;;GAIG;AACH,wBAAgB,sCAAsC,CACpD,QAAQ,EAAE,yBAAyB,EACnC,kBAAkB,EAAE,gCAAgC,EACpD,mBAAmB,EAAE,0BAA0B,EAC/C,aAAa,EAAE,oBAAoB,EACnC,YAAY,EAAE,0BAA0B,GACvC,IAAI,CAMN;AAED;;;GAGG;AACH,wBAAgB,0BAA0B,CACxC,gBAAgB,EAAE,OAAO,uDAAuD,EAAE,gBAAgB,GACjG,IAAI,CAEN;AAED;;GAEG;AACH,wBAAgB,mBAAmB,IAAI,OAAO,uDAAuD,EAAE,gBAAgB,GAAG,IAAI,CAE7H;AAED;;;GAGG;AACH,wBAAgB,kBAAkB,IAAI,yBAAyB,CAO9D;AAED;;;GAGG;AACH,wBAAgB,qBAAqB,IAAI,gCAAgC,CAOxE;AAED;;;GAGG;AACH,wBAAgB,sBAAsB,IAAI,0BAA0B,CAOnE;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,IAAI,oBAAoB,CAOvD;AAID,eAAO,MAAM,4BAA4B,EAAE,0CAA0C,EAqBpF,CAAC;AAUF;;;;;;;GAOG;AACH,wBAAgB,iCAAiC,CAC/C,gBAAgB,EAAE,qCAAqC,GACtD,IAAI,CAwCN"}
1
+ {"version":3,"file":"billing-custom-implementations.backend.d.ts","sourceRoot":"","sources":["../../../../../../src/billing/services/custom-impl/billing-custom-implementations.backend.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,sCAAsC,CAAC;AAEtF,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,uBAAuB,CAAC;AAClE,OAAO,KAAK,EAAE,qCAAqC,EAAE,MAAM,6FAA6F,CAAC;AAEzJ,OAAO,KAAK,EAAE,0CAA0C,EAAE,MAAM,4GAA4G,CAAC;AAC7K,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,kEAAkE,CAAC;AACnH,OAAO,KAAK,EAAE,gCAAgC,EAAE,MAAM,sFAAsF,CAAC;AAC7I,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,+EAA+E,CAAC;AAiDhI;;;;GAIG;AACH,wBAAgB,sCAAsC,CACpD,QAAQ,EAAE,yBAAyB,EACnC,kBAAkB,EAAE,gCAAgC,EACpD,mBAAmB,EAAE,0BAA0B,EAC/C,aAAa,EAAE,oBAAoB,EACnC,YAAY,EAAE,0BAA0B,EACxC,WAAW,EAAE,MAAM,GAClB,IAAI,CAON;AAED;;;GAGG;AACH;;;;;;;;;;;GAWG;AACH,wBAAgB,uBAAuB,CACrC,oBAAoB,EAAE,OAAO,gFAAgF,EAAE,2BAA2B,GACzI,IAAI,CAEN;AAED;;;;;GAKG;AACH,wBAAgB,uBAAuB,IACrC,OAAO,gFAAgF,EAAE,2BAA2B,GAAG,IAAI,CAE5H;AAED,wBAAgB,0BAA0B,CACxC,gBAAgB,EAAE,OAAO,uDAAuD,EAAE,gBAAgB,GACjG,IAAI,CAEN;AAED;;GAEG;AACH,wBAAgB,mBAAmB,IAAI,OAAO,uDAAuD,EAAE,gBAAgB,GAAG,IAAI,CAE7H;AAED;;;GAGG;AACH,wBAAgB,kBAAkB,IAAI,yBAAyB,CAO9D;AAED;;;;;;;GAOG;AACH,wBAAgB,qBAAqB,IAAI,MAAM,CAO9C;AAED;;;GAGG;AACH,wBAAgB,qBAAqB,IAAI,gCAAgC,CAOxE;AAED;;;GAGG;AACH,wBAAgB,sBAAsB,IAAI,0BAA0B,CAOnE;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,IAAI,oBAAoB,CAOvD;AAID,eAAO,MAAM,4BAA4B,EAAE,0CAA0C,EAqBpF,CAAC;AAUF;;;;;;;GAOG;AACH,wBAAgB,iCAAiC,CAC/C,gBAAgB,EAAE,qCAAqC,GACtD,IAAI,CAwCN"}
@@ -22,8 +22,11 @@ let _billingProvider = null;
22
22
  let _featureSyncService = null;
23
23
  let _billingStateService = null;
24
24
  let _billingConfig = null;
25
+ /** The ref the billing provider was RESOLVED under at startup — the one rows are stamped with. */
26
+ let _billingProviderRef = null;
25
27
  let _errorBuilder = null;
26
28
  let _webSocketService = null;
29
+ let _usageMeteringService = null;
27
30
  /** Throw a CONFIGURATION WildoError_Backend, or fall back to plain Error if error builder itself isn't initialized yet. */
28
31
  function throwBillingNotInitialized(message) {
29
32
  if (_errorBuilder) {
@@ -39,8 +42,9 @@ function throwBillingNotInitialized(message) {
39
42
  * Called from start-application after the billing provider is resolved.
40
43
  * Must be called before any billing custom operation executes.
41
44
  */
42
- export function initializeBillingCustomImplementations(provider, featureSyncService, billingStateService, billingConfig, errorBuilder) {
45
+ export function initializeBillingCustomImplementations(provider, featureSyncService, billingStateService, billingConfig, errorBuilder, providerRef) {
43
46
  _billingProvider = provider;
47
+ _billingProviderRef = providerRef;
44
48
  _featureSyncService = featureSyncService;
45
49
  _billingStateService = billingStateService;
46
50
  _billingConfig = billingConfig;
@@ -50,6 +54,30 @@ export function initializeBillingCustomImplementations(provider, featureSyncServ
50
54
  * Set the WebSocket service for credit pool post-op event emission.
51
55
  * Called from start-application after WebSocket service is resolved.
52
56
  */
57
+ /**
58
+ * Publish the usage-metering service for the post-operation usage hook (#415).
59
+ *
60
+ * A module-level seam rather than a DI edge, deliberately and for the same reason the WebSocket
61
+ * service beside it uses one: `UsageMeteringBackendService` injects
62
+ * `ServicesRegistryHandlerService`, and the hook lives ON that handler — so injecting the metering
63
+ * service there would be a container cycle.
64
+ *
65
+ * It also gives the right behaviour for free: an application with no billing configured never calls
66
+ * this, `getUsageMeteringService()` returns `null`, and the hook costs one null check per write
67
+ * instead of resolving a service that would refuse anyway.
68
+ */
69
+ export function setUsageMeteringService(usageMeteringService) {
70
+ _usageMeteringService = usageMeteringService;
71
+ }
72
+ /**
73
+ * The usage-metering service, or `null` when billing is not configured.
74
+ *
75
+ * `null` rather than a throw, unlike `getBillingProvider()`: a write on a resource that declares no
76
+ * metered usage must not be able to fail because billing is absent, and the caller checks.
77
+ */
78
+ export function getUsageMeteringService() {
79
+ return _usageMeteringService;
80
+ }
53
81
  export function setBillingWebSocketService(webSocketService) {
54
82
  _webSocketService = webSocketService;
55
83
  }
@@ -69,6 +97,20 @@ export function getBillingProvider() {
69
97
  }
70
98
  return _billingProvider;
71
99
  }
100
+ /**
101
+ * The provider ref the billing adapter was resolved under. Rows that record which provider
102
+ * owns a customer (`providerRef` on billing accounts) take it from HERE — never from a literal
103
+ * default: `config.providerRef || 'stripe'` stood at that site until 2026-09-05 (#327), a branch
104
+ * on a provider ref that the guard test could not see and that would have stamped every row
105
+ * 'stripe' under any other billing adapter.
106
+ * @throws if initializeBillingCustomImplementations() has not been called
107
+ */
108
+ export function getBillingProviderRef() {
109
+ if (!_billingProviderRef) {
110
+ throwBillingNotInitialized('Billing provider ref not initialized — initializeBillingCustomImplementations() must be called first');
111
+ }
112
+ return _billingProviderRef;
113
+ }
72
114
  /**
73
115
  * Get the feature sync service (lazy — resolved at operation execution time).
74
116
  * @throws if initializeBillingCustomImplementations() has not been called
@@ -1 +1 @@
1
- {"version":3,"file":"billing-custom-implementations.backend.js","sourceRoot":"","sources":["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yBAAyB,CAAC,cAAc,EAAE,KAAK,EAAE,YAAY,EAAE,oBAAoB,EAAE,MAAM,EAAE,gBAAgB,EAAE,EAAE;YAChI,MAAM,EAAE,GAAG,mBAAmB,EAAE,CAAC;YACjC,IAAI,CAAC,EAAE;gBAAE,OAAO;YAEhB,MAAM,QAAQ,GAAG,sCAAsC,CAAC,YAAY,CAAC,CAAC;YACtE,IAAI,CAAC,QAAQ;gBAAE,OAAO;YAEtB,MAAM,gBAAgB,GAAG,MAAM,EAAE,CAAC,QAAQ,CAAC,qBAAqB,CAAuB,CAAC;YACxF,IAAI,CAAC,gBAAgB;gBAAE,OAAO;YAE9B,MAAM,aAAa,GAAG,gBAAgB,CAAC,QAAQ,CAAC,QAAQ,CAAuB,CAAC;YAChF,IAAI,CAAC,aAAa;gBAAE,OAAO;YAE3B,MAAM,OAAO,GAAG;gBACd,IAAI,EAAE,kBAAkB,CAAC,2BAA2B;gBACpD,OAAO,EAAE,EAAE,SAAS,EAAE,QAAQ,CAAC,SAAS,EAAE,aAAa,EAAE,gBAAgB,EAAE;gBAC3E,SAAS,EAAE,IAAI,IAAI,EAAE;aACtB,CAAC;YAEF,QAAQ,QAAQ,CAAC,SAAS,EAAE,CAAC;gBAC3B,KAAK,oBAAoB,CAAC,aAAa;oBAAE,MAAM,EAAE,CAAC,kBAAkB,CAAC,aAAa,EAAE,OAAO,CAAC,CAAC;oBAAC,MAAM;gBACpG,KAAK,oBAAoB,CAAC,SAAS;oBAAE,MAAM,EAAE,CAAC,UAAU,CAAC,aAAa,EAAE,OAAO,CAAC,CAAC;oBAAC,MAAM;YAC1F,CAAC;QACH,CAAC,CAAC,CAAC;IACL,CAAC;AACH,CAAC","sourcesContent":["/**\n * Billing Custom Implementations — Aggregator + Late-Binding Setup\n *\n * Exports all billing resource custom implementations for registration\n * in CoreBackend_ServiceImplementationsFactories.\n *\n * Uses late-binding for the billing provider and feature sync service:\n * - Factory functions are registered at startup (before billing is initialized)\n * - Handler functions execute at operation time (after billing is initialized)\n * - initializeBillingCustomImplementations() must be called during billing setup\n *\n * @see billing-polymorphic-full-implementation.md §4.4\n */\n\nimport type { StandardBilling_Interface } from '@wildo-ai/external-connectors-models';\nimport { CoreResourceType, CoreWebSocketEvent, ResourcePrimaryScope, ErrorType, ErrorCustomMessageReference } from '@wildo-ai/saas-models';\nimport type { BillingConfiguration } from '@wildo-ai/saas-models';\nimport type { ServicesRegistryHandlerBackendService } from '~wildo-backend-lib/base-classes/services/services/services-registry-handler.backend.service';\nimport { BILLING_SCOPE_TO_VARIANTS, CREDIT_POOL_VARIANT_TYPES, resolveBillingVariantsFromResourceType } from '~wildo-backend-lib/billing/services/custom-impl/billing-custom-impl-utils.backend';\nimport type { ResourceCustomServiceImplementationFactory } from '~wildo-backend-lib/base-classes/services/services/resource-operation-custom-implementation.factory.backend';\nimport type { ErrorBuilderBackendService } from '~wildo-backend-lib/errors/services/error-builder.backend.service';\nimport type { BillingFeatureSyncBackendService } from '~wildo-backend-lib/billing/services/back-office/billing-feature-sync.backend.service';\nimport type { BillingStateBackendService } from '~wildo-backend-lib/billing/services/back-office/billing-state.backend.service';\nimport {\n createSubscriptionCancelFactories,\n createSubscriptionResumeFactories,\n createSubscriptionChangePlanFactories,\n createSubscriptionAddAddonFactories,\n createSubscriptionRemoveAddonFactories,\n} from '~wildo-backend-lib/billing/services/custom-impl/subscription.mutations.custom-impl.backend.service';\nimport {\n createBillingAccountCreateFactories,\n createBillingAccountDeleteDependentsGuardFactories,\n createBillingAccountOpenCheckoutFactories,\n createBillingAccountOpenPortalFactories,\n createBillingAccountGetStateFactories,\n} from '~wildo-backend-lib/billing/services/custom-impl/billing-account.mutations.custom-impl.backend.service';\nimport {\n createCreditPoolConsumeFactories,\n createCreditPoolTopUpFactories,\n} from '~wildo-backend-lib/billing/services/custom-impl/credit-pool.custom-ops.custom-impl.backend.service';\nimport {\n createPromotionCreateFactory,\n createPromotionApplyFactory,\n createPromotionDeactivateFactory,\n createPromotionDeactivateBulkFactory,\n} from '~wildo-backend-lib/billing/services/custom-impl/promotion.custom-ops.custom-impl.backend.service';\n\n// ── Late-Binding References ──────────────────────────────────────────\n\nlet _billingProvider: StandardBilling_Interface | null = null;\nlet _featureSyncService: BillingFeatureSyncBackendService | null = null;\nlet _billingStateService: BillingStateBackendService | null = null;\nlet _billingConfig: BillingConfiguration | null = null;\nlet _errorBuilder: ErrorBuilderBackendService | null = null;\nlet _webSocketService: import('~wildo-backend-lib/requests/service/websocket.service').WebSocketService | null = null;\n\n/** Throw a CONFIGURATION WildoError_Backend, or fall back to plain Error if error builder itself isn't initialized yet. */\nfunction throwBillingNotInitialized(message: string): never {\n if (_errorBuilder) {\n throw _errorBuilder.buildError(ErrorType.CONFIGURATION, undefined, {\n customMessageReference: ErrorCustomMessageReference.CONFIGURATION,\n context: { message },\n });\n }\n throw new Error(message);\n}\n\n/**\n * Initialize billing custom implementation dependencies.\n * Called from start-application after the billing provider is resolved.\n * Must be called before any billing custom operation executes.\n */\nexport function initializeBillingCustomImplementations(\n provider: StandardBilling_Interface,\n featureSyncService: BillingFeatureSyncBackendService,\n billingStateService: BillingStateBackendService,\n billingConfig: BillingConfiguration,\n errorBuilder: ErrorBuilderBackendService,\n): void {\n _billingProvider = provider;\n _featureSyncService = featureSyncService;\n _billingStateService = billingStateService;\n _billingConfig = billingConfig;\n _errorBuilder = errorBuilder;\n}\n\n/**\n * Set the WebSocket service for credit pool post-op event emission.\n * Called from start-application after WebSocket service is resolved.\n */\nexport function setBillingWebSocketService(\n webSocketService: import('~wildo-backend-lib/requests/service/websocket.service').WebSocketService,\n): void {\n _webSocketService = webSocketService;\n}\n\n/**\n * Get the WebSocket service (optional — returns null if not initialized).\n */\nexport function getWebSocketService(): import('~wildo-backend-lib/requests/service/websocket.service').WebSocketService | null {\n return _webSocketService;\n}\n\n/**\n * Get the billing provider (lazy — resolved at operation execution time).\n * @throws if initializeBillingCustomImplementations() has not been called\n */\nexport function getBillingProvider(): StandardBilling_Interface {\n if (!_billingProvider) {\n throwBillingNotInitialized(\n 'Billing provider not initialized — initializeBillingCustomImplementations() must be called first',\n );\n }\n return _billingProvider;\n}\n\n/**\n * Get the feature sync service (lazy — resolved at operation execution time).\n * @throws if initializeBillingCustomImplementations() has not been called\n */\nexport function getFeatureSyncService(): BillingFeatureSyncBackendService {\n if (!_featureSyncService) {\n throwBillingNotInitialized(\n 'Feature sync service not initialized — initializeBillingCustomImplementations() must be called first',\n );\n }\n return _featureSyncService;\n}\n\n/**\n * Get the billing state service (lazy — resolved at operation execution time).\n * @throws if initializeBillingCustomImplementations() has not been called\n */\nexport function getBillingStateService(): BillingStateBackendService {\n if (!_billingStateService) {\n throwBillingNotInitialized(\n 'Billing state service not initialized — initializeBillingCustomImplementations() must be called first',\n );\n }\n return _billingStateService;\n}\n\n/**\n * Get the billing configuration (lazy — resolved at operation execution time).\n * @throws if initializeBillingCustomImplementations() has not been called\n */\nexport function getBillingConfig(): BillingConfiguration {\n if (!_billingConfig) {\n throwBillingNotInitialized(\n 'Billing config not initialized — initializeBillingCustomImplementations() must be called first',\n );\n }\n return _billingConfig;\n}\n\n// ── All billing custom implementation factories ──────────────────────\n\nexport const billingCustomImplementations: ResourceCustomServiceImplementationFactory[] = [\n // Subscription operations\n ...createSubscriptionCancelFactories(),\n ...createSubscriptionResumeFactories(),\n ...createSubscriptionChangePlanFactories(),\n ...createSubscriptionAddAddonFactories(),\n ...createSubscriptionRemoveAddonFactories(),\n // Billing account operations\n ...createBillingAccountCreateFactories(),\n ...createBillingAccountDeleteDependentsGuardFactories(),\n ...createBillingAccountOpenCheckoutFactories(),\n ...createBillingAccountOpenPortalFactories(),\n ...createBillingAccountGetStateFactories(),\n // Credit pool operations\n ...createCreditPoolConsumeFactories(),\n ...createCreditPoolTopUpFactories(),\n // Promotion operations\n createPromotionCreateFactory(),\n createPromotionApplyFactory(),\n createPromotionDeactivateFactory(),\n createPromotionDeactivateBulkFactory(),\n];\n\n// ── Post-operation hook registration ─────────────────────────────────\n\n/** All subscription polymorphic variant types. */\nconst SUBSCRIPTION_VARIANT_TYPES: readonly string[] = [\n CoreResourceType.ORGANIZATION_SUBSCRIPTIONS,\n CoreResourceType.USER_SUBSCRIPTIONS,\n];\n\n/**\n * Register post-operation hooks on subscription variant types.\n * After any successful mutation on a subscription, triggers feature sync\n * to recompute billing-derived features from current subscription state.\n *\n * This replaces explicit feature sync calls in subscription custom impls\n * and the webhook event router — the hook fires automatically.\n */\nexport function registerBillingPostOperationHooks(\n servicesRegistry: ServicesRegistryHandlerBackendService,\n): void {\n for (const subscriptionType of SUBSCRIPTION_VARIANT_TYPES) {\n servicesRegistry.registerPostOperationHook(subscriptionType, async (resourceType, _operationIdentifier, result, _executionContext) => {\n const variants = resolveBillingVariantsFromResourceType(resourceType);\n if (!variants) return;\n\n const billingAccountId = result?.[variants.billingAccountFkField] as string | undefined;\n if (!billingAccountId) return;\n\n const featureSyncService = getFeatureSyncService();\n await featureSyncService.onSubscriptionChanged(billingAccountId, variants);\n });\n }\n\n for (const creditPoolType of CREDIT_POOL_VARIANT_TYPES) {\n servicesRegistry.registerPostOperationHook(creditPoolType, async (resourceType, _operationIdentifier, result, executionContext) => {\n const ws = getWebSocketService();\n if (!ws) return;\n\n const variants = resolveBillingVariantsFromResourceType(resourceType);\n if (!variants) return;\n\n const billingAccountId = result?.[variants.billingAccountFkField] as string | undefined;\n if (!billingAccountId) return;\n\n const scopeEntityId = executionContext[variants.scopeKey] as string | undefined;\n if (!scopeEntityId) return;\n\n const message = {\n type: CoreWebSocketEvent.BILLING_CREDIT_POOL_UPDATED,\n payload: { scopeType: variants.scopeType, scopeEntityId, billingAccountId },\n timestamp: new Date(),\n };\n\n switch (variants.scopeType) {\n case ResourcePrimaryScope.ORGANIZATIONS: await ws.sendToOrganization(scopeEntityId, message); break;\n case ResourcePrimaryScope.USER_SELF: await ws.sendToUser(scopeEntityId, message); break;\n }\n });\n }\n}\n"]}
1
+ {"version":3,"file":"billing-custom-implementations.backend.js","sourceRoot":"","sources":["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,QAAQ,CAAC,SAAS,EAAE,CAAC;gBAC3B,KAAK,oBAAoB,CAAC,aAAa;oBAAE,MAAM,EAAE,CAAC,kBAAkB,CAAC,aAAa,EAAE,OAAO,CAAC,CAAC;oBAAC,MAAM;gBACpG,KAAK,oBAAoB,CAAC,SAAS;oBAAE,MAAM,EAAE,CAAC,UAAU,CAAC,aAAa,EAAE,OAAO,CAAC,CAAC;oBAAC,MAAM;YAC1F,CAAC;QACH,CAAC,CAAC,CAAC;IACL,CAAC;AACH,CAAC","sourcesContent":["/**\n * Billing Custom Implementations — Aggregator + Late-Binding Setup\n *\n * Exports all billing resource custom implementations for registration\n * in CoreBackend_ServiceImplementationsFactories.\n *\n * Uses late-binding for the billing provider and feature sync service:\n * - Factory functions are registered at startup (before billing is initialized)\n * - Handler functions execute at operation time (after billing is initialized)\n * - initializeBillingCustomImplementations() must be called during billing setup\n *\n * @see billing-polymorphic-full-implementation.md §4.4\n */\n\nimport type { StandardBilling_Interface } from '@wildo-ai/external-connectors-models';\nimport { CoreResourceType, CoreWebSocketEvent, ResourcePrimaryScope, ErrorType, ErrorCustomMessageReference } from '@wildo-ai/saas-models';\nimport type { BillingConfiguration } from '@wildo-ai/saas-models';\nimport type { ServicesRegistryHandlerBackendService } from '~wildo-backend-lib/base-classes/services/services/services-registry-handler.backend.service';\nimport { BILLING_SCOPE_TO_VARIANTS, CREDIT_POOL_VARIANT_TYPES, resolveBillingVariantsFromResourceType } from '~wildo-backend-lib/billing/services/custom-impl/billing-custom-impl-utils.backend';\nimport type { ResourceCustomServiceImplementationFactory } from '~wildo-backend-lib/base-classes/services/services/resource-operation-custom-implementation.factory.backend';\nimport type { ErrorBuilderBackendService } from '~wildo-backend-lib/errors/services/error-builder.backend.service';\nimport type { BillingFeatureSyncBackendService } from '~wildo-backend-lib/billing/services/back-office/billing-feature-sync.backend.service';\nimport type { BillingStateBackendService } from '~wildo-backend-lib/billing/services/back-office/billing-state.backend.service';\nimport {\n createSubscriptionCancelFactories,\n createSubscriptionResumeFactories,\n createSubscriptionChangePlanFactories,\n createSubscriptionAddAddonFactories,\n createSubscriptionRemoveAddonFactories,\n} from '~wildo-backend-lib/billing/services/custom-impl/subscription.mutations.custom-impl.backend.service';\nimport {\n createBillingAccountCreateFactories,\n createBillingAccountDeleteDependentsGuardFactories,\n createBillingAccountOpenCheckoutFactories,\n createBillingAccountOpenPortalFactories,\n createBillingAccountGetStateFactories,\n} from '~wildo-backend-lib/billing/services/custom-impl/billing-account.mutations.custom-impl.backend.service';\nimport {\n createCreditPoolConsumeFactories,\n createCreditPoolTopUpFactories,\n} from '~wildo-backend-lib/billing/services/custom-impl/credit-pool.custom-ops.custom-impl.backend.service';\nimport {\n createPromotionCreateFactory,\n createPromotionApplyFactory,\n createPromotionDeactivateFactory,\n createPromotionDeactivateBulkFactory,\n} from '~wildo-backend-lib/billing/services/custom-impl/promotion.custom-ops.custom-impl.backend.service';\n\n// ── Late-Binding References ──────────────────────────────────────────\n\nlet _billingProvider: StandardBilling_Interface | null = null;\nlet _featureSyncService: BillingFeatureSyncBackendService | null = null;\nlet _billingStateService: BillingStateBackendService | null = null;\nlet _billingConfig: BillingConfiguration | null = null;\n/** The ref the billing provider was RESOLVED under at startup — the one rows are stamped with. */\nlet _billingProviderRef: string | null = null;\nlet _errorBuilder: ErrorBuilderBackendService | null = null;\nlet _webSocketService: import('~wildo-backend-lib/requests/service/websocket.service').WebSocketService | null = null;\nlet _usageMeteringService: import('~wildo-backend-lib/billing/services/back-office/usage-metering.backend.service').UsageMeteringBackendService | null = null;\n\n/** Throw a CONFIGURATION WildoError_Backend, or fall back to plain Error if error builder itself isn't initialized yet. */\nfunction throwBillingNotInitialized(message: string): never {\n if (_errorBuilder) {\n throw _errorBuilder.buildError(ErrorType.CONFIGURATION, undefined, {\n customMessageReference: ErrorCustomMessageReference.CONFIGURATION,\n context: { message },\n });\n }\n throw new Error(message);\n}\n\n/**\n * Initialize billing custom implementation dependencies.\n * Called from start-application after the billing provider is resolved.\n * Must be called before any billing custom operation executes.\n */\nexport function initializeBillingCustomImplementations(\n provider: StandardBilling_Interface,\n featureSyncService: BillingFeatureSyncBackendService,\n billingStateService: BillingStateBackendService,\n billingConfig: BillingConfiguration,\n errorBuilder: ErrorBuilderBackendService,\n providerRef: string,\n): void {\n _billingProvider = provider;\n _billingProviderRef = providerRef;\n _featureSyncService = featureSyncService;\n _billingStateService = billingStateService;\n _billingConfig = billingConfig;\n _errorBuilder = errorBuilder;\n}\n\n/**\n * Set the WebSocket service for credit pool post-op event emission.\n * Called from start-application after WebSocket service is resolved.\n */\n/**\n * Publish the usage-metering service for the post-operation usage hook (#415).\n *\n * A module-level seam rather than a DI edge, deliberately and for the same reason the WebSocket\n * service beside it uses one: `UsageMeteringBackendService` injects\n * `ServicesRegistryHandlerService`, and the hook lives ON that handler — so injecting the metering\n * service there would be a container cycle.\n *\n * It also gives the right behaviour for free: an application with no billing configured never calls\n * this, `getUsageMeteringService()` returns `null`, and the hook costs one null check per write\n * instead of resolving a service that would refuse anyway.\n */\nexport function setUsageMeteringService(\n usageMeteringService: import('~wildo-backend-lib/billing/services/back-office/usage-metering.backend.service').UsageMeteringBackendService,\n): void {\n _usageMeteringService = usageMeteringService;\n}\n\n/**\n * The usage-metering service, or `null` when billing is not configured.\n *\n * `null` rather than a throw, unlike `getBillingProvider()`: a write on a resource that declares no\n * metered usage must not be able to fail because billing is absent, and the caller checks.\n */\nexport function getUsageMeteringService():\n import('~wildo-backend-lib/billing/services/back-office/usage-metering.backend.service').UsageMeteringBackendService | null {\n return _usageMeteringService;\n}\n\nexport function setBillingWebSocketService(\n webSocketService: import('~wildo-backend-lib/requests/service/websocket.service').WebSocketService,\n): void {\n _webSocketService = webSocketService;\n}\n\n/**\n * Get the WebSocket service (optional — returns null if not initialized).\n */\nexport function getWebSocketService(): import('~wildo-backend-lib/requests/service/websocket.service').WebSocketService | null {\n return _webSocketService;\n}\n\n/**\n * Get the billing provider (lazy — resolved at operation execution time).\n * @throws if initializeBillingCustomImplementations() has not been called\n */\nexport function getBillingProvider(): StandardBilling_Interface {\n if (!_billingProvider) {\n throwBillingNotInitialized(\n 'Billing provider not initialized — initializeBillingCustomImplementations() must be called first',\n );\n }\n return _billingProvider;\n}\n\n/**\n * The provider ref the billing adapter was resolved under. Rows that record which provider\n * owns a customer (`providerRef` on billing accounts) take it from HERE — never from a literal\n * default: `config.providerRef || 'stripe'` stood at that site until 2026-09-05 (#327), a branch\n * on a provider ref that the guard test could not see and that would have stamped every row\n * 'stripe' under any other billing adapter.\n * @throws if initializeBillingCustomImplementations() has not been called\n */\nexport function getBillingProviderRef(): string {\n if (!_billingProviderRef) {\n throwBillingNotInitialized(\n 'Billing provider ref not initialized — initializeBillingCustomImplementations() must be called first',\n );\n }\n return _billingProviderRef;\n}\n\n/**\n * Get the feature sync service (lazy — resolved at operation execution time).\n * @throws if initializeBillingCustomImplementations() has not been called\n */\nexport function getFeatureSyncService(): BillingFeatureSyncBackendService {\n if (!_featureSyncService) {\n throwBillingNotInitialized(\n 'Feature sync service not initialized — initializeBillingCustomImplementations() must be called first',\n );\n }\n return _featureSyncService;\n}\n\n/**\n * Get the billing state service (lazy — resolved at operation execution time).\n * @throws if initializeBillingCustomImplementations() has not been called\n */\nexport function getBillingStateService(): BillingStateBackendService {\n if (!_billingStateService) {\n throwBillingNotInitialized(\n 'Billing state service not initialized — initializeBillingCustomImplementations() must be called first',\n );\n }\n return _billingStateService;\n}\n\n/**\n * Get the billing configuration (lazy — resolved at operation execution time).\n * @throws if initializeBillingCustomImplementations() has not been called\n */\nexport function getBillingConfig(): BillingConfiguration {\n if (!_billingConfig) {\n throwBillingNotInitialized(\n 'Billing config not initialized — initializeBillingCustomImplementations() must be called first',\n );\n }\n return _billingConfig;\n}\n\n// ── All billing custom implementation factories ──────────────────────\n\nexport const billingCustomImplementations: ResourceCustomServiceImplementationFactory[] = [\n // Subscription operations\n ...createSubscriptionCancelFactories(),\n ...createSubscriptionResumeFactories(),\n ...createSubscriptionChangePlanFactories(),\n ...createSubscriptionAddAddonFactories(),\n ...createSubscriptionRemoveAddonFactories(),\n // Billing account operations\n ...createBillingAccountCreateFactories(),\n ...createBillingAccountDeleteDependentsGuardFactories(),\n ...createBillingAccountOpenCheckoutFactories(),\n ...createBillingAccountOpenPortalFactories(),\n ...createBillingAccountGetStateFactories(),\n // Credit pool operations\n ...createCreditPoolConsumeFactories(),\n ...createCreditPoolTopUpFactories(),\n // Promotion operations\n createPromotionCreateFactory(),\n createPromotionApplyFactory(),\n createPromotionDeactivateFactory(),\n createPromotionDeactivateBulkFactory(),\n];\n\n// ── Post-operation hook registration ─────────────────────────────────\n\n/** All subscription polymorphic variant types. */\nconst SUBSCRIPTION_VARIANT_TYPES: readonly string[] = [\n CoreResourceType.ORGANIZATION_SUBSCRIPTIONS,\n CoreResourceType.USER_SUBSCRIPTIONS,\n];\n\n/**\n * Register post-operation hooks on subscription variant types.\n * After any successful mutation on a subscription, triggers feature sync\n * to recompute billing-derived features from current subscription state.\n *\n * This replaces explicit feature sync calls in subscription custom impls\n * and the webhook event router — the hook fires automatically.\n */\nexport function registerBillingPostOperationHooks(\n servicesRegistry: ServicesRegistryHandlerBackendService,\n): void {\n for (const subscriptionType of SUBSCRIPTION_VARIANT_TYPES) {\n servicesRegistry.registerPostOperationHook(subscriptionType, async (resourceType, _operationIdentifier, result, _executionContext) => {\n const variants = resolveBillingVariantsFromResourceType(resourceType);\n if (!variants) return;\n\n const billingAccountId = result?.[variants.billingAccountFkField] as string | undefined;\n if (!billingAccountId) return;\n\n const featureSyncService = getFeatureSyncService();\n await featureSyncService.onSubscriptionChanged(billingAccountId, variants);\n });\n }\n\n for (const creditPoolType of CREDIT_POOL_VARIANT_TYPES) {\n servicesRegistry.registerPostOperationHook(creditPoolType, async (resourceType, _operationIdentifier, result, executionContext) => {\n const ws = getWebSocketService();\n if (!ws) return;\n\n const variants = resolveBillingVariantsFromResourceType(resourceType);\n if (!variants) return;\n\n const billingAccountId = result?.[variants.billingAccountFkField] as string | undefined;\n if (!billingAccountId) return;\n\n const scopeEntityId = executionContext[variants.scopeKey] as string | undefined;\n if (!scopeEntityId) return;\n\n const message = {\n type: CoreWebSocketEvent.BILLING_CREDIT_POOL_UPDATED,\n payload: { scopeType: variants.scopeType, scopeEntityId, billingAccountId },\n timestamp: new Date(),\n };\n\n switch (variants.scopeType) {\n case ResourcePrimaryScope.ORGANIZATIONS: await ws.sendToOrganization(scopeEntityId, message); break;\n case ResourcePrimaryScope.USER_SELF: await ws.sendToUser(scopeEntityId, message); break;\n }\n });\n }\n}\n"]}
@@ -4,7 +4,8 @@
4
4
  * Promotions are APPLICATION-scoped (not polymorphic) — 1 factory per operation.
5
5
  *
6
6
  * CREATE: PREFIX syncs coupon to billing provider → core CREATE writes to DB with provider IDs
7
- * APPLY: REPLACE validates the promotion + records redemption. No standard CRUD equivalent.
7
+ * APPLY: REPLACE validates the promotion and reports its discount. No standard CRUD equivalent,
8
+ * and it records NO redemption — completion does (see the factory's docstring).
8
9
  * DEACTIVATE: PREFIX returns { isActive: false } → core UPDATE writes to DB
9
10
  *
10
11
  * @see billing-polymorphic-full-implementation.md §4.6.3 + §4.6.4 + §4.6.5
@@ -28,8 +29,15 @@ export declare function createPromotionCreateFactory(): ResourceCustomServiceImp
28
29
  /**
29
30
  * Create Promotion APPLY replace factory.
30
31
  *
31
- * Validates the promotion, records a redemption, and returns discount info.
32
- * The caller (typically OPEN_CHECKOUT) uses the returned discount to pass the coupon to Stripe.
32
+ * VALIDATES the promotion and returns its discount info. It records NOTHING.
33
+ *
34
+ * The redemption is counted when the purchase COMPLETES — `handleCheckoutCompleted`, behind the
35
+ * durable settlement claim — because entering a code is not redeeming one. See the block where the
36
+ * increment used to be for the full reasoning, including why leaving it here would double-count.
37
+ *
38
+ * The docstring here previously said "the caller (typically OPEN_CHECKOUT)". `OPEN_CHECKOUT` has
39
+ * never called this verb: it re-validates a supplied code inline. This is a CLIENT-facing verb, for
40
+ * a purchase form that wants to show the discount before the customer commits.
33
41
  */
34
42
  export declare function createPromotionApplyFactory(): ResourceCustomServiceImplementationFactory;
35
43
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"promotion.custom-ops.custom-impl.backend.service.d.ts","sourceRoot":"","sources":["../../../../../../src/billing/services/custom-impl/promotion.custom-ops.custom-impl.backend.service.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAaH,OAAO,EAEL,KAAK,0CAA0C,EAChD,MAAM,4GAA4G,CAAC;AAQpH;;;;;;;;;;;;;GAaG;AACH,wBAAgB,4BAA4B,IAAI,0CAA0C,CAiEzF;AAMD;;;;;GAKG;AACH,wBAAgB,2BAA2B,IAAI,0CAA0C,CA+FxF;AAMD;;;;;;;;;;GAUG;AACH,wBAAgB,gCAAgC,IAAI,0CAA0C,CAkB7F;AAED;;;;;;;GAOG;AACH,wBAAgB,oCAAoC,IAAI,0CAA0C,CAmBjG"}
1
+ {"version":3,"file":"promotion.custom-ops.custom-impl.backend.service.d.ts","sourceRoot":"","sources":["../../../../../../src/billing/services/custom-impl/promotion.custom-ops.custom-impl.backend.service.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAaH,OAAO,EAEL,KAAK,0CAA0C,EAChD,MAAM,4GAA4G,CAAC;AAQpH;;;;;;;;;;;;;GAaG;AACH,wBAAgB,4BAA4B,IAAI,0CAA0C,CAiEzF;AAMD;;;;;;;;;;;;GAYG;AACH,wBAAgB,2BAA2B,IAAI,0CAA0C,CA4FxF;AAMD;;;;;;;;;;GAUG;AACH,wBAAgB,gCAAgC,IAAI,0CAA0C,CAkB7F;AAED;;;;;;;GAOG;AACH,wBAAgB,oCAAoC,IAAI,0CAA0C,CAmBjG"}
@@ -4,7 +4,8 @@
4
4
  * Promotions are APPLICATION-scoped (not polymorphic) — 1 factory per operation.
5
5
  *
6
6
  * CREATE: PREFIX syncs coupon to billing provider → core CREATE writes to DB with provider IDs
7
- * APPLY: REPLACE validates the promotion + records redemption. No standard CRUD equivalent.
7
+ * APPLY: REPLACE validates the promotion and reports its discount. No standard CRUD equivalent,
8
+ * and it records NO redemption — completion does (see the factory's docstring).
8
9
  * DEACTIVATE: PREFIX returns { isActive: false } → core UPDATE writes to DB
9
10
  *
10
11
  * @see billing-polymorphic-full-implementation.md §4.6.3 + §4.6.4 + §4.6.5
@@ -96,8 +97,15 @@ export function createPromotionCreateFactory() {
96
97
  /**
97
98
  * Create Promotion APPLY replace factory.
98
99
  *
99
- * Validates the promotion, records a redemption, and returns discount info.
100
- * The caller (typically OPEN_CHECKOUT) uses the returned discount to pass the coupon to Stripe.
100
+ * VALIDATES the promotion and returns its discount info. It records NOTHING.
101
+ *
102
+ * The redemption is counted when the purchase COMPLETES — `handleCheckoutCompleted`, behind the
103
+ * durable settlement claim — because entering a code is not redeeming one. See the block where the
104
+ * increment used to be for the full reasoning, including why leaving it here would double-count.
105
+ *
106
+ * The docstring here previously said "the caller (typically OPEN_CHECKOUT)". `OPEN_CHECKOUT` has
107
+ * never called this verb: it re-validates a supplied code inline. This is a CLIENT-facing verb, for
108
+ * a purchase form that wants to show the discount before the customer commits.
101
109
  */
102
110
  export function createPromotionApplyFactory() {
103
111
  const factory = (_resourcesRegistryService) => {
@@ -148,19 +156,25 @@ export function createPromotionApplyFactory() {
148
156
  context: { promotionId: _id, reason: 'Code does not match' },
149
157
  });
150
158
  }
151
- // C2: Atomically increment timesRedeemed to prevent race conditions
152
- if (promotion.maxRedemptions !== null && promotion.maxRedemptions !== undefined) {
153
- const result = await utils.repositoriesRegistry.atomicGuardedMutation(CoreResourceType.PROMOTIONS, { _id, timesRedeemed: { $lt: promotion.maxRedemptions } }, { increment: { timesRedeemed: 1 } }, executionContext);
154
- if (!result) {
155
- throw utils.errorBuilder.buildError(ErrorType.BUSINESS_RULE, executionContext, {
156
- customMessageReference: ErrorCustomMessageReference.BILLING_PROMOTION_INVALID,
157
- context: { promotionId: _id, reason: 'Maximum redemptions reached' },
158
- });
159
- }
160
- }
161
- else {
162
- await utils.repositoriesRegistry.atomicGuardedMutation(CoreResourceType.PROMOTIONS, { _id }, { increment: { timesRedeemed: 1 } }, executionContext);
163
- }
159
+ /*
160
+ * COUNTS NOTHING, and that is the change (#518 follow-up).
161
+ *
162
+ * This used to increment `timesRedeemed` here, guarded by the cap. It was the only place
163
+ * a redemption was ever counted, and it counted at the WRONG MOMENT — this verb runs when
164
+ * a customer types a code into a purchase form, which is not a redemption. A customer who
165
+ * types a code and closes the tab consumed one anyway, so a limited campaign was exhausted
166
+ * by window-shoppers.
167
+ *
168
+ * A redemption is now counted exactly where the money moves: the
169
+ * `checkout.session.completed` webhook, behind the durable settlement claim that makes the
170
+ * count exactly-once across replicas and retries. Leaving the increment here as well would
171
+ * double-count every customer who used this verb and then completed the purchase — the two
172
+ * are two views of ONE redemption, not two redemptions.
173
+ *
174
+ * The cap check above stays, because it is what makes this verb answer honestly: an
175
+ * exhausted code must be refused at the moment it is entered, not silently accepted and
176
+ * then refused at completion when the customer has already paid.
177
+ */
164
178
  // Return discount info for the caller
165
179
  return {
166
180
  valid: true,
@@ -1 +1 @@
1
- {"version":3,"file":"promotion.custom-ops.custom-impl.backend.service.js","sourceRoot":"","sources":["../../../../../../src/billing/services/custom-impl/promotion.custom-ops.custom-impl.backend.service.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EACL,gBAAgB,EAChB,4BAA4B,EAC5B,qBAAqB,EACrB,SAAS,EACT,2BAA2B,EAC3B,aAAa,EACb,YAAY,EACZ,iBAAiB,EACjB,oBAAoB,GACrB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EACL,yCAAyC,GAE1C,MAAM,4GAA4G,CAAC;AAEpH,OAAO,EAAE,kBAAkB,EAAE,MAAM,wFAAwF,CAAC;AAE5H,uEAAuE;AACvE,kCAAkC;AAClC,uEAAuE;AAEvE;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,4BAA4B;IAC1C,MAAM,OAAO,GAAG,CAAC,yBAA0D,EAAE,EAAE;QAC7E,OAA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AE,QAAQ,EAAE,KAAK,EAAE,CAAC;gBAC7B,CAAC;aACF;SACF,CAAC,CAAC;IACL,CAAC,CAAC;IAEF,OAAO,OAAgE,CAAC;AAC1E,CAAC","sourcesContent":["/**\n * Promotion Custom Operations — CREATE (prefix), APPLY (replace), DEACTIVATE (prefix)\n *\n * Promotions are APPLICATION-scoped (not polymorphic) — 1 factory per operation.\n *\n * CREATE: PREFIX syncs coupon to billing provider → core CREATE writes to DB with provider IDs\n * APPLY: REPLACE validates the promotion + records redemption. No standard CRUD equivalent.\n * DEACTIVATE: PREFIX returns { isActive: false } → core UPDATE writes to DB\n *\n * @see billing-polymorphic-full-implementation.md §4.6.3 + §4.6.4 + §4.6.5\n */\n\nimport {\n CoreResourceType,\n ResourceOperationVariantType,\n CoreResourceOperation,\n ErrorType,\n ErrorCustomMessageReference,\n PromotionType,\n DiscountType,\n PromotionDuration,\n Promotion_Operations,\n} from '@wildo-ai/saas-models';\nimport {\n createResourceCustomServiceImplementation,\n type ResourceCustomServiceImplementationFactory,\n} from '~wildo-backend-lib/base-classes/services/services/resource-operation-custom-implementation.factory.backend';\nimport type { ResourcesRegistryBackendService } from '~wildo-backend-lib/resources/services/resources-registry.backend.service';\nimport { getBillingProvider } from '~wildo-backend-lib/billing/services/custom-impl/billing-custom-implementations.backend';\n\n// ════════════════════════════════════════════════════════════════════\n// CREATE — PREFIX_CORE_OPERATIONS\n// ════════════════════════════════════════════════════════════════════\n\n/**\n * Create Promotion CREATE prefix factory.\n *\n * Syncs the coupon (and optionally promotion code) to the billing provider\n * before the core CREATE writes to DB. Augments input with provider IDs.\n *\n * Registered on `INTERNAL_CALL` — the variant the resource configuration actually declares\n * for CREATE. Same drift class as the billing-account CREATE prefix: authored against\n * `REPOSITORY_ONLY`, orphaned once the configured variant moved, and silent because custom\n * implementations resolve by an EXACT operation-path key embedding `variantType`. Orphaned,\n * the promotion row is persisted with no `providerCouponId` / `providerPromotionId`, and\n * OPEN_CHECKOUT later rejects it as \"not synced to billing provider\". Pinned by\n * `billing-custom-impl-operation-path-coherence.test.ts`.\n */\nexport function createPromotionCreateFactory(): ResourceCustomServiceImplementationFactory {\n const factory = (_resourcesRegistryService: ResourcesRegistryBackendService) => {\n return createResourceCustomServiceImplementation({\n operationPath: {\n resourceIdentifier: CoreResourceType.PROMOTIONS,\n operationIdentifier: CoreResourceOperation.CREATE,\n variantType: ResourceOperationVariantType.INTERNAL_CALL,\n isOperationDefault: true,\n },\n handlers: {\n prefixCoreOperations: async (_id, input, executionContext, _operationPath, utils) => {\n // L5: Validate discount fields match the declared discountType\n if (input.discountType === DiscountType.PERCENTAGE && (input.discountPercentage === undefined || input.discountPercentage === null)) {\n throw utils.errorBuilder.buildError(ErrorType.VALIDATION, executionContext, {\n customMessageReference: ErrorCustomMessageReference.BILLING_PROMOTION_INVALID,\n context: { reason: 'discountPercentage is required for PERCENTAGE discount type' },\n });\n }\n if (input.discountType === DiscountType.FIXED_AMOUNT && !input.discountFixedAmount) {\n throw utils.errorBuilder.buildError(ErrorType.VALIDATION, executionContext, {\n customMessageReference: ErrorCustomMessageReference.BILLING_PROMOTION_INVALID,\n context: { reason: 'discountFixedAmount is required for FIXED_AMOUNT discount type' },\n });\n }\n\n const durationMap: Record<string, 'once' | 'repeating' | 'forever'> = {\n [PromotionDuration.ONCE]: 'once',\n [PromotionDuration.REPEATING]: 'repeating',\n [PromotionDuration.FOREVER]: 'forever',\n };\n\n // H1: Provider sync must succeed — throw on failure\n const provider = getBillingProvider();\n const couponResult = await provider.createCoupon({\n ...(input.discountType === DiscountType.PERCENTAGE && { percentOff: input.discountPercentage }),\n ...(input.discountType === DiscountType.FIXED_AMOUNT && input.discountFixedAmount && {\n amountOff: Number(input.discountFixedAmount.amount),\n currency: input.discountFixedAmount.currency,\n }),\n duration: durationMap[input.duration] ?? 'once',\n ...(input.durationInMonths && { durationInMonths: input.durationInMonths }),\n ...(input.maxRedemptions && { maxRedemptions: input.maxRedemptions }),\n ...(input.metadata && { metadata: input.metadata }),\n });\n const providerCouponId = couponResult.providerCouponId;\n\n let providerPromotionId: string | undefined;\n if (input.type === PromotionType.PROMOTION_CODE && input.code && providerCouponId) {\n const promoResult = await provider.createPromotionCode(providerCouponId, input.code);\n providerPromotionId = promoResult.providerPromotionId;\n }\n\n return {\n ...input,\n providerCouponId,\n providerPromotionId,\n isActive: true,\n timesRedeemed: 0,\n };\n },\n },\n });\n };\n\n return factory as unknown as ResourceCustomServiceImplementationFactory;\n}\n\n// ════════════════════════════════════════════════════════════════════\n// APPLY — REPLACE_CORE_OPERATIONS\n// ════════════════════════════════════════════════════════════════════\n\n/**\n * Create Promotion APPLY replace factory.\n *\n * Validates the promotion, records a redemption, and returns discount info.\n * The caller (typically OPEN_CHECKOUT) uses the returned discount to pass the coupon to Stripe.\n */\nexport function createPromotionApplyFactory(): ResourceCustomServiceImplementationFactory {\n const factory = (_resourcesRegistryService: ResourcesRegistryBackendService) => {\n return createResourceCustomServiceImplementation({\n operationPath: {\n resourceIdentifier: CoreResourceType.PROMOTIONS,\n operationIdentifier: Promotion_Operations.APPLY,\n variantType: ResourceOperationVariantType.API_CALL,\n isOperationDefault: true,\n },\n handlers: {\n replaceCoreOperations: async (_id, input, executionContext, _operationPath, utils) => {\n const promotion = utils.currentObject;\n\n // Validate promotion is active\n if (!promotion.isActive) {\n throw utils.errorBuilder.buildError(ErrorType.BUSINESS_RULE, executionContext, {\n customMessageReference: ErrorCustomMessageReference.BILLING_PROMOTION_INVALID,\n context: { promotionId: _id, reason: 'Promotion is not active' },\n });\n }\n\n // Validate date range\n const now = new Date();\n if (promotion.validFrom && now < new Date(promotion.validFrom)) {\n throw utils.errorBuilder.buildError(ErrorType.BUSINESS_RULE, executionContext, {\n customMessageReference: ErrorCustomMessageReference.BILLING_PROMOTION_INVALID,\n context: { promotionId: _id, reason: 'Promotion has not started yet' },\n });\n }\n if (promotion.validUntil && now > new Date(promotion.validUntil)) {\n throw utils.errorBuilder.buildError(ErrorType.BUSINESS_RULE, executionContext, {\n customMessageReference: ErrorCustomMessageReference.BILLING_PROMOTION_INVALID,\n context: { promotionId: _id, reason: 'Promotion has expired' },\n });\n }\n\n // Validate max redemptions\n if (promotion.maxRedemptions !== null && promotion.maxRedemptions !== undefined) {\n if ((promotion.timesRedeemed ?? 0) >= promotion.maxRedemptions) {\n throw utils.errorBuilder.buildError(ErrorType.BUSINESS_RULE, executionContext, {\n customMessageReference: ErrorCustomMessageReference.BILLING_PROMOTION_INVALID,\n context: { promotionId: _id, reason: 'Maximum redemptions reached' },\n });\n }\n }\n\n // Validate code match (when the promotion has a code)\n if (promotion.code && input.code !== promotion.code) {\n throw utils.errorBuilder.buildError(ErrorType.BUSINESS_RULE, executionContext, {\n customMessageReference: ErrorCustomMessageReference.BILLING_PROMOTION_INVALID,\n context: { promotionId: _id, reason: 'Code does not match' },\n });\n }\n\n // C2: Atomically increment timesRedeemed to prevent race conditions\n if (promotion.maxRedemptions !== null && promotion.maxRedemptions !== undefined) {\n const result = await utils.repositoriesRegistry.atomicGuardedMutation(\n CoreResourceType.PROMOTIONS,\n { _id, timesRedeemed: { $lt: promotion.maxRedemptions } },\n { increment: { timesRedeemed: 1 } },\n executionContext,\n );\n if (!result) {\n throw utils.errorBuilder.buildError(ErrorType.BUSINESS_RULE, executionContext, {\n customMessageReference: ErrorCustomMessageReference.BILLING_PROMOTION_INVALID,\n context: { promotionId: _id, reason: 'Maximum redemptions reached' },\n });\n }\n } else {\n await utils.repositoriesRegistry.atomicGuardedMutation(\n CoreResourceType.PROMOTIONS,\n { _id },\n { increment: { timesRedeemed: 1 } },\n executionContext,\n );\n }\n\n // Return discount info for the caller\n return {\n valid: true,\n promotionId: _id,\n providerCouponId: promotion.providerCouponId,\n providerPromotionId: promotion.providerPromotionId,\n discount: {\n type: promotion.discountType,\n ...(promotion.discountType === DiscountType.PERCENTAGE && { percentage: promotion.discountPercentage }),\n ...(promotion.discountType === DiscountType.FIXED_AMOUNT && { amount: promotion.discountFixedAmount }),\n },\n };\n },\n },\n });\n };\n\n return factory as unknown as ResourceCustomServiceImplementationFactory;\n}\n\n// ════════════════════════════════════════════════════════════════════\n// DEACTIVATE — PREFIX_CORE_OPERATIONS\n// ════════════════════════════════════════════════════════════════════\n\n/**\n * Create Promotion DEACTIVATE prefix factory.\n *\n * Trivially returns { isActive: false } — core UPDATE writes to DB.\n *\n * The operation declares `requestDto: z.object({})` (single) / `{ _ids }` (bulk), so `isActive`\n * can ONLY arrive from here. Before that narrowing the verb inherited the resource's full update\n * contract — including `isActive` itself, so \"deactivate\" could re-activate — and this return was\n * MERGED onto the caller payload rather than replacing it, leaving `code`, `discountPercentage`\n * and `maxRedemptions` writable through a route named deactivate.\n */\nexport function createPromotionDeactivateFactory(): ResourceCustomServiceImplementationFactory {\n const factory = (_resourcesRegistryService: ResourcesRegistryBackendService) => {\n return createResourceCustomServiceImplementation({\n operationPath: {\n resourceIdentifier: CoreResourceType.PROMOTIONS,\n operationIdentifier: Promotion_Operations.DEACTIVATE,\n variantType: ResourceOperationVariantType.API_CALL,\n isOperationDefault: true,\n },\n handlers: {\n prefixCoreOperations: async () => {\n return { isActive: false };\n },\n },\n });\n };\n\n return factory as unknown as ResourceCustomServiceImplementationFactory;\n}\n\n/**\n * Create Promotion DEACTIVATE prefix factory — BULK companion (`haveBulkOperation: true`).\n *\n * A bulk companion is a SEPARATE operation variant with its own path key (`isOperationDefault:\n * false` + `isBulkOperation: true`), so it needs its own registration: the single-row factory\n * above does not cover it. The bulk contract is `{ _ids }` and `_ids` is not a persisted field,\n * so without this handler the route would validate a list of promotion ids and write nothing.\n */\nexport function createPromotionDeactivateBulkFactory(): ResourceCustomServiceImplementationFactory {\n const factory = (_resourcesRegistryService: ResourcesRegistryBackendService) => {\n return createResourceCustomServiceImplementation({\n operationPath: {\n resourceIdentifier: CoreResourceType.PROMOTIONS,\n operationIdentifier: Promotion_Operations.DEACTIVATE,\n variantType: ResourceOperationVariantType.API_CALL,\n isOperationDefault: false,\n isBulkOperation: true,\n },\n handlers: {\n prefixCoreOperations: async () => {\n return { isActive: false };\n },\n },\n });\n };\n\n return factory as unknown as ResourceCustomServiceImplementationFactory;\n}\n"]}
1
+ {"version":3,"file":"promotion.custom-ops.custom-impl.backend.service.js","sourceRoot":"","sources":["../../../../../../src/billing/services/custom-impl/promotion.custom-ops.custom-impl.backend.service.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EACL,gBAAgB,EAChB,4BAA4B,EAC5B,qBAAqB,EACrB,SAAS,EACT,2BAA2B,EAC3B,aAAa,EACb,YAAY,EACZ,iBAAiB,EACjB,oBAAoB,GACrB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EACL,yCAAyC,GAE1C,MAAM,4GAA4G,CAAC;AAEpH,OAAO,EAAE,kBAAkB,EAAE,MAAM,wFAAwF,CAAC;AAE5H,uEAAuE;AACvE,kCAAkC;AAClC,uEAAuE;AAEvE;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,4BAA4B;IAC1C,MAAM,OAAO,GAAG,CAAC,yBAA0D,EAAE,EAAE;QAC7E,OAAO,yCAAyC,CAAC;YAC/C,aAAa,EAAE;gBACb,kBAAkB,EAAE,gBAAgB,CAAC,UAAU;gBAC/C,mBAAmB,EAAE,qBAAqB,CAAC,MAAM;gBACjD,WAAW,EAAE,4BAA4B,CAAC,aAAa;gBACvD,kBAAkB,EAAE,IAAI;aACzB;YACD,QAAQ,EAAE;gBACR,oBAAoB,EAAE,KAAK,EAAE,GAAG,EAAE,KAAK,EAAE,gBAAgB,EAAE,cAAc,EAAE,KAAK,EAAE,EAAE;oBAClF,+DAA+D;oBAC/D,IAAI,KAAK,CAAC,YAAY,KAAK,YAAY,CAAC,UAAU,IAAI,CAAC,KAAK,CAAC,kBAAkB,KAAK,SAAS,IAAI,KAAK,CAAC,kBAAkB,KAAK,IAAI,CAAC,EAAE,CAAC;wBACpI,MAAM,KAAK,CAAC,YAAY,CAAC,UAAU,CAAC,SAAS,CAAC,UAAU,EAAE,g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CREATE (prefix), APPLY (replace), DEACTIVATE (prefix)\n *\n * Promotions are APPLICATION-scoped (not polymorphic) — 1 factory per operation.\n *\n * CREATE: PREFIX syncs coupon to billing provider → core CREATE writes to DB with provider IDs\n * APPLY: REPLACE validates the promotion and reports its discount. No standard CRUD equivalent,\n * and it records NO redemption — completion does (see the factory's docstring).\n * DEACTIVATE: PREFIX returns { isActive: false } → core UPDATE writes to DB\n *\n * @see billing-polymorphic-full-implementation.md §4.6.3 + §4.6.4 + §4.6.5\n */\n\nimport {\n CoreResourceType,\n ResourceOperationVariantType,\n CoreResourceOperation,\n ErrorType,\n ErrorCustomMessageReference,\n PromotionType,\n DiscountType,\n PromotionDuration,\n Promotion_Operations,\n} from '@wildo-ai/saas-models';\nimport {\n createResourceCustomServiceImplementation,\n type ResourceCustomServiceImplementationFactory,\n} from '~wildo-backend-lib/base-classes/services/services/resource-operation-custom-implementation.factory.backend';\nimport type { ResourcesRegistryBackendService } from '~wildo-backend-lib/resources/services/resources-registry.backend.service';\nimport { getBillingProvider } from '~wildo-backend-lib/billing/services/custom-impl/billing-custom-implementations.backend';\n\n// ════════════════════════════════════════════════════════════════════\n// CREATE — PREFIX_CORE_OPERATIONS\n// ════════════════════════════════════════════════════════════════════\n\n/**\n * Create Promotion CREATE prefix factory.\n *\n * Syncs the coupon (and optionally promotion code) to the billing provider\n * before the core CREATE writes to DB. Augments input with provider IDs.\n *\n * Registered on `INTERNAL_CALL` — the variant the resource configuration actually declares\n * for CREATE. Same drift class as the billing-account CREATE prefix: authored against\n * `REPOSITORY_ONLY`, orphaned once the configured variant moved, and silent because custom\n * implementations resolve by an EXACT operation-path key embedding `variantType`. Orphaned,\n * the promotion row is persisted with no `providerCouponId` / `providerPromotionId`, and\n * OPEN_CHECKOUT later rejects it as \"not synced to billing provider\". Pinned by\n * `billing-custom-impl-operation-path-coherence.test.ts`.\n */\nexport function createPromotionCreateFactory(): ResourceCustomServiceImplementationFactory {\n const factory = (_resourcesRegistryService: ResourcesRegistryBackendService) => {\n return createResourceCustomServiceImplementation({\n operationPath: {\n resourceIdentifier: CoreResourceType.PROMOTIONS,\n operationIdentifier: CoreResourceOperation.CREATE,\n variantType: ResourceOperationVariantType.INTERNAL_CALL,\n isOperationDefault: true,\n },\n handlers: {\n prefixCoreOperations: async (_id, input, executionContext, _operationPath, utils) => {\n // L5: Validate discount fields match the declared discountType\n if (input.discountType === DiscountType.PERCENTAGE && (input.discountPercentage === undefined || input.discountPercentage === null)) {\n throw utils.errorBuilder.buildError(ErrorType.VALIDATION, executionContext, {\n customMessageReference: ErrorCustomMessageReference.BILLING_PROMOTION_INVALID,\n context: { reason: 'discountPercentage is required for PERCENTAGE discount type' },\n });\n }\n if (input.discountType === DiscountType.FIXED_AMOUNT && !input.discountFixedAmount) {\n throw utils.errorBuilder.buildError(ErrorType.VALIDATION, executionContext, {\n customMessageReference: ErrorCustomMessageReference.BILLING_PROMOTION_INVALID,\n context: { reason: 'discountFixedAmount is required for FIXED_AMOUNT discount type' },\n });\n }\n\n const durationMap: Record<string, 'once' | 'repeating' | 'forever'> = {\n [PromotionDuration.ONCE]: 'once',\n [PromotionDuration.REPEATING]: 'repeating',\n [PromotionDuration.FOREVER]: 'forever',\n };\n\n // H1: Provider sync must succeed — throw on failure\n const provider = getBillingProvider();\n const couponResult = await provider.createCoupon({\n ...(input.discountType === DiscountType.PERCENTAGE && { percentOff: input.discountPercentage }),\n ...(input.discountType === DiscountType.FIXED_AMOUNT && input.discountFixedAmount && {\n amountOff: Number(input.discountFixedAmount.amount),\n currency: input.discountFixedAmount.currency,\n }),\n duration: durationMap[input.duration] ?? 'once',\n ...(input.durationInMonths && { durationInMonths: input.durationInMonths }),\n ...(input.maxRedemptions && { maxRedemptions: input.maxRedemptions }),\n ...(input.metadata && { metadata: input.metadata }),\n });\n const providerCouponId = couponResult.providerCouponId;\n\n let providerPromotionId: string | undefined;\n if (input.type === PromotionType.PROMOTION_CODE && input.code && providerCouponId) {\n const promoResult = await provider.createPromotionCode(providerCouponId, input.code);\n providerPromotionId = promoResult.providerPromotionId;\n }\n\n return {\n ...input,\n providerCouponId,\n providerPromotionId,\n isActive: true,\n timesRedeemed: 0,\n };\n },\n },\n });\n };\n\n return factory as unknown as ResourceCustomServiceImplementationFactory;\n}\n\n// ════════════════════════════════════════════════════════════════════\n// APPLY — REPLACE_CORE_OPERATIONS\n// ════════════════════════════════════════════════════════════════════\n\n/**\n * Create Promotion APPLY replace factory.\n *\n * VALIDATES the promotion and returns its discount info. It records NOTHING.\n *\n * The redemption is counted when the purchase COMPLETES — `handleCheckoutCompleted`, behind the\n * durable settlement claim — because entering a code is not redeeming one. See the block where the\n * increment used to be for the full reasoning, including why leaving it here would double-count.\n *\n * The docstring here previously said \"the caller (typically OPEN_CHECKOUT)\". `OPEN_CHECKOUT` has\n * never called this verb: it re-validates a supplied code inline. This is a CLIENT-facing verb, for\n * a purchase form that wants to show the discount before the customer commits.\n */\nexport function createPromotionApplyFactory(): ResourceCustomServiceImplementationFactory {\n const factory = (_resourcesRegistryService: ResourcesRegistryBackendService) => {\n return createResourceCustomServiceImplementation({\n operationPath: {\n resourceIdentifier: CoreResourceType.PROMOTIONS,\n operationIdentifier: Promotion_Operations.APPLY,\n variantType: ResourceOperationVariantType.API_CALL,\n isOperationDefault: true,\n },\n handlers: {\n replaceCoreOperations: async (_id, input, executionContext, _operationPath, utils) => {\n const promotion = utils.currentObject;\n\n // Validate promotion is active\n if (!promotion.isActive) {\n throw utils.errorBuilder.buildError(ErrorType.BUSINESS_RULE, executionContext, {\n customMessageReference: ErrorCustomMessageReference.BILLING_PROMOTION_INVALID,\n context: { promotionId: _id, reason: 'Promotion is not active' },\n });\n }\n\n // Validate date range\n const now = new Date();\n if (promotion.validFrom && now < new Date(promotion.validFrom)) {\n throw utils.errorBuilder.buildError(ErrorType.BUSINESS_RULE, executionContext, {\n customMessageReference: ErrorCustomMessageReference.BILLING_PROMOTION_INVALID,\n context: { promotionId: _id, reason: 'Promotion has not started yet' },\n });\n }\n if (promotion.validUntil && now > new Date(promotion.validUntil)) {\n throw utils.errorBuilder.buildError(ErrorType.BUSINESS_RULE, executionContext, {\n customMessageReference: ErrorCustomMessageReference.BILLING_PROMOTION_INVALID,\n context: { promotionId: _id, reason: 'Promotion has expired' },\n });\n }\n\n // Validate max redemptions\n if (promotion.maxRedemptions !== null && promotion.maxRedemptions !== undefined) {\n if ((promotion.timesRedeemed ?? 0) >= promotion.maxRedemptions) {\n throw utils.errorBuilder.buildError(ErrorType.BUSINESS_RULE, executionContext, {\n customMessageReference: ErrorCustomMessageReference.BILLING_PROMOTION_INVALID,\n context: { promotionId: _id, reason: 'Maximum redemptions reached' },\n });\n }\n }\n\n // Validate code match (when the promotion has a code)\n if (promotion.code && input.code !== promotion.code) {\n throw utils.errorBuilder.buildError(ErrorType.BUSINESS_RULE, executionContext, {\n customMessageReference: ErrorCustomMessageReference.BILLING_PROMOTION_INVALID,\n context: { promotionId: _id, reason: 'Code does not match' },\n });\n }\n\n /*\n * COUNTS NOTHING, and that is the change (#518 follow-up).\n *\n * This used to increment `timesRedeemed` here, guarded by the cap. It was the only place\n * a redemption was ever counted, and it counted at the WRONG MOMENT — this verb runs when\n * a customer types a code into a purchase form, which is not a redemption. A customer who\n * types a code and closes the tab consumed one anyway, so a limited campaign was exhausted\n * by window-shoppers.\n *\n * A redemption is now counted exactly where the money moves: the\n * `checkout.session.completed` webhook, behind the durable settlement claim that makes the\n * count exactly-once across replicas and retries. Leaving the increment here as well would\n * double-count every customer who used this verb and then completed the purchase — the two\n * are two views of ONE redemption, not two redemptions.\n *\n * The cap check above stays, because it is what makes this verb answer honestly: an\n * exhausted code must be refused at the moment it is entered, not silently accepted and\n * then refused at completion when the customer has already paid.\n */\n\n // Return discount info for the caller\n return {\n valid: true,\n promotionId: _id,\n providerCouponId: promotion.providerCouponId,\n providerPromotionId: promotion.providerPromotionId,\n discount: {\n type: promotion.discountType,\n ...(promotion.discountType === DiscountType.PERCENTAGE && { percentage: promotion.discountPercentage }),\n ...(promotion.discountType === DiscountType.FIXED_AMOUNT && { amount: promotion.discountFixedAmount }),\n },\n };\n },\n },\n });\n };\n\n return factory as unknown as ResourceCustomServiceImplementationFactory;\n}\n\n// ════════════════════════════════════════════════════════════════════\n// DEACTIVATE — PREFIX_CORE_OPERATIONS\n// ════════════════════════════════════════════════════════════════════\n\n/**\n * Create Promotion DEACTIVATE prefix factory.\n *\n * Trivially returns { isActive: false } — core UPDATE writes to DB.\n *\n * The operation declares `requestDto: z.object({})` (single) / `{ _ids }` (bulk), so `isActive`\n * can ONLY arrive from here. Before that narrowing the verb inherited the resource's full update\n * contract — including `isActive` itself, so \"deactivate\" could re-activate — and this return was\n * MERGED onto the caller payload rather than replacing it, leaving `code`, `discountPercentage`\n * and `maxRedemptions` writable through a route named deactivate.\n */\nexport function createPromotionDeactivateFactory(): ResourceCustomServiceImplementationFactory {\n const factory = (_resourcesRegistryService: ResourcesRegistryBackendService) => {\n return createResourceCustomServiceImplementation({\n operationPath: {\n resourceIdentifier: CoreResourceType.PROMOTIONS,\n operationIdentifier: Promotion_Operations.DEACTIVATE,\n variantType: ResourceOperationVariantType.API_CALL,\n isOperationDefault: true,\n },\n handlers: {\n prefixCoreOperations: async () => {\n return { isActive: false };\n },\n },\n });\n };\n\n return factory as unknown as ResourceCustomServiceImplementationFactory;\n}\n\n/**\n * Create Promotion DEACTIVATE prefix factory — BULK companion (`haveBulkOperation: true`).\n *\n * A bulk companion is a SEPARATE operation variant with its own path key (`isOperationDefault:\n * false` + `isBulkOperation: true`), so it needs its own registration: the single-row factory\n * above does not cover it. The bulk contract is `{ _ids }` and `_ids` is not a persisted field,\n * so without this handler the route would validate a list of promotion ids and write nothing.\n */\nexport function createPromotionDeactivateBulkFactory(): ResourceCustomServiceImplementationFactory {\n const factory = (_resourcesRegistryService: ResourcesRegistryBackendService) => {\n return createResourceCustomServiceImplementation({\n operationPath: {\n resourceIdentifier: CoreResourceType.PROMOTIONS,\n operationIdentifier: Promotion_Operations.DEACTIVATE,\n variantType: ResourceOperationVariantType.API_CALL,\n isOperationDefault: false,\n isBulkOperation: true,\n },\n handlers: {\n prefixCoreOperations: async () => {\n return { isActive: false };\n },\n },\n });\n };\n\n return factory as unknown as ResourceCustomServiceImplementationFactory;\n}\n"]}