@fantastic.dev/better-stripe 0.54.0 → 0.56.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 +264 -8
- package/dist/client/connect/payoutAdoptionTestHelpers.d.ts.map +1 -1
- package/dist/client/connect/payoutExecutionTestHelpers.d.ts +132 -4
- package/dist/client/connect/payoutExecutionTestHelpers.d.ts.map +1 -1
- package/dist/client/connect/payoutLargeAdoptionTestHelpers.d.ts +264 -8
- package/dist/client/connect/payoutLargeAdoptionTestHelpers.d.ts.map +1 -1
- package/dist/client/connect/payoutSyncTestHelpers.d.ts +132 -4
- package/dist/client/connect/payoutSyncTestHelpers.d.ts.map +1 -1
- package/dist/client/index.d.ts +9 -0
- package/dist/client/index.d.ts.map +1 -1
- package/dist/client/index.js +1 -0
- package/dist/client/index.js.map +1 -1
- package/dist/client/usage/catalogPrices.d.ts +2 -0
- package/dist/client/usage/catalogPrices.d.ts.map +1 -1
- package/dist/client/usage/catalogPrices.js +15 -0
- package/dist/client/usage/catalogPrices.js.map +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/deliveryProvider.d.ts.map +1 -1
- package/dist/client/usage/deliveryProvider.js +26 -1
- package/dist/client/usage/deliveryProvider.js.map +1 -1
- package/dist/client/usage/index.d.ts +9 -0
- package/dist/client/usage/index.d.ts.map +1 -1
- package/dist/client/usage/index.js +1 -0
- package/dist/client/usage/index.js.map +1 -1
- package/dist/client/usage/invoiceObservation.d.ts +38 -0
- package/dist/client/usage/invoiceObservation.d.ts.map +1 -0
- package/dist/client/usage/invoiceObservation.js +157 -0
- package/dist/client/usage/invoiceObservation.js.map +1 -0
- package/dist/client/usage/observationClient.d.ts +83 -0
- package/dist/client/usage/observationClient.d.ts.map +1 -0
- package/dist/client/usage/observationClient.js +157 -0
- package/dist/client/usage/observationClient.js.map +1 -0
- package/dist/client/usage/observationTypes.d.ts +63 -0
- package/dist/client/usage/observationTypes.d.ts.map +1 -0
- package/dist/client/usage/observationTypes.js +59 -0
- package/dist/client/usage/observationTypes.js.map +1 -0
- package/dist/client/usage/providerObservation.d.ts +4 -0
- package/dist/client/usage/providerObservation.d.ts.map +1 -0
- package/dist/client/usage/providerObservation.js +96 -0
- package/dist/client/usage/providerObservation.js.map +1 -0
- package/dist/client/usage/reconciliation.d.ts +12 -0
- package/dist/client/usage/reconciliation.d.ts.map +1 -0
- package/dist/client/usage/reconciliation.js +48 -0
- package/dist/client/usage/reconciliation.js.map +1 -0
- package/dist/client/usage/subscription.fixtures.d.ts +118 -0
- package/dist/client/usage/subscription.fixtures.d.ts.map +1 -0
- package/dist/client/usage/subscription.fixtures.js +84 -0
- package/dist/client/usage/subscription.fixtures.js.map +1 -0
- package/dist/client/usage/subscriptionAbandonment.d.ts +8 -0
- package/dist/client/usage/subscriptionAbandonment.d.ts.map +1 -0
- package/dist/client/usage/subscriptionAbandonment.js +82 -0
- package/dist/client/usage/subscriptionAbandonment.js.map +1 -0
- package/dist/client/usage/subscriptionCancellation.d.ts +9 -0
- package/dist/client/usage/subscriptionCancellation.d.ts.map +1 -0
- package/dist/client/usage/subscriptionCancellation.js +39 -0
- package/dist/client/usage/subscriptionCancellation.js.map +1 -0
- package/dist/client/usage/subscriptionCheckout.d.ts +52 -0
- package/dist/client/usage/subscriptionCheckout.d.ts.map +1 -0
- package/dist/client/usage/subscriptionCheckout.js +94 -0
- package/dist/client/usage/subscriptionCheckout.js.map +1 -0
- package/dist/client/usage/subscriptionClient.d.ts +267 -0
- package/dist/client/usage/subscriptionClient.d.ts.map +1 -0
- package/dist/client/usage/subscriptionClient.js +93 -0
- package/dist/client/usage/subscriptionClient.js.map +1 -0
- package/dist/client/usage/subscriptionErrors.d.ts +5 -0
- package/dist/client/usage/subscriptionErrors.d.ts.map +1 -0
- package/dist/client/usage/subscriptionErrors.js +9 -0
- package/dist/client/usage/subscriptionErrors.js.map +1 -0
- package/dist/client/usage/subscriptionInvoiceSchema.d.ts +203 -0
- package/dist/client/usage/subscriptionInvoiceSchema.d.ts.map +1 -0
- package/dist/client/usage/subscriptionInvoiceSchema.js +108 -0
- package/dist/client/usage/subscriptionInvoiceSchema.js.map +1 -0
- package/dist/client/usage/subscriptionLifecycle.d.ts +80 -0
- package/dist/client/usage/subscriptionLifecycle.d.ts.map +1 -0
- package/dist/client/usage/subscriptionLifecycle.js +87 -0
- package/dist/client/usage/subscriptionLifecycle.js.map +1 -0
- package/dist/client/usage/subscriptionProvider.d.ts +111 -0
- package/dist/client/usage/subscriptionProvider.d.ts.map +1 -0
- package/dist/client/usage/subscriptionProvider.js +147 -0
- package/dist/client/usage/subscriptionProvider.js.map +1 -0
- package/dist/client/usage/subscriptionTerms.d.ts +161 -0
- package/dist/client/usage/subscriptionTerms.d.ts.map +1 -0
- package/dist/client/usage/subscriptionTerms.js +242 -0
- package/dist/client/usage/subscriptionTerms.js.map +1 -0
- package/dist/client/usage/subscriptionTransport.fixtures.d.ts +25 -0
- package/dist/client/usage/subscriptionTransport.fixtures.d.ts.map +1 -0
- package/dist/client/usage/subscriptionTransport.fixtures.js +203 -0
- package/dist/client/usage/subscriptionTransport.fixtures.js.map +1 -0
- package/dist/client/usage/summary.d.ts +50 -0
- package/dist/client/usage/summary.d.ts.map +1 -0
- package/dist/client/usage/summary.js +110 -0
- package/dist/client/usage/summary.js.map +1 -0
- package/dist/client/webhooks/processors.d.ts.map +1 -1
- package/dist/client/webhooks/processors.js +2 -0
- package/dist/client/webhooks/processors.js.map +1 -1
- package/dist/client/webhooks/usageSubscriptions.d.ts +5 -0
- package/dist/client/webhooks/usageSubscriptions.d.ts.map +1 -0
- package/dist/client/webhooks/usageSubscriptions.js +54 -0
- package/dist/client/webhooks/usageSubscriptions.js.map +1 -0
- package/dist/component/_generated/api.d.ts +22 -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 -5
- 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 +10 -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 +16 -16
- package/dist/component/balanceFunding/preparationHandlers.d.ts +8 -8
- package/dist/component/balanceFunding/stateHandlers.d.ts +8 -8
- package/dist/component/balanceFunding/workflowValidators.d.ts +16 -16
- package/dist/component/earnings/triggers.d.ts +296 -22
- package/dist/component/earnings/triggers.d.ts.map +1 -1
- package/dist/component/payoutRelease/queries.d.ts +2 -2
- package/dist/component/payoutRelease/queries.d.ts.map +1 -1
- package/dist/component/refundHistory/queries.d.ts +1 -1
- package/dist/component/schema.d.ts +132 -4
- package/dist/component/schema.js +8 -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 +5 -0
- package/dist/component/usage/mutations.js.map +1 -1
- package/dist/component/usage/queries.d.ts +2 -0
- package/dist/component/usage/queries.d.ts.map +1 -1
- package/dist/component/usage/schema.d.ts +21 -9
- package/dist/component/usage/schema.d.ts.map +1 -1
- package/dist/component/usage/schema.js +5 -1
- package/dist/component/usage/schema.js.map +1 -1
- package/dist/component/usageDelivery/fields.d.ts +4 -2
- package/dist/component/usageDelivery/fields.d.ts.map +1 -1
- package/dist/component/usageDelivery/fields.js +3 -1
- package/dist/component/usageDelivery/fields.js.map +1 -1
- package/dist/component/usageDelivery/helpers.d.ts +5 -3
- package/dist/component/usageDelivery/helpers.d.ts.map +1 -1
- package/dist/component/usageDelivery/mutations.d.ts +3 -3
- package/dist/component/usageDelivery/mutations.d.ts.map +1 -1
- package/dist/component/usageDelivery/mutations.js +8 -1
- package/dist/component/usageDelivery/mutations.js.map +1 -1
- package/dist/component/usageDelivery/queries.d.ts +19 -3
- package/dist/component/usageDelivery/queries.d.ts.map +1 -1
- package/dist/component/usageDelivery/queries.js +20 -3
- package/dist/component/usageDelivery/queries.js.map +1 -1
- package/dist/component/usageDelivery/schema.d.ts +2 -2
- package/dist/component/usageDelivery/steps.d.ts +1 -1
- package/dist/component/usageDelivery/steps.d.ts.map +1 -1
- package/dist/component/usageDelivery/steps.js +20 -2
- package/dist/component/usageDelivery/steps.js.map +1 -1
- package/dist/component/usageObservations/helpers.d.ts +38 -0
- package/dist/component/usageObservations/helpers.d.ts.map +1 -0
- package/dist/component/usageObservations/helpers.js +80 -0
- package/dist/component/usageObservations/helpers.js.map +1 -0
- package/dist/component/usageObservations/history.d.ts +6 -0
- package/dist/component/usageObservations/history.d.ts.map +1 -0
- package/dist/component/usageObservations/history.js +29 -0
- package/dist/component/usageObservations/history.js.map +1 -0
- package/dist/component/usageObservations/mutations.d.ts +6 -0
- package/dist/component/usageObservations/mutations.d.ts.map +1 -0
- package/dist/component/usageObservations/mutations.js +39 -0
- package/dist/component/usageObservations/mutations.js.map +1 -0
- package/dist/component/usageObservations/queries.d.ts +78 -0
- package/dist/component/usageObservations/queries.d.ts.map +1 -0
- package/dist/component/usageObservations/queries.js +131 -0
- package/dist/component/usageObservations/queries.js.map +1 -0
- package/dist/component/usageObservations/schema.d.ts +72 -0
- package/dist/component/usageObservations/schema.d.ts.map +1 -0
- package/dist/component/usageObservations/schema.js +29 -0
- package/dist/component/usageObservations/schema.js.map +1 -0
- package/dist/component/usageSubscriptions/abandonment.d.ts +4 -0
- package/dist/component/usageSubscriptions/abandonment.d.ts.map +1 -0
- package/dist/component/usageSubscriptions/abandonment.js +59 -0
- package/dist/component/usageSubscriptions/abandonment.js.map +1 -0
- package/dist/component/usageSubscriptions/acceptance.d.ts +11 -0
- package/dist/component/usageSubscriptions/acceptance.d.ts.map +1 -0
- package/dist/component/usageSubscriptions/acceptance.js +38 -0
- package/dist/component/usageSubscriptions/acceptance.js.map +1 -0
- package/dist/component/usageSubscriptions/helpers.d.ts +39 -0
- package/dist/component/usageSubscriptions/helpers.d.ts.map +1 -0
- package/dist/component/usageSubscriptions/helpers.js +28 -0
- package/dist/component/usageSubscriptions/helpers.js.map +1 -0
- package/dist/component/usageSubscriptions/history.d.ts +46 -0
- package/dist/component/usageSubscriptions/history.d.ts.map +1 -0
- package/dist/component/usageSubscriptions/history.js +46 -0
- package/dist/component/usageSubscriptions/history.js.map +1 -0
- package/dist/component/usageSubscriptions/mutations.d.ts +64 -0
- package/dist/component/usageSubscriptions/mutations.d.ts.map +1 -0
- package/dist/component/usageSubscriptions/mutations.js +252 -0
- package/dist/component/usageSubscriptions/mutations.js.map +1 -0
- package/dist/component/usageSubscriptions/queries.d.ts +81 -0
- package/dist/component/usageSubscriptions/queries.d.ts.map +1 -0
- package/dist/component/usageSubscriptions/queries.js +70 -0
- package/dist/component/usageSubscriptions/queries.js.map +1 -0
- package/dist/component/usageSubscriptions/retirement.d.ts +4 -0
- package/dist/component/usageSubscriptions/retirement.d.ts.map +1 -0
- package/dist/component/usageSubscriptions/retirement.js +80 -0
- package/dist/component/usageSubscriptions/retirement.js.map +1 -0
- package/dist/component/usageSubscriptions/schema.d.ts +191 -0
- package/dist/component/usageSubscriptions/schema.d.ts.map +1 -0
- package/dist/component/usageSubscriptions/schema.js +69 -0
- package/dist/component/usageSubscriptions/schema.js.map +1 -0
- package/dist/test.d.ts +6 -0
- package/dist/test.d.ts.map +1 -0
- package/dist/test.js +15 -0
- package/dist/test.js.map +1 -0
- package/docs/README.md +4 -0
- package/docs/evidence/native-metering/clock-finalization-run.json +129 -0
- package/docs/evidence/native-metering/clock-lag-run.json +111 -0
- package/docs/evidence/native-metering/paid-run.json +107 -0
- package/docs/evidence/native-metering/promotional-run.json +103 -0
- package/docs/metered-usage.md +14 -0
- package/docs/metering-setup.md +7 -1
- package/docs/usage-observations.md +152 -0
- package/docs/usage-subscriptions.md +278 -0
- package/package.json +5 -2
- package/src/client/index.ts +26 -0
- package/src/client/usage/catalogPrices.ts +21 -0
- package/src/client/usage/client.ts +2 -2
- package/src/client/usage/deliveryProvider.test.ts +70 -1
- package/src/client/usage/deliveryProvider.ts +43 -2
- package/src/client/usage/index.ts +27 -0
- package/src/client/usage/invoiceObservation.test.ts +195 -0
- package/src/client/usage/invoiceObservation.ts +203 -0
- package/src/client/usage/observationClient.ts +233 -0
- package/src/client/usage/observationTypes.ts +101 -0
- package/src/client/usage/providerObservation.test.ts +207 -0
- package/src/client/usage/providerObservation.ts +124 -0
- package/src/client/usage/reconciliation.test.ts +117 -0
- package/src/client/usage/reconciliation.ts +86 -0
- package/src/client/usage/subscription.fixtures.ts +84 -0
- package/src/client/usage/subscriptionAbandonment.test.ts +124 -0
- package/src/client/usage/subscriptionAbandonment.ts +116 -0
- package/src/client/usage/subscriptionCancellation.ts +90 -0
- package/src/client/usage/subscriptionCheckout.test.ts +31 -0
- package/src/client/usage/subscriptionCheckout.ts +152 -0
- package/src/client/usage/subscriptionClient.test.ts +316 -0
- package/src/client/usage/subscriptionClient.ts +204 -0
- package/src/client/usage/subscriptionErrors.ts +14 -0
- package/src/client/usage/subscriptionInvoiceSchema.ts +116 -0
- package/src/client/usage/subscriptionLifecycle.ts +165 -0
- package/src/client/usage/subscriptionProvider.test.ts +48 -0
- package/src/client/usage/subscriptionProvider.ts +247 -0
- package/src/client/usage/subscriptionTerms.test.ts +158 -0
- package/src/client/usage/subscriptionTerms.ts +294 -0
- package/src/client/usage/subscriptionTransport.fixtures.ts +241 -0
- package/src/client/usage/summary.test.ts +222 -0
- package/src/client/usage/summary.ts +188 -0
- package/src/client/webhooks/processors.ts +2 -0
- package/src/client/webhooks/usageSubscriptions.test.ts +162 -0
- package/src/client/webhooks/usageSubscriptions.ts +81 -0
- package/src/component/_generated/api.ts +22 -0
- package/src/component/_generated/component.ts +335 -0
- package/src/component/accountClosure/mutations.ts +12 -0
- package/src/component/schema.ts +16 -0
- package/src/component/usage/mutations.ts +5 -0
- package/src/component/usage/schema.ts +5 -1
- package/src/component/usageDelivery/fields.ts +3 -0
- package/src/component/usageDelivery/mutations.ts +26 -1
- package/src/component/usageDelivery/queries.ts +30 -3
- package/src/component/usageDelivery/steps.ts +61 -2
- package/src/component/usageObservations/helpers.ts +95 -0
- package/src/component/usageObservations/history.test.ts +87 -0
- package/src/component/usageObservations/history.ts +39 -0
- package/src/component/usageObservations/mutations.ts +39 -0
- package/src/component/usageObservations/queries.test.ts +162 -0
- package/src/component/usageObservations/queries.ts +145 -0
- package/src/component/usageObservations/schema.ts +40 -0
- package/src/component/usageSubscriptions/abandonment.ts +80 -0
- package/src/component/usageSubscriptions/acceptance.test.ts +122 -0
- package/src/component/usageSubscriptions/acceptance.ts +66 -0
- package/src/component/usageSubscriptions/helpers.ts +33 -0
- package/src/component/usageSubscriptions/history.test.ts +69 -0
- package/src/component/usageSubscriptions/history.ts +68 -0
- package/src/component/usageSubscriptions/mutations.test.ts +205 -0
- package/src/component/usageSubscriptions/mutations.ts +275 -0
- package/src/component/usageSubscriptions/queries.ts +78 -0
- package/src/component/usageSubscriptions/retirement.ts +105 -0
- package/src/component/usageSubscriptions/schema.ts +73 -0
|
@@ -8321,6 +8321,7 @@ export type ComponentApi<Name extends string | undefined = string | undefined> =
|
|
|
8321
8321
|
recordJson: string;
|
|
8322
8322
|
reservationId?: string;
|
|
8323
8323
|
scopeKey: string;
|
|
8324
|
+
subscriptionId?: string;
|
|
8324
8325
|
subscriptionJson: string;
|
|
8325
8326
|
};
|
|
8326
8327
|
} | null,
|
|
@@ -8366,6 +8367,7 @@ export type ComponentApi<Name extends string | undefined = string | undefined> =
|
|
|
8366
8367
|
recordJson: string;
|
|
8367
8368
|
reservationId?: string;
|
|
8368
8369
|
scopeKey: string;
|
|
8370
|
+
subscriptionId?: string;
|
|
8369
8371
|
subscriptionJson: string;
|
|
8370
8372
|
};
|
|
8371
8373
|
}>;
|
|
@@ -8474,6 +8476,7 @@ export type ComponentApi<Name extends string | undefined = string | undefined> =
|
|
|
8474
8476
|
held: boolean;
|
|
8475
8477
|
providerIdentifier: string;
|
|
8476
8478
|
reason?:
|
|
8479
|
+
| "billing_period_closed"
|
|
8477
8480
|
| "rate_limited"
|
|
8478
8481
|
| "provider_unavailable"
|
|
8479
8482
|
| "provider_outcome_unknown"
|
|
@@ -8552,6 +8555,7 @@ export type ComponentApi<Name extends string | undefined = string | undefined> =
|
|
|
8552
8555
|
held: boolean;
|
|
8553
8556
|
providerIdentifier: string;
|
|
8554
8557
|
reason?:
|
|
8558
|
+
| "billing_period_closed"
|
|
8555
8559
|
| "rate_limited"
|
|
8556
8560
|
| "provider_unavailable"
|
|
8557
8561
|
| "provider_outcome_unknown"
|
|
@@ -8606,6 +8610,7 @@ export type ComponentApi<Name extends string | undefined = string | undefined> =
|
|
|
8606
8610
|
held: boolean;
|
|
8607
8611
|
providerIdentifier: string;
|
|
8608
8612
|
reason?:
|
|
8613
|
+
| "billing_period_closed"
|
|
8609
8614
|
| "rate_limited"
|
|
8610
8615
|
| "provider_unavailable"
|
|
8611
8616
|
| "provider_outcome_unknown"
|
|
@@ -8660,6 +8665,7 @@ export type ComponentApi<Name extends string | undefined = string | undefined> =
|
|
|
8660
8665
|
held: boolean;
|
|
8661
8666
|
providerIdentifier: string;
|
|
8662
8667
|
reason?:
|
|
8668
|
+
| "billing_period_closed"
|
|
8663
8669
|
| "rate_limited"
|
|
8664
8670
|
| "provider_unavailable"
|
|
8665
8671
|
| "provider_outcome_unknown"
|
|
@@ -8707,6 +8713,7 @@ export type ComponentApi<Name extends string | undefined = string | undefined> =
|
|
|
8707
8713
|
};
|
|
8708
8714
|
},
|
|
8709
8715
|
{
|
|
8716
|
+
billingCutoff: number | null;
|
|
8710
8717
|
event: {
|
|
8711
8718
|
_creationTime: number;
|
|
8712
8719
|
_id: string;
|
|
@@ -8716,8 +8723,14 @@ export type ComponentApi<Name extends string | undefined = string | undefined> =
|
|
|
8716
8723
|
recordJson: string;
|
|
8717
8724
|
reservationId?: string;
|
|
8718
8725
|
scopeKey: string;
|
|
8726
|
+
subscriptionId?: string;
|
|
8719
8727
|
subscriptionJson: string;
|
|
8720
8728
|
};
|
|
8729
|
+
managedCollection: null | {
|
|
8730
|
+
daysUntilDue: number | null;
|
|
8731
|
+
defaultPaymentMethod: string | null;
|
|
8732
|
+
method: "send_invoice" | "charge_automatically";
|
|
8733
|
+
};
|
|
8721
8734
|
outbox: {
|
|
8722
8735
|
_creationTime: number;
|
|
8723
8736
|
_id: string;
|
|
@@ -8727,11 +8740,13 @@ export type ComponentApi<Name extends string | undefined = string | undefined> =
|
|
|
8727
8740
|
eventId: string;
|
|
8728
8741
|
firstSendAt?: number;
|
|
8729
8742
|
held?: boolean;
|
|
8743
|
+
historySequence?: number;
|
|
8730
8744
|
leaseUntil?: number;
|
|
8731
8745
|
nextAttemptAt: number;
|
|
8732
8746
|
provider?: string;
|
|
8733
8747
|
providerIdentifier: string;
|
|
8734
8748
|
reason?:
|
|
8749
|
+
| "billing_period_closed"
|
|
8735
8750
|
| "rate_limited"
|
|
8736
8751
|
| "provider_unavailable"
|
|
8737
8752
|
| "provider_outcome_unknown"
|
|
@@ -8756,6 +8771,326 @@ export type ComponentApi<Name extends string | undefined = string | undefined> =
|
|
|
8756
8771
|
>;
|
|
8757
8772
|
};
|
|
8758
8773
|
};
|
|
8774
|
+
usageObservations: {
|
|
8775
|
+
mutations: {
|
|
8776
|
+
save: FunctionReference<
|
|
8777
|
+
"mutation",
|
|
8778
|
+
"internal",
|
|
8779
|
+
{ observationJson: string; sourceJson: string; startedAt: number },
|
|
8780
|
+
null,
|
|
8781
|
+
Name
|
|
8782
|
+
>;
|
|
8783
|
+
};
|
|
8784
|
+
queries: {
|
|
8785
|
+
cached: FunctionReference<
|
|
8786
|
+
"query",
|
|
8787
|
+
"internal",
|
|
8788
|
+
{ sourceJson: string },
|
|
8789
|
+
string | null,
|
|
8790
|
+
Name
|
|
8791
|
+
>;
|
|
8792
|
+
deliveryHistory: FunctionReference<
|
|
8793
|
+
"query",
|
|
8794
|
+
"internal",
|
|
8795
|
+
{
|
|
8796
|
+
eventId: string;
|
|
8797
|
+
paginationOpts: {
|
|
8798
|
+
cursor: string | null;
|
|
8799
|
+
endCursor?: string | null;
|
|
8800
|
+
id?: number;
|
|
8801
|
+
maximumBytesRead?: number;
|
|
8802
|
+
maximumRowsRead?: number;
|
|
8803
|
+
numItems: number;
|
|
8804
|
+
};
|
|
8805
|
+
scope: {
|
|
8806
|
+
customerAccount: string;
|
|
8807
|
+
livemode: boolean;
|
|
8808
|
+
meterId: string;
|
|
8809
|
+
stripeAccountId: string;
|
|
8810
|
+
};
|
|
8811
|
+
},
|
|
8812
|
+
{
|
|
8813
|
+
continueCursor: string;
|
|
8814
|
+
isDone: boolean;
|
|
8815
|
+
legacyHistoryMissing: boolean;
|
|
8816
|
+
page: Array<{
|
|
8817
|
+
_creationTime: number;
|
|
8818
|
+
_id: string;
|
|
8819
|
+
attempt: number;
|
|
8820
|
+
created?: number;
|
|
8821
|
+
eventId: string;
|
|
8822
|
+
identity: string;
|
|
8823
|
+
phase:
|
|
8824
|
+
| "started"
|
|
8825
|
+
| "accepted"
|
|
8826
|
+
| "rate_limited"
|
|
8827
|
+
| "unavailable"
|
|
8828
|
+
| "unknown"
|
|
8829
|
+
| "rejected"
|
|
8830
|
+
| "held"
|
|
8831
|
+
| "resumed"
|
|
8832
|
+
| "window_expired"
|
|
8833
|
+
| "retry_exhausted";
|
|
8834
|
+
recordedAt: number;
|
|
8835
|
+
scopeKey: string;
|
|
8836
|
+
sequence: number;
|
|
8837
|
+
}>;
|
|
8838
|
+
pageStatus?: "SplitRecommended" | "SplitRequired" | null;
|
|
8839
|
+
splitCursor?: string | null;
|
|
8840
|
+
},
|
|
8841
|
+
Name
|
|
8842
|
+
>;
|
|
8843
|
+
summary: FunctionReference<
|
|
8844
|
+
"query",
|
|
8845
|
+
"internal",
|
|
8846
|
+
{
|
|
8847
|
+
maxRecords: number;
|
|
8848
|
+
period: { end: number; start: number };
|
|
8849
|
+
scope: {
|
|
8850
|
+
customerAccount: string;
|
|
8851
|
+
livemode: boolean;
|
|
8852
|
+
meterId: string;
|
|
8853
|
+
stripeAccountId: string;
|
|
8854
|
+
};
|
|
8855
|
+
},
|
|
8856
|
+
string,
|
|
8857
|
+
Name
|
|
8858
|
+
>;
|
|
8859
|
+
validationHistory: FunctionReference<
|
|
8860
|
+
"query",
|
|
8861
|
+
"internal",
|
|
8862
|
+
{
|
|
8863
|
+
eventId: string;
|
|
8864
|
+
paginationOpts: {
|
|
8865
|
+
cursor: string | null;
|
|
8866
|
+
endCursor?: string | null;
|
|
8867
|
+
id?: number;
|
|
8868
|
+
maximumBytesRead?: number;
|
|
8869
|
+
maximumRowsRead?: number;
|
|
8870
|
+
numItems: number;
|
|
8871
|
+
};
|
|
8872
|
+
scope: {
|
|
8873
|
+
customerAccount: string;
|
|
8874
|
+
livemode: boolean;
|
|
8875
|
+
meterId: string;
|
|
8876
|
+
stripeAccountId: string;
|
|
8877
|
+
};
|
|
8878
|
+
},
|
|
8879
|
+
{
|
|
8880
|
+
continueCursor: string;
|
|
8881
|
+
isDone: boolean;
|
|
8882
|
+
page: Array<{
|
|
8883
|
+
_creationTime: number;
|
|
8884
|
+
_id: string;
|
|
8885
|
+
code:
|
|
8886
|
+
| "meter_event_customer_not_found"
|
|
8887
|
+
| "meter_event_no_customer_defined"
|
|
8888
|
+
| "meter_event_dimension_count_too_high"
|
|
8889
|
+
| "archived_meter"
|
|
8890
|
+
| "timestamp_too_far_in_past"
|
|
8891
|
+
| "timestamp_in_future"
|
|
8892
|
+
| "meter_event_value_not_found"
|
|
8893
|
+
| "meter_event_invalid_value"
|
|
8894
|
+
| "no_meter";
|
|
8895
|
+
dedupe: string;
|
|
8896
|
+
eventId: string;
|
|
8897
|
+
observedAt: number;
|
|
8898
|
+
providerEventId: string;
|
|
8899
|
+
scopeKey: string;
|
|
8900
|
+
}>;
|
|
8901
|
+
pageStatus?: "SplitRecommended" | "SplitRequired" | null;
|
|
8902
|
+
splitCursor?: string | null;
|
|
8903
|
+
},
|
|
8904
|
+
Name
|
|
8905
|
+
>;
|
|
8906
|
+
};
|
|
8907
|
+
};
|
|
8908
|
+
usageSubscriptions: {
|
|
8909
|
+
mutations: {
|
|
8910
|
+
abandon: FunctionReference<
|
|
8911
|
+
"mutation",
|
|
8912
|
+
"internal",
|
|
8913
|
+
{ key: string; proofJson: string },
|
|
8914
|
+
null,
|
|
8915
|
+
Name
|
|
8916
|
+
>;
|
|
8917
|
+
completeCancellation: FunctionReference<
|
|
8918
|
+
"mutation",
|
|
8919
|
+
"internal",
|
|
8920
|
+
{ key: string; nativeJson: string; startedAt: number },
|
|
8921
|
+
string,
|
|
8922
|
+
Name
|
|
8923
|
+
>;
|
|
8924
|
+
linkCheckout: FunctionReference<
|
|
8925
|
+
"mutation",
|
|
8926
|
+
"internal",
|
|
8927
|
+
{ checkoutId: string; key: string },
|
|
8928
|
+
null,
|
|
8929
|
+
Name
|
|
8930
|
+
>;
|
|
8931
|
+
prepare: FunctionReference<
|
|
8932
|
+
"mutation",
|
|
8933
|
+
"internal",
|
|
8934
|
+
{ method: "direct" | "checkout"; termsJson: string },
|
|
8935
|
+
{
|
|
8936
|
+
_creationTime: number;
|
|
8937
|
+
_id: string;
|
|
8938
|
+
abandonedId?: string;
|
|
8939
|
+
checkoutId?: string;
|
|
8940
|
+
controlKey?: string;
|
|
8941
|
+
firstAttemptAt: number;
|
|
8942
|
+
historyCount?: number;
|
|
8943
|
+
key: string;
|
|
8944
|
+
method: "direct" | "checkout";
|
|
8945
|
+
providerId?: string;
|
|
8946
|
+
retiredAt?: number;
|
|
8947
|
+
retirementInvoiceId?: string;
|
|
8948
|
+
scopeKey: string;
|
|
8949
|
+
startedAt?: number;
|
|
8950
|
+
termsJson: string;
|
|
8951
|
+
viewJson?: string;
|
|
8952
|
+
},
|
|
8953
|
+
Name
|
|
8954
|
+
>;
|
|
8955
|
+
prepareCancellation: FunctionReference<
|
|
8956
|
+
"mutation",
|
|
8957
|
+
"internal",
|
|
8958
|
+
{ cancelAtPeriodEnd: boolean; key: string; operationId: string },
|
|
8959
|
+
{
|
|
8960
|
+
_creationTime: number;
|
|
8961
|
+
_id: string;
|
|
8962
|
+
cancelAtPeriodEnd: boolean;
|
|
8963
|
+
firstAttemptAt: number;
|
|
8964
|
+
intentKey: string;
|
|
8965
|
+
key: string;
|
|
8966
|
+
operationId: string;
|
|
8967
|
+
resultJson?: string;
|
|
8968
|
+
},
|
|
8969
|
+
Name
|
|
8970
|
+
>;
|
|
8971
|
+
retire: FunctionReference<
|
|
8972
|
+
"mutation",
|
|
8973
|
+
"internal",
|
|
8974
|
+
{ key: string; proofJson: string },
|
|
8975
|
+
null,
|
|
8976
|
+
Name
|
|
8977
|
+
>;
|
|
8978
|
+
save: FunctionReference<
|
|
8979
|
+
"mutation",
|
|
8980
|
+
"internal",
|
|
8981
|
+
{ key: string; nativeJson: string; startedAt: number },
|
|
8982
|
+
null,
|
|
8983
|
+
Name
|
|
8984
|
+
>;
|
|
8985
|
+
saveInvoice: FunctionReference<
|
|
8986
|
+
"mutation",
|
|
8987
|
+
"internal",
|
|
8988
|
+
{
|
|
8989
|
+
invoiceId: string;
|
|
8990
|
+
key: string;
|
|
8991
|
+
observationsJson: string;
|
|
8992
|
+
startedAt: number;
|
|
8993
|
+
},
|
|
8994
|
+
null,
|
|
8995
|
+
Name
|
|
8996
|
+
>;
|
|
8997
|
+
};
|
|
8998
|
+
queries: {
|
|
8999
|
+
get: FunctionReference<
|
|
9000
|
+
"query",
|
|
9001
|
+
"internal",
|
|
9002
|
+
{
|
|
9003
|
+
requestId: string;
|
|
9004
|
+
scope: {
|
|
9005
|
+
customerAccount: string;
|
|
9006
|
+
livemode: boolean;
|
|
9007
|
+
stripeAccountId: string;
|
|
9008
|
+
};
|
|
9009
|
+
},
|
|
9010
|
+
{
|
|
9011
|
+
_creationTime: number;
|
|
9012
|
+
_id: string;
|
|
9013
|
+
abandonedId?: string;
|
|
9014
|
+
checkoutId?: string;
|
|
9015
|
+
controlKey?: string;
|
|
9016
|
+
firstAttemptAt: number;
|
|
9017
|
+
historyCount?: number;
|
|
9018
|
+
key: string;
|
|
9019
|
+
method: "direct" | "checkout";
|
|
9020
|
+
providerId?: string;
|
|
9021
|
+
retiredAt?: number;
|
|
9022
|
+
retirementInvoiceId?: string;
|
|
9023
|
+
scopeKey: string;
|
|
9024
|
+
startedAt?: number;
|
|
9025
|
+
termsJson: string;
|
|
9026
|
+
viewJson?: string;
|
|
9027
|
+
} | null,
|
|
9028
|
+
Name
|
|
9029
|
+
>;
|
|
9030
|
+
history: FunctionReference<
|
|
9031
|
+
"query",
|
|
9032
|
+
"internal",
|
|
9033
|
+
{
|
|
9034
|
+
kind: "subscription" | "invoice" | "retirement";
|
|
9035
|
+
paginationOpts: {
|
|
9036
|
+
cursor: string | null;
|
|
9037
|
+
endCursor?: string | null;
|
|
9038
|
+
id?: number;
|
|
9039
|
+
maximumBytesRead?: number;
|
|
9040
|
+
maximumRowsRead?: number;
|
|
9041
|
+
numItems: number;
|
|
9042
|
+
};
|
|
9043
|
+
requestId: string;
|
|
9044
|
+
scope: {
|
|
9045
|
+
customerAccount: string;
|
|
9046
|
+
livemode: boolean;
|
|
9047
|
+
stripeAccountId: string;
|
|
9048
|
+
};
|
|
9049
|
+
},
|
|
9050
|
+
{
|
|
9051
|
+
continueCursor: string;
|
|
9052
|
+
isDone: boolean;
|
|
9053
|
+
page: Array<{
|
|
9054
|
+
_creationTime: number;
|
|
9055
|
+
_id: string;
|
|
9056
|
+
fingerprint: string;
|
|
9057
|
+
intentKey: string;
|
|
9058
|
+
kind: "subscription" | "invoice" | "retirement";
|
|
9059
|
+
observationJson: string;
|
|
9060
|
+
resourceId: string;
|
|
9061
|
+
startedAt: number;
|
|
9062
|
+
}>;
|
|
9063
|
+
pageStatus?: "SplitRecommended" | "SplitRequired" | null;
|
|
9064
|
+
splitCursor?: string | null;
|
|
9065
|
+
},
|
|
9066
|
+
Name
|
|
9067
|
+
>;
|
|
9068
|
+
lookup: FunctionReference<
|
|
9069
|
+
"query",
|
|
9070
|
+
"internal",
|
|
9071
|
+
{ key: string },
|
|
9072
|
+
{
|
|
9073
|
+
_creationTime: number;
|
|
9074
|
+
_id: string;
|
|
9075
|
+
abandonedId?: string;
|
|
9076
|
+
checkoutId?: string;
|
|
9077
|
+
controlKey?: string;
|
|
9078
|
+
firstAttemptAt: number;
|
|
9079
|
+
historyCount?: number;
|
|
9080
|
+
key: string;
|
|
9081
|
+
method: "direct" | "checkout";
|
|
9082
|
+
providerId?: string;
|
|
9083
|
+
retiredAt?: number;
|
|
9084
|
+
retirementInvoiceId?: string;
|
|
9085
|
+
scopeKey: string;
|
|
9086
|
+
startedAt?: number;
|
|
9087
|
+
termsJson: string;
|
|
9088
|
+
viewJson?: string;
|
|
9089
|
+
} | null,
|
|
9090
|
+
Name
|
|
9091
|
+
>;
|
|
9092
|
+
};
|
|
9093
|
+
};
|
|
8759
9094
|
webhooks: {
|
|
8760
9095
|
mutations: {
|
|
8761
9096
|
insertWebhookEvent: FunctionReference<
|
|
@@ -7,6 +7,18 @@ export const prepare = mutation({
|
|
|
7
7
|
args: { stripeAccountId: v.string() },
|
|
8
8
|
returns: v.object({ closure: closureDoc, isRetry: v.boolean() }),
|
|
9
9
|
handler: async (ctx, { stripeAccountId }) => {
|
|
10
|
+
const payerLock = await ctx.db
|
|
11
|
+
.query("usageSubscriptionLocks")
|
|
12
|
+
.withIndex("by_payer", (q) => q.eq("customerAccount", stripeAccountId))
|
|
13
|
+
.first();
|
|
14
|
+
const realmLock = await ctx.db
|
|
15
|
+
.query("usageSubscriptionLocks")
|
|
16
|
+
.withIndex("by_realm", (q) => q.eq("stripeAccountId", stripeAccountId))
|
|
17
|
+
.first();
|
|
18
|
+
if (payerLock || realmLock)
|
|
19
|
+
throw new Error(
|
|
20
|
+
"Close out managed usage enrollment before account closure",
|
|
21
|
+
);
|
|
10
22
|
const existing = await closureByStripeId(ctx, stripeAccountId);
|
|
11
23
|
if (existing) return { closure: existing, isRetry: true };
|
|
12
24
|
const account = await ctx.db
|
package/src/component/schema.ts
CHANGED
|
@@ -1,3 +1,13 @@
|
|
|
1
|
+
import {
|
|
2
|
+
controlsTable as usageSubscriptionControls,
|
|
3
|
+
intentsTable as usageSubscriptionIntents,
|
|
4
|
+
locksTable as usageSubscriptionLocks,
|
|
5
|
+
historyTable as usageSubscriptionHistory,
|
|
6
|
+
} from "./usageSubscriptions/schema.js";
|
|
7
|
+
import {
|
|
8
|
+
historyTable as usageDeliveryHistory,
|
|
9
|
+
observationsTable as usageProviderObservations,
|
|
10
|
+
} from "./usageObservations/schema.js";
|
|
1
11
|
import {
|
|
2
12
|
errorsTable as usageDeliveryErrors,
|
|
3
13
|
locksTable as usageDeliveryLocks,
|
|
@@ -100,6 +110,12 @@ import { pricesTable, productsTable } from "./products/schema";
|
|
|
100
110
|
import { webhookEventsTable } from "./webhooks/schema";
|
|
101
111
|
|
|
102
112
|
export default defineSchema({
|
|
113
|
+
usageSubscriptionControls,
|
|
114
|
+
usageSubscriptionIntents,
|
|
115
|
+
usageSubscriptionLocks,
|
|
116
|
+
usageSubscriptionHistory,
|
|
117
|
+
usageProviderObservations,
|
|
118
|
+
usageDeliveryHistory,
|
|
103
119
|
usageDeliveryLocks,
|
|
104
120
|
usageDeliveryErrors,
|
|
105
121
|
usageCatalog: usageCatalogTable,
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { managedBillingCutoff } from "../usageSubscriptions/acceptance.js";
|
|
1
2
|
import { v } from "convex/values";
|
|
2
3
|
import type { FunctionHandle } from "convex/server";
|
|
3
4
|
import { mutation } from "../_generated/server.js";
|
|
@@ -61,6 +62,9 @@ export const record = mutation({
|
|
|
61
62
|
};
|
|
62
63
|
}
|
|
63
64
|
const now = Math.floor(Date.now() / 1000);
|
|
65
|
+
const cutoff = await managedBillingCutoff(ctx, event, subscription);
|
|
66
|
+
if (cutoff !== null && now >= cutoff)
|
|
67
|
+
throw new Error("Managed usage billing period is closing or closed");
|
|
64
68
|
if (event.occurredAt < now - 35 * 86400 || event.occurredAt > now + 300)
|
|
65
69
|
throw new Error("Usage occurrence is outside the native delivery window");
|
|
66
70
|
if (
|
|
@@ -96,6 +100,7 @@ export const record = mutation({
|
|
|
96
100
|
)
|
|
97
101
|
throw new Error("Usage reservation does not match event");
|
|
98
102
|
const eventId = await ctx.db.insert("usageEvents", {
|
|
103
|
+
subscriptionId: subscription.subscriptionId,
|
|
99
104
|
reservationId: args.reservationId,
|
|
100
105
|
scopeKey: key,
|
|
101
106
|
identity: event.identity,
|
|
@@ -17,6 +17,7 @@ export const deliveryValidator = v.union(
|
|
|
17
17
|
v.literal("held"),
|
|
18
18
|
);
|
|
19
19
|
export const eventFields = {
|
|
20
|
+
subscriptionId: v.optional(v.string()),
|
|
20
21
|
reservationId: v.optional(v.id("usageReservations")),
|
|
21
22
|
scopeKey: v.string(),
|
|
22
23
|
identity: v.string(),
|
|
@@ -32,6 +33,7 @@ export const eventDoc = v.object({
|
|
|
32
33
|
});
|
|
33
34
|
export const usageEventsTable = defineTable(eventFields)
|
|
34
35
|
.index("by_identity", ["identity"])
|
|
36
|
+
.index("by_scope_subscription", ["scopeKey", "subscriptionId"])
|
|
35
37
|
.index("by_scope_time", ["scopeKey", "occurredAt"]);
|
|
36
38
|
export const outboxFields = {
|
|
37
39
|
...deliveryFields,
|
|
@@ -71,4 +73,6 @@ export const usageReservationsTable = defineTable({
|
|
|
71
73
|
v.literal("released"),
|
|
72
74
|
),
|
|
73
75
|
eventId: v.optional(v.id("usageEvents")),
|
|
74
|
-
})
|
|
76
|
+
})
|
|
77
|
+
.index("by_scope_source", ["scopeKey", "sourceEventId"])
|
|
78
|
+
.index("by_scope_state", ["scopeKey", "state"]);
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { defineTable } from "convex/server";
|
|
2
2
|
import { v } from "convex/values";
|
|
3
3
|
export const reason = v.union(
|
|
4
|
+
v.literal("billing_period_closed"),
|
|
4
5
|
v.literal("rate_limited"),
|
|
5
6
|
v.literal("provider_unavailable"),
|
|
6
7
|
v.literal("provider_outcome_unknown"),
|
|
@@ -12,6 +13,7 @@ export const reason = v.union(
|
|
|
12
13
|
);
|
|
13
14
|
export { usageDeliveryOutcomeValidator as outcome } from "../../client/usage/deliveryProtocol.js";
|
|
14
15
|
export const deliveryFields = {
|
|
16
|
+
historySequence: v.optional(v.number()),
|
|
15
17
|
provider: v.optional(v.string()),
|
|
16
18
|
workflowId: v.optional(v.string()),
|
|
17
19
|
definitionVersion: v.optional(v.literal(1)),
|
|
@@ -56,4 +58,5 @@ export const errorDoc = v.object({
|
|
|
56
58
|
});
|
|
57
59
|
export const errorsTable = defineTable(errorFields)
|
|
58
60
|
.index("by_dedupe", ["dedupe"])
|
|
61
|
+
.index("by_scope", ["scopeKey"])
|
|
59
62
|
.index("by_event", ["eventId"]);
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { appendDeliveryHistory } from "../usageObservations/history.js";
|
|
1
2
|
import { errorCode } from "./fields.js";
|
|
2
3
|
import type { PreparedUsageRecord } from "../../client/usage/records.js";
|
|
3
4
|
import { mutation } from "../_generated/server.js";
|
|
@@ -81,6 +82,14 @@ export const hold = mutation({
|
|
|
81
82
|
? { state: "held" as const, reason: "administrative_hold" as const }
|
|
82
83
|
: {}),
|
|
83
84
|
});
|
|
85
|
+
if (!outbox.held)
|
|
86
|
+
await appendDeliveryHistory(
|
|
87
|
+
ctx,
|
|
88
|
+
args.eventId,
|
|
89
|
+
"held",
|
|
90
|
+
outbox.attempts,
|
|
91
|
+
`control:${(outbox.historySequence ?? 0) + 1}:held`,
|
|
92
|
+
);
|
|
84
93
|
return await currentStatus(ctx, (await read(ctx, args)).outbox);
|
|
85
94
|
},
|
|
86
95
|
});
|
|
@@ -94,8 +103,16 @@ export const resume = mutation({
|
|
|
94
103
|
["provider_accepted", "rejected"].includes(outbox.state) ||
|
|
95
104
|
outbox.reason === "delivery_window_expired"
|
|
96
105
|
) {
|
|
97
|
-
if (outbox.held)
|
|
106
|
+
if (outbox.held) {
|
|
98
107
|
await ctx.db.patch("usageOutbox", outbox._id, { held: false });
|
|
108
|
+
await appendDeliveryHistory(
|
|
109
|
+
ctx,
|
|
110
|
+
args.eventId,
|
|
111
|
+
"resumed",
|
|
112
|
+
outbox.attempts,
|
|
113
|
+
`control:${(outbox.historySequence ?? 0) + 1}:resumed`,
|
|
114
|
+
);
|
|
115
|
+
}
|
|
99
116
|
return await currentStatus(ctx, (await read(ctx, args)).outbox);
|
|
100
117
|
}
|
|
101
118
|
if (!outbox.provider)
|
|
@@ -105,6 +122,14 @@ export const resume = mutation({
|
|
|
105
122
|
state: outbox.state === "sending" ? "sending" : "queued",
|
|
106
123
|
reason: undefined,
|
|
107
124
|
});
|
|
125
|
+
if (outbox.held || outbox.state === "held")
|
|
126
|
+
await appendDeliveryHistory(
|
|
127
|
+
ctx,
|
|
128
|
+
args.eventId,
|
|
129
|
+
"resumed",
|
|
130
|
+
outbox.attempts,
|
|
131
|
+
`control:${(outbox.historySequence ?? 0) + 1}:resumed`,
|
|
132
|
+
);
|
|
108
133
|
await launch(ctx, args, outbox);
|
|
109
134
|
return await currentStatus(ctx, (await read(ctx, args)).outbox);
|
|
110
135
|
},
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { managedBillingPolicy } from "../usageSubscriptions/acceptance.js";
|
|
2
|
+
import { subscriptionSnapshot } from "../usage/helpers.js";
|
|
1
3
|
import { query, internalQuery } from "../_generated/server.js";
|
|
2
4
|
import { refFields, status } from "./schema.js";
|
|
3
5
|
import { read, currentStatus } from "./helpers.js";
|
|
@@ -11,13 +13,38 @@ export const get = query({
|
|
|
11
13
|
});
|
|
12
14
|
const snapshotDefinition = {
|
|
13
15
|
args: refFields,
|
|
14
|
-
returns: v.object({
|
|
16
|
+
returns: v.object({
|
|
17
|
+
event: eventDoc,
|
|
18
|
+
outbox: outboxDoc,
|
|
19
|
+
billingCutoff: v.union(v.number(), v.null()),
|
|
20
|
+
managedCollection: v.union(
|
|
21
|
+
v.null(),
|
|
22
|
+
v.object({
|
|
23
|
+
method: v.union(
|
|
24
|
+
v.literal("send_invoice"),
|
|
25
|
+
v.literal("charge_automatically"),
|
|
26
|
+
),
|
|
27
|
+
daysUntilDue: v.union(v.number(), v.null()),
|
|
28
|
+
defaultPaymentMethod: v.union(v.string(), v.null()),
|
|
29
|
+
}),
|
|
30
|
+
),
|
|
31
|
+
}),
|
|
15
32
|
handler: async (
|
|
16
33
|
ctx: import("../_generated/server.js").QueryCtx,
|
|
17
34
|
args: import("convex/values").Infer<typeof _refValidator>,
|
|
18
35
|
) => {
|
|
19
|
-
const { event, outbox } = await read(ctx, args);
|
|
20
|
-
|
|
36
|
+
const { event, outbox, record } = await read(ctx, args);
|
|
37
|
+
const policy = await managedBillingPolicy(
|
|
38
|
+
ctx,
|
|
39
|
+
record,
|
|
40
|
+
subscriptionSnapshot(event.subscriptionJson),
|
|
41
|
+
);
|
|
42
|
+
return {
|
|
43
|
+
event,
|
|
44
|
+
outbox,
|
|
45
|
+
billingCutoff: policy?.cutoff ?? null,
|
|
46
|
+
managedCollection: policy?.collection ?? null,
|
|
47
|
+
};
|
|
21
48
|
},
|
|
22
49
|
};
|
|
23
50
|
const _refValidator = v.object(refFields);
|