@unchainedshop/core-enrollments 5.0.0-alpha.5 → 5.0.0-alpha.8
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/README.md
CHANGED
|
@@ -13,97 +13,21 @@ npm install @unchainedshop/core-enrollments
|
|
|
13
13
|
|
|
14
14
|
## Usage
|
|
15
15
|
|
|
16
|
-
|
|
17
|
-
import { configureEnrollmentsModule, EnrollmentStatus } from '@unchainedshop/core-enrollments';
|
|
16
|
+
The platform initializes this module as `platform.unchainedAPI.modules.enrollments`.
|
|
18
17
|
|
|
19
|
-
|
|
18
|
+
```typescript
|
|
19
|
+
import { EnrollmentStatus } from '@unchainedshop/core-enrollments';
|
|
20
20
|
|
|
21
|
-
|
|
22
|
-
const
|
|
21
|
+
const { enrollments } = platform.unchainedAPI.modules;
|
|
22
|
+
const activeEnrollments = await enrollments.findEnrollments({
|
|
23
|
+
status: [EnrollmentStatus.ACTIVE],
|
|
23
24
|
userId: 'user-123',
|
|
24
|
-
productId: 'plan-product-456',
|
|
25
|
-
quantity: 1,
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
// Activate enrollment
|
|
29
|
-
await enrollmentsModule.activate(enrollmentId);
|
|
30
|
-
|
|
31
|
-
// Find active enrollments
|
|
32
|
-
const enrollments = await enrollmentsModule.findEnrollments({
|
|
33
|
-
status: EnrollmentStatus.ACTIVE,
|
|
34
25
|
});
|
|
35
26
|
```
|
|
36
27
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
### Module Configuration
|
|
40
|
-
|
|
41
|
-
| Export | Description |
|
|
42
|
-
|--------|-------------|
|
|
43
|
-
| `configureEnrollmentsModule` | Configure and return the enrollments module |
|
|
44
|
-
|
|
45
|
-
### Queries
|
|
46
|
-
|
|
47
|
-
| Method | Description |
|
|
48
|
-
|--------|-------------|
|
|
49
|
-
| `findEnrollment` | Find enrollment by ID |
|
|
50
|
-
| `findEnrollments` | Find enrollments with filtering and pagination |
|
|
51
|
-
| `count` | Count enrollments matching query |
|
|
52
|
-
| `enrollmentExists` | Check if enrollment exists |
|
|
53
|
-
|
|
54
|
-
### Mutations
|
|
55
|
-
|
|
56
|
-
| Method | Description |
|
|
57
|
-
|--------|-------------|
|
|
58
|
-
| `create` | Create a new enrollment |
|
|
59
|
-
| `update` | Update enrollment data |
|
|
60
|
-
| `delete` | Delete an enrollment |
|
|
61
|
-
| `activate` | Activate an enrollment |
|
|
62
|
-
| `terminate` | Terminate an enrollment |
|
|
63
|
-
|
|
64
|
-
### Period Management
|
|
65
|
-
|
|
66
|
-
| Method | Description |
|
|
67
|
-
|--------|-------------|
|
|
68
|
-
| `addPeriod` | Add a billing period |
|
|
69
|
-
| `findPeriod` | Find a specific period |
|
|
70
|
-
| `isExpired` | Check if enrollment is expired |
|
|
71
|
-
|
|
72
|
-
### Utilities
|
|
73
|
-
|
|
74
|
-
| Export | Description |
|
|
75
|
-
|--------|-------------|
|
|
76
|
-
| `addToDate` | Add time interval to date |
|
|
77
|
-
|
|
78
|
-
### Constants
|
|
79
|
-
|
|
80
|
-
| Export | Description |
|
|
81
|
-
|--------|-------------|
|
|
82
|
-
| `EnrollmentStatus` | Status values (INITIAL, ACTIVE, PAUSED, TERMINATED) |
|
|
83
|
-
|
|
84
|
-
### Settings
|
|
85
|
-
|
|
86
|
-
| Export | Description |
|
|
87
|
-
|--------|-------------|
|
|
88
|
-
| `enrollmentsSettings` | Access enrollment module settings |
|
|
89
|
-
|
|
90
|
-
### Types
|
|
91
|
-
|
|
92
|
-
| Export | Description |
|
|
93
|
-
|--------|-------------|
|
|
94
|
-
| `Enrollment` | Enrollment document type |
|
|
95
|
-
| `EnrollmentPeriod` | Period document type |
|
|
96
|
-
| `EnrollmentsModule` | Module interface type |
|
|
97
|
-
|
|
98
|
-
## Events
|
|
28
|
+
Status filters accept arrays. Enrollment lifecycle operations and recurring order generation are coordinated by `unchainedAPI.services.enrollments` and the registered enrollment and worker plugins. The module stores enrollments and their periods (`addEnrollmentPeriod`).
|
|
99
29
|
|
|
100
|
-
|
|
101
|
-
|-------|-------------|
|
|
102
|
-
| `ENROLLMENT_CREATE` | Enrollment created |
|
|
103
|
-
| `ENROLLMENT_UPDATE` | Enrollment updated |
|
|
104
|
-
| `ENROLLMENT_REMOVE` | Enrollment deleted |
|
|
105
|
-
| `ENROLLMENT_ACTIVATE` | Enrollment activated |
|
|
106
|
-
| `ENROLLMENT_TERMINATE` | Enrollment terminated |
|
|
30
|
+
See the [module guide](https://docs.unchained.shop/platform-configuration/modules/enrollments), [public exports](src/enrollments-index.ts), and [module implementation](src/module/configureEnrollmentsModule.ts).
|
|
107
31
|
|
|
108
32
|
## License
|
|
109
33
|
|
|
@@ -18,6 +18,9 @@ export declare const configureEnrollmentsModule: ({ db, migrationRepository, opt
|
|
|
18
18
|
} | {
|
|
19
19
|
orderId: string;
|
|
20
20
|
}, options?: mongodb.FindOptions) => Promise<Enrollment | null>;
|
|
21
|
+
findEnrollmentsByOrderIds: ({ orderIds }: {
|
|
22
|
+
orderIds: string[];
|
|
23
|
+
}, options?: mongodb.FindOptions) => Promise<Enrollment[]>;
|
|
21
24
|
findEnrollments: ({ limit, offset, sort, ...query }: EnrollmentQuery & {
|
|
22
25
|
limit?: number;
|
|
23
26
|
offset?: number;
|
|
@@ -111,6 +111,11 @@ export const configureEnrollmentsModule = async ({ db, migrationRepository, opti
|
|
|
111
111
|
}
|
|
112
112
|
return Enrollments.findOne({ 'periods.orderId': params.orderId, deleted: null }, options);
|
|
113
113
|
},
|
|
114
|
+
findEnrollmentsByOrderIds: async ({ orderIds }, options) => {
|
|
115
|
+
if (!orderIds?.length)
|
|
116
|
+
return [];
|
|
117
|
+
return Enrollments.find({ 'periods.orderId': { $in: orderIds }, deleted: null }, options).toArray();
|
|
118
|
+
},
|
|
114
119
|
findEnrollments: async ({ limit, offset, sort, ...query }) => {
|
|
115
120
|
const defaultSortOption = [{ key: 'created', value: SortDirection.ASC }];
|
|
116
121
|
const enrollments = Enrollments.find(buildFindSelector(query), {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@unchainedshop/core-enrollments",
|
|
3
3
|
"description": "Subscription and recurring billing module for the Unchained Engine",
|
|
4
|
-
"version": "5.0.0-alpha.
|
|
4
|
+
"version": "5.0.0-alpha.8",
|
|
5
5
|
"main": "lib/enrollments-index.js",
|
|
6
6
|
"types": "lib/enrollments-index.d.ts",
|
|
7
7
|
"type": "module",
|
|
@@ -35,9 +35,9 @@
|
|
|
35
35
|
},
|
|
36
36
|
"homepage": "https://github.com/unchainedshop/unchained#readme",
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@unchainedshop/events": "^5.0.0-alpha.
|
|
39
|
-
"@unchainedshop/mongodb": "^5.0.0-alpha.
|
|
40
|
-
"@unchainedshop/utils": "^5.0.0-alpha.
|
|
38
|
+
"@unchainedshop/events": "^5.0.0-alpha.8",
|
|
39
|
+
"@unchainedshop/mongodb": "^5.0.0-alpha.8",
|
|
40
|
+
"@unchainedshop/utils": "^5.0.0-alpha.8"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
43
|
"@types/node": "^26.2.0",
|