@unchainedshop/core-events 2.17.0 → 2.18.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.
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
import { ModuleCreateMutation, ModuleInput } from '@unchainedshop/types/core.js';
|
|
4
|
-
import { Event } from '../db/EventsCollection.js';
|
|
5
|
-
import { EventReport } from '@unchainedshop/types/events.js';
|
|
1
|
+
import { ModuleInput } from '@unchainedshop/types/core.js';
|
|
2
|
+
import { EventsModule } from '@unchainedshop/types/events.js';
|
|
6
3
|
export type EventQuery = {
|
|
7
4
|
types?: Array<string>;
|
|
8
5
|
queryString?: string;
|
|
@@ -13,22 +10,5 @@ export declare const buildFindSelector: ({ types, queryString, created }: EventQ
|
|
|
13
10
|
$text?: any;
|
|
14
11
|
created?: any;
|
|
15
12
|
};
|
|
16
|
-
export interface EventsModule extends ModuleCreateMutation<Event> {
|
|
17
|
-
findEvent: (params: mongodb.Filter<Event> & {
|
|
18
|
-
eventId: string;
|
|
19
|
-
}, options?: mongodb.FindOptions) => Promise<Event>;
|
|
20
|
-
findEvents: (params: EventQuery & {
|
|
21
|
-
limit?: number;
|
|
22
|
-
offset?: number;
|
|
23
|
-
sort?: Array<SortOption>;
|
|
24
|
-
}, options?: mongodb.FindOptions) => Promise<Array<Event>>;
|
|
25
|
-
type: (event: Event) => string;
|
|
26
|
-
count: (query: EventQuery) => Promise<number>;
|
|
27
|
-
getReport: (params?: {
|
|
28
|
-
from?: Date;
|
|
29
|
-
to?: Date;
|
|
30
|
-
types?: string[];
|
|
31
|
-
}) => Promise<EventReport[]>;
|
|
32
|
-
}
|
|
33
13
|
export declare const configureEventsModule: ({ db, }: ModuleInput<Record<string, never>>) => Promise<EventsModule>;
|
|
34
14
|
//# sourceMappingURL=configureEventsModule.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"configureEventsModule.d.ts","sourceRoot":"","sources":["../../src/module/configureEventsModule.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"configureEventsModule.d.ts","sourceRoot":"","sources":["../../src/module/configureEventsModule.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,WAAW,EAAmB,MAAM,8BAA8B,CAAC;AAI5E,OAAO,EAAe,YAAY,EAAE,MAAM,gCAAgC,CAAC;AAE3E,MAAM,MAAM,UAAU,GAAG;IACvB,KAAK,CAAC,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;IACtB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,OAAO,CAAC,EAAE,IAAI,CAAC;CAChB,CAAC;AAEF,eAAO,MAAM,iBAAiB,oCAAqC,UAAU;WAClD,GAAG;YAAU,GAAG;cAAY,GAAG;CAMzD,CAAC;AAEF,eAAO,MAAM,qBAAqB,YAE/B,WAAW,CAAC,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC,KAAG,OAAO,CAAC,YAAY,CA8F3D,CAAC"}
|
|
@@ -44,22 +44,22 @@ export const configureEventsModule = async ({ db, }) => {
|
|
|
44
44
|
const count = await Events.countDocuments(buildFindSelector(query));
|
|
45
45
|
return count;
|
|
46
46
|
},
|
|
47
|
-
getReport: async ({
|
|
47
|
+
getReport: async ({ dateRange, types } = { dateRange: {}, types: null }) => {
|
|
48
48
|
const pipeline = [];
|
|
49
49
|
const matchConditions = [];
|
|
50
50
|
// build date filter based on provided values it can be a range if both to and from is supplied
|
|
51
51
|
// a upper or lowe limit if either from or to is provided
|
|
52
52
|
// or all if none is provided
|
|
53
|
-
if (
|
|
53
|
+
if (dateRange?.start || dateRange?.end) {
|
|
54
54
|
const dateConditions = [];
|
|
55
|
-
if (
|
|
56
|
-
const fromDate = new Date(
|
|
55
|
+
if (dateRange?.start) {
|
|
56
|
+
const fromDate = new Date(dateRange?.start);
|
|
57
57
|
dateConditions.push({
|
|
58
58
|
$or: [{ created: { $gte: fromDate } }, { updated: { $gte: fromDate } }],
|
|
59
59
|
});
|
|
60
60
|
}
|
|
61
|
-
if (
|
|
62
|
-
const toDate = new Date(
|
|
61
|
+
if (dateRange?.end) {
|
|
62
|
+
const toDate = new Date(dateRange?.end);
|
|
63
63
|
dateConditions.push({
|
|
64
64
|
$or: [{ created: { $lte: toDate } }, { updated: { $lte: toDate } }],
|
|
65
65
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"configureEventsModule.js","sourceRoot":"","sources":["../../src/module/configureEventsModule.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"configureEventsModule.js","sourceRoot":"","sources":["../../src/module/configureEventsModule.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,mBAAmB,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AACrG,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,EAAE,aAAa,EAAc,MAAM,6BAA6B,CAAC;AAExE,OAAO,EAAE,gBAAgB,EAAS,MAAM,2BAA2B,CAAC;AACpE,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AACrD,OAAO,EAAE,4BAA4B,EAAE,MAAM,mCAAmC,CAAC;AASjF,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,EAAE,KAAK,EAAE,WAAW,EAAE,OAAO,EAAc,EAAE,EAAE;IAC/E,MAAM,QAAQ,GAA+C,EAAE,CAAC;IAEhE,IAAI,KAAK,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;QAAE,QAAQ,CAAC,IAAI,GAAG,EAAE,GAAG,EAAE,KAAK,EAAE,CAAC;IAClE,IAAI,WAAW;QAAE,QAAQ,CAAC,KAAK,GAAG,EAAE,OAAO,EAAE,WAAW,EAAE,CAAC;IAC3D,IAAI,OAAO;QAAE,QAAQ,CAAC,OAAO,GAAG,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC;IAClD,OAAO,QAAQ,CAAC;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GAAG,CAAC,EAAE,CAAC;oBAC9B,eAAe,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,cAAc,EAAE,CAAC,CAAC;gBACjD,CAAC;YACH,CAAC;YACD,+EAA+E;YAC/E,IAAI,KAAK,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,KAAK,CAAC,MAAM,EAAE,CAAC;gBAClD,eAAe,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,EAAE,GAAG,EAAE,KAAK,EAAE,EAAE,CAAC,CAAC;YACjD,CAAC;YACD,IAAI,eAAe,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;gBAC/B,QAAQ,CAAC,IAAI,CAAC;oBACZ,MAAM,EAAE;wBACN,IAAI,EAAE,eAAe;qBACtB;iBACF,CAAC,CAAC;YACL,CAAC;YAED,QAAQ,CAAC,IAAI,CACX,GAAG;gBACD;oBACE,MAAM,EAAE;wBACN,GAAG,EAAE,OAAO;wBACZ,SAAS,EAAE,EAAE,IAAI,EAAE,CAAC,EAAE;qBACvB;iBACF;gBACD;oBACE,QAAQ,EAAE;wBACR,GAAG,EAAE,CAAC;wBACN,IAAI,EAAE,MAAM;wBACZ,SAAS,EAAE,CAAC;qBACb;iBACF;aACF,CACF,CAAC;YAEF,OAAO,MAAM,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC,OAAO,EAA4B,CAAC;QACxE,CAAC;KACF,CAAC;AACJ,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@unchainedshop/core-events",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.18.0",
|
|
4
4
|
"main": "lib/events-index.js",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": "./lib/events-index.js",
|
|
@@ -31,15 +31,15 @@
|
|
|
31
31
|
},
|
|
32
32
|
"homepage": "https://github.com/unchainedshop/unchained#readme",
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@unchainedshop/events": "^2.
|
|
35
|
-
"@unchainedshop/utils": "^2.
|
|
34
|
+
"@unchainedshop/events": "^2.18.0",
|
|
35
|
+
"@unchainedshop/utils": "^2.18.0",
|
|
36
36
|
"simpl-schema": "^3.4.6"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
|
-
"@types/node": "^22.
|
|
40
|
-
"@unchainedshop/types": "^2.
|
|
39
|
+
"@types/node": "^22.10.2",
|
|
40
|
+
"@unchainedshop/types": "^2.18.0",
|
|
41
41
|
"jest": "^29.7.0",
|
|
42
42
|
"ts-jest": "^29.2.5",
|
|
43
|
-
"typescript": "^5.
|
|
43
|
+
"typescript": "^5.7.2"
|
|
44
44
|
}
|
|
45
45
|
}
|
|
@@ -1,13 +1,11 @@
|
|
|
1
|
-
import type { mongodb } from '@unchainedshop/mongodb';
|
|
2
|
-
|
|
3
1
|
import { generateDbFilterById, generateDbMutations, buildSortOptions } from '@unchainedshop/mongodb';
|
|
4
2
|
import { getRegisteredEvents } from '@unchainedshop/events';
|
|
5
3
|
import { SortDirection, SortOption } from '@unchainedshop/types/api.js';
|
|
6
|
-
import {
|
|
4
|
+
import { ModuleInput, ModuleMutations } from '@unchainedshop/types/core.js';
|
|
7
5
|
import { EventsCollection, Event } from '../db/EventsCollection.js';
|
|
8
6
|
import { EventsSchema } from '../db/EventsSchema.js';
|
|
9
7
|
import { configureEventHistoryAdapter } from './configureEventHistoryAdapter.js';
|
|
10
|
-
import { EventReport } from '@unchainedshop/types/events.js';
|
|
8
|
+
import { EventReport, EventsModule } from '@unchainedshop/types/events.js';
|
|
11
9
|
|
|
12
10
|
export type EventQuery = {
|
|
13
11
|
types?: Array<string>;
|
|
@@ -24,27 +22,6 @@ export const buildFindSelector = ({ types, queryString, created }: EventQuery) =
|
|
|
24
22
|
return selector;
|
|
25
23
|
};
|
|
26
24
|
|
|
27
|
-
export interface EventsModule extends ModuleCreateMutation<Event> {
|
|
28
|
-
findEvent: (
|
|
29
|
-
params: mongodb.Filter<Event> & { eventId: string },
|
|
30
|
-
options?: mongodb.FindOptions,
|
|
31
|
-
) => Promise<Event>;
|
|
32
|
-
|
|
33
|
-
findEvents: (
|
|
34
|
-
params: EventQuery & {
|
|
35
|
-
limit?: number;
|
|
36
|
-
offset?: number;
|
|
37
|
-
sort?: Array<SortOption>;
|
|
38
|
-
},
|
|
39
|
-
options?: mongodb.FindOptions,
|
|
40
|
-
) => Promise<Array<Event>>;
|
|
41
|
-
|
|
42
|
-
type: (event: Event) => string;
|
|
43
|
-
|
|
44
|
-
count: (query: EventQuery) => Promise<number>;
|
|
45
|
-
getReport: (params?: { from?: Date; to?: Date; types?: string[] }) => Promise<EventReport[]>;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
25
|
export const configureEventsModule = async ({
|
|
49
26
|
db,
|
|
50
27
|
}: ModuleInput<Record<string, never>>): Promise<EventsModule> => {
|
|
@@ -84,22 +61,22 @@ export const configureEventsModule = async ({
|
|
|
84
61
|
return count;
|
|
85
62
|
},
|
|
86
63
|
|
|
87
|
-
getReport: async ({
|
|
64
|
+
getReport: async ({ dateRange, types } = { dateRange: {}, types: null }) => {
|
|
88
65
|
const pipeline = [];
|
|
89
66
|
const matchConditions = [];
|
|
90
67
|
// build date filter based on provided values it can be a range if both to and from is supplied
|
|
91
68
|
// a upper or lowe limit if either from or to is provided
|
|
92
69
|
// or all if none is provided
|
|
93
|
-
if (
|
|
70
|
+
if (dateRange?.start || dateRange?.end) {
|
|
94
71
|
const dateConditions = [];
|
|
95
|
-
if (
|
|
96
|
-
const fromDate = new Date(
|
|
72
|
+
if (dateRange?.start) {
|
|
73
|
+
const fromDate = new Date(dateRange?.start);
|
|
97
74
|
dateConditions.push({
|
|
98
75
|
$or: [{ created: { $gte: fromDate } }, { updated: { $gte: fromDate } }],
|
|
99
76
|
});
|
|
100
77
|
}
|
|
101
|
-
if (
|
|
102
|
-
const toDate = new Date(
|
|
78
|
+
if (dateRange?.end) {
|
|
79
|
+
const toDate = new Date(dateRange?.end);
|
|
103
80
|
dateConditions.push({
|
|
104
81
|
$or: [{ created: { $lte: toDate } }, { updated: { $lte: toDate } }],
|
|
105
82
|
});
|