@crvouga/mockingbird-service-stripe 0.1.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 (142) hide show
  1. package/README.md +254 -0
  2. package/dist/account.d.ts +8 -0
  3. package/dist/account.d.ts.map +1 -0
  4. package/dist/account.js +13 -0
  5. package/dist/account.js.map +1 -0
  6. package/dist/charges.d.ts +4 -0
  7. package/dist/charges.d.ts.map +1 -0
  8. package/dist/charges.js +89 -0
  9. package/dist/charges.js.map +1 -0
  10. package/dist/checkout-sessions.d.ts +5 -0
  11. package/dist/checkout-sessions.d.ts.map +1 -0
  12. package/dist/checkout-sessions.js +303 -0
  13. package/dist/checkout-sessions.js.map +1 -0
  14. package/dist/constants.d.ts +3 -0
  15. package/dist/constants.d.ts.map +1 -0
  16. package/dist/constants.js +3 -0
  17. package/dist/constants.js.map +1 -0
  18. package/dist/coupons.d.ts +4 -0
  19. package/dist/coupons.d.ts.map +1 -0
  20. package/dist/coupons.js +158 -0
  21. package/dist/coupons.js.map +1 -0
  22. package/dist/customers.d.ts +4 -0
  23. package/dist/customers.d.ts.map +1 -0
  24. package/dist/customers.js +218 -0
  25. package/dist/customers.js.map +1 -0
  26. package/dist/disputes.d.ts +4 -0
  27. package/dist/disputes.d.ts.map +1 -0
  28. package/dist/disputes.js +36 -0
  29. package/dist/disputes.js.map +1 -0
  30. package/dist/errors.d.ts +29 -0
  31. package/dist/errors.d.ts.map +1 -0
  32. package/dist/errors.js +74 -0
  33. package/dist/errors.js.map +1 -0
  34. package/dist/events.d.ts +4 -0
  35. package/dist/events.d.ts.map +1 -0
  36. package/dist/events.js +76 -0
  37. package/dist/events.js.map +1 -0
  38. package/dist/expand.d.ts +11 -0
  39. package/dist/expand.d.ts.map +1 -0
  40. package/dist/expand.js +45 -0
  41. package/dist/expand.js.map +1 -0
  42. package/dist/fields.d.ts +25 -0
  43. package/dist/fields.d.ts.map +1 -0
  44. package/dist/fields.js +117 -0
  45. package/dist/fields.js.map +1 -0
  46. package/dist/generated/openapi.d.ts +7 -0
  47. package/dist/generated/openapi.d.ts.map +1 -0
  48. package/dist/generated/openapi.js +5 -0
  49. package/dist/generated/openapi.js.map +1 -0
  50. package/dist/index.d.ts +43 -0
  51. package/dist/index.d.ts.map +1 -0
  52. package/dist/index.js +172 -0
  53. package/dist/index.js.map +1 -0
  54. package/dist/internal.d.ts +134 -0
  55. package/dist/internal.d.ts.map +1 -0
  56. package/dist/internal.js +460 -0
  57. package/dist/internal.js.map +1 -0
  58. package/dist/invoice-items.d.ts +4 -0
  59. package/dist/invoice-items.d.ts.map +1 -0
  60. package/dist/invoice-items.js +179 -0
  61. package/dist/invoice-items.js.map +1 -0
  62. package/dist/invoices.d.ts +4 -0
  63. package/dist/invoices.d.ts.map +1 -0
  64. package/dist/invoices.js +312 -0
  65. package/dist/invoices.js.map +1 -0
  66. package/dist/list.d.ts +24 -0
  67. package/dist/list.d.ts.map +1 -0
  68. package/dist/list.js +68 -0
  69. package/dist/list.js.map +1 -0
  70. package/dist/params.d.ts +29 -0
  71. package/dist/params.d.ts.map +1 -0
  72. package/dist/params.js +165 -0
  73. package/dist/params.js.map +1 -0
  74. package/dist/payment-intents.d.ts +4 -0
  75. package/dist/payment-intents.d.ts.map +1 -0
  76. package/dist/payment-intents.js +232 -0
  77. package/dist/payment-intents.js.map +1 -0
  78. package/dist/payment-methods.d.ts +4 -0
  79. package/dist/payment-methods.d.ts.map +1 -0
  80. package/dist/payment-methods.js +99 -0
  81. package/dist/payment-methods.js.map +1 -0
  82. package/dist/prices.d.ts +4 -0
  83. package/dist/prices.d.ts.map +1 -0
  84. package/dist/prices.js +176 -0
  85. package/dist/prices.js.map +1 -0
  86. package/dist/products.d.ts +6 -0
  87. package/dist/products.d.ts.map +1 -0
  88. package/dist/products.js +202 -0
  89. package/dist/products.js.map +1 -0
  90. package/dist/promotion-codes.d.ts +4 -0
  91. package/dist/promotion-codes.d.ts.map +1 -0
  92. package/dist/promotion-codes.js +193 -0
  93. package/dist/promotion-codes.js.map +1 -0
  94. package/dist/qa-corpus.d.ts +26 -0
  95. package/dist/qa-corpus.d.ts.map +1 -0
  96. package/dist/qa-corpus.js +42 -0
  97. package/dist/qa-corpus.js.map +1 -0
  98. package/dist/refunds.d.ts +4 -0
  99. package/dist/refunds.d.ts.map +1 -0
  100. package/dist/refunds.js +125 -0
  101. package/dist/refunds.js.map +1 -0
  102. package/dist/render.d.ts +60 -0
  103. package/dist/render.d.ts.map +1 -0
  104. package/dist/render.js +426 -0
  105. package/dist/render.js.map +1 -0
  106. package/dist/reshape-qa.d.ts +8 -0
  107. package/dist/reshape-qa.d.ts.map +1 -0
  108. package/dist/reshape-qa.js +102 -0
  109. package/dist/reshape-qa.js.map +1 -0
  110. package/dist/search.d.ts +32 -0
  111. package/dist/search.d.ts.map +1 -0
  112. package/dist/search.js +64 -0
  113. package/dist/search.js.map +1 -0
  114. package/dist/setup-intents.d.ts +4 -0
  115. package/dist/setup-intents.d.ts.map +1 -0
  116. package/dist/setup-intents.js +129 -0
  117. package/dist/setup-intents.js.map +1 -0
  118. package/dist/state.d.ts +485 -0
  119. package/dist/state.d.ts.map +1 -0
  120. package/dist/state.js +143 -0
  121. package/dist/state.js.map +1 -0
  122. package/dist/subscription-schedules.d.ts +4 -0
  123. package/dist/subscription-schedules.d.ts.map +1 -0
  124. package/dist/subscription-schedules.js +122 -0
  125. package/dist/subscription-schedules.js.map +1 -0
  126. package/dist/subscriptions.d.ts +23 -0
  127. package/dist/subscriptions.d.ts.map +1 -0
  128. package/dist/subscriptions.js +260 -0
  129. package/dist/subscriptions.js.map +1 -0
  130. package/dist/test-tokens.d.ts +27 -0
  131. package/dist/test-tokens.d.ts.map +1 -0
  132. package/dist/test-tokens.js +61 -0
  133. package/dist/test-tokens.js.map +1 -0
  134. package/dist/url.d.ts +6 -0
  135. package/dist/url.d.ts.map +1 -0
  136. package/dist/url.js +38 -0
  137. package/dist/url.js.map +1 -0
  138. package/dist/version.d.ts +3 -0
  139. package/dist/version.d.ts.map +1 -0
  140. package/dist/version.js +3 -0
  141. package/dist/version.js.map +1 -0
  142. package/package.json +72 -0
