@happyvertical/smrt-commerce 0.30.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.
Files changed (101) hide show
  1. package/AGENTS.md +44 -0
  2. package/CLAUDE.md +1 -0
  3. package/LICENSE +7 -0
  4. package/README.md +146 -0
  5. package/dist/__smrt-register__.d.ts +2 -0
  6. package/dist/__smrt-register__.d.ts.map +1 -0
  7. package/dist/collections/ContractCollection.d.ts +87 -0
  8. package/dist/collections/ContractCollection.d.ts.map +1 -0
  9. package/dist/collections/CustomerCollection.d.ts +58 -0
  10. package/dist/collections/CustomerCollection.d.ts.map +1 -0
  11. package/dist/collections/FulfillmentCollection.d.ts +75 -0
  12. package/dist/collections/FulfillmentCollection.d.ts.map +1 -0
  13. package/dist/collections/InvoiceCollection.d.ts +162 -0
  14. package/dist/collections/InvoiceCollection.d.ts.map +1 -0
  15. package/dist/collections/InvoiceLineItemCollection.d.ts +90 -0
  16. package/dist/collections/InvoiceLineItemCollection.d.ts.map +1 -0
  17. package/dist/collections/PaymentAllocationCollection.d.ts +86 -0
  18. package/dist/collections/PaymentAllocationCollection.d.ts.map +1 -0
  19. package/dist/collections/PaymentCollection.d.ts +96 -0
  20. package/dist/collections/PaymentCollection.d.ts.map +1 -0
  21. package/dist/collections/PaymentIntentCollection.d.ts +66 -0
  22. package/dist/collections/PaymentIntentCollection.d.ts.map +1 -0
  23. package/dist/collections/PayoutCollection.d.ts +47 -0
  24. package/dist/collections/PayoutCollection.d.ts.map +1 -0
  25. package/dist/collections/VendorCollection.d.ts +59 -0
  26. package/dist/collections/VendorCollection.d.ts.map +1 -0
  27. package/dist/collections/index.d.ts +15 -0
  28. package/dist/collections/index.d.ts.map +1 -0
  29. package/dist/index.d.ts +5 -0
  30. package/dist/index.d.ts.map +1 -0
  31. package/dist/index.js +5308 -0
  32. package/dist/index.js.map +1 -0
  33. package/dist/manifest.json +13852 -0
  34. package/dist/models/Contract.d.ts +425 -0
  35. package/dist/models/Contract.d.ts.map +1 -0
  36. package/dist/models/ContractLineItem.d.ts +92 -0
  37. package/dist/models/ContractLineItem.d.ts.map +1 -0
  38. package/dist/models/Customer.d.ts +98 -0
  39. package/dist/models/Customer.d.ts.map +1 -0
  40. package/dist/models/Fulfillment.d.ts +99 -0
  41. package/dist/models/Fulfillment.d.ts.map +1 -0
  42. package/dist/models/FulfillmentLineItem.d.ts +42 -0
  43. package/dist/models/FulfillmentLineItem.d.ts.map +1 -0
  44. package/dist/models/Invoice.d.ts +326 -0
  45. package/dist/models/Invoice.d.ts.map +1 -0
  46. package/dist/models/InvoiceLineItem.d.ts +120 -0
  47. package/dist/models/InvoiceLineItem.d.ts.map +1 -0
  48. package/dist/models/Payment.d.ts +269 -0
  49. package/dist/models/Payment.d.ts.map +1 -0
  50. package/dist/models/PaymentAllocation.d.ts +93 -0
  51. package/dist/models/PaymentAllocation.d.ts.map +1 -0
  52. package/dist/models/PaymentIntent.d.ts +341 -0
  53. package/dist/models/PaymentIntent.d.ts.map +1 -0
  54. package/dist/models/Payout.d.ts +200 -0
  55. package/dist/models/Payout.d.ts.map +1 -0
  56. package/dist/models/Vendor.d.ts +153 -0
  57. package/dist/models/Vendor.d.ts.map +1 -0
  58. package/dist/models/index.d.ts +17 -0
  59. package/dist/models/index.d.ts.map +1 -0
  60. package/dist/playground.d.ts +2 -0
  61. package/dist/playground.d.ts.map +1 -0
  62. package/dist/playground.js +108 -0
  63. package/dist/playground.js.map +1 -0
  64. package/dist/smrt-knowledge.json +5494 -0
  65. package/dist/svelte/components/InvoiceActions.svelte +191 -0
  66. package/dist/svelte/components/InvoiceActions.svelte.d.ts +26 -0
  67. package/dist/svelte/components/InvoiceActions.svelte.d.ts.map +1 -0
  68. package/dist/svelte/components/InvoiceCard.svelte +233 -0
  69. package/dist/svelte/components/InvoiceCard.svelte.d.ts +16 -0
  70. package/dist/svelte/components/InvoiceCard.svelte.d.ts.map +1 -0
  71. package/dist/svelte/components/InvoiceHeader.svelte +258 -0
  72. package/dist/svelte/components/InvoiceHeader.svelte.d.ts +26 -0
  73. package/dist/svelte/components/InvoiceHeader.svelte.d.ts.map +1 -0
  74. package/dist/svelte/components/InvoiceLineItems.svelte +322 -0
  75. package/dist/svelte/components/InvoiceLineItems.svelte.d.ts +24 -0
  76. package/dist/svelte/components/InvoiceLineItems.svelte.d.ts.map +1 -0
  77. package/dist/svelte/components/InvoiceTotals.svelte +193 -0
  78. package/dist/svelte/components/InvoiceTotals.svelte.d.ts +27 -0
  79. package/dist/svelte/components/InvoiceTotals.svelte.d.ts.map +1 -0
  80. package/dist/svelte/components/UnbilledItems.svelte +355 -0
  81. package/dist/svelte/components/UnbilledItems.svelte.d.ts +18 -0
  82. package/dist/svelte/components/UnbilledItems.svelte.d.ts.map +1 -0
  83. package/dist/svelte/i18n.d.ts +19 -0
  84. package/dist/svelte/i18n.d.ts.map +1 -0
  85. package/dist/svelte/i18n.js +19 -0
  86. package/dist/svelte/index.d.ts +40 -0
  87. package/dist/svelte/index.d.ts.map +1 -0
  88. package/dist/svelte/index.js +43 -0
  89. package/dist/svelte/playground.d.ts +103 -0
  90. package/dist/svelte/playground.d.ts.map +1 -0
  91. package/dist/svelte/playground.js +103 -0
  92. package/dist/svelte/types.d.ts +47 -0
  93. package/dist/svelte/types.d.ts.map +1 -0
  94. package/dist/svelte/types.js +4 -0
  95. package/dist/types/index.d.ts +234 -0
  96. package/dist/types/index.d.ts.map +1 -0
  97. package/dist/ui.d.ts +10 -0
  98. package/dist/ui.d.ts.map +1 -0
  99. package/dist/ui.js +85 -0
  100. package/dist/ui.js.map +1 -0
  101. package/package.json +87 -0
