@fantastic.dev/better-stripe 0.57.0 → 0.59.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.
- package/CHANGELOG.md +12 -0
- package/README.md +3 -1
- package/dist/client/connect/payoutAdoptionTestHelpers.d.ts +356 -50
- package/dist/client/connect/payoutAdoptionTestHelpers.d.ts.map +1 -1
- package/dist/client/connect/payoutExecutionTestHelpers.d.ts +162 -9
- package/dist/client/connect/payoutExecutionTestHelpers.d.ts.map +1 -1
- package/dist/client/connect/payoutLargeAdoptionTestHelpers.d.ts +356 -50
- package/dist/client/connect/payoutLargeAdoptionTestHelpers.d.ts.map +1 -1
- package/dist/client/connect/payoutSyncTestHelpers.d.ts +162 -9
- package/dist/client/connect/payoutSyncTestHelpers.d.ts.map +1 -1
- package/dist/client/usage/allowanceClient.d.ts +51 -0
- package/dist/client/usage/allowanceClient.d.ts.map +1 -0
- package/dist/client/usage/allowanceClient.js +64 -0
- package/dist/client/usage/allowanceClient.js.map +1 -0
- package/dist/client/usage/allowanceTerms.d.ts +64 -0
- package/dist/client/usage/allowanceTerms.d.ts.map +1 -0
- package/dist/client/usage/allowanceTerms.js +101 -0
- package/dist/client/usage/allowanceTerms.js.map +1 -0
- package/dist/client/usage/client.d.ts +2 -2
- package/dist/client/usage/client.d.ts.map +1 -1
- package/dist/client/usage/client.js +2 -2
- package/dist/client/usage/client.js.map +1 -1
- package/dist/client/usage/correctionClient.d.ts +33 -0
- package/dist/client/usage/correctionClient.d.ts.map +1 -0
- package/dist/client/usage/correctionClient.js +27 -0
- package/dist/client/usage/correctionClient.js.map +1 -0
- package/dist/client/usage/correctionEligibility.d.ts +4 -0
- package/dist/client/usage/correctionEligibility.d.ts.map +1 -0
- package/dist/client/usage/correctionEligibility.js +7 -0
- package/dist/client/usage/correctionEligibility.js.map +1 -0
- package/dist/client/usage/correctionInvoice.d.ts +9 -0
- package/dist/client/usage/correctionInvoice.d.ts.map +1 -0
- package/dist/client/usage/correctionInvoice.js +218 -0
- package/dist/client/usage/correctionInvoice.js.map +1 -0
- package/dist/client/usage/correctionInvoiceProof.d.ts +29 -0
- package/dist/client/usage/correctionInvoiceProof.d.ts.map +1 -0
- package/dist/client/usage/correctionInvoiceProof.js +41 -0
- package/dist/client/usage/correctionInvoiceProof.js.map +1 -0
- package/dist/client/usage/correctionProofs.d.ts +36 -0
- package/dist/client/usage/correctionProofs.d.ts.map +1 -0
- package/dist/client/usage/correctionProofs.js +41 -0
- package/dist/client/usage/correctionProofs.js.map +1 -0
- package/dist/client/usage/correctionProvider.d.ts +6 -0
- package/dist/client/usage/correctionProvider.d.ts.map +1 -0
- package/dist/client/usage/correctionProvider.js +243 -0
- package/dist/client/usage/correctionProvider.js.map +1 -0
- package/dist/client/usage/correctionRead.d.ts +27 -0
- package/dist/client/usage/correctionRead.d.ts.map +1 -0
- package/dist/client/usage/correctionRead.js +36 -0
- package/dist/client/usage/correctionRead.js.map +1 -0
- package/dist/client/usage/correctionTerms.d.ts +64 -0
- package/dist/client/usage/correctionTerms.d.ts.map +1 -0
- package/dist/client/usage/correctionTerms.js +65 -0
- package/dist/client/usage/correctionTerms.js.map +1 -0
- package/dist/client/usage/correctionTransport.fixtures.d.ts +37 -0
- package/dist/client/usage/correctionTransport.fixtures.d.ts.map +1 -0
- package/dist/client/usage/correctionTransport.fixtures.js +322 -0
- package/dist/client/usage/correctionTransport.fixtures.js.map +1 -0
- package/dist/client/usage/creditClient.d.ts +1 -1
- package/dist/client/usage/index.d.ts +4 -0
- package/dist/client/usage/index.d.ts.map +1 -1
- package/dist/client/usage/observationClient.d.ts +20 -0
- package/dist/client/usage/observationClient.d.ts.map +1 -1
- package/dist/client/usage/observationClient.js +20 -6
- package/dist/client/usage/observationClient.js.map +1 -1
- package/dist/client/usage/records.d.ts +1 -1
- package/dist/client/usage/records.d.ts.map +1 -1
- package/dist/client/usage/records.js.map +1 -1
- package/dist/client/usage/summary.d.ts +3 -0
- package/dist/client/usage/summary.d.ts.map +1 -1
- package/dist/client/usage/summary.js +9 -4
- package/dist/client/usage/summary.js.map +1 -1
- package/dist/client/usageExports.d.ts +4 -0
- package/dist/client/usageExports.d.ts.map +1 -1
- package/dist/component/_generated/api.d.ts +20 -0
- package/dist/component/_generated/api.d.ts.map +1 -1
- package/dist/component/_generated/api.js.map +1 -1
- package/dist/component/_generated/component.d.ts +324 -13
- package/dist/component/_generated/component.d.ts.map +1 -1
- package/dist/component/accountClosure/mutations.d.ts.map +1 -1
- package/dist/component/accountClosure/mutations.js +13 -0
- package/dist/component/accountClosure/mutations.js.map +1 -1
- package/dist/component/balanceFunding/internal/actions.d.ts +11 -11
- package/dist/component/balanceFunding/mutations.d.ts +43 -43
- package/dist/component/balanceFunding/workflowValidators.d.ts +16 -16
- package/dist/component/earnings/triggers.d.ts +288 -10
- package/dist/component/earnings/triggers.d.ts.map +1 -1
- package/dist/component/schema.d.ts +162 -9
- package/dist/component/schema.js +7 -0
- package/dist/component/schema.js.map +1 -1
- package/dist/component/usage/mutations.d.ts.map +1 -1
- package/dist/component/usage/mutations.js +4 -0
- package/dist/component/usage/mutations.js.map +1 -1
- package/dist/component/usage/queries.d.ts +2 -2
- package/dist/component/usage/schema.d.ts +21 -15
- package/dist/component/usage/schema.d.ts.map +1 -1
- package/dist/component/usage/schema.js +4 -2
- package/dist/component/usage/schema.js.map +1 -1
- package/dist/component/usageAllowance/helpers.d.ts +78 -0
- package/dist/component/usageAllowance/helpers.d.ts.map +1 -0
- package/dist/component/usageAllowance/helpers.js +99 -0
- package/dist/component/usageAllowance/helpers.js.map +1 -0
- package/dist/component/usageAllowance/mutations.d.ts +37 -0
- package/dist/component/usageAllowance/mutations.d.ts.map +1 -0
- package/dist/component/usageAllowance/mutations.js +99 -0
- package/dist/component/usageAllowance/mutations.js.map +1 -0
- package/dist/component/usageAllowance/queries.d.ts +36 -0
- package/dist/component/usageAllowance/queries.d.ts.map +1 -0
- package/dist/component/usageAllowance/queries.js +122 -0
- package/dist/component/usageAllowance/queries.js.map +1 -0
- package/dist/component/usageAllowance/reservations.d.ts +25 -0
- package/dist/component/usageAllowance/reservations.d.ts.map +1 -0
- package/dist/component/usageAllowance/reservations.js +150 -0
- package/dist/component/usageAllowance/reservations.js.map +1 -0
- package/dist/component/usageAllowance/schema.d.ts +77 -0
- package/dist/component/usageAllowance/schema.d.ts.map +1 -0
- package/dist/component/usageAllowance/schema.js +32 -0
- package/dist/component/usageAllowance/schema.js.map +1 -0
- package/dist/component/usageCorrections/accounting.d.ts +5 -0
- package/dist/component/usageCorrections/accounting.d.ts.map +1 -0
- package/dist/component/usageCorrections/accounting.js +55 -0
- package/dist/component/usageCorrections/accounting.js.map +1 -0
- package/dist/component/usageCorrections/cancellation.d.ts +6 -0
- package/dist/component/usageCorrections/cancellation.d.ts.map +1 -0
- package/dist/component/usageCorrections/cancellation.js +29 -0
- package/dist/component/usageCorrections/cancellation.js.map +1 -0
- package/dist/component/usageCorrections/helpers.d.ts +60 -0
- package/dist/component/usageCorrections/helpers.d.ts.map +1 -0
- package/dist/component/usageCorrections/helpers.js +52 -0
- package/dist/component/usageCorrections/helpers.js.map +1 -0
- package/dist/component/usageCorrections/invoice.d.ts +38 -0
- package/dist/component/usageCorrections/invoice.d.ts.map +1 -0
- package/dist/component/usageCorrections/invoice.js +82 -0
- package/dist/component/usageCorrections/invoice.js.map +1 -0
- package/dist/component/usageCorrections/mutations.d.ts +121 -0
- package/dist/component/usageCorrections/mutations.d.ts.map +1 -0
- package/dist/component/usageCorrections/mutations.js +256 -0
- package/dist/component/usageCorrections/mutations.js.map +1 -0
- package/dist/component/usageCorrections/queries.d.ts +115 -0
- package/dist/component/usageCorrections/queries.d.ts.map +1 -0
- package/dist/component/usageCorrections/queries.js +84 -0
- package/dist/component/usageCorrections/queries.js.map +1 -0
- package/dist/component/usageCorrections/schema.d.ts +248 -0
- package/dist/component/usageCorrections/schema.d.ts.map +1 -0
- package/dist/component/usageCorrections/schema.js +74 -0
- package/dist/component/usageCorrections/schema.js.map +1 -0
- package/dist/component/usageCredits/queries.d.ts +1 -1
- package/dist/component/usageCredits/queries.d.ts.map +1 -1
- package/dist/component/usageCredits/queries.js +6 -0
- package/dist/component/usageCredits/queries.js.map +1 -1
- package/dist/component/usageCredits/schema.d.ts +5 -5
- package/dist/component/usageCredits/schema.d.ts.map +1 -1
- package/dist/component/usageCredits/schema.js +1 -1
- package/dist/component/usageCredits/schema.js.map +1 -1
- package/dist/component/usageDelivery/fields.d.ts +2 -2
- package/dist/component/usageDelivery/fields.d.ts.map +1 -1
- package/dist/component/usageDelivery/fields.js +1 -1
- package/dist/component/usageDelivery/fields.js.map +1 -1
- package/dist/component/usageDelivery/helpers.d.ts +7 -6
- package/dist/component/usageDelivery/helpers.d.ts.map +1 -1
- package/dist/component/usageDelivery/mutations.d.ts +6 -6
- package/dist/component/usageDelivery/mutations.d.ts.map +1 -1
- package/dist/component/usageDelivery/mutations.js +9 -1
- package/dist/component/usageDelivery/mutations.js.map +1 -1
- package/dist/component/usageDelivery/queries.d.ts +8 -6
- package/dist/component/usageDelivery/queries.d.ts.map +1 -1
- package/dist/component/usageDelivery/schema.d.ts +4 -4
- package/dist/component/usageDelivery/steps.d.ts +2 -2
- package/dist/component/usageDelivery/steps.js +1 -1
- package/dist/component/usageDelivery/steps.js.map +1 -1
- package/dist/component/usageObservations/queries.d.ts.map +1 -1
- package/dist/component/usageObservations/queries.js +4 -2
- package/dist/component/usageObservations/queries.js.map +1 -1
- package/dist/component/usageSubscriptions/retirement.d.ts.map +1 -1
- package/dist/component/usageSubscriptions/retirement.js +24 -2
- package/dist/component/usageSubscriptions/retirement.js.map +1 -1
- package/docs/README.md +4 -0
- package/docs/usage-corrections.md +249 -0
- package/docs/usage-limits.md +217 -0
- package/package.json +3 -1
- package/src/client/usage/allowanceClient.test.ts +93 -0
- package/src/client/usage/allowanceClient.ts +134 -0
- package/src/client/usage/allowanceTerms.test.ts +131 -0
- package/src/client/usage/allowanceTerms.ts +172 -0
- package/src/client/usage/client.ts +2 -2
- package/src/client/usage/correctionClient.test.ts +153 -0
- package/src/client/usage/correctionClient.ts +62 -0
- package/src/client/usage/correctionCredits.test.ts +156 -0
- package/src/client/usage/correctionEligibility.ts +14 -0
- package/src/client/usage/correctionInvoice.test.ts +127 -0
- package/src/client/usage/correctionInvoice.ts +269 -0
- package/src/client/usage/correctionInvoiceProof.ts +40 -0
- package/src/client/usage/correctionProofs.ts +40 -0
- package/src/client/usage/correctionProvider.ts +326 -0
- package/src/client/usage/correctionRead.ts +73 -0
- package/src/client/usage/correctionRecovery.test.ts +113 -0
- package/src/client/usage/correctionTerms.ts +98 -0
- package/src/client/usage/correctionTransport.fixtures.ts +372 -0
- package/src/client/usage/index.ts +19 -0
- package/src/client/usage/observationClient.ts +20 -6
- package/src/client/usage/records.ts +7 -1
- package/src/client/usage/summary.ts +12 -4
- package/src/client/usageExports.ts +19 -0
- package/src/component/_generated/api.ts +20 -0
- package/src/component/_generated/component.ts +423 -1
- package/src/component/accountClosure/mutations.ts +17 -0
- package/src/component/schema.ts +14 -0
- package/src/component/usage/allowance.test.ts +435 -0
- package/src/component/usage/mutations.ts +13 -0
- package/src/component/usage/schema.ts +6 -1
- package/src/component/usageAllowance/helpers.ts +137 -0
- package/src/component/usageAllowance/mutations.ts +139 -0
- package/src/component/usageAllowance/queries.ts +140 -0
- package/src/component/usageAllowance/reservations.ts +220 -0
- package/src/component/usageAllowance/schema.ts +37 -0
- package/src/component/usageCorrections/accounting.ts +79 -0
- package/src/component/usageCorrections/cancellation.ts +32 -0
- package/src/component/usageCorrections/corrections.test.ts +389 -0
- package/src/component/usageCorrections/helpers.ts +57 -0
- package/src/component/usageCorrections/invoice.ts +103 -0
- package/src/component/usageCorrections/mutations.ts +278 -0
- package/src/component/usageCorrections/queries.ts +94 -0
- package/src/component/usageCorrections/schema.ts +90 -0
- package/src/component/usageCredits/queries.ts +4 -0
- package/src/component/usageCredits/schema.ts +1 -0
- package/src/component/usageDelivery/fields.ts +1 -0
- package/src/component/usageDelivery/mutations.ts +8 -3
- package/src/component/usageDelivery/steps.ts +1 -1
- package/src/component/usageObservations/queries.ts +5 -2
- package/src/component/usageSubscriptions/retirement.ts +31 -2
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"correctionProofs.d.ts","sourceRoot":"","sources":["../../../src/client/usage/correctionProofs.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,eAAO,MAAM,iBAAiB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;oBAsC5B,CAAC"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
export const correctionOutcome = z.union([
|
|
3
|
+
z.strictObject({
|
|
4
|
+
status: z.enum(["pending", "complete"]),
|
|
5
|
+
eventName: z.string().min(1).max(100),
|
|
6
|
+
identifier: z.string().min(1).max(100),
|
|
7
|
+
livemode: z.boolean(),
|
|
8
|
+
nativeAdjustmentId: z.string().min(1).max(100).nullable(),
|
|
9
|
+
creditBackingVerified: z.boolean(),
|
|
10
|
+
billingSafe: z.boolean().default(false),
|
|
11
|
+
invoiceId: z
|
|
12
|
+
.string()
|
|
13
|
+
.regex(/^in_[a-zA-Z0-9]+$/)
|
|
14
|
+
.max(100)
|
|
15
|
+
.optional(),
|
|
16
|
+
}),
|
|
17
|
+
z.strictObject({
|
|
18
|
+
status: z.literal("local_complete"),
|
|
19
|
+
creditBackingVerified: z.literal(true),
|
|
20
|
+
}),
|
|
21
|
+
z.strictObject({
|
|
22
|
+
status: z.enum(["held", "invoice_adjustment_required", "unsupported"]),
|
|
23
|
+
reason: z.enum([
|
|
24
|
+
"native_cancellation_expired",
|
|
25
|
+
"original_delivery_unresolved",
|
|
26
|
+
"provider_unavailable",
|
|
27
|
+
"provider_outcome_unknown",
|
|
28
|
+
"billing_period_closed",
|
|
29
|
+
"native_invoice_finalized",
|
|
30
|
+
"native_invoice_history_incomplete",
|
|
31
|
+
"credit_backing_requires_reconciliation",
|
|
32
|
+
"native_cancellation_rejected",
|
|
33
|
+
]),
|
|
34
|
+
invoiceId: z
|
|
35
|
+
.string()
|
|
36
|
+
.regex(/^in_[a-zA-Z0-9]+$/)
|
|
37
|
+
.max(100)
|
|
38
|
+
.optional(),
|
|
39
|
+
}),
|
|
40
|
+
]);
|
|
41
|
+
//# sourceMappingURL=correctionProofs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"correctionProofs.js","sourceRoot":"","sources":["../../../src/client/usage/correctionProofs.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,CAAC,KAAK,CAAC;IACvC,CAAC,CAAC,YAAY,CAAC;QACb,MAAM,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,SAAS,EAAE,UAAU,CAAC,CAAC;QACvC,SAAS,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC;QACrC,UAAU,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC;QACtC,QAAQ,EAAE,CAAC,CAAC,OAAO,EAAE;QACrB,kBAAkB,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,QAAQ,EAAE;QACzD,qBAAqB,EAAE,CAAC,CAAC,OAAO,EAAE;QAClC,WAAW,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC;QACvC,SAAS,EAAE,CAAC;aACT,MAAM,EAAE;aACR,KAAK,CAAC,mBAAmB,CAAC;aAC1B,GAAG,CAAC,GAAG,CAAC;aACR,QAAQ,EAAE;KACd,CAAC;IACF,CAAC,CAAC,YAAY,CAAC;QACb,MAAM,EAAE,CAAC,CAAC,OAAO,CAAC,gBAAgB,CAAC;QACnC,qBAAqB,EAAE,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC;KACvC,CAAC;IACF,CAAC,CAAC,YAAY,CAAC;QACb,MAAM,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,6BAA6B,EAAE,aAAa,CAAC,CAAC;QACtE,MAAM,EAAE,CAAC,CAAC,IAAI,CAAC;YACb,6BAA6B;YAC7B,8BAA8B;YAC9B,sBAAsB;YACtB,0BAA0B;YAC1B,uBAAuB;YACvB,0BAA0B;YAC1B,mCAAmC;YACnC,wCAAwC;YACxC,8BAA8B;SAC/B,CAAC;QACF,SAAS,EAAE,CAAC;aACT,MAAM,EAAE;aACR,KAAK,CAAC,mBAAmB,CAAC;aAC1B,GAAG,CAAC,GAAG,CAAC;aACR,QAAQ,EAAE;KACd,CAAC;CACH,CAAC,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { Component, RunCtx } from "../helpers.js";
|
|
2
|
+
import type { UsageDeliveryProviderOptions } from "./deliveryProvider.js";
|
|
3
|
+
import { type UsageCorrectionOptions } from "./correctionTerms.js";
|
|
4
|
+
/** All native context comes from the immutable component event, never browser claims. */
|
|
5
|
+
export declare function requestUsageCorrection(component: Component, ctx: RunCtx, input: UsageCorrectionOptions, options?: UsageDeliveryProviderOptions): Promise<import("./correctionTerms.js").UsageCorrectionView>;
|
|
6
|
+
//# sourceMappingURL=correctionProvider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"correctionProvider.d.ts","sourceRoot":"","sources":["../../../src/client/usage/correctionProvider.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAKvD,OAAO,KAAK,EAAE,4BAA4B,EAAE,MAAM,uBAAuB,CAAC;AAK1E,OAAO,EAGL,KAAK,sBAAsB,EAC5B,MAAM,sBAAsB,CAAC;AA8E9B,yFAAyF;AACzF,wBAAsB,sBAAsB,CAC1C,SAAS,EAAE,SAAS,EACpB,GAAG,EAAE,MAAM,EACX,KAAK,EAAE,sBAAsB,EAC7B,OAAO,GAAE,4BAAiC,+DAkO3C"}
|
|
@@ -0,0 +1,243 @@
|
|
|
1
|
+
import { locallyCancelable } from "./correctionEligibility.js";
|
|
2
|
+
import Stripe from "stripe";
|
|
3
|
+
import { runMutationOrThrow } from "../helpers.js";
|
|
4
|
+
import { componentRef } from "../webhooks/helpers.js";
|
|
5
|
+
import { verifyRealm, verifyMeter } from "./catalogTypes.js";
|
|
6
|
+
import { verifyCreditDelivery } from "./creditDelivery.js";
|
|
7
|
+
import { subscriptionSnapshot } from "../../component/usage/helpers.js";
|
|
8
|
+
import { correctionRequest, correctionView, } from "./correctionTerms.js";
|
|
9
|
+
const customerId = (customer) => typeof customer === "string" ? customer : customer?.id;
|
|
10
|
+
async function finalizedInvoice(stripe, record, subscriptionId, receivedAt) {
|
|
11
|
+
const invoices = await stripe.invoices.list({
|
|
12
|
+
subscription: subscriptionId,
|
|
13
|
+
limit: 100,
|
|
14
|
+
});
|
|
15
|
+
if (invoices.has_more !== false)
|
|
16
|
+
return { held: true };
|
|
17
|
+
for (const invoice of invoices.data) {
|
|
18
|
+
if (!/^in_[a-zA-Z0-9]+$/.test(invoice.id) ||
|
|
19
|
+
invoice.currency !== record.binding.plan.rate.currency ||
|
|
20
|
+
invoice.parent?.type !== "subscription_details" ||
|
|
21
|
+
(typeof invoice.parent.subscription_details?.subscription === "string"
|
|
22
|
+
? invoice.parent.subscription_details.subscription
|
|
23
|
+
: invoice.parent.subscription_details?.subscription?.id) !==
|
|
24
|
+
subscriptionId ||
|
|
25
|
+
invoice.livemode !== record.scope.livemode ||
|
|
26
|
+
invoice.customer_account !== record.scope.customerAccount ||
|
|
27
|
+
customerId(invoice.customer) !== record.binding.stripeCustomerId)
|
|
28
|
+
return { held: true };
|
|
29
|
+
if (invoice.status === "draft")
|
|
30
|
+
continue;
|
|
31
|
+
const finalizedAt = invoice.status_transitions?.finalized_at;
|
|
32
|
+
if (!["open", "paid", "void", "uncollectible"].includes(invoice.status ?? "") ||
|
|
33
|
+
!Number.isSafeInteger(finalizedAt) ||
|
|
34
|
+
finalizedAt < 0)
|
|
35
|
+
return { held: true };
|
|
36
|
+
if (finalizedAt < receivedAt)
|
|
37
|
+
continue;
|
|
38
|
+
if (invoice.lines.has_more !== false)
|
|
39
|
+
return { held: true };
|
|
40
|
+
for (const line of invoice.lines.data) {
|
|
41
|
+
const priceId = line.pricing?.price_details?.price;
|
|
42
|
+
if (!priceId)
|
|
43
|
+
return { held: true };
|
|
44
|
+
if (priceId !== record.binding.stripePriceId)
|
|
45
|
+
continue;
|
|
46
|
+
if (!Number.isSafeInteger(line.period?.start) ||
|
|
47
|
+
!Number.isSafeInteger(line.period?.end) ||
|
|
48
|
+
line.period.end <= line.period.start)
|
|
49
|
+
return { held: true };
|
|
50
|
+
if (line.period.start > record.occurredAt ||
|
|
51
|
+
line.period.end <= record.occurredAt)
|
|
52
|
+
continue;
|
|
53
|
+
const quantity = line.quantity_decimal != null
|
|
54
|
+
? line.quantity_decimal.toString()
|
|
55
|
+
: typeof line.quantity === "number" &&
|
|
56
|
+
Number.isSafeInteger(line.quantity) &&
|
|
57
|
+
line.quantity >= 0
|
|
58
|
+
? String(line.quantity)
|
|
59
|
+
: null;
|
|
60
|
+
if (quantity === null ||
|
|
61
|
+
quantity.length > 64 ||
|
|
62
|
+
!/^(0|[1-9]\d*)(\.\d+)?$/.test(quantity))
|
|
63
|
+
return { held: true };
|
|
64
|
+
if (!/^0(?:\.0+)?$/.test(quantity))
|
|
65
|
+
return { held: false, invoiceId: invoice.id };
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
return { held: false };
|
|
69
|
+
}
|
|
70
|
+
/** All native context comes from the immutable component event, never browser claims. */
|
|
71
|
+
export async function requestUsageCorrection(component, ctx, input, options = {}) {
|
|
72
|
+
const request = correctionRequest.parse(input);
|
|
73
|
+
let row = (await runMutationOrThrow(ctx, componentRef(component, "usageCorrections/mutations/prepare"), { inputJson: JSON.stringify(request) }));
|
|
74
|
+
const claimed = (await runMutationOrThrow(ctx, componentRef(component, "usageCorrections/mutations/claim"), { key: row.key }));
|
|
75
|
+
const read = async () => (await ctx.runQuery(componentRef(component, "usageCorrections/queries/get"), {
|
|
76
|
+
scope: request.scope,
|
|
77
|
+
eventId: request.eventId,
|
|
78
|
+
correctionId: request.correctionId,
|
|
79
|
+
}));
|
|
80
|
+
if (claimed.kind !== "ready")
|
|
81
|
+
return correctionView(await read());
|
|
82
|
+
const save = async (outcome) => {
|
|
83
|
+
row = (await runMutationOrThrow(ctx, componentRef(component, "usageCorrections/mutations/save"), {
|
|
84
|
+
key: row.key,
|
|
85
|
+
attempt: claimed.attempt,
|
|
86
|
+
outcomeJson: JSON.stringify(outcome),
|
|
87
|
+
}));
|
|
88
|
+
return correctionView(row);
|
|
89
|
+
};
|
|
90
|
+
if (!options.stripeSecretKey)
|
|
91
|
+
return save({ status: "held", reason: "provider_unavailable" });
|
|
92
|
+
const record = JSON.parse(row.recordJson), subscription = subscriptionSnapshot(row.subscriptionJson);
|
|
93
|
+
const stripe = new Stripe(options.stripeSecretKey, {
|
|
94
|
+
apiVersion: record.binding.apiVersion,
|
|
95
|
+
maxNetworkRetries: 0,
|
|
96
|
+
timeout: 15000,
|
|
97
|
+
...(options.httpClient ? { httpClient: options.httpClient } : {}),
|
|
98
|
+
});
|
|
99
|
+
let writing = false, outcome;
|
|
100
|
+
try {
|
|
101
|
+
await verifyRealm(stripe, {
|
|
102
|
+
stripeAccountId: record.scope.stripeAccountId,
|
|
103
|
+
livemode: record.scope.livemode,
|
|
104
|
+
});
|
|
105
|
+
const customer = await stripe.customers.retrieve(record.scope.customerAccount);
|
|
106
|
+
if (customer.deleted ||
|
|
107
|
+
customer.id !== record.binding.stripeCustomerId ||
|
|
108
|
+
customer.customer_account !== record.scope.customerAccount ||
|
|
109
|
+
customer.livemode !== record.scope.livemode)
|
|
110
|
+
throw new Error("Native correction payer mismatch");
|
|
111
|
+
const saved = (await ctx.runQuery(componentRef(component, "usageDelivery/queries/snapshot"), { scope: request.scope, eventId: request.eventId }));
|
|
112
|
+
if (saved.outbox.correctionKey !== row.key)
|
|
113
|
+
throw new Error("Native correction intent mismatch");
|
|
114
|
+
const unsent = locallyCancelable(saved.outbox);
|
|
115
|
+
if (unsent) {
|
|
116
|
+
await verifyCreditDelivery(stripe, component, ctx, saved.event, record);
|
|
117
|
+
return save({ status: "local_complete", creditBackingVerified: true });
|
|
118
|
+
}
|
|
119
|
+
if (!saved.outbox.receipt ||
|
|
120
|
+
saved.outbox.state === "sending" ||
|
|
121
|
+
saved.outbox.state === "unknown")
|
|
122
|
+
return save({ status: "held", reason: "original_delivery_unresolved" });
|
|
123
|
+
const now = Date.now() / 1000;
|
|
124
|
+
if (now - saved.outbox.receipt.created >= 23 * 3600)
|
|
125
|
+
return save({
|
|
126
|
+
status: "invoice_adjustment_required",
|
|
127
|
+
reason: "native_cancellation_expired",
|
|
128
|
+
});
|
|
129
|
+
if (now + 15 >= subscription.period.end - 60)
|
|
130
|
+
return save({
|
|
131
|
+
status: "invoice_adjustment_required",
|
|
132
|
+
reason: "billing_period_closed",
|
|
133
|
+
});
|
|
134
|
+
const [meter, native] = await Promise.all([
|
|
135
|
+
stripe.billing.meters.retrieve(record.scope.meterId),
|
|
136
|
+
stripe.subscriptions.retrieve(subscription.subscriptionId),
|
|
137
|
+
]);
|
|
138
|
+
if (meter.id !== record.scope.meterId)
|
|
139
|
+
throw new Error("Native correction meter identity mismatch");
|
|
140
|
+
verifyMeter(meter, {
|
|
141
|
+
scope: record.scope,
|
|
142
|
+
plan: record.binding.plan,
|
|
143
|
+
eventName: record.binding.eventName,
|
|
144
|
+
displayName: meter.display_name,
|
|
145
|
+
});
|
|
146
|
+
const item = native.items.data.find((item) => item.id === subscription.subscriptionItemId);
|
|
147
|
+
if (native.id !== subscription.subscriptionId ||
|
|
148
|
+
native.livemode !== record.scope.livemode ||
|
|
149
|
+
native.customer_account !== record.scope.customerAccount ||
|
|
150
|
+
customerId(native.customer) !== record.binding.stripeCustomerId ||
|
|
151
|
+
native.status !== "active" ||
|
|
152
|
+
native.items.has_more ||
|
|
153
|
+
!item ||
|
|
154
|
+
item.price.id !== record.binding.stripePriceId ||
|
|
155
|
+
item.current_period_start !== subscription.period.start ||
|
|
156
|
+
item.current_period_end !== subscription.period.end ||
|
|
157
|
+
native.billing_thresholds)
|
|
158
|
+
throw new Error("Original native correction period mismatch");
|
|
159
|
+
const invoice = await finalizedInvoice(stripe, record, subscription.subscriptionId, saved.outbox.receipt.created);
|
|
160
|
+
if (invoice.held)
|
|
161
|
+
return save({
|
|
162
|
+
status: "held",
|
|
163
|
+
reason: "native_invoice_history_incomplete",
|
|
164
|
+
});
|
|
165
|
+
if (invoice.invoiceId)
|
|
166
|
+
return save({
|
|
167
|
+
status: "invoice_adjustment_required",
|
|
168
|
+
reason: "native_invoice_finalized",
|
|
169
|
+
invoiceId: invoice.invoiceId,
|
|
170
|
+
});
|
|
171
|
+
const current = await read();
|
|
172
|
+
const sendAt = Date.now() / 1000;
|
|
173
|
+
if (current.attempt !== claimed.attempt ||
|
|
174
|
+
[
|
|
175
|
+
"confirmed",
|
|
176
|
+
"unsupported",
|
|
177
|
+
"provider_accepted",
|
|
178
|
+
"invoice_adjustment_required",
|
|
179
|
+
].includes(current.state) ||
|
|
180
|
+
(current.leaseUntil ?? 0) <= sendAt + 60)
|
|
181
|
+
return correctionView(current);
|
|
182
|
+
if (sendAt + 15 >= subscription.period.end - 60)
|
|
183
|
+
return save({
|
|
184
|
+
status: "invoice_adjustment_required",
|
|
185
|
+
reason: "billing_period_closed",
|
|
186
|
+
});
|
|
187
|
+
if (sendAt - saved.outbox.receipt.created >= 23 * 3600 ||
|
|
188
|
+
sendAt - (current.attemptedAt ?? current.firstAttemptAt) >= 23 * 3600)
|
|
189
|
+
return save({
|
|
190
|
+
status: "invoice_adjustment_required",
|
|
191
|
+
reason: "native_cancellation_expired",
|
|
192
|
+
});
|
|
193
|
+
writing = true;
|
|
194
|
+
const response = await stripe.billing.meterEventAdjustments.create({
|
|
195
|
+
event_name: record.binding.eventName,
|
|
196
|
+
type: "cancel",
|
|
197
|
+
cancel: { identifier: saved.outbox.providerIdentifier },
|
|
198
|
+
}, { idempotencyKey: `bs_usage_correction_${row.key}` });
|
|
199
|
+
if (response.object !== "billing.meter_event_adjustment" ||
|
|
200
|
+
response.type !== "cancel" ||
|
|
201
|
+
response.event_name !== record.binding.eventName ||
|
|
202
|
+
response.cancel?.identifier !== saved.outbox.providerIdentifier ||
|
|
203
|
+
response.livemode !== record.scope.livemode ||
|
|
204
|
+
!["pending", "complete"].includes(response.status))
|
|
205
|
+
throw new Error("Native correction response mismatch");
|
|
206
|
+
let creditBackingVerified = record.binding.plan.model !== "prepaid";
|
|
207
|
+
let billingSafe = response.status === "complete" &&
|
|
208
|
+
Date.now() / 1000 + 15 < subscription.period.end - 60;
|
|
209
|
+
let invoiceId;
|
|
210
|
+
if (response.status === "complete") {
|
|
211
|
+
const after = await finalizedInvoice(stripe, record, subscription.subscriptionId, saved.outbox.receipt.created);
|
|
212
|
+
invoiceId = after.invoiceId;
|
|
213
|
+
billingSafe = billingSafe && !after.held && !invoiceId;
|
|
214
|
+
if (record.binding.plan.model === "prepaid") {
|
|
215
|
+
try {
|
|
216
|
+
await verifyCreditDelivery(stripe, component, ctx, saved.event, record);
|
|
217
|
+
creditBackingVerified = true;
|
|
218
|
+
}
|
|
219
|
+
catch {
|
|
220
|
+
creditBackingVerified = false;
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
outcome = {
|
|
225
|
+
status: response.status,
|
|
226
|
+
eventName: response.event_name,
|
|
227
|
+
identifier: response.cancel.identifier,
|
|
228
|
+
livemode: response.livemode,
|
|
229
|
+
nativeAdjustmentId: null,
|
|
230
|
+
creditBackingVerified,
|
|
231
|
+
billingSafe,
|
|
232
|
+
...(invoiceId ? { invoiceId } : {}),
|
|
233
|
+
};
|
|
234
|
+
}
|
|
235
|
+
catch {
|
|
236
|
+
outcome = {
|
|
237
|
+
status: "held",
|
|
238
|
+
reason: writing ? "provider_outcome_unknown" : "provider_unavailable",
|
|
239
|
+
};
|
|
240
|
+
}
|
|
241
|
+
return save(outcome);
|
|
242
|
+
}
|
|
243
|
+
//# sourceMappingURL=correctionProvider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"correctionProvider.js","sourceRoot":"","sources":["../../../src/client/usage/correctionProvider.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,4BAA4B,CAAC;AAC/D,OAAO,MAAM,MAAM,QAAQ,CAAC;AAE5B,OAAO,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AACnD,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAKtD,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAC7D,OAAO,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAC3D,OAAO,EAAE,oBAAoB,EAAE,MAAM,kCAAkC,CAAC;AACxE,OAAO,EACL,iBAAiB,EACjB,cAAc,GAEf,MAAM,sBAAsB,CAAC;AAI9B,MAAM,UAAU,GAAG,CAAC,QAAwC,EAAE,EAAE,CAC9D,OAAO,QAAQ,KAAK,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC;AACzD,KAAK,UAAU,gBAAgB,CAC7B,MAAc,EACd,MAA2B,EAC3B,cAAsB,EACtB,UAAkB;IAElB,MAAM,QAAQ,GAAG,MAAM,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC;QAC1C,YAAY,EAAE,cAAc;QAC5B,KAAK,EAAE,GAAG;KACX,CAAC,CAAC;IACH,IAAI,QAA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kB,EAAE,IAAI;YACxB,qBAAqB;YACrB,WAAW;YACX,GAAG,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,SAAS,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;SACpC,CAAC;IACJ,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,GAAG;YACR,MAAM,EAAE,MAAM;YACd,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC,0BAA0B,CAAC,CAAC,CAAC,sBAAsB;SACtE,CAAC;IACJ,CAAC;IACD,OAAO,IAAI,CAAC,OAAO,CAAC,CAAC;AACvB,CAAC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { PreparedUsageRecord } from "./records.js";
|
|
2
|
+
import type { UsageSubscriptionBinding } from "./boundaries.js";
|
|
3
|
+
import type { Component, RunCtx } from "../helpers.js";
|
|
4
|
+
import type { Doc } from "../../component/_generated/dataModel.js";
|
|
5
|
+
import { type UsagePeriod } from "./boundaries.js";
|
|
6
|
+
import { type UsageScope } from "./records.js";
|
|
7
|
+
export type UsageCorrectionHistoryRecord = Doc<"usageCorrectionHistory"> & {
|
|
8
|
+
record: PreparedUsageRecord;
|
|
9
|
+
subscription: UsageSubscriptionBinding;
|
|
10
|
+
evidence: unknown;
|
|
11
|
+
recordedAt: number;
|
|
12
|
+
};
|
|
13
|
+
export type UsageCorrectionHistoryPage = {
|
|
14
|
+
records: UsageCorrectionHistoryRecord[];
|
|
15
|
+
cursor: string | null;
|
|
16
|
+
isDone: boolean;
|
|
17
|
+
coverage: "recorded" | "not_recorded";
|
|
18
|
+
legacyHistoryMissing: boolean;
|
|
19
|
+
};
|
|
20
|
+
export declare function readCorrectionEvidence(component: Component, ctx: RunCtx, input: {
|
|
21
|
+
scope: UsageScope;
|
|
22
|
+
eventId?: string;
|
|
23
|
+
period?: UsagePeriod;
|
|
24
|
+
limit: number;
|
|
25
|
+
cursor: string | null;
|
|
26
|
+
}): Promise<UsageCorrectionHistoryPage>;
|
|
27
|
+
//# sourceMappingURL=correctionRead.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"correctionRead.d.ts","sourceRoot":"","sources":["../../../src/client/usage/correctionRead.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AACxD,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,iBAAiB,CAAC;AAEhE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAEvD,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,yCAAyC,CAAC;AACnE,OAAO,EAA4B,KAAK,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAC7E,OAAO,EAAe,KAAK,UAAU,EAAE,MAAM,cAAc,CAAC;AAE5D,MAAM,MAAM,4BAA4B,GAAG,GAAG,CAAC,wBAAwB,CAAC,GAAG;IACzE,MAAM,EAAE,mBAAmB,CAAC;IAC5B,YAAY,EAAE,wBAAwB,CAAC;IACvC,QAAQ,EAAE,OAAO,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;CACpB,CAAC;AACF,MAAM,MAAM,0BAA0B,GAAG;IACvC,OAAO,EAAE,4BAA4B,EAAE,CAAC;IACxC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,MAAM,EAAE,OAAO,CAAC;IAChB,QAAQ,EAAE,UAAU,GAAG,cAAc,CAAC;IACtC,oBAAoB,EAAE,OAAO,CAAC;CAC/B,CAAC;AACF,wBAAsB,sBAAsB,CAC1C,SAAS,EAAE,SAAS,EACpB,GAAG,EAAE,MAAM,EACX,KAAK,EAAE;IACL,KAAK,EAAE,UAAU,CAAC;IAClB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,MAAM,CAAC,EAAE,WAAW,CAAC;IACrB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;CACvB,GACA,OAAO,CAAC,0BAA0B,CAAC,CAwCrC"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { subscriptionSnapshot } from "../../component/usage/helpers.js";
|
|
2
|
+
import { componentRef } from "../webhooks/helpers.js";
|
|
3
|
+
import { validateUsagePageRequest } from "./boundaries.js";
|
|
4
|
+
import { scopeSchema } from "./records.js";
|
|
5
|
+
import { z } from "zod";
|
|
6
|
+
export async function readCorrectionEvidence(component, ctx, input) {
|
|
7
|
+
const page = validateUsagePageRequest({
|
|
8
|
+
period: input.period ?? { start: 0, end: 1 },
|
|
9
|
+
limit: input.limit,
|
|
10
|
+
cursor: input.cursor,
|
|
11
|
+
});
|
|
12
|
+
const scope = scopeSchema.parse(input.scope);
|
|
13
|
+
const result = (await ctx.runQuery(componentRef(component, input.eventId
|
|
14
|
+
? "usageCorrections/queries/readHistory"
|
|
15
|
+
: "usageCorrections/queries/periodHistory"), {
|
|
16
|
+
scope,
|
|
17
|
+
...(input.eventId
|
|
18
|
+
? { eventId: z.string().min(1).max(100).parse(input.eventId) }
|
|
19
|
+
: { period: page.period }),
|
|
20
|
+
paginationOpts: { numItems: page.limit, cursor: page.cursor },
|
|
21
|
+
}));
|
|
22
|
+
return {
|
|
23
|
+
records: result.page.map((row) => ({
|
|
24
|
+
...row,
|
|
25
|
+
record: JSON.parse(row.recordJson),
|
|
26
|
+
subscription: subscriptionSnapshot(row.subscriptionJson),
|
|
27
|
+
evidence: JSON.parse(row.evidenceJson),
|
|
28
|
+
recordedAt: row.at,
|
|
29
|
+
})),
|
|
30
|
+
cursor: result.isDone ? null : result.continueCursor,
|
|
31
|
+
isDone: result.isDone,
|
|
32
|
+
coverage: result.page.length ? "recorded" : "not_recorded",
|
|
33
|
+
legacyHistoryMissing: result.legacyHistoryMissing ?? false,
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=correctionRead.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"correctionRead.js","sourceRoot":"","sources":["../../../src/client/usage/correctionRead.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AO;QACL,OAAO,EAAE,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC;YACjC,GAAG,GAAG;YACN,MAAM,EAAE,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,UAAU,CAAwB;YACzD,YAAY,EAAE,oBAAoB,CAAC,GAAG,CAAC,gBAAgB,CAAC;YACxD,QAAQ,EAAE,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,YAAY,CAAY;YACjD,UAAU,EAAE,GAAG,CAAC,EAAE;SACnB,CAAC,CAAC;QACH,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,cAAc;QACpD,MAAM,EAAE,MAAM,CAAC,MAAM;QACrB,QAAQ,EAAE,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,cAAc;QAC1D,oBAAoB,EAAE,MAAM,CAAC,oBAAoB,IAAI,KAAK;KAC3D,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { invoiceCorrectionProof } from "./correctionInvoiceProof.js";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
export declare const correctionRequest: z.ZodObject<{
|
|
4
|
+
scope: z.ZodObject<{
|
|
5
|
+
stripeAccountId: z.ZodString;
|
|
6
|
+
customerAccount: z.ZodString;
|
|
7
|
+
meterId: z.ZodString;
|
|
8
|
+
livemode: z.ZodBoolean;
|
|
9
|
+
}, z.core.$strict>;
|
|
10
|
+
eventId: z.ZodString;
|
|
11
|
+
correctionId: z.ZodString;
|
|
12
|
+
actor: z.ZodString;
|
|
13
|
+
reason: z.ZodString;
|
|
14
|
+
operation: z.ZodLiteral<"cancel">;
|
|
15
|
+
quantity: z.ZodOptional<z.ZodString>;
|
|
16
|
+
}, z.core.$strict>;
|
|
17
|
+
export type UsageCorrectionOptions = z.infer<typeof correctionRequest>;
|
|
18
|
+
export declare const correctionState: z.ZodEnum<{
|
|
19
|
+
confirmed: "confirmed";
|
|
20
|
+
held: "held";
|
|
21
|
+
invoice_adjustment_required: "invoice_adjustment_required";
|
|
22
|
+
provider_accepted: "provider_accepted";
|
|
23
|
+
requested: "requested";
|
|
24
|
+
unsupported: "unsupported";
|
|
25
|
+
}>;
|
|
26
|
+
export type UsageInvoiceCorrectionEvidence = z.infer<typeof invoiceCorrectionProof>;
|
|
27
|
+
export type UsageCorrectionView = {
|
|
28
|
+
cashCollection: "none";
|
|
29
|
+
invoiceAdjustment: UsageInvoiceCorrectionEvidence | null;
|
|
30
|
+
observedAt: number;
|
|
31
|
+
nativeCreditNoteStatus: "issued" | "void" | null;
|
|
32
|
+
resolution: "event_cancellation" | "invoice_credit";
|
|
33
|
+
correctionId: string;
|
|
34
|
+
eventId: string;
|
|
35
|
+
sourceEventId: string;
|
|
36
|
+
state: z.infer<typeof correctionState>;
|
|
37
|
+
reason: string;
|
|
38
|
+
actor: string;
|
|
39
|
+
requestedReason: string;
|
|
40
|
+
quantity: string;
|
|
41
|
+
nativeAdjustmentId: string | null;
|
|
42
|
+
nativeStatus: "pending" | "complete" | null;
|
|
43
|
+
invoiceId: string | null;
|
|
44
|
+
creditNoteId: string | null;
|
|
45
|
+
refundId: string | null;
|
|
46
|
+
cashConsequence: "none" | "operator_resolution_required" | "verified_external_adjustment";
|
|
47
|
+
restoredQuantity: string;
|
|
48
|
+
};
|
|
49
|
+
export declare function correctionView(row: import("../../component/_generated/dataModel.js").Doc<"usageCorrections">): UsageCorrectionView;
|
|
50
|
+
export declare const invoiceCorrectionOptions: z.ZodObject<{
|
|
51
|
+
scope: z.ZodObject<{
|
|
52
|
+
stripeAccountId: z.ZodString;
|
|
53
|
+
customerAccount: z.ZodString;
|
|
54
|
+
meterId: z.ZodString;
|
|
55
|
+
livemode: z.ZodBoolean;
|
|
56
|
+
}, z.core.$strict>;
|
|
57
|
+
eventId: z.ZodString;
|
|
58
|
+
correctionId: z.ZodString;
|
|
59
|
+
invoiceId: z.ZodString;
|
|
60
|
+
creditNoteId: z.ZodString;
|
|
61
|
+
amount: z.ZodNumber;
|
|
62
|
+
}, z.core.$strict>;
|
|
63
|
+
export type UsageInvoiceCorrectionOptions = z.infer<typeof invoiceCorrectionOptions>;
|
|
64
|
+
//# sourceMappingURL=correctionTerms.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"correctionTerms.d.ts","sourceRoot":"","sources":["../../../src/client/usage/correctionTerms.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AACrE,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,eAAO,MAAM,iBAAiB;;;;;;;;;;;;;kBAQ5B,CAAC;AACH,MAAM,MAAM,sBAAsB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,iBAAiB,CAAC,CAAC;AACvE,eAAO,MAAM,eAAe;;;;;;;EAO1B,CAAC;AACH,MAAM,MAAM,8BAA8B,GAAG,CAAC,CAAC,KAAK,CAClD,OAAO,sBAAsB,CAC9B,CAAC;AACF,MAAM,MAAM,mBAAmB,GAAG;IAChC,cAAc,EAAE,MAAM,CAAC;IACvB,iBAAiB,EAAE,8BAA8B,GAAG,IAAI,CAAC;IACzD,UAAU,EAAE,MAAM,CAAC;IACnB,sBAAsB,EAAE,QAAQ,GAAG,MAAM,GAAG,IAAI,CAAC;IACjD,UAAU,EAAE,oBAAoB,GAAG,gBAAgB,CAAC;IACpD,YAAY,EAAE,MAAM,CAAC;IACrB,OAAO,EAAE,MAAM,CAAC;IAChB,aAAa,EAAE,MAAM,CAAC;IACtB,KAAK,EAAE,CAAC,CAAC,KAAK,CAAC,OAAO,eAAe,CAAC,CAAC;IACvC,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,eAAe,EAAE,MAAM,CAAC;IACxB,QAAQ,EAAE,MAAM,CAAC;IACjB,kBAAkB,EAAE,MAAM,GAAG,IAAI,CAAC;IAClC,YAAY,EAAE,SAAS,GAAG,UAAU,GAAG,IAAI,CAAC;IAC5C,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,YAAY,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,eAAe,EACb,MAAM,GAAG,8BAA8B,GAAG,8BAA8B,CAAC;IAC3E,gBAAgB,EAAE,MAAM,CAAC;CAC1B,CAAC;AAEF,wBAAgB,cAAc,CAC5B,GAAG,EAAE,OAAO,yCAAyC,EAAE,GAAG,CAAC,kBAAkB,CAAC,GAC7E,mBAAmB,CA6BrB;AAED,eAAO,MAAM,wBAAwB;;;;;;;;;;;;kBAanC,CAAC;AACH,MAAM,MAAM,6BAA6B,GAAG,CAAC,CAAC,KAAK,CACjD,OAAO,wBAAwB,CAChC,CAAC"}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { invoiceCorrectionProof } from "./correctionInvoiceProof.js";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
import { scopeSchema } from "./records.js";
|
|
4
|
+
export const correctionRequest = z.strictObject({
|
|
5
|
+
scope: scopeSchema,
|
|
6
|
+
eventId: z.string().min(1).max(100),
|
|
7
|
+
correctionId: z.string().min(1).max(100),
|
|
8
|
+
actor: z.string().min(1).max(200),
|
|
9
|
+
reason: z.string().min(1).max(500),
|
|
10
|
+
operation: z.literal("cancel"),
|
|
11
|
+
quantity: z.string().optional(),
|
|
12
|
+
});
|
|
13
|
+
export const correctionState = z.enum([
|
|
14
|
+
"requested",
|
|
15
|
+
"provider_accepted",
|
|
16
|
+
"confirmed",
|
|
17
|
+
"held",
|
|
18
|
+
"unsupported",
|
|
19
|
+
"invoice_adjustment_required",
|
|
20
|
+
]);
|
|
21
|
+
export function correctionView(row) {
|
|
22
|
+
const request = correctionRequest.parse(JSON.parse(row.inputJson));
|
|
23
|
+
const invoiceAdjustment = row.adjustmentJson
|
|
24
|
+
? invoiceCorrectionProof.parse(JSON.parse(row.adjustmentJson))
|
|
25
|
+
: null;
|
|
26
|
+
if (invoiceAdjustment && row.nativeCreditNoteStatus)
|
|
27
|
+
invoiceAdjustment.creditNoteStatus = row.nativeCreditNoteStatus;
|
|
28
|
+
return {
|
|
29
|
+
cashCollection: "none",
|
|
30
|
+
invoiceAdjustment,
|
|
31
|
+
observedAt: row.observedAt ?? row.firstAttemptAt,
|
|
32
|
+
nativeCreditNoteStatus: row.nativeCreditNoteStatus ?? null,
|
|
33
|
+
resolution: row.resolution ?? "event_cancellation",
|
|
34
|
+
correctionId: row.correctionId,
|
|
35
|
+
eventId: row.eventId,
|
|
36
|
+
sourceEventId: JSON.parse(row.recordJson).sourceEventId,
|
|
37
|
+
state: row.state,
|
|
38
|
+
reason: row.reason,
|
|
39
|
+
actor: request.actor,
|
|
40
|
+
requestedReason: request.reason,
|
|
41
|
+
quantity: row.quantity,
|
|
42
|
+
nativeAdjustmentId: row.nativeAdjustmentId ?? null,
|
|
43
|
+
nativeStatus: row.nativeStatus ?? null,
|
|
44
|
+
invoiceId: row.invoiceId ?? null,
|
|
45
|
+
creditNoteId: row.creditNoteId ?? null,
|
|
46
|
+
refundId: row.refundId ?? null,
|
|
47
|
+
cashConsequence: row.cashConsequence,
|
|
48
|
+
restoredQuantity: row.restoredQuantity,
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
export const invoiceCorrectionOptions = z.strictObject({
|
|
52
|
+
scope: scopeSchema,
|
|
53
|
+
eventId: z.string().min(1).max(100),
|
|
54
|
+
correctionId: z.string().min(1).max(100),
|
|
55
|
+
invoiceId: z
|
|
56
|
+
.string()
|
|
57
|
+
.regex(/^in_[a-zA-Z0-9]+$/)
|
|
58
|
+
.max(100),
|
|
59
|
+
creditNoteId: z
|
|
60
|
+
.string()
|
|
61
|
+
.regex(/^cn_[a-zA-Z0-9]+$/)
|
|
62
|
+
.max(100),
|
|
63
|
+
amount: z.number().int().positive().max(99999999),
|
|
64
|
+
});
|
|
65
|
+
//# sourceMappingURL=correctionTerms.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"correctionTerms.js","sourceRoot":"","sources":["../../../src/client/usage/correctionTerms.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AACrE,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAC3C,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,CAAC,YAAY,CAAC;IAC9C,KAAK,EAAE,WAAW;IAClB,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC;IACnC,YAAY,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC;IACxC,KAAK,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC;IACjC,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC;IAClC,SAAS,EAAE,CAAC,CAAC,OAAO,CAAC,QAAQ,CAAC;IAC9B,QAAQ,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;CAChC,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,CAAC,IAAI,CAAC;IACpC,WAAW;IACX,mBAAmB;IACnB,WAAW;IACX,MAAM;IACN,aAAa;IACb,6BAA6B;CAC9B,CAAC,CAAC;AA4BH,MAAM,UAAU,cAAc,CAC5B,GAA8E;IAE9E,MAAM,OAAO,GAAG,iBAAiB,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,C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M,CAAC,MAAM,wBAAwB,GAAG,CAAC,CAAC,YAAY,CAAC;IACrD,KAAK,EAAE,WAAW;IAClB,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC;IACnC,YAAY,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC;IACxC,SAAS,EAAE,CAAC;SACT,MAAM,EAAE;SACR,KAAK,CAAC,mBAAmB,CAAC;SAC1B,GAAG,CAAC,GAAG,CAAC;IACX,YAAY,EAAE,CAAC;SACZ,MAAM,EAAE;SACR,KAAK,CAAC,mBAAmB,CAAC;SAC1B,GAAG,CAAC,GAAG,CAAC;IACX,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,CAAC,QAAQ,EAAE,CAAC,GAAG,CAAC,QAAQ,CAAC;CAClD,CAAC,CAAC"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { UsageDeliveryProviderOptions } from "./deliveryProvider.js";
|
|
2
|
+
import type { UsageCorrectionOptions } from "./correctionTerms.js";
|
|
3
|
+
import type { UsageReceipt } from "./boundaries.js";
|
|
4
|
+
import type { UsageSubscriptionView } from "./subscriptionTerms.js";
|
|
5
|
+
import { BetterStripe } from "../index.js";
|
|
6
|
+
import { fixture } from "./subscriptionTransport.fixtures.js";
|
|
7
|
+
type CorrectionState = {
|
|
8
|
+
status: string;
|
|
9
|
+
missingEvidence: boolean;
|
|
10
|
+
advanceAtInvoiceRead: number;
|
|
11
|
+
failFirstAdjustment: boolean;
|
|
12
|
+
invalidCash: boolean;
|
|
13
|
+
paidAdjustment: boolean;
|
|
14
|
+
refundSucceeded: boolean;
|
|
15
|
+
voidedNote: boolean;
|
|
16
|
+
truncatedNote: boolean;
|
|
17
|
+
foreignLine: boolean;
|
|
18
|
+
finalizeOnAdjust: boolean;
|
|
19
|
+
finalized: boolean;
|
|
20
|
+
creditNoteAmount: number;
|
|
21
|
+
foreignNote: boolean;
|
|
22
|
+
};
|
|
23
|
+
export declare function setupCorrection(withAllowance?: boolean, periodEnd?: number): Promise<{
|
|
24
|
+
f: ReturnType<typeof fixture>;
|
|
25
|
+
client: BetterStripe;
|
|
26
|
+
options: UsageDeliveryProviderOptions;
|
|
27
|
+
correction: UsageCorrectionOptions;
|
|
28
|
+
receipt: UsageReceipt;
|
|
29
|
+
calls: Array<{
|
|
30
|
+
body: URLSearchParams;
|
|
31
|
+
key: string | null;
|
|
32
|
+
}>;
|
|
33
|
+
state: CorrectionState;
|
|
34
|
+
original: UsageSubscriptionView["bindings"][number];
|
|
35
|
+
}>;
|
|
36
|
+
export {};
|
|
37
|
+
//# sourceMappingURL=correctionTransport.fixtures.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"correctionTransport.fixtures.d.ts","sourceRoot":"","sources":["../../../src/client/usage/correctionTransport.fixtures.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,4BAA4B,EAAE,MAAM,uBAAuB,CAAC;AAC1E,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,sBAAsB,CAAC;AACnE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AACpD,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,wBAAwB,CAAC;AAKpE,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAG3C,OAAO,EAAE,OAAO,EAAE,MAAM,qCAAqC,CAAC;AAM9D,KAAK,eAAe,GAAG;IACrB,MAAM,EAAE,MAAM,CAAC;IACf,eAAe,EAAE,OAAO,CAAC;IACzB,oBAAoB,EAAE,MAAM,CAAC;IAC7B,mBAAmB,EAAE,OAAO,CAAC;IAC7B,WAAW,EAAE,OAAO,CAAC;IACrB,cAAc,EAAE,OAAO,CAAC;IACxB,eAAe,EAAE,OAAO,CAAC;IACzB,UAAU,EA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