feat: add features package

This commit is contained in:
Karol Sójko
2022-07-05 14:58:29 +02:00
parent e335d0d2c2
commit 44d3e96468
69 changed files with 2214 additions and 28 deletions

View File

@@ -0,0 +1,78 @@
import { ComponentPermission } from '../Component/ComponentPermission'
import { ContentType, RoleName, SubscriptionName } from '@standardnotes/common'
import { ComponentArea } from '../Component/ComponentArea'
import { PermissionName } from '../Permission/PermissionName'
import { FeatureIdentifier } from './FeatureIdentifier'
import { ComponentFlag } from '../Component/ComponentFlag'
import { NoteType } from '../Component/NoteType'
import { ThemeDockIcon } from '../Component/ThemeDockIcon'
type RoleFields = {
/** Server populated */
role_name?: RoleName
/** Statically populated. Non-influencing; used as a reference by other static consumers (such as email service) */
availableInSubscriptions: SubscriptionName[]
}
export type BaseFeatureDescription = RoleFields & {
deletion_warning?: string
deprecated?: boolean
deprecation_message?: string
description?: string
expires_at?: number
flags?: ComponentFlag[]
identifier: FeatureIdentifier
marketing_url?: string
name?: string
no_expire?: boolean
no_mobile?: boolean
thumbnail_url?: string
permission_name: PermissionName
}
export type ServerFeatureDescription = RoleFields & {
name?: string
identifier: FeatureIdentifier
permission_name: PermissionName
}
export type ClientFeatureDescription = RoleFields & {
identifier: FeatureIdentifier
permission_name: PermissionName
description: string
name: string
}
export type ComponentFeatureDescription = BaseFeatureDescription & {
/** The relative path of the index.html file or the main css file if theme, within the component folder itself */
index_path: string
content_type: ContentType
area: ComponentArea
}
export type ThirdPartyFeatureDescription = ComponentFeatureDescription & {
url: string
}
export type IframeComponentFeatureDescription = ComponentFeatureDescription & {
component_permissions: ComponentPermission[]
}
export type EditorFeatureDescription = IframeComponentFeatureDescription & {
file_type: 'txt' | 'html' | 'md' | 'json'
/** Whether an editor is interchangable with another editor that has the same file_type */
interchangeable: boolean
note_type: NoteType
spellcheckControl?: boolean
}
export type ThemeFeatureDescription = ComponentFeatureDescription & {
/** Some themes can be layered on top of other themes */
layerable?: boolean
dock_icon?: ThemeDockIcon
}
export type FeatureDescription = BaseFeatureDescription &
Partial<ComponentFeatureDescription & EditorFeatureDescription & ThemeFeatureDescription>

View File

