medusa-plugin-ratings 0.1.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 (31) hide show
  1. package/.medusa/server/medusa-config.d.ts +1 -0
  2. package/.medusa/server/medusa-config.js +23 -0
  3. package/.medusa/server/src/admin/index.js +490 -0
  4. package/.medusa/server/src/admin/index.mjs +489 -0
  5. package/.medusa/server/src/api/admin/reviews/[id]/route.d.ts +5 -0
  6. package/.medusa/server/src/api/admin/reviews/[id]/route.js +48 -0
  7. package/.medusa/server/src/api/admin/reviews/approve/route.d.ts +3 -0
  8. package/.medusa/server/src/api/admin/reviews/approve/route.js +25 -0
  9. package/.medusa/server/src/api/admin/reviews/reject/route.d.ts +3 -0
  10. package/.medusa/server/src/api/admin/reviews/reject/route.js +25 -0
  11. package/.medusa/server/src/api/admin/reviews/route.d.ts +4 -0
  12. package/.medusa/server/src/api/admin/reviews/route.js +34 -0
  13. package/.medusa/server/src/api/middlewares.d.ts +2 -0
  14. package/.medusa/server/src/api/middlewares.js +84 -0
  15. package/.medusa/server/src/api/store/reviews/[productId]/route.d.ts +4 -0
  16. package/.medusa/server/src/api/store/reviews/[productId]/route.js +85 -0
  17. package/.medusa/server/src/api/validators.d.ts +144 -0
  18. package/.medusa/server/src/api/validators.js +38 -0
  19. package/.medusa/server/src/modules/review/index.d.ts +36 -0
  20. package/.medusa/server/src/modules/review/index.js +25 -0
  21. package/.medusa/server/src/modules/review/migrations/Migration20260409183947.d.ts +5 -0
  22. package/.medusa/server/src/modules/review/migrations/Migration20260409183947.js +22 -0
  23. package/.medusa/server/src/modules/review/models/review-activity.d.ts +27 -0
  24. package/.medusa/server/src/modules/review/models/review-activity.js +21 -0
  25. package/.medusa/server/src/modules/review/models/review.d.ts +26 -0
  26. package/.medusa/server/src/modules/review/models/review.js +30 -0
  27. package/.medusa/server/src/modules/review/service.d.ts +139 -0
  28. package/.medusa/server/src/modules/review/service.js +46 -0
  29. package/LICENSE +21 -0
  30. package/README.md +51 -0
  31. package/package.json +88 -0
