@happyvertical/smrt-products 0.40.69 → 0.41.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 (28) hide show
  1. package/AGENTS.md +2 -1
  2. package/dist/lib/chunks/{ProductAssetCollection-BLfdEtYT.js → ProductAssetCollection-kErZwsTl.js} +3 -3
  3. package/dist/lib/chunks/{ProductAssetCollection-BLfdEtYT.js.map → ProductAssetCollection-kErZwsTl.js.map} +1 -1
  4. package/dist/lib/chunks/{ProductCollection-BDcBK9RN.js → ProductCollection-CiRifn2i.js} +2 -2
  5. package/dist/lib/chunks/{ProductCollection-BDcBK9RN.js.map → ProductCollection-CiRifn2i.js.map} +1 -1
  6. package/dist/lib/chunks/{Sku-C181XteX.js → Sku-DAZUXG7E.js} +13 -2
  7. package/dist/lib/chunks/Sku-DAZUXG7E.js.map +1 -0
  8. package/dist/lib/chunks/__smrt-register__-DvcpAIuW.js +6 -0
  9. package/dist/lib/chunks/__smrt-register__-DvcpAIuW.js.map +1 -0
  10. package/dist/lib/chunks/{collections-DWmWE4J4.js → collections-DRyKqpnl.js} +5 -5
  11. package/dist/lib/chunks/{collections-DWmWE4J4.js.map → collections-DRyKqpnl.js.map} +1 -1
  12. package/dist/lib/chunks/{generated-2mfImB_V.js → generated-900NHE8P.js} +2 -2
  13. package/dist/lib/chunks/{generated-2mfImB_V.js.map → generated-900NHE8P.js.map} +1 -1
  14. package/dist/lib/chunks/models-D8F5quuo.js +2 -0
  15. package/dist/lib/collections.js +3 -3
  16. package/dist/lib/generated.js +1 -1
  17. package/dist/lib/index.js +7 -7
  18. package/dist/lib/lib/models/Category.d.ts.map +1 -1
  19. package/dist/lib/lib/models/Product.d.ts +11 -0
  20. package/dist/lib/lib/models/Product.d.ts.map +1 -1
  21. package/dist/lib/manifest.json +130 -76
  22. package/dist/lib/models.js +2 -2
  23. package/dist/lib/smrt-knowledge.json +17 -5
  24. package/package.json +10 -9
  25. package/dist/lib/chunks/Sku-C181XteX.js.map +0 -1
  26. package/dist/lib/chunks/__smrt-register__-C_7iriA_.js +0 -6
  27. package/dist/lib/chunks/__smrt-register__-C_7iriA_.js.map +0 -1
  28. package/dist/lib/chunks/models-CzIxjfe7.js +0 -2
@@ -2,7 +2,7 @@
2
2
  "version": "1.0.0",
3
3
  "timestamp": 0,
4
4
  "packageName": "@happyvertical/smrt-products",
5
- "packageVersion": "0.40.69",
5
+ "packageVersion": "0.41.0",
6
6
  "objects": {
7
7
  "@happyvertical/smrt-products:CategoryCollection": {
8
8
  "name": "categorycollection",
@@ -58,12 +58,6 @@
58
58
  }
59
59
  },
60
60
  "indexes": [
61
- {
62
- "name": "category_collections_id_idx",
63
- "columns": [
64
- "id"
65
- ]
66
- },
67
61
  {
68
62
  "name": "category_collections_slug_context_idx",
69
63
  "columns": [
@@ -71,6 +65,12 @@
71
65
  "context"
72
66
  ],
73
67
  "unique": true
68
+ },
69
+ {
70
+ "name": "category_collections_created_at_idx",
71
+ "columns": [
72
+ "created_at"
73
+ ]
74
74
  }
75
75
  ],
76
76
  "version": "f2f42d47"
@@ -137,12 +137,6 @@
137
137
  }
138
138
  },
139
139
  "indexes": [
140
- {
141
- "name": "products_id_idx",
142
- "columns": [
143
- "id"
144
- ]
145
- },
146
140
  {
147
141
  "name": "products_slug_context_idx",
148
142
  "columns": [
@@ -150,6 +144,12 @@
150
144
  "context"
151
145
  ],
152
146
  "unique": true
147
+ },
148
+ {
149
+ "name": "products_created_at_idx",
150
+ "columns": [
151
+ "created_at"
152
+ ]
153
153
  }
154
154
  ],
155
155
  "version": "d7d2c125"
@@ -389,12 +389,6 @@
389
389
  }
390
390
  },
391
391
  "indexes": [
392
- {
393
- "name": "product_assets_id_idx",
394
- "columns": [
395
- "id"
396
- ]
397
- },
398
392
  {
399
393
  "name": "product_assets_slug_context_idx",
400
394
  "columns": [
@@ -402,6 +396,12 @@
402
396
  "context"
403
397
  ],
404
398
  "unique": true
399
+ },
400
+ {
401
+ "name": "product_assets_created_at_idx",
402
+ "columns": [
403
+ "created_at"
404
+ ]
405
405
  }
406
406
  ],
407
407
  "version": "ffb1b593"
@@ -548,12 +548,6 @@
548
548
  }
549
549
  },
550
550
  "indexes": [
551
- {
552
- "name": "product_collections_id_idx",
553
- "columns": [
554
- "id"
555
- ]
556
- },
557
551
  {
558
552
  "name": "product_collections_slug_context_idx",
559
553
  "columns": [
@@ -561,6 +555,12 @@
561
555
  "context"
562
556
  ],
563
557
  "unique": true
558
+ },
559
+ {
560
+ "name": "product_collections_created_at_idx",
561
+ "columns": [
562
+ "created_at"
563
+ ]
564
564
  }
565
565
  ],
566
566
  "version": "51a90ef1"
@@ -647,12 +647,6 @@
647
647
  }
648
648
  },
649
649
  "indexes": [
650
- {
651
- "name": "product_variants_id_idx",
652
- "columns": [
653
- "id"
654
- ]
655
- },
656
650
  {
657
651
  "name": "product_variants_slug_context_idx",
658
652
  "columns": [
@@ -660,6 +654,12 @@
660
654
  "context"
661
655
  ],
662
656
  "unique": true
657
+ },
658
+ {
659
+ "name": "product_variants_created_at_idx",
660
+ "columns": [
661
+ "created_at"
662
+ ]
663
663
  }
664
664
  ],
665
665
  "version": "7e192164"
@@ -783,12 +783,6 @@
783
783
  }
784
784
  },
785
785
  "indexes": [
786
- {
787
- "name": "product_skus_id_idx",
788
- "columns": [
789
- "id"
790
- ]
791
- },
792
786
  {
793
787
  "name": "product_skus_slug_context_idx",
794
788
  "columns": [
@@ -796,6 +790,12 @@
796
790
  "context"
797
791
  ],
798
792
  "unique": true
793
+ },
794
+ {
795
+ "name": "product_skus_created_at_idx",
796
+ "columns": [
797
+ "created_at"
798
+ ]
799
799
  }
800
800
  ],
801
801
  "version": "f3e8dedc"
@@ -1374,7 +1374,13 @@
1374
1374
  "cli": true,
1375
1375
  "tenantScoped": {
1376
1376
  "mode": "optional"
1377
- }
1377
+ },
1378
+ "conflictColumns": [
1379
+ "tenant_id",
1380
+ "slug",
1381
+ "context",
1382
+ "_meta_type"
1383
+ ]
1378
1384
  },
1379
1385
  "extends": "SmrtObject",
1380
1386
  "exportName": "Category",
@@ -1468,15 +1474,10 @@
1468
1474
  }
1469
1475
  },
1470
1476
  "indexes": [
1471
- {
1472
- "name": "categories_id_idx",
1473
- "columns": [
1474
- "id"
1475
- ]
1476
- },
1477
1477
  {
1478
1478
  "name": "categories_slug_context_meta_type_idx",
1479
1479
  "columns": [
1480
+ "tenant_id",
1480
1481
  "slug",
1481
1482
  "context",
1482
1483
  "_meta_type"
@@ -1488,6 +1489,19 @@
1488
1489
  "columns": [
1489
1490
  "_meta_type"
1490
1491
  ]
1492
+ },
1493
+ {
1494
+ "name": "categories_tenant_id_created_at_idx",
1495
+ "columns": [
1496
+ "tenant_id",
1497
+ "created_at"
1498
+ ]
1499
+ },
1500
+ {
1501
+ "name": "categories_parent_id_idx",
1502
+ "columns": [
1503
+ "parent_id"
1504
+ ]
1491
1505
  }
1492
1506
  ],
1493
1507
  "version": "9b7d356d"
@@ -2303,15 +2317,10 @@
2303
2317
  }
2304
2318
  },
2305
2319
  "indexes": [
2306
- {
2307
- "name": "products_id_idx",
2308
- "columns": [
2309
- "id"
2310
- ]
2311
- },
2312
2320
  {
2313
2321
  "name": "products_slug_context_meta_type_idx",
2314
2322
  "columns": [
2323
+ "tenant_id",
2315
2324
  "slug",
2316
2325
  "context",
2317
2326
  "_meta_type"
@@ -2323,9 +2332,16 @@
2323
2332
  "columns": [
2324
2333
  "_meta_type"
2325
2334
  ]
2335
+ },
2336
+ {
2337
+ "name": "products_tenant_id_created_at_idx",
2338
+ "columns": [
2339
+ "tenant_id",
2340
+ "created_at"
2341
+ ]
2326
2342
  }
2327
2343
  ],
2328
- "version": "4a33c96d"
2344
+ "version": "a7b4d592"
2329
2345
  }