@@ -0,0 +1,425 @@
1
+ import { Meta, SmrtObject } from '@happyvertical/smrt-core';
2
+ import { ContractStatus, ContractType } from '../types/index.js';
3
+ /**
4
+ * Contract is the base class for all commercial agreements.
5
+ *
6
+ * Uses Single Table Inheritance (STI) to support different contract types:
7
+ * - Estimate: Quote/proposal for customer
8
+ * - Order: Customer purchase order
9
+ * - Lease: Rental/lease agreement
10
+ * - Agreement: Service/maintenance agreement
11
+ * - PurchaseOrder: Order to vendor/supplier
12
+ *
13
+ * @example
14
+ * ```typescript
15
+ * // Create a customer order
16
+ * const order = await contracts.create({
17
+ * _meta_type: 'Order',
18
+ * customerId: customer.id,
19
+ * totalAmount: 1500.00,
20
+ * status: ContractStatus.DRAFT
21
+ * });
22
+ *
23
+ * // Create a purchase order to vendor
24
+ * const po = await contracts.create({
25
+ * _meta_type: 'PurchaseOrder',
26
+ * vendorId: vendor.id,
27
+ * totalAmount: 5000.00,
28
+ * reference: 'PO-2024-001'
29
+ * });
30
+ * ```
31
+ */
32
+ export declare class Contract extends SmrtObject {
33
+ /**
34
+ * Tenant ID for multi-tenant isolation
35
+ * Nullable to support both tenant-scoped and global contracts
36
+ */
37
+ tenantId: string | null;
38
+ /**
39
+ * Contract type discriminator (STI)
40
+ */
41
+ contractType: ContractType;
42
+ /**
43
+ * Current status of the contract
44
+ */
45
+ status: ContractStatus;
46
+ /**
47
+ * Customer ID (for sales contracts: Estimate, Order, Agreement)
48
+ */
49
+ customerId: string;
50
+ /**
51
+ * Vendor ID (for purchase contracts: PurchaseOrder)
52
+ */
53
+ vendorId: string;
54
+ /**
55
+ * Subtotal before tax
56
+ */
57
+ subtotal: number;
58
+ /**
59
+ * Tax amount
60
+ */
61
+ taxAmount: number;
62
+ /**
63
+ * Total amount including tax
64
+ */
65
+ totalAmount: number;
66
+ /**
67
+ * Currency code (ISO 4217)
68
+ */
69
+ currency: string;
70
+ /**
71
+ * Date contract was issued
72
+ */
73
+ issueDate: Date;
74
+ /**
75
+ * Payment due date
76
+ */
77
+ dueDate: Date | null;
78
+ /**
79
+ * Expiry date (for estimates/quotes)
80
+ */
81
+ expiryDate: Date | null;
82
+ /**
83
+ * External reference number (PO number, quote number, etc.)
84
+ */
85
+ reference: string;
86
+ /**
87
+ * Internal notes
88
+ */
89
+ notes: string;
90
+ /**
91
+ * Terms and conditions
92
+ */
93
+ terms: string;
94
+ /**
95
+ * Sales channel that owns this contract.
96
+ *
97
+ * Plain string so consumers can model their own channels without an enum
98
+ * change (e.g. `dtc-web`, `wholesale-b2b`, `pos-store-1`, `marketplace-faire`).
99
+ * Empty string means "unattributed / legacy".
100
+ */
101
+ channelId: string;
102
+ /**
103
+ * STI discriminator field
104
+ */
105
+ static readonly _stiField = "contractType";
106
+ constructor(options?: any);
107
+ /**
108
+ * Check if contract is in draft state
109
+ */
110
+ isDraft(): boolean;
111
+ /**
112
+ * Check if contract is accepted
113
+ */
114
+ isAccepted(): boolean;
115
+ /**
116
+ * Check if contract is completed
117
+ */
118
+ isCompleted(): boolean;
119
+ /**
120
+ * Check if contract is expired (for estimates)
121
+ */
122
+ isExpired(): boolean;
123
+ /**
124
+ * Check if contract is overdue
125
+ */
126
+ isOverdue(): boolean;
127
+ /**
128
+ * Calculate and update totals from line items
129
+ */
130
+ recalculateTotals(): Promise<void>;
131
+ /**
132
+ * Capture the status the row was loaded with so the save-time transition
133
+ * guard can reject illegal status flips made via raw field assignment
134
+ * (mass-assignment on the generated update route, a stale caller, etc.).
135
+ * Only persisted rows carry a prior status.
136
+ */
137
+ initialize(): Promise<this>;
138
+ /**
139
+ * Validate the status transition before persisting, then save. Inherited by
140
+ * every STI subtype (Estimate/Order/Lease/.../LicenseSale), so a forged
141
+ * `status` on any of them is caught here. LicenseSale layers its own
142
+ * rights-immutability guard on top via `super.save()`. See S5 audit #1390.
143
+ */
144
+ save(): Promise<this>;
145
+ /**
146
+ * Reject an illegal status flip done via raw assignment. No-op transitions
147
+ * and brand-new rows are always allowed.
148
+ */
149
+ protected assertContractStatusTransition(prior: ContractStatus | undefined): void;
150
+ /**
151
+ * Resolve the AUTHORITATIVE prior status (S5 audit #1390 round 5, codex
152
+ * MEDIUM#2). The WeakMap is only populated when {@link initialize} loaded the
153
+ * row from the DB; it is empty for an instance built via
154
+ * `collection.create({ id: <existing>, _skipLoad: true })` — the upsert path
155
+ * that lets a caller write onto an existing row without hydrating it. Trusting
156
+ * an empty WeakMap there would treat the write as a brand-new row and skip the
157
+ * transition guard entirely (a poisonable prior-state). Mirrors the
158
+ * authoritative-prior-load applied to Payment/PaymentIntent/Invoice/Payout.
159
+ *
160
+ * So when this instance carries an `id`, read the persisted row straight from
161
+ * the database and treat its `status` as the prior — a create-onto-existing is
162
+ * an update. Only when no row exists in the DB (truly new) do we fall back to
163
+ * the WeakMap (which is also empty then), i.e. `undefined` = genuinely new.
164
+ * The raw row's `status` column is single-word (no snake_case transform).
165
+ */
166
+ protected resolvePriorStatus(): Promise<ContractStatus | undefined>;
167
+ }
168
+ /**
169
+ * Estimate - Quote or proposal for a customer
170
+ */
171
+ export declare class Estimate extends Contract {
172
+ contractType: ContractType;
173
+ }
174
+ /**
175
+ * Order - Customer purchase order
176
+ */
177
+ export declare class Order extends Contract {
178
+ contractType: ContractType;
179
+ }
180
+ /**
181
+ * Lease - Rental or lease agreement
182
+ */
183
+ export declare class Lease extends Contract {
184
+ contractType: ContractType;
185
+ }
186
+ /**
187
+ * Agreement - Service or maintenance agreement
188
+ */
189
+ export declare class Agreement extends Contract {
190
+ contractType: ContractType;
191
+ }
192
+ /**
193
+ * PurchaseOrder - Order sent to vendor/supplier
194
+ */
195
+ export declare class PurchaseOrder extends Contract {
196
+ contractType: ContractType;
197
+ }
198
+ /**
199
+ * WholesaleOrder - B2B order placed by a wholesale customer.
200
+ *
201
+ * Behaves like an Order but is conventionally created against a customer with
202
+ * `customerType: 'wholesale'`, uses NET-30/60 payment terms, and is delivered
203
+ * via the wholesale-portal channel rather than retail checkout.
204
+ */
205
+ export declare class WholesaleOrder extends Contract {
206
+ contractType: ContractType;
207
+ }
208
+ /**
209
+ * ProductionOrder - instruction to commission goods from an internal or
210
+ * external factory.
211
+ *
212
+ * The manufacturing equivalent of a {@link PurchaseOrder} — but instead of
213
+ * buying finished inventory, you're paying to *make* it. A ProductionOrder
214
+ * consumes raw materials per a Bill of Materials (see
215
+ * `@happyvertical/smrt-manufacturing`) and produces finished SKU stock when
216
+ * posted (see `@happyvertical/smrt-inventory`).
217
+ *
218
+ * Carries two STI-meta fields that `ProductionService.consumeMaterials` /
219
+ * `runProduction` read from the loaded row to resolve which BOM to walk:
220
+ *
221
+ * - `productId` — plain string ref to the upstream `Product` (or any
222
+ * STI subtype, e.g. apparel `Style`). Used to look up the *active*
223
+ * BOM via `BomService.findActiveForProduct` when no explicit
224
+ * revision was pinned at the time the order was placed.
225
+ * - `bomId` — optional pin to a specific BOM revision. When set, the
226
+ * manufacturing service consumes against that exact revision even
227
+ * if a newer BOM has become active in the meantime (keeps a
228
+ * posted run from silently switching recipes mid-flight).
229
+ *
230
+ * Both fields are `Meta<string>` so the scanner routes them into the
231
+ * shared `_meta_data` JSON column on the Contract STI table instead of
232
+ * widening the base schema with manufacturing-specific columns.
233
+ */
234
+ export declare class ProductionOrder extends Contract {
235
+ contractType: ContractType;
236
+ /**
237
+ * Plain string reference to the upstream product the order is asked
238
+ * to make. Cross-package id; never `@foreignKey()`. Required by
239
+ * `ProductionService.consumeMaterials` unless `bomId` is supplied.
240
+ */
241
+ productId: Meta<string>;
242
+ /**
243
+ * Optional explicit BOM revision the order locked to at posting
244
+ * time. When set, manufacturing uses this exact row even if the
245
+ * product's active BOM has since changed. When empty, falls back
246
+ * to the active BOM for `productId`.
247
+ */
248
+ bomId: Meta<string>;
249
+ }
250
+ /**
251
+ * Cart - transient order-in-progress for a shopper.
252
+ *
253
+ * Persisted as a Contract so it can hold the same line items, totals, and
254
+ * customer reference as a real Order, then convert in place (the application
255
+ * promotes the row from `_meta_type: Cart` to `_meta_type: Order` at checkout
256
+ * rather than copying data between tables).
257
+ *
258
+ * A Cart starts in {@link ContractStatus.DRAFT} via the base `Contract.status`
259
+ * default — the subclass doesn't need its own override. Application code
260
+ * is responsible for promoting the row to `ContractStatus.PENDING` /
261
+ * `ACCEPTED` at checkout time; the framework doesn't enforce a state
262
+ * machine on the cart → order transition.
263
+ */
264
+ export declare class Cart extends Contract {
265
+ contractType: ContractType;
266
+ }
267
+ /**
268
+ * Snapshot of the rights granted by a {@link LicenseSale}. The fields are
269
+ * intentionally typed (not a generic JSON blob) so they survive schema
270
+ * migrations and downstream consumers (PDF templating, hash-registry
271
+ * publishers) can rely on the shape without re-parsing.
272
+ *
273
+ * Each field is opaque text — the values that make sense vary by
274
+ * industry. A stock-media marketplace might use:
275
+ *
276
+ * - `medium`: `web,print,social`
277
+ * - `distributionScope`: `worldwide` / `territorial`
278
+ * - `exclusivity`: `exclusive` / `non-exclusive`
279
+ * - `duration`: `perpetual` / `12-months` / `event-only`
280
+ * - `territory`: ISO-3166 list or `worldwide`
281
+ *
282
+ * Booleans (`sublicensing`, `derivatives`) are typed as such; everything
283
+ * else is a string so the model doesn't dictate vocabulary.
284
+ */
285
+ export interface LicenseRightsSnapshot {
286
+ medium: string;
287
+ distributionScope: string;
288
+ exclusivity: string;
289
+ duration: string;
290
+ territory: string;
291
+ sublicensing: boolean;
292
+ derivatives: boolean;
293
+ }
294
+ /**
295
+ * LicenseSale — industry-neutral licensing primitive.
296
+ *
297
+ * Sits alongside the other Contract STI subtypes (Estimate, Order,
298
+ * Lease, Agreement, PurchaseOrder, WholesaleOrder, ProductionOrder,
299
+ * Cart) and represents a single sale of rights for a fee. A
300
+ * stock-media marketplace selling a one-time license, a music-
301
+ * licensing platform issuing a sync license, a code-asset marketplace
302
+ * granting a redistribution right — all use the same primitive.
303
+ *
304
+ * Immutability invariant: once a `LicenseSale` is saved with
305
+ * {@link ContractStatus.ACCEPTED}, its rights snapshot becomes
306
+ * frozen. Re-saving with mutated rights throws. The only legal
307
+ * transition out of ACCEPTED is `revoke()` (which moves status to
308
+ * CANCELLED without changing the rights). If a different snapshot
309
+ * is genuinely needed, the operator's contract is to issue a *new*
310
+ * LicenseSale row and let the old one stand as historical record.
311
+ *
312
+ * All subtype-specific fields are declared as `Meta<T>` so the
313
+ * scanner routes them into the shared `_meta_data` JSON column on
314
+ * the `contracts` STI table — no migration of the base schema needed
315
+ * to land this subtype.
316
+ */
317
+ export declare class LicenseSale extends Contract {
318
+ contractType: ContractType;
319
+ /**
320
+ * Plain string reference to the upstream `Sku` (from
321
+ * `@happyvertical/smrt-products`) that this license was sold against.
322
+ * Cross-package id; never `@foreignKey()`.
323
+ */
324
+ skuId: Meta<string>;
325
+ /**
326
+ * Plain string reference to the `Payment` that satisfied the
327
+ * purchase. Cross-model reference matches the rest of the
328
+ * package's convention.
329
+ */
330
+ paymentId: Meta<string>;
331
+ /**
332
+ * The licensee's email address — the primary identity carried
333
+ * forward into PDF generation and any downstream hash-registry
334
+ * publication. Required; without it, downstream rights cannot be
335
+ * attributed.
336
+ */
337
+ licenseeEmail: Meta<string>;
338
+ /**
339
+ * Optional legal-entity name of the licensee for purchases that
340
+ * warrant it (typically high-tier B2B licenses). Empty string for
341
+ * individual-buyer licenses where the email *is* the legal identity.
342
+ */
343
+ licenseeLegalEntity: Meta<string>;
344
+ /**
345
+ * Optional ISO-3166 jurisdiction code of the licensee, captured for
346
+ * tax / disclosure / governing-law purposes. Empty when not
347
+ * required.
348
+ */
349
+ licenseeJurisdiction: Meta<string>;
350
+ /** Permitted media — `web,print,social`, `broadcast`, etc. */
351
+ rightsMedium: Meta<string>;
352
+ /** Distribution scope — `worldwide`, `territorial`, `private`, etc. */
353
+ rightsDistributionScope: Meta<string>;
354
+ /** Exclusivity — `exclusive` / `non-exclusive` / `co-exclusive`. */
355
+ rightsExclusivity: Meta<string>;
356
+ /** Duration — `perpetual` / `12-months` / `event-only`, etc. */
357
+ rightsDuration: Meta<string>;
358
+ /** Territory — ISO-3166 list, `worldwide`, region name, etc. */
359
+ rightsTerritory: Meta<string>;
360
+ /** Whether the licensee may sublicense the rights. */
361
+ rightsSublicensing: Meta<boolean>;
362
+ /** Whether the licensee may create derivative works. */
363
+ rightsDerivatives: Meta<boolean>;
364
+ /** URL of the signed PDF (typically a cloud-storage public URL). */
365
+ pdfUrl: Meta<string>;
366
+ /**
367
+ * SHA-256 of the signed PDF bytes (hex string, no `0x` prefix).
368
+ * Lets downstream consumers verify the PDF the licensee holds is
369
+ * the one this row was issued for, without re-fetching.
370
+ */
371
+ pdfHash: Meta<string>;
372
+ /**
373
+ * Optional reference to an on-chain hash-registry entry — set when
374
+ * the LicenseSale's `pdfHash` has been anchored on a public chain
375
+ * for tamper-evidence. Format is whatever the hash-registry
376
+ * service emits (e.g. `chain:tx-hash:log-index`). Empty for
377
+ * deployments that don't publish hashes on-chain.
378
+ */
379
+ onChainHashRegistryRef: Meta<string>;
380
+ constructor(options?: any);
381
+ /**
382
+ * Once `super.initialize()` has applied the framework's option-
383
+ * override pass, capture the rights snapshot if (and only if) the
384
+ * row arrived already issued. That's how the immutability guard
385
+ * tells "freshly drafting a license" (snapshot still mutable) apart
386
+ * from "loaded an already-issued row" (snapshot frozen).
387
+ */
388
+ initialize(): Promise<this>;
389
+ /**
390
+ * Return the current rights snapshot as a typed object. Read-only
391
+ * for callers — mutation should go through assignment to the
392
+ * individual `rights*` fields, gated by the issued-immutability
393
+ * guard.
394
+ */
395
+ getRightsSnapshot(): LicenseRightsSnapshot;
396
+ /**
397
+ * Revoke an issued license — moves status to `CANCELLED` without
398
+ * touching the rights snapshot (which stays frozen). Throws if
399
+ * called on a non-issued license; a draft license should be
400
+ * deleted, not revoked.
401
+ */
402
+ revoke(): void;
403
+ /**
404
+ * Save with the immutability check: if the row was loaded with
405
+ * `ACCEPTED` status, the rights snapshot at save time must match
406
+ * the snapshot at load time. Anything else means an out-of-band
407
+ * mutation crept in and we surface it instead of letting the row
408
+ * drift silently.
409
+ *
410
+ * Newly-drafted licenses (where the row was constructed without
411
+ * `ACCEPTED` status) capture their snapshot at the moment the
412
+ * caller transitions to `ACCEPTED` and saves — `validateImmutable`
413
+ * picks that up post-save on the next call.
414
+ */
415
+ save(): Promise<this>;
416
+ /**
417
+ * Compare the current rights against the captured snapshot
418
+ * (populated either at load time by `initialize` or at first
419
+ * issuance by `save`). Throws on mismatch.
420
+ */
421
+ private validateImmutable;
422
+ private serializeRightsSnapshot;
423
+ }
424
+ export default Contract;
425
+ //# sourceMappingURL=Contract.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Contract.d.ts","sourceRoot":"","sources":["../../src/models/Contract.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAEL,KAAK,IAAI,EACT,UAAU,EAEX,MAAM,0BAA0B,CAAC;AAElC,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AA2CjE;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,qBAOa,QAAS,SAAQ,UAAU;IACtC;;;OAGG;IAEH,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAQ;IAE/B;;OAEG;IACH,YAAY,EAAE,YAAY,CAAsB;IAEhD;;OAEG;IACH,MAAM,EAAE,cAAc,CAAwB;IAE9C;;OAEG;IAEH,UAAU,EAAE,MAAM,CAAM;IAExB;;OAEG;IAEH,QAAQ,EAAE,MAAM,CAAM;IAEtB;;OAEG;IACH,QAAQ,EAAE,MAAM,CAAO;IAEvB;;OAEG;IACH,SAAS,EAAE,MAAM,CAAO;IAExB;;OAEG;IACH,WAAW,EAAE,MAAM,CAAO;IAE1B;;OAEG;IACH,QAAQ,EAAE,MAAM,CAAS;IAEzB;;OAEG;IACH,SAAS,EAAE,IAAI,CAAc;IAE7B;;OAEG;IACH,OAAO,EAAE,IAAI,GAAG,IAAI,CAAQ;IAE5B;;OAEG;IACH,UAAU,EAAE,IAAI,GAAG,IAAI,CAAQ;IAE/B;;OAEG;IACH,SAAS,EAAE,MAAM,CAAM;IAEvB;;OAEG;IACH,KAAK,EAAE,MAAM,CAAM;IAEnB;;OAEG;IACH,KAAK,EAAE,MAAM,CAAM;IAEnB;;;;;;OAMG;IACH,SAAS,EAAE,MAAM,CAAM;IAEvB;;OAEG;IACH,MAAM,CAAC,QAAQ,CAAC,SAAS,kBAAkB;gBAE/B,OAAO,GAAE,GAAQ;IAsB7B;;OAEG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C,MAAM,CAAC,CAAM;IAE1B;;;;OAIG;IACH,OAAO,EAAE,IAAI,CAAC,MAAM,CAAC,CAAM;IAE3B;;;;;;OAMG;IACH,sBAAsB,EAAE,IAAI,CAAC,MAAM,CAAC,CAAM;gBAE9B,OAAO,GAAE,GAAQ;IA8B7B;;;;;;OAMG;IACY,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAQ1C;;;;;OAKG;IACH,iBAAiB,IAAI,qBAAqB;IAY1C;;;;;OAKG;IACH,MAAM,IAAI,IAAI;IASd;;;;;;;;;;;OAWG;IACY,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IAcpC;;;;OAIG;IACH,OAAO,CAAC,iBAAiB;IAYzB,OAAO,CAAC,uBAAuB;CAahC;AAED,eAAe,QAAQ,CAAC"}
@@ -0,0 +1,92 @@
1
+ import { SmrtObject } from '@happyvertical/smrt-core';
2
+ /**
3
+ * ContractLineItem represents a single line item on a contract.
4
+ *
5
+ * Line items contain the details of what is being sold/purchased,
6
+ * including quantity, pricing, and optional subscription details.
7
+ *
8
+ * @example
9
+ * ```typescript
10
+ * const lineItem = await lineItems.create({
11
+ * contractId: order.id,
12
+ * description: 'Widget Pro',
13
+ * quantity: 10,
14
+ * unitPrice: 49.99,
15
+ * taxRate: 0.08
16
+ * });
17
+ * ```
18
+ */
19
+ export declare class ContractLineItem extends SmrtObject {
20
+ /**
21
+ * Tenant ID for multi-tenant isolation
22
+ * Nullable to support both tenant-scoped and global line items
23
+ */
24
+ tenantId: string | null;
25
+ /**
26
+ * Parent contract
27
+ */
28
+ contractId: string;
29
+ /**
30
+ * Item description
31
+ */
32
+ description: string;
33
+ /**
34
+ * Quantity ordered
35
+ */
36
+ quantity: number;
37
+ /**
38
+ * Unit price before discount
39
+ */
40
+ unitPrice: number;
41
+ /**
42
+ * Discount amount (flat, not percentage)
43
+ */
44
+ discount: number;
45
+ /**
46
+ * Tax rate as decimal (e.g., 0.08 for 8%)
47
+ */
48
+ taxRate: number;
49
+ /**
50
+ * Calculated line amount (qty * price - discount + tax)
51
+ */
52
+ amount: number;
53
+ /**
54
+ * Optional product reference (cross-package, plain string)
55
+ */
56
+ productId: string;
57
+ /**
58
+ * SKU or item code
59
+ */
60
+ sku: string;
61
+ /**
62
+ * Start date (for lease/subscription items)
63
+ */
64
+ startDate: Date | null;
65
+ /**
66
+ * End date (for lease/subscription items)
67
+ */
68
+ endDate: Date | null;
69
+ /**
70
+ * Billing period (for subscriptions: 'monthly', 'yearly', etc.)
71
+ */
72
+ billingPeriod: string;
73
+ /**
74
+ * Sort order within the contract
75
+ */
76
+ sortOrder: number;
77
+ constructor(options?: any);
78
+ /**
79
+ * Calculate the line amount
80
+ */
81
+ calculateAmount(): number;
82
+ /**
83
+ * Check if this is a subscription/recurring item
84
+ */
85
+ isRecurring(): boolean;
86
+ /**
87
+ * Check if subscription is active
88
+ */
89
+ isSubscriptionActive(): boolean;
90
+ }
91
+ export default ContractLineItem;
92
+ //# sourceMappingURL=ContractLineItem.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ContractLineItem.d.ts","sourceRoot":"","sources":["../../src/models/ContractLineItem.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAGL,UAAU,EAEX,MAAM,0BAA0B,CAAC;AAGlC;;;;;;;;;;;;;;;;GAgBG;AACH,qBAOa,gBAAiB,SAAQ,UAAU;IAC9C;;;OAGG;IAEH,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAQ;IAE/B;;OAEG;IAEH,UAAU,EAAE,MAAM,CAAM;IAExB;;OAEG;IACH,WAAW,EAAE,MAAM,CAAM;IAEzB;;OAEG;IACH,QAAQ,EAAE,MAAM,CAAO;IAEvB;;OAEG;IACH,SAAS,EAAE,MAAM,CAAO;IAExB;;OAEG;IACH,QAAQ,EAAE,MAAM,CAAO;IAEvB;;OAEG;IACH,OAAO,EAAE,MAAM,CAAO;IAEtB;;OAEG;IACH,MAAM,EAAE,MAAM,CAAO;IAErB;;OAEG;IAEH,SAAS,EAAE,MAAM,CAAM;IAEvB;;OAEG;IACH,GAAG,EAAE,MAAM,CAAM;IAEjB;;OAEG;IACH,SAAS,EAAE,IAAI,GAAG,IAAI,CAAQ;IAE9B;;OAEG;IACH,OAAO,EAAE,IAAI,GAAG,IAAI,CAAQ;IAE5B;;OAEG;IACH,aAAa,EAAE,MAAM,CAAM;IAE3B;;OAEG;IACH,SAAS,EAAE,MAAM,CAAK;gBAEV,OAAO,GAAE,GAAQ;IAoB7B;;OAEG;IACH,eAAe,IAAI,MAAM;IAMzB;;OAEG;IACH,WAAW,IAAI,OAAO;IAItB;;OAEG;IACH,oBAAoB,IAAI,OAAO;CAUhC;AAED,eAAe,gBAAgB,CAAC"}
@@ -0,0 +1,98 @@
1
+ import { SmrtObject } from '@happyvertical/smrt-core';
2
+ import { Address, CustomerStatus, CustomerType } from '../types/index.js';
3
+ /**
4
+ * Customer represents the customer role for a Profile.
5
+ *
6
+ * One Profile can have multiple Customer records (e.g., different business contexts).
7
+ * Customer stores customer-specific data like credit limits and payment terms.
8
+ *
9
+ * @example
10
+ * ```typescript
11
+ * const customer = await customers.create({
12
+ * profileId: 'profile-uuid',
13
+ * creditLimit: 10000,
14
+ * paymentTerms: 'Net 30'
15
+ * });
16
+ * ```
17
+ */
18
+ export declare class Customer extends SmrtObject {
19
+ /**
20
+ * Tenant ID for multi-tenant isolation
21
+ * Nullable to support both tenant-scoped and global customers
22
+ */
23
+ tenantId: string | null;
24
+ /**
25
+ * Reference to smrt-profiles Profile
26
+ * Plain string for cross-package reference
27
+ */
28
+ profileId: string;
29
+ /**
30
+ * Maximum credit extended to this customer
31
+ */
32
+ creditLimit: number;
33
+ /**
34
+ * Payment terms (e.g., "Net 30", "Due on receipt", "2/10 Net 30")
35
+ */
36
+ paymentTerms: string;
37
+ /**
38
+ * Whether customer is exempt from tax
39
+ */
40
+ taxExempt: boolean;
41
+ /**
42
+ * Tax identification number
43
+ *
44
+ * Sensitive (#1540): PII excluded from generated API/MCP responses and
45
+ * rejected as a `where` filter key.
46
+ */
47
+ taxId: string;
48
+ /**
49
+ * Default shipping address
50
+ */
51
+ defaultShippingAddress: Address;
52
+ /**
53
+ * Default billing address
54
+ */
55
+ defaultBillingAddress: Address;
56
+ /**
57
+ * Customer status
58
+ */
59
+ status: CustomerStatus;
60
+ /**
61
+ * Customer classification — DTC, wholesale, or retail.
62
+ *
63
+ * Drives channel access (wholesale portal vs. storefront vs. POS), default
64
+ * price tier, and credit terms. Defaults to DTC for backwards compatibility.
65
+ */
66
+ customerType: CustomerType;
67
+ /**
68
+ * Internal notes about this customer
69
+ */
70
+ notes: string;
71
+ constructor(options?: any);
72
+ /**
73
+ * Convenience predicate: is this a wholesale customer?
74
+ */
75
+ isWholesale(): boolean;
76
+ /**
77
+ * Check if customer is active
78
+ */
79
+ isActive(): boolean;
80
+ /**
81
+ * Check if customer has available credit
82
+ */
83
+ hasAvailableCredit(amount: number): boolean;
84
+ /**
85
+ * Get the profile ID for external lookup.
86
+ *
87
+ * To get the actual Profile object, use the ProfileCollection from smrt-profiles:
88
+ * ```typescript
89
+ * const profiles = await ProfileCollection.create(options);
90
+ * const profile = await profiles.get({ id: customer.profileId });
91
+ * ```
92
+ *
93
+ * @returns The profile ID or empty string if not set
94
+ */
95
+ getProfileId(): string;
96
+ }
97
+ export default Customer;
98
+ //# sourceMappingURL=Customer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Customer.d.ts","sourceRoot":"","sources":["../../src/models/Customer.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAGL,UAAU,EAEX,MAAM,0BAA0B,CAAC;AAElC,OAAO,EAAE,KAAK,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAE/E;;;;;;;;;;;;;;GAcG;AACH,qBAMa,QAAS,SAAQ,UAAU;IACtC;;;OAGG;IAEH,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAQ;IAE/B;;;OAGG;IAEH,SAAS,EAAE,MAAM,CAAM;IAEvB;;OAEG;IACH,WAAW,EAAE,MAAM,CAAO;IAE1B;;OAEG;IACH,YAAY,EAAE,MAAM,CAAM;IAE1B;;OAEG;IACH,SAAS,EAAE,OAAO,CAAS;IAE3B;;;;;OAKG;IAEH,KAAK,EAAE,MAAM,CAAM;IAEnB;;OAEG;IACH,sBAAsB,EAAE,OAAO,CAAM;IAErC;;OAEG;IACH,qBAAqB,EAAE,OAAO,CAAM;IAEpC;;OAEG;IACH,MAAM,EAAE,cAAc,CAAyB;IAE/C;;;;;OAKG;IACH,YAAY,EAAE,YAAY,CAAoB;IAE9C;;OAEG;IACH,KAAK,EAAE,MAAM,CAAM;gBAEP,OAAO,GAAE,GAAQ;IA4B7B;;OAEG;IACH,WAAW,IAAI,OAAO;IAItB;;OAEG;IACH,QAAQ,IAAI,OAAO;IAInB;;OAEG;IACH,kBAAkB,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO;IAK3C;;;;;;;;;;OAUG;IACH,YAAY,IAAI,MAAM;CAGvB;AAED,eAAe,QAAQ,CAAC"}