@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.
Files changed (94) hide show
  1. package/AGENTS.md +65 -0
  2. package/COMPONENTS.md +231 -0
  3. package/README.md +201 -0
  4. package/package.json +46 -0
  5. package/src/__tests__/controllers.test.ts +2227 -0
  6. package/src/__tests__/state.test.ts +138 -0
  7. package/src/admin/components/categories-admin.mdx +3 -0
  8. package/src/admin/components/categories-admin.tsx +449 -0
  9. package/src/admin/components/category-form.mdx +9 -0
  10. package/src/admin/components/category-form.tsx +490 -0
  11. package/src/admin/components/category-list.mdx +75 -0
  12. package/src/admin/components/category-list.tsx +168 -0
  13. package/src/admin/components/collections-admin.mdx +3 -0
  14. package/src/admin/components/collections-admin.tsx +771 -0
  15. package/src/admin/components/index.tsx +8 -0
  16. package/src/admin/components/product-detail.mdx +12 -0
  17. package/src/admin/components/product-detail.tsx +790 -0
  18. package/src/admin/components/product-edit.tsx +60 -0
  19. package/src/admin/components/product-form.tsx +793 -0
  20. package/src/admin/components/product-list.mdx +3 -0
  21. package/src/admin/components/product-list.tsx +1125 -0
  22. package/src/admin/components/product-new.tsx +38 -0
  23. package/src/admin/endpoints/add-collection-product.ts +17 -0
  24. package/src/admin/endpoints/bulk-action.ts +43 -0
  25. package/src/admin/endpoints/create-category.ts +52 -0
  26. package/src/admin/endpoints/create-collection.ts +35 -0
  27. package/src/admin/endpoints/create-product.ts +50 -0
  28. package/src/admin/endpoints/create-variant.ts +45 -0
  29. package/src/admin/endpoints/delete-category.ts +27 -0
  30. package/src/admin/endpoints/delete-collection.ts +12 -0
  31. package/src/admin/endpoints/delete-product.ts +27 -0
  32. package/src/admin/endpoints/delete-variant.ts +27 -0
  33. package/src/admin/endpoints/get-product.ts +23 -0
  34. package/src/admin/endpoints/import-products.ts +47 -0
  35. package/src/admin/endpoints/index.ts +43 -0
  36. package/src/admin/endpoints/list-categories.ts +21 -0
  37. package/src/admin/endpoints/list-collections.ts +20 -0
  38. package/src/admin/endpoints/list-products.ts +25 -0
  39. package/src/admin/endpoints/remove-collection-product.ts +15 -0
  40. package/src/admin/endpoints/update-category.ts +82 -0
  41. package/src/admin/endpoints/update-collection.ts +22 -0
  42. package/src/admin/endpoints/update-product.ts +67 -0
  43. package/src/admin/endpoints/update-variant.ts +41 -0
  44. package/src/controllers.ts +1410 -0
  45. package/src/index.ts +120 -0
  46. package/src/markdown.ts +150 -0
  47. package/src/mdx.d.ts +5 -0
  48. package/src/schema.ts +352 -0
  49. package/src/state.ts +84 -0
  50. package/src/store/components/_hooks.ts +78 -0
  51. package/src/store/components/_types.ts +73 -0
  52. package/src/store/components/_utils.ts +14 -0
  53. package/src/store/components/back-in-stock-notify.tsx +97 -0
  54. package/src/store/components/collection-card.mdx +42 -0
  55. package/src/store/components/collection-card.tsx +12 -0
  56. package/src/store/components/collection-detail.mdx +12 -0
  57. package/src/store/components/collection-detail.tsx +149 -0
  58. package/src/store/components/collection-grid.mdx +9 -0
  59. package/src/store/components/collection-grid.tsx +80 -0
  60. package/src/store/components/featured-products.mdx +9 -0
  61. package/src/store/components/featured-products.tsx +75 -0
  62. package/src/store/components/filter-chip.mdx +25 -0
  63. package/src/store/components/filter-chip.tsx +12 -0
  64. package/src/store/components/index.tsx +39 -0
  65. package/src/store/components/product-card.mdx +69 -0
  66. package/src/store/components/product-card.tsx +71 -0
  67. package/src/store/components/product-detail.mdx +30 -0
  68. package/src/store/components/product-detail.tsx +488 -0
  69. package/src/store/components/product-listing.mdx +7 -0
  70. package/src/store/components/product-listing.tsx +423 -0
  71. package/src/store/components/product-reviews-section.mdx +21 -0
  72. package/src/store/components/product-reviews-section.tsx +372 -0
  73. package/src/store/components/recently-viewed.tsx +100 -0
  74. package/src/store/components/related-products.mdx +6 -0
  75. package/src/store/components/related-products.tsx +62 -0
  76. package/src/store/components/star-display.mdx +18 -0
  77. package/src/store/components/star-display.tsx +27 -0
  78. package/src/store/components/star-picker.mdx +21 -0
  79. package/src/store/components/star-picker.tsx +21 -0
  80. package/src/store/components/stock-badge.mdx +12 -0
  81. package/src/store/components/stock-badge.tsx +19 -0
  82. package/src/store/endpoints/get-category.ts +61 -0
  83. package/src/store/endpoints/get-collection.ts +46 -0
  84. package/src/store/endpoints/get-featured.ts +18 -0
  85. package/src/store/endpoints/get-product.ts +52 -0
  86. package/src/store/endpoints/get-related.ts +20 -0
  87. package/src/store/endpoints/index.ts +23 -0
  88. package/src/store/endpoints/list-categories.ts +13 -0
  89. package/src/store/endpoints/list-collections.ts +22 -0
  90. package/src/store/endpoints/list-products.ts +28 -0
  91. package/src/store/endpoints/search-products.ts +18 -0
  92. package/src/store/endpoints/store-search.ts +111 -0
  93. package/tsconfig.json +9 -0
  94. 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
+ );