@@ -0,0 +1,53 @@
export enum FeatureIdentifier {
AccountSwitcher = 'com.standardnotes.account-switcher',
CloudLink = 'org.standardnotes.cloudlink',
DailyDropboxBackup = 'org.standardnotes.daily-dropbox-backup',
DailyEmailBackup = 'org.standardnotes.daily-email-backup',
DailyGDriveBackup = 'org.standardnotes.daily-gdrive-backup',
DailyOneDriveBackup = 'org.standardnotes.daily-onedrive-backup',
Files = 'org.standardnotes.files',
FilesBeta = 'org.standardnotes.files-beta',
FilesLowStorageTier = 'org.standardnotes.files-low-storage-tier',
FilesMaximumStorageTier = 'org.standardnotes.files-max-storage-tier',
ListedCustomDomain = 'org.standardnotes.listed-custom-domain',
NoteHistory30Days = 'org.standardnotes.note-history-30',
NoteHistory365Days = 'org.standardnotes.note-history-365',
NoteHistoryUnlimited = 'org.standardnotes.note-history-unlimited',
SignInAlerts = 'com.standardnotes.sign-in-alerts',
SmartFilters = 'org.standardnotes.smart-filters',
TagNesting = 'org.standardnotes.tag-nesting',
TwoFactorAuth = 'org.standardnotes.two-factor-auth',
AutobiographyTheme = 'org.standardnotes.theme-autobiography',
DynamicTheme = 'org.standardnotes.theme-dynamic',
FocusedTheme = 'org.standardnotes.theme-focus',
FocusMode = 'org.standardnotes.focus-mode',
FuturaTheme = 'org.standardnotes.theme-futura',
MidnightTheme = 'org.standardnotes.theme-midnight',
SolarizedDarkTheme = 'org.standardnotes.theme-solarized-dark',
TitaniumTheme = 'org.standardnotes.theme-titanium',
AdvancedChecklist = 'org.standardnotes.advanced-checklist',
CodeEditor = 'org.standardnotes.code-editor',
MarkdownProEditor = 'org.standardnotes.advanced-markdown-editor',
MarkdownVisualEditor = 'org.standardnotes.markdown-visual-editor',
PlainTextEditor = 'org.standardnotes.plain-text-editor',
PlusEditor = 'org.standardnotes.plus-editor',
SheetsEditor = 'org.standardnotes.standard-sheets',
TaskEditor = 'org.standardnotes.simple-task-editor',
TokenVaultEditor = 'org.standardnotes.token-vault',
DeprecatedBoldEditor = 'org.standardnotes.bold-editor',
DeprecatedMarkdownBasicEditor = 'org.standardnotes.simple-markdown-editor',
DeprecatedMarkdownMathEditor = 'org.standardnotes.fancy-markdown-editor',
DeprecatedMarkdownMinimistEditor = 'org.standardnotes.minimal-markdown-editor',
DeprecatedFoldersComponent = 'org.standardnotes.folders',
DeprecatedFileSafe = 'org.standardnotes.file-safe',
}
/**
* Identifier for standalone filesafe instance offered as legacy installable via extensions-server
*/
export const LegacyFileSafeIdentifier = 'org.standardnotes.legacy.file-safe'
export const ExperimentalFeatures = [FeatureIdentifier.AdvancedChecklist]

View File

@@ -0,0 +1,19 @@
import { SubscriptionName } from '@standardnotes/common'
import { GetFeatures, GetFeaturesForSubscription } from './Features'
describe('features', () => {
it('all features should have availableInSubscriptions populated', () => {
const features = GetFeatures()
for (const feature of features) {
expect(feature.availableInSubscriptions.length).toBeGreaterThan(0)
}
})
it('gets features for plus plan', () => {
const features = GetFeaturesForSubscription(SubscriptionName.PlusPlan)
for (const feature of features) {
expect(feature.availableInSubscriptions.includes(SubscriptionName.PlusPlan))
}
})
})

View File

@@ -0,0 +1,28 @@
import { FeatureDescription } from './FeatureDescription'
import { FeatureIdentifier } from './FeatureIdentifier'
import { editors } from '../Lists/Editors'
import { themes } from '../Lists/Themes'
import { serverFeatures } from '../Lists/ServerFeatures'
import { clientFeatures } from '../Lists/ClientFeatures'
import { GetDeprecatedFeatures } from '../Lists/DeprecatedFeatures'
import { experimentalFeatures } from '../Lists/ExperimentalFeatures'
import { SubscriptionName } from '@standardnotes/common'
export function GetFeatures(): FeatureDescription[] {
return [
...themes(),
...editors(),
...serverFeatures(),
...clientFeatures(),
...experimentalFeatures(),
...GetDeprecatedFeatures(),
]
}
export function GetFeaturesForSubscription(subscription: SubscriptionName): FeatureDescription[] {
return GetFeatures().filter((feature) => feature.availableInSubscriptions.includes(subscription))
}
export function FindNativeFeature(identifier: FeatureIdentifier): FeatureDescription | undefined {
return GetFeatures().find((f) => f.identifier === identifier)
}