meta.ts 15 KB

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