@unchainedshop/core-enrollments 3.0.0-alpha7 → 3.0.0-rc.11
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/lib/addToDate.d.ts +2 -0
- package/lib/addToDate.d.ts.map +1 -0
- package/lib/addToDate.js +39 -0
- package/lib/addToDate.js.map +1 -0
- package/lib/db/EnrollmentsCollection.d.ts +50 -1
- package/lib/db/EnrollmentsCollection.d.ts.map +1 -1
- package/lib/db/EnrollmentsCollection.js +7 -0
- package/lib/db/EnrollmentsCollection.js.map +1 -1
- package/lib/enrollments-index.d.ts +2 -4
- package/lib/enrollments-index.d.ts.map +1 -1
- package/lib/enrollments-index.js +2 -4
- package/lib/enrollments-index.js.map +1 -1
- package/lib/enrollments-settings.d.ts +3 -3
- package/lib/enrollments-settings.d.ts.map +1 -1
- package/lib/enrollments-settings.js.map +1 -1
- package/lib/module/configureEnrollmentsModule.d.ts +41 -54
- package/lib/module/configureEnrollmentsModule.d.ts.map +1 -1
- package/lib/module/configureEnrollmentsModule.js +22 -143
- package/lib/module/configureEnrollmentsModule.js.map +1 -1
- package/package.json +14 -14
- package/src/addToDate.ts +58 -0
- package/src/db/EnrollmentsCollection.ts +49 -1
- package/src/enrollments-index.ts +2 -6
- package/src/enrollments-settings.ts +2 -3
- package/src/module/buildFindSelector.test.ts +1 -1
- package/src/module/configureEnrollmentsModule.ts +77 -339
- package/tsconfig.json +5 -7
- package/lib/db/EnrollmentStatus.d.ts +0 -7
- package/lib/db/EnrollmentStatus.d.ts.map +0 -1
- package/lib/db/EnrollmentStatus.js +0 -8
- package/lib/db/EnrollmentStatus.js.map +0 -1
- package/lib/director/EnrollmentAdapter.d.ts +0 -7
- package/lib/director/EnrollmentAdapter.d.ts.map +0 -1
- package/lib/director/EnrollmentAdapter.js +0 -73
- package/lib/director/EnrollmentAdapter.js.map +0 -1
- package/lib/director/EnrollmentDirector.d.ts +0 -3
- package/lib/director/EnrollmentDirector.d.ts.map +0 -1
- package/lib/director/EnrollmentDirector.js +0 -46
- package/lib/director/EnrollmentDirector.js.map +0 -1
- package/lib/director/EnrollmentError.d.ts +0 -7
- package/lib/director/EnrollmentError.d.ts.map +0 -1
- package/lib/director/EnrollmentError.js +0 -8
- package/lib/director/EnrollmentError.js.map +0 -1
- package/lib/types.d.ts +0 -100
- package/lib/types.d.ts.map +0 -1
- package/lib/types.js +0 -8
- package/lib/types.js.map +0 -1
- package/src/db/EnrollmentStatus.ts +0 -6
- package/src/director/EnrollmentAdapter.ts +0 -82
- package/src/director/EnrollmentDirector.ts +0 -60
- package/src/director/EnrollmentError.ts +0 -6
- package/src/module/periodForReferenceDate.test.ts +0 -23
- package/src/types.ts +0 -113
package/package.json
CHANGED
|
@@ -1,16 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@unchainedshop/core-enrollments",
|
|
3
|
-
"version": "3.0.0-
|
|
3
|
+
"version": "3.0.0-rc.11",
|
|
4
4
|
"main": "lib/enrollments-index.js",
|
|
5
|
-
"exports": {
|
|
6
|
-
".": "./lib/enrollments-index.js",
|
|
7
|
-
"./*": "./lib/*"
|
|
8
|
-
},
|
|
9
5
|
"types": "lib/enrollments-index.d.ts",
|
|
10
6
|
"type": "module",
|
|
11
7
|
"scripts": {
|
|
12
|
-
"clean": "
|
|
13
|
-
"
|
|
8
|
+
"clean": "tsc -b --clean",
|
|
9
|
+
"build": "tsc -b",
|
|
10
|
+
"prepublishOnly": "npm run clean && npm run build",
|
|
14
11
|
"watch": "tsc -w",
|
|
15
12
|
"test": "NODE_OPTIONS=--experimental-vm-modules jest --detectOpenHandles --forceExit",
|
|
16
13
|
"test:watch": "NODE_OPTIONS=--experimental-vm-modules jest --watch --detectOpenHandles --forceExit"
|
|
@@ -24,7 +21,10 @@
|
|
|
24
21
|
"ecommerce",
|
|
25
22
|
"core"
|
|
26
23
|
],
|
|
27
|
-
"
|
|
24
|
+
"authors": [
|
|
25
|
+
"Joël Meiller",
|
|
26
|
+
"Pascal Kaufmann"
|
|
27
|
+
],
|
|
28
28
|
"license": "EUPL-1.2",
|
|
29
29
|
"bugs": {
|
|
30
30
|
"url": "https://github.com/unchainedshop/unchained/issues"
|
|
@@ -32,15 +32,15 @@
|
|
|
32
32
|
"homepage": "https://github.com/unchainedshop/unchained#readme",
|
|
33
33
|
"dependencies": {
|
|
34
34
|
"@breejs/later": "^4.2.0",
|
|
35
|
-
"@unchainedshop/events": "^3.0.0-
|
|
36
|
-
"@unchainedshop/logger": "^3.0.0-
|
|
37
|
-
"@unchainedshop/utils": "^3.0.0-
|
|
38
|
-
"date-fns": "^4.1.0"
|
|
35
|
+
"@unchainedshop/events": "^3.0.0-rc.11",
|
|
36
|
+
"@unchainedshop/logger": "^3.0.0-rc.11",
|
|
37
|
+
"@unchainedshop/utils": "^3.0.0-rc.11"
|
|
39
38
|
},
|
|
40
39
|
"devDependencies": {
|
|
41
|
-
"@types/
|
|
40
|
+
"@types/breejs__later": "^4.1.5",
|
|
41
|
+
"@types/node": "^22.10.2",
|
|
42
42
|
"jest": "^29.7.0",
|
|
43
43
|
"ts-jest": "^29.2.5",
|
|
44
|
-
"typescript": "^5.
|
|
44
|
+
"typescript": "^5.7.2"
|
|
45
45
|
}
|
|
46
46
|
}
|
package/src/addToDate.ts
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/* eslint-disable */
|
|
2
|
+
// @ts-nocheck
|
|
3
|
+
|
|
4
|
+
/* esm.sh - esbuild bundle(date-fns@4.1.0/add) es2022 production */
|
|
5
|
+
const F = Math.pow(10, 8) * 24 * 60 * 60 * 1e3,
|
|
6
|
+
b = -F;
|
|
7
|
+
const N = 3600;
|
|
8
|
+
const a = N * 24,
|
|
9
|
+
k = a * 7,
|
|
10
|
+
Y = a * 365.2425,
|
|
11
|
+
T = Y / 12,
|
|
12
|
+
w = T * 3,
|
|
13
|
+
p = Symbol.for('constructDateFrom');
|
|
14
|
+
function r(t, o) {
|
|
15
|
+
return typeof t == 'function'
|
|
16
|
+
? t(o)
|
|
17
|
+
: t && typeof t == 'object' && p in t
|
|
18
|
+
? t[p](o)
|
|
19
|
+
: t instanceof Date // @ts-ignore
|
|
20
|
+
? new t.constructor(o)
|
|
21
|
+
: new Date(o);
|
|
22
|
+
}
|
|
23
|
+
function c(t, o) {
|
|
24
|
+
return r(o || t, t);
|
|
25
|
+
}
|
|
26
|
+
function f(t, o, e) {
|
|
27
|
+
const n = c(t, e?.in);
|
|
28
|
+
return isNaN(o) ? r(e?.in || t, NaN) : (o && n.setDate(n.getDate() + o), n);
|
|
29
|
+
}
|
|
30
|
+
function x(t, o, e) {
|
|
31
|
+
const n = c(t, e?.in);
|
|
32
|
+
if (isNaN(o)) return r(e?.in || t, NaN);
|
|
33
|
+
if (!o) return n;
|
|
34
|
+
const i = n.getDate(),
|
|
35
|
+
s = r(e?.in || t, n.getTime());
|
|
36
|
+
s.setMonth(n.getMonth() + o + 1, 0);
|
|
37
|
+
const m = s.getDate();
|
|
38
|
+
return i >= m ? s : (n.setFullYear(s.getFullYear(), s.getMonth(), i), n);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export function addToDate(t, o, e?: any) {
|
|
42
|
+
let {
|
|
43
|
+
years: n = 0,
|
|
44
|
+
months: i = 0,
|
|
45
|
+
weeks: s = 0,
|
|
46
|
+
days: m = 0,
|
|
47
|
+
hours: I = 0,
|
|
48
|
+
minutes: l = 0,
|
|
49
|
+
seconds: h = 0,
|
|
50
|
+
} = o,
|
|
51
|
+
u = c(t, e?.in),
|
|
52
|
+
d = i || n ? x(u, i + n * 12) : u,
|
|
53
|
+
y = m || s ? f(d, m + s * 7) : d,
|
|
54
|
+
D = l + I * 60,
|
|
55
|
+
M = (h + D * 60) * 1e3;
|
|
56
|
+
return r(e?.in || t, +y + M);
|
|
57
|
+
}
|
|
58
|
+
//# sourceMappingURL=add.js.map
|
|
@@ -1,5 +1,53 @@
|
|
|
1
1
|
import { mongodb, buildDbIndexes } from '@unchainedshop/mongodb';
|
|
2
|
-
import {
|
|
2
|
+
import { TimestampFields, LogFields, Address, Contact } from '@unchainedshop/mongodb';
|
|
3
|
+
|
|
4
|
+
export interface EnrollmentPeriod {
|
|
5
|
+
start: Date;
|
|
6
|
+
end: Date;
|
|
7
|
+
orderId?: string;
|
|
8
|
+
isTrial?: boolean;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export interface EnrollmentPlan {
|
|
12
|
+
configuration: Array<{ key: string; value: string }>;
|
|
13
|
+
productId: string;
|
|
14
|
+
quantity: number;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export enum EnrollmentStatus {
|
|
18
|
+
INITIAL = 'INITIAL',
|
|
19
|
+
ACTIVE = 'ACTIVE',
|
|
20
|
+
PAUSED = 'PAUSED',
|
|
21
|
+
TERMINATED = 'TERMINATED',
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export type Enrollment = {
|
|
25
|
+
_id?: string;
|
|
26
|
+
billingAddress: Address;
|
|
27
|
+
configuration?: Array<{ key: string; value: string }>;
|
|
28
|
+
contact: Contact;
|
|
29
|
+
context?: any;
|
|
30
|
+
countryCode?: string;
|
|
31
|
+
currencyCode?: string;
|
|
32
|
+
delivery: {
|
|
33
|
+
deliveryProviderId?: string;
|
|
34
|
+
context?: any;
|
|
35
|
+
};
|
|
36
|
+
enrollmentNumber?: string;
|
|
37
|
+
orderIdForFirstPeriod?: string;
|
|
38
|
+
expires?: Date;
|
|
39
|
+
meta?: any;
|
|
40
|
+
payment: {
|
|
41
|
+
paymentProviderId?: string;
|
|
42
|
+
context?: any;
|
|
43
|
+
};
|
|
44
|
+
periods: Array<EnrollmentPeriod>;
|
|
45
|
+
productId: string;
|
|
46
|
+
quantity?: number;
|
|
47
|
+
status: EnrollmentStatus;
|
|
48
|
+
userId: string;
|
|
49
|
+
} & LogFields &
|
|
50
|
+
TimestampFields;
|
|
3
51
|
|
|
4
52
|
export const EnrollmentsCollection = async (db: mongodb.Db) => {
|
|
5
53
|
const Enrollments = db.collection<Enrollment>('enrollments');
|
package/src/enrollments-index.ts
CHANGED
|
@@ -1,8 +1,4 @@
|
|
|
1
|
-
export * from './
|
|
1
|
+
export * from './db/EnrollmentsCollection.js';
|
|
2
2
|
export * from './module/configureEnrollmentsModule.js';
|
|
3
3
|
export * from './enrollments-settings.js';
|
|
4
|
-
|
|
5
|
-
export { EnrollmentAdapter } from './director/EnrollmentAdapter.js';
|
|
6
|
-
export { EnrollmentDirector } from './director/EnrollmentDirector.js';
|
|
7
|
-
|
|
8
|
-
export { EnrollmentStatus } from './db/EnrollmentStatus.js';
|
|
4
|
+
export * from './addToDate.js';
|
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
import later from '@breejs/later';
|
|
2
|
-
import { WorkerSchedule } from '@unchainedshop/core-worker';
|
|
3
2
|
import { generateRandomHash } from '@unchainedshop/utils';
|
|
4
|
-
import { Enrollment } from './
|
|
3
|
+
import { Enrollment } from './db/EnrollmentsCollection.js';
|
|
5
4
|
|
|
6
5
|
const everyHourSchedule = later.parse.text('every 59 minutes');
|
|
7
6
|
|
|
8
7
|
export interface EnrollmentsSettingsOptions {
|
|
9
|
-
autoSchedulingSchedule?:
|
|
8
|
+
autoSchedulingSchedule?: later.ScheduleData;
|
|
10
9
|
enrollmentNumberHashFn?: (enrollment: Enrollment, index: number) => string;
|
|
11
10
|
}
|
|
12
11
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { EnrollmentStatus } from '@unchainedshop/core-enrollments';
|
|
2
1
|
import { buildFindSelector } from './configureEnrollmentsModule.js';
|
|
2
|
+
import { EnrollmentStatus } from '../db/EnrollmentsCollection.js';
|
|
3
3
|
|
|
4
4
|
describe('buildFindSelector', () => {
|
|
5
5
|
it('Should correct filter when passed status, userId and queryString', () => {
|