2330
2346
  },
2331
2347
  "@happyvertical/smrt-products:Product": {
@@ -3008,7 +3024,13 @@
3008
3024
  "cli": true,
3009
3025
  "tenantScoped": {
3010
3026
  "mode": "optional"
3011
- }
3027
+ },
3028
+ "conflictColumns": [
3029
+ "tenant_id",
3030
+ "slug",
3031
+ "context",
3032
+ "_meta_type"
3033
+ ]
3012
3034
  },
3013
3035
  "extends": "SmrtObject",
3014
3036
  "exportName": "Product",
@@ -3113,15 +3135,10 @@
3113
3135
  }
3114
3136
  },
3115
3137
  "indexes": [
3116
- {
3117
- "name": "products_id_idx",
3118
- "columns": [
3119
- "id"
3120
- ]
3121
- },
3122
3138
  {
3123
3139
  "name": "products_slug_context_meta_type_idx",
3124
3140
  "columns": [
3141
+ "tenant_id",
3125
3142
  "slug",
3126
3143
  "context",
3127
3144
  "_meta_type"
@@ -3133,6 +3150,13 @@
3133
3150
  "columns": [
3134
3151
  "_meta_type"
3135
3152
  ]
3153
+ },
3154
+ {
3155
+ "name": "products_tenant_id_created_at_idx",
3156
+ "columns": [
3157
+ "tenant_id",
3158
+ "created_at"
3159
+ ]
3136
3160
  }
3137
3161
  ],
3138
3162
  "version": "a7b4d592"
@@ -3291,12 +3315,6 @@
3291
3315
  }
3292
3316
  },
3293
3317
  "indexes": [
3294
- {
3295
- "name": "product_assets_id_idx",
3296
- "columns": [
3297
- "id"
3298
- ]
3299
- },
3300
3318
  {
3301
3319
  "name": "product_assets_product_id_asset_id_idx",
3302
3320
  "columns": [
@@ -3306,6 +3324,26 @@
3306
3324
  "tenant_id"
3307
3325
  ],
3308
3326
  "unique": true
3327
+ },
3328
+ {
3329
+ "name": "product_assets_slug_context_idx",
3330
+ "columns": [
3331
+ "slug",
3332
+ "context"
3333
+ ]
3334
+ },
3335
+ {
3336
+ "name": "product_assets_tenant_id_created_at_idx",
3337
+ "columns": [
3338
+ "tenant_id",
3339
+ "created_at"
3340
+ ]
3341
+ },
3342
+ {
3343
+ "name": "product_assets_asset_id_idx",
3344
+ "columns": [
3345
+ "asset_id"
3346
+ ]
3309
3347
  }
3310
3348
  ],
3311
3349
  "version": "320e1554"
@@ -3501,12 +3539,6 @@
3501
3539
  }
3502
3540
  },
3503
3541
  "indexes": [
3504
- {
3505
- "name": "product_variants_id_idx",
3506
- "columns": [
3507
- "id"
3508
- ]
3509
- },
3510
3542
  {
3511
3543
  "name": "product_variants_product_id_axis_name_idx",
3512
3544
  "columns": [
@@ -3515,6 +3547,20 @@
3515
3547
  "tenant_id"
3516
3548
  ],
3517
3549
  "unique": true
3550
+ },
3551
+ {
3552
+ "name": "product_variants_slug_context_idx",
3553
+ "columns": [
3554
+ "slug",
3555
+ "context"
3556
+ ]
3557
+ },
3558
+ {
3559
+ "name": "product_variants_tenant_id_created_at_idx",
3560
+ "columns": [
3561
+ "tenant_id",
3562
+ "created_at"
3563
+ ]
3518
3564
  }
3519
3565
  ],
3520
3566
  "version": "2891ff02"
@@ -3741,12 +3787,6 @@
3741
3787
  }
3742
3788
  },
3743
3789
  "indexes": [
3744
- {
3745
- "name": "product_skus_id_idx",
3746
- "columns": [
3747
- "id"
3748
- ]
3749
- },
3750
3790
  {
3751
3791
  "name": "product_skus_code_tenant_id_idx",
3752
3792
  "columns": [
@@ -3754,6 +3794,20 @@
3754
3794
  "tenant_id"
3755
3795
  ],
3756
3796
  "unique": true
3797
+ },
3798
+ {
3799
+ "name": "product_skus_slug_context_idx",
3800
+ "columns": [
3801
+ "slug",
3802
+ "context"
3803
+ ]
3804
+ },
3805
+ {
3806
+ "name": "product_skus_tenant_id_created_at_idx",
3807
+ "columns": [
3808
+ "tenant_id",
3809
+ "created_at"
3810
+ ]
3757
3811
  }
3758
3812
  ],
3759
3813
  "version": "89d5a311"
@@ -1,3 +1,3 @@
1
- import { a as Product, i as Material, n as ProductVariant, o as ProductType, r as ProductAsset, s as Category, t as Sku } from "./chunks/Sku-C181XteX.js";
2
- import "./chunks/models-CzIxjfe7.js";
1
+ import { a as Product, i as Material, n as ProductVariant, o as ProductType, r as ProductAsset, s as Category, t as Sku } from "./chunks/Sku-DAZUXG7E.js";
2
+ import "./chunks/models-D8F5quuo.js";
3
3
  export { Category, Material, Product, ProductAsset, ProductType, ProductVariant, Sku };
@@ -3,13 +3,13 @@
3
3
  "sensitiveFieldsExcluded": true,
4
4
  "generatedAt": "1970-01-01T00:00:00.000Z",
5
5
  "packageName": "@happyvertical/smrt-products",
6
- "packageVersion": "0.40.69",
6
+ "packageVersion": "0.41.0",
7
7
  "sourceManifestPath": "dist/lib/manifest.json",
8
8
  "agentDocPath": "AGENTS.md",
9
9
  "sourceHashes": {
10
- "manifest": "b2a2bdb0a0eb41c5abfc0a20d3ea12629d7ec9105c504e3ab8387ec425881cb4",
11
- "packageJson": "6447bbd50f947ed4b6d91cafdfd22ab5a9926d45fd7cff6d1d61236dfa0aa5dd",
12
- "agents": "33d82ef8e2eb4597c4165e7576c20a02a76d224a75cadcbd89f9ce9cc1deae3c"
10
+ "manifest": "57cd60cd1bb4be8708590d6a8e9cd9e83b04d11cd4af494cd2a10bddb9fea83c",
11
+ "packageJson": "68a15e0d2d9b1dd6324fa1923a7f382a7983cd2637d3a6ea147793fbafde6098",
12
+ "agents": "4ddde01c48baf13de773cdb57353a148f3fe3b93d21e99d8ac57677cda809e26"
13
13
  },
14
14
  "exports": [
15
15
  ".",
@@ -797,6 +797,12 @@
797
797
  "field": "tenantId"
798
798
  },
799
799
  "tableStrategy": "sti",
