@shware/purchase 1.8.9 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (128) hide show
  1. package/dist/_virtual/_rolldown/runtime.cjs +23 -0
  2. package/dist/app-store/config.cjs +105 -128
  3. package/dist/app-store/config.cjs.map +1 -1
  4. package/dist/app-store/config.d.cts +36 -33
  5. package/dist/app-store/config.d.cts.map +1 -0
  6. package/dist/app-store/config.d.mts +42 -0
  7. package/dist/app-store/config.d.mts.map +1 -0
  8. package/dist/app-store/config.mjs +100 -91
  9. package/dist/app-store/config.mjs.map +1 -1
  10. package/dist/app-store/index.cjs +3 -31
  11. package/dist/app-store/index.d.cts +2 -3
  12. package/dist/app-store/index.d.mts +2 -0
  13. package/dist/app-store/index.mjs +1 -5
  14. package/dist/google-play/config.cjs +108 -123
  15. package/dist/google-play/config.cjs.map +1 -1
  16. package/dist/google-play/config.d.cts +35 -33
  17. package/dist/google-play/config.d.cts.map +1 -0
  18. package/dist/google-play/config.d.mts +41 -0
  19. package/dist/google-play/config.d.mts.map +1 -0
  20. package/dist/google-play/config.mjs +103 -86
  21. package/dist/google-play/config.mjs.map +1 -1
  22. package/dist/google-play/index.cjs +9 -42
  23. package/dist/google-play/index.d.cts +3 -4
  24. package/dist/google-play/index.d.mts +3 -0
  25. package/dist/google-play/index.mjs +2 -17
  26. package/dist/google-play/real-time-developer-notification.cjs +122 -81
  27. package/dist/google-play/real-time-developer-notification.cjs.map +1 -1
  28. package/dist/google-play/real-time-developer-notification.d.cts +119 -117
  29. package/dist/google-play/real-time-developer-notification.d.cts.map +1 -0
  30. package/dist/google-play/real-time-developer-notification.d.mts +150 -0
  31. package/dist/google-play/real-time-developer-notification.d.mts.map +1 -0
  32. package/dist/google-play/real-time-developer-notification.mjs +118 -53
  33. package/dist/google-play/real-time-developer-notification.mjs.map +1 -1
  34. package/dist/index.cjs +13 -48
  35. package/dist/index.d.cts +5 -6
  36. package/dist/index.d.mts +5 -0
  37. package/dist/index.mjs +2 -19
  38. package/dist/stripe/config.cjs +114 -133
  39. package/dist/stripe/config.cjs.map +1 -1
  40. package/dist/stripe/config.d.cts +46 -37
  41. package/dist/stripe/config.d.cts.map +1 -0
  42. package/dist/stripe/config.d.mts +52 -0
  43. package/dist/stripe/config.d.mts.map +1 -0
  44. package/dist/stripe/config.mjs +109 -96
  45. package/dist/stripe/config.mjs.map +1 -1
  46. package/dist/stripe/handler.cjs +25 -53
  47. package/dist/stripe/handler.cjs.map +1 -1
  48. package/dist/stripe/handler.d.cts +10 -9
  49. package/dist/stripe/handler.d.cts.map +1 -0
  50. package/dist/stripe/handler.d.mts +16 -0
  51. package/dist/stripe/handler.d.mts.map +1 -0
  52. package/dist/stripe/handler.mjs +25 -29
  53. package/dist/stripe/handler.mjs.map +1 -1
  54. package/dist/stripe/index.cjs +27 -74
  55. package/dist/stripe/index.d.cts +8 -12
  56. package/dist/stripe/index.d.mts +8 -0
  57. package/dist/stripe/index.mjs +5 -44
  58. package/dist/stripe/mapper.cjs +168 -219
  59. package/dist/stripe/mapper.cjs.map +1 -1
  60. package/dist/stripe/mapper.d.cts +115 -114
  61. package/dist/stripe/mapper.d.cts.map +1 -0
  62. package/dist/stripe/mapper.d.mts +158 -0
  63. package/dist/stripe/mapper.d.mts.map +1 -0
  64. package/dist/stripe/mapper.mjs +155 -182
  65. package/dist/stripe/mapper.mjs.map +1 -1
  66. package/dist/stripe/metadata.cjs +11 -35
  67. package/dist/stripe/metadata.cjs.map +1 -1
  68. package/dist/stripe/metadata.d.cts +9 -7
  69. package/dist/stripe/metadata.d.cts.map +1 -0
  70. package/dist/stripe/metadata.d.mts +12 -0
  71. package/dist/stripe/metadata.d.mts.map +1 -0
  72. package/dist/stripe/metadata.mjs +11 -11
  73. package/dist/stripe/metadata.mjs.map +1 -1
  74. package/dist/stripe/pending-checkout.cjs +55 -61
  75. package/dist/stripe/pending-checkout.cjs.map +1 -1
  76. package/dist/stripe/pending-checkout.d.cts +3 -1
  77. package/dist/stripe/pending-checkout.d.cts.map +1 -0
  78. package/dist/stripe/{pending-checkout.d.ts → pending-checkout.d.mts} +3 -1
  79. package/dist/stripe/pending-checkout.d.mts.map +1 -0
  80. package/dist/stripe/pending-checkout.mjs +52 -34
  81. package/dist/stripe/pending-checkout.mjs.map +1 -1
  82. package/dist/stripe/schema.cjs +30 -55
  83. package/dist/stripe/schema.cjs.map +1 -1
  84. package/dist/stripe/schema.d.cts +36 -37
  85. package/dist/stripe/schema.d.cts.map +1 -0
  86. package/dist/stripe/schema.d.mts +40 -0
  87. package/dist/stripe/schema.d.mts.map +1 -0
  88. package/dist/stripe/schema.mjs +28 -40
  89. package/dist/stripe/schema.mjs.map +1 -1
  90. package/dist/subscription/index.cjs +178 -80
  91. package/dist/subscription/index.cjs.map +1 -1
  92. package/dist/subscription/index.d.cts +136 -134
  93. package/dist/subscription/index.d.cts.map +1 -0
  94. package/dist/subscription/index.d.mts +150 -0
  95. package/dist/subscription/index.d.mts.map +1 -0
  96. package/dist/subscription/index.mjs +173 -51
  97. package/dist/subscription/index.mjs.map +1 -1
  98. package/dist/types.cjs +0 -19
  99. package/dist/types.d.cts +7 -6
  100. package/dist/types.d.cts.map +1 -0
  101. package/dist/types.d.mts +10 -0
  102. package/dist/types.d.mts.map +1 -0
  103. package/dist/types.mjs +1 -1
  104. package/package.json +40 -25
  105. package/dist/app-store/config.d.ts +0 -39
  106. package/dist/app-store/index.cjs.map +0 -1
  107. package/dist/app-store/index.d.ts +0 -3
  108. package/dist/app-store/index.mjs.map +0 -1
  109. package/dist/google-play/config.d.ts +0 -39
  110. package/dist/google-play/index.cjs.map +0 -1
  111. package/dist/google-play/index.d.ts +0 -4
  112. package/dist/google-play/index.mjs.map +0 -1
  113. package/dist/google-play/real-time-developer-notification.d.ts +0 -148
  114. package/dist/index.cjs.map +0 -1
  115. package/dist/index.d.ts +0 -6
  116. package/dist/index.mjs.map +0 -1
  117. package/dist/stripe/config.d.ts +0 -43
  118. package/dist/stripe/handler.d.ts +0 -15
  119. package/dist/stripe/index.cjs.map +0 -1
  120. package/dist/stripe/index.d.ts +0 -12
  121. package/dist/stripe/index.mjs.map +0 -1
  122. package/dist/stripe/mapper.d.ts +0 -157
  123. package/dist/stripe/metadata.d.ts +0 -10
  124. package/dist/stripe/schema.d.ts +0 -41
  125. package/dist/subscription/index.d.ts +0 -148
  126. package/dist/types.cjs.map +0 -1
  127. package/dist/types.d.ts +0 -9
  128. package/dist/types.mjs.map +0 -1
