meta.ts 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337
  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 AllowedImageName,
  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 { 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. ManagedGroupSubscription,
  32. MemberGroupSubscription,
  33. } from '../../../types/subscription/dashboard/subscription'
  34. import { SplitTestInfo } from '../../../types/split-test'
  35. import { ValidationStatus } from '../../../types/group-management/validation'
  36. import { ManagedInstitution } from '../../../types/subscription/dashboard/managed-institution'
  37. import { OnboardingFormData } from '../../../types/onboarding'
  38. import { GroupSSOTestResult } from '../../../modules/group-settings/frontend/js/utils/types'
  39. import {
  40. AccessToken,
  41. InstitutionLink,
  42. SAMLError,
  43. } from '../../../types/settings-page'
  44. import { SuggestedLanguage } from '../../../types/system-message'
  45. import type { TeamInvite } from '../../../types/team-invite'
  46. import { GroupPlans } from '../../../types/subscription/dashboard/group-plans'
  47. import { GroupSSOLinkingStatus } from '../../../types/subscription/sso'
  48. import { PasswordStrengthOptions } from '../../../types/password-strength-options'
  49. import { Subscription as ProjectDashboardSubscription } from '../../../types/project/dashboard/subscription'
  50. import { ThirdPartyIds } from '../../../types/third-party-ids'
  51. import { Publisher } from '../../../types/subscription/dashboard/publisher'
  52. import { SubscriptionChangePreview } from '../../../types/subscription/subscription-change-preview'
  53. import { DefaultNavbarMetadata } from '@/features/ui/components/types/default-navbar-metadata'
  54. import { FooterMetadata } from '@/features/ui/components/types/footer-metadata'
  55. import type { ScriptLogType } from '../../../modules/admin-panel/frontend/js/features/script-logs/script-log'
  56. import { ActiveExperiment } from './labs-utils'
  57. import { Subscription as AdminSubscription } from '../../../types/admin/subscription'
  58. export interface Meta {
  59. 'ol-ExposedSettings': ExposedSettings
  60. 'ol-addonPrices': Record<
  61. string,
  62. { annual: string; monthly: string; annualDividedByTwelve: string }
  63. >
  64. 'ol-adminSubscription': AdminSubscription
  65. 'ol-aiAssistViaWritefullSource': string
  66. 'ol-allInReconfirmNotificationPeriods': UserEmailData[]
  67. 'ol-allowedExperiments': string[]
  68. 'ol-allowedImageNames': AllowedImageName[]
  69. 'ol-anonymous': boolean
  70. 'ol-baseAssetPath': string
  71. 'ol-bootstrapVersion': 3 | 5
  72. 'ol-brandVariation': Record<string, any>
  73. // dynamic keys based on permissions
  74. 'ol-canUseAddSeatsFeature': boolean
  75. 'ol-canUseFlexibleLicensing': boolean
  76. 'ol-canUseFlexibleLicensingForConsolidatedPlans': boolean
  77. 'ol-cannot-add-secondary-email': boolean
  78. 'ol-cannot-change-password': boolean
  79. 'ol-cannot-delete-own-account': boolean
  80. 'ol-cannot-join-subscription': boolean
  81. 'ol-cannot-leave-group-subscription': boolean
  82. 'ol-cannot-link-google-sso': boolean
  83. 'ol-cannot-link-other-third-party-sso': boolean
  84. 'ol-cannot-reactivate-subscription': boolean
  85. 'ol-cannot-use-ai': boolean
  86. 'ol-capabilities': Array<'dropbox' | 'chat'>
  87. 'ol-compileSettings': {
  88. reducedTimeoutWarning: string
  89. compileTimeout: number
  90. }
  91. 'ol-compilesUserContentDomain': string
  92. 'ol-countryCode': PricingFormState['country']
  93. 'ol-couponCode': PricingFormState['coupon']
  94. 'ol-createdAt': Date
  95. 'ol-csrfToken': string
  96. 'ol-currentInstitutionsWithLicence': Institution[]
  97. 'ol-currentManagedUserAdminEmail': string
  98. 'ol-currentUrl': string
  99. 'ol-customerIoEnabled': boolean
  100. 'ol-debugPdfDetach': boolean
  101. 'ol-detachRole': 'detached' | 'detacher' | ''
  102. 'ol-dictionariesRoot': 'string'
  103. 'ol-dropbox': { error: boolean; registered: boolean }
  104. 'ol-editorThemes': string[]
  105. 'ol-email': string
  106. 'ol-emailAddressLimit': number
  107. 'ol-error': { name: string } | undefined
  108. 'ol-expired': boolean
  109. 'ol-features': Features
  110. 'ol-footer': FooterMetadata
  111. 'ol-fromPlansPage': boolean
  112. 'ol-galleryTagName': string
  113. 'ol-gitBridgeEnabled': boolean
  114. 'ol-gitBridgePublicBaseUrl': string
  115. 'ol-github': { enabled: boolean; error: boolean }
  116. 'ol-groupAuditLogs': []
  117. 'ol-groupId': string
  118. 'ol-groupName': string
  119. 'ol-groupPlans': GroupPlans
  120. 'ol-groupPolicy': GroupPolicy
  121. 'ol-groupSSOActive': boolean
  122. 'ol-groupSSOTestResult': GroupSSOTestResult
  123. 'ol-groupSettingsAdvertisedFor': string[]
  124. 'ol-groupSettingsEnabledFor': string[]
  125. 'ol-groupSize': number
  126. 'ol-groupSsoSetupSuccess': boolean
  127. 'ol-groupSubscriptionsPendingEnrollment': PendingGroupSubscriptionEnrollment[]
  128. 'ol-groupsAndEnterpriseBannerVariant': GroupsAndEnterpriseBannerVariant
  129. 'ol-hasAiAssistViaWritefull': boolean
  130. 'ol-hasGroupSSOFeature': boolean
  131. 'ol-hasIndividualPaidSubscription': boolean
  132. 'ol-hasManagedUsersFeature': boolean
  133. 'ol-hasPassword': boolean
  134. 'ol-hasSplitTestWriteAccess': boolean
  135. 'ol-hasSubscription': boolean
  136. 'ol-hasTrackChangesFeature': boolean
  137. 'ol-hideLinkingWidgets': boolean // CI only
  138. 'ol-i18n': { currentLangCode: string }
  139. 'ol-inactiveTutorials': string[]
  140. 'ol-institutionEmailNonCanonical': string | undefined
  141. 'ol-institutionLinked': InstitutionLink | undefined
  142. 'ol-inviteToken': string
  143. 'ol-inviterName': string
  144. 'ol-isCollectionMethodManual': boolean
  145. 'ol-isExternalAuthenticationSystemUsed': boolean
  146. 'ol-isManagedAccount': boolean
  147. 'ol-isPaywallChangeCompileTimeoutEnabled': boolean
  148. 'ol-isProfessional': boolean
  149. 'ol-isRegisteredViaGoogle': boolean
  150. 'ol-isRestrictedTokenMember': boolean
  151. 'ol-isSaas': boolean
  152. 'ol-isUserGroupManager': boolean
  153. 'ol-itm_campaign': string
  154. 'ol-itm_content': string
  155. 'ol-itm_referrer': string
  156. 'ol-labs': boolean
  157. 'ol-labsExperiments': ActiveExperiment[] | undefined
  158. 'ol-languages': SpellCheckLanguage[]
  159. 'ol-learnedWords': string[]
  160. 'ol-legacyEditorThemes': string[]
  161. 'ol-licenseQuantity': number | undefined
  162. 'ol-loadingText': string
  163. 'ol-managedGroupSubscriptions': ManagedGroupSubscription[]
  164. 'ol-managedInstitutions': ManagedInstitution[]
  165. 'ol-managedPublishers': Publisher[]
  166. 'ol-managedUsersActive': boolean
  167. 'ol-managedUsersEnabled': boolean
  168. 'ol-managers': MinimalUser[]
  169. 'ol-mathJaxPath': string
  170. 'ol-maxDocLength': number
  171. 'ol-maxReconnectGracefullyIntervalMs': number
  172. 'ol-memberGroupSubscriptions': MemberGroupSubscription[]
  173. 'ol-memberOfSSOEnabledGroups': GroupSSOLinkingStatus[]
  174. 'ol-members': MinimalUser[]
  175. 'ol-navbar': DefaultNavbarMetadata
  176. 'ol-no-single-dollar': boolean
  177. 'ol-notifications': NotificationType[]
  178. 'ol-notificationsInstitution': InstitutionType[]
  179. 'ol-oauthProviders': OAuthProviders
  180. 'ol-odcData': OnboardingFormData
  181. 'ol-odcRole': string
  182. 'ol-overallThemes': OverallThemeMeta[]
  183. 'ol-pages': number
  184. 'ol-passwordStrengthOptions': PasswordStrengthOptions
  185. 'ol-paywallPlans': { [key: string]: string }
  186. 'ol-personalAccessTokens': AccessToken[] | undefined
  187. 'ol-plan': Plan
  188. 'ol-planCode': string
  189. 'ol-planCodesChangingAtTermEnd': string[] | undefined
  190. 'ol-plans': Plan[]
  191. 'ol-portalTemplates': PortalTemplate[]
  192. 'ol-postCheckoutRedirect': string
  193. 'ol-postUrl': string
  194. 'ol-prefetchedProjectsBlob': GetProjectsResponseBody | undefined
  195. 'ol-preventCompileOnLoad'?: boolean
  196. 'ol-primaryEmail': { email: string; confirmed: boolean }
  197. 'ol-project': any // TODO
  198. 'ol-projectEntityCounts'?: { files: number; docs: number }
  199. 'ol-projectHistoryBlobsEnabled': boolean
  200. 'ol-projectName': string
  201. 'ol-projectOwnerHasPremiumOnPageLoad': boolean
  202. 'ol-projectSyncSuccessMessage': string
  203. 'ol-projectTags': Tag[]
  204. 'ol-project_id': string
  205. 'ol-purchaseReferrer': string
  206. 'ol-recommendedCurrency': CurrencyCode
  207. 'ol-reconfirmationRemoveEmail': string
  208. 'ol-reconfirmedViaSAML': string
  209. 'ol-recurlyAccount':
  210. | {
  211. code: string
  212. error?: undefined
  213. }
  214. | {
  215. error: boolean
  216. code?: undefined
  217. }
  218. | undefined
  219. 'ol-recurlyApiKey': string
  220. 'ol-recurlySubdomain': string
  221. 'ol-ro-mirror-on-client-no-local-storage': boolean
  222. 'ol-samlError': SAMLError | undefined
  223. 'ol-script-log': ScriptLogType
  224. 'ol-script-logs': ScriptLogType[]
  225. 'ol-settingsGroupSSO': { enabled: boolean } | undefined
  226. 'ol-settingsPlans': Plan[]
  227. 'ol-shouldAllowEditingDetails': boolean
  228. 'ol-shouldLoadHotjar': boolean
  229. 'ol-showAiAssistNotification': boolean
  230. 'ol-showAiErrorAssistant': boolean
  231. 'ol-showBrlGeoBanner': boolean
  232. 'ol-showCouponField': boolean
  233. 'ol-showGroupDiscount': boolean
  234. 'ol-showGroupsAndEnterpriseBanner': boolean
  235. 'ol-showInrGeoBanner': boolean
  236. 'ol-showLATAMBanner': boolean
  237. 'ol-showSupport': boolean
  238. 'ol-showSymbolPalette': boolean
  239. 'ol-showTemplatesServerPro': boolean
  240. 'ol-showUSGovBanner': boolean
  241. 'ol-showUpgradePrompt': boolean
  242. 'ol-skipUrl': string
  243. 'ol-splitTestInfo': { [name: string]: SplitTestInfo }
  244. 'ol-splitTestName': string
  245. 'ol-splitTestVariants': { [name: string]: string }
  246. 'ol-ssoDisabled': boolean
  247. 'ol-ssoErrorMessage': string
  248. 'ol-stripeCustomerId': string
  249. 'ol-stripeUKApiKey': string
  250. 'ol-subscription': any // TODO: mixed types, split into two fields
  251. 'ol-subscriptionChangePreview': SubscriptionChangePreview
  252. 'ol-subscriptionId': string
  253. 'ol-suggestedLanguage': SuggestedLanguage | undefined
  254. 'ol-survey': Survey | undefined
  255. 'ol-symbolPaletteAvailable': boolean
  256. 'ol-tags': Tag[]
  257. 'ol-teamInvites': TeamInvite[]
  258. 'ol-thirdPartyIds': ThirdPartyIds
  259. 'ol-totalLicenses': number
  260. 'ol-translationIoNotLoaded': string
  261. 'ol-translationLoadErrorMessage': string
  262. 'ol-translationMaintenance': string
  263. 'ol-translationUnableToJoin': string
  264. 'ol-usGovBannerVariant': USGovBannerVariant
  265. 'ol-useShareJsHash': boolean
  266. 'ol-user': User
  267. 'ol-userAffiliations': Affiliation[]
  268. 'ol-userCanExtendTrial': boolean
  269. 'ol-userCanNotStartRequestedTrial': boolean
  270. 'ol-userEmails': UserEmailData[]
  271. 'ol-userSettings': UserSettings
  272. 'ol-user_id': string | undefined
  273. 'ol-users': ManagedUser[]
  274. 'ol-usersBestSubscription': ProjectDashboardSubscription | undefined
  275. 'ol-usersEmail': string | undefined
  276. 'ol-usersSubscription': { personal: boolean; group: boolean }
  277. 'ol-validationStatus': ValidationStatus
  278. 'ol-wikiEnabled': boolean
  279. 'ol-writefullCssUrl': string
  280. 'ol-writefullEnabled': boolean
  281. 'ol-writefullJsUrl': string
  282. 'ol-wsUrl': string
  283. }
  284. type DeepPartial<T> =
  285. T extends Record<string, any> ? { [P in keyof T]?: DeepPartial<T[P]> } : T
  286. export type PartialMeta = DeepPartial<Meta>
  287. export type MetaAttributesCache<
  288. K extends keyof PartialMeta = keyof PartialMeta,
  289. > = Map<K, PartialMeta[K]>
  290. export type MetaTag = {
  291. [K in keyof Meta]: {
  292. name: K
  293. value: Meta[K]
  294. }
  295. }[keyof Meta]
  296. // cache for parsed values
  297. window.metaAttributesCache = window.metaAttributesCache || new Map()
  298. export default function getMeta<T extends keyof Meta>(name: T): Meta[T] {
  299. if (window.metaAttributesCache.has(name)) {
  300. return window.metaAttributesCache.get(name)
  301. }
  302. const element = document.head.querySelector(
  303. `meta[name="${name}"]`
  304. ) as HTMLMetaElement
  305. if (!element) {
  306. return undefined!
  307. }
  308. const plainTextValue = element.content
  309. let value
  310. switch (element.dataset.type) {
  311. case 'boolean':
  312. // in pug: content=false -> no content field
  313. // in pug: content=true -> empty content field
  314. value = element.hasAttribute('content')
  315. break
  316. case 'json':
  317. if (!plainTextValue) {
  318. // JSON.parse('') throws
  319. value = undefined
  320. } else {
  321. value = JSON.parse(plainTextValue)
  322. }
  323. break
  324. default:
  325. value = plainTextValue
  326. }
  327. window.metaAttributesCache.set(name, value)
  328. return value
  329. }