800
+ "conflictColumns": [
801
+ "tenant_id",
802
+ "slug",
803
+ "context",
804
+ "_meta_type"
805
+ ],
800
806
  "surfaces": [
801
807
  {
802
808
  "kind": "api",
@@ -1892,6 +1898,12 @@
1892
1898
  "field": "tenantId"
1893
1899
  },
1894
1900
  "tableStrategy": "sti",
1901
+ "conflictColumns": [
1902
+ "tenant_id",
1903
+ "slug",
1904
+ "context",
1905
+ "_meta_type"
1906
+ ],
1895
1907
  "surfaces": [
1896
1908
  {
1897
1909
  "kind": "api",
@@ -2774,5 +2786,5 @@
2774
2786
  "polymorphicAssociations": 0,
2775
2787
  "uuidColumns": 21
2776
2788
  },
2777
- "agentDoc": "# @happyvertical/smrt-products\n\nProduct catalog — reference template for triple-consumption: npm package library, module federation, and standalone REST API server.\n\n## Models\n\n- **Product**: STI base. Tenant-scoped (`@TenantScoped({ mode: 'optional' })`, nullable `tenantId`). Knowledge base product with specs, tags, and the `productType` discriminator. Consumers subclass this with vertical-specific subtypes (apparel `Style`, automotive `Model`, furniture `Design`, etc.).\n- **Material**: STI subtype. Raw input consumed by manufacturing (fabric, trim, thread, packaging, component). Meta fields: `materialKind`, `uom`, `costPerUnit`. Materials are first-class products in the catalog — the SAP/NetSuite pattern. Bills of materials in `@happyvertical/smrt-manufacturing` reference Materials by id.\n- **ProductVariant**: standalone (NOT a Product STI subtype). Declarative axis definition: `productId`, `axisName` (e.g. `'size'`, `'color'`, `'finish'`), `allowedValues` (JSON-stored array), optional `label` and `sortOrder`. Per-SKU value pins live on `Sku.attributes`. Lives in its own `product_variants` table; `conflictColumns: ['product_id', 'axis_name', 'tenant_id']`.\n- **Sku**: standalone. The smallest sellable / countable unit. `productId` points at a `Product` or any of its STI subtypes; `code` is the human-meaningful identifier; `attributes` JSON pins each axis value (`{ size: 'M', color: 'navy' }`). Lives in its own `product_skus` table; `conflictColumns: ['code', 'tenant_id']`. Stock balance and movement history for a Sku live in `@happyvertical/smrt-inventory`.\n- **ProductAsset**: dedicated owned-asset join in `product_assets` with `relationship` and `sortOrder`. Tenant-scoped to match Product.\n- **Category**: hierarchical (parentId, level, productCount). STI base, tenant-scoped.\n\n## Vertical-specific Product subtypes\n\nThis package deliberately ships ONLY the generic primitives. Domain-specific top-level item types live in the consumer's template:\n\n- Apparel: `Style extends Product`, `Makeup extends Product`\n- Furniture: `Design extends Product`, `Configuration extends Product`\n- Automotive: `Model extends Product`, `Trim extends Product`\n- CPG: `Brand extends Product`, `Recipe extends Product`\n\nEach is a small subclass: `@smrt()`, override `productType`, add `@meta()` fields. See `packages/template-apparel-erp` for a worked example.\n\n## Variants — the two concepts\n\nThe framework's variant story uses two distinct primitives that look similar but do different jobs:\n\n- **`ProductVariant`** — *axis declaration*. \"For product X, axis `size` accepts the values `[XS, S, M, L, XL]`.\" Drives form/UI choices.\n- **`Sku.attributes`** — *per-unit value pins*. `{ color: 'navy', size: 'M' }` on each concrete sellable SKU.\n\nBoth live in this package — all catalog shapes are here. Stock motion (where the SKU is, how many, history) lives in `@happyvertical/smrt-inventory`.\n\nThere is deliberately no separate \"catalog grouping above SKU\" row (a la a \"Navy colorway\" row sitting between the Product and its Skus). Group SKUs by axis value via `attributes.color = 'navy'` queries; attach per-axis-value assets via `ProductAsset` rows with relationship metadata. Matches how Shopify, Stripe Products, and most e-commerce platforms model the same shape.\n\n## Collections\n\n- **ProductCollection** — base. Polymorphic queries return the correct subclass instance per row.\n- **MaterialCollection** — STI-filtered subclass. Override `_itemClass`; framework auto-filters by `_meta_type`.\n- **ProductVariantCollection** — standalone collection over `product_variants`. Helpers: `findForProduct(productId)`, `findAxis(productId, axisName)`.\n- **SkuCollection** — standalone collection over `product_skus`. Helpers: `findByCode`, `findByBarcode`, `findByProduct`, `findByParent`, `findActive`.\n- **CategoryCollection** — standard Category CRUD with `getRootCategories()`.\n- **ProductAssetCollection** — direct access to `product_assets` rows and product asset helper wrappers.\n\n## Multi-tenancy\n\nOptional. With `withTenant(id, fn)` (from `@happyvertical/smrt-tenancy`), all queries auto-filter and inserts auto-stamp `tenantId`. Without it, models behave globally (`tenantId = null`). This lets the same package serve both shared reference catalogs and per-merchant SaaS catalogs.\n\n## Triple-Consumption Pattern\n\nSame codebase consumed three ways:\n1. **NPM library**: import classes directly\n2. **Module federation**: runtime component sharing (experimental)\n3. **Standalone API**: `startRestServer([Product, Category])`\n\n## Virtual Modules (Vite)\n\nAuto-generated via Vite plugins: `@happyvertical/smrt-client` (TypeScript client), `@happyvertical/smrt-types`, `@happyvertical/smrt-routes` (Express), `@happyvertical/smrt-mcp`, `@happyvertical/smrt-manifest`.\n\nSvelte 5 stores use runes (`$state`, `$derived`, `$effect`). `product-store.svelte.ts` is the main store (backed by the SMRT client); `product-store.client.svelte.ts` is a virtual-module-free variant for federation builds.\n\n## Client-data runtime — reference store (#1761)\n\nProducts is the reference consumer of the `@happyvertical/smrt-web` browser client-data runtime.\n\n- **Store** — `src/lib/stores/product-collection.ts` (subpath `@happyvertical/smrt-products/stores/product-collection`). `createProductCollection(definition, options)` builds a cached, reactive `SmrtWebCollection<ProductData>` over the generated `/api/v1/products` REST surface via `createSmrtCollection`. It is plugin-agnostic on purpose: the `products` definition is a PARAMETER (not a top-level import), so importing the store never eagerly resolves `@happyvertical/smrt-virt-web` (which exists only under the SMRT Vite plugin) — a unit test / npm consumer supplies its own definition. `productsCollectionDefinition()` lazily resolves the plugin definition (dynamic `import()`; resolved for `tsc` via the `@smrt/web` ambient alias). Deliberately NOT re-exported from the always-loaded `./stores` barrel — importing it is an explicit opt-in to the engine.\n- **Live surface** — `src/lib/components/LiveProductList.svelte` binds the store with `liveCollection` from `@happyvertical/smrt-svelte/web` (live rows + optimistic insert); it takes the definition as a prop. `src/app/pages/LiveProductsPage.svelte` (route `#live`) resolves the component AND the definition via `import()` and passes the definition down.\n- **Code-split (ratified condition ①)** — the ~76 kB TanStack engine must NEVER load on public / smrt-sites pages. `LiveProductsPage` reaches `LiveProductList` and the store ONLY through dynamic `import()`, so the engine lands in a lazily-loaded chunk; the app entry stays engine-free. NEVER import the store or live component statically from an app-root / public entry. `scripts/check-web-engine-code-split.mjs` (wrapped by `src/web-engine-code-split.spec.ts`, `pnpm test:code-split`) proves this against the REAL app graph: it runs the `--mode standalone` vite build and asserts, over the emitted rollup chunk graph, that the entry's static-import closure has zero `@tanstack/*` and the engine is reached only via `dynamicImports`. If the build hits the pre-existing nested-worktree `Tsconfig not found` failure locally, it falls back to a static-import-graph walk of the real `src/app/main.ts` (CI runs the real build).\n\n## Schema migrations (Phase 1 release)\n\nThis package's schema changed shape between the previous release and the Phase 1 apparel-ERP release. Consumers upgrading need to migrate two tables.\n\n### `Sku` rows moved tables\n\nPreviously `Sku` shipped in `@happyvertical/smrt-inventory` under table `inventory_skus`. It now lives here under `product_skus`. Cross-package refs (`StockLevel.skuId`, `BomLine.componentSkuId`) carry plain string ids that still resolve.\n\n**Upgrade procedure** (works on SQLite + Postgres; does NOT rely on `CREATE TABLE AS` which strips constraints):\n\n1. **Boot the new version once** so the framework's lazy `syncSchema` creates `product_skus` with the right PRIMARY KEY, NOT NULL, UNIQUE (`code`, `tenant_id`), and indexes derived from the `Sku` model.\n\n2. **Idempotently copy rows**:\n\n ```sql\n BEGIN;\n INSERT INTO product_skus (\n id, slug, context, created_at, updated_at,\n tenant_id, product_id, code, barcode, name,\n attributes, weight_grams, parent_sku_id, active\n )\n SELECT\n id, slug, context, created_at, updated_at,\n tenant_id, product_id, code, barcode, name,\n attributes, weight_grams, parent_sku_id, active\n FROM inventory_skus\n WHERE NOT EXISTS (\n SELECT 1 FROM product_skus p WHERE p.id = inventory_skus.id\n );\n COMMIT;\n ```\n\n3. **Drop the legacy table** once row counts match:\n\n ```sql\n DROP TABLE IF EXISTS inventory_skus;\n ```\n\n### `ProductVariant` changed shape entirely\n\nPreviously a Product STI subtype carrying `parentProductId` + `axisValues` JSON inside `_meta_data` on the shared `products` table (`_meta_type='@happyvertical/smrt-products:ProductVariant'`). It is now a **standalone model** on its own `product_variants` table, with columns `productId`, `axisName`, `allowedValues`, `label`, `sortOrder`.\n\n**There is no automatic data conversion.** The old \"catalog grouping above SKU\" concept doesn't map 1:1 to the new \"per-axis declaration\" concept. Recommended procedure:\n\n1. Inspect the old rows: `SELECT * FROM products WHERE _meta_type = '@happyvertical/smrt-products:ProductVariant';`. Treat them as historical reference.\n2. Re-author axis declarations against the new shape (one `ProductVariant` row per `(productId, axisName)` pair, with `allowedValues` listing the values).\n3. Once the new declarations are populated and verified, remove the legacy rows: `DELETE FROM products WHERE _meta_type = '@happyvertical/smrt-products:ProductVariant';`.\n\nIf you had per-colorway / per-variant images attached via `ProductAsset` rows pointing at old ProductVariant ids, repoint those to the parent Product id; group-by-axis-value queries on `Sku.attributes` cover the same use case at the SKU level.\n\n## Gotchas\n\n- **`ProductVariant` and `Sku` are NOT Product STI subtypes** — they each have their own table (`product_variants`, `product_skus`) because their shapes don't fit the Product schema. Don't try to query them via `ProductCollection`.\n- **`npm run build` emits the published library surface directly**: package consumers read model, collection, and helper exports from `dist/lib`. Cross-package imports from this package should target `/models` or `/collections` subpaths (not the main entry) when the consumer isn't a vite app — the main entry pulls in vite virtual modules.\n- **Use `npm run build:all` only when you need standalone or federation bundles** in addition to the library output\n- **Constructor must explicitly assign all properties**: `Object.assign` doesn't work reliably with decorators\n- **STI subtype-specific fields use `Meta<T>`** — declare them as `fieldName: Meta<FieldType> = defaultValue`. The AST scanner detects the `Meta<T>` type wrapper at build time and routes the field through `_meta_data` JSON storage instead of materializing it as a column on the parent's table. Do **NOT** use the runtime `@meta()` decorator on STI children — it never reaches the manifest, so the schema generator treats the field as an ordinary column on the parent table and the framework's hydration path can't tell it's meta. Override `productType` on each subclass.\n- **Tenant-scoped STI children must repeat `@TenantScoped`** — `@TenantScoped` registers per concrete className, so `Material extends Product` inheriting from a tenant-scoped `Product` is NOT automatically tenant-scoped itself. `MaterialCollection.list/save` passes `'Material'` to the tenant interceptor, which looks up `'Material'` (not `'Product'`) in the per-class registry. Without an explicit `@TenantScoped({ mode: 'optional' })` on `Material`, material rows skip the tenant auto-filter and auto-populate.\n- **STI children must repeat `@smrt({ api, mcp, cli })` generation config (S5 #1406)** — like `@TenantScoped`, the generation config is registered per concrete className and is NOT inherited from the STI parent. An empty `@smrt()` on a child resolves `getConfig(child).api/.mcp` to `undefined`, which the REST and MCP generators treat as \"expose EVERYTHING\" — including `delete` and write-capable MCP tools — even when the parent deliberately restricts its surface. The package's `mcp.ts` generator enumerates the whole registry, so an under-configured child ships a wide-open surface silently. Re-declare the parent's `api`/`mcp`/`cli` posture on every subtype (see `Material`). Consumer subtypes (apparel `Style`/`Makeup`, automotive `Model`/`Trim`, …) must do the same.\n- **Two-tenant same-slug is currently a hard error** for tenant-scoped STI bases (`Product`, `Category`). The core schema generator hardcodes the STI unique index as `(slug, context, _meta_type)` and does NOT include `tenant_id` even for `@TenantScoped` classes. Two tenants saving a row with the same slug + context + meta_type collide at the SQL layer. Workaround: namespace slugs per tenant on the application side (e.g. `${tenantId}-widget`) until the upstream framework fix lands.\n- **Module Federation marked experimental**: may change\n"
2789
+ "agentDoc": "# @happyvertical/smrt-products\n\nProduct catalog — reference template for triple-consumption: npm package library, module federation, and standalone REST API server.\n\n## Models\n\n- **Product**: STI base. Tenant-scoped (`@TenantScoped({ mode: 'optional' })`, nullable `tenantId`). Knowledge base product with specs, tags, and the `productType` discriminator. Consumers subclass this with vertical-specific subtypes (apparel `Style`, automotive `Model`, furniture `Design`, etc.).\n- **Material**: STI subtype. Raw input consumed by manufacturing (fabric, trim, thread, packaging, component). Meta fields: `materialKind`, `uom`, `costPerUnit`. Materials are first-class products in the catalog — the SAP/NetSuite pattern. Bills of materials in `@happyvertical/smrt-manufacturing` reference Materials by id.\n- **ProductVariant**: standalone (NOT a Product STI subtype). Declarative axis definition: `productId`, `axisName` (e.g. `'size'`, `'color'`, `'finish'`), `allowedValues` (JSON-stored array), optional `label` and `sortOrder`. Per-SKU value pins live on `Sku.attributes`. Lives in its own `product_variants` table; `conflictColumns: ['product_id', 'axis_name', 'tenant_id']`.\n- **Sku**: standalone. The smallest sellable / countable unit. `productId` points at a `Product` or any of its STI subtypes; `code` is the human-meaningful identifier; `attributes` JSON pins each axis value (`{ size: 'M', color: 'navy' }`). Lives in its own `product_skus` table; `conflictColumns: ['code', 'tenant_id']`. Stock balance and movement history for a Sku live in `@happyvertical/smrt-inventory`.\n- **ProductAsset**: dedicated owned-asset join in `product_assets` with `relationship` and `sortOrder`. Tenant-scoped to match Product.\n- **Category**: hierarchical (parentId, level, productCount). STI base, tenant-scoped.\n\n## Vertical-specific Product subtypes\n\nThis package deliberately ships ONLY the generic primitives. Domain-specific top-level item types live in the consumer's template:\n\n- Apparel: `Style extends Product`, `Makeup extends Product`\n- Furniture: `Design extends Product`, `Configuration extends Product`\n- Automotive: `Model extends Product`, `Trim extends Product`\n- CPG: `Brand extends Product`, `Recipe extends Product`\n\nEach is a small subclass: `@smrt()`, override `productType`, add `@meta()` fields. See `packages/template-apparel-erp` for a worked example.\n\n## Variants — the two concepts\n\nThe framework's variant story uses two distinct primitives that look similar but do different jobs:\n\n- **`ProductVariant`** — *axis declaration*. \"For product X, axis `size` accepts the values `[XS, S, M, L, XL]`.\" Drives form/UI choices.\n- **`Sku.attributes`** — *per-unit value pins*. `{ color: 'navy', size: 'M' }` on each concrete sellable SKU.\n\nBoth live in this package — all catalog shapes are here. Stock motion (where the SKU is, how many, history) lives in `@happyvertical/smrt-inventory`.\n\nThere is deliberately no separate \"catalog grouping above SKU\" row (a la a \"Navy colorway\" row sitting between the Product and its Skus). Group SKUs by axis value via `attributes.color = 'navy'` queries; attach per-axis-value assets via `ProductAsset` rows with relationship metadata. Matches how Shopify, Stripe Products, and most e-commerce platforms model the same shape.\n\n## Collections\n\n- **ProductCollection** — base. Polymorphic queries return the correct subclass instance per row.\n- **MaterialCollection** — STI-filtered subclass. Override `_itemClass`; framework auto-filters by `_meta_type`.\n- **ProductVariantCollection** — standalone collection over `product_variants`. Helpers: `findForProduct(productId)`, `findAxis(productId, axisName)`.\n- **SkuCollection** — standalone collection over `product_skus`. Helpers: `findByCode`, `findByBarcode`, `findByProduct`, `findByParent`, `findActive`.\n- **CategoryCollection** — standard Category CRUD with `getRootCategories()`.\n- **ProductAssetCollection** — direct access to `product_assets` rows and product asset helper wrappers.\n\n## Multi-tenancy\n\nOptional. With `withTenant(id, fn)` (from `@happyvertical/smrt-tenancy`), all queries auto-filter and inserts auto-stamp `tenantId`. Without it, models behave globally (`tenantId = null`). This lets the same package serve both shared reference catalogs and per-merchant SaaS catalogs.\n\n## Triple-Consumption Pattern\n\nSame codebase consumed three ways:\n1. **NPM library**: import classes directly\n2. **Module federation**: runtime component sharing (experimental)\n3. **Standalone API**: `startRestServer([Product, Category])`\n\n## Virtual Modules (Vite)\n\nAuto-generated via Vite plugins: `@happyvertical/smrt-client` (TypeScript client), `@happyvertical/smrt-types`, `@happyvertical/smrt-routes` (Express), `@happyvertical/smrt-mcp`, `@happyvertical/smrt-manifest`.\n\nSvelte 5 stores use runes (`$state`, `$derived`, `$effect`). `product-store.svelte.ts` is the main store (backed by the SMRT client); `product-store.client.svelte.ts` is a virtual-module-free variant for federation builds.\n\n## Client-data runtime — reference store (#1761)\n\nProducts is the reference consumer of the `@happyvertical/smrt-web` browser client-data runtime.\n\n- **Store** — `src/lib/stores/product-collection.ts` (subpath `@happyvertical/smrt-products/stores/product-collection`). `createProductCollection(definition, options)` builds a cached, reactive `SmrtWebCollection<ProductData>` over the generated `/api/v1/products` REST surface via `createSmrtCollection`. It is plugin-agnostic on purpose: the `products` definition is a PARAMETER (not a top-level import), so importing the store never eagerly resolves `@happyvertical/smrt-virt-web` (which exists only under the SMRT Vite plugin) — a unit test / npm consumer supplies its own definition. `productsCollectionDefinition()` lazily resolves the plugin definition (dynamic `import()`; resolved for `tsc` via the `@smrt/web` ambient alias). Deliberately NOT re-exported from the always-loaded `./stores` barrel — importing it is an explicit opt-in to the engine.\n- **Live surface** — `src/lib/components/LiveProductList.svelte` binds the store with `liveCollection` from `@happyvertical/smrt-svelte/web` (live rows + optimistic insert); it takes the definition as a prop. `src/app/pages/LiveProductsPage.svelte` (route `#live`) resolves the component AND the definition via `import()` and passes the definition down.\n- **Code-split (ratified condition ①)** — the ~76 kB TanStack engine must NEVER load on public / smrt-sites pages. `LiveProductsPage` reaches `LiveProductList` and the store ONLY through dynamic `import()`, so the engine lands in a lazily-loaded chunk; the app entry stays engine-free. NEVER import the store or live component statically from an app-root / public entry. `scripts/check-web-engine-code-split.mjs` (wrapped by `src/web-engine-code-split.spec.ts`, `pnpm test:code-split`) proves this against the REAL app graph: it runs the `--mode standalone` vite build and asserts, over the emitted rollup chunk graph, that the entry's static-import closure has zero `@tanstack/*` and the engine is reached only via `dynamicImports`. If the build hits the pre-existing nested-worktree `Tsconfig not found` failure locally, it falls back to a static-import-graph walk of the real `src/app/main.ts` (CI runs the real build).\n\n## Schema migrations (Phase 1 release)\n\nThis package's schema changed shape between the previous release and the Phase 1 apparel-ERP release. Consumers upgrading need to migrate two tables.\n\n### `Sku` rows moved tables\n\nPreviously `Sku` shipped in `@happyvertical/smrt-inventory` under table `inventory_skus`. It now lives here under `product_skus`. Cross-package refs (`StockLevel.skuId`, `BomLine.componentSkuId`) carry plain string ids that still resolve.\n\n**Upgrade procedure** (works on SQLite + Postgres; does NOT rely on `CREATE TABLE AS` which strips constraints):\n\n1. **Boot the new version once** so the framework's lazy `syncSchema` creates `product_skus` with the right PRIMARY KEY, NOT NULL, UNIQUE (`code`, `tenant_id`), and indexes derived from the `Sku` model.\n\n2. **Idempotently copy rows**:\n\n ```sql\n BEGIN;\n INSERT INTO product_skus (\n id, slug, context, created_at, updated_at,\n tenant_id, product_id, code, barcode, name,\n attributes, weight_grams, parent_sku_id, active\n )\n SELECT\n id, slug, context, created_at, updated_at,\n tenant_id, product_id, code, barcode, name,\n attributes, weight_grams, parent_sku_id, active\n FROM inventory_skus\n WHERE NOT EXISTS (\n SELECT 1 FROM product_skus p WHERE p.id = inventory_skus.id\n );\n COMMIT;\n ```\n\n3. **Drop the legacy table** once row counts match:\n\n ```sql\n DROP TABLE IF EXISTS inventory_skus;\n ```\n\n### `ProductVariant` changed shape entirely\n\nPreviously a Product STI subtype carrying `parentProductId` + `axisValues` JSON inside `_meta_data` on the shared `products` table (`_meta_type='@happyvertical/smrt-products:ProductVariant'`). It is now a **standalone model** on its own `product_variants` table, with columns `productId`, `axisName`, `allowedValues`, `label`, `sortOrder`.\n\n**There is no automatic data conversion.** The old \"catalog grouping above SKU\" concept doesn't map 1:1 to the new \"per-axis declaration\" concept. Recommended procedure:\n\n1. Inspect the old rows: `SELECT * FROM products WHERE _meta_type = '@happyvertical/smrt-products:ProductVariant';`. Treat them as historical reference.\n2. Re-author axis declarations against the new shape (one `ProductVariant` row per `(productId, axisName)` pair, with `allowedValues` listing the values).\n3. Once the new declarations are populated and verified, remove the legacy rows: `DELETE FROM products WHERE _meta_type = '@happyvertical/smrt-products:ProductVariant';`.\n\nIf you had per-colorway / per-variant images attached via `ProductAsset` rows pointing at old ProductVariant ids, repoint those to the parent Product id; group-by-axis-value queries on `Sku.attributes` cover the same use case at the SKU level.\n\n## Gotchas\n\n- **`ProductVariant` and `Sku` are NOT Product STI subtypes** — they each have their own table (`product_variants`, `product_skus`) because their shapes don't fit the Product schema. Don't try to query them via `ProductCollection`.\n- **`npm run build` emits the published library surface directly**: package consumers read model, collection, and helper exports from `dist/lib`. Cross-package imports from this package should target `/models` or `/collections` subpaths (not the main entry) when the consumer isn't a vite app — the main entry pulls in vite virtual modules.\n- **Use `npm run build:all` only when you need standalone or federation bundles** in addition to the library output\n- **Constructor must explicitly assign all properties**: `Object.assign` doesn't work reliably with decorators\n- **STI subtype-specific fields use `Meta<T>`** — declare them as `fieldName: Meta<FieldType> = defaultValue`. The AST scanner detects the `Meta<T>` type wrapper at build time and routes the field through `_meta_data` JSON storage instead of materializing it as a column on the parent's table. Do **NOT** use the runtime `@meta()` decorator on STI children — it never reaches the manifest, so the schema generator treats the field as an ordinary column on the parent table and the framework's hydration path can't tell it's meta. Override `productType` on each subclass.\n- **Tenant-scoped STI children must repeat `@TenantScoped`** — `@TenantScoped` registers per concrete className, so `Material extends Product` inheriting from a tenant-scoped `Product` is NOT automatically tenant-scoped itself. `MaterialCollection.list/save` passes `'Material'` to the tenant interceptor, which looks up `'Material'` (not `'Product'`) in the per-class registry. Without an explicit `@TenantScoped({ mode: 'optional' })` on `Material`, material rows skip the tenant auto-filter and auto-populate.\n- **STI children must repeat `@smrt({ api, mcp, cli })` generation config (S5 #1406)** — like `@TenantScoped`, the generation config is registered per concrete className and is NOT inherited from the STI parent. An empty `@smrt()` on a child resolves `getConfig(child).api/.mcp` to `undefined`, which the REST and MCP generators treat as \"expose EVERYTHING\" — including `delete` and write-capable MCP tools — even when the parent deliberately restricts its surface. The package's `mcp.ts` generator enumerates the whole registry, so an under-configured child ships a wide-open surface silently. Re-declare the parent's `api`/`mcp`/`cli` posture on every subtype (see `Material`). Consumer subtypes (apparel `Style`/`Makeup`, automotive `Model`/`Trim`, …) must do the same.\n- **Two tenants can share a slug on `Product`/`Category` (smrt#2360)** — a tenant-scoped STI base keys on `(tenant_id, slug, context, _meta_type)` by default, on the schema index and the runtime upsert alike, so no per-tenant slug namespacing and no `conflictColumns` override is needed. Global rows (`tenantId = null`) still dedup among themselves through the SDK's null-aware upsert. Existing databases pick the new key up through `smrt db:migrate` (same-name index swap) — deploy the code and the migration together, since neither version's create binds against the other's index.\n- **`price` is integer minor units** (cents, satoshis) — `$19.99` is `1999`. Money is exact, so `price` initializes `= 0`; writing `19.99` is the bug, and PostgreSQL rejects it with `22P02` while SQLite's affinity stores it and hides it from this package's SQLite suites. `pnpm --filter @happyvertical/smrt-products test:postgres` is the lane that holds the line (#2361). Because `Product` is the STI base, the column is shared by every consumer subtype. `Material.costPerUnit` is a `Meta<number>` in `_meta_data` rather than a column, so it is outside this rule.\n- **Module Federation marked experimental**: may change\n"
2778
2790
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@happyvertical/smrt-products",
3
- "version": "0.40.69",
3
+ "version": "0.41.0",
4
4
  "description": "SMRT products module: triple-purpose microservice template for standalone apps, federated modules, and NPM libraries",
5
5
  "author": "HappyVertical",
6
6
  "type": "module",
@@ -60,13 +60,13 @@
60
60
  "@happyvertical/utils": "^0.88.0",
61
61
  "cors": "^2.8.6",
62
62
  "express": "^5.2.1",
63
- "@happyvertical/smrt-core": "0.40.69",
64
- "@happyvertical/smrt-scanner": "0.40.69",
65
- "@happyvertical/smrt-svelte": "0.40.69",
66
- "@happyvertical/smrt-assets": "0.40.69",
67
- "@happyvertical/smrt-tenancy": "0.40.69",
68
- "@happyvertical/smrt-ui": "0.40.69",
69
- "@happyvertical/smrt-web": "0.40.69"
63
+ "@happyvertical/smrt-assets": "0.41.0",
64
+ "@happyvertical/smrt-core": "0.41.0",
65
+ "@happyvertical/smrt-scanner": "0.41.0",
66
+ "@happyvertical/smrt-svelte": "0.41.0",
67
+ "@happyvertical/smrt-tenancy": "0.41.0",
68
+ "@happyvertical/smrt-ui": "0.41.0",
69
+ "@happyvertical/smrt-web": "0.41.0"
70
70
  },
71
71
  "peerDependencies": {
72
72
  "svelte": "^5.56.4"
@@ -89,7 +89,7 @@
89
89
  "typescript": "5.9.3",
90
90
  "vite": "8.1.4",
91
91
  "vitest": "4.1.10",
92
- "@happyvertical/smrt-vitest": "0.40.69"
92
+ "@happyvertical/smrt-vitest": "0.41.0"
93
93
  },
94
94
  "keywords": [
95
95
  "smrt",
@@ -128,6 +128,7 @@
128
128
  "start:federation": "node dist/federation/main.js",
129
129
  "preview": "vite preview",
130
130
  "test": "vitest run",
131
+ "test:postgres": "node ../../scripts/run-with-ci-postgres.mjs -- pnpm exec vitest run src/price-field.postgres.test.ts",
131
132
  "test:watch": "vitest",
132
133
  "test:code-split": "node scripts/check-web-engine-code-split.mjs",
133
134
  "verify:pack": "node ../../scripts/verify-package-types-exports.js .",
@@ -1 +0,0 @@
1
- {"version":3,"file":"Sku-C181XteX.js","names":[],"sources":["../../../src/lib/models/Category.ts","../../../src/lib/models/types.ts","../../../src/lib/models/Product.ts","../../../src/lib/models/Material.ts","../../../src/lib/models/ProductAsset.ts","../../../src/lib/models/ProductVariant.ts","../../../src/lib/models/Sku.ts"],"sourcesContent":["/**\n * Product knowledge base category model\n *\n * SMRT auto-generates REST APIs, MCP tools, and TypeScript clients from this class.\n */\n\nimport {\n foreignKey,\n SmrtObject,\n type SmrtObjectOptions,\n smrt,\n} from '@happyvertical/smrt-core';\nimport { TenantScoped, tenantId } from '@happyvertical/smrt-tenancy';\n\n/**\n * Options for Category initialization\n */\nexport interface CategoryOptions extends SmrtObjectOptions {\n tenantId?: string | null;\n name?: string;\n description?: string;\n parentId?: string;\n level?: number;\n productCount?: number;\n active?: boolean;\n}\n\n/**\n * Product knowledge base category for organizing product information.\n *\n * Optional tenancy — categories may be shared globally (tenantId=null) or\n * scoped to a tenant. Hierarchical via parentId.\n */\n@TenantScoped({ mode: 'optional' })\n@smrt({\n tableStrategy: 'sti',\n // See the matching note on `Product` — overriding `conflictColumns`\n // to include `tenant_id` causes a SQLite `ON CONFLICT clause does not\n // match any … UNIQUE constraint` error because the core schema\n // generator's hardcoded STI unique index is `(slug, context,\n // _meta_type)` and does not include the tenant column. Until the\n // upstream framework fix lands, two tenants cannot share a category\n // slug at the schema level.\n api: {\n include: ['list', 'get', 'create', 'update'], // Standard CRUD except delete\n },\n mcp: {\n include: ['list', 'get'], // AI tools for category discovery\n },\n cli: true, // Enable CLI commands for admin\n})\nexport class Category extends SmrtObject {\n /**\n * Tenant ID for multi-tenant isolation.\n * Nullable to support both tenant-scoped and global categories.\n */\n @tenantId({ nullable: true })\n tenantId: string | null = null;\n\n name = '';\n description = '';\n @foreignKey('Category')\n parentId?: string; // For hierarchical categories\n level = 0; // Category depth in hierarchy\n productCount = 0; // Number of products in this category\n active = true;\n\n constructor(options: CategoryOptions = {}) {\n super(options);\n if (options.tenantId !== undefined) this.tenantId = options.tenantId;\n this.name = options.name || '';\n this.description = options.description || '';\n this.parentId = options.parentId;\n this.level = options.level || 0;\n this.productCount = options.productCount || 0;\n this.active = options.active !== undefined ? options.active : true;\n }\n}\n","/**\n * Shared types for the products package.\n *\n * @packageDocumentation\n */\n\n/**\n * Discriminator for Product STI subtypes.\n *\n * Industry-vertical templates extend `Product` with their own STI subtypes\n * (apparel uses `Style`/`Makeup`; furniture might use `Design`/`Finish`;\n * automotive `Model`/`Trim`) — the upstream package only ships the truly\n * generic primitives:\n *\n * - {@link ProductType.PRODUCT} — plain catalog item (base)\n * - {@link ProductType.MATERIAL} — raw input consumed by manufacturing\n *\n * The axis-declaration concept (\"this product varies along `size` with\n * values `[XS, S, M, L, XL]`\") is NOT a Product STI subtype — it lives in\n * its own model, {@link ProductVariant}, with a separate table. Per-SKU\n * value pins live on `Sku.attributes` (also in this package — `Sku` was\n * relocated from `@happyvertical/smrt-inventory` to here in Phase 1 so\n * every catalog primitive lives under one roof; inventory only holds\n * stock levels and movements now).\n */\nexport enum ProductType {\n /** Generic catalog item (default). */\n PRODUCT = 'product',\n /** A raw input — fabric, trim, packaging, etc. — consumed by manufacturing. */\n MATERIAL = 'material',\n}\n\n/**\n * High-level classification of a {@link ProductType.MATERIAL} item.\n *\n * Open string so consumers can extend with vertical-specific kinds without\n * an enum change. The `(string & {})` branch preserves the literal-string\n * autocomplete suggestions in IDEs — a bare `| string` would collapse the\n * whole union to `string` and erase the named hints (same pattern as\n * `StockMovementReason` in `@happyvertical/smrt-inventory`).\n */\nexport type MaterialKind =\n | 'fabric'\n | 'trim'\n | 'thread'\n | 'label'\n | 'packaging'\n | 'component'\n | (string & {});\n","/**\n * Product knowledge base model\n *\n * SMRT auto-generates REST APIs, MCP tools, and TypeScript clients from this class.\n */\n\nimport type { Asset } from '@happyvertical/smrt-assets';\nimport {\n assertValidOwnedAssetRelationship,\n assertValidOwnedAssetSortOrder,\n resolveOwnedAssetsById,\n} from '@happyvertical/smrt-assets';\nimport {\n SmrtObject,\n type SmrtObjectOptions,\n smrt,\n} from '@happyvertical/smrt-core';\nimport {\n getCurrentTenant,\n TenantScoped,\n tenantId,\n} from '@happyvertical/smrt-tenancy';\nimport { ProductType } from './types';\n\n/**\n * Options for Product initialization\n */\nexport interface ProductOptions extends SmrtObjectOptions {\n tenantId?: string | null;\n productType?: ProductType;\n name?: string;\n description?: string;\n category?: string;\n manufacturer?: string;\n model?: string;\n price?: number;\n inStock?: boolean;\n specifications?: Record<string, unknown>;\n tags?: string[];\n}\n\n/**\n * Product information for knowledge base queries.\n *\n * STI base — subclasses (e.g. `Material` upstream, `Style`/`Makeup` in the\n * apparel template) share this table via the `_meta_type` discriminator\n * and `productType` field. Optional tenancy lets the same package serve\n * shared global catalogs OR per-merchant catalogs.\n */\n@TenantScoped({ mode: 'optional' })\n@smrt({\n tableStrategy: 'sti',\n // KNOWN LIMITATION (tracked for framework follow-up): the core schema\n // generator hardcodes the STI unique index as\n // `(slug, context, _meta_type)` and does not include `tenant_id`\n // even when the class is `@TenantScoped`. As a result two tenants\n // cannot save a row with the same slug+context+type — the UNIQUE\n // constraint at the SQL layer rejects the second insert.\n //\n // We deliberately do NOT override `conflictColumns` here to add\n // `tenant_id`: doing so would put the runtime upsert path\n // (`ON CONFLICT ('slug','context','_meta_type','tenant_id')`) out of\n // step with the actual unique index, producing `SQLITE_ERROR: ON\n // CONFLICT clause does not match any … UNIQUE constraint` on every\n // save. Production callers should either (a) namespace their slugs\n // per tenant on the application side (e.g. `${tenantId}-widget`), or\n // (b) wait for the upstream framework fix that extends the STI\n // unique index with `tenant_id` for tenant-scoped tables.\n api: {\n include: ['list', 'get', 'create', 'update'], // Standard CRUD except delete\n },\n mcp: {\n include: ['list', 'get'], // AI tools for product discovery\n },\n cli: true, // Enable CLI commands for admin\n})\nexport class Product extends SmrtObject {\n /**\n * Tenant ID for multi-tenant isolation.\n * Nullable to support both tenant-scoped and global catalogs.\n */\n @tenantId({ nullable: true })\n tenantId: string | null = null;\n\n /**\n * STI discriminator. Subclasses override this with their type.\n */\n productType: ProductType = ProductType.PRODUCT;\n\n name = '';\n description = '';\n category = ''; // Reference to category\n manufacturer = '';\n model = '';\n price = 0;\n inStock = true;\n specifications: Record<string, unknown> = {};\n tags: string[] = [];\n\n constructor(options: ProductOptions = {}) {\n super(options);\n if (options.tenantId !== undefined) this.tenantId = options.tenantId;\n // Treat `null` like `undefined`: existing product rows written\n // before the `product_type` column existed hydrate with the field\n // as SQL `NULL`, and without this guard the SmrtObject loader would\n // overwrite the `ProductType.PRODUCT` initializer with `null`. The\n // STI discriminator `_meta_type` still identifies the row's\n // subtype; `productType` is the secondary human-readable label and\n // should fall back to the base default for legacy rows.\n if (options.productType !== undefined && options.productType !== null) {\n this.productType = options.productType;\n }\n this.name = options.name || '';\n this.description = options.description || '';\n this.category = options.category || '';\n this.manufacturer = options.manufacturer || '';\n this.model = options.model || '';\n this.price = options.price || 0;\n this.inStock = options.inStock !== undefined ? options.inStock : true;\n this.specifications = options.specifications || {};\n this.tags = options.tags || [];\n }\n\n async getSpecification(key: string): Promise<unknown> {\n return this.specifications[key];\n }\n\n async updateSpecification(key: string, value: unknown): Promise<void> {\n this.specifications[key] = value;\n }\n\n private async getProductAssetCollection() {\n const { ProductAssetCollection } = await import(\n '../collections/ProductAssetCollection'\n );\n return ProductAssetCollection.create({ db: this.db });\n }\n async getAssets(relationship?: string): Promise<Asset[]> {\n if (!this.id) {\n return [];\n }\n\n const productAssets = await this.getProductAssetCollection();\n // Don't pass `this.tenantId` here. ProductAsset is @TenantScoped, so the\n // tenancy interceptor auto-filters the underlying list() by the active\n // context. Passing `this.tenantId` would apply a second explicit filter on\n // TOP of the interceptor's — and when this Product is a global/shared row\n // (`tenantId === null`), that second filter would drop every per-tenant\n // link to it. The interceptor is the right boundary: in a tenant scope it\n // returns that tenant's links; outside any scope it returns everything. See\n // the `ProductAsset` model comment about cross-tenant linking.\n const linkedAssets = await productAssets.byLeft(\n this.id,\n relationship ? { relationship } : {},\n );\n\n // Use the ACTIVE tenant context's tenantId, not `this.tenantId`,\n // when resolving the underlying assets. `resolveOwnedAssetsById`\n // treats its `tenantId` arg as the caller's identity: when set, it\n // enters `withSystemContext` to bypass the interceptor and then\n // includes both that-tenant-owned AND global (tenantId === null)\n // assets in the visible set. Passing `this.tenantId` would force\n // a global Product (`tenantId === null`) running inside a tenant\n // request into the \"no caller tenant\" branch — the interceptor\n // would then filter to only the tenant's own assets and drop\n // every global asset linked to the shared product. Reading the\n // active context fixes both directions: tenant requests see\n // tenant + global assets; system requests see everything.\n const ctxTenantId = getCurrentTenant()?.tenantId ?? null;\n return resolveOwnedAssetsById(\n this.db,\n linkedAssets.map((link) => link.assetId),\n ctxTenantId,\n );\n }\n\n async addAsset(\n asset: Asset,\n relationship = 'attachment',\n sortOrder = 0,\n ): Promise<void> {\n if (!this.id || !asset.id) {\n throw new Error('Cannot associate unsaved product or asset');\n }\n\n assertValidOwnedAssetRelationship(relationship);\n assertValidOwnedAssetSortOrder(sortOrder);\n\n const productAssets = await this.getProductAssetCollection();\n // Same rationale as `getAssets` — the interceptor's auto-populate sets the\n // new row's `tenantId` from the active context, so we don't hard-wire\n // `this.tenantId`. When this Product is global (`tenantId === null`) but a\n // tenant is linking it, the link should land under that tenant, not under\n // the global namespace.\n await productAssets.attach(this.id, asset.id, {\n relationship,\n sortOrder,\n });\n }\n\n async removeAsset(assetId: string, relationship?: string): Promise<void> {\n if (!this.id) {\n return;\n }\n\n const productAssets = await this.getProductAssetCollection();\n // Tenant-scoped delete: pass only the relationship filter and let the\n // interceptor scope the underlying list() to the active tenant, rather\n // than constraining to `this.tenantId` (which on a global product would\n // never match a tenant-owned link). System-style callers without a tenant\n // context sweep every matching row — the existing `detach` semantics.\n await productAssets.detach(\n this.id,\n assetId,\n relationship ? { relationship } : {},\n );\n }\n}\n","/**\n * Material — STI subtype of Product representing a raw input consumed by\n * manufacturing: fabric, thread, trim, labels, packaging, components.\n *\n * Materials are first-class products in the catalog (the SAP/NetSuite pattern):\n * they have a name, description, vendor, unit cost, and live in inventory just\n * like finished goods. Bills of materials in `@happyvertical/smrt-manufacturing`\n * reference Materials by id.\n *\n * @packageDocumentation\n */\n\nimport { type Meta, smrt } from '@happyvertical/smrt-core';\nimport { TenantScoped } from '@happyvertical/smrt-tenancy';\nimport { Product, type ProductOptions } from './Product';\nimport { type MaterialKind, ProductType } from './types';\n\nexport interface MaterialOptions extends ProductOptions {\n materialKind?: MaterialKind;\n uom?: string;\n costPerUnit?: number;\n}\n\n// @TenantScoped is registered per concrete class, so inheriting from\n// Product is NOT enough — `MaterialCollection.list()` passes 'Material'\n// (not 'Product') to the interceptor, which then fails its\n// `isTenantScopedClass(className)` lookup and skips tenant auto-filter\n// + auto-populate. Repeat the decorator here so material rows\n// participate in the same tenant isolation as their Product parent.\n@TenantScoped({ mode: 'optional' })\n// SECURITY (S5 #1406): @smrt() generation config is ALSO registered per\n// concrete class and is NOT inherited from the STI parent. An empty\n// `@smrt()` here would resolve `getConfig('Material').api/.mcp` to\n// `undefined`, which the REST + MCP generators treat as \"expose\n// EVERYTHING\" — including `delete`, `create`, and `update` MCP tools —\n// even though the `Product` base deliberately restricts itself to CRUD\n// (no delete) over REST and read-only (`list`/`get`) over MCP. The\n// products `mcp.ts` generator enumerates the whole registry, so a\n// silently-wide-open Material surface ships the moment the package's own\n// server is generated. Re-declare the parent's restricted posture so the\n// STI child matches its base — and so consumers copying this canonical\n// subtype example (apparel `Style`/`Makeup`, automotive `Model`/`Trim`,\n// …) inherit the secure pattern instead of an accidental open surface.\n@smrt({\n api: {\n include: ['list', 'get', 'create', 'update'], // no delete, matches Product\n },\n mcp: {\n include: ['list', 'get'], // read-only AI tools, matches Product\n },\n cli: true,\n})\nexport class Material extends Product {\n override productType: ProductType = ProductType.MATERIAL;\n\n // STI child-specific fields use the `Meta<T>` type wrapper rather than\n // the runtime `@meta()` decorator. The scanner detects the wrapper at\n // build time (via the type annotation) and emits the field with\n // `type: 'meta'` in the manifest, which routes it through `_meta_data`\n // JSON storage at schema-generation time. The runtime decorator path\n // doesn't reach the manifest, so STI children that only use `@meta()`\n // get materialized as ordinary columns on the parent's table.\n\n /** Classification — fabric, trim, thread, label, packaging, component, ... */\n materialKind: Meta<MaterialKind> = 'component';\n\n /** Unit of measure — \"yards\", \"meters\", \"each\", \"grams\", \"lbs\". */\n uom: Meta<string> = 'each';\n\n /**\n * Latest known cost per UOM. For sophisticated cost rollup, manufacturing\n * may pull from purchase-order history instead of this denormalised value.\n */\n costPerUnit: Meta<number> = 0.0;\n\n constructor(options: MaterialOptions = {}) {\n super(options);\n if (options.materialKind !== undefined)\n this.materialKind = options.materialKind;\n if (options.uom !== undefined) this.uom = options.uom;\n if (options.costPerUnit !== undefined)\n this.costPerUnit = options.costPerUnit;\n }\n}\n","import type { SmrtObjectOptions } from '@happyvertical/smrt-core';\nimport {\n crossPackageRef,\n field,\n foreignKey,\n SmrtObject,\n smrt,\n} from '@happyvertical/smrt-core';\nimport { TenantScoped, tenantId } from '@happyvertical/smrt-tenancy';\n\nexport interface ProductAssetOptions extends SmrtObjectOptions {\n tenantId?: string | null;\n productId?: string;\n assetId?: string;\n relationship?: string;\n sortOrder?: number;\n}\n\n@TenantScoped({ mode: 'optional' })\n@smrt({\n tableName: 'product_assets',\n // tenant_id is included so two tenants can independently link the same\n // shared product/asset under the same relationship without their rows\n // colliding (or worse, one tenant silently overwriting another's link\n // via UPSERT).\n conflictColumns: ['product_id', 'asset_id', 'relationship', 'tenant_id'],\n api: false,\n mcp: false,\n cli: false,\n})\nexport class ProductAsset extends SmrtObject {\n @tenantId({ nullable: true })\n tenantId: string | null = null;\n\n @foreignKey('Product', { required: true })\n productId = '';\n\n @crossPackageRef('@happyvertical/smrt-assets:Asset', { required: true })\n assetId = '';\n\n @field({ required: true })\n relationship = 'attachment';\n\n @field()\n sortOrder = 0;\n\n constructor(options: ProductAssetOptions = {}) {\n super(options);\n if (options.tenantId !== undefined) this.tenantId = options.tenantId;\n if (options.productId) this.productId = options.productId;\n if (options.assetId) this.assetId = options.assetId;\n if (options.relationship) this.relationship = options.relationship;\n if (options.sortOrder !== undefined) this.sortOrder = options.sortOrder;\n }\n}\n","/**\n * ProductVariant — declarative description of one axis along which a\n * product's SKUs differ.\n *\n * A `ProductVariant` row says \"for product X, axis Y has the following\n * allowed values\". The actual per-SKU value lives on `Sku.attributes`\n * (also in this package — `Sku` was relocated to `@happyvertical/smrt-products`\n * in Phase 1; inventory only holds stock motion now), keyed by `axisName`.\n * This split keeps the axis catalog (form choices, UI grouping, ordering)\n * separate from the per-unit instances.\n *\n * Deliberately generic. `axisName` is free-form — apparel teams might\n * use `'size'` and `'color'`, automotive teams `'trim'` and `'engine'`,\n * CPG teams `'packSize'` and `'flavor'`. The framework never inspects\n * the axis name.\n *\n * NOT a Product STI subtype — it's its own model with its own table,\n * because the shape (axis declaration) doesn't fit the Product schema\n * (no name, no price, no category — it's metadata about a Product, not\n * a Product itself).\n *\n * @packageDocumentation\n */\n\nimport {\n field,\n SmrtObject,\n type SmrtObjectOptions,\n smrt,\n} from '@happyvertical/smrt-core';\nimport { TenantScoped, tenantId } from '@happyvertical/smrt-tenancy';\n\n/**\n * Options accepted by the {@link ProductVariant} constructor.\n */\nexport interface ProductVariantOptions extends SmrtObjectOptions {\n tenantId?: string | null;\n productId?: string;\n axisName?: string;\n label?: string;\n allowedValues?: string[] | string;\n sortOrder?: number;\n}\n\n@TenantScoped({ mode: 'optional' })\n@smrt({\n tableName: 'product_variants',\n conflictColumns: ['product_id', 'axis_name', 'tenant_id'],\n api: { include: ['list', 'get', 'create', 'update'] },\n mcp: { include: ['list', 'get'] },\n cli: true,\n})\nexport class ProductVariant extends SmrtObject {\n /** Tenant scope. `null` means the variant axis is global. */\n @tenantId({ nullable: true })\n tenantId: string | null = null;\n\n /**\n * Plain string reference to the {@link Product} this axis belongs to\n * (or any Product STI subtype — `Material`, or vertical subtypes\n * defined in templates such as the apparel `Style` / `Makeup`).\n */\n @field({ required: true })\n productId: string = '';\n\n /**\n * The name of the axis (`'size'`, `'color'`, `'finish'`, `'voltage'`,\n * `'packSize'`, …). Free-form — the framework treats this as opaque.\n */\n @field({ required: true })\n axisName: string = '';\n\n /** Optional human-friendly label for forms / UIs (defaults to `axisName`). */\n label: string = '';\n\n /**\n * Allowed values for this axis, stored as a JSON string. Named\n * `allowedValues` (rather than `values`) because the unprefixed name\n * collides with the SQL `VALUES` keyword on several engines. Use\n * {@link getValues} / {@link setValues} to round-trip the array form.\n */\n allowedValues: string = '[]';\n\n /** Sort order for displaying multiple axes in a consistent column order. */\n sortOrder: number = 0;\n\n constructor(options: ProductVariantOptions = {}) {\n super(options);\n if (options.tenantId !== undefined) this.tenantId = options.tenantId;\n if (options.productId !== undefined) this.productId = options.productId;\n if (options.axisName !== undefined) this.axisName = options.axisName;\n if (options.label !== undefined) this.label = options.label;\n if (options.allowedValues !== undefined)\n this.setValues(options.allowedValues);\n if (options.sortOrder !== undefined) this.sortOrder = options.sortOrder;\n\n // Default the label to axisName when no explicit label was supplied.\n // The field docstring promises this behavior and admin UIs render\n // `variant.label` directly; without this fallback an axis declared\n // as `{ axisName: 'size' }` would render with a blank label.\n if (!this.label && this.axisName) {\n this.label = this.axisName;\n }\n }\n\n /**\n * Parse and return the {@link allowedValues} JSON array. Returns an\n * empty array if the stored value cannot be parsed as an array.\n */\n getValues(): string[] {\n if (!this.allowedValues) return [];\n try {\n const parsed = JSON.parse(this.allowedValues);\n return Array.isArray(parsed) ? parsed.map((value) => String(value)) : [];\n } catch {\n return [];\n }\n }\n\n /**\n * Serialize the allowed values back into the stored\n * {@link allowedValues} string. Accepts either an array or a\n * pre-serialized JSON string.\n */\n setValues(value: string[] | string): void {\n if (typeof value === 'string') {\n this.allowedValues = value;\n return;\n }\n this.allowedValues = JSON.stringify(Array.isArray(value) ? value : []);\n }\n}\n","/**\n * Sku — smallest sellable and countable unit.\n *\n * A SKU is the concrete catalog row that downstream inventory counts.\n * It references a higher-level concept in this same package (a\n * {@link Product} or any of its STI subtypes) via the plain string\n * `productId` field. The same pattern serves apparel (one SKU per\n * size/color), furniture (one SKU per finish), automotive parts,\n * grocery (one SKU per pack size), or any other vertical that needs\n * to count discrete units.\n *\n * Axis values such as `{ size: 'M', color: 'navy' }`, `{ finish: 'walnut' }`,\n * or `{ packSize: '12oz' }` are stored as opaque JSON in `attributes`;\n * the declarative axis catalog lives in {@link ProductVariant} in this\n * same package.\n *\n * Stock balance and movement history for a SKU live in\n * `@happyvertical/smrt-inventory` as `StockLevel` and `StockMovement`.\n *\n * @packageDocumentation\n */\n\nimport {\n field,\n SmrtObject,\n type SmrtObjectOptions,\n smrt,\n} from '@happyvertical/smrt-core';\nimport { TenantScoped, tenantId } from '@happyvertical/smrt-tenancy';\n\n/**\n * Options accepted by the {@link Sku} constructor.\n */\nexport interface SkuOptions extends SmrtObjectOptions {\n tenantId?: string | null;\n productId?: string;\n code?: string;\n barcode?: string;\n name?: string;\n attributes?: Record<string, unknown> | string;\n weightGrams?: number;\n parentSkuId?: string;\n active?: boolean;\n}\n\n@TenantScoped({ mode: 'optional' })\n@smrt({\n tableName: 'product_skus',\n conflictColumns: ['code', 'tenant_id'],\n api: { include: ['list', 'get', 'create', 'update'] },\n mcp: { include: ['list', 'get'] },\n cli: true,\n})\nexport class Sku extends SmrtObject {\n /** Tenant scope. `null` means the SKU is a global record. */\n @tenantId({ nullable: true })\n tenantId: string | null = null;\n\n /**\n * Plain string reference to a row in this package — typically a\n * `Product` id (or any of its STI subtypes, such as `Material`\n * upstream or `Style` / `Makeup` in the apparel template).\n *\n * Marked required so the framework rejects a save with `productId`\n * empty or unset. Without this, downstream consumers (inventory\n * stock motion, manufacturing BOM resolution) would have to filter\n * out orphan SKU rows that point at no product — a sharp footgun\n * the moment one slips through. The `@field({ required: true })`\n * decorator also surfaces the constraint in generated REST/MCP\n * schemas.\n */\n @field({ required: true })\n productId: string = '';\n\n /**\n * Stable, human-meaningful identifier such as a UPC, internal SKU\n * code, or part number. Together with `tenantId` this is the natural\n * key (`conflictColumns: ['code', 'tenant_id']`), so re-saving an\n * identical row is an upsert rather than a UNIQUE violation.\n */\n @field({ required: true })\n code: string = '';\n\n /** Optional scannable barcode (EAN/UPC/Code-128/etc.). */\n barcode: string = '';\n\n /** Display name for UIs. Optional — `code` is enough for machines. */\n name: string = '';\n\n /**\n * Axis values for this SKU expressed as JSON, e.g. `{ size: 'M' }`,\n * `{ finish: 'walnut' }`, or `{ voltage: '230V' }`.\n *\n * The persisted column type is text; use {@link getAttributes} and\n * {@link setAttributes} to round-trip parsed values without worrying\n * about parse errors.\n */\n attributes: string = '{}';\n\n /** Optional physical weight in grams for shipping / cost calculations. */\n @field({ type: 'decimal' })\n weightGrams: number = 0.0;\n\n /**\n * Optional self-reference for bundles / kits — set to the id of the\n * \"parent\" SKU that this SKU is a component of.\n */\n parentSkuId: string = '';\n\n /**\n * Soft-active flag. Inactive SKUs stay queryable for history but\n * should not be offered for sale or production planning.\n */\n active: boolean = true;\n\n constructor(options: SkuOptions = {}) {\n super(options);\n if (options.tenantId !== undefined) this.tenantId = options.tenantId;\n if (options.productId !== undefined) this.productId = options.productId;\n if (options.code !== undefined) this.code = options.code;\n if (options.barcode !== undefined) this.barcode = options.barcode;\n if (options.name !== undefined) this.name = options.name;\n if (options.attributes !== undefined)\n this.setAttributes(options.attributes);\n if (options.weightGrams !== undefined)\n this.weightGrams = options.weightGrams;\n if (options.parentSkuId !== undefined)\n this.parentSkuId = options.parentSkuId;\n if (options.active !== undefined) this.active = options.active;\n }\n\n /**\n * Parse and return the {@link attributes} JSON. Returns an empty\n * object if the stored value is invalid JSON so callers don't have\n * to wrap every read in a try/catch.\n */\n getAttributes(): Record<string, unknown> {\n if (!this.attributes) return {};\n try {\n const parsed = JSON.parse(this.attributes);\n return parsed && typeof parsed === 'object' && !Array.isArray(parsed)\n ? (parsed as Record<string, unknown>)\n : {};\n } catch {\n return {};\n }\n }\n\n /**\n * Serialize axis values back into the stored {@link attributes}\n * string. Accepts either an object (will be `JSON.stringify`'d) or a\n * raw JSON string that the caller has already serialized.\n */\n setAttributes(value: Record<string, unknown> | string): void {\n if (typeof value === 'string') {\n this.attributes = value;\n return;\n }\n this.attributes = JSON.stringify(value ?? {});\n }\n}\n"],"mappings":";;;;;;;;;;AAmDO,IAAA,WAAA,MAAM,iBAAiB,WAAW;;;;;CAKvC,WAC0B;CAE1B,OAAO;CACP,cAAc;CACd;CAEA,QAAQ;CACR,eAAe;CACf,SAAS;CAET,YAAY,UAA2B,CAAC,GAAG;EACzC,MAAM,OAAO;EACb,IAAI,QAAQ,aAAa,KAAA,GAAW,KAAK,WAAW,QAAQ;EAC5D,KAAK,OAAO,QAAQ,QAAQ;EAC5B,KAAK,cAAc,QAAQ,eAAe;EAC1C,KAAK,WAAW,QAAQ;EACxB,KAAK,QAAQ,QAAQ,SAAS;EAC9B,KAAK,eAAe,QAAQ,gBAAgB;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