mumz-strapi-plugin-coupon 1.1.0 → 1.1.1

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 (2) hide show
  1. package/README.md +13 -302
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -1,311 +1,22 @@
1
- # Strapi Plugin - Coupon Management
2
-
1
+ #Strapi Plugin - Coupon Management
3
2
  A centralized coupon management system for Strapi that handles validation, redemption, and tracking across multiple service domains.
4
3
 
5
4
  ## Requirements
6
-
7
5
  - Strapi 5.0.0 or higher
8
6
  - Node.js 18.0.0 or higher
9
7
  - npm 6.0.0 or higher
10
8
  - PostgreSQL, MySQL, or SQLite
11
9
 
12
10
  ## Features
13
-
14
- - Centralized coupon creation and management
15
- - Cross-domain coupon support (Homecare, Nannies, Gear Refresh, etc.)
16
- - Flexible discount types (percentage, flat)
17
- - Usage limits and validity periods
18
- - User eligibility validation
19
- - Service-specific applicability
20
- - Complete redemption audit trail
21
- - RESTful API endpoints
22
- - Race condition protection for concurrent redemptions
23
- - Input validation and sanitization
24
- - Rate limiting on public endpoints
25
- - ✅ TypeScript support with full type definitions
26
-
27
- ## Installation
28
-
29
- ### Using npm (via GitHub)
30
-
31
- ```bash
32
- npm install github:mumzworld-tech/mumz-services-coupons-strapi-plugin
33
- ```
34
-
35
- ### Using yarn (via GitHub)
36
-
37
- ```bash
38
- yarn add github:mumzworld-tech/mumz-services-coupons-strapi-plugin
39
- ```
40
-
41
- ## Configuration
42
-
43
- Add the plugin to your Strapi configuration:
44
-
45
- **`config/plugins.js`** or **`config/plugins.ts`**:
46
-
47
- ```javascript
48
- module.exports = {
49
- 'coupon': {
50
- enabled: true,
51
- resolve: './node_modules/mumz-strapi-plugin-coupon'
52
- },
53
- };
54
- ```
55
-
56
- ## API Endpoints
57
-
58
- ### 1. Validate Coupon
59
-
60
- **POST** `/api/coupon/validate`
61
-
62
- Validates a coupon for a user before applying it.
63
-
64
- **Request Body:**
65
- ```json
66
- {
67
- "couponCode": "WELCOME10",
68
- "phoneNumber": "+97155XXXXXX",
69
- "orderAmount": 250.00
70
- }
71
- ```
72
-
73
- **Success Response:**
74
- ```json
75
- {
76
- "isValid": true,
77
- "discountType": "percentage",
78
- "discountValue": 10,
79
- "discountAmount": 25,
80
- "finalAmount": 225.00,
81
- "message": "Coupon applied successfully."
82
- }
83
- ```
84
-
85
- **Error Response:**
86
- ```json
87
- {
88
- "isValid": false,
89
- "errorCode": "COUPON_EXPIRED",
90
- "message": "This coupon has expired."
91
- }
92
- ```
93
-
94
- ### 2. Redeem Coupon
95
-
96
- **POST** `/api/coupon/redeem`
97
-
98
- Marks a coupon as redeemed once successfully applied.
99
-
100
- **Request Body:**
101
- ```json
102
- {
103
- "couponCode": "WELCOME10",
104
- "phoneNumber": "+97155XXXXXX",
105
- "orderId": "order_67890",
106
- "orderAmount": 250.00
107
- }
108
- ```
109
-
110
- **Response:**
111
- ```json
112
- {
113
- "success": true,
114
- "message": "Coupon redeemed successfully.",
115
- "redemptionId": "redeem_1"
116
- }
117
- ```
118
-
119
- ### 3. Create Coupon (No Auth Required)
120
-
121
- **POST** `/api/coupon`
122
-
123
- Create new coupons. Authentication has been disabled for easier integration.
124
-
125
- **Request Body:**
126
- ```json
127
- {
128
- "code": "SUMMER25",
129
- "discountType": "flat",
130
- "discountValue": 25,
131
- "maxUsage": 1000,
132
- "validFrom": "2025-05-01T00:00:00Z",
133
- "validTo": "2025-06-30T23:59:59Z"
134
- }
135
- ```
136
-
137
- **Response:**
138
- ```json
139
- {
140
- "couponId": "coupon_abc123",
141
- "message": "Coupon created successfully."
142
- }
143
- ```
144
-
145
- ## Error Codes
146
-
147
- | Code | Description |
148
- |------|-------------|
149
- | `COUPON_NOT_FOUND` | Coupon code does not exist |
150
- | `COUPON_EXPIRED` | Coupon validity period has expired |
151
- | `COUPON_ALREADY_USED` | User has already redeemed this coupon |
152
- | `USAGE_LIMIT_REACHED` | Coupon usage limit has been reached |
153
-
154
- ## Quick Start
155
-
156
- ### 1. Installation
157
-
158
- See [INSTALLATION.md](./INSTALLATION.md) for detailed installation instructions.
159
-
160
- ```bash
161
- # Install from GitHub
162
- npm install github:mumzworld-tech/mumz-services-coupons-strapi-plugin#v1.0.0
163
-
164
- # Configure in config/plugins.js
165
- module.exports = {
166
- 'coupon': {
167
- enabled: true,
168
- resolve: './node_modules/mumz-strapi-plugin-coupon',
169
- },
170
- };
171
-
172
- # Build and start Strapi
173
- npm run build
174
- npm run develop
175
- ```
176
-
177
- ### 2. Verify Installation
178
-
179
- Check that the plugin loaded successfully:
180
- - Admin panel shows **Coupon** and **Redemption** content types
181
- - Routes are registered: `npx strapi routes:list | grep coupon`
182
- - See console logs: "Coupon plugin registered" and "Coupon plugin bootstrapped"
183
-
184
- ### 3. Test the Plugin
185
-
186
- See [TESTING.md](./TESTING.md) for comprehensive testing instructions.
187
-
188
- ```bash
189
- # Create a test coupon via API
190
- curl -X POST http://localhost:1337/api/coupon \
191
- -H "Content-Type: application/json" \
192
- -d '{
193
- "code": "WELCOME10",
194
- "discountType": "percentage",
195
- "discountValue": 10,
196
- "maxUsage": 1000,
197
- "validFrom": "2025-01-01T00:00:00Z",
198
- "validTo": "2025-12-31T23:59:59Z",
199
- "description": "Welcome discount - 10% off"
200
- }'
201
-
202
- # Validate the coupon
203
- curl -X POST http://localhost:1337/api/coupon/validate \
204
- -H "Content-Type: application/json" \
205
- -d '{
206
- "couponCode": "WELCOME10",
207
- "phoneNumber": "+971551234567",
208
- "orderAmount": 250.00
209
- }'
210
- ```
211
-
212
- ## Development
213
-
214
- ### Prerequisites
215
-
216
- - Node.js >= 18.x
217
- - npm >= 6.x
218
-
219
- ### Setup
220
-
221
- ```bash
222
- # Install dependencies
223
- npm install
224
-
225
- # Build the plugin
226
- npm run build
227
-
228
- # Watch mode for development
229
- npm run watch
230
- ```
231
-
232
- ### Building for Production
233
-
234
- ```bash
235
- npm run clean
236
- npm run build
237
- ```
238
-
239
- ## Publishing to GitHub
240
-
241
- See [PUBLISHING.md](./PUBLISHING.md) for detailed instructions on publishing this plugin internally via GitHub.
242
-
243
- ## TypeScript Usage
244
-
245
- The plugin is written in TypeScript and provides full type definitions:
246
-
247
- ```typescript
248
- import type {
249
- ValidateCouponRequest,
250
- ValidationResponse,
251
- RedeemCouponRequest,
252
- RedemptionResponse,
253
- CreateCouponRequest,
254
- CreateResponse
255
- } from 'strapi-plugin-coupon/dist/services/coupon';
256
-
257
- // Example: Validate a coupon
258
- const result: ValidationResponse = await strapi
259
- .plugin('coupon')
260
- .service('coupon')
261
- .validate({
262
- couponCode: 'WELCOME10',
263
- service: 'homecare',
264
- phoneNumber: '+971551234567',
265
- orderAmount: 250.00,
266
- });
267
-
268
- if (result.isValid) {
269
- console.log(`Discount: ${result.discountAmount}`);
270
- console.log(`Final Amount: ${result.finalAmount}`);
271
- }
272
- ```
273
-
274
- ## Rate Limiting
275
-
276
- The plugin implements rate limiting on public endpoints:
277
- - `/validate`: 10 requests per minute per IP
278
- - `/redeem`: 5 requests per minute per IP
279
-
280
- The plugin uses in-memory rate limiting which is suitable for single-instance deployments.
281
-
282
- ## Security Features
283
-
284
- - ✅ Input validation on all endpoints
285
- - ✅ Protection against SQL injection
286
- - ✅ Race condition prevention using optimistic locking
287
- - ✅ Phone number validation (E.164 format)
288
- - ✅ Service and coupon code validation
289
- - ✅ Rate limiting to prevent abuse
290
-
291
- ## Troubleshooting
292
-
293
- ### Build fails with TypeScript errors
294
-
295
- Ensure dependencies are installed:
296
- ```bash
297
- npm install
298
- npm run build
299
- ```
300
-
301
- ### Plugin not loading in Strapi
302
-
303
- Verify the plugin configuration in `config/plugins.js` and ensure the plugin is properly installed in `node_modules`.
304
-
305
- ### Rate limit errors (429)
306
-
307
- Default rate limits are 10 req/min for validate, 5 req/min for redeem. These can be adjusted in the route configuration.
308
-
309
- ## License
310
-
311
- MIT
11
+ ✅ Centralized coupon creation and management
12
+ Cross-domain coupon support (Homecare, Nannies, Gear Refresh, etc.)
13
+ Flexible discount types (percentage, flat)
14
+ Usage limits and validity periods
15
+ User eligibility validation
16
+ Service-specific applicability
17
+ Complete redemption audit trail
18
+ RESTful API endpoints
19
+ Race condition protection for concurrent redemptions
20
+ Input validation and sanitization
21
+ Rate limiting on public endpoints
22
+ TypeScript support with full type definitions
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mumz-strapi-plugin-coupon",
3
- "version": "1.1.0",
3
+ "version": "1.1.1",
4
4
  "description": "Strapi plugin for centralized coupon management across multiple services",
5
5
  "strapi": {
6
6
  "name": "coupon",