@happyvertical/smrt-products 0.37.2 ā 0.37.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/lib/chunks/ProductAssetCollection-TbeaVxzc.js +38 -0
- package/dist/lib/chunks/ProductAssetCollection-TbeaVxzc.js.map +1 -0
- package/dist/lib/chunks/ProductCollection-8QlfZ9ez.js +28 -0
- package/dist/lib/chunks/ProductCollection-8QlfZ9ez.js.map +1 -0
- package/dist/lib/chunks/Sku-B0w2dfHb.js +467 -0
- package/dist/lib/chunks/Sku-B0w2dfHb.js.map +1 -0
- package/dist/lib/chunks/__smrt-register__-DAo7IPPx.js +22 -0
- package/dist/lib/chunks/__smrt-register__-DAo7IPPx.js.map +1 -0
- package/dist/lib/chunks/collections-6PSqhUmZ.js +162 -0
- package/dist/lib/chunks/collections-6PSqhUmZ.js.map +1 -0
- package/dist/lib/chunks/components-C6VpNVcg.js +398 -0
- package/dist/lib/chunks/components-C6VpNVcg.js.map +1 -0
- package/dist/lib/chunks/decorate-C25O10I-.js +9 -0
- package/dist/lib/chunks/generated-CM3rwUcw.js +7 -0
- package/dist/lib/chunks/generated-CM3rwUcw.js.map +1 -0
- package/dist/lib/chunks/models-JPB-sld2.js +2 -0
- package/dist/lib/chunks/rolldown-runtime-D7D4PA-g.js +13 -0
- package/dist/lib/chunks/stores-CB0SI1c5.js +119 -0
- package/dist/lib/chunks/stores-CB0SI1c5.js.map +1 -0
- package/dist/lib/chunks/utils-BgTqlQoH.js +30 -0
- package/dist/lib/chunks/utils-BgTqlQoH.js.map +1 -0
- package/dist/lib/collections.js +4 -12
- package/dist/lib/components.js +2 -6
- package/dist/lib/generated.js +2 -5
- package/dist/lib/index.js +191 -216
- package/dist/lib/index.js.map +1 -1
- package/dist/lib/lib/i18n.js +82 -91
- package/dist/lib/lib/i18n.js.map +1 -1
- package/dist/lib/lib/mock-smrt-client.js +116 -129
- package/dist/lib/lib/mock-smrt-client.js.map +1 -1
- package/dist/lib/lib/stores/product-store.svelte.d.ts.map +1 -1
- package/dist/lib/manifest.json +2 -2
- package/dist/lib/models.js +3 -12
- package/dist/lib/smrt-knowledge.json +14 -14
- package/dist/lib/smrt-products.css +1 -0
- package/dist/lib/stores.js +2 -6
- package/dist/lib/utils.js +2 -27
- package/package.json +23 -23
- package/dist/lib/chunks/ProductAssetCollection-B93HdSlX.js +0 -64
- package/dist/lib/chunks/ProductAssetCollection-B93HdSlX.js.map +0 -1
- package/dist/lib/chunks/ProductForm-CU0UvKEF.js +0 -430
- package/dist/lib/chunks/ProductForm-CU0UvKEF.js.map +0 -1
- package/dist/lib/chunks/Sku-sl6xf1PR.js +0 -494
- package/dist/lib/chunks/Sku-sl6xf1PR.js.map +0 -1
- package/dist/lib/chunks/SkuCollection-f_a3k93c.js +0 -160
- package/dist/lib/chunks/SkuCollection-f_a3k93c.js.map +0 -1
- package/dist/lib/chunks/__smrt-register__-BIgFaVKn.js +0 -5
- package/dist/lib/chunks/__smrt-register__-BIgFaVKn.js.map +0 -1
- package/dist/lib/chunks/index-i3-ci1FB.js +0 -6
- package/dist/lib/chunks/index-i3-ci1FB.js.map +0 -1
- package/dist/lib/chunks/product-store.svelte-Dayd5n3W.js +0 -132
- package/dist/lib/chunks/product-store.svelte-Dayd5n3W.js.map +0 -1
- package/dist/lib/collections.js.map +0 -1
- package/dist/lib/components.js.map +0 -1
- package/dist/lib/generated.js.map +0 -1
- package/dist/lib/models.js.map +0 -1
- package/dist/lib/stores.js.map +0 -1
- package/dist/lib/utils.js.map +0 -1
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import { createClient } from "../lib/mock-smrt-client.js";
|
|
2
|
+
import * as $ from "svelte/internal/client";
|
|
3
|
+
//#region src/lib/stores/product-store.svelte.ts
|
|
4
|
+
var ProductStoreClass = class {
|
|
5
|
+
#data = $.state($.proxy({
|
|
6
|
+
items: [],
|
|
7
|
+
loading: false,
|
|
8
|
+
error: null,
|
|
9
|
+
selectedProduct: null
|
|
10
|
+
}));
|
|
11
|
+
get data() {
|
|
12
|
+
return $.get(this.#data);
|
|
13
|
+
}
|
|
14
|
+
set data(value) {
|
|
15
|
+
$.set(this.#data, value, true);
|
|
16
|
+
}
|
|
17
|
+
api = createClient("/api/v1");
|
|
18
|
+
get items() {
|
|
19
|
+
return this.data.items;
|
|
20
|
+
}
|
|
21
|
+
get loading() {
|
|
22
|
+
return this.data.loading;
|
|
23
|
+
}
|
|
24
|
+
get error() {
|
|
25
|
+
return this.data.error;
|
|
26
|
+
}
|
|
27
|
+
get selectedProduct() {
|
|
28
|
+
return this.data.selectedProduct;
|
|
29
|
+
}
|
|
30
|
+
get inStockCount() {
|
|
31
|
+
return this.data.items.filter((p) => p.inStock).length;
|
|
32
|
+
}
|
|
33
|
+
get totalValue() {
|
|
34
|
+
return this.data.items.reduce((sum, product) => sum + (product.price || 0), 0);
|
|
35
|
+
}
|
|
36
|
+
get categories() {
|
|
37
|
+
const categorySet = new Set(this.data.items.map((p) => p.category).filter(Boolean));
|
|
38
|
+
return Array.from(categorySet);
|
|
39
|
+
}
|
|
40
|
+
async loadProducts() {
|
|
41
|
+
this.data.loading = true;
|
|
42
|
+
this.data.error = null;
|
|
43
|
+
try {
|
|
44
|
+
const response = await this.api.products.list();
|
|
45
|
+
if (response.data) this.data.items = response.data;
|
|
46
|
+
} catch (err) {
|
|
47
|
+
this.data.error = err instanceof Error ? err.message : "Failed to load products";
|
|
48
|
+
} finally {
|
|
49
|
+
this.data.loading = false;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
async createProduct(productData) {
|
|
53
|
+
this.data.loading = true;
|
|
54
|
+
this.data.error = null;
|
|
55
|
+
try {
|
|
56
|
+
const response = await this.api.products.create(productData);
|
|
57
|
+
if (response.data) this.data.items.push(response.data);
|
|
58
|
+
return response;
|
|
59
|
+
} catch (err) {
|
|
60
|
+
this.data.error = err instanceof Error ? err.message : "Failed to create product";
|
|
61
|
+
throw err;
|
|
62
|
+
} finally {
|
|
63
|
+
this.data.loading = false;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
async updateProduct(id, updates) {
|
|
67
|
+
this.data.loading = true;
|
|
68
|
+
this.data.error = null;
|
|
69
|
+
try {
|
|
70
|
+
const response = await this.api.products.update(id, updates);
|
|
71
|
+
if (response.data) {
|
|
72
|
+
const index = this.data.items.findIndex((p) => p.id === id);
|
|
73
|
+
if (index !== -1) this.data.items[index] = response.data;
|
|
74
|
+
if (this.data.selectedProduct?.id === id) this.data.selectedProduct = response.data;
|
|
75
|
+
}
|
|
76
|
+
return response;
|
|
77
|
+
} catch (err) {
|
|
78
|
+
this.data.error = err instanceof Error ? err.message : "Failed to update product";
|
|
79
|
+
throw err;
|
|
80
|
+
} finally {
|
|
81
|
+
this.data.loading = false;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
async deleteProduct(id) {
|
|
85
|
+
this.data.loading = true;
|
|
86
|
+
this.data.error = null;
|
|
87
|
+
try {
|
|
88
|
+
await this.api.products.delete(id);
|
|
89
|
+
this.data.items = this.data.items.filter((p) => p.id !== id);
|
|
90
|
+
if (this.data.selectedProduct?.id === id) this.data.selectedProduct = null;
|
|
91
|
+
} catch (err) {
|
|
92
|
+
this.data.error = err instanceof Error ? err.message : "Failed to delete product";
|
|
93
|
+
throw err;
|
|
94
|
+
} finally {
|
|
95
|
+
this.data.loading = false;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
selectProduct(product) {
|
|
99
|
+
this.data.selectedProduct = product;
|
|
100
|
+
}
|
|
101
|
+
clearError() {
|
|
102
|
+
this.data.error = null;
|
|
103
|
+
}
|
|
104
|
+
filterByCategory(category) {
|
|
105
|
+
return this.data.items.filter((p) => p.category === category);
|
|
106
|
+
}
|
|
107
|
+
filterInStock() {
|
|
108
|
+
return this.data.items.filter((p) => p.inStock);
|
|
109
|
+
}
|
|
110
|
+
searchProducts(query) {
|
|
111
|
+
const lowercaseQuery = query.toLowerCase();
|
|
112
|
+
return this.data.items.filter((product) => product.name?.toLowerCase().includes(lowercaseQuery) || product.description?.toLowerCase().includes(lowercaseQuery) || product.tags?.some((tag) => tag.toLowerCase().includes(lowercaseQuery)));
|
|
113
|
+
}
|
|
114
|
+
};
|
|
115
|
+
var productStore = new ProductStoreClass();
|
|
116
|
+
//#endregion
|
|
117
|
+
export { productStore as n, ProductStoreClass as t };
|
|
118
|
+
|
|
119
|
+
//# sourceMappingURL=stores-CB0SI1c5.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stores-CB0SI1c5.js","names":[],"sources":["../../../src/lib/stores/product-store.svelte.ts"],"sourcesContent":["/**\n * Product Store - Svelte 5 Runes State Management\n *\n * Reactive store for managing product state with SMRT auto-generated client.\n * Uses Svelte 5 runes for reactive state management.\n */\n\nimport { createClient, type ProductData } from '../mock-smrt-client';\n\ninterface ProductStore {\n items: ProductData[];\n loading: boolean;\n error: string | null;\n selectedProduct: ProductData | null;\n}\n\nexport class ProductStoreClass {\n private data = $state<ProductStore>({\n items: [],\n loading: false,\n error: null,\n selectedProduct: null,\n });\n\n private api = createClient('/api/v1');\n\n // Reactive getters\n get items() {\n return this.data.items;\n }\n get loading() {\n return this.data.loading;\n }\n get error() {\n return this.data.error;\n }\n get selectedProduct() {\n return this.data.selectedProduct;\n }\n\n // Derived state\n get inStockCount() {\n return this.data.items.filter((p) => p.inStock).length;\n }\n\n get totalValue() {\n return this.data.items.reduce(\n (sum, product) => sum + (product.price || 0),\n 0,\n );\n }\n\n get categories() {\n const categorySet = new Set(\n this.data.items.map((p) => p.category).filter(Boolean),\n );\n return Array.from(categorySet);\n }\n\n // Actions\n async loadProducts() {\n this.data.loading = true;\n this.data.error = null;\n\n try {\n const response = await this.api.products.list();\n if (response.data) {\n this.data.items = response.data;\n }\n } catch (err) {\n this.data.error =\n err instanceof Error ? err.message : 'Failed to load products';\n } finally {\n this.data.loading = false;\n }\n }\n\n async createProduct(productData: Partial<ProductData>) {\n this.data.loading = true;\n this.data.error = null;\n\n try {\n const response = await this.api.products.create(productData);\n if (response.data) {\n this.data.items.push(response.data);\n }\n return response;\n } catch (err) {\n this.data.error =\n err instanceof Error ? err.message : 'Failed to create product';\n throw err;\n } finally {\n this.data.loading = false;\n }\n }\n\n async updateProduct(id: string, updates: Partial<ProductData>) {\n this.data.loading = true;\n this.data.error = null;\n\n try {\n const response = await this.api.products.update(id, updates);\n if (response.data) {\n const index = this.data.items.findIndex((p) => p.id === id);\n if (index !== -1) {\n this.data.items[index] = response.data;\n }\n\n // Update selected product if it's the one being updated\n if (this.data.selectedProduct?.id === id) {\n this.data.selectedProduct = response.data;\n }\n }\n return response;\n } catch (err) {\n this.data.error =\n err instanceof Error ? err.message : 'Failed to update product';\n throw err;\n } finally {\n this.data.loading = false;\n }\n }\n\n async deleteProduct(id: string) {\n this.data.loading = true;\n this.data.error = null;\n\n try {\n await this.api.products.delete(id);\n this.data.items = this.data.items.filter((p) => p.id !== id);\n\n // Clear selection if deleted product was selected\n if (this.data.selectedProduct?.id === id) {\n this.data.selectedProduct = null;\n }\n } catch (err) {\n this.data.error =\n err instanceof Error ? err.message : 'Failed to delete product';\n throw err;\n } finally {\n this.data.loading = false;\n }\n }\n\n selectProduct(product: ProductData | null) {\n this.data.selectedProduct = product;\n }\n\n clearError() {\n this.data.error = null;\n }\n\n // Filter methods (return derived arrays, don't mutate state)\n filterByCategory(category: string): ProductData[] {\n return this.data.items.filter((p) => p.category === category);\n }\n\n filterInStock(): ProductData[] {\n return this.data.items.filter((p) => p.inStock);\n }\n\n searchProducts(query: string): ProductData[] {\n const lowercaseQuery = query.toLowerCase();\n return this.data.items.filter(\n (product) =>\n product.name?.toLowerCase().includes(lowercaseQuery) ||\n product.description?.toLowerCase().includes(lowercaseQuery) ||\n product.tags?.some((tag) => tag.toLowerCase().includes(lowercaseQuery)),\n );\n }\n}\n\n// Export singleton instance\nexport const productStore = new ProductStoreClass();\n"],"mappings":";;;AAgBA,IAAa,oBAAb,MAA+B;SAC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AAO;CAChD;CAEA,eAAe,OAA8B;EAC3C,MAAM,iBAAiB,MAAM,YAAA;EAC7B,OAAO,KAAK,KAAK,MAAM,QACpB,YACC,QAAQ,MAAM,YAAA,CAAA,CAAc,SAAS,cAAc,KACnD,QAAQ,aAAa,YAAA,CAAA,CAAc,SAAS,cAAc,KAC1D,QAAQ,MAAM,MAAM,QAAQ,IAAI,YAAA,CAAA,CAAc,SAAS,cAAc,CAAA,CAAA;CAE3E;AACF;AAGA,IAAa,eAAe,IAAI,kBAAA"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
//#region src/lib/utils/index.ts
|
|
2
|
+
/**
|
|
3
|
+
* SMRT Template Utilities
|
|
4
|
+
*
|
|
5
|
+
* Shared utility functions for product management functionality.
|
|
6
|
+
*/
|
|
7
|
+
function formatPrice(price) {
|
|
8
|
+
return new Intl.NumberFormat("en-US", {
|
|
9
|
+
style: "currency",
|
|
10
|
+
currency: "USD"
|
|
11
|
+
}).format(price);
|
|
12
|
+
}
|
|
13
|
+
function formatDate(date) {
|
|
14
|
+
const dateObj = typeof date === "string" ? new Date(date) : date;
|
|
15
|
+
return new Intl.DateTimeFormat("en-US", {
|
|
16
|
+
year: "numeric",
|
|
17
|
+
month: "short",
|
|
18
|
+
day: "numeric"
|
|
19
|
+
}).format(dateObj);
|
|
20
|
+
}
|
|
21
|
+
function slugify(text) {
|
|
22
|
+
return text.normalize("NFKD").replace(/[^\p{L}\p{N} ]+/gu, "").trim().toLowerCase().replace(/ +/g, "-").replace(/^-+|-+$/g, "");
|
|
23
|
+
}
|
|
24
|
+
function generateId() {
|
|
25
|
+
return Math.random().toString(36).substr(2, 9);
|
|
26
|
+
}
|
|
27
|
+
//#endregion
|
|
28
|
+
export { slugify as i, formatPrice as n, generateId as r, formatDate as t };
|
|
29
|
+
|
|
30
|
+
//# sourceMappingURL=utils-BgTqlQoH.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils-BgTqlQoH.js","names":[],"sources":["../../../src/lib/utils/index.ts"],"sourcesContent":["/**\n * SMRT Template Utilities\n *\n * Shared utility functions for product management functionality.\n */\n\nexport function formatPrice(price: number): string {\n return new Intl.NumberFormat('en-US', {\n style: 'currency',\n currency: 'USD',\n }).format(price);\n}\n\nexport function formatDate(date: string | Date): string {\n const dateObj = typeof date === 'string' ? new Date(date) : date;\n return new Intl.DateTimeFormat('en-US', {\n year: 'numeric',\n month: 'short',\n day: 'numeric',\n }).format(dateObj);\n}\n\nexport function slugify(text: string): string {\n return text\n .normalize('NFKD')\n .replace(/[^\\p{L}\\p{N} ]+/gu, '')\n .trim()\n .toLowerCase()\n .replace(/ +/g, '-')\n .replace(/^-+|-+$/g, '');\n}\n\nexport function generateId(): string {\n return Math.random().toString(36).substr(2, 9);\n}\n"],"mappings":";;;;;;AAMA,SAAgB,YAAY,OAAuB;CACjD,OAAO,IAAI,KAAK,aAAa,SAAS;EACpC,OAAO;EACP,UAAU;CACZ,CAAC,CAAC,CAAC,OAAO,KAAK;AACjB;AAEA,SAAgB,WAAW,MAA6B;CACtD,MAAM,UAAU,OAAO,SAAS,WAAW,IAAI,KAAK,IAAI,IAAI;CAC5D,OAAO,IAAI,KAAK,eAAe,SAAS;EACtC,MAAM;EACN,OAAO;EACP,KAAK;CACP,CAAC,CAAC,CAAC,OAAO,OAAO;AACnB;AAEA,SAAgB,QAAQ,MAAsB;CAC5C,OAAO,KACJ,UAAU,MAAM,CAAC,CACjB,QAAQ,qBAAqB,EAAE,CAAC,CAChC,KAAK,CAAC,CACN,YAAY,CAAC,CACb,QAAQ,OAAO,GAAG,CAAC,CACnB,QAAQ,YAAY,EAAE;AAC3B;AAEA,SAAgB,aAAqB;CACnC,OAAO,KAAK,OAAO,CAAC,CAAC,SAAS,EAAE,CAAC,CAAC,OAAO,GAAG,CAAC;AAC/C"}
|
package/dist/lib/collections.js
CHANGED
|
@@ -1,12 +1,4 @@
|
|
|
1
|
-
import "./chunks/
|
|
2
|
-
import {
|
|
3
|
-
import { ProductAssetCollection } from "./chunks/ProductAssetCollection-
|
|
4
|
-
export {
|
|
5
|
-
C as CategoryCollection,
|
|
6
|
-
M as MaterialCollection,
|
|
7
|
-
ProductAssetCollection,
|
|
8
|
-
P as ProductCollection,
|
|
9
|
-
a as ProductVariantCollection,
|
|
10
|
-
S as SkuCollection
|
|
11
|
-
};
|
|
12
|
-
//# sourceMappingURL=collections.js.map
|
|
1
|
+
import { i as CategoryCollection, n as ProductVariantCollection, r as MaterialCollection, t as SkuCollection } from "./chunks/collections-6PSqhUmZ.js";
|
|
2
|
+
import { t as ProductCollection } from "./chunks/ProductCollection-8QlfZ9ez.js";
|
|
3
|
+
import { t as ProductAssetCollection } from "./chunks/ProductAssetCollection-TbeaVxzc.js";
|
|
4
|
+
export { CategoryCollection, MaterialCollection, ProductAssetCollection, ProductCollection, ProductVariantCollection, SkuCollection };
|
package/dist/lib/components.js
CHANGED
|
@@ -1,6 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export {
|
|
3
|
-
P as ProductCard,
|
|
4
|
-
a as ProductForm
|
|
5
|
-
};
|
|
6
|
-
//# sourceMappingURL=components.js.map
|
|
1
|
+
import { n as ProductCard, t as ProductForm } from "./chunks/components-C6VpNVcg.js";
|
|
2
|
+
export { ProductCard, ProductForm };
|
package/dist/lib/generated.js
CHANGED
package/dist/lib/index.js
CHANGED
|
@@ -1,228 +1,203 @@
|
|
|
1
|
-
import "./chunks/
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
1
|
+
import { t as __exportAll } from "./chunks/rolldown-runtime-D7D4PA-g.js";
|
|
2
|
+
import "./chunks/__smrt-register__-DAo7IPPx.js";
|
|
3
|
+
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-B0w2dfHb.js";
|
|
4
|
+
import { i as CategoryCollection, n as ProductVariantCollection, r as MaterialCollection, t as SkuCollection } from "./chunks/collections-6PSqhUmZ.js";
|
|
5
|
+
import { t as ProductCollection } from "./chunks/ProductCollection-8QlfZ9ez.js";
|
|
6
|
+
import { t as ProductAssetCollection } from "./chunks/ProductAssetCollection-TbeaVxzc.js";
|
|
7
|
+
import { n as ProductCard, t as ProductForm } from "./chunks/components-C6VpNVcg.js";
|
|
8
|
+
import { t as autoGeneratedComponents } from "./chunks/generated-CM3rwUcw.js";
|
|
9
|
+
import "./chunks/models-JPB-sld2.js";
|
|
10
|
+
import { n as productStore, t as ProductStoreClass } from "./chunks/stores-CB0SI1c5.js";
|
|
11
|
+
import { i as slugify, n as formatPrice, r as generateId, t as formatDate } from "./chunks/utils-BgTqlQoH.js";
|
|
12
|
+
import { startRestServer } from "@happyvertical/smrt-core";
|
|
13
|
+
import createClient$1 from "@happyvertical/smrt-virt-client";
|
|
14
|
+
import createClient from "@smrt/client";
|
|
4
15
|
import { manifest } from "@smrt/manifest";
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
import { C, M, P, a, S } from "./chunks/SkuCollection-f_a3k93c.js";
|
|
8
|
-
import { ProductAssetCollection } from "./chunks/ProductAssetCollection-B93HdSlX.js";
|
|
9
|
-
import { P as P2, a as a2 } from "./chunks/ProductForm-CU0UvKEF.js";
|
|
10
|
-
import { a as a3 } from "./chunks/index-i3-ci1FB.js";
|
|
11
|
-
import { P as Product, C as Category } from "./chunks/Sku-sl6xf1PR.js";
|
|
12
|
-
import { M as M2, a as a4, b, c, S as S2 } from "./chunks/Sku-sl6xf1PR.js";
|
|
13
|
-
import { P as P3, p } from "./chunks/product-store.svelte-Dayd5n3W.js";
|
|
14
|
-
import { formatDate, formatPrice, generateId, slugify } from "./utils.js";
|
|
16
|
+
import createMCPServer from "@smrt/mcp";
|
|
17
|
+
import setupRoutes from "@smrt/routes";
|
|
15
18
|
import { MCPGenerator } from "@happyvertical/smrt-core/generators/mcp";
|
|
16
|
-
|
|
19
|
+
//#region src/client.ts
|
|
20
|
+
/**
|
|
21
|
+
* SMRT Template Client
|
|
22
|
+
*
|
|
23
|
+
* Demonstrates auto-generated TypeScript client from SMRT objects.
|
|
24
|
+
* No manual client code needed - everything is generated from @smrt() decorated classes.
|
|
25
|
+
*/
|
|
17
26
|
async function demonstrateClient() {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
if (import.meta.url === `file://${process.argv[1]}`) {
|
|
64
|
-
demonstrateClient().catch(console.error);
|
|
27
|
+
console.log("š Creating auto-generated API client...");
|
|
28
|
+
const api = createClient$1("http://localhost:3000/api/v1");
|
|
29
|
+
try {
|
|
30
|
+
console.log("\nš¦ Testing Product operations:");
|
|
31
|
+
const newProduct = {
|
|
32
|
+
name: "Demo Product",
|
|
33
|
+
description: "A product created by the auto-generated client",
|
|
34
|
+
price: 29.99,
|
|
35
|
+
inStock: true,
|
|
36
|
+
tags: ["demo", "auto-generated"]
|
|
37
|
+
};
|
|
38
|
+
console.log("Creating product:", newProduct);
|
|
39
|
+
const createdProduct = await api.products.create(newProduct);
|
|
40
|
+
console.log("ā
Created:", createdProduct);
|
|
41
|
+
console.log("\nš Listing all products:");
|
|
42
|
+
const products = await api.products.list();
|
|
43
|
+
console.log("Products:", products);
|
|
44
|
+
if (createdProduct?.id) {
|
|
45
|
+
console.log(`\nš Getting product ${createdProduct.id}:`);
|
|
46
|
+
const product = await api.products.get(createdProduct.id);
|
|
47
|
+
console.log("Product:", product);
|
|
48
|
+
console.log("\nāļø Updating product:");
|
|
49
|
+
const updatedProduct = await api.products.update(createdProduct.id, {
|
|
50
|
+
price: 39.99,
|
|
51
|
+
description: "Updated description"
|
|
52
|
+
});
|
|
53
|
+
console.log("Updated:", updatedProduct);
|
|
54
|
+
}
|
|
55
|
+
console.log("\nš·ļø Testing Category operations:");
|
|
56
|
+
const newCategory = {
|
|
57
|
+
name: "Demo Category",
|
|
58
|
+
description: "A category created by the auto-generated client",
|
|
59
|
+
active: true
|
|
60
|
+
};
|
|
61
|
+
console.log("Creating category:", newCategory);
|
|
62
|
+
const createdCategory = await api.categories.create(newCategory);
|
|
63
|
+
console.log("ā
Created:", createdCategory);
|
|
64
|
+
console.log("\nš Listing all categories:");
|
|
65
|
+
const categories = await api.categories.list();
|
|
66
|
+
console.log("Categories:", categories);
|
|
67
|
+
} catch (error) {
|
|
68
|
+
console.error("ā Client error:", error);
|
|
69
|
+
}
|
|
65
70
|
}
|
|
71
|
+
if (import.meta.url === `file://${process.argv[1]}`) demonstrateClient().catch(console.error);
|
|
72
|
+
//#endregion
|
|
73
|
+
//#region src/mcp.ts
|
|
74
|
+
/**
|
|
75
|
+
* MCP Server Generator Script for @have/products
|
|
76
|
+
*
|
|
77
|
+
* This script generates a complete MCP server with stdio transport
|
|
78
|
+
* from the Product and Category SMRT objects.
|
|
79
|
+
*
|
|
80
|
+
* Run with: npm run generate:mcp
|
|
81
|
+
*/
|
|
82
|
+
var mcp_exports = /* @__PURE__ */ __exportAll({ generateMCPServer: () => generateMCPServer });
|
|
83
|
+
/**
|
|
84
|
+
* Generate MCP server for products package
|
|
85
|
+
*/
|
|
66
86
|
async function generateMCPServer() {
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
generateReadme: true
|
|
93
|
-
});
|
|
94
|
-
console.log("\nā
MCP Server generation complete!");
|
|
95
|
-
console.log("\nš Next steps:");
|
|
96
|
-
console.log(" 1. Build the server: npm run build");
|
|
97
|
-
console.log(
|
|
98
|
-
" 2. Add to Claude Desktop config (see dist/claude-config.example.json)"
|
|
99
|
-
);
|
|
100
|
-
console.log(" 3. Restart Claude Desktop");
|
|
101
|
-
console.log(" 4. Use the tools in Claude Code!\n");
|
|
87
|
+
console.log("š¤ Generating MCP Server for @have/products...\n");
|
|
88
|
+
const generator = new MCPGenerator({
|
|
89
|
+
name: "products-mcp-server",
|
|
90
|
+
version: "1.0.0",
|
|
91
|
+
description: "MCP server exposing Product and Category SMRT objects"
|
|
92
|
+
}, {});
|
|
93
|
+
const tools = await generator.generateTools();
|
|
94
|
+
console.log(`š Discovered ${tools.length} tools from SMRT objects:`);
|
|
95
|
+
tools.forEach((tool) => {
|
|
96
|
+
console.log(` - ${tool.name}: ${tool.description}`);
|
|
97
|
+
});
|
|
98
|
+
console.log();
|
|
99
|
+
await generator.generateServer({
|
|
100
|
+
outputPath: "dist/mcp-server.js",
|
|
101
|
+
serverName: "products-mcp",
|
|
102
|
+
debug: false,
|
|
103
|
+
generateClaudeConfigFile: true,
|
|
104
|
+
generateReadme: true
|
|
105
|
+
});
|
|
106
|
+
console.log("\nā
MCP Server generation complete!");
|
|
107
|
+
console.log("\nš Next steps:");
|
|
108
|
+
console.log(" 1. Build the server: npm run build");
|
|
109
|
+
console.log(" 2. Add to Claude Desktop config (see dist/claude-config.example.json)");
|
|
110
|
+
console.log(" 3. Restart Claude Desktop");
|
|
111
|
+
console.log(" 4. Use the tools in Claude Code!\n");
|
|
102
112
|
}
|
|
103
|
-
if (import.meta.url === `file://${process.argv[1]}`) {
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
+
if (import.meta.url === `file://${process.argv[1]}`) generateMCPServer().catch((error) => {
|
|
114
|
+
console.error("ā MCP server generation failed:", error);
|
|
115
|
+
process.exit(1);
|
|
116
|
+
});
|
|
117
|
+
//#endregion
|
|
118
|
+
//#region src/server.ts
|
|
119
|
+
/**
|
|
120
|
+
* SMRT Template Server
|
|
121
|
+
*
|
|
122
|
+
* Demonstrates auto-generated REST API from SMRT objects.
|
|
123
|
+
* No manual route definitions needed - everything is generated from @smrt() decorated classes.
|
|
124
|
+
*/
|
|
125
|
+
var server_exports = /* @__PURE__ */ __exportAll({ startServer: () => startServer });
|
|
126
|
+
/**
|
|
127
|
+
* Reference auth stub (#1540). Generated routes are FAIL-CLOSED: without an
|
|
128
|
+
* `authMiddleware` (or `@smrt({ api: { public: true } })` on the model) every
|
|
129
|
+
* route returns 401. This stub demonstrates the contract ā replace it with your
|
|
130
|
+
* real auth (verify a session cookie / bearer token, attach the principal).
|
|
131
|
+
*
|
|
132
|
+
* Returning the (optionally augmented) request allows the call; returning a
|
|
133
|
+
* `Response` rejects it.
|
|
134
|
+
*/
|
|
113
135
|
function demoAuthMiddleware(_objectName, _action) {
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
headers: { "Content-Type": "application/json" }
|
|
122
|
-
}
|
|
123
|
-
);
|
|
124
|
-
}
|
|
125
|
-
return req;
|
|
126
|
-
};
|
|
136
|
+
return async (req) => {
|
|
137
|
+
if (!req.headers.get("authorization")) return new Response(JSON.stringify({ error: "Authentication required" }), {
|
|
138
|
+
status: 401,
|
|
139
|
+
headers: { "Content-Type": "application/json" }
|
|
140
|
+
});
|
|
141
|
+
return req;
|
|
142
|
+
};
|
|
127
143
|
}
|
|
128
144
|
async function startServer() {
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
console.log(" POST /api/v1/categories - Create category");
|
|
153
|
-
console.log("\nš” Try these endpoints (auth required ā send a token):");
|
|
154
|
-
console.log(
|
|
155
|
-
' curl http://localhost:3000/api/v1/products -H "Authorization: Bearer <token>"'
|
|
156
|
-
);
|
|
157
|
-
console.log(
|
|
158
|
-
' curl http://localhost:3000/api/v1/categories -H "Authorization: Bearer <token>"'
|
|
159
|
-
);
|
|
160
|
-
console.log(
|
|
161
|
-
` curl -X POST http://localhost:3000/api/v1/products -H "Authorization: Bearer <token>" -H "Content-Type: application/json" -d '{"name":"Test Product","price":29.99}'`
|
|
162
|
-
);
|
|
163
|
-
return { shutdown };
|
|
164
|
-
}
|
|
165
|
-
if (import.meta.url === `file://${process.argv[1]}`) {
|
|
166
|
-
startServer().catch(console.error);
|
|
145
|
+
console.log("š Starting SMRT Template Server...");
|
|
146
|
+
const shutdown = await startRestServer([Product, Category], {}, {
|
|
147
|
+
port: 3e3,
|
|
148
|
+
hostname: "127.0.0.1",
|
|
149
|
+
basePath: "/api/v1",
|
|
150
|
+
enableCors: true,
|
|
151
|
+
allowedOrigins: ["http://localhost:3000"],
|
|
152
|
+
authMiddleware: demoAuthMiddleware
|
|
153
|
+
});
|
|
154
|
+
console.log("ā
Server ready!");
|
|
155
|
+
console.log("š” REST API: http://localhost:3000/api/v1");
|
|
156
|
+
console.log("š Endpoints:");
|
|
157
|
+
console.log(" GET /api/v1/products - List products");
|
|
158
|
+
console.log(" POST /api/v1/products - Create product");
|
|
159
|
+
console.log(" GET /api/v1/products/:id - Get product");
|
|
160
|
+
console.log(" PUT /api/v1/products/:id - Update product");
|
|
161
|
+
console.log(" GET /api/v1/categories - List categories");
|
|
162
|
+
console.log(" POST /api/v1/categories - Create category");
|
|
163
|
+
console.log("\nš” Try these endpoints (auth required ā send a token):");
|
|
164
|
+
console.log(" curl http://localhost:3000/api/v1/products -H \"Authorization: Bearer <token>\"");
|
|
165
|
+
console.log(" curl http://localhost:3000/api/v1/categories -H \"Authorization: Bearer <token>\"");
|
|
166
|
+
console.log(" curl -X POST http://localhost:3000/api/v1/products -H \"Authorization: Bearer <token>\" -H \"Content-Type: application/json\" -d '{\"name\":\"Test Product\",\"price\":29.99}'");
|
|
167
|
+
return { shutdown };
|
|
167
168
|
}
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
169
|
+
if (import.meta.url === `file://${process.argv[1]}`) startServer().catch(console.error);
|
|
170
|
+
//#endregion
|
|
171
|
+
//#region src/index.ts
|
|
172
|
+
/**
|
|
173
|
+
* Start all services for demonstration (legacy function)
|
|
174
|
+
*/
|
|
172
175
|
async function startAll() {
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
176
|
+
const { startServer } = await Promise.resolve().then(() => server_exports);
|
|
177
|
+
const { generateMCPServer } = await Promise.resolve().then(() => mcp_exports);
|
|
178
|
+
console.log("š Starting SMRT Template - Full Demo\n");
|
|
179
|
+
console.log("1ļøā£ Starting REST API...");
|
|
180
|
+
const server = await startServer();
|
|
181
|
+
console.log("\n2ļøā£ Starting MCP Server...");
|
|
182
|
+
const mcp = await generateMCPServer();
|
|
183
|
+
console.log("\n⨠All services running!");
|
|
184
|
+
console.log("\nšÆ What was auto-generated:");
|
|
185
|
+
console.log(" ⢠REST endpoints for Product and Category");
|
|
186
|
+
console.log(" ⢠TypeScript client with full type safety");
|
|
187
|
+
console.log(" ⢠MCP tools for AI model integration");
|
|
188
|
+
console.log(" ⢠OpenAPI/Swagger documentation");
|
|
189
|
+
console.log(" ⢠Live reloading during development");
|
|
190
|
+
console.log("\nš Next steps:");
|
|
191
|
+
console.log(" ⢠Modify src/lib/models/ to add new fields");
|
|
192
|
+
console.log(" ⢠Add new @smrt() classes to auto-generate more APIs");
|
|
193
|
+
console.log(" ⢠Run bun run dev to see live updates");
|
|
194
|
+
return {
|
|
195
|
+
server,
|
|
196
|
+
mcp
|
|
197
|
+
};
|
|
195
198
|
}
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
Product,
|
|
202
|
-
a4 as ProductAsset,
|
|
203
|
-
ProductAssetCollection,
|
|
204
|
-
P2 as ProductCard,
|
|
205
|
-
P as ProductCollection,
|
|
206
|
-
a2 as ProductForm,
|
|
207
|
-
P3 as ProductStoreClass,
|
|
208
|
-
b as ProductType,
|
|
209
|
-
c as ProductVariant,
|
|
210
|
-
a as ProductVariantCollection,
|
|
211
|
-
S2 as Sku,
|
|
212
|
-
S as SkuCollection,
|
|
213
|
-
a3 as autoGeneratedComponents,
|
|
214
|
-
default2 as createClient,
|
|
215
|
-
default3 as createMCPServer,
|
|
216
|
-
demonstrateClient,
|
|
217
|
-
formatDate,
|
|
218
|
-
formatPrice,
|
|
219
|
-
generateId,
|
|
220
|
-
generateMCPServer,
|
|
221
|
-
manifest,
|
|
222
|
-
p as productStore,
|
|
223
|
-
default4 as setupRoutes,
|
|
224
|
-
slugify,
|
|
225
|
-
startAll,
|
|
226
|
-
startServer
|
|
227
|
-
};
|
|
228
|
-
//# sourceMappingURL=index.js.map
|
|
199
|
+
if (import.meta.url === `file://${process.argv[1]}`) startAll().catch(console.error);
|
|
200
|
+
//#endregion
|
|
201
|
+
export { Category, CategoryCollection, Material, MaterialCollection, Product, ProductAsset, ProductAssetCollection, ProductCard, ProductCollection, ProductForm, ProductStoreClass, ProductType, ProductVariant, ProductVariantCollection, Sku, SkuCollection, autoGeneratedComponents, createClient, createMCPServer, demonstrateClient, formatDate, formatPrice, generateId, generateMCPServer, manifest, productStore, setupRoutes, slugify, startAll, startServer };
|
|
202
|
+
|
|
203
|
+
//# sourceMappingURL=index.js.map
|