@stamhoofd/models 2.151.1 → 2.152.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.
- package/dist/migrations/1788385713-notifications-table.sql +16 -0
- package/dist/migrations/1788385714-notification-recipients-table.sql +16 -0
- package/dist/migrations/1788385715-notification-preferences-table.sql +12 -0
- package/dist/models/Notification.d.ts +28 -0
- package/dist/models/Notification.d.ts.map +1 -0
- package/dist/models/Notification.js +84 -0
- package/dist/models/Notification.js.map +1 -0
- package/dist/models/NotificationPreference.d.ts +14 -0
- package/dist/models/NotificationPreference.d.ts.map +1 -0
- package/dist/models/NotificationPreference.js +56 -0
- package/dist/models/NotificationPreference.js.map +1 -0
- package/dist/models/NotificationRecipient.d.ts +19 -0
- package/dist/models/NotificationRecipient.d.ts.map +1 -0
- package/dist/models/NotificationRecipient.js +77 -0
- package/dist/models/NotificationRecipient.js.map +1 -0
- package/dist/structures/OrganizationServerMetaData.d.ts +35 -0
- package/dist/structures/OrganizationServerMetaData.d.ts.map +1 -1
- package/dist/structures/OrganizationServerMetaData.js +68 -0
- package/dist/structures/OrganizationServerMetaData.js.map +1 -1
- package/package.json +3 -3
- package/src/migrations/1788385713-notifications-table.sql +16 -0
- package/src/migrations/1788385714-notification-recipients-table.sql +16 -0
- package/src/migrations/1788385715-notification-preferences-table.sql +12 -0
- package/src/models/Notification.ts +74 -0
- package/src/models/NotificationPreference.ts +50 -0
- package/src/models/NotificationRecipient.ts +70 -0
- package/src/structures/OrganizationServerMetaData.ts +61 -0
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
CREATE TABLE `notifications` (
|
|
2
|
+
`id` varchar(36) NOT NULL,
|
|
3
|
+
`type` varchar(64) NOT NULL,
|
|
4
|
+
`organizationId` varchar(36) DEFAULT NULL,
|
|
5
|
+
`subjectType` varchar(36) DEFAULT NULL,
|
|
6
|
+
`subjectId` varchar(36) DEFAULT NULL,
|
|
7
|
+
`payload` json NOT NULL,
|
|
8
|
+
`groupKey` varchar(255) DEFAULT NULL,
|
|
9
|
+
`groupResourceCount` int NOT NULL DEFAULT '0',
|
|
10
|
+
`groupResources` json NOT NULL,
|
|
11
|
+
`createdAt` datetime NOT NULL,
|
|
12
|
+
`updatedAt` datetime NOT NULL,
|
|
13
|
+
PRIMARY KEY (`id` DESC),
|
|
14
|
+
KEY `groupKey` (`organizationId`,`type`,`groupKey`,`createdAt` DESC) USING BTREE,
|
|
15
|
+
CONSTRAINT `notifications_ibfk_1` FOREIGN KEY (`organizationId`) REFERENCES `organizations` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
|
|
16
|
+
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
CREATE TABLE `notification_recipients` (
|
|
2
|
+
`id` varchar(36) NOT NULL,
|
|
3
|
+
`notificationId` varchar(36) NOT NULL,
|
|
4
|
+
`userId` varchar(36) NOT NULL,
|
|
5
|
+
`readCount` int NOT NULL DEFAULT '0',
|
|
6
|
+
`readAt` datetime DEFAULT NULL,
|
|
7
|
+
`seenAt` datetime DEFAULT NULL,
|
|
8
|
+
`dismissedAt` datetime DEFAULT NULL,
|
|
9
|
+
`createdAt` datetime NOT NULL,
|
|
10
|
+
PRIMARY KEY (`id` DESC),
|
|
11
|
+
UNIQUE KEY `notificationId_userId` (`notificationId`,`userId`),
|
|
12
|
+
KEY `userId_id` (`userId`,`id` DESC) USING BTREE,
|
|
13
|
+
KEY `userId_readAt` (`userId`,`readAt`),
|
|
14
|
+
CONSTRAINT `notification_recipients_ibfk_1` FOREIGN KEY (`notificationId`) REFERENCES `notifications` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
|
|
15
|
+
CONSTRAINT `notification_recipients_ibfk_2` FOREIGN KEY (`userId`) REFERENCES `users` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
|
|
16
|
+
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
CREATE TABLE `notification_preferences` (
|
|
2
|
+
`id` varchar(36) NOT NULL,
|
|
3
|
+
`userId` varchar(36) NOT NULL,
|
|
4
|
+
`notificationType` varchar(64) NOT NULL,
|
|
5
|
+
`channel` varchar(32) NOT NULL,
|
|
6
|
+
`enabled` tinyint(1) NOT NULL DEFAULT '1',
|
|
7
|
+
`createdAt` datetime NOT NULL,
|
|
8
|
+
`updatedAt` datetime NOT NULL,
|
|
9
|
+
PRIMARY KEY (`id`),
|
|
10
|
+
UNIQUE KEY `userId_type_channel` (`userId`,`notificationType`,`channel`),
|
|
11
|
+
CONSTRAINT `notification_preferences_ibfk_1` FOREIGN KEY (`userId`) REFERENCES `users` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
|
|
12
|
+
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { QueryableModel } from '@stamhoofd/sql';
|
|
2
|
+
import { NamedObject } from '@stamhoofd/structures';
|
|
3
|
+
import type { NotificationSubjectType } from '@stamhoofd/structures/notifications/NotificationSubjectType.js';
|
|
4
|
+
import type { NotificationType } from '@stamhoofd/structures/notifications/NotificationType.js';
|
|
5
|
+
/**
|
|
6
|
+
* Shared between all its recipients (see NotificationRecipient).
|
|
7
|
+
*/
|
|
8
|
+
export declare class Notification extends QueryableModel {
|
|
9
|
+
static table: string;
|
|
10
|
+
id: string;
|
|
11
|
+
type: NotificationType;
|
|
12
|
+
organizationId: string | null;
|
|
13
|
+
subjectType: NotificationSubjectType | null;
|
|
14
|
+
subjectId: string | null;
|
|
15
|
+
/**
|
|
16
|
+
* Shape depends on `type`
|
|
17
|
+
*/
|
|
18
|
+
payload: unknown;
|
|
19
|
+
/**
|
|
20
|
+
* Recent notifications with the same type, organizationId and groupKey are merged into one
|
|
21
|
+
*/
|
|
22
|
+
groupKey: string | null;
|
|
23
|
+
groupResourceCount: number;
|
|
24
|
+
groupResources: NamedObject[];
|
|
25
|
+
createdAt: Date;
|
|
26
|
+
updatedAt: Date;
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=Notification.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Notification.d.ts","sourceRoot":"","sources":["../../src/models/Notification.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAChD,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACpD,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,gEAAgE,CAAC;AAC9G,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,yDAAyD,CAAC;AAGhG;;GAEG;AACH,qBAAa,YAAa,SAAQ,cAAc;IAC5C,MAAM,CAAC,KAAK,SAAmB;IAQ/B,EAAE,EAAG,MAAM,CAAC;IAGZ,IAAI,EAAE,gBAAgB,CAAC;IAGvB,cAAc,EAAE,MAAM,GAAG,IAAI,CAAQ;IAGrC,WAAW,EAAE,uBAAuB,GAAG,IAAI,CAAQ;IAGnD,SAAS,EAAE,MAAM,GAAG,IAAI,CAAQ;IAEhC;;OAEG;IAEH,OAAO,EAAE,OAAO,CAAM;IAEtB;;OAEG;IAEH,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAQ;IAG/B,kBAAkB,SAAK;IAGvB,cAAc,EAAE,WAAW,EAAE,CAAM;IAYnC,SAAS,EAAE,IAAI,CAAC;IAUhB,SAAS,EAAE,IAAI,CAAC;CACnB"}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { __decorate } from "tslib";
|
|
2
|
+
import { column } from '@simonbackx/simple-database';
|
|
3
|
+
import { AnyDecoder, ArrayDecoder } from '@simonbackx/simple-encoding';
|
|
4
|
+
import { QueryableModel } from '@stamhoofd/sql';
|
|
5
|
+
import { NamedObject } from '@stamhoofd/structures';
|
|
6
|
+
import { v7 as uuidv7 } from 'uuid';
|
|
7
|
+
/**
|
|
8
|
+
* Shared between all its recipients (see NotificationRecipient).
|
|
9
|
+
*/
|
|
10
|
+
export class Notification extends QueryableModel {
|
|
11
|
+
static table = 'notifications';
|
|
12
|
+
id;
|
|
13
|
+
type;
|
|
14
|
+
organizationId = null;
|
|
15
|
+
subjectType = null;
|
|
16
|
+
subjectId = null;
|
|
17
|
+
/**
|
|
18
|
+
* Shape depends on `type`
|
|
19
|
+
*/
|
|
20
|
+
payload = {};
|
|
21
|
+
/**
|
|
22
|
+
* Recent notifications with the same type, organizationId and groupKey are merged into one
|
|
23
|
+
*/
|
|
24
|
+
groupKey = null;
|
|
25
|
+
groupResourceCount = 0;
|
|
26
|
+
groupResources = [];
|
|
27
|
+
createdAt;
|
|
28
|
+
updatedAt;
|
|
29
|
+
}
|
|
30
|
+
__decorate([
|
|
31
|
+
column({
|
|
32
|
+
primary: true, type: 'string', beforeSave(value) {
|
|
33
|
+
// uuidv7 keeps ids sortable by creation time
|
|
34
|
+
return value ?? uuidv7();
|
|
35
|
+
},
|
|
36
|
+
})
|
|
37
|
+
], Notification.prototype, "id", void 0);
|
|
38
|
+
__decorate([
|
|
39
|
+
column({ type: 'string' })
|
|
40
|
+
], Notification.prototype, "type", void 0);
|
|
41
|
+
__decorate([
|
|
42
|
+
column({ type: 'string', nullable: true })
|
|
43
|
+
], Notification.prototype, "organizationId", void 0);
|
|
44
|
+
__decorate([
|
|
45
|
+
column({ type: 'string', nullable: true })
|
|
46
|
+
], Notification.prototype, "subjectType", void 0);
|
|
47
|
+
__decorate([
|
|
48
|
+
column({ type: 'string', nullable: true })
|
|
49
|
+
], Notification.prototype, "subjectId", void 0);
|
|
50
|
+
__decorate([
|
|
51
|
+
column({ type: 'json', decoder: AnyDecoder })
|
|
52
|
+
], Notification.prototype, "payload", void 0);
|
|
53
|
+
__decorate([
|
|
54
|
+
column({ type: 'string', nullable: true })
|
|
55
|
+
], Notification.prototype, "groupKey", void 0);
|
|
56
|
+
__decorate([
|
|
57
|
+
column({ type: 'integer' })
|
|
58
|
+
], Notification.prototype, "groupResourceCount", void 0);
|
|
59
|
+
__decorate([
|
|
60
|
+
column({ type: 'json', decoder: new ArrayDecoder(NamedObject) })
|
|
61
|
+
], Notification.prototype, "groupResources", void 0);
|
|
62
|
+
__decorate([
|
|
63
|
+
column({
|
|
64
|
+
type: 'datetime', beforeSave(old) {
|
|
65
|
+
if (old !== undefined) {
|
|
66
|
+
return old;
|
|
67
|
+
}
|
|
68
|
+
const date = new Date();
|
|
69
|
+
date.setMilliseconds(0);
|
|
70
|
+
return date;
|
|
71
|
+
},
|
|
72
|
+
})
|
|
73
|
+
], Notification.prototype, "createdAt", void 0);
|
|
74
|
+
__decorate([
|
|
75
|
+
column({
|
|
76
|
+
type: 'datetime', beforeSave() {
|
|
77
|
+
const date = new Date();
|
|
78
|
+
date.setMilliseconds(0);
|
|
79
|
+
return date;
|
|
80
|
+
},
|
|
81
|
+
skipUpdate: true,
|
|
82
|
+
})
|
|
83
|
+
], Notification.prototype, "updatedAt", void 0);
|
|
84
|
+
//# sourceMappingURL=Notification.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Notification.js","sourceRoot":"","sources":["../../src/models/Notification.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,6BAA6B,CAAC;AACrD,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AACvE,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAChD,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAGpD,OAAO,EAAE,EAAE,IAAI,MAAM,EAAE,MAAM,MAAM,CAAC;AAEpC;;GAEG;AACH,MAAM,OAAO,YAAa,SAAQ,cAAc;IAC5C,MAAM,CAAC,KAAK,GAAG,eAAe,CAAC;IAQ/B,EAAE,CAAU;IAGZ,IAAI,CAAmB;IAG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EAAE,UAAU,EAAE,UAAU,CAAC,GAAS;YAClC,IAAI,GAAG,KAAK,SAAS,EAAE,CAAC;gBACpB,OAAO,GAAG,CAAC;YACf,CAAC;YACD,MAAM,IAAI,GAAG,IAAI,IAAI,EAAE,CAAC;YACxB,IAAI,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC;YACxB,OAAO,IAAI,CAAC;QAChB,CAAC;KACJ,CAAC;+CACc;AAUhB;IARC,MAAM,CAAC;QACJ,IAAI,EAAE,UAAU,EAAE,UAAU;YACxB,MAAM,IAAI,GAAG,IAAI,IAAI,EAAE,CAAC;YACxB,IAAI,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC;YACxB,OAAO,IAAI,CAAC;QAChB,CAAC;QACD,UAAU,EAAE,IAAI;KACnB,CAAC;+CACc"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { QueryableModel } from '@stamhoofd/sql';
|
|
2
|
+
import type { NotificationChannel } from '@stamhoofd/structures/notifications/NotificationChannel.js';
|
|
3
|
+
import type { NotificationType } from '@stamhoofd/structures/notifications/NotificationType.js';
|
|
4
|
+
export declare class NotificationPreference extends QueryableModel {
|
|
5
|
+
static table: string;
|
|
6
|
+
id: string;
|
|
7
|
+
userId: string;
|
|
8
|
+
notificationType: NotificationType;
|
|
9
|
+
channel: NotificationChannel;
|
|
10
|
+
enabled: boolean;
|
|
11
|
+
createdAt: Date;
|
|
12
|
+
updatedAt: Date;
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=NotificationPreference.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"NotificationPreference.d.ts","sourceRoot":"","sources":["../../src/models/NotificationPreference.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAChD,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,4DAA4D,CAAC;AACtG,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,yDAAyD,CAAC;AAGhG,qBAAa,sBAAuB,SAAQ,cAAc;IACtD,MAAM,CAAC,KAAK,SAA8B;IAO1C,EAAE,EAAG,MAAM,CAAC;IAGZ,MAAM,EAAE,MAAM,CAAC;IAGf,gBAAgB,EAAE,gBAAgB,CAAC;IAGnC,OAAO,EAAE,mBAAmB,CAAC;IAG7B,OAAO,UAAQ;IAYf,SAAS,EAAE,IAAI,CAAC;IAUhB,SAAS,EAAE,IAAI,CAAC;CACnB"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { __decorate } from "tslib";
|
|
2
|
+
import { column } from '@simonbackx/simple-database';
|
|
3
|
+
import { QueryableModel } from '@stamhoofd/sql';
|
|
4
|
+
import { v4 as uuidv4 } from 'uuid';
|
|
5
|
+
export class NotificationPreference extends QueryableModel {
|
|
6
|
+
static table = 'notification_preferences';
|
|
7
|
+
id;
|
|
8
|
+
userId;
|
|
9
|
+
notificationType;
|
|
10
|
+
channel;
|
|
11
|
+
enabled = true;
|
|
12
|
+
createdAt;
|
|
13
|
+
updatedAt;
|
|
14
|
+
}
|
|
15
|
+
__decorate([
|
|
16
|
+
column({
|
|
17
|
+
primary: true, type: 'string', beforeSave(value) {
|
|
18
|
+
return value ?? uuidv4();
|
|
19
|
+
},
|
|
20
|
+
})
|
|
21
|
+
], NotificationPreference.prototype, "id", void 0);
|
|
22
|
+
__decorate([
|
|
23
|
+
column({ type: 'string' })
|
|
24
|
+
], NotificationPreference.prototype, "userId", void 0);
|
|
25
|
+
__decorate([
|
|
26
|
+
column({ type: 'string' })
|
|
27
|
+
], NotificationPreference.prototype, "notificationType", void 0);
|
|
28
|
+
__decorate([
|
|
29
|
+
column({ type: 'string' })
|
|
30
|
+
], NotificationPreference.prototype, "channel", void 0);
|
|
31
|
+
__decorate([
|
|
32
|
+
column({ type: 'boolean' })
|
|
33
|
+
], NotificationPreference.prototype, "enabled", void 0);
|
|
34
|
+
__decorate([
|
|
35
|
+
column({
|
|
36
|
+
type: 'datetime', beforeSave(old) {
|
|
37
|
+
if (old !== undefined) {
|
|
38
|
+
return old;
|
|
39
|
+
}
|
|
40
|
+
const date = new Date();
|
|
41
|
+
date.setMilliseconds(0);
|
|
42
|
+
return date;
|
|
43
|
+
},
|
|
44
|
+
})
|
|
45
|
+
], NotificationPreference.prototype, "createdAt", void 0);
|
|
46
|
+
__decorate([
|
|
47
|
+
column({
|
|
48
|
+
type: 'datetime', beforeSave() {
|
|
49
|
+
const date = new Date();
|
|
50
|
+
date.setMilliseconds(0);
|
|
51
|
+
return date;
|
|
52
|
+
},
|
|
53
|
+
skipUpdate: true,
|
|
54
|
+
})
|
|
55
|
+
], NotificationPreference.prototype, "updatedAt", void 0);
|
|
56
|
+
//# sourceMappingURL=NotificationPreference.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"NotificationPreference.js","sourceRoot":"","sources":["../../src/models/NotificationPreference.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,6BAA6B,CAAC;AACrD,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAGhD,OAAO,EAAE,EAAE,IAAI,MAAM,EAAE,MAAM,MAAM,CAAC;AAEpC,MAAM,OAAO,sBAAuB,SAAQ,cAAc;IACtD,MAAM,CAAC,KAAK,GAAG,0BAA0B,CAAC;IAO1C,EAAE,CAAU;IAGZ,MAAM,CAAS;IAGf,gBAAgB,CAAmB;IAGnC,OAAO,CAAsB;IAG7B,OAAO,GAAG,IAAI,CAAC;IAYf,SAAS,CAAO;IAUhB,SAAS,CAAO;;AAlChB;IALC,MAAM,CAAC;QACJ,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,QAAQ,EAAE,UAAU,CAAC,KAAK;YAC3C,OAAO,KAAK,IAAI,MAAM,EAAE,CAAC;QAC7B,CAAC;KACJ,CAAC;kDACU;AAGZ;IADC,MAAM,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC;sDACZ;AAGf;IADC,MAAM,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC;gEACQ;AAGnC;IADC,MAAM,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC;uDACE;AAG7B;IADC,MAAM,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC;uDACb;AAYf;IAVC,MAAM,CAAC;QACJ,IAAI,EAAE,UAAU,EAAE,UAAU,CAAC,GAAS;YAClC,IAAI,GAAG,KAAK,SAAS,EAAE,CAAC;gBACpB,OAAO,GAAG,CAAC;YACf,CAAC;YACD,MAAM,IAAI,GAAG,IAAI,IAAI,EAAE,CAAC;YACxB,IAAI,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC;YACxB,OAAO,IAAI,CAAC;QAChB,CAAC;KACJ,CAAC;yDACc;AAUhB;IARC,MAAM,CAAC;QACJ,IAAI,EAAE,UAAU,EAAE,UAAU;YACxB,MAAM,IAAI,GAAG,IAAI,IAAI,EAAE,CAAC;YACxB,IAAI,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC;YACxB,OAAO,IAAI,CAAC;QAChB,CAAC;QACD,UAAU,EAAE,IAAI;KACnB,CAAC;yDACc"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { QueryableModel } from '@stamhoofd/sql';
|
|
2
|
+
import { UserNotification } from '@stamhoofd/structures/notifications/UserNotification.js';
|
|
3
|
+
import type { Notification } from './Notification.js';
|
|
4
|
+
export declare class NotificationRecipient extends QueryableModel {
|
|
5
|
+
static table: string;
|
|
6
|
+
id: string;
|
|
7
|
+
notificationId: string;
|
|
8
|
+
userId: string;
|
|
9
|
+
/**
|
|
10
|
+
* Notification.groupResourceCount at the moment the user last read it
|
|
11
|
+
*/
|
|
12
|
+
readCount: number;
|
|
13
|
+
readAt: Date | null;
|
|
14
|
+
seenAt: Date | null;
|
|
15
|
+
dismissedAt: Date | null;
|
|
16
|
+
createdAt: Date;
|
|
17
|
+
getStructure(notification: Notification): UserNotification;
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=NotificationRecipient.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"NotificationRecipient.d.ts","sourceRoot":"","sources":["../../src/models/NotificationRecipient.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAChD,OAAO,EAAE,gBAAgB,EAAE,MAAM,yDAAyD,CAAC;AAE3F,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAEtD,qBAAa,qBAAsB,SAAQ,cAAc;IACrD,MAAM,CAAC,KAAK,SAA6B;IAOzC,EAAE,EAAG,MAAM,CAAC;IAGZ,cAAc,EAAE,MAAM,CAAC;IAGvB,MAAM,EAAE,MAAM,CAAC;IAEf;;OAEG;IAEH,SAAS,SAAK;IAGd,MAAM,EAAE,IAAI,GAAG,IAAI,CAAQ;IAG3B,MAAM,EAAE,IAAI,GAAG,IAAI,CAAQ;IAG3B,WAAW,EAAE,IAAI,GAAG,IAAI,CAAQ;IAYhC,SAAS,EAAE,IAAI,CAAC;IAEhB,YAAY,CAAC,YAAY,EAAE,YAAY,GAAG,gBAAgB;CAoB7D"}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { __decorate } from "tslib";
|
|
2
|
+
import { column } from '@simonbackx/simple-database';
|
|
3
|
+
import { QueryableModel } from '@stamhoofd/sql';
|
|
4
|
+
import { UserNotification } from '@stamhoofd/structures/notifications/UserNotification.js';
|
|
5
|
+
import { v7 as uuidv7 } from 'uuid';
|
|
6
|
+
export class NotificationRecipient extends QueryableModel {
|
|
7
|
+
static table = 'notification_recipients';
|
|
8
|
+
id;
|
|
9
|
+
notificationId;
|
|
10
|
+
userId;
|
|
11
|
+
/**
|
|
12
|
+
* Notification.groupResourceCount at the moment the user last read it
|
|
13
|
+
*/
|
|
14
|
+
readCount = 0;
|
|
15
|
+
readAt = null;
|
|
16
|
+
seenAt = null;
|
|
17
|
+
dismissedAt = null;
|
|
18
|
+
createdAt;
|
|
19
|
+
getStructure(notification) {
|
|
20
|
+
return UserNotification.create({
|
|
21
|
+
id: this.id,
|
|
22
|
+
notificationId: notification.id,
|
|
23
|
+
type: notification.type,
|
|
24
|
+
organizationId: notification.organizationId,
|
|
25
|
+
subjectType: notification.subjectType,
|
|
26
|
+
subjectId: notification.subjectId,
|
|
27
|
+
payload: notification.payload,
|
|
28
|
+
groupKey: notification.groupKey,
|
|
29
|
+
groupResourceCount: notification.groupResourceCount,
|
|
30
|
+
groupResources: notification.groupResources,
|
|
31
|
+
readCount: this.readCount,
|
|
32
|
+
readAt: this.readAt,
|
|
33
|
+
seenAt: this.seenAt,
|
|
34
|
+
dismissedAt: this.dismissedAt,
|
|
35
|
+
createdAt: notification.createdAt,
|
|
36
|
+
updatedAt: notification.updatedAt,
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
__decorate([
|
|
41
|
+
column({
|
|
42
|
+
primary: true, type: 'string', beforeSave(value) {
|
|
43
|
+
return value ?? uuidv7();
|
|
44
|
+
},
|
|
45
|
+
})
|
|
46
|
+
], NotificationRecipient.prototype, "id", void 0);
|
|
47
|
+
__decorate([
|
|
48
|
+
column({ type: 'string' })
|
|
49
|
+
], NotificationRecipient.prototype, "notificationId", void 0);
|
|
50
|
+
__decorate([
|
|
51
|
+
column({ type: 'string' })
|
|
52
|
+
], NotificationRecipient.prototype, "userId", void 0);
|
|
53
|
+
__decorate([
|
|
54
|
+
column({ type: 'integer' })
|
|
55
|
+
], NotificationRecipient.prototype, "readCount", void 0);
|
|
56
|
+
__decorate([
|
|
57
|
+
column({ type: 'datetime', nullable: true })
|
|
58
|
+
], NotificationRecipient.prototype, "readAt", void 0);
|
|
59
|
+
__decorate([
|
|
60
|
+
column({ type: 'datetime', nullable: true })
|
|
61
|
+
], NotificationRecipient.prototype, "seenAt", void 0);
|
|
62
|
+
__decorate([
|
|
63
|
+
column({ type: 'datetime', nullable: true })
|
|
64
|
+
], NotificationRecipient.prototype, "dismissedAt", void 0);
|
|
65
|
+
__decorate([
|
|
66
|
+
column({
|
|
67
|
+
type: 'datetime', beforeSave(old) {
|
|
68
|
+
if (old !== undefined) {
|
|
69
|
+
return old;
|
|
70
|
+
}
|
|
71
|
+
const date = new Date();
|
|
72
|
+
date.setMilliseconds(0);
|
|
73
|
+
return date;
|
|
74
|
+
},
|
|
75
|
+
})
|
|
76
|
+
], NotificationRecipient.prototype, "createdAt", void 0);
|
|
77
|
+
//# sourceMappingURL=NotificationRecipient.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"NotificationRecipient.js","sourceRoot":"","sources":["../../src/models/NotificationRecipient.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,6BAA6B,CAAC;AACrD,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAChD,OAAO,EAAE,gBAAgB,EAAE,MAAM,yDAAyD,CAAC;AAC3F,OAAO,EAAE,EAAE,IAAI,MAAM,EAAE,MAAM,MAAM,CAAC;AAGpC,MAAM,OAAO,qBAAsB,SAAQ,cAAc;IACrD,MAAM,CAAC,KAAK,GAAG,yBAAyB,CAAC;IAOzC,EAAE,CAAU;IAGZ,cAAc,CAAS;IAGvB,MAAM,CAAS;IAEf;;OAEG;IAEH,SAAS,GAAG,CAAC,CAAC;IAGd,MAAM,GAAgB,IAAI,CAAC;IAG3B,MAAM,GAAgB,IAAI,CAAC;IAG3B,WAAW,GAAgB,IAAI,CAAC;IAYhC,SAAS,CAAO;IAEhB,YAAY,CAAC,YAA0B;QACnC,OAAO,gBAAgB,CAAC,MAAM,CAAC;YAC3B,EAAE,EAAE,IAAI,CAAC,EAAE;YACX,cAAc,EAAE,YAAY,CAAC,EAAE;YAC/B,IAAI,EAAE,YAAY,CAAC,IAAI;YACvB,cAAc,EAAE,YAAY,CAAC,cAAc;YAC3C,WAAW,EAAE,YAAY,CAAC,WAAW;YACrC,SAAS,EAAE,YAAY,CA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AAG,IAAI,IAAI,EAAE,CAAC;YACxB,IAAI,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC;YACxB,OAAO,IAAI,CAAC;QAChB,CAAC;KACJ,CAAC;wDACc"}
|
|
@@ -4,6 +4,36 @@ export declare class DripEmail extends AutoEncoder {
|
|
|
4
4
|
id: string;
|
|
5
5
|
date: Date;
|
|
6
6
|
}
|
|
7
|
+
export declare class BlockedPaymentMandate extends AutoEncoder {
|
|
8
|
+
/**
|
|
9
|
+
* External mandate id of the provider
|
|
10
|
+
*/
|
|
11
|
+
id: string;
|
|
12
|
+
blockedAt: Date;
|
|
13
|
+
/**
|
|
14
|
+
* Card number or IBAN (PaymentMandate.identifier) of the blocked mandate, so newer mandates for the same
|
|
15
|
+
* card or account stay blocked even when this mandate is revoked at the provider
|
|
16
|
+
*/
|
|
17
|
+
identifier: string | null;
|
|
18
|
+
/**
|
|
19
|
+
* The (chargeback) payment that caused the block, null when blocked manually
|
|
20
|
+
*/
|
|
21
|
+
paymentId: string | null;
|
|
22
|
+
}
|
|
23
|
+
export declare class PaymentMandateChargebacks extends AutoEncoder {
|
|
24
|
+
/**
|
|
25
|
+
* External mandate id of the provider
|
|
26
|
+
*/
|
|
27
|
+
id: string;
|
|
28
|
+
identifier: string | null;
|
|
29
|
+
/**
|
|
30
|
+
* Dates of the most recent chargebacks (last 12 months, at most 5)
|
|
31
|
+
*/
|
|
32
|
+
dates: Date[];
|
|
33
|
+
static readonly maxDates = 5;
|
|
34
|
+
static readonly maxAge: number;
|
|
35
|
+
add(date: Date): void;
|
|
36
|
+
}
|
|
7
37
|
export declare class OrganizationServerMetaData extends AutoEncoder {
|
|
8
38
|
privateDKIMKey?: string;
|
|
9
39
|
publicDKIMKey?: string;
|
|
@@ -27,6 +57,11 @@ export declare class OrganizationServerMetaData extends AutoEncoder {
|
|
|
27
57
|
isDNSUnstable: boolean;
|
|
28
58
|
mollieCustomerId?: string;
|
|
29
59
|
mollieMandateId: string | null;
|
|
60
|
+
/**
|
|
61
|
+
* Mandates that can no longer be used to pay, even if they are still valid at the provider
|
|
62
|
+
*/
|
|
63
|
+
blockedMandates: BlockedPaymentMandate[];
|
|
64
|
+
mandateChargebacks: PaymentMandateChargebacks[];
|
|
30
65
|
ssoConfiguration: OpenIDClientConfiguration | null;
|
|
31
66
|
/**
|
|
32
67
|
* List of specific emails that were send to this organization
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"OrganizationServerMetaData.d.ts","sourceRoot":"","sources":["../../src/structures/OrganizationServerMetaData.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,WAAW,EAAiF,MAAM,6BAA6B,CAAC;AACvJ,OAAO,EAAE,yBAAyB,EAAE,MAAM,uBAAuB,CAAC;AAElE,qBAAa,SAAU,SAAQ,WAAW;IAEtC,EAAE,EAAE,MAAM,CAAC;IAGX,IAAI,OAAc;CACrB;AAED,qBAAa,0BAA2B,SAAQ,WAAW;IAEvD,cAAc,CAAC,EAAE,MAAM,CAAC;IAGxB,aAAa,CAAC,EAAE,MAAM,CAAC;IAGvB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAE1B;;;OAGG;IAEH,sBAAsB,CAAC,EAAE,IAAI,CAAC;IAE9B;;;OAGG;IAEH,sBAAsB,UAAQ;IAE9B;;;OAGG;IAEH,qBAAqB,SAAK;IAG1B,mBAAmB,CAAC,EAAE,IAAI,EAAE,CAAC;IAG7B,aAAa,EAAE,OAAO,CAAS;IAG/B,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAG1B,eAAe,EAAE,MAAM,GAAG,IAAI,CAAQ;
|
|
1
|
+
{"version":3,"file":"OrganizationServerMetaData.d.ts","sourceRoot":"","sources":["../../src/structures/OrganizationServerMetaData.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,WAAW,EAAiF,MAAM,6BAA6B,CAAC;AACvJ,OAAO,EAAE,yBAAyB,EAAE,MAAM,uBAAuB,CAAC;AAElE,qBAAa,SAAU,SAAQ,WAAW;IAEtC,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D,YAAY;IAMZ,cAAc;IAed;;OAEG;IACH,wBAAwB;IAKxB,QAAQ,CAAC,UAAU,EAAE,MAAM;IAM3B,QAAQ,CAAC,UAAU,EAAE,MAAM,EAAE,MAAM,GAAE,MAAM,GAAG,IAAW;CAU5D"}
|
|
@@ -11,6 +11,63 @@ __decorate([
|
|
|
11
11
|
__decorate([
|
|
12
12
|
field({ decoder: DateDecoder })
|
|
13
13
|
], DripEmail.prototype, "date", void 0);
|
|
14
|
+
export class BlockedPaymentMandate extends AutoEncoder {
|
|
15
|
+
/**
|
|
16
|
+
* External mandate id of the provider
|
|
17
|
+
*/
|
|
18
|
+
id;
|
|
19
|
+
blockedAt = new Date();
|
|
20
|
+
/**
|
|
21
|
+
* Card number or IBAN (PaymentMandate.identifier) of the blocked mandate, so newer mandates for the same
|
|
22
|
+
* card or account stay blocked even when this mandate is revoked at the provider
|
|
23
|
+
*/
|
|
24
|
+
identifier = null;
|
|
25
|
+
/**
|
|
26
|
+
* The (chargeback) payment that caused the block, null when blocked manually
|
|
27
|
+
*/
|
|
28
|
+
paymentId = null;
|
|
29
|
+
}
|
|
30
|
+
__decorate([
|
|
31
|
+
field({ decoder: StringDecoder })
|
|
32
|
+
], BlockedPaymentMandate.prototype, "id", void 0);
|
|
33
|
+
__decorate([
|
|
34
|
+
field({ decoder: DateDecoder })
|
|
35
|
+
], BlockedPaymentMandate.prototype, "blockedAt", void 0);
|
|
36
|
+
__decorate([
|
|
37
|
+
field({ decoder: StringDecoder, nullable: true })
|
|
38
|
+
], BlockedPaymentMandate.prototype, "identifier", void 0);
|
|
39
|
+
__decorate([
|
|
40
|
+
field({ decoder: StringDecoder, nullable: true })
|
|
41
|
+
], BlockedPaymentMandate.prototype, "paymentId", void 0);
|
|
42
|
+
export class PaymentMandateChargebacks extends AutoEncoder {
|
|
43
|
+
/**
|
|
44
|
+
* External mandate id of the provider
|
|
45
|
+
*/
|
|
46
|
+
id;
|
|
47
|
+
identifier = null;
|
|
48
|
+
/**
|
|
49
|
+
* Dates of the most recent chargebacks (last 12 months, at most 5)
|
|
50
|
+
*/
|
|
51
|
+
dates = [];
|
|
52
|
+
static maxDates = 5;
|
|
53
|
+
static maxAge = 1000 * 60 * 60 * 24 * 365;
|
|
54
|
+
add(date) {
|
|
55
|
+
const minimum = new Date(date.getTime() - PaymentMandateChargebacks.maxAge);
|
|
56
|
+
this.dates = [...this.dates, date]
|
|
57
|
+
.filter(d => d >= minimum)
|
|
58
|
+
.sort((a, b) => b.getTime() - a.getTime())
|
|
59
|
+
.slice(0, PaymentMandateChargebacks.maxDates);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
__decorate([
|
|
63
|
+
field({ decoder: StringDecoder })
|
|
64
|
+
], PaymentMandateChargebacks.prototype, "id", void 0);
|
|
65
|
+
__decorate([
|
|
66
|
+
field({ decoder: StringDecoder, nullable: true })
|
|
67
|
+
], PaymentMandateChargebacks.prototype, "identifier", void 0);
|
|
68
|
+
__decorate([
|
|
69
|
+
field({ decoder: new ArrayDecoder(DateDecoder) })
|
|
70
|
+
], PaymentMandateChargebacks.prototype, "dates", void 0);
|
|
14
71
|
export class OrganizationServerMetaData extends AutoEncoder {
|
|
15
72
|
privateDKIMKey;
|
|
16
73
|
publicDKIMKey;
|
|
@@ -34,6 +91,11 @@ export class OrganizationServerMetaData extends AutoEncoder {
|
|
|
34
91
|
isDNSUnstable = false;
|
|
35
92
|
mollieCustomerId;
|
|
36
93
|
mollieMandateId = null;
|
|
94
|
+
/**
|
|
95
|
+
* Mandates that can no longer be used to pay, even if they are still valid at the provider
|
|
96
|
+
*/
|
|
97
|
+
blockedMandates = [];
|
|
98
|
+
mandateChargebacks = [];
|
|
37
99
|
ssoConfiguration = null;
|
|
38
100
|
/**
|
|
39
101
|
* List of specific emails that were send to this organization
|
|
@@ -110,6 +172,12 @@ __decorate([
|
|
|
110
172
|
__decorate([
|
|
111
173
|
field({ decoder: StringDecoder, optional: true, nullable: true })
|
|
112
174
|
], OrganizationServerMetaData.prototype, "mollieMandateId", void 0);
|
|
175
|
+
__decorate([
|
|
176
|
+
field({ decoder: new ArrayDecoder(BlockedPaymentMandate), version: 417 })
|
|
177
|
+
], OrganizationServerMetaData.prototype, "blockedMandates", void 0);
|
|
178
|
+
__decorate([
|
|
179
|
+
field({ decoder: new ArrayDecoder(PaymentMandateChargebacks), version: 417 })
|
|
180
|
+
], OrganizationServerMetaData.prototype, "mandateChargebacks", void 0);
|
|
113
181
|
__decorate([
|
|
114
182
|
field({ decoder: OpenIDClientConfiguration, nullable: true, version: 189 })
|
|
115
183
|
], OrganizationServerMetaData.prototype, "ssoConfiguration", void 0);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"OrganizationServerMetaData.js","sourceRoot":"","sources":["../../src/structures/OrganizationServerMetaData.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,cAAc,EAAE,WAAW,EAAE,KAAK,EAAE,cAAc,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AACvJ,OAAO,EAAE,yBAAyB,EAAE,MAAM,uBAAuB,CAAC;AAElE,MAAM,OAAO,SAAU,SAAQ,WAAW;IAEtC,EAAE,CAAS;IAGX,IAAI,GAAG,IAAI,IAAI,EAAE,CAAC;CACrB;AAJG;IADC,KAAK,CAAC,EAAE,OAAO,EAAE,aAAa,EAAE,CAAC;qCACvB;AAGX;IADC,KAAK,CAAC,EAAE,OAAO,EAAE,WAAW,EAAE,CAAC;uCACd;AAGtB,MAAM,OAAO,0BAA2B,SAAQ,WAAW;IAEvD,cAAc,CAAU;IAGxB,aAAa,CAAU;IAGvB,gBAAgB,CAAU;IAE1B;;;OAGG;IAEH,sBAAsB,CAAQ;IAE9B;;;OAGG;IAEH,sBAAsB,GAAG,IAAI,CAAC;IAE9B;;;OAGG;IAEH,qBAAqB,GAAG,CAAC,CAAC;IAG1B,mBAAmB,CAAU;IAG7B,aAAa,GAAY,KAAK,CAAC;IAG/B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,EAAE,OAAO,EAAE,GAAG,EAAE;YACpG,MAAM,CAAC,GAAG,IAAI,GAAG,EAAqB,CAAC;YACvC,MAAM,UAAU,GAAG,yBAAyB,CAAC;YAC7C,CAAC,CAAC,GAAG,CAAC,UAAU,EAAE,SAAS,CAAC,MAAM,CAAC,EAAE,EAAE,EAAE,UAAU,EAAE,CAAC,CAAC,CAAC;YACxD,OAAO,CAAC,CAAC;QACb,CAAC,EAAE,CAAC;IACH,KAAK,CAAC,EAAE,OAAO,EAAE,IAAI,UAAU,CAAC,aAAa,EAAE,SAAS,CAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,OAAO,EAAE,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE;YACpG,MAAM,CAAC,GAAG,IAAI,GAAG,EAAqB,CAAC;YACvC,MAAM,UAAU,GAAG,yBAAyB,CAAC;YAC7C,CAAC,CAAC,GAAG,CAAC,UAAU,EAAE,SAAS,CAAC,MAAM,CAAC,EAAE,EAAE,EAAE,UAAU,EAAE,CAAC,CAAC,CAAC;YACxD,OAAO,CAAC,CAAC;QACb,CAAC,EAAE,CAAC;iEAC8C"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stamhoofd/models",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.152.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -44,7 +44,7 @@
|
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
46
|
"@simonbackx/simple-database": "1.40.0",
|
|
47
|
-
"@stamhoofd/test-utils": "2.
|
|
47
|
+
"@stamhoofd/test-utils": "2.152.0",
|
|
48
48
|
"@types/luxon": "3.7.2",
|
|
49
49
|
"@types/uuid": "8.3.4",
|
|
50
50
|
"vitest": "4.1.10"
|
|
@@ -63,5 +63,5 @@
|
|
|
63
63
|
"publishConfig": {
|
|
64
64
|
"access": "public"
|
|
65
65
|
},
|
|
66
|
-
"gitHead": "
|
|
66
|
+
"gitHead": "66475bb3d64a936320e419ecf8f7d7ad98ff71e8"
|
|
67
67
|
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
CREATE TABLE `notifications` (
|
|
2
|
+
`id` varchar(36) NOT NULL,
|
|
3
|
+
`type` varchar(64) NOT NULL,
|
|
4
|
+
`organizationId` varchar(36) DEFAULT NULL,
|
|
5
|
+
`subjectType` varchar(36) DEFAULT NULL,
|
|
6
|
+
`subjectId` varchar(36) DEFAULT NULL,
|
|
7
|
+
`payload` json NOT NULL,
|
|
8
|
+
`groupKey` varchar(255) DEFAULT NULL,
|
|
9
|
+
`groupResourceCount` int NOT NULL DEFAULT '0',
|
|
10
|
+
`groupResources` json NOT NULL,
|
|
11
|
+
`createdAt` datetime NOT NULL,
|
|
12
|
+
`updatedAt` datetime NOT NULL,
|
|
13
|
+
PRIMARY KEY (`id` DESC),
|
|
14
|
+
KEY `groupKey` (`organizationId`,`type`,`groupKey`,`createdAt` DESC) USING BTREE,
|
|
15
|
+
CONSTRAINT `notifications_ibfk_1` FOREIGN KEY (`organizationId`) REFERENCES `organizations` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
|
|
16
|
+
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
CREATE TABLE `notification_recipients` (
|
|
2
|
+
`id` varchar(36) NOT NULL,
|
|
3
|
+
`notificationId` varchar(36) NOT NULL,
|
|
4
|
+
`userId` varchar(36) NOT NULL,
|
|
5
|
+
`readCount` int NOT NULL DEFAULT '0',
|
|
6
|
+
`readAt` datetime DEFAULT NULL,
|
|
7
|
+
`seenAt` datetime DEFAULT NULL,
|
|
8
|
+
`dismissedAt` datetime DEFAULT NULL,
|
|
9
|
+
`createdAt` datetime NOT NULL,
|
|
10
|
+
PRIMARY KEY (`id` DESC),
|
|
11
|
+
UNIQUE KEY `notificationId_userId` (`notificationId`,`userId`),
|
|
12
|
+
KEY `userId_id` (`userId`,`id` DESC) USING BTREE,
|
|
13
|
+
KEY `userId_readAt` (`userId`,`readAt`),
|
|
14
|
+
CONSTRAINT `notification_recipients_ibfk_1` FOREIGN KEY (`notificationId`) REFERENCES `notifications` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
|
|
15
|
+
CONSTRAINT `notification_recipients_ibfk_2` FOREIGN KEY (`userId`) REFERENCES `users` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
|
|
16
|
+
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
CREATE TABLE `notification_preferences` (
|
|
2
|
+
`id` varchar(36) NOT NULL,
|
|
3
|
+
`userId` varchar(36) NOT NULL,
|
|
4
|
+
`notificationType` varchar(64) NOT NULL,
|
|
5
|
+
`channel` varchar(32) NOT NULL,
|
|
6
|
+
`enabled` tinyint(1) NOT NULL DEFAULT '1',
|
|
7
|
+
`createdAt` datetime NOT NULL,
|
|
8
|
+
`updatedAt` datetime NOT NULL,
|
|
9
|
+
PRIMARY KEY (`id`),
|
|
10
|
+
UNIQUE KEY `userId_type_channel` (`userId`,`notificationType`,`channel`),
|
|
11
|
+
CONSTRAINT `notification_preferences_ibfk_1` FOREIGN KEY (`userId`) REFERENCES `users` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
|
|
12
|
+
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { column } from '@simonbackx/simple-database';
|
|
2
|
+
import { AnyDecoder, ArrayDecoder } from '@simonbackx/simple-encoding';
|
|
3
|
+
import { QueryableModel } from '@stamhoofd/sql';
|
|
4
|
+
import { NamedObject } from '@stamhoofd/structures';
|
|
5
|
+
import type { NotificationSubjectType } from '@stamhoofd/structures/notifications/NotificationSubjectType.js';
|
|
6
|
+
import type { NotificationType } from '@stamhoofd/structures/notifications/NotificationType.js';
|
|
7
|
+
import { v7 as uuidv7 } from 'uuid';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Shared between all its recipients (see NotificationRecipient).
|
|
11
|
+
*/
|
|
12
|
+
export class Notification extends QueryableModel {
|
|
13
|
+
static table = 'notifications';
|
|
14
|
+
|
|
15
|
+
@column({
|
|
16
|
+
primary: true, type: 'string', beforeSave(value) {
|
|
17
|
+
// uuidv7 keeps ids sortable by creation time
|
|
18
|
+
return value ?? uuidv7();
|
|
19
|
+
},
|
|
20
|
+
})
|
|
21
|
+
id!: string;
|
|
22
|
+
|
|
23
|
+
@column({ type: 'string' })
|
|
24
|
+
type: NotificationType;
|
|
25
|
+
|
|
26
|
+
@column({ type: 'string', nullable: true })
|
|
27
|
+
organizationId: string | null = null;
|
|
28
|
+
|
|
29
|
+
@column({ type: 'string', nullable: true })
|
|
30
|
+
subjectType: NotificationSubjectType | null = null;
|
|
31
|
+
|
|
32
|
+
@column({ type: 'string', nullable: true })
|
|
33
|
+
subjectId: string | null = null;
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Shape depends on `type`
|
|
37
|
+
*/
|
|
38
|
+
@column({ type: 'json', decoder: AnyDecoder })
|
|
39
|
+
payload: unknown = {};
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Recent notifications with the same type, organizationId and groupKey are merged into one
|
|
43
|
+
*/
|
|
44
|
+
@column({ type: 'string', nullable: true })
|
|
45
|
+
groupKey: string | null = null;
|
|
46
|
+
|
|
47
|
+
@column({ type: 'integer' })
|
|
48
|
+
groupResourceCount = 0;
|
|
49
|
+
|
|
50
|
+
@column({ type: 'json', decoder: new ArrayDecoder(NamedObject) })
|
|
51
|
+
groupResources: NamedObject[] = [];
|
|
52
|
+
|
|
53
|
+
@column({
|
|
54
|
+
type: 'datetime', beforeSave(old?: any) {
|
|
55
|
+
if (old !== undefined) {
|
|
56
|
+
return old;
|
|
57
|
+
}
|
|
58
|
+
const date = new Date();
|
|
59
|
+
date.setMilliseconds(0);
|
|
60
|
+
return date;
|
|
61
|
+
},
|
|
62
|
+
})
|
|
63
|
+
createdAt: Date;
|
|
64
|
+
|
|
65
|
+
@column({
|
|
66
|
+
type: 'datetime', beforeSave() {
|
|
67
|
+
const date = new Date();
|
|
68
|
+
date.setMilliseconds(0);
|
|
69
|
+
return date;
|
|
70
|
+
},
|
|
71
|
+
skipUpdate: true,
|
|
72
|
+
})
|
|
73
|
+
updatedAt: Date;
|
|
74
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { column } from '@simonbackx/simple-database';
|
|
2
|
+
import { QueryableModel } from '@stamhoofd/sql';
|
|
3
|
+
import type { NotificationChannel } from '@stamhoofd/structures/notifications/NotificationChannel.js';
|
|
4
|
+
import type { NotificationType } from '@stamhoofd/structures/notifications/NotificationType.js';
|
|
5
|
+
import { v4 as uuidv4 } from 'uuid';
|
|
6
|
+
|
|
7
|
+
export class NotificationPreference extends QueryableModel {
|
|
8
|
+
static table = 'notification_preferences';
|
|
9
|
+
|
|
10
|
+
@column({
|
|
11
|
+
primary: true, type: 'string', beforeSave(value) {
|
|
12
|
+
return value ?? uuidv4();
|
|
13
|
+
},
|
|
14
|
+
})
|
|
15
|
+
id!: string;
|
|
16
|
+
|
|
17
|
+
@column({ type: 'string' })
|
|
18
|
+
userId: string;
|
|
19
|
+
|
|
20
|
+
@column({ type: 'string' })
|
|
21
|
+
notificationType: NotificationType;
|
|
22
|
+
|
|
23
|
+
@column({ type: 'string' })
|
|
24
|
+
channel: NotificationChannel;
|
|
25
|
+
|
|
26
|
+
@column({ type: 'boolean' })
|
|
27
|
+
enabled = true;
|
|
28
|
+
|
|
29
|
+
@column({
|
|
30
|
+
type: 'datetime', beforeSave(old?: any) {
|
|
31
|
+
if (old !== undefined) {
|
|
32
|
+
return old;
|
|
33
|
+
}
|
|
34
|
+
const date = new Date();
|
|
35
|
+
date.setMilliseconds(0);
|
|
36
|
+
return date;
|
|
37
|
+
},
|
|
38
|
+
})
|
|
39
|
+
createdAt: Date;
|
|
40
|
+
|
|
41
|
+
@column({
|
|
42
|
+
type: 'datetime', beforeSave() {
|
|
43
|
+
const date = new Date();
|
|
44
|
+
date.setMilliseconds(0);
|
|
45
|
+
return date;
|
|
46
|
+
},
|
|
47
|
+
skipUpdate: true,
|
|
48
|
+
})
|
|
49
|
+
updatedAt: Date;
|
|
50
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { column } from '@simonbackx/simple-database';
|
|
2
|
+
import { QueryableModel } from '@stamhoofd/sql';
|
|
3
|
+
import { UserNotification } from '@stamhoofd/structures/notifications/UserNotification.js';
|
|
4
|
+
import { v7 as uuidv7 } from 'uuid';
|
|
5
|
+
import type { Notification } from './Notification.js';
|
|
6
|
+
|
|
7
|
+
export class NotificationRecipient extends QueryableModel {
|
|
8
|
+
static table = 'notification_recipients';
|
|
9
|
+
|
|
10
|
+
@column({
|
|
11
|
+
primary: true, type: 'string', beforeSave(value) {
|
|
12
|
+
return value ?? uuidv7();
|
|
13
|
+
},
|
|
14
|
+
})
|
|
15
|
+
id!: string;
|
|
16
|
+
|
|
17
|
+
@column({ type: 'string' })
|
|
18
|
+
notificationId: string;
|
|
19
|
+
|
|
20
|
+
@column({ type: 'string' })
|
|
21
|
+
userId: string;
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Notification.groupResourceCount at the moment the user last read it
|
|
25
|
+
*/
|
|
26
|
+
@column({ type: 'integer' })
|
|
27
|
+
readCount = 0;
|
|
28
|
+
|
|
29
|
+
@column({ type: 'datetime', nullable: true })
|
|
30
|
+
readAt: Date | null = null;
|
|
31
|
+
|
|
32
|
+
@column({ type: 'datetime', nullable: true })
|
|
33
|
+
seenAt: Date | null = null;
|
|
34
|
+
|
|
35
|
+
@column({ type: 'datetime', nullable: true })
|
|
36
|
+
dismissedAt: Date | null = null;
|
|
37
|
+
|
|
38
|
+
@column({
|
|
39
|
+
type: 'datetime', beforeSave(old?: any) {
|
|
40
|
+
if (old !== undefined) {
|
|
41
|
+
return old;
|
|
42
|
+
}
|
|
43
|
+
const date = new Date();
|
|
44
|
+
date.setMilliseconds(0);
|
|
45
|
+
return date;
|
|
46
|
+
},
|
|
47
|
+
})
|
|
48
|
+
createdAt: Date;
|
|
49
|
+
|
|
50
|
+
getStructure(notification: Notification): UserNotification {
|
|
51
|
+
return UserNotification.create({
|
|
52
|
+
id: this.id,
|
|
53
|
+
notificationId: notification.id,
|
|
54
|
+
type: notification.type,
|
|
55
|
+
organizationId: notification.organizationId,
|
|
56
|
+
subjectType: notification.subjectType,
|
|
57
|
+
subjectId: notification.subjectId,
|
|
58
|
+
payload: notification.payload,
|
|
59
|
+
groupKey: notification.groupKey,
|
|
60
|
+
groupResourceCount: notification.groupResourceCount,
|
|
61
|
+
groupResources: notification.groupResources,
|
|
62
|
+
readCount: this.readCount,
|
|
63
|
+
readAt: this.readAt,
|
|
64
|
+
seenAt: this.seenAt,
|
|
65
|
+
dismissedAt: this.dismissedAt,
|
|
66
|
+
createdAt: notification.createdAt,
|
|
67
|
+
updatedAt: notification.updatedAt,
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
}
|
|
@@ -9,6 +9,58 @@ export class DripEmail extends AutoEncoder {
|
|
|
9
9
|
date = new Date();
|
|
10
10
|
}
|
|
11
11
|
|
|
12
|
+
export class BlockedPaymentMandate extends AutoEncoder {
|
|
13
|
+
/**
|
|
14
|
+
* External mandate id of the provider
|
|
15
|
+
*/
|
|
16
|
+
@field({ decoder: StringDecoder })
|
|
17
|
+
id: string;
|
|
18
|
+
|
|
19
|
+
@field({ decoder: DateDecoder })
|
|
20
|
+
blockedAt = new Date();
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Card number or IBAN (PaymentMandate.identifier) of the blocked mandate, so newer mandates for the same
|
|
24
|
+
* card or account stay blocked even when this mandate is revoked at the provider
|
|
25
|
+
*/
|
|
26
|
+
@field({ decoder: StringDecoder, nullable: true })
|
|
27
|
+
identifier: string | null = null;
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* The (chargeback) payment that caused the block, null when blocked manually
|
|
31
|
+
*/
|
|
32
|
+
@field({ decoder: StringDecoder, nullable: true })
|
|
33
|
+
paymentId: string | null = null;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export class PaymentMandateChargebacks extends AutoEncoder {
|
|
37
|
+
/**
|
|
38
|
+
* External mandate id of the provider
|
|
39
|
+
*/
|
|
40
|
+
@field({ decoder: StringDecoder })
|
|
41
|
+
id: string;
|
|
42
|
+
|
|
43
|
+
@field({ decoder: StringDecoder, nullable: true })
|
|
44
|
+
identifier: string | null = null;
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Dates of the most recent chargebacks (last 12 months, at most 5)
|
|
48
|
+
*/
|
|
49
|
+
@field({ decoder: new ArrayDecoder(DateDecoder) })
|
|
50
|
+
dates: Date[] = [];
|
|
51
|
+
|
|
52
|
+
static readonly maxDates = 5;
|
|
53
|
+
static readonly maxAge = 1000 * 60 * 60 * 24 * 365;
|
|
54
|
+
|
|
55
|
+
add(date: Date) {
|
|
56
|
+
const minimum = new Date(date.getTime() - PaymentMandateChargebacks.maxAge);
|
|
57
|
+
this.dates = [...this.dates, date]
|
|
58
|
+
.filter(d => d >= minimum)
|
|
59
|
+
.sort((a, b) => b.getTime() - a.getTime())
|
|
60
|
+
.slice(0, PaymentMandateChargebacks.maxDates);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
12
64
|
export class OrganizationServerMetaData extends AutoEncoder {
|
|
13
65
|
@field({ decoder: StringDecoder, optional: true })
|
|
14
66
|
privateDKIMKey?: string;
|
|
@@ -52,6 +104,15 @@ export class OrganizationServerMetaData extends AutoEncoder {
|
|
|
52
104
|
@field({ decoder: StringDecoder, optional: true, nullable: true })
|
|
53
105
|
mollieMandateId: string | null = null;
|
|
54
106
|
|
|
107
|
+
/**
|
|
108
|
+
* Mandates that can no longer be used to pay, even if they are still valid at the provider
|
|
109
|
+
*/
|
|
110
|
+
@field({ decoder: new ArrayDecoder(BlockedPaymentMandate), version: 417 })
|
|
111
|
+
blockedMandates: BlockedPaymentMandate[] = [];
|
|
112
|
+
|
|
113
|
+
@field({ decoder: new ArrayDecoder(PaymentMandateChargebacks), version: 417 })
|
|
114
|
+
mandateChargebacks: PaymentMandateChargebacks[] = [];
|
|
115
|
+
|
|
55
116
|
@field({ decoder: OpenIDClientConfiguration, nullable: true, version: 189 })
|
|
56
117
|
ssoConfiguration: OpenIDClientConfiguration | null = null;
|
|
57
118
|
|