-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(auth): add script for fixing subscriptions with missing id state (…
…#1030) * fix(auth): add subscription id safe guards on handlers * feat(domain-events): add subscription state events * feat(domain-events): add subscription state events * feat(auth): add handling of subscription state fetched events * feat(auth): add script for fixing subscriptions state
- Loading branch information
1 parent
6f07aaf
commit 86b0508
Showing
22 changed files
with
363 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import 'reflect-metadata' | ||
|
||
import { Logger } from 'winston' | ||
|
||
import { ContainerConfigLoader } from '../src/Bootstrap/Container' | ||
import TYPES from '../src/Bootstrap/Types' | ||
import { Env } from '../src/Bootstrap/Env' | ||
import { UserSubscriptionRepositoryInterface } from '../src/Domain/Subscription/UserSubscriptionRepositoryInterface' | ||
import { DomainEventFactoryInterface } from '../src/Domain/Event/DomainEventFactoryInterface' | ||
import { DomainEventPublisherInterface } from '@standardnotes/domain-events' | ||
import { UserRepositoryInterface } from '../src/Domain/User/UserRepositoryInterface' | ||
import { Uuid } from '@standardnotes/domain-core' | ||
|
||
const fixSubscriptions = async ( | ||
userRepository: UserRepositoryInterface, | ||
userSubscriptionRepository: UserSubscriptionRepositoryInterface, | ||
domainEventFactory: DomainEventFactoryInterface, | ||
domainEventPublisher: DomainEventPublisherInterface, | ||
): Promise<void> => { | ||
const subscriptions = await userSubscriptionRepository.findBySubscriptionId(0) | ||
|
||
for (const subscription of subscriptions) { | ||
const userUuidOrError = Uuid.create(subscription.userUuid) | ||
if (userUuidOrError.isFailed()) { | ||
continue | ||
} | ||
const userUuid = userUuidOrError.getValue() | ||
|
||
const user = await userRepository.findOneByUuid(userUuid) | ||
if (!user) { | ||
continue | ||
} | ||
|
||
await domainEventPublisher.publish( | ||
domainEventFactory.createSubscriptionStateRequestedEvent({ | ||
userEmail: user.email, | ||
}), | ||
) | ||
} | ||
} | ||
|
||
const container = new ContainerConfigLoader('worker') | ||
void container.load().then((container) => { | ||
const env: Env = new Env() | ||
env.load() | ||
|
||
const logger: Logger = container.get(TYPES.Auth_Logger) | ||
|
||
logger.info('Starting to fix subscriptions with missing subscriptionId ...') | ||
|
||
const userRepository = container.get<UserRepositoryInterface>(TYPES.Auth_UserRepository) | ||
const userSubscriptionRepository = container.get<UserSubscriptionRepositoryInterface>( | ||
TYPES.Auth_UserSubscriptionRepository, | ||
) | ||
const domainEventFactory = container.get<DomainEventFactoryInterface>(TYPES.Auth_DomainEventFactory) | ||
const domainEventPublisher = container.get<DomainEventPublisherInterface>(TYPES.Auth_DomainEventPublisher) | ||
|
||
Promise.resolve( | ||
fixSubscriptions(userRepository, userSubscriptionRepository, domainEventFactory, domainEventPublisher), | ||
) | ||
.then(() => { | ||
logger.info('Finished fixing subscriptions with missing subscriptionId.') | ||
|
||
process.exit(0) | ||
}) | ||
.catch((error) => { | ||
logger.error('Failed to fix subscriptions with missing subscriptionId.', { | ||
error: error.message, | ||
stack: error.stack, | ||
}) | ||
|
||
process.exit(1) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
'use strict' | ||
|
||
const path = require('path') | ||
|
||
const pnp = require(path.normalize(path.resolve(__dirname, '../../..', '.pnp.cjs'))).setup() | ||
|
||
const index = require(path.normalize(path.resolve(__dirname, '../dist/bin/fix_subscriptions.js'))) | ||
|
||
Object.defineProperty(exports, '__esModule', { value: true }) | ||
|
||
exports.default = index |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.