chore: legacy fixes (#2343)
This commit is contained in:
43
packages/web/src/javascripts/Application/DevMode.ts
Normal file
43
packages/web/src/javascripts/Application/DevMode.ts
Normal file
@@ -0,0 +1,43 @@
|
||||
import { InternalFeature, InternalFeatureService } from '@standardnotes/snjs'
|
||||
import { WebApplicationInterface } from '@standardnotes/ui-services'
|
||||
|
||||
export class DevMode {
|
||||
constructor(private application: WebApplicationInterface) {
|
||||
InternalFeatureService.get().enableFeature(InternalFeature.Vaults)
|
||||
}
|
||||
|
||||
/** Valid only when running a mock event publisher on port 3124 */
|
||||
async purchaseMockSubscription() {
|
||||
const subscriptionId = 2000
|
||||
const email = this.application.getUser()?.email
|
||||
const response = await fetch('http://localhost:3124/events', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
Accept: 'application/json',
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify({
|
||||
eventType: 'SUBSCRIPTION_PURCHASED',
|
||||
eventPayload: {
|
||||
userEmail: email,
|
||||
subscriptionId: subscriptionId,
|
||||
subscriptionName: 'PRO_PLAN',
|
||||
subscriptionExpiresAt: (new Date().getTime() + 3_600_000) * 1_000,
|
||||
timestamp: Date.now(),
|
||||
offline: false,
|
||||
discountCode: null,
|
||||
limitedDiscountPurchased: false,
|
||||
newSubscriber: true,
|
||||
totalActiveSubscriptionsCount: 1,
|
||||
userRegisteredAt: 1,
|
||||
billingFrequency: 12,
|
||||
payAmount: 59.0,
|
||||
},
|
||||
}),
|
||||
})
|
||||
|
||||
if (!response.ok) {
|
||||
console.error(`Failed to publish mocked event: ${response.status} ${response.statusText}`)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -51,18 +51,21 @@ import { FeatureName } from '@/Controllers/FeatureName'
|
||||
import { ItemGroupController } from '@/Components/NoteView/Controller/ItemGroupController'
|
||||
import { VisibilityObserver } from './VisibilityObserver'
|
||||
import { MomentsService } from '@/Controllers/Moments/MomentsService'
|
||||
import { purchaseMockSubscription } from '@/Utils/Dev/PurchaseMockSubscription'
|
||||
import { DevMode } from './DevMode'
|
||||
|
||||
export type WebEventObserver = (event: WebAppEvent, data?: unknown) => void
|
||||
|
||||
export class WebApplication extends SNApplication implements WebApplicationInterface {
|
||||
private webServices!: WebServices
|
||||
private webEventObservers: WebEventObserver[] = []
|
||||
public itemControllerGroup: ItemGroupController
|
||||
private mobileWebReceiver?: MobileWebReceiver
|
||||
private androidBackHandler?: AndroidBackHandler
|
||||
public readonly itemControllerGroup: ItemGroupController
|
||||
public readonly routeService: RouteServiceInterface
|
||||
private visibilityObserver?: VisibilityObserver
|
||||
|
||||
private readonly webServices!: WebServices
|
||||
private readonly webEventObservers: WebEventObserver[] = []
|
||||
private readonly mobileWebReceiver?: MobileWebReceiver
|
||||
private readonly androidBackHandler?: AndroidBackHandler
|
||||
private readonly visibilityObserver?: VisibilityObserver
|
||||
|
||||
public readonly devMode?: DevMode
|
||||
|
||||
constructor(
|
||||
deviceInterface: WebOrDesktopDevice,
|
||||
@@ -91,6 +94,10 @@ export class WebApplication extends SNApplication implements WebApplicationInter
|
||||
u2fAuthenticatorVerificationPromptFunction: startAuthentication,
|
||||
})
|
||||
|
||||
if (isDev) {
|
||||
this.devMode = new DevMode(this)
|
||||
}
|
||||
|
||||
makeObservable(this, {
|
||||
dealloced: observable,
|
||||
})
|
||||
@@ -152,7 +159,7 @@ export class WebApplication extends SNApplication implements WebApplicationInter
|
||||
;(service as { application?: WebApplication }).application = undefined
|
||||
}
|
||||
|
||||
this.webServices = {} as WebServices
|
||||
;(this.webServices as unknown) = undefined
|
||||
|
||||
this.itemControllerGroup.deinit()
|
||||
;(this.itemControllerGroup as unknown) = undefined
|
||||
@@ -165,7 +172,7 @@ export class WebApplication extends SNApplication implements WebApplicationInter
|
||||
|
||||
if (this.visibilityObserver) {
|
||||
this.visibilityObserver.deinit()
|
||||
this.visibilityObserver = undefined
|
||||
;(this.visibilityObserver as unknown) = undefined
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error while deiniting application', error)
|
||||
@@ -458,12 +465,4 @@ export class WebApplication extends SNApplication implements WebApplicationInter
|
||||
generateUUID(): string {
|
||||
return this.options.crypto.generateUUID()
|
||||
}
|
||||
|
||||
dev__purchaseMockSubscription() {
|
||||
if (!isDev) {
|
||||
throw new Error('This method is only available in dev mode')
|
||||
}
|
||||
|
||||
void purchaseMockSubscription(this.getUser()?.email as string, 2000)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user