@stamhoofd/models 2.24.0 → 2.25.2
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/src/helpers/EmailBuilder.d.ts.map +1 -1
- package/dist/src/helpers/EmailBuilder.js +18 -7
- package/dist/src/helpers/EmailBuilder.js.map +1 -1
- package/dist/src/migrations/1724929140-default-templates-verify-email.sql +5 -0
- package/dist/src/migrations/1724939437-default-templates-invite-admin.sql +5 -0
- package/dist/src/models/Email.d.ts.map +1 -1
- package/dist/src/models/Email.js +9 -3
- package/dist/src/models/Email.js.map +1 -1
- package/dist/src/models/EmailRecipient.d.ts.map +1 -1
- package/dist/src/models/EmailRecipient.js.map +1 -1
- package/dist/src/models/EmailVerificationCode.d.ts +1 -1
- package/dist/src/models/EmailVerificationCode.d.ts.map +1 -1
- package/dist/src/models/EmailVerificationCode.js +44 -25
- package/dist/src/models/EmailVerificationCode.js.map +1 -1
- package/dist/src/models/Organization.d.ts +7 -9
- package/dist/src/models/Organization.d.ts.map +1 -1
- package/dist/src/models/Organization.js +20 -35
- package/dist/src/models/Organization.js.map +1 -1
- package/package.json +2 -2
- package/src/helpers/EmailBuilder.ts +22 -8
- package/src/migrations/1724929140-default-templates-verify-email.sql +5 -0
- package/src/migrations/1724939437-default-templates-invite-admin.sql +5 -0
- package/src/models/Email.ts +9 -3
- package/src/models/EmailRecipient.ts +1 -0
- package/src/models/EmailVerificationCode.ts +46 -27
- package/src/models/Organization.ts +21 -41
|
@@ -130,27 +130,19 @@ export class Organization extends Model {
|
|
|
130
130
|
|
|
131
131
|
// Methods
|
|
132
132
|
static async getByEmail(email: string): Promise<Organization | undefined> {
|
|
133
|
-
if (["hallo@stamhoofd.be", "hallo@stamhoofd.nl"].includes(email)) {
|
|
134
|
-
return
|
|
135
|
-
}
|
|
136
133
|
if (email.startsWith('noreply-')) {
|
|
137
134
|
// Trim
|
|
138
135
|
email = email.substring("noreply-".length)
|
|
139
136
|
}
|
|
140
137
|
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
if (email.endsWith("@stamhoofd.nl")) {
|
|
152
|
-
const uri = email.substring(0, email.length - "@stamhoofd.nl".length)
|
|
153
|
-
return await Organization.getByURI(uri)
|
|
138
|
+
for (const domain of [
|
|
139
|
+
...Object.values(STAMHOOFD.domains.defaultBroadcastEmail ?? {}),
|
|
140
|
+
...Object.values(STAMHOOFD.domains.defaultTransactionalEmail ?? {}),
|
|
141
|
+
]) {
|
|
142
|
+
if (email.endsWith("@" + domain)) {
|
|
143
|
+
const uri = email.substring(0, email.length - ("@" + domain).length)
|
|
144
|
+
return await Organization.getByURI(uri)
|
|
145
|
+
}
|
|
154
146
|
}
|
|
155
147
|
|
|
156
148
|
const at = email.indexOf("@");
|
|
@@ -872,38 +864,27 @@ export class Organization extends Model {
|
|
|
872
864
|
}
|
|
873
865
|
|
|
874
866
|
/**
|
|
875
|
-
*
|
|
867
|
+
* Return default e-mail address if no email addresses are set.
|
|
876
868
|
*/
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
const User = (await import('./User')).User;
|
|
880
|
-
const admins = await User.where({ organizationId: this.id, permissions: { sign: "!=", value: null }})
|
|
881
|
-
const filtered = admins.filter(a => a.permissions?.forOrganization(this)?.hasAccessRight(AccessRight.OrganizationFinanceDirector))
|
|
882
|
-
|
|
883
|
-
if (filtered.length > 0) {
|
|
884
|
-
return filtered.map(f => f.getEmailTo() ).join(", ")
|
|
885
|
-
}
|
|
869
|
+
getDefaultFrom(i18n: I18n, withName = true, type: 'transactional' | 'broadcast' = 'broadcast') {
|
|
870
|
+
const domain = type === 'transactional' ? i18n.localizedDomains.defaultTransactionalEmail() : i18n.localizedDomains.defaultBroadcastEmail()
|
|
886
871
|
|
|
887
|
-
return undefined
|
|
888
|
-
}
|
|
889
|
-
|
|
890
|
-
/**
|
|
891
|
-
* Return default e-mail address for important e-mails that should have the highest deliverability
|
|
892
|
-
*/
|
|
893
|
-
getStrongEmail(i18n: I18n, withName = true) {
|
|
894
872
|
if (!withName) {
|
|
895
|
-
return ('noreply-' + this.uri+"@"+
|
|
873
|
+
return ('noreply-' + this.uri+"@"+domain);
|
|
896
874
|
}
|
|
897
|
-
return '"'+this.name.replaceAll("\"", "\\\"")+'" <'+ ('noreply-' + this.uri+"@"+
|
|
875
|
+
return '"'+this.name.replaceAll("\"", "\\\"")+'" <'+ ('noreply-' + this.uri+"@"+domain) +'>'
|
|
898
876
|
}
|
|
899
877
|
|
|
878
|
+
/**
|
|
879
|
+
* @deprecated Switch to EmailBuilder.sendEmailTemplate
|
|
880
|
+
*/
|
|
900
881
|
getEmail(id: string | null, strongDefault = false): { from: string; replyTo: string | undefined } {
|
|
901
882
|
if (id === null) {
|
|
902
883
|
return this.getDefaultEmail(strongDefault)
|
|
903
884
|
}
|
|
904
885
|
|
|
905
886
|
// Send confirmation e-mail
|
|
906
|
-
let from =
|
|
887
|
+
let from = this.getDefaultFrom(this.i18n, false, strongDefault ? 'transactional' : 'broadcast')
|
|
907
888
|
const sender: OrganizationEmail | undefined = this.privateMeta.emails.find(e => e.id === id)
|
|
908
889
|
let replyTo: string | undefined = undefined
|
|
909
890
|
|
|
@@ -935,13 +916,12 @@ export class Organization extends Model {
|
|
|
935
916
|
return this.getDefaultEmail(strongDefault)
|
|
936
917
|
}
|
|
937
918
|
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
919
|
+
/**
|
|
920
|
+
* @deprecated Switch to EmailBuilder.sendEmailTemplate
|
|
921
|
+
*/
|
|
942
922
|
getDefaultEmail(strongDefault = false): { from: string; replyTo: string | undefined } {
|
|
943
923
|
// Send confirmation e-mail
|
|
944
|
-
let from = strongDefault ? this.
|
|
924
|
+
let from = strongDefault ? this.getDefaultFrom(this.i18n, false) : this.uri+"@stamhoofd.email";
|
|
945
925
|
const sender: OrganizationEmail | undefined = this.privateMeta.emails.find(e => e.default) ?? this.privateMeta.emails[0];
|
|
946
926
|
let replyTo: string | undefined = undefined
|
|
947
927
|
|