meta.ts 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412
  1. import { User, Features, FeatureUsage } 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 { Subscription as AdminSubscription } from '../../../types/admin/subscription'
  66. import { AdminCapability } from '../../../types/admin-capabilities'
  67. import { AlgoliaConfig } from '../../../modules/algolia-search/frontend/js/types'
  68. import { WritefullPublicEnv } from '@wf/domain/writefull-public-env'
  69. import { UserNotificationPreferences } from '../../../types/notifications'
  70. import { SharingPermissions } from '../../../modules/sharing-permissions/app/src/types'
  71. import { FullHistoryFailure } from '@ol-types/history/projectHistory'
  72. export interface Meta {
  73. 'ol-ExposedSettings': ExposedSettings
  74. 'ol-addonPrices': Record<
  75. string,
  76. { annual: string; monthly: string; annualDividedByTwelve: string }
  77. >
  78. 'ol-adminCapabilities': AdminCapability[]
  79. 'ol-adminSubscription': AdminSubscription
  80. 'ol-adminUserExists': boolean
  81. 'ol-aiAssistViaWritefullSource': string
  82. 'ol-algolia': AlgoliaConfig | undefined
  83. 'ol-allInReconfirmNotificationPeriods': UserEmailData[]
  84. 'ol-allowedExperiments': string[]
  85. 'ol-anonymous': boolean
  86. 'ol-baseAssetPath': string
  87. 'ol-brandVariation': Record<string, any>
  88. 'ol-canUseAddSeatsFeature': boolean
  89. 'ol-canUseClsiCache': boolean
  90. 'ol-canUseFlexibleLicensing': boolean
  91. // dynamic keys based on permissions
  92. 'ol-cannot-add-secondary-email': boolean
  93. 'ol-cannot-change-password': boolean
  94. 'ol-cannot-delete-own-account': boolean
  95. 'ol-cannot-join-subscription': boolean
  96. 'ol-cannot-leave-group-subscription': boolean
  97. 'ol-cannot-link-google-sso': boolean
  98. 'ol-cannot-link-other-third-party-sso': boolean
  99. 'ol-cannot-reactivate-subscription': boolean
  100. 'ol-cannot-use-ai': boolean
  101. 'ol-capabilities': Array<'dropbox' | 'chat' | 'use-ai' | 'link-sharing'>
  102. 'ol-compileSettings': {
  103. compileTimeout: number
  104. }
  105. 'ol-compilesUserContentDomain': string
  106. 'ol-countryCode': PricingFormState['country']
  107. 'ol-couponCode': PricingFormState['coupon']
  108. 'ol-createNewUserViaDomainCapture': boolean
  109. 'ol-createdAt': Date
  110. 'ol-csrfToken': string
  111. 'ol-currentInstitutionsWithLicence': Institution[]
  112. 'ol-currentManagedUserAdminEmail': string
  113. 'ol-currentUrl': string
  114. 'ol-customerIoEnabled': boolean
  115. 'ol-debugPdfDetach': boolean
  116. 'ol-detachRole': 'detached' | 'detacher' | ''
  117. 'ol-dictionariesRoot': 'string'
  118. 'ol-domainCaptureEnabled': boolean | undefined
  119. 'ol-domainCaptureTestURL': string | undefined
  120. 'ol-domainVerificationUIEnabled': boolean
  121. 'ol-dropbox': { error: boolean; registered: boolean }
  122. 'ol-editorThemes': { name: string; dark: boolean }[]
  123. 'ol-email': string
  124. 'ol-emailAddressLimit': number
  125. 'ol-error': { name: string } | undefined
  126. 'ol-errorType': string | undefined
  127. 'ol-expired': boolean
  128. 'ol-featureUsage': FeatureUsage
  129. 'ol-features': Features
  130. 'ol-footer': FooterMetadata
  131. 'ol-galleryTagName': string
  132. 'ol-gitBridgeEnabled': boolean
  133. 'ol-gitBridgePublicBaseUrl': string
  134. 'ol-github': { enabled: boolean; error: boolean }
  135. 'ol-groupAuditLogs': []
  136. 'ol-groupDomains': []
  137. 'ol-groupId': string
  138. 'ol-groupName': string
  139. 'ol-groupPlans': GroupPlans
  140. 'ol-groupPlansData': GroupPlansData
  141. 'ol-groupPolicy': GroupPolicy
  142. 'ol-groupSSOActive': boolean
  143. 'ol-groupSSOConfig'?: SSOConfig
  144. 'ol-groupSSOTestResult': GroupSSOTestResult
  145. 'ol-groupSettingsAdvertisedFor': string[]
  146. 'ol-groupSettingsEnabledFor': string[]
  147. 'ol-groupSize': number
  148. 'ol-groupSsoSetupSuccess': boolean
  149. 'ol-groupSubscriptionsPendingEnrollment': PendingGroupSubscriptionEnrollment[]
  150. 'ol-groupsAndEnterpriseBannerVariant': GroupsAndEnterpriseBannerVariant
  151. 'ol-hasAiAssistViaWritefull': boolean
  152. 'ol-hasAiFreeTier': boolean
  153. 'ol-hasGroupSSOFeature': boolean
  154. 'ol-hasIndividualPaidSubscription': boolean
  155. 'ol-hasManagedUsersFeature': boolean
  156. 'ol-hasModifyGroupManagerAccess': boolean
  157. 'ol-hasPassword': boolean
  158. 'ol-hasSplitTestWriteAccess': boolean
  159. 'ol-hasSubscription': boolean
  160. 'ol-hasTrackChangesFeature': boolean
  161. 'ol-hasUnlimitedAi': boolean
  162. 'ol-hasWriteAccess': boolean
  163. 'ol-hideLinkingWidgets': boolean // CI only
  164. 'ol-historyBlobStats': {
  165. projectId: string
  166. textBlobsBytes: number
  167. binaryBlobsBytes: number
  168. totalBytes: number
  169. nTextBlobs: number
  170. nBinaryBlobs: number
  171. owned?: boolean
  172. }[]
  173. 'ol-i18n': { currentLangCode: string }
  174. 'ol-imageNames': ImageName[]
  175. 'ol-inactiveTutorials': string[]
  176. 'ol-institutionEmail': string | undefined
  177. 'ol-institutionEmailNonCanonical': string | undefined
  178. 'ol-institutionLinked': InstitutionLink | undefined
  179. 'ol-inviteToken': string
  180. 'ol-inviterName': string
  181. 'ol-isCollectionMethodManual': boolean
  182. 'ol-isExternalAuthenticationSystemUsed': boolean
  183. 'ol-isManagedAccount': boolean
  184. 'ol-isManagedGroupAdmin': boolean
  185. 'ol-isProfessional': boolean
  186. 'ol-isRegisteredViaGoogle': boolean
  187. 'ol-isRestrictedTokenMember': boolean
  188. 'ol-isSaas': boolean
  189. 'ol-isUserGroupManager': boolean
  190. 'ol-itm_campaign': string
  191. 'ol-itm_content': string
  192. 'ol-itm_referrer': string
  193. 'ol-joinedGroupName': string
  194. 'ol-labs': boolean
  195. 'ol-labsExperiments': Array<{
  196. name: string
  197. title: string
  198. description: string
  199. icon: string
  200. surveyLink: string
  201. isFull: boolean
  202. optedIn: boolean
  203. }>
  204. 'ol-languages': SpellCheckLanguage[]
  205. 'ol-learnedWords': string[]
  206. 'ol-legacyEditorThemes': { name: string; dark: boolean }[]
  207. 'ol-licenseQuantity'?: number
  208. 'ol-loadingText': string
  209. 'ol-localIndividualPlans': LocalIndividualPlans
  210. 'ol-managedGroupSubscriptions': ManagedGroupSubscription[]
  211. 'ol-managedInstitutions': ManagedInstitution[]
  212. 'ol-managedPublishers': Publisher[]
  213. 'ol-managedUsersActive': boolean
  214. 'ol-managedUsersEnabled': boolean
  215. 'ol-managers': MinimalUser[]
  216. 'ol-mathJaxPath': string
  217. 'ol-maxDocLength': number
  218. 'ol-maxReconnectGracefullyIntervalMs': number
  219. 'ol-memberGroupSubscriptions': MemberGroupSubscription[]
  220. 'ol-memberOfSSOEnabledGroups': GroupSSOLinkingStatus[]
  221. 'ol-members': MinimalUser[]
  222. 'ol-multiple-group-subscriptions': Array<
  223. Pick<GroupSubscription, 'teamName'> & { id: string; email: string }
  224. >
  225. 'ol-navbar': DefaultNavbarMetadata
  226. 'ol-newsletter-subscribed': boolean
  227. 'ol-no-single-dollar': boolean
  228. 'ol-notifications': NotificationType[]
  229. 'ol-notificationsInstitution': InstitutionType[]
  230. 'ol-oauthProviders': OAuthProviders
  231. 'ol-odcData': OnboardingFormData
  232. 'ol-otMigrationStage': number
  233. 'ol-overallThemes': OverallThemeMeta[]
  234. 'ol-ownerIsManaged': boolean
  235. 'ol-pages': number
  236. 'ol-passwordStrengthOptions': PasswordStrengthOptions
  237. 'ol-paywallPlans': { [key: string]: string }
  238. 'ol-personalAccessTokens': AccessToken[] | undefined
  239. 'ol-plan': Plan
  240. 'ol-planCode': string
  241. 'ol-planCodesChangingAtTermEnd': string[] | undefined
  242. 'ol-plans': Plan[]
  243. 'ol-portalTemplates': PortalTemplate[]
  244. 'ol-postCheckoutRedirect': string
  245. 'ol-postUrl': string
  246. 'ol-prefetchedProjectsBlob': GetProjectsResponseBody | undefined
  247. 'ol-preventCompileOnLoad'?: boolean
  248. 'ol-primaryEmail': { email: string; confirmed: boolean }
  249. 'ol-project': any // TODO
  250. 'ol-projectEntityCounts': { files: number; docs: number }
  251. 'ol-projectHistoryFailures': FullHistoryFailure[]
  252. 'ol-projectName': string
  253. 'ol-projectSyncSuccessMessage': string
  254. 'ol-projectTags': Tag[]
  255. 'ol-project_id': string
  256. 'ol-purchaseReferrer': string
  257. 'ol-recommendedCurrency': CurrencyCode
  258. 'ol-reconfirmationRemoveEmail': string
  259. 'ol-reconfirmedViaSAML': string
  260. 'ol-recurlyAccount':
  261. | {
  262. code: string
  263. error?: undefined
  264. }
  265. | {
  266. error: boolean
  267. code?: undefined
  268. }
  269. | undefined
  270. 'ol-recurlyApiKey': string
  271. 'ol-recurlySubdomain': string
  272. 'ol-ro-mirror-on-client-no-local-storage': boolean
  273. 'ol-samlError': SAMLError | undefined
  274. 'ol-script-log': ScriptLogType
  275. 'ol-script-logs': ScriptLogType[]
  276. 'ol-settingsGroupSSO': { enabled: boolean } | undefined
  277. 'ol-settingsPlans': Plan[]
  278. 'ol-sharingPermissions': SharingPermissions
  279. 'ol-shouldAllowEditingDetails': boolean
  280. 'ol-shouldLoadHotjar': boolean
  281. 'ol-showAiFeatures': boolean
  282. 'ol-showCouponField': boolean
  283. 'ol-showGroupDiscount': boolean
  284. 'ol-showGroupsAndEnterpriseBanner': boolean
  285. 'ol-showInrGeoBanner': boolean
  286. 'ol-showLATAMBanner': boolean
  287. 'ol-showSupport': boolean
  288. 'ol-showSymbolPalette': boolean
  289. 'ol-showTemplatesServerPro': boolean
  290. 'ol-showUSGovBanner': boolean
  291. 'ol-showUpgradePrompt': boolean
  292. 'ol-splitTestInfo': { [name: string]: SplitTestInfo }
  293. 'ol-splitTestName': string
  294. 'ol-splitTestVariants': { [name: string]: string }
  295. 'ol-ssoDisabled': boolean
  296. 'ol-ssoErrorMessage': string
  297. 'ol-ssoInitPath': string
  298. 'ol-standardPlanPricing': {
  299. monthly?: string
  300. annual?: string
  301. monthlyTimesTwelve?: string
  302. }
  303. 'ol-stripeCustomerData': Array<{
  304. customerId: string
  305. subscriptionId: string
  306. subscriptionState: string | null
  307. paymentProviderService: StripePaymentProviderService | null
  308. managementUrl: string
  309. segment?: string | null
  310. error?: string
  311. }>
  312. 'ol-stripePublicKeyUK': string
  313. 'ol-stripePublicKeyUS': string
  314. 'ol-subscription': any // TODO: mixed types, split into two fields
  315. 'ol-subscriptionChangePreview': SubscriptionChangePreview
  316. 'ol-subscriptionCreationPreview': SubscriptionCreationPreview
  317. 'ol-subscriptionFeatures': {
  318. managedUsers?: boolean
  319. groupSSO?: boolean
  320. domainCapture?: boolean
  321. }
  322. 'ol-subscriptionId': string
  323. 'ol-subscriptionPaymentErrorCode': string | null
  324. 'ol-suggestedLanguage': SuggestedLanguage | undefined
  325. 'ol-survey': Survey | undefined
  326. 'ol-symbolPaletteAvailable': boolean
  327. 'ol-tags': Tag[]
  328. 'ol-teamInvites': TeamInvite[]
  329. 'ol-thirdPartyIds': ThirdPartyIds
  330. 'ol-totalLicenses': number
  331. 'ol-translationIoNotLoaded': string
  332. 'ol-translationLoadErrorMessage': string
  333. 'ol-translationMaintenance': string
  334. 'ol-translationUnableToJoin': string
  335. 'ol-trialDisabledReason': string | undefined
  336. 'ol-usGovBannerVariant': USGovBannerVariant
  337. 'ol-useShareJsHash': boolean
  338. 'ol-user': User
  339. 'ol-userAffiliations': Affiliation[]
  340. 'ol-userCanExtendTrial': boolean
  341. 'ol-userCanNotStartRequestedTrial': boolean
  342. 'ol-userEmails': UserEmailData[]
  343. 'ol-userNotificationPreferences': UserNotificationPreferences
  344. 'ol-userSettings': UserSettings
  345. 'ol-user_id': string | undefined
  346. 'ol-users': ManagedUser[]
  347. 'ol-usersBestSubscription': ProjectDashboardSubscription | undefined
  348. 'ol-usersEmail': string | undefined
  349. 'ol-usersSubscription': { personal: boolean; group: boolean }
  350. 'ol-validationStatus': ValidationStatus
  351. 'ol-viaDomainCapture': boolean
  352. 'ol-wikiEnabled': boolean
  353. 'ol-writefullEnabled': boolean
  354. 'ol-writefullEnv': WritefullPublicEnv
  355. 'ol-wsUrl': string
  356. }
  357. type DeepPartial<T> =
  358. T extends Record<string, any> ? { [P in keyof T]?: DeepPartial<T[P]> } : T
  359. export type PartialMeta = DeepPartial<Meta>
  360. export type MetaAttributesCache<
  361. K extends keyof PartialMeta = keyof PartialMeta,
  362. > = Map<K, PartialMeta[K]>
  363. export type MetaTag = {
  364. [K in keyof Meta]: {
  365. name: K
  366. value: Meta[K]
  367. }
  368. }[keyof Meta]
  369. // cache for parsed values
  370. window.metaAttributesCache = window.metaAttributesCache || new Map()
  371. export default function getMeta<T extends keyof Meta>(name: T): Meta[T] {
  372. if (window.metaAttributesCache.has(name)) {
  373. return window.metaAttributesCache.get(name)
  374. }
  375. const element = document.head.querySelector(
  376. `meta[name="${name}"]`
  377. ) as HTMLMetaElement
  378. if (!element) {
  379. return undefined!
  380. }
  381. const plainTextValue = element.content
  382. let value
  383. switch (element.dataset.type) {
  384. case 'boolean':
  385. // in pug: content=false -> no content field
  386. // in pug: content=true -> empty content field
  387. value = element.hasAttribute('content')
  388. break
  389. case 'json':
  390. case 'number':
  391. if (!plainTextValue) {
  392. // JSON.parse('') throws
  393. value = undefined
  394. } else {
  395. value = JSON.parse(plainTextValue)
  396. }
  397. break
  398. default:
  399. value = plainTextValue
  400. }
  401. window.metaAttributesCache.set(name, value)
  402. return value
  403. }