diff --git a/services/web/app/src/Features/Authentication/AuthenticationController.mjs b/services/web/app/src/Features/Authentication/AuthenticationController.mjs index 62efb907b3..f698c2fd3e 100644 --- a/services/web/app/src/Features/Authentication/AuthenticationController.mjs +++ b/services/web/app/src/Features/Authentication/AuthenticationController.mjs @@ -24,7 +24,7 @@ import AdminAuthorizationHelper from '../Helpers/AdminAuthorizationHelper.mjs' import Modules from '../../infrastructure/Modules.js' import { expressify, promisify } from '@overleaf/promise-utils' import { handleAuthenticateErrors } from './AuthenticationErrors.js' -import EmailHelper from '../Helpers/EmailHelper.js' +import EmailHelper from '../Helpers/EmailHelper.mjs' const { hasAdminAccess } = AdminAuthorizationHelper diff --git a/services/web/app/src/Features/Authentication/AuthenticationManager.mjs b/services/web/app/src/Features/Authentication/AuthenticationManager.mjs index c4455b7f51..0d45c4eaa8 100644 --- a/services/web/app/src/Features/Authentication/AuthenticationManager.mjs +++ b/services/web/app/src/Features/Authentication/AuthenticationManager.mjs @@ -1,8 +1,8 @@ import Settings from '@overleaf/settings' -import { User } from '../../models/User.js' +import { User } from '../../models/User.mjs' import { db, ObjectId } from '../../infrastructure/mongodb.js' import bcrypt from 'bcrypt' -import EmailHelper from '../Helpers/EmailHelper.js' +import EmailHelper from '../Helpers/EmailHelper.mjs' import { InvalidEmailError, @@ -16,7 +16,7 @@ import { callbackify, callbackifyMultiResult } from '@overleaf/promise-utils' import HaveIBeenPwned from './HaveIBeenPwned.mjs' import UserAuditLogHandler from '../User/UserAuditLogHandler.mjs' import logger from '@overleaf/logger' -import DiffHelper from '../Helpers/DiffHelper.js' +import DiffHelper from '../Helpers/DiffHelper.mjs' import Metrics from '@overleaf/metrics' const BCRYPT_ROUNDS = Settings.security.bcryptRounds || 12 diff --git a/services/web/app/src/Features/Authorization/AuthorizationManager.mjs b/services/web/app/src/Features/Authorization/AuthorizationManager.mjs index 55ce69e738..7a9be587b9 100644 --- a/services/web/app/src/Features/Authorization/AuthorizationManager.mjs +++ b/services/web/app/src/Features/Authorization/AuthorizationManager.mjs @@ -4,7 +4,7 @@ import Features from '../../infrastructure/Features.js' import CollaboratorsGetter from '../Collaborators/CollaboratorsGetter.mjs' import CollaboratorsHandler from '../Collaborators/CollaboratorsHandler.mjs' import ProjectGetter from '../Project/ProjectGetter.mjs' -import { User } from '../../models/User.js' +import { User } from '../../models/User.mjs' import PrivilegeLevels from './PrivilegeLevels.js' import TokenAccessHandler from '../TokenAccess/TokenAccessHandler.mjs' import PublicAccessLevels from './PublicAccessLevels.mjs' diff --git a/services/web/app/src/Features/Captcha/CaptchaMiddleware.mjs b/services/web/app/src/Features/Captcha/CaptchaMiddleware.mjs index 42ae80d8cf..45e0902617 100644 --- a/services/web/app/src/Features/Captcha/CaptchaMiddleware.mjs +++ b/services/web/app/src/Features/Captcha/CaptchaMiddleware.mjs @@ -6,7 +6,7 @@ import OError from '@overleaf/o-error' import DeviceHistory from './DeviceHistory.mjs' import AuthenticationController from '../Authentication/AuthenticationController.mjs' import { expressify } from '@overleaf/promise-utils' -import EmailsHelper from '../Helpers/EmailHelper.js' +import EmailsHelper from '../Helpers/EmailHelper.mjs' function respondInvalidCaptcha(req, res) { res.status(400).json({ diff --git a/services/web/app/src/Features/Collaborators/CollaboratorsEmailHandler.mjs b/services/web/app/src/Features/Collaborators/CollaboratorsEmailHandler.mjs index 39b1bf12df..aa84824e76 100644 --- a/services/web/app/src/Features/Collaborators/CollaboratorsEmailHandler.mjs +++ b/services/web/app/src/Features/Collaborators/CollaboratorsEmailHandler.mjs @@ -1,5 +1,5 @@ import { callbackify } from 'node:util' -import { Project } from '../../models/Project.js' +import { Project } from '../../models/Project.mjs' import EmailHandler from '../Email/EmailHandler.mjs' import Settings from '@overleaf/settings' diff --git a/services/web/app/src/Features/Collaborators/CollaboratorsGetter.mjs b/services/web/app/src/Features/Collaborators/CollaboratorsGetter.mjs index 54d2112740..b75a06f955 100644 --- a/services/web/app/src/Features/Collaborators/CollaboratorsGetter.mjs +++ b/services/web/app/src/Features/Collaborators/CollaboratorsGetter.mjs @@ -4,7 +4,7 @@ import { callbackify } from 'node:util' import pLimit from 'p-limit' import mongodb from 'mongodb-legacy' import OError from '@overleaf/o-error' -import { Project } from '../../models/Project.js' +import { Project } from '../../models/Project.mjs' import UserGetter from '../User/UserGetter.mjs' import ProjectGetter from '../Project/ProjectGetter.mjs' import PublicAccessLevels from '../Authorization/PublicAccessLevels.mjs' diff --git a/services/web/app/src/Features/Collaborators/CollaboratorsHandler.mjs b/services/web/app/src/Features/Collaborators/CollaboratorsHandler.mjs index 1eee8a6936..ab7f366315 100644 --- a/services/web/app/src/Features/Collaborators/CollaboratorsHandler.mjs +++ b/services/web/app/src/Features/Collaborators/CollaboratorsHandler.mjs @@ -1,6 +1,6 @@ import { callbackify } from 'node:util' import OError from '@overleaf/o-error' -import { Project } from '../../models/Project.js' +import { Project } from '../../models/Project.mjs' import ProjectGetter from '../Project/ProjectGetter.mjs' import logger from '@overleaf/logger' import ContactManager from '../Contacts/ContactManager.mjs' diff --git a/services/web/app/src/Features/Collaborators/CollaboratorsInviteController.mjs b/services/web/app/src/Features/Collaborators/CollaboratorsInviteController.mjs index 33bdefd212..75d280701e 100644 --- a/services/web/app/src/Features/Collaborators/CollaboratorsInviteController.mjs +++ b/services/web/app/src/Features/Collaborators/CollaboratorsInviteController.mjs @@ -6,7 +6,7 @@ import CollaboratorsInviteHandler from './CollaboratorsInviteHandler.mjs' import CollaboratorsInviteGetter from './CollaboratorsInviteGetter.mjs' import logger from '@overleaf/logger' import Settings from '@overleaf/settings' -import EmailHelper from '../Helpers/EmailHelper.js' +import EmailHelper from '../Helpers/EmailHelper.mjs' import EditorRealTimeController from '../Editor/EditorRealTimeController.mjs' import AnalyticsManager from '../Analytics/AnalyticsManager.mjs' import SessionManager from '../Authentication/SessionManager.mjs' diff --git a/services/web/app/src/Features/Collaborators/CollaboratorsInviteGetter.mjs b/services/web/app/src/Features/Collaborators/CollaboratorsInviteGetter.mjs index 766f1f4708..8ce4651e49 100644 --- a/services/web/app/src/Features/Collaborators/CollaboratorsInviteGetter.mjs +++ b/services/web/app/src/Features/Collaborators/CollaboratorsInviteGetter.mjs @@ -1,5 +1,5 @@ import logger from '@overleaf/logger' -import { ProjectInvite } from '../../models/ProjectInvite.js' +import { ProjectInvite } from '../../models/ProjectInvite.mjs' import PrivilegeLevels from '../Authorization/PrivilegeLevels.js' import CollaboratorsInviteHelper from './CollaboratorsInviteHelper.mjs' diff --git a/services/web/app/src/Features/Collaborators/CollaboratorsInviteHandler.mjs b/services/web/app/src/Features/Collaborators/CollaboratorsInviteHandler.mjs index 58c99eeba5..4c956dc102 100644 --- a/services/web/app/src/Features/Collaborators/CollaboratorsInviteHandler.mjs +++ b/services/web/app/src/Features/Collaborators/CollaboratorsInviteHandler.mjs @@ -1,5 +1,5 @@ import { callbackify } from 'node:util' -import { ProjectInvite } from '../../models/ProjectInvite.js' +import { ProjectInvite } from '../../models/ProjectInvite.mjs' import logger from '@overleaf/logger' import CollaboratorsEmailHandler from './CollaboratorsEmailHandler.mjs' import CollaboratorsHandler from './CollaboratorsHandler.mjs' diff --git a/services/web/app/src/Features/Collaborators/OwnershipTransferHandler.mjs b/services/web/app/src/Features/Collaborators/OwnershipTransferHandler.mjs index 79ed8b0435..093f6893c8 100644 --- a/services/web/app/src/Features/Collaborators/OwnershipTransferHandler.mjs +++ b/services/web/app/src/Features/Collaborators/OwnershipTransferHandler.mjs @@ -1,5 +1,5 @@ import logger from '@overleaf/logger' -import { Project } from '../../models/Project.js' +import { Project } from '../../models/Project.mjs' import ProjectGetter from '../Project/ProjectGetter.mjs' import UserGetter from '../User/UserGetter.mjs' import CollaboratorsHandler from './CollaboratorsHandler.mjs' diff --git a/services/web/app/src/Features/Cooldown/CooldownManager.js b/services/web/app/src/Features/Cooldown/CooldownManager.mjs similarity index 83% rename from services/web/app/src/Features/Cooldown/CooldownManager.js rename to services/web/app/src/Features/Cooldown/CooldownManager.mjs index 8c6b708c07..5f190d1a08 100644 --- a/services/web/app/src/Features/Cooldown/CooldownManager.js +++ b/services/web/app/src/Features/Cooldown/CooldownManager.mjs @@ -1,7 +1,7 @@ -const RedisWrapper = require('../../infrastructure/RedisWrapper') +import RedisWrapper from '../../infrastructure/RedisWrapper.js' +import logger from '@overleaf/logger' +import { promisify } from '@overleaf/promise-utils' const rclient = RedisWrapper.client('cooldown') -const logger = require('@overleaf/logger') -const { promisify } = require('@overleaf/promise-utils') const COOLDOWN_IN_SECONDS = 60 * 10 @@ -45,4 +45,4 @@ CooldownManager.promises = { isProjectOnCooldown: promisify(CooldownManager.isProjectOnCooldown), } -module.exports = CooldownManager +export default CooldownManager diff --git a/services/web/app/src/Features/Cooldown/CooldownMiddleware.mjs b/services/web/app/src/Features/Cooldown/CooldownMiddleware.mjs index 46a84eb571..d2d1cb01e3 100644 --- a/services/web/app/src/Features/Cooldown/CooldownMiddleware.mjs +++ b/services/web/app/src/Features/Cooldown/CooldownMiddleware.mjs @@ -10,7 +10,7 @@ * DS207: Consider shorter variations of null checks * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md */ -import CooldownManager from './CooldownManager.js' +import CooldownManager from './CooldownManager.mjs' import logger from '@overleaf/logger' let CooldownMiddleware diff --git a/services/web/app/src/Features/FileStore/FileStoreHandler.mjs b/services/web/app/src/Features/FileStore/FileStoreHandler.mjs index 982616f44b..6abc6602b9 100644 --- a/services/web/app/src/Features/FileStore/FileStoreHandler.mjs +++ b/services/web/app/src/Features/FileStore/FileStoreHandler.mjs @@ -4,7 +4,7 @@ import Async from 'async' import FileHashManager from './FileHashManager.mjs' import HistoryManager from '../History/HistoryManager.mjs' import ProjectDetailsHandler from '../Project/ProjectDetailsHandler.mjs' -import { File } from '../../models/File.js' +import { File } from '../../models/File.mjs' import OError from '@overleaf/o-error' import { promisifyAll } from '@overleaf/promise-utils' import Modules from '../../infrastructure/Modules.js' diff --git a/services/web/app/src/Features/GlobalMetrics/GlobalMetricsManager.mjs b/services/web/app/src/Features/GlobalMetrics/GlobalMetricsManager.mjs index d8991614d7..5be629f490 100644 --- a/services/web/app/src/Features/GlobalMetrics/GlobalMetricsManager.mjs +++ b/services/web/app/src/Features/GlobalMetrics/GlobalMetricsManager.mjs @@ -1,4 +1,4 @@ -import { GlobalMetric } from '../../models/GlobalMetric.js' +import { GlobalMetric } from '../../models/GlobalMetric.mjs' /** * A Generic collection used to track metrics shared across the entirety of the application * examples: diff --git a/services/web/app/src/Features/Helpers/AuthorizationHelper.mjs b/services/web/app/src/Features/Helpers/AuthorizationHelper.mjs index 9bac0c0769..9d16102113 100644 --- a/services/web/app/src/Features/Helpers/AuthorizationHelper.mjs +++ b/services/web/app/src/Features/Helpers/AuthorizationHelper.mjs @@ -1,4 +1,4 @@ -import { UserSchema } from '../../models/User.js' +import { UserSchema } from '../../models/User.mjs' export default { hasAnyStaffAccess, diff --git a/services/web/app/src/Features/Helpers/DiffHelper.js b/services/web/app/src/Features/Helpers/DiffHelper.mjs similarity index 95% rename from services/web/app/src/Features/Helpers/DiffHelper.js rename to services/web/app/src/Features/Helpers/DiffHelper.mjs index c2d1d73fd3..b8b2b3005a 100644 --- a/services/web/app/src/Features/Helpers/DiffHelper.js +++ b/services/web/app/src/Features/Helpers/DiffHelper.mjs @@ -17,7 +17,7 @@ function _calculateRatio(matches, length) { * corresponding (approximatey) to the overlap between the strings. * Identical strings produce 1.0, completely different strings produce 0.0 * */ -function stringSimilarity(a, b) { +export function stringSimilarity(a, b) { if ( typeof a !== 'string' || typeof b !== 'string' || @@ -50,6 +50,6 @@ function stringSimilarity(a, b) { return _calculateRatio(matches, a.length + b.length) } -module.exports = { +export default { stringSimilarity, } diff --git a/services/web/app/src/Features/Helpers/EmailHelper.js b/services/web/app/src/Features/Helpers/EmailHelper.mjs similarity index 90% rename from services/web/app/src/Features/Helpers/EmailHelper.js rename to services/web/app/src/Features/Helpers/EmailHelper.mjs index 80b96dfea0..34e96b91d9 100644 --- a/services/web/app/src/Features/Helpers/EmailHelper.js +++ b/services/web/app/src/Features/Helpers/EmailHelper.mjs @@ -1,4 +1,6 @@ -const { parseOneAddress } = require('email-addresses') +import emailAddresses from 'email-addresses' + +const { parseOneAddress } = emailAddresses // available for frontend in https://github.com/overleaf/internal/blob/19d432c70b173752ee7c6d8978dd6be16b042921/services/web/frontend/js/shared/utils/email.tsx#L4 const EMAIL_REGEXP = @@ -36,7 +38,7 @@ function parseEmail(email, parseRfcAddress = false) { return matched[0] } -module.exports = { +export default { getDomain, parseEmail, } diff --git a/services/web/app/src/Features/InactiveData/InactiveProjectManager.mjs b/services/web/app/src/Features/InactiveData/InactiveProjectManager.mjs index 6ec4c0f6b4..be91231fd3 100644 --- a/services/web/app/src/Features/InactiveData/InactiveProjectManager.mjs +++ b/services/web/app/src/Features/InactiveData/InactiveProjectManager.mjs @@ -4,7 +4,7 @@ import DocstoreManager from '../Docstore/DocstoreManager.mjs' import DocumentUpdaterHandler from '../DocumentUpdater/DocumentUpdaterHandler.mjs' import ProjectGetter from '../Project/ProjectGetter.mjs' import ProjectUpdateHandler from '../Project/ProjectUpdateHandler.mjs' -import { Project } from '../../models/Project.js' +import { Project } from '../../models/Project.mjs' import Modules from '../../infrastructure/Modules.js' import { READ_PREFERENCE_SECONDARY } from '../../infrastructure/mongodb.js' import { callbackifyAll } from '@overleaf/promise-utils' diff --git a/services/web/app/src/Features/Institutions/InstitutionsManager.mjs b/services/web/app/src/Features/Institutions/InstitutionsManager.mjs index 9c6c9d2f6e..989aa6596b 100644 --- a/services/web/app/src/Features/Institutions/InstitutionsManager.mjs +++ b/services/web/app/src/Features/Institutions/InstitutionsManager.mjs @@ -10,8 +10,8 @@ import UserGetter from '../User/UserGetter.mjs' import NotificationsBuilder from '../Notifications/NotificationsBuilder.mjs' import NotificationsHandler from '../Notifications/NotificationsHandler.mjs' import SubscriptionLocator from '../Subscription/SubscriptionLocator.mjs' -import { Institution } from '../../models/Institution.js' -import { Subscription } from '../../models/Subscription.js' +import { Institution } from '../../models/Institution.mjs' +import { Subscription } from '../../models/Subscription.mjs' import OError from '@overleaf/o-error' const { ObjectId } = mongodb diff --git a/services/web/app/src/Features/LinkedFiles/LinkedFilesHandler.mjs b/services/web/app/src/Features/LinkedFiles/LinkedFilesHandler.mjs index 2cd8272ece..4bbc9069b8 100644 --- a/services/web/app/src/Features/LinkedFiles/LinkedFilesHandler.mjs +++ b/services/web/app/src/Features/LinkedFiles/LinkedFilesHandler.mjs @@ -1,7 +1,7 @@ import FileWriter from '../../infrastructure/FileWriter.js' import EditorController from '../Editor/EditorController.mjs' import ProjectLocator from '../Project/ProjectLocator.mjs' -import { Project } from '../../models/Project.js' +import { Project } from '../../models/Project.mjs' import ProjectGetter from '../Project/ProjectGetter.mjs' import LinkedFilesErrors from './LinkedFilesErrors.mjs' import { callbackifyAll } from '@overleaf/promise-utils' diff --git a/services/web/app/src/Features/OnboardingDataCollection/OnboardingDataCollectionManager.mjs b/services/web/app/src/Features/OnboardingDataCollection/OnboardingDataCollectionManager.mjs index 8359add440..99bb0a3d7a 100644 --- a/services/web/app/src/Features/OnboardingDataCollection/OnboardingDataCollectionManager.mjs +++ b/services/web/app/src/Features/OnboardingDataCollection/OnboardingDataCollectionManager.mjs @@ -1,4 +1,4 @@ -import OnboardingDataCollectionModel from '../../models/OnboardingDataCollection.js' +import OnboardingDataCollectionModel from '../../models/OnboardingDataCollection.mjs' import OError from '@overleaf/o-error' const { OnboardingDataCollection, OnboardingDataCollectionSchema } = diff --git a/services/web/app/src/Features/PasswordReset/PasswordResetController.mjs b/services/web/app/src/Features/PasswordReset/PasswordResetController.mjs index d9221f23b5..a945c93ffd 100644 --- a/services/web/app/src/Features/PasswordReset/PasswordResetController.mjs +++ b/services/web/app/src/Features/PasswordReset/PasswordResetController.mjs @@ -6,7 +6,7 @@ import UserGetter from '../User/UserGetter.mjs' import UserUpdater from '../User/UserUpdater.mjs' import UserSessionsManager from '../User/UserSessionsManager.mjs' import OError from '@overleaf/o-error' -import EmailsHelper from '../Helpers/EmailHelper.js' +import EmailsHelper from '../Helpers/EmailHelper.mjs' import { expressify } from '@overleaf/promise-utils' import { z, validateReq } from '../../infrastructure/Validation.js' diff --git a/services/web/app/src/Features/PasswordReset/PasswordResetHandler.mjs b/services/web/app/src/Features/PasswordReset/PasswordResetHandler.mjs index 5ff08f36c2..33d785e80f 100644 --- a/services/web/app/src/Features/PasswordReset/PasswordResetHandler.mjs +++ b/services/web/app/src/Features/PasswordReset/PasswordResetHandler.mjs @@ -1,7 +1,7 @@ import settings from '@overleaf/settings' import UserAuditLogHandler from '../User/UserAuditLogHandler.mjs' import UserGetter from '../User/UserGetter.mjs' -import OneTimeTokenHandler from '../Security/OneTimeTokenHandler.js' +import OneTimeTokenHandler from '../Security/OneTimeTokenHandler.mjs' import EmailHandler from '../Email/EmailHandler.mjs' import AuthenticationManager from '../Authentication/AuthenticationManager.mjs' import { callbackify, promisify } from 'node:util' diff --git a/services/web/app/src/Features/Project/IterablePath.js b/services/web/app/src/Features/Project/IterablePath.mjs similarity index 74% rename from services/web/app/src/Features/Project/IterablePath.js rename to services/web/app/src/Features/Project/IterablePath.mjs index 52cf068c42..1c6ad90eb5 100644 --- a/services/web/app/src/Features/Project/IterablePath.js +++ b/services/web/app/src/Features/Project/IterablePath.mjs @@ -3,13 +3,9 @@ * `folder.folders` or `folder.fileRefs` are missing it returns an * empty array. */ -function iterablePaths(folder, field) { +export function iterablePaths(folder, field) { if (!folder) { return [] } return folder[field] || [] } - -module.exports = { - iterablePaths, -} diff --git a/services/web/app/src/Features/Project/ProjectAuditLogHandler.mjs b/services/web/app/src/Features/Project/ProjectAuditLogHandler.mjs index 87f8bac857..114d3ef3f8 100644 --- a/services/web/app/src/Features/Project/ProjectAuditLogHandler.mjs +++ b/services/web/app/src/Features/Project/ProjectAuditLogHandler.mjs @@ -1,5 +1,5 @@ import logger from '@overleaf/logger' -import { ProjectAuditLogEntry } from '../../models/ProjectAuditLogEntry.js' +import { ProjectAuditLogEntry } from '../../models/ProjectAuditLogEntry.mjs' import { callbackify } from '@overleaf/promise-utils' import SubscriptionLocator from '../Subscription/SubscriptionLocator.mjs' diff --git a/services/web/app/src/Features/Project/ProjectCollabratecDetailsHandler.mjs b/services/web/app/src/Features/Project/ProjectCollabratecDetailsHandler.mjs index 55d19a4bd6..d9f66b66fc 100644 --- a/services/web/app/src/Features/Project/ProjectCollabratecDetailsHandler.mjs +++ b/services/web/app/src/Features/Project/ProjectCollabratecDetailsHandler.mjs @@ -1,6 +1,6 @@ import mongodb from 'mongodb-legacy' -import { Project } from '../../models/Project.js' +import { Project } from '../../models/Project.mjs' import { callbackifyAll } from '@overleaf/promise-utils' const { ObjectId } = mongodb diff --git a/services/web/app/src/Features/Project/ProjectController.mjs b/services/web/app/src/Features/Project/ProjectController.mjs index 58fab31622..9ae4d5d6e4 100644 --- a/services/web/app/src/Features/Project/ProjectController.mjs +++ b/services/web/app/src/Features/Project/ProjectController.mjs @@ -12,9 +12,9 @@ import ProjectCreationHandler from './ProjectCreationHandler.mjs' import EditorController from '../Editor/EditorController.mjs' import ProjectHelper from './ProjectHelper.mjs' import metrics from '@overleaf/metrics' -import { User } from '../../models/User.js' +import { User } from '../../models/User.mjs' import SubscriptionLocator from '../Subscription/SubscriptionLocator.mjs' -import { isPaidSubscription } from '../Subscription/SubscriptionHelper.js' +import SubscriptionHelper from '../Subscription/SubscriptionHelper.mjs' import LimitationsManager from '../Subscription/LimitationsManager.mjs' import Settings from '@overleaf/settings' import AuthorizationManager from '../Authorization/AuthorizationManager.mjs' @@ -52,6 +52,7 @@ import SubscriptionController from '../Subscription/SubscriptionController.mjs' import { formatCurrency } from '../../util/currency.js' import UserSettingsHelper from './UserSettingsHelper.mjs' +const { isPaidSubscription } = SubscriptionHelper const { hasAdminAccess } = AdminAuthorizationHelper const { ObjectId } = mongodb /** diff --git a/services/web/app/src/Features/Project/ProjectCreationHandler.mjs b/services/web/app/src/Features/Project/ProjectCreationHandler.mjs index ef614f7f05..03ad4437a2 100644 --- a/services/web/app/src/Features/Project/ProjectCreationHandler.mjs +++ b/services/web/app/src/Features/Project/ProjectCreationHandler.mjs @@ -3,12 +3,12 @@ import metrics from '@overleaf/metrics' import Settings from '@overleaf/settings' import mongodb from 'mongodb-legacy' import Features from '../../infrastructure/Features.js' -import { Project } from '../../models/Project.js' -import { Folder } from '../../models/Folder.js' +import { Project } from '../../models/Project.mjs' +import { Folder } from '../../models/Folder.mjs' import ProjectEntityUpdateHandler from './ProjectEntityUpdateHandler.mjs' import ProjectDetailsHandler from './ProjectDetailsHandler.mjs' import HistoryManager from '../History/HistoryManager.mjs' -import { User } from '../../models/User.js' +import { User } from '../../models/User.mjs' import fs from 'node:fs' import path from 'node:path' import { callbackify } from 'node:util' diff --git a/services/web/app/src/Features/Project/ProjectDeleter.mjs b/services/web/app/src/Features/Project/ProjectDeleter.mjs index 276e3765cb..eda7671270 100644 --- a/services/web/app/src/Features/Project/ProjectDeleter.mjs +++ b/services/web/app/src/Features/Project/ProjectDeleter.mjs @@ -6,9 +6,9 @@ import { } from '../../infrastructure/mongodb.js' import Modules from '../../infrastructure/Modules.js' import { callbackify } from 'node:util' -import { Project } from '../../models/Project.js' -import { DeletedProject } from '../../models/DeletedProject.js' -import { ProjectAuditLogEntry } from '../../models/ProjectAuditLogEntry.js' +import { Project } from '../../models/Project.mjs' +import { DeletedProject } from '../../models/DeletedProject.mjs' +import { ProjectAuditLogEntry } from '../../models/ProjectAuditLogEntry.mjs' import Errors from '../Errors/Errors.js' import logger from '@overleaf/logger' import Settings from '@overleaf/settings' diff --git a/services/web/app/src/Features/Project/ProjectDetailsHandler.mjs b/services/web/app/src/Features/Project/ProjectDetailsHandler.mjs index 758429dae6..a2116ecdf3 100644 --- a/services/web/app/src/Features/Project/ProjectDetailsHandler.mjs +++ b/services/web/app/src/Features/Project/ProjectDetailsHandler.mjs @@ -1,7 +1,7 @@ import _ from 'lodash' import ProjectGetter from './ProjectGetter.mjs' import UserGetter from '../User/UserGetter.mjs' -import { Project } from '../../models/Project.js' +import { Project } from '../../models/Project.mjs' import logger from '@overleaf/logger' import TpdsUpdateSender from '../ThirdPartyDataStore/TpdsUpdateSender.mjs' import PublicAccessLevels from '../Authorization/PublicAccessLevels.mjs' diff --git a/services/web/app/src/Features/Project/ProjectDuplicator.mjs b/services/web/app/src/Features/Project/ProjectDuplicator.mjs index 1f2ec0f773..d125578651 100644 --- a/services/web/app/src/Features/Project/ProjectDuplicator.mjs +++ b/services/web/app/src/Features/Project/ProjectDuplicator.mjs @@ -3,8 +3,8 @@ import Path from 'node:path' import logger from '@overleaf/logger' import OError from '@overleaf/o-error' import { promiseMapWithLimit } from '@overleaf/promise-utils' -import { Doc } from '../../models/Doc.js' -import { File } from '../../models/File.js' +import { Doc } from '../../models/Doc.mjs' +import { File } from '../../models/File.mjs' import DocstoreManager from '../Docstore/DocstoreManager.mjs' import DocumentUpdaterHandler from '../DocumentUpdater/DocumentUpdaterHandler.mjs' import HistoryManager from '../History/HistoryManager.mjs' diff --git a/services/web/app/src/Features/Project/ProjectEntityHandler.mjs b/services/web/app/src/Features/Project/ProjectEntityHandler.mjs index 8a2e18c0d8..acc4e26438 100644 --- a/services/web/app/src/Features/Project/ProjectEntityHandler.mjs +++ b/services/web/app/src/Features/Project/ProjectEntityHandler.mjs @@ -4,7 +4,7 @@ import Errors from '../Errors/Errors.js' import ProjectGetter from './ProjectGetter.mjs' import { callbackifyAll } from '@overleaf/promise-utils' import OError from '@overleaf/o-error' -import { iterablePaths } from './IterablePath.js' +import { iterablePaths } from './IterablePath.mjs' async function getAllDocs(projectId) { // We get the path and name info from the project, and the lines and diff --git a/services/web/app/src/Features/Project/ProjectEntityMongoUpdateHandler.mjs b/services/web/app/src/Features/Project/ProjectEntityMongoUpdateHandler.mjs index 2843621d52..59e0d72619 100644 --- a/services/web/app/src/Features/Project/ProjectEntityMongoUpdateHandler.mjs +++ b/services/web/app/src/Features/Project/ProjectEntityMongoUpdateHandler.mjs @@ -5,17 +5,17 @@ import path from 'node:path' import mongodb from 'mongodb-legacy' import Settings from '@overleaf/settings' import OError from '@overleaf/o-error' -import CooldownManager from '../Cooldown/CooldownManager.js' +import CooldownManager from '../Cooldown/CooldownManager.mjs' import Errors from '../Errors/Errors.js' -import { Folder } from '../../models/Folder.js' +import { Folder } from '../../models/Folder.mjs' import LockManager from '../../infrastructure/LockManager.js' -import { Project } from '../../models/Project.js' +import { Project } from '../../models/Project.mjs' import ProjectEntityHandler from './ProjectEntityHandler.mjs' import ProjectGetter from './ProjectGetter.mjs' import ProjectLocator from './ProjectLocator.mjs' import FolderStructureBuilder from './FolderStructureBuilder.mjs' import SafePath from './SafePath.mjs' -import { iterablePaths } from './IterablePath.js' +import { iterablePaths } from './IterablePath.mjs' const { ObjectId } = mongodb diff --git a/services/web/app/src/Features/Project/ProjectEntityUpdateHandler.mjs b/services/web/app/src/Features/Project/ProjectEntityUpdateHandler.mjs index 0a482cea73..34d76d893c 100644 --- a/services/web/app/src/Features/Project/ProjectEntityUpdateHandler.mjs +++ b/services/web/app/src/Features/Project/ProjectEntityUpdateHandler.mjs @@ -4,13 +4,13 @@ import logger from '@overleaf/logger' import Settings from '@overleaf/settings' import Path from 'node:path' import fs from 'node:fs' -import { Doc } from '../../models/Doc.js' +import { Doc } from '../../models/Doc.mjs' import DocstoreManager from '../Docstore/DocstoreManager.mjs' import DocumentUpdaterHandler from '../../Features/DocumentUpdater/DocumentUpdaterHandler.mjs' import Errors from '../Errors/Errors.js' import FileStoreHandler from '../FileStore/FileStoreHandler.mjs' import LockManager from '../../infrastructure/LockManager.js' -import { Project } from '../../models/Project.js' +import { Project } from '../../models/Project.mjs' import ProjectEntityHandler from './ProjectEntityHandler.mjs' import ProjectGetter from './ProjectGetter.mjs' import ProjectLocator from './ProjectLocator.mjs' @@ -22,7 +22,7 @@ import TpdsUpdateSender from '../ThirdPartyDataStore/TpdsUpdateSender.mjs' import FileWriter from '../../infrastructure/FileWriter.js' import EditorRealTimeController from '../Editor/EditorRealTimeController.mjs' import { callbackifyMultiResult, callbackify } from '@overleaf/promise-utils' -import { iterablePaths } from './IterablePath.js' +import { iterablePaths } from './IterablePath.mjs' const LOCK_NAMESPACE = 'sequentialProjectStructureUpdateLock' const VALID_ROOT_DOC_EXTENSIONS = Settings.validRootDocExtensions diff --git a/services/web/app/src/Features/Project/ProjectGetter.mjs b/services/web/app/src/Features/Project/ProjectGetter.mjs index 0903a0504c..2aafb73892 100644 --- a/services/web/app/src/Features/Project/ProjectGetter.mjs +++ b/services/web/app/src/Features/Project/ProjectGetter.mjs @@ -1,9 +1,9 @@ import { db } from '../../infrastructure/mongodb.js' import { normalizeQuery } from '../Helpers/Mongo.js' import OError from '@overleaf/o-error' -import { Project } from '../../models/Project.js' +import { Project } from '../../models/Project.mjs' import LockManager from '../../infrastructure/LockManager.js' -import { DeletedProject } from '../../models/DeletedProject.js' +import { DeletedProject } from '../../models/DeletedProject.mjs' import { callbackifyAll } from '@overleaf/promise-utils' import ProjectEntityMongoUpdateHandler from './ProjectEntityMongoUpdateHandler.mjs' import CollaboratorsGetter from '../Collaborators/CollaboratorsGetter.mjs' diff --git a/services/web/app/src/Features/Project/ProjectHistoryHandler.mjs b/services/web/app/src/Features/Project/ProjectHistoryHandler.mjs index b08533522e..adbae9dfab 100644 --- a/services/web/app/src/Features/Project/ProjectHistoryHandler.mjs +++ b/services/web/app/src/Features/Project/ProjectHistoryHandler.mjs @@ -1,4 +1,4 @@ -import { Project } from '../../models/Project.js' +import { Project } from '../../models/Project.mjs' import ProjectDetailsHandler from './ProjectDetailsHandler.mjs' import HistoryManager from '../History/HistoryManager.mjs' import ProjectEntityUpdateHandler from './ProjectEntityUpdateHandler.mjs' diff --git a/services/web/app/src/Features/Project/ProjectListController.mjs b/services/web/app/src/Features/Project/ProjectListController.mjs index 2e5a5fc1e3..0cfb78a099 100644 --- a/services/web/app/src/Features/Project/ProjectListController.mjs +++ b/services/web/app/src/Features/Project/ProjectListController.mjs @@ -19,7 +19,7 @@ import SubscriptionViewModelBuilder from '../Subscription/SubscriptionViewModelB import NotificationsHandler from '../Notifications/NotificationsHandler.mjs' import Modules from '../../infrastructure/Modules.js' import { OError, V1ConnectionError } from '../Errors/Errors.js' -import { User } from '../../models/User.js' +import { User } from '../../models/User.mjs' import UserPrimaryEmailCheckHandler from '../User/UserPrimaryEmailCheckHandler.mjs' import UserController from '../User/UserController.mjs' import NotificationsBuilder from '../Notifications/NotificationsBuilder.mjs' @@ -27,10 +27,10 @@ import GeoIpLookup from '../../infrastructure/GeoIpLookup.mjs' import SplitTestHandler from '../SplitTests/SplitTestHandler.mjs' import SplitTestSessionHandler from '../SplitTests/SplitTestSessionHandler.mjs' import TutorialHandler from '../Tutorial/TutorialHandler.mjs' -import SubscriptionHelper from '../Subscription/SubscriptionHelper.js' +import SubscriptionHelper from '../Subscription/SubscriptionHelper.mjs' import PermissionsManager from '../Authorization/PermissionsManager.mjs' import AnalyticsManager from '../Analytics/AnalyticsManager.mjs' -import { OnboardingDataCollection } from '../../models/OnboardingDataCollection.js' +import { OnboardingDataCollection } from '../../models/OnboardingDataCollection.mjs' import UserSettingsHelper from './UserSettingsHelper.mjs' /** diff --git a/services/web/app/src/Features/Project/ProjectLocator.mjs b/services/web/app/src/Features/Project/ProjectLocator.mjs index 3a3d8ba962..abc80b9dcb 100644 --- a/services/web/app/src/Features/Project/ProjectLocator.mjs +++ b/services/web/app/src/Features/Project/ProjectLocator.mjs @@ -5,7 +5,7 @@ import async from 'async' import ProjectGetter from './ProjectGetter.mjs' import Errors from '../Errors/Errors.js' import { promisifyMultiResult } from '@overleaf/promise-utils' -import { iterablePaths } from './IterablePath.js' +import { iterablePaths } from './IterablePath.mjs' /** * @param project diff --git a/services/web/app/src/Features/Project/ProjectOptionsHandler.mjs b/services/web/app/src/Features/Project/ProjectOptionsHandler.mjs index 9d577fc35e..d80e8c75c8 100644 --- a/services/web/app/src/Features/Project/ProjectOptionsHandler.mjs +++ b/services/web/app/src/Features/Project/ProjectOptionsHandler.mjs @@ -1,4 +1,4 @@ -import { Project } from '../../models/Project.js' +import { Project } from '../../models/Project.mjs' import settings from '@overleaf/settings' import { callbackify } from 'node:util' import { db, ObjectId } from '../../infrastructure/mongodb.js' diff --git a/services/web/app/src/Features/Project/ProjectUpdateHandler.mjs b/services/web/app/src/Features/Project/ProjectUpdateHandler.mjs index 2352ef1ad1..f4b366acc0 100644 --- a/services/web/app/src/Features/Project/ProjectUpdateHandler.mjs +++ b/services/web/app/src/Features/Project/ProjectUpdateHandler.mjs @@ -1,4 +1,4 @@ -import { Project } from '../../models/Project.js' +import { Project } from '../../models/Project.mjs' import { callbackify } from 'node:util' const ProjectUpdateHandler = { diff --git a/services/web/app/src/Features/Referal/ReferalAllocator.mjs b/services/web/app/src/Features/Referal/ReferalAllocator.mjs index 6e37a5c063..5fb2c714b9 100644 --- a/services/web/app/src/Features/Referal/ReferalAllocator.mjs +++ b/services/web/app/src/Features/Referal/ReferalAllocator.mjs @@ -1,5 +1,5 @@ import OError from '@overleaf/o-error' -import { User } from '../../models/User.js' +import { User } from '../../models/User.mjs' import FeaturesUpdater from '../Subscription/FeaturesUpdater.mjs' import { callbackify } from '@overleaf/promise-utils' diff --git a/services/web/app/src/Features/Referal/ReferalFeatures.mjs b/services/web/app/src/Features/Referal/ReferalFeatures.mjs index 5ee8541786..dfb725927b 100644 --- a/services/web/app/src/Features/Referal/ReferalFeatures.mjs +++ b/services/web/app/src/Features/Referal/ReferalFeatures.mjs @@ -1,6 +1,6 @@ import _ from 'lodash' import { callbackify } from 'node:util' -import { User } from '../../models/User.js' +import { User } from '../../models/User.mjs' import Settings from '@overleaf/settings' const ReferalFeatures = { diff --git a/services/web/app/src/Features/Referal/ReferalHandler.mjs b/services/web/app/src/Features/Referal/ReferalHandler.mjs index 1d389bb860..3821fbb6ea 100644 --- a/services/web/app/src/Features/Referal/ReferalHandler.mjs +++ b/services/web/app/src/Features/Referal/ReferalHandler.mjs @@ -1,5 +1,5 @@ import { callbackify } from '@overleaf/promise-utils' -import { User } from '../../models/User.js' +import { User } from '../../models/User.mjs' async function getReferedUsers(userId) { const projection = { refered_users: 1, refered_user_count: 1 } diff --git a/services/web/app/src/Features/SamlLog/SamlLogHandler.mjs b/services/web/app/src/Features/SamlLog/SamlLogHandler.mjs index 37845c6be2..c55043291a 100644 --- a/services/web/app/src/Features/SamlLog/SamlLogHandler.mjs +++ b/services/web/app/src/Features/SamlLog/SamlLogHandler.mjs @@ -1,4 +1,4 @@ -import { SamlLog } from '../../models/SamlLog.js' +import { SamlLog } from '../../models/SamlLog.mjs' import SessionManager from '../Authentication/SessionManager.mjs' import logger from '@overleaf/logger' import loggerSerializers from '@overleaf/logger/serializers.js' diff --git a/services/web/app/src/Features/Security/OneTimeTokenHandler.js b/services/web/app/src/Features/Security/OneTimeTokenHandler.mjs similarity index 92% rename from services/web/app/src/Features/Security/OneTimeTokenHandler.js rename to services/web/app/src/Features/Security/OneTimeTokenHandler.mjs index 2b38f15635..2bfb7844e3 100644 --- a/services/web/app/src/Features/Security/OneTimeTokenHandler.js +++ b/services/web/app/src/Features/Security/OneTimeTokenHandler.mjs @@ -1,7 +1,7 @@ -const crypto = require('crypto') -const { db } = require('../../infrastructure/mongodb') -const Errors = require('../Errors/Errors') -const { callbackify } = require('util') +import crypto from 'node:crypto' +import { db } from '../../infrastructure/mongodb.js' +import Errors from '../Errors/Errors.js' +import { callbackify } from 'node:util' const ONE_HOUR_IN_S = 60 * 60 @@ -119,4 +119,4 @@ const OneTimeTokenHandler = { }, } -module.exports = OneTimeTokenHandler +export default OneTimeTokenHandler diff --git a/services/web/app/src/Features/SplitTests/SplitTestHandler.mjs b/services/web/app/src/Features/SplitTests/SplitTestHandler.mjs index df82b8074b..36501f2be4 100644 --- a/services/web/app/src/Features/SplitTests/SplitTestHandler.mjs +++ b/services/web/app/src/Features/SplitTests/SplitTestHandler.mjs @@ -6,7 +6,7 @@ import crypto from 'node:crypto' import _ from 'lodash' import { callbackify } from 'node:util' import SplitTestCache from './SplitTestCache.mjs' -import { SplitTest } from '../../models/SplitTest.js' +import { SplitTest } from '../../models/SplitTest.mjs' import UserAnalyticsIdCache from '../Analytics/UserAnalyticsIdCache.mjs' import Features from '../../infrastructure/Features.js' import SplitTestUtils from './SplitTestUtils.mjs' diff --git a/services/web/app/src/Features/SplitTests/SplitTestManager.mjs b/services/web/app/src/Features/SplitTests/SplitTestManager.mjs index 587e75ef34..27b05dc6e1 100644 --- a/services/web/app/src/Features/SplitTests/SplitTestManager.mjs +++ b/services/web/app/src/Features/SplitTests/SplitTestManager.mjs @@ -1,4 +1,4 @@ -import { SplitTest } from '../../models/SplitTest.js' +import { SplitTest } from '../../models/SplitTest.mjs' import SplitTestUtils from './SplitTestUtils.mjs' import OError from '@overleaf/o-error' import _ from 'lodash' diff --git a/services/web/app/src/Features/Subscription/FeaturesUpdater.mjs b/services/web/app/src/Features/Subscription/FeaturesUpdater.mjs index ee75dfb017..9b318ba5d2 100644 --- a/services/web/app/src/Features/Subscription/FeaturesUpdater.mjs +++ b/services/web/app/src/Features/Subscription/FeaturesUpdater.mjs @@ -3,7 +3,7 @@ import { callbackify } from 'node:util' import { callbackifyMultiResult } from '@overleaf/promise-utils' import PlansLocator from './PlansLocator.mjs' import SubscriptionLocator from './SubscriptionLocator.mjs' -import SubscriptionHelper from './SubscriptionHelper.js' +import SubscriptionHelper from './SubscriptionHelper.mjs' import UserFeaturesUpdater from './UserFeaturesUpdater.mjs' import FeaturesHelper from './FeaturesHelper.mjs' import Settings from '@overleaf/settings' diff --git a/services/web/app/src/Features/Subscription/PaymentProviderEntities.mjs b/services/web/app/src/Features/Subscription/PaymentProviderEntities.mjs index b1af9257f6..caeab041c1 100644 --- a/services/web/app/src/Features/Subscription/PaymentProviderEntities.mjs +++ b/services/web/app/src/Features/Subscription/PaymentProviderEntities.mjs @@ -20,7 +20,7 @@ import OError from '@overleaf/o-error' import { DuplicateAddOnError, AddOnNotPresentError } from './Errors.js' import PlansLocator from './PlansLocator.mjs' -import SubscriptionHelper from './SubscriptionHelper.js' +import SubscriptionHelper from './SubscriptionHelper.mjs' import { AI_ADD_ON_CODE, isStandaloneAiAddOnPlanCode } from './AiHelper.js' export const MEMBERS_LIMIT_ADD_ON_CODE = 'additional-license' diff --git a/services/web/app/src/Features/Subscription/SubscriptionController.mjs b/services/web/app/src/Features/Subscription/SubscriptionController.mjs index 550d9124b5..0108a9e348 100644 --- a/services/web/app/src/Features/Subscription/SubscriptionController.mjs +++ b/services/web/app/src/Features/Subscription/SubscriptionController.mjs @@ -2,7 +2,7 @@ import SessionManager from '../Authentication/SessionManager.mjs' import SubscriptionHandler from './SubscriptionHandler.mjs' -import SubscriptionHelper from './SubscriptionHelper.js' +import SubscriptionHelper from './SubscriptionHelper.mjs' import SubscriptionViewModelBuilder from './SubscriptionViewModelBuilder.mjs' import LimitationsManager from './LimitationsManager.mjs' import RecurlyWrapper from './RecurlyWrapper.mjs' @@ -28,7 +28,7 @@ import { subscriptionChangeIsAiAssistUpgrade, } from './AiHelper.js' import PlansLocator from './PlansLocator.mjs' -import { User } from '../../models/User.js' +import { User } from '../../models/User.mjs' import UserGetter from '../User/UserGetter.mjs' import PermissionsManager from '../Authorization/PermissionsManager.mjs' import { sanitizeSessionUserForFrontEnd } from '../../infrastructure/FrontEndUser.mjs' diff --git a/services/web/app/src/Features/Subscription/SubscriptionGroupController.mjs b/services/web/app/src/Features/Subscription/SubscriptionGroupController.mjs index c308be313f..f9fe532391 100644 --- a/services/web/app/src/Features/Subscription/SubscriptionGroupController.mjs +++ b/services/web/app/src/Features/Subscription/SubscriptionGroupController.mjs @@ -8,7 +8,7 @@ import UserAuditLogHandler from '../User/UserAuditLogHandler.mjs' import { expressify } from '@overleaf/promise-utils' import Modules from '../../infrastructure/Modules.js' import UserGetter from '../User/UserGetter.mjs' -import { Subscription } from '../../models/Subscription.js' +import { Subscription } from '../../models/Subscription.mjs' import { z, validateReq } from '../../infrastructure/Validation.js' import { isProfessionalGroupPlan } from './PlansHelper.mjs' import { diff --git a/services/web/app/src/Features/Subscription/SubscriptionGroupHandler.mjs b/services/web/app/src/Features/Subscription/SubscriptionGroupHandler.mjs index 3c6e485059..3a14f74cc0 100644 --- a/services/web/app/src/Features/Subscription/SubscriptionGroupHandler.mjs +++ b/services/web/app/src/Features/Subscription/SubscriptionGroupHandler.mjs @@ -4,9 +4,9 @@ import OError from '@overleaf/o-error' import SubscriptionUpdater from './SubscriptionUpdater.mjs' import SubscriptionLocator from './SubscriptionLocator.mjs' import SubscriptionController from './SubscriptionController.mjs' -import SubscriptionHelper from './SubscriptionHelper.js' -import { Subscription } from '../../models/Subscription.js' -import { User } from '../../models/User.js' +import SubscriptionHelper from './SubscriptionHelper.mjs' +import { Subscription } from '../../models/Subscription.mjs' +import { User } from '../../models/User.mjs' import PlansLocator from './PlansLocator.mjs' import TeamInvitesHandler from './TeamInvitesHandler.mjs' import GroupPlansData from './GroupPlansData.js' @@ -19,7 +19,7 @@ import { HasPastDueInvoiceError, HasNoAdditionalLicenseWhenManuallyCollectedError, } from './Errors.js' -import EmailHelper from '../Helpers/EmailHelper.js' +import EmailHelper from '../Helpers/EmailHelper.mjs' import { InvalidEmailError } from '../Errors/Errors.js' const MEMBERS_LIMIT_ADD_ON_CODE = diff --git a/services/web/app/src/Features/Subscription/SubscriptionHandler.mjs b/services/web/app/src/Features/Subscription/SubscriptionHandler.mjs index 774705654e..edd5456230 100644 --- a/services/web/app/src/Features/Subscription/SubscriptionHandler.mjs +++ b/services/web/app/src/Features/Subscription/SubscriptionHandler.mjs @@ -3,9 +3,9 @@ import RecurlyWrapper from './RecurlyWrapper.mjs' import RecurlyClient from './RecurlyClient.mjs' -import { User } from '../../models/User.js' +import { User } from '../../models/User.mjs' import logger from '@overleaf/logger' -import SubscriptionHelper from './SubscriptionHelper.js' +import SubscriptionHelper from './SubscriptionHelper.mjs' import SubscriptionUpdater from './SubscriptionUpdater.mjs' import SubscriptionLocator from './SubscriptionLocator.mjs' import LimitationsManager from './LimitationsManager.mjs' diff --git a/services/web/app/src/Features/Subscription/SubscriptionHelper.js b/services/web/app/src/Features/Subscription/SubscriptionHelper.mjs similarity index 96% rename from services/web/app/src/Features/Subscription/SubscriptionHelper.js rename to services/web/app/src/Features/Subscription/SubscriptionHelper.mjs index 74d982c9c9..0a84b28520 100644 --- a/services/web/app/src/Features/Subscription/SubscriptionHelper.js +++ b/services/web/app/src/Features/Subscription/SubscriptionHelper.mjs @@ -1,10 +1,10 @@ // @ts-check -const Settings = require('@overleaf/settings') -const { formatCurrency } = require('../../util/currency') -const GroupPlansData = require('./GroupPlansData') -const { isStandaloneAiAddOnPlanCode } = require('./AiHelper') -const { Subscription } = require('../../models/Subscription') +import Settings from '@overleaf/settings' +import { formatCurrency } from '../../util/currency.js' +import GroupPlansData from './GroupPlansData.js' +import { isStandaloneAiAddOnPlanCode } from './AiHelper.js' +import { Subscription } from '../../models/Subscription.mjs' const MILLISECONDS = 1_000 /** @@ -253,7 +253,7 @@ function getStripeCustomerAdminUrl(customerId, service) { return `${baseUrl}/customers/${customerId}` } -module.exports = { +export default { shouldPlanChangeAtTermEnd, generateInitialLocalizedGroupPrice, isPaidSubscription, diff --git a/services/web/app/src/Features/Subscription/SubscriptionLocator.mjs b/services/web/app/src/Features/Subscription/SubscriptionLocator.mjs index d4aa4477c9..3ded2be604 100644 --- a/services/web/app/src/Features/Subscription/SubscriptionLocator.mjs +++ b/services/web/app/src/Features/Subscription/SubscriptionLocator.mjs @@ -4,9 +4,9 @@ import { callbackifyAll } from '@overleaf/promise-utils' -import { Subscription } from '../../models/Subscription.js' -import SubscriptionHelper from './SubscriptionHelper.js' -import { DeletedSubscription } from '../../models/DeletedSubscription.js' +import { Subscription } from '../../models/Subscription.mjs' +import SubscriptionHelper from './SubscriptionHelper.mjs' +import { DeletedSubscription } from '../../models/DeletedSubscription.mjs' import logger from '@overleaf/logger' import { AI_ADD_ON_CODE, isStandaloneAiAddOnPlanCode } from './AiHelper.js' import './GroupPlansData.js' // make sure dynamic group plans are loaded diff --git a/services/web/app/src/Features/Subscription/SubscriptionUpdater.mjs b/services/web/app/src/Features/Subscription/SubscriptionUpdater.mjs index 39b1cf7025..6936a55634 100644 --- a/services/web/app/src/Features/Subscription/SubscriptionUpdater.mjs +++ b/services/web/app/src/Features/Subscription/SubscriptionUpdater.mjs @@ -1,18 +1,18 @@ import { db, ObjectId } from '../../infrastructure/mongodb.js' import { callbackify } from '@overleaf/promise-utils' -import { Subscription } from '../../models/Subscription.js' +import { Subscription } from '../../models/Subscription.mjs' import SubscriptionLocator from './SubscriptionLocator.mjs' import PlansLocator from './PlansLocator.mjs' import FeaturesUpdater from './FeaturesUpdater.mjs' import FeaturesHelper from './FeaturesHelper.mjs' import AnalyticsManager from '../Analytics/AnalyticsManager.mjs' -import { DeletedSubscription } from '../../models/DeletedSubscription.js' +import { DeletedSubscription } from '../../models/DeletedSubscription.mjs' import logger from '@overleaf/logger' import Features from '../../infrastructure/Features.js' import UserAuditLogHandler from '../User/UserAuditLogHandler.mjs' import UserUpdater from '../User/UserUpdater.mjs' import AccountMappingHelper from '../Analytics/AccountMappingHelper.mjs' -import { SSOConfig } from '../../models/SSOConfig.js' +import { SSOConfig } from '../../models/SSOConfig.mjs' import mongoose from '../../infrastructure/Mongoose.js' import Modules from '../../infrastructure/Modules.js' diff --git a/services/web/app/src/Features/Subscription/SubscriptionViewModelBuilder.mjs b/services/web/app/src/Features/Subscription/SubscriptionViewModelBuilder.mjs index 9fec3a8e5b..b4e67c67e8 100644 --- a/services/web/app/src/Features/Subscription/SubscriptionViewModelBuilder.mjs +++ b/services/web/app/src/Features/Subscription/SubscriptionViewModelBuilder.mjs @@ -12,7 +12,7 @@ import PublishersGetter from '../Publishers/PublishersGetter.mjs' import sanitizeHtml from 'sanitize-html' import _ from 'lodash' import async from 'async' -import SubscriptionHelper from './SubscriptionHelper.js' +import SubscriptionHelper from './SubscriptionHelper.mjs' import { callbackify } from '@overleaf/promise-utils' import { V1ConnectionError } from '../Errors/Errors.js' import FeaturesHelper from './FeaturesHelper.mjs' diff --git a/services/web/app/src/Features/Subscription/TeamInvitesController.mjs b/services/web/app/src/Features/Subscription/TeamInvitesController.mjs index 58c39bda37..76f8a222dc 100644 --- a/services/web/app/src/Features/Subscription/TeamInvitesController.mjs +++ b/services/web/app/src/Features/Subscription/TeamInvitesController.mjs @@ -4,9 +4,9 @@ import OError from '@overleaf/o-error' import TeamInvitesHandler from './TeamInvitesHandler.mjs' import SessionManager from '../Authentication/SessionManager.mjs' import SubscriptionLocator from './SubscriptionLocator.mjs' -import SubscriptionHelper from './SubscriptionHelper.js' +import SubscriptionHelper from './SubscriptionHelper.mjs' import ErrorController from '../Errors/ErrorController.mjs' -import EmailHelper from '../Helpers/EmailHelper.js' +import EmailHelper from '../Helpers/EmailHelper.mjs' import UserGetter from '../User/UserGetter.mjs' import { expressify } from '@overleaf/promise-utils' import HttpErrorHandler from '../Errors/HttpErrorHandler.mjs' diff --git a/services/web/app/src/Features/Subscription/TeamInvitesHandler.mjs b/services/web/app/src/Features/Subscription/TeamInvitesHandler.mjs index e7d0240eb1..477127a0b1 100644 --- a/services/web/app/src/Features/Subscription/TeamInvitesHandler.mjs +++ b/services/web/app/src/Features/Subscription/TeamInvitesHandler.mjs @@ -3,14 +3,14 @@ import crypto from 'node:crypto' import settings from '@overleaf/settings' import Modules from '../../infrastructure/Modules.js' import mongodb from 'mongodb-legacy' -import { Subscription } from '../../models/Subscription.js' -import { SSOConfig } from '../../models/SSOConfig.js' +import { Subscription } from '../../models/Subscription.mjs' +import { SSOConfig } from '../../models/SSOConfig.mjs' import UserGetter from '../User/UserGetter.mjs' import SubscriptionLocator from './SubscriptionLocator.mjs' import SubscriptionUpdater from './SubscriptionUpdater.mjs' import LimitationsManager from './LimitationsManager.mjs' import EmailHandler from '../Email/EmailHandler.mjs' -import EmailHelper from '../Helpers/EmailHelper.js' +import EmailHelper from '../Helpers/EmailHelper.mjs' import Errors from '../Errors/Errors.js' import { callbackify, callbackifyMultiResult } from '@overleaf/promise-utils' import NotificationsBuilder from '../Notifications/NotificationsBuilder.mjs' diff --git a/services/web/app/src/Features/Subscription/UserFeaturesUpdater.mjs b/services/web/app/src/Features/Subscription/UserFeaturesUpdater.mjs index 0fd61c791a..1c96063b8f 100644 --- a/services/web/app/src/Features/Subscription/UserFeaturesUpdater.mjs +++ b/services/web/app/src/Features/Subscription/UserFeaturesUpdater.mjs @@ -1,4 +1,4 @@ -import { User } from '../../models/User.js' +import { User } from '../../models/User.mjs' import { callbackify } from 'node:util' import Settings from '@overleaf/settings' diff --git a/services/web/app/src/Features/Survey/SurveyCache.mjs b/services/web/app/src/Features/Survey/SurveyCache.mjs index d3552c25d7..0c9332dcb4 100644 --- a/services/web/app/src/Features/Survey/SurveyCache.mjs +++ b/services/web/app/src/Features/Survey/SurveyCache.mjs @@ -1,5 +1,5 @@ import SurveyManager from './SurveyManager.mjs' -import { Survey } from '../../models/Survey.js' +import { Survey } from '../../models/Survey.mjs' import { CacheLoader } from 'cache-flow' class SurveyCache extends CacheLoader { diff --git a/services/web/app/src/Features/Survey/SurveyManager.mjs b/services/web/app/src/Features/Survey/SurveyManager.mjs index cbb23ca0fa..6ecea42660 100644 --- a/services/web/app/src/Features/Survey/SurveyManager.mjs +++ b/services/web/app/src/Features/Survey/SurveyManager.mjs @@ -1,4 +1,4 @@ -import { Survey } from '../../models/Survey.js' +import { Survey } from '../../models/Survey.mjs' import OError from '@overleaf/o-error' async function getSurvey() { diff --git a/services/web/app/src/Features/SystemMessages/SystemMessageManager.mjs b/services/web/app/src/Features/SystemMessages/SystemMessageManager.mjs index 0da9e302fe..a664a56fba 100644 --- a/services/web/app/src/Features/SystemMessages/SystemMessageManager.mjs +++ b/services/web/app/src/Features/SystemMessages/SystemMessageManager.mjs @@ -1,4 +1,4 @@ -import { SystemMessage } from '../../models/SystemMessage.js' +import { SystemMessage } from '../../models/SystemMessage.mjs' import { addRequiredCleanupHandlerBeforeDrainingConnections } from '../../infrastructure/GracefulShutdown.js' import { callbackifyAll } from '@overleaf/promise-utils' import logger from '@overleaf/logger' diff --git a/services/web/app/src/Features/Tags/TagsHandler.mjs b/services/web/app/src/Features/Tags/TagsHandler.mjs index 72bf9f79e0..53caadcc68 100644 --- a/services/web/app/src/Features/Tags/TagsHandler.mjs +++ b/services/web/app/src/Features/Tags/TagsHandler.mjs @@ -1,4 +1,4 @@ -import { Tag } from '../../models/Tag.js' +import { Tag } from '../../models/Tag.mjs' import { callbackify } from '@overleaf/promise-utils' const MAX_TAG_LENGTH = 50 diff --git a/services/web/app/src/Features/Templates/TemplatesManager.mjs b/services/web/app/src/Features/Templates/TemplatesManager.mjs index b083cd77c7..aefab9ff13 100644 --- a/services/web/app/src/Features/Templates/TemplatesManager.mjs +++ b/services/web/app/src/Features/Templates/TemplatesManager.mjs @@ -1,4 +1,4 @@ -import { Project } from '../../models/Project.js' +import { Project } from '../../models/Project.mjs' import ProjectDetailsHandler from '../Project/ProjectDetailsHandler.mjs' import ProjectOptionsHandlerModule from '../Project/ProjectOptionsHandler.mjs' import ProjectRootDocManagerModule from '../Project/ProjectRootDocManager.mjs' diff --git a/services/web/app/src/Features/ThirdPartyDataStore/TpdsProjectFlusher.mjs b/services/web/app/src/Features/ThirdPartyDataStore/TpdsProjectFlusher.mjs index fa27faeda4..206682972b 100644 --- a/services/web/app/src/Features/ThirdPartyDataStore/TpdsProjectFlusher.mjs +++ b/services/web/app/src/Features/ThirdPartyDataStore/TpdsProjectFlusher.mjs @@ -3,7 +3,7 @@ import logger from '@overleaf/logger' import DocumentUpdaterHandler from '../DocumentUpdater/DocumentUpdaterHandler.mjs' import ProjectGetter from '../Project/ProjectGetter.mjs' import ProjectEntityHandler from '../Project/ProjectEntityHandler.mjs' -import { Project } from '../../models/Project.js' +import { Project } from '../../models/Project.mjs' import TpdsUpdateSender from './TpdsUpdateSender.mjs' import OError from '@overleaf/o-error' diff --git a/services/web/app/src/Features/ThirdPartyDataStore/TpdsUpdateHandler.mjs b/services/web/app/src/Features/ThirdPartyDataStore/TpdsUpdateHandler.mjs index 85842195d9..599db69109 100644 --- a/services/web/app/src/Features/ThirdPartyDataStore/TpdsUpdateHandler.mjs +++ b/services/web/app/src/Features/ThirdPartyDataStore/TpdsUpdateHandler.mjs @@ -8,7 +8,7 @@ import ProjectGetter from '../Project/ProjectGetter.mjs' import ProjectHelper from '../Project/ProjectHelper.mjs' import ProjectRootDocManager from '../Project/ProjectRootDocManager.mjs' import FileTypeManager from '../Uploads/FileTypeManager.mjs' -import CooldownManager from '../Cooldown/CooldownManager.js' +import CooldownManager from '../Cooldown/CooldownManager.mjs' import Errors from '../Errors/Errors.js' import Modules from '../../infrastructure/Modules.js' diff --git a/services/web/app/src/Features/TokenAccess/TokenAccessHandler.mjs b/services/web/app/src/Features/TokenAccess/TokenAccessHandler.mjs index 05b350f789..88d643707f 100644 --- a/services/web/app/src/Features/TokenAccess/TokenAccessHandler.mjs +++ b/services/web/app/src/Features/TokenAccess/TokenAccessHandler.mjs @@ -1,4 +1,4 @@ -import { Project } from '../../models/Project.js' +import { Project } from '../../models/Project.mjs' import PublicAccessLevels from '../Authorization/PublicAccessLevels.mjs' import PrivilegeLevels from '../Authorization/PrivilegeLevels.js' import mongodb from 'mongodb-legacy' diff --git a/services/web/app/src/Features/Uploads/ProjectUploadManager.mjs b/services/web/app/src/Features/Uploads/ProjectUploadManager.mjs index 4e658903d6..c1fce8f934 100644 --- a/services/web/app/src/Features/Uploads/ProjectUploadManager.mjs +++ b/services/web/app/src/Features/Uploads/ProjectUploadManager.mjs @@ -2,7 +2,7 @@ import Path from 'node:path' import fs from 'node:fs' import { callbackify } from 'node:util' import ArchiveManager from './ArchiveManager.mjs' -import { Doc } from '../../models/Doc.js' +import { Doc } from '../../models/Doc.mjs' import DocstoreManager from '../Docstore/DocstoreManager.mjs' import DocumentHelper from '../Documents/DocumentHelper.mjs' import DocumentUpdaterHandler from '../DocumentUpdater/DocumentUpdaterHandler.mjs' diff --git a/services/web/app/src/Features/User/SAMLIdentityManager.mjs b/services/web/app/src/Features/User/SAMLIdentityManager.mjs index 3d8e84a467..dd14a29fc2 100644 --- a/services/web/app/src/Features/User/SAMLIdentityManager.mjs +++ b/services/web/app/src/Features/User/SAMLIdentityManager.mjs @@ -9,7 +9,7 @@ import UserAuditLogHandler from '../User/UserAuditLogHandler.mjs' import UserGetter from '../User/UserGetter.mjs' import UserUpdater from '../User/UserUpdater.mjs' import logger from '@overleaf/logger' -import { User } from '../../models/User.js' +import { User } from '../../models/User.mjs' import { promiseMapWithLimit } from '@overleaf/promise-utils' const { ObjectId } = mongodb diff --git a/services/web/app/src/Features/User/ThirdPartyIdentityManager.mjs b/services/web/app/src/Features/User/ThirdPartyIdentityManager.mjs index 65f3fa62c5..5da2254d31 100644 --- a/services/web/app/src/Features/User/ThirdPartyIdentityManager.mjs +++ b/services/web/app/src/Features/User/ThirdPartyIdentityManager.mjs @@ -5,7 +5,7 @@ import Errors from '../Errors/Errors.js' import _ from 'lodash' import logger from '@overleaf/logger' import settings from '@overleaf/settings' -import { User } from '../../../../app/src/models/User.js' +import { User } from '../../../../app/src/models/User.mjs' import { callbackify } from '@overleaf/promise-utils' import OError from '@overleaf/o-error' diff --git a/services/web/app/src/Features/User/UserAuditLogHandler.mjs b/services/web/app/src/Features/User/UserAuditLogHandler.mjs index a617231f43..919dc30d8a 100644 --- a/services/web/app/src/Features/User/UserAuditLogHandler.mjs +++ b/services/web/app/src/Features/User/UserAuditLogHandler.mjs @@ -1,6 +1,6 @@ import OError from '@overleaf/o-error' import logger from '@overleaf/logger' -import { UserAuditLogEntry } from '../../models/UserAuditLogEntry.js' +import { UserAuditLogEntry } from '../../models/UserAuditLogEntry.mjs' import { callbackify } from 'node:util' import SubscriptionLocator from '../Subscription/SubscriptionLocator.mjs' diff --git a/services/web/app/src/Features/User/UserController.mjs b/services/web/app/src/Features/User/UserController.mjs index a66fedbbb7..9a21c494d1 100644 --- a/services/web/app/src/Features/User/UserController.mjs +++ b/services/web/app/src/Features/User/UserController.mjs @@ -1,7 +1,7 @@ import UserHandler from './UserHandler.mjs' import UserDeleter from './UserDeleter.mjs' import UserGetter from './UserGetter.mjs' -import { User } from '../../models/User.js' +import { User } from '../../models/User.mjs' import NewsletterManager from '../Newsletter/NewsletterManager.mjs' import logger from '@overleaf/logger' import metrics from '@overleaf/metrics' @@ -21,7 +21,7 @@ import { promisify } from 'node:util' import { expressify } from '@overleaf/promise-utils' import { acceptsJson } from '../../infrastructure/RequestContentTypeDetection.js' import Modules from '../../infrastructure/Modules.js' -import OneTimeTokenHandler from '../Security/OneTimeTokenHandler.js' +import OneTimeTokenHandler from '../Security/OneTimeTokenHandler.mjs' async function _sendSecurityAlertClearedSessions(user) { const emailOptions = { diff --git a/services/web/app/src/Features/User/UserCreator.mjs b/services/web/app/src/Features/User/UserCreator.mjs index a5604f1f52..08ed98b455 100644 --- a/services/web/app/src/Features/User/UserCreator.mjs +++ b/services/web/app/src/Features/User/UserCreator.mjs @@ -2,7 +2,7 @@ import logger from '@overleaf/logger' import util from 'node:util' import { AffiliationError } from '../Errors/Errors.js' import Features from '../../infrastructure/Features.js' -import { User } from '../../models/User.js' +import { User } from '../../models/User.mjs' import UserDeleter from './UserDeleter.mjs' import UserGetter from './UserGetter.mjs' import UserUpdater from './UserUpdater.mjs' diff --git a/services/web/app/src/Features/User/UserDeleter.mjs b/services/web/app/src/Features/User/UserDeleter.mjs index d3657a8696..60704ae572 100644 --- a/services/web/app/src/Features/User/UserDeleter.mjs +++ b/services/web/app/src/Features/User/UserDeleter.mjs @@ -1,10 +1,10 @@ import { callbackify } from 'node:util' import logger from '@overleaf/logger' import Settings from '@overleaf/settings' -import { User } from '../../models/User.js' -import { DeletedUser } from '../../models/DeletedUser.js' -import { UserAuditLogEntry } from '../../models/UserAuditLogEntry.js' -import { Feedback } from '../../models/Feedback.js' +import { User } from '../../models/User.mjs' +import { DeletedUser } from '../../models/DeletedUser.mjs' +import { UserAuditLogEntry } from '../../models/UserAuditLogEntry.mjs' +import { Feedback } from '../../models/Feedback.mjs' import NewsletterManager from '../Newsletter/NewsletterManager.mjs' import ProjectDeleter from '../Project/ProjectDeleter.mjs' import SubscriptionHandler from '../Subscription/SubscriptionHandler.mjs' diff --git a/services/web/app/src/Features/User/UserEmailsConfirmationHandler.mjs b/services/web/app/src/Features/User/UserEmailsConfirmationHandler.mjs index e85cca3a80..444b4dda56 100644 --- a/services/web/app/src/Features/User/UserEmailsConfirmationHandler.mjs +++ b/services/web/app/src/Features/User/UserEmailsConfirmationHandler.mjs @@ -1,6 +1,6 @@ -import EmailHelper from '../Helpers/EmailHelper.js' +import EmailHelper from '../Helpers/EmailHelper.mjs' import EmailHandler from '../Email/EmailHandler.mjs' -import OneTimeTokenHandler from '../Security/OneTimeTokenHandler.js' +import OneTimeTokenHandler from '../Security/OneTimeTokenHandler.mjs' import settings from '@overleaf/settings' import Errors from '../Errors/Errors.js' import UserUpdater from './UserUpdater.mjs' diff --git a/services/web/app/src/Features/User/UserEmailsController.mjs b/services/web/app/src/Features/User/UserEmailsController.mjs index c63ce4cdd3..0a30410740 100644 --- a/services/web/app/src/Features/User/UserEmailsController.mjs +++ b/services/web/app/src/Features/User/UserEmailsController.mjs @@ -6,7 +6,7 @@ import UserGetter from './UserGetter.mjs' import UserUpdater from './UserUpdater.mjs' import UserSessionsManager from './UserSessionsManager.mjs' import EmailHandler from '../Email/EmailHandler.mjs' -import EmailHelper from '../Helpers/EmailHelper.js' +import EmailHelper from '../Helpers/EmailHelper.mjs' import UserEmailsConfirmationHandler from './UserEmailsConfirmationHandler.mjs' import InstitutionsAPI from '../Institutions/InstitutionsAPI.mjs' import Errors from '../Errors/Errors.js' diff --git a/services/web/app/src/Features/User/UserGetter.mjs b/services/web/app/src/Features/User/UserGetter.mjs index d2cbda1441..c8bce40136 100644 --- a/services/web/app/src/Features/User/UserGetter.mjs +++ b/services/web/app/src/Features/User/UserGetter.mjs @@ -6,7 +6,7 @@ import InstitutionsAPI from '../Institutions/InstitutionsAPI.mjs' import InstitutionsHelper from '../Institutions/InstitutionsHelper.mjs' import Errors from '../Errors/Errors.js' import Features from '../../infrastructure/Features.js' -import { User } from '../../models/User.js' +import { User } from '../../models/User.mjs' import { normalizeQuery, normalizeMultiQuery } from '../Helpers/Mongo.js' import Modules from '../../infrastructure/Modules.js' import FeaturesHelper from '../Subscription/FeaturesHelper.mjs' diff --git a/services/web/app/src/Features/User/UserRegistrationHandler.mjs b/services/web/app/src/Features/User/UserRegistrationHandler.mjs index d01be0acf7..5e77955da2 100644 --- a/services/web/app/src/Features/User/UserRegistrationHandler.mjs +++ b/services/web/app/src/Features/User/UserRegistrationHandler.mjs @@ -1,4 +1,4 @@ -import { User } from '../../models/User.js' +import { User } from '../../models/User.mjs' import UserCreator from './UserCreator.mjs' import UserGetter from './UserGetter.mjs' import AuthenticationManager from '../Authentication/AuthenticationManager.mjs' @@ -6,9 +6,9 @@ import NewsletterManager from '../Newsletter/NewsletterManager.mjs' import logger from '@overleaf/logger' import crypto from 'node:crypto' import EmailHandler from '../Email/EmailHandler.mjs' -import OneTimeTokenHandler from '../Security/OneTimeTokenHandler.js' +import OneTimeTokenHandler from '../Security/OneTimeTokenHandler.mjs' import settings from '@overleaf/settings' -import EmailHelper from '../Helpers/EmailHelper.js' +import EmailHelper from '../Helpers/EmailHelper.mjs' import { callbackify, callbackifyMultiResult } from '@overleaf/promise-utils' import OError from '@overleaf/o-error' diff --git a/services/web/app/src/Features/User/UserUpdater.mjs b/services/web/app/src/Features/User/UserUpdater.mjs index 7356790d86..f45b0456d2 100644 --- a/services/web/app/src/Features/User/UserUpdater.mjs +++ b/services/web/app/src/Features/User/UserUpdater.mjs @@ -8,7 +8,7 @@ import InstitutionsAPI from '../Institutions/InstitutionsAPI.mjs' import Features from '../../infrastructure/Features.js' import FeaturesUpdater from '../Subscription/FeaturesUpdater.mjs' import EmailHandler from '../Email/EmailHandler.mjs' -import EmailHelper from '../Helpers/EmailHelper.js' +import EmailHelper from '../Helpers/EmailHelper.mjs' import Errors from '../Errors/Errors.js' import NewsletterManager from '../Newsletter/NewsletterManager.mjs' import UserAuditLogHandler from './UserAuditLogHandler.mjs' diff --git a/services/web/app/src/Features/UserMembership/UserMembershipController.mjs b/services/web/app/src/Features/UserMembership/UserMembershipController.mjs index 257dd8ae2c..381299d910 100644 --- a/services/web/app/src/Features/UserMembership/UserMembershipController.mjs +++ b/services/web/app/src/Features/UserMembership/UserMembershipController.mjs @@ -1,10 +1,10 @@ import SessionManager from '../Authentication/SessionManager.mjs' import UserMembershipHandler from './UserMembershipHandler.mjs' import Errors from '../Errors/Errors.js' -import EmailHelper from '../Helpers/EmailHelper.js' +import EmailHelper from '../Helpers/EmailHelper.mjs' import { csvAttachment } from '../../infrastructure/Response.js' import UserMembershipErrors from './UserMembershipErrors.mjs' -import { SSOConfig } from '../../models/SSOConfig.js' +import { SSOConfig } from '../../models/SSOConfig.mjs' import { Parser as CSVParser } from 'json2csv' import { expressify } from '@overleaf/promise-utils' import PlansLocator from '../Subscription/PlansLocator.mjs' diff --git a/services/web/app/src/Features/UserMembership/UserMembershipHandler.mjs b/services/web/app/src/Features/UserMembership/UserMembershipHandler.mjs index 6e170f3e6b..f34937df82 100644 --- a/services/web/app/src/Features/UserMembership/UserMembershipHandler.mjs +++ b/services/web/app/src/Features/UserMembership/UserMembershipHandler.mjs @@ -1,8 +1,8 @@ import mongodb from 'mongodb-legacy' import { callbackify } from '@overleaf/promise-utils' -import { Institution } from '../../models/Institution.js' -import { Subscription } from '../../models/Subscription.js' -import { Publisher } from '../../models/Publisher.js' +import { Institution } from '../../models/Institution.mjs' +import { Subscription } from '../../models/Subscription.mjs' +import { Publisher } from '../../models/Publisher.mjs' import UserMembershipViewModel from './UserMembershipViewModel.mjs' import UserGetter from '../User/UserGetter.mjs' import UserMembershipErrors from './UserMembershipErrors.mjs' diff --git a/services/web/app/src/Features/UserMembership/UserMembershipsHandler.mjs b/services/web/app/src/Features/UserMembership/UserMembershipsHandler.mjs index 3e5239cdae..fc1c6d0b8e 100644 --- a/services/web/app/src/Features/UserMembership/UserMembershipsHandler.mjs +++ b/services/web/app/src/Features/UserMembership/UserMembershipsHandler.mjs @@ -13,9 +13,9 @@ import async from 'async' import { promisifyAll } from '@overleaf/promise-utils' import UserMembershipEntityConfigs from './UserMembershipEntityConfigs.mjs' -import InstitutionModel from '../../models/Institution.js' -import SubscriptionModel from '../../models/Subscription.js' -import PublisherModel from '../../models/Publisher.js' +import * as InstitutionModel from '../../models/Institution.mjs' +import * as SubscriptionModel from '../../models/Subscription.mjs' +import * as PublisherModel from '../../models/Publisher.mjs' const EntityModels = { Institution: InstitutionModel.Institution, diff --git a/services/web/app/src/models/DeletedProject.js b/services/web/app/src/models/DeletedProject.mjs similarity index 79% rename from services/web/app/src/models/DeletedProject.js rename to services/web/app/src/models/DeletedProject.mjs index c1f6ce9e2c..652c052849 100644 --- a/services/web/app/src/models/DeletedProject.js +++ b/services/web/app/src/models/DeletedProject.mjs @@ -1,10 +1,10 @@ -const mongoose = require('../infrastructure/Mongoose') -const { ProjectSchema } = require('./Project') +import mongoose from '../infrastructure/Mongoose.js' +import { ProjectSchema } from './Project.mjs' const { Schema } = mongoose const { ObjectId } = Schema -const DeleterDataSchema = new Schema({ +export const DeleterDataSchema = new Schema({ deleterId: { type: ObjectId, ref: 'User' }, deleterIpAddress: { type: String }, deletedAt: { type: Date }, @@ -30,5 +30,7 @@ const DeletedProjectSchema = new Schema( { collection: 'deletedProjects', minimize: false } ) -exports.DeletedProject = mongoose.model('DeletedProject', DeletedProjectSchema) -exports.DeletedProjectSchema = DeletedProjectSchema +export const DeletedProject = mongoose.model( + 'DeletedProject', + DeletedProjectSchema +) diff --git a/services/web/app/src/models/DeletedSubscription.js b/services/web/app/src/models/DeletedSubscription.mjs similarity index 66% rename from services/web/app/src/models/DeletedSubscription.js rename to services/web/app/src/models/DeletedSubscription.mjs index 10b649d9be..b37d2f1ea6 100644 --- a/services/web/app/src/models/DeletedSubscription.js +++ b/services/web/app/src/models/DeletedSubscription.mjs @@ -1,10 +1,10 @@ -const mongoose = require('../infrastructure/Mongoose') -const { SubscriptionSchema } = require('./Subscription') +import mongoose from '../infrastructure/Mongoose.js' +import { SubscriptionSchema } from './Subscription.mjs' const { Schema } = mongoose const { ObjectId } = Schema -const DeleterDataSchema = new Schema( +export const DeleterDataSchema = new Schema( { deleterId: { type: ObjectId, ref: 'User' }, deleterIpAddress: { type: String }, @@ -26,9 +26,7 @@ const DeletedSubscriptionSchema = new Schema( { collection: 'deletedSubscriptions', minimize: false } ) -exports.DeletedSubscription = mongoose.model( +export const DeletedSubscription = mongoose.model( 'DeletedSubscription', DeletedSubscriptionSchema ) - -exports.DeletedSubscriptionSchema = DeletedSubscriptionSchema diff --git a/services/web/app/src/models/DeletedUser.js b/services/web/app/src/models/DeletedUser.mjs similarity index 73% rename from services/web/app/src/models/DeletedUser.js rename to services/web/app/src/models/DeletedUser.mjs index 5d20f9bb40..17f221c3ce 100644 --- a/services/web/app/src/models/DeletedUser.js +++ b/services/web/app/src/models/DeletedUser.mjs @@ -1,5 +1,5 @@ -const mongoose = require('../infrastructure/Mongoose') -const { UserSchema } = require('./User') +import mongoose from '../infrastructure/Mongoose.js' +import { UserSchema } from './User.mjs' const { Schema } = mongoose const { ObjectId } = Schema @@ -18,7 +18,7 @@ const DeleterDataSchema = new Schema({ deletedUserOverleafId: { type: Number }, }) -const DeletedUserSchema = new Schema( +export const DeletedUserSchema = new Schema( { deleterData: DeleterDataSchema, user: UserSchema, @@ -26,6 +26,4 @@ const DeletedUserSchema = new Schema( { collection: 'deletedUsers', minimize: false } ) -exports.DeletedUser = mongoose.model('DeletedUser', DeletedUserSchema) - -exports.DeletedUserSchema = DeletedUserSchema +export const DeletedUser = mongoose.model('DeletedUser', DeletedUserSchema) diff --git a/services/web/app/src/models/Doc.js b/services/web/app/src/models/Doc.js deleted file mode 100644 index 9f38ac0975..0000000000 --- a/services/web/app/src/models/Doc.js +++ /dev/null @@ -1,14 +0,0 @@ -const mongoose = require('../infrastructure/Mongoose') - -const { Schema } = mongoose - -const DocSchema = new Schema( - { - name: { type: String, default: 'new doc' }, - }, - { minimize: false } -) - -exports.Doc = mongoose.model('Doc', DocSchema) - -exports.DocSchema = DocSchema diff --git a/services/web/app/src/models/Doc.mjs b/services/web/app/src/models/Doc.mjs new file mode 100644 index 0000000000..c06ff3b775 --- /dev/null +++ b/services/web/app/src/models/Doc.mjs @@ -0,0 +1,12 @@ +import mongoose from '../infrastructure/Mongoose.js' + +const { Schema } = mongoose + +export const DocSchema = new Schema( + { + name: { type: String, default: 'new doc' }, + }, + { minimize: false } +) + +export const Doc = mongoose.model('Doc', DocSchema) diff --git a/services/web/app/src/models/DocSnapshot.js b/services/web/app/src/models/DocSnapshot.mjs similarity index 70% rename from services/web/app/src/models/DocSnapshot.js rename to services/web/app/src/models/DocSnapshot.mjs index b851d4a94f..0a5793f818 100644 --- a/services/web/app/src/models/DocSnapshot.js +++ b/services/web/app/src/models/DocSnapshot.mjs @@ -1,4 +1,4 @@ -const mongoose = require('../infrastructure/Mongoose') +import mongoose from '../infrastructure/Mongoose.js' const { Schema } = mongoose @@ -15,4 +15,4 @@ const DocSnapshotSchema = new Schema( { collection: 'docSnapshots', minimize: false } ) -exports.DocSnapshot = mongoose.model('DocSnapshot', DocSnapshotSchema) +export const DocSnapshot = mongoose.model('DocSnapshot', DocSnapshotSchema) diff --git a/services/web/app/src/models/Feedback.js b/services/web/app/src/models/Feedback.mjs similarity index 59% rename from services/web/app/src/models/Feedback.js rename to services/web/app/src/models/Feedback.mjs index 8b6382114f..ef583a0ac9 100644 --- a/services/web/app/src/models/Feedback.js +++ b/services/web/app/src/models/Feedback.mjs @@ -1,8 +1,8 @@ -const mongoose = require('../infrastructure/Mongoose') +import mongoose from '../infrastructure/Mongoose.js' const { Schema } = mongoose const { ObjectId } = Schema -const FeedbackSchema = new Schema( +export const FeedbackSchema = new Schema( { userId: { type: ObjectId, @@ -20,5 +20,4 @@ const FeedbackSchema = new Schema( { minimize: false } ) -exports.Feedback = mongoose.model('Feedback', FeedbackSchema) -exports.FeedbackSchema = FeedbackSchema +export const Feedback = mongoose.model('Feedback', FeedbackSchema) diff --git a/services/web/app/src/models/File.js b/services/web/app/src/models/File.mjs similarity index 67% rename from services/web/app/src/models/File.js rename to services/web/app/src/models/File.mjs index 5a7c772e3e..60742e6797 100644 --- a/services/web/app/src/models/File.js +++ b/services/web/app/src/models/File.mjs @@ -1,8 +1,8 @@ -const mongoose = require('../infrastructure/Mongoose') +import mongoose from '../infrastructure/Mongoose.js' const { Schema } = mongoose -const FileSchema = new Schema( +export const FileSchema = new Schema( { name: { type: String, @@ -23,5 +23,4 @@ const FileSchema = new Schema( { minimize: false } ) -exports.File = mongoose.model('File', FileSchema) -exports.FileSchema = FileSchema +export const File = mongoose.model('File', FileSchema) diff --git a/services/web/app/src/models/Folder.js b/services/web/app/src/models/Folder.js deleted file mode 100644 index 52312e90d8..0000000000 --- a/services/web/app/src/models/Folder.js +++ /dev/null @@ -1,21 +0,0 @@ -const mongoose = require('../infrastructure/Mongoose') -const { DocSchema } = require('./Doc') -const { FileSchema } = require('./File') - -const { Schema } = mongoose - -const FolderSchema = new Schema( - { - name: { type: String, default: 'new folder' }, - }, - { minimize: false } -) - -FolderSchema.add({ - docs: [DocSchema], - fileRefs: [FileSchema], - folders: [FolderSchema], -}) - -exports.Folder = mongoose.model('Folder', FolderSchema) -exports.FolderSchema = FolderSchema diff --git a/services/web/app/src/models/Folder.mjs b/services/web/app/src/models/Folder.mjs new file mode 100644 index 0000000000..7ac893f868 --- /dev/null +++ b/services/web/app/src/models/Folder.mjs @@ -0,0 +1,20 @@ +import mongoose from '../infrastructure/Mongoose.js' +import { DocSchema } from './Doc.mjs' +import { FileSchema } from './File.mjs' + +const { Schema } = mongoose + +export const FolderSchema = new Schema( + { + name: { type: String, default: 'new folder' }, + }, + { minimize: false } +) + +FolderSchema.add({ + docs: [DocSchema], + fileRefs: [FileSchema], + folders: [FolderSchema], +}) + +export const Folder = mongoose.model('Folder', FolderSchema) diff --git a/services/web/app/src/models/GlobalMetric.js b/services/web/app/src/models/GlobalMetric.js deleted file mode 100644 index 824c1478a2..0000000000 --- a/services/web/app/src/models/GlobalMetric.js +++ /dev/null @@ -1,19 +0,0 @@ -const mongoose = require('../infrastructure/Mongoose') -const { Schema } = mongoose - -const GlobalMetricSchema = new Schema( - { - _id: { type: String, required: true }, - value: { - type: Number, - default: 0, - }, - }, - { - collection: 'globalMetrics', - minimize: false, - } -) - -exports.GlobalMetric = mongoose.model('GlobalMetric', GlobalMetricSchema) -exports.GlobalMetricSchema = GlobalMetricSchema diff --git a/services/web/app/src/models/GlobalMetric.mjs b/services/web/app/src/models/GlobalMetric.mjs new file mode 100644 index 0000000000..de019d40b2 --- /dev/null +++ b/services/web/app/src/models/GlobalMetric.mjs @@ -0,0 +1,18 @@ +import mongoose from '../infrastructure/Mongoose.js' +const { Schema } = mongoose + +export const GlobalMetricSchema = new Schema( + { + _id: { type: String, required: true }, + value: { + type: Number, + default: 0, + }, + }, + { + collection: 'globalMetrics', + minimize: false, + } +) + +export const GlobalMetric = mongoose.model('GlobalMetric', GlobalMetricSchema) diff --git a/services/web/app/src/models/GroupAuditLogEntry.js b/services/web/app/src/models/GroupAuditLogEntry.mjs similarity index 66% rename from services/web/app/src/models/GroupAuditLogEntry.js rename to services/web/app/src/models/GroupAuditLogEntry.mjs index 3bda4ebf95..5d834df350 100644 --- a/services/web/app/src/models/GroupAuditLogEntry.js +++ b/services/web/app/src/models/GroupAuditLogEntry.mjs @@ -1,7 +1,7 @@ -const mongoose = require('../infrastructure/Mongoose') +import mongoose from '../infrastructure/Mongoose.js' const { Schema } = mongoose -const GroupAuditLogEntrySchema = new Schema( +export const GroupAuditLogEntrySchema = new Schema( { groupId: { type: Schema.Types.ObjectId, index: true }, info: { type: Object }, @@ -16,8 +16,7 @@ const GroupAuditLogEntrySchema = new Schema( } ) -exports.GroupAuditLogEntry = mongoose.model( +export const GroupAuditLogEntry = mongoose.model( 'GroupAuditLogEntry', GroupAuditLogEntrySchema ) -exports.GroupAuditLogEntrySchema = GroupAuditLogEntrySchema diff --git a/services/web/app/src/models/GroupPolicy.js b/services/web/app/src/models/GroupPolicy.mjs similarity index 83% rename from services/web/app/src/models/GroupPolicy.js rename to services/web/app/src/models/GroupPolicy.mjs index 55728a2415..c38488aa63 100644 --- a/services/web/app/src/models/GroupPolicy.js +++ b/services/web/app/src/models/GroupPolicy.mjs @@ -1,8 +1,8 @@ -const mongoose = require('../infrastructure/Mongoose') +import mongoose from '../infrastructure/Mongoose.js' const { Schema } = mongoose -const GroupPolicySchema = new Schema( +export const GroupPolicySchema = new Schema( { // User can't delete their own account userCannotDeleteOwnAccount: Boolean, @@ -34,5 +34,4 @@ const GroupPolicySchema = new Schema( { minimize: false } ) -exports.GroupPolicy = mongoose.model('GroupPolicy', GroupPolicySchema) -exports.GroupPolicySchema = GroupPolicySchema +export const GroupPolicy = mongoose.model('GroupPolicy', GroupPolicySchema) diff --git a/services/web/app/src/models/Institution.js b/services/web/app/src/models/Institution.mjs similarity index 76% rename from services/web/app/src/models/Institution.js rename to services/web/app/src/models/Institution.mjs index fd18cf33c2..a51dbd3f0b 100644 --- a/services/web/app/src/models/Institution.js +++ b/services/web/app/src/models/Institution.mjs @@ -1,12 +1,12 @@ -const mongoose = require('../infrastructure/Mongoose') +import mongoose from '../infrastructure/Mongoose.js' +import settings from '@overleaf/settings' +import logger from '@overleaf/logger' +import { promisify } from '@overleaf/promise-utils' +import { fetchJson } from '@overleaf/fetch-utils' const { Schema } = mongoose const { ObjectId } = Schema -const settings = require('@overleaf/settings') -const logger = require('@overleaf/logger') -const { promisify } = require('@overleaf/promise-utils') -const { fetchJson } = require('@overleaf/fetch-utils') -const InstitutionSchema = new Schema( +export const InstitutionSchema = new Schema( { v1Id: { type: Number, required: true }, managerIds: [{ type: ObjectId, ref: 'User' }], @@ -45,5 +45,4 @@ InstitutionSchema.method( promisify(InstitutionSchema.methods.fetchV1Data) ) -exports.Institution = mongoose.model('Institution', InstitutionSchema) -exports.InstitutionSchema = InstitutionSchema +export const Institution = mongoose.model('Institution', InstitutionSchema) diff --git a/services/web/app/src/models/OauthAccessToken.js b/services/web/app/src/models/OauthAccessToken.mjs similarity index 73% rename from services/web/app/src/models/OauthAccessToken.js rename to services/web/app/src/models/OauthAccessToken.mjs index 8b3dbc8926..d3a9edc9fe 100644 --- a/services/web/app/src/models/OauthAccessToken.js +++ b/services/web/app/src/models/OauthAccessToken.mjs @@ -1,9 +1,9 @@ -const mongoose = require('../infrastructure/Mongoose') +import mongoose from '../infrastructure/Mongoose.js' const { Schema } = mongoose const { ObjectId } = Schema -const OauthAccessTokenSchema = new Schema( +export const OauthAccessTokenSchema = new Schema( { accessToken: String, accessTokenPartial: String, @@ -24,9 +24,7 @@ const OauthAccessTokenSchema = new Schema( } ) -exports.OauthAccessToken = mongoose.model( +export const OauthAccessToken = mongoose.model( 'OauthAccessToken', OauthAccessTokenSchema ) - -exports.OauthAccessTokenSchema = OauthAccessTokenSchema diff --git a/services/web/app/src/models/OauthApplication.js b/services/web/app/src/models/OauthApplication.mjs similarity index 61% rename from services/web/app/src/models/OauthApplication.js rename to services/web/app/src/models/OauthApplication.mjs index d7bd181fd6..83ff51fa55 100644 --- a/services/web/app/src/models/OauthApplication.js +++ b/services/web/app/src/models/OauthApplication.mjs @@ -1,8 +1,8 @@ -const mongoose = require('../infrastructure/Mongoose') +import mongoose from '../infrastructure/Mongoose.js' const { Schema } = mongoose -const OauthApplicationSchema = new Schema( +export const OauthApplicationSchema = new Schema( { id: String, clientSecret: String, @@ -18,9 +18,7 @@ const OauthApplicationSchema = new Schema( } ) -exports.OauthApplication = mongoose.model( +export const OauthApplication = mongoose.model( 'OauthApplication', OauthApplicationSchema ) - -exports.OauthApplicationSchema = OauthApplicationSchema diff --git a/services/web/app/src/models/OauthAuthorizationCode.js b/services/web/app/src/models/OauthAuthorizationCode.mjs similarity index 68% rename from services/web/app/src/models/OauthAuthorizationCode.js rename to services/web/app/src/models/OauthAuthorizationCode.mjs index 6b9822377f..9750750f1a 100644 --- a/services/web/app/src/models/OauthAuthorizationCode.js +++ b/services/web/app/src/models/OauthAuthorizationCode.mjs @@ -1,9 +1,9 @@ -const mongoose = require('../infrastructure/Mongoose') +import mongoose from '../infrastructure/Mongoose.js' const { Schema } = mongoose const { ObjectId } = Schema -const OauthAuthorizationCodeSchema = new Schema( +export const OauthAuthorizationCodeSchema = new Schema( { authorizationCode: String, expiresAt: Date, @@ -20,9 +20,7 @@ const OauthAuthorizationCodeSchema = new Schema( } ) -exports.OauthAuthorizationCode = mongoose.model( +export const OauthAuthorizationCode = mongoose.model( 'OauthAuthorizationCode', OauthAuthorizationCodeSchema ) - -exports.OauthAuthorizationCodeSchema = OauthAuthorizationCodeSchema diff --git a/services/web/app/src/models/OnboardingDataCollection.js b/services/web/app/src/models/OnboardingDataCollection.mjs similarity index 76% rename from services/web/app/src/models/OnboardingDataCollection.js rename to services/web/app/src/models/OnboardingDataCollection.mjs index e0625f71fc..edab377914 100644 --- a/services/web/app/src/models/OnboardingDataCollection.js +++ b/services/web/app/src/models/OnboardingDataCollection.mjs @@ -1,7 +1,7 @@ -const mongoose = require('../infrastructure/Mongoose') +import mongoose from '../infrastructure/Mongoose.js' const { Schema } = mongoose -const OnboardingDataCollectionSchema = new Schema( +export const OnboardingDataCollectionSchema = new Schema( { firstName: { type: String, default: null }, lastName: { type: String, default: null }, @@ -24,10 +24,12 @@ const OnboardingDataCollectionSchema = new Schema( } ) -module.exports = { - OnboardingDataCollection: mongoose.model( - 'OnboardingDataCollection', - OnboardingDataCollectionSchema - ), +export const OnboardingDataCollection = mongoose.model( + 'OnboardingDataCollection', + OnboardingDataCollectionSchema +) + +export default { + OnboardingDataCollection, OnboardingDataCollectionSchema, } diff --git a/services/web/app/src/models/Project.js b/services/web/app/src/models/Project.mjs similarity index 92% rename from services/web/app/src/models/Project.js rename to services/web/app/src/models/Project.mjs index 69db145038..fec4769008 100644 --- a/services/web/app/src/models/Project.js +++ b/services/web/app/src/models/Project.mjs @@ -1,7 +1,7 @@ -const mongoose = require('../infrastructure/Mongoose') -const _ = require('lodash') -const { FolderSchema } = require('./Folder') -const Errors = require('../Features/Errors/Errors') +import mongoose from '../infrastructure/Mongoose.js' +import _ from 'lodash' +import { FolderSchema } from './Folder.mjs' +import Errors from '../Features/Errors/Errors.js' const ConcreteObjectId = mongoose.Types.ObjectId const { Schema } = mongoose @@ -12,7 +12,7 @@ const DeletedDocSchema = new Schema({ deletedAt: { type: Date }, }) -const ProjectSchema = new Schema( +export const ProjectSchema = new Schema( { name: { type: String, default: 'new project' }, lastUpdated: { @@ -127,5 +127,4 @@ function applyToAllFilesRecursivly(folder, fun) { } ProjectSchema.statics.applyToAllFilesRecursivly = applyToAllFilesRecursivly -exports.Project = mongoose.model('Project', ProjectSchema) -exports.ProjectSchema = ProjectSchema +export const Project = mongoose.model('Project', ProjectSchema) diff --git a/services/web/app/src/models/ProjectAuditLogEntry.js b/services/web/app/src/models/ProjectAuditLogEntry.mjs similarity index 70% rename from services/web/app/src/models/ProjectAuditLogEntry.js rename to services/web/app/src/models/ProjectAuditLogEntry.mjs index fb4a950a40..7e668a60e3 100644 --- a/services/web/app/src/models/ProjectAuditLogEntry.js +++ b/services/web/app/src/models/ProjectAuditLogEntry.mjs @@ -1,7 +1,7 @@ -const mongoose = require('../infrastructure/Mongoose') +import mongoose from '../infrastructure/Mongoose.js' const { Schema } = mongoose -const ProjectAuditLogEntrySchema = new Schema( +export const ProjectAuditLogEntrySchema = new Schema( { projectId: { type: Schema.Types.ObjectId, index: true }, managedSubscriptionId: { type: Schema.Types.ObjectId, index: true }, @@ -17,8 +17,7 @@ const ProjectAuditLogEntrySchema = new Schema( } ) -exports.ProjectAuditLogEntry = mongoose.model( +export const ProjectAuditLogEntry = mongoose.model( 'ProjectAuditLogEntry', ProjectAuditLogEntrySchema ) -exports.ProjectAuditLogEntrySchema = ProjectAuditLogEntrySchema diff --git a/services/web/app/src/models/ProjectHistoryFailure.js b/services/web/app/src/models/ProjectHistoryFailure.mjs similarity index 80% rename from services/web/app/src/models/ProjectHistoryFailure.js rename to services/web/app/src/models/ProjectHistoryFailure.mjs index 7bfd1a3d85..f584945ce5 100644 --- a/services/web/app/src/models/ProjectHistoryFailure.js +++ b/services/web/app/src/models/ProjectHistoryFailure.mjs @@ -1,4 +1,4 @@ -const mongoose = require('../infrastructure/Mongoose') +import mongoose from '../infrastructure/Mongoose.js' const { Schema } = mongoose @@ -18,7 +18,7 @@ const ProjectHistoryFailureSchema = new Schema( { collection: 'projectHistoryFailures', minimize: false } ) -exports.ProjectHistoryFailure = mongoose.model( +export const ProjectHistoryFailure = mongoose.model( 'ProjectHistoryFailure', ProjectHistoryFailureSchema ) diff --git a/services/web/app/src/models/ProjectInvite.js b/services/web/app/src/models/ProjectInvite.mjs similarity index 64% rename from services/web/app/src/models/ProjectInvite.js rename to services/web/app/src/models/ProjectInvite.mjs index a7bfbad1e0..879cd9f49c 100644 --- a/services/web/app/src/models/ProjectInvite.js +++ b/services/web/app/src/models/ProjectInvite.mjs @@ -1,9 +1,9 @@ -const mongoose = require('../infrastructure/Mongoose') +import mongoose from '../infrastructure/Mongoose.js' const { Schema } = mongoose const { ObjectId } = Schema -const EXPIRY_IN_SECONDS = 60 * 60 * 24 * 30 +export const EXPIRY_IN_SECONDS = 60 * 60 * 24 * 30 const ExpiryDate = function () { const timestamp = new Date() @@ -11,7 +11,7 @@ const ExpiryDate = function () { return timestamp } -const ProjectInviteSchema = new Schema( +export const ProjectInviteSchema = new Schema( { email: String, tokenHmac: String, @@ -31,6 +31,7 @@ const ProjectInviteSchema = new Schema( } ) -exports.ProjectInvite = mongoose.model('ProjectInvite', ProjectInviteSchema) -exports.ProjectInviteSchema = ProjectInviteSchema -exports.EXPIRY_IN_SECONDS = EXPIRY_IN_SECONDS +export const ProjectInvite = mongoose.model( + 'ProjectInvite', + ProjectInviteSchema +) diff --git a/services/web/app/src/models/Publisher.js b/services/web/app/src/models/Publisher.mjs similarity index 77% rename from services/web/app/src/models/Publisher.js rename to services/web/app/src/models/Publisher.mjs index e9e10e49c0..9bbbd24e54 100644 --- a/services/web/app/src/models/Publisher.js +++ b/services/web/app/src/models/Publisher.mjs @@ -1,11 +1,11 @@ -const mongoose = require('../infrastructure/Mongoose') +import mongoose from '../infrastructure/Mongoose.js' +import settings from '@overleaf/settings' +import logger from '@overleaf/logger' +import request from 'request' const { Schema } = mongoose const { ObjectId } = Schema -const settings = require('@overleaf/settings') -const logger = require('@overleaf/logger') -const request = require('request') -const PublisherSchema = new Schema( +export const PublisherSchema = new Schema( { slug: { type: String, required: true }, managerIds: [{ type: ObjectId, ref: 'User' }], @@ -46,5 +46,4 @@ PublisherSchema.method('fetchV1Data', function (callback) { ) }) -exports.Publisher = mongoose.model('Publisher', PublisherSchema) -exports.PublisherSchema = PublisherSchema +export const Publisher = mongoose.model('Publisher', PublisherSchema) diff --git a/services/web/app/src/models/SSOConfig.js b/services/web/app/src/models/SSOConfig.mjs similarity index 73% rename from services/web/app/src/models/SSOConfig.js rename to services/web/app/src/models/SSOConfig.mjs index 0349d8a651..6db3584619 100644 --- a/services/web/app/src/models/SSOConfig.js +++ b/services/web/app/src/models/SSOConfig.mjs @@ -1,7 +1,7 @@ -const mongoose = require('../infrastructure/Mongoose') +import mongoose from '../infrastructure/Mongoose.js' const { Schema } = mongoose -const SSOConfigSchema = new Schema( +export const SSOConfigSchema = new Schema( { entryPoint: { type: String, required: true }, certificates: { type: Array, default: [''], required: true }, @@ -20,5 +20,4 @@ const SSOConfigSchema = new Schema( } ) -exports.SSOConfig = mongoose.model('SSOConfig', SSOConfigSchema) -exports.SSOConfigSchema = SSOConfigSchema +export const SSOConfig = mongoose.model('SSOConfig', SSOConfigSchema) diff --git a/services/web/app/src/models/SamlCache.js b/services/web/app/src/models/SamlCache.js deleted file mode 100644 index 185fe61422..0000000000 --- a/services/web/app/src/models/SamlCache.js +++ /dev/null @@ -1,16 +0,0 @@ -const mongoose = require('../infrastructure/Mongoose') -const { Schema } = mongoose - -const SamlCacheSchema = new Schema( - { - createdAt: { type: Date }, - requestId: { type: String }, - }, - { - collection: 'samlCache', - minimize: false, - } -) - -exports.SamlCache = mongoose.model('SamlCache', SamlCacheSchema) -exports.SamlCacheSchema = SamlCacheSchema diff --git a/services/web/app/src/models/SamlCache.mjs b/services/web/app/src/models/SamlCache.mjs new file mode 100644 index 0000000000..a58a76ea68 --- /dev/null +++ b/services/web/app/src/models/SamlCache.mjs @@ -0,0 +1,15 @@ +import mongoose from '../infrastructure/Mongoose.js' +const { Schema } = mongoose + +export const SamlCacheSchema = new Schema( + { + createdAt: { type: Date }, + requestId: { type: String }, + }, + { + collection: 'samlCache', + minimize: false, + } +) + +export const SamlCache = mongoose.model('SamlCache', SamlCacheSchema) diff --git a/services/web/app/src/models/SamlLog.js b/services/web/app/src/models/SamlLog.mjs similarity index 69% rename from services/web/app/src/models/SamlLog.js rename to services/web/app/src/models/SamlLog.mjs index 52889770f0..929c7b2600 100644 --- a/services/web/app/src/models/SamlLog.js +++ b/services/web/app/src/models/SamlLog.mjs @@ -1,7 +1,7 @@ -const mongoose = require('../infrastructure/Mongoose') +import mongoose from '../infrastructure/Mongoose.js' const { Schema } = mongoose -const SamlLogSchema = new Schema( +export const SamlLogSchema = new Schema( { createdAt: { type: Date, default: () => new Date() }, data: { type: Object }, @@ -18,5 +18,4 @@ const SamlLogSchema = new Schema( } ) -exports.SamlLog = mongoose.model('SamlLog', SamlLogSchema) -exports.SamlLogSchema = SamlLogSchema +export const SamlLog = mongoose.model('SamlLog', SamlLogSchema) diff --git a/services/web/app/src/models/SplitTest.js b/services/web/app/src/models/SplitTest.mjs similarity index 95% rename from services/web/app/src/models/SplitTest.js rename to services/web/app/src/models/SplitTest.mjs index c605693bfa..b15c81adb4 100644 --- a/services/web/app/src/models/SplitTest.js +++ b/services/web/app/src/models/SplitTest.mjs @@ -1,4 +1,4 @@ -const mongoose = require('../infrastructure/Mongoose') +import mongoose from '../infrastructure/Mongoose.js' const { Schema } = mongoose const { ObjectId } = Schema @@ -112,7 +112,7 @@ const VersionSchema = new Schema( { _id: false } ) -const SplitTestSchema = new Schema( +export const SplitTestSchema = new Schema( { name: { type: String, @@ -178,7 +178,4 @@ const SplitTestSchema = new Schema( { minimize: false } ) -module.exports = { - SplitTest: mongoose.model('SplitTest', SplitTestSchema), - SplitTestSchema, -} +export const SplitTest = mongoose.model('SplitTest', SplitTestSchema) diff --git a/services/web/app/src/models/Subscription.js b/services/web/app/src/models/Subscription.mjs similarity index 91% rename from services/web/app/src/models/Subscription.js rename to services/web/app/src/models/Subscription.mjs index c7606d39ea..416f637c6f 100644 --- a/services/web/app/src/models/Subscription.js +++ b/services/web/app/src/models/Subscription.mjs @@ -1,10 +1,10 @@ -const mongoose = require('../infrastructure/Mongoose') -const { TeamInviteSchema } = require('./TeamInvite') +import mongoose from '../infrastructure/Mongoose.js' +import { TeamInviteSchema } from './TeamInvite.mjs' const { Schema } = mongoose const { ObjectId } = Schema -const SubscriptionSchema = new Schema( +export const SubscriptionSchema = new Schema( { admin_id: { type: ObjectId, @@ -123,5 +123,4 @@ SubscriptionSchema.method('fetchV1Data', function (callback) { callback(null, this) }) -exports.Subscription = mongoose.model('Subscription', SubscriptionSchema) -exports.SubscriptionSchema = SubscriptionSchema +export const Subscription = mongoose.model('Subscription', SubscriptionSchema) diff --git a/services/web/app/src/models/Survey.js b/services/web/app/src/models/Survey.mjs similarity index 86% rename from services/web/app/src/models/Survey.js rename to services/web/app/src/models/Survey.mjs index 01068ef49a..3c98e19fb8 100644 --- a/services/web/app/src/models/Survey.js +++ b/services/web/app/src/models/Survey.mjs @@ -1,11 +1,11 @@ -const mongoose = require('../infrastructure/Mongoose') +import mongoose from '../infrastructure/Mongoose.js' const { Schema } = mongoose const MIN_NAME_LENGTH = 3 const MAX_NAME_LENGTH = 200 const NAME_REGEX = /^[a-z0-9-]+$/ -const SurveySchema = new Schema( +export const SurveySchema = new Schema( { name: { type: String, @@ -62,7 +62,4 @@ const SurveySchema = new Schema( } ) -module.exports = { - Survey: mongoose.model('Survey', SurveySchema), - SurveySchema, -} +export const Survey = mongoose.model('Survey', SurveySchema) diff --git a/services/web/app/src/models/SystemMessage.js b/services/web/app/src/models/SystemMessage.mjs similarity index 51% rename from services/web/app/src/models/SystemMessage.js rename to services/web/app/src/models/SystemMessage.mjs index c3e37d00c6..4191801f4e 100644 --- a/services/web/app/src/models/SystemMessage.js +++ b/services/web/app/src/models/SystemMessage.mjs @@ -1,4 +1,4 @@ -const mongoose = require('../infrastructure/Mongoose') +import mongoose from '../infrastructure/Mongoose.js' const { Schema } = mongoose @@ -9,4 +9,7 @@ const SystemMessageSchema = new Schema( { minimize: false } ) -exports.SystemMessage = mongoose.model('SystemMessage', SystemMessageSchema) +export const SystemMessage = mongoose.model( + 'SystemMessage', + SystemMessageSchema +) diff --git a/services/web/app/src/models/Tag.js b/services/web/app/src/models/Tag.mjs similarity index 76% rename from services/web/app/src/models/Tag.js rename to services/web/app/src/models/Tag.mjs index 8e0eb115dc..7824d95d53 100644 --- a/services/web/app/src/models/Tag.js +++ b/services/web/app/src/models/Tag.mjs @@ -1,4 +1,4 @@ -const mongoose = require('../infrastructure/Mongoose') +import mongoose from '../infrastructure/Mongoose.js' const { Schema } = mongoose const COLOR_REGEX = /^#[a-fA-F0-9]{6}$/ @@ -6,7 +6,7 @@ const COLOR_REGEX = /^#[a-fA-F0-9]{6}$/ // Note that for legacy reasons, user_id and project_ids are plain strings, // not ObjectIds. -const TagSchema = new Schema( +export const TagSchema = new Schema( { user_id: { type: String, required: true }, name: { type: String, required: true }, @@ -24,5 +24,4 @@ const TagSchema = new Schema( { minimize: false } ) -exports.Tag = mongoose.model('Tag', TagSchema) -exports.TagSchema = TagSchema +export const Tag = mongoose.model('Tag', TagSchema) diff --git a/services/web/app/src/models/TeamInvite.js b/services/web/app/src/models/TeamInvite.js deleted file mode 100644 index b115d27261..0000000000 --- a/services/web/app/src/models/TeamInvite.js +++ /dev/null @@ -1,16 +0,0 @@ -const mongoose = require('../infrastructure/Mongoose') - -const { Schema } = mongoose - -const TeamInviteSchema = new Schema( - { - email: { type: String, required: true }, - token: { type: String }, - inviterName: { type: String }, - sentAt: { type: Date }, - }, - { minimize: false } -) - -exports.TeamInvite = mongoose.model('TeamInvite', TeamInviteSchema) -exports.TeamInviteSchema = TeamInviteSchema diff --git a/services/web/app/src/models/TeamInvite.mjs b/services/web/app/src/models/TeamInvite.mjs new file mode 100644 index 0000000000..dfa31c09ff --- /dev/null +++ b/services/web/app/src/models/TeamInvite.mjs @@ -0,0 +1,15 @@ +import mongoose from '../infrastructure/Mongoose.js' + +const { Schema } = mongoose + +export const TeamInviteSchema = new Schema( + { + email: { type: String, required: true }, + token: { type: String }, + inviterName: { type: String }, + sentAt: { type: Date }, + }, + { minimize: false } +) + +export const TeamInvite = mongoose.model('TeamInvite', TeamInviteSchema) diff --git a/services/web/app/src/models/User.js b/services/web/app/src/models/User.mjs similarity index 94% rename from services/web/app/src/models/User.js rename to services/web/app/src/models/User.mjs index bdf8a4c4ed..5739474106 100644 --- a/services/web/app/src/models/User.js +++ b/services/web/app/src/models/User.mjs @@ -1,6 +1,6 @@ -const Settings = require('@overleaf/settings') -const mongoose = require('../infrastructure/Mongoose') -const TokenGenerator = require('../Features/TokenGenerator/TokenGenerator') +import Settings from '@overleaf/settings' +import mongoose from '../infrastructure/Mongoose.js' +import TokenGenerator from '../Features/TokenGenerator/TokenGenerator.js' const { Schema } = mongoose const { ObjectId } = Schema @@ -8,7 +8,7 @@ const { ObjectId } = Schema const MAX_EMAIL_LENGTH = 254 const MAX_NAME_LENGTH = 255 -const UserSchema = new Schema( +export const UserSchema = new Schema( { email: { type: String, default: '', maxlength: MAX_EMAIL_LENGTH }, emails: [ @@ -236,6 +236,10 @@ const UserSchema = new Schema( function formatSplitTestsSchema(next) { if (this.splitTests) { for (const splitTestKey of Object.keys(this.splitTests)) { + // Old splitTests can be a plain string - skip anything that isn't an array + if (!Array.isArray(this.splitTests[splitTestKey])) { + continue + } for (const variantIndex in this.splitTests[splitTestKey]) { this.splitTests[splitTestKey][variantIndex].assignedAt = new Date( this.splitTests[splitTestKey][variantIndex].assignedAt @@ -247,5 +251,4 @@ function formatSplitTestsSchema(next) { } UserSchema.pre('save', formatSplitTestsSchema) -exports.User = mongoose.model('User', UserSchema) -exports.UserSchema = UserSchema +export const User = mongoose.model('User', UserSchema) diff --git a/services/web/app/src/models/UserAuditLogEntry.js b/services/web/app/src/models/UserAuditLogEntry.mjs similarity index 70% rename from services/web/app/src/models/UserAuditLogEntry.js rename to services/web/app/src/models/UserAuditLogEntry.mjs index f239adca2f..11442a9d0c 100644 --- a/services/web/app/src/models/UserAuditLogEntry.js +++ b/services/web/app/src/models/UserAuditLogEntry.mjs @@ -1,7 +1,7 @@ -const mongoose = require('../infrastructure/Mongoose') +import mongoose from '../infrastructure/Mongoose.js' const { Schema } = mongoose -const UserAuditLogEntrySchema = new Schema( +export const UserAuditLogEntrySchema = new Schema( { userId: { type: Schema.Types.ObjectId, index: true }, managedSubscriptionId: { type: Schema.Types.ObjectId, index: true }, @@ -17,8 +17,7 @@ const UserAuditLogEntrySchema = new Schema( } ) -exports.UserAuditLogEntry = mongoose.model( +export const UserAuditLogEntry = mongoose.model( 'UserAuditLogEntry', UserAuditLogEntrySchema ) -exports.UserAuditLogEntrySchema = UserAuditLogEntrySchema diff --git a/services/web/app/src/models/UserFeatureUsage.js b/services/web/app/src/models/UserFeatureUsage.mjs similarity index 54% rename from services/web/app/src/models/UserFeatureUsage.js rename to services/web/app/src/models/UserFeatureUsage.mjs index 8935990e0a..50c86127af 100644 --- a/services/web/app/src/models/UserFeatureUsage.js +++ b/services/web/app/src/models/UserFeatureUsage.mjs @@ -1,4 +1,4 @@ -const mongoose = require('../infrastructure/Mongoose') +import mongoose from '../infrastructure/Mongoose.js' const { Schema } = mongoose const Usage = new Schema({ @@ -6,16 +6,14 @@ const Usage = new Schema({ periodStart: { type: Date }, }) -const UserFeatureUsageSchema = new Schema({ +export const UserFeatureUsageSchema = new Schema({ features: { aiErrorAssistant: Usage, aiWorkbench: Usage, }, }) -exports.UserFeatureUsage = mongoose.model( +export const UserFeatureUsage = mongoose.model( 'UserFeatureUsage', UserFeatureUsageSchema ) - -exports.UserFeatureUsageSchema = UserFeatureUsageSchema diff --git a/services/web/modules/launchpad/app/src/LaunchpadController.mjs b/services/web/modules/launchpad/app/src/LaunchpadController.mjs index 101372b3ca..94cc8b35a2 100644 --- a/services/web/modules/launchpad/app/src/LaunchpadController.mjs +++ b/services/web/modules/launchpad/app/src/LaunchpadController.mjs @@ -6,7 +6,7 @@ import logger from '@overleaf/logger' import UserRegistrationHandler from '../../../../app/src/Features/User/UserRegistrationHandler.mjs' import EmailHandler from '../../../../app/src/Features/Email/EmailHandler.mjs' import UserGetter from '../../../../app/src/Features/User/UserGetter.mjs' -import { User } from '../../../../app/src/models/User.js' +import { User } from '../../../../app/src/models/User.mjs' import AuthenticationManager from '../../../../app/src/Features/Authentication/AuthenticationManager.mjs' import AuthenticationController from '../../../../app/src/Features/Authentication/AuthenticationController.mjs' import SessionManager from '../../../../app/src/Features/Authentication/SessionManager.mjs' diff --git a/services/web/modules/launchpad/test/unit/src/LaunchpadController.test.mjs b/services/web/modules/launchpad/test/unit/src/LaunchpadController.test.mjs index 80150aa705..a0d3ce5b88 100644 --- a/services/web/modules/launchpad/test/unit/src/LaunchpadController.test.mjs +++ b/services/web/modules/launchpad/test/unit/src/LaunchpadController.test.mjs @@ -52,7 +52,7 @@ describe('LaunchpadController', function () { }), })) - vi.doMock('../../../../../app/src/models/User.js', () => ({ + vi.doMock('../../../../../app/src/models/User.mjs', () => ({ User: ctx.User, })) diff --git a/services/web/modules/server-ce-scripts/scripts/export-legacy-user-projects.mjs b/services/web/modules/server-ce-scripts/scripts/export-legacy-user-projects.mjs index d7fcbed45d..1598309f71 100644 --- a/services/web/modules/server-ce-scripts/scripts/export-legacy-user-projects.mjs +++ b/services/web/modules/server-ce-scripts/scripts/export-legacy-user-projects.mjs @@ -11,8 +11,8 @@ import mongodb from '../../../app/src/infrastructure/mongodb.js' import DocumentUpdaterHandler from '../../../app/src/Features/DocumentUpdater/DocumentUpdaterHandler.js' import ProjectZipStreamManager from '../../../app/src/Features/Downloads/ProjectZipStreamManager.js' import logger from 'logger-sharelatex' -import { Project } from '../../../app/src/models/Project.js' -import { User } from '../../../app/src/models/User.js' +import { Project } from '../../../app/src/models/Project.mjs' +import { User } from '../../../app/src/models/User.mjs' import readline from 'readline' function parseArgs() { diff --git a/services/web/modules/server-ce-scripts/scripts/export-user-projects.mjs b/services/web/modules/server-ce-scripts/scripts/export-user-projects.mjs index c84e72037a..f33edcddb8 100644 --- a/services/web/modules/server-ce-scripts/scripts/export-user-projects.mjs +++ b/services/web/modules/server-ce-scripts/scripts/export-user-projects.mjs @@ -12,8 +12,8 @@ import ProjectZipStreamManager from '../../../app/src/Features/Downloads/Project import logger from '@overleaf/logger' import { promisify } from '@overleaf/promise-utils' import { gracefulShutdown } from '../../../app/src/infrastructure/GracefulShutdown.js' -import { Project } from '../../../app/src/models/Project.js' -import { User } from '../../../app/src/models/User.js' +import { Project } from '../../../app/src/models/Project.mjs' +import { User } from '../../../app/src/models/User.mjs' import readline from 'readline' function parseArgs() { diff --git a/services/web/modules/server-ce-scripts/scripts/migrate-user-emails.mjs b/services/web/modules/server-ce-scripts/scripts/migrate-user-emails.mjs index b8cc54626b..a5661c8978 100644 --- a/services/web/modules/server-ce-scripts/scripts/migrate-user-emails.mjs +++ b/services/web/modules/server-ce-scripts/scripts/migrate-user-emails.mjs @@ -14,11 +14,12 @@ import minimist from 'minimist' import os from 'os' import fs from 'fs' import * as csv from 'csv/sync' -import { parseEmail } from '../../../app/src/Features/Helpers/EmailHelper.js' +import EmailHelper from '../../../app/src/Features/Helpers/EmailHelper.mjs' import UserGetter from '../../../app/src/Features/User/UserGetter.mjs' import UserUpdater from '../../../app/src/Features/User/UserUpdater.mjs' import UserSessionsManager from '../../../app/src/Features/User/UserSessionsManager.mjs' +const { parseEmail } = EmailHelper const hostname = os.hostname() const scriptTimestamp = new Date().toISOString() diff --git a/services/web/modules/server-ce-scripts/scripts/transfer-all-projects-to-user.mjs b/services/web/modules/server-ce-scripts/scripts/transfer-all-projects-to-user.mjs index eafd301c0b..6c54e9a3b2 100644 --- a/services/web/modules/server-ce-scripts/scripts/transfer-all-projects-to-user.mjs +++ b/services/web/modules/server-ce-scripts/scripts/transfer-all-projects-to-user.mjs @@ -2,7 +2,7 @@ import { ObjectId } from '../../../app/src/infrastructure/mongodb.js' import minimist from 'minimist' import OwnershipTransferHandler from '../../../app/src/Features/Collaborators/OwnershipTransferHandler.mjs' import UserGetter from '../../../app/src/Features/User/UserGetter.mjs' -import EmailHelper from '../../../app/src/Features/Helpers/EmailHelper.js' +import EmailHelper from '../../../app/src/Features/Helpers/EmailHelper.mjs' const args = minimist(process.argv.slice(2), { string: ['from-user', 'to-user'], diff --git a/services/web/scripts/add_salesforce_data_to_subscriptions.mjs b/services/web/scripts/add_salesforce_data_to_subscriptions.mjs index 264640f587..80cc4db36c 100755 --- a/services/web/scripts/add_salesforce_data_to_subscriptions.mjs +++ b/services/web/scripts/add_salesforce_data_to_subscriptions.mjs @@ -3,7 +3,7 @@ import minimist from 'minimist' import { parse } from 'csv' import Stream from 'node:stream/promises' import { ObjectId } from '../app/src/infrastructure/mongodb.js' -import { Subscription } from '../app/src/models/Subscription.js' +import { Subscription } from '../app/src/models/Subscription.mjs' import { scriptRunner } from './lib/ScriptRunner.mjs' function usage() { diff --git a/services/web/scripts/add_subscription_members_csv.mjs b/services/web/scripts/add_subscription_members_csv.mjs index 1dbd5d8084..25a29bed0d 100644 --- a/services/web/scripts/add_subscription_members_csv.mjs +++ b/services/web/scripts/add_subscription_members_csv.mjs @@ -3,7 +3,7 @@ import minimist from 'minimist' import { parse } from 'csv' import Stream from 'node:stream/promises' import SubscriptionGroupHandler from '../app/src/Features/Subscription/SubscriptionGroupHandler.mjs' -import { Subscription } from '../app/src/models/Subscription.js' +import { Subscription } from '../app/src/models/Subscription.mjs' import { InvalidEmailError } from '../app/src/Features/Errors/Errors.js' function usage() { diff --git a/services/web/scripts/analytics/sync_group_subscription_memberships.mjs b/services/web/scripts/analytics/sync_group_subscription_memberships.mjs index 21ab920c5e..9480f7c32e 100644 --- a/services/web/scripts/analytics/sync_group_subscription_memberships.mjs +++ b/services/web/scripts/analytics/sync_group_subscription_memberships.mjs @@ -1,7 +1,7 @@ import GoogleBigQueryHelper from './helpers/GoogleBigQueryHelper.mjs' -import { Subscription } from '../../app/src/models/Subscription.js' +import { Subscription } from '../../app/src/models/Subscription.mjs' import AnalyticsManager from '../../app/src/Features/Analytics/AnalyticsManager.mjs' -import { DeletedSubscription } from '../../app/src/models/DeletedSubscription.js' +import { DeletedSubscription } from '../../app/src/models/DeletedSubscription.mjs' import minimist from 'minimist' import _ from 'lodash' import mongodb from 'mongodb-legacy' diff --git a/services/web/scripts/backfill_mixpanel_user_properties.mjs b/services/web/scripts/backfill_mixpanel_user_properties.mjs index 1324cefb1d..6e3dabd4c2 100644 --- a/services/web/scripts/backfill_mixpanel_user_properties.mjs +++ b/services/web/scripts/backfill_mixpanel_user_properties.mjs @@ -1,5 +1,5 @@ // @ts-check -import '../app/src/models/User.js' +import '../app/src/models/User.mjs' import { batchedUpdateWithResultHandling } from '@overleaf/mongo-utils/batchedUpdate.js' import { promiseMapWithLimit } from '@overleaf/promise-utils' import { getQueue } from '../app/src/infrastructure/Queues.js' diff --git a/services/web/scripts/create_project.mjs b/services/web/scripts/create_project.mjs index 70f6ae4706..f883c00d5a 100644 --- a/services/web/scripts/create_project.mjs +++ b/services/web/scripts/create_project.mjs @@ -8,7 +8,7 @@ import path from 'node:path' import _ from 'lodash' import parseArgs from 'minimist' import OError from '@overleaf/o-error' -import { User } from '../app/src/models/User.js' +import { User } from '../app/src/models/User.mjs' import ProjectCreationHandler from '../app/src/Features/Project/ProjectCreationHandler.mjs' import ProjectEntityUpdateHandler from '../app/src/Features/Project/ProjectEntityUpdateHandler.mjs' import ProjectEntityHandler from '../app/src/Features/Project/ProjectEntityHandler.mjs' diff --git a/services/web/scripts/delete_dangling_file_refs.mjs b/services/web/scripts/delete_dangling_file_refs.mjs index df2ae91e22..2a290b162c 100644 --- a/services/web/scripts/delete_dangling_file_refs.mjs +++ b/services/web/scripts/delete_dangling_file_refs.mjs @@ -8,7 +8,7 @@ import mongodb from 'mongodb-legacy' import { db } from '../app/src/infrastructure/mongodb.js' import Errors from '../app/src/Features/Errors/Errors.js' import ProjectEntityMongoUpdateHandler from '../app/src/Features/Project/ProjectEntityMongoUpdateHandler.mjs' -import { iterablePaths } from '../app/src/Features/Project/IterablePath.js' +import { iterablePaths } from '../app/src/Features/Project/IterablePath.mjs' import { scriptRunner } from './lib/ScriptRunner.mjs' import HistoryManager from '../app/src/Features/History/HistoryManager.mjs' diff --git a/services/web/scripts/delete_subscriptions.mjs b/services/web/scripts/delete_subscriptions.mjs index 2cf17d75c2..6fb4610614 100644 --- a/services/web/scripts/delete_subscriptions.mjs +++ b/services/web/scripts/delete_subscriptions.mjs @@ -1,4 +1,4 @@ -import { Subscription } from '../app/src/models/Subscription.js' +import { Subscription } from '../app/src/models/Subscription.mjs' import SubscriptionUpdater from '../app/src/Features/Subscription/SubscriptionUpdater.mjs' import minimist from 'minimist' import mongodb from 'mongodb-legacy' diff --git a/services/web/scripts/ensure_affiliations.mjs b/services/web/scripts/ensure_affiliations.mjs index 5ffc0695ee..72d19d8c31 100644 --- a/services/web/scripts/ensure_affiliations.mjs +++ b/services/web/scripts/ensure_affiliations.mjs @@ -1,4 +1,4 @@ -import { User } from '../app/src/models/User.js' +import { User } from '../app/src/models/User.mjs' import UserController from '../app/src/Features/User/UserController.mjs' import Logger from '@overleaf/logger' import pLimit from 'p-limit' diff --git a/services/web/scripts/example/script_for_migration.mjs b/services/web/scripts/example/script_for_migration.mjs index 0c201eebab..2c73dc77d3 100644 --- a/services/web/scripts/example/script_for_migration.mjs +++ b/services/web/scripts/example/script_for_migration.mjs @@ -6,7 +6,7 @@ * in the migrations directory. */ -import { User } from '../../app/src/models/User.js' +import { User } from '../../app/src/models/User.mjs' import { fileURLToPath } from 'node:url' // const somePackage = require('some-package') diff --git a/services/web/scripts/extract_day1_churn_users.mjs b/services/web/scripts/extract_day1_churn_users.mjs index 0dd50e2099..d95cdf3959 100644 --- a/services/web/scripts/extract_day1_churn_users.mjs +++ b/services/web/scripts/extract_day1_churn_users.mjs @@ -2,7 +2,7 @@ import { scriptRunner } from './lib/ScriptRunner.mjs' import * as csv from 'csv' import fs from 'node:fs' import minimist from 'minimist' -import { User } from '../app/src/models/User.js' +import { User } from '../app/src/models/User.mjs' /** * This script extracts users who churned after day 1 - ie. their last session was within 24 hours of registering diff --git a/services/web/scripts/extract_onboardingdatacollection_csv.mjs b/services/web/scripts/extract_onboardingdatacollection_csv.mjs index a485a623dd..2eac33c3f7 100644 --- a/services/web/scripts/extract_onboardingdatacollection_csv.mjs +++ b/services/web/scripts/extract_onboardingdatacollection_csv.mjs @@ -1,7 +1,7 @@ import { scriptRunner } from './lib/ScriptRunner.mjs' import * as csv from 'csv' import fs from 'node:fs' -import { OnboardingDataCollection } from '../app/src/models/OnboardingDataCollection.js' +import { OnboardingDataCollection } from '../app/src/models/OnboardingDataCollection.mjs' /** * This script extracts the OnboardingDataCollection collection from the database diff --git a/services/web/scripts/extract_onboardingdatacollection_never_used_latex.mjs b/services/web/scripts/extract_onboardingdatacollection_never_used_latex.mjs index 339b08876e..57705c0aa5 100644 --- a/services/web/scripts/extract_onboardingdatacollection_never_used_latex.mjs +++ b/services/web/scripts/extract_onboardingdatacollection_never_used_latex.mjs @@ -2,8 +2,8 @@ import { scriptRunner } from './lib/ScriptRunner.mjs' import * as csv from 'csv' import fs from 'node:fs' import minimist from 'minimist' -import { OnboardingDataCollection } from '../app/src/models/OnboardingDataCollection.js' -import { User } from '../app/src/models/User.js' +import { OnboardingDataCollection } from '../app/src/models/OnboardingDataCollection.mjs' +import { User } from '../app/src/models/User.mjs' import SubscriptionLocator from '../app/src/Features/Subscription/SubscriptionLocator.mjs' import Settings from '@overleaf/settings' import { fetchJson } from '@overleaf/fetch-utils' diff --git a/services/web/scripts/investigate_esm.mjs b/services/web/scripts/investigate_esm.mjs new file mode 100644 index 0000000000..9f31240e91 --- /dev/null +++ b/services/web/scripts/investigate_esm.mjs @@ -0,0 +1,147 @@ +/* eslint-disable */ +import { extractImports, findJSAndImports } from './esm-check-migration.mjs' +import path from 'node:path' +import fs from 'node:fs' + +const imports = await findJSAndImports( + ['app', 'modules'].map(dir => path.resolve(dir)) +) + +const entryPoint = fs.existsSync('app.js') ? 'app.js' : 'app.mjs' +imports.set(path.resolve(entryPoint), extractImports(entryPoint)) + +const moduleImports = new Map() +imports.forEach((deps, module) => { + for (const dep of deps) { + if (!moduleImports.has(dep)) { + moduleImports.set(dep, new Set()) + } + moduleImports.set(dep, moduleImports.get(dep).add(module)) + } +}) + +const soloImports = new Map() +moduleImports.forEach((importedBy, module) => { + if (importedBy.size === 1) { + soloImports.set(module, [...importedBy][0]) + } +}) + +console.log(soloImports) + +for (const [module, importedBy] of soloImports) { + if (!moduleImports.has(importedBy)) { + console.log( + `${module} is only imported by ${importedBy}, which has no other imports` + ) + } + if (soloImports.has(importedBy)) { + console.log( + `${module} is only imported by ${importedBy}, which is only imported by ${soloImports.get(importedBy)}` + ) + } + const chains = findDependencyChainsToTarget(imports, module) + const conversionsToMake = chains.reduce((conversions, chain) => { + chain.forEach(dep => { + conversions.add(dep) + }) + return conversions + }, new Set()) + + if (conversionsToMake.length < 10) { + console.log( + `To convert ${module}, would need to convert: ${[...conversionsToMake].length}` + ) + } +} + +// --- Circular dependency detection --- +function findCircularDependencies(importsMap) { + const cycles = [] + const visited = new Set() + const stack = [] + + function dfs(file, pathStack) { + if (pathStack.includes(file)) { + // Cycle detected + const cycleStart = pathStack.indexOf(file) + cycles.push(pathStack.slice(cycleStart).concat(file)) + return + } + if (!importsMap.has(file)) return + pathStack.push(file) + for (const imp of importsMap.get(file)) { + const resolvedImp = path.resolve(imp) + dfs(resolvedImp, pathStack) + } + pathStack.pop() + } + + for (const file of importsMap.keys()) { + dfs(file, []) + } + return cycles +} + +const cycles = findCircularDependencies(imports) +if (cycles.length > 0) { + console.log('Circular dependencies found:') + for (const cycle of cycles) { + console.log(' ' + cycle.join(' -> ')) + } +} else { + console.log('No circular dependencies detected.') +} + +// --- Find all chains of dependencies to a target file --- +function findDependencyChainsToTarget(importsMap, targetPath) { + const chains = [] + const resolvedTarget = path.resolve(targetPath) + + function dfs(current, pathStack) { + if (pathStack.includes(current)) return // avoid cycles + pathStack.push(current) + if (current === resolvedTarget) { + chains.push([...pathStack]) + pathStack.pop() + return + } + if (!importsMap.has(current)) { + pathStack.pop() + return + } + for (const imp of importsMap.get(current)) { + const resolvedImp = path.resolve(imp) + dfs(resolvedImp, pathStack) + } + pathStack.pop() + } + + for (const file of importsMap.keys()) { + if (file === resolvedTarget) continue // skip self + dfs(file, []) + } + return chains +} + +// Example usage: set your target file path here +const targetFile = + '/Users/arumble/Documents/Projects/internal/services/web/app/src/Features/Analytics/AnalyticsManager.js' // <-- change to your target +const chains = findDependencyChainsToTarget(imports, targetFile) +if (chains.length > 0) { + console.log(`Dependency chains leading to ${targetFile}:`) + for (const chain of chains) { + console.log(' ' + chain.join(' -> ')) + } +} else { + console.log(`No dependency chains found leading to ${targetFile}.`) +} + +const conversionsToMake = chains.reduce((conversions, chain) => { + chain.forEach(dep => { + conversions.add(dep) + }) + return conversions +}, new Set()) + +console.log([...conversionsToMake].join(' ')) diff --git a/services/web/scripts/re_add_deleted_emails.mjs b/services/web/scripts/re_add_deleted_emails.mjs index e910073c5a..8d8a620505 100644 --- a/services/web/scripts/re_add_deleted_emails.mjs +++ b/services/web/scripts/re_add_deleted_emails.mjs @@ -10,7 +10,7 @@ import Errors from '../app/src/Features/Errors/Errors.js' import UserGetter from '../app/src/Features/User/UserGetter.mjs' import { READ_PREFERENCE_SECONDARY } from '@overleaf/mongo-utils/batchedUpdate.js' import UserUpdater from '../app/src/Features/User/UserUpdater.mjs' -import EmailHelper from '../app/src/Features/Helpers/EmailHelper.js' +import EmailHelper from '../app/src/Features/Helpers/EmailHelper.mjs' import AsyncLocalStorage from '../app/src/infrastructure/AsyncLocalStorage.js' import AnalyticsManager from '../app/src/Features/Analytics/AnalyticsManager.mjs' import UserAuditLogHandler from '../app/src/Features/User/UserAuditLogHandler.mjs' diff --git a/services/web/scripts/recurly/resync_recurly_state_single_subscription.mjs b/services/web/scripts/recurly/resync_recurly_state_single_subscription.mjs index 13b005b02a..f72809a965 100644 --- a/services/web/scripts/recurly/resync_recurly_state_single_subscription.mjs +++ b/services/web/scripts/recurly/resync_recurly_state_single_subscription.mjs @@ -1,4 +1,4 @@ -import { Subscription } from '../../app/src/models/Subscription.js' +import { Subscription } from '../../app/src/models/Subscription.mjs' import RecurlyWrapper from '../../app/src/Features/Subscription/RecurlyWrapper.mjs' import SubscriptionUpdater from '../../app/src/Features/Subscription/SubscriptionUpdater.mjs' import minimist from 'minimist' diff --git a/services/web/scripts/recurly/resync_subscriptions.mjs b/services/web/scripts/recurly/resync_subscriptions.mjs index 00f10b7b29..17b4bfa9db 100644 --- a/services/web/scripts/recurly/resync_subscriptions.mjs +++ b/services/web/scripts/recurly/resync_subscriptions.mjs @@ -1,4 +1,4 @@ -import { Subscription } from '../../app/src/models/Subscription.js' +import { Subscription } from '../../app/src/models/Subscription.mjs' import RecurlyWrapper from '../../app/src/Features/Subscription/RecurlyWrapper.mjs' import SubscriptionUpdater from '../../app/src/Features/Subscription/SubscriptionUpdater.mjs' import minimist from 'minimist' diff --git a/services/web/scripts/remove_oauth_application.mjs b/services/web/scripts/remove_oauth_application.mjs index fd37ca374c..95eddfca94 100644 --- a/services/web/scripts/remove_oauth_application.mjs +++ b/services/web/scripts/remove_oauth_application.mjs @@ -1,4 +1,4 @@ -import { OauthApplication } from '../app/src/models/OauthApplication.js' +import { OauthApplication } from '../app/src/models/OauthApplication.mjs' import parseArgs from 'minimist' import OError from '@overleaf/o-error' import { scriptRunner } from './lib/ScriptRunner.mjs' diff --git a/services/web/scripts/remove_user_enrollment.mjs b/services/web/scripts/remove_user_enrollment.mjs index a4ebcdb4d2..64073607a9 100644 --- a/services/web/scripts/remove_user_enrollment.mjs +++ b/services/web/scripts/remove_user_enrollment.mjs @@ -7,8 +7,8 @@ import minimist from 'minimist' import { ObjectId } from '../app/src/infrastructure/mongodb.js' -import { User } from '../app/src/models/User.js' -import { Subscription } from '../app/src/models/Subscription.js' +import { User } from '../app/src/models/User.mjs' +import { Subscription } from '../app/src/models/Subscription.mjs' import UserAuditLogHandler from '../app/src/Features/User/UserAuditLogHandler.mjs' const argv = minimist(process.argv.slice(2)) diff --git a/services/web/scripts/set_tex_live_image.mjs b/services/web/scripts/set_tex_live_image.mjs index a0d48dd9f3..f513afe0bc 100644 --- a/services/web/scripts/set_tex_live_image.mjs +++ b/services/web/scripts/set_tex_live_image.mjs @@ -1,6 +1,6 @@ import Settings from '@overleaf/settings' import mongodb from 'mongodb-legacy' -import { Project } from '../app/src/models/Project.js' +import { Project } from '../app/src/models/Project.mjs' import { scriptRunner } from './lib/ScriptRunner.mjs' const { ObjectId } = mongodb diff --git a/services/web/scripts/validate-data-of-model.mjs b/services/web/scripts/validate-data-of-model.mjs index 7c9aa38f0c..63788bef6d 100644 --- a/services/web/scripts/validate-data-of-model.mjs +++ b/services/web/scripts/validate-data-of-model.mjs @@ -3,9 +3,8 @@ import { db } from '../app/src/infrastructure/mongodb.js' const MODEL_NAME = process.argv.pop() -// Todo: handle mjs file once models have been converted to ES module const { [MODEL_NAME]: Model } = await import( - `../app/src/models/${MODEL_NAME}.js` + `../app/src/models/${MODEL_NAME}.mjs` ) function processBatch(batch) { diff --git a/services/web/test/acceptance/src/ConvertEmailConfirmedAtToDates.js b/services/web/test/acceptance/src/ConvertEmailConfirmedAtToDates.mjs similarity index 100% rename from services/web/test/acceptance/src/ConvertEmailConfirmedAtToDates.js rename to services/web/test/acceptance/src/ConvertEmailConfirmedAtToDates.mjs diff --git a/services/web/test/acceptance/src/ConvertSplitTestAssignedAtToDates.js b/services/web/test/acceptance/src/ConvertSplitTestAssignedAtToDates.mjs similarity index 100% rename from services/web/test/acceptance/src/ConvertSplitTestAssignedAtToDates.js rename to services/web/test/acceptance/src/ConvertSplitTestAssignedAtToDates.mjs diff --git a/services/web/test/acceptance/src/ModelTests.mjs b/services/web/test/acceptance/src/ModelTests.mjs index 7a58cf0a53..9ef32cf08c 100644 --- a/services/web/test/acceptance/src/ModelTests.mjs +++ b/services/web/test/acceptance/src/ModelTests.mjs @@ -1,6 +1,6 @@ import { expect } from 'chai' -import { User } from '../../../app/src/models/User.js' -import { Subscription } from '../../../app/src/models/Subscription.js' +import { User } from '../../../app/src/models/User.mjs' +import { Subscription } from '../../../app/src/models/Subscription.mjs' describe('mongoose', function () { describe('User', function () { diff --git a/services/web/test/acceptance/src/MongoHelper.mjs b/services/web/test/acceptance/src/MongoHelper.mjs index 269939e8ff..dc7ddbeab6 100644 --- a/services/web/test/acceptance/src/MongoHelper.mjs +++ b/services/web/test/acceptance/src/MongoHelper.mjs @@ -1,7 +1,7 @@ import { expect } from 'chai' import mongodb from 'mongodb-legacy' import mongoose from 'mongoose' -import { User as UserModel } from '../../../app/src/models/User.js' +import { User as UserModel } from '../../../app/src/models/User.mjs' import { db } from '../../../app/src/infrastructure/mongodb.js' import { normalizeQuery, diff --git a/services/web/test/acceptance/src/ProjectCRUDTests.mjs b/services/web/test/acceptance/src/ProjectCRUDTests.mjs index 71bad436d0..2c6d638e9f 100644 --- a/services/web/test/acceptance/src/ProjectCRUDTests.mjs +++ b/services/web/test/acceptance/src/ProjectCRUDTests.mjs @@ -1,9 +1,9 @@ import { expect } from 'chai' import UserHelper from './helpers/User.mjs' -import { Project } from '../../../app/src/models/Project.js' +import { Project } from '../../../app/src/models/Project.mjs' import mongodb from 'mongodb-legacy' import cheerio from 'cheerio' -import { Subscription } from '../../../app/src/models/Subscription.js' +import { Subscription } from '../../../app/src/models/Subscription.mjs' import Features from '../../../app/src/infrastructure/Features.js' const ObjectId = mongodb.ObjectId diff --git a/services/web/test/acceptance/src/ProjectStructureTests.mjs b/services/web/test/acceptance/src/ProjectStructureTests.mjs index 14edf58c4f..22e22a9fcc 100644 --- a/services/web/test/acceptance/src/ProjectStructureTests.mjs +++ b/services/web/test/acceptance/src/ProjectStructureTests.mjs @@ -2,7 +2,7 @@ import chai, { expect } from 'chai' import mongodb from 'mongodb-legacy' import Path from 'node:path' import fs from 'node:fs' -import { Project } from '../../../app/src/models/Project.js' +import { Project } from '../../../app/src/models/Project.mjs' import ProjectGetter from '../../../app/src/Features/Project/ProjectGetter.mjs' import UserHelper from './helpers/User.mjs' import MockDocStoreApiClass from './mocks/MockDocstoreApi.mjs' diff --git a/services/web/test/acceptance/src/SettingsTests.mjs b/services/web/test/acceptance/src/SettingsTests.mjs index 3d0c015bb3..52378f1044 100644 --- a/services/web/test/acceptance/src/SettingsTests.mjs +++ b/services/web/test/acceptance/src/SettingsTests.mjs @@ -58,4 +58,33 @@ describe('SettingsPage', function () { return done() }) }) + + it('can save when splitTests contains a string variant rather than an object', function (done) { + const newFirstName = 'newfirstname' + const assignedAtVariant = { + variantName: 'enabled', + versionNumber: 12, + phase: 'release', + assignedAt: new Date('2024-08-17T09:17:28.349Z'), + } + this.user.mongoUpdate( + { + $set: { + 'splitTests.string-variant': 'default', + 'splitTests.assigned-at-date': [assignedAtVariant], + }, + }, + () => { + this.user.updateSettings({ first_name: newFirstName }, error => { + expect(error).not.to.exist + this.user.get((error, user) => { + user.splitTests.should.haveOwnProperty('string-variant') + user.splitTests.should.haveOwnProperty('assigned-at-date') + user.splitTests['assigned-at-date'].should.eql([assignedAtVariant]) + done() + }) + }) + } + ) + }) }) diff --git a/services/web/test/acceptance/src/helpers/DeletedSubscription.mjs b/services/web/test/acceptance/src/helpers/DeletedSubscription.mjs index 3d64877cec..2e218c6f26 100644 --- a/services/web/test/acceptance/src/helpers/DeletedSubscription.mjs +++ b/services/web/test/acceptance/src/helpers/DeletedSubscription.mjs @@ -1,8 +1,8 @@ import { expect } from 'chai' import MockSubscription from './Subscription.mjs' import SubscriptionUpdater from '../../../../app/src/Features/Subscription/SubscriptionUpdater.mjs' -import { Subscription as SubscriptionModel } from '../../../../app/src/models/Subscription.js' -import { DeletedSubscription as DeletedSubscriptionModel } from '../../../../app/src/models/DeletedSubscription.js' +import { Subscription as SubscriptionModel } from '../../../../app/src/models/Subscription.mjs' +import { DeletedSubscription as DeletedSubscriptionModel } from '../../../../app/src/models/DeletedSubscription.mjs' import { promisifyClass } from '@overleaf/promise-utils' class DeletedSubscription { diff --git a/services/web/test/acceptance/src/helpers/Institution.mjs b/services/web/test/acceptance/src/helpers/Institution.mjs index eb2bd0b274..416c61bc99 100644 --- a/services/web/test/acceptance/src/helpers/Institution.mjs +++ b/services/web/test/acceptance/src/helpers/Institution.mjs @@ -1,5 +1,5 @@ import mongodb from 'mongodb-legacy' -import { Institution as InstitutionModel } from '../../../../app/src/models/Institution.js' +import { Institution as InstitutionModel } from '../../../../app/src/models/Institution.mjs' const { ObjectId } = mongodb diff --git a/services/web/test/acceptance/src/helpers/Publisher.mjs b/services/web/test/acceptance/src/helpers/Publisher.mjs index 8300157cc2..8d8e336332 100644 --- a/services/web/test/acceptance/src/helpers/Publisher.mjs +++ b/services/web/test/acceptance/src/helpers/Publisher.mjs @@ -1,5 +1,5 @@ import mongodb from 'mongodb-legacy' -import { Publisher as PublisherModel } from '../../../../app/src/models/Publisher.js' +import { Publisher as PublisherModel } from '../../../../app/src/models/Publisher.mjs' import { callbackifyClass } from '@overleaf/promise-utils' const { ObjectId } = mongodb diff --git a/services/web/test/acceptance/src/helpers/SAMLHelper.mjs b/services/web/test/acceptance/src/helpers/SAMLHelper.mjs index 531e3fdacc..d4092eb6f3 100644 --- a/services/web/test/acceptance/src/helpers/SAMLHelper.mjs +++ b/services/web/test/acceptance/src/helpers/SAMLHelper.mjs @@ -1,7 +1,7 @@ import fs from 'node:fs' import path from 'node:path' import { SignedXml } from 'xml-crypto' -import { SamlLog } from '../../../../app/src/models/SamlLog.js' +import { SamlLog } from '../../../../app/src/models/SamlLog.mjs' import { expect } from 'chai' import zlib from 'node:zlib' import { fileURLToPath } from 'node:url' diff --git a/services/web/test/acceptance/src/helpers/Subscription.mjs b/services/web/test/acceptance/src/helpers/Subscription.mjs index eec39c3bf6..afa1297de0 100644 --- a/services/web/test/acceptance/src/helpers/Subscription.mjs +++ b/services/web/test/acceptance/src/helpers/Subscription.mjs @@ -4,8 +4,8 @@ import { callbackifyClass } from '@overleaf/promise-utils' import SubscriptionUpdater from '../../../../app/src/Features/Subscription/SubscriptionUpdater.mjs' import PermissionsManager from '../../../../app/src/Features/Authorization/PermissionsManager.mjs' import SSOConfigManager from '../../../../modules/group-settings/app/src/sso/SSOConfigManager.mjs' -import { Subscription as SubscriptionModel } from '../../../../app/src/models/Subscription.js' -import { DeletedSubscription as DeletedSubscriptionModel } from '../../../../app/src/models/DeletedSubscription.js' +import { Subscription as SubscriptionModel } from '../../../../app/src/models/Subscription.mjs' +import { DeletedSubscription as DeletedSubscriptionModel } from '../../../../app/src/models/DeletedSubscription.mjs' import Modules from '../../../../app/src/infrastructure/Modules.js' class PromisifiedSubscription { diff --git a/services/web/test/acceptance/src/helpers/User.mjs b/services/web/test/acceptance/src/helpers/User.mjs index 48ba98c9b5..3bc4d801f1 100644 --- a/services/web/test/acceptance/src/helpers/User.mjs +++ b/services/web/test/acceptance/src/helpers/User.mjs @@ -2,16 +2,14 @@ import OError from '@overleaf/o-error' import request from './request.js' import settings from '@overleaf/settings' import { db, ObjectId } from '../../../../app/src/infrastructure/mongodb.js' -import { User as UserModel } from '../../../../app/src/models/User.js' +import { User as UserModel } from '../../../../app/src/models/User.mjs' import UserUpdater from '../../../../app/src/Features/User/UserUpdater.mjs' import AuthenticationManager from '../../../../app/src/Features/Authentication/AuthenticationManager.mjs' import { promisifyClass } from '@overleaf/promise-utils' import fs from 'node:fs' import Path from 'node:path' -import { fileURLToPath } from 'node:url' import { Cookie } from 'tough-cookie' -const __dirname = fileURLToPath(new URL('.', import.meta.url)) const COOKIE_DOMAIN = settings.cookieDomain // The cookie domain has a leading '.' but the cookie jar stores it without. const DEFAULT_COOKIE_URL = `https://${COOKIE_DOMAIN.replace(/^\./, '')}/` @@ -853,7 +851,7 @@ class User { callback ) { const fileStream = fs.createReadStream( - Path.resolve(Path.join(__dirname, '..', '..', 'files', file)) + Path.resolve(Path.join(import.meta.dirname, '..', '..', 'files', file)) ) this.request.post( diff --git a/services/web/test/acceptance/src/helpers/UserHelper.mjs b/services/web/test/acceptance/src/helpers/UserHelper.mjs index b218554da0..aea5ca66ee 100644 --- a/services/web/test/acceptance/src/helpers/UserHelper.mjs +++ b/services/web/test/acceptance/src/helpers/UserHelper.mjs @@ -9,7 +9,7 @@ import moment from 'moment' import fetch from 'node-fetch' import mongodb from 'mongodb-legacy' -import { UserAuditLogEntry } from '../../../../app/src/models/UserAuditLogEntry.js' +import { UserAuditLogEntry } from '../../../../app/src/models/UserAuditLogEntry.mjs' // Import the rate limiter so we can clear it between tests diff --git a/services/web/test/acceptance/src/helpers/groupSSO.mjs b/services/web/test/acceptance/src/helpers/groupSSO.mjs index c908773ed6..d72fd372e1 100644 --- a/services/web/test/acceptance/src/helpers/groupSSO.mjs +++ b/services/web/test/acceptance/src/helpers/groupSSO.mjs @@ -2,14 +2,14 @@ import fs from 'node:fs' import Path from 'node:path' import UserModule from './User.mjs' import SubscriptionHelper from './Subscription.mjs' -import { SSOConfig } from '../../../../app/src/models/SSOConfig.js' +import { SSOConfig } from '../../../../app/src/models/SSOConfig.mjs' import UserHelper from './UserHelper.mjs' import SAMLHelper from './SAMLHelper.mjs' import Settings from '@overleaf/settings' import GroupUtils from '../../../../app/src/Features/Subscription/GroupUtils.mjs' import UserGetter from '../../../../app/src/Features/User/UserGetter.mjs' import { fileURLToPath } from 'node:url' -import { Subscription as SubscriptionModel } from '../../../../app/src/models/Subscription.js' +import { Subscription as SubscriptionModel } from '../../../../app/src/models/Subscription.mjs' const { promises: User } = UserModule const { promises: Subscription } = SubscriptionHelper diff --git a/services/web/test/unit/src/Collaborators/CollaboratorsGetter.test.mjs b/services/web/test/unit/src/Collaborators/CollaboratorsGetter.test.mjs index 02fd445098..cd6506c7d4 100644 --- a/services/web/test/unit/src/Collaborators/CollaboratorsGetter.test.mjs +++ b/services/web/test/unit/src/Collaborators/CollaboratorsGetter.test.mjs @@ -2,11 +2,9 @@ import { vi, expect } from 'vitest' import Path from 'path' import sinon from 'sinon' import mongodb from 'mongodb-legacy' -import indirectlyImportModels from '../helpers/indirectlyImportModels.js' +import { Project } from '../../../../app/src/models/Project.mjs' import Errors from '../../../../app/src/Features/Errors/Errors.js' -const { Project } = indirectlyImportModels(['Project']) - const { ObjectId } = mongodb vi.mock('../../../../app/src/Features/Errors/Errors.js', () => diff --git a/services/web/test/unit/src/Collaborators/CollaboratorsHandler.test.mjs b/services/web/test/unit/src/Collaborators/CollaboratorsHandler.test.mjs index f3f924125e..fa4e4bc2b2 100644 --- a/services/web/test/unit/src/Collaborators/CollaboratorsHandler.test.mjs +++ b/services/web/test/unit/src/Collaborators/CollaboratorsHandler.test.mjs @@ -2,12 +2,11 @@ import { vi, expect } from 'vitest' import path from 'path' import sinon from 'sinon' import Errors from '../../../../app/src/Features/Errors/Errors.js' -import indirectlyImportModels from '../helpers/indirectlyImportModels.js' +import { Project } from '../../../../app/src/models/Project.mjs' import mongodb from 'mongodb-legacy' import { setTimeout } from 'node:timers/promises' const { ObjectId } = mongodb -const { Project } = indirectlyImportModels(['Project']) vi.mock('../../../../app/src/Features/Errors/Errors.js', () => vi.importActual('../../../../app/src/Features/Errors/Errors.js') ) diff --git a/services/web/test/unit/src/Collaborators/CollaboratorsInviteHandler.test.mjs b/services/web/test/unit/src/Collaborators/CollaboratorsInviteHandler.test.mjs index 660994f2f8..41e5e3eba5 100644 --- a/services/web/test/unit/src/Collaborators/CollaboratorsInviteHandler.test.mjs +++ b/services/web/test/unit/src/Collaborators/CollaboratorsInviteHandler.test.mjs @@ -82,7 +82,7 @@ describe('CollaboratorsInviteHandler', function () { default: ctx.settings, })) - vi.doMock('../../../../app/src/models/ProjectInvite.js', () => ({ + vi.doMock('../../../../app/src/models/ProjectInvite.mjs', () => ({ ProjectInvite: ctx.ProjectInvite, })) diff --git a/services/web/test/unit/src/Collaborators/OwnershipTransferHandler.test.mjs b/services/web/test/unit/src/Collaborators/OwnershipTransferHandler.test.mjs index f526aaa29b..35e48e2e15 100644 --- a/services/web/test/unit/src/Collaborators/OwnershipTransferHandler.test.mjs +++ b/services/web/test/unit/src/Collaborators/OwnershipTransferHandler.test.mjs @@ -89,7 +89,7 @@ describe('OwnershipTransferHandler', function () { default: ctx.ProjectGetter, })) - vi.doMock('../../../../app/src/models/Project.js', () => ({ + vi.doMock('../../../../app/src/models/Project.mjs', () => ({ Project: ctx.ProjectModel, })) diff --git a/services/web/test/unit/src/Cooldown/CooldownManagerTests.js b/services/web/test/unit/src/Cooldown/CooldownManager.sequential.test.mjs similarity index 53% rename from services/web/test/unit/src/Cooldown/CooldownManagerTests.js rename to services/web/test/unit/src/Cooldown/CooldownManager.sequential.test.mjs index 5531c4b8ea..fdd757f03f 100644 --- a/services/web/test/unit/src/Cooldown/CooldownManagerTests.js +++ b/services/web/test/unit/src/Cooldown/CooldownManager.sequential.test.mjs @@ -1,16 +1,16 @@ -const { expect } = require('chai') -const { ObjectId } = require('mongodb-legacy') -const CooldownManager = require('../../../../app/src/Features/Cooldown/CooldownManager') -const { - cleanupTestRedis, -} = require('../../../../app/src/infrastructure/RedisWrapper') +import { expect } from 'vitest' +import mongodb from 'mongodb-legacy' +import CooldownManager from '../../../../app/src/Features/Cooldown/CooldownManager.mjs' +import { cleanupTestRedis } from '../../../../app/src/infrastructure/RedisWrapper.js' + +const { ObjectId } = mongodb describe('CooldownManager', function () { beforeEach(cleanupTestRedis) - beforeEach(function () { - this.project1Id = new ObjectId().toString() - this.project2Id = new ObjectId().toString() + beforeEach(function (ctx) { + ctx.project1Id = new ObjectId().toString() + ctx.project2Id = new ObjectId().toString() }) describe('_buildKey', function () { @@ -21,35 +21,35 @@ describe('CooldownManager', function () { describe('isProjectOnCooldown', function () { describe('when no project is on cooldown', function () { - it('returns false for project 1', async function () { + it('returns false for project 1', async function (ctx) { const result = await CooldownManager.promises.isProjectOnCooldown( - this.project1Id + ctx.project1Id ) expect(result).to.be.false }) - it('returns false for project 2', async function () { + it('returns false for project 2', async function (ctx) { const result = await CooldownManager.promises.isProjectOnCooldown( - this.project2Id + ctx.project2Id ) expect(result).to.be.false }) }) describe('when project 1 is on cooldown', function () { - beforeEach(async function () { - await CooldownManager.promises.putProjectOnCooldown(this.project1Id) + beforeEach(async function (ctx) { + await CooldownManager.promises.putProjectOnCooldown(ctx.project1Id) }) - it('returns true for project 1', async function () { + it('returns true for project 1', async function (ctx) { const result = await CooldownManager.promises.isProjectOnCooldown( - this.project1Id + ctx.project1Id ) expect(result).to.be.true }) - it('returns false for project 2', async function () { + it('returns false for project 2', async function (ctx) { const result = await CooldownManager.promises.isProjectOnCooldown( - this.project2Id + ctx.project2Id ) expect(result).to.be.false }) diff --git a/services/web/test/unit/src/Cooldown/CooldownMiddleware.test.mjs b/services/web/test/unit/src/Cooldown/CooldownMiddleware.test.mjs index 846a54d4ce..f7294c3b08 100644 --- a/services/web/test/unit/src/Cooldown/CooldownMiddleware.test.mjs +++ b/services/web/test/unit/src/Cooldown/CooldownMiddleware.test.mjs @@ -10,7 +10,7 @@ describe('CooldownMiddleware', function () { ctx.CooldownManager = { isProjectOnCooldown: sinon.stub() } vi.doMock( - '../../../../app/src/Features/Cooldown/CooldownManager.js', + '../../../../app/src/Features/Cooldown/CooldownManager.mjs', () => ({ default: ctx.CooldownManager, }) diff --git a/services/web/test/unit/src/HelperFiles/DiffHelperTests.js b/services/web/test/unit/src/HelperFiles/DiffHelper.test.mjs similarity index 87% rename from services/web/test/unit/src/HelperFiles/DiffHelperTests.js rename to services/web/test/unit/src/HelperFiles/DiffHelper.test.mjs index 518bffc534..b1149aa5b4 100644 --- a/services/web/test/unit/src/HelperFiles/DiffHelperTests.js +++ b/services/web/test/unit/src/HelperFiles/DiffHelper.test.mjs @@ -1,7 +1,5 @@ -const { expect } = require('chai') -const { - stringSimilarity, -} = require('../../../../app/src/Features/Helpers/DiffHelper') +import { expect } from 'vitest' +import { stringSimilarity } from '../../../../app/src/Features/Helpers/DiffHelper.mjs' describe('DiffHelper', function () { describe('stringSimilarity', function () { diff --git a/services/web/test/unit/src/HelperFiles/EmailHelperTests.js b/services/web/test/unit/src/HelperFiles/EmailHelper.test.mjs similarity index 53% rename from services/web/test/unit/src/HelperFiles/EmailHelperTests.js rename to services/web/test/unit/src/HelperFiles/EmailHelper.test.mjs index 2d56b7c638..31660b284f 100644 --- a/services/web/test/unit/src/HelperFiles/EmailHelperTests.js +++ b/services/web/test/unit/src/HelperFiles/EmailHelper.test.mjs @@ -1,21 +1,19 @@ -const { expect } = require('chai') -const { - parseEmail, -} = require('../../../../app/src/Features/Helpers/EmailHelper') +import { expect } from 'vitest' +import EmailHelper from '../../../../app/src/Features/Helpers/EmailHelper.mjs' describe('EmailHelper', function () { it('should parse a single email', function () { const address = 'test@example.com' const expected = 'test@example.com' - expect(parseEmail(address)).to.equal(expected) - expect(parseEmail(address, true)).to.equal(expected) + expect(EmailHelper.parseEmail(address)).to.equal(expected) + expect(EmailHelper.parseEmail(address, true)).to.equal(expected) }) it('should parse a valid email address', function () { const address = '"Test Person" ' const expected = 'test@example.com' - expect(parseEmail(address)).to.equal(null) - expect(parseEmail(address, true)).to.equal(expected) + expect(EmailHelper.parseEmail(address)).to.equal(null) + expect(EmailHelper.parseEmail(address, true)).to.equal(expected) }) it('should return null for garbage input', function () { @@ -31,26 +29,26 @@ describe('EmailHelper', function () { { toString: true }, ] for (const input of cases) { - expect(parseEmail(input)).to.equal(null, input) - expect(parseEmail(input, true)).to.equal(null, input) + expect(EmailHelper.parseEmail(input)).to.equal(null, input) + expect(EmailHelper.parseEmail(input, true)).to.equal(null, input) } }) it('should return null for an invalid single email', function () { const address = 'testexample.com' - expect(parseEmail(address)).to.equal(null) - expect(parseEmail(address, true)).to.equal(null) + expect(EmailHelper.parseEmail(address)).to.equal(null) + expect(EmailHelper.parseEmail(address, true)).to.equal(null) }) it('should return null for an invalid email address', function () { const address = '"Test Person" test@example.com>' - expect(parseEmail(address)).to.equal(null) - expect(parseEmail(address, true)).to.equal(null) + expect(EmailHelper.parseEmail(address)).to.equal(null) + expect(EmailHelper.parseEmail(address, true)).to.equal(null) }) it('should return null for a group of addresses', function () { const address = 'Group name:test1@example.com,test2@example.com;' - expect(parseEmail(address)).to.equal(null) - expect(parseEmail(address, true)).to.equal(null) + expect(EmailHelper.parseEmail(address)).to.equal(null) + expect(EmailHelper.parseEmail(address, true)).to.equal(null) }) }) diff --git a/services/web/test/unit/src/Project/IterablePathTests.js b/services/web/test/unit/src/Project/IterablePath.test.mjs similarity index 77% rename from services/web/test/unit/src/Project/IterablePathTests.js rename to services/web/test/unit/src/Project/IterablePath.test.mjs index e00607eb69..88f6e3abc4 100644 --- a/services/web/test/unit/src/Project/IterablePathTests.js +++ b/services/web/test/unit/src/Project/IterablePath.test.mjs @@ -1,7 +1,5 @@ -const { expect } = require('chai') -const { - iterablePaths, -} = require('../../../../app/src/Features/Project/IterablePath') +import { expect } from 'vitest' +import { iterablePaths } from '../../../../app/src/Features/Project/IterablePath.mjs' describe('iterablePaths', function () { it('returns an empty array for empty folders', function () { diff --git a/services/web/test/unit/src/Project/ProjectCollabratecDetails.test.mjs b/services/web/test/unit/src/Project/ProjectCollabratecDetails.test.mjs index 68ab92e3c5..8907fdda2d 100644 --- a/services/web/test/unit/src/Project/ProjectCollabratecDetails.test.mjs +++ b/services/web/test/unit/src/Project/ProjectCollabratecDetails.test.mjs @@ -18,7 +18,7 @@ describe('ProjectCollabratecDetailsHandler', function () { default: { ObjectId }, })) - vi.doMock('../../../../app/src/models/Project.js', () => ({ + vi.doMock('../../../../app/src/models/Project.mjs', () => ({ Project: ctx.ProjectModel, })) diff --git a/services/web/test/unit/src/Project/ProjectDeleter.test.mjs b/services/web/test/unit/src/Project/ProjectDeleter.test.mjs index 5dbea99d6c..0b58751221 100644 --- a/services/web/test/unit/src/Project/ProjectDeleter.test.mjs +++ b/services/web/test/unit/src/Project/ProjectDeleter.test.mjs @@ -2,15 +2,12 @@ import { vi, expect } from 'vitest' import sinon from 'sinon' import tk from 'timekeeper' import moment from 'moment' -import indirectlyImportModels from '../helpers/indirectlyImportModels.js' +import { Project } from '../../../../app/src/models/Project.mjs' +import { DeletedProject } from '../../../../app/src/models/DeletedProject.mjs' import mongodb from 'mongodb-legacy' import Errors from '../../../../app/src/Features/Errors/Errors.js' const modulePath = '../../../../app/src/Features/Project/ProjectDeleter' -const { Project, DeletedProject } = indirectlyImportModels([ - 'Project', - 'DeletedProject', -]) const { ObjectId, ReadPreference } = mongodb vi.mock('../../../../app/src/Features/Errors/Errors.js', () => vi.importActual('../../../../app/src/Features/Errors/Errors.js') diff --git a/services/web/test/unit/src/Project/ProjectEntityMongoUpdateHandler.test.mjs b/services/web/test/unit/src/Project/ProjectEntityMongoUpdateHandler.test.mjs index 4e8f9e86d1..ab400edc59 100644 --- a/services/web/test/unit/src/Project/ProjectEntityMongoUpdateHandler.test.mjs +++ b/services/web/test/unit/src/Project/ProjectEntityMongoUpdateHandler.test.mjs @@ -3,9 +3,8 @@ import sinon from 'sinon' import tk from 'timekeeper' import Errors from '../../../../app/src/Features/Errors/Errors.js' import mongodb from 'mongodb-legacy' -import indirectlyImportModels from '../helpers/indirectlyImportModels.js' +import { Project } from '../../../../app/src/models/Project.mjs' -const { Project } = indirectlyImportModels(['Project']) const { ObjectId } = mongodb vi.mock('../../../../app/src/Features/Errors/Errors.js', () => diff --git a/services/web/test/unit/src/Project/ProjectHistoryHandler.test.mjs b/services/web/test/unit/src/Project/ProjectHistoryHandler.test.mjs index e3b94e09b5..6937b3c9a2 100644 --- a/services/web/test/unit/src/Project/ProjectHistoryHandler.test.mjs +++ b/services/web/test/unit/src/Project/ProjectHistoryHandler.test.mjs @@ -33,7 +33,7 @@ describe('ProjectHistoryHandler', function () { default: (ctx.Settings = {}), })) - vi.doMock('../../../../app/src/models/Project.js', () => ({ + vi.doMock('../../../../app/src/models/Project.mjs', () => ({ Project: ctx.ProjectModel, })) diff --git a/services/web/test/unit/src/Referal/ReferalAllocator.test.mjs b/services/web/test/unit/src/Referal/ReferalAllocator.test.mjs index ae5e9bb27f..423d707735 100644 --- a/services/web/test/unit/src/Referal/ReferalAllocator.test.mjs +++ b/services/web/test/unit/src/Referal/ReferalAllocator.test.mjs @@ -5,7 +5,7 @@ const modulePath = '../../../../app/src/Features/Referal/ReferalAllocator.mjs' describe('ReferalAllocator', function () { beforeEach(async function (ctx) { - vi.doMock('../../../../app/src/models/User.js', () => ({ + vi.doMock('../../../../app/src/models/User.mjs', () => ({ User: (ctx.User = {}), })) diff --git a/services/web/test/unit/src/Security/OneTimeTokenHandlerTests.js b/services/web/test/unit/src/Security/OneTimeTokenHandler.sequential.test.mjs similarity index 84% rename from services/web/test/unit/src/Security/OneTimeTokenHandlerTests.js rename to services/web/test/unit/src/Security/OneTimeTokenHandler.sequential.test.mjs index b48dffe237..df412f2d39 100644 --- a/services/web/test/unit/src/Security/OneTimeTokenHandlerTests.js +++ b/services/web/test/unit/src/Security/OneTimeTokenHandler.sequential.test.mjs @@ -1,24 +1,28 @@ -const sinon = require('sinon') -const { expect } = require('chai') -const Errors = require('../../../../app/src/Features/Errors/Errors') -const { +import sinon from 'sinon' +import { beforeAll, beforeEach, describe, expect, it, vi } from 'vitest' +import Errors from '../../../../app/src/Features/Errors/Errors.js' +import { connectionPromise, cleanupTestDatabase, -} = require('../../../../app/src/infrastructure/mongodb') -const OneTimeTokenHandler = require('../../../../app/src/Features/Security/OneTimeTokenHandler') +} from '../../../../app/src/infrastructure/mongodb.js' +import OneTimeTokenHandler from '../../../../app/src/Features/Security/OneTimeTokenHandler.mjs' + +vi.mock('../../../../app/src/Features/Errors/Errors.js', () => + vi.importActual('../../../../app/src/Features/Errors/Errors.js') +) describe('OneTimeTokenHandler', function () { - before(async function () { + beforeAll(async function () { await connectionPromise }) beforeEach(cleanupTestDatabase) - beforeEach(function () { - this.clock = sinon.useFakeTimers() + beforeEach(function (ctx) { + ctx.clock = sinon.useFakeTimers() }) - afterEach(function () { - this.clock.restore() + afterEach(function (ctx) { + ctx.clock.restore() }) describe('getNewToken', function () { @@ -34,30 +38,30 @@ describe('OneTimeTokenHandler', function () { expect(data).to.equal('mock-data-to-store') }) - it('expires the generated token after 1 hour', async function () { + it('expires the generated token after 1 hour', async function (ctx) { const token = await OneTimeTokenHandler.promises.getNewToken( 'password', 'mock-data-to-store' ) - this.clock.tick('25:00:00') + ctx.clock.tick('25:00:00') await expect( OneTimeTokenHandler.promises.peekValueFromToken('password', token) ).to.be.rejectedWith(Errors.NotFoundError) }) - it('accepts an expiresIn parameter', async function () { + it('accepts an expiresIn parameter', async function (ctx) { const token = await OneTimeTokenHandler.promises.getNewToken( 'password', 'mock-data-to-store', { expiresIn: 42 } ) - this.clock.tick('00:30') + ctx.clock.tick('00:30') const { data } = await OneTimeTokenHandler.promises.peekValueFromToken( 'password', token ) expect(data).to.equal('mock-data-to-store') - this.clock.tick('00:15') + ctx.clock.tick('00:15') await expect( OneTimeTokenHandler.promises.peekValueFromToken('password', token) ).to.be.rejectedWith(Errors.NotFoundError) diff --git a/services/web/test/unit/src/Subscription/PaymentProviderEntities.test.mjs b/services/web/test/unit/src/Subscription/PaymentProviderEntities.test.mjs index 380d1b42e2..8b60574599 100644 --- a/services/web/test/unit/src/Subscription/PaymentProviderEntities.test.mjs +++ b/services/web/test/unit/src/Subscription/PaymentProviderEntities.test.mjs @@ -4,7 +4,7 @@ import Errors from '../../../../app/src/Features/Subscription/Errors.js' import PaymentProviderEntities from '../../../../app/src/Features/Subscription/PaymentProviderEntities.mjs' import { AI_ADD_ON_CODE } from '../../../../app/src/Features/Subscription/AiHelper.js' -import SubscriptionHelper from '../../../../app/src/Features/Subscription/SubscriptionHelper.js' +import SubscriptionHelper from '../../../../app/src/Features/Subscription/SubscriptionHelper.mjs' const { PaymentProviderSubscriptionChangeRequest, diff --git a/services/web/test/unit/src/Subscription/SubscriptionController.test.mjs b/services/web/test/unit/src/Subscription/SubscriptionController.test.mjs index 103acc862b..1d4e6ec607 100644 --- a/services/web/test/unit/src/Subscription/SubscriptionController.test.mjs +++ b/services/web/test/unit/src/Subscription/SubscriptionController.test.mjs @@ -3,7 +3,7 @@ import sinon from 'sinon' import MockRequest from '../helpers/MockRequest.js' import MockResponse from '../helpers/MockResponse.js' import SubscriptionErrors from '../../../../app/src/Features/Subscription/Errors.js' -import SubscriptionHelper from '../../../../app/src/Features/Subscription/SubscriptionHelper.js' +import SubscriptionHelper from '../../../../app/src/Features/Subscription/SubscriptionHelper.mjs' import { AI_ADD_ON_CODE } from '../../../../app/src/Features/Subscription/AiHelper.js' const modulePath = diff --git a/services/web/test/unit/src/Subscription/SubscriptionHandler.test.mjs b/services/web/test/unit/src/Subscription/SubscriptionHandler.test.mjs index 7f0290f4a0..2a3ce3a33a 100644 --- a/services/web/test/unit/src/Subscription/SubscriptionHandler.test.mjs +++ b/services/web/test/unit/src/Subscription/SubscriptionHandler.test.mjs @@ -1,7 +1,7 @@ import { expect, vi } from 'vitest' import sinon from 'sinon' import PaymentProviderEntities from '../../../../app/src/Features/Subscription/PaymentProviderEntities.mjs' -import SubscriptionHelper from '../../../../app/src/Features/Subscription/SubscriptionHelper.js' +import SubscriptionHelper from '../../../../app/src/Features/Subscription/SubscriptionHelper.mjs' const { PaymentProviderSubscription } = PaymentProviderEntities const MODULE_PATH = diff --git a/services/web/test/unit/src/Subscription/SubscriptionHelperTests.js b/services/web/test/unit/src/Subscription/SubscriptionHelper.test.mjs similarity index 60% rename from services/web/test/unit/src/Subscription/SubscriptionHelperTests.js rename to services/web/test/unit/src/Subscription/SubscriptionHelper.test.mjs index 3257d5812b..1a55733127 100644 --- a/services/web/test/unit/src/Subscription/SubscriptionHelperTests.js +++ b/services/web/test/unit/src/Subscription/SubscriptionHelper.test.mjs @@ -1,6 +1,5 @@ -const SandboxedModule = require('sandboxed-module') -const { expect } = require('chai') -const sinon = require('sinon') +import { vi, expect } from 'vitest' +import sinon from 'sinon' const modulePath = '../../../../app/src/Features/Subscription/SubscriptionHelper' @@ -31,9 +30,9 @@ const plans = { } describe('SubscriptionHelper', function () { - beforeEach(function () { - this.clock = sinon.useFakeTimers(new Date('2023-06-15T10:00:00Z')) - this.Subscription = { + beforeEach(async function (ctx) { + ctx.clock = sinon.useFakeTimers(new Date('2023-06-15T10:00:00Z')) + ctx.Subscription = { findOne: sinon.stub().returns({ exec: sinon.stub().resolves(), }), @@ -49,86 +48,91 @@ describe('SubscriptionHelper', function () { exec: sinon.stub().resolves(), }), } - this.INITIAL_LICENSE_SIZE = 2 - this.settings = { + ctx.INITIAL_LICENSE_SIZE = 2 + ctx.settings = { groupPlanModalOptions: {}, } - this.GroupPlansData = { + ctx.GroupPlansData = { enterprise: { collaborator: { CHF: { - [this.INITIAL_LICENSE_SIZE]: { + [ctx.INITIAL_LICENSE_SIZE]: { price_in_cents: 1000, }, }, DKK: { - [this.INITIAL_LICENSE_SIZE]: { + [ctx.INITIAL_LICENSE_SIZE]: { price_in_cents: 2000, }, }, SEK: { - [this.INITIAL_LICENSE_SIZE]: { + [ctx.INITIAL_LICENSE_SIZE]: { price_in_cents: 3000, }, }, NOK: { - [this.INITIAL_LICENSE_SIZE]: { + [ctx.INITIAL_LICENSE_SIZE]: { price_in_cents: 4000, }, }, USD: { - [this.INITIAL_LICENSE_SIZE]: { + [ctx.INITIAL_LICENSE_SIZE]: { price_in_cents: 5000, }, }, }, professional: { CHF: { - [this.INITIAL_LICENSE_SIZE]: { + [ctx.INITIAL_LICENSE_SIZE]: { price_in_cents: 10000, }, }, DKK: { - [this.INITIAL_LICENSE_SIZE]: { + [ctx.INITIAL_LICENSE_SIZE]: { price_in_cents: 20000, }, }, SEK: { - [this.INITIAL_LICENSE_SIZE]: { + [ctx.INITIAL_LICENSE_SIZE]: { price_in_cents: 30000, }, }, NOK: { - [this.INITIAL_LICENSE_SIZE]: { + [ctx.INITIAL_LICENSE_SIZE]: { price_in_cents: 40000, }, }, USD: { - [this.INITIAL_LICENSE_SIZE]: { + [ctx.INITIAL_LICENSE_SIZE]: { price_in_cents: 50000, }, }, }, }, } - this.SubscriptionHelper = SandboxedModule.require(modulePath, { - globals: { - Date: this.clock.Date, - }, - requires: { - '../../models/Subscription': { - Subscription: this.Subscription, - }, - '@overleaf/settings': this.settings, - './GroupPlansData': this.GroupPlansData, - }, - }) + + vi.doMock('../../../../app/src/models/Subscription', () => ({ + Subscription: ctx.Subscription, + })) + + vi.doMock('@overleaf/settings', () => ({ + default: ctx.settings, + })) + + vi.doMock( + '../../../../app/src/Features/Subscription/GroupPlansData', + () => ({ + default: ctx.GroupPlansData, + }) + ) + + ctx.SubscriptionHelper = (await import(modulePath)).default }) describe('shouldPlanChangeAtTermEnd', function () { - it('should return false if isInTrial is true', function () { + it('should return false if isInTrial is true', function (ctx) { const isInTrial = true - const changeAtTermEnd = this.SubscriptionHelper.shouldPlanChangeAtTermEnd( + const changeAtTermEnd = ctx.SubscriptionHelper.shouldPlanChangeAtTermEnd( plans.expensive, plans.cheaper, isInTrial @@ -136,9 +140,9 @@ describe('SubscriptionHelper', function () { expect(changeAtTermEnd).to.be.false }) - it('should return true if the new plan is less expensive', function () { + it('should return true if the new plan is less expensive', function (ctx) { const isInTrial = false - const changeAtTermEnd = this.SubscriptionHelper.shouldPlanChangeAtTermEnd( + const changeAtTermEnd = ctx.SubscriptionHelper.shouldPlanChangeAtTermEnd( plans.expensive, plans.cheaper, isInTrial @@ -146,9 +150,9 @@ describe('SubscriptionHelper', function () { expect(changeAtTermEnd).to.be.true }) - it('should return false if the new plan is more exepensive', function () { + it('should return false if the new plan is more exepensive', function (ctx) { const isInTrial = false - const changeAtTermEnd = this.SubscriptionHelper.shouldPlanChangeAtTermEnd( + const changeAtTermEnd = ctx.SubscriptionHelper.shouldPlanChangeAtTermEnd( plans.cheaper, plans.expensive, isInTrial @@ -156,10 +160,10 @@ describe('SubscriptionHelper', function () { expect(changeAtTermEnd).to.be.false }) - it('should return false if the new plan is the same price', function () { + it('should return false if the new plan is the same price', function (ctx) { const isInTrial = false - const changeAtTermEnd = this.SubscriptionHelper.shouldPlanChangeAtTermEnd( + const changeAtTermEnd = ctx.SubscriptionHelper.shouldPlanChangeAtTermEnd( plans.cheaper, plans.alsoCheap, isInTrial @@ -167,10 +171,10 @@ describe('SubscriptionHelper', function () { expect(changeAtTermEnd).to.be.false }) - it('should return false if the change is from an individual plan to a more expensive group plan', function () { + it('should return false if the change is from an individual plan to a more expensive group plan', function (ctx) { const isInTrial = false - const changeAtTermEnd = this.SubscriptionHelper.shouldPlanChangeAtTermEnd( + const changeAtTermEnd = ctx.SubscriptionHelper.shouldPlanChangeAtTermEnd( plans.expensive, plans.expensiveGroup, isInTrial @@ -178,10 +182,10 @@ describe('SubscriptionHelper', function () { expect(changeAtTermEnd).to.be.false }) - it('should return true if the change is from an individual plan to a cheaper group plan', function () { + it('should return true if the change is from an individual plan to a cheaper group plan', function (ctx) { const isInTrial = false - const changeAtTermEnd = this.SubscriptionHelper.shouldPlanChangeAtTermEnd( + const changeAtTermEnd = ctx.SubscriptionHelper.shouldPlanChangeAtTermEnd( plans.expensive, plans.cheapGroup, isInTrial @@ -192,12 +196,9 @@ describe('SubscriptionHelper', function () { describe('generateInitialLocalizedGroupPrice', function () { describe('CHF currency', function () { - it('should return the correct localized price for every plan', function () { + it('should return the correct localized price for every plan', function (ctx) { const localizedPrice = - this.SubscriptionHelper.generateInitialLocalizedGroupPrice( - 'CHF', - 'fr' - ) + ctx.SubscriptionHelper.generateInitialLocalizedGroupPrice('CHF', 'fr') expect(localizedPrice).to.deep.equal({ price: { @@ -213,12 +214,9 @@ describe('SubscriptionHelper', function () { }) describe('DKK currency', function () { - it('should return the correct localized price for every plan', function () { + it('should return the correct localized price for every plan', function (ctx) { const localizedPrice = - this.SubscriptionHelper.generateInitialLocalizedGroupPrice( - 'DKK', - 'da' - ) + ctx.SubscriptionHelper.generateInitialLocalizedGroupPrice('DKK', 'da') expect(localizedPrice).to.deep.equal({ price: { @@ -234,12 +232,9 @@ describe('SubscriptionHelper', function () { }) describe('SEK currency', function () { - it('should return the correct localized price for every plan', function () { + it('should return the correct localized price for every plan', function (ctx) { const localizedPrice = - this.SubscriptionHelper.generateInitialLocalizedGroupPrice( - 'SEK', - 'sv' - ) + ctx.SubscriptionHelper.generateInitialLocalizedGroupPrice('SEK', 'sv') expect(localizedPrice).to.deep.equal({ price: { @@ -255,9 +250,9 @@ describe('SubscriptionHelper', function () { }) describe('NOK currency', function () { - it('should return the correct localized price for every plan', function () { + it('should return the correct localized price for every plan', function (ctx) { const localizedPrice = - this.SubscriptionHelper.generateInitialLocalizedGroupPrice( + ctx.SubscriptionHelper.generateInitialLocalizedGroupPrice( 'NOK', // there seem to be possible inconsistencies with the CI // maybe it depends on what languages are installed on the server? @@ -278,12 +273,9 @@ describe('SubscriptionHelper', function () { }) describe('other supported currencies', function () { - it('should return the correct localized price for every plan', function () { + it('should return the correct localized price for every plan', function (ctx) { const localizedPrice = - this.SubscriptionHelper.generateInitialLocalizedGroupPrice( - 'USD', - 'en' - ) + ctx.SubscriptionHelper.generateInitialLocalizedGroupPrice('USD', 'en') expect(localizedPrice).to.deep.equal({ price: { @@ -300,235 +292,219 @@ describe('SubscriptionHelper', function () { }) describe('isPaidSubscription', function () { - it('should return true for a subscription with a recurly subscription id', function () { - const result = this.SubscriptionHelper.isPaidSubscription({ + it('should return true for a subscription with a recurly subscription id', function (ctx) { + const result = ctx.SubscriptionHelper.isPaidSubscription({ recurlySubscription_id: 'some-id', }) expect(result).to.be.true }) - it('should return true for a subscription with a stripe subscription id', function () { - const result = this.SubscriptionHelper.isPaidSubscription({ + it('should return true for a subscription with a stripe subscription id', function (ctx) { + const result = ctx.SubscriptionHelper.isPaidSubscription({ paymentProvider: { subscriptionId: 'some-id' }, }) expect(result).to.be.true }) - it('should return false for a free subscription', function () { - const result = this.SubscriptionHelper.isPaidSubscription({}) + it('should return false for a free subscription', function (ctx) { + const result = ctx.SubscriptionHelper.isPaidSubscription({}) expect(result).to.be.false }) - it('should return false for a missing subscription', function () { - const result = this.SubscriptionHelper.isPaidSubscription() + it('should return false for a missing subscription', function (ctx) { + const result = ctx.SubscriptionHelper.isPaidSubscription() expect(result).to.be.false }) }) describe('isIndividualActivePaidSubscription', function () { - it('should return true for an active recurly subscription', function () { - const result = this.SubscriptionHelper.isIndividualActivePaidSubscription( - { - groupPlan: false, - recurlyStatus: { state: 'active' }, - recurlySubscription_id: 'some-id', - } - ) + it('should return true for an active recurly subscription', function (ctx) { + const result = ctx.SubscriptionHelper.isIndividualActivePaidSubscription({ + groupPlan: false, + recurlyStatus: { state: 'active' }, + recurlySubscription_id: 'some-id', + }) expect(result).to.be.true }) - it('should return true for an active stripe subscription', function () { - const result = this.SubscriptionHelper.isIndividualActivePaidSubscription( - { - groupPlan: false, - paymentProvider: { subscriptionId: 'sub_123', state: 'active' }, - } - ) + it('should return true for an active stripe subscription', function (ctx) { + const result = ctx.SubscriptionHelper.isIndividualActivePaidSubscription({ + groupPlan: false, + paymentProvider: { subscriptionId: 'sub_123', state: 'active' }, + }) expect(result).to.be.true }) - it('should return false for a canceled recurly subscription', function () { - const result = this.SubscriptionHelper.isIndividualActivePaidSubscription( - { - groupPlan: false, - recurlyStatus: { state: 'canceled' }, - recurlySubscription_id: 'some-id', - } - ) + it('should return false for a canceled recurly subscription', function (ctx) { + const result = ctx.SubscriptionHelper.isIndividualActivePaidSubscription({ + groupPlan: false, + recurlyStatus: { state: 'canceled' }, + recurlySubscription_id: 'some-id', + }) expect(result).to.be.false }) - it('should return false for a canceled stripe subscription', function () { - const result = this.SubscriptionHelper.isIndividualActivePaidSubscription( - { - groupPlan: false, - paymentProvider: { state: 'canceled', subscriptionId: 'sub_123' }, - } - ) + it('should return false for a canceled stripe subscription', function (ctx) { + const result = ctx.SubscriptionHelper.isIndividualActivePaidSubscription({ + groupPlan: false, + paymentProvider: { state: 'canceled', subscriptionId: 'sub_123' }, + }) expect(result).to.be.false }) - it('should return false for a group plan subscription', function () { - const result = this.SubscriptionHelper.isIndividualActivePaidSubscription( - { - groupPlan: true, - recurlyStatus: { state: 'active' }, - recurlySubscription_id: 'some-id', - } - ) + it('should return false for a group plan subscription', function (ctx) { + const result = ctx.SubscriptionHelper.isIndividualActivePaidSubscription({ + groupPlan: true, + recurlyStatus: { state: 'active' }, + recurlySubscription_id: 'some-id', + }) expect(result).to.be.false }) - it('should return false for a free subscription', function () { - const result = this.SubscriptionHelper.isIndividualActivePaidSubscription( + it('should return false for a free subscription', function (ctx) { + const result = ctx.SubscriptionHelper.isIndividualActivePaidSubscription( {} ) expect(result).to.be.false }) - it('should return false for a subscription with an empty string for recurlySubscription_id', function () { - const result = this.SubscriptionHelper.isIndividualActivePaidSubscription( - { - groupPlan: false, - recurlySubscription_id: '', - recurlyStatus: { state: 'active' }, - } - ) + it('should return false for a subscription with an empty string for recurlySubscription_id', function (ctx) { + const result = ctx.SubscriptionHelper.isIndividualActivePaidSubscription({ + groupPlan: false, + recurlySubscription_id: '', + recurlyStatus: { state: 'active' }, + }) expect(result).to.be.false }) - it('should return false for a subscription with an empty string for paymentProvider.subscriptionId', function () { - const result = this.SubscriptionHelper.isIndividualActivePaidSubscription( - { - groupPlan: false, - paymentProvider: { state: 'active', subscriptionId: '' }, - } - ) + it('should return false for a subscription with an empty string for paymentProvider.subscriptionId', function (ctx) { + const result = ctx.SubscriptionHelper.isIndividualActivePaidSubscription({ + groupPlan: false, + paymentProvider: { state: 'active', subscriptionId: '' }, + }) expect(result).to.be.false }) - it('should return false for a missing subscription', function () { - const result = this.SubscriptionHelper.isPaidSubscription() + it('should return false for a missing subscription', function (ctx) { + const result = ctx.SubscriptionHelper.isPaidSubscription() expect(result).to.be.false }) }) describe('getPaymentProviderSubscriptionId', function () { - it('should return the recurly subscription id if it exists', function () { - const result = this.SubscriptionHelper.getPaymentProviderSubscriptionId({ + it('should return the recurly subscription id if it exists', function (ctx) { + const result = ctx.SubscriptionHelper.getPaymentProviderSubscriptionId({ recurlySubscription_id: 'some-id', }) expect(result).to.equal('some-id') }) - it('should return the payment provider subscription id if it exists', function () { - const result = this.SubscriptionHelper.getPaymentProviderSubscriptionId({ + it('should return the payment provider subscription id if it exists', function (ctx) { + const result = ctx.SubscriptionHelper.getPaymentProviderSubscriptionId({ paymentProvider: { subscriptionId: 'sub_123' }, }) expect(result).to.equal('sub_123') }) - it('should return null if no subscription id exists', function () { - const result = this.SubscriptionHelper.getPaymentProviderSubscriptionId( - {} - ) + it('should return null if no subscription id exists', function (ctx) { + const result = ctx.SubscriptionHelper.getPaymentProviderSubscriptionId({}) expect(result).to.be.null }) }) describe('getPaidSubscriptionState', function () { - it('should return the recurly state if it exists', function () { - const result = this.SubscriptionHelper.getPaidSubscriptionState({ + it('should return the recurly state if it exists', function (ctx) { + const result = ctx.SubscriptionHelper.getPaidSubscriptionState({ recurlyStatus: { state: 'active' }, }) expect(result).to.equal('active') }) - it('should return the payment provider state if it exists', function () { - const result = this.SubscriptionHelper.getPaidSubscriptionState({ + it('should return the payment provider state if it exists', function (ctx) { + const result = ctx.SubscriptionHelper.getPaidSubscriptionState({ paymentProvider: { state: 'active' }, }) expect(result).to.equal('active') }) - it('should return null if no state exists', function () { - const result = this.SubscriptionHelper.getPaidSubscriptionState({}) + it('should return null if no state exists', function (ctx) { + const result = ctx.SubscriptionHelper.getPaidSubscriptionState({}) expect(result).to.be.null }) }) describe('getSubscriptionTrialStartedAt', function () { - it('should return the recurly trial start date if it exists', function () { - const result = this.SubscriptionHelper.getSubscriptionTrialStartedAt({ + it('should return the recurly trial start date if it exists', function (ctx) { + const result = ctx.SubscriptionHelper.getSubscriptionTrialStartedAt({ recurlySubscription_id: 'some-id', recurlyStatus: { trialStartedAt: new Date('2023-01-01') }, }) expect(result).to.deep.equal(new Date('2023-01-01')) }) - it('should return the payment provider trial start date if it exists', function () { - const result = this.SubscriptionHelper.getSubscriptionTrialStartedAt({ + it('should return the payment provider trial start date if it exists', function (ctx) { + const result = ctx.SubscriptionHelper.getSubscriptionTrialStartedAt({ recurlyStatus: {}, paymentProvider: { trialStartedAt: new Date('2023-01-01') }, }) expect(result).to.deep.equal(new Date('2023-01-01')) }) - it('should return undefined if no trial start date exists', function () { - const result = this.SubscriptionHelper.getSubscriptionTrialStartedAt({}) + it('should return undefined if no trial start date exists', function (ctx) { + const result = ctx.SubscriptionHelper.getSubscriptionTrialStartedAt({}) expect(result).to.be.undefined }) }) describe('getSubscriptionTrialEndsAt', function () { - it('should return the recurly trial end date if it exists', function () { - const result = this.SubscriptionHelper.getSubscriptionTrialEndsAt({ + it('should return the recurly trial end date if it exists', function (ctx) { + const result = ctx.SubscriptionHelper.getSubscriptionTrialEndsAt({ recurlySubscription_id: 'some-id', recurlyStatus: { trialEndsAt: new Date('2023-01-01') }, }) expect(result).to.deep.equal(new Date('2023-01-01')) }) - it('should return the payment provider trial end date if it exists', function () { - const result = this.SubscriptionHelper.getSubscriptionTrialEndsAt({ + it('should return the payment provider trial end date if it exists', function (ctx) { + const result = ctx.SubscriptionHelper.getSubscriptionTrialEndsAt({ recurlyStatus: {}, paymentProvider: { trialEndsAt: new Date('2023-01-01') }, }) expect(result).to.deep.equal(new Date('2023-01-01')) }) - it('should return undefined if no trial end date exists', function () { - const result = this.SubscriptionHelper.getSubscriptionTrialEndsAt({}) + it('should return undefined if no trial end date exists', function (ctx) { + const result = ctx.SubscriptionHelper.getSubscriptionTrialEndsAt({}) expect(result).to.be.undefined }) }) describe('isInTrial', function () { - it('should return false if trialEndsAt is null', function () { - const result = this.SubscriptionHelper.isInTrial(null) + it('should return false if trialEndsAt is null', function (ctx) { + const result = ctx.SubscriptionHelper.isInTrial(null) expect(result).to.be.false }) - it('should return false if trialEndsAt is before now', function () { + it('should return false if trialEndsAt is before now', function (ctx) { const tenDaysAgo = new Date() tenDaysAgo.setDate(tenDaysAgo.getDate() - 10) - const result = this.SubscriptionHelper.isInTrial(tenDaysAgo) + const result = ctx.SubscriptionHelper.isInTrial(tenDaysAgo) expect(result).to.be.false }) - it('should return true if trialEndsAt is after now', function () { + it('should return true if trialEndsAt is after now', function (ctx) { const tenDaysFromNow = new Date() tenDaysFromNow.setDate(tenDaysFromNow.getDate() + 10) - const result = this.SubscriptionHelper.isInTrial(tenDaysFromNow) + const result = ctx.SubscriptionHelper.isInTrial(tenDaysFromNow) expect(result).to.be.true }) }) describe('recomputeSubscriptionState', function () { - beforeEach(function () { - this.clock.now = new Date('2023-06-15T10:00:00Z') + beforeEach(function (ctx) { + ctx.clock.now = new Date('2023-06-15T10:00:00Z') - this.baseSubscription = { + ctx.baseSubscription = { _id: 'subscription_id', paymentProvider: { service: 'stripe-test', @@ -541,16 +517,16 @@ describe('SubscriptionHelper', function () { }) describe('when subscription has no paymentProvider subscriptionId', function () { - it('should return subscription unchanged', async function () { + it('should return subscription unchanged', async function (ctx) { const subscription = { _id: 'subscription_id' } const result = - await this.SubscriptionHelper.recomputeSubscriptionState(subscription) + await ctx.SubscriptionHelper.recomputeSubscriptionState(subscription) expect(result).to.equal(subscription) }) }) describe('when subscription has no pausePeriodStart', function () { - it('should return subscription unchanged', async function () { + it('should return subscription unchanged', async function (ctx) { const subscription = { _id: 'subscription_id', paymentProvider: { @@ -559,22 +535,22 @@ describe('SubscriptionHelper', function () { }, } const result = - await this.SubscriptionHelper.recomputeSubscriptionState(subscription) + await ctx.SubscriptionHelper.recomputeSubscriptionState(subscription) expect(result).to.equal(subscription) }) }) describe('when subscription should be paused', function () { describe('and current state is active', function () { - it('should change state to paused', async function () { - const subscription = { ...this.baseSubscription } + it('should change state to paused', async function (ctx) { + const subscription = { ...ctx.baseSubscription } const result = - await this.SubscriptionHelper.recomputeSubscriptionState( + await ctx.SubscriptionHelper.recomputeSubscriptionState( subscription ) expect(result.paymentProvider.state).to.equal('paused') - expect(this.Subscription.updateOne).to.have.been.calledWith( + expect(ctx.Subscription.updateOne).to.have.been.calledWith( { _id: 'subscription_id' }, { 'paymentProvider.state': 'paused' } ) @@ -582,64 +558,64 @@ describe('SubscriptionHelper', function () { }) describe('and current state is already paused', function () { - it('should not change state', async function () { + it('should not change state', async function (ctx) { const subscription = { - ...this.baseSubscription, + ...ctx.baseSubscription, paymentProvider: { - ...this.baseSubscription.paymentProvider, + ...ctx.baseSubscription.paymentProvider, state: 'paused', }, } const result = - await this.SubscriptionHelper.recomputeSubscriptionState( + await ctx.SubscriptionHelper.recomputeSubscriptionState( subscription ) expect(result.paymentProvider.state).to.equal('paused') - expect(this.Subscription.updateOne.called).to.be.false + expect(ctx.Subscription.updateOne.called).to.be.false }) }) }) describe('when subscription should not be paused', function () { describe('before pause period starts', function () { - beforeEach(function () { - this.clock.now = new Date('2023-06-15T08:00:00Z') + beforeEach(function (ctx) { + ctx.clock.now = new Date('2023-06-15T08:00:00Z') }) - it('should keep active state unchanged', async function () { - const subscription = { ...this.baseSubscription } + it('should keep active state unchanged', async function (ctx) { + const subscription = { ...ctx.baseSubscription } const result = - await this.SubscriptionHelper.recomputeSubscriptionState( + await ctx.SubscriptionHelper.recomputeSubscriptionState( subscription ) expect(result.paymentProvider.state).to.equal('active') - expect(this.Subscription.updateOne.called).to.be.false + expect(ctx.Subscription.updateOne.called).to.be.false }) }) describe('after pause period ends', function () { - beforeEach(function () { - this.clock.now = new Date('2023-06-15T12:00:00Z') + beforeEach(function (ctx) { + ctx.clock.now = new Date('2023-06-15T12:00:00Z') }) describe('and current state is paused', function () { - it('should change state to active', async function () { + it('should change state to active', async function (ctx) { const subscription = { - ...this.baseSubscription, + ...ctx.baseSubscription, paymentProvider: { - ...this.baseSubscription.paymentProvider, + ...ctx.baseSubscription.paymentProvider, state: 'paused', }, } const result = - await this.SubscriptionHelper.recomputeSubscriptionState( + await ctx.SubscriptionHelper.recomputeSubscriptionState( subscription ) expect(result.paymentProvider.state).to.equal('active') - expect(this.Subscription.updateOne).to.have.been.calledWith( + expect(ctx.Subscription.updateOne).to.have.been.calledWith( { _id: 'subscription_id' }, { 'paymentProvider.state': 'active' } ) @@ -647,112 +623,112 @@ describe('SubscriptionHelper', function () { }) describe('and current state is already active', function () { - it('should keep state unchanged', async function () { - const subscription = { ...this.baseSubscription } + it('should keep state unchanged', async function (ctx) { + const subscription = { ...ctx.baseSubscription } const result = - await this.SubscriptionHelper.recomputeSubscriptionState( + await ctx.SubscriptionHelper.recomputeSubscriptionState( subscription ) expect(result.paymentProvider.state).to.equal('active') - expect(this.Subscription.updateOne.called).to.be.false + expect(ctx.Subscription.updateOne.called).to.be.false }) }) }) }) describe('when subscription has no pausePeriodEnd (indefinite pause)', function () { - beforeEach(function () { - this.baseSubscription.paymentProvider.pausePeriodEnd = undefined + beforeEach(function (ctx) { + ctx.baseSubscription.paymentProvider.pausePeriodEnd = undefined }) - it('should not transition to paused state when pausePeriodEnd is missing', async function () { - const subscription = { ...this.baseSubscription } + it('should not transition to paused state when pausePeriodEnd is missing', async function (ctx) { + const subscription = { ...ctx.baseSubscription } const result = - await this.SubscriptionHelper.recomputeSubscriptionState(subscription) + await ctx.SubscriptionHelper.recomputeSubscriptionState(subscription) expect(result.paymentProvider.state).to.equal('active') - expect(this.Subscription.updateOne.called).to.be.false + expect(ctx.Subscription.updateOne.called).to.be.false }) - it('should keep paused state when already paused and no end date', async function () { + it('should keep paused state when already paused and no end date', async function (ctx) { const subscription = { - ...this.baseSubscription, + ...ctx.baseSubscription, paymentProvider: { - ...this.baseSubscription.paymentProvider, + ...ctx.baseSubscription.paymentProvider, state: 'paused', pausePeriodEnd: undefined, }, } const result = - await this.SubscriptionHelper.recomputeSubscriptionState(subscription) + await ctx.SubscriptionHelper.recomputeSubscriptionState(subscription) expect(result.paymentProvider.state).to.equal('paused') - expect(this.Subscription.updateOne.called).to.be.false + expect(ctx.Subscription.updateOne.called).to.be.false }) }) }) describe('getRecurlyCustomerAdminUrl', function () { - beforeEach(function () { - this.settings.siteUrl = 'https://www.overleaf.com' + beforeEach(function (ctx) { + ctx.settings.siteUrl = 'https://www.overleaf.com' }) - it('should return production Recurly account URL', function () { + it('should return production Recurly account URL', function (ctx) { const result = - this.SubscriptionHelper.getRecurlyCustomerAdminUrl('user_789') + ctx.SubscriptionHelper.getRecurlyCustomerAdminUrl('user_789') expect(result).to.equal( 'https://sharelatex.recurly.com/accounts/user_789' ) }) - it('should return sandbox Recurly account URL for dev environment', function () { - this.settings.siteUrl = 'https://dev-overleaf.com' + it('should return sandbox Recurly account URL for dev environment', function (ctx) { + ctx.settings.siteUrl = 'https://dev-overleaf.com' const result = - this.SubscriptionHelper.getRecurlyCustomerAdminUrl('user_789') + ctx.SubscriptionHelper.getRecurlyCustomerAdminUrl('user_789') expect(result).to.equal( 'https://sharelatex-sandbox.recurly.com/accounts/user_789' ) }) - it('should return sandbox Recurly account URL for staging environment', function () { - this.settings.siteUrl = 'https://stag-overleaf.com' + it('should return sandbox Recurly account URL for staging environment', function (ctx) { + ctx.settings.siteUrl = 'https://stag-overleaf.com' const result = - this.SubscriptionHelper.getRecurlyCustomerAdminUrl('user_789') + ctx.SubscriptionHelper.getRecurlyCustomerAdminUrl('user_789') expect(result).to.equal( 'https://sharelatex-sandbox.recurly.com/accounts/user_789' ) }) - it('should return null if customerId is null', function () { - const result = this.SubscriptionHelper.getRecurlyCustomerAdminUrl(null) + it('should return null if customerId is null', function (ctx) { + const result = ctx.SubscriptionHelper.getRecurlyCustomerAdminUrl(null) expect(result).to.be.null }) - it('should return null if customerId is undefined', function () { + it('should return null if customerId is undefined', function (ctx) { const result = - this.SubscriptionHelper.getRecurlyCustomerAdminUrl(undefined) + ctx.SubscriptionHelper.getRecurlyCustomerAdminUrl(undefined) expect(result).to.be.null }) - it('should handle empty string customerId', function () { - const result = this.SubscriptionHelper.getRecurlyCustomerAdminUrl('') + it('should handle empty string customerId', function (ctx) { + const result = ctx.SubscriptionHelper.getRecurlyCustomerAdminUrl('') expect(result).to.equal('https://sharelatex.recurly.com/accounts/') }) }) describe('getStripeCustomerAdminUrl', function () { - beforeEach(function () { - this.settings.siteUrl = 'https://www.overleaf.com' - this.settings.apis = { + beforeEach(function (ctx) { + ctx.settings.siteUrl = 'https://www.overleaf.com' + ctx.settings.apis = { stripeUS: { accountId: 'acct_us_123' }, stripeUK: { accountId: 'acct_uk_456' }, } }) describe('stripe-us', function () { - it('should return production Stripe US customer URL', function () { - const result = this.SubscriptionHelper.getStripeCustomerAdminUrl( + it('should return production Stripe US customer URL', function (ctx) { + const result = ctx.SubscriptionHelper.getStripeCustomerAdminUrl( 'cus_us_789', 'stripe-us' ) @@ -761,9 +737,9 @@ describe('SubscriptionHelper', function () { ) }) - it('should return test Stripe US customer URL for dev environment', function () { - this.settings.siteUrl = 'https://dev-overleaf.com' - const result = this.SubscriptionHelper.getStripeCustomerAdminUrl( + it('should return test Stripe US customer URL for dev environment', function (ctx) { + ctx.settings.siteUrl = 'https://dev-overleaf.com' + const result = ctx.SubscriptionHelper.getStripeCustomerAdminUrl( 'cus_us_789', 'stripe-us' ) @@ -772,9 +748,9 @@ describe('SubscriptionHelper', function () { ) }) - it('should return test Stripe US customer URL for staging environment', function () { - this.settings.siteUrl = 'https://stag-overleaf.com' - const result = this.SubscriptionHelper.getStripeCustomerAdminUrl( + it('should return test Stripe US customer URL for staging environment', function (ctx) { + ctx.settings.siteUrl = 'https://stag-overleaf.com' + const result = ctx.SubscriptionHelper.getStripeCustomerAdminUrl( 'cus_us_789', 'stripe-us' ) @@ -785,8 +761,8 @@ describe('SubscriptionHelper', function () { }) describe('stripe-uk', function () { - it('should return production Stripe UK customer URL', function () { - const result = this.SubscriptionHelper.getStripeCustomerAdminUrl( + it('should return production Stripe UK customer URL', function (ctx) { + const result = ctx.SubscriptionHelper.getStripeCustomerAdminUrl( 'cus_uk_123', 'stripe-uk' ) @@ -795,9 +771,9 @@ describe('SubscriptionHelper', function () { ) }) - it('should return test Stripe UK customer URL for dev environment', function () { - this.settings.siteUrl = 'https://dev-overleaf.com' - const result = this.SubscriptionHelper.getStripeCustomerAdminUrl( + it('should return test Stripe UK customer URL for dev environment', function (ctx) { + ctx.settings.siteUrl = 'https://dev-overleaf.com' + const result = ctx.SubscriptionHelper.getStripeCustomerAdminUrl( 'cus_uk_123', 'stripe-uk' ) @@ -807,75 +783,75 @@ describe('SubscriptionHelper', function () { }) }) - it('should return null if accountId is missing', function () { - this.settings.apis.stripeUS = {} - const result = this.SubscriptionHelper.getStripeCustomerAdminUrl( + it('should return null if accountId is missing', function (ctx) { + ctx.settings.apis.stripeUS = {} + const result = ctx.SubscriptionHelper.getStripeCustomerAdminUrl( 'cus_us_789', 'stripe-us' ) expect(result).to.be.null }) - it('should return null if customerId is null', function () { - const result = this.SubscriptionHelper.getStripeCustomerAdminUrl( + it('should return null if customerId is null', function (ctx) { + const result = ctx.SubscriptionHelper.getStripeCustomerAdminUrl( null, 'stripe-us' ) expect(result).to.be.null }) - it('should return null if service is null', function () { - const result = this.SubscriptionHelper.getStripeCustomerAdminUrl( + it('should return null if service is null', function (ctx) { + const result = ctx.SubscriptionHelper.getStripeCustomerAdminUrl( 'cus_us_789', null ) expect(result).to.be.null }) - it('should return null if customerId is undefined', function () { - const result = this.SubscriptionHelper.getStripeCustomerAdminUrl( + it('should return null if customerId is undefined', function (ctx) { + const result = ctx.SubscriptionHelper.getStripeCustomerAdminUrl( undefined, 'stripe-us' ) expect(result).to.be.null }) - it('should return null if service is undefined', function () { - const result = this.SubscriptionHelper.getStripeCustomerAdminUrl( + it('should return null if service is undefined', function (ctx) { + const result = ctx.SubscriptionHelper.getStripeCustomerAdminUrl( 'cus_us_789', undefined ) expect(result).to.be.null }) - it('should return null if both customerId and service are null', function () { - const result = this.SubscriptionHelper.getStripeCustomerAdminUrl( + it('should return null if both customerId and service are null', function (ctx) { + const result = ctx.SubscriptionHelper.getStripeCustomerAdminUrl( null, null ) expect(result).to.be.null }) - it('should return null if accountId is missing for UK', function () { - this.settings.apis.stripeUK = {} - const result = this.SubscriptionHelper.getStripeCustomerAdminUrl( + it('should return null if accountId is missing for UK', function (ctx) { + ctx.settings.apis.stripeUK = {} + const result = ctx.SubscriptionHelper.getStripeCustomerAdminUrl( 'cus_uk_789', 'stripe-uk' ) expect(result).to.be.null }) - it('should return null if apis object is missing', function () { - this.settings.apis = {} - const result = this.SubscriptionHelper.getStripeCustomerAdminUrl( + it('should return null if apis object is missing', function (ctx) { + ctx.settings.apis = {} + const result = ctx.SubscriptionHelper.getStripeCustomerAdminUrl( 'cus_us_789', 'stripe-us' ) expect(result).to.be.null }) - it('should handle empty string customerId', function () { - const result = this.SubscriptionHelper.getStripeCustomerAdminUrl( + it('should handle empty string customerId', function (ctx) { + const result = ctx.SubscriptionHelper.getStripeCustomerAdminUrl( '', 'stripe-us' ) @@ -884,8 +860,8 @@ describe('SubscriptionHelper', function () { ) }) - it('should return null if service is not stripe-us or stripe-uk', function () { - const result = this.SubscriptionHelper.getStripeCustomerAdminUrl( + it('should return null if service is not stripe-us or stripe-uk', function (ctx) { + const result = ctx.SubscriptionHelper.getStripeCustomerAdminUrl( 'cus_us_789', 'some-other-service' ) diff --git a/services/web/test/unit/src/Subscription/SubscriptionViewModelBuilder.test.mjs b/services/web/test/unit/src/Subscription/SubscriptionViewModelBuilder.test.mjs index 90737cf3df..336679b070 100644 --- a/services/web/test/unit/src/Subscription/SubscriptionViewModelBuilder.test.mjs +++ b/services/web/test/unit/src/Subscription/SubscriptionViewModelBuilder.test.mjs @@ -1,7 +1,7 @@ import { vi, assert } from 'vitest' import sinon from 'sinon' import PaymentProviderEntities from '../../../../app/src/Features/Subscription/PaymentProviderEntities.mjs' -import SubscriptionHelper from '../../../../app/src/Features/Subscription/SubscriptionHelper.js' +import SubscriptionHelper from '../../../../app/src/Features/Subscription/SubscriptionHelper.mjs' const { PaymentProviderAccount, diff --git a/services/web/test/unit/src/Tags/TagsHandler.test.mjs b/services/web/test/unit/src/Tags/TagsHandler.test.mjs index b1f2fdb545..f7562f787a 100644 --- a/services/web/test/unit/src/Tags/TagsHandler.test.mjs +++ b/services/web/test/unit/src/Tags/TagsHandler.test.mjs @@ -1,8 +1,8 @@ import { vi, expect } from 'vitest' import sinon from 'sinon' -import { Tag } from '../helpers/models/Tag.js' import mongodb from 'mongodb-legacy' import path from 'node:path' +import { Tag } from '../../../../app/src/models/Tag.mjs' const { ObjectId } = mongodb const modulePath = path.join( diff --git a/services/web/test/unit/src/ThirdPartyDataStore/TpdsProjectFlusher.test.mjs b/services/web/test/unit/src/ThirdPartyDataStore/TpdsProjectFlusher.test.mjs index 64c7782c3f..11aa7bc7bd 100644 --- a/services/web/test/unit/src/ThirdPartyDataStore/TpdsProjectFlusher.test.mjs +++ b/services/web/test/unit/src/ThirdPartyDataStore/TpdsProjectFlusher.test.mjs @@ -1,9 +1,7 @@ import { vi, expect } from 'vitest' import sinon from 'sinon' import mongodb from 'mongodb-legacy' -import indirectlyImportModels from '../helpers/indirectlyImportModels.js' - -const { Project } = indirectlyImportModels(['Project']) +import { Project } from '../../../../app/src/models/Project.mjs' const { ObjectId } = mongodb diff --git a/services/web/test/unit/src/User/UserAuditLogHandler.test.mjs b/services/web/test/unit/src/User/UserAuditLogHandler.test.mjs index 7e3bb5bbb4..7bda3b03f8 100644 --- a/services/web/test/unit/src/User/UserAuditLogHandler.test.mjs +++ b/services/web/test/unit/src/User/UserAuditLogHandler.test.mjs @@ -1,9 +1,7 @@ import { vi, expect } from 'vitest' import sinon from 'sinon' import mongodb from 'mongodb-legacy' -import indirectlyImportModels from '../helpers/indirectlyImportModels.js' - -const { UserAuditLogEntry } = indirectlyImportModels(['UserAuditLogEntry']) +import { UserAuditLogEntry } from '../../../../app/src/models/UserAuditLogEntry.mjs' const { ObjectId } = mongodb diff --git a/services/web/test/unit/src/User/UserDeleter.test.mjs b/services/web/test/unit/src/User/UserDeleter.test.mjs index 3baf70edd3..5e41c89a80 100644 --- a/services/web/test/unit/src/User/UserDeleter.test.mjs +++ b/services/web/test/unit/src/User/UserDeleter.test.mjs @@ -4,9 +4,8 @@ import tk from 'timekeeper' import moment from 'moment' import Errors from '../../../../app/src/Features/Errors/Errors.js' import mongoose from 'mongoose' -import indirectlyImportModels from '../helpers/indirectlyImportModels.js' - -const { User, DeletedUser } = indirectlyImportModels(['User', 'DeletedUser']) +import { DeletedUser } from '../../../../app/src/models/DeletedUser.mjs' +import { User } from '../../../../app/src/models/User.mjs' const ObjectId = mongoose.Types.ObjectId diff --git a/services/web/test/unit/src/User/UserEmailsConfirmationHandler.test.mjs b/services/web/test/unit/src/User/UserEmailsConfirmationHandler.test.mjs index 9c23805a9c..6ed79d7874 100644 --- a/services/web/test/unit/src/User/UserEmailsConfirmationHandler.test.mjs +++ b/services/web/test/unit/src/User/UserEmailsConfirmationHandler.test.mjs @@ -10,7 +10,7 @@ import { vi, expect } from 'vitest' import sinon from 'sinon' import Errors from '../../../../app/src/Features/Errors/Errors.js' -import EmailHelper from '../../../../app/src/Features/Helpers/EmailHelper.js' +import EmailHelper from '../../../../app/src/Features/Helpers/EmailHelper.mjs' const modulePath = '../../../../app/src/Features/User/UserEmailsConfirmationHandler' diff --git a/services/web/test/unit/src/User/UserRegistrationHandler.test.mjs b/services/web/test/unit/src/User/UserRegistrationHandler.test.mjs index f8e7e50826..ce1f478fbf 100644 --- a/services/web/test/unit/src/User/UserRegistrationHandler.test.mjs +++ b/services/web/test/unit/src/User/UserRegistrationHandler.test.mjs @@ -1,7 +1,7 @@ import { vi, expect } from 'vitest' import assert from 'assert' import sinon from 'sinon' -import EmailHelper from '../../../../app/src/Features/Helpers/EmailHelper.js' +import EmailHelper from '../../../../app/src/Features/Helpers/EmailHelper.mjs' const modulePath = '../../../../app/src/Features/User/UserRegistrationHandler' diff --git a/services/web/test/unit/src/UserMembership/UserMembershipsHandler.test.mjs b/services/web/test/unit/src/UserMembership/UserMembershipsHandler.test.mjs index d06510fc44..7885d1fa8f 100644 --- a/services/web/test/unit/src/UserMembership/UserMembershipsHandler.test.mjs +++ b/services/web/test/unit/src/UserMembership/UserMembershipsHandler.test.mjs @@ -17,15 +17,15 @@ describe('UserMembershipsHandler', function () { ctx.Publisher = { updateMany: sinon.stub().resolves(null) } vi.doMock('../../../../app/src/models/Institution', () => ({ - default: { Institution: ctx.Institution }, + Institution: ctx.Institution, })) vi.doMock('../../../../app/src/models/Subscription', () => ({ - default: { Subscription: ctx.Subscription }, + Subscription: ctx.Subscription, })) vi.doMock('../../../../app/src/models/Publisher', () => ({ - default: { Publisher: ctx.Publisher }, + Publisher: ctx.Publisher, })) ctx.UserMembershipsHandler = (await import(modulePath)).default diff --git a/services/web/test/unit/src/helpers/MockModel.js b/services/web/test/unit/src/helpers/MockModel.js deleted file mode 100644 index 764dd5240a..0000000000 --- a/services/web/test/unit/src/helpers/MockModel.js +++ /dev/null @@ -1,39 +0,0 @@ -const SandboxedModule = require('sandboxed-module') -const mongoose = require('mongoose') - -/** - * Imports a model as we would usually do with e.g. `require('models/User')` - * an returns a model an schema, but without connecting to Mongo. This allows - * us to use model classes in tests, and to use them with `sinon-mongoose` - * - * @param modelName the name of the model - e.g. 'User' - * @param requires additional `requires` to be passed to SanboxedModule in - * the event that these also need to be stubbed. For example, - * additional dependent models to be included - * - * @return model and schema pair - e.g. { User, UserSchema } - */ - -module.exports = (modelName, requires = {}) => { - const model = {} - - requires['../infrastructure/Mongoose'] = { - createConnection: () => { - return { - model: () => {}, - } - }, - model: (modelName, schema) => { - model[modelName + 'Schema'] = schema - model[modelName] = mongoose.model(modelName, schema) - }, - Schema: mongoose.Schema, - Types: mongoose.Types, - } - - SandboxedModule.require('../../../../app/src/models/' + modelName, { - requires, - }) - - return model -} diff --git a/services/web/test/unit/src/helpers/indirectlyImportModels.js b/services/web/test/unit/src/helpers/indirectlyImportModels.js deleted file mode 100644 index cfa4706b49..0000000000 --- a/services/web/test/unit/src/helpers/indirectlyImportModels.js +++ /dev/null @@ -1,19 +0,0 @@ -// When importing models in vitest unit tests we need to import them from a CJS file -// instead of directly from the test file so that we can mock the model when it is imported via CJS -// and make sure that is in the require cache for other imports. -// -// TODO: This helper can be removed when all models are converted to ESM and vitest can handle them correctly. - -/** - * - * @param {string[]} models - */ -module.exports = function (models) { - return models.reduce((exports, model) => { - const module = require(`./models/${model}`) - return { - ...exports, - ...module, - } - }, {}) -} diff --git a/services/web/test/unit/src/helpers/models/DeletedProject.js b/services/web/test/unit/src/helpers/models/DeletedProject.js deleted file mode 100644 index f3537bcb43..0000000000 --- a/services/web/test/unit/src/helpers/models/DeletedProject.js +++ /dev/null @@ -1,5 +0,0 @@ -const mockModel = require('../MockModel') - -module.exports = mockModel('DeletedProject', { - './Project': require('./Project'), -}) diff --git a/services/web/test/unit/src/helpers/models/DeletedUser.js b/services/web/test/unit/src/helpers/models/DeletedUser.js deleted file mode 100644 index 92d932c784..0000000000 --- a/services/web/test/unit/src/helpers/models/DeletedUser.js +++ /dev/null @@ -1,5 +0,0 @@ -const mockModel = require('../MockModel') - -module.exports = mockModel('DeletedUser', { - './User': require('./User'), -}) diff --git a/services/web/test/unit/src/helpers/models/Doc.js b/services/web/test/unit/src/helpers/models/Doc.js deleted file mode 100644 index ac7bed3683..0000000000 --- a/services/web/test/unit/src/helpers/models/Doc.js +++ /dev/null @@ -1,3 +0,0 @@ -const mockModel = require('../MockModel') - -module.exports = mockModel('Doc') diff --git a/services/web/test/unit/src/helpers/models/File.js b/services/web/test/unit/src/helpers/models/File.js deleted file mode 100644 index 3c57aa363e..0000000000 --- a/services/web/test/unit/src/helpers/models/File.js +++ /dev/null @@ -1,3 +0,0 @@ -const mockModel = require('../MockModel') - -module.exports = mockModel('File') diff --git a/services/web/test/unit/src/helpers/models/Folder.js b/services/web/test/unit/src/helpers/models/Folder.js deleted file mode 100644 index 3abf588ff9..0000000000 --- a/services/web/test/unit/src/helpers/models/Folder.js +++ /dev/null @@ -1,6 +0,0 @@ -const mockModel = require('../MockModel') - -module.exports = mockModel('Folder', { - './Doc': require('./Doc'), - './File': require('./File'), -}) diff --git a/services/web/test/unit/src/helpers/models/Project.js b/services/web/test/unit/src/helpers/models/Project.js deleted file mode 100644 index 508db37d85..0000000000 --- a/services/web/test/unit/src/helpers/models/Project.js +++ /dev/null @@ -1,5 +0,0 @@ -const mockModel = require('../MockModel') - -module.exports = mockModel('Project', { - './Folder': require('./Folder'), -}) diff --git a/services/web/test/unit/src/helpers/models/Tag.js b/services/web/test/unit/src/helpers/models/Tag.js deleted file mode 100644 index fa6c2aa1f5..0000000000 --- a/services/web/test/unit/src/helpers/models/Tag.js +++ /dev/null @@ -1,3 +0,0 @@ -const mockModel = require('../MockModel') - -module.exports = mockModel('Tag') diff --git a/services/web/test/unit/src/helpers/models/User.js b/services/web/test/unit/src/helpers/models/User.js deleted file mode 100644 index 7190fd6640..0000000000 --- a/services/web/test/unit/src/helpers/models/User.js +++ /dev/null @@ -1,5 +0,0 @@ -const mockModel = require('../MockModel') - -module.exports = mockModel('User', { - './Project': require('./Project'), -}) diff --git a/services/web/test/unit/src/helpers/models/UserAuditLogEntry.js b/services/web/test/unit/src/helpers/models/UserAuditLogEntry.js deleted file mode 100644 index f31838ba3d..0000000000 --- a/services/web/test/unit/src/helpers/models/UserAuditLogEntry.js +++ /dev/null @@ -1,3 +0,0 @@ -const mockModel = require('../MockModel') - -module.exports = mockModel('UserAuditLogEntry') diff --git a/services/web/test/unit/src/infrastructure/MongodbTests.js b/services/web/test/unit/src/infrastructure/Mongodb.test.mjs similarity index 98% rename from services/web/test/unit/src/infrastructure/MongodbTests.js rename to services/web/test/unit/src/infrastructure/Mongodb.test.mjs index 65cab5f7b6..28ae2c6171 100644 --- a/services/web/test/unit/src/infrastructure/MongodbTests.js +++ b/services/web/test/unit/src/infrastructure/Mongodb.test.mjs @@ -1,6 +1,8 @@ -const { ObjectId } = require('mongodb-legacy') -const { expect } = require('chai') -const sinon = require('sinon') +import mongodb from 'mongodb-legacy' +import { expect } from 'vitest' +import sinon from 'sinon' + +const { ObjectId } = mongodb describe('Mongo ObjectId comparison', function () { const ObjectId1 = new ObjectId('111111111111111111111111') diff --git a/services/web/test/unit/vitest_bootstrap.mjs b/services/web/test/unit/vitest_bootstrap.mjs index 50ff559bc9..cc057bd1f0 100644 --- a/services/web/test/unit/vitest_bootstrap.mjs +++ b/services/web/test/unit/vitest_bootstrap.mjs @@ -4,35 +4,7 @@ import sinon from 'sinon' import logger from '@overleaf/logger' import sinonChai from 'sinon-chai' import chaiAsPromised from 'chai-as-promised' -import SandboxedModule from 'sandboxed-module' -import { createRequire } from 'module' - -const require = createRequire(import.meta.url) - -SandboxedModule.configure({ - ignoreMissing: true, - requires: { - // This is already imported the same way in the mocha bootstrap - // eslint-disable-next-line import/no-extraneous-dependencies - sshpk: require('sshpk'), - }, - globals: { - AbortController, - AbortSignal, - Buffer, - Promise, - console, - process, - URL, - TextEncoder, - TextDecoder, - }, - sourceTransformers: { - removeNodePrefix: function (source) { - return source.replace(/require\(['"]node:/g, "require('") - }, - }, -}) +import mongoose from 'mongoose' /* * Chai configuration @@ -80,4 +52,8 @@ afterEach(() => { vi.restoreAllMocks() vi.resetModules() sinon.restore() + const modelNames = mongoose.modelNames() + modelNames.forEach(name => { + delete mongoose.connection.models[name] + }) })