refactor: native feature management (#2350)

This commit is contained in:
Mo
2023-07-12 12:56:08 -05:00
committed by GitHub
parent 49f7581cd8
commit 078ef3772c
223 changed files with 3996 additions and 3438 deletions

View File

@@ -0,0 +1,42 @@
import { LEGACY_PROD_EXT_ORIGIN, PROD_OFFLINE_FEATURES_URL } from '@Lib/Hosts'
import { SNFeatureRepo } from '@standardnotes/models'
import { MutatorClientInterface } from '@standardnotes/services'
export class MigrateFeatureRepoToOfflineEntitlementsUseCase {
constructor(private mutator: MutatorClientInterface) {}
async execute(featureRepos: SNFeatureRepo[] = []): Promise<SNFeatureRepo[]> {
const updatedRepos: SNFeatureRepo[] = []
for (const item of featureRepos) {
if (item.migratedToOfflineEntitlements) {
continue
}
if (!item.onlineUrl) {
continue
}
const repoUrl = item.onlineUrl
const { origin } = new URL(repoUrl)
if (!origin.includes(LEGACY_PROD_EXT_ORIGIN)) {
continue
}
const userKeyMatch = repoUrl.match(/\w{32,64}/)
if (userKeyMatch && userKeyMatch.length > 0) {
const userKey = userKeyMatch[0]
const updatedRepo = await this.mutator.changeFeatureRepo(item, (m) => {
m.offlineFeaturesUrl = PROD_OFFLINE_FEATURES_URL
m.offlineKey = userKey
m.migratedToOfflineEntitlements = true
})
updatedRepos.push(updatedRepo)
}
}
return updatedRepos
}
}