@@ -1,46 +1,7 @@
1
- // src/stripe/index.ts
2
- import {
3
- mapTime,
4
- mapPrice,
5
- mapCharge,
6
- mapInvoice,
7
- mapLineItem,
8
- mapPaymentIntent,
9
- mapCheckoutSession,
10
- mapSubscriptionStatus,
11
- minorUnits,
12
- price,
13
- getPurchaseProperties,
14
- getBeginCheckoutProperties
15
- } from "./mapper.mjs";
1
+ import { StripeConfig } from "./config.mjs";
16
2
  import { StripeEventHandler } from "./handler.mjs";
17
- import {
18
- cancellationDetailsSchema,
19
- createCheckoutSessionSchema
20
- } from "./schema.mjs";
3
+ import { getBeginCheckoutProperties, getPurchaseProperties, mapCharge, mapCheckoutSession, mapInvoice, mapLineItem, mapPaymentIntent, mapPrice, mapSubscriptionStatus, mapTime, minorUnits, price } from "./mapper.mjs";
4
+ import { cancellationDetailsSchema, createCheckoutSessionSchema } from "./schema.mjs";
21
5
  import { METADATA_KEYS } from "./metadata.mjs";
22
- import { StripeConfig } from "./config.mjs";
23
- import { addPendingCheckout, removePendingCheckout, getPendingCheckouts } from "./pending-checkout.mjs";
24
- export {
25
- METADATA_KEYS,
26
- StripeConfig,
27
- StripeEventHandler,
28
- addPendingCheckout,
29
- cancellationDetailsSchema,
30
- createCheckoutSessionSchema,
31
- getBeginCheckoutProperties,
32
- getPendingCheckouts,
33
- getPurchaseProperties,
34
- mapCharge,
35
- mapCheckoutSession,
36
- mapInvoice,
37
- mapLineItem,
38
- mapPaymentIntent,
39
- mapPrice,
40
- mapSubscriptionStatus,
41
- mapTime,
42
- minorUnits,
43
- price,
44
- removePendingCheckout
45
- };
46
- //# sourceMappingURL=index.mjs.map
6
+ import { addPendingCheckout, getPendingCheckouts, removePendingCheckout } from "./pending-checkout.mjs";
7
+ export { METADATA_KEYS, StripeConfig, StripeEventHandler, addPendingCheckout, cancellationDetailsSchema, createCheckoutSessionSchema, getBeginCheckoutProperties, getPendingCheckouts, getPurchaseProperties, mapCharge, mapCheckoutSession, mapInvoice, mapLineItem, mapPaymentIntent, mapPrice, mapSubscriptionStatus, mapTime, minorUnits, price, removePendingCheckout };
@@ -1,244 +1,193 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
-
20
- // src/stripe/mapper.ts
21
- var mapper_exports = {};
22
- __export(mapper_exports, {
23
- ZERO_DECIMAL_CURRENCIES: () => ZERO_DECIMAL_CURRENCIES,
24
- getBeginCheckoutProperties: () => getBeginCheckoutProperties,
25
- getPurchaseProperties: () => getPurchaseProperties,
26
- mapCharge: () => mapCharge,
27
- mapCheckoutSession: () => mapCheckoutSession,
28
- mapInvoice: () => mapInvoice,
29
- mapLineItem: () => mapLineItem,
30
- mapPaymentIntent: () => mapPaymentIntent,
31
- mapPrice: () => mapPrice,
32
- mapSubscriptionStatus: () => mapSubscriptionStatus,
33
- mapTime: () => mapTime,
34
- minorUnits: () => minorUnits,
35
- price: () => price
36
- });
37
- module.exports = __toCommonJS(mapper_exports);
38
- var import_subscription = require("../subscription/index.cjs");
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ require("../subscription/index.cjs");
3
+ //#region src/stripe/mapper.ts
39
4
  function mapTime(stripeTimestampSeconds) {
40
- if (!stripeTimestampSeconds) return null;
41
- return new Date(stripeTimestampSeconds * 1e3).toISOString();
5
+ if (!stripeTimestampSeconds) return null;
6
+ return (/* @__PURE__ */ new Date(stripeTimestampSeconds * 1e3)).toISOString();
42
7
  }
