@fantastic.dev/better-stripe 0.52.0 → 0.54.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 +1 -1
- package/dist/client/connect/payoutAdoptionTestHelpers.d.ts +160 -2
- package/dist/client/connect/payoutAdoptionTestHelpers.d.ts.map +1 -1
- package/dist/client/connect/payoutExecutionTestHelpers.d.ts +80 -1
- package/dist/client/connect/payoutExecutionTestHelpers.d.ts.map +1 -1
- package/dist/client/connect/payoutLargeAdoptionTestHelpers.d.ts +160 -2
- package/dist/client/connect/payoutLargeAdoptionTestHelpers.d.ts.map +1 -1
- package/dist/client/connect/payoutSyncTestHelpers.d.ts +80 -1
- package/dist/client/connect/payoutSyncTestHelpers.d.ts.map +1 -1
- package/dist/client/index.d.ts +6 -0
- package/dist/client/index.d.ts.map +1 -1
- package/dist/client/index.js +2 -0
- package/dist/client/index.js.map +1 -1
- package/dist/client/products/catalogClient.d.ts +23 -0
- package/dist/client/products/catalogClient.d.ts.map +1 -1
- package/dist/client/products/catalogClient.js +32 -0
- package/dist/client/products/catalogClient.js.map +1 -1
- package/dist/client/products/fixedPrice.d.ts +4 -0
- package/dist/client/products/fixedPrice.d.ts.map +1 -0
- package/dist/client/products/fixedPrice.js +10 -0
- package/dist/client/products/fixedPrice.js.map +1 -0
- package/dist/client/products/products.d.ts.map +1 -1
- package/dist/client/products/products.js +3 -0
- package/dist/client/products/products.js.map +1 -1
- package/dist/client/usage/catalog.d.ts +7 -0
- package/dist/client/usage/catalog.d.ts.map +1 -0
- package/dist/client/usage/catalog.js +55 -0
- package/dist/client/usage/catalog.js.map +1 -0
- package/dist/client/usage/catalogLifecycle.d.ts +25 -0
- package/dist/client/usage/catalogLifecycle.d.ts.map +1 -0
- package/dist/client/usage/catalogLifecycle.js +64 -0
- package/dist/client/usage/catalogLifecycle.js.map +1 -0
- package/dist/client/usage/catalogMath.d.ts +3 -0
- package/dist/client/usage/catalogMath.d.ts.map +1 -0
- package/dist/client/usage/catalogMath.js +21 -0
- package/dist/client/usage/catalogMath.js.map +1 -0
- package/dist/client/usage/catalogPrices.d.ts +5 -0
- package/dist/client/usage/catalogPrices.d.ts.map +1 -0
- package/dist/client/usage/catalogPrices.js +178 -0
- package/dist/client/usage/catalogPrices.js.map +1 -0
- package/dist/client/usage/catalogRead.d.ts +25 -0
- package/dist/client/usage/catalogRead.d.ts.map +1 -0
- package/dist/client/usage/catalogRead.js +71 -0
- package/dist/client/usage/catalogRead.js.map +1 -0
- package/dist/client/usage/catalogTypes.d.ts +97 -0
- package/dist/client/usage/catalogTypes.d.ts.map +1 -0
- package/dist/client/usage/catalogTypes.js +106 -0
- package/dist/client/usage/catalogTypes.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 +3 -3
- package/dist/client/usage/client.js.map +1 -1
- package/dist/client/usage/deliveryClient.d.ts +64 -0
- package/dist/client/usage/deliveryClient.d.ts.map +1 -0
- package/dist/client/usage/deliveryClient.js +60 -0
- package/dist/client/usage/deliveryClient.js.map +1 -0
- package/dist/client/usage/deliveryProtocol.d.ts +130 -0
- package/dist/client/usage/deliveryProtocol.d.ts.map +1 -0
- package/dist/client/usage/deliveryProtocol.js +21 -0
- package/dist/client/usage/deliveryProtocol.js.map +1 -0
- package/dist/client/usage/deliveryProvider.d.ts +32 -0
- package/dist/client/usage/deliveryProvider.d.ts.map +1 -0
- package/dist/client/usage/deliveryProvider.js +127 -0
- package/dist/client/usage/deliveryProvider.js.map +1 -0
- package/dist/client/usage/index.d.ts +3 -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/webhooks/handler.d.ts.map +1 -1
- package/dist/client/webhooks/handler.js +2 -1
- package/dist/client/webhooks/handler.js.map +1 -1
- package/dist/client/webhooks/meterErrors.d.ts +5 -0
- package/dist/client/webhooks/meterErrors.d.ts.map +1 -0
- package/dist/client/webhooks/meterErrors.js +98 -0
- package/dist/client/webhooks/meterErrors.js.map +1 -0
- package/dist/client/webhooks/processors.d.ts.map +1 -1
- package/dist/client/webhooks/processors.js +3 -0
- package/dist/client/webhooks/processors.js.map +1 -1
- package/dist/client/webhooks/v2.d.ts.map +1 -1
- package/dist/client/webhooks/v2.js +5 -0
- package/dist/client/webhooks/v2.js.map +1 -1
- package/dist/component/_generated/api.d.ts +18 -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 +232 -0
- package/dist/component/_generated/component.d.ts.map +1 -1
- package/dist/component/earnings/triggers.d.ts +150 -2
- 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 +80 -1
- package/dist/component/schema.js +5 -0
- package/dist/component/schema.js.map +1 -1
- package/dist/component/usage/schema.d.ts +96 -1
- package/dist/component/usage/schema.d.ts.map +1 -1
- package/dist/component/usage/schema.js +11 -2
- package/dist/component/usage/schema.js.map +1 -1
- package/dist/component/usageCatalog/mutations.d.ts +25 -0
- package/dist/component/usageCatalog/mutations.d.ts.map +1 -0
- package/dist/component/usageCatalog/mutations.js +75 -0
- package/dist/component/usageCatalog/mutations.js.map +1 -0
- package/dist/component/usageCatalog/queries.d.ts +33 -0
- package/dist/component/usageCatalog/queries.d.ts.map +1 -0
- package/dist/component/usageCatalog/queries.js +26 -0
- package/dist/component/usageCatalog/queries.js.map +1 -0
- package/dist/component/usageCatalog/schema.d.ts +57 -0
- package/dist/component/usageCatalog/schema.d.ts.map +1 -0
- package/dist/component/usageCatalog/schema.js +22 -0
- package/dist/component/usageCatalog/schema.js.map +1 -0
- package/dist/component/usageDelivery/bridge.d.ts +25 -0
- package/dist/component/usageDelivery/bridge.d.ts.map +1 -0
- package/dist/component/usageDelivery/bridge.js +45 -0
- package/dist/component/usageDelivery/bridge.js.map +1 -0
- package/dist/component/usageDelivery/fields.d.ts +78 -0
- package/dist/component/usageDelivery/fields.d.ts.map +1 -0
- package/dist/component/usageDelivery/fields.js +38 -0
- package/dist/component/usageDelivery/fields.js.map +1 -0
- package/dist/component/usageDelivery/helpers.d.ts +83 -0
- package/dist/component/usageDelivery/helpers.d.ts.map +1 -0
- package/dist/component/usageDelivery/helpers.js +63 -0
- package/dist/component/usageDelivery/helpers.js.map +1 -0
- package/dist/component/usageDelivery/mutations.d.ts +97 -0
- package/dist/component/usageDelivery/mutations.d.ts.map +1 -0
- package/dist/component/usageDelivery/mutations.js +153 -0
- package/dist/component/usageDelivery/mutations.js.map +1 -0
- package/dist/component/usageDelivery/queries.d.ts +113 -0
- package/dist/component/usageDelivery/queries.d.ts.map +1 -0
- package/dist/component/usageDelivery/queries.js +22 -0
- package/dist/component/usageDelivery/queries.js.map +1 -0
- package/dist/component/usageDelivery/schema.d.ts +79 -0
- package/dist/component/usageDelivery/schema.d.ts.map +1 -0
- package/dist/component/usageDelivery/schema.js +30 -0
- package/dist/component/usageDelivery/schema.js.map +1 -0
- package/dist/component/usageDelivery/steps.d.ts +85 -0
- package/dist/component/usageDelivery/steps.d.ts.map +1 -0
- package/dist/component/usageDelivery/steps.js +154 -0
- package/dist/component/usageDelivery/steps.js.map +1 -0
- package/dist/component/usageDelivery/workflow.d.ts +15 -0
- package/dist/component/usageDelivery/workflow.d.ts.map +1 -0
- package/dist/component/usageDelivery/workflow.js +28 -0
- package/dist/component/usageDelivery/workflow.js.map +1 -0
- package/docs/README.md +5 -1
- package/docs/metering-setup.md +3 -1
- package/docs/usage-catalog.md +106 -0
- package/docs/usage-delivery.md +143 -0
- package/package.json +4 -2
- package/src/client/index.ts +23 -0
- package/src/client/products/catalogClient.ts +77 -0
- package/src/client/products/fixedPrice.test.ts +57 -0
- package/src/client/products/fixedPrice.ts +13 -0
- package/src/client/products/products.ts +2 -0
- package/src/client/usage/catalog.test.ts +464 -0
- package/src/client/usage/catalog.ts +117 -0
- package/src/client/usage/catalogLifecycle.ts +128 -0
- package/src/client/usage/catalogMath.test.ts +13 -0
- package/src/client/usage/catalogMath.ts +22 -0
- package/src/client/usage/catalogPrices.ts +251 -0
- package/src/client/usage/catalogRead.ts +98 -0
- package/src/client/usage/catalogTypes.ts +170 -0
- package/src/client/usage/client.ts +5 -2
- package/src/client/usage/deliveryClient.ts +130 -0
- package/src/client/usage/deliveryProtocol.ts +26 -0
- package/src/client/usage/deliveryProvider.test.ts +207 -0
- package/src/client/usage/deliveryProvider.ts +155 -0
- package/src/client/usage/index.ts +13 -0
- package/src/client/webhooks/handler.ts +2 -1
- package/src/client/webhooks/meterErrors.test.ts +164 -0
- package/src/client/webhooks/meterErrors.ts +118 -0
- package/src/client/webhooks/processors.ts +2 -0
- package/src/client/webhooks/v2.ts +5 -0
- package/src/component/_generated/api.ts +18 -0
- package/src/component/_generated/component.ts +380 -0
- package/src/component/schema.ts +8 -0
- package/src/component/usage/schema.ts +11 -2
- package/src/component/usageCatalog/mutations.ts +79 -0
- package/src/component/usageCatalog/queries.ts +32 -0
- package/src/component/usageCatalog/schema.ts +21 -0
- package/src/component/usageDelivery/bridge.ts +56 -0
- package/src/component/usageDelivery/concurrency.test.ts +62 -0
- package/src/component/usageDelivery/fields.ts +59 -0
- package/src/component/usageDelivery/helpers.ts +77 -0
- package/src/component/usageDelivery/mutations.ts +185 -0
- package/src/component/usageDelivery/queries.ts +25 -0
- package/src/component/usageDelivery/schema.ts +33 -0
- package/src/component/usageDelivery/steps.ts +171 -0
- package/src/component/usageDelivery/workflow.test.ts +402 -0
- package/src/component/usageDelivery/workflow.ts +36 -0
|
@@ -8376,6 +8376,386 @@ export type ComponentApi<Name extends string | undefined = string | undefined> =
|
|
|
8376
8376
|
>;
|
|
8377
8377
|
};
|
|
8378
8378
|
};
|
|
8379
|
+
usageCatalog: {
|
|
8380
|
+
mutations: {
|
|
8381
|
+
complete: FunctionReference<
|
|
8382
|
+
"mutation",
|
|
8383
|
+
"internal",
|
|
8384
|
+
{
|
|
8385
|
+
key: string;
|
|
8386
|
+
kind: "meter" | "price";
|
|
8387
|
+
observationJson: string;
|
|
8388
|
+
providerId: string;
|
|
8389
|
+
scopeKey: string;
|
|
8390
|
+
},
|
|
8391
|
+
null,
|
|
8392
|
+
Name
|
|
8393
|
+
>;
|
|
8394
|
+
prepare: FunctionReference<
|
|
8395
|
+
"mutation",
|
|
8396
|
+
"internal",
|
|
8397
|
+
{
|
|
8398
|
+
key: string;
|
|
8399
|
+
kind: "meter" | "price";
|
|
8400
|
+
scopeKey: string;
|
|
8401
|
+
termsJson: string;
|
|
8402
|
+
},
|
|
8403
|
+
{
|
|
8404
|
+
_creationTime: number;
|
|
8405
|
+
_id: string;
|
|
8406
|
+
firstAttemptAt: number;
|
|
8407
|
+
key: string;
|
|
8408
|
+
kind: "meter" | "price";
|
|
8409
|
+
observationJson?: string;
|
|
8410
|
+
observedAt?: number;
|
|
8411
|
+
providerId?: string;
|
|
8412
|
+
scopeKey: string;
|
|
8413
|
+
termsJson: string;
|
|
8414
|
+
},
|
|
8415
|
+
Name
|
|
8416
|
+
>;
|
|
8417
|
+
};
|
|
8418
|
+
queries: {
|
|
8419
|
+
get: FunctionReference<
|
|
8420
|
+
"query",
|
|
8421
|
+
"internal",
|
|
8422
|
+
{ key: string; kind: "meter" | "price"; scopeKey: string },
|
|
8423
|
+
{
|
|
8424
|
+
_creationTime: number;
|
|
8425
|
+
_id: string;
|
|
8426
|
+
firstAttemptAt: number;
|
|
8427
|
+
key: string;
|
|
8428
|
+
kind: "meter" | "price";
|
|
8429
|
+
observationJson?: string;
|
|
8430
|
+
observedAt?: number;
|
|
8431
|
+
providerId?: string;
|
|
8432
|
+
scopeKey: string;
|
|
8433
|
+
termsJson: string;
|
|
8434
|
+
} | null,
|
|
8435
|
+
Name
|
|
8436
|
+
>;
|
|
8437
|
+
getByProvider: FunctionReference<
|
|
8438
|
+
"query",
|
|
8439
|
+
"internal",
|
|
8440
|
+
{ kind: "meter" | "price"; providerId: string; scopeKey: string },
|
|
8441
|
+
{
|
|
8442
|
+
_creationTime: number;
|
|
8443
|
+
_id: string;
|
|
8444
|
+
firstAttemptAt: number;
|
|
8445
|
+
key: string;
|
|
8446
|
+
kind: "meter" | "price";
|
|
8447
|
+
observationJson?: string;
|
|
8448
|
+
observedAt?: number;
|
|
8449
|
+
providerId?: string;
|
|
8450
|
+
scopeKey: string;
|
|
8451
|
+
termsJson: string;
|
|
8452
|
+
} | null,
|
|
8453
|
+
Name
|
|
8454
|
+
>;
|
|
8455
|
+
};
|
|
8456
|
+
};
|
|
8457
|
+
usageDelivery: {
|
|
8458
|
+
mutations: {
|
|
8459
|
+
hold: FunctionReference<
|
|
8460
|
+
"mutation",
|
|
8461
|
+
"internal",
|
|
8462
|
+
{
|
|
8463
|
+
eventId: string;
|
|
8464
|
+
scope: {
|
|
8465
|
+
customerAccount: string;
|
|
8466
|
+
livemode: boolean;
|
|
8467
|
+
meterId: string;
|
|
8468
|
+
stripeAccountId: string;
|
|
8469
|
+
};
|
|
8470
|
+
},
|
|
8471
|
+
{
|
|
8472
|
+
attempts: number;
|
|
8473
|
+
eventId: string;
|
|
8474
|
+
held: boolean;
|
|
8475
|
+
providerIdentifier: string;
|
|
8476
|
+
reason?:
|
|
8477
|
+
| "rate_limited"
|
|
8478
|
+
| "provider_unavailable"
|
|
8479
|
+
| "provider_outcome_unknown"
|
|
8480
|
+
| "provider_rejected"
|
|
8481
|
+
| "retry_exhausted"
|
|
8482
|
+
| "delivery_window_expired"
|
|
8483
|
+
| "scope_busy"
|
|
8484
|
+
| "administrative_hold";
|
|
8485
|
+
receipt?: { created: number; identifier: string };
|
|
8486
|
+
state:
|
|
8487
|
+
| "queued"
|
|
8488
|
+
| "sending"
|
|
8489
|
+
| "provider_accepted"
|
|
8490
|
+
| "rejected"
|
|
8491
|
+
| "unknown"
|
|
8492
|
+
| "held";
|
|
8493
|
+
validationErrors: Array<{
|
|
8494
|
+
code:
|
|
8495
|
+
| "meter_event_customer_not_found"
|
|
8496
|
+
| "meter_event_no_customer_defined"
|
|
8497
|
+
| "meter_event_dimension_count_too_high"
|
|
8498
|
+
| "archived_meter"
|
|
8499
|
+
| "timestamp_too_far_in_past"
|
|
8500
|
+
| "timestamp_in_future"
|
|
8501
|
+
| "meter_event_value_not_found"
|
|
8502
|
+
| "meter_event_invalid_value"
|
|
8503
|
+
| "no_meter";
|
|
8504
|
+
observedAt: number;
|
|
8505
|
+
providerEventId: string;
|
|
8506
|
+
}>;
|
|
8507
|
+
validationHistoryComplete: boolean;
|
|
8508
|
+
},
|
|
8509
|
+
Name
|
|
8510
|
+
>;
|
|
8511
|
+
recordErrorReport: FunctionReference<
|
|
8512
|
+
"mutation",
|
|
8513
|
+
"internal",
|
|
8514
|
+
{
|
|
8515
|
+
livemode: boolean;
|
|
8516
|
+
meterId?: string;
|
|
8517
|
+
providerEventId: string;
|
|
8518
|
+
samples: Array<{
|
|
8519
|
+
code:
|
|
8520
|
+
| "meter_event_customer_not_found"
|
|
8521
|
+
| "meter_event_no_customer_defined"
|
|
8522
|
+
| "meter_event_dimension_count_too_high"
|
|
8523
|
+
| "archived_meter"
|
|
8524
|
+
| "timestamp_too_far_in_past"
|
|
8525
|
+
| "timestamp_in_future"
|
|
8526
|
+
| "meter_event_value_not_found"
|
|
8527
|
+
| "meter_event_invalid_value"
|
|
8528
|
+
| "no_meter";
|
|
8529
|
+
identifier: string;
|
|
8530
|
+
}>;
|
|
8531
|
+
stripeAccountId: string;
|
|
8532
|
+
truncated: boolean;
|
|
8533
|
+
},
|
|
8534
|
+
{ matched: number; truncated: boolean; unattributed: number },
|
|
8535
|
+
Name
|
|
8536
|
+
>;
|
|
8537
|
+
resume: FunctionReference<
|
|
8538
|
+
"mutation",
|
|
8539
|
+
"internal",
|
|
8540
|
+
{
|
|
8541
|
+
eventId: string;
|
|
8542
|
+
scope: {
|
|
8543
|
+
customerAccount: string;
|
|
8544
|
+
livemode: boolean;
|
|
8545
|
+
meterId: string;
|
|
8546
|
+
stripeAccountId: string;
|
|
8547
|
+
};
|
|
8548
|
+
},
|
|
8549
|
+
{
|
|
8550
|
+
attempts: number;
|
|
8551
|
+
eventId: string;
|
|
8552
|
+
held: boolean;
|
|
8553
|
+
providerIdentifier: string;
|
|
8554
|
+
reason?:
|
|
8555
|
+
| "rate_limited"
|
|
8556
|
+
| "provider_unavailable"
|
|
8557
|
+
| "provider_outcome_unknown"
|
|
8558
|
+
| "provider_rejected"
|
|
8559
|
+
| "retry_exhausted"
|
|
8560
|
+
| "delivery_window_expired"
|
|
8561
|
+
| "scope_busy"
|
|
8562
|
+
| "administrative_hold";
|
|
8563
|
+
receipt?: { created: number; identifier: string };
|
|
8564
|
+
state:
|
|
8565
|
+
| "queued"
|
|
8566
|
+
| "sending"
|
|
8567
|
+
| "provider_accepted"
|
|
8568
|
+
| "rejected"
|
|
8569
|
+
| "unknown"
|
|
8570
|
+
| "held";
|
|
8571
|
+
validationErrors: Array<{
|
|
8572
|
+
code:
|
|
8573
|
+
| "meter_event_customer_not_found"
|
|
8574
|
+
| "meter_event_no_customer_defined"
|
|
8575
|
+
| "meter_event_dimension_count_too_high"
|
|
8576
|
+
| "archived_meter"
|
|
8577
|
+
| "timestamp_too_far_in_past"
|
|
8578
|
+
| "timestamp_in_future"
|
|
8579
|
+
| "meter_event_value_not_found"
|
|
8580
|
+
| "meter_event_invalid_value"
|
|
8581
|
+
| "no_meter";
|
|
8582
|
+
observedAt: number;
|
|
8583
|
+
providerEventId: string;
|
|
8584
|
+
}>;
|
|
8585
|
+
validationHistoryComplete: boolean;
|
|
8586
|
+
},
|
|
8587
|
+
Name
|
|
8588
|
+
>;
|
|
8589
|
+
start: FunctionReference<
|
|
8590
|
+
"mutation",
|
|
8591
|
+
"internal",
|
|
8592
|
+
{
|
|
8593
|
+
definitionVersion: 1;
|
|
8594
|
+
eventId: string;
|
|
8595
|
+
provider: string;
|
|
8596
|
+
scope: {
|
|
8597
|
+
customerAccount: string;
|
|
8598
|
+
livemode: boolean;
|
|
8599
|
+
meterId: string;
|
|
8600
|
+
stripeAccountId: string;
|
|
8601
|
+
};
|
|
8602
|
+
},
|
|
8603
|
+
{
|
|
8604
|
+
attempts: number;
|
|
8605
|
+
eventId: string;
|
|
8606
|
+
held: boolean;
|
|
8607
|
+
providerIdentifier: string;
|
|
8608
|
+
reason?:
|
|
8609
|
+
| "rate_limited"
|
|
8610
|
+
| "provider_unavailable"
|
|
8611
|
+
| "provider_outcome_unknown"
|
|
8612
|
+
| "provider_rejected"
|
|
8613
|
+
| "retry_exhausted"
|
|
8614
|
+
| "delivery_window_expired"
|
|
8615
|
+
| "scope_busy"
|
|
8616
|
+
| "administrative_hold";
|
|
8617
|
+
receipt?: { created: number; identifier: string };
|
|
8618
|
+
state:
|
|
8619
|
+
| "queued"
|
|
8620
|
+
| "sending"
|
|
8621
|
+
| "provider_accepted"
|
|
8622
|
+
| "rejected"
|
|
8623
|
+
| "unknown"
|
|
8624
|
+
| "held";
|
|
8625
|
+
validationErrors: Array<{
|
|
8626
|
+
code:
|
|
8627
|
+
| "meter_event_customer_not_found"
|
|
8628
|
+
| "meter_event_no_customer_defined"
|
|
8629
|
+
| "meter_event_dimension_count_too_high"
|
|
8630
|
+
| "archived_meter"
|
|
8631
|
+
| "timestamp_too_far_in_past"
|
|
8632
|
+
| "timestamp_in_future"
|
|
8633
|
+
| "meter_event_value_not_found"
|
|
8634
|
+
| "meter_event_invalid_value"
|
|
8635
|
+
| "no_meter";
|
|
8636
|
+
observedAt: number;
|
|
8637
|
+
providerEventId: string;
|
|
8638
|
+
}>;
|
|
8639
|
+
validationHistoryComplete: boolean;
|
|
8640
|
+
},
|
|
8641
|
+
Name
|
|
8642
|
+
>;
|
|
8643
|
+
};
|
|
8644
|
+
queries: {
|
|
8645
|
+
get: FunctionReference<
|
|
8646
|
+
"query",
|
|
8647
|
+
"internal",
|
|
8648
|
+
{
|
|
8649
|
+
eventId: string;
|
|
8650
|
+
scope: {
|
|
8651
|
+
customerAccount: string;
|
|
8652
|
+
livemode: boolean;
|
|
8653
|
+
meterId: string;
|
|
8654
|
+
stripeAccountId: string;
|
|
8655
|
+
};
|
|
8656
|
+
},
|
|
8657
|
+
{
|
|
8658
|
+
attempts: number;
|
|
8659
|
+
eventId: string;
|
|
8660
|
+
held: boolean;
|
|
8661
|
+
providerIdentifier: string;
|
|
8662
|
+
reason?:
|
|
8663
|
+
| "rate_limited"
|
|
8664
|
+
| "provider_unavailable"
|
|
8665
|
+
| "provider_outcome_unknown"
|
|
8666
|
+
| "provider_rejected"
|
|
8667
|
+
| "retry_exhausted"
|
|
8668
|
+
| "delivery_window_expired"
|
|
8669
|
+
| "scope_busy"
|
|
8670
|
+
| "administrative_hold";
|
|
8671
|
+
receipt?: { created: number; identifier: string };
|
|
8672
|
+
state:
|
|
8673
|
+
| "queued"
|
|
8674
|
+
| "sending"
|
|
8675
|
+
| "provider_accepted"
|
|
8676
|
+
| "rejected"
|
|
8677
|
+
| "unknown"
|
|
8678
|
+
| "held";
|
|
8679
|
+
validationErrors: Array<{
|
|
8680
|
+
code:
|
|
8681
|
+
| "meter_event_customer_not_found"
|
|
8682
|
+
| "meter_event_no_customer_defined"
|
|
8683
|
+
| "meter_event_dimension_count_too_high"
|
|
8684
|
+
| "archived_meter"
|
|
8685
|
+
| "timestamp_too_far_in_past"
|
|
8686
|
+
| "timestamp_in_future"
|
|
8687
|
+
| "meter_event_value_not_found"
|
|
8688
|
+
| "meter_event_invalid_value"
|
|
8689
|
+
| "no_meter";
|
|
8690
|
+
observedAt: number;
|
|
8691
|
+
providerEventId: string;
|
|
8692
|
+
}>;
|
|
8693
|
+
validationHistoryComplete: boolean;
|
|
8694
|
+
},
|
|
8695
|
+
Name
|
|
8696
|
+
>;
|
|
8697
|
+
snapshot: FunctionReference<
|
|
8698
|
+
"query",
|
|
8699
|
+
"internal",
|
|
8700
|
+
{
|
|
8701
|
+
eventId: string;
|
|
8702
|
+
scope: {
|
|
8703
|
+
customerAccount: string;
|
|
8704
|
+
livemode: boolean;
|
|
8705
|
+
meterId: string;
|
|
8706
|
+
stripeAccountId: string;
|
|
8707
|
+
};
|
|
8708
|
+
},
|
|
8709
|
+
{
|
|
8710
|
+
event: {
|
|
8711
|
+
_creationTime: number;
|
|
8712
|
+
_id: string;
|
|
8713
|
+
acceptedAt: number;
|
|
8714
|
+
identity: string;
|
|
8715
|
+
occurredAt: number;
|
|
8716
|
+
recordJson: string;
|
|
8717
|
+
reservationId?: string;
|
|
8718
|
+
scopeKey: string;
|
|
8719
|
+
subscriptionJson: string;
|
|
8720
|
+
};
|
|
8721
|
+
outbox: {
|
|
8722
|
+
_creationTime: number;
|
|
8723
|
+
_id: string;
|
|
8724
|
+
attempts: number;
|
|
8725
|
+
definitionVersion?: 1;
|
|
8726
|
+
dispatch?: string;
|
|
8727
|
+
eventId: string;
|
|
8728
|
+
firstSendAt?: number;
|
|
8729
|
+
held?: boolean;
|
|
8730
|
+
leaseUntil?: number;
|
|
8731
|
+
nextAttemptAt: number;
|
|
8732
|
+
provider?: string;
|
|
8733
|
+
providerIdentifier: string;
|
|
8734
|
+
reason?:
|
|
8735
|
+
| "rate_limited"
|
|
8736
|
+
| "provider_unavailable"
|
|
8737
|
+
| "provider_outcome_unknown"
|
|
8738
|
+
| "provider_rejected"
|
|
8739
|
+
| "retry_exhausted"
|
|
8740
|
+
| "delivery_window_expired"
|
|
8741
|
+
| "scope_busy"
|
|
8742
|
+
| "administrative_hold";
|
|
8743
|
+
receipt?: { created: number; identifier: string };
|
|
8744
|
+
scopeKey: string;
|
|
8745
|
+
state:
|
|
8746
|
+
| "queued"
|
|
8747
|
+
| "sending"
|
|
8748
|
+
| "provider_accepted"
|
|
8749
|
+
| "rejected"
|
|
8750
|
+
| "unknown"
|
|
8751
|
+
| "held";
|
|
8752
|
+
workflowId?: string;
|
|
8753
|
+
};
|
|
8754
|
+
},
|
|
8755
|
+
Name
|
|
8756
|
+
>;
|
|
8757
|
+
};
|
|
8758
|
+
};
|
|
8379
8759
|
webhooks: {
|
|
8380
8760
|
mutations: {
|
|
8381
8761
|
insertWebhookEvent: FunctionReference<
|
package/src/component/schema.ts
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
import {
|
|
2
|
+
errorsTable as usageDeliveryErrors,
|
|
3
|
+
locksTable as usageDeliveryLocks,
|
|
4
|
+
} from "./usageDelivery/fields.js";
|
|
1
5
|
import { claimsTable as refundSyncClaimsTable } from "./refundSync/schema.js";
|
|
2
6
|
import { operationsTable as processingCostReconciliationOperations } from "./processingCostReconciliation/schema.js";
|
|
3
7
|
import {
|
|
@@ -68,6 +72,7 @@ import {
|
|
|
68
72
|
commissionTermsTable,
|
|
69
73
|
commissionDecisionsTable,
|
|
70
74
|
} from "./settlement/schema";
|
|
75
|
+
import { usageCatalogTable } from "./usageCatalog/schema.js";
|
|
71
76
|
import { defineSchema } from "convex/server";
|
|
72
77
|
import {
|
|
73
78
|
usageEventsTable,
|
|
@@ -95,6 +100,9 @@ import { pricesTable, productsTable } from "./products/schema";
|
|
|
95
100
|
import { webhookEventsTable } from "./webhooks/schema";
|
|
96
101
|
|
|
97
102
|
export default defineSchema({
|
|
103
|
+
usageDeliveryLocks,
|
|
104
|
+
usageDeliveryErrors,
|
|
105
|
+
usageCatalog: usageCatalogTable,
|
|
98
106
|
usageEvents: usageEventsTable,
|
|
99
107
|
usageOutbox: usageOutboxTable,
|
|
100
108
|
usageScopeCounters: usageScopeCountersTable,
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { deliveryFields } from "../usageDelivery/fields.js";
|
|
1
2
|
import { defineTable } from "convex/server";
|
|
2
3
|
import { v } from "convex/values";
|
|
3
4
|
|
|
@@ -32,7 +33,8 @@ export const eventDoc = v.object({
|
|
|
32
33
|
export const usageEventsTable = defineTable(eventFields)
|
|
33
34
|
.index("by_identity", ["identity"])
|
|
34
35
|
.index("by_scope_time", ["scopeKey", "occurredAt"]);
|
|
35
|
-
export const
|
|
36
|
+
export const outboxFields = {
|
|
37
|
+
...deliveryFields,
|
|
36
38
|
eventId: v.id("usageEvents"),
|
|
37
39
|
scopeKey: v.string(),
|
|
38
40
|
state: deliveryValidator,
|
|
@@ -40,7 +42,14 @@ export const usageOutboxTable = defineTable({
|
|
|
40
42
|
nextAttemptAt: v.number(),
|
|
41
43
|
providerIdentifier: v.string(),
|
|
42
44
|
dispatch: v.optional(v.string()),
|
|
43
|
-
}
|
|
45
|
+
};
|
|
46
|
+
export const outboxDoc = v.object({
|
|
47
|
+
_id: v.id("usageOutbox"),
|
|
48
|
+
_creationTime: v.number(),
|
|
49
|
+
...outboxFields,
|
|
50
|
+
});
|
|
51
|
+
export const usageOutboxTable = defineTable(outboxFields)
|
|
52
|
+
.index("by_provider_identifier", ["providerIdentifier"])
|
|
44
53
|
.index("by_event", ["eventId"])
|
|
45
54
|
.index("by_state_next", ["state", "nextAttemptAt"])
|
|
46
55
|
.index("by_scope_state", ["scopeKey", "state"]);
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { v } from "convex/values";
|
|
2
|
+
import { mutation } from "../_generated/server.js";
|
|
3
|
+
import { doc, kind } from "./schema.js";
|
|
4
|
+
function bounded(value: string, max: number) {
|
|
5
|
+
if (!value || new TextEncoder().encode(value).length > max)
|
|
6
|
+
throw new Error("Invalid usage catalog size");
|
|
7
|
+
}
|
|
8
|
+
export const prepare = mutation({
|
|
9
|
+
args: { scopeKey: v.string(), kind, key: v.string(), termsJson: v.string() },
|
|
10
|
+
returns: doc,
|
|
11
|
+
handler: async (ctx, args) => {
|
|
12
|
+
bounded(args.scopeKey, 256);
|
|
13
|
+
bounded(args.key, 512);
|
|
14
|
+
bounded(args.termsJson, 8192);
|
|
15
|
+
const existing = await ctx.db
|
|
16
|
+
.query("usageCatalog")
|
|
17
|
+
.withIndex("by_scope_kind_key", (q) =>
|
|
18
|
+
q
|
|
19
|
+
.eq("scopeKey", args.scopeKey)
|
|
20
|
+
.eq("kind", args.kind)
|
|
21
|
+
.eq("key", args.key),
|
|
22
|
+
)
|
|
23
|
+
.unique();
|
|
24
|
+
if (existing) {
|
|
25
|
+
if (existing.termsJson !== args.termsJson)
|
|
26
|
+
throw new Error("Immutable usage catalog terms conflict");
|
|
27
|
+
return existing;
|
|
28
|
+
}
|
|
29
|
+
const id = await ctx.db.insert("usageCatalog", {
|
|
30
|
+
...args,
|
|
31
|
+
firstAttemptAt: Math.floor(Date.now() / 1000),
|
|
32
|
+
});
|
|
33
|
+
const result = await ctx.db.get("usageCatalog", id);
|
|
34
|
+
if (!result) throw new Error("Usage catalog intent unavailable");
|
|
35
|
+
return result;
|
|
36
|
+
},
|
|
37
|
+
});
|
|
38
|
+
export const complete = mutation({
|
|
39
|
+
args: {
|
|
40
|
+
scopeKey: v.string(),
|
|
41
|
+
kind,
|
|
42
|
+
key: v.string(),
|
|
43
|
+
providerId: v.string(),
|
|
44
|
+
observationJson: v.string(),
|
|
45
|
+
},
|
|
46
|
+
returns: v.null(),
|
|
47
|
+
handler: async (ctx, args) => {
|
|
48
|
+
bounded(args.providerId, 100);
|
|
49
|
+
bounded(args.observationJson, 8192);
|
|
50
|
+
const row = await ctx.db
|
|
51
|
+
.query("usageCatalog")
|
|
52
|
+
.withIndex("by_scope_kind_key", (q) =>
|
|
53
|
+
q
|
|
54
|
+
.eq("scopeKey", args.scopeKey)
|
|
55
|
+
.eq("kind", args.kind)
|
|
56
|
+
.eq("key", args.key),
|
|
57
|
+
)
|
|
58
|
+
.unique();
|
|
59
|
+
if (!row || (row.providerId && row.providerId !== args.providerId))
|
|
60
|
+
throw new Error("Usage catalog reassignment rejected");
|
|
61
|
+
const existing = await ctx.db
|
|
62
|
+
.query("usageCatalog")
|
|
63
|
+
.withIndex("by_scope_kind_provider", (q) =>
|
|
64
|
+
q
|
|
65
|
+
.eq("scopeKey", args.scopeKey)
|
|
66
|
+
.eq("kind", args.kind)
|
|
67
|
+
.eq("providerId", args.providerId),
|
|
68
|
+
)
|
|
69
|
+
.unique();
|
|
70
|
+
if (existing && existing._id !== row._id)
|
|
71
|
+
throw new Error("Usage catalog ownership conflict");
|
|
72
|
+
await ctx.db.patch("usageCatalog", row._id, {
|
|
73
|
+
providerId: args.providerId,
|
|
74
|
+
observationJson: args.observationJson,
|
|
75
|
+
observedAt: Math.floor(Date.now() / 1000),
|
|
76
|
+
});
|
|
77
|
+
return null;
|
|
78
|
+
},
|
|
79
|
+
});
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { v } from "convex/values";
|
|
2
|
+
import { query } from "../_generated/server.js";
|
|
3
|
+
import { kind, doc } from "./schema.js";
|
|
4
|
+
export const get = query({
|
|
5
|
+
args: { scopeKey: v.string(), kind, key: v.string() },
|
|
6
|
+
returns: v.union(doc, v.null()),
|
|
7
|
+
handler: async (ctx, args) =>
|
|
8
|
+
ctx.db
|
|
9
|
+
.query("usageCatalog")
|
|
10
|
+
.withIndex("by_scope_kind_key", (q) =>
|
|
11
|
+
q
|
|
12
|
+
.eq("scopeKey", args.scopeKey)
|
|
13
|
+
.eq("kind", args.kind)
|
|
14
|
+
.eq("key", args.key),
|
|
15
|
+
)
|
|
16
|
+
.unique(),
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
export const getByProvider = query({
|
|
20
|
+
args: { scopeKey: v.string(), kind, providerId: v.string() },
|
|
21
|
+
returns: v.union(doc, v.null()),
|
|
22
|
+
handler: async (ctx, args) =>
|
|
23
|
+
ctx.db
|
|
24
|
+
.query("usageCatalog")
|
|
25
|
+
.withIndex("by_scope_kind_provider", (q) =>
|
|
26
|
+
q
|
|
27
|
+
.eq("scopeKey", args.scopeKey)
|
|
28
|
+
.eq("kind", args.kind)
|
|
29
|
+
.eq("providerId", args.providerId),
|
|
30
|
+
)
|
|
31
|
+
.unique(),
|
|
32
|
+
});
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { defineTable } from "convex/server";
|
|
2
|
+
import { v } from "convex/values";
|
|
3
|
+
export const kind = v.union(v.literal("meter"), v.literal("price"));
|
|
4
|
+
export const fields = {
|
|
5
|
+
observedAt: v.optional(v.number()),
|
|
6
|
+
scopeKey: v.string(),
|
|
7
|
+
kind,
|
|
8
|
+
key: v.string(),
|
|
9
|
+
termsJson: v.string(),
|
|
10
|
+
firstAttemptAt: v.number(),
|
|
11
|
+
providerId: v.optional(v.string()),
|
|
12
|
+
observationJson: v.optional(v.string()),
|
|
13
|
+
};
|
|
14
|
+
export const doc = v.object({
|
|
15
|
+
_id: v.id("usageCatalog"),
|
|
16
|
+
_creationTime: v.number(),
|
|
17
|
+
...fields,
|
|
18
|
+
});
|
|
19
|
+
export const usageCatalogTable = defineTable(fields)
|
|
20
|
+
.index("by_scope_kind_key", ["scopeKey", "kind", "key"])
|
|
21
|
+
.index("by_scope_kind_provider", ["scopeKey", "kind", "providerId"]);
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { anyApi, type FunctionHandle } from "convex/server";
|
|
2
|
+
import { internalAction } from "../_generated/server.js";
|
|
3
|
+
import { request } from "./schema.js";
|
|
4
|
+
import { outcome } from "./fields.js";
|
|
5
|
+
import type { Infer } from "convex/values";
|
|
6
|
+
import { z } from "zod";
|
|
7
|
+
const accepted = z.strictObject({
|
|
8
|
+
status: z.literal("accepted"),
|
|
9
|
+
created: z.number().int().nonnegative().max(Number.MAX_SAFE_INTEGER),
|
|
10
|
+
});
|
|
11
|
+
const parsedOutcome = z.union([
|
|
12
|
+
accepted,
|
|
13
|
+
z.strictObject({
|
|
14
|
+
status: z.enum(["rate_limited", "unavailable", "unknown", "rejected"]),
|
|
15
|
+
}),
|
|
16
|
+
]);
|
|
17
|
+
export const invoke = internalAction({
|
|
18
|
+
args: request,
|
|
19
|
+
returns: outcome,
|
|
20
|
+
handler: async (ctx, args): Promise<Infer<typeof outcome>> => {
|
|
21
|
+
try {
|
|
22
|
+
const { outbox } = await ctx.runQuery(
|
|
23
|
+
anyApi.usageDelivery.queries.saved,
|
|
24
|
+
{ scope: args.scope, eventId: args.eventId },
|
|
25
|
+
);
|
|
26
|
+
if (outbox.held) return { status: "unavailable" };
|
|
27
|
+
if (
|
|
28
|
+
!outbox.provider ||
|
|
29
|
+
outbox.attempts !== args.attempt ||
|
|
30
|
+
outbox.state !== "sending" ||
|
|
31
|
+
outbox.providerIdentifier !== args.identifier
|
|
32
|
+
)
|
|
33
|
+
return { status: "unknown" };
|
|
34
|
+
const raw: unknown = await ctx.runAction(
|
|
35
|
+
outbox.provider as FunctionHandle<"action">,
|
|
36
|
+
args,
|
|
37
|
+
);
|
|
38
|
+
if (!raw || typeof raw !== "object" || Array.isArray(raw))
|
|
39
|
+
return { status: "unknown" };
|
|
40
|
+
const result = raw as Record<string, unknown>;
|
|
41
|
+
if (
|
|
42
|
+
Object.keys(result).length !== Object.keys(args).length + 1 ||
|
|
43
|
+
Object.keys(args).some(
|
|
44
|
+
(key) =>
|
|
45
|
+
JSON.stringify(result[key]) !==
|
|
46
|
+
JSON.stringify(args[key as keyof typeof args]),
|
|
47
|
+
)
|
|
48
|
+
)
|
|
49
|
+
return { status: "unknown" };
|
|
50
|
+
const validated = parsedOutcome.safeParse(result.outcome);
|
|
51
|
+
return validated.success ? validated.data : { status: "unknown" };
|
|
52
|
+
} catch {
|
|
53
|
+
return { status: "unknown" };
|
|
54
|
+
}
|
|
55
|
+
},
|
|
56
|
+
});
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { convexTest } from "convex-test";
|
|
2
|
+
import { makeFunctionReference } from "convex/server";
|
|
3
|
+
import { expect, it, vi } from "vitest";
|
|
4
|
+
import { schema, modules } from "../../test.js";
|
|
5
|
+
const record = makeFunctionReference<"mutation">("usage/mutations:record"),
|
|
6
|
+
claim = makeFunctionReference<"mutation">("usageDelivery/steps:claim");
|
|
7
|
+
it("serializes the same native customer/meter even across distinct authorized payer scopes", async () => {
|
|
8
|
+
vi.useFakeTimers();
|
|
9
|
+
try {
|
|
10
|
+
const t = convexTest(schema, modules),
|
|
11
|
+
now = Math.floor(Date.now() / 1000);
|
|
12
|
+
const accepted = [];
|
|
13
|
+
for (const customerAccount of ["acct_aliasA", "acct_aliasB"]) {
|
|
14
|
+
const scope = {
|
|
15
|
+
stripeAccountId: "acct_platform",
|
|
16
|
+
customerAccount,
|
|
17
|
+
meterId: "mtr_calls",
|
|
18
|
+
livemode: false,
|
|
19
|
+
};
|
|
20
|
+
const receipt = await t.mutation(record, {
|
|
21
|
+
inputJson: JSON.stringify({
|
|
22
|
+
scope,
|
|
23
|
+
binding: {
|
|
24
|
+
stripeCustomerId: "cus_shared",
|
|
25
|
+
stripePriceId: "price_calls",
|
|
26
|
+
eventName: "calls",
|
|
27
|
+
plan: {
|
|
28
|
+
key: "calls",
|
|
29
|
+
version: "v1",
|
|
30
|
+
model: "pay_as_you_go",
|
|
31
|
+
unit: { name: "call", precision: 0 },
|
|
32
|
+
rate: { currency: "usd", unitAmountDecimal: "2" },
|
|
33
|
+
},
|
|
34
|
+
},
|
|
35
|
+
sourceEventId: "one",
|
|
36
|
+
quantity: "1",
|
|
37
|
+
occurredAt: now,
|
|
38
|
+
}),
|
|
39
|
+
subscriptionJson: JSON.stringify({
|
|
40
|
+
subscriptionId: "sub_calls",
|
|
41
|
+
subscriptionItemId: "si_calls",
|
|
42
|
+
stripePriceId: "price_calls",
|
|
43
|
+
period: { start: now - 1, end: now + 86400 },
|
|
44
|
+
interval: "month",
|
|
45
|
+
}),
|
|
46
|
+
});
|
|
47
|
+
accepted.push({ scope, eventId: receipt.eventId });
|
|
48
|
+
}
|
|
49
|
+
expect(await t.mutation(claim, accepted[0])).toMatchObject({
|
|
50
|
+
kind: "ready",
|
|
51
|
+
});
|
|
52
|
+
vi.setSystemTime(Date.now() + 2000);
|
|
53
|
+
expect(await t.mutation(claim, accepted[1])).toMatchObject({
|
|
54
|
+
kind: "wait",
|
|
55
|
+
delayMs: 60000,
|
|
56
|
+
});
|
|
57
|
+
const rows = await t.run((ctx) => ctx.db.query("usageOutbox").take(2));
|
|
58
|
+
expect(rows.map((r) => r.attempts)).toEqual([1, 0]);
|
|
59
|
+
} finally {
|
|
60
|
+
vi.useRealTimers();
|
|
61
|
+
}
|
|
62
|
+
});
|