meta.ts 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397
  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-dropbox': { error: boolean; registered: boolean }
  120. 'ol-editorThemes': { name: string; dark: boolean }[]
  121. 'ol-email': string
  122. 'ol-emailAddressLimit': number
  123. 'ol-error': { name: string } | undefined
  124. 'ol-errorType': string | undefined
  125. 'ol-expired': boolean
  126. 'ol-features': Features
  127. 'ol-footer': FooterMetadata
  128. 'ol-fromPlansPage': boolean
  129. 'ol-galleryTagName': string
  130. 'ol-gitBridgeEnabled': boolean
  131. 'ol-gitBridgePublicBaseUrl': string
  132. 'ol-github': { enabled: boolean; error: boolean }
  133. 'ol-groupAuditLogs': []
  134. 'ol-groupId': string
  135. 'ol-groupName': string
  136. 'ol-groupPlans': GroupPlans
  137. 'ol-groupPlansData': GroupPlansData
  138. 'ol-groupPolicy': GroupPolicy
  139. 'ol-groupSSOActive': boolean
  140. 'ol-groupSSOConfig'?: SSOConfig
  141. 'ol-groupSSOTestResult': GroupSSOTestResult
  142. 'ol-groupSettingsAdvertisedFor': string[]
  143. 'ol-groupSettingsEnabledFor': string[]
  144. 'ol-groupSize': number
  145. 'ol-groupSsoSetupSuccess': boolean
  146. 'ol-groupSubscriptionsPendingEnrollment': PendingGroupSubscriptionEnrollment[]
  147. 'ol-groupsAndEnterpriseBannerVariant': GroupsAndEnterpriseBannerVariant
  148. 'ol-hasAiAssistViaWritefull': boolean
  149. 'ol-hasGroupSSOFeature': boolean
  150. 'ol-hasIndividualPaidSubscription': boolean
  151. 'ol-hasManagedUsersFeature': boolean
  152. 'ol-hasModifyGroupManagerAccess': boolean
  153. 'ol-hasPassword': boolean
  154. 'ol-hasSplitTestWriteAccess': boolean
  155. 'ol-hasSubscription': boolean
  156. 'ol-hasTrackChangesFeature': boolean
  157. 'ol-hasWriteAccess': boolean
  158. 'ol-hideLinkingWidgets': boolean // CI only
  159. 'ol-historyBlobStats': {
  160. projectId: string
  161. textBlobsBytes: number
  162. binaryBlobsBytes: number
  163. totalBytes: number
  164. nTextBlobs: number
  165. nBinaryBlobs: number
  166. owned?: boolean
  167. }[]
  168. 'ol-i18n': { currentLangCode: string }
  169. 'ol-imageNames': ImageName[]
  170. 'ol-inactiveTutorials': string[]
  171. 'ol-institutionEmail': string | undefined
  172. 'ol-institutionEmailNonCanonical': string | undefined
  173. 'ol-institutionLinked': InstitutionLink | undefined
  174. 'ol-inviteToken': string
  175. 'ol-inviterName': string
  176. 'ol-isCollectionMethodManual': boolean
  177. 'ol-isExternalAuthenticationSystemUsed': boolean
  178. 'ol-isManagedAccount': boolean
  179. 'ol-isProfessional': boolean
  180. 'ol-isRegisteredViaGoogle': boolean
  181. 'ol-isRestrictedTokenMember': boolean
  182. 'ol-isSaas': boolean
  183. 'ol-isUserGroupManager': boolean
  184. 'ol-itm_campaign': string
  185. 'ol-itm_content': string
  186. 'ol-itm_referrer': string
  187. 'ol-joinedGroupName': string
  188. 'ol-labs': boolean
  189. 'ol-labsExperiments': ActiveExperiment[] | undefined
  190. 'ol-languages': SpellCheckLanguage[]
  191. 'ol-learnedWords': string[]
  192. 'ol-legacyEditorThemes': { name: string; dark: boolean }[]
  193. 'ol-licenseQuantity'?: number
  194. 'ol-loadingText': string
  195. 'ol-localIndividualPlans': LocalIndividualPlans
  196. 'ol-managedGroupSubscriptions': ManagedGroupSubscription[]
  197. 'ol-managedInstitutions': ManagedInstitution[]
  198. 'ol-managedPublishers': Publisher[]
  199. 'ol-managedUsersActive': boolean
  200. 'ol-managedUsersEnabled': boolean
  201. 'ol-managers': MinimalUser[]
  202. 'ol-mathJaxPath': string
  203. 'ol-maxDocLength': number
  204. 'ol-maxReconnectGracefullyIntervalMs': number
  205. 'ol-memberGroupSubscriptions': MemberGroupSubscription[]
  206. 'ol-memberOfSSOEnabledGroups': GroupSSOLinkingStatus[]
  207. 'ol-members': MinimalUser[]
  208. 'ol-multiple-group-subscriptions': Array<
  209. Pick<GroupSubscription, 'teamName'> & { id: string; email: string }
  210. >
  211. 'ol-navbar': DefaultNavbarMetadata
  212. 'ol-newsletter-subscribed': boolean
  213. 'ol-no-single-dollar': boolean
  214. 'ol-notifications': NotificationType[]
  215. 'ol-notificationsInstitution': InstitutionType[]
  216. 'ol-oauthProviders': OAuthProviders
  217. 'ol-odcData': OnboardingFormData
  218. 'ol-onAiFreeTrial': boolean
  219. 'ol-otMigrationStage': number
  220. 'ol-overallThemes': OverallThemeMeta[]
  221. 'ol-ownerIsManaged': boolean
  222. 'ol-pages': number
  223. 'ol-passwordStrengthOptions': PasswordStrengthOptions
  224. 'ol-paywallPlans': { [key: string]: string }
  225. 'ol-personalAccessTokens': AccessToken[] | undefined
  226. 'ol-plan': Plan
  227. 'ol-planCode': string
  228. 'ol-planCodesChangingAtTermEnd': string[] | undefined
  229. 'ol-plans': Plan[]
  230. 'ol-portalTemplates': PortalTemplate[]
  231. 'ol-postCheckoutRedirect': string
  232. 'ol-postUrl': string
  233. 'ol-prefetchedProjectsBlob': GetProjectsResponseBody | undefined
  234. 'ol-preventCompileOnLoad'?: boolean
  235. 'ol-primaryEmail': { email: string; confirmed: boolean }
  236. 'ol-project': any // TODO
  237. 'ol-projectEntityCounts': { files: number; docs: number }
  238. 'ol-projectName': string
  239. 'ol-projectSyncSuccessMessage': string
  240. 'ol-projectTags': Tag[]
  241. 'ol-project_id': string
  242. 'ol-purchaseReferrer': string
  243. 'ol-recommendedCurrency': CurrencyCode
  244. 'ol-reconfirmationRemoveEmail': string
  245. 'ol-reconfirmedViaSAML': string
  246. 'ol-recurlyAccount':
  247. | {
  248. code: string
  249. error?: undefined
  250. }
  251. | {
  252. error: boolean
  253. code?: undefined
  254. }
  255. | undefined
  256. 'ol-recurlyApiKey': string
  257. 'ol-recurlySubdomain': string
  258. 'ol-ro-mirror-on-client-no-local-storage': boolean
  259. 'ol-samlError': SAMLError | undefined
  260. 'ol-script-log': ScriptLogType
  261. 'ol-script-logs': ScriptLogType[]
  262. 'ol-settingsGroupSSO': { enabled: boolean } | undefined
  263. 'ol-settingsPlans': Plan[]
  264. 'ol-shouldAllowEditingDetails': boolean
  265. 'ol-shouldLoadHotjar': boolean
  266. 'ol-showAiFeatures': boolean
  267. 'ol-showCouponField': boolean
  268. 'ol-showGroupDiscount': boolean
  269. 'ol-showGroupsAndEnterpriseBanner': boolean
  270. 'ol-showInrGeoBanner': boolean
  271. 'ol-showLATAMBanner': boolean
  272. 'ol-showSupport': boolean
  273. 'ol-showSymbolPalette': boolean
  274. 'ol-showTemplatesServerPro': boolean
  275. 'ol-showUSGovBanner': boolean
  276. 'ol-showUpgradePrompt': boolean
  277. 'ol-splitTestInfo': { [name: string]: SplitTestInfo }
  278. 'ol-splitTestName': string
  279. 'ol-splitTestVariants': { [name: string]: string }
  280. 'ol-ssoDisabled': boolean
  281. 'ol-ssoErrorMessage': string
  282. 'ol-ssoInitPath': string
  283. 'ol-standardPlanPricing': {
  284. monthly?: string
  285. annual?: string
  286. monthlyTimesTwelve?: string
  287. }
  288. 'ol-stripeCustomerData': Array<{
  289. customerId: string
  290. subscriptionId: string
  291. subscriptionState: string | null
  292. paymentProviderService: StripePaymentProviderService | null
  293. managementUrl: string
  294. segment?: string | null
  295. error?: string
  296. }>
  297. 'ol-stripePublicKeyUK': string
  298. 'ol-stripePublicKeyUS': string
  299. 'ol-subscription': any // TODO: mixed types, split into two fields
  300. 'ol-subscriptionChangePreview': SubscriptionChangePreview
  301. 'ol-subscriptionCreationPreview': SubscriptionCreationPreview
  302. 'ol-subscriptionFeatures': {
  303. managedUsers?: boolean
  304. groupSSO?: boolean
  305. domainCapture?: boolean
  306. }
  307. 'ol-subscriptionId': string
  308. 'ol-subscriptionPaymentErrorCode': string | null
  309. 'ol-suggestedLanguage': SuggestedLanguage | undefined
  310. 'ol-survey': Survey | undefined
  311. 'ol-symbolPaletteAvailable': boolean
  312. 'ol-tags': Tag[]
  313. 'ol-teamInvites': TeamInvite[]
  314. 'ol-thirdPartyIds': ThirdPartyIds
  315. 'ol-totalLicenses': number
  316. 'ol-translationIoNotLoaded': string
  317. 'ol-translationLoadErrorMessage': string
  318. 'ol-translationMaintenance': string
  319. 'ol-translationUnableToJoin': string
  320. 'ol-trialDisabledReason': string | undefined
  321. 'ol-usGovBannerVariant': USGovBannerVariant
  322. 'ol-useShareJsHash': boolean
  323. 'ol-user': User
  324. 'ol-userAffiliations': Affiliation[]
  325. 'ol-userCanExtendTrial': boolean
  326. 'ol-userCanNotStartRequestedTrial': boolean
  327. 'ol-userEmails': UserEmailData[]
  328. 'ol-userNotificationPreferences': UserNotificationPreferences
  329. 'ol-userSettings': UserSettings
  330. 'ol-user_id': string | undefined
  331. 'ol-users': ManagedUser[]
  332. 'ol-usersBestSubscription': ProjectDashboardSubscription | undefined
  333. 'ol-usersEmail': string | undefined
  334. 'ol-usersSubscription': { personal: boolean; group: boolean }
  335. 'ol-validationStatus': ValidationStatus
  336. 'ol-viaDomainCapture': boolean
  337. 'ol-wikiEnabled': boolean
  338. 'ol-writefullEnabled': boolean
  339. 'ol-writefullEnv': WritefullPublicEnv
  340. 'ol-wsUrl': string
  341. }
  342. type DeepPartial<T> =
  343. T extends Record<string, any> ? { [P in keyof T]?: DeepPartial<T[P]> } : T
  344. export type PartialMeta = DeepPartial<Meta>
  345. export type MetaAttributesCache<
  346. K extends keyof PartialMeta = keyof PartialMeta,
  347. > = Map<K, PartialMeta[K]>
  348. export type MetaTag = {
  349. [K in keyof Meta]: {
  350. name: K
  351. value: Meta[K]
  352. }
  353. }[keyof Meta]
  354. // cache for parsed values
  355. window.metaAttributesCache = window.metaAttributesCache || new Map()
  356. export default function getMeta<T extends keyof Meta>(name: T): Meta[T] {
  357. if (window.metaAttributesCache.has(name)) {
  358. return window.metaAttributesCache.get(name)
  359. }
  360. const element = document.head.querySelector(
  361. `meta[name="${name}"]`
  362. ) as HTMLMetaElement
  363. if (!element) {
  364. return undefined!
  365. }
  366. const plainTextValue = element.content
  367. let value
  368. switch (element.dataset.type) {
  369. case 'boolean':
  370. // in pug: content=false -> no content field
  371. // in pug: content=true -> empty content field
  372. value = element.hasAttribute('content')
  373. break
  374. case 'json':
  375. case 'number':
  376. if (!plainTextValue) {
  377. // JSON.parse('') throws
  378. value = undefined
  379. } else {
  380. value = JSON.parse(plainTextValue)
  381. }
  382. break
  383. default:
  384. value = plainTextValue
  385. }
  386. window.metaAttributesCache.set(name, value)
  387. return value
  388. }