meta.ts 13 KB

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