mirror of
https://github.com/standardnotes/server
synced 2026-07-14 00:01:54 -04:00
feat(auth): remove offline subscription token created event in favour of email requested
This commit is contained in:
@@ -0,0 +1,9 @@
|
||||
import { html } from './offline-subscription-token-created.html'
|
||||
|
||||
export function getSubject(): string {
|
||||
return 'Access to your Standard Notes Subscription Dashboard'
|
||||
}
|
||||
|
||||
export function getBody(email: string, offlineSubscriptionDashboardUrl: string): string {
|
||||
return html(email, offlineSubscriptionDashboardUrl)
|
||||
}
|
||||
@@ -5,11 +5,5 @@ export function getSubject(email: string): string {
|
||||
}
|
||||
|
||||
export function getBody(email: string, device: string, browser: string, date: Date): string {
|
||||
const body = html
|
||||
|
||||
return body
|
||||
.replace('%%EMAIL%%', email)
|
||||
.replace('%%DEVICE%%', device)
|
||||
.replace('%%BROWSER%%', browser)
|
||||
.replace('%%TIME_AND_DATE%%', date.toLocaleString())
|
||||
return html(email, device, browser, date.toLocaleString())
|
||||
}
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
export const html = (userEmail: string, offlineSubscriptionDashboardUrl: string) => `<div class="sn-component">
|
||||
<div class="sk-panel static">
|
||||
<div class="sk-panel-content">
|
||||
<div class="sk-panel-section">
|
||||
<h1 class="h1 title sk-panel-row">
|
||||
<div class="sk-panel-column">
|
||||
Access your Standard Notes Subscription Dashboard,
|
||||
</div>
|
||||
</h1>
|
||||
<div class="faded sk-panel-row small">Registered as ${userEmail}</div>
|
||||
</div>
|
||||
<div class="sk-panel-section">
|
||||
<div class="title">Link to your subscription dashboard: <a
|
||||
href="${offlineSubscriptionDashboardUrl}">${offlineSubscriptionDashboardUrl}</a></div>
|
||||
</div>
|
||||
<div class="sk-panel-section">
|
||||
<p>
|
||||
Get help any time by visiting our <a href="https://standardnotes.com/help">Help page</a>
|
||||
or by replying directly to this email.
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>`
|
||||
@@ -1,15 +1,15 @@
|
||||
export const html = `
|
||||
export const html = (email: string, device: string, browser: string, timeAndDate: string) => `
|
||||
<div>
|
||||
<p>Hello,</p>
|
||||
<p>We've detected a new sign-in to your account %%EMAIL%%.</p>
|
||||
<p>We've detected a new sign-in to your account ${email}</p>
|
||||
<p>
|
||||
<b>Device type</b>: %%DEVICE%%
|
||||
<b>Device type</b>: ${device}
|
||||
</p>
|
||||
<p>
|
||||
<b>Browser type</b>: %%BROWSER%%
|
||||
<b>Browser type</b>: ${browser}
|
||||
</p>
|
||||
<p>
|
||||
<strong>Time and date</strong>: <span>%%TIME_AND_DATE%%</span>
|
||||
<strong>Time and date</strong>: <span>${timeAndDate}</span>
|
||||
</p>
|
||||
<p>
|
||||
If this was you, please disregard this email. If it wasn't you, we recommend signing into your account and
|
||||
|
||||
@@ -6,7 +6,6 @@ import {
|
||||
UserEmailChangedEvent,
|
||||
UserRegisteredEvent,
|
||||
UserRolesChangedEvent,
|
||||
OfflineSubscriptionTokenCreatedEvent,
|
||||
EmailBackupRequestedEvent,
|
||||
CloudBackupRequestedEvent,
|
||||
ListedAccountRequestedEvent,
|
||||
@@ -290,24 +289,6 @@ export class DomainEventFactory implements DomainEventFactoryInterface {
|
||||
}
|
||||
}
|
||||
|
||||
createOfflineSubscriptionTokenCreatedEvent(token: string, email: string): OfflineSubscriptionTokenCreatedEvent {
|
||||
return {
|
||||
type: 'OFFLINE_SUBSCRIPTION_TOKEN_CREATED',
|
||||
createdAt: this.timer.getUTCDate(),
|
||||
meta: {
|
||||
correlation: {
|
||||
userIdentifier: email,
|
||||
userIdentifierType: 'email',
|
||||
},
|
||||
origin: DomainEventService.Auth,
|
||||
},
|
||||
payload: {
|
||||
token,
|
||||
email,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
createUserRegisteredEvent(dto: {
|
||||
userUuid: string
|
||||
email: string
|
||||
|
||||
@@ -6,7 +6,6 @@ import {
|
||||
UserRegisteredEvent,
|
||||
UserRolesChangedEvent,
|
||||
UserEmailChangedEvent,
|
||||
OfflineSubscriptionTokenCreatedEvent,
|
||||
EmailBackupRequestedEvent,
|
||||
ListedAccountRequestedEvent,
|
||||
UserDisabledSessionUserAgentLoggingEvent,
|
||||
@@ -56,7 +55,6 @@ export interface DomainEventFactoryInterface {
|
||||
}): AccountDeletionRequestedEvent
|
||||
createUserRolesChangedEvent(userUuid: string, email: string, currentRoles: RoleName[]): UserRolesChangedEvent
|
||||
createUserEmailChangedEvent(userUuid: string, fromEmail: string, toEmail: string): UserEmailChangedEvent
|
||||
createOfflineSubscriptionTokenCreatedEvent(token: string, email: string): OfflineSubscriptionTokenCreatedEvent
|
||||
createUserDisabledSessionUserAgentLoggingEvent(dto: {
|
||||
userUuid: Uuid
|
||||
email: string
|
||||
|
||||
+7
-10
@@ -5,7 +5,7 @@ import { TimerInterface } from '@standardnotes/time'
|
||||
import { OfflineSubscriptionTokenRepositoryInterface } from '../../Auth/OfflineSubscriptionTokenRepositoryInterface'
|
||||
|
||||
import { CreateOfflineSubscriptionToken } from './CreateOfflineSubscriptionToken'
|
||||
import { DomainEventPublisherInterface, OfflineSubscriptionTokenCreatedEvent } from '@standardnotes/domain-events'
|
||||
import { DomainEventPublisherInterface, EmailRequestedEvent } from '@standardnotes/domain-events'
|
||||
import { DomainEventFactoryInterface } from '../../Event/DomainEventFactoryInterface'
|
||||
import { OfflineUserSubscriptionRepositoryInterface } from '../../Subscription/OfflineUserSubscriptionRepositoryInterface'
|
||||
import { OfflineUserSubscription } from '../../Subscription/OfflineUserSubscription'
|
||||
@@ -47,9 +47,9 @@ describe('CreateOfflineSubscriptionToken', () => {
|
||||
domainEventPublisher.publish = jest.fn()
|
||||
|
||||
domainEventFactory = {} as jest.Mocked<DomainEventFactoryInterface>
|
||||
domainEventFactory.createOfflineSubscriptionTokenCreatedEvent = jest
|
||||
domainEventFactory.createEmailRequestedEvent = jest
|
||||
.fn()
|
||||
.mockReturnValue({} as jest.Mocked<OfflineSubscriptionTokenCreatedEvent>)
|
||||
.mockReturnValue({} as jest.Mocked<EmailRequestedEvent>)
|
||||
|
||||
timer = {} as jest.Mocked<TimerInterface>
|
||||
timer.convertStringDateToMicroseconds = jest.fn().mockReturnValue(1)
|
||||
@@ -71,10 +71,7 @@ describe('CreateOfflineSubscriptionToken', () => {
|
||||
expiresAt: 1,
|
||||
})
|
||||
|
||||
expect(domainEventFactory.createOfflineSubscriptionTokenCreatedEvent).toHaveBeenCalledWith(
|
||||
'random-string',
|
||||
'[email protected]',
|
||||
)
|
||||
expect(domainEventFactory.createEmailRequestedEvent).toHaveBeenCalled()
|
||||
expect(domainEventPublisher.publish).toHaveBeenCalled()
|
||||
})
|
||||
|
||||
@@ -91,7 +88,7 @@ describe('CreateOfflineSubscriptionToken', () => {
|
||||
})
|
||||
|
||||
expect(offlineSubscriptionTokenRepository.save).not.toHaveBeenCalled()
|
||||
expect(domainEventFactory.createOfflineSubscriptionTokenCreatedEvent).not.toHaveBeenCalled()
|
||||
expect(domainEventFactory.createEmailRequestedEvent).not.toHaveBeenCalled()
|
||||
expect(domainEventPublisher.publish).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
@@ -110,7 +107,7 @@ describe('CreateOfflineSubscriptionToken', () => {
|
||||
})
|
||||
|
||||
expect(offlineSubscriptionTokenRepository.save).not.toHaveBeenCalled()
|
||||
expect(domainEventFactory.createOfflineSubscriptionTokenCreatedEvent).not.toHaveBeenCalled()
|
||||
expect(domainEventFactory.createEmailRequestedEvent).not.toHaveBeenCalled()
|
||||
expect(domainEventPublisher.publish).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
@@ -129,7 +126,7 @@ describe('CreateOfflineSubscriptionToken', () => {
|
||||
})
|
||||
|
||||
expect(offlineSubscriptionTokenRepository.save).not.toHaveBeenCalled()
|
||||
expect(domainEventFactory.createOfflineSubscriptionTokenCreatedEvent).not.toHaveBeenCalled()
|
||||
expect(domainEventFactory.createEmailRequestedEvent).not.toHaveBeenCalled()
|
||||
expect(domainEventPublisher.publish).not.toHaveBeenCalled()
|
||||
})
|
||||
})
|
||||
|
||||
+9
-1
@@ -1,4 +1,5 @@
|
||||
import { DomainEventPublisherInterface } from '@standardnotes/domain-events'
|
||||
import { EmailLevel } from '@standardnotes/domain-core'
|
||||
import { CryptoNode } from '@standardnotes/sncrypto-node'
|
||||
import { TimerInterface } from '@standardnotes/time'
|
||||
import { inject, injectable } from 'inversify'
|
||||
@@ -6,6 +7,7 @@ import { Logger } from 'winston'
|
||||
|
||||
import TYPES from '../../../Bootstrap/Types'
|
||||
import { OfflineSubscriptionTokenRepositoryInterface } from '../../Auth/OfflineSubscriptionTokenRepositoryInterface'
|
||||
import { getBody, getSubject } from '../../Email/OfflineSubscriptionTokenCreated'
|
||||
import { DomainEventFactoryInterface } from '../../Event/DomainEventFactoryInterface'
|
||||
import { OfflineUserSubscriptionRepositoryInterface } from '../../Subscription/OfflineUserSubscriptionRepositoryInterface'
|
||||
import { UseCaseInterface } from '../UseCaseInterface'
|
||||
@@ -62,7 +64,13 @@ export class CreateOfflineSubscriptionToken implements UseCaseInterface {
|
||||
await this.offlineSubscriptionTokenRepository.save(offlineSubscriptionToken)
|
||||
|
||||
await this.domainEventPublisher.publish(
|
||||
this.domainEventFactory.createOfflineSubscriptionTokenCreatedEvent(token, dto.userEmail),
|
||||
this.domainEventFactory.createEmailRequestedEvent({
|
||||
body: getBody(dto.userEmail, `https://standardnotes.com/dashboard/offline?subscription_token=${token}`),
|
||||
level: EmailLevel.LEVELS.System,
|
||||
subject: getSubject(),
|
||||
messageIdentifier: 'OFFLINE_SUBSCRIPTION_ACCESS',
|
||||
userEmail: dto.userEmail,
|
||||
}),
|
||||
)
|
||||
|
||||
return {
|
||||
|
||||
@@ -1,8 +0,0 @@
|
||||
import { DomainEventInterface } from './DomainEventInterface'
|
||||
|
||||
import { OfflineSubscriptionTokenCreatedEventPayload } from './OfflineSubscriptionTokenCreatedEventPayload'
|
||||
|
||||
export interface OfflineSubscriptionTokenCreatedEvent extends DomainEventInterface {
|
||||
type: 'OFFLINE_SUBSCRIPTION_TOKEN_CREATED'
|
||||
payload: OfflineSubscriptionTokenCreatedEventPayload
|
||||
}
|
||||
@@ -1,4 +0,0 @@
|
||||
export interface OfflineSubscriptionTokenCreatedEventPayload {
|
||||
token: string
|
||||
email: string
|
||||
}
|
||||
@@ -50,8 +50,6 @@ export * from './Event/ListedAccountRequestedEvent'
|
||||
export * from './Event/ListedAccountRequestedEventPayload'
|
||||
export * from './Event/MuteEmailsSettingChangedEvent'
|
||||
export * from './Event/MuteEmailsSettingChangedEventPayload'
|
||||
export * from './Event/OfflineSubscriptionTokenCreatedEvent'
|
||||
export * from './Event/OfflineSubscriptionTokenCreatedEventPayload'
|
||||
export * from './Event/OneDriveBackupFailedEvent'
|
||||
export * from './Event/OneDriveBackupFailedEventPayload'
|
||||
export * from './Event/PaymentFailedEvent'
|
||||
|
||||
Reference in New Issue
Block a user