@86d-app/reviews 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 (53) hide show
  1. package/AGENTS.md +41 -0
  2. package/COMPONENTS.md +34 -0
  3. package/README.md +192 -0
  4. package/package.json +46 -0
  5. package/src/__tests__/service-impl.test.ts +1436 -0
  6. package/src/admin/components/index.ts +3 -0
  7. package/src/admin/components/index.tsx +3 -0
  8. package/src/admin/components/review-analytics.mdx +3 -0
  9. package/src/admin/components/review-analytics.tsx +221 -0
  10. package/src/admin/components/review-list.mdx +89 -0
  11. package/src/admin/components/review-list.tsx +308 -0
  12. package/src/admin/components/review-moderation.mdx +3 -0
  13. package/src/admin/components/review-moderation.tsx +447 -0
  14. package/src/admin/endpoints/approve-review.ts +19 -0
  15. package/src/admin/endpoints/delete-review.ts +17 -0
  16. package/src/admin/endpoints/get-review.ts +16 -0
  17. package/src/admin/endpoints/index.ts +23 -0
  18. package/src/admin/endpoints/list-review-requests.ts +23 -0
  19. package/src/admin/endpoints/list-reviews.ts +25 -0
  20. package/src/admin/endpoints/reject-review.ts +19 -0
  21. package/src/admin/endpoints/respond-review.ts +22 -0
  22. package/src/admin/endpoints/review-analytics.ts +14 -0
  23. package/src/admin/endpoints/review-request-stats.ts +12 -0
  24. package/src/admin/endpoints/send-review-request.ts +41 -0
  25. package/src/index.ts +73 -0
  26. package/src/mdx.d.ts +5 -0
  27. package/src/schema.ts +37 -0
  28. package/src/service-impl.ts +263 -0
  29. package/src/service.ts +126 -0
  30. package/src/store/components/_hooks.ts +13 -0
  31. package/src/store/components/_utils.ts +16 -0
  32. package/src/store/components/distribution-bars.mdx +21 -0
  33. package/src/store/components/distribution-bars.tsx +13 -0
  34. package/src/store/components/index.tsx +20 -0
  35. package/src/store/components/product-reviews.mdx +52 -0
  36. package/src/store/components/product-reviews.tsx +172 -0
  37. package/src/store/components/review-card.mdx +32 -0
  38. package/src/store/components/review-card.tsx +87 -0
  39. package/src/store/components/review-form.mdx +111 -0
  40. package/src/store/components/review-form.tsx +68 -0
  41. package/src/store/components/reviews-summary.mdx +6 -0
  42. package/src/store/components/reviews-summary.tsx +30 -0
  43. package/src/store/components/star-display.mdx +18 -0
  44. package/src/store/components/star-display.tsx +28 -0
  45. package/src/store/components/star-picker.mdx +21 -0
  46. package/src/store/components/star-picker.tsx +23 -0
  47. package/src/store/endpoints/index.ts +11 -0
  48. package/src/store/endpoints/list-my-reviews.ts +38 -0
  49. package/src/store/endpoints/list-product-reviews.ts +26 -0
  50. package/src/store/endpoints/mark-helpful.ts +16 -0
  51. package/src/store/endpoints/submit-review.ts +33 -0
  52. package/tsconfig.json +9 -0
  53. package/vitest.config.ts +2 -0
@@ -0,0 +1,16 @@
1
+ import { createStoreEndpoint, z } from "@86d-app/core";
2
+ import type { ReviewController } from "../../service";
3
+
4
+ export const markHelpful = createStoreEndpoint(
5
+ "/reviews/:id/helpful",
6
+ {
7
+ method: "POST",
8
+ params: z.object({ id: z.string() }),
9
+ },
10
+ async (ctx) => {
11
+ const controller = ctx.context.controllers.reviews as ReviewController;
12
+ const review = await controller.markHelpful(ctx.params.id);
13
+ if (!review) return { error: "Review not found", status: 404 };
14
+ return { helpfulCount: review.helpfulCount };
15
+ },
16
+ );
@@ -0,0 +1,33 @@
1
+ import { createStoreEndpoint, sanitizeText, z } from "@86d-app/core";
2
+ import type { ReviewController } from "../../service";
3
+
4
+ export const submitReview = createStoreEndpoint(
5
+ "/reviews",
6
+ {
7
+ method: "POST",
8
+ body: z.object({
9
+ productId: z.string(),
10
+ authorName: z.string().max(200).transform(sanitizeText),
11
+ authorEmail: z.string().email(),
12
+ rating: z.number().int().min(1).max(5),
13
+ title: z.string().max(500).transform(sanitizeText).optional(),
14
+ body: z.string().max(10000).transform(sanitizeText),
15
+ customerId: z.string().optional(),
16
+ isVerifiedPurchase: z.boolean().optional(),
17
+ }),
18
+ },
19
+ async (ctx) => {
20
+ const controller = ctx.context.controllers.reviews as ReviewController;
21
+ const review = await controller.createReview({
22
+ productId: ctx.body.productId,
23
+ authorName: ctx.body.authorName,
24
+ authorEmail: ctx.body.authorEmail,
25
+ rating: ctx.body.rating,
26
+ title: ctx.body.title,
27
+ body: ctx.body.body,
28
+ customerId: ctx.body.customerId,
29
+ isVerifiedPurchase: ctx.body.isVerifiedPurchase,
30
+ });
31
+ return { review };
32
+ },
33
+ );
package/tsconfig.json ADDED
@@ -0,0 +1,9 @@
1
+ {
2
+ "extends": "../../tsconfig.base.json",
3
+ "compilerOptions": {
4
+ "lib": ["ES2022", "dom", "dom.iterable"],
5
+ "jsx": "preserve"
6
+ },
7
+ "include": ["src"],
8
+ "exclude": ["node_modules"]
9
+ }
@@ -0,0 +1,2 @@
1
+ import { defineConfig } from "vitest/config";
2
+ export default defineConfig({ test: { environment: "node" } });