chore(web): put sign-in email notifications setting under paywall (#2249)
* chore: upgrade setting names to value objects * chore(web): put sign-in email notifications setting under paywall * chore: fix using setting name value objects in mocha tests * chore: fix wording on email notifications titles
This commit is contained in:
@@ -1,13 +1,7 @@
|
||||
import { SNApiService } from '../Api/ApiService'
|
||||
import { SettingsGateway } from './SettingsGateway'
|
||||
import { SNSessionManager } from '../Session/SessionManager'
|
||||
import {
|
||||
CloudProvider,
|
||||
EmailBackupFrequency,
|
||||
SettingName,
|
||||
SensitiveSettingName,
|
||||
SubscriptionSettingName,
|
||||
} from '@standardnotes/settings'
|
||||
import { CloudProvider, EmailBackupFrequency, SettingName } from '@standardnotes/settings'
|
||||
import { ExtensionsServerURL } from '@Lib/Hosts'
|
||||
import { AbstractService, InternalEventBusInterface } from '@standardnotes/services'
|
||||
import { SettingsClientInterface } from './SettingsClientInterface'
|
||||
@@ -46,7 +40,7 @@ export class SNSettingsService extends AbstractService implements SettingsClient
|
||||
return this.provider.getSetting(name)
|
||||
}
|
||||
|
||||
async getSubscriptionSetting(name: SubscriptionSettingName) {
|
||||
async getSubscriptionSetting(name: SettingName) {
|
||||
return this.provider.getSubscriptionSetting(name)
|
||||
}
|
||||
|
||||
@@ -54,7 +48,7 @@ export class SNSettingsService extends AbstractService implements SettingsClient
|
||||
return this.provider.updateSetting(name, payload, sensitive)
|
||||
}
|
||||
|
||||
async getDoesSensitiveSettingExist(name: SensitiveSettingName) {
|
||||
async getDoesSensitiveSettingExist(name: SettingName) {
|
||||
return this.provider.getDoesSensitiveSettingExist(name)
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { SettingName, SensitiveSettingName, EmailBackupFrequency } from '@standardnotes/settings'
|
||||
import { SettingName, EmailBackupFrequency } from '@standardnotes/settings'
|
||||
import { SettingsList } from './SettingsList'
|
||||
|
||||
export interface SettingsClientInterface {
|
||||
@@ -6,7 +6,7 @@ export interface SettingsClientInterface {
|
||||
|
||||
getSetting(name: SettingName): Promise<string | undefined>
|
||||
|
||||
getDoesSensitiveSettingExist(name: SensitiveSettingName): Promise<boolean>
|
||||
getDoesSensitiveSettingExist(name: SettingName): Promise<boolean>
|
||||
|
||||
updateSetting(name: SettingName, payload: string, sensitive?: boolean): Promise<void>
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { SettingsList } from './SettingsList'
|
||||
import { SettingName, SensitiveSettingName, SubscriptionSettingName } from '@standardnotes/settings'
|
||||
import { SettingName } from '@standardnotes/settings'
|
||||
import { API_MESSAGE_INVALID_SESSION } from '@standardnotes/services'
|
||||
import { HttpStatusCode, isErrorResponse, User } from '@standardnotes/responses'
|
||||
import { SettingsServerInterface } from './SettingsServerInterface'
|
||||
@@ -46,7 +46,7 @@ export class SettingsGateway {
|
||||
}
|
||||
|
||||
async getSetting(name: SettingName): Promise<string | undefined> {
|
||||
const response = await this.settingsApi.getSetting(this.userUuid, name)
|
||||
const response = await this.settingsApi.getSetting(this.userUuid, name.value)
|
||||
|
||||
if (response.status === HttpStatusCode.BadRequest) {
|
||||
return undefined
|
||||
@@ -59,8 +59,12 @@ export class SettingsGateway {
|
||||
return response?.data?.setting?.value ?? undefined
|
||||
}
|
||||
|
||||
async getSubscriptionSetting(name: SubscriptionSettingName): Promise<string | undefined> {
|
||||
const response = await this.settingsApi.getSubscriptionSetting(this.userUuid, name)
|
||||
async getSubscriptionSetting(name: SettingName): Promise<string | undefined> {
|
||||
if (!name.isASubscriptionSetting()) {
|
||||
throw new Error(`Setting ${name.value} is not a subscription setting`)
|
||||
}
|
||||
|
||||
const response = await this.settingsApi.getSubscriptionSetting(this.userUuid, name.value)
|
||||
|
||||
if (response.status === HttpStatusCode.BadRequest) {
|
||||
return undefined
|
||||
@@ -73,8 +77,12 @@ export class SettingsGateway {
|
||||
return response?.data?.setting?.value ?? undefined
|
||||
}
|
||||
|
||||
async getDoesSensitiveSettingExist(name: SensitiveSettingName): Promise<boolean> {
|
||||
const response = await this.settingsApi.getSetting(this.userUuid, name)
|
||||
async getDoesSensitiveSettingExist(name: SettingName): Promise<boolean> {
|
||||
if (!name.isSensitive()) {
|
||||
throw new Error(`Setting ${name.value} is not sensitive`)
|
||||
}
|
||||
|
||||
const response = await this.settingsApi.getSetting(this.userUuid, name.value)
|
||||
|
||||
if (response.status === HttpStatusCode.BadRequest) {
|
||||
return false
|
||||
@@ -88,14 +96,14 @@ export class SettingsGateway {
|
||||
}
|
||||
|
||||
async updateSetting(name: SettingName, payload: string, sensitive: boolean): Promise<void> {
|
||||
const response = await this.settingsApi.updateSetting(this.userUuid, name, payload, sensitive)
|
||||
const response = await this.settingsApi.updateSetting(this.userUuid, name.value, payload, sensitive)
|
||||
if (isErrorResponse(response)) {
|
||||
throw new Error(response.data?.error.message)
|
||||
}
|
||||
}
|
||||
|
||||
async deleteSetting(name: SettingName): Promise<void> {
|
||||
const response = await this.settingsApi.deleteSetting(this.userUuid, name)
|
||||
const response = await this.settingsApi.deleteSetting(this.userUuid, name.value)
|
||||
if (isErrorResponse(response)) {
|
||||
throw new Error(response.data?.error.message)
|
||||
}
|
||||
|
||||
@@ -28,16 +28,16 @@ type SettingType =
|
||||
| OneDriveBackupFrequency
|
||||
|
||||
export class SettingsList {
|
||||
private map: Partial<Record<SettingName, SettingData>> = {}
|
||||
private map: Partial<Record<string, SettingData>> = {}
|
||||
|
||||
constructor(settings: SettingData[]) {
|
||||
for (const setting of settings) {
|
||||
this.map[setting.name as SettingName] = setting
|
||||
this.map[setting.name] = setting
|
||||
}
|
||||
}
|
||||
|
||||
getSettingValue<T = SettingType, D = SettingType>(setting: SettingName, defaultValue: D): T {
|
||||
const settingData = this.map[setting]
|
||||
getSettingValue<T = SettingType, D = SettingType>(settingName: SettingName, defaultValue: D): T {
|
||||
const settingData = this.map[settingName.value]
|
||||
return (settingData?.value as unknown as T) || (defaultValue as unknown as T)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user