@stamhoofd/models 2.137.4 → 2.137.5
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/models/Document.d.ts +0 -4
- package/dist/models/Document.d.ts.map +1 -1
- package/dist/models/Document.js +1 -75
- package/dist/models/Document.js.map +1 -1
- package/dist/models/DocumentTemplate.d.ts +0 -3
- package/dist/models/DocumentTemplate.d.ts.map +1 -1
- package/dist/models/DocumentTemplate.js +1 -63
- package/dist/models/DocumentTemplate.js.map +1 -1
- package/dist/models/Email.d.ts +1 -23
- package/dist/models/Email.d.ts.map +1 -1
- package/dist/models/Email.js +2 -200
- package/dist/models/Email.js.map +1 -1
- package/dist/models/EmailVerificationCode.d.ts +0 -5
- package/dist/models/EmailVerificationCode.d.ts.map +1 -1
- package/dist/models/EmailVerificationCode.js +0 -84
- package/dist/models/EmailVerificationCode.js.map +1 -1
- package/dist/models/Image.d.ts.map +1 -1
- package/dist/models/Image.js +11 -14
- package/dist/models/Image.js.map +1 -1
- package/dist/models/MemberPlatformMembership.d.ts +0 -8
- package/dist/models/MemberPlatformMembership.d.ts.map +1 -1
- package/dist/models/MemberPlatformMembership.js +1 -242
- package/dist/models/MemberPlatformMembership.js.map +1 -1
- package/dist/models/Order.d.ts +1 -32
- package/dist/models/Order.d.ts.map +1 -1
- package/dist/models/Order.js +1 -182
- package/dist/models/Order.js.map +1 -1
- package/dist/models/Organization.d.ts +1 -14
- package/dist/models/Organization.d.ts.map +1 -1
- package/dist/models/Organization.js +10 -408
- package/dist/models/Organization.js.map +1 -1
- package/dist/models/PasswordToken.d.ts +0 -8
- package/dist/models/PasswordToken.d.ts.map +1 -1
- package/dist/models/PasswordToken.js +0 -23
- package/dist/models/PasswordToken.js.map +1 -1
- package/dist/models/Platform.d.ts.map +1 -1
- package/dist/models/Platform.js +7 -2
- package/dist/models/Platform.js.map +1 -1
- package/dist/models/STPackage.d.ts +1 -6
- package/dist/models/STPackage.d.ts.map +1 -1
- package/dist/models/STPackage.js +1 -98
- package/dist/models/STPackage.js.map +1 -1
- package/package.json +3 -3
- package/src/models/Document.ts +1 -84
- package/src/models/DocumentTemplate.ts +1 -71
- package/src/models/Email.ts +3 -230
- package/src/models/EmailVerificationCode.ts +0 -96
- package/src/models/Image.ts +11 -14
- package/src/models/MemberPlatformMembership.ts +1 -285
- package/src/models/Order.ts +1 -204
- package/src/models/Organization.test.ts +46 -0
- package/src/models/Organization.ts +10 -491
- package/src/models/PasswordToken.ts +0 -29
- package/src/models/Platform.ts +9 -2
- package/src/models/STPackage.ts +1 -110
- package/src/models/MemberPlatformMembership.test.ts +0 -70
|
@@ -5,8 +5,6 @@ import basex from 'base-x';
|
|
|
5
5
|
import crypto from 'crypto';
|
|
6
6
|
import { User } from './User.js';
|
|
7
7
|
import { SimpleError } from '@simonbackx/simple-errors';
|
|
8
|
-
import { getAppHost } from '@stamhoofd/structures';
|
|
9
|
-
import { Platform } from './Platform.js';
|
|
10
8
|
const ALPHABET = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz';
|
|
11
9
|
const bs58 = basex(ALPHABET);
|
|
12
10
|
async function randomBytes(size) {
|
|
@@ -80,27 +78,6 @@ export class PasswordToken extends QueryableModel {
|
|
|
80
78
|
await token.save();
|
|
81
79
|
return token;
|
|
82
80
|
}
|
|
83
|
-
static async getPasswordRecoveryUrl(user, organization, i18n, validUntil) {
|
|
84
|
-
// Send an e-mail to say you already have an account + follow password forgot flow
|
|
85
|
-
const token = await PasswordToken.createToken(user, validUntil);
|
|
86
|
-
return token.getPasswordRecoveryUrl(organization, i18n, user);
|
|
87
|
-
}
|
|
88
|
-
/**
|
|
89
|
-
* Build the password recovery url for this (already created) token.
|
|
90
|
-
* Pass the user to avoid an extra query when it is already loaded.
|
|
91
|
-
*/
|
|
92
|
-
async getPasswordRecoveryUrl(organization, i18n, user) {
|
|
93
|
-
const tokenUser = user ?? await User.getByID(this.userId);
|
|
94
|
-
if (!tokenUser) {
|
|
95
|
-
throw new Error('PasswordToken without a valid user');
|
|
96
|
-
}
|
|
97
|
-
if (tokenUser.organizationId !== null && ((tokenUser.organizationId ?? null) !== (organization?.id ?? null))) {
|
|
98
|
-
throw new Error('Unexpected mismatch in organization id for PasswordToken');
|
|
99
|
-
}
|
|
100
|
-
const hasOrganizationPermissions = organization ? tokenUser.permissions?.forOrganization(organization, await Platform.getSharedStruct())?.isEmpty === false : false;
|
|
101
|
-
const host = 'https://' + getAppHost(hasOrganizationPermissions ? 'dashboard' : 'registration', organization, hasOrganizationPermissions, i18n);
|
|
102
|
-
return host + '/reset-password?token=' + encodeURIComponent(this.token);
|
|
103
|
-
}
|
|
104
81
|
static async clearFor(userId) {
|
|
105
82
|
const query = `DELETE from ${this.table} where userId = ?`;
|
|
106
83
|
await Database.delete(query, [userId]);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PasswordToken.js","sourceRoot":"","sources":["../../src/models/PasswordToken.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,6BAA6B,CAAC;
|
|
1
|
+
{"version":3,"file":"PasswordToken.js","sourceRoot":"","sources":["../../src/models/PasswordToken.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,6BAA6B,CAAC;AAC/D,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAChD,OAAO,KAAK,MAAM,QAAQ,CAAC;AAC3B,OAAO,MAAM,MAAM,QAAQ,CAAC;AAE5B,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AACxD,MAAM,QAAQ,GAAG,4DAA4D,CAAC;AAC9E,MAAM,IAAI,GAAG,KAAK,CAAC,QAAQ,CAAC,CAAC;AAI7B,KAAK,UAAU,WAAW,CAAC,IAAY;IACnC,OAAO,IAAI,OAAO,CAAC,CAA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AAK,GAAG,IAAI,CAAC,MAAM,CAAC,MAAM,WAAW,CAAC,GAAG,CAAC,CAAC,CAAC,WAAW,EAAE,CAAC;QAChE,MAAM,KAAK,CAAC,IAAI,EAAE,CAAC;QACnB,OAAO,KAAK,CAAC;IACjB,CAAC;IAED,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAC,MAAc;QAChC,MAAM,KAAK,GAAG,eAAe,IAAI,CAAC,KAAK,mBAAmB,CAAC;QAC3D,MAAM,QAAQ,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC;IAC3C,CAAC;;AA7FD;IADC,MAAM,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC;4CAC5B;AAGd;IADC,MAAM,CAAC,EAAE,IAAI,EAAE,UAAU,EAAE,CAAC;iDACZ;AAYjB;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;gDACc;AAGhB;IADC,MAAM,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC;6CACZ"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Platform.d.ts","sourceRoot":"","sources":["../../src/models/Platform.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAChD,OAAO,
|
|
1
|
+
{"version":3,"file":"Platform.d.ts","sourceRoot":"","sources":["../../src/models/Platform.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAChD,OAAO,EAAmC,cAAc,EAAE,qBAAqB,EAAE,oBAAoB,EAAE,QAAQ,IAAI,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAMjK,qBAAa,QAAS,SAAQ,cAAc;IACxC,MAAM,CAAC,KAAK,SAAc;IAO1B,EAAE,EAAG,MAAM,CAAC;IAGZ,MAAM,EAAE,cAAc,CAA6B;IAGnD,QAAQ,EAAE,MAAM,CAAC;IAGjB,gBAAgB,EAAE,MAAM,GAAG,IAAI,CAAQ;IAGvC,YAAY,EAAE,MAAM,GAAG,IAAI,CAAQ;IAGnC,wBAAwB,EAAE,MAAM,GAAG,IAAI,CAAQ;IAG/C,aAAa,EAAE,qBAAqB,CAAoC;IAExE;;OAEG;IAEH,YAAY,EAAE,oBAAoB,CAAmC;IAErE;;;;OAIG;IACH,IAAI,kBAAkB,WAUrB;IAED,OAAO,CAAC,MAAM,CAAC,MAAM,CAAyB;IAC9C,OAAO,CAAC,MAAM,CAAC,mBAAmB,CAA0E;IAC5G,OAAO,CAAC,MAAM,CAAC,YAAY,CAA+B;WAE7C,eAAe,IAAI,OAAO,CAAC,cAAc,CAAC;IAYjD,mBAAmB;WAMZ,sBAAsB,IAAI,OAAO,CAAC,cAAc,GAAG;QAAE,aAAa,EAAE,qBAAqB,CAAA;KAAE,CAAC;WAY5F,aAAa,IAAI,OAAO,CAAC,QAAQ,CAAC;WA2BlC,SAAS,IAAI,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAC,GAAG;QAAE,IAAI,EAAE,KAAK,CAAA;KAAE,CAAC;WAmB1D,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;mBAYnB,kBAAkB;WAuB1B,UAAU;WAKV,wBAAwB;IAQ/B,IAAI;CAcb"}
|
package/dist/models/Platform.js
CHANGED
|
@@ -3,7 +3,8 @@ import { column } from '@simonbackx/simple-database';
|
|
|
3
3
|
import { SimpleError } from '@simonbackx/simple-errors';
|
|
4
4
|
import { QueueHandler } from '@stamhoofd/queues';
|
|
5
5
|
import { QueryableModel } from '@stamhoofd/sql';
|
|
6
|
-
import { PlatformConfig, PlatformPrivateConfig, PlatformServerConfig, Platform as PlatformStruct } from '@stamhoofd/structures';
|
|
6
|
+
import { AuditLogReplacementDependencies, PlatformConfig, PlatformPrivateConfig, PlatformServerConfig, Platform as PlatformStruct } from '@stamhoofd/structures';
|
|
7
|
+
import { uuidToName } from '@stamhoofd/structures/helpers/uuidToName.js';
|
|
7
8
|
import { deepFreeze } from '@stamhoofd/utility';
|
|
8
9
|
import { v4 as uuidv4 } from 'uuid';
|
|
9
10
|
import { RegistrationPeriod } from './RegistrationPeriod.js';
|
|
@@ -120,7 +121,11 @@ export class Platform extends QueryableModel {
|
|
|
120
121
|
this.sharedPrivateStruct = struct.clone();
|
|
121
122
|
const clone = struct.clone();
|
|
122
123
|
clone.privateConfig = null;
|
|
123
|
-
|
|
124
|
+
// Audit logs render uuids from a bare id, so they cannot receive a platform through their
|
|
125
|
+
// call chain. Bind the resolver to the struct we are about to cache, so it is refreshed
|
|
126
|
+
// together with the caches. Uses the public struct on purpose: resolving privateConfig
|
|
127
|
+
// roles would change the names that get persisted in audit logs.
|
|
128
|
+
AuditLogReplacementDependencies.uuidToName = uuid => uuidToName(uuid, clone);
|
|
124
129
|
this.sharedStruct = clone;
|
|
125
130
|
}
|
|
126
131
|
static async clearCache() {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Platform.js","sourceRoot":"","sources":["../../src/models/Platform.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,6BAA6B,CAAC;AACrD,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AACxD,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAChD,OAAO,EAAE,cAAc,EAAE,qBAAqB,EAAE,oBAAoB,EAAE,QAAQ,IAAI,cAAc,EAAE,MAAM,uBAAuB,CAAC;
|
|
1
|
+
{"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AM,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;0DACI;AAG/C;IADC,MAAM,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,qBAAqB,EAAE,CAAC;+CACe;AAMxE;IADC,MAAM,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,oBAAoB,EAAE,CAAC;8CACa"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { STPackageMeta, STPackageStatus } from '@stamhoofd/structures';
|
|
2
2
|
import { QueryableModel } from '@stamhoofd/sql';
|
|
3
3
|
export declare class STPackage extends QueryableModel {
|
|
4
4
|
static table: string;
|
|
@@ -27,10 +27,5 @@ export declare class STPackage extends QueryableModel {
|
|
|
27
27
|
*/
|
|
28
28
|
createRenewed(): STPackage;
|
|
29
29
|
createStatus(): STPackageStatus;
|
|
30
|
-
sendExpiryEmail(): Promise<void>;
|
|
31
|
-
sendEmailTemplate(data: {
|
|
32
|
-
type: EmailTemplateType;
|
|
33
|
-
replyTo?: string;
|
|
34
|
-
}): Promise<void>;
|
|
35
30
|
}
|
|
36
31
|
//# sourceMappingURL=STPackage.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"STPackage.d.ts","sourceRoot":"","sources":["../../src/models/STPackage.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"STPackage.d.ts","sourceRoot":"","sources":["../../src/models/STPackage.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,aAAa,EAAE,eAAe,EAA2D,MAAM,uBAAuB,CAAC;AAGhI,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAEhD,qBAAa,SAAU,SAAQ,cAAc;IACzC,MAAM,CAAC,KAAK,SAAwB;IAQpC,EAAE,EAAG,MAAM,CAAC;IAEZ;;OAEG;IAEH,cAAc,EAAE,MAAM,CAAC;IAGvB,IAAI,EAAE,aAAa,CAAC;IAYpB,SAAS,EAAE,IAAI,CAAC;IAUhB,SAAS,EAAE,IAAI,CAAC;IAGhB,OAAO,EAAE,IAAI,GAAG,IAAI,CAAQ;IAG5B,UAAU,EAAE,IAAI,GAAG,IAAI,CAAQ;IAG/B,QAAQ,EAAE,IAAI,GAAG,IAAI,CAAQ;IAG7B,UAAU,SAAK;IAGf,WAAW,EAAE,IAAI,GAAG,IAAI,CAAQ;IAEhC;;OAEG;IACH,IAAI,OAAO,gBAQV;IAEK,QAAQ;IAeR,QAAQ,CAAC,OAAO,EAAE,SAAS;IAM3B,UAAU;IAQhB;;OAEG;IACH,aAAa,IAAI,SAAS;IAkE1B,YAAY,IAAI,eAAe;CAoBlC"}
|
package/dist/models/STPackage.js
CHANGED
|
@@ -1,12 +1,9 @@
|
|
|
1
1
|
import { __decorate } from "tslib";
|
|
2
2
|
import { column } from '@simonbackx/simple-database';
|
|
3
3
|
import { SimpleError } from '@simonbackx/simple-errors';
|
|
4
|
-
import {
|
|
5
|
-
import { Formatter } from '@stamhoofd/utility';
|
|
4
|
+
import { STPackageMeta, STPackageStatus, STPackageStatusServiceFee, STPackageType, STPricingType } from '@stamhoofd/structures';
|
|
6
5
|
import { v4 as uuidv4 } from 'uuid';
|
|
7
6
|
import { QueryableModel } from '@stamhoofd/sql';
|
|
8
|
-
import { sendEmailTemplate } from '../helpers/EmailBuilder.js';
|
|
9
|
-
import { Organization } from './Organization.js';
|
|
10
7
|
export class STPackage extends QueryableModel {
|
|
11
8
|
static table = 'stamhoofd_packages';
|
|
12
9
|
// Columns
|
|
@@ -139,100 +136,6 @@ export class STPackage extends QueryableModel {
|
|
|
139
136
|
],
|
|
140
137
|
});
|
|
141
138
|
}
|
|
142
|
-
async sendExpiryEmail() {
|
|
143
|
-
if (this.validAt === null) {
|
|
144
|
-
// never activated
|
|
145
|
-
return;
|
|
146
|
-
}
|
|
147
|
-
if (this.removeAt && this.removeAt <= new Date()) {
|
|
148
|
-
this.emailCount += 1;
|
|
149
|
-
await this.save();
|
|
150
|
-
return;
|
|
151
|
-
}
|
|
152
|
-
let allowDays = 0;
|
|
153
|
-
let type = null;
|
|
154
|
-
if (this.meta.type === STPackageType.Members) {
|
|
155
|
-
type = EmailTemplateType.MembersExpirationReminder;
|
|
156
|
-
allowDays = 32;
|
|
157
|
-
}
|
|
158
|
-
else if (this.meta.type === STPackageType.Webshops) {
|
|
159
|
-
type = EmailTemplateType.WebshopsExpirationReminder;
|
|
160
|
-
allowDays = 32;
|
|
161
|
-
}
|
|
162
|
-
else if (this.meta.type === STPackageType.SingleWebshop) {
|
|
163
|
-
type = EmailTemplateType.SingleWebshopExpirationReminder;
|
|
164
|
-
allowDays = 7;
|
|
165
|
-
}
|
|
166
|
-
else if (this.meta.type === STPackageType.TrialMembers) {
|
|
167
|
-
type = EmailTemplateType.TrialMembersExpirationReminder;
|
|
168
|
-
allowDays = 3;
|
|
169
|
-
}
|
|
170
|
-
else if (this.meta.type === STPackageType.TrialWebshops) {
|
|
171
|
-
type = EmailTemplateType.TrialWebshopsExpirationReminder;
|
|
172
|
-
allowDays = 3;
|
|
173
|
-
}
|
|
174
|
-
const allowFrom = new Date(Date.now() + 1000 * 60 * 60 * 24 * allowDays);
|
|
175
|
-
if (type && (this.validUntil === null || this.validUntil < new Date() || this.validUntil > allowFrom)) {
|
|
176
|
-
console.log('Skip sending expiration email for ' + this.id);
|
|
177
|
-
return;
|
|
178
|
-
}
|
|
179
|
-
if (type) {
|
|
180
|
-
console.log('Sending expiration email for ' + this.id, type);
|
|
181
|
-
if (STAMHOOFD.environment === 'production') {
|
|
182
|
-
await this.sendEmailTemplate({
|
|
183
|
-
type,
|
|
184
|
-
});
|
|
185
|
-
}
|
|
186
|
-
this.lastEmailAt = new Date();
|
|
187
|
-
}
|
|
188
|
-
else {
|
|
189
|
-
console.log('Skip sending expiration email for ' + this.id + ' (no type)');
|
|
190
|
-
}
|
|
191
|
-
this.emailCount += 1;
|
|
192
|
-
await this.save();
|
|
193
|
-
}
|
|
194
|
-
async sendEmailTemplate(data) {
|
|
195
|
-
const organization = await Organization.getByID(this.organizationId);
|
|
196
|
-
if (!organization) {
|
|
197
|
-
console.error('Could not find package organization ' + this.id);
|
|
198
|
-
return;
|
|
199
|
-
}
|
|
200
|
-
const admins = await organization.getFullAdmins();
|
|
201
|
-
const recipients = admins.map(admin => Recipient.create({
|
|
202
|
-
firstName: admin.firstName,
|
|
203
|
-
lastName: admin.lastName,
|
|
204
|
-
email: admin.email,
|
|
205
|
-
replacements: [
|
|
206
|
-
Replacement.create({
|
|
207
|
-
token: 'organizationName',
|
|
208
|
-
value: organization.name,
|
|
209
|
-
}),
|
|
210
|
-
Replacement.create({
|
|
211
|
-
token: 'packageName',
|
|
212
|
-
value: this.meta.name ?? '',
|
|
213
|
-
}),
|
|
214
|
-
Replacement.create({
|
|
215
|
-
token: 'validUntil',
|
|
216
|
-
value: this.validUntil ? Formatter.dateTime(this.validUntil) : 'nooit',
|
|
217
|
-
}),
|
|
218
|
-
Replacement.create({
|
|
219
|
-
token: 'validUntilDate',
|
|
220
|
-
value: this.validUntil ? Formatter.date(this.validUntil) : 'nooit',
|
|
221
|
-
}),
|
|
222
|
-
Replacement.create({
|
|
223
|
-
token: 'renewUrl',
|
|
224
|
-
value: `https://${(STAMHOOFD.domains.dashboard ?? 'stamhoofd.app')}/${organization.i18n.locale}/beheerders/${organization.uri}/instellingen/functionaliteiten`,
|
|
225
|
-
}),
|
|
226
|
-
],
|
|
227
|
-
}));
|
|
228
|
-
// Create e-mail builder
|
|
229
|
-
await sendEmailTemplate(null, {
|
|
230
|
-
template: {
|
|
231
|
-
type: data.type,
|
|
232
|
-
},
|
|
233
|
-
recipients,
|
|
234
|
-
});
|
|
235
|
-
}
|
|
236
139
|
}
|
|
237
140
|
__decorate([
|
|
238
141
|
column({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"STPackage.js","sourceRoot":"","sources":["../../src/models/STPackage.ts"],"names":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C,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;4CACc;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;4CACc;AAGhB;IADC,MAAM,CAAC,EAAE,IAAI,EAAE,UAAU,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;0CACjB;AAG5B;IADC,MAAM,CAAC,EAAE,IAAI,EAAE,UAAU,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;6CACd;AAG/B;IADC,MAAM,CAAC,EAAE,IAAI,EAAE,UAAU,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;2CAChB;AAG7B;IADC,MAAM,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC;6CACb;AAGf;IADC,MAAM,CAAC,EAAE,IAAI,EAAE,UAAU,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;8CACb"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stamhoofd/models",
|
|
3
|
-
"version": "2.137.
|
|
3
|
+
"version": "2.137.5",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
},
|
|
46
46
|
"devDependencies": {
|
|
47
47
|
"@simonbackx/simple-database": "1.37.1",
|
|
48
|
-
"@stamhoofd/test-utils": "2.137.
|
|
48
|
+
"@stamhoofd/test-utils": "2.137.5",
|
|
49
49
|
"@types/luxon": "3.7.2",
|
|
50
50
|
"@types/uuid": "8.3.4",
|
|
51
51
|
"vitest": "4.1.10"
|
|
@@ -64,5 +64,5 @@
|
|
|
64
64
|
"publishConfig": {
|
|
65
65
|
"access": "public"
|
|
66
66
|
},
|
|
67
|
-
"gitHead": "
|
|
67
|
+
"gitHead": "52c8072d0294d8005c9d36a79219708ea148a357"
|
|
68
68
|
}
|
package/src/models/Document.ts
CHANGED
|
@@ -1,13 +1,11 @@
|
|
|
1
1
|
import { column } from '@simonbackx/simple-database';
|
|
2
|
-
import { DocumentData, DocumentStatus, Document as DocumentStruct
|
|
2
|
+
import { DocumentData, DocumentStatus, Document as DocumentStruct } from '@stamhoofd/structures';
|
|
3
3
|
import { Formatter } from '@stamhoofd/utility';
|
|
4
4
|
import { v4 as uuidv4 } from 'uuid';
|
|
5
5
|
|
|
6
6
|
import { SimpleError } from '@simonbackx/simple-errors';
|
|
7
7
|
import { QueryableModel } from '@stamhoofd/sql';
|
|
8
|
-
import { render } from '../helpers/Handlebars.js';
|
|
9
8
|
import type { Member, MemberWithRegistrations, RegistrationWithMember } from './Member.js';
|
|
10
|
-
import type { Organization } from './Organization.js';
|
|
11
9
|
import { Registration } from './Registration.js';
|
|
12
10
|
|
|
13
11
|
export class Document extends QueryableModel {
|
|
@@ -83,64 +81,6 @@ export class Document extends QueryableModel {
|
|
|
83
81
|
return DocumentStruct.create(this);
|
|
84
82
|
}
|
|
85
83
|
|
|
86
|
-
buildContext(organization: Organization) {
|
|
87
|
-
// Convert the field answers in a simplified javascript object
|
|
88
|
-
const data: Record<string, any> = {
|
|
89
|
-
id: this.id,
|
|
90
|
-
name: this.data.name,
|
|
91
|
-
number: this.number,
|
|
92
|
-
created_at: this.createdAt,
|
|
93
|
-
organization: {
|
|
94
|
-
name: organization.name,
|
|
95
|
-
companyName: organization.meta.companies[0]?.name || organization.name,
|
|
96
|
-
companyNumber: organization.meta.companies[0]?.companyNumber || null,
|
|
97
|
-
address: organization.address,
|
|
98
|
-
companyAddress: organization.meta.companies[0]?.address ?? organization.address,
|
|
99
|
-
},
|
|
100
|
-
};
|
|
101
|
-
const platformLogo = Platform.shared.config.logoDocuments ?? Platform.shared.config.horizontalLogo ?? Platform.shared.config.squareLogo;
|
|
102
|
-
const organizationLogo = organization.meta.horizontalLogo ?? organization.meta.squareLogo;
|
|
103
|
-
const logo = organizationLogo || platformLogo;
|
|
104
|
-
|
|
105
|
-
if (organizationLogo) {
|
|
106
|
-
data['organization'] = {
|
|
107
|
-
...data['organization'],
|
|
108
|
-
logo: organizationLogo.encode({ version: Version }) ?? null,
|
|
109
|
-
};
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
if (platformLogo) {
|
|
113
|
-
data['platform'] = {
|
|
114
|
-
logo: platformLogo.encode({ version: Version }) ?? null,
|
|
115
|
-
};
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
if (logo) {
|
|
119
|
-
data['logo'] = logo.encode({ version: Version }) ?? null;
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
for (const field of this.data.fieldAnswers.values()) {
|
|
123
|
-
const keys = field.settings.id.split('.');
|
|
124
|
-
let current = data;
|
|
125
|
-
const lastKey = keys.pop()!;
|
|
126
|
-
if (!lastKey) {
|
|
127
|
-
throw new Error('Invalid field id');
|
|
128
|
-
}
|
|
129
|
-
for (const key of keys) {
|
|
130
|
-
if (!current[key]) {
|
|
131
|
-
current[key] = {};
|
|
132
|
-
}
|
|
133
|
-
current = current[key];
|
|
134
|
-
|
|
135
|
-
if (typeof current !== 'object') {
|
|
136
|
-
throw new Error('Invalid field type');
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
current[lastKey] = field.objectValue;
|
|
140
|
-
}
|
|
141
|
-
return data;
|
|
142
|
-
}
|
|
143
|
-
|
|
144
84
|
async updateData(): Promise<void> {
|
|
145
85
|
if (this.isLocked) {
|
|
146
86
|
console.log('Document is locked, skipping update');
|
|
@@ -267,27 +207,4 @@ export class Document extends QueryableModel {
|
|
|
267
207
|
console.error(e);
|
|
268
208
|
}
|
|
269
209
|
}
|
|
270
|
-
|
|
271
|
-
// Rander handlebars template
|
|
272
|
-
async getRenderedHtml(organization: Organization): Promise<string | null> {
|
|
273
|
-
const DocumentTemplate = (await import('./DocumentTemplate.js')).DocumentTemplate;
|
|
274
|
-
const template = await DocumentTemplate.getByID(this.templateId);
|
|
275
|
-
if (!template) {
|
|
276
|
-
return null;
|
|
277
|
-
}
|
|
278
|
-
|
|
279
|
-
return await this.getRenderedHtmlForTemplate(organization, template.html);
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
// Rander handlebars template
|
|
283
|
-
private async getRenderedHtmlForTemplate(organization: Organization, htmlTemplate: string): Promise<string | null> {
|
|
284
|
-
try {
|
|
285
|
-
const context = this.buildContext(organization);
|
|
286
|
-
const renderedHtml = await render(htmlTemplate, context);
|
|
287
|
-
return renderedHtml;
|
|
288
|
-
} catch (e) {
|
|
289
|
-
console.error('Failed to render document html', e);
|
|
290
|
-
return null;
|
|
291
|
-
}
|
|
292
|
-
}
|
|
293
210
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { column } from '@simonbackx/simple-database';
|
|
2
|
-
import {
|
|
2
|
+
import { SimpleError } from '@simonbackx/simple-errors';
|
|
3
3
|
import { QueueHandler } from '@stamhoofd/queues';
|
|
4
4
|
import type { Parent, RecordAnswer } from '@stamhoofd/structures';
|
|
5
5
|
import { BalanceItemStatus, DocumentData, DocumentPrivateSettings, DocumentSettings, DocumentStatus, DocumentTemplatePrivate, GroupType, NationalRegisterNumberOptOut, RecordAddressAnswer, RecordAnswerDecoder, RecordDateAnswer, RecordPriceAnswer, RecordSettings, RecordTextAnswer, RecordType } from '@stamhoofd/structures';
|
|
@@ -7,13 +7,11 @@ import { Formatter, Sorter } from '@stamhoofd/utility';
|
|
|
7
7
|
import { v4 as uuidv4 } from 'uuid';
|
|
8
8
|
|
|
9
9
|
import { QueryableModel } from '@stamhoofd/sql';
|
|
10
|
-
import { render } from '../helpers/Handlebars.js';
|
|
11
10
|
import { BalanceItem } from './BalanceItem.js';
|
|
12
11
|
import { Document } from './Document.js';
|
|
13
12
|
import { Group } from './Group.js';
|
|
14
13
|
import type { RegistrationWithMember } from './Member.js';
|
|
15
14
|
import { Member } from './Member.js';
|
|
16
|
-
import type { Organization } from './Organization.js';
|
|
17
15
|
import { Registration } from './Registration.js';
|
|
18
16
|
import { User } from './User.js';
|
|
19
17
|
|
|
@@ -717,74 +715,6 @@ export class DocumentTemplate extends QueryableModel {
|
|
|
717
715
|
return lastNumber + 1;
|
|
718
716
|
}
|
|
719
717
|
|
|
720
|
-
private async buildContext(organization: Organization) {
|
|
721
|
-
// Convert the field answers in a simplified javascript object
|
|
722
|
-
const documents = (await this.buildAll({ generateNumbers: true })).filter(d => d.status === DocumentStatus.Published && !!d.number).sort((a, b) => Sorter.byNumberValue(b.number ?? 0, a.number ?? 0));
|
|
723
|
-
|
|
724
|
-
// Check numbers are strictly increasing
|
|
725
|
-
let lastNumber = 0;
|
|
726
|
-
for (const document of documents) {
|
|
727
|
-
if (document.number !== lastNumber + 1) {
|
|
728
|
-
document.number = lastNumber + 1;
|
|
729
|
-
await document.save();
|
|
730
|
-
}
|
|
731
|
-
lastNumber = document.number;
|
|
732
|
-
}
|
|
733
|
-
|
|
734
|
-
const data = {
|
|
735
|
-
id: this.id,
|
|
736
|
-
created_at: this.createdAt,
|
|
737
|
-
documents: documents.map(d => d.buildContext(organization)),
|
|
738
|
-
organization: {
|
|
739
|
-
name: organization.name,
|
|
740
|
-
companyName: organization.meta.companies[0]?.name || organization.name,
|
|
741
|
-
companyNumber: organization.meta.companies[0]?.companyNumber || null,
|
|
742
|
-
address: organization.address,
|
|
743
|
-
companyAddress: organization.meta.companies[0]?.address ?? organization.address,
|
|
744
|
-
},
|
|
745
|
-
};
|
|
746
|
-
|
|
747
|
-
for (const field of this.settings.fieldAnswers.values()) {
|
|
748
|
-
const keys = field.settings.id.split('.');
|
|
749
|
-
let current = data;
|
|
750
|
-
const lastKey = keys.pop()!;
|
|
751
|
-
if (!lastKey) {
|
|
752
|
-
throw new Error('Invalid field id');
|
|
753
|
-
}
|
|
754
|
-
for (const key of keys) {
|
|
755
|
-
if (!current[key]) {
|
|
756
|
-
current[key] = {};
|
|
757
|
-
}
|
|
758
|
-
current = current[key];
|
|
759
|
-
|
|
760
|
-
if (typeof current !== 'object') {
|
|
761
|
-
throw new Error('Invalid field type');
|
|
762
|
-
}
|
|
763
|
-
}
|
|
764
|
-
current[lastKey] = field.objectValue;
|
|
765
|
-
}
|
|
766
|
-
|
|
767
|
-
return data;
|
|
768
|
-
}
|
|
769
|
-
|
|
770
|
-
async getRenderedXml(organization: Organization) {
|
|
771
|
-
if (!this.privateSettings.templateDefinition.xmlExport) {
|
|
772
|
-
return null;
|
|
773
|
-
}
|
|
774
|
-
|
|
775
|
-
try {
|
|
776
|
-
const context = await this.buildContext(organization);
|
|
777
|
-
const renderedHtml = await render(this.privateSettings.templateDefinition.xmlExport, context);
|
|
778
|
-
return renderedHtml;
|
|
779
|
-
} catch (e) {
|
|
780
|
-
if (isSimpleError(e) || isSimpleErrors(e)) {
|
|
781
|
-
throw e;
|
|
782
|
-
}
|
|
783
|
-
console.error('Failed to render document html', e);
|
|
784
|
-
return null;
|
|
785
|
-
}
|
|
786
|
-
}
|
|
787
|
-
|
|
788
718
|
areAnswersComplete(answers: Map<string, RecordAnswer>) {
|
|
789
719
|
for (const field of this.privateSettings.templateDefinition.documentFieldCategories.flatMap(c => c.getAllRecords())) {
|
|
790
720
|
const answer = answers.get(field.id);
|