@@ -0,0 +1,139 @@
1
+ import { ReviewActivityType } from './models/review-activity';
2
+ import { ReviewStatus } from './models/review';
3
+ export type ReviewModuleOptions = {
4
+ defaultStatus?: ReviewStatus;
5
+ };
6
+ declare const ReviewService_base: import("@medusajs/framework/utils").MedusaServiceReturnType<import("@medusajs/framework/utils").ModelConfigurationsToConfigTemplate<{
7
+ readonly Review: import("@medusajs/framework/utils").DmlEntity<import("@medusajs/framework/utils").DMLEntitySchemaBuilder<{
8
+ id: import("@medusajs/framework/utils").PrimaryKeyModifier<string, import("@medusajs/framework/utils").IdProperty>;
9
+ status: import("@medusajs/framework/utils").EnumProperty<typeof ReviewStatus>;
10
+ rating: import("@medusajs/framework/utils").NumberProperty;
11
+ title: import("@medusajs/framework/utils").NullableModifier<string, import("@medusajs/framework/utils").TextProperty>;
12
+ body: import("@medusajs/framework/utils").TextProperty;
13
+ author_name: import("@medusajs/framework/utils").TextProperty;
14
+ author_email: import("@medusajs/framework/utils").NullableModifier<string, import("@medusajs/framework/utils").TextProperty>;
15
+ product_id: import("@medusajs/framework/utils").NullableModifier<string, import("@medusajs/framework/utils").TextProperty>;
16
+ order_id: import("@medusajs/framework/utils").NullableModifier<string, import("@medusajs/framework/utils").TextProperty>;
17
+ customer_id: import("@medusajs/framework/utils").NullableModifier<string, import("@medusajs/framework/utils").TextProperty>;
18
+ metadata: import("@medusajs/framework/utils").NullableModifier<Record<string, unknown>, import("@medusajs/framework/utils").JSONProperty>;
19
+ activity: import("@medusajs/framework/utils").HasMany<() => import("@medusajs/framework/utils").DmlEntity<import("@medusajs/framework/utils").DMLEntitySchemaBuilder<{
20
+ id: import("@medusajs/framework/utils").PrimaryKeyModifier<string, import("@medusajs/framework/utils").IdProperty>;
21
+ type: import("@medusajs/framework/utils").EnumProperty<typeof ReviewActivityType>;
22
+ user_id: import("@medusajs/framework/utils").TextProperty;
23
+ note: import("@medusajs/framework/utils").NullableModifier<string, import("@medusajs/framework/utils").TextProperty>;
24
+ metadata: import("@medusajs/framework/utils").NullableModifier<Record<string, unknown>, import("@medusajs/framework/utils").JSONProperty>;
25
+ review: import("@medusajs/framework/utils").BelongsTo<() => import("@medusajs/framework/utils").DmlEntity<import("@medusajs/framework/utils").DMLEntitySchemaBuilder</*elided*/ any>, "review">, undefined>;
26
+ }>, "review_activity">>;
27
+ }>, "review">;
28
+ readonly ReviewActivity: import("@medusajs/framework/utils").DmlEntity<import("@medusajs/framework/utils").DMLEntitySchemaBuilder<{
29
+ id: import("@medusajs/framework/utils").PrimaryKeyModifier<string, import("@medusajs/framework/utils").IdProperty>;
30
+ type: import("@medusajs/framework/utils").EnumProperty<typeof ReviewActivityType>;
31
+ user_id: import("@medusajs/framework/utils").TextProperty;
32
+ note: import("@medusajs/framework/utils").NullableModifier<string, import("@medusajs/framework/utils").TextProperty>;
33
+ metadata: import("@medusajs/framework/utils").NullableModifier<Record<string, unknown>, import("@medusajs/framework/utils").JSONProperty>;
34
+ review: import("@medusajs/framework/utils").BelongsTo<() => import("@medusajs/framework/utils").DmlEntity<import("@medusajs/framework/utils").DMLEntitySchemaBuilder<{
35
+ id: import("@medusajs/framework/utils").PrimaryKeyModifier<string, import("@medusajs/framework/utils").IdProperty>;
36
+ status: import("@medusajs/framework/utils").EnumProperty<typeof ReviewStatus>;
37
+ rating: import("@medusajs/framework/utils").NumberProperty;
38
+ title: import("@medusajs/framework/utils").NullableModifier<string, import("@medusajs/framework/utils").TextProperty>;
39
+ body: import("@medusajs/framework/utils").TextProperty;
40
+ author_name: import("@medusajs/framework/utils").TextProperty;
41
+ author_email: import("@medusajs/framework/utils").NullableModifier<string, import("@medusajs/framework/utils").TextProperty>;
42
+ product_id: import("@medusajs/framework/utils").NullableModifier<string, import("@medusajs/framework/utils").TextProperty>;
43
+ order_id: import("@medusajs/framework/utils").NullableModifier<string, import("@medusajs/framework/utils").TextProperty>;
44
+ customer_id: import("@medusajs/framework/utils").NullableModifier<string, import("@medusajs/framework/utils").TextProperty>;
45
+ metadata: import("@medusajs/framework/utils").NullableModifier<Record<string, unknown>, import("@medusajs/framework/utils").JSONProperty>;
46
+ activity: import("@medusajs/framework/utils").HasMany<() => import("@medusajs/framework/utils").DmlEntity<import("@medusajs/framework/utils").DMLEntitySchemaBuilder</*elided*/ any>, "review_activity">>;
47
+ }>, "review">, undefined>;
48
+ }>, "review_activity">;
49
+ }>>;
50
+ export declare class ReviewService extends ReviewService_base {
51
+ protected options_: ReviewModuleOptions;
52
+ constructor(container: any, options?: ReviewModuleOptions);
53
+ getOptions(): ReviewModuleOptions;
54
+ approveReview(id: string, userId: string): Promise<{
55
+ id: string;
56
+ status: ReviewStatus;
57
+ rating: number;
58
+ title: string | null;
59
+ body: string;
60
+ author_name: string;
61
+ author_email: string | null;
62
+ product_id: string | null;
63
+ order_id: string | null;
64
+ customer_id: string | null;
65
+ metadata: Record<string, unknown> | null;
66
+ activity: {
67
+ id: string;
68
+ type: ReviewActivityType;
69
+ user_id: string;
70
+ note: string | null;
71
+ metadata: Record<string, unknown> | null;
72
+ review: /*elided*/ any;
73
+ created_at: Date;
74
+ updated_at: Date;
75
+ deleted_at: Date | null;
76
+ review_id: string;
77
+ }[];
78
+ created_at: Date;
79
+ updated_at: Date;
80
+ deleted_at: Date | null;
81
+ }>;
82
+ rejectReview(id: string, userId: string): Promise<{
83
+ id: string;
84
+ status: ReviewStatus;
85
+ rating: number;
86
+ title: string | null;
87
+ body: string;
88
+ author_name: string;
89
+ author_email: string | null;
90
+ product_id: string | null;
91
+ order_id: string | null;
92
+ customer_id: string | null;
93
+ metadata: Record<string, unknown> | null;
94
+ activity: {
95
+ id: string;
96
+ type: ReviewActivityType;
97
+ user_id: string;
98
+ note: string | null;
99
+ metadata: Record<string, unknown> | null;
100
+ review: /*elided*/ any;
101
+ created_at: Date;
102
+ updated_at: Date;
103
+ deleted_at: Date | null;
104
+ review_id: string;
105
+ }[];
106
+ created_at: Date;
107
+ updated_at: Date;
108
+ deleted_at: Date | null;
109
+ }>;
110
+ addNote(reviewId: string, userId: string, note: string): Promise<{
111
+ id: string;
112
+ type: ReviewActivityType;
113
+ user_id: string;
114
+ note: string | null;
115
+ metadata: Record<string, unknown> | null;
116
+ review: {
117
+ id: string;
118
+ status: ReviewStatus;
119
+ rating: number;
120
+ title: string | null;
121
+ body: string;
122
+ author_name: string;
123
+ author_email: string | null;
124
+ product_id: string | null;
125
+ order_id: string | null;
126
+ customer_id: string | null;
127
+ metadata: Record<string, unknown> | null;
128
+ activity: /*elided*/ any[];
129
+ created_at: Date;
130
+ updated_at: Date;
131
+ deleted_at: Date | null;
132
+ };
133
+ created_at: Date;
134
+ updated_at: Date;
135
+ deleted_at: Date | null;
136
+ review_id: string;
137
+ }>;
138
+ }
139
+ export {};
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ReviewService = void 0;
4
+ const utils_1 = require("@medusajs/framework/utils");
5
+ const review_1 = require("./models/review");
6
+ const review_activity_1 = require("./models/review-activity");
7
+ const review_2 = require("./models/review");
8
+ class ReviewService extends (0, utils_1.MedusaService)({ Review: review_1.Review, ReviewActivity: review_activity_1.ReviewActivity }) {
9
+ constructor(container, options) {
10
+ super(container);
11
+ this.options_ = {
12
+ defaultStatus: options?.defaultStatus ?? review_2.ReviewStatus.PENDING
13
+ };
14
+ }
15
+ getOptions() {
16
+ return this.options_;
17
+ }
18
+ async approveReview(id, userId) {
19
+ const review = await this.updateReviews({ id, status: review_2.ReviewStatus.APPROVED });
20
+ await this.createReviewActivities({
21
+ review_id: id,
22
+ user_id: userId,
23
+ type: review_activity_1.ReviewActivityType.APPROVE
24
+ });
25
+ return review;
26
+ }
27
+ async rejectReview(id, userId) {
28
+ const review = await this.updateReviews({ id, status: review_2.ReviewStatus.REJECTED });
29
+ await this.createReviewActivities({
30
+ review_id: id,
31
+ user_id: userId,
32
+ type: review_activity_1.ReviewActivityType.REJECT
33
+ });
34
+ return review;
35
+ }
36
+ async addNote(reviewId, userId, note) {
37
+ return this.createReviewActivities({
38
+ review_id: reviewId,
39
+ user_id: userId,
40
+ type: review_activity_1.ReviewActivityType.NOTE,
41
+ note
42
+ });
43
+ }
44
+ }
45
+ exports.ReviewService = ReviewService;
46
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic2VydmljZS5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uLy4uLy4uL3NyYy9tb2R1bGVzL3Jldmlldy9zZXJ2aWNlLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7OztBQUFBLHFEQUF5RDtBQUN6RCw0Q0FBd0M7QUFDeEMsOERBQTZFO0FBQzdFLDRDQUE4QztBQU05QyxNQUFhLGFBQWMsU0FBUSxJQUFBLHFCQUFhLEVBQUMsRUFBRSxNQUFNLEVBQU4sZUFBTSxFQUFFLGNBQWMsRUFBZCxnQ0FBYyxFQUFFLENBQUM7SUFHM0UsWUFBWSxTQUFjLEVBQUUsT0FBNkI7UUFDeEQsS0FBSyxDQUFDLFNBQVMsQ0FBQyxDQUFBO1FBQ2hCLElBQUksQ0FBQyxRQUFRLEdBQUc7WUFDZixhQUFhLEVBQUUsT0FBTyxFQUFFLGFBQWEsSUFBSSxxQkFBWSxDQUFDLE9BQU87U0FDN0QsQ0FBQTtJQUNGLENBQUM7SUFFRCxVQUFVO1FBQ1QsT0FBTyxJQUFJLENBQUMsUUFBUSxDQUFBO0lBQ3JCLENBQUM7SUFFRCxLQUFLLENBQUMsYUFBYSxDQUFDLEVBQVUsRUFBRSxNQUFjO1FBQzdDLE1BQU0sTUFBTSxHQUFHLE1BQU0sSUFBSSxDQUFDLGFBQWEsQ0FBQyxFQUFFLEVBQUUsRUFBRSxNQUFNLEVBQUUscUJBQVksQ0FBQyxRQUFRLEVBQUUsQ0FBQyxDQUFBO1FBQzlFLE1BQU0sSUFBSSxDQUFDLHNCQUFzQixDQUFDO1lBQ2pDLFNBQVMsRUFBRSxFQUFFO1lBQ2IsT0FBTyxFQUFFLE1BQU07WUFDZixJQUFJLEVBQUUsb0NBQWtCLENBQUMsT0FBTztTQUNoQyxDQUFDLENBQUE7UUFDRixPQUFPLE1BQU0sQ0FBQTtJQUNkLENBQUM7SUFFRCxLQUFLLENBQUMsWUFBWSxDQUFDLEVBQVUsRUFBRSxNQUFjO1FBQzVDLE1BQU0sTUFBTSxHQUFHLE1BQU0sSUFBSSxDQUFDLGFBQWEsQ0FBQyxFQUFFLEVBQUUsRUFBRSxNQUFNLEVBQUUscUJBQVksQ0FBQyxRQUFRLEVBQUUsQ0FBQyxDQUFBO1FBQzlFLE1BQU0sSUFBSSxDQUFDLHNCQUFzQixDQUFDO1lBQ2pDLFNBQVMsRUFBRSxFQUFFO1lBQ2IsT0FBTyxFQUFFLE1BQU07WUFDZixJQUFJLEVBQUUsb0NBQWtCLENBQUMsTUFBTTtTQUMvQixDQUFDLENBQUE7UUFDRixPQUFPLE1BQU0sQ0FBQTtJQUNkLENBQUM7SUFFRCxLQUFLLENBQUMsT0FBTyxDQUFDLFFBQWdCLEVBQUUsTUFBYyxFQUFFLElBQVk7UUFDM0QsT0FBTyxJQUFJLENBQUMsc0JBQXNCLENBQUM7WUFDbEMsU0FBUyxFQUFFLFFBQVE7WUFDbkIsT0FBTyxFQUFFLE1BQU07WUFDZixJQUFJLEVBQUUsb0NBQWtCLENBQUMsSUFBSTtZQUM3QixJQUFJO1NBQ0osQ0FBQyxDQUFBO0lBQ0gsQ0FBQztDQUNEO0FBMUNELHNDQTBDQyJ9
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2026 Lacey Pevey
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,51 @@
1
+ # medusa-plugin-reviews
2
+
3
+ Product review and rating plugin for Medusa v2 with admin moderation workflow.
4
+
5
+ [Documentation](https://pevey.com/medusa-plugin-reviews)
6
+
7
+ If you are not familiar with Medusa, you can learn more on [the project web site](https://www.medusajs.com/).
8
+
9
+ ## Features
10
+
11
+ - Customer-submitted product reviews with 1-5 star ratings
12
+ - Admin moderation workflow: pending, approved, rejected
13
+ - Bulk approve/reject actions
14
+ - Activity logging for all admin actions and notes
15
+ - Store API with caching (5-minute TTL) for approved reviews
16
+ - Authenticated customers can see their own pending reviews
17
+ - Admin pages for review management with filtering and search
18
+
19
+ ## Installation
20
+
21
+ Inside your medusa backend root folder:
22
+
23
+ ```bash
24
+ yarn add medusa-plugin-reviews
25
+ ```
26
+
27
+ Replace "yarn add" with the correct command for your package manager if you are using (for example) npm, pnpm, or bun.
28
+
29
+ ## Configuration
30
+
31
+ Enable in your `medusa-config.ts` file. Example:
32
+
33
+ ```ts
34
+ module.exports = defineConfig({
35
+ //... other config
36
+ plugins: [
37
+ {
38
+ resolve: 'medusa-plugin-reviews',
39
+ options: {}
40
+ }
41
+ // ... other plugins
42
+ ]
43
+ })
44
+ ```
45
+
46
+ ## Usage
47
+
48
+ - Customers submit reviews via `POST /store/reviews/:productId`.
49
+ - Approved reviews are served via `GET /store/reviews/:productId` with caching.
50
+ - Manage reviews from the Reviews section in the Medusa admin sidebar.
51
+ - Approve or reject reviews individually or in bulk.
package/package.json ADDED
@@ -0,0 +1,88 @@
1
+ {
2
+ "name": "medusa-plugin-ratings",
3
+ "version": "0.1.0",
4
+ "description": "Product review and rating plugin for Medusa v2 with moderation workflow",
5
+ "author": "Lacey Pevey",
6
+ "license": "MIT",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "https://github.com/pevey/medusa-plugins"
10
+ },
11
+ "homepage": "https://pevey.com/medusa-plugin-ratings",
12
+ "files": [
13
+ ".medusa/server"
14
+ ],
15
+ "exports": {
16
+ "./package.json": "./package.json",
17
+ "./admin": {
18
+ "import": "./.medusa/server/src/admin/index.mjs",
19
+ "require": "./.medusa/server/src/admin/index.js",
20
+ "default": "./.medusa/server/src/admin/index.js"
21
+ },
22
+ "./.medusa/server/src/modules/*": {
23
+ "types": "./.medusa/server/src/modules/*/index.d.ts",
24
+ "default": "./.medusa/server/src/modules/*/index.js"
25
+ },
26
+ "./modules/*": {
27
+ "types": "./.medusa/server/src/modules/*/index.d.ts",
28
+ "default": "./.medusa/server/src/modules/*/index.js"
29
+ },
30
+ "./providers/*": {
31
+ "types": "./.medusa/server/src/providers/*/index.d.ts",
32
+ "default": "./.medusa/server/src/providers/*/index.js"
33
+ },
34
+ "./*": {
35
+ "types": "./.medusa/server/src/*.d.ts",
36
+ "default": "./.medusa/server/src/*.js"
37
+ },
38
+ ".": {
39
+ "types": "./.medusa/server/src/modules/review/index.d.ts",
40
+ "default": "./.medusa/server/src/modules/review/index.js"
41
+ }
42
+ },
43
+ "keywords": [
44
+ "medusa-v2",
45
+ "medusa",
46
+ "reviews",
47
+ "ratings",
48
+ "product reviews",
49
+ "moderation"
50
+ ],
51
+ "scripts": {
52
+ "build": "medusa plugin:build",
53
+ "clean:snapshots": "find . -name '.snapshot-*.json' -path '*/migrations/*' -delete",
54
+ "dev": "medusa plugin:develop",
55
+ "prepublishOnly": "medusa plugin:build",
56
+ "test:unit": "TEST_TYPE=unit NODE_OPTIONS=--experimental-vm-modules jest --silent --runInBand --detectOpenHandles --forceExit --passWithNoTests",
57
+ "test:integration:http": "TEST_TYPE=integration:http NODE_OPTIONS=--experimental-vm-modules jest --silent=false --runInBand --detectOpenHandles --forceExit"
58
+ },
59
+ "devDependencies": {
60
+ "@medusajs/admin-sdk": "2.13.6",
61
+ "@medusajs/cli": "2.13.6",
62
+ "@medusajs/framework": "2.13.6",
63
+ "@medusajs/icons": "2.13.6",
64
+ "@medusajs/ui": "4.0.25",
65
+ "@swc/core": "^1.7.28",
66
+ "@swc/jest": "^0.2.39",
67
+ "@types/jest": "^30.0.0",
68
+ "@types/node": "^20.0.0",
69
+ "@types/react": "^18.3.2",
70
+ "@types/react-dom": "^18.2.25",
71
+ "jest": "^29.7.0",
72
+ "prop-types": "^15.8.1",
73
+ "react": "^18.2.0",
74
+ "react-dom": "^18.2.0",
75
+ "ts-node": "^10.9.2",
76
+ "typescript": "^5.6.2",
77
+ "vite": "^5.2.11",
78
+ "yalc": "^1.0.0-pre.53"
79
+ },
80
+ "peerDependencies": {
81
+ "@medusajs/framework": "2.13.6",
82
+ "@medusajs/js-sdk": "2.13.6",
83
+ "@medusajs/medusa": "2.13.6"
84
+ },
85
+ "engines": {
86
+ "node": ">=20"
87
+ }
88
+ }