@happyvertical/smrt-commerce 0.51.31 → 0.51.33

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (55) hide show
  1. package/dist/__tests__/foreign-key-fixtures.d.ts +13 -0
  2. package/dist/__tests__/foreign-key-fixtures.d.ts.map +1 -0
  3. package/dist/__tests__/helpers/anchor-fixture.d.ts +36 -0
  4. package/dist/__tests__/helpers/anchor-fixture.d.ts.map +1 -0
  5. package/dist/__tests__/helpers/billing-fixture.d.ts +51 -0
  6. package/dist/__tests__/helpers/billing-fixture.d.ts.map +1 -0
  7. package/dist/__tests__/helpers/consumer-license-sale.d.ts +13 -0
  8. package/dist/__tests__/helpers/consumer-license-sale.d.ts.map +1 -0
  9. package/dist/__tests__/helpers/fake-stripe.d.ts +146 -0
  10. package/dist/__tests__/helpers/fake-stripe.d.ts.map +1 -0
  11. package/dist/billing/cards.d.ts +14 -4
  12. package/dist/billing/credits.d.ts +2 -2
  13. package/dist/billing/cycles.d.ts +21 -1
  14. package/dist/billing/events.d.ts +14 -4
  15. package/dist/billing/jobs.d.ts +3 -3
  16. package/dist/billing/period-close.d.ts +1 -1
  17. package/dist/billing/provider.d.ts +12 -2
  18. package/dist/billing/runtime.d.ts +17 -12
  19. package/dist/billing/stripe.d.ts +11 -2
  20. package/dist/billing/top-up.d.ts +4 -4
  21. package/dist/collections/ContractCollection.d.ts +4 -0
  22. package/dist/collections/ContractLineItemCollection.d.ts +4 -0
  23. package/dist/collections/CustomerCollection.d.ts +4 -0
  24. package/dist/collections/FulfillmentCollection.d.ts +5 -1
  25. package/dist/collections/FulfillmentLineItemCollection.d.ts +4 -0
  26. package/dist/collections/InvoiceCollection.d.ts +4 -0
  27. package/dist/collections/InvoiceLineItemCollection.d.ts +5 -1
  28. package/dist/collections/PaymentAllocationCollection.d.ts +4 -0
  29. package/dist/collections/PaymentCollection.d.ts +5 -1
  30. package/dist/collections/PaymentInstrumentCollection.d.ts +4 -0
  31. package/dist/collections/PaymentIntentCollection.d.ts +12 -1
  32. package/dist/collections/PayoutCollection.d.ts +12 -1
  33. package/dist/collections/VendorCollection.d.ts +4 -0
  34. package/dist/index.d.ts +63 -0
  35. package/dist/index.js +1 -1
  36. package/dist/manifest.json +1 -1
  37. package/dist/migrations/moneyMinorUnits.d.ts +61 -1
  38. package/dist/models/Contract.d.ts +6 -2
  39. package/dist/models/ContractLineItem.d.ts +5 -1
  40. package/dist/models/Customer.d.ts +5 -1
  41. package/dist/models/Fulfillment.d.ts +5 -1
  42. package/dist/models/FulfillmentLineItem.d.ts +5 -1
  43. package/dist/models/Invoice.d.ts +6 -2
  44. package/dist/models/InvoiceLineItem.d.ts +5 -1
  45. package/dist/models/Payment.d.ts +6 -2
  46. package/dist/models/PaymentAllocation.d.ts +5 -1
  47. package/dist/models/PaymentInstrument.d.ts +5 -1
  48. package/dist/models/PaymentIntent.d.ts +24 -1
  49. package/dist/models/Payout.d.ts +24 -1
  50. package/dist/models/Vendor.d.ts +5 -1
  51. package/dist/models/billing.d.ts +8 -1
  52. package/dist/smrt-knowledge.json +4 -4
  53. package/dist/types/index.d.ts +5 -1
  54. package/dist/ui.d.ts +14 -1
  55. package/package.json +10 -10
@@ -2,7 +2,7 @@
2
2
  "version": "1.0.0",
