@fantastic.dev/better-stripe 0.58.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 +6 -0
- package/README.md +1 -1
- package/dist/client/connect/payoutAdoptionTestHelpers.d.ts +238 -18
- package/dist/client/connect/payoutAdoptionTestHelpers.d.ts.map +1 -1
- package/dist/client/connect/payoutExecutionTestHelpers.d.ts +119 -9
- package/dist/client/connect/payoutExecutionTestHelpers.d.ts.map +1 -1
- package/dist/client/connect/payoutLargeAdoptionTestHelpers.d.ts +238 -18
- package/dist/client/connect/payoutLargeAdoptionTestHelpers.d.ts.map +1 -1
- package/dist/client/connect/payoutSyncTestHelpers.d.ts +119 -9
- package/dist/client/connect/payoutSyncTestHelpers.d.ts.map +1 -1
- package/dist/client/usage/allowanceClient.d.ts +1 -1
- 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 +2 -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 +2 -0
- package/dist/client/usageExports.d.ts.map +1 -1
- package/dist/component/_generated/api.d.ts +12 -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 +255 -14
- 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/mutations.d.ts +27 -27
- package/dist/component/balanceFunding/stateHandlers.d.ts +8 -8
- package/dist/component/earnings/triggers.d.ts +212 -26
- package/dist/component/earnings/triggers.d.ts.map +1 -1
- package/dist/component/schema.d.ts +119 -9
- package/dist/component/schema.js +4 -0
- package/dist/component/schema.js.map +1 -1
- package/dist/component/usage/queries.d.ts +2 -2
- package/dist/component/usage/schema.d.ts +18 -13
- package/dist/component/usage/schema.d.ts.map +1 -1
- package/dist/component/usage/schema.js +2 -1
- package/dist/component/usage/schema.js.map +1 -1
- package/dist/component/usageAllowance/queries.d.ts +1 -1
- package/dist/component/usageAllowance/queries.d.ts.map +1 -1
- package/dist/component/usageAllowance/queries.js +10 -1
- package/dist/component/usageAllowance/queries.js.map +1 -1
- package/dist/component/usageAllowance/schema.d.ts +5 -5
- package/dist/component/usageAllowance/schema.d.ts.map +1 -1
- package/dist/component/usageAllowance/schema.js +1 -1
- package/dist/component/usageAllowance/schema.js.map +1 -1
- 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 +2 -0
- package/docs/usage-corrections.md +249 -0
- package/docs/usage-limits.md +1 -1
- package/package.json +2 -1
- 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 +11 -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 +11 -0
- package/src/component/_generated/api.ts +12 -0
- package/src/component/_generated/component.ts +330 -2
- package/src/component/accountClosure/mutations.ts +17 -0
- package/src/component/schema.ts +8 -0
- package/src/component/usage/schema.ts +2 -0
- package/src/component/usageAllowance/queries.ts +8 -1
- package/src/component/usageAllowance/schema.ts +1 -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
|
@@ -8307,6 +8307,7 @@ export type ComponentApi<Name extends string | undefined = string | undefined> =
|
|
|
8307
8307
|
{
|
|
8308
8308
|
delivery:
|
|
8309
8309
|
| "queued"
|
|
8310
|
+
| "canceled"
|
|
8310
8311
|
| "sending"
|
|
8311
8312
|
| "provider_accepted"
|
|
8312
8313
|
| "rejected"
|
|
@@ -8353,6 +8354,7 @@ export type ComponentApi<Name extends string | undefined = string | undefined> =
|
|
|
8353
8354
|
page: Array<{
|
|
8354
8355
|
delivery:
|
|
8355
8356
|
| "queued"
|
|
8357
|
+
| "canceled"
|
|
8356
8358
|
| "sending"
|
|
8357
8359
|
| "provider_accepted"
|
|
8358
8360
|
| "rejected"
|
|
@@ -8444,7 +8446,8 @@ export type ComponentApi<Name extends string | undefined = string | undefined> =
|
|
|
8444
8446
|
at: number;
|
|
8445
8447
|
evidenceJson: string;
|
|
8446
8448
|
key: string;
|
|
8447
|
-
kind:
|
|
8449
|
+
kind:
|
|
8450
|
+
"policy" | "reservation" | "commit" | "release" | "correction";
|
|
8448
8451
|
}>;
|
|
8449
8452
|
},
|
|
8450
8453
|
Name
|
|
@@ -8550,6 +8553,319 @@ export type ComponentApi<Name extends string | undefined = string | undefined> =
|
|
|
8550
8553
|
>;
|
|
8551
8554
|
};
|
|
8552
8555
|
};
|
|
8556
|
+
usageCorrections: {
|
|
8557
|
+
mutations: {
|
|
8558
|
+
adopt: FunctionReference<
|
|
8559
|
+
"mutation",
|
|
8560
|
+
"internal",
|
|
8561
|
+
{ key: string; proofJson: string },
|
|
8562
|
+
{
|
|
8563
|
+
_creationTime: number;
|
|
8564
|
+
_id: string;
|
|
8565
|
+
adjustmentJson?: string;
|
|
8566
|
+
attempt: number;
|
|
8567
|
+
attemptedAt?: number;
|
|
8568
|
+
cashConsequence:
|
|
8569
|
+
| "none"
|
|
8570
|
+
| "operator_resolution_required"
|
|
8571
|
+
| "verified_external_adjustment";
|
|
8572
|
+
correctionId: string;
|
|
8573
|
+
creditNoteId?: string;
|
|
8574
|
+
customerAccount?: string;
|
|
8575
|
+
eventId: string;
|
|
8576
|
+
firstAttemptAt: number;
|
|
8577
|
+
historyCount: number;
|
|
8578
|
+
inputJson: string;
|
|
8579
|
+
invoiceId?: string;
|
|
8580
|
+
key: string;
|
|
8581
|
+
leaseUntil?: number;
|
|
8582
|
+
nativeAdjustmentId?: string;
|
|
8583
|
+
nativeCreditNoteStatus?: "issued" | "void";
|
|
8584
|
+
nativeStatus?: "pending" | "complete";
|
|
8585
|
+
observedAt?: number;
|
|
8586
|
+
quantity: string;
|
|
8587
|
+
reason: string;
|
|
8588
|
+
recordJson: string;
|
|
8589
|
+
refundId?: string;
|
|
8590
|
+
resolution?: "event_cancellation" | "invoice_credit";
|
|
8591
|
+
restoredQuantity: string;
|
|
8592
|
+
scaledQuantity: string;
|
|
8593
|
+
scopeKey: string;
|
|
8594
|
+
state:
|
|
8595
|
+
| "requested"
|
|
8596
|
+
| "provider_accepted"
|
|
8597
|
+
| "confirmed"
|
|
8598
|
+
| "held"
|
|
8599
|
+
| "unsupported"
|
|
8600
|
+
| "invoice_adjustment_required";
|
|
8601
|
+
stripeAccountId?: string;
|
|
8602
|
+
subscriptionJson: string;
|
|
8603
|
+
},
|
|
8604
|
+
Name
|
|
8605
|
+
>;
|
|
8606
|
+
claim: FunctionReference<
|
|
8607
|
+
"mutation",
|
|
8608
|
+
"internal",
|
|
8609
|
+
{ key: string },
|
|
8610
|
+
{ attempt: number; kind: "ready" | "busy" | "done" },
|
|
8611
|
+
Name
|
|
8612
|
+
>;
|
|
8613
|
+
prepare: FunctionReference<
|
|
8614
|
+
"mutation",
|
|
8615
|
+
"internal",
|
|
8616
|
+
{ inputJson: string },
|
|
8617
|
+
{
|
|
8618
|
+
_creationTime: number;
|
|
8619
|
+
_id: string;
|
|
8620
|
+
adjustmentJson?: string;
|
|
8621
|
+
attempt: number;
|
|
8622
|
+
attemptedAt?: number;
|
|
8623
|
+
cashConsequence:
|
|
8624
|
+
| "none"
|
|
8625
|
+
| "operator_resolution_required"
|
|
8626
|
+
| "verified_external_adjustment";
|
|
8627
|
+
correctionId: string;
|
|
8628
|
+
creditNoteId?: string;
|
|
8629
|
+
customerAccount?: string;
|
|
8630
|
+
eventId: string;
|
|
8631
|
+
firstAttemptAt: number;
|
|
8632
|
+
historyCount: number;
|
|
8633
|
+
inputJson: string;
|
|
8634
|
+
invoiceId?: string;
|
|
8635
|
+
key: string;
|
|
8636
|
+
leaseUntil?: number;
|
|
8637
|
+
nativeAdjustmentId?: string;
|
|
8638
|
+
nativeCreditNoteStatus?: "issued" | "void";
|
|
8639
|
+
nativeStatus?: "pending" | "complete";
|
|
8640
|
+
observedAt?: number;
|
|
8641
|
+
quantity: string;
|
|
8642
|
+
reason: string;
|
|
8643
|
+
recordJson: string;
|
|
8644
|
+
refundId?: string;
|
|
8645
|
+
resolution?: "event_cancellation" | "invoice_credit";
|
|
8646
|
+
restoredQuantity: string;
|
|
8647
|
+
scaledQuantity: string;
|
|
8648
|
+
scopeKey: string;
|
|
8649
|
+
state:
|
|
8650
|
+
| "requested"
|
|
8651
|
+
| "provider_accepted"
|
|
8652
|
+
| "confirmed"
|
|
8653
|
+
| "held"
|
|
8654
|
+
| "unsupported"
|
|
8655
|
+
| "invoice_adjustment_required";
|
|
8656
|
+
stripeAccountId?: string;
|
|
8657
|
+
subscriptionJson: string;
|
|
8658
|
+
},
|
|
8659
|
+
Name
|
|
8660
|
+
>;
|
|
8661
|
+
save: FunctionReference<
|
|
8662
|
+
"mutation",
|
|
8663
|
+
"internal",
|
|
8664
|
+
{ attempt: number; key: string; outcomeJson: string },
|
|
8665
|
+
{
|
|
8666
|
+
_creationTime: number;
|
|
8667
|
+
_id: string;
|
|
8668
|
+
adjustmentJson?: string;
|
|
8669
|
+
attempt: number;
|
|
8670
|
+
attemptedAt?: number;
|
|
8671
|
+
cashConsequence:
|
|
8672
|
+
| "none"
|
|
8673
|
+
| "operator_resolution_required"
|
|
8674
|
+
| "verified_external_adjustment";
|
|
8675
|
+
correctionId: string;
|
|
8676
|
+
creditNoteId?: string;
|
|
8677
|
+
customerAccount?: string;
|
|
8678
|
+
eventId: string;
|
|
8679
|
+
firstAttemptAt: number;
|
|
8680
|
+
historyCount: number;
|
|
8681
|
+
inputJson: string;
|
|
8682
|
+
invoiceId?: string;
|
|
8683
|
+
key: string;
|
|
8684
|
+
leaseUntil?: number;
|
|
8685
|
+
nativeAdjustmentId?: string;
|
|
8686
|
+
nativeCreditNoteStatus?: "issued" | "void";
|
|
8687
|
+
nativeStatus?: "pending" | "complete";
|
|
8688
|
+
observedAt?: number;
|
|
8689
|
+
quantity: string;
|
|
8690
|
+
reason: string;
|
|
8691
|
+
recordJson: string;
|
|
8692
|
+
refundId?: string;
|
|
8693
|
+
resolution?: "event_cancellation" | "invoice_credit";
|
|
8694
|
+
restoredQuantity: string;
|
|
8695
|
+
scaledQuantity: string;
|
|
8696
|
+
scopeKey: string;
|
|
8697
|
+
state:
|
|
8698
|
+
| "requested"
|
|
8699
|
+
| "provider_accepted"
|
|
8700
|
+
| "confirmed"
|
|
8701
|
+
| "held"
|
|
8702
|
+
| "unsupported"
|
|
8703
|
+
| "invoice_adjustment_required";
|
|
8704
|
+
stripeAccountId?: string;
|
|
8705
|
+
subscriptionJson: string;
|
|
8706
|
+
},
|
|
8707
|
+
Name
|
|
8708
|
+
>;
|
|
8709
|
+
};
|
|
8710
|
+
queries: {
|
|
8711
|
+
get: FunctionReference<
|
|
8712
|
+
"query",
|
|
8713
|
+
"internal",
|
|
8714
|
+
{
|
|
8715
|
+
correctionId: string;
|
|
8716
|
+
eventId: string;
|
|
8717
|
+
scope: {
|
|
8718
|
+
customerAccount: string;
|
|
8719
|
+
livemode: boolean;
|
|
8720
|
+
meterId: string;
|
|
8721
|
+
stripeAccountId: string;
|
|
8722
|
+
};
|
|
8723
|
+
},
|
|
8724
|
+
{
|
|
8725
|
+
_creationTime: number;
|
|
8726
|
+
_id: string;
|
|
8727
|
+
adjustmentJson?: string;
|
|
8728
|
+
attempt: number;
|
|
8729
|
+
attemptedAt?: number;
|
|
8730
|
+
cashConsequence:
|
|
8731
|
+
| "none"
|
|
8732
|
+
| "operator_resolution_required"
|
|
8733
|
+
| "verified_external_adjustment";
|
|
8734
|
+
correctionId: string;
|
|
8735
|
+
creditNoteId?: string;
|
|
8736
|
+
customerAccount?: string;
|
|
8737
|
+
eventId: string;
|
|
8738
|
+
firstAttemptAt: number;
|
|
8739
|
+
historyCount: number;
|
|
8740
|
+
inputJson: string;
|
|
8741
|
+
invoiceId?: string;
|
|
8742
|
+
key: string;
|
|
8743
|
+
leaseUntil?: number;
|
|
8744
|
+
nativeAdjustmentId?: string;
|
|
8745
|
+
nativeCreditNoteStatus?: "issued" | "void";
|
|
8746
|
+
nativeStatus?: "pending" | "complete";
|
|
8747
|
+
observedAt?: number;
|
|
8748
|
+
quantity: string;
|
|
8749
|
+
reason: string;
|
|
8750
|
+
recordJson: string;
|
|
8751
|
+
refundId?: string;
|
|
8752
|
+
resolution?: "event_cancellation" | "invoice_credit";
|
|
8753
|
+
restoredQuantity: string;
|
|
8754
|
+
scaledQuantity: string;
|
|
8755
|
+
scopeKey: string;
|
|
8756
|
+
state:
|
|
8757
|
+
| "requested"
|
|
8758
|
+
| "provider_accepted"
|
|
8759
|
+
| "confirmed"
|
|
8760
|
+
| "held"
|
|
8761
|
+
| "unsupported"
|
|
8762
|
+
| "invoice_adjustment_required";
|
|
8763
|
+
stripeAccountId?: string;
|
|
8764
|
+
subscriptionJson: string;
|
|
8765
|
+
} | null,
|
|
8766
|
+
Name
|
|
8767
|
+
>;
|
|
8768
|
+
periodHistory: FunctionReference<
|
|
8769
|
+
"query",
|
|
8770
|
+
"internal",
|
|
8771
|
+
{
|
|
8772
|
+
paginationOpts: {
|
|
8773
|
+
cursor: string | null;
|
|
8774
|
+
endCursor?: string | null;
|
|
8775
|
+
id?: number;
|
|
8776
|
+
maximumBytesRead?: number;
|
|
8777
|
+
maximumRowsRead?: number;
|
|
8778
|
+
numItems: number;
|
|
8779
|
+
};
|
|
8780
|
+
period: { end: number; start: number };
|
|
8781
|
+
scope: {
|
|
8782
|
+
customerAccount: string;
|
|
8783
|
+
livemode: boolean;
|
|
8784
|
+
meterId: string;
|
|
8785
|
+
stripeAccountId: string;
|
|
8786
|
+
};
|
|
8787
|
+
},
|
|
8788
|
+
{
|
|
8789
|
+
continueCursor: string;
|
|
8790
|
+
isDone: boolean;
|
|
8791
|
+
legacyHistoryMissing: boolean;
|
|
8792
|
+
page: Array<{
|
|
8793
|
+
_creationTime: number;
|
|
8794
|
+
_id: string;
|
|
8795
|
+
at: number;
|
|
8796
|
+
eventId: string;
|
|
8797
|
+
evidenceJson: string;
|
|
8798
|
+
key: string;
|
|
8799
|
+
occurredAt?: number;
|
|
8800
|
+
reason: string;
|
|
8801
|
+
recordJson: string;
|
|
8802
|
+
scopeKey: string;
|
|
8803
|
+
sequence: number;
|
|
8804
|
+
state:
|
|
8805
|
+
| "requested"
|
|
8806
|
+
| "provider_accepted"
|
|
8807
|
+
| "confirmed"
|
|
8808
|
+
| "held"
|
|
8809
|
+
| "unsupported"
|
|
8810
|
+
| "invoice_adjustment_required";
|
|
8811
|
+
subscriptionJson: string;
|
|
8812
|
+
}>;
|
|
8813
|
+
pageStatus?: "SplitRecommended" | "SplitRequired" | null;
|
|
8814
|
+
splitCursor?: string | null;
|
|
8815
|
+
},
|
|
8816
|
+
Name
|
|
8817
|
+
>;
|
|
8818
|
+
readHistory: FunctionReference<
|
|
8819
|
+
"query",
|
|
8820
|
+
"internal",
|
|
8821
|
+
{
|
|
8822
|
+
eventId: string;
|
|
8823
|
+
paginationOpts: {
|
|
8824
|
+
cursor: string | null;
|
|
8825
|
+
endCursor?: string | null;
|
|
8826
|
+
id?: number;
|
|
8827
|
+
maximumBytesRead?: number;
|
|
8828
|
+
maximumRowsRead?: number;
|
|
8829
|
+
numItems: number;
|
|
8830
|
+
};
|
|
8831
|
+
scope: {
|
|
8832
|
+
customerAccount: string;
|
|
8833
|
+
livemode: boolean;
|
|
8834
|
+
meterId: string;
|
|
8835
|
+
stripeAccountId: string;
|
|
8836
|
+
};
|
|
8837
|
+
},
|
|
8838
|
+
{
|
|
8839
|
+
continueCursor: string;
|
|
8840
|
+
isDone: boolean;
|
|
8841
|
+
page: Array<{
|
|
8842
|
+
_creationTime: number;
|
|
8843
|
+
_id: string;
|
|
8844
|
+
at: number;
|
|
8845
|
+
eventId: string;
|
|
8846
|
+
evidenceJson: string;
|
|
8847
|
+
key: string;
|
|
8848
|
+
occurredAt?: number;
|
|
8849
|
+
reason: string;
|
|
8850
|
+
recordJson: string;
|
|
8851
|
+
scopeKey: string;
|
|
8852
|
+
sequence: number;
|
|
8853
|
+
state:
|
|
8854
|
+
| "requested"
|
|
8855
|
+
| "provider_accepted"
|
|
8856
|
+
| "confirmed"
|
|
8857
|
+
| "held"
|
|
8858
|
+
| "unsupported"
|
|
8859
|
+
| "invoice_adjustment_required";
|
|
8860
|
+
subscriptionJson: string;
|
|
8861
|
+
}>;
|
|
8862
|
+
pageStatus?: "SplitRecommended" | "SplitRequired" | null;
|
|
8863
|
+
splitCursor?: string | null;
|
|
8864
|
+
},
|
|
8865
|
+
Name
|
|
8866
|
+
>;
|
|
8867
|
+
};
|
|
8868
|
+
};
|
|
8553
8869
|
usageCredits: {
|
|
8554
8870
|
mutations: {
|
|
8555
8871
|
cancelPurchase: FunctionReference<
|
|
@@ -8931,7 +9247,8 @@ export type ComponentApi<Name extends string | undefined = string | undefined> =
|
|
|
8931
9247
|
| "release"
|
|
8932
9248
|
| "observation"
|
|
8933
9249
|
| "recovery"
|
|
8934
|
-
| "closure"
|
|
9250
|
+
| "closure"
|
|
9251
|
+
| "correction";
|
|
8935
9252
|
purchaseKey?: string;
|
|
8936
9253
|
sourceKey: string;
|
|
8937
9254
|
}>;
|
|
@@ -8962,6 +9279,7 @@ export type ComponentApi<Name extends string | undefined = string | undefined> =
|
|
|
8962
9279
|
held: boolean;
|
|
8963
9280
|
providerIdentifier: string;
|
|
8964
9281
|
reason?:
|
|
9282
|
+
| "usage_canceled"
|
|
8965
9283
|
| "billing_period_closed"
|
|
8966
9284
|
| "rate_limited"
|
|
8967
9285
|
| "provider_unavailable"
|
|
@@ -8974,6 +9292,7 @@ export type ComponentApi<Name extends string | undefined = string | undefined> =
|
|
|
8974
9292
|
receipt?: { created: number; identifier: string };
|
|
8975
9293
|
state:
|
|
8976
9294
|
| "queued"
|
|
9295
|
+
| "canceled"
|
|
8977
9296
|
| "sending"
|
|
8978
9297
|
| "provider_accepted"
|
|
8979
9298
|
| "rejected"
|
|
@@ -9041,6 +9360,7 @@ export type ComponentApi<Name extends string | undefined = string | undefined> =
|
|
|
9041
9360
|
held: boolean;
|
|
9042
9361
|
providerIdentifier: string;
|
|
9043
9362
|
reason?:
|
|
9363
|
+
| "usage_canceled"
|
|
9044
9364
|
| "billing_period_closed"
|
|
9045
9365
|
| "rate_limited"
|
|
9046
9366
|
| "provider_unavailable"
|
|
@@ -9053,6 +9373,7 @@ export type ComponentApi<Name extends string | undefined = string | undefined> =
|
|
|
9053
9373
|
receipt?: { created: number; identifier: string };
|
|
9054
9374
|
state:
|
|
9055
9375
|
| "queued"
|
|
9376
|
+
| "canceled"
|
|
9056
9377
|
| "sending"
|
|
9057
9378
|
| "provider_accepted"
|
|
9058
9379
|
| "rejected"
|
|
@@ -9096,6 +9417,7 @@ export type ComponentApi<Name extends string | undefined = string | undefined> =
|
|
|
9096
9417
|
held: boolean;
|
|
9097
9418
|
providerIdentifier: string;
|
|
9098
9419
|
reason?:
|
|
9420
|
+
| "usage_canceled"
|
|
9099
9421
|
| "billing_period_closed"
|
|
9100
9422
|
| "rate_limited"
|
|
9101
9423
|
| "provider_unavailable"
|
|
@@ -9108,6 +9430,7 @@ export type ComponentApi<Name extends string | undefined = string | undefined> =
|
|
|
9108
9430
|
receipt?: { created: number; identifier: string };
|
|
9109
9431
|
state:
|
|
9110
9432
|
| "queued"
|
|
9433
|
+
| "canceled"
|
|
9111
9434
|
| "sending"
|
|
9112
9435
|
| "provider_accepted"
|
|
9113
9436
|
| "rejected"
|
|
@@ -9151,6 +9474,7 @@ export type ComponentApi<Name extends string | undefined = string | undefined> =
|
|
|
9151
9474
|
held: boolean;
|
|
9152
9475
|
providerIdentifier: string;
|
|
9153
9476
|
reason?:
|
|
9477
|
+
| "usage_canceled"
|
|
9154
9478
|
| "billing_period_closed"
|
|
9155
9479
|
| "rate_limited"
|
|
9156
9480
|
| "provider_unavailable"
|
|
@@ -9163,6 +9487,7 @@ export type ComponentApi<Name extends string | undefined = string | undefined> =
|
|
|
9163
9487
|
receipt?: { created: number; identifier: string };
|
|
9164
9488
|
state:
|
|
9165
9489
|
| "queued"
|
|
9490
|
+
| "canceled"
|
|
9166
9491
|
| "sending"
|
|
9167
9492
|
| "provider_accepted"
|
|
9168
9493
|
| "rejected"
|
|
@@ -9221,6 +9546,7 @@ export type ComponentApi<Name extends string | undefined = string | undefined> =
|
|
|
9221
9546
|
_creationTime: number;
|
|
9222
9547
|
_id: string;
|
|
9223
9548
|
attempts: number;
|
|
9549
|
+
correctionKey?: string;
|
|
9224
9550
|
definitionVersion?: 1;
|
|
9225
9551
|
dispatch?: string;
|
|
9226
9552
|
eventId: string;
|
|
@@ -9232,6 +9558,7 @@ export type ComponentApi<Name extends string | undefined = string | undefined> =
|
|
|
9232
9558
|
provider?: string;
|
|
9233
9559
|
providerIdentifier: string;
|
|
9234
9560
|
reason?:
|
|
9561
|
+
| "usage_canceled"
|
|
9235
9562
|
| "billing_period_closed"
|
|
9236
9563
|
| "rate_limited"
|
|
9237
9564
|
| "provider_unavailable"
|
|
@@ -9245,6 +9572,7 @@ export type ComponentApi<Name extends string | undefined = string | undefined> =
|
|
|
9245
9572
|
scopeKey: string;
|
|
9246
9573
|
state:
|
|
9247
9574
|
| "queued"
|
|
9575
|
+
| "canceled"
|
|
9248
9576
|
| "sending"
|
|
9249
9577
|
| "provider_accepted"
|
|
9250
9578
|
| "rejected"
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { unresolvedCorrectionStates } from "../usageCorrections/cancellation.js";
|
|
1
2
|
import { v } from "convex/values";
|
|
2
3
|
import { mutation } from "../_generated/server.js";
|
|
3
4
|
import { closureByStripeId } from "./helpers.js";
|
|
@@ -7,6 +8,22 @@ export const prepare = mutation({
|
|
|
7
8
|
args: { stripeAccountId: v.string() },
|
|
8
9
|
returns: v.object({ closure: closureDoc, isRetry: v.boolean() }),
|
|
9
10
|
handler: async (ctx, { stripeAccountId }) => {
|
|
11
|
+
for (const state of unresolvedCorrectionStates) {
|
|
12
|
+
const payerCorrection = await ctx.db
|
|
13
|
+
.query("usageCorrections")
|
|
14
|
+
.withIndex("by_payer_state", (q) =>
|
|
15
|
+
q.eq("customerAccount", stripeAccountId).eq("state", state),
|
|
16
|
+
)
|
|
17
|
+
.first();
|
|
18
|
+
const realmCorrection = await ctx.db
|
|
19
|
+
.query("usageCorrections")
|
|
20
|
+
.withIndex("by_realm_state", (q) =>
|
|
21
|
+
q.eq("stripeAccountId", stripeAccountId).eq("state", state),
|
|
22
|
+
)
|
|
23
|
+
.first();
|
|
24
|
+
if (payerCorrection || realmCorrection)
|
|
25
|
+
throw new Error("Resolve usage corrections before account closure");
|
|
26
|
+
}
|
|
10
27
|
const payerLock = await ctx.db
|
|
11
28
|
.query("usageSubscriptionLocks")
|
|
12
29
|
.withIndex("by_payer", (q) => q.eq("customerAccount", stripeAccountId))
|
package/src/component/schema.ts
CHANGED
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
import {
|
|
2
|
+
claimsTable as usageCorrectionClaims,
|
|
3
|
+
operationsTable as usageCorrections,
|
|
4
|
+
historyTable as usageCorrectionHistory,
|
|
5
|
+
} from "./usageCorrections/schema.js";
|
|
1
6
|
import {
|
|
2
7
|
policiesTable as usageAllowancePolicies,
|
|
3
8
|
historyTable as usageAllowanceHistory,
|
|
@@ -120,6 +125,9 @@ import { pricesTable, productsTable } from "./products/schema";
|
|
|
120
125
|
import { webhookEventsTable } from "./webhooks/schema";
|
|
121
126
|
|
|
122
127
|
export default defineSchema({
|
|
128
|
+
usageCorrectionClaims,
|
|
129
|
+
usageCorrections,
|
|
130
|
+
usageCorrectionHistory,
|
|
123
131
|
usageAllowancePolicies,
|
|
124
132
|
usageAllowanceHistory,
|
|
125
133
|
usageSubscriptionControls,
|
|
@@ -10,6 +10,7 @@ export const scopeValidator = v.object({
|
|
|
10
10
|
});
|
|
11
11
|
export const deliveryValidator = v.union(
|
|
12
12
|
v.literal("queued"),
|
|
13
|
+
v.literal("canceled"),
|
|
13
14
|
v.literal("sending"),
|
|
14
15
|
v.literal("provider_accepted"),
|
|
15
16
|
v.literal("rejected"),
|
|
@@ -41,6 +42,7 @@ export const usageEventsTable = defineTable(eventFields)
|
|
|
41
42
|
])
|
|
42
43
|
.index("by_scope_time", ["scopeKey", "occurredAt"]);
|
|
43
44
|
export const outboxFields = {
|
|
45
|
+
correctionKey: v.optional(v.string()),
|
|
44
46
|
...deliveryFields,
|
|
45
47
|
eventId: v.id("usageEvents"),
|
|
46
48
|
scopeKey: v.string(),
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { verifiedCancellation } from "../usageCorrections/cancellation.js";
|
|
1
2
|
import { paginationOptsValidator } from "convex/server";
|
|
2
3
|
import { v } from "convex/values";
|
|
3
4
|
import { query } from "../_generated/server.js";
|
|
@@ -109,7 +110,13 @@ export const reconciliation = query({
|
|
|
109
110
|
reservation.scaledQuantity !== record.scaledQuantity
|
|
110
111
|
)
|
|
111
112
|
complete = false;
|
|
112
|
-
|
|
113
|
+
const outbox = await ctx.db
|
|
114
|
+
.query("usageOutbox")
|
|
115
|
+
.withIndex("by_event", (q) => q.eq("eventId", event._id))
|
|
116
|
+
.unique();
|
|
117
|
+
const canceled = await verifiedCancellation(ctx, event, outbox);
|
|
118
|
+
if (canceled === "unverified") complete = false;
|
|
119
|
+
if (canceled !== "confirmed") accepted += BigInt(record.scaledQuantity);
|
|
113
120
|
}
|
|
114
121
|
for (const reservation of reservations)
|
|
115
122
|
reserved += BigInt(reservation.scaledQuantity);
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import type { MutationCtx } from "../_generated/server.js";
|
|
2
|
+
import type { Doc } from "../_generated/dataModel.js";
|
|
3
|
+
import { creditAllocations } from "../usageCredits/reservations.js";
|
|
4
|
+
import { account, history as creditHistory } from "../usageCredits/helpers.js";
|
|
5
|
+
import {
|
|
6
|
+
policyRow,
|
|
7
|
+
history as allowanceHistory,
|
|
8
|
+
} from "../usageAllowance/helpers.js";
|
|
9
|
+
/** Called only for a full proven cancellation, in the same transaction as the terminal receipt. */
|
|
10
|
+
export async function restore(
|
|
11
|
+
ctx: MutationCtx,
|
|
12
|
+
correction: Doc<"usageCorrections">,
|
|
13
|
+
event: Doc<"usageEvents">,
|
|
14
|
+
) {
|
|
15
|
+
if (!event.reservationId) return;
|
|
16
|
+
const reservation = await ctx.db.get(
|
|
17
|
+
"usageReservations",
|
|
18
|
+
event.reservationId,
|
|
19
|
+
);
|
|
20
|
+
if (
|
|
21
|
+
!reservation ||
|
|
22
|
+
reservation.state !== "committed" ||
|
|
23
|
+
reservation.eventId !== event._id ||
|
|
24
|
+
reservation.scopeKey !== correction.scopeKey ||
|
|
25
|
+
reservation.scaledQuantity !== correction.scaledQuantity
|
|
26
|
+
)
|
|
27
|
+
throw new Error("Correction reservation provenance mismatch");
|
|
28
|
+
if (reservation.accountingKind === "allowance") {
|
|
29
|
+
const policy = await policyRow(ctx, reservation.accountKey!);
|
|
30
|
+
if (!policy || BigInt(policy.consumed) < BigInt(correction.scaledQuantity))
|
|
31
|
+
throw new Error("Correction allowance backing unavailable");
|
|
32
|
+
await ctx.db.patch("usageAllowancePolicies", policy._id, {
|
|
33
|
+
consumed: (
|
|
34
|
+
BigInt(policy.consumed) - BigInt(correction.scaledQuantity)
|
|
35
|
+
).toString(),
|
|
36
|
+
});
|
|
37
|
+
await allowanceHistory(ctx, policy, "correction", {
|
|
38
|
+
correctionKey: correction.key,
|
|
39
|
+
eventId: event._id,
|
|
40
|
+
scaledQuantity: correction.scaledQuantity,
|
|
41
|
+
cashCollection: "none",
|
|
42
|
+
});
|
|
43
|
+
} else if (reservation.accountingKind === "prepaid") {
|
|
44
|
+
const ledger = await account(ctx, reservation.accountKey!);
|
|
45
|
+
if (ledger.closed || ledger.frozenReason)
|
|
46
|
+
throw new Error("Correction credit account requires reconciliation");
|
|
47
|
+
const allocations = creditAllocations.parse(
|
|
48
|
+
JSON.parse(reservation.allocationsJson!),
|
|
49
|
+
);
|
|
50
|
+
for (const allocation of allocations) {
|
|
51
|
+
const grant = await ctx.db.get(
|
|
52
|
+
"usageCreditGrants",
|
|
53
|
+
allocation.grantId as import("../_generated/dataModel.js").Id<"usageCreditGrants">,
|
|
54
|
+
);
|
|
55
|
+
if (
|
|
56
|
+
!grant ||
|
|
57
|
+
grant.accountKey !== ledger.key ||
|
|
58
|
+
grant.frozen ||
|
|
59
|
+
grant.nativeExpired ||
|
|
60
|
+
(grant.expiresAt !== null && grant.expiresAt <= Date.now() / 1000) ||
|
|
61
|
+
BigInt(grant.consumed) < BigInt(allocation.quantity)
|
|
62
|
+
)
|
|
63
|
+
throw new Error("Correction original credit backing unavailable");
|
|
64
|
+
await ctx.db.patch("usageCreditGrants", grant._id, {
|
|
65
|
+
consumed: (
|
|
66
|
+
BigInt(grant.consumed) - BigInt(allocation.quantity)
|
|
67
|
+
).toString(),
|
|
68
|
+
available: (
|
|
69
|
+
BigInt(grant.available) + BigInt(allocation.quantity)
|
|
70
|
+
).toString(),
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
await creditHistory(ctx, ledger.key, "correction", correction.key, {
|
|
74
|
+
eventId: event._id,
|
|
75
|
+
allocations,
|
|
76
|
+
cashCollection: "none",
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { QueryCtx } from "../_generated/server.js";
|
|
2
|
+
import type { Doc } from "../_generated/dataModel.js";
|
|
3
|
+
/** Never treat an unproven terminal projection as canceled billable quantity. */
|
|
4
|
+
export async function verifiedCancellation(
|
|
5
|
+
ctx: QueryCtx,
|
|
6
|
+
event: Doc<"usageEvents">,
|
|
7
|
+
outbox: Doc<"usageOutbox"> | null,
|
|
8
|
+
) {
|
|
9
|
+
if (outbox?.state !== "canceled") return "none" as const;
|
|
10
|
+
if (!outbox.correctionKey) return "unverified" as const;
|
|
11
|
+
const correction = await ctx.db
|
|
12
|
+
.query("usageCorrections")
|
|
13
|
+
.withIndex("by_key", (q) => q.eq("key", outbox.correctionKey!))
|
|
14
|
+
.unique();
|
|
15
|
+
const record = JSON.parse(event.recordJson);
|
|
16
|
+
return correction?.state === "confirmed" &&
|
|
17
|
+
correction.resolution !== "invoice_credit" &&
|
|
18
|
+
correction.eventId === event._id &&
|
|
19
|
+
correction.scopeKey === event.scopeKey &&
|
|
20
|
+
correction.recordJson === event.recordJson &&
|
|
21
|
+
correction.subscriptionJson === event.subscriptionJson &&
|
|
22
|
+
correction.scaledQuantity === record.scaledQuantity &&
|
|
23
|
+
correction.restoredQuantity === record.quantity
|
|
24
|
+
? ("confirmed" as const)
|
|
25
|
+
: ("unverified" as const);
|
|
26
|
+
}
|
|
27
|
+
export const unresolvedCorrectionStates = [
|
|
28
|
+
"requested",
|
|
29
|
+
"provider_accepted",
|
|
30
|
+
"held",
|
|
31
|
+
"invoice_adjustment_required",
|
|
32
|
+
] as const;
|