meta.ts 14 KB

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