@owlmeans/server-payment 0.1.18-rc.2 → 0.1.18-rc.21

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 (222) hide show
  1. package/README.md +109 -25
  2. package/agent-meta/manifest.json +2 -2
  3. package/agent-meta/skills/server-payment/SKILL.md +475 -52
  4. package/build/actions/index.d.ts +1 -0
  5. package/build/actions/index.d.ts.map +1 -1
  6. package/build/actions/index.js +1 -0
  7. package/build/actions/index.js.map +1 -1
  8. package/build/actions/resync-subscriptions.d.ts +3 -0
  9. package/build/actions/resync-subscriptions.d.ts.map +1 -0
  10. package/build/actions/resync-subscriptions.js +7 -0
  11. package/build/actions/resync-subscriptions.js.map +1 -0
  12. package/build/actions/resync.d.ts +1 -0
  13. package/build/actions/resync.d.ts.map +1 -1
  14. package/build/actions/resync.js +7 -3
  15. package/build/actions/resync.js.map +1 -1
  16. package/build/actions/webhook.d.ts.map +1 -1
  17. package/build/actions/webhook.js +6 -3
  18. package/build/actions/webhook.js.map +1 -1
  19. package/build/config.d.ts +60 -5
  20. package/build/config.d.ts.map +1 -1
  21. package/build/config.js +237 -5
  22. package/build/config.js.map +1 -1
  23. package/build/consts.d.ts +75 -3
  24. package/build/consts.d.ts.map +1 -1
  25. package/build/consts.js +94 -5
  26. package/build/consts.js.map +1 -1
  27. package/build/consumer/capture.d.ts +74 -0
  28. package/build/consumer/capture.d.ts.map +1 -0
  29. package/build/consumer/capture.js +291 -0
  30. package/build/consumer/capture.js.map +1 -0
  31. package/build/consumer/format.d.ts +27 -0
  32. package/build/consumer/format.d.ts.map +1 -0
  33. package/build/consumer/format.js +81 -0
  34. package/build/consumer/format.js.map +1 -0
  35. package/build/consumer/handlers.d.ts +28 -0
  36. package/build/consumer/handlers.d.ts.map +1 -0
  37. package/build/consumer/handlers.js +173 -0
  38. package/build/consumer/handlers.js.map +1 -0
  39. package/build/consumer/index.d.ts +7 -0
  40. package/build/consumer/index.d.ts.map +1 -0
  41. package/build/consumer/index.js +6 -0
  42. package/build/consumer/index.js.map +1 -0
  43. package/build/consumer/mail.d.ts +27 -0
  44. package/build/consumer/mail.d.ts.map +1 -0
  45. package/build/consumer/mail.js +314 -0
  46. package/build/consumer/mail.js.map +1 -0
  47. package/build/consumer/origin.d.ts +14 -0
  48. package/build/consumer/origin.d.ts.map +1 -0
  49. package/build/consumer/origin.js +47 -0
  50. package/build/consumer/origin.js.map +1 -0
  51. package/build/consumer/reconcile.d.ts +12 -0
  52. package/build/consumer/reconcile.d.ts.map +1 -0
  53. package/build/consumer/reconcile.js +317 -0
  54. package/build/consumer/reconcile.js.map +1 -0
  55. package/build/consumer/records.d.ts +78 -0
  56. package/build/consumer/records.d.ts.map +1 -0
  57. package/build/consumer/records.js +296 -0
  58. package/build/consumer/records.js.map +1 -0
  59. package/build/consumer/service.d.ts +51 -0
  60. package/build/consumer/service.d.ts.map +1 -0
  61. package/build/consumer/service.js +760 -0
  62. package/build/consumer/service.js.map +1 -0
  63. package/build/consumer/withdrawal.d.ts +57 -0
  64. package/build/consumer/withdrawal.d.ts.map +1 -0
  65. package/build/consumer/withdrawal.js +247 -0
  66. package/build/consumer/withdrawal.js.map +1 -0
  67. package/build/entitlement.d.ts +10 -0
  68. package/build/entitlement.d.ts.map +1 -0
  69. package/build/entitlement.js +69 -0
  70. package/build/entitlement.js.map +1 -0
  71. package/build/entrypoints.d.ts +1 -1
  72. package/build/entrypoints.d.ts.map +1 -1
  73. package/build/entrypoints.js +2 -1
  74. package/build/entrypoints.js.map +1 -1
  75. package/build/gate.d.ts +32 -4
  76. package/build/gate.d.ts.map +1 -1
  77. package/build/gate.js +59 -19
  78. package/build/gate.js.map +1 -1
  79. package/build/index.d.ts +18 -3
  80. package/build/index.d.ts.map +1 -1
  81. package/build/index.js +15 -3
  82. package/build/index.js.map +1 -1
  83. package/build/limit.d.ts +13 -0
  84. package/build/limit.d.ts.map +1 -0
  85. package/build/limit.js +47 -0
  86. package/build/limit.js.map +1 -0
  87. package/build/model.d.ts +10 -1
  88. package/build/model.d.ts.map +1 -1
  89. package/build/model.js +215 -17
  90. package/build/model.js.map +1 -1
  91. package/build/observer.d.ts +9 -0
  92. package/build/observer.d.ts.map +1 -1
  93. package/build/observer.js +38 -12
  94. package/build/observer.js.map +1 -1
  95. package/build/plan.d.ts +22 -0
  96. package/build/plan.d.ts.map +1 -0
  97. package/build/plan.js +72 -0
  98. package/build/plan.js.map +1 -0
  99. package/build/plugins/checkout-plugins.d.ts +49 -0
  100. package/build/plugins/checkout-plugins.d.ts.map +1 -0
  101. package/build/plugins/checkout-plugins.js +124 -0
  102. package/build/plugins/checkout-plugins.js.map +1 -0
  103. package/build/plugins/estimate.d.ts +43 -0
  104. package/build/plugins/estimate.d.ts.map +1 -0
  105. package/build/plugins/estimate.js +268 -0
  106. package/build/plugins/estimate.js.map +1 -0
  107. package/build/plugins/events.d.ts +45 -10
  108. package/build/plugins/events.d.ts.map +1 -1
  109. package/build/plugins/events.js +605 -136
  110. package/build/plugins/events.js.map +1 -1
  111. package/build/plugins/fx.d.ts +31 -0
  112. package/build/plugins/fx.d.ts.map +1 -0
  113. package/build/plugins/fx.js +81 -0
  114. package/build/plugins/fx.js.map +1 -0
  115. package/build/plugins/portal.d.ts +37 -0
  116. package/build/plugins/portal.d.ts.map +1 -0
  117. package/build/plugins/portal.js +265 -0
  118. package/build/plugins/portal.js.map +1 -0
  119. package/build/plugins/refunds.d.ts +33 -0
  120. package/build/plugins/refunds.d.ts.map +1 -0
  121. package/build/plugins/refunds.js +80 -0
  122. package/build/plugins/refunds.js.map +1 -0
  123. package/build/plugins/stripe.d.ts +36 -4
  124. package/build/plugins/stripe.d.ts.map +1 -1
  125. package/build/plugins/stripe.js +492 -97
  126. package/build/plugins/stripe.js.map +1 -1
  127. package/build/plugins/webhook-manager.d.ts +46 -0
  128. package/build/plugins/webhook-manager.d.ts.map +1 -0
  129. package/build/plugins/webhook-manager.js +231 -0
  130. package/build/plugins/webhook-manager.js.map +1 -0
  131. package/build/reconcile.d.ts +15 -0
  132. package/build/reconcile.d.ts.map +1 -0
  133. package/build/reconcile.js +88 -0
  134. package/build/reconcile.js.map +1 -0
  135. package/build/resource.d.ts +12 -1
  136. package/build/resource.d.ts.map +1 -1
  137. package/build/resource.js +97 -6
  138. package/build/resource.js.map +1 -1
  139. package/build/service.d.ts +28 -3
  140. package/build/service.d.ts.map +1 -1
  141. package/build/service.js +146 -19
  142. package/build/service.js.map +1 -1
  143. package/build/subscription.d.ts +48 -0
  144. package/build/subscription.d.ts.map +1 -0
  145. package/build/subscription.js +176 -0
  146. package/build/subscription.js.map +1 -0
  147. package/build/sync.d.ts +28 -1
  148. package/build/sync.d.ts.map +1 -1
  149. package/build/sync.js +208 -31
  150. package/build/sync.js.map +1 -1
  151. package/build/types.d.ts +1115 -36
  152. package/build/types.d.ts.map +1 -1
  153. package/build/usage.d.ts +63 -0
  154. package/build/usage.d.ts.map +1 -0
  155. package/build/usage.js +363 -0
  156. package/build/usage.js.map +1 -0
  157. package/build/utils.d.ts +52 -1
  158. package/build/utils.d.ts.map +1 -1
  159. package/build/utils.js +69 -7
  160. package/build/utils.js.map +1 -1
  161. package/package.json +17 -13
  162. package/src/actions/index.ts +1 -0
  163. package/src/actions/resync-subscriptions.ts +10 -0
  164. package/src/actions/resync.ts +6 -3
  165. package/src/actions/webhook.ts +5 -3
  166. package/src/config.ts +264 -8
  167. package/src/consts.ts +114 -6
  168. package/src/consumer/capture.ts +362 -0
  169. package/src/consumer/format.ts +90 -0
  170. package/src/consumer/handlers.ts +211 -0
  171. package/src/consumer/index.ts +6 -0
  172. package/src/consumer/mail.ts +368 -0
  173. package/src/consumer/origin.ts +63 -0
  174. package/src/consumer/reconcile.ts +329 -0
  175. package/src/consumer/records.ts +374 -0
  176. package/src/consumer/service.ts +868 -0
  177. package/src/consumer/withdrawal.ts +302 -0
  178. package/src/entitlement.ts +84 -0
  179. package/src/entrypoints.ts +2 -1
  180. package/src/gate.ts +88 -21
  181. package/src/index.ts +24 -3
  182. package/src/limit.ts +57 -0
  183. package/src/model.ts +237 -18
  184. package/src/observer.ts +44 -11
  185. package/src/plan.ts +89 -0
  186. package/src/plugins/checkout-plugins.ts +155 -0
  187. package/src/plugins/estimate.ts +339 -0
  188. package/src/plugins/events.ts +677 -121
  189. package/src/plugins/fx.ts +122 -0
  190. package/src/plugins/portal.ts +306 -0
  191. package/src/plugins/refunds.ts +108 -0
  192. package/src/plugins/stripe.ts +581 -96
  193. package/src/plugins/webhook-manager.ts +270 -0
  194. package/src/reconcile.ts +103 -0
  195. package/src/resource.ts +152 -7
  196. package/src/service.ts +174 -18
  197. package/src/subscription.ts +231 -0
  198. package/src/sync.ts +249 -29
  199. package/src/types.ts +1227 -32
  200. package/src/usage.ts +453 -0
  201. package/src/utils.ts +127 -10
  202. package/tests/checkout-consumer.spec.ts +348 -0
  203. package/tests/checkout-plugins.spec.ts +164 -0
  204. package/tests/checkout.spec.ts +184 -83
  205. package/tests/consumer-events.spec.ts +218 -0
  206. package/tests/consumer-fixtures.ts +132 -0
  207. package/tests/consumer-ops.spec.ts +351 -0
  208. package/tests/consumer-rights.integration.spec.ts +150 -0
  209. package/tests/consumer-rights.spec.ts +501 -0
  210. package/tests/context.ts +109 -0
  211. package/tests/entitlement.spec.ts +103 -0
  212. package/tests/estimate.spec.ts +240 -0
  213. package/tests/events.spec.ts +356 -0
  214. package/tests/fake-stripe.ts +972 -0
  215. package/tests/gate.spec.ts +62 -72
  216. package/tests/limit-gate.spec.ts +68 -0
  217. package/tests/portal.spec.ts +200 -0
  218. package/tests/protocol.spec.ts +23 -6
  219. package/tests/sync.spec.ts +114 -0
  220. package/tests/usage.integration.spec.ts +101 -0
  221. package/tests/usage.spec.ts +171 -0
  222. package/tests/webhook-manager.spec.ts +152 -0
