@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,314 @@
1
+ import { MAILER_SERVICE } from '@owlmeans/mailer';
2
+ import { CancellationStatus, consumerText, linksOf, PurchaseKind, WithdrawalStatus, } from '@owlmeans/payment';
3
+ import { findPlan, findProduct } from '../plan.js';
4
+ import { compact, consumerConsents, consumerDeclarations, consumerMailConfig, consumerRightsOf, errorText, payment, purchases, } from '../utils.js';
5
+ import { escapeHtml, formatDate, formatDateTime, formatDeadline, formatMoney, isReservedAddress, } from './format.js';
6
+ import { contactEmailOf, recordEvent } from './records.js';
7
+ const RECORD_KIND = {
8
+ purchase: 'purchase', consent: 'consent', start: 'consent', withdrawal: 'declaration', cancellation: 'declaration',
9
+ };
10
+ const text = (lng, path, vars = {}) => consumerText(lng, path, vars);
11
+ const textOf = (blocks, lng) => blocks
12
+ .map(block => 'text' in block ? block.text : text(lng, 'email.common.link', { label: block.label, url: block.url }))
13
+ .join('\n\n');
14
+ const htmlOf = (blocks) => blocks.map(block => 'text' in block
15
+ ? `<p>${escapeHtml(block.text).replace(/\n/g, '<br>')}</p>`
16
+ : `<p>${escapeHtml(block.label)}: <a href="${escapeHtml(block.url)}">${escapeHtml(block.url)}</a></p>`).join('\n');
17
+ const linkBlocks = (lng, links, which) => {
18
+ const labels = {
19
+ billingTerms: 'links.billing-terms',
20
+ withdrawalInformation: 'links.withdrawal-information',
21
+ withdrawalForm: 'links.withdrawal-form',
22
+ withdrawalFunction: 'links.withdrawal-function',
23
+ cancellation: 'links.cancellation',
24
+ };
25
+ return which
26
+ .filter(key => links[key] != null && links[key] !== '')
27
+ .map(key => ({ label: text(lng, labels[key]), url: links[key] }));
28
+ };
29
+ /** The trader as the mails and the withdrawal information name it: legal name, address, e-mail. */
30
+ export const traderIdentityOf = (trader) => [trader.legalName, trader.address, trader.email].filter(part => part != null && part.trim() !== '').join(', ');
31
+ /** The declared trader; an undeclared one falls back to the service name (no mechanism is on then). */
32
+ export const traderOf = (ctx, mail) => mail?.trader ?? { name: ctx.cfg.service, legalName: ctx.cfg.service };
33
+ /** A plan's title in a language: its localization, else its catalogue title, else its sku. */
34
+ export const planTitleOf = async (ctx, planSku, lng) => {
35
+ if (planSku == null) {
36
+ return '';
37
+ }
38
+ const plan = await findPlan(ctx, planSku);
39
+ const localized = plan != null ? await payment(ctx).localize(lng, plan).catch(() => null) : null;
40
+ return localized?.title ?? plan?.title ?? planSku;
41
+ };
42
+ const productTitleOf = async (ctx, purchase, lng) => {
43
+ const plan = purchase.planSku != null ? await findPlan(ctx, purchase.planSku) : null;
44
+ const product = await findProduct(ctx, purchase.productSku);
45
+ const entity = plan ?? product;
46
+ const localized = entity != null ? await payment(ctx).localize(lng, entity).catch(() => null) : null;
47
+ return localized?.title ?? plan?.title ?? product?.title ?? purchase.productSku;
48
+ };
49
+ const renderPurchase = async (ctx, data) => {
50
+ const lng = data.language;
51
+ const purchase = data.purchase;
52
+ const blocks = [{
53
+ text: text(lng, 'email.purchase.body', {
54
+ contractRef: purchase.contractRef,
55
+ date: formatDateTime(new Date(purchase.purchasedAt), lng),
56
+ product: await productTitleOf(ctx, purchase, lng),
57
+ total: formatMoney(purchase.amountTotalMinor, purchase.currency, lng),
58
+ tax: formatMoney(purchase.amountTaxMinor, purchase.currency, lng),
59
+ }),
60
+ }];
61
+ if (data.consent != null) {
62
+ blocks.push({ text: text(lng, 'email.purchase.start-request', { statement: data.consent.text.checkbox }) });
63
+ }
64
+ const identity = traderIdentityOf(data.trader);
65
+ blocks.push({
66
+ text: text(lng, 'email.purchase.withdrawal-information', {
67
+ trader: identity,
68
+ withdrawalFunction: data.links.withdrawalFunction ?? data.links.withdrawalInformation ?? data.links.billingTerms,
69
+ }),
70
+ });
71
+ blocks.push({ text: text(lng, 'email.purchase.model-form', { trader: identity }) });
72
+ blocks.push(...linkBlocks(lng, data.links, [
73
+ 'billingTerms', 'withdrawalInformation', 'withdrawalForm', 'withdrawalFunction',
74
+ ...(purchase.kind === PurchaseKind.Subscription ? ['cancellation'] : []),
75
+ ]));
76
+ return { subject: text(lng, 'email.purchase.subject', { contractRef: purchase.contractRef }), blocks };
77
+ };
78
+ const renderConsent = (data) => {
79
+ const lng = data.language;
80
+ const consent = data.consent;
81
+ const lines = (data.purchases ?? []).map(purchase => text(lng, 'email.consent.purchase', {
82
+ contractRef: purchase.contractRef,
83
+ date: formatDate(new Date(purchase.purchasedAt), lng),
84
+ amount: formatMoney(purchase.amountTotalMinor, purchase.currency, lng),
85
+ deadline: purchase.deadline != null ? formatDeadline(new Date(purchase.deadline), lng) : '—',
86
+ }));
87
+ return {
88
+ subject: text(lng, 'email.consent.subject'),
89
+ blocks: [
90
+ {
91
+ text: text(lng, 'email.consent.body', {
92
+ date: formatDateTime(new Date(consent.decidedAt), lng), statement: consent.text.checkbox,
93
+ purchases: lines.join('\n'),
94
+ }),
95
+ },
96
+ { text: text(lng, 'email.consent.unused') },
97
+ ...linkBlocks(lng, data.links, ['billingTerms', 'withdrawalInformation', 'withdrawalFunction']),
98
+ ],
99
+ };
100
+ };
101
+ const renderStart = async (ctx, data) => {
102
+ const lng = data.language;
103
+ const consent = data.consent;
104
+ const title = consent.planName ?? await planTitleOf(ctx, consent.planSku, lng);
105
+ return {
106
+ subject: text(lng, 'email.start.subject', { plan: title }),
107
+ blocks: [
108
+ {
109
+ text: text(lng, 'email.start.body', {
110
+ date: formatDateTime(new Date(consent.decidedAt), lng), plan: title, statement: consent.text.checkbox,
111
+ }),
112
+ },
113
+ { text: text(lng, 'email.start.rule') },
114
+ ...linkBlocks(lng, data.links, ['billingTerms', 'withdrawalInformation', 'withdrawalFunction']),
115
+ ],
116
+ };
117
+ };
118
+ const renderWithdrawal = (data) => {
119
+ const lng = data.language;
120
+ const declaration = data.declaration;
121
+ const blocks = [{
122
+ text: text(lng, 'email.withdrawal.body', {
123
+ date: formatDateTime(new Date(declaration.receivedAt), lng), name: declaration.name,
124
+ contract: declaration.contractRef ?? data.purchase?.contractRef ?? '—', email: declaration.email,
125
+ }),
126
+ }];
127
+ const status = declaration.status;
128
+ // `received`: nothing is executed on this declaration (no match, or no statutory right) — the
129
+ // receipt says what happens if it does match, exactly as for an unknown contract.
130
+ if (!declaration.matched || declaration.duplicateOf != null || status === WithdrawalStatus.Received) {
131
+ blocks.push({ text: text(lng, 'email.withdrawal.unmatched') });
132
+ }
133
+ else if (status === WithdrawalStatus.Expired) {
134
+ const deadline = data.purchase?.deadline;
135
+ blocks.push({
136
+ text: text(lng, 'email.withdrawal.expired', {
137
+ deadline: deadline != null ? formatDeadline(new Date(deadline), lng) : '—',
138
+ }),
139
+ });
140
+ }
141
+ else if ((status === WithdrawalStatus.Processing || status === WithdrawalStatus.Refunded)
142
+ && declaration.refundMinor != null && declaration.currency != null) {
143
+ blocks.push({ text: text(lng, 'email.withdrawal.refund', { amount: formatMoney(declaration.refundMinor, declaration.currency, lng) }) });
144
+ }
145
+ else {
146
+ blocks.push({ text: text(lng, 'email.withdrawal.review') });
147
+ }
148
+ blocks.push(...linkBlocks(lng, data.links, ['billingTerms', 'withdrawalInformation']));
149
+ return { subject: text(lng, 'email.withdrawal.subject'), blocks };
150
+ };
151
+ const renderCancellation = (data) => {
152
+ const lng = data.language;
153
+ const declaration = data.declaration;
154
+ const requested = declaration.effective === 'date' && declaration.requestedDate != null
155
+ ? formatDate(new Date(`${declaration.requestedDate}T00:00:00Z`), lng)
156
+ : text(lng, 'cancellation.effective-earliest');
157
+ const blocks = [{
158
+ text: text(lng, 'email.cancellation.body', {
159
+ date: formatDateTime(new Date(declaration.receivedAt), lng), name: declaration.name,
160
+ contract: declaration.contractRef ?? declaration.subscriptionId ?? '—',
161
+ kind: text(lng, `cancellation.kind-${declaration.cancellationKind ?? 'ordinary'}`),
162
+ requested, email: declaration.email,
163
+ }),
164
+ }];
165
+ if (declaration.status === CancellationStatus.Review) {
166
+ blocks.push({ text: text(lng, 'email.cancellation.review') });
167
+ }
168
+ else if (declaration.matched && declaration.effectiveAt != null) {
169
+ blocks.push({ text: text(lng, 'email.cancellation.effective', { effectiveAt: formatDate(new Date(declaration.effectiveAt), lng) }) });
170
+ }
171
+ else {
172
+ blocks.push({ text: text(lng, 'email.cancellation.unmatched') });
173
+ }
174
+ blocks.push(...linkBlocks(lng, data.links, ['billingTerms']));
175
+ return { subject: text(lng, 'email.cancellation.subject'), blocks };
176
+ };
177
+ /**
178
+ * Everything a mail of `kind` about `recordId` is rendered from, read back from the records — the
179
+ * mail repeats exactly what was recorded, and a retry renders the same message. `null` when there
180
+ * is nobody to write to.
181
+ */
182
+ export const mailDataOf = async (ctx, policy, trader, kind, recordId) => {
183
+ const base = { kind, recordId, trader };
184
+ switch (kind) {
185
+ case 'purchase': {
186
+ const purchase = await purchases(ctx).byPurchaseId(recordId);
187
+ if (purchase?.email == null || purchase.email === '')
188
+ return null;
189
+ const consent = purchase.startRequestId != null
190
+ ? await consumerConsents(ctx).load(purchase.startRequestId).catch(() => null) : null;
191
+ return compact({
192
+ ...base, entityId: purchase.entityId, language: purchase.language, to: purchase.email,
193
+ name: purchase.name ?? undefined, links: linksOf(policy, purchase.language), purchase,
194
+ consent: consent ?? undefined,
195
+ });
196
+ }
197
+ case 'consent':
198
+ case 'start': {
199
+ const consent = await consumerConsents(ctx).load(recordId);
200
+ if (consent == null)
201
+ return null;
202
+ const to = consent.email ?? await contactEmailOf(ctx, consent.entityId);
203
+ if (to == null)
204
+ return null;
205
+ const covered = consent.purchaseIds.length > 0
206
+ ? (await purchases(ctx).list({ purchaseId: consent.purchaseIds }, { size: 0 })).items : [];
207
+ return compact({
208
+ ...base, entityId: consent.entityId, language: consent.language, to, name: consent.name ?? undefined,
209
+ links: consent.links, consent, purchases: covered,
210
+ });
211
+ }
212
+ default: {
213
+ const declaration = await consumerDeclarations(ctx).load(recordId);
214
+ if (declaration == null)
215
+ return null;
216
+ const purchase = declaration.purchaseId != null ? await purchases(ctx).byPurchaseId(declaration.purchaseId) : null;
217
+ return compact({
218
+ ...base, entityId: declaration.entityId ?? undefined, language: declaration.language, to: declaration.email,
219
+ name: declaration.name, links: linksOf(policy, declaration.language), declaration,
220
+ purchase: purchase ?? undefined,
221
+ });
222
+ }
223
+ }
224
+ };
225
+ const render = async (ctx, data, mail) => {
226
+ const lng = data.language;
227
+ const body = data.kind === 'purchase' ? await renderPurchase(ctx, data)
228
+ : data.kind === 'consent' ? renderConsent(data)
229
+ : data.kind === 'start' ? await renderStart(ctx, data)
230
+ : data.kind === 'withdrawal' ? renderWithdrawal(data)
231
+ : renderCancellation(data);
232
+ const blocks = [
233
+ { text: data.name != null && data.name !== '' ? text(lng, 'email.common.greeting-named', { name: data.name }) : text(lng, 'email.common.greeting') },
234
+ ...body.blocks,
235
+ { text: text(lng, 'email.common.trader', { trader: traderIdentityOf(data.trader) }) },
236
+ { text: text(lng, 'email.common.footer') },
237
+ ];
238
+ return compact({
239
+ to: data.to,
240
+ subject: body.subject,
241
+ text: textOf(blocks, lng),
242
+ html: htmlOf(blocks),
243
+ from: mail?.from,
244
+ replyTo: mail?.replyTo,
245
+ });
246
+ };
247
+ const mailerOf = (ctx, alias) => ctx.hasService?.(alias) === true
248
+ ? ctx.service(alias) : null;
249
+ /**
250
+ * Send one consumer-rights mail on a durable medium, in the language the consumer was shown, and
251
+ * record the outcome as a `mail` event (step = the mail kind): sent, skipped (a reserved domain
252
+ * such as `.test` / `.example` / `.invalid` / `.localhost`, or a renderer that suppressed it) or
253
+ * failed (a transport error, no mailer registered — retried by `reconcile`). The application's
254
+ * renderer (`useMailRenderer`) may replace the message. Each archive (`bcc`) address gets its own
255
+ * copy. Never throws.
256
+ *
257
+ * @returns whether the consumer's own copy was handed to the mailer
258
+ */
259
+ export const sendConsumerMail = async (ctx, policy, kind, recordId) => {
260
+ const recordKind = RECORD_KIND[kind];
261
+ let entityId;
262
+ try {
263
+ const mail = await consumerMailConfig(ctx);
264
+ const data = await mailDataOf(ctx, policy, traderOf(ctx, mail), kind, recordId);
265
+ entityId = data?.entityId;
266
+ if (data == null) {
267
+ await recordEvent(ctx, { recordId, recordKind, action: 'mail', step: kind, ok: true, skipped: true, detail: '{"reason":"no-recipient"}' });
268
+ return false;
269
+ }
270
+ if (isReservedAddress(data.to)) {
271
+ await recordEvent(ctx, {
272
+ recordId, recordKind, entityId, action: 'mail', step: kind, ok: true, skipped: true,
273
+ detail: JSON.stringify({ reason: 'reserved-domain', to: data.to }),
274
+ });
275
+ return false;
276
+ }
277
+ const rendered = await render(ctx, data, mail);
278
+ const renderer = consumerRightsOf(ctx)?.mailRenderer() ?? null;
279
+ const replaced = renderer != null ? await renderer(kind, data, rendered) : undefined;
280
+ if (replaced === null) {
281
+ await recordEvent(ctx, {
282
+ recordId, recordKind, entityId, action: 'mail', step: kind, ok: true, skipped: true, detail: '{"reason":"renderer"}',
283
+ });
284
+ return false;
285
+ }
286
+ const message = replaced ?? rendered;
287
+ const mailer = mailerOf(ctx, mail?.alias ?? MAILER_SERVICE);
288
+ if (mailer == null) {
289
+ await recordEvent(ctx, { recordId, recordKind, entityId, action: 'mail', step: kind, ok: false, error: 'mailer:absent' });
290
+ return false;
291
+ }
292
+ await mailer.send(message);
293
+ const archive = [];
294
+ for (const address of mail?.bcc ?? []) {
295
+ try {
296
+ await mailer.send({ ...message, to: address });
297
+ }
298
+ catch (error) {
299
+ archive.push(`${address}: ${errorText(error)}`);
300
+ }
301
+ }
302
+ await recordEvent(ctx, {
303
+ recordId, recordKind, entityId, action: 'mail', step: kind, ok: true,
304
+ detail: JSON.stringify(compact({ to: message.to, subject: message.subject, archiveFailures: archive.length > 0 ? archive : undefined })),
305
+ });
306
+ return true;
307
+ }
308
+ catch (error) {
309
+ console.error(`[payment] consumer mail "${kind}" of "${recordId}" failed`, error);
310
+ await recordEvent(ctx, { recordId, recordKind, entityId, action: 'mail', step: kind, ok: false, error: errorText(error) });
311
+ return false;
312
+ }
313
+ };
314
+ //# sourceMappingURL=mail.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mail.js","sourceRoot":"","sources":["../../src/consumer/mail.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAA;AAEjD,OAAO,EACL,kBAAkB,EAAE,YAAY,EAAE,OAAO,EAAE,YAAY,EAAE,gBAAgB,GAC1E,MAAM,mBAAmB,CAAA;AAG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KAAK,SAAS,CAAC,KAAK,CAAC,EAAE,CAAC,CAAA;YACjD,CAAC;QACH,CAAC;QACD,MAAM,WAAW,CAAC,GAAG,EAAE;YACrB,QAAQ,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,EAAE,EAAE,IAAI;YACpE,MAAM,EAAE,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,EAAE,EAAE,EAAE,OAAO,CAAC,EAAE,EAAE,OAAO,EAAE,OAAO,CAAC,OAAO,EAAE,eAAe,EAAE,OAAO,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,SAAS,EAAE,CAAC,CAAC;SACzI,CAAC,CAAA;QAEF,OAAO,IAAI,CAAA;IACb,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,CAAC,KAAK,CAAC,4BAA4B,IAAI,SAAS,QAAQ,UAAU,EAAE,KAAK,CAAC,CAAA;QACjF,MAAM,WAAW,CAAC,GAAG,EAAE,EAAE,QAAQ,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,SAAS,CAAC,KAAK,CAAC,EAAE,CAAC,CAAA;QAE1H,OAAO,KAAK,CAAA;IACd,CAAC;AACH,CAAC,CAAA"}
@@ -0,0 +1,14 @@
1
+ import type { AbstractRequest } from '@owlmeans/entrypoint';
2
+ import type { RequestOrigin } from '../types.js';
3
+ /**
4
+ * The evidence a consumer act is recorded with. `ip` is `cf-connecting-ip` (a Cloudflare edge
5
+ * sets it and strips a client's own), else the LAST `x-forwarded-for` entry (the one the nearest
6
+ * proxy appended — the first is whatever the client claimed), else `x-real-ip`, else the socket
7
+ * peer. The raw `x-forwarded-for`, the `user-agent` (at most 512 characters), `cf-ipcountry`
8
+ * (the geolocated country — second location evidence for VAT) and `accept-language` are kept as
9
+ * they arrived. The default `metaOf` of the consumer-rights handlers.
10
+ */
11
+ export declare const requestOriginOf: (req: AbstractRequest) => RequestOrigin;
12
+ /** The origin fields of a record: only those with a value. */
13
+ export declare const originFields: (origin: RequestOrigin | undefined) => RequestOrigin;
14
+ //# sourceMappingURL=origin.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"origin.d.ts","sourceRoot":"","sources":["../../src/consumer/origin.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAA;AAC3D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AA6BhD;;;;;;;GAOG;AACH,eAAO,MAAM,eAAe,QAAS,eAAe,KAAG,aAiBtD,CAAA;AAED,8DAA8D;AAC9D,eAAO,MAAM,YAAY,WAAY,aAAa,GAAG,SAAS,KAAG,aAI/C,CAAA"}
@@ -0,0 +1,47 @@
1
+ const USER_AGENT_MAX = 512;
2
+ const HEADER_MAX = 1024;
3
+ /** A header's first value (Fastify lower-cases names; a repeated header arrives as an array). */
4
+ const headerOf = (headers, name) => {
5
+ const raw = headers?.[name];
6
+ const value = Array.isArray(raw) ? raw[0] : raw;
7
+ if (typeof value !== 'string') {
8
+ return undefined;
9
+ }
10
+ const trimmed = value.trim();
11
+ return trimmed === '' ? undefined : trimmed;
12
+ };
13
+ /** The socket peer of the original server request, when the transport exposes one. */
14
+ const socketOf = (req) => {
15
+ const original = req.original;
16
+ const address = original?.socket?.remoteAddress ?? original?.raw?.socket?.remoteAddress ?? original?.ip;
17
+ return typeof address === 'string' && address !== '' ? address : undefined;
18
+ };
19
+ /**
20
+ * The evidence a consumer act is recorded with. `ip` is `cf-connecting-ip` (a Cloudflare edge
21
+ * sets it and strips a client's own), else the LAST `x-forwarded-for` entry (the one the nearest
22
+ * proxy appended — the first is whatever the client claimed), else `x-real-ip`, else the socket
23
+ * peer. The raw `x-forwarded-for`, the `user-agent` (at most 512 characters), `cf-ipcountry`
24
+ * (the geolocated country — second location evidence for VAT) and `accept-language` are kept as
25
+ * they arrived. The default `metaOf` of the consumer-rights handlers.
26
+ */
27
+ export const requestOriginOf = (req) => {
28
+ const headers = req.headers;
29
+ const forwardedFor = headerOf(headers, 'x-forwarded-for');
30
+ const forwarded = forwardedFor?.split(',').map(entry => entry.trim()).filter(entry => entry !== '');
31
+ const ip = headerOf(headers, 'cf-connecting-ip') ?? forwarded?.[forwarded.length - 1]
32
+ ?? headerOf(headers, 'x-real-ip') ?? socketOf(req);
33
+ const userAgent = headerOf(headers, 'user-agent');
34
+ const ipCountry = headerOf(headers, 'cf-ipcountry');
35
+ const acceptLanguage = headerOf(headers, 'accept-language');
36
+ return {
37
+ ...(ip != null ? { ip: ip.slice(0, HEADER_MAX) } : {}),
38
+ ...(forwardedFor != null ? { forwardedFor: forwardedFor.slice(0, HEADER_MAX) } : {}),
39
+ ...(userAgent != null ? { userAgent: userAgent.slice(0, USER_AGENT_MAX) } : {}),
40
+ ...(ipCountry != null && /^[A-Za-z]{2}$/.test(ipCountry) ? { ipCountry: ipCountry.toUpperCase() } : {}),
41
+ ...(acceptLanguage != null ? { acceptLanguage: acceptLanguage.slice(0, 256) } : {}),
42
+ };
43
+ };
44
+ /** The origin fields of a record: only those with a value. */
45
+ export const originFields = (origin) => Object.fromEntries(Object.entries(origin ?? {}).filter(([key, value]) => ['ip', 'forwardedFor', 'userAgent', 'ipCountry', 'acceptLanguage', 'via'].includes(key)
46
+ && typeof value === 'string' && value !== ''));
47
+ //# sourceMappingURL=origin.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"origin.js","sourceRoot":"","sources":["../../src/consumer/origin.ts"],"names":[],"mappings":"AAGA,MAAM,cAAc,GAAG,GAAG,CAAA;AAC1B,MAAM,UAAU,GAAG,IAAI,CAAA;AAIvB,iGAAiG;AACjG,MAAM,QAAQ,GAAG,CAAC,OAA4B,EAAE,IAAY,EAAsB,EAAE;IAClF,MAAM,GAAG,GAAG,OAAO,EAAE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MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,MAAiC,EAAiB,EAAE,CAAC,MAAM,CAAC,WAAW,CAClG,MAAM,CAAC,OAAO,CAAC,MAAM,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,EAAE,EAAE,CACnD,CAAC,IAAI,EAAE,cAAc,EAAE,WAAW,EAAE,WAAW,EAAE,gBAAgB,EAAE,KAAK,CAAC,CAAC,QAAQ,CAAC,GAAG,CAAC;OACpF,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,EAAE,CAAC,CAC/B,CAAA"}
@@ -0,0 +1,12 @@
1
+ import type { Context as ApiContext } from '@owlmeans/server-api';
2
+ import type { ConsumerRightsInternals } from './service.js';
3
+ import type { ConsumerReconcileOptions, ConsumerReconcileResult } from '../types.js';
4
+ /**
5
+ * The consumer-rights repair an application runs nightly: retry the paygate steps of withdrawals
6
+ * (refunds, credit notes, subscription cancels) and scheduled cancellations, failed mails and
7
+ * failed observers; backfill purchases of completed checkouts of the last 16 days that have no
8
+ * row; lock organizations that paid before countries were locked. The paygate steps, the
9
+ * backfill and the legacy locks need a managed service. Each step handles at most `limit` items.
10
+ */
11
+ export declare const reconcileConsumerRights: (ctx: ApiContext, internals: ConsumerRightsInternals, opts?: ConsumerReconcileOptions) => Promise<ConsumerReconcileResult>;
12
+ //# sourceMappingURL=reconcile.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"reconcile.d.ts","sourceRoot":"","sources":["../../src/consumer/reconcile.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,OAAO,IAAI,UAAU,EAAE,MAAM,sBAAsB,CAAA;AAcjE,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,cAAc,CAAA;AAE3D,OAAO,KAAK,EAC6B,wBAAwB,EAAE,uBAAuB,EACzF,MAAM,aAAa,CAAA;AA0QpB;;;;;;GAMG;AACH,eAAO,MAAM,uBAAuB,QAC7B,UAAU,aAAa,uBAAuB,SAAQ,wBAAwB,KAClF,OAAO,CAAC,uBAAuB,CA8BjC,CAAA"}