43
- function mapPrice(price2) {
44
- return {
45
- id: price2.id,
46
- type: price2.type,
47
- active: price2.active,
48
- billing_scheme: price2.billing_scheme,
49
- currency: price2.currency,
50
- unit_amount: price2.unit_amount,
51
- unit_amount_decimal: price2.unit_amount_decimal?.toString() ?? null,
52
- recurring: price2.recurring
53
- };
8
+ function mapPrice(price) {
9
+ return {
10
+ id: price.id,
11
+ type: price.type,
12
+ active: price.active,
13
+ billing_scheme: price.billing_scheme,
14
+ currency: price.currency,
15
+ unit_amount: price.unit_amount,
16
+ unit_amount_decimal: price.unit_amount_decimal?.toString() ?? null,
17
+ recurring: price.recurring
18
+ };
54
19
  }
55
20
  function mapLineItem(item) {
56
- return {
57
- id: item.price ? typeof item.price.product === "string" ? item.price.product : item.price.product.id : item.id,
58
- currency: item.currency,
59
- quantity: item.quantity,
60
- description: item.description,
61
- amount_tax: item.amount_tax,
62
- amount_total: item.amount_total,
63
- amount_subtotal: item.amount_subtotal,
64
- amount_discount: item.amount_discount,
65
- price: item.price ? mapPrice(item.price) : null
66
- };
21
+ return {
22
+ id: item.price ? typeof item.price.product === "string" ? item.price.product : item.price.product.id : item.id,
23
+ currency: item.currency,
24
+ quantity: item.quantity,
25
+ description: item.description,
26
+ amount_tax: item.amount_tax,
27
+ amount_total: item.amount_total,
28
+ amount_subtotal: item.amount_subtotal,
29
+ amount_discount: item.amount_discount,
30
+ price: item.price ? mapPrice(item.price) : null
31
+ };
67
32
  }
68
33
  function mapCheckoutSession(session) {
69
- let coupon = void 0;
70
- if (Array.isArray(session.discounts) && session.discounts.length !== 0) {
71
- const discount = session.discounts[0];
72
- if (discount.coupon && typeof discount.coupon === "object") {
73
- coupon = discount.coupon.id;
74
- } else if (typeof discount.coupon === "string") {
75
- coupon = discount.coupon;
76
- } else {
77
- coupon = void 0;
78
- }
79
- }
80
- const payment_status = session.payment_status;
81
- return {
82
- id: session.id,
83
- url: session.url,
84
- coupon,
85
- livemode: session.livemode,
86
- expires_at: session.expires_at,
87
- payment_status,
88
- currency: session.currency,
89
- amount_total: session.amount_total,
90
- line_items: session.line_items?.data.map(mapLineItem)
91
- };
34
+ let coupon = void 0;
35
+ if (Array.isArray(session.discounts) && session.discounts.length !== 0) {
36
+ const discount = session.discounts[0];
37
+ if (discount.coupon && typeof discount.coupon === "object") coupon = discount.coupon.id;
38
+ else if (typeof discount.coupon === "string") coupon = discount.coupon;
39
+ else coupon = void 0;
40
+ }
41
+ const payment_status = session.payment_status;
42
+ return {
43
+ id: session.id,
44
+ url: session.url,
45
+ coupon,
46
+ livemode: session.livemode,
47
+ expires_at: session.expires_at,
48
+ payment_status,
49
+ currency: session.currency,
50
+ amount_total: session.amount_total,
51
+ line_items: session.line_items?.data.map(mapLineItem)
52
+ };
92
53
  }
93
54
  function mapInvoice(i) {
94
- return {
95
- id: i.id,
96
- number: i.number,
97
- total: i.total,
98
- subtotal: i.subtotal,
99
- amount_due: i.amount_due,
100
- amount_paid: i.amount_paid,
101
- amount_remaining: i.amount_remaining,
102
- currency: i.currency,
103
- billing_reason: i.billing_reason,
104
- hosted_invoice_url: i.hosted_invoice_url,
105
- invoice_pdf: i.invoice_pdf,
106
- receipt_number: i.receipt_number,
107
- status: i.status,
108
- created: i.created,
109
- period_start: i.period_start,
110
- period_end: i.period_end
111
- };
55
+ return {
56
+ id: i.id,
57
+ number: i.number,
58
+ total: i.total,
59
+ subtotal: i.subtotal,
60
+ amount_due: i.amount_due,
61
+ amount_paid: i.amount_paid,
62
+ amount_remaining: i.amount_remaining,
63
+ currency: i.currency,
64
+ billing_reason: i.billing_reason,
65
+ hosted_invoice_url: i.hosted_invoice_url,
66
+ invoice_pdf: i.invoice_pdf,
67
+ receipt_number: i.receipt_number,
68
+ status: i.status,
69
+ created: i.created,
70
+ period_start: i.period_start,
71
+ period_end: i.period_end
72
+ };
112
73
  }
113
74
  function mapPaymentIntent(intent) {
114
- return {
115
- id: intent.id,
116
- amount: intent.amount,
117
- amount_capturable: intent.amount_capturable,
118
- amount_received: intent.amount_received,
119
- currency: intent.currency,
120
- client_secret: intent.client_secret,
121
- description: intent.description,
122
- status: intent.status,
123
- created: intent.created
124
- };
75
+ return {
76
+ id: intent.id,
77
+ amount: intent.amount,
78
+ amount_capturable: intent.amount_capturable,
79
+ amount_received: intent.amount_received,
80
+ currency: intent.currency,
81
+ client_secret: intent.client_secret,
82
+ description: intent.description,
83
+ status: intent.status,
84
+ created: intent.created
85
+ };
125
86
  }
126
87
  function mapCharge(charge) {
127
- return {
128
- id: charge.id,
129
- description: charge.description,
130
- currency: charge.currency,
131
- amount: charge.amount,
132
- amount_captured: charge.amount_captured,
133
- amount_refunded: charge.amount_refunded,
134
- receipt_email: charge.receipt_email,
135
- receipt_number: charge.receipt_number,
136
- receipt_url: charge.receipt_url,
137
- status: charge.status,
138
- created: charge.created,
139
- payment_intent: charge.payment_intent && typeof charge.payment_intent === "object" ? mapPaymentIntent(charge.payment_intent) : void 0
140
- };
88
+ return {
89
+ id: charge.id,
90
+ description: charge.description,
91
+ currency: charge.currency,
92
+ amount: charge.amount,
93
+ amount_captured: charge.amount_captured,
94
+ amount_refunded: charge.amount_refunded,
95
+ receipt_email: charge.receipt_email,
96
+ receipt_number: charge.receipt_number,
97
+ receipt_url: charge.receipt_url,
98
+ status: charge.status,
99
+ created: charge.created,
100
+ payment_intent: charge.payment_intent && typeof charge.payment_intent === "object" ? mapPaymentIntent(charge.payment_intent) : void 0
101
+ };
141
102
  }
142
103
  function mapSubscriptionStatus(status) {
143
- switch (status) {
144
- case "active":
145
- return import_subscription.SubscriptionStatus.ACTIVE;
146
- case "canceled":
147
- return import_subscription.SubscriptionStatus.CANCELED;
148
- case "incomplete":
149
- return import_subscription.SubscriptionStatus.INCOMPLETE;
150
- case "incomplete_expired":
151
- return import_subscription.SubscriptionStatus.INCOMPLETE_EXPIRED;
152
- case "past_due":
153
- return import_subscription.SubscriptionStatus.PAST_DUE;
154
- case "paused":
155
- return import_subscription.SubscriptionStatus.PAUSED;
156
- case "trialing":
157
- return import_subscription.SubscriptionStatus.TRIALING;
158
- case "unpaid":
159
- return import_subscription.SubscriptionStatus.UNPAID;
160
- default: {
161
- console.error(`Invalid stripe status: ${String(status)}`);
162
- throw new Error(`Invalid stripe status: ${String(status)}`);
163
- }
164
- }
104
+ switch (status) {
105
+ case "active": return "ACTIVE";
106
+ case "canceled": return "CANCELED";
107
+ case "incomplete": return "INCOMPLETE";
108
+ case "incomplete_expired": return "INCOMPLETE_EXPIRED";
109
+ case "past_due": return "PAST_DUE";
110
+ case "paused": return "PAUSED";
111
+ case "trialing": return "TRIALING";
112
+ case "unpaid": return "UNPAID";
113
+ default:
114
+ console.error(`Invalid stripe status: ${String(status)}`);
115
+ throw new Error(`Invalid stripe status: ${String(status)}`);
116
+ }
165
117
  }
166
- var ZERO_DECIMAL_CURRENCIES = [
167
- "BIF",
168
- "CLP",
169
- "DJF",
170
- "GNF",
171
- "JPY",
172
- "KMF",
173
- "KRW",
174
- "MGA",
175
- "PYG",
176
- "RWF",
177
- "UGX",
178
- "VND",
179
- "VUV",
180
- "XAF",
181
- "XOF",
182
- "XPF"
118
+ const ZERO_DECIMAL_CURRENCIES = [
119
+ "BIF",
120
+ "CLP",
121
+ "DJF",
122
+ "GNF",
123
+ "JPY",
124
+ "KMF",
125
+ "KRW",
126
+ "MGA",
127
+ "PYG",
128
+ "RWF",
129
+ "UGX",
130
+ "VND",
131
+ "VUV",
132
+ "XAF",
133
+ "XOF",
134
+ "XPF"
183
135
  ];
184
136
  function minorUnits(currency) {
185
- return ZERO_DECIMAL_CURRENCIES.includes(currency.toUpperCase()) ? 1 : 100;
137
+ return ZERO_DECIMAL_CURRENCIES.includes(currency.toUpperCase()) ? 1 : 100;
186
138
  }
187
139
  function price(value, currency) {
188
- return value / minorUnits(currency);
140
+ return value / minorUnits(currency);
189
141
  }
190
142
  function getPurchaseProperties(session) {
191
- let value;
192
- let currency;
193
- if (!session.amount_total || !session.currency) {
194
- value = session.line_items?.reduce((acc, item) => acc + (item.amount_total ?? 0), 0) ?? 0;
195
- currency = session.line_items?.[0]?.currency ?? "usd";
196
- } else {
197
- value = session.amount_total;
198
- currency = session.currency;
199
- }
200
- return {
201
- transaction_id: session.id,
202
- value: price(value, currency),
203
- currency: currency.toUpperCase(),
204
- coupon: session.coupon,
205
- items: session.line_items?.map((item, index) => ({
206
- index,
207
- item_id: item.id,
208
- item_name: item.description ?? "",
209
- price: price(item.amount_total, item.currency),
210
- quantity: item.quantity ?? 1,
211
- discount: price(item.amount_discount, item.currency)
212
- }))
213
- };
143
+ let value;
144
+ let currency;
145
+ if (!session.amount_total || !session.currency) {
146
+ value = session.line_items?.reduce((acc, item) => acc + (item.amount_total ?? 0), 0) ?? 0;
147
+ currency = session.line_items?.[0]?.currency ?? "usd";
148
+ } else {
149
+ value = session.amount_total;
150
+ currency = session.currency;
151
+ }
152
+ return {
153
+ transaction_id: session.id,
154
+ value: price(value, currency),
155
+ currency: currency.toUpperCase(),
156
+ coupon: session.coupon,
157
+ items: session.line_items?.map((item, index) => ({
158
+ index,
159
+ item_id: item.id,
160
+ item_name: item.description ?? "",
161
+ price: price(item.amount_total, item.currency),
162
+ quantity: item.quantity ?? 1,
163
+ discount: price(item.amount_discount, item.currency)
164
+ }))
165
+ };
214
166
  }
215
167
  function getBeginCheckoutProperties(p) {
216
- return {
217
- currency: p.currency.toUpperCase(),
218
- value: price(p.unit_amount, p.currency),
219
- items: [
220
- {
221
- item_id: p.product.id,
222
- item_name: p.product.name,
223
- price: price(p.unit_amount, p.currency)
224
- }
225
- ]
226
- };
168
+ return {
169
+ currency: p.currency.toUpperCase(),
170
+ value: price(p.unit_amount, p.currency),
171
+ items: [{
172
+ item_id: p.product.id,
173
+ item_name: p.product.name,
174
+ price: price(p.unit_amount, p.currency)
175
+ }]
176
+ };
227
177
  }
228
- // Annotate the CommonJS export names for ESM import in node:
229
- 0 && (module.exports = {
230
- ZERO_DECIMAL_CURRENCIES,
231
- getBeginCheckoutProperties,
232
- getPurchaseProperties,
233
- mapCharge,
234
- mapCheckoutSession,
235
- mapInvoice,
236
- mapLineItem,
237
- mapPaymentIntent,
238
- mapPrice,
239
- mapSubscriptionStatus,
240
- mapTime,
241
- minorUnits,
242
- price
243
- });
178
+ //#endregion
179
+ exports.ZERO_DECIMAL_CURRENCIES = ZERO_DECIMAL_CURRENCIES;
180
+ exports.getBeginCheckoutProperties = getBeginCheckoutProperties;
181
+ exports.getPurchaseProperties = getPurchaseProperties;
182
+ exports.mapCharge = mapCharge;
183
+ exports.mapCheckoutSession = mapCheckoutSession;
184
+ exports.mapInvoice = mapInvoice;
185
+ exports.mapLineItem = mapLineItem;
186
+ exports.mapPaymentIntent = mapPaymentIntent;
187
+ exports.mapPrice = mapPrice;
188
+ exports.mapSubscriptionStatus = mapSubscriptionStatus;
189
+ exports.mapTime = mapTime;
190
+ exports.minorUnits = minorUnits;
191
+ exports.price = price;
192
+
244
193
  //# sourceMappingURL=mapper.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/stripe/mapper.ts"],"sourcesContent":["import { type Stripe } from 'stripe';\nimport { SubscriptionStatus } from '../subscription/index';\n\nexport function mapTime<T extends number | null>(\n stripeTimestampSeconds: T\n): T extends number ? string : null {\n if (!stripeTimestampSeconds) return null as T extends number ? string : null;\n return new Date(stripeTimestampSeconds * 1000).toISOString() as T extends number ? string : null;\n}\n\nexport type Price = {\n id: string;\n type: Stripe.Price.Type;\n active: boolean;\n billing_scheme: Stripe.Price.BillingScheme;\n currency: Stripe.Price['currency'];\n unit_amount: number | null;\n unit_amount_decimal: string | null;\n recurring: Stripe.Price.Recurring | null;\n};\n\nexport function mapPrice(price: Stripe.Price): Price {\n return {\n id: price.id,\n type: price.type,\n active: price.active,\n billing_scheme: price.billing_scheme,\n currency: price.currency,\n unit_amount: price.unit_amount,\n unit_amount_decimal: price.unit_amount_decimal?.toString() ?? null,\n recurring: price.recurring,\n };\n}\n\nexport function mapLineItem(item: Stripe.LineItem) {\n return {\n id: item.price\n ? typeof item.price.product === 'string'\n ? item.price.product\n : item.price.product.id\n : item.id,\n currency: item.currency,\n quantity: item.quantity,\n description: item.description,\n amount_tax: item.amount_tax,\n amount_total: item.amount_total,\n amount_subtotal: item.amount_subtotal,\n amount_discount: item.amount_discount,\n price: item.price ? mapPrice(item.price) : null,\n };\n}\n\nexport type PaymentStatus = 'no_payment_required' | 'paid' | 'unpaid';\n\nexport function mapCheckoutSession(session: Stripe.Checkout.Session) {\n let coupon: string | undefined = undefined;\n if (Array.isArray(session.discounts) && session.discounts.length !== 0) {\n const discount = session.discounts[0];\n if (discount.coupon && typeof discount.coupon === 'object') {\n coupon = discount.coupon.id;\n } else if (typeof discount.coupon === 'string') {\n coupon = discount.coupon;\n } else {\n coupon = undefined;\n }\n }\n\n // The variable annotation makes the emitted .d.ts reference the local\n // PaymentStatus alias instead of stripe's internal module path (TS2883)\n const payment_status: PaymentStatus = session.payment_status;\n\n return {\n id: session.id,\n url: session.url,\n coupon,\n livemode: session.livemode,\n expires_at: session.expires_at,\n payment_status,\n currency: session.currency,\n amount_total: session.amount_total,\n line_items: session.line_items?.data.map(mapLineItem),\n };\n}\n\nexport function mapInvoice(i: Stripe.Invoice) {\n return {\n id: i.id,\n number: i.number,\n total: i.total,\n subtotal: i.subtotal,\n amount_due: i.amount_due,\n amount_paid: i.amount_paid,\n amount_remaining: i.amount_remaining,\n currency: i.currency,\n billing_reason: i.billing_reason,\n hosted_invoice_url: i.hosted_invoice_url,\n invoice_pdf: i.invoice_pdf,\n receipt_number: i.receipt_number,\n status: i.status,\n created: i.created,\n period_start: i.period_start,\n period_end: i.period_end,\n };\n}\n\nexport function mapPaymentIntent(intent: Stripe.PaymentIntent) {\n return {\n id: intent.id,\n amount: intent.amount,\n amount_capturable: intent.amount_capturable,\n amount_received: intent.amount_received,\n currency: intent.currency,\n client_secret: intent.client_secret,\n description: intent.description,\n status: intent.status,\n created: intent.created,\n };\n}\n\nexport function mapCharge(charge: Stripe.Charge) {\n return {\n id: charge.id,\n description: charge.description,\n currency: charge.currency,\n amount: charge.amount,\n amount_captured: charge.amount_captured,\n amount_refunded: charge.amount_refunded,\n receipt_email: charge.receipt_email,\n receipt_number: charge.receipt_number,\n receipt_url: charge.receipt_url,\n status: charge.status,\n created: charge.created,\n payment_intent:\n charge.payment_intent && typeof charge.payment_intent === 'object'\n ? mapPaymentIntent(charge.payment_intent)\n : undefined,\n };\n}\n\nexport type CheckoutSession = ReturnType<typeof mapCheckoutSession>;\nexport type ProductPrice = {\n id: string;\n type: Stripe.Price.Type;\n unit_amount: number;\n currency: Stripe.Price['currency'];\n product: {\n id: Stripe.Product['id'];\n name: Stripe.Product['name'];\n description: Stripe.Product['description'];\n livemode: Stripe.Product['livemode'];\n };\n};\n\nexport function mapSubscriptionStatus(status: Stripe.Subscription.Status): SubscriptionStatus {\n switch (status) {\n case 'active':\n return SubscriptionStatus.ACTIVE;\n case 'canceled':\n return SubscriptionStatus.CANCELED;\n case 'incomplete':\n return SubscriptionStatus.INCOMPLETE;\n case 'incomplete_expired':\n return SubscriptionStatus.INCOMPLETE_EXPIRED;\n case 'past_due':\n return SubscriptionStatus.PAST_DUE;\n case 'paused':\n return SubscriptionStatus.PAUSED;\n case 'trialing':\n return SubscriptionStatus.TRIALING;\n case 'unpaid':\n return SubscriptionStatus.UNPAID;\n default: {\n console.error(`Invalid stripe status: ${String(status)}`);\n throw new Error(`Invalid stripe status: ${String(status)}`);\n }\n }\n}\n\nexport const ZERO_DECIMAL_CURRENCIES = [\n 'BIF',\n 'CLP',\n 'DJF',\n 'GNF',\n 'JPY',\n 'KMF',\n 'KRW',\n 'MGA',\n 'PYG',\n 'RWF',\n 'UGX',\n 'VND',\n 'VUV',\n 'XAF',\n 'XOF',\n 'XPF',\n];\n\nexport function minorUnits(currency: string) {\n return ZERO_DECIMAL_CURRENCIES.includes(currency.toUpperCase()) ? 1 : 100;\n}\n\nexport function price(value: number, currency: string) {\n return value / minorUnits(currency);\n}\n\nexport interface Item {\n item_id: string;\n item_name: string;\n affiliation?: 'Google Store' | (string & {});\n coupon?: string;\n discount?: number;\n index?: number;\n item_brand?: string;\n item_category?: string;\n item_category2?: string;\n item_category3?: string;\n item_category4?: string;\n item_category5?: string;\n item_list_id?: string;\n item_list_name?: string;\n item_variant?: string;\n location_id?: string;\n price?: number;\n quantity?: number;\n}\n\nexport interface PurchaseProperties {\n currency: string;\n value: number;\n transaction_id: string;\n coupon?: string;\n shipping?: number;\n tax?: number;\n items?: Item[];\n}\n\nexport interface BeginCheckoutProperties {\n currency: string;\n value: number;\n coupon?: string;\n items: Item[];\n}\n\nexport function getPurchaseProperties(session: CheckoutSession): PurchaseProperties {\n let value: number;\n let currency: string;\n if (!session.amount_total || !session.currency) {\n value = session.line_items?.reduce((acc, item) => acc + (item.amount_total ?? 0), 0) ?? 0;\n currency = session.line_items?.[0]?.currency ?? 'usd';\n } else {\n value = session.amount_total;\n currency = session.currency;\n }\n\n return {\n transaction_id: session.id,\n value: price(value, currency),\n currency: currency.toUpperCase(),\n coupon: session.coupon,\n items: session.line_items?.map((item, index) => ({\n index,\n item_id: item.id,\n item_name: item.description ?? '',\n price: price(item.amount_total, item.currency),\n quantity: item.quantity ?? 1,\n discount: price(item.amount_discount, item.currency),\n })),\n };\n}\n\nexport function getBeginCheckoutProperties(p: ProductPrice): BeginCheckoutProperties {\n return {\n currency: p.currency.toUpperCase(),\n value: price(p.unit_amount, p.currency),\n items: [\n {\n item_id: p.product.id,\n item_name: p.product.name,\n price: price(p.unit_amount, p.currency),\n },\n ],\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,0BAAmC;AAE5B,SAAS,QACd,wBACkC;AAClC,MAAI,CAAC,uBAAwB,QAAO;AACpC,SAAO,IAAI,KAAK,yBAAyB,GAAI,EAAE,YAAY;AAC7D;AAaO,SAAS,SAASA,QAA4B;AACnD,SAAO;AAAA,IACL,IAAIA,OAAM;AAAA,IACV,MAAMA,OAAM;AAAA,IACZ,QAAQA,OAAM;AAAA,IACd,gBAAgBA,OAAM;AAAA,IACtB,UAAUA,OAAM;AAAA,IAChB,aAAaA,OAAM;AAAA,IACnB,qBAAqBA,OAAM,qBAAqB,SAAS,KAAK;AAAA,IAC9D,WAAWA,OAAM;AAAA,EACnB;AACF;AAEO,SAAS,YAAY,MAAuB;AACjD,SAAO;AAAA,IACL,IAAI,KAAK,QACL,OAAO,KAAK,MAAM,YAAY,WAC5B,KAAK,MAAM,UACX,KAAK,MAAM,QAAQ,KACrB,KAAK;AAAA,IACT,UAAU,KAAK;AAAA,IACf,UAAU,KAAK;AAAA,IACf,aAAa,KAAK;AAAA,IAClB,YAAY,KAAK;AAAA,IACjB,cAAc,KAAK;AAAA,IACnB,iBAAiB,KAAK;AAAA,IACtB,iBAAiB,KAAK;AAAA,IACtB,OAAO,KAAK,QAAQ,SAAS,KAAK,KAAK,IAAI;AAAA,EAC7C;AACF;AAIO,SAAS,mBAAmB,SAAkC;AACnE,MAAI,SAA6B;AACjC,MAAI,MAAM,QAAQ,QAAQ,SAAS,KAAK,QAAQ,UAAU,WAAW,GAAG;AACtE,UAAM,WAAW,QAAQ,UAAU,CAAC;AACpC,QAAI,SAAS,UAAU,OAAO,SAAS,WAAW,UAAU;AAC1D,eAAS,SA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CAAC,QAAQ,gBAAgB,CAAC,QAAQ,UAAU;AAC9C,YAAQ,QAAQ,YAAY,OAAO,CAAC,KAAK,SAAS,OAAO,KAAK,gBAAgB,IAAI,CAAC,KAAK;AACxF,eAAW,QAAQ,aAAa,CAAC,GAAG,YAAY;AAAA,EAClD,OAAO;AACL,YAAQ,QAAQ;AAChB,eAAW,QAAQ;AAAA,EACrB;AAEA,SAAO;AAAA,IACL,gBAAgB,QAAQ;AAAA,IACxB,OAAO,MAAM,OAAO,QAAQ;AAAA,IAC5B,UAAU,SAAS,YAAY;AAAA,IAC/B,QAAQ,QAAQ;AAAA,IAChB,OAAO,QAAQ,YAAY,IAAI,CAAC,MAAM,WAAW;AAAA,MAC/C;AAAA,MACA,SAAS,KAAK;AAAA,MACd,WAAW,KAAK,eAAe;AAAA,MAC/B,OAAO,MAAM,KAAK,cAAc,KAAK,QAAQ;AAAA,MAC7C,UAAU,KAAK,YAAY;AAAA,MAC3B,UAAU,MAAM,KAAK,iBAAiB,KAAK,QAAQ;AAAA,IACrD,EAAE;AAAA,EACJ;AACF;AAEO,SAAS,2BAA2B,GAA0C;AACnF,SAAO;AAAA,IACL,UAAU,EAAE,SAAS,YAAY;AAAA,IACjC,OAAO,MAAM,EAAE,aAAa,EAAE,QAAQ;AAAA,IACtC,OAAO;AAAA,MACL;AAAA,QACE,SAAS,EAAE,QAAQ;AAAA,QACnB,WAAW,EAAE,QAAQ;AAAA,QACrB,OAAO,MAAM,EAAE,aAAa,EAAE,QAAQ;AAAA,MACxC;AAAA,IACF;AAAA,EACF;AACF;","names":["price"]}
1
+ {"version":3,"file":"mapper.cjs","names":[],"sources":["../../src/stripe/mapper.ts"],"sourcesContent":["import { type Stripe } from 'stripe';\nimport { SubscriptionStatus } from '../subscription/index';\n\nexport function mapTime<T extends number | null>(\n stripeTimestampSeconds: T\n): T extends number ? string : null {\n if (!stripeTimestampSeconds) return null as T extends number ? string : null;\n return new Date(stripeTimestampSeconds * 1000).toISOString() as T extends number ? string : null;\n}\n\nexport type Price = {\n id: string;\n type: Stripe.Price.Type;\n active: boolean;\n billing_scheme: Stripe.Price.BillingScheme;\n currency: Stripe.Price['currency'];\n unit_amount: number | null;\n unit_amount_decimal: string | null;\n recurring: Stripe.Price.Recurring | null;\n};\n\nexport function mapPrice(price: Stripe.Price): Price {\n return {\n id: price.id,\n type: price.type,\n active: price.active,\n billing_scheme: price.billing_scheme,\n currency: price.currency,\n unit_amount: price.unit_amount,\n unit_amount_decimal: price.unit_amount_decimal?.toString() ?? null,\n recurring: price.recurring,\n };\n}\n\nexport function mapLineItem(item: Stripe.LineItem) {\n return {\n id: item.price\n ? typeof item.price.product === 'string'\n ? item.price.product\n : item.price.product.id\n : item.id,\n currency: item.currency,\n quantity: item.quantity,\n description: item.description,\n amount_tax: item.amount_tax,\n amount_total: item.amount_total,\n amount_subtotal: item.amount_subtotal,\n amount_discount: item.amount_discount,\n price: item.price ? mapPrice(item.price) : null,\n };\n}\n\nexport type PaymentStatus = 'no_payment_required' | 'paid' | 'unpaid';\n\nexport function mapCheckoutSession(session: Stripe.Checkout.Session) {\n let coupon: string | undefined = undefined;\n if (Array.isArray(session.discounts) && session.discounts.length !== 0) {\n const discount = session.discounts[0];\n if (discount.coupon && typeof discount.coupon === 'object') {\n coupon = discount.coupon.id;\n } else if (typeof discount.coupon === 'string') {\n coupon = discount.coupon;\n } else {\n coupon = undefined;\n }\n }\n\n // The variable annotation makes the emitted .d.ts reference the local\n // PaymentStatus alias instead of stripe's internal module path (TS2883)\n const payment_status: PaymentStatus = session.payment_status;\n\n return {\n id: session.id,\n url: session.url,\n coupon,\n livemode: session.livemode,\n expires_at: session.expires_at,\n payment_status,\n currency: session.currency,\n amount_total: session.amount_total,\n line_items: session.line_items?.data.map(mapLineItem),\n };\n}\n\nexport function mapInvoice(i: Stripe.Invoice) {\n return {\n id: i.id,\n number: i.number,\n total: i.total,\n subtotal: i.subtotal,\n amount_due: i.amount_due,\n amount_paid: i.amount_paid,\n amount_remaining: i.amount_remaining,\n currency: i.currency,\n billing_reason: i.billing_reason,\n hosted_invoice_url: i.hosted_invoice_url,\n invoice_pdf: i.invoice_pdf,\n receipt_number: i.receipt_number,\n status: i.status,\n created: i.created,\n period_start: i.period_start,\n period_end: i.period_end,\n };\n}\n\nexport function mapPaymentIntent(intent: Stripe.PaymentIntent) {\n return {\n id: intent.id,\n amount: intent.amount,\n amount_capturable: intent.amount_capturable,\n amount_received: intent.amount_received,\n currency: intent.currency,\n client_secret: intent.client_secret,\n description: intent.description,\n status: intent.status,\n created: intent.created,\n };\n}\n\nexport function mapCharge(charge: Stripe.Charge) {\n return {\n id: charge.id,\n description: charge.description,\n currency: charge.currency,\n amount: charge.amount,\n amount_captured: charge.amount_captured,\n amount_refunded: charge.amount_refunded,\n receipt_email: charge.receipt_email,\n receipt_number: charge.receipt_number,\n receipt_url: charge.receipt_url,\n status: charge.status,\n created: charge.created,\n payment_intent:\n charge.payment_intent && typeof charge.payment_intent === 'object'\n ? mapPaymentIntent(charge.payment_intent)\n : undefined,\n };\n}\n\nexport type CheckoutSession = ReturnType<typeof mapCheckoutSession>;\nexport type ProductPrice = {\n id: string;\n type: Stripe.Price.Type;\n unit_amount: number;\n currency: Stripe.Price['currency'];\n product: {\n id: Stripe.Product['id'];\n name: Stripe.Product['name'];\n description: Stripe.Product['description'];\n livemode: Stripe.Product['livemode'];\n };\n};\n\nexport function mapSubscriptionStatus(status: Stripe.Subscription.Status): SubscriptionStatus {\n switch (status) {\n case 'active':\n return SubscriptionStatus.ACTIVE;\n case 'canceled':\n return SubscriptionStatus.CANCELED;\n case 'incomplete':\n return SubscriptionStatus.INCOMPLETE;\n case 'incomplete_expired':\n return SubscriptionStatus.INCOMPLETE_EXPIRED;\n case 'past_due':\n return SubscriptionStatus.PAST_DUE;\n case 'paused':\n return SubscriptionStatus.PAUSED;\n case 'trialing':\n return SubscriptionStatus.TRIALING;\n case 'unpaid':\n return SubscriptionStatus.UNPAID;\n default: {\n console.error(`Invalid stripe status: ${String(status)}`);\n throw new Error(`Invalid stripe status: ${String(status)}`);\n }\n }\n}\n\nexport const ZERO_DECIMAL_CURRENCIES = [\n 'BIF',\n 'CLP',\n 'DJF',\n 'GNF',\n 'JPY',\n 'KMF',\n 'KRW',\n 'MGA',\n 'PYG',\n 'RWF',\n 'UGX',\n 'VND',\n 'VUV',\n 'XAF',\n 'XOF',\n 'XPF',\n];\n\nexport function minorUnits(currency: string) {\n return ZERO_DECIMAL_CURRENCIES.includes(currency.toUpperCase()) ? 1 : 100;\n}\n\nexport function price(value: number, currency: string) {\n return value / minorUnits(currency);\n}\n\nexport interface Item {\n item_id: string;\n item_name: string;\n affiliation?: 'Google Store' | (string & {});\n coupon?: string;\n discount?: number;\n index?: number;\n item_brand?: string;\n item_category?: string;\n item_category2?: string;\n item_category3?: string;\n item_category4?: string;\n item_category5?: string;\n item_list_id?: string;\n item_list_name?: string;\n item_variant?: string;\n location_id?: string;\n price?: number;\n quantity?: number;\n}\n\nexport interface PurchaseProperties {\n currency: string;\n value: number;\n transaction_id: string;\n coupon?: string;\n shipping?: number;\n tax?: number;\n items?: Item[];\n}\n\nexport interface BeginCheckoutProperties {\n currency: string;\n value: number;\n coupon?: string;\n items: Item[];\n}\n\nexport function getPurchaseProperties(session: CheckoutSession): PurchaseProperties {\n let value: number;\n let currency: string;\n if (!session.amount_total || !session.currency) {\n value = session.line_items?.reduce((acc, item) => acc + (item.amount_total ?? 0), 0) ?? 0;\n currency = session.line_items?.[0]?.currency ?? 'usd';\n } else {\n value = session.amount_total;\n currency = session.currency;\n }\n\n return {\n transaction_id: session.id,\n value: price(value, currency),\n currency: currency.toUpperCase(),\n coupon: session.coupon,\n items: session.line_items?.map((item, index) => ({\n index,\n item_id: item.id,\n item_name: item.description ?? '',\n price: price(item.amount_total, item.currency),\n quantity: item.quantity ?? 1,\n discount: price(item.amount_discount, item.currency),\n })),\n };\n}\n\nexport function getBeginCheckoutProperties(p: ProductPrice): BeginCheckoutProperties {\n return {\n currency: p.currency.toUpperCase(),\n value: price(p.unit_amount, p.currency),\n items: [\n {\n item_id: p.product.id,\n item_name: p.product.name,\n price: price(p.unit_amount, p.currency),\n },\n ],\n };\n}\n"],"mappings":";;;AAGA,SAAgB,QACd,wBACkC;CAClC,IAAI,CAAC,wBAAwB,OAAO;CACpC,wBAAO,IAAI,KAAK,yBAAyB,GAAI,EAAA,CAAE,YAAY;AAC7D;AAaA,SAAgB,SAAS,OAA4B;CACnD,OAAO;EACL,IAAI,MAAM;EACV,MAAM,MAAM;EACZ,QAAQ,MAAM;EACd,gBAAgB,MAAM;EACtB,UAAU,MAAM;EAChB,aAAa,MAAM;EACnB,qBAAqB,MAAM,qBAAqB,SAAS,KAAK;EAC9D,WAAW,MAAM;CACnB;AACF;AAEA,SAAgB,YAAY,MAAuB;CACjD,OAAO;EACL,IAAI,KAAK,QACL,OAAO,KAAK,MAAM,YAAY,WAC5B,KAAK,MAAM,UACX,KAAK,MAAM,QAAQ,KACrB,KAAK;EACT,UAAU,KAAK;EACf,UAAU,KAAK;EACf,aAAa,KAAK;EAClB,YAAY,KAAK;EACjB,cAAc,KAAK;EACnB,iBAAiB,KAAK;EACtB,iBAAiB,KAAK;EACtB,OAAO,KAAK,QAAQ,SAAS,KAAK,KAAK,IAAI;CAC7C;AACF;AAIA,SAAgB,mBAAmB,SAAkC;CACnE,IAAI,SAA6B,KAAA;CACjC,IAAI,MAAM,QAAQ,QAAQ,SAAS,KAAK,QAAQ,UAAU,WAAW,GAAG;EACtE,MAAM,WAAW,QAAQ,UAAU;EACnC,IAAI,SAAS,UAAU,OAAO,SAAS,WAAW,UAChD,SAAS,SAAS,OAAO;OACpB,IAAI,OAAO,SAAS,WAAW,UACpC,SAAS,SAAS;OAElB,SAAS,KAAA;CAEb;CAIA,MAAM,iBAAgC,QAAQ;CAE9C,OAAO;EACL,IAAI,QAAQ;EACZ,KAAK,QAAQ;EACb;EACA,UAAU,QAAQ;EAClB,YAAY,QAAQ;EACpB;EACA,UAAU,QAAQ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