@stamhoofd/models 2.137.4 → 2.138.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/helpers/Handlebars.d.ts.map +1 -1
- package/dist/helpers/Handlebars.js +1 -1
- package/dist/helpers/Handlebars.js.map +1 -1
- package/dist/helpers/errorToSimpleErrors.d.ts +3 -0
- package/dist/helpers/errorToSimpleErrors.d.ts.map +1 -0
- package/dist/helpers/errorToSimpleErrors.js +17 -0
- package/dist/helpers/errorToSimpleErrors.js.map +1 -0
- package/dist/index.d.ts +0 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +0 -1
- package/dist/index.js.map +1 -1
- package/dist/migrations/1782902314-tokens-authenticated-at.sql +2 -0
- package/dist/migrations/1782902315-create-mfa-totp-table.sql +13 -0
- package/dist/migrations/1782902316-create-webauthn-credentials-table.sql +17 -0
- package/dist/migrations/1782902317-create-mfa-recovery-codes-table.sql +10 -0
- package/dist/migrations/1782902318-create-mfa-tokens-table.sql +13 -0
- package/dist/migrations/1782902319-create-webauthn-challenges-table.sql +10 -0
- package/dist/migrations/1784039947-mfa-totp-last-used-counter.sql +2 -0
- package/dist/migrations/1784122354-webauthn-credential-provider.sql +3 -0
- package/dist/migrations/1784500000-webauthn-credential-rp-id.sql +9 -0
- package/dist/migrations/1785354091-platform-parent-tenant-id.sql +1 -0
- package/dist/migrations/1785354092-platform-fees-tenant-id.sql +1 -0
- package/dist/migrations/1785354093-platform-uri.sql +1 -0
- package/dist/migrations/1785354094-platform-domain.sql +1 -0
- package/dist/migrations/1785354095-platform-uri-unique.sql +1 -0
- package/dist/migrations/1785354096-platform-domain-unique.sql +1 -0
- package/dist/migrations/1785354097-platform-parent-tenant-id-index.sql +1 -0
- package/dist/migrations/1785354098-platform-tenant-backfill.d.ts +4 -0
- package/dist/migrations/1785354098-platform-tenant-backfill.d.ts.map +1 -0
- package/dist/migrations/1785354098-platform-tenant-backfill.js +10 -0
- package/dist/migrations/1785354098-platform-tenant-backfill.js.map +1 -0
- package/dist/migrations/1785417301-users-last-active-at.sql +2 -0
- 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 -29
- package/dist/models/Email.d.ts.map +1 -1
- package/dist/models/Email.js +4 -823
- 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/MFARecoveryCode.d.ts +17 -0
- package/dist/models/MFARecoveryCode.d.ts.map +1 -0
- package/dist/models/MFARecoveryCode.js +55 -0
- package/dist/models/MFARecoveryCode.js.map +1 -0
- package/dist/models/MFATOTP.d.ts +44 -0
- package/dist/models/MFATOTP.d.ts.map +1 -0
- package/dist/models/MFATOTP.js +116 -0
- package/dist/models/MFATOTP.js.map +1 -0
- package/dist/models/MFAToken.d.ts +49 -0
- package/dist/models/MFAToken.d.ts.map +1 -0
- package/dist/models/MFAToken.js +137 -0
- package/dist/models/MFAToken.js.map +1 -0
- 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 -51
- package/dist/models/Organization.d.ts.map +1 -1
- package/dist/models/Organization.js +1 -530
- 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 +28 -4
- package/dist/models/Platform.d.ts.map +1 -1
- package/dist/models/Platform.js +111 -50
- 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/dist/models/Token.d.ts +40 -1
- package/dist/models/Token.d.ts.map +1 -1
- package/dist/models/Token.js +68 -2
- package/dist/models/Token.js.map +1 -1
- package/dist/models/User.d.ts +25 -0
- package/dist/models/User.d.ts.map +1 -1
- package/dist/models/User.js +36 -0
- package/dist/models/User.js.map +1 -1
- package/dist/models/WebauthnChallenge.d.ts +27 -0
- package/dist/models/WebauthnChallenge.d.ts.map +1 -0
- package/dist/models/WebauthnChallenge.js +81 -0
- package/dist/models/WebauthnChallenge.js.map +1 -0
- package/dist/models/WebauthnCredential.d.ts +58 -0
- package/dist/models/WebauthnCredential.d.ts.map +1 -0
- package/dist/models/WebauthnCredential.js +144 -0
- package/dist/models/WebauthnCredential.js.map +1 -0
- package/dist/models/index.d.ts +5 -0
- package/dist/models/index.d.ts.map +1 -1
- package/dist/models/index.js +5 -0
- package/dist/models/index.js.map +1 -1
- package/package.json +3 -3
- package/src/helpers/Handlebars.ts +5 -9
- package/src/helpers/errorToSimpleErrors.ts +17 -0
- package/src/index.ts +0 -1
- package/src/migrations/1782902314-tokens-authenticated-at.sql +2 -0
- package/src/migrations/1782902315-create-mfa-totp-table.sql +13 -0
- package/src/migrations/1782902316-create-webauthn-credentials-table.sql +17 -0
- package/src/migrations/1782902317-create-mfa-recovery-codes-table.sql +10 -0
- package/src/migrations/1782902318-create-mfa-tokens-table.sql +13 -0
- package/src/migrations/1782902319-create-webauthn-challenges-table.sql +10 -0
- package/src/migrations/1784039947-mfa-totp-last-used-counter.sql +2 -0
- package/src/migrations/1784122354-webauthn-credential-provider.sql +3 -0
- package/src/migrations/1784500000-webauthn-credential-rp-id.sql +9 -0
- package/src/migrations/1785354091-platform-parent-tenant-id.sql +1 -0
- package/src/migrations/1785354092-platform-fees-tenant-id.sql +1 -0
- package/src/migrations/1785354093-platform-uri.sql +1 -0
- package/src/migrations/1785354094-platform-domain.sql +1 -0
- package/src/migrations/1785354095-platform-uri-unique.sql +1 -0
- package/src/migrations/1785354096-platform-domain-unique.sql +1 -0
- package/src/migrations/1785354097-platform-parent-tenant-id-index.sql +1 -0
- package/src/migrations/1785354098-platform-tenant-backfill.ts +14 -0
- package/src/migrations/1785417301-users-last-active-at.sql +2 -0
- package/src/models/Document.ts +1 -84
- package/src/models/DocumentTemplate.ts +1 -71
- package/src/models/Email.ts +5 -941
- package/src/models/EmailVerificationCode.ts +0 -96
- package/src/models/Image.ts +11 -14
- package/src/models/MFARecoveryCode.ts +52 -0
- package/src/models/MFATOTP.ts +112 -0
- package/src/models/MFAToken.ts +138 -0
- package/src/models/MemberPlatformMembership.ts +1 -285
- package/src/models/Order.ts +1 -204
- package/src/models/Organization.ts +2 -637
- package/src/models/PasswordToken.ts +0 -29
- package/src/models/Platform.test.ts +167 -3
- package/src/models/Platform.ts +125 -50
- package/src/models/STPackage.ts +1 -110
- package/src/models/Token.ts +73 -2
- package/src/models/User.ts +37 -0
- package/src/models/WebauthnChallenge.ts +80 -0
- package/src/models/WebauthnCredential.ts +130 -0
- package/src/models/index.ts +6 -0
- package/dist/helpers/EmailBuilder.d.ts +0 -121
- package/dist/helpers/EmailBuilder.d.ts.map +0 -1
- package/dist/helpers/EmailBuilder.js +0 -659
- package/dist/helpers/EmailBuilder.js.map +0 -1
- package/src/helpers/EmailBuilder.test.ts +0 -291
- package/src/helpers/EmailBuilder.ts +0 -818
- package/src/models/Email.test.ts +0 -1222
- package/src/models/MemberPlatformMembership.test.ts +0 -70
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);
|