meta.ts 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  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. ManagedGroupSubscription,
  31. MemberGroupSubscription,
  32. } from '../../../types/subscription/dashboard/subscription'
  33. import { SplitTestInfo } from '../../../types/split-test'
  34. import { ValidationStatus } from '../../../types/group-management/validation'
  35. import { ManagedInstitution } from '../../../types/subscription/dashboard/managed-institution'
  36. import { GroupSSOTestResult } from '../../../modules/group-settings/frontend/js/utils/types'
  37. import {
  38. AccessToken,
  39. InstitutionLink,
  40. SAMLError,
  41. } from '../../../types/settings-page'
  42. import { SuggestedLanguage } from '../../../types/system-message'
  43. import type { TeamInvite } from '../../../types/team-invite'
  44. import { GroupPlans } from '../../../types/subscription/dashboard/group-plans'
  45. import { GroupSSOLinkingStatus } from '../../../types/subscription/sso'
  46. import { PasswordStrengthOptions } from '../../../types/password-strength-options'
  47. import { Subscription as ProjectDashboardSubscription } from '../../../types/project/dashboard/subscription'
  48. import { ThirdPartyIds } from '../../../types/third-party-ids'
  49. import { Publisher } from '../../../types/subscription/dashboard/publisher'
  50. import { DefaultNavbarMetadata } from '@/features/ui/components/types/default-navbar-metadata'
  51. import { FatFooterMetadata } from '@/features/ui/components/types/fat-footer-metadata'
  52. export interface Meta {
  53. 'ol-ExposedSettings': ExposedSettings
  54. 'ol-allInReconfirmNotificationPeriods': UserEmailData[]
  55. 'ol-allowedExperiments': string[]
  56. 'ol-allowedImageNames': AllowedImageName[]
  57. 'ol-anonymous': boolean
  58. 'ol-baseAssetPath': string
  59. 'ol-bootstrapVersion': 3 | 5
  60. 'ol-brandVariation': Record<string, any>
  61. // dynamic keys based on permissions
  62. 'ol-cannot-add-secondary-email': boolean
  63. 'ol-cannot-change-password': boolean
  64. 'ol-cannot-delete-own-account': boolean
  65. 'ol-cannot-join-subscription': boolean
  66. 'ol-cannot-leave-group-subscription': boolean
  67. 'ol-cannot-link-google-sso': boolean
  68. 'ol-cannot-link-other-third-party-sso': boolean
  69. 'ol-cannot-reactivate-subscription': boolean
  70. 'ol-cannot-use-ai': boolean
  71. 'ol-chatEnabled': boolean
  72. 'ol-countryCode': PricingFormState['country']
  73. 'ol-couponCode': PricingFormState['coupon']
  74. 'ol-createdAt': Date
  75. 'ol-csrfToken': string
  76. 'ol-currentInstitutionsWithLicence': Institution[]
  77. 'ol-currentManagedUserAdminEmail': string
  78. 'ol-currentUrl': string
  79. 'ol-debugPdfDetach': boolean
  80. 'ol-detachRole': 'detached' | 'detacher' | ''
  81. 'ol-dictionariesRoot': 'string'
  82. 'ol-dropbox': { error: boolean; registered: boolean }
  83. 'ol-editorThemes': string[]
  84. 'ol-email': string
  85. 'ol-emailAddressLimit': number
  86. 'ol-error': { name: string } | undefined
  87. 'ol-expired': boolean
  88. 'ol-features': Features
  89. 'ol-footer': FatFooterMetadata
  90. 'ol-fromPlansPage': boolean
  91. 'ol-galleryTagName': string
  92. 'ol-gitBridgeEnabled': boolean
  93. 'ol-gitBridgePublicBaseUrl': string
  94. 'ol-github': { enabled: boolean; error: boolean }
  95. 'ol-groupId': string
  96. 'ol-groupName': string
  97. 'ol-groupPlans': GroupPlans
  98. 'ol-groupSSOActive': boolean
  99. 'ol-groupSSOTestResult': GroupSSOTestResult
  100. 'ol-groupSettingsEnabledFor': string[]
  101. 'ol-groupSize': number
  102. 'ol-groupSsoSetupSuccess': boolean
  103. 'ol-groupSubscriptionsPendingEnrollment': PendingGroupSubscriptionEnrollment[]
  104. 'ol-groupsAndEnterpriseBannerVariant': GroupsAndEnterpriseBannerVariant
  105. 'ol-hasGroupSSOFeature': boolean
  106. 'ol-hasIndividualRecurlySubscription': boolean
  107. 'ol-hasManagedUsersFeature': boolean
  108. 'ol-hasPassword': boolean
  109. 'ol-hasSubscription': boolean
  110. 'ol-hasTrackChangesFeature': boolean
  111. 'ol-hideLinkingWidgets': boolean // CI only
  112. 'ol-i18n': { currentLangCode: string }
  113. 'ol-inactiveTutorials': string[]
  114. 'ol-institutionEmailNonCanonical': string | undefined
  115. 'ol-institutionLinked': InstitutionLink | undefined
  116. 'ol-inviteToken': string
  117. 'ol-inviterName': string
  118. 'ol-isExternalAuthenticationSystemUsed': boolean
  119. 'ol-isManagedAccount': boolean
  120. 'ol-isProfessional': boolean
  121. 'ol-isRegisteredViaGoogle': boolean
  122. 'ol-isRestrictedTokenMember': boolean
  123. 'ol-isSaas': boolean
  124. 'ol-itm_campaign': string
  125. 'ol-itm_content': string
  126. 'ol-itm_referrer': string
  127. 'ol-labs': boolean
  128. 'ol-languages': SpellCheckLanguage[]
  129. 'ol-learnedWords': string[]
  130. 'ol-legacyEditorThemes': string[]
  131. 'ol-linkSharingEnforcement': boolean
  132. 'ol-linkSharingWarning': boolean
  133. 'ol-loadingText': string
  134. 'ol-managedGroupSubscriptions': ManagedGroupSubscription[]
  135. 'ol-managedInstitutions': ManagedInstitution[]
  136. 'ol-managedPublishers': Publisher[]
  137. 'ol-managedUsersActive': boolean
  138. 'ol-managedUsersEnabled': boolean
  139. 'ol-managers': MinimalUser[]
  140. 'ol-mathJaxPath': string
  141. 'ol-maxDocLength': number
  142. 'ol-memberGroupSubscriptions': MemberGroupSubscription[]
  143. 'ol-memberOfSSOEnabledGroups': GroupSSOLinkingStatus[]
  144. 'ol-members': MinimalUser[]
  145. 'ol-navbar': DefaultNavbarMetadata
  146. 'ol-no-single-dollar': boolean
  147. 'ol-notifications': NotificationType[]
  148. 'ol-notificationsInstitution': InstitutionType[]
  149. 'ol-oauthProviders': OAuthProviders
  150. 'ol-overallThemes': OverallThemeMeta[]
  151. 'ol-passwordStrengthOptions': PasswordStrengthOptions
  152. 'ol-personalAccessTokens': AccessToken[] | undefined
  153. 'ol-plan': Plan
  154. 'ol-planCode': string
  155. 'ol-planCodesChangingAtTermEnd': string[] | undefined
  156. 'ol-plans': Plan[]
  157. 'ol-portalTemplates': PortalTemplate[]
  158. 'ol-postCheckoutRedirect': string
  159. 'ol-postUrl': string
  160. 'ol-prefetchedProjectsBlob': GetProjectsResponseBody | undefined
  161. 'ol-primaryEmail': { email: string; confirmed: boolean }
  162. 'ol-project': any // TODO
  163. 'ol-projectSyncSuccessMessage': string
  164. 'ol-projectTags': Tag[]
  165. 'ol-project_id': string
  166. 'ol-recommendedCurrency': CurrencyCode
  167. 'ol-reconfirmationRemoveEmail': string
  168. 'ol-reconfirmedViaSAML': string
  169. 'ol-recurlyApiKey': string
  170. 'ol-recurlySubdomain': string
  171. 'ol-ro-mirror-on-client-no-local-storage': boolean
  172. 'ol-samlError': SAMLError | undefined
  173. 'ol-settingsGroupSSO': { enabled: boolean } | undefined
  174. 'ol-settingsPlans': Plan[]
  175. 'ol-shouldAllowEditingDetails': boolean
  176. 'ol-showAiErrorAssistant': boolean
  177. 'ol-showBrlGeoBanner': boolean
  178. 'ol-showCouponField': boolean
  179. 'ol-showGroupsAndEnterpriseBanner': boolean
  180. 'ol-showInrGeoBanner': boolean
  181. 'ol-showLATAMBanner': boolean
  182. 'ol-showSupport': boolean
  183. 'ol-showSymbolPalette': boolean
  184. 'ol-showTemplatesServerPro': boolean
  185. 'ol-showUSGovBanner': boolean
  186. 'ol-showUpgradePrompt': boolean
  187. 'ol-skipUrl': string
  188. 'ol-splitTestInfo': { [name: string]: SplitTestInfo }
  189. 'ol-splitTestVariants': { [name: string]: string }
  190. 'ol-ssoDisabled': boolean
  191. 'ol-ssoErrorMessage': string
  192. 'ol-subscription': any // TODO: mixed types, split into two fields
  193. 'ol-subscriptionId': string
  194. 'ol-suggestedLanguage': SuggestedLanguage | undefined
  195. 'ol-survey': Survey | undefined
  196. 'ol-symbolPaletteAvailable': boolean
  197. 'ol-tags': Tag[]
  198. 'ol-teamInvites': TeamInvite[]
  199. 'ol-thirdPartyIds': ThirdPartyIds
  200. 'ol-translationIoNotLoaded': string
  201. 'ol-translationLoadErrorMessage': string
  202. 'ol-translationMaintenance': string
  203. 'ol-translationUnableToJoin': string
  204. 'ol-usGovBannerVariant': USGovBannerVariant
  205. 'ol-useShareJsHash': boolean
  206. 'ol-usedLatex': 'never' | 'occasionally' | 'often' | undefined
  207. 'ol-user': User
  208. 'ol-userAffiliations': Affiliation[]
  209. 'ol-userCanExtendTrial': boolean
  210. 'ol-userCanNotStartRequestedTrial': boolean
  211. 'ol-userEmails': UserEmailData[]
  212. 'ol-userSettings': UserSettings
  213. 'ol-user_id': string | undefined
  214. 'ol-users': ManagedUser[]
  215. 'ol-usersBestSubscription': ProjectDashboardSubscription | undefined
  216. 'ol-usersEmail': string | undefined
  217. 'ol-validationStatus': ValidationStatus
  218. 'ol-websiteRedesignPlansVariant': 'default' | 'light-design' | 'new-design'
  219. 'ol-wikiEnabled': boolean
  220. 'ol-writefullCssUrl': string
  221. 'ol-writefullEnabled': boolean
  222. 'ol-writefullJsUrl': string
  223. 'ol-wsUrl': string
  224. }
  225. // cache for parsed values
  226. window.metaAttributesCache = window.metaAttributesCache || new Map()
  227. export default function getMeta<T extends keyof Meta>(name: T): Meta[T] {
  228. if (window.metaAttributesCache.has(name)) {
  229. return window.metaAttributesCache.get(name)
  230. }
  231. const element = document.head.querySelector(
  232. `meta[name="${name}"]`
  233. ) as HTMLMetaElement
  234. if (!element) {
  235. return undefined!
  236. }
  237. const plainTextValue = element.content
  238. let value
  239. switch (element.dataset.type) {
  240. case 'boolean':
  241. // in pug: content=false -> no content field
  242. // in pug: content=true -> empty content field
  243. value = element.hasAttribute('content')
  244. break
  245. case 'json':
  246. if (!plainTextValue) {
  247. // JSON.parse('') throws
  248. value = undefined
  249. } else {
  250. value = JSON.parse(plainTextValue)
  251. }
  252. break
  253. default:
  254. value = plainTextValue
  255. }
  256. window.metaAttributesCache.set(name, value)
  257. return value
  258. }