@@ -0,0 +1,81 @@
1
+ import { randomInt } from 'node:crypto';
2
+ import { lastWithdrawalDayOf } from '@owlmeans/payment';
3
+ import { CONTRACT_REF_ALPHABET, RESERVED_MAIL_TLDS } from '../consts.js';
4
+ /** `CR-YYMMDD-XXXXXX` — the purchase's UTC date and six characters of an unambiguous alphabet. */
5
+ export const makeContractRef = (at = new Date()) => {
6
+ const date = [at.getUTCFullYear() % 100, at.getUTCMonth() + 1, at.getUTCDate()]
7
+ .map(part => String(part).padStart(2, '0')).join('');
8
+ const suffix = Array.from({ length: 6 }, () => CONTRACT_REF_ALPHABET[randomInt(CONTRACT_REF_ALPHABET.length)]).join('');
9
+ return `CR-${date}-${suffix}`;
10
+ };
11
+ /** A contract reference as a person may type it: trimmed, upper-cased, look-alike dashes unified. */
12
+ export const normalizeContractRef = (value) => value.trim().toUpperCase().replace(/[‐-―−\s]+/g, '-');
13
+ export const normalizeEmail = (value) => (value ?? '').trim().toLowerCase();
14
+ /**
15
+ * Whether an address is on a reserved top-level domain (`.test`, `.example`, `.invalid`,
16
+ * `.localhost` — RFC 2606 / 6761), any subdomain included: `a@shop.test`, `a@mail.shop.test`,
17
+ * `a@localhost`. Case, surrounding spaces, a display-name form (`Name <a@shop.test>`) and a
18
+ * trailing root dot are all read through.
19
+ */
20
+ export const isReservedAddress = (address) => {
21
+ const bare = normalizeEmail(address).replace(/^.*<([^>]*)>.*$/, '$1');
22
+ const domain = (bare.split('@').pop() ?? '').trim().replace(/\.+$/, '');
23
+ const tld = domain.split('.').pop() ?? '';
24
+ return RESERVED_MAIL_TLDS.includes(tld);
25
+ };
26
+ export const escapeHtml = (value) => value
27
+ .replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;')
28
+ .replace(/"/g, '&quot;').replace(/'/g, '&#39;');
29
+ const fractionDigitsOf = (currency) => {
30
+ try {
31
+ return new Intl.NumberFormat('en', { style: 'currency', currency: currency.toUpperCase() })
32
+ .resolvedOptions().maximumFractionDigits ?? 2;
33
+ }
34
+ catch {
35
+ return 2;
36
+ }
37
+ };
38
+ /** Minor units as a localized amount with its currency (`12,56 €`, `$12.56`). */
39
+ export const formatMoney = (amountMinor, currency, lng) => {
40
+ const digits = fractionDigitsOf(currency);
41
+ const major = amountMinor / 10 ** digits;
42
+ try {
43
+ return new Intl.NumberFormat(lng, { style: 'currency', currency: currency.toUpperCase() }).format(major);
44
+ }
45
+ catch {
46
+ return `${major.toFixed(digits)} ${currency.toUpperCase()}`;
47
+ }
48
+ };
49
+ /** A date and time in UTC, localized (`23 September 2026, 14:05`). */
50
+ export const formatDateTime = (at, lng) => {
51
+ try {
52
+ return new Intl.DateTimeFormat(lng, { dateStyle: 'long', timeStyle: 'short', timeZone: 'UTC' }).format(at);
53
+ }
54
+ catch {
55
+ return at.toISOString().replace('T', ' ').slice(0, 16);
56
+ }
57
+ };
58
+ /** A calendar date in UTC, localized. */
59
+ export const formatDate = (at, lng) => {
60
+ try {
61
+ return new Intl.DateTimeFormat(lng, { dateStyle: 'long', timeZone: 'UTC' }).format(at);
62
+ }
63
+ catch {
64
+ return at.toISOString().slice(0, 10);
65
+ }
66
+ };
67
+ /**
68
+ * The last included day of a window whose deadline is EXCLUSIVE (the first instant it is over),
69
+ * as a UTC date — the copy says "until the end of <date>": 13 October 00:00 UTC is "12 October".
70
+ */
71
+ export const formatDeadline = (deadline, lng) => formatDate(lastWithdrawalDayOf(deadline), lng);
72
+ /** A country's name in a language, else its code. */
73
+ export const countryName = (country, lng) => {
74
+ try {
75
+ return new Intl.DisplayNames([lng], { type: 'region' }).of(country.toUpperCase()) ?? country;
76
+ }
77
+ catch {
78
+ return country;
79
+ }
80
+ };
81
+ //# sourceMappingURL=format.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"format.js","sourceRoot":"","sources":["../../src/consumer/format.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AACvC,OAAO,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAA;AACvD,OAAO,EAAE,qBAAqB,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAA;AAExE,kGAAkG;AAClG,MAAM,CAAC,MAAM,eAAe,GAAG,CA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WAAW,GAAG,CAAC,OAAe,EAAE,GAAW,EAAU,EAAE;IAClE,IAAI,CAAC;QACH,OAAO,IAAI,IAAI,CAAC,YAAY,CAAC,CAAC,GAAG,CAAC,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC,CAAC,EAAE,CAAC,OAAO,CAAC,WAAW,EAAE,CAAC,IAAI,OAAO,CAAA;IAC9F,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,OAAO,CAAA;IAChB,CAAC;AACH,CAAC,CAAA"}
@@ -0,0 +1,28 @@
1
+ import type { EntrypointProtocolDeclaration } from '@owlmeans/entrypoint';
2
+ import type { CheckoutReadProtocols, ConsumerRightsAccountProtocols, ConsumerRightsPublicProtocols } from '@owlmeans/payment';
3
+ import type { ServerProtocolEntrypoint } from '@owlmeans/server-entrypoint';
4
+ import type { CheckoutReadHandlerOptions, ConsumerRightsHandlerOptions } from '../types.js';
5
+ type Bound = ServerProtocolEntrypoint<EntrypointProtocolDeclaration>;
6
+ /** The protocol tree `makeConsumerRightsProtocols` builds, with or without its public subtree. */
7
+ export type ConsumerRightsTree = ConsumerRightsAccountProtocols & {
8
+ public?: ConsumerRightsPublicProtocols;
9
+ };
10
+ /**
11
+ * Server bindings of `makeConsumerRightsProtocols`' tree over the consumer-rights service. The
12
+ * account routes act for the request's organization (`resolveEntity`, default `req.entity.id`);
13
+ * the money-moving acts (consent, start request, withdrawal, cancellation) pass `guardMoney` first
14
+ * (refuse an API key there). The public routes — the statutory functions without a login — need
15
+ * `throttle` (a wiring error otherwise), drop a filled honeypot silently, and answer every
16
+ * declaration with the same receipt shape after at least `publicMinMs`, matched or not. Every hook
17
+ * gets the request's context as its last argument.
18
+ *
19
+ * @throws SyntaxError when the tree has a public subtree and no `throttle` is given
20
+ */
21
+ export declare const consumerRightsEntrypoints: (protocols: ConsumerRightsTree, opts?: ConsumerRightsHandlerOptions) => Bound[];
22
+ /**
23
+ * Server bindings of `makeCheckoutReadProtocols`' tree: the entity's amount policy as the checkout
24
+ * plugins narrow it now (the same computation the checkout enforces) and the synced plan prices.
25
+ */
26
+ export declare const checkoutReadEntrypoints: (protocols: CheckoutReadProtocols, opts?: CheckoutReadHandlerOptions) => Bound[];
27
+ export {};
28
+ //# sourceMappingURL=handlers.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"handlers.d.ts","sourceRoot":"","sources":["../../src/consumer/handlers.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAmB,6BAA6B,EAAE,MAAM,sBAAsB,CAAA;AAE1F,OAAO,KAAK,EACV,qBAAqB,EAAE,8BAA8B,EAAE,6BAA6B,EAErF,MAAM,mBAAmB,CAAA;AAI1B,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,6BAA6B,CAAA;AAK3E,OAAO,KAAK,EACV,0BAA0B,EAAE,4BAA4B,EAEzD,MAAM,aAAa,CAAA;AAEpB,KAAK,KAAK,GAAG,wBAAwB,CAAC,6BAA6B,CAAC,CAAA;AAEpE,kGAAkG;AAClG,MAAM,MAAM,kBAAkB,GAAG,8BAA8B,GAAG;IAAE,MAAM,CAAC,EAAE,6BAA6B,CAAA;CAAE,CAAA;AAiC5G;;;;;;;;;;GAUG;AACH,eAAO,MAAM,yBAAyB,cACzB,kBAAkB,SAAQ,4BAA4B,KAChE,KAAK,EA8GP,CAAA;AAED;;;GAGG;AACH,eAAO,MAAM,uBAAuB,cAAe,qBAAqB,SAAQ,0BAA0B,KAAQ,KAAK,EAwBtH,CAAA"}
@@ -0,0 +1,173 @@
1
+ import { randomBytes } from 'node:crypto';
2
+ import { AuthForbidden } from '@owlmeans/auth';
3
+ import { ConsumerRightsError, DeclarationChannel } from '@owlmeans/payment';
4
+ import { handlers } from '@owlmeans/server-api';
5
+ import { bind } from '@owlmeans/server-entrypoint';
6
+ import { CONSUMER_RIGHTS_SERVICE, GATEWAY_SERVICE } from '../consts.js';
7
+ import { payment } from '../utils.js';
8
+ import { requestOriginOf } from './origin.js';
9
+ import { unlockedProfileView } from './records.js';
10
+ const defaultEntity = (req, _ctx) => req.entity?.id ?? null;
11
+ const DEFAULT_PUBLIC_MIN_MS = 1000;
12
+ const sleep = async (ms) => await new Promise(resolve => setTimeout(resolve, ms));
13
+ /** Answer no sooner than `minMs` after the start — a matched declaration takes as long as an unmatched one. */
14
+ const padded = async (minMs, run) => {
15
+ const started = Date.now();
16
+ try {
17
+ return await run();
18
+ }
19
+ finally {
20
+ const left = minMs - (Date.now() - started);
21
+ if (left > 0)
22
+ await sleep(left);
23
+ }
24
+ };
25
+ /** The public answer: what was declared and when — never a status, an amount or a match. */
26
+ const publicPart = (receipt) => ({
27
+ declarationId: receipt.declarationId, receivedAt: receipt.receivedAt, content: receipt.content, mailed: receipt.mailed,
28
+ });
29
+ /** A form a bot filled (the honeypot) gets the same shape of answer, and nothing is recorded or sent. */
30
+ const decoyReceipt = (content) => ({
31
+ declarationId: randomBytes(12).toString('hex'), receivedAt: new Date(), content, mailed: false,
32
+ });
33
+ const typed = (fields) => Object.fromEntries(Object.entries(fields).filter((entry) => typeof entry[1] === 'string' && entry[1].trim() !== ''));
34
+ /**
35
+ * Server bindings of `makeConsumerRightsProtocols`' tree over the consumer-rights service. The
36
+ * account routes act for the request's organization (`resolveEntity`, default `req.entity.id`);
37
+ * the money-moving acts (consent, start request, withdrawal, cancellation) pass `guardMoney` first
38
+ * (refuse an API key there). The public routes — the statutory functions without a login — need
39
+ * `throttle` (a wiring error otherwise), drop a filled honeypot silently, and answer every
40
+ * declaration with the same receipt shape after at least `publicMinMs`, matched or not. Every hook
41
+ * gets the request's context as its last argument.
42
+ *
43
+ * @throws SyntaxError when the tree has a public subtree and no `throttle` is given
44
+ */
45
+ export const consumerRightsEntrypoints = (protocols, opts = {}) => {
46
+ if (protocols.public != null && opts.throttle == null) {
47
+ throw new SyntaxError('consumer-rights: the public routes need a throttle');
48
+ }
49
+ const api = handlers();
50
+ const serviceOf = (ctx) => ctx.service(opts.serviceAlias ?? CONSUMER_RIGHTS_SERVICE);
51
+ const apiCtx = (ctx) => ctx;
52
+ const entityOf = (req, ctx) => {
53
+ const entityId = (opts.resolveEntity ?? defaultEntity)(req, apiCtx(ctx));
54
+ if (entityId == null || entityId === '') {
55
+ throw new AuthForbidden('entity');
56
+ }
57
+ return entityId;
58
+ };
59
+ const subjectFor = async (req, ctx) => ({
60
+ ...(await opts.subjectOf?.(req, apiCtx(ctx)) ?? {}),
61
+ entityId: entityOf(req, ctx),
62
+ channel: DeclarationChannel.InApp,
63
+ });
64
+ const metaOf = (req, ctx) => opts.metaOf != null ? opts.metaOf(req, apiCtx(ctx)) : requestOriginOf(req);
65
+ const guard = async (req, action, ctx) => {
66
+ await opts.guardMoney?.(req, action, apiCtx(ctx));
67
+ };
68
+ const minMs = opts.publicMinMs ?? DEFAULT_PUBLIC_MIN_MS;
69
+ const bound = [
70
+ bind(protocols.base),
71
+ bind(protocols.profile, api.request(protocols.profile, async (req, ctx) => await serviceOf(ctx).profile(entityOf(req, ctx))
72
+ ?? unlockedProfileView(await payment(ctx).consumerRightsPolicy()))),
73
+ bind(protocols.purchases, api.request(protocols.purchases, async (req, ctx) => ({ purchases: await serviceOf(ctx).purchases(entityOf(req, ctx)) }))),
74
+ bind(protocols.consent, api.request(protocols.consent, async (req, ctx) => await serviceOf(ctx).consentView(entityOf(req, ctx)))),
75
+ bind(protocols.giveConsent, api.body(protocols.giveConsent, async (body, ctx, req) => {
76
+ await guard(req, 'consent', ctx);
77
+ return await serviceOf(ctx).recordConsent(await subjectFor(req, ctx), body, metaOf(req, ctx));
78
+ })),
79
+ bind(protocols.start, api.request(protocols.start, async (req, ctx) => await serviceOf(ctx).startView(entityOf(req, ctx), String(req.query.planSku)))),
80
+ bind(protocols.requestStart, api.body(protocols.requestStart, async (body, ctx, req) => {
81
+ await guard(req, 'start', ctx);
82
+ const plan = await opts.planNameOf?.(body.planSku, body.language, req, apiCtx(ctx));
83
+ return await serviceOf(ctx).recordStartRequest(await subjectFor(req, ctx), body, metaOf(req, ctx), plan != null ? { plan } : {});
84
+ })),
85
+ bind(protocols.withdrawals, api.request(protocols.withdrawals, async (req, ctx) => {
86
+ const subject = await subjectFor(req, ctx);
87
+ return await serviceOf(ctx).withdrawalCandidates(subject.entityId, subject);
88
+ })),
89
+ bind(protocols.withdraw, api.body(protocols.withdraw, async (body, ctx, req) => {
90
+ await guard(req, 'withdraw', ctx);
91
+ return await serviceOf(ctx).withdraw(await subjectFor(req, ctx), body, metaOf(req, ctx));
92
+ })),
93
+ bind(protocols.cancel, api.body(protocols.cancel, async (body, ctx, req) => {
94
+ await guard(req, 'cancel', ctx);
95
+ return await serviceOf(ctx).cancel(await subjectFor(req, ctx), body, metaOf(req, ctx));
96
+ })),
97
+ ];
98
+ const pub = protocols.public;
99
+ if (pub == null) {
100
+ return bound;
101
+ }
102
+ const throttle = opts.throttle;
103
+ return [
104
+ ...bound,
105
+ bind(pub.base),
106
+ bind(pub.policy, api.request(pub.policy, async (_req, ctx) => {
107
+ const policy = await payment(ctx).consumerRightsPolicy();
108
+ if (policy == null) {
109
+ throw new ConsumerRightsError('policy:none');
110
+ }
111
+ const view = {
112
+ mechanisms: { withdrawal: policy.mechanisms.withdrawal, cancellation: policy.mechanisms.cancellation },
113
+ languages: Object.keys(policy.links),
114
+ links: policy.links,
115
+ textVersion: policy.textVersion,
116
+ };
117
+ return view;
118
+ })),
119
+ bind(pub.withdraw, api.body(pub.withdraw, async (body, ctx, req) => {
120
+ const origin = metaOf(req, ctx);
121
+ await throttle(req, { action: 'withdrawal', email: body.email, ...(origin.ip != null ? { ip: origin.ip } : {}) }, apiCtx(ctx));
122
+ return await padded(minMs, async () => {
123
+ const content = typed({ name: body.name, contract: body.contractRef, email: body.email });
124
+ if (body.honeypot != null && body.honeypot !== '') {
125
+ return decoyReceipt(content);
126
+ }
127
+ return publicPart(await serviceOf(ctx).withdraw(null, body, origin));
128
+ });
129
+ })),
130
+ bind(pub.cancel, api.body(pub.cancel, async (body, ctx, req) => {
131
+ const origin = metaOf(req, ctx);
132
+ await throttle(req, { action: 'cancellation', email: body.email, ...(origin.ip != null ? { ip: origin.ip } : {}) }, apiCtx(ctx));
133
+ return await padded(minMs, async () => {
134
+ const content = typed({
135
+ name: body.name, contract: body.contractRef, email: body.email, kind: body.kind, reason: body.reason,
136
+ date: body.effective === 'date' ? body.date : undefined,
137
+ });
138
+ if (body.honeypot != null && body.honeypot !== '') {
139
+ return decoyReceipt(content);
140
+ }
141
+ return publicPart(await serviceOf(ctx).cancel(null, body, origin));
142
+ });
143
+ })),
144
+ ];
145
+ };
146
+ /**
147
+ * Server bindings of `makeCheckoutReadProtocols`' tree: the entity's amount policy as the checkout
148
+ * plugins narrow it now (the same computation the checkout enforces) and the synced plan prices.
149
+ */
150
+ export const checkoutReadEntrypoints = (protocols, opts = {}) => {
151
+ const api = handlers();
152
+ const gatewayOf = (ctx) => ctx.service(opts.gatewayAlias ?? GATEWAY_SERVICE);
153
+ const entityOf = (req, ctx) => {
154
+ const entityId = (opts.resolveEntity ?? defaultEntity)(req, ctx);
155
+ if (entityId == null || entityId === '') {
156
+ throw new AuthForbidden('entity');
157
+ }
158
+ return entityId;
159
+ };
160
+ return [
161
+ bind(protocols.base),
162
+ bind(protocols.amountPolicy, api.request(protocols.amountPolicy, async (req, ctx) => {
163
+ const { productSku, planSku } = req.query;
164
+ return await gatewayOf(ctx).amountPolicy(ctx, entityOf(req, ctx), productSku, planSku ?? undefined);
165
+ })),
166
+ bind(protocols.planPrices, api.request(protocols.planPrices, async (req, ctx) => {
167
+ entityOf(req, ctx);
168
+ const { productSku } = req.query;
169
+ return { prices: await gatewayOf(ctx).planPrices(ctx, productSku) };
170
+ })),
171
+ ];
172
+ };
173
+ //# sourceMappingURL=handlers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"handlers.js","sourceRoot":"","sources":["../../src/consumer/handlers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AACzC,OAAO,EAAE,aAAa,EAAE,MA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AAC,CAAC,YAAY,CAAC,GAA4B,EAAE,QAAQ,CAAC,GAAG,EAAE,GAAG,CAAC,EAAE,UAAU,EAAE,OAAO,IAAI,SAAS,CAAC,CAAA;QAC9H,CAAC,CAAC,CAAC;QACH,IAAI,CAAC,SAAS,CAAC,UAAU,EAAE,GAAG,CAAC,OAAO,CAAC,SAAS,CAAC,UAAU,EAAE,KAAK,EAAE,GAAG,EAAE,GAAG,EAAE,EAAE;YAC9E,QAAQ,CAAC,GAAG,EAAE,GAAG,CAAC,CAAA;YAClB,MAAM,EAAE,UAAU,EAAE,GAAG,GAAG,CAAC,KAA+B,CAAA;YAC1D,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC,GAAG,CAAC,CAAC,UAAU,CAAC,GAA4B,EAAE,UAAU,CAAC,EAAE,CAAA;QAC9F,CAAC,CAAC,CAAC;KACO,CAAA;AACd,CAAC,CAAA"}
@@ -0,0 +1,7 @@
1
+ export { requestOriginOf } from './origin.js';
2
+ export { appendConsumerRights, makeConsumerRightsService } from './service.js';
3
+ export { consumerRightsEntrypoints, checkoutReadEntrypoints } from './handlers.js';
4
+ export type { ConsumerRightsTree } from './handlers.js';
5
+ export { traderIdentityOf } from './mail.js';
6
+ export { makeContractRef, isReservedAddress } from './format.js';
7
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/consumer/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAC7C,OAAO,EAAE,oBAAoB,EAAE,yBAAyB,EAAE,MAAM,cAAc,CAAA;AAC9E,OAAO,EAAE,yBAAyB,EAAE,uBAAuB,EAAE,MAAM,eAAe,CAAA;AAClF,YAAY,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAA;AACvD,OAAO,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAA;AAC5C,OAAO,EAAE,eAAe,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAA"}
@@ -0,0 +1,6 @@
1
+ export { requestOriginOf } from './origin.js';
2
+ export { appendConsumerRights, makeConsumerRightsService } from './service.js';
3
+ export { consumerRightsEntrypoints, checkoutReadEntrypoints } from './handlers.js';
4
+ export { traderIdentityOf } from './mail.js';
5
+ export { makeContractRef, isReservedAddress } from './format.js';
6
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/consumer/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAC7C,OAAO,EAAE,oBAAoB,EAAE,yBAAyB,EAAE,MAAM,cAAc,CAAA;AAC9E,OAAO,EAAE,yBAAyB,EAAE,uBAAuB,EAAE,MAAM,eAAe,CAAA;AAElF,OAAO,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAA;AAC5C,OAAO,EAAE,eAAe,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAA"}
@@ -0,0 +1,27 @@
1
+ import type { ConsumerRightsPolicy } from '@owlmeans/payment';
2
+ import type { Context as ApiContext } from '@owlmeans/server-api';
3
+ import type { ConsumerMailData, ConsumerMailKind, ConsumerMailPluginConfig, TraderDef } from '../types.js';
4
+ /** The trader as the mails and the withdrawal information name it: legal name, address, e-mail. */
5
+ export declare const traderIdentityOf: (trader: TraderDef) => string;
6
+ /** The declared trader; an undeclared one falls back to the service name (no mechanism is on then). */
7
+ export declare const traderOf: (ctx: ApiContext, mail: ConsumerMailPluginConfig | null) => TraderDef;
8
+ /** A plan's title in a language: its localization, else its catalogue title, else its sku. */
9
+ export declare const planTitleOf: (ctx: ApiContext, planSku: string | undefined, lng: string) => Promise<string>;
10
+ /**
11
+ * Everything a mail of `kind` about `recordId` is rendered from, read back from the records — the
12
+ * mail repeats exactly what was recorded, and a retry renders the same message. `null` when there
13
+ * is nobody to write to.
14
+ */
15
+ export declare const mailDataOf: (ctx: ApiContext, policy: ConsumerRightsPolicy, trader: TraderDef, kind: ConsumerMailKind, recordId: string) => Promise<ConsumerMailData | null>;
16
+ /**
17
+ * Send one consumer-rights mail on a durable medium, in the language the consumer was shown, and
18
+ * record the outcome as a `mail` event (step = the mail kind): sent, skipped (a reserved domain
19
+ * such as `.test` / `.example` / `.invalid` / `.localhost`, or a renderer that suppressed it) or
20
+ * failed (a transport error, no mailer registered — retried by `reconcile`). The application's
21
+ * renderer (`useMailRenderer`) may replace the message. Each archive (`bcc`) address gets its own
22
+ * copy. Never throws.
23
+ *
24
+ * @returns whether the consumer's own copy was handed to the mailer
25
+ */
26
+ export declare const sendConsumerMail: (ctx: ApiContext, policy: ConsumerRightsPolicy, kind: ConsumerMailKind, recordId: string) => Promise<boolean>;
27
+ //# sourceMappingURL=mail.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mail.d.ts","sourceRoot":"","sources":["../../src/consumer/mail.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAuB,oBAAoB,EAAc,MAAM,mBAAmB,CAAA;AAC9F,OAAO,KAAK,EAAE,OAAO,IAAI,UAAU,EAAE,MAAM,sBAAsB,CAAA;AAUjE,OAAO,KAAK,EACwC,gBAAgB,EAAE,gBAAgB,EAAE,wBAAwB,EAC1E,SAAS,EAC9C,MAAM,aAAa,CAAA;AAuCpB,mGAAmG;AACnG,eAAO,MAAM,gBAAgB,WAAY,SAAS,KAAG,MAC2D,CAAA;AAEhH,uGAAuG;AACvG,eAAO,MAAM,QAAQ,QAAS,UAAU,QAAQ,wBAAwB,GAAG,IAAI,KAAG,SACX,CAAA;AAEvE,8FAA8F;AAC9F,eAAO,MAAM,WAAW,QAAe,UAAU,WAAW,MAAM,GAAG,SAAS,OAAO,MAAM,KAAG,OAAO,CAAC,MAAM,CAQ3G,CAAA;AAkJD;;;;GAIG;AACH,eAAO,MAAM,UAAU,QAChB,UAAU,UAAU,oBAAoB,UAAU,SAAS,QAAQ,gBAAgB,YAAY,MAAM,KACzG,OAAO,CAAC,gBAAgB,GAAG,IAAI,CAyCjC,CAAA;AAgCD;;;;;;;;;GASG;AACH,eAAO,MAAM,gBAAgB,QACtB,UAAU,UAAU,oBAAoB,QAAQ,gBAAgB,YAAY,MAAM,KACtF,OAAO,CAAC,OAAO,CAsDjB,CAAA"}