meta.ts 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399
  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 { ActiveExperiment } from './labs-utils'
  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. 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': ActiveExperiment[] | undefined
  192. 'ol-languages': SpellCheckLanguage[]
  193. 'ol-learnedWords': string[]
  194. 'ol-legacyEditorThemes': { name: string; dark: boolean }[]
  195. 'ol-licenseQuantity'?: number
  196. 'ol-loadingText': string
  197. 'ol-localIndividualPlans': LocalIndividualPlans
  198. 'ol-managedGroupSubscriptions': ManagedGroupSubscription[]
  199. 'ol-managedInstitutions': ManagedInstitution[]
  200. 'ol-managedPublishers': Publisher[]
  201. 'ol-managedUsersActive': boolean
  202. 'ol-managedUsersEnabled': boolean
  203. 'ol-managers': MinimalUser[]
  204. 'ol-mathJaxPath': string
  205. 'ol-maxDocLength': number
  206. 'ol-maxReconnectGracefullyIntervalMs': number
  207. 'ol-memberGroupSubscriptions': MemberGroupSubscription[]
  208. 'ol-memberOfSSOEnabledGroups': GroupSSOLinkingStatus[]
  209. 'ol-members': MinimalUser[]
  210. 'ol-multiple-group-subscriptions': Array<
  211. Pick<GroupSubscription, 'teamName'> & { id: string; email: string }
  212. >
  213. 'ol-navbar': DefaultNavbarMetadata
  214. 'ol-newsletter-subscribed': boolean
  215. 'ol-no-single-dollar': boolean
  216. 'ol-notifications': NotificationType[]
  217. 'ol-notificationsInstitution': InstitutionType[]
  218. 'ol-oauthProviders': OAuthProviders
  219. 'ol-odcData': OnboardingFormData
  220. 'ol-onAiFreeTrial': boolean
  221. 'ol-otMigrationStage': number
  222. 'ol-overallThemes': OverallThemeMeta[]
  223. 'ol-ownerIsManaged': boolean
  224. 'ol-pages': number
  225. 'ol-passwordStrengthOptions': PasswordStrengthOptions
  226. 'ol-paywallPlans': { [key: string]: string }
  227. 'ol-personalAccessTokens': AccessToken[] | undefined
  228. 'ol-plan': Plan
  229. 'ol-planCode': string
  230. 'ol-planCodesChangingAtTermEnd': string[] | undefined
  231. 'ol-plans': Plan[]
  232. 'ol-portalTemplates': PortalTemplate[]
  233. 'ol-postCheckoutRedirect': string
  234. 'ol-postUrl': string
  235. 'ol-prefetchedProjectsBlob': GetProjectsResponseBody | undefined
  236. 'ol-preventCompileOnLoad'?: boolean
  237. 'ol-primaryEmail': { email: string; confirmed: boolean }
  238. 'ol-project': any // TODO
  239. 'ol-projectEntityCounts': { files: number; docs: number }
  240. 'ol-projectName': string
  241. 'ol-projectSyncSuccessMessage': string
  242. 'ol-projectTags': Tag[]
  243. 'ol-project_id': string
  244. 'ol-purchaseReferrer': string
  245. 'ol-recommendedCurrency': CurrencyCode
  246. 'ol-reconfirmationRemoveEmail': string
  247. 'ol-reconfirmedViaSAML': string
  248. 'ol-recurlyAccount':
  249. | {
  250. code: string
  251. error?: undefined
  252. }
  253. | {
  254. error: boolean
  255. code?: undefined
  256. }
  257. | undefined
  258. 'ol-recurlyApiKey': string
  259. 'ol-recurlySubdomain': string
  260. 'ol-ro-mirror-on-client-no-local-storage': boolean
  261. 'ol-samlError': SAMLError | undefined
  262. 'ol-script-log': ScriptLogType
  263. 'ol-script-logs': ScriptLogType[]
  264. 'ol-settingsGroupSSO': { enabled: boolean } | undefined
  265. 'ol-settingsPlans': Plan[]
  266. 'ol-shouldAllowEditingDetails': boolean
  267. 'ol-shouldLoadHotjar': boolean
  268. 'ol-showAiFeatures': boolean
  269. 'ol-showCouponField': boolean
  270. 'ol-showGroupDiscount': boolean
  271. 'ol-showGroupsAndEnterpriseBanner': boolean
  272. 'ol-showInrGeoBanner': boolean
  273. 'ol-showLATAMBanner': boolean
  274. 'ol-showSupport': boolean
  275. 'ol-showSymbolPalette': boolean
  276. 'ol-showTemplatesServerPro': boolean
  277. 'ol-showUSGovBanner': boolean
  278. 'ol-showUpgradePrompt': boolean
  279. 'ol-splitTestInfo': { [name: string]: SplitTestInfo }
  280. 'ol-splitTestName': string
  281. 'ol-splitTestVariants': { [name: string]: string }
  282. 'ol-ssoDisabled': boolean
  283. 'ol-ssoErrorMessage': string
  284. 'ol-ssoInitPath': string
  285. 'ol-standardPlanPricing': {
  286. monthly?: string
  287. annual?: string
  288. monthlyTimesTwelve?: string
  289. }
  290. 'ol-stripeCustomerData': Array<{
  291. customerId: string
  292. subscriptionId: string
  293. subscriptionState: string | null
  294. paymentProviderService: StripePaymentProviderService | null
  295. managementUrl: string
  296. segment?: string | null
  297. error?: string
  298. }>
  299. 'ol-stripePublicKeyUK': string
  300. 'ol-stripePublicKeyUS': string
  301. 'ol-subscription': any // TODO: mixed types, split into two fields
  302. 'ol-subscriptionChangePreview': SubscriptionChangePreview
  303. 'ol-subscriptionCreationPreview': SubscriptionCreationPreview
  304. 'ol-subscriptionFeatures': {
  305. managedUsers?: boolean
  306. groupSSO?: boolean
  307. domainCapture?: boolean
  308. }
  309. 'ol-subscriptionId': string
  310. 'ol-subscriptionPaymentErrorCode': string | null
  311. 'ol-suggestedLanguage': SuggestedLanguage | undefined
  312. 'ol-survey': Survey | undefined
  313. 'ol-symbolPaletteAvailable': boolean
  314. 'ol-tags': Tag[]
  315. 'ol-teamInvites': TeamInvite[]
  316. 'ol-thirdPartyIds': ThirdPartyIds
  317. 'ol-totalLicenses': number
  318. 'ol-translationIoNotLoaded': string
  319. 'ol-translationLoadErrorMessage': string
  320. 'ol-translationMaintenance': string
  321. 'ol-translationUnableToJoin': string
  322. 'ol-trialDisabledReason': string | undefined
  323. 'ol-usGovBannerVariant': USGovBannerVariant
  324. 'ol-useShareJsHash': boolean
  325. 'ol-user': User
  326. 'ol-userAffiliations': Affiliation[]
  327. 'ol-userCanExtendTrial': boolean
  328. 'ol-userCanNotStartRequestedTrial': boolean
  329. 'ol-userEmails': UserEmailData[]
  330. 'ol-userNotificationPreferences': UserNotificationPreferences
  331. 'ol-userSettings': UserSettings
  332. 'ol-user_id': string | undefined
  333. 'ol-users': ManagedUser[]
  334. 'ol-usersBestSubscription': ProjectDashboardSubscription | undefined
  335. 'ol-usersEmail': string | undefined
  336. 'ol-usersSubscription': { personal: boolean; group: boolean }
  337. 'ol-validationStatus': ValidationStatus
  338. 'ol-viaDomainCapture': boolean
  339. 'ol-wikiEnabled': boolean
  340. 'ol-writefullEnabled': boolean
  341. 'ol-writefullEnv': WritefullPublicEnv
  342. 'ol-wsUrl': string
  343. }
  344. type DeepPartial<T> =
  345. T extends Record<string, any> ? { [P in keyof T]?: DeepPartial<T[P]> } : T
  346. export type PartialMeta = DeepPartial<Meta>
  347. export type MetaAttributesCache<
  348. K extends keyof PartialMeta = keyof PartialMeta,
  349. > = Map<K, PartialMeta[K]>
  350. export type MetaTag = {
  351. [K in keyof Meta]: {
  352. name: K
  353. value: Meta[K]
  354. }
  355. }[keyof Meta]
  356. // cache for parsed values
  357. window.metaAttributesCache = window.metaAttributesCache || new Map()
  358. export default function getMeta<T extends keyof Meta>(name: T): Meta[T] {
  359. if (window.metaAttributesCache.has(name)) {
  360. return window.metaAttributesCache.get(name)
  361. }
  362. const element = document.head.querySelector(
  363. `meta[name="${name}"]`
  364. ) as HTMLMetaElement
  365. if (!element) {
  366. return undefined!
  367. }
  368. const plainTextValue = element.content
  369. let value
  370. switch (element.dataset.type) {
  371. case 'boolean':
  372. // in pug: content=false -> no content field
  373. // in pug: content=true -> empty content field
  374. value = element.hasAttribute('content')
  375. break
  376. case 'json':
  377. case 'number':
  378. if (!plainTextValue) {
  379. // JSON.parse('') throws
  380. value = undefined
  381. } else {
  382. value = JSON.parse(plainTextValue)
  383. }
  384. break
  385. default:
  386. value = plainTextValue
  387. }
  388. window.metaAttributesCache.set(name, value)
  389. return value
  390. }