@@ -0,0 +1,26 @@
1
+ /**
2
+ * The Stripe surface the QA suites exercise: every operation the vendored contract marks
3
+ * supported (the unsupported ones answer a Stripe-shaped error by design and are listed with
4
+ * reasons in SUPPORT.md). Derived from the document so the list can never drift from the contract.
5
+ */
6
+ export declare const QA_SURFACE_OPS: readonly string[];
7
+ /** Pinned values the suites use, so offline walks exercise realistic shapes. */
8
+ export declare const QA_METADATA: {
9
+ readonly intent: "e2e-test";
10
+ readonly source: "e2e-test";
11
+ readonly userId: "1001";
12
+ };
13
+ export declare const QA_AMOUNTS: readonly [1000, 15000, 17999];
14
+ export declare const QA_CUSTOMER: {
15
+ readonly email: "qa+e2e@test.example.com";
16
+ readonly name: "Ada Lovelace";
17
+ readonly phone: "+15555550123";
18
+ };
19
+ /** Test payment methods and card tokens the suites attach by id. */
20
+ export declare const QA_TEST_PAYMENT_METHODS: readonly ["pm_card_visa", "pm_card_mastercard", "pm_card_authenticationRequired"];
21
+ export declare const QA_TEST_CARD_TOKENS: readonly ["tok_visa", "tok_mastercard", "tok_chargeDeclinedInsufficientFunds", "tok_chargeDeclinedExpiredCard", "tok_chargeCustomerFail"];
22
+ /** Search queries the suites issue, covering every metadata key their handlers read. */
23
+ export declare const QA_SEARCH_QUERIES: readonly ["metadata['userId']:'1001'", "metadata['paymentId']:'1001'", "metadata['billingInvoiceId']:'inv_1001'", "email:'qa+e2e@test.example.com'"];
24
+ /** Coupon / promotion-code fixture values used by the shop and coupon flows. */
25
+ export declare const QA_COUPON_CODES: readonly ["QA10", "QA-FREE-BLOODWORK"];
26
+ //# sourceMappingURL=qa-corpus.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"qa-corpus.d.ts","sourceRoot":"","sources":["../src/qa-corpus.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AACH,eAAO,MAAM,cAAc,EAAE,SAAS,MAAM,EAA+B,CAAA;AAE3E,gFAAgF;AAChF,eAAO,MAAM,WAAW;;;;CAId,CAAA;AAEV,eAAO,MAAM,UAAU,+BAAgC,CAAA;AAEvD,eAAO,MAAM,WAAW;;;;CAId,CAAA;AAEV,oEAAoE;AACpE,eAAO,MAAM,uBAAuB,mFAI1B,CAAA;AAEV,eAAO,MAAM,mBAAmB,2IAMtB,CAAA;AAEV,wFAAwF;AACxF,eAAO,MAAM,iBAAiB,sJAKpB,CAAA;AAEV,gFAAgF;AAChF,eAAO,MAAM,eAAe,wCAAyC,CAAA"}
@@ -0,0 +1,42 @@
1
+ import { supportedOperationIds } from "./generated/openapi.js";
2
+ /**
3
+ * The Stripe surface the QA suites exercise: every operation the vendored contract marks
4
+ * supported (the unsupported ones answer a Stripe-shaped error by design and are listed with
5
+ * reasons in SUPPORT.md). Derived from the document so the list can never drift from the contract.
6
+ */
7
+ export const QA_SURFACE_OPS = [...supportedOperationIds];
8
+ /** Pinned values the suites use, so offline walks exercise realistic shapes. */
9
+ export const QA_METADATA = {
10
+ intent: "e2e-test",
11
+ source: "e2e-test",
12
+ userId: "1001",
13
+ };
14
+ export const QA_AMOUNTS = [1000, 15000, 17999];
15
+ export const QA_CUSTOMER = {
16
+ email: "qa+e2e@test.example.com",
17
+ name: "Ada Lovelace",
18
+ phone: "+15555550123",
19
+ };
20
+ /** Test payment methods and card tokens the suites attach by id. */
21
+ export const QA_TEST_PAYMENT_METHODS = [
22
+ "pm_card_visa",
23
+ "pm_card_mastercard",
24
+ "pm_card_authenticationRequired",
25
+ ];
26
+ export const QA_TEST_CARD_TOKENS = [
27
+ "tok_visa",
28
+ "tok_mastercard",
29
+ "tok_chargeDeclinedInsufficientFunds",
30
+ "tok_chargeDeclinedExpiredCard",
31
+ "tok_chargeCustomerFail",
32
+ ];
33
+ /** Search queries the suites issue, covering every metadata key their handlers read. */
34
+ export const QA_SEARCH_QUERIES = [
35
+ "metadata['userId']:'1001'",
36
+ "metadata['paymentId']:'1001'",
37
+ "metadata['billingInvoiceId']:'inv_1001'",
38
+ "email:'qa+e2e@test.example.com'",
39
+ ];
40
+ /** Coupon / promotion-code fixture values used by the shop and coupon flows. */
41
+ export const QA_COUPON_CODES = ["QA10", "QA-FREE-BLOODWORK"];
42
+ //# sourceMappingURL=qa-corpus.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"qa-corpus.js","sourceRoot":"","sources":["../src/qa-corpus.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,wBAAwB,CAAA;AAE9D;;;;GAIG;AACH,MAAM,CAAC,MAAM,cAAc,GAAsB,CAAC,GAAG,qBAAqB,CAAC,CAAA;AAE3E,gFAAgF;AAChF,MAAM,CAAC,MAAM,WAAW,GAAG;IACzB,MAAM,EAAE,UAAU;IAClB,MAAM,EAAE,UAAU;IAClB,MAAM,EAAE,MAAM;CACN,CAAA;AAEV,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,IAAI,EAAE,KAAK,EAAE,KAAK,CAAU,CAAA;AAEvD,MAAM,CAAC,MAAM,WAAW,GAAG;IACzB,KAAK,EAAE,yBAAyB;IAChC,IAAI,EAAE,cAAc;IACpB,KAAK,EAAE,cAAc;CACb,CAAA;AAEV,oEAAoE;AACpE,MAAM,CAAC,MAAM,uBAAuB,GAAG;IACrC,cAAc;IACd,oBAAoB;IACpB,gCAAgC;CACxB,CAAA;AAEV,MAAM,CAAC,MAAM,mBAAmB,GAAG;IACjC,UAAU;IACV,gBAAgB;IAChB,qCAAqC;IACrC,+BAA+B;IAC/B,wBAAwB;CAChB,CAAA;AAEV,wFAAwF;AACxF,MAAM,CAAC,MAAM,iBAAiB,GAAG;IAC/B,2BAA2B;IAC3B,8BAA8B;IAC9B,yCAAyC;IACzC,iCAAiC;CACzB,CAAA;AAEV,gFAAgF;AAChF,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,MAAM,EAAE,mBAAmB,CAAU,CAAA"}
@@ -0,0 +1,4 @@
1
+ import { type OperationHandler } from "@crvouga/mockingbird-service";
2
+ import { type Services } from "./internal.js";
3
+ export declare const refundHandlers: (services: Services) => Record<string, OperationHandler>;
4
+ //# sourceMappingURL=refunds.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"refunds.d.ts","sourceRoot":"","sources":["../src/refunds.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,KAAK,gBAAgB,EAAE,MAAM,8BAA8B,CAAA;AAGlF,OAAO,EAML,KAAK,QAAQ,EACd,MAAM,eAAe,CAAA;AAyDtB,eAAO,MAAM,cAAc,GAAI,UAAU,QAAQ,KAAG,MAAM,CAAC,MAAM,EAAE,gBAAgB,CA0FjF,CAAA"}
@@ -0,0 +1,125 @@
1
+ import { jsonResponse } from "@crvouga/mockingbird-service";
2
+ import { invalidRequest, resourceMissing } from "./errors.js";
3
+ import { applyExpand } from "./expand.js";
4
+ import { mergeRecordMetadata, requestScope, requireCharge, requireIntent, } from "./internal.js";
5
+ import { matchesCreated, paginate } from "./list.js";
6
+ import { bodyParams, queryParams } from "./params.js";
7
+ import { renderCharge, renderPaymentIntent, renderRefund } from "./render.js";
8
+ import { seconds } from "./state.js";
9
+ const stringOf = (params, key) => {
10
+ const value = params[key];
11
+ return typeof value === "string" && value !== "" ? value : null;
12
+ };
13
+ const requireRefund = (scope, id) => {
14
+ const refund = scope.account.refunds.get(id);
15
+ if (!refund)
16
+ throw resourceMissing("refund", id, "refund");
17
+ return refund;
18
+ };
19
+ const expanders = (scope) => {
20
+ const charge = (id) => {
21
+ const record = scope.account.charges.get(id);
22
+ return record ? renderCharge(record) : undefined;
23
+ };
24
+ const paymentIntent = (id) => {
25
+ const record = scope.account.paymentIntents.get(id);
26
+ return record ? renderPaymentIntent(record) : undefined;
27
+ };
28
+ return {
29
+ charge,
30
+ payment_intent: paymentIntent,
31
+ "data.charge": charge,
32
+ "data.payment_intent": paymentIntent,
33
+ };
34
+ };
35
+ const render = (scope, refund, expand) => applyExpand(renderRefund(refund), expand, expanders(scope));
36
+ /** Resolve the charge a refund against a payment intent would reverse. */
37
+ const refundableCharge = (scope, chargeId, intentId) => {
38
+ if (chargeId !== null) {
39
+ const charge = requireCharge(scope, chargeId, "charge");
40
+ return { charge, paymentIntent: charge.payment_intent };
41
+ }
42
+ const intent = requireIntent(scope, intentId ?? "", "payment_intent");
43
+ if (intent.status !== "succeeded" || intent.latest_charge === null)
44
+ throw invalidRequest("This payment_intent cannot be refunded because it does not have a successful charge.", "payment_intent");
45
+ const charge = requireCharge(scope, intent.latest_charge, "charge");
46
+ return { charge, paymentIntent: intent.id };
47
+ };
48
+ export const refundHandlers = (services) => ({
49
+ GetRefunds: async (context) => {
50
+ const scope = requestScope(services, context);
51
+ const params = queryParams(context);
52
+ const charge = stringOf(params, "charge");
53
+ const paymentIntent = stringOf(params, "payment_intent");
54
+ const page = await paginate(scope.account.refunds, params, {
55
+ url: "/v1/refunds",
56
+ kind: "refund",
57
+ where: (record) => matchesCreated(record.created, params.created) &&
58
+ (charge === null || record.charge === charge) &&
59
+ (paymentIntent === null || record.payment_intent === paymentIntent),
60
+ render: renderRefund,
61
+ });
62
+ return jsonResponse(200, applyExpand(page, params.expand, expanders(scope)));
63
+ },
64
+ PostRefunds: async (context) => {
65
+ const scope = requestScope(services, context);
66
+ const params = bodyParams(context);
67
+ const chargeId = stringOf(params, "charge");
68
+ const intentId = stringOf(params, "payment_intent");
69
+ if (chargeId === null && intentId === null)
70
+ throw invalidRequest("Must provide either a charge or a payment_intent.", "charge");
71
+ if (chargeId !== null && intentId !== null)
72
+ throw invalidRequest("You cannot provide both a charge and a payment_intent.", "payment_intent");
73
+ const { charge, paymentIntent } = refundableCharge(scope, chargeId, intentId);
74
+ if (charge.status !== "succeeded")
75
+ throw invalidRequest(`This charge cannot be refunded because it has a status of ${charge.status}.`, "charge");
76
+ const remaining = charge.amount - charge.amount_refunded;
77
+ if (remaining <= 0)
78
+ throw invalidRequest(`Charge ${charge.id} has already been refunded.`, "charge", "charge_already_refunded");
79
+ const amount = typeof params.amount === "number" ? params.amount : remaining;
80
+ if (amount > remaining)
81
+ throw invalidRequest(`Refund amount (${amount}) is greater than the remaining amount that can be refunded (${remaining}).`, "amount");
82
+ const id = scope.ids.next("re_");
83
+ const refund = {
84
+ id,
85
+ amount,
86
+ charge: charge.id,
87
+ created: seconds(scope.now),
88
+ currency: charge.currency,
89
+ metadata: mergeRecordMetadata({}, params.metadata),
90
+ payment_intent: paymentIntent,
91
+ reason: stringOf(params, "reason"),
92
+ receipt_number: null,
93
+ status: "succeeded",
94
+ };
95
+ const amountRefunded = charge.amount_refunded + amount;
96
+ scope.account.charges.update(charge.id, {
97
+ ...charge,
98
+ amount_refunded: amountRefunded,
99
+ refund_ids: [...charge.refund_ids, id],
100
+ refunded: amountRefunded >= charge.amount,
101
+ });
102
+ scope.account.refunds.insert(id, refund);
103
+ scope.emit("refund.created", renderRefund(refund));
104
+ return jsonResponse(200, render(scope, refund, params.expand));
105
+ },
106
+ GetRefundsRefund: async (context) => {
107
+ const scope = requestScope(services, context);
108
+ const params = queryParams(context);
109
+ const refund = requireRefund(scope, context.params.refund ?? "");
110
+ return jsonResponse(200, render(scope, refund, params.expand));
111
+ },
112
+ PostRefundsRefund: async (context) => {
113
+ const scope = requestScope(services, context);
114
+ const params = bodyParams(context);
115
+ const current = requireRefund(scope, context.params.refund ?? "");
116
+ const refund = {
117
+ ...current,
118
+ metadata: mergeRecordMetadata(current.metadata, params.metadata),
119
+ };
120
+ scope.account.refunds.update(refund.id, refund);
121
+ scope.emit("refund.updated", renderRefund(refund));
122
+ return jsonResponse(200, render(scope, refund, params.expand));
123
+ },
124
+ });
125
+ //# sourceMappingURL=refunds.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"refunds.js","sourceRoot":"","sources":["../src/refunds.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAyB,MAAM,8BAA8B,CAAA;AAClF,OAAO,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,aAA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EAAE,EAAE;QACnC,MAAM,KAAK,GAAG,YAAY,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAA;QAC7C,MAAM,MAAM,GAAG,UAAU,CAAC,OAAO,CAAC,CAAA;QAClC,MAAM,OAAO,GAAG,aAAa,CAAC,KAAK,EAAE,OAAO,CAAC,MAAM,CAAC,MAAM,IAAI,EAAE,CAAC,CAAA;QACjE,MAAM,MAAM,GAAiB;YAC3B,GAAG,OAAO;YACV,QAAQ,EAAE,mBAAmB,CAAC,OAAO,CAAC,QAAQ,EAAE,MAAM,CAAC,QAAQ,CAAC;SACjE,CAAA;QACD,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,EAAE,MAAM,CAAC,CAAA;QAC/C,KAAK,CAAC,IAAI,CAAC,gBAAgB,EAAE,YAAY,CAAC,MAAM,CAAC,CAAC,CAAA;QAClD,OAAO,YAAY,CAAC,GAAG,EAAE,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC,CAAA;IAChE,CAAC;CACF,CAAC,CAAA"}
@@ -0,0 +1,60 @@
1
+ import type { AccountState, ChargeRecord, CheckoutSessionLineRecord, CheckoutSessionRecord, CouponRecord, CustomerBalanceTransactionRecord, CustomerRecord, DiscountRecord, DisputeRecord, InvoiceItemRecord, InvoiceRecord, PaymentIntentRecord, PaymentMethodRecord, PriceRecord, ProductRecord, PromotionCodeRecord, RefundRecord, SetupIntentRecord, SubscriptionItemRecord, SubscriptionRecord, SubscriptionScheduleRecord, WebhookEventRecord } from "./state.js";
2
+ type RecordValue = Record<string, unknown>;
3
+ export declare const unitAmountOf: (decimal: string) => number | null;
4
+ export declare const renderCustomer: (customer: CustomerRecord) => RecordValue;
5
+ export declare const renderDeletedCustomer: (id: string) => {
6
+ id: string;
7
+ object: string;
8
+ deleted: boolean;
9
+ };
10
+ export declare const renderProduct: (product: ProductRecord) => RecordValue;
11
+ export declare const renderDeletedProduct: (id: string) => {
12
+ id: string;
13
+ object: string;
14
+ deleted: boolean;
15
+ };
16
+ export declare const renderPrice: (price: PriceRecord) => RecordValue;
17
+ /** Price as an inline object, falling back to the bare id when the record is gone. */
18
+ export declare const priceOrId: (scope: AccountState, id: string) => RecordValue | string;
19
+ export declare const renderPaymentMethod: (method: PaymentMethodRecord) => RecordValue;
20
+ export declare const renderPaymentIntent: (intent: PaymentIntentRecord) => RecordValue;
21
+ export declare const renderSetupIntent: (intent: SetupIntentRecord) => RecordValue;
22
+ export declare const renderCharge: (charge: ChargeRecord) => RecordValue;
23
+ export declare const renderRefund: (refund: RefundRecord) => RecordValue;
24
+ export declare const renderDispute: (dispute: DisputeRecord) => RecordValue;
25
+ export declare const renderCustomerBalanceTransaction: (transaction: CustomerBalanceTransactionRecord) => RecordValue;
26
+ export declare const renderDiscount: (discount: DiscountRecord) => RecordValue;
27
+ export declare const renderDiscounts: (scope: AccountState, ids: readonly string[]) => RecordValue[];
28
+ export declare const renderCoupon: (coupon: CouponRecord) => RecordValue;
29
+ export declare const renderDeletedCoupon: (id: string) => {
30
+ id: string;
31
+ object: string;
32
+ deleted: boolean;
33
+ };
34
+ export declare const renderPromotionCode: (promotion: PromotionCodeRecord) => RecordValue;
35
+ export declare const renderCheckoutLineItem: (line: CheckoutSessionLineRecord, scope: AccountState) => RecordValue;
36
+ export declare const renderCheckoutSession: (session: CheckoutSessionRecord) => RecordValue;
37
+ export declare const renderInvoice: (invoice: InvoiceRecord, scope: AccountState) => RecordValue;
38
+ export declare const renderDeletedInvoice: (id: string) => {
39
+ id: string;
40
+ object: string;
41
+ deleted: boolean;
42
+ };
43
+ export declare const renderInvoiceItem: (item: InvoiceItemRecord) => RecordValue;
44
+ export declare const renderDeletedInvoiceItem: (id: string) => {
45
+ id: string;
46
+ object: string;
47
+ deleted: boolean;
48
+ };
49
+ export declare const renderSubscriptionItem: (item: SubscriptionItemRecord, scope: AccountState) => RecordValue;
50
+ export declare const renderSubscription: (subscription: SubscriptionRecord, scope: AccountState) => RecordValue;
51
+ export declare const renderDeletedSubscriptionItem: (id: string) => {
52
+ id: string;
53
+ object: string;
54
+ deleted: boolean;
55
+ };
56
+ export declare const renderSubscriptionSchedule: (schedule: SubscriptionScheduleRecord) => RecordValue;
57
+ /** Events are stored as their exact wire JSON, so rendering is a parse of those bytes. */
58
+ export declare const renderEvent: (event: WebhookEventRecord) => RecordValue;
59
+ export {};
60
+ //# sourceMappingURL=render.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"render.d.ts","sourceRoot":"","sources":["../src/render.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,YAAY,EACZ,YAAY,EACZ,yBAAyB,EACzB,qBAAqB,EACrB,YAAY,EACZ,gCAAgC,EAChC,cAAc,EACd,cAAc,EACd,aAAa,EACb,iBAAiB,EAEjB,aAAa,EACb,mBAAmB,EACnB,mBAAmB,EACnB,WAAW,EACX,aAAa,EACb,mBAAmB,EACnB,YAAY,EACZ,iBAAiB,EACjB,sBAAsB,EACtB,kBAAkB,EAClB,0BAA0B,EAC1B,kBAAkB,EACnB,MAAM,YAAY,CAAA;AAEnB,KAAK,WAAW,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;AAU1C,eAAO,MAAM,YAAY,GAAI,SAAS,MAAM,KAAG,MAAM,GAAG,IACR,CAAA;AAEhD,eAAO,MAAM,cAAc,GAAI,UAAU,cAAc,KAAG,WA0BxD,CAAA;AAEF,eAAO,MAAM,qBAAqB,GAAI,IAAI,MAAM;;;;CAI9C,CAAA;AAEF,eAAO,MAAM,aAAa,GAAI,SAAS,aAAa,KAAG,WAmBrD,CAAA;AAEF,eAAO,MAAM,oBAAoB,GAAI,IAAI,MAAM;;;;CAI7C,CAAA;AAEF,eAAO,MAAM,WAAW,GAAI,OAAO,WAAW,KAAG,WA0B/C,CAAA;AAEF,sFAAsF;AACtF,eAAO,MAAM,SAAS,GAAI,OAAO,YAAY,EAAE,IAAI,MAAM,KAAG,W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