meta.ts 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408
  1. import { User, Features } from '../../../types/user'
  2. import { User as MinimalUser } from '../../../types/admin/user'
  3. import { User as ManagedUser } from '../../../types/group-management/user'
  4. import { UserSettings } from '../../../types/user-settings'
  5. import { OAuthProviders } from '../../../types/oauth-providers'
  6. import { ExposedSettings } from '../../../types/exposed-settings'
  7. import {
  8. type ImageName,
  9. OverallThemeMeta,
  10. type SpellCheckLanguage,
  11. } from '../../../types/project-settings'
  12. import { CurrencyCode } from '../../../types/subscription/currency'
  13. import { PricingFormState } from '../../../types/subscription/payment-context-value'
  14. import { LocalIndividualPlans, Plan } from '../../../types/subscription/plan'
  15. import { Affiliation } from '../../../types/affiliation'
  16. import type { PortalTemplate } from '../../../types/portal-template'
  17. import { UserEmailData } from '../../../types/user-email'
  18. import {
  19. GroupsAndEnterpriseBannerVariant,
  20. Institution as InstitutionType,
  21. Notification as NotificationType,
  22. PendingGroupSubscriptionEnrollment,
  23. USGovBannerVariant,
  24. } from '../../../types/project/dashboard/notification'
  25. import { Survey } from '../../../types/project/dashboard/survey'
  26. import { GetProjectsResponseBody } from '../../../types/project/dashboard/api'
  27. import { Tag } from '../../../app/src/Features/Tags/types'
  28. import { Institution } from '../../../types/institution'
  29. import {
  30. GroupPolicy,
  31. GroupSubscription,
  32. ManagedGroupSubscription,
  33. MemberGroupSubscription,
  34. StripePaymentProviderService,
  35. } from '../../../types/subscription/dashboard/subscription'
  36. import { SplitTestInfo } from '../../../types/split-test'
  37. import { ValidationStatus } from '../../../types/group-management/validation'
  38. import { ManagedInstitution } from '../../../types/subscription/dashboard/managed-institution'
  39. import { OnboardingFormData } from '../../../types/onboarding'
  40. import { GroupSSOTestResult } from '../../../modules/group-settings/frontend/js/utils/types'
  41. import {
  42. AccessToken,
  43. InstitutionLink,
  44. SAMLError,
  45. } from '../../../types/settings-page'
  46. import { SuggestedLanguage } from '../../../types/system-message'
  47. import type { TeamInvite } from '../../../types/team-invite'
  48. import {
  49. GroupPlans,
  50. GroupPlansData,
  51. } from '../../../types/subscription/dashboard/group-plans'
  52. import {
  53. GroupSSOLinkingStatus,
  54. SSOConfig,
  55. } from '../../../types/subscription/sso'
  56. import { PasswordStrengthOptions } from '../../../types/password-strength-options'
  57. import { Subscription as ProjectDashboardSubscription } from '../../../types/project/dashboard/subscription'
  58. import { ThirdPartyIds } from '../../../types/third-party-ids'
  59. import { Publisher } from '../../../types/subscription/dashboard/publisher'
  60. import { SubscriptionChangePreview } from '../../../types/subscription/subscription-change-preview'
  61. import { SubscriptionCreationPreview } from '../../../types/subscription/subscription-creation-preview'
  62. import { DefaultNavbarMetadata } from '@/shared/components/types/default-navbar-metadata'
  63. import { FooterMetadata } from '@/shared/components/types/footer-metadata'
  64. import type { ScriptLogType } from '../../../modules/admin-panel/frontend/js/features/script-logs/script-log'
  65. import { Subscription as AdminSubscription } from '../../../types/admin/subscription'
  66. import { AdminCapability } from '../../../types/admin-capabilities'
  67. import { AlgoliaConfig } from '../../../modules/algolia-search/frontend/js/types'
  68. import { WritefullPublicEnv } from '@wf/domain/writefull-public-env'
  69. import { UserNotificationPreferences } from '../../../types/notifications'
  70. import { SharingPermissions } from '../../../modules/sharing-permissions/app/src/types'
  71. export interface Meta {
  72. 'ol-ExposedSettings': ExposedSettings
  73. 'ol-addonPrices': Record<
  74. string,
  75. { annual: string; monthly: string; annualDividedByTwelve: string }
  76. >
  77. 'ol-adminCapabilities': AdminCapability[]
  78. 'ol-adminSubscription': AdminSubscription
  79. 'ol-adminUserExists': boolean
  80. 'ol-aiAssistViaWritefullSource': string
  81. 'ol-algolia': AlgoliaConfig | undefined
  82. 'ol-allInReconfirmNotificationPeriods': UserEmailData[]
  83. 'ol-allowedExperiments': string[]
  84. 'ol-anonymous': boolean
  85. 'ol-baseAssetPath': string
  86. 'ol-brandVariation': Record<string, any>
  87. 'ol-canUseAddSeatsFeature': boolean
  88. 'ol-canUseClsiCache': boolean
  89. 'ol-canUseFlexibleLicensing': boolean
  90. // dynamic keys based on permissions
  91. 'ol-cannot-add-secondary-email': boolean
  92. 'ol-cannot-change-password': boolean
  93. 'ol-cannot-delete-own-account': boolean
  94. 'ol-cannot-join-subscription': boolean
  95. 'ol-cannot-leave-group-subscription': boolean
  96. 'ol-cannot-link-google-sso': boolean
  97. 'ol-cannot-link-other-third-party-sso': boolean
  98. 'ol-cannot-reactivate-subscription': boolean
  99. 'ol-cannot-use-ai': boolean
  100. 'ol-capabilities': Array<'dropbox' | 'chat' | 'use-ai' | 'link-sharing'>
  101. 'ol-compileSettings': {
  102. compileTimeout: number
  103. }
  104. 'ol-compilesUserContentDomain': string
  105. 'ol-countryCode': PricingFormState['country']
  106. 'ol-couponCode': PricingFormState['coupon']
  107. 'ol-createNewUserViaDomainCapture': boolean
  108. 'ol-createdAt': Date
  109. 'ol-csrfToken': string
  110. 'ol-currentInstitutionsWithLicence': Institution[]
  111. 'ol-currentManagedUserAdminEmail': string
  112. 'ol-currentUrl': string
  113. 'ol-customerIoEnabled': boolean
  114. 'ol-debugPdfDetach': boolean
  115. 'ol-detachRole': 'detached' | 'detacher' | ''
  116. 'ol-dictionariesRoot': 'string'
  117. 'ol-domainCaptureEnabled': boolean | undefined
  118. 'ol-domainCaptureTestURL': string | undefined
  119. 'ol-domainVerificationUIEnabled': boolean
  120. 'ol-dropbox': { error: boolean; registered: boolean }
  121. 'ol-editorThemes': { name: string; dark: boolean }[]
  122. 'ol-email': string
  123. 'ol-emailAddressLimit': number
  124. 'ol-error': { name: string } | undefined
  125. 'ol-errorType': string | undefined
  126. 'ol-expired': boolean
  127. 'ol-features': Features
  128. 'ol-footer': FooterMetadata
  129. 'ol-fromPlansPage': boolean
  130. 'ol-galleryTagName': string
  131. 'ol-gitBridgeEnabled': boolean
  132. 'ol-gitBridgePublicBaseUrl': string
  133. 'ol-github': { enabled: boolean; error: boolean }
  134. 'ol-groupAuditLogs': []
  135. 'ol-groupDomains': []
  136. 'ol-groupId': string
  137. 'ol-groupName': string
  138. 'ol-groupPlans': GroupPlans
  139. 'ol-groupPlansData': GroupPlansData
  140. 'ol-groupPolicy': GroupPolicy
  141. 'ol-groupSSOActive': boolean
  142. 'ol-groupSSOConfig'?: SSOConfig
  143. 'ol-groupSSOTestResult': GroupSSOTestResult
  144. 'ol-groupSettingsAdvertisedFor': string[]
  145. 'ol-groupSettingsEnabledFor': string[]
  146. 'ol-groupSize': number
  147. 'ol-groupSsoSetupSuccess': boolean
  148. 'ol-groupSubscriptionsPendingEnrollment': PendingGroupSubscriptionEnrollment[]
  149. 'ol-groupsAndEnterpriseBannerVariant': GroupsAndEnterpriseBannerVariant
  150. 'ol-hasAiAssistViaWritefull': boolean
  151. 'ol-hasGroupSSOFeature': boolean
  152. 'ol-hasIndividualPaidSubscription': boolean
  153. 'ol-hasManagedUsersFeature': boolean
  154. 'ol-hasModifyGroupManagerAccess': boolean
  155. 'ol-hasPassword': boolean
  156. 'ol-hasSplitTestWriteAccess': boolean
  157. 'ol-hasSubscription': boolean
  158. 'ol-hasTrackChangesFeature': boolean
  159. 'ol-hasWriteAccess': boolean
  160. 'ol-hideLinkingWidgets': boolean // CI only
  161. 'ol-historyBlobStats': {
  162. projectId: string
  163. textBlobsBytes: number
  164. binaryBlobsBytes: number
  165. totalBytes: number
  166. nTextBlobs: number
  167. nBinaryBlobs: number
  168. owned?: boolean
  169. }[]
  170. 'ol-i18n': { currentLangCode: string }
  171. 'ol-imageNames': ImageName[]
  172. 'ol-inactiveTutorials': string[]
  173. 'ol-institutionEmail': string | undefined
  174. 'ol-institutionEmailNonCanonical': string | undefined
  175. 'ol-institutionLinked': InstitutionLink | undefined
  176. 'ol-inviteToken': string
  177. 'ol-inviterName': string
  178. 'ol-isCollectionMethodManual': boolean
  179. 'ol-isExternalAuthenticationSystemUsed': boolean
  180. 'ol-isManagedAccount': boolean
  181. 'ol-isProfessional': boolean
  182. 'ol-isRegisteredViaGoogle': boolean
  183. 'ol-isRestrictedTokenMember': boolean
  184. 'ol-isSaas': boolean
  185. 'ol-isUserGroupManager': boolean
  186. 'ol-itm_campaign': string
  187. 'ol-itm_content': string
  188. 'ol-itm_referrer': string
  189. 'ol-joinedGroupName': string
  190. 'ol-labs': boolean
  191. 'ol-labsExperiments': Array<{
  192. name: string
  193. title: string
  194. description: string
  195. icon: string
  196. surveyLink: string
  197. isFull: boolean
  198. optedIn: boolean
  199. }>
  200. 'ol-languages': SpellCheckLanguage[]
  201. 'ol-learnedWords': string[]
  202. 'ol-legacyEditorThemes': { name: string; dark: boolean }[]
  203. 'ol-licenseQuantity'?: number
  204. 'ol-loadingText': string
  205. 'ol-localIndividualPlans': LocalIndividualPlans
  206. 'ol-managedGroupSubscriptions': ManagedGroupSubscription[]
  207. 'ol-managedInstitutions': ManagedInstitution[]
  208. 'ol-managedPublishers': Publisher[]
  209. 'ol-managedUsersActive': boolean
  210. 'ol-managedUsersEnabled': boolean
  211. 'ol-managers': MinimalUser[]
  212. 'ol-mathJaxPath': string
  213. 'ol-maxDocLength': number
  214. 'ol-maxReconnectGracefullyIntervalMs': number
  215. 'ol-memberGroupSubscriptions': MemberGroupSubscription[]
  216. 'ol-memberOfSSOEnabledGroups': GroupSSOLinkingStatus[]
  217. 'ol-members': MinimalUser[]
  218. 'ol-multiple-group-subscriptions': Array<
  219. Pick<GroupSubscription, 'teamName'> & { id: string; email: string }
  220. >
  221. 'ol-navbar': DefaultNavbarMetadata
  222. 'ol-newsletter-subscribed': boolean
  223. 'ol-no-single-dollar': boolean
  224. 'ol-notifications': NotificationType[]
  225. 'ol-notificationsInstitution': InstitutionType[]
  226. 'ol-oauthProviders': OAuthProviders
  227. 'ol-odcData': OnboardingFormData
  228. 'ol-onAiFreeTrial': boolean
  229. 'ol-otMigrationStage': number
  230. 'ol-overallThemes': OverallThemeMeta[]
  231. 'ol-ownerIsManaged': boolean
  232. 'ol-pages': number
  233. 'ol-passwordStrengthOptions': PasswordStrengthOptions
  234. 'ol-paywallPlans': { [key: string]: string }
  235. 'ol-personalAccessTokens': AccessToken[] | undefined
  236. 'ol-plan': Plan
  237. 'ol-planCode': string
  238. 'ol-planCodesChangingAtTermEnd': string[] | undefined
  239. 'ol-plans': Plan[]
  240. 'ol-portalTemplates': PortalTemplate[]
  241. 'ol-postCheckoutRedirect': string
  242. 'ol-postUrl': string
  243. 'ol-prefetchedProjectsBlob': GetProjectsResponseBody | undefined
  244. 'ol-preventCompileOnLoad'?: boolean
  245. 'ol-primaryEmail': { email: string; confirmed: boolean }
  246. 'ol-project': any // TODO
  247. 'ol-projectEntityCounts': { files: number; docs: number }
  248. 'ol-projectName': string
  249. 'ol-projectSyncSuccessMessage': string
  250. 'ol-projectTags': Tag[]
  251. 'ol-project_id': string
  252. 'ol-purchaseReferrer': string
  253. 'ol-recommendedCurrency': CurrencyCode
  254. 'ol-reconfirmationRemoveEmail': string
  255. 'ol-reconfirmedViaSAML': string
  256. 'ol-recurlyAccount':
  257. | {
  258. code: string
  259. error?: undefined
  260. }
  261. | {
  262. error: boolean
  263. code?: undefined
  264. }
  265. | undefined
  266. 'ol-recurlyApiKey': string
  267. 'ol-recurlySubdomain': string
  268. 'ol-ro-mirror-on-client-no-local-storage': boolean
  269. 'ol-samlError': SAMLError | undefined
  270. 'ol-script-log': ScriptLogType
  271. 'ol-script-logs': ScriptLogType[]
  272. 'ol-settingsGroupSSO': { enabled: boolean } | undefined
  273. 'ol-settingsPlans': Plan[]
  274. 'ol-sharingPermissions': SharingPermissions
  275. 'ol-shouldAllowEditingDetails': boolean
  276. 'ol-shouldLoadHotjar': boolean
  277. 'ol-showAiFeatures': boolean
  278. 'ol-showCouponField': boolean
  279. 'ol-showGroupDiscount': boolean
  280. 'ol-showGroupsAndEnterpriseBanner': boolean
  281. 'ol-showInrGeoBanner': boolean
  282. 'ol-showLATAMBanner': boolean
  283. 'ol-showSupport': boolean
  284. 'ol-showSymbolPalette': boolean
  285. 'ol-showTemplatesServerPro': boolean
  286. 'ol-showUSGovBanner': boolean
  287. 'ol-showUpgradePrompt': boolean
  288. 'ol-splitTestInfo': { [name: string]: SplitTestInfo }
  289. 'ol-splitTestName': string
  290. 'ol-splitTestVariants': { [name: string]: string }
  291. 'ol-ssoDisabled': boolean
  292. 'ol-ssoErrorMessage': string
  293. 'ol-ssoInitPath': string
  294. 'ol-standardPlanPricing': {
  295. monthly?: string
  296. annual?: string
  297. monthlyTimesTwelve?: string
  298. }
  299. 'ol-stripeCustomerData': Array<{
  300. customerId: string
  301. subscriptionId: string
  302. subscriptionState: string | null
  303. paymentProviderService: StripePaymentProviderService | null
  304. managementUrl: string
  305. segment?: string | null
  306. error?: string
  307. }>
  308. 'ol-stripePublicKeyUK': string
  309. 'ol-stripePublicKeyUS': string
  310. 'ol-subscription': any // TODO: mixed types, split into two fields
  311. 'ol-subscriptionChangePreview': SubscriptionChangePreview
  312. 'ol-subscriptionCreationPreview': SubscriptionCreationPreview
  313. 'ol-subscriptionFeatures': {
  314. managedUsers?: boolean
  315. groupSSO?: boolean
  316. domainCapture?: boolean
  317. }
  318. 'ol-subscriptionId': string
  319. 'ol-subscriptionPaymentErrorCode': string | null
  320. 'ol-suggestedLanguage': SuggestedLanguage | undefined
  321. 'ol-survey': Survey | undefined
  322. 'ol-symbolPaletteAvailable': boolean
  323. 'ol-tags': Tag[]
  324. 'ol-teamInvites': TeamInvite[]
  325. 'ol-thirdPartyIds': ThirdPartyIds
  326. 'ol-totalLicenses': number
  327. 'ol-translationIoNotLoaded': string
  328. 'ol-translationLoadErrorMessage': string
  329. 'ol-translationMaintenance': string
  330. 'ol-translationUnableToJoin': string
  331. 'ol-trialDisabledReason': string | undefined
  332. 'ol-usGovBannerVariant': USGovBannerVariant
  333. 'ol-useShareJsHash': boolean
  334. 'ol-user': User
  335. 'ol-userAffiliations': Affiliation[]
  336. 'ol-userCanExtendTrial': boolean
  337. 'ol-userCanNotStartRequestedTrial': boolean
  338. 'ol-userEmails': UserEmailData[]
  339. 'ol-userNotificationPreferences': UserNotificationPreferences
  340. 'ol-userSettings': UserSettings
  341. 'ol-user_id': string | undefined
  342. 'ol-users': ManagedUser[]
  343. 'ol-usersBestSubscription': ProjectDashboardSubscription | undefined
  344. 'ol-usersEmail': string | undefined
  345. 'ol-usersSubscription': { personal: boolean; group: boolean }
  346. 'ol-validationStatus': ValidationStatus
  347. 'ol-viaDomainCapture': boolean
  348. 'ol-wikiEnabled': boolean
  349. 'ol-writefullEnabled': boolean
  350. 'ol-writefullEnv': WritefullPublicEnv
  351. 'ol-wsUrl': string
  352. }
  353. type DeepPartial<T> =
  354. T extends Record<string, any> ? { [P in keyof T]?: DeepPartial<T[P]> } : T
  355. export type PartialMeta = DeepPartial<Meta>
  356. export type MetaAttributesCache<
  357. K extends keyof PartialMeta = keyof PartialMeta,
  358. > = Map<K, PartialMeta[K]>
  359. export type MetaTag = {
  360. [K in keyof Meta]: {
  361. name: K
  362. value: Meta[K]
  363. }
  364. }[keyof Meta]
  365. // cache for parsed values
  366. window.metaAttributesCache = window.metaAttributesCache || new Map()
  367. export default function getMeta<T extends keyof Meta>(name: T): Meta[T] {
  368. if (window.metaAttributesCache.has(name)) {
  369. return window.metaAttributesCache.get(name)
  370. }
  371. const element = document.head.querySelector(
  372. `meta[name="${name}"]`
  373. ) as HTMLMetaElement
  374. if (!element) {
  375. return undefined!
  376. }
  377. const plainTextValue = element.content
  378. let value
  379. switch (element.dataset.type) {
  380. case 'boolean':
  381. // in pug: content=false -> no content field
  382. // in pug: content=true -> empty content field
  383. value = element.hasAttribute('content')
  384. break
  385. case 'json':
  386. case 'number':
  387. if (!plainTextValue) {
  388. // JSON.parse('') throws
  389. value = undefined
  390. } else {
  391. value = JSON.parse(plainTextValue)
  392. }
  393. break
  394. default:
  395. value = plainTextValue
  396. }
  397. window.metaAttributesCache.set(name, value)
  398. return value
  399. }