@86d-app/products 0.0.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/AGENTS.md +65 -0
- package/COMPONENTS.md +231 -0
- package/README.md +201 -0
- package/package.json +46 -0
- package/src/__tests__/controllers.test.ts +2227 -0
- package/src/__tests__/state.test.ts +138 -0
- package/src/admin/components/categories-admin.mdx +3 -0
- package/src/admin/components/categories-admin.tsx +449 -0
- package/src/admin/components/category-form.mdx +9 -0
- package/src/admin/components/category-form.tsx +490 -0
- package/src/admin/components/category-list.mdx +75 -0
- package/src/admin/components/category-list.tsx +168 -0
- package/src/admin/components/collections-admin.mdx +3 -0
- package/src/admin/components/collections-admin.tsx +771 -0
- package/src/admin/components/index.tsx +8 -0
- package/src/admin/components/product-detail.mdx +12 -0
- package/src/admin/components/product-detail.tsx +790 -0
- package/src/admin/components/product-edit.tsx +60 -0
- package/src/admin/components/product-form.tsx +793 -0
- package/src/admin/components/product-list.mdx +3 -0
- package/src/admin/components/product-list.tsx +1125 -0
- package/src/admin/components/product-new.tsx +38 -0
- package/src/admin/endpoints/add-collection-product.ts +17 -0
- package/src/admin/endpoints/bulk-action.ts +43 -0
- package/src/admin/endpoints/create-category.ts +52 -0
- package/src/admin/endpoints/create-collection.ts +35 -0
- package/src/admin/endpoints/create-product.ts +50 -0
- package/src/admin/endpoints/create-variant.ts +45 -0
- package/src/admin/endpoints/delete-category.ts +27 -0
- package/src/admin/endpoints/delete-collection.ts +12 -0
- package/src/admin/endpoints/delete-product.ts +27 -0
- package/src/admin/endpoints/delete-variant.ts +27 -0
- package/src/admin/endpoints/get-product.ts +23 -0
- package/src/admin/endpoints/import-products.ts +47 -0
- package/src/admin/endpoints/index.ts +43 -0
- package/src/admin/endpoints/list-categories.ts +21 -0
- package/src/admin/endpoints/list-collections.ts +20 -0
- package/src/admin/endpoints/list-products.ts +25 -0
- package/src/admin/endpoints/remove-collection-product.ts +15 -0
- package/src/admin/endpoints/update-category.ts +82 -0
- package/src/admin/endpoints/update-collection.ts +22 -0
- package/src/admin/endpoints/update-product.ts +67 -0
- package/src/admin/endpoints/update-variant.ts +41 -0
- package/src/controllers.ts +1410 -0
- package/src/index.ts +120 -0
- package/src/markdown.ts +150 -0
- package/src/mdx.d.ts +5 -0
- package/src/schema.ts +352 -0
- package/src/state.ts +84 -0
- package/src/store/components/_hooks.ts +78 -0
- package/src/store/components/_types.ts +73 -0
- package/src/store/components/_utils.ts +14 -0
- package/src/store/components/back-in-stock-notify.tsx +97 -0
- package/src/store/components/collection-card.mdx +42 -0
- package/src/store/components/collection-card.tsx +12 -0
- package/src/store/components/collection-detail.mdx +12 -0
- package/src/store/components/collection-detail.tsx +149 -0
- package/src/store/components/collection-grid.mdx +9 -0
- package/src/store/components/collection-grid.tsx +80 -0
- package/src/store/components/featured-products.mdx +9 -0
- package/src/store/components/featured-products.tsx +75 -0
- package/src/store/components/filter-chip.mdx +25 -0
- package/src/store/components/filter-chip.tsx +12 -0
- package/src/store/components/index.tsx +39 -0
- package/src/store/components/product-card.mdx +69 -0
- package/src/store/components/product-card.tsx +71 -0
- package/src/store/components/product-detail.mdx +30 -0
- package/src/store/components/product-detail.tsx +488 -0
- package/src/store/components/product-listing.mdx +7 -0
- package/src/store/components/product-listing.tsx +423 -0
- package/src/store/components/product-reviews-section.mdx +21 -0
- package/src/store/components/product-reviews-section.tsx +372 -0
- package/src/store/components/recently-viewed.tsx +100 -0
- package/src/store/components/related-products.mdx +6 -0
- package/src/store/components/related-products.tsx +62 -0
- package/src/store/components/star-display.mdx +18 -0
- package/src/store/components/star-display.tsx +27 -0
- package/src/store/components/star-picker.mdx +21 -0
- package/src/store/components/star-picker.tsx +21 -0
- package/src/store/components/stock-badge.mdx +12 -0
- package/src/store/components/stock-badge.tsx +19 -0
- package/src/store/endpoints/get-category.ts +61 -0
- package/src/store/endpoints/get-collection.ts +46 -0
- package/src/store/endpoints/get-featured.ts +18 -0
- package/src/store/endpoints/get-product.ts +52 -0
- package/src/store/endpoints/get-related.ts +20 -0
- package/src/store/endpoints/index.ts +23 -0
- package/src/store/endpoints/list-categories.ts +13 -0
- package/src/store/endpoints/list-collections.ts +22 -0
- package/src/store/endpoints/list-products.ts +28 -0
- package/src/store/endpoints/search-products.ts +18 -0
- package/src/store/endpoints/store-search.ts +111 -0
- package/tsconfig.json +9 -0
- package/vitest.config.ts +7 -0
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { createAdminEndpoint, sanitizeText, z } from "@86d-app/core";
|
|
2
|
+
|
|
3
|
+
export const updateCollection = createAdminEndpoint(
|
|
4
|
+
"/admin/collections/:id",
|
|
5
|
+
{
|
|
6
|
+
method: "PUT",
|
|
7
|
+
params: z.object({ id: z.string() }),
|
|
8
|
+
body: z.object({
|
|
9
|
+
name: z.string().min(1).max(200).transform(sanitizeText).optional(),
|
|
10
|
+
slug: z.string().min(1).max(200).optional(),
|
|
11
|
+
description: z.string().max(5000).transform(sanitizeText).optional(),
|
|
12
|
+
image: z.string().max(2000).optional(),
|
|
13
|
+
isFeatured: z.boolean().optional(),
|
|
14
|
+
isVisible: z.boolean().optional(),
|
|
15
|
+
position: z.number().int().min(0).optional(),
|
|
16
|
+
}),
|
|
17
|
+
},
|
|
18
|
+
async (ctx) => {
|
|
19
|
+
const collection = await ctx.context.controllers.collection.update(ctx);
|
|
20
|
+
return { collection };
|
|
21
|
+
},
|
|
22
|
+
);
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { createAdminEndpoint, sanitizeText, z } from "@86d-app/core";
|
|
2
|
+
import type { Product } from "../../controllers";
|
|
3
|
+
|
|
4
|
+
export const updateProduct = createAdminEndpoint(
|
|
5
|
+
"/admin/products/:id",
|
|
6
|
+
{
|
|
7
|
+
method: "PUT",
|
|
8
|
+
params: z.object({
|
|
9
|
+
id: z.string(),
|
|
10
|
+
}),
|
|
11
|
+
body: z.object({
|
|
12
|
+
name: z.string().min(1).max(200).transform(sanitizeText).optional(),
|
|
13
|
+
slug: z.string().min(1).max(200).optional(),
|
|
14
|
+
description: z.string().max(10000).transform(sanitizeText).optional(),
|
|
15
|
+
shortDescription: z.string().max(500).transform(sanitizeText).optional(),
|
|
16
|
+
price: z.number().positive().optional(),
|
|
17
|
+
compareAtPrice: z.number().positive().nullable().optional(),
|
|
18
|
+
costPrice: z.number().positive().nullable().optional(),
|
|
19
|
+
sku: z.string().max(100).nullable().optional(),
|
|
20
|
+
barcode: z.string().max(100).nullable().optional(),
|
|
21
|
+
inventory: z.number().int().min(0).optional(),
|
|
22
|
+
trackInventory: z.boolean().optional(),
|
|
23
|
+
allowBackorder: z.boolean().optional(),
|
|
24
|
+
status: z.enum(["draft", "active", "archived"]).optional(),
|
|
25
|
+
categoryId: z.string().nullable().optional(),
|
|
26
|
+
images: z.array(z.string()).optional(),
|
|
27
|
+
tags: z.array(z.string()).optional(),
|
|
28
|
+
metadata: z.record(z.string(), z.any()).optional(),
|
|
29
|
+
weight: z.number().positive().nullable().optional(),
|
|
30
|
+
weightUnit: z.enum(["kg", "lb", "oz", "g"]).nullable().optional(),
|
|
31
|
+
isFeatured: z.boolean().optional(),
|
|
32
|
+
}),
|
|
33
|
+
},
|
|
34
|
+
async (ctx) => {
|
|
35
|
+
const { body } = ctx;
|
|
36
|
+
const controllers = ctx.context.controllers;
|
|
37
|
+
|
|
38
|
+
// Check if product exists
|
|
39
|
+
const existingProduct = (await controllers.product.getById(
|
|
40
|
+
ctx,
|
|
41
|
+
)) as Product | null;
|
|
42
|
+
if (!existingProduct) {
|
|
43
|
+
return {
|
|
44
|
+
error: "Product not found",
|
|
45
|
+
status: 404,
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// If slug is being changed, check uniqueness
|
|
50
|
+
if (body.slug && body.slug !== existingProduct.slug) {
|
|
51
|
+
const productWithSlug = await controllers.product.getBySlug({
|
|
52
|
+
...ctx,
|
|
53
|
+
query: { slug: body.slug },
|
|
54
|
+
});
|
|
55
|
+
if (productWithSlug) {
|
|
56
|
+
return {
|
|
57
|
+
error: "A product with this slug already exists",
|
|
58
|
+
status: 400,
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const product = await controllers.product.update(ctx);
|
|
64
|
+
|
|
65
|
+
return { product };
|
|
66
|
+
},
|
|
67
|
+
);
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { createAdminEndpoint, sanitizeText, z } from "@86d-app/core";
|
|
2
|
+
|
|
3
|
+
export const updateVariant = createAdminEndpoint(
|
|
4
|
+
"/admin/variants/:id",
|
|
5
|
+
{
|
|
6
|
+
method: "PUT",
|
|
7
|
+
params: z.object({
|
|
8
|
+
id: z.string(),
|
|
9
|
+
}),
|
|
10
|
+
body: z.object({
|
|
11
|
+
name: z.string().min(1).max(200).transform(sanitizeText).optional(),
|
|
12
|
+
sku: z.string().max(100).nullable().optional(),
|
|
13
|
+
barcode: z.string().max(100).nullable().optional(),
|
|
14
|
+
price: z.number().positive().optional(),
|
|
15
|
+
compareAtPrice: z.number().positive().nullable().optional(),
|
|
16
|
+
costPrice: z.number().positive().nullable().optional(),
|
|
17
|
+
inventory: z.number().int().min(0).optional(),
|
|
18
|
+
options: z.record(z.string(), z.string()).optional(),
|
|
19
|
+
images: z.array(z.string()).optional(),
|
|
20
|
+
weight: z.number().positive().nullable().optional(),
|
|
21
|
+
weightUnit: z.enum(["kg", "lb", "oz", "g"]).nullable().optional(),
|
|
22
|
+
position: z.number().int().min(0).optional(),
|
|
23
|
+
}),
|
|
24
|
+
},
|
|
25
|
+
async (ctx) => {
|
|
26
|
+
const controllers = ctx.context.controllers;
|
|
27
|
+
|
|
28
|
+
// Check if variant exists
|
|
29
|
+
const existingVariant = await controllers.variant.getById(ctx);
|
|
30
|
+
if (!existingVariant) {
|
|
31
|
+
return {
|
|
32
|
+
error: "Variant not found",
|
|
33
|
+
status: 404,
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const variant = await controllers.variant.update(ctx);
|
|
38
|
+
|
|
39
|
+
return { variant };
|
|
40
|
+
},
|
|
41
|
+
);
|