3
3
  "timestamp": 0,
4
4
  "packageName": "@happyvertical/smrt-commerce",
5
- "packageVersion": "0.51.31",
5
+ "packageVersion": "0.51.33",
6
6
  "objects": {
7
7
  "@happyvertical/smrt-commerce:ContractCollection": {
8
8
  "name": "contractcollection",
@@ -1,4 +1,64 @@
1
- import { DatabaseInterface, MinorUnitsPreflightResult, MinorUnitsRescaleResult, MoneyColumnTarget } from '@happyvertical/smrt-core/migrations';
1
+ /**
2
+ * Commerce money columns: floating-point major units → integer minor units.
3
+ *
4
+ * Ships as an explicit, opt-in migration rather than a schema-differ upgrade
5
+ * because REAL→INTEGER is not information-preserving: an automatic
6
+ * `ALTER … TYPE integer` would truncate a stored `19.99` to `19` and destroy 99
7
+ * cents on every row. The values have to be rescaled by the currency's
8
+ * minor-unit factor *during* the type change (#2401).
9
+ *
10
+ * Run it from one deploy process, after the writers are upgraded:
11
+ *
12
+ * ```ts
13
+ * import { getDatabase } from '@happyvertical/sql';
14
+ * import {
15
+ * preflightCommerceMoneyMinorUnits,
16
+ * migrateCommerceMoneyToMinorUnits,
17
+ * } from '@happyvertical/smrt-commerce';
18
+ *
19
+ * const db = await getDatabase({ type: 'postgres', url: process.env.DATABASE_URL! });
20
+ *
21
+ * // 1. Read-only. Prints rows that would be rounded or exceed JavaScript's
22
+ * // safe-integer range when hydrated.
23
+ * console.log((await preflightCommerceMoneyMinorUnits(db)).summary);
24
+ *
25
+ * // 2. Convert. Idempotent — a second run is a no-op.
26
+ * await migrateCommerceMoneyToMinorUnits(db);
27
+ * ```
28
+ *
29
+ * Engine notes:
30
+ *
31
+ * - **PostgreSQL / DuckDB** — the column type changes in place with
32
+ * `USING round(col * 100)`.
33
+ * - **SQLite** — values are rescaled, but the *declared* type cannot be altered
34
+ * in place. SQLite's declared type is only an affinity, so the column already
35
+ * behaves as integer minor units; bringing the declaration into line needs
36
+ * the table-rebuild path (#2370). The result reports those columns in
37
+ * `declaredTypeChangePending`.
38
+ *
39
+ * Fresh PostgreSQL and DuckDB INTEGER columns materialize as BIGINT. The
40
+ * preflight lists values that would exceed JavaScript's safe-integer range
41
+ * after rescaling, because SMRT rejects rather than rounds those on hydration.
42
+ * Existing PostgreSQL `int4` columns require the explicit widening in #2424.
43
+ *
44
+ * ## Two things this migration deliberately does NOT convert
45
+ *
46
+ * Both hold amounts in a **native asset's** minor unit rather than the
47
+ * deployment's currency, so there is no single scale that is correct for every
48
+ * row and a blanket ×100 would silently destroy data:
49
+ *
50
+ * - **`payments.native_amount`** — satoshis on a BTC rail (×1e8), cents on a
51
+ * fiat or stablecoin rail (×1e2), in the same column, discriminated only by
52
+ * `native_currency`. See {@link COMMERCE_NATIVE_UNIT_COLUMNS} for the
53
+ * two-step conversion.
54
+ * - **`payment_intents.payment_options[].nativeAmount`** — the same problem
55
+ * inside a JSON column, per option. Because an intent's price lock defaults
56
+ * to 15 minutes, the supported answer is to **let open intents expire and be
57
+ * re-quoted**: an unconverted option simply fails to reconcile against the
58
+ * payment that arrives (the check is an exact `!==`), which is a safe, loud
59
+ * failure rather than a silently mis-scaled quote.
60
+ */
61
+ import { type DatabaseInterface, type MinorUnitsPreflightResult, type MinorUnitsRescaleResult, type MoneyColumnTarget } from '@happyvertical/smrt-core/migrations';
2
62
  /** Marker recorded in `_smrt_backfills` once the column rescale has run. */
3
63
  export declare const COMMERCE_MONEY_MINOR_UNITS_BACKFILL = "@happyvertical/smrt-commerce:money-minor-units:v1";
4
64
  /**
@@ -1,5 +1,9 @@
1
- import { Meta, SmrtObject } from '@happyvertical/smrt-core';
2
- import { ContractOptions, ContractStatus, ContractType, LicenseSaleOptions } from '../types/index.js';
1
+ /**
2
+ * Contract model with STI for different contract types
3
+ * @packageDocumentation
4
+ */
5
+ import { type Meta, SmrtObject } from '@happyvertical/smrt-core';
6
+ import { type ContractOptions, ContractStatus, ContractType, type LicenseSaleOptions } from '../types/index.js';
3
7
  /**
4
8
  * Contract is the base class for all commercial agreements.
5
9
  *
@@ -1,5 +1,9 @@
1
+ /**
2
+ * ContractLineItem model - individual items on a contract
3
+ * @packageDocumentation
4
+ */
1
5
  import { SmrtObject } from '@happyvertical/smrt-core';
2
- import { ContractLineItemOptions } from '../types/index.js';
6
+ import type { ContractLineItemOptions } from '../types/index.js';
3
7
  /**
4
8
  * ContractLineItem represents a single line item on a contract.
5
9
  *
@@ -1,5 +1,9 @@
1
+ /**
2
+ * Customer model - links to Profile with customer-specific data
3
+ * @packageDocumentation
4
+ */
1
5
  import { SmrtObject } from '@happyvertical/smrt-core';
2
- import { Address, CustomerOptions, CustomerStatus, CustomerType } from '../types/index.js';
6
+ import { type Address, type CustomerOptions, CustomerStatus, CustomerType } from '../types/index.js';
3
7
  /**
4
8
  * Customer represents the customer role for a Profile.
5
9
  *
@@ -1,5 +1,9 @@
1
+ /**
2
+ * Fulfillment model - tracks delivery of contract items
3
+ * @packageDocumentation
4
+ */
1
5
  import { SmrtObject } from '@happyvertical/smrt-core';
2
- import { Address, FulfillmentOptions, FulfillmentStatus, FulfillmentType } from '../types/index.js';
6
+ import { type Address, type FulfillmentOptions, FulfillmentStatus, FulfillmentType } from '../types/index.js';
3
7
  /**
4
8
  * Fulfillment tracks the delivery or completion of contract items.
5
9
  *
@@ -1,5 +1,9 @@
1
+ /**
2
+ * FulfillmentLineItem model - tracks which contract items were fulfilled
3
+ * @packageDocumentation
4
+ */
1
5
  import { SmrtObject } from '@happyvertical/smrt-core';
2
- import { FulfillmentLineItemOptions } from '../types/index.js';
6
+ import type { FulfillmentLineItemOptions } from '../types/index.js';
3
7
  /**
4
8
  * FulfillmentLineItem tracks which contract line items are included
5
9
  * in a specific fulfillment and how much was fulfilled.
@@ -1,6 +1,10 @@
1
+ /**
2
+ * Invoice model - billing document sent to customers
3
+ * @packageDocumentation
4
+ */
1
5
  import { SmrtObject } from '@happyvertical/smrt-core';
2
- import { Journal } from '@happyvertical/smrt-ledgers';
3
- import { AccountingInvoiceInput, InvoiceOptions, InvoiceStatus, RecognizeRevenueOptions } from '../types/index.js';
6
+ import type { Journal } from '@happyvertical/smrt-ledgers';
7
+ import { type AccountingInvoiceInput, type InvoiceOptions, InvoiceStatus, type RecognizeRevenueOptions } from '../types/index.js';
4
8
  /**
5
9
  * Invoice represents a bill sent to a customer for goods or services.
6
10
  *
@@ -1,5 +1,9 @@
1
+ /**
2
+ * InvoiceLineItem model - individual items on an invoice
3
+ * @packageDocumentation
4
+ */
1
5
  import { SmrtObject } from '@happyvertical/smrt-core';
2
- import { AccountingLineItemInput, InvoiceLineItemOptions } from '../types/index.js';
6
+ import type { AccountingLineItemInput, InvoiceLineItemOptions } from '../types/index.js';
3
7
  /**
4
8
  * InvoiceLineItem represents a single line item on an invoice.
5
9
  *
@@ -1,6 +1,10 @@
1
+ /**
2
+ * Payment model - tracks payments with ledger integration
3
+ * @packageDocumentation
4
+ */
1
5
  import { SmrtObject } from '@happyvertical/smrt-core';
2
- import { Journal } from '@happyvertical/smrt-ledgers';
3
- import { PaymentMethod, PaymentOptions, PaymentStatus, RecordPaymentOptions } from '../types/index.js';
6
+ import type { Journal } from '@happyvertical/smrt-ledgers';
7
+ import { PaymentMethod, type PaymentOptions, PaymentStatus, type RecordPaymentOptions } from '../types/index.js';
4
8
  /**
5
9
  * Payment represents a financial transaction against a contract.
6
10
  *
@@ -1,5 +1,9 @@
1
+ /**
2
+ * PaymentAllocation model - maps payments to invoices
3
+ * @packageDocumentation
4
+ */
1
5
  import { SmrtObject } from '@happyvertical/smrt-core';
2
- import { PaymentAllocationOptions } from '../types/index.js';
6
+ import type { PaymentAllocationOptions } from '../types/index.js';
3
7
  /**
4
8
  * PaymentAllocation tracks how payments are applied to invoices.
5
9
  *
@@ -1,5 +1,9 @@
1
+ /**
2
+ * PaymentInstrument model - a reusable saved payment method ("card on file").
3
+ * @packageDocumentation
4
+ */
1
5
  import { SmrtObject } from '@happyvertical/smrt-core';
2
- import { PaymentInstrumentOptions, PaymentInstrumentStatus } from '../types/index.js';
6
+ import { type PaymentInstrumentOptions, PaymentInstrumentStatus } from '../types/index.js';
3
7
  /**
4
8
  * PaymentInstrument stores a reusable payment method a customer has saved with
5
9
  * a payment backend (e.g. a card vaulted by Stripe), so it can be charged later
@@ -1,5 +1,28 @@
1
+ /**
2
+ * PaymentIntent — short-lived pre-payment commitment with multi-option
3
+ * semantics.
4
+ *
5
+ * A PaymentIntent is a one-shot quote that locks a USD price for a fixed
6
+ * window and lists one or more `PaymentOption`s describing different
7
+ * payment rails (USDC-on-Base, BTC, Stripe, etc.) that can each satisfy
8
+ * the intent. The first option that receives an incoming payment wins —
9
+ * the intent transitions to {@link PaymentIntentStatus.PAID} and the
10
+ * other options are implicitly retired. Later inbound funds to a
11
+ * retired option must be flagged for refund by the consumer's
12
+ * payment-routing layer.
13
+ *
14
+ * Distinct from `Estimate` (a long-form contract proposal STI subtype
15
+ * of `Contract`): a `PaymentIntent` is short-lived (minutes, not days),
16
+ * carries no line items, and exists to coordinate the moment-of-payment.
17
+ *
18
+ * Industry-neutral: any application that offers more than one route to
19
+ * pay for the same thing — marketplaces, billing systems with multi-
20
+ * provider checkout, agent-driven (x402) flows — benefits.
21
+ *
22
+ * @packageDocumentation
23
+ */
1
24
  import { SmrtObject } from '@happyvertical/smrt-core';
2
- import { PaymentIntentOptions, PaymentIntentStatus, PaymentOption } from '../types/index.js';
25
+ import { type PaymentIntentOptions, PaymentIntentStatus, type PaymentOption } from '../types/index.js';
3
26
  export declare class PaymentIntent extends SmrtObject {
4
27
  /**
5
28
  * Tenant ID for multi-tenant isolation. Nullable so the same model
@@ -1,5 +1,28 @@
1
+ /**
2
+ * Payout — operator-to-supplier outgoing remittance.
3
+ *
4
+ * A Payout sits on the opposite side of a {@link Payment}: it tracks
5
+ * funds *leaving* the operator's wallet and arriving at a vendor's
6
+ * payout address. The two are kept as distinct models (rather than
7
+ * overloading `Payment` with a `direction` field) because the status
8
+ * machine, chain semantics, and audit story differ.
9
+ *
10
+ * Industry-neutral: any operator that ingests one payment and remits
11
+ * funds to a third party — marketplaces, payment processors with
12
+ * Connect-style fan-out, royalty distributors, escrow services —
13
+ * benefits.
14
+ *
15
+ * MVP scope: no currency conversion. The payout's amounts and currency
16
+ * mirror the originating Payment's native currency, and the vendor
17
+ * needs a matching `Vendor.payoutAddresses` entry to receive funds.
18
+ * Filtering at quote time (`PaymentIntent.paymentOptions`) is the
19
+ * consumer's job; the model just enforces the natural-key invariant
20
+ * and the status machine.
21
+ *
22
+ * @packageDocumentation
23
+ */
1
24
  import { SmrtObject } from '@happyvertical/smrt-core';
2
- import { PayoutOptions, PayoutStatus } from '../types/index.js';
25
+ import { type PayoutOptions, PayoutStatus } from '../types/index.js';
3
26
  export declare class Payout extends SmrtObject {
4
27
  /**
5
28
  * Tenant ID for multi-tenant isolation. Nullable so global / single-
@@ -1,5 +1,9 @@
1
+ /**
2
+ * Vendor model - links to Profile with vendor-specific data
3
+ * @packageDocumentation
4
+ */
1
5
  import { SmrtObject } from '@happyvertical/smrt-core';
2
- import { VendorOptions, VendorStatus } from '../types/index.js';
6
+ import { type VendorOptions, VendorStatus } from '../types/index.js';
3
7
  /**
4
8
  * Vendor represents the vendor/supplier role for a Profile.
5
9
  *
@@ -1,5 +1,12 @@
1
+ /**
2
+ * Billing-period close records (#3060).
3
+ *
4
+ * These are system tables managed by `BillingRuntime`, like smrt-tenancy's
5
+ * `_smrt_billing_relationships`: they span a seller and its payers, so they
6
+ * are not tenant-scoped and have no generated API, CLI, or MCP surface.
7
+ */
1
8
  import { SmrtCollection, SmrtObject } from '@happyvertical/smrt-core';
2
- import { JobExecutionContext } from '@happyvertical/smrt-jobs';
9
+ import { type JobExecutionContext } from '@happyvertical/smrt-jobs';
3
10
  /**
4
11
  * Who a runtime bills. `provider` closes the platform's `ClientCharge`s,
5
12
  * their `BillingAdjustment`s, and the platform's flat plans; `reseller`
@@ -3,12 +3,12 @@
3
3
  "sensitiveFieldsExcluded": true,
4
4
  "generatedAt": "1970-01-01T00:00:00.000Z",
5
5
  "packageName": "@happyvertical/smrt-commerce",
6
- "packageVersion": "0.51.31",
6
+ "packageVersion": "0.51.33",
7
7
  "sourceManifestPath": "dist/manifest.json",
8
8
  "agentDocPath": "AGENTS.md",
9
9
  "sourceHashes": {
10
- "manifest": "688c5d915cea4eaf60b54eafc4b161e14d6143fefc3043d54020c9e18f02aa17",
11
- "packageJson": "e6ee5f0d8e93f49996a8f9e565c02e5e8524ac73c12188669db6123b60aaa233",
10
+ "manifest": "e0d8ced41c0783b44fcecbc8b7deec93a522341696cac0d14b0be9710c0985a9",
11
+ "packageJson": "c16cfdd1a63bd45bbfeb58f75d92bf824f9ec31856a7354e5a23b4f01e52c6ef",
12
12
  "agents": "05a98db8f3cc2137b030cbcbaedb112880f42613574cea68f6aebe03b7adcc3b"
13
13
  },
14
14
  "exports": [
@@ -34,7 +34,7 @@
34
34
  "fast-glob": "^3.3.3",
35
35
  "svelte": "^5.57.1",
36
36
  "svelte-check": "^4.7.6",
37
- "typescript": "5.9.3",
37
+ "typescript": "6.0.3",
38
38
  "vite": "8.1.4",
39
39
  "vitest": "4.1.10"
40
40
  },
@@ -1,4 +1,8 @@
1
- import { SmrtObjectOptions } from '@happyvertical/smrt-core';
1
+ /**
2
+ * Commerce package type definitions
3
+ * @packageDocumentation
4
+ */
5
+ import type { SmrtObjectOptions } from '@happyvertical/smrt-core';
2
6
  export declare enum CustomerStatus {
3
7
  ACTIVE = "active",
4
8
  INACTIVE = "inactive",
package/dist/ui.d.ts CHANGED
@@ -1,4 +1,17 @@
1
- import { ModuleUISlot, SmrtModuleMeta } from '@happyvertical/smrt-types';
1
+ /**
2
+ * Commerce Module UI Slot Declarations
3
+ *
4
+ * This file defines the UI extension points for the commerce module.
5
+ * UI components are implemented in the ./svelte subpath.
6
+ *
7
+ * @example Usage
8
+ * ```typescript
9
+ * // In application code
10
+ * import { COMMERCE_MODULE_META } from '@happyvertical/smrt-commerce';
11
+ * console.log(COMMERCE_MODULE_META.uiSlots);
12
+ * ```
13
+ */
14
+ import type { ModuleUISlot, SmrtModuleMeta } from '@happyvertical/smrt-types';
2
15
  /**
3
16
  * Commerce module UI slots
4
17
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@happyvertical/smrt-commerce",
3
- "version": "0.51.31",
3
+ "version": "0.51.33",
4
4
  "smrtJsdoc": "strict",
5
5
  "description": "Commerce models for the SMRT framework - contracts, fulfillments, payments",
6
6
  "type": "module",
@@ -51,13 +51,13 @@
51
51
  },
52
52
  "dependencies": {
53
53
  "@happyvertical/accounting": "^0.94.1",
54
- "@happyvertical/smrt-core": "0.51.31",
55
- "@happyvertical/smrt-jobs": "0.51.31",
56
- "@happyvertical/smrt-ledgers": "0.51.31",
57
- "@happyvertical/smrt-subscriptions": "0.51.31",
58
- "@happyvertical/smrt-tenancy": "0.51.31",
59
- "@happyvertical/smrt-types": "0.51.31",
60
- "@happyvertical/smrt-ui": "0.51.31"
54
+ "@happyvertical/smrt-core": "0.51.33",
55
+ "@happyvertical/smrt-jobs": "0.51.33",
56
+ "@happyvertical/smrt-ledgers": "0.51.33",
57
+ "@happyvertical/smrt-subscriptions": "0.51.33",
58
+ "@happyvertical/smrt-tenancy": "0.51.33",
59
+ "@happyvertical/smrt-types": "0.51.33",
60
+ "@happyvertical/smrt-ui": "0.51.33"
61
61
  },
62
62
  "peerDependencies": {
63
63
  "svelte": "^5.57.1"
@@ -68,14 +68,14 @@
68
68
  }
69
69
  },
70
70
  "devDependencies": {
71
- "@happyvertical/smrt-vitest": "0.51.31",
71
+ "@happyvertical/smrt-vitest": "0.51.33",
72
72
  "@sveltejs/package": "^2.5.8",
73
73
  "@sveltejs/vite-plugin-svelte": "^7.3.0",
74
74
  "@types/node": "24.13.6",
75
75
  "fast-glob": "^3.3.3",
76
76
  "svelte": "^5.57.1",
77
77
  "svelte-check": "^4.7.6",
78
- "typescript": "5.9.3",
78
+ "typescript": "6.0.3",
79
79
  "vite": "8.1.4",
80
80
  "vitest": "4.1.10"
81
81
  },