@stamhoofd/models 2.39.0 → 2.40.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/src/factories/AddressFactory.d.ts +3 -4
- package/dist/src/factories/AddressFactory.d.ts.map +1 -1
- package/dist/src/factories/AddressFactory.js +13 -13
- package/dist/src/factories/EmergencyContactFactory.d.ts +3 -4
- package/dist/src/factories/EmergencyContactFactory.d.ts.map +1 -1
- package/dist/src/factories/EmergencyContactFactory.js +27 -27
- package/dist/src/factories/EmergencyContactFactory.js.map +1 -1
- package/dist/src/factories/GroupFactory.d.ts +4 -4
- package/dist/src/factories/GroupFactory.d.ts.map +1 -1
- package/dist/src/factories/GroupFactory.js +8 -8
- package/dist/src/factories/GroupFactory.js.map +1 -1
- package/dist/src/factories/MemberFactory.d.ts +4 -4
- package/dist/src/factories/MemberFactory.d.ts.map +1 -1
- package/dist/src/factories/MemberFactory.js +17 -17
- package/dist/src/factories/MemberFactory.js.map +1 -1
- package/dist/src/factories/OrganizationFactory.d.ts +4 -4
- package/dist/src/factories/OrganizationFactory.js +8 -8
- package/dist/src/factories/OrganizationFactory.js.map +1 -1
- package/dist/src/factories/ParentFactory.d.ts +1 -1
- package/dist/src/factories/ParentFactory.js +19 -19
- package/dist/src/factories/ParentFactory.js.map +1 -1
- package/dist/src/factories/RecordFactory.d.ts +2 -3
- package/dist/src/factories/RecordFactory.d.ts.map +1 -1
- package/dist/src/factories/RecordFactory.js +1 -1
- package/dist/src/factories/RecordFactory.js.map +1 -1
- package/dist/src/factories/RegisterCodeFactory.d.ts +2 -2
- package/dist/src/factories/RegisterCodeFactory.d.ts.map +1 -1
- package/dist/src/factories/RegisterCodeFactory.js +2 -2
- package/dist/src/factories/RegistrationFactory.d.ts +3 -3
- package/dist/src/factories/RegistrationFactory.d.ts.map +1 -1
- package/dist/src/factories/RegistrationFactory.js.map +1 -1
- package/dist/src/factories/RegistrationPeriodFactory.d.ts +2 -2
- package/dist/src/factories/RegistrationPeriodFactory.js.map +1 -1
- package/dist/src/factories/UserFactory.d.ts +3 -3
- package/dist/src/factories/UserFactory.d.ts.map +1 -1
- package/dist/src/factories/UserFactory.js +3 -3
- package/dist/src/factories/UserFactory.js.map +1 -1
- package/dist/src/factories/WebshopFactory.d.ts +4 -4
- package/dist/src/factories/WebshopFactory.d.ts.map +1 -1
- package/dist/src/factories/WebshopFactory.js +1 -1
- package/dist/src/factories/WebshopFactory.js.map +1 -1
- package/dist/src/helpers/DNSValidator.d.ts +1 -1
- package/dist/src/helpers/DNSValidator.d.ts.map +1 -1
- package/dist/src/helpers/DNSValidator.js +33 -33
- package/dist/src/helpers/DNSValidator.js.map +1 -1
- package/dist/src/helpers/EmailBuilder.d.ts +10 -10
- package/dist/src/helpers/EmailBuilder.d.ts.map +1 -1
- package/dist/src/helpers/EmailBuilder.js +34 -34
- package/dist/src/helpers/EmailBuilder.js.map +1 -1
- package/dist/src/helpers/GroupBuilder.d.ts.map +1 -1
- package/dist/src/helpers/GroupBuilder.js +57 -57
- package/dist/src/helpers/GroupBuilder.js.map +1 -1
- package/dist/src/helpers/Handlebars.d.ts.map +1 -1
- package/dist/src/helpers/Handlebars.js +29 -29
- package/dist/src/helpers/Handlebars.js.map +1 -1
- package/dist/src/helpers/MemberMerger.d.ts +1 -1
- package/dist/src/helpers/MemberMerger.d.ts.map +1 -1
- package/dist/src/helpers/MemberMerger.js +33 -33
- package/dist/src/helpers/MemberMerger.js.map +1 -1
- package/dist/src/helpers/MemberMerger.test.js +194 -194
- package/dist/src/helpers/MemberMerger.test.js.map +1 -1
- package/dist/src/helpers/RateLimiter.d.ts.map +1 -1
- package/dist/src/helpers/RateLimiter.js +2 -2
- package/dist/src/helpers/RateLimiter.js.map +1 -1
- package/dist/src/helpers/SetupStepsUpdater.d.ts +22 -0
- package/dist/src/helpers/SetupStepsUpdater.d.ts.map +1 -0
- package/dist/src/helpers/SetupStepsUpdater.js +255 -0
- package/dist/src/helpers/SetupStepsUpdater.js.map +1 -0
- package/dist/src/helpers/WebshopCounter.d.ts +1 -1
- package/dist/src/helpers/WebshopCounter.d.ts.map +1 -1
- package/dist/src/helpers/WebshopCounter.js +1 -1
- package/dist/src/helpers/WebshopCounter.js.map +1 -1
- package/dist/src/helpers/WebshopCounter.test.js +6 -6
- package/dist/src/helpers/WebshopCounter.test.js.map +1 -1
- package/dist/src/index.d.ts +20 -19
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +1 -0
- package/dist/src/index.js.map +1 -1
- package/dist/src/migrations/1605262045-import-postcodes.js +12 -12
- package/dist/src/migrations/1605262046-import-postcodes-nl.js +10 -10
- package/dist/src/models/BalanceItem.d.ts.map +1 -1
- package/dist/src/models/BalanceItem.js +37 -37
- package/dist/src/models/BalanceItem.js.map +1 -1
- package/dist/src/models/BalanceItemPayment.d.ts.map +1 -1
- package/dist/src/models/BalanceItemPayment.js +13 -13
- package/dist/src/models/BalanceItemPayment.js.map +1 -1
- package/dist/src/models/BuckarooPayment.d.ts +1 -1
- package/dist/src/models/BuckarooPayment.d.ts.map +1 -1
- package/dist/src/models/BuckarooPayment.js +5 -5
- package/dist/src/models/BuckarooPayment.js.map +1 -1
- package/dist/src/models/CachedOutstandingBalance.d.ts.map +1 -1
- package/dist/src/models/CachedOutstandingBalance.js +37 -37
- package/dist/src/models/CachedOutstandingBalance.js.map +1 -1
- package/dist/src/models/Document.d.ts +4 -4
- package/dist/src/models/Document.d.ts.map +1 -1
- package/dist/src/models/Document.js +27 -27
- package/dist/src/models/Document.js.map +1 -1
- package/dist/src/models/DocumentTemplate.d.ts +4 -4
- package/dist/src/models/DocumentTemplate.d.ts.map +1 -1
- package/dist/src/models/DocumentTemplate.js +72 -72
- package/dist/src/models/DocumentTemplate.js.map +1 -1
- package/dist/src/models/Email.d.ts.map +1 -1
- package/dist/src/models/Email.js +63 -64
- 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 +20 -20
- package/dist/src/models/EmailRecipient.js.map +1 -1
- package/dist/src/models/EmailTemplate.d.ts +3 -3
- package/dist/src/models/EmailTemplate.d.ts.map +1 -1
- package/dist/src/models/EmailTemplate.js +16 -16
- package/dist/src/models/EmailTemplate.js.map +1 -1
- package/dist/src/models/EmailVerificationCode.d.ts +2 -2
- package/dist/src/models/EmailVerificationCode.d.ts.map +1 -1
- package/dist/src/models/EmailVerificationCode.js +57 -55
- package/dist/src/models/EmailVerificationCode.js.map +1 -1
- package/dist/src/models/Event.d.ts +2 -2
- package/dist/src/models/Event.d.ts.map +1 -1
- package/dist/src/models/Event.js +15 -15
- package/dist/src/models/Event.js.map +1 -1
- package/dist/src/models/Group.d.ts +3 -1
- package/dist/src/models/Group.d.ts.map +1 -1
- package/dist/src/models/Group.js +46 -35
- package/dist/src/models/Group.js.map +1 -1
- package/dist/src/models/Image.d.ts +1 -1
- package/dist/src/models/Image.d.ts.map +1 -1
- package/dist/src/models/Image.js +26 -26
- package/dist/src/models/Image.js.map +1 -1
- package/dist/src/models/Member.d.ts +8 -8
- package/dist/src/models/Member.d.ts.map +1 -1
- package/dist/src/models/Member.js +60 -60
- package/dist/src/models/Member.js.map +1 -1
- package/dist/src/models/MemberPlatformMembership.d.ts +3 -3
- package/dist/src/models/MemberPlatformMembership.d.ts.map +1 -1
- package/dist/src/models/MemberPlatformMembership.js +26 -26
- package/dist/src/models/MemberPlatformMembership.js.map +1 -1
- package/dist/src/models/MemberResponsibilityRecord.d.ts.map +1 -1
- package/dist/src/models/MemberResponsibilityRecord.js +13 -13
- package/dist/src/models/MemberResponsibilityRecord.js.map +1 -1
- package/dist/src/models/MergedMember.d.ts +3 -3
- package/dist/src/models/MergedMember.d.ts.map +1 -1
- package/dist/src/models/MergedMember.js +19 -19
- package/dist/src/models/MergedMember.js.map +1 -1
- package/dist/src/models/MolliePayment.d.ts +1 -1
- package/dist/src/models/MolliePayment.d.ts.map +1 -1
- package/dist/src/models/MolliePayment.js +5 -5
- package/dist/src/models/MolliePayment.js.map +1 -1
- package/dist/src/models/MollieToken.d.ts.map +1 -1
- package/dist/src/models/MollieToken.js +60 -60
- package/dist/src/models/MollieToken.js.map +1 -1
- package/dist/src/models/OneTimeToken.d.ts +2 -2
- package/dist/src/models/OneTimeToken.d.ts.map +1 -1
- package/dist/src/models/OneTimeToken.js +13 -13
- package/dist/src/models/OneTimeToken.js.map +1 -1
- package/dist/src/models/Order.d.ts +1 -1
- package/dist/src/models/Order.d.ts.map +1 -1
- package/dist/src/models/Order.js +70 -70
- package/dist/src/models/Order.js.map +1 -1
- package/dist/src/models/Organization.d.ts +5 -5
- package/dist/src/models/Organization.d.ts.map +1 -1
- package/dist/src/models/Organization.js +127 -127
- package/dist/src/models/Organization.js.map +1 -1
- package/dist/src/models/OrganizationRegistrationPeriod.d.ts.map +1 -1
- package/dist/src/models/OrganizationRegistrationPeriod.js +15 -15
- package/dist/src/models/OrganizationRegistrationPeriod.js.map +1 -1
- package/dist/src/models/PasswordToken.d.ts +3 -3
- package/dist/src/models/PasswordToken.d.ts.map +1 -1
- package/dist/src/models/PasswordToken.js +17 -17
- package/dist/src/models/PasswordToken.js.map +1 -1
- package/dist/src/models/PayconiqPayment.d.ts +1 -1
- package/dist/src/models/PayconiqPayment.d.ts.map +1 -1
- package/dist/src/models/PayconiqPayment.js +49 -49
- package/dist/src/models/PayconiqPayment.js.map +1 -1
- package/dist/src/models/Payment.d.ts +3 -3
- package/dist/src/models/Payment.d.ts.map +1 -1
- package/dist/src/models/Payment.js +36 -36
- package/dist/src/models/Payment.js.map +1 -1
- package/dist/src/models/Platform.d.ts +2 -2
- package/dist/src/models/Platform.d.ts.map +1 -1
- package/dist/src/models/Platform.js +8 -8
- package/dist/src/models/Platform.js.map +1 -1
- package/dist/src/models/RegisterCode.d.ts +1 -1
- package/dist/src/models/RegisterCode.d.ts.map +1 -1
- package/dist/src/models/RegisterCode.js +11 -11
- package/dist/src/models/RegisterCode.js.map +1 -1
- package/dist/src/models/Registration.d.ts +1 -1
- package/dist/src/models/Registration.d.ts.map +1 -1
- package/dist/src/models/Registration.js +88 -88
- package/dist/src/models/Registration.js.map +1 -1
- package/dist/src/models/RegistrationPeriod.d.ts.map +1 -1
- package/dist/src/models/RegistrationPeriod.js +12 -12
- package/dist/src/models/RegistrationPeriod.js.map +1 -1
- package/dist/src/models/STCredit.d.ts +1 -1
- package/dist/src/models/STCredit.d.ts.map +1 -1
- package/dist/src/models/STCredit.js +12 -12
- package/dist/src/models/STCredit.js.map +1 -1
- package/dist/src/models/STInvoice.d.ts +1 -1
- package/dist/src/models/STInvoice.d.ts.map +1 -1
- package/dist/src/models/STInvoice.js +16 -16
- package/dist/src/models/STInvoice.js.map +1 -1
- package/dist/src/models/STPackage.d.ts +1 -1
- package/dist/src/models/STPackage.d.ts.map +1 -1
- package/dist/src/models/STPackage.js +39 -39
- package/dist/src/models/STPackage.js.map +1 -1
- package/dist/src/models/STPendingInvoice.d.ts +1 -1
- package/dist/src/models/STPendingInvoice.d.ts.map +1 -1
- package/dist/src/models/STPendingInvoice.js +11 -11
- package/dist/src/models/STPendingInvoice.js.map +1 -1
- package/dist/src/models/StripeAccount.d.ts.map +1 -1
- package/dist/src/models/StripeAccount.js +13 -13
- package/dist/src/models/StripeAccount.js.map +1 -1
- package/dist/src/models/StripeCheckoutSession.d.ts +1 -1
- package/dist/src/models/StripeCheckoutSession.d.ts.map +1 -1
- package/dist/src/models/StripeCheckoutSession.js +7 -7
- package/dist/src/models/StripeCheckoutSession.js.map +1 -1
- package/dist/src/models/StripePaymentIntent.d.ts +1 -1
- package/dist/src/models/StripePaymentIntent.d.ts.map +1 -1
- package/dist/src/models/StripePaymentIntent.js +7 -7
- package/dist/src/models/StripePaymentIntent.js.map +1 -1
- package/dist/src/models/Ticket.d.ts +2 -2
- package/dist/src/models/Ticket.d.ts.map +1 -1
- package/dist/src/models/Ticket.js +23 -23
- package/dist/src/models/Ticket.js.map +1 -1
- package/dist/src/models/Token.d.ts +3 -3
- package/dist/src/models/Token.d.ts.map +1 -1
- package/dist/src/models/Token.js +27 -27
- package/dist/src/models/Token.js.map +1 -1
- package/dist/src/models/Token.test.js +11 -11
- package/dist/src/models/UsedRegisterCode.d.ts +1 -1
- package/dist/src/models/UsedRegisterCode.d.ts.map +1 -1
- package/dist/src/models/UsedRegisterCode.js +10 -10
- package/dist/src/models/UsedRegisterCode.js.map +1 -1
- package/dist/src/models/User.d.ts +4 -4
- package/dist/src/models/User.d.ts.map +1 -1
- package/dist/src/models/User.js +53 -51
- package/dist/src/models/User.js.map +1 -1
- package/dist/src/models/UserPermissions.d.ts +3 -3
- package/dist/src/models/UserPermissions.d.ts.map +1 -1
- package/dist/src/models/UserPermissions.js +12 -12
- package/dist/src/models/UserPermissions.js.map +1 -1
- package/dist/src/models/Webshop.d.ts +1 -1
- package/dist/src/models/Webshop.d.ts.map +1 -1
- package/dist/src/models/Webshop.js +23 -23
- package/dist/src/models/Webshop.js.map +1 -1
- package/dist/src/models/WebshopDiscountCode.d.ts +1 -1
- package/dist/src/models/WebshopDiscountCode.d.ts.map +1 -1
- package/dist/src/models/WebshopDiscountCode.js +16 -16
- package/dist/src/models/WebshopDiscountCode.js.map +1 -1
- package/dist/src/models/addresses/City.d.ts.map +1 -1
- package/dist/src/models/addresses/City.js +9 -9
- package/dist/src/models/addresses/City.js.map +1 -1
- package/dist/src/models/addresses/PostalCode.d.ts.map +1 -1
- package/dist/src/models/addresses/PostalCode.js +11 -11
- package/dist/src/models/addresses/PostalCode.js.map +1 -1
- package/dist/src/models/addresses/PostalCode.test.js +22 -22
- package/dist/src/models/addresses/PostalCode.test.js.map +1 -1
- package/dist/src/models/addresses/Province.d.ts.map +1 -1
- package/dist/src/models/addresses/Province.js +5 -5
- package/dist/src/models/addresses/Province.js.map +1 -1
- package/dist/src/models/addresses/Street.d.ts.map +1 -1
- package/dist/src/models/addresses/Street.js +6 -6
- package/dist/src/models/addresses/Street.js.map +1 -1
- package/dist/src/models/index.d.ts +46 -46
- package/dist/src/models/index.d.ts.map +1 -1
- package/dist/src/models/index.js +0 -1
- package/dist/src/models/index.js.map +1 -1
- package/dist/src/structures/OrganizationServerMetaData.d.ts.map +1 -1
- package/dist/src/structures/OrganizationServerMetaData.js +4 -4
- package/dist/src/structures/OrganizationServerMetaData.js.map +1 -1
- package/dist/tests/jest.global.setup.d.ts.map +1 -1
- package/dist/tests/jest.global.setup.js +15 -13
- package/dist/tests/jest.global.setup.js.map +1 -1
- package/dist/tests/jest.setup.js +3 -1
- package/dist/tests/jest.setup.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/package.json +3 -3
- package/src/factories/AddressFactory.ts +17 -17
- package/src/factories/EmergencyContactFactory.ts +30 -31
- package/src/factories/GroupFactory.ts +30 -30
- package/src/factories/MemberFactory.ts +41 -38
- package/src/factories/OrganizationFactory.ts +15 -15
- package/src/factories/ParentFactory.ts +24 -24
- package/src/factories/RecordFactory.ts +5 -4
- package/src/factories/RegisterCodeFactory.ts +7 -7
- package/src/factories/RegistrationFactory.ts +16 -16
- package/src/factories/RegistrationPeriodFactory.ts +5 -5
- package/src/factories/UserFactory.ts +20 -19
- package/src/factories/WebshopFactory.ts +14 -14
- package/src/helpers/DNSValidator.ts +89 -84
- package/src/helpers/EmailBuilder.ts +141 -135
- package/src/helpers/GroupBuilder.ts +181 -181
- package/src/helpers/Handlebars.ts +57 -54
- package/src/helpers/MemberMerger.test.ts +702 -702
- package/src/helpers/MemberMerger.ts +83 -77
- package/src/helpers/RateLimiter.ts +25 -27
- package/src/helpers/SetupStepsUpdater.ts +402 -0
- package/src/helpers/WebshopCounter.test.ts +12 -12
- package/src/helpers/WebshopCounter.ts +20 -19
- package/src/index.ts +20 -19
- package/src/migrations/1605262045-import-postcodes.ts +59 -63
- package/src/migrations/1605262046-import-postcodes-nl.ts +41 -43
- package/src/models/BalanceItem.ts +173 -172
- package/src/models/BalanceItemPayment.ts +32 -33
- package/src/models/BuckarooPayment.ts +7 -7
- package/src/models/CachedOutstandingBalance.ts +98 -99
- package/src/models/Document.ts +90 -87
- package/src/models/DocumentTemplate.ts +207 -198
- package/src/models/Email.ts +198 -200
- package/src/models/EmailRecipient.ts +38 -39
- package/src/models/EmailTemplate.ts +36 -37
- package/src/models/EmailVerificationCode.ts +146 -142
- package/src/models/Event.ts +53 -53
- package/src/models/Group.ts +136 -123
- package/src/models/Image.ts +48 -48
- package/src/models/Member.ts +277 -275
- package/src/models/MemberPlatformMembership.ts +71 -71
- package/src/models/MemberResponsibilityRecord.ts +32 -32
- package/src/models/MergedMember.ts +77 -77
- package/src/models/MolliePayment.ts +7 -7
- package/src/models/MollieToken.ts +131 -126
- package/src/models/OneTimeToken.ts +40 -39
- package/src/models/Order.ts +379 -372
- package/src/models/Organization.ts +332 -325
- package/src/models/OrganizationRegistrationPeriod.ts +50 -50
- package/src/models/PasswordToken.ts +42 -42
- package/src/models/PayconiqPayment.ts +80 -76
- package/src/models/Payment.ts +86 -86
- package/src/models/Platform.ts +21 -22
- package/src/models/RegisterCode.ts +26 -26
- package/src/models/Registration.ts +167 -168
- package/src/models/RegistrationPeriod.ts +29 -29
- package/src/models/STCredit.ts +24 -25
- package/src/models/STInvoice.ts +34 -34
- package/src/models/STPackage.ts +143 -136
- package/src/models/STPendingInvoice.ts +26 -26
- package/src/models/StripeAccount.ts +27 -27
- package/src/models/StripeCheckoutSession.ts +10 -10
- package/src/models/StripePaymentIntent.ts +10 -10
- package/src/models/Ticket.ts +51 -52
- package/src/models/Token.test.ts +13 -13
- package/src/models/Token.ts +64 -63
- package/src/models/UsedRegisterCode.ts +20 -21
- package/src/models/User.ts +148 -144
- package/src/models/UserPermissions.ts +25 -28
- package/src/models/Webshop.ts +53 -53
- package/src/models/WebshopDiscountCode.ts +33 -33
- package/src/models/addresses/City.ts +12 -12
- package/src/models/addresses/PostalCode.test.ts +68 -69
- package/src/models/addresses/PostalCode.ts +57 -57
- package/src/models/addresses/Province.ts +8 -8
- package/src/models/addresses/Street.ts +10 -12
- package/src/models/index.ts +54 -55
- package/src/structures/OrganizationServerMetaData.ts +36 -36
|
@@ -1,28 +1,28 @@
|
|
|
1
|
-
import { column,Model } from
|
|
2
|
-
import { v4 as uuidv4 } from
|
|
1
|
+
import { column, Model } from '@simonbackx/simple-database';
|
|
2
|
+
import { v4 as uuidv4 } from 'uuid';
|
|
3
3
|
|
|
4
4
|
export class StripeCheckoutSession extends Model {
|
|
5
|
-
static table =
|
|
5
|
+
static table = 'stripe_checkout_sessions';
|
|
6
6
|
|
|
7
7
|
@column({
|
|
8
|
-
primary: true, type:
|
|
8
|
+
primary: true, type: 'string', beforeSave(value) {
|
|
9
9
|
return value ?? uuidv4();
|
|
10
|
-
}
|
|
10
|
+
},
|
|
11
11
|
})
|
|
12
12
|
id!: string;
|
|
13
13
|
|
|
14
|
-
@column({ type:
|
|
14
|
+
@column({ type: 'string' })
|
|
15
15
|
paymentId: string;
|
|
16
16
|
|
|
17
|
-
@column({ type:
|
|
17
|
+
@column({ type: 'string' })
|
|
18
18
|
stripeSessionId: string;
|
|
19
19
|
|
|
20
|
-
@column({ type:
|
|
20
|
+
@column({ type: 'string', nullable: true })
|
|
21
21
|
organizationId: string | null = null;
|
|
22
22
|
|
|
23
23
|
/**
|
|
24
24
|
* For direct charges, this should be set
|
|
25
25
|
*/
|
|
26
|
-
@column({ type:
|
|
27
|
-
accountId: string|null = null
|
|
26
|
+
@column({ type: 'string', nullable: true })
|
|
27
|
+
accountId: string | null = null;
|
|
28
28
|
}
|
|
@@ -1,28 +1,28 @@
|
|
|
1
|
-
import { column,Model } from
|
|
2
|
-
import { v4 as uuidv4 } from
|
|
1
|
+
import { column, Model } from '@simonbackx/simple-database';
|
|
2
|
+
import { v4 as uuidv4 } from 'uuid';
|
|
3
3
|
|
|
4
4
|
export class StripePaymentIntent extends Model {
|
|
5
|
-
static table =
|
|
5
|
+
static table = 'stripe_payment_intents';
|
|
6
6
|
|
|
7
7
|
@column({
|
|
8
|
-
primary: true, type:
|
|
8
|
+
primary: true, type: 'string', beforeSave(value) {
|
|
9
9
|
return value ?? uuidv4();
|
|
10
|
-
}
|
|
10
|
+
},
|
|
11
11
|
})
|
|
12
12
|
id!: string;
|
|
13
13
|
|
|
14
|
-
@column({ type:
|
|
14
|
+
@column({ type: 'string' })
|
|
15
15
|
paymentId: string;
|
|
16
16
|
|
|
17
|
-
@column({ type:
|
|
17
|
+
@column({ type: 'string' })
|
|
18
18
|
stripeIntentId: string;
|
|
19
19
|
|
|
20
|
-
@column({ type:
|
|
20
|
+
@column({ type: 'string', nullable: true })
|
|
21
21
|
organizationId: string | null = null;
|
|
22
22
|
|
|
23
23
|
/**
|
|
24
24
|
* For direct charges, this should be set
|
|
25
25
|
*/
|
|
26
|
-
@column({ type:
|
|
27
|
-
accountId: string|null = null
|
|
26
|
+
@column({ type: 'string', nullable: true })
|
|
27
|
+
accountId: string | null = null;
|
|
28
28
|
}
|
package/src/models/Ticket.ts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import { column, ManyToOneRelation, Model } from
|
|
2
|
-
import { CartReservedSeat } from
|
|
3
|
-
import basex from
|
|
4
|
-
import crypto from
|
|
5
|
-
import { v4 as uuidv4 } from
|
|
1
|
+
import { column, ManyToOneRelation, Model } from '@simonbackx/simple-database';
|
|
2
|
+
import { CartReservedSeat } from '@stamhoofd/structures';
|
|
3
|
+
import basex from 'base-x';
|
|
4
|
+
import crypto from 'crypto';
|
|
5
|
+
import { v4 as uuidv4 } from 'uuid';
|
|
6
6
|
|
|
7
7
|
import { Order, Organization, Webshop } from './';
|
|
8
8
|
|
|
9
9
|
// Note: 0 and O is removed to prevent typing it in wrong
|
|
10
|
-
const ALPHABET = '123456789ABCDEFGHJKLMNPQRSTUVWXYZ'
|
|
11
|
-
const bs58 = basex(ALPHABET)
|
|
10
|
+
const ALPHABET = '123456789ABCDEFGHJKLMNPQRSTUVWXYZ';
|
|
11
|
+
const bs58 = basex(ALPHABET);
|
|
12
12
|
|
|
13
13
|
async function randomBytes(size: number): Promise<Buffer> {
|
|
14
14
|
return new Promise((resolve, reject) => {
|
|
@@ -24,33 +24,32 @@ async function randomBytes(size: number): Promise<Buffer> {
|
|
|
24
24
|
|
|
25
25
|
/**
|
|
26
26
|
* Use this method when you don't need access to the items of an order.
|
|
27
|
-
* This avoids the select in the database, saving some bytes in network communication
|
|
27
|
+
* This avoids the select in the database, saving some bytes in network communication
|
|
28
28
|
* (especially needed when clients requests all the changed tickets)
|
|
29
29
|
*/
|
|
30
30
|
export class Ticket extends Model {
|
|
31
|
-
static table =
|
|
31
|
+
static table = 'webshop_tickets';
|
|
32
32
|
|
|
33
33
|
// Columns
|
|
34
34
|
@column({
|
|
35
|
-
primary: true, type:
|
|
35
|
+
primary: true, type: 'string', beforeSave(value) {
|
|
36
36
|
return value ?? uuidv4();
|
|
37
|
-
}
|
|
37
|
+
},
|
|
38
38
|
})
|
|
39
39
|
id!: string;
|
|
40
40
|
|
|
41
41
|
/**
|
|
42
42
|
* Unique per webshop. Used for lookups
|
|
43
43
|
*/
|
|
44
|
-
@column({ type:
|
|
44
|
+
@column({ type: 'string', async beforeSave(value) {
|
|
45
45
|
return value ?? bs58.encode(await randomBytes(10));
|
|
46
46
|
} })
|
|
47
|
-
secret!: string
|
|
48
|
-
|
|
47
|
+
secret!: string;
|
|
49
48
|
|
|
50
|
-
@column({ foreignKey: Ticket.organization, type:
|
|
49
|
+
@column({ foreignKey: Ticket.organization, type: 'string' })
|
|
51
50
|
organizationId: string;
|
|
52
51
|
|
|
53
|
-
@column({ foreignKey: Ticket.webshop, type:
|
|
52
|
+
@column({ foreignKey: Ticket.webshop, type: 'string' })
|
|
54
53
|
webshopId: string;
|
|
55
54
|
|
|
56
55
|
/**
|
|
@@ -59,76 +58,76 @@ export class Ticket extends Model {
|
|
|
59
58
|
* The order details should remain private to a ticket holder except for the item details
|
|
60
59
|
* + also the orderID should remain private for the holder (since this provides access via URL, need to add a secret here)
|
|
61
60
|
*/
|
|
62
|
-
@column({ foreignKey: Ticket.order, type:
|
|
63
|
-
orderId: string
|
|
61
|
+
@column({ foreignKey: Ticket.order, type: 'string' })
|
|
62
|
+
orderId: string;
|
|
64
63
|
|
|
65
64
|
/**
|
|
66
65
|
* null = whole order
|
|
67
66
|
*/
|
|
68
|
-
@column({ type:
|
|
69
|
-
itemId: string | null = null
|
|
67
|
+
@column({ type: 'string', nullable: true })
|
|
68
|
+
itemId: string | null = null;
|
|
70
69
|
|
|
71
70
|
/**
|
|
72
71
|
* If multiple items are made for the same product, this contains the index
|
|
73
72
|
*/
|
|
74
|
-
@column({ type:
|
|
75
|
-
index = 0
|
|
73
|
+
@column({ type: 'number' })
|
|
74
|
+
index = 0;
|
|
76
75
|
|
|
77
76
|
/**
|
|
78
77
|
* total items with index
|
|
79
78
|
*/
|
|
80
|
-
@column({ type:
|
|
81
|
-
total = 0
|
|
79
|
+
@column({ type: 'number' })
|
|
80
|
+
total = 0;
|
|
82
81
|
|
|
83
82
|
/**
|
|
84
83
|
* If multiple items are made for the same product, this contains the index
|
|
85
84
|
*/
|
|
86
|
-
@column({ type:
|
|
87
|
-
seat: CartReservedSeat | null = null
|
|
85
|
+
@column({ type: 'json', nullable: true, decoder: CartReservedSeat })
|
|
86
|
+
seat: CartReservedSeat | null = null;
|
|
88
87
|
|
|
89
88
|
/**
|
|
90
89
|
* In case the seat is changed, this contains the first assigned seat
|
|
91
90
|
*/
|
|
92
|
-
@column({ type:
|
|
93
|
-
originalSeat: CartReservedSeat | null = null
|
|
91
|
+
@column({ type: 'json', nullable: true, decoder: CartReservedSeat })
|
|
92
|
+
originalSeat: CartReservedSeat | null = null;
|
|
94
93
|
|
|
95
94
|
@column({
|
|
96
|
-
type:
|
|
95
|
+
type: 'datetime', beforeSave(old?: any) {
|
|
97
96
|
if (old !== undefined) {
|
|
98
97
|
return old;
|
|
99
98
|
}
|
|
100
|
-
const date = new Date()
|
|
101
|
-
date.setMilliseconds(0)
|
|
102
|
-
return date
|
|
103
|
-
}
|
|
99
|
+
const date = new Date();
|
|
100
|
+
date.setMilliseconds(0);
|
|
101
|
+
return date;
|
|
102
|
+
},
|
|
104
103
|
})
|
|
105
|
-
createdAt: Date
|
|
104
|
+
createdAt: Date;
|
|
106
105
|
|
|
107
106
|
@column({
|
|
108
|
-
type:
|
|
109
|
-
const date = new Date()
|
|
110
|
-
date.setMilliseconds(0)
|
|
111
|
-
return date
|
|
107
|
+
type: 'datetime', beforeSave() {
|
|
108
|
+
const date = new Date();
|
|
109
|
+
date.setMilliseconds(0);
|
|
110
|
+
return date;
|
|
112
111
|
},
|
|
113
|
-
skipUpdate: true
|
|
112
|
+
skipUpdate: true,
|
|
114
113
|
})
|
|
115
|
-
updatedAt: Date
|
|
114
|
+
updatedAt: Date;
|
|
116
115
|
|
|
117
|
-
@column({ type:
|
|
118
|
-
deletedAt: Date | null = null
|
|
116
|
+
@column({ type: 'datetime', nullable: true })
|
|
117
|
+
deletedAt: Date | null = null;
|
|
119
118
|
|
|
120
|
-
@column({ type:
|
|
121
|
-
scannedAt: Date | null = null
|
|
119
|
+
@column({ type: 'datetime', nullable: true })
|
|
120
|
+
scannedAt: Date | null = null;
|
|
122
121
|
|
|
123
|
-
@column({ type:
|
|
124
|
-
scannedBy: string | null = null
|
|
122
|
+
@column({ type: 'string', nullable: true })
|
|
123
|
+
scannedBy: string | null = null;
|
|
125
124
|
|
|
126
|
-
static webshop = new ManyToOneRelation(Webshop,
|
|
127
|
-
static order = new ManyToOneRelation(Order,
|
|
128
|
-
static organization = new ManyToOneRelation(Organization,
|
|
125
|
+
static webshop = new ManyToOneRelation(Webshop, 'webshop');
|
|
126
|
+
static order = new ManyToOneRelation(Order, 'order');
|
|
127
|
+
static organization = new ManyToOneRelation(Organization, 'organization');
|
|
129
128
|
|
|
130
129
|
getUrl(this: Ticket & { webshop: Webshop & { organization: Organization } }) {
|
|
131
|
-
return
|
|
130
|
+
return 'https://' + this.webshop.getHost() + '/ticket/' + this.secret;
|
|
132
131
|
}
|
|
133
132
|
|
|
134
133
|
get isDeleted() {
|
|
@@ -140,6 +139,6 @@ export class Ticket extends Model {
|
|
|
140
139
|
return;
|
|
141
140
|
}
|
|
142
141
|
this.deletedAt = new Date();
|
|
143
|
-
await this.save()
|
|
142
|
+
await this.save();
|
|
144
143
|
}
|
|
145
|
-
}
|
|
144
|
+
}
|
package/src/models/Token.test.ts
CHANGED
|
@@ -3,11 +3,11 @@ import { Database } from '@simonbackx/simple-database';
|
|
|
3
3
|
import { OrganizationFactory } from '../factories/OrganizationFactory';
|
|
4
4
|
import { UserFactory } from '../factories/UserFactory';
|
|
5
5
|
import { Organization } from './Organization';
|
|
6
|
-
import { Token } from
|
|
7
|
-
import { User } from
|
|
6
|
+
import { Token } from './Token';
|
|
7
|
+
import { User } from './User';
|
|
8
8
|
|
|
9
|
-
describe(
|
|
10
|
-
const existingToken =
|
|
9
|
+
describe('Model.Token', () => {
|
|
10
|
+
const existingToken = 'ABCDEFG';
|
|
11
11
|
let user: User;
|
|
12
12
|
let organization: Organization;
|
|
13
13
|
|
|
@@ -15,22 +15,22 @@ describe("Model.Token", () => {
|
|
|
15
15
|
organization = await new OrganizationFactory({}).create();
|
|
16
16
|
user = await new UserFactory({ organization }).create();
|
|
17
17
|
|
|
18
|
-
await Database.insert(
|
|
18
|
+
await Database.insert('INSERT INTO ' + Token.table + ' SET ?', [
|
|
19
19
|
{
|
|
20
20
|
accessToken: existingToken,
|
|
21
|
-
refreshToken:
|
|
21
|
+
refreshToken: 'refreshtoken',
|
|
22
22
|
|
|
23
|
-
accessTokenValidUntil:
|
|
24
|
-
refreshTokenValidUntil:
|
|
23
|
+
accessTokenValidUntil: '2050-08-29 14:30:15',
|
|
24
|
+
refreshTokenValidUntil: '2050-08-29 14:30:15',
|
|
25
25
|
userId: user.id,
|
|
26
26
|
// = "myPassword"
|
|
27
|
-
createdAt:
|
|
28
|
-
updatedAt:
|
|
27
|
+
createdAt: '2020-03-29 14:30:15',
|
|
28
|
+
updatedAt: '2020-03-29 14:30:15',
|
|
29
29
|
},
|
|
30
30
|
]);
|
|
31
31
|
});
|
|
32
32
|
|
|
33
|
-
test(
|
|
33
|
+
test('Get token', async () => {
|
|
34
34
|
const token: any = await Token.getByAccessToken(existingToken);
|
|
35
35
|
expect(token).toBeDefined();
|
|
36
36
|
expect(token).toBeInstanceOf(Token);
|
|
@@ -39,7 +39,7 @@ describe("Model.Token", () => {
|
|
|
39
39
|
expect(token.userId).toEqual(user.id);
|
|
40
40
|
});
|
|
41
41
|
|
|
42
|
-
test(
|
|
42
|
+
test('Create a token', async () => {
|
|
43
43
|
const token = await Token.createToken(user);
|
|
44
44
|
expect(token).toBeDefined();
|
|
45
45
|
if (!token) return;
|
|
@@ -63,7 +63,7 @@ describe("Model.Token", () => {
|
|
|
63
63
|
refreshToken: token.refreshToken,
|
|
64
64
|
userId: token.userId,
|
|
65
65
|
accessTokenValidUntil: token.accessTokenValidUntil,
|
|
66
|
-
refreshTokenValidUntil: token.refreshTokenValidUntil
|
|
66
|
+
refreshTokenValidUntil: token.refreshTokenValidUntil,
|
|
67
67
|
});
|
|
68
68
|
});
|
|
69
69
|
});
|
package/src/models/Token.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { column, Database, ManyToOneRelation, Model } from
|
|
2
|
-
import { ApiUser } from
|
|
3
|
-
import crypto from
|
|
1
|
+
import { column, Database, ManyToOneRelation, Model } from '@simonbackx/simple-database';
|
|
2
|
+
import { ApiUser } from '@stamhoofd/structures';
|
|
3
|
+
import crypto from 'crypto';
|
|
4
4
|
|
|
5
|
-
import { RateLimiter } from
|
|
5
|
+
import { RateLimiter } from '../helpers/RateLimiter';
|
|
6
6
|
import { User } from './';
|
|
7
7
|
|
|
8
8
|
export type TokenWithUser = Token & { user: User };
|
|
@@ -21,85 +21,85 @@ async function randomBytes(size: number): Promise<Buffer> {
|
|
|
21
21
|
|
|
22
22
|
export const apiUserRateLimiter = new RateLimiter({
|
|
23
23
|
limits: [
|
|
24
|
-
{
|
|
24
|
+
{
|
|
25
25
|
// Block heavy bursts (5req/s for 5s)
|
|
26
26
|
limit: 25,
|
|
27
|
-
duration: 5 * 1000
|
|
27
|
+
duration: 5 * 1000,
|
|
28
28
|
},
|
|
29
|
-
{
|
|
29
|
+
{
|
|
30
30
|
// max 1req/s during 150s
|
|
31
31
|
limit: 150,
|
|
32
|
-
duration: 150 * 1000
|
|
32
|
+
duration: 150 * 1000,
|
|
33
33
|
},
|
|
34
|
-
{
|
|
34
|
+
{
|
|
35
35
|
// 1000 requests per hour
|
|
36
36
|
limit: 1000,
|
|
37
|
-
duration: 60 * 1000 * 60
|
|
37
|
+
duration: 60 * 1000 * 60,
|
|
38
38
|
},
|
|
39
|
-
{
|
|
39
|
+
{
|
|
40
40
|
// 2000 requests per day
|
|
41
41
|
limit: 2000,
|
|
42
|
-
duration: 24 * 60 * 1000 * 60
|
|
43
|
-
}
|
|
44
|
-
]
|
|
42
|
+
duration: 24 * 60 * 1000 * 60,
|
|
43
|
+
},
|
|
44
|
+
],
|
|
45
45
|
});
|
|
46
46
|
|
|
47
47
|
export class Token extends Model {
|
|
48
|
-
static table =
|
|
48
|
+
static table = 'tokens';
|
|
49
49
|
static MAX_DEVICES = 15;
|
|
50
50
|
|
|
51
|
-
@column({ type:
|
|
51
|
+
@column({ type: 'string', foreignKey: Token.user })
|
|
52
52
|
userId: string;
|
|
53
53
|
|
|
54
54
|
// Columns
|
|
55
|
-
@column({ primary: true, type:
|
|
55
|
+
@column({ primary: true, type: 'string' })
|
|
56
56
|
accessToken: string;
|
|
57
57
|
|
|
58
|
-
@column({ type:
|
|
58
|
+
@column({ type: 'string' })
|
|
59
59
|
refreshToken: string;
|
|
60
60
|
|
|
61
|
-
@column({ type:
|
|
61
|
+
@column({ type: 'datetime' })
|
|
62
62
|
accessTokenValidUntil: Date;
|
|
63
63
|
|
|
64
|
-
@column({ type:
|
|
64
|
+
@column({ type: 'datetime' })
|
|
65
65
|
refreshTokenValidUntil: Date;
|
|
66
66
|
|
|
67
67
|
@column({
|
|
68
|
-
type:
|
|
68
|
+
type: 'datetime', beforeSave(old?: any) {
|
|
69
69
|
if (old !== undefined) {
|
|
70
70
|
return old;
|
|
71
71
|
}
|
|
72
|
-
const date = new Date()
|
|
73
|
-
date.setMilliseconds(0)
|
|
74
|
-
return date
|
|
75
|
-
}
|
|
72
|
+
const date = new Date();
|
|
73
|
+
date.setMilliseconds(0);
|
|
74
|
+
return date;
|
|
75
|
+
},
|
|
76
76
|
})
|
|
77
|
-
createdAt: Date
|
|
77
|
+
createdAt: Date;
|
|
78
78
|
|
|
79
79
|
@column({
|
|
80
|
-
type:
|
|
81
|
-
const date = new Date()
|
|
82
|
-
date.setMilliseconds(0)
|
|
83
|
-
return date
|
|
80
|
+
type: 'datetime', beforeSave() {
|
|
81
|
+
const date = new Date();
|
|
82
|
+
date.setMilliseconds(0);
|
|
83
|
+
return date;
|
|
84
84
|
},
|
|
85
|
-
skipUpdate: true
|
|
85
|
+
skipUpdate: true,
|
|
86
86
|
})
|
|
87
|
-
updatedAt: Date
|
|
87
|
+
updatedAt: Date;
|
|
88
88
|
|
|
89
|
-
static user = new ManyToOneRelation(User,
|
|
89
|
+
static user = new ManyToOneRelation(User, 'user');
|
|
90
90
|
|
|
91
91
|
isAccessTokenExpired(): boolean {
|
|
92
|
-
return this.accessTokenValidUntil < new Date() || this.refreshTokenValidUntil < new Date()
|
|
92
|
+
return this.accessTokenValidUntil < new Date() || this.refreshTokenValidUntil < new Date();
|
|
93
93
|
}
|
|
94
94
|
|
|
95
95
|
static async getAPIUserWithToken(user: User) {
|
|
96
96
|
if (!user.isApiUser) {
|
|
97
|
-
throw new Error('Unexpected user type')
|
|
97
|
+
throw new Error('Unexpected user type');
|
|
98
98
|
}
|
|
99
99
|
|
|
100
100
|
const [lastToken] = await this.where({
|
|
101
|
-
userId: user.id
|
|
102
|
-
}, {limit: 1})
|
|
101
|
+
userId: user.id,
|
|
102
|
+
}, { limit: 1 });
|
|
103
103
|
|
|
104
104
|
return ApiUser.create({
|
|
105
105
|
id: user.id,
|
|
@@ -108,7 +108,7 @@ export class Token extends Model {
|
|
|
108
108
|
permissions: user.permissions,
|
|
109
109
|
expiresAt: lastToken?.accessTokenValidUntil ?? null,
|
|
110
110
|
createdAt: user.createdAt,
|
|
111
|
-
})
|
|
111
|
+
});
|
|
112
112
|
}
|
|
113
113
|
|
|
114
114
|
/**
|
|
@@ -118,8 +118,8 @@ export class Token extends Model {
|
|
|
118
118
|
const [rows] = await Database.select(
|
|
119
119
|
`SELECT ${this.getDefaultSelect()}, user.* FROM ${
|
|
120
120
|
this.table
|
|
121
|
-
} ${Token.user.joinQuery(this.table,
|
|
122
|
-
[accessToken]
|
|
121
|
+
} ${Token.user.joinQuery(this.table, 'user')} WHERE ${this.primary.name} = ? LIMIT 1 `,
|
|
122
|
+
[accessToken],
|
|
123
123
|
);
|
|
124
124
|
|
|
125
125
|
if (rows.length == 0) {
|
|
@@ -135,13 +135,13 @@ export class Token extends Model {
|
|
|
135
135
|
|
|
136
136
|
if (!ignoreExpireDate && (token.accessTokenValidUntil < new Date() || token.refreshTokenValidUntil < new Date())) {
|
|
137
137
|
// Also if the refresh token is invalid, the access token will always be invalid
|
|
138
|
-
return undefined
|
|
138
|
+
return undefined;
|
|
139
139
|
}
|
|
140
140
|
|
|
141
|
-
const user = User.fromRow(rows[0][
|
|
141
|
+
const user = User.fromRow(rows[0]['user']) || null;
|
|
142
142
|
|
|
143
143
|
if (!user) {
|
|
144
|
-
console.warn(
|
|
144
|
+
console.warn('Selected a token without a user!');
|
|
145
145
|
return undefined;
|
|
146
146
|
}
|
|
147
147
|
|
|
@@ -151,10 +151,10 @@ export class Token extends Model {
|
|
|
151
151
|
// Methods
|
|
152
152
|
static async getByRefreshToken(refreshToken: string): Promise<TokenWithUser | undefined> {
|
|
153
153
|
const [rows] = await Database.select(
|
|
154
|
-
`SELECT ${this.getDefaultSelect()}, ${User.getDefaultSelect(
|
|
155
|
-
|
|
156
|
-
} ${Token.user.joinQuery(this.table,
|
|
157
|
-
[refreshToken]
|
|
154
|
+
`SELECT ${this.getDefaultSelect()}, ${User.getDefaultSelect('user')} FROM ${
|
|
155
|
+
this.table
|
|
156
|
+
} ${Token.user.joinQuery(this.table, 'user')} WHERE \`refreshToken\` = ? LIMIT 1 `,
|
|
157
|
+
[refreshToken],
|
|
158
158
|
);
|
|
159
159
|
|
|
160
160
|
if (rows.length == 0) {
|
|
@@ -170,16 +170,16 @@ export class Token extends Model {
|
|
|
170
170
|
|
|
171
171
|
if (token.refreshTokenValidUntil < new Date()) {
|
|
172
172
|
// Refreh token invalid = can throw it away
|
|
173
|
-
token.delete().catch(e => {
|
|
174
|
-
console.error(e)
|
|
175
|
-
})
|
|
176
|
-
return undefined
|
|
173
|
+
token.delete().catch((e) => {
|
|
174
|
+
console.error(e);
|
|
175
|
+
});
|
|
176
|
+
return undefined;
|
|
177
177
|
}
|
|
178
178
|
|
|
179
|
-
const user = User.fromRow(rows[0][
|
|
179
|
+
const user = User.fromRow(rows[0]['user']) || null;
|
|
180
180
|
|
|
181
181
|
if (!user || user.isApiUser) {
|
|
182
|
-
console.warn(
|
|
182
|
+
console.warn('Selected a token without a user!');
|
|
183
183
|
return undefined;
|
|
184
184
|
}
|
|
185
185
|
|
|
@@ -189,13 +189,13 @@ export class Token extends Model {
|
|
|
189
189
|
/**
|
|
190
190
|
* Create a token that is expired. This can be usefull if renewing the token is restricted by some account state.
|
|
191
191
|
* E.g. you cannot renew this token until the e-mail address has been verified.
|
|
192
|
-
* @param user
|
|
192
|
+
* @param user
|
|
193
193
|
*/
|
|
194
194
|
static async createExpiredToken<U extends User>(user: U): Promise<(Token & { user: U })> {
|
|
195
195
|
const token = await this.createUnsavedToken(user);
|
|
196
196
|
|
|
197
197
|
/// Expired a month ago (to prevent any timezone bugs)
|
|
198
|
-
token.accessTokenValidUntil = new Date(Date.now() - 24 * 60 * 60 * 1000 * 31
|
|
198
|
+
token.accessTokenValidUntil = new Date(Date.now() - 24 * 60 * 60 * 1000 * 31);
|
|
199
199
|
token.accessTokenValidUntil.setMilliseconds(0);
|
|
200
200
|
|
|
201
201
|
await token.save();
|
|
@@ -215,17 +215,18 @@ export class Token extends Model {
|
|
|
215
215
|
rows,
|
|
216
216
|
] = await Database.delete(
|
|
217
217
|
`DELETE FROM \`${this.table}\` WHERE ${this.primary.name} IN (SELECT ${this.primary.name} FROM (SELECT ${this.primary.name} FROM \`${this.table}\` WHERE \`userId\` = ? ORDER BY\`refreshTokenValidUntil\` DESC LIMIT ? OFFSET ?) x)`,
|
|
218
|
-
[user.id, this.MAX_DEVICES, this.MAX_DEVICES]
|
|
218
|
+
[user.id, this.MAX_DEVICES, this.MAX_DEVICES],
|
|
219
219
|
);
|
|
220
220
|
|
|
221
221
|
if (rows.affectedRows > 0) {
|
|
222
222
|
console.log(`Deleted ${rows.affectedRows} old tokens first`);
|
|
223
223
|
}
|
|
224
|
-
}
|
|
224
|
+
}
|
|
225
|
+
catch (e) {
|
|
225
226
|
// This is not a crucial operation, so don't fail when there is a deadlock problem in the query
|
|
226
|
-
console.error(e)
|
|
227
|
+
console.error(e);
|
|
227
228
|
}
|
|
228
|
-
|
|
229
|
+
|
|
229
230
|
const token = new Token().setRelation(Token.user, user);
|
|
230
231
|
token.accessTokenValidUntil = new Date();
|
|
231
232
|
token.accessTokenValidUntil.setTime(token.accessTokenValidUntil.getTime() + 3600 * 1000);
|
|
@@ -235,8 +236,8 @@ export class Token extends Model {
|
|
|
235
236
|
token.refreshTokenValidUntil.setTime(token.refreshTokenValidUntil.getTime() + 3600 * 1000 * 24 * 365);
|
|
236
237
|
token.refreshTokenValidUntil.setMilliseconds(0);
|
|
237
238
|
|
|
238
|
-
token.accessToken = (await randomBytes(192)).toString(
|
|
239
|
-
token.refreshToken = (await randomBytes(192)).toString(
|
|
239
|
+
token.accessToken = (await randomBytes(192)).toString('base64').toUpperCase();
|
|
240
|
+
token.refreshToken = (await randomBytes(192)).toString('base64').toUpperCase();
|
|
240
241
|
return token;
|
|
241
242
|
}
|
|
242
243
|
|
|
@@ -248,7 +249,7 @@ export class Token extends Model {
|
|
|
248
249
|
|
|
249
250
|
static async createApiToken<U extends User>(user: U): Promise<(Token & { user: U })> {
|
|
250
251
|
const token = await this.createUnsavedToken(user);
|
|
251
|
-
|
|
252
|
+
|
|
252
253
|
// 5 year valid
|
|
253
254
|
token.accessTokenValidUntil = new Date();
|
|
254
255
|
token.accessTokenValidUntil.setTime(token.accessTokenValidUntil.getTime() + 1000 * 60 * 60 * 24 * 365 * 5);
|
|
@@ -264,6 +265,6 @@ export class Token extends Model {
|
|
|
264
265
|
|
|
265
266
|
static async clearFor(userId: string, currentToken: string) {
|
|
266
267
|
const query = `DELETE from ${this.table} where userId = ? AND accessToken != ?`;
|
|
267
|
-
await Database.delete(query, [userId, currentToken])
|
|
268
|
+
await Database.delete(query, [userId, currentToken]);
|
|
268
269
|
}
|
|
269
270
|
}
|
|
@@ -1,51 +1,50 @@
|
|
|
1
|
-
import { column, Model } from
|
|
2
|
-
import { v4 as uuidv4 } from
|
|
3
|
-
|
|
1
|
+
import { column, Model } from '@simonbackx/simple-database';
|
|
2
|
+
import { v4 as uuidv4 } from 'uuid';
|
|
4
3
|
|
|
5
4
|
export class UsedRegisterCode extends Model {
|
|
6
|
-
static table =
|
|
5
|
+
static table = 'used_register_codes';
|
|
7
6
|
|
|
8
7
|
@column({
|
|
9
|
-
primary: true, type:
|
|
8
|
+
primary: true, type: 'string', beforeSave(value) {
|
|
10
9
|
return value ?? uuidv4();
|
|
11
|
-
}
|
|
10
|
+
},
|
|
12
11
|
})
|
|
13
12
|
id!: string;
|
|
14
13
|
|
|
15
|
-
@column({ type:
|
|
14
|
+
@column({ type: 'string' })
|
|
16
15
|
code: string;
|
|
17
16
|
|
|
18
17
|
/**
|
|
19
18
|
* Code is used by...
|
|
20
19
|
*/
|
|
21
|
-
@column({ type:
|
|
20
|
+
@column({ type: 'string' })
|
|
22
21
|
organizationId: string;
|
|
23
22
|
|
|
24
23
|
/**
|
|
25
24
|
* Set if this has been rewarded
|
|
26
25
|
*/
|
|
27
|
-
@column({ type:
|
|
26
|
+
@column({ type: 'string', nullable: true })
|
|
28
27
|
creditId: string | null = null;
|
|
29
28
|
|
|
30
29
|
@column({
|
|
31
|
-
type:
|
|
30
|
+
type: 'datetime', beforeSave(old?: any) {
|
|
32
31
|
if (old !== undefined) {
|
|
33
32
|
return old;
|
|
34
33
|
}
|
|
35
|
-
const date = new Date()
|
|
36
|
-
date.setMilliseconds(0)
|
|
37
|
-
return date
|
|
38
|
-
}
|
|
34
|
+
const date = new Date();
|
|
35
|
+
date.setMilliseconds(0);
|
|
36
|
+
return date;
|
|
37
|
+
},
|
|
39
38
|
})
|
|
40
|
-
createdAt: Date
|
|
39
|
+
createdAt: Date;
|
|
41
40
|
|
|
42
41
|
@column({
|
|
43
|
-
type:
|
|
44
|
-
const date = new Date()
|
|
45
|
-
date.setMilliseconds(0)
|
|
46
|
-
return date
|
|
42
|
+
type: 'datetime', beforeSave() {
|
|
43
|
+
const date = new Date();
|
|
44
|
+
date.setMilliseconds(0);
|
|
45
|
+
return date;
|
|
47
46
|
},
|
|
48
|
-
skipUpdate: true
|
|
47
|
+
skipUpdate: true,
|
|
49
48
|
})
|
|
50
|
-
updatedAt: Date
|
|
49
|
+
updatedAt: Date;
|
|
51
50
|
}
|