diff --git a/services/web/app/src/Features/Authentication/AuthenticationController.mjs b/services/web/app/src/Features/Authentication/AuthenticationController.mjs index f698c2fd3e..62efb907b3 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.mjs' +import EmailHelper from '../Helpers/EmailHelper.js' const { hasAdminAccess } = AdminAuthorizationHelper diff --git a/services/web/app/src/Features/Authentication/AuthenticationManager.mjs b/services/web/app/src/Features/Authentication/AuthenticationManager.mjs index 0d45c4eaa8..c4455b7f51 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.mjs' +import { User } from '../../models/User.js' import { db, ObjectId } from '../../infrastructure/mongodb.js' import bcrypt from 'bcrypt' -import EmailHelper from '../Helpers/EmailHelper.mjs' +import EmailHelper from '../Helpers/EmailHelper.js' 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.mjs' +import DiffHelper from '../Helpers/DiffHelper.js' 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 7a9be587b9..55ce69e738 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.mjs' +import { User } from '../../models/User.js' 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 45e0902617..42ae80d8cf 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.mjs' +import EmailsHelper from '../Helpers/EmailHelper.js' 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 aa84824e76..39b1bf12df 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.mjs' +import { Project } from '../../models/Project.js' 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 b75a06f955..54d2112740 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.mjs' +import { Project } from '../../models/Project.js' 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 ab7f366315..1eee8a6936 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.mjs' +import { Project } from '../../models/Project.js' 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 75d280701e..33bdefd212 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.mjs' +import EmailHelper from '../Helpers/EmailHelper.js' 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 8ce4651e49..766f1f4708 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.mjs' +import { ProjectInvite } from '../../models/ProjectInvite.js' 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 4c956dc102..58c99eeba5 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.mjs' +import { ProjectInvite } from '../../models/ProjectInvite.js' 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 093f6893c8..79ed8b0435 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.mjs' +import { Project } from '../../models/Project.js' 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.mjs b/services/web/app/src/Features/Cooldown/CooldownManager.js similarity index 83% rename from services/web/app/src/Features/Cooldown/CooldownManager.mjs rename to services/web/app/src/Features/Cooldown/CooldownManager.js index 5f190d1a08..8c6b708c07 100644 --- a/services/web/app/src/Features/Cooldown/CooldownManager.mjs +++ b/services/web/app/src/Features/Cooldown/CooldownManager.js @@ -1,7 +1,7 @@ -import RedisWrapper from '../../infrastructure/RedisWrapper.js' -import logger from '@overleaf/logger' -import { promisify } from '@overleaf/promise-utils' +const RedisWrapper = require('../../infrastructure/RedisWrapper') 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), } -export default CooldownManager +module.exports = CooldownManager diff --git a/services/web/app/src/Features/Cooldown/CooldownMiddleware.mjs b/services/web/app/src/Features/Cooldown/CooldownMiddleware.mjs index d2d1cb01e3..46a84eb571 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.mjs' +import CooldownManager from './CooldownManager.js' 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 6abc6602b9..982616f44b 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.mjs' +import { File } from '../../models/File.js' 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 5be629f490..d8991614d7 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.mjs' +import { GlobalMetric } from '../../models/GlobalMetric.js' /** * 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 9d16102113..9bac0c0769 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.mjs' +import { UserSchema } from '../../models/User.js' export default { hasAnyStaffAccess, diff --git a/services/web/app/src/Features/Helpers/DiffHelper.mjs b/services/web/app/src/Features/Helpers/DiffHelper.js similarity index 95% rename from services/web/app/src/Features/Helpers/DiffHelper.mjs rename to services/web/app/src/Features/Helpers/DiffHelper.js index b8b2b3005a..c2d1d73fd3 100644 --- a/services/web/app/src/Features/Helpers/DiffHelper.mjs +++ b/services/web/app/src/Features/Helpers/DiffHelper.js @@ -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 * */ -export function stringSimilarity(a, b) { +function stringSimilarity(a, b) { if ( typeof a !== 'string' || typeof b !== 'string' || @@ -50,6 +50,6 @@ export function stringSimilarity(a, b) { return _calculateRatio(matches, a.length + b.length) } -export default { +module.exports = { stringSimilarity, } diff --git a/services/web/app/src/Features/Helpers/EmailHelper.mjs b/services/web/app/src/Features/Helpers/EmailHelper.js similarity index 90% rename from services/web/app/src/Features/Helpers/EmailHelper.mjs rename to services/web/app/src/Features/Helpers/EmailHelper.js index 34e96b91d9..80b96dfea0 100644 --- a/services/web/app/src/Features/Helpers/EmailHelper.mjs +++ b/services/web/app/src/Features/Helpers/EmailHelper.js @@ -1,6 +1,4 @@ -import emailAddresses from 'email-addresses' - -const { parseOneAddress } = emailAddresses +const { parseOneAddress } = require('email-addresses') // available for frontend in https://github.com/overleaf/internal/blob/19d432c70b173752ee7c6d8978dd6be16b042921/services/web/frontend/js/shared/utils/email.tsx#L4 const EMAIL_REGEXP = @@ -38,7 +36,7 @@ function parseEmail(email, parseRfcAddress = false) { return matched[0] } -export default { +module.exports = { getDomain, parseEmail, } diff --git a/services/web/app/src/Features/InactiveData/InactiveProjectManager.mjs b/services/web/app/src/Features/InactiveData/InactiveProjectManager.mjs index be91231fd3..6ec4c0f6b4 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.mjs' +import { Project } from '../../models/Project.js' 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 989aa6596b..9c6c9d2f6e 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.mjs' -import { Subscription } from '../../models/Subscription.mjs' +import { Institution } from '../../models/Institution.js' +import { Subscription } from '../../models/Subscription.js' 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 4bbc9069b8..2cd8272ece 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.mjs' +import { Project } from '../../models/Project.js' 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 99bb0a3d7a..8359add440 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.mjs' +import OnboardingDataCollectionModel from '../../models/OnboardingDataCollection.js' 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 a945c93ffd..d9221f23b5 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.mjs' +import EmailsHelper from '../Helpers/EmailHelper.js' 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 33d785e80f..5ff08f36c2 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.mjs' +import OneTimeTokenHandler from '../Security/OneTimeTokenHandler.js' 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.mjs b/services/web/app/src/Features/Project/IterablePath.js similarity index 74% rename from services/web/app/src/Features/Project/IterablePath.mjs rename to services/web/app/src/Features/Project/IterablePath.js index 1c6ad90eb5..52cf068c42 100644 --- a/services/web/app/src/Features/Project/IterablePath.mjs +++ b/services/web/app/src/Features/Project/IterablePath.js @@ -3,9 +3,13 @@ * `folder.folders` or `folder.fileRefs` are missing it returns an * empty array. */ -export function iterablePaths(folder, field) { +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 753987c0b7..8a594a7801 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.mjs' +import { ProjectAuditLogEntry } from '../../models/ProjectAuditLogEntry.js' 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 d9f66b66fc..55d19a4bd6 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.mjs' +import { Project } from '../../models/Project.js' 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 6186f9af44..5d89b2c850 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.mjs' +import { User } from '../../models/User.js' import SubscriptionLocator from '../Subscription/SubscriptionLocator.mjs' -import SubscriptionHelper from '../Subscription/SubscriptionHelper.mjs' +import { isPaidSubscription } from '../Subscription/SubscriptionHelper.js' import LimitationsManager from '../Subscription/LimitationsManager.mjs' import Settings from '@overleaf/settings' import AuthorizationManager from '../Authorization/AuthorizationManager.mjs' @@ -52,7 +52,6 @@ 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 03ad4437a2..ef614f7f05 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.mjs' -import { Folder } from '../../models/Folder.mjs' +import { Project } from '../../models/Project.js' +import { Folder } from '../../models/Folder.js' import ProjectEntityUpdateHandler from './ProjectEntityUpdateHandler.mjs' import ProjectDetailsHandler from './ProjectDetailsHandler.mjs' import HistoryManager from '../History/HistoryManager.mjs' -import { User } from '../../models/User.mjs' +import { User } from '../../models/User.js' 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 eda7671270..276e3765cb 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.mjs' -import { DeletedProject } from '../../models/DeletedProject.mjs' -import { ProjectAuditLogEntry } from '../../models/ProjectAuditLogEntry.mjs' +import { Project } from '../../models/Project.js' +import { DeletedProject } from '../../models/DeletedProject.js' +import { ProjectAuditLogEntry } from '../../models/ProjectAuditLogEntry.js' 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 a2116ecdf3..758429dae6 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.mjs' +import { Project } from '../../models/Project.js' 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 d125578651..1f2ec0f773 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.mjs' -import { File } from '../../models/File.mjs' +import { Doc } from '../../models/Doc.js' +import { File } from '../../models/File.js' 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 acc4e26438..8a2e18c0d8 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.mjs' +import { iterablePaths } from './IterablePath.js' 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 59e0d72619..2843621d52 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.mjs' +import CooldownManager from '../Cooldown/CooldownManager.js' import Errors from '../Errors/Errors.js' -import { Folder } from '../../models/Folder.mjs' +import { Folder } from '../../models/Folder.js' import LockManager from '../../infrastructure/LockManager.js' -import { Project } from '../../models/Project.mjs' +import { Project } from '../../models/Project.js' 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.mjs' +import { iterablePaths } from './IterablePath.js' const { ObjectId } = mongodb diff --git a/services/web/app/src/Features/Project/ProjectEntityUpdateHandler.mjs b/services/web/app/src/Features/Project/ProjectEntityUpdateHandler.mjs index 34d76d893c..0a482cea73 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.mjs' +import { Doc } from '../../models/Doc.js' 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.mjs' +import { Project } from '../../models/Project.js' 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.mjs' +import { iterablePaths } from './IterablePath.js' 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 2aafb73892..0903a0504c 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.mjs' +import { Project } from '../../models/Project.js' import LockManager from '../../infrastructure/LockManager.js' -import { DeletedProject } from '../../models/DeletedProject.mjs' +import { DeletedProject } from '../../models/DeletedProject.js' 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 adbae9dfab..b08533522e 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.mjs' +import { Project } from '../../models/Project.js' 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 0cfb78a099..2e5a5fc1e3 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.mjs' +import { User } from '../../models/User.js' 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.mjs' +import SubscriptionHelper from '../Subscription/SubscriptionHelper.js' import PermissionsManager from '../Authorization/PermissionsManager.mjs' import AnalyticsManager from '../Analytics/AnalyticsManager.mjs' -import { OnboardingDataCollection } from '../../models/OnboardingDataCollection.mjs' +import { OnboardingDataCollection } from '../../models/OnboardingDataCollection.js' 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 abc80b9dcb..3a3d8ba962 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.mjs' +import { iterablePaths } from './IterablePath.js' /** * @param project diff --git a/services/web/app/src/Features/Project/ProjectOptionsHandler.mjs b/services/web/app/src/Features/Project/ProjectOptionsHandler.mjs index d80e8c75c8..9d577fc35e 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.mjs' +import { Project } from '../../models/Project.js' 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 f4b366acc0..2352ef1ad1 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.mjs' +import { Project } from '../../models/Project.js' 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 5fb2c714b9..6e37a5c063 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.mjs' +import { User } from '../../models/User.js' 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 dfb725927b..5ee8541786 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.mjs' +import { User } from '../../models/User.js' 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 3821fbb6ea..1d389bb860 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.mjs' +import { User } from '../../models/User.js' 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 c55043291a..37845c6be2 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.mjs' +import { SamlLog } from '../../models/SamlLog.js' 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.mjs b/services/web/app/src/Features/Security/OneTimeTokenHandler.js similarity index 92% rename from services/web/app/src/Features/Security/OneTimeTokenHandler.mjs rename to services/web/app/src/Features/Security/OneTimeTokenHandler.js index 2bfb7844e3..2b38f15635 100644 --- a/services/web/app/src/Features/Security/OneTimeTokenHandler.mjs +++ b/services/web/app/src/Features/Security/OneTimeTokenHandler.js @@ -1,7 +1,7 @@ -import crypto from 'node:crypto' -import { db } from '../../infrastructure/mongodb.js' -import Errors from '../Errors/Errors.js' -import { callbackify } from 'node:util' +const crypto = require('crypto') +const { db } = require('../../infrastructure/mongodb') +const Errors = require('../Errors/Errors') +const { callbackify } = require('util') const ONE_HOUR_IN_S = 60 * 60 @@ -119,4 +119,4 @@ const OneTimeTokenHandler = { }, } -export default OneTimeTokenHandler +module.exports = OneTimeTokenHandler diff --git a/services/web/app/src/Features/SplitTests/SplitTestHandler.mjs b/services/web/app/src/Features/SplitTests/SplitTestHandler.mjs index 36501f2be4..df82b8074b 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.mjs' +import { SplitTest } from '../../models/SplitTest.js' 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 27b05dc6e1..587e75ef34 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.mjs' +import { SplitTest } from '../../models/SplitTest.js' 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 9b318ba5d2..ee75dfb017 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.mjs' +import SubscriptionHelper from './SubscriptionHelper.js' 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 0e5ba6aadf..089673c34d 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.mjs' +import SubscriptionHelper from './SubscriptionHelper.js' 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 0dade58bce..ca21ca6f51 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.mjs' +import SubscriptionHelper from './SubscriptionHelper.js' 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.mjs' +import { User } from '../../models/User.js' 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 f9fe532391..c308be313f 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.mjs' +import { Subscription } from '../../models/Subscription.js' 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 3a14f74cc0..3c6e485059 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.mjs' -import { Subscription } from '../../models/Subscription.mjs' -import { User } from '../../models/User.mjs' +import SubscriptionHelper from './SubscriptionHelper.js' +import { Subscription } from '../../models/Subscription.js' +import { User } from '../../models/User.js' 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.mjs' +import EmailHelper from '../Helpers/EmailHelper.js' 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 edd5456230..774705654e 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.mjs' +import { User } from '../../models/User.js' import logger from '@overleaf/logger' -import SubscriptionHelper from './SubscriptionHelper.mjs' +import SubscriptionHelper from './SubscriptionHelper.js' 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.mjs b/services/web/app/src/Features/Subscription/SubscriptionHelper.js similarity index 95% rename from services/web/app/src/Features/Subscription/SubscriptionHelper.mjs rename to services/web/app/src/Features/Subscription/SubscriptionHelper.js index d97bc3bdd2..d65a7d3304 100644 --- a/services/web/app/src/Features/Subscription/SubscriptionHelper.mjs +++ b/services/web/app/src/Features/Subscription/SubscriptionHelper.js @@ -1,7 +1,7 @@ -import { formatCurrency } from '../../util/currency.js' -import GroupPlansData from './GroupPlansData.js' -import { isStandaloneAiAddOnPlanCode } from './AiHelper.js' -import { Subscription } from '../../models/Subscription.mjs' +const { formatCurrency } = require('../../util/currency') +const GroupPlansData = require('./GroupPlansData') +const { isStandaloneAiAddOnPlanCode } = require('./AiHelper') +const { Subscription } = require('../../models/Subscription') const MILLISECONDS = 1_000 /** @@ -196,7 +196,7 @@ function isInTrial(trialEndsAt) { return trialEndsAt.getTime() > Date.now() } -export default { +module.exports = { shouldPlanChangeAtTermEnd, generateInitialLocalizedGroupPrice, isPaidSubscription, diff --git a/services/web/app/src/Features/Subscription/SubscriptionLocator.mjs b/services/web/app/src/Features/Subscription/SubscriptionLocator.mjs index 3ded2be604..d4aa4477c9 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.mjs' -import SubscriptionHelper from './SubscriptionHelper.mjs' -import { DeletedSubscription } from '../../models/DeletedSubscription.mjs' +import { Subscription } from '../../models/Subscription.js' +import SubscriptionHelper from './SubscriptionHelper.js' +import { DeletedSubscription } from '../../models/DeletedSubscription.js' 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 6936a55634..39b1cf7025 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.mjs' +import { Subscription } from '../../models/Subscription.js' 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.mjs' +import { DeletedSubscription } from '../../models/DeletedSubscription.js' 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.mjs' +import { SSOConfig } from '../../models/SSOConfig.js' 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 b4e67c67e8..9fec3a8e5b 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.mjs' +import SubscriptionHelper from './SubscriptionHelper.js' 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 76f8a222dc..58c39bda37 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.mjs' +import SubscriptionHelper from './SubscriptionHelper.js' import ErrorController from '../Errors/ErrorController.mjs' -import EmailHelper from '../Helpers/EmailHelper.mjs' +import EmailHelper from '../Helpers/EmailHelper.js' 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 e1bb4e3abf..79d6aac79a 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.mjs' -import { SSOConfig } from '../../models/SSOConfig.mjs' +import { Subscription } from '../../models/Subscription.js' +import { SSOConfig } from '../../models/SSOConfig.js' 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.mjs' +import EmailHelper from '../Helpers/EmailHelper.js' 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 1c96063b8f..0fd61c791a 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.mjs' +import { User } from '../../models/User.js' 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 0c9332dcb4..d3552c25d7 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.mjs' +import { Survey } from '../../models/Survey.js' 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 6ecea42660..cbb23ca0fa 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.mjs' +import { Survey } from '../../models/Survey.js' 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 a664a56fba..0da9e302fe 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.mjs' +import { SystemMessage } from '../../models/SystemMessage.js' 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 53caadcc68..72bf9f79e0 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.mjs' +import { Tag } from '../../models/Tag.js' 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 aefab9ff13..b083cd77c7 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.mjs' +import { Project } from '../../models/Project.js' 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 206682972b..fa27faeda4 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.mjs' +import { Project } from '../../models/Project.js' 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 599db69109..85842195d9 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.mjs' +import CooldownManager from '../Cooldown/CooldownManager.js' 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 88d643707f..05b350f789 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.mjs' +import { Project } from '../../models/Project.js' 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 c1fce8f934..4e658903d6 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.mjs' +import { Doc } from '../../models/Doc.js' 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 dd14a29fc2..3d8e84a467 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.mjs' +import { User } from '../../models/User.js' 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 5da2254d31..65f3fa62c5 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.mjs' +import { User } from '../../../../app/src/models/User.js' 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 919dc30d8a..a617231f43 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.mjs' +import { UserAuditLogEntry } from '../../models/UserAuditLogEntry.js' 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 9a21c494d1..a66fedbbb7 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.mjs' +import { User } from '../../models/User.js' 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.mjs' +import OneTimeTokenHandler from '../Security/OneTimeTokenHandler.js' 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 08ed98b455..a5604f1f52 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.mjs' +import { User } from '../../models/User.js' 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 60704ae572..d3657a8696 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.mjs' -import { DeletedUser } from '../../models/DeletedUser.mjs' -import { UserAuditLogEntry } from '../../models/UserAuditLogEntry.mjs' -import { Feedback } from '../../models/Feedback.mjs' +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 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 444b4dda56..e85cca3a80 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.mjs' +import EmailHelper from '../Helpers/EmailHelper.js' import EmailHandler from '../Email/EmailHandler.mjs' -import OneTimeTokenHandler from '../Security/OneTimeTokenHandler.mjs' +import OneTimeTokenHandler from '../Security/OneTimeTokenHandler.js' 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 0a30410740..c63ce4cdd3 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.mjs' +import EmailHelper from '../Helpers/EmailHelper.js' 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 c8bce40136..d2cbda1441 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.mjs' +import { User } from '../../models/User.js' 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 5e77955da2..d01be0acf7 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.mjs' +import { User } from '../../models/User.js' 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.mjs' +import OneTimeTokenHandler from '../Security/OneTimeTokenHandler.js' import settings from '@overleaf/settings' -import EmailHelper from '../Helpers/EmailHelper.mjs' +import EmailHelper from '../Helpers/EmailHelper.js' 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 f45b0456d2..7356790d86 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.mjs' +import EmailHelper from '../Helpers/EmailHelper.js' 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 381299d910..257dd8ae2c 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.mjs' +import EmailHelper from '../Helpers/EmailHelper.js' import { csvAttachment } from '../../infrastructure/Response.js' import UserMembershipErrors from './UserMembershipErrors.mjs' -import { SSOConfig } from '../../models/SSOConfig.mjs' +import { SSOConfig } from '../../models/SSOConfig.js' 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 f34937df82..6e170f3e6b 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.mjs' -import { Subscription } from '../../models/Subscription.mjs' -import { Publisher } from '../../models/Publisher.mjs' +import { Institution } from '../../models/Institution.js' +import { Subscription } from '../../models/Subscription.js' +import { Publisher } from '../../models/Publisher.js' 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 fc1c6d0b8e..3e5239cdae 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 * as InstitutionModel from '../../models/Institution.mjs' -import * as SubscriptionModel from '../../models/Subscription.mjs' -import * as PublisherModel from '../../models/Publisher.mjs' +import InstitutionModel from '../../models/Institution.js' +import SubscriptionModel from '../../models/Subscription.js' +import PublisherModel from '../../models/Publisher.js' const EntityModels = { Institution: InstitutionModel.Institution, diff --git a/services/web/app/src/models/DeletedProject.mjs b/services/web/app/src/models/DeletedProject.js similarity index 79% rename from services/web/app/src/models/DeletedProject.mjs rename to services/web/app/src/models/DeletedProject.js index 652c052849..c1f6ce9e2c 100644 --- a/services/web/app/src/models/DeletedProject.mjs +++ b/services/web/app/src/models/DeletedProject.js @@ -1,10 +1,10 @@ -import mongoose from '../infrastructure/Mongoose.js' -import { ProjectSchema } from './Project.mjs' +const mongoose = require('../infrastructure/Mongoose') +const { ProjectSchema } = require('./Project') const { Schema } = mongoose const { ObjectId } = Schema -export const DeleterDataSchema = new Schema({ +const DeleterDataSchema = new Schema({ deleterId: { type: ObjectId, ref: 'User' }, deleterIpAddress: { type: String }, deletedAt: { type: Date }, @@ -30,7 +30,5 @@ const DeletedProjectSchema = new Schema( { collection: 'deletedProjects', minimize: false } ) -export const DeletedProject = mongoose.model( - 'DeletedProject', - DeletedProjectSchema -) +exports.DeletedProject = mongoose.model('DeletedProject', DeletedProjectSchema) +exports.DeletedProjectSchema = DeletedProjectSchema diff --git a/services/web/app/src/models/DeletedSubscription.mjs b/services/web/app/src/models/DeletedSubscription.js similarity index 66% rename from services/web/app/src/models/DeletedSubscription.mjs rename to services/web/app/src/models/DeletedSubscription.js index b37d2f1ea6..10b649d9be 100644 --- a/services/web/app/src/models/DeletedSubscription.mjs +++ b/services/web/app/src/models/DeletedSubscription.js @@ -1,10 +1,10 @@ -import mongoose from '../infrastructure/Mongoose.js' -import { SubscriptionSchema } from './Subscription.mjs' +const mongoose = require('../infrastructure/Mongoose') +const { SubscriptionSchema } = require('./Subscription') const { Schema } = mongoose const { ObjectId } = Schema -export const DeleterDataSchema = new Schema( +const DeleterDataSchema = new Schema( { deleterId: { type: ObjectId, ref: 'User' }, deleterIpAddress: { type: String }, @@ -26,7 +26,9 @@ const DeletedSubscriptionSchema = new Schema( { collection: 'deletedSubscriptions', minimize: false } ) -export const DeletedSubscription = mongoose.model( +exports.DeletedSubscription = mongoose.model( 'DeletedSubscription', DeletedSubscriptionSchema ) + +exports.DeletedSubscriptionSchema = DeletedSubscriptionSchema diff --git a/services/web/app/src/models/DeletedUser.mjs b/services/web/app/src/models/DeletedUser.js similarity index 73% rename from services/web/app/src/models/DeletedUser.mjs rename to services/web/app/src/models/DeletedUser.js index 17f221c3ce..5d20f9bb40 100644 --- a/services/web/app/src/models/DeletedUser.mjs +++ b/services/web/app/src/models/DeletedUser.js @@ -1,5 +1,5 @@ -import mongoose from '../infrastructure/Mongoose.js' -import { UserSchema } from './User.mjs' +const mongoose = require('../infrastructure/Mongoose') +const { UserSchema } = require('./User') const { Schema } = mongoose const { ObjectId } = Schema @@ -18,7 +18,7 @@ const DeleterDataSchema = new Schema({ deletedUserOverleafId: { type: Number }, }) -export const DeletedUserSchema = new Schema( +const DeletedUserSchema = new Schema( { deleterData: DeleterDataSchema, user: UserSchema, @@ -26,4 +26,6 @@ export const DeletedUserSchema = new Schema( { collection: 'deletedUsers', minimize: false } ) -export const DeletedUser = mongoose.model('DeletedUser', DeletedUserSchema) +exports.DeletedUser = mongoose.model('DeletedUser', DeletedUserSchema) + +exports.DeletedUserSchema = DeletedUserSchema diff --git a/services/web/app/src/models/Doc.js b/services/web/app/src/models/Doc.js new file mode 100644 index 0000000000..9f38ac0975 --- /dev/null +++ b/services/web/app/src/models/Doc.js @@ -0,0 +1,14 @@ +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 deleted file mode 100644 index c06ff3b775..0000000000 --- a/services/web/app/src/models/Doc.mjs +++ /dev/null @@ -1,12 +0,0 @@ -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.mjs b/services/web/app/src/models/DocSnapshot.js similarity index 70% rename from services/web/app/src/models/DocSnapshot.mjs rename to services/web/app/src/models/DocSnapshot.js index 0a5793f818..b851d4a94f 100644 --- a/services/web/app/src/models/DocSnapshot.mjs +++ b/services/web/app/src/models/DocSnapshot.js @@ -1,4 +1,4 @@ -import mongoose from '../infrastructure/Mongoose.js' +const mongoose = require('../infrastructure/Mongoose') const { Schema } = mongoose @@ -15,4 +15,4 @@ const DocSnapshotSchema = new Schema( { collection: 'docSnapshots', minimize: false } ) -export const DocSnapshot = mongoose.model('DocSnapshot', DocSnapshotSchema) +exports.DocSnapshot = mongoose.model('DocSnapshot', DocSnapshotSchema) diff --git a/services/web/app/src/models/Feedback.mjs b/services/web/app/src/models/Feedback.js similarity index 59% rename from services/web/app/src/models/Feedback.mjs rename to services/web/app/src/models/Feedback.js index ef583a0ac9..8b6382114f 100644 --- a/services/web/app/src/models/Feedback.mjs +++ b/services/web/app/src/models/Feedback.js @@ -1,8 +1,8 @@ -import mongoose from '../infrastructure/Mongoose.js' +const mongoose = require('../infrastructure/Mongoose') const { Schema } = mongoose const { ObjectId } = Schema -export const FeedbackSchema = new Schema( +const FeedbackSchema = new Schema( { userId: { type: ObjectId, @@ -20,4 +20,5 @@ export const FeedbackSchema = new Schema( { minimize: false } ) -export const Feedback = mongoose.model('Feedback', FeedbackSchema) +exports.Feedback = mongoose.model('Feedback', FeedbackSchema) +exports.FeedbackSchema = FeedbackSchema diff --git a/services/web/app/src/models/File.mjs b/services/web/app/src/models/File.js similarity index 67% rename from services/web/app/src/models/File.mjs rename to services/web/app/src/models/File.js index 60742e6797..5a7c772e3e 100644 --- a/services/web/app/src/models/File.mjs +++ b/services/web/app/src/models/File.js @@ -1,8 +1,8 @@ -import mongoose from '../infrastructure/Mongoose.js' +const mongoose = require('../infrastructure/Mongoose') const { Schema } = mongoose -export const FileSchema = new Schema( +const FileSchema = new Schema( { name: { type: String, @@ -23,4 +23,5 @@ export const FileSchema = new Schema( { minimize: false } ) -export const File = mongoose.model('File', FileSchema) +exports.File = mongoose.model('File', FileSchema) +exports.FileSchema = FileSchema diff --git a/services/web/app/src/models/Folder.js b/services/web/app/src/models/Folder.js new file mode 100644 index 0000000000..52312e90d8 --- /dev/null +++ b/services/web/app/src/models/Folder.js @@ -0,0 +1,21 @@ +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 deleted file mode 100644 index 7ac893f868..0000000000 --- a/services/web/app/src/models/Folder.mjs +++ /dev/null @@ -1,20 +0,0 @@ -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 new file mode 100644 index 0000000000..824c1478a2 --- /dev/null +++ b/services/web/app/src/models/GlobalMetric.js @@ -0,0 +1,19 @@ +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 deleted file mode 100644 index de019d40b2..0000000000 --- a/services/web/app/src/models/GlobalMetric.mjs +++ /dev/null @@ -1,18 +0,0 @@ -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.mjs b/services/web/app/src/models/GroupAuditLogEntry.js similarity index 66% rename from services/web/app/src/models/GroupAuditLogEntry.mjs rename to services/web/app/src/models/GroupAuditLogEntry.js index 5d834df350..3bda4ebf95 100644 --- a/services/web/app/src/models/GroupAuditLogEntry.mjs +++ b/services/web/app/src/models/GroupAuditLogEntry.js @@ -1,7 +1,7 @@ -import mongoose from '../infrastructure/Mongoose.js' +const mongoose = require('../infrastructure/Mongoose') const { Schema } = mongoose -export const GroupAuditLogEntrySchema = new Schema( +const GroupAuditLogEntrySchema = new Schema( { groupId: { type: Schema.Types.ObjectId, index: true }, info: { type: Object }, @@ -16,7 +16,8 @@ export const GroupAuditLogEntrySchema = new Schema( } ) -export const GroupAuditLogEntry = mongoose.model( +exports.GroupAuditLogEntry = mongoose.model( 'GroupAuditLogEntry', GroupAuditLogEntrySchema ) +exports.GroupAuditLogEntrySchema = GroupAuditLogEntrySchema diff --git a/services/web/app/src/models/GroupPolicy.mjs b/services/web/app/src/models/GroupPolicy.js similarity index 83% rename from services/web/app/src/models/GroupPolicy.mjs rename to services/web/app/src/models/GroupPolicy.js index c38488aa63..55728a2415 100644 --- a/services/web/app/src/models/GroupPolicy.mjs +++ b/services/web/app/src/models/GroupPolicy.js @@ -1,8 +1,8 @@ -import mongoose from '../infrastructure/Mongoose.js' +const mongoose = require('../infrastructure/Mongoose') const { Schema } = mongoose -export const GroupPolicySchema = new Schema( +const GroupPolicySchema = new Schema( { // User can't delete their own account userCannotDeleteOwnAccount: Boolean, @@ -34,4 +34,5 @@ export const GroupPolicySchema = new Schema( { minimize: false } ) -export const GroupPolicy = mongoose.model('GroupPolicy', GroupPolicySchema) +exports.GroupPolicy = mongoose.model('GroupPolicy', GroupPolicySchema) +exports.GroupPolicySchema = GroupPolicySchema diff --git a/services/web/app/src/models/Institution.mjs b/services/web/app/src/models/Institution.js similarity index 76% rename from services/web/app/src/models/Institution.mjs rename to services/web/app/src/models/Institution.js index a51dbd3f0b..fd18cf33c2 100644 --- a/services/web/app/src/models/Institution.mjs +++ b/services/web/app/src/models/Institution.js @@ -1,12 +1,12 @@ -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 mongoose = require('../infrastructure/Mongoose') 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') -export const InstitutionSchema = new Schema( +const InstitutionSchema = new Schema( { v1Id: { type: Number, required: true }, managerIds: [{ type: ObjectId, ref: 'User' }], @@ -45,4 +45,5 @@ InstitutionSchema.method( promisify(InstitutionSchema.methods.fetchV1Data) ) -export const Institution = mongoose.model('Institution', InstitutionSchema) +exports.Institution = mongoose.model('Institution', InstitutionSchema) +exports.InstitutionSchema = InstitutionSchema diff --git a/services/web/app/src/models/OauthAccessToken.mjs b/services/web/app/src/models/OauthAccessToken.js similarity index 73% rename from services/web/app/src/models/OauthAccessToken.mjs rename to services/web/app/src/models/OauthAccessToken.js index d3a9edc9fe..8b3dbc8926 100644 --- a/services/web/app/src/models/OauthAccessToken.mjs +++ b/services/web/app/src/models/OauthAccessToken.js @@ -1,9 +1,9 @@ -import mongoose from '../infrastructure/Mongoose.js' +const mongoose = require('../infrastructure/Mongoose') const { Schema } = mongoose const { ObjectId } = Schema -export const OauthAccessTokenSchema = new Schema( +const OauthAccessTokenSchema = new Schema( { accessToken: String, accessTokenPartial: String, @@ -24,7 +24,9 @@ export const OauthAccessTokenSchema = new Schema( } ) -export const OauthAccessToken = mongoose.model( +exports.OauthAccessToken = mongoose.model( 'OauthAccessToken', OauthAccessTokenSchema ) + +exports.OauthAccessTokenSchema = OauthAccessTokenSchema diff --git a/services/web/app/src/models/OauthApplication.mjs b/services/web/app/src/models/OauthApplication.js similarity index 61% rename from services/web/app/src/models/OauthApplication.mjs rename to services/web/app/src/models/OauthApplication.js index 83ff51fa55..d7bd181fd6 100644 --- a/services/web/app/src/models/OauthApplication.mjs +++ b/services/web/app/src/models/OauthApplication.js @@ -1,8 +1,8 @@ -import mongoose from '../infrastructure/Mongoose.js' +const mongoose = require('../infrastructure/Mongoose') const { Schema } = mongoose -export const OauthApplicationSchema = new Schema( +const OauthApplicationSchema = new Schema( { id: String, clientSecret: String, @@ -18,7 +18,9 @@ export const OauthApplicationSchema = new Schema( } ) -export const OauthApplication = mongoose.model( +exports.OauthApplication = mongoose.model( 'OauthApplication', OauthApplicationSchema ) + +exports.OauthApplicationSchema = OauthApplicationSchema diff --git a/services/web/app/src/models/OauthAuthorizationCode.mjs b/services/web/app/src/models/OauthAuthorizationCode.js similarity index 68% rename from services/web/app/src/models/OauthAuthorizationCode.mjs rename to services/web/app/src/models/OauthAuthorizationCode.js index 9750750f1a..6b9822377f 100644 --- a/services/web/app/src/models/OauthAuthorizationCode.mjs +++ b/services/web/app/src/models/OauthAuthorizationCode.js @@ -1,9 +1,9 @@ -import mongoose from '../infrastructure/Mongoose.js' +const mongoose = require('../infrastructure/Mongoose') const { Schema } = mongoose const { ObjectId } = Schema -export const OauthAuthorizationCodeSchema = new Schema( +const OauthAuthorizationCodeSchema = new Schema( { authorizationCode: String, expiresAt: Date, @@ -20,7 +20,9 @@ export const OauthAuthorizationCodeSchema = new Schema( } ) -export const OauthAuthorizationCode = mongoose.model( +exports.OauthAuthorizationCode = mongoose.model( 'OauthAuthorizationCode', OauthAuthorizationCodeSchema ) + +exports.OauthAuthorizationCodeSchema = OauthAuthorizationCodeSchema diff --git a/services/web/app/src/models/OnboardingDataCollection.mjs b/services/web/app/src/models/OnboardingDataCollection.js similarity index 76% rename from services/web/app/src/models/OnboardingDataCollection.mjs rename to services/web/app/src/models/OnboardingDataCollection.js index edab377914..e0625f71fc 100644 --- a/services/web/app/src/models/OnboardingDataCollection.mjs +++ b/services/web/app/src/models/OnboardingDataCollection.js @@ -1,7 +1,7 @@ -import mongoose from '../infrastructure/Mongoose.js' +const mongoose = require('../infrastructure/Mongoose') const { Schema } = mongoose -export const OnboardingDataCollectionSchema = new Schema( +const OnboardingDataCollectionSchema = new Schema( { firstName: { type: String, default: null }, lastName: { type: String, default: null }, @@ -24,12 +24,10 @@ export const OnboardingDataCollectionSchema = new Schema( } ) -export const OnboardingDataCollection = mongoose.model( - 'OnboardingDataCollection', - OnboardingDataCollectionSchema -) - -export default { - OnboardingDataCollection, +module.exports = { + OnboardingDataCollection: mongoose.model( + 'OnboardingDataCollection', + OnboardingDataCollectionSchema + ), OnboardingDataCollectionSchema, } diff --git a/services/web/app/src/models/Project.mjs b/services/web/app/src/models/Project.js similarity index 92% rename from services/web/app/src/models/Project.mjs rename to services/web/app/src/models/Project.js index fec4769008..69db145038 100644 --- a/services/web/app/src/models/Project.mjs +++ b/services/web/app/src/models/Project.js @@ -1,7 +1,7 @@ -import mongoose from '../infrastructure/Mongoose.js' -import _ from 'lodash' -import { FolderSchema } from './Folder.mjs' -import Errors from '../Features/Errors/Errors.js' +const mongoose = require('../infrastructure/Mongoose') +const _ = require('lodash') +const { FolderSchema } = require('./Folder') +const Errors = require('../Features/Errors/Errors') const ConcreteObjectId = mongoose.Types.ObjectId const { Schema } = mongoose @@ -12,7 +12,7 @@ const DeletedDocSchema = new Schema({ deletedAt: { type: Date }, }) -export const ProjectSchema = new Schema( +const ProjectSchema = new Schema( { name: { type: String, default: 'new project' }, lastUpdated: { @@ -127,4 +127,5 @@ function applyToAllFilesRecursivly(folder, fun) { } ProjectSchema.statics.applyToAllFilesRecursivly = applyToAllFilesRecursivly -export const Project = mongoose.model('Project', ProjectSchema) +exports.Project = mongoose.model('Project', ProjectSchema) +exports.ProjectSchema = ProjectSchema diff --git a/services/web/app/src/models/ProjectAuditLogEntry.mjs b/services/web/app/src/models/ProjectAuditLogEntry.js similarity index 70% rename from services/web/app/src/models/ProjectAuditLogEntry.mjs rename to services/web/app/src/models/ProjectAuditLogEntry.js index 7e668a60e3..fb4a950a40 100644 --- a/services/web/app/src/models/ProjectAuditLogEntry.mjs +++ b/services/web/app/src/models/ProjectAuditLogEntry.js @@ -1,7 +1,7 @@ -import mongoose from '../infrastructure/Mongoose.js' +const mongoose = require('../infrastructure/Mongoose') const { Schema } = mongoose -export const ProjectAuditLogEntrySchema = new Schema( +const ProjectAuditLogEntrySchema = new Schema( { projectId: { type: Schema.Types.ObjectId, index: true }, managedSubscriptionId: { type: Schema.Types.ObjectId, index: true }, @@ -17,7 +17,8 @@ export const ProjectAuditLogEntrySchema = new Schema( } ) -export const ProjectAuditLogEntry = mongoose.model( +exports.ProjectAuditLogEntry = mongoose.model( 'ProjectAuditLogEntry', ProjectAuditLogEntrySchema ) +exports.ProjectAuditLogEntrySchema = ProjectAuditLogEntrySchema diff --git a/services/web/app/src/models/ProjectHistoryFailure.mjs b/services/web/app/src/models/ProjectHistoryFailure.js similarity index 80% rename from services/web/app/src/models/ProjectHistoryFailure.mjs rename to services/web/app/src/models/ProjectHistoryFailure.js index f584945ce5..7bfd1a3d85 100644 --- a/services/web/app/src/models/ProjectHistoryFailure.mjs +++ b/services/web/app/src/models/ProjectHistoryFailure.js @@ -1,4 +1,4 @@ -import mongoose from '../infrastructure/Mongoose.js' +const mongoose = require('../infrastructure/Mongoose') const { Schema } = mongoose @@ -18,7 +18,7 @@ const ProjectHistoryFailureSchema = new Schema( { collection: 'projectHistoryFailures', minimize: false } ) -export const ProjectHistoryFailure = mongoose.model( +exports.ProjectHistoryFailure = mongoose.model( 'ProjectHistoryFailure', ProjectHistoryFailureSchema ) diff --git a/services/web/app/src/models/ProjectInvite.mjs b/services/web/app/src/models/ProjectInvite.js similarity index 64% rename from services/web/app/src/models/ProjectInvite.mjs rename to services/web/app/src/models/ProjectInvite.js index 879cd9f49c..a7bfbad1e0 100644 --- a/services/web/app/src/models/ProjectInvite.mjs +++ b/services/web/app/src/models/ProjectInvite.js @@ -1,9 +1,9 @@ -import mongoose from '../infrastructure/Mongoose.js' +const mongoose = require('../infrastructure/Mongoose') const { Schema } = mongoose const { ObjectId } = Schema -export const EXPIRY_IN_SECONDS = 60 * 60 * 24 * 30 +const EXPIRY_IN_SECONDS = 60 * 60 * 24 * 30 const ExpiryDate = function () { const timestamp = new Date() @@ -11,7 +11,7 @@ const ExpiryDate = function () { return timestamp } -export const ProjectInviteSchema = new Schema( +const ProjectInviteSchema = new Schema( { email: String, tokenHmac: String, @@ -31,7 +31,6 @@ export const ProjectInviteSchema = new Schema( } ) -export const ProjectInvite = mongoose.model( - 'ProjectInvite', - ProjectInviteSchema -) +exports.ProjectInvite = mongoose.model('ProjectInvite', ProjectInviteSchema) +exports.ProjectInviteSchema = ProjectInviteSchema +exports.EXPIRY_IN_SECONDS = EXPIRY_IN_SECONDS diff --git a/services/web/app/src/models/Publisher.mjs b/services/web/app/src/models/Publisher.js similarity index 77% rename from services/web/app/src/models/Publisher.mjs rename to services/web/app/src/models/Publisher.js index 9bbbd24e54..e9e10e49c0 100644 --- a/services/web/app/src/models/Publisher.mjs +++ b/services/web/app/src/models/Publisher.js @@ -1,11 +1,11 @@ -import mongoose from '../infrastructure/Mongoose.js' -import settings from '@overleaf/settings' -import logger from '@overleaf/logger' -import request from 'request' +const mongoose = require('../infrastructure/Mongoose') const { Schema } = mongoose const { ObjectId } = Schema +const settings = require('@overleaf/settings') +const logger = require('@overleaf/logger') +const request = require('request') -export const PublisherSchema = new Schema( +const PublisherSchema = new Schema( { slug: { type: String, required: true }, managerIds: [{ type: ObjectId, ref: 'User' }], @@ -46,4 +46,5 @@ PublisherSchema.method('fetchV1Data', function (callback) { ) }) -export const Publisher = mongoose.model('Publisher', PublisherSchema) +exports.Publisher = mongoose.model('Publisher', PublisherSchema) +exports.PublisherSchema = PublisherSchema diff --git a/services/web/app/src/models/SSOConfig.mjs b/services/web/app/src/models/SSOConfig.js similarity index 73% rename from services/web/app/src/models/SSOConfig.mjs rename to services/web/app/src/models/SSOConfig.js index 6db3584619..0349d8a651 100644 --- a/services/web/app/src/models/SSOConfig.mjs +++ b/services/web/app/src/models/SSOConfig.js @@ -1,7 +1,7 @@ -import mongoose from '../infrastructure/Mongoose.js' +const mongoose = require('../infrastructure/Mongoose') const { Schema } = mongoose -export const SSOConfigSchema = new Schema( +const SSOConfigSchema = new Schema( { entryPoint: { type: String, required: true }, certificates: { type: Array, default: [''], required: true }, @@ -20,4 +20,5 @@ export const SSOConfigSchema = new Schema( } ) -export const SSOConfig = mongoose.model('SSOConfig', SSOConfigSchema) +exports.SSOConfig = mongoose.model('SSOConfig', SSOConfigSchema) +exports.SSOConfigSchema = SSOConfigSchema diff --git a/services/web/app/src/models/SamlCache.js b/services/web/app/src/models/SamlCache.js new file mode 100644 index 0000000000..185fe61422 --- /dev/null +++ b/services/web/app/src/models/SamlCache.js @@ -0,0 +1,16 @@ +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 deleted file mode 100644 index a58a76ea68..0000000000 --- a/services/web/app/src/models/SamlCache.mjs +++ /dev/null @@ -1,15 +0,0 @@ -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.mjs b/services/web/app/src/models/SamlLog.js similarity index 69% rename from services/web/app/src/models/SamlLog.mjs rename to services/web/app/src/models/SamlLog.js index 929c7b2600..52889770f0 100644 --- a/services/web/app/src/models/SamlLog.mjs +++ b/services/web/app/src/models/SamlLog.js @@ -1,7 +1,7 @@ -import mongoose from '../infrastructure/Mongoose.js' +const mongoose = require('../infrastructure/Mongoose') const { Schema } = mongoose -export const SamlLogSchema = new Schema( +const SamlLogSchema = new Schema( { createdAt: { type: Date, default: () => new Date() }, data: { type: Object }, @@ -18,4 +18,5 @@ export const SamlLogSchema = new Schema( } ) -export const SamlLog = mongoose.model('SamlLog', SamlLogSchema) +exports.SamlLog = mongoose.model('SamlLog', SamlLogSchema) +exports.SamlLogSchema = SamlLogSchema diff --git a/services/web/app/src/models/SplitTest.mjs b/services/web/app/src/models/SplitTest.js similarity index 95% rename from services/web/app/src/models/SplitTest.mjs rename to services/web/app/src/models/SplitTest.js index b15c81adb4..c605693bfa 100644 --- a/services/web/app/src/models/SplitTest.mjs +++ b/services/web/app/src/models/SplitTest.js @@ -1,4 +1,4 @@ -import mongoose from '../infrastructure/Mongoose.js' +const mongoose = require('../infrastructure/Mongoose') const { Schema } = mongoose const { ObjectId } = Schema @@ -112,7 +112,7 @@ const VersionSchema = new Schema( { _id: false } ) -export const SplitTestSchema = new Schema( +const SplitTestSchema = new Schema( { name: { type: String, @@ -178,4 +178,7 @@ export const SplitTestSchema = new Schema( { minimize: false } ) -export const SplitTest = mongoose.model('SplitTest', SplitTestSchema) +module.exports = { + SplitTest: mongoose.model('SplitTest', SplitTestSchema), + SplitTestSchema, +} diff --git a/services/web/app/src/models/Subscription.mjs b/services/web/app/src/models/Subscription.js similarity index 91% rename from services/web/app/src/models/Subscription.mjs rename to services/web/app/src/models/Subscription.js index 416f637c6f..c7606d39ea 100644 --- a/services/web/app/src/models/Subscription.mjs +++ b/services/web/app/src/models/Subscription.js @@ -1,10 +1,10 @@ -import mongoose from '../infrastructure/Mongoose.js' -import { TeamInviteSchema } from './TeamInvite.mjs' +const mongoose = require('../infrastructure/Mongoose') +const { TeamInviteSchema } = require('./TeamInvite') const { Schema } = mongoose const { ObjectId } = Schema -export const SubscriptionSchema = new Schema( +const SubscriptionSchema = new Schema( { admin_id: { type: ObjectId, @@ -123,4 +123,5 @@ SubscriptionSchema.method('fetchV1Data', function (callback) { callback(null, this) }) -export const Subscription = mongoose.model('Subscription', SubscriptionSchema) +exports.Subscription = mongoose.model('Subscription', SubscriptionSchema) +exports.SubscriptionSchema = SubscriptionSchema diff --git a/services/web/app/src/models/Survey.mjs b/services/web/app/src/models/Survey.js similarity index 86% rename from services/web/app/src/models/Survey.mjs rename to services/web/app/src/models/Survey.js index 3c98e19fb8..01068ef49a 100644 --- a/services/web/app/src/models/Survey.mjs +++ b/services/web/app/src/models/Survey.js @@ -1,11 +1,11 @@ -import mongoose from '../infrastructure/Mongoose.js' +const mongoose = require('../infrastructure/Mongoose') const { Schema } = mongoose const MIN_NAME_LENGTH = 3 const MAX_NAME_LENGTH = 200 const NAME_REGEX = /^[a-z0-9-]+$/ -export const SurveySchema = new Schema( +const SurveySchema = new Schema( { name: { type: String, @@ -62,4 +62,7 @@ export const SurveySchema = new Schema( } ) -export const Survey = mongoose.model('Survey', SurveySchema) +module.exports = { + Survey: mongoose.model('Survey', SurveySchema), + SurveySchema, +} diff --git a/services/web/app/src/models/SystemMessage.mjs b/services/web/app/src/models/SystemMessage.js similarity index 51% rename from services/web/app/src/models/SystemMessage.mjs rename to services/web/app/src/models/SystemMessage.js index 4191801f4e..c3e37d00c6 100644 --- a/services/web/app/src/models/SystemMessage.mjs +++ b/services/web/app/src/models/SystemMessage.js @@ -1,4 +1,4 @@ -import mongoose from '../infrastructure/Mongoose.js' +const mongoose = require('../infrastructure/Mongoose') const { Schema } = mongoose @@ -9,7 +9,4 @@ const SystemMessageSchema = new Schema( { minimize: false } ) -export const SystemMessage = mongoose.model( - 'SystemMessage', - SystemMessageSchema -) +exports.SystemMessage = mongoose.model('SystemMessage', SystemMessageSchema) diff --git a/services/web/app/src/models/Tag.mjs b/services/web/app/src/models/Tag.js similarity index 76% rename from services/web/app/src/models/Tag.mjs rename to services/web/app/src/models/Tag.js index 7824d95d53..8e0eb115dc 100644 --- a/services/web/app/src/models/Tag.mjs +++ b/services/web/app/src/models/Tag.js @@ -1,4 +1,4 @@ -import mongoose from '../infrastructure/Mongoose.js' +const mongoose = require('../infrastructure/Mongoose') 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. -export const TagSchema = new Schema( +const TagSchema = new Schema( { user_id: { type: String, required: true }, name: { type: String, required: true }, @@ -24,4 +24,5 @@ export const TagSchema = new Schema( { minimize: false } ) -export const Tag = mongoose.model('Tag', TagSchema) +exports.Tag = mongoose.model('Tag', TagSchema) +exports.TagSchema = TagSchema diff --git a/services/web/app/src/models/TeamInvite.js b/services/web/app/src/models/TeamInvite.js new file mode 100644 index 0000000000..b115d27261 --- /dev/null +++ b/services/web/app/src/models/TeamInvite.js @@ -0,0 +1,16 @@ +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 deleted file mode 100644 index dfa31c09ff..0000000000 --- a/services/web/app/src/models/TeamInvite.mjs +++ /dev/null @@ -1,15 +0,0 @@ -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.mjs b/services/web/app/src/models/User.js similarity index 96% rename from services/web/app/src/models/User.mjs rename to services/web/app/src/models/User.js index 6bfebfc3a5..bdf8a4c4ed 100644 --- a/services/web/app/src/models/User.mjs +++ b/services/web/app/src/models/User.js @@ -1,6 +1,6 @@ -import Settings from '@overleaf/settings' -import mongoose from '../infrastructure/Mongoose.js' -import TokenGenerator from '../Features/TokenGenerator/TokenGenerator.js' +const Settings = require('@overleaf/settings') +const mongoose = require('../infrastructure/Mongoose') +const TokenGenerator = require('../Features/TokenGenerator/TokenGenerator') const { Schema } = mongoose const { ObjectId } = Schema @@ -8,7 +8,7 @@ const { ObjectId } = Schema const MAX_EMAIL_LENGTH = 254 const MAX_NAME_LENGTH = 255 -export const UserSchema = new Schema( +const UserSchema = new Schema( { email: { type: String, default: '', maxlength: MAX_EMAIL_LENGTH }, emails: [ @@ -247,4 +247,5 @@ function formatSplitTestsSchema(next) { } UserSchema.pre('save', formatSplitTestsSchema) -export const User = mongoose.model('User', UserSchema) +exports.User = mongoose.model('User', UserSchema) +exports.UserSchema = UserSchema diff --git a/services/web/app/src/models/UserAuditLogEntry.mjs b/services/web/app/src/models/UserAuditLogEntry.js similarity index 70% rename from services/web/app/src/models/UserAuditLogEntry.mjs rename to services/web/app/src/models/UserAuditLogEntry.js index 11442a9d0c..f239adca2f 100644 --- a/services/web/app/src/models/UserAuditLogEntry.mjs +++ b/services/web/app/src/models/UserAuditLogEntry.js @@ -1,7 +1,7 @@ -import mongoose from '../infrastructure/Mongoose.js' +const mongoose = require('../infrastructure/Mongoose') const { Schema } = mongoose -export const UserAuditLogEntrySchema = new Schema( +const UserAuditLogEntrySchema = new Schema( { userId: { type: Schema.Types.ObjectId, index: true }, managedSubscriptionId: { type: Schema.Types.ObjectId, index: true }, @@ -17,7 +17,8 @@ export const UserAuditLogEntrySchema = new Schema( } ) -export const UserAuditLogEntry = mongoose.model( +exports.UserAuditLogEntry = mongoose.model( 'UserAuditLogEntry', UserAuditLogEntrySchema ) +exports.UserAuditLogEntrySchema = UserAuditLogEntrySchema diff --git a/services/web/app/src/models/UserFeatureUsage.mjs b/services/web/app/src/models/UserFeatureUsage.js similarity index 54% rename from services/web/app/src/models/UserFeatureUsage.mjs rename to services/web/app/src/models/UserFeatureUsage.js index 50c86127af..8935990e0a 100644 --- a/services/web/app/src/models/UserFeatureUsage.mjs +++ b/services/web/app/src/models/UserFeatureUsage.js @@ -1,4 +1,4 @@ -import mongoose from '../infrastructure/Mongoose.js' +const mongoose = require('../infrastructure/Mongoose') const { Schema } = mongoose const Usage = new Schema({ @@ -6,14 +6,16 @@ const Usage = new Schema({ periodStart: { type: Date }, }) -export const UserFeatureUsageSchema = new Schema({ +const UserFeatureUsageSchema = new Schema({ features: { aiErrorAssistant: Usage, aiWorkbench: Usage, }, }) -export const UserFeatureUsage = mongoose.model( +exports.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 94cc8b35a2..101372b3ca 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.mjs' +import { User } from '../../../../app/src/models/User.js' 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 a0d3ce5b88..80150aa705 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.mjs', () => ({ + vi.doMock('../../../../../app/src/models/User.js', () => ({ 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 1598309f71..d7fcbed45d 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.mjs' -import { User } from '../../../app/src/models/User.mjs' +import { Project } from '../../../app/src/models/Project.js' +import { User } from '../../../app/src/models/User.js' 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 f33edcddb8..c84e72037a 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.mjs' -import { User } from '../../../app/src/models/User.mjs' +import { Project } from '../../../app/src/models/Project.js' +import { User } from '../../../app/src/models/User.js' 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 a5661c8978..b8cc54626b 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,12 +14,11 @@ import minimist from 'minimist' import os from 'os' import fs from 'fs' import * as csv from 'csv/sync' -import EmailHelper from '../../../app/src/Features/Helpers/EmailHelper.mjs' +import { parseEmail } from '../../../app/src/Features/Helpers/EmailHelper.js' 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 6c54e9a3b2..eafd301c0b 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.mjs' +import EmailHelper from '../../../app/src/Features/Helpers/EmailHelper.js' 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 80cc4db36c..264640f587 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.mjs' +import { Subscription } from '../app/src/models/Subscription.js' 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 25a29bed0d..1dbd5d8084 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.mjs' +import { Subscription } from '../app/src/models/Subscription.js' 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 9480f7c32e..21ab920c5e 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.mjs' +import { Subscription } from '../../app/src/models/Subscription.js' import AnalyticsManager from '../../app/src/Features/Analytics/AnalyticsManager.mjs' -import { DeletedSubscription } from '../../app/src/models/DeletedSubscription.mjs' +import { DeletedSubscription } from '../../app/src/models/DeletedSubscription.js' 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 6e3dabd4c2..1324cefb1d 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.mjs' +import '../app/src/models/User.js' 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 f883c00d5a..70f6ae4706 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.mjs' +import { User } from '../app/src/models/User.js' 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 2a290b162c..df2ae91e22 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.mjs' +import { iterablePaths } from '../app/src/Features/Project/IterablePath.js' 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 6fb4610614..2cf17d75c2 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.mjs' +import { Subscription } from '../app/src/models/Subscription.js' 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 72d19d8c31..5ffc0695ee 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.mjs' +import { User } from '../app/src/models/User.js' 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 2c73dc77d3..0c201eebab 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.mjs' +import { User } from '../../app/src/models/User.js' 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 d95cdf3959..0dd50e2099 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.mjs' +import { User } from '../app/src/models/User.js' /** * 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 2eac33c3f7..a485a623dd 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.mjs' +import { OnboardingDataCollection } from '../app/src/models/OnboardingDataCollection.js' /** * 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 57705c0aa5..339b08876e 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.mjs' -import { User } from '../app/src/models/User.mjs' +import { OnboardingDataCollection } from '../app/src/models/OnboardingDataCollection.js' +import { User } from '../app/src/models/User.js' 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 deleted file mode 100644 index 9f31240e91..0000000000 --- a/services/web/scripts/investigate_esm.mjs +++ /dev/null @@ -1,147 +0,0 @@ -/* 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 8d8a620505..e910073c5a 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.mjs' +import EmailHelper from '../app/src/Features/Helpers/EmailHelper.js' 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 f72809a965..13b005b02a 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.mjs' +import { Subscription } from '../../app/src/models/Subscription.js' 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 17b4bfa9db..00f10b7b29 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.mjs' +import { Subscription } from '../../app/src/models/Subscription.js' 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 95eddfca94..fd37ca374c 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.mjs' +import { OauthApplication } from '../app/src/models/OauthApplication.js' 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 64073607a9..a4ebcdb4d2 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.mjs' -import { Subscription } from '../app/src/models/Subscription.mjs' +import { User } from '../app/src/models/User.js' +import { Subscription } from '../app/src/models/Subscription.js' 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 f513afe0bc..a0d48dd9f3 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.mjs' +import { Project } from '../app/src/models/Project.js' 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 63788bef6d..7c9aa38f0c 100644 --- a/services/web/scripts/validate-data-of-model.mjs +++ b/services/web/scripts/validate-data-of-model.mjs @@ -3,8 +3,9 @@ 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}.mjs` + `../app/src/models/${MODEL_NAME}.js` ) function processBatch(batch) { diff --git a/services/web/test/acceptance/src/ConvertEmailConfirmedAtToDates.mjs b/services/web/test/acceptance/src/ConvertEmailConfirmedAtToDates.js similarity index 100% rename from services/web/test/acceptance/src/ConvertEmailConfirmedAtToDates.mjs rename to services/web/test/acceptance/src/ConvertEmailConfirmedAtToDates.js diff --git a/services/web/test/acceptance/src/ConvertSplitTestAssignedAtToDates.mjs b/services/web/test/acceptance/src/ConvertSplitTestAssignedAtToDates.js similarity index 100% rename from services/web/test/acceptance/src/ConvertSplitTestAssignedAtToDates.mjs rename to services/web/test/acceptance/src/ConvertSplitTestAssignedAtToDates.js diff --git a/services/web/test/acceptance/src/ModelTests.mjs b/services/web/test/acceptance/src/ModelTests.mjs index 9ef32cf08c..7a58cf0a53 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.mjs' -import { Subscription } from '../../../app/src/models/Subscription.mjs' +import { User } from '../../../app/src/models/User.js' +import { Subscription } from '../../../app/src/models/Subscription.js' 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 dc7ddbeab6..269939e8ff 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.mjs' +import { User as UserModel } from '../../../app/src/models/User.js' 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 2c6d638e9f..71bad436d0 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.mjs' +import { Project } from '../../../app/src/models/Project.js' import mongodb from 'mongodb-legacy' import cheerio from 'cheerio' -import { Subscription } from '../../../app/src/models/Subscription.mjs' +import { Subscription } from '../../../app/src/models/Subscription.js' 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 22e22a9fcc..14edf58c4f 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.mjs' +import { Project } from '../../../app/src/models/Project.js' 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/helpers/DeletedSubscription.mjs b/services/web/test/acceptance/src/helpers/DeletedSubscription.mjs index 2e218c6f26..3d64877cec 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.mjs' -import { DeletedSubscription as DeletedSubscriptionModel } from '../../../../app/src/models/DeletedSubscription.mjs' +import { Subscription as SubscriptionModel } from '../../../../app/src/models/Subscription.js' +import { DeletedSubscription as DeletedSubscriptionModel } from '../../../../app/src/models/DeletedSubscription.js' 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 416c61bc99..eb2bd0b274 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.mjs' +import { Institution as InstitutionModel } from '../../../../app/src/models/Institution.js' const { ObjectId } = mongodb diff --git a/services/web/test/acceptance/src/helpers/Publisher.mjs b/services/web/test/acceptance/src/helpers/Publisher.mjs index 8d8e336332..8300157cc2 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.mjs' +import { Publisher as PublisherModel } from '../../../../app/src/models/Publisher.js' 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 d4092eb6f3..531e3fdacc 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.mjs' +import { SamlLog } from '../../../../app/src/models/SamlLog.js' 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 afa1297de0..eec39c3bf6 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.mjs' -import { DeletedSubscription as DeletedSubscriptionModel } from '../../../../app/src/models/DeletedSubscription.mjs' +import { Subscription as SubscriptionModel } from '../../../../app/src/models/Subscription.js' +import { DeletedSubscription as DeletedSubscriptionModel } from '../../../../app/src/models/DeletedSubscription.js' 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 3bc4d801f1..48ba98c9b5 100644 --- a/services/web/test/acceptance/src/helpers/User.mjs +++ b/services/web/test/acceptance/src/helpers/User.mjs @@ -2,14 +2,16 @@ 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.mjs' +import { User as UserModel } from '../../../../app/src/models/User.js' 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(/^\./, '')}/` @@ -851,7 +853,7 @@ class User { callback ) { const fileStream = fs.createReadStream( - Path.resolve(Path.join(import.meta.dirname, '..', '..', 'files', file)) + Path.resolve(Path.join(__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 aea5ca66ee..b218554da0 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.mjs' +import { UserAuditLogEntry } from '../../../../app/src/models/UserAuditLogEntry.js' // 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 d72fd372e1..c908773ed6 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.mjs' +import { SSOConfig } from '../../../../app/src/models/SSOConfig.js' 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.mjs' +import { Subscription as SubscriptionModel } from '../../../../app/src/models/Subscription.js' 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 cd6506c7d4..02fd445098 100644 --- a/services/web/test/unit/src/Collaborators/CollaboratorsGetter.test.mjs +++ b/services/web/test/unit/src/Collaborators/CollaboratorsGetter.test.mjs @@ -2,9 +2,11 @@ import { vi, expect } from 'vitest' import Path from 'path' import sinon from 'sinon' import mongodb from 'mongodb-legacy' -import { Project } from '../../../../app/src/models/Project.mjs' +import indirectlyImportModels from '../helpers/indirectlyImportModels.js' 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 fa4e4bc2b2..f3f924125e 100644 --- a/services/web/test/unit/src/Collaborators/CollaboratorsHandler.test.mjs +++ b/services/web/test/unit/src/Collaborators/CollaboratorsHandler.test.mjs @@ -2,11 +2,12 @@ import { vi, expect } from 'vitest' import path from 'path' import sinon from 'sinon' import Errors from '../../../../app/src/Features/Errors/Errors.js' -import { Project } from '../../../../app/src/models/Project.mjs' +import indirectlyImportModels from '../helpers/indirectlyImportModels.js' 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 41e5e3eba5..660994f2f8 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.mjs', () => ({ + vi.doMock('../../../../app/src/models/ProjectInvite.js', () => ({ 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 35e48e2e15..f526aaa29b 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.mjs', () => ({ + vi.doMock('../../../../app/src/models/Project.js', () => ({ Project: ctx.ProjectModel, })) diff --git a/services/web/test/unit/src/Cooldown/CooldownManager.sequential.test.mjs b/services/web/test/unit/src/Cooldown/CooldownManagerTests.js similarity index 53% rename from services/web/test/unit/src/Cooldown/CooldownManager.sequential.test.mjs rename to services/web/test/unit/src/Cooldown/CooldownManagerTests.js index fdd757f03f..5531c4b8ea 100644 --- a/services/web/test/unit/src/Cooldown/CooldownManager.sequential.test.mjs +++ b/services/web/test/unit/src/Cooldown/CooldownManagerTests.js @@ -1,16 +1,16 @@ -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 +const { expect } = require('chai') +const { ObjectId } = require('mongodb-legacy') +const CooldownManager = require('../../../../app/src/Features/Cooldown/CooldownManager') +const { + cleanupTestRedis, +} = require('../../../../app/src/infrastructure/RedisWrapper') describe('CooldownManager', function () { beforeEach(cleanupTestRedis) - beforeEach(function (ctx) { - ctx.project1Id = new ObjectId().toString() - ctx.project2Id = new ObjectId().toString() + beforeEach(function () { + this.project1Id = new ObjectId().toString() + this.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 (ctx) { + it('returns false for project 1', async function () { const result = await CooldownManager.promises.isProjectOnCooldown( - ctx.project1Id + this.project1Id ) expect(result).to.be.false }) - it('returns false for project 2', async function (ctx) { + it('returns false for project 2', async function () { const result = await CooldownManager.promises.isProjectOnCooldown( - ctx.project2Id + this.project2Id ) expect(result).to.be.false }) }) describe('when project 1 is on cooldown', function () { - beforeEach(async function (ctx) { - await CooldownManager.promises.putProjectOnCooldown(ctx.project1Id) + beforeEach(async function () { + await CooldownManager.promises.putProjectOnCooldown(this.project1Id) }) - it('returns true for project 1', async function (ctx) { + it('returns true for project 1', async function () { const result = await CooldownManager.promises.isProjectOnCooldown( - ctx.project1Id + this.project1Id ) expect(result).to.be.true }) - it('returns false for project 2', async function (ctx) { + it('returns false for project 2', async function () { const result = await CooldownManager.promises.isProjectOnCooldown( - ctx.project2Id + this.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 f7294c3b08..846a54d4ce 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.mjs', + '../../../../app/src/Features/Cooldown/CooldownManager.js', () => ({ default: ctx.CooldownManager, }) diff --git a/services/web/test/unit/src/HelperFiles/DiffHelper.test.mjs b/services/web/test/unit/src/HelperFiles/DiffHelperTests.js similarity index 87% rename from services/web/test/unit/src/HelperFiles/DiffHelper.test.mjs rename to services/web/test/unit/src/HelperFiles/DiffHelperTests.js index b1149aa5b4..518bffc534 100644 --- a/services/web/test/unit/src/HelperFiles/DiffHelper.test.mjs +++ b/services/web/test/unit/src/HelperFiles/DiffHelperTests.js @@ -1,5 +1,7 @@ -import { expect } from 'vitest' -import { stringSimilarity } from '../../../../app/src/Features/Helpers/DiffHelper.mjs' +const { expect } = require('chai') +const { + stringSimilarity, +} = require('../../../../app/src/Features/Helpers/DiffHelper') describe('DiffHelper', function () { describe('stringSimilarity', function () { diff --git a/services/web/test/unit/src/HelperFiles/EmailHelper.test.mjs b/services/web/test/unit/src/HelperFiles/EmailHelperTests.js similarity index 53% rename from services/web/test/unit/src/HelperFiles/EmailHelper.test.mjs rename to services/web/test/unit/src/HelperFiles/EmailHelperTests.js index 31660b284f..2d56b7c638 100644 --- a/services/web/test/unit/src/HelperFiles/EmailHelper.test.mjs +++ b/services/web/test/unit/src/HelperFiles/EmailHelperTests.js @@ -1,19 +1,21 @@ -import { expect } from 'vitest' -import EmailHelper from '../../../../app/src/Features/Helpers/EmailHelper.mjs' +const { expect } = require('chai') +const { + parseEmail, +} = require('../../../../app/src/Features/Helpers/EmailHelper') describe('EmailHelper', function () { it('should parse a single email', function () { const address = 'test@example.com' const expected = 'test@example.com' - expect(EmailHelper.parseEmail(address)).to.equal(expected) - expect(EmailHelper.parseEmail(address, true)).to.equal(expected) + expect(parseEmail(address)).to.equal(expected) + expect(parseEmail(address, true)).to.equal(expected) }) it('should parse a valid email address', function () { const address = '"Test Person" ' const expected = 'test@example.com' - expect(EmailHelper.parseEmail(address)).to.equal(null) - expect(EmailHelper.parseEmail(address, true)).to.equal(expected) + expect(parseEmail(address)).to.equal(null) + expect(parseEmail(address, true)).to.equal(expected) }) it('should return null for garbage input', function () { @@ -29,26 +31,26 @@ describe('EmailHelper', function () { { toString: true }, ] for (const input of cases) { - expect(EmailHelper.parseEmail(input)).to.equal(null, input) - expect(EmailHelper.parseEmail(input, true)).to.equal(null, input) + expect(parseEmail(input)).to.equal(null, input) + expect(parseEmail(input, true)).to.equal(null, input) } }) it('should return null for an invalid single email', function () { const address = 'testexample.com' - expect(EmailHelper.parseEmail(address)).to.equal(null) - expect(EmailHelper.parseEmail(address, true)).to.equal(null) + expect(parseEmail(address)).to.equal(null) + expect(parseEmail(address, true)).to.equal(null) }) it('should return null for an invalid email address', function () { const address = '"Test Person" test@example.com>' - expect(EmailHelper.parseEmail(address)).to.equal(null) - expect(EmailHelper.parseEmail(address, true)).to.equal(null) + expect(parseEmail(address)).to.equal(null) + expect(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(EmailHelper.parseEmail(address)).to.equal(null) - expect(EmailHelper.parseEmail(address, true)).to.equal(null) + expect(parseEmail(address)).to.equal(null) + expect(parseEmail(address, true)).to.equal(null) }) }) diff --git a/services/web/test/unit/src/Project/IterablePath.test.mjs b/services/web/test/unit/src/Project/IterablePathTests.js similarity index 77% rename from services/web/test/unit/src/Project/IterablePath.test.mjs rename to services/web/test/unit/src/Project/IterablePathTests.js index 88f6e3abc4..e00607eb69 100644 --- a/services/web/test/unit/src/Project/IterablePath.test.mjs +++ b/services/web/test/unit/src/Project/IterablePathTests.js @@ -1,5 +1,7 @@ -import { expect } from 'vitest' -import { iterablePaths } from '../../../../app/src/Features/Project/IterablePath.mjs' +const { expect } = require('chai') +const { + iterablePaths, +} = require('../../../../app/src/Features/Project/IterablePath') 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 8907fdda2d..68ab92e3c5 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.mjs', () => ({ + vi.doMock('../../../../app/src/models/Project.js', () => ({ 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 0b58751221..5dbea99d6c 100644 --- a/services/web/test/unit/src/Project/ProjectDeleter.test.mjs +++ b/services/web/test/unit/src/Project/ProjectDeleter.test.mjs @@ -2,12 +2,15 @@ import { vi, expect } from 'vitest' import sinon from 'sinon' import tk from 'timekeeper' import moment from 'moment' -import { Project } from '../../../../app/src/models/Project.mjs' -import { DeletedProject } from '../../../../app/src/models/DeletedProject.mjs' +import indirectlyImportModels from '../helpers/indirectlyImportModels.js' 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 ab400edc59..4e8f9e86d1 100644 --- a/services/web/test/unit/src/Project/ProjectEntityMongoUpdateHandler.test.mjs +++ b/services/web/test/unit/src/Project/ProjectEntityMongoUpdateHandler.test.mjs @@ -3,8 +3,9 @@ import sinon from 'sinon' import tk from 'timekeeper' import Errors from '../../../../app/src/Features/Errors/Errors.js' import mongodb from 'mongodb-legacy' -import { Project } from '../../../../app/src/models/Project.mjs' +import indirectlyImportModels from '../helpers/indirectlyImportModels.js' +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 6937b3c9a2..e3b94e09b5 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.mjs', () => ({ + vi.doMock('../../../../app/src/models/Project.js', () => ({ 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 423d707735..ae5e9bb27f 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.mjs', () => ({ + vi.doMock('../../../../app/src/models/User.js', () => ({ User: (ctx.User = {}), })) diff --git a/services/web/test/unit/src/Security/OneTimeTokenHandler.sequential.test.mjs b/services/web/test/unit/src/Security/OneTimeTokenHandlerTests.js similarity index 84% rename from services/web/test/unit/src/Security/OneTimeTokenHandler.sequential.test.mjs rename to services/web/test/unit/src/Security/OneTimeTokenHandlerTests.js index df412f2d39..b48dffe237 100644 --- a/services/web/test/unit/src/Security/OneTimeTokenHandler.sequential.test.mjs +++ b/services/web/test/unit/src/Security/OneTimeTokenHandlerTests.js @@ -1,28 +1,24 @@ -import sinon from 'sinon' -import { beforeAll, beforeEach, describe, expect, it, vi } from 'vitest' -import Errors from '../../../../app/src/Features/Errors/Errors.js' -import { +const sinon = require('sinon') +const { expect } = require('chai') +const Errors = require('../../../../app/src/Features/Errors/Errors') +const { connectionPromise, cleanupTestDatabase, -} 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') -) +} = require('../../../../app/src/infrastructure/mongodb') +const OneTimeTokenHandler = require('../../../../app/src/Features/Security/OneTimeTokenHandler') describe('OneTimeTokenHandler', function () { - beforeAll(async function () { + before(async function () { await connectionPromise }) beforeEach(cleanupTestDatabase) - beforeEach(function (ctx) { - ctx.clock = sinon.useFakeTimers() + beforeEach(function () { + this.clock = sinon.useFakeTimers() }) - afterEach(function (ctx) { - ctx.clock.restore() + afterEach(function () { + this.clock.restore() }) describe('getNewToken', function () { @@ -38,30 +34,30 @@ describe('OneTimeTokenHandler', function () { expect(data).to.equal('mock-data-to-store') }) - it('expires the generated token after 1 hour', async function (ctx) { + it('expires the generated token after 1 hour', async function () { const token = await OneTimeTokenHandler.promises.getNewToken( 'password', 'mock-data-to-store' ) - ctx.clock.tick('25:00:00') + this.clock.tick('25:00:00') await expect( OneTimeTokenHandler.promises.peekValueFromToken('password', token) ).to.be.rejectedWith(Errors.NotFoundError) }) - it('accepts an expiresIn parameter', async function (ctx) { + it('accepts an expiresIn parameter', async function () { const token = await OneTimeTokenHandler.promises.getNewToken( 'password', 'mock-data-to-store', { expiresIn: 42 } ) - ctx.clock.tick('00:30') + this.clock.tick('00:30') const { data } = await OneTimeTokenHandler.promises.peekValueFromToken( 'password', token ) expect(data).to.equal('mock-data-to-store') - ctx.clock.tick('00:15') + this.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 8b60574599..380d1b42e2 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.mjs' +import SubscriptionHelper from '../../../../app/src/Features/Subscription/SubscriptionHelper.js' 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 1d4e6ec607..103acc862b 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.mjs' +import SubscriptionHelper from '../../../../app/src/Features/Subscription/SubscriptionHelper.js' 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 2a3ce3a33a..7f0290f4a0 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.mjs' +import SubscriptionHelper from '../../../../app/src/Features/Subscription/SubscriptionHelper.js' const { PaymentProviderSubscription } = PaymentProviderEntities const MODULE_PATH = diff --git a/services/web/test/unit/src/Subscription/SubscriptionHelper.test.mjs b/services/web/test/unit/src/Subscription/SubscriptionHelperTests.js similarity index 61% rename from services/web/test/unit/src/Subscription/SubscriptionHelper.test.mjs rename to services/web/test/unit/src/Subscription/SubscriptionHelperTests.js index a77800361a..fae3e6e2e6 100644 --- a/services/web/test/unit/src/Subscription/SubscriptionHelper.test.mjs +++ b/services/web/test/unit/src/Subscription/SubscriptionHelperTests.js @@ -1,5 +1,6 @@ -import { vi, expect } from 'vitest' -import sinon from 'sinon' +const SandboxedModule = require('sandboxed-module') +const { expect } = require('chai') +const sinon = require('sinon') const modulePath = '../../../../app/src/Features/Subscription/SubscriptionHelper' @@ -30,9 +31,9 @@ const plans = { } describe('SubscriptionHelper', function () { - beforeEach(async function (ctx) { - ctx.clock = sinon.useFakeTimers(new Date('2023-06-15T10:00:00Z')) - ctx.Subscription = { + beforeEach(function () { + this.clock = sinon.useFakeTimers(new Date('2023-06-15T10:00:00Z')) + this.Subscription = { findOne: sinon.stub().returns({ exec: sinon.stub().resolves(), }), @@ -48,91 +49,86 @@ describe('SubscriptionHelper', function () { exec: sinon.stub().resolves(), }), } - ctx.INITIAL_LICENSE_SIZE = 2 - ctx.settings = { + this.INITIAL_LICENSE_SIZE = 2 + this.settings = { groupPlanModalOptions: {}, } - ctx.GroupPlansData = { + this.GroupPlansData = { enterprise: { collaborator: { CHF: { - [ctx.INITIAL_LICENSE_SIZE]: { + [this.INITIAL_LICENSE_SIZE]: { price_in_cents: 1000, }, }, DKK: { - [ctx.INITIAL_LICENSE_SIZE]: { + [this.INITIAL_LICENSE_SIZE]: { price_in_cents: 2000, }, }, SEK: { - [ctx.INITIAL_LICENSE_SIZE]: { + [this.INITIAL_LICENSE_SIZE]: { price_in_cents: 3000, }, }, NOK: { - [ctx.INITIAL_LICENSE_SIZE]: { + [this.INITIAL_LICENSE_SIZE]: { price_in_cents: 4000, }, }, USD: { - [ctx.INITIAL_LICENSE_SIZE]: { + [this.INITIAL_LICENSE_SIZE]: { price_in_cents: 5000, }, }, }, professional: { CHF: { - [ctx.INITIAL_LICENSE_SIZE]: { + [this.INITIAL_LICENSE_SIZE]: { price_in_cents: 10000, }, }, DKK: { - [ctx.INITIAL_LICENSE_SIZE]: { + [this.INITIAL_LICENSE_SIZE]: { price_in_cents: 20000, }, }, SEK: { - [ctx.INITIAL_LICENSE_SIZE]: { + [this.INITIAL_LICENSE_SIZE]: { price_in_cents: 30000, }, }, NOK: { - [ctx.INITIAL_LICENSE_SIZE]: { + [this.INITIAL_LICENSE_SIZE]: { price_in_cents: 40000, }, }, USD: { - [ctx.INITIAL_LICENSE_SIZE]: { + [this.INITIAL_LICENSE_SIZE]: { price_in_cents: 50000, }, }, }, }, } - - 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 + this.SubscriptionHelper = SandboxedModule.require(modulePath, { + globals: { + Date: this.clock.Date, + }, + requires: { + '../../models/Subscription': { + Subscription: this.Subscription, + }, + '@overleaf/settings': this.settings, + './GroupPlansData': this.GroupPlansData, + }, + }) }) describe('shouldPlanChangeAtTermEnd', function () { - it('should return false if isInTrial is true', function (ctx) { + it('should return false if isInTrial is true', function () { const isInTrial = true - const changeAtTermEnd = ctx.SubscriptionHelper.shouldPlanChangeAtTermEnd( + const changeAtTermEnd = this.SubscriptionHelper.shouldPlanChangeAtTermEnd( plans.expensive, plans.cheaper, isInTrial @@ -140,9 +136,9 @@ describe('SubscriptionHelper', function () { expect(changeAtTermEnd).to.be.false }) - it('should return true if the new plan is less expensive', function (ctx) { + it('should return true if the new plan is less expensive', function () { const isInTrial = false - const changeAtTermEnd = ctx.SubscriptionHelper.shouldPlanChangeAtTermEnd( + const changeAtTermEnd = this.SubscriptionHelper.shouldPlanChangeAtTermEnd( plans.expensive, plans.cheaper, isInTrial @@ -150,9 +146,9 @@ describe('SubscriptionHelper', function () { expect(changeAtTermEnd).to.be.true }) - it('should return false if the new plan is more exepensive', function (ctx) { + it('should return false if the new plan is more exepensive', function () { const isInTrial = false - const changeAtTermEnd = ctx.SubscriptionHelper.shouldPlanChangeAtTermEnd( + const changeAtTermEnd = this.SubscriptionHelper.shouldPlanChangeAtTermEnd( plans.cheaper, plans.expensive, isInTrial @@ -160,10 +156,10 @@ describe('SubscriptionHelper', function () { expect(changeAtTermEnd).to.be.false }) - it('should return false if the new plan is the same price', function (ctx) { + it('should return false if the new plan is the same price', function () { const isInTrial = false - const changeAtTermEnd = ctx.SubscriptionHelper.shouldPlanChangeAtTermEnd( + const changeAtTermEnd = this.SubscriptionHelper.shouldPlanChangeAtTermEnd( plans.cheaper, plans.alsoCheap, isInTrial @@ -171,10 +167,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 (ctx) { + it('should return false if the change is from an individual plan to a more expensive group plan', function () { const isInTrial = false - const changeAtTermEnd = ctx.SubscriptionHelper.shouldPlanChangeAtTermEnd( + const changeAtTermEnd = this.SubscriptionHelper.shouldPlanChangeAtTermEnd( plans.expensive, plans.expensiveGroup, isInTrial @@ -182,10 +178,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 (ctx) { + it('should return true if the change is from an individual plan to a cheaper group plan', function () { const isInTrial = false - const changeAtTermEnd = ctx.SubscriptionHelper.shouldPlanChangeAtTermEnd( + const changeAtTermEnd = this.SubscriptionHelper.shouldPlanChangeAtTermEnd( plans.expensive, plans.cheapGroup, isInTrial @@ -196,9 +192,12 @@ describe('SubscriptionHelper', function () { describe('generateInitialLocalizedGroupPrice', function () { describe('CHF currency', function () { - it('should return the correct localized price for every plan', function (ctx) { + it('should return the correct localized price for every plan', function () { const localizedPrice = - ctx.SubscriptionHelper.generateInitialLocalizedGroupPrice('CHF', 'fr') + this.SubscriptionHelper.generateInitialLocalizedGroupPrice( + 'CHF', + 'fr' + ) expect(localizedPrice).to.deep.equal({ price: { @@ -214,9 +213,12 @@ describe('SubscriptionHelper', function () { }) describe('DKK currency', function () { - it('should return the correct localized price for every plan', function (ctx) { + it('should return the correct localized price for every plan', function () { const localizedPrice = - ctx.SubscriptionHelper.generateInitialLocalizedGroupPrice('DKK', 'da') + this.SubscriptionHelper.generateInitialLocalizedGroupPrice( + 'DKK', + 'da' + ) expect(localizedPrice).to.deep.equal({ price: { @@ -232,9 +234,12 @@ describe('SubscriptionHelper', function () { }) describe('SEK currency', function () { - it('should return the correct localized price for every plan', function (ctx) { + it('should return the correct localized price for every plan', function () { const localizedPrice = - ctx.SubscriptionHelper.generateInitialLocalizedGroupPrice('SEK', 'sv') + this.SubscriptionHelper.generateInitialLocalizedGroupPrice( + 'SEK', + 'sv' + ) expect(localizedPrice).to.deep.equal({ price: { @@ -250,9 +255,9 @@ describe('SubscriptionHelper', function () { }) describe('NOK currency', function () { - it('should return the correct localized price for every plan', function (ctx) { + it('should return the correct localized price for every plan', function () { const localizedPrice = - ctx.SubscriptionHelper.generateInitialLocalizedGroupPrice( + this.SubscriptionHelper.generateInitialLocalizedGroupPrice( 'NOK', // there seem to be possible inconsistencies with the CI // maybe it depends on what languages are installed on the server? @@ -273,9 +278,12 @@ describe('SubscriptionHelper', function () { }) describe('other supported currencies', function () { - it('should return the correct localized price for every plan', function (ctx) { + it('should return the correct localized price for every plan', function () { const localizedPrice = - ctx.SubscriptionHelper.generateInitialLocalizedGroupPrice('USD', 'en') + this.SubscriptionHelper.generateInitialLocalizedGroupPrice( + 'USD', + 'en' + ) expect(localizedPrice).to.deep.equal({ price: { @@ -292,219 +300,235 @@ describe('SubscriptionHelper', function () { }) describe('isPaidSubscription', function () { - it('should return true for a subscription with a recurly subscription id', function (ctx) { - const result = ctx.SubscriptionHelper.isPaidSubscription({ + it('should return true for a subscription with a recurly subscription id', function () { + const result = this.SubscriptionHelper.isPaidSubscription({ recurlySubscription_id: 'some-id', }) expect(result).to.be.true }) - it('should return true for a subscription with a stripe subscription id', function (ctx) { - const result = ctx.SubscriptionHelper.isPaidSubscription({ + it('should return true for a subscription with a stripe subscription id', function () { + const result = this.SubscriptionHelper.isPaidSubscription({ paymentProvider: { subscriptionId: 'some-id' }, }) expect(result).to.be.true }) - it('should return false for a free subscription', function (ctx) { - const result = ctx.SubscriptionHelper.isPaidSubscription({}) + it('should return false for a free subscription', function () { + const result = this.SubscriptionHelper.isPaidSubscription({}) expect(result).to.be.false }) - it('should return false for a missing subscription', function (ctx) { - const result = ctx.SubscriptionHelper.isPaidSubscription() + it('should return false for a missing subscription', function () { + const result = this.SubscriptionHelper.isPaidSubscription() expect(result).to.be.false }) }) describe('isIndividualActivePaidSubscription', function () { - 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', - }) + it('should return true for an active recurly subscription', function () { + const result = this.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 (ctx) { - const result = ctx.SubscriptionHelper.isIndividualActivePaidSubscription({ - groupPlan: false, - paymentProvider: { subscriptionId: 'sub_123', state: 'active' }, - }) + it('should return true for an active stripe subscription', function () { + const result = this.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 (ctx) { - const result = ctx.SubscriptionHelper.isIndividualActivePaidSubscription({ - groupPlan: false, - recurlyStatus: { state: 'canceled' }, - recurlySubscription_id: 'some-id', - }) + it('should return false for a canceled recurly subscription', function () { + const result = this.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 (ctx) { - const result = ctx.SubscriptionHelper.isIndividualActivePaidSubscription({ - groupPlan: false, - paymentProvider: { state: 'canceled', subscriptionId: 'sub_123' }, - }) + it('should return false for a canceled stripe subscription', function () { + const result = this.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 (ctx) { - const result = ctx.SubscriptionHelper.isIndividualActivePaidSubscription({ - groupPlan: true, - recurlyStatus: { state: 'active' }, - recurlySubscription_id: 'some-id', - }) + it('should return false for a group plan subscription', function () { + const result = this.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 (ctx) { - const result = ctx.SubscriptionHelper.isIndividualActivePaidSubscription( + it('should return false for a free subscription', function () { + const result = this.SubscriptionHelper.isIndividualActivePaidSubscription( {} ) expect(result).to.be.false }) - 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' }, - }) + 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' }, + } + ) expect(result).to.be.false }) - 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: '' }, - }) + 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: '' }, + } + ) expect(result).to.be.false }) - it('should return false for a missing subscription', function (ctx) { - const result = ctx.SubscriptionHelper.isPaidSubscription() + it('should return false for a missing subscription', function () { + const result = this.SubscriptionHelper.isPaidSubscription() expect(result).to.be.false }) }) describe('getPaymentProviderSubscriptionId', function () { - it('should return the recurly subscription id if it exists', function (ctx) { - const result = ctx.SubscriptionHelper.getPaymentProviderSubscriptionId({ + it('should return the recurly subscription id if it exists', function () { + const result = this.SubscriptionHelper.getPaymentProviderSubscriptionId({ recurlySubscription_id: 'some-id', }) expect(result).to.equal('some-id') }) - it('should return the payment provider subscription id if it exists', function (ctx) { - const result = ctx.SubscriptionHelper.getPaymentProviderSubscriptionId({ + it('should return the payment provider subscription id if it exists', function () { + const result = this.SubscriptionHelper.getPaymentProviderSubscriptionId({ paymentProvider: { subscriptionId: 'sub_123' }, }) expect(result).to.equal('sub_123') }) - it('should return null if no subscription id exists', function (ctx) { - const result = ctx.SubscriptionHelper.getPaymentProviderSubscriptionId({}) + it('should return null if no subscription id exists', function () { + const result = this.SubscriptionHelper.getPaymentProviderSubscriptionId( + {} + ) expect(result).to.be.null }) }) describe('getPaidSubscriptionState', function () { - it('should return the recurly state if it exists', function (ctx) { - const result = ctx.SubscriptionHelper.getPaidSubscriptionState({ + it('should return the recurly state if it exists', function () { + const result = this.SubscriptionHelper.getPaidSubscriptionState({ recurlyStatus: { state: 'active' }, }) expect(result).to.equal('active') }) - it('should return the payment provider state if it exists', function (ctx) { - const result = ctx.SubscriptionHelper.getPaidSubscriptionState({ + it('should return the payment provider state if it exists', function () { + const result = this.SubscriptionHelper.getPaidSubscriptionState({ paymentProvider: { state: 'active' }, }) expect(result).to.equal('active') }) - it('should return null if no state exists', function (ctx) { - const result = ctx.SubscriptionHelper.getPaidSubscriptionState({}) + it('should return null if no state exists', function () { + const result = this.SubscriptionHelper.getPaidSubscriptionState({}) expect(result).to.be.null }) }) describe('getSubscriptionTrialStartedAt', function () { - it('should return the recurly trial start date if it exists', function (ctx) { - const result = ctx.SubscriptionHelper.getSubscriptionTrialStartedAt({ + it('should return the recurly trial start date if it exists', function () { + const result = this.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 (ctx) { - const result = ctx.SubscriptionHelper.getSubscriptionTrialStartedAt({ + it('should return the payment provider trial start date if it exists', function () { + const result = this.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 (ctx) { - const result = ctx.SubscriptionHelper.getSubscriptionTrialStartedAt({}) + it('should return undefined if no trial start date exists', function () { + const result = this.SubscriptionHelper.getSubscriptionTrialStartedAt({}) expect(result).to.be.undefined }) }) describe('getSubscriptionTrialEndsAt', function () { - it('should return the recurly trial end date if it exists', function (ctx) { - const result = ctx.SubscriptionHelper.getSubscriptionTrialEndsAt({ + it('should return the recurly trial end date if it exists', function () { + const result = this.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 (ctx) { - const result = ctx.SubscriptionHelper.getSubscriptionTrialEndsAt({ + it('should return the payment provider trial end date if it exists', function () { + const result = this.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 (ctx) { - const result = ctx.SubscriptionHelper.getSubscriptionTrialEndsAt({}) + it('should return undefined if no trial end date exists', function () { + const result = this.SubscriptionHelper.getSubscriptionTrialEndsAt({}) expect(result).to.be.undefined }) }) describe('isInTrial', function () { - it('should return false if trialEndsAt is null', function (ctx) { - const result = ctx.SubscriptionHelper.isInTrial(null) + it('should return false if trialEndsAt is null', function () { + const result = this.SubscriptionHelper.isInTrial(null) expect(result).to.be.false }) - it('should return false if trialEndsAt is before now', function (ctx) { + it('should return false if trialEndsAt is before now', function () { const tenDaysAgo = new Date() tenDaysAgo.setDate(tenDaysAgo.getDate() - 10) - const result = ctx.SubscriptionHelper.isInTrial(tenDaysAgo) + const result = this.SubscriptionHelper.isInTrial(tenDaysAgo) expect(result).to.be.false }) - it('should return true if trialEndsAt is after now', function (ctx) { + it('should return true if trialEndsAt is after now', function () { const tenDaysFromNow = new Date() tenDaysFromNow.setDate(tenDaysFromNow.getDate() + 10) - const result = ctx.SubscriptionHelper.isInTrial(tenDaysFromNow) + const result = this.SubscriptionHelper.isInTrial(tenDaysFromNow) expect(result).to.be.true }) }) describe('recomputeSubscriptionState', function () { - beforeEach(function (ctx) { - ctx.clock.now = new Date('2023-06-15T10:00:00Z') + beforeEach(function () { + this.clock.now = new Date('2023-06-15T10:00:00Z') - ctx.baseSubscription = { + this.baseSubscription = { _id: 'subscription_id', paymentProvider: { service: 'stripe-test', @@ -517,16 +541,16 @@ describe('SubscriptionHelper', function () { }) describe('when subscription has no paymentProvider subscriptionId', function () { - it('should return subscription unchanged', async function (ctx) { + it('should return subscription unchanged', async function () { const subscription = { _id: 'subscription_id' } const result = - await ctx.SubscriptionHelper.recomputeSubscriptionState(subscription) + await this.SubscriptionHelper.recomputeSubscriptionState(subscription) expect(result).to.equal(subscription) }) }) describe('when subscription has no pausePeriodStart', function () { - it('should return subscription unchanged', async function (ctx) { + it('should return subscription unchanged', async function () { const subscription = { _id: 'subscription_id', paymentProvider: { @@ -535,22 +559,22 @@ describe('SubscriptionHelper', function () { }, } const result = - await ctx.SubscriptionHelper.recomputeSubscriptionState(subscription) + await this.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 (ctx) { - const subscription = { ...ctx.baseSubscription } + it('should change state to paused', async function () { + const subscription = { ...this.baseSubscription } const result = - await ctx.SubscriptionHelper.recomputeSubscriptionState( + await this.SubscriptionHelper.recomputeSubscriptionState( subscription ) expect(result.paymentProvider.state).to.equal('paused') - expect(ctx.Subscription.updateOne).to.have.been.calledWith( + expect(this.Subscription.updateOne).to.have.been.calledWith( { _id: 'subscription_id' }, { 'paymentProvider.state': 'paused' } ) @@ -558,64 +582,64 @@ describe('SubscriptionHelper', function () { }) describe('and current state is already paused', function () { - it('should not change state', async function (ctx) { + it('should not change state', async function () { const subscription = { - ...ctx.baseSubscription, + ...this.baseSubscription, paymentProvider: { - ...ctx.baseSubscription.paymentProvider, + ...this.baseSubscription.paymentProvider, state: 'paused', }, } const result = - await ctx.SubscriptionHelper.recomputeSubscriptionState( + await this.SubscriptionHelper.recomputeSubscriptionState( subscription ) expect(result.paymentProvider.state).to.equal('paused') - expect(ctx.Subscription.updateOne.called).to.be.false + expect(this.Subscription.updateOne.called).to.be.false }) }) }) describe('when subscription should not be paused', function () { describe('before pause period starts', function () { - beforeEach(function (ctx) { - ctx.clock.now = new Date('2023-06-15T08:00:00Z') + beforeEach(function () { + this.clock.now = new Date('2023-06-15T08:00:00Z') }) - it('should keep active state unchanged', async function (ctx) { - const subscription = { ...ctx.baseSubscription } + it('should keep active state unchanged', async function () { + const subscription = { ...this.baseSubscription } const result = - await ctx.SubscriptionHelper.recomputeSubscriptionState( + await this.SubscriptionHelper.recomputeSubscriptionState( subscription ) expect(result.paymentProvider.state).to.equal('active') - expect(ctx.Subscription.updateOne.called).to.be.false + expect(this.Subscription.updateOne.called).to.be.false }) }) describe('after pause period ends', function () { - beforeEach(function (ctx) { - ctx.clock.now = new Date('2023-06-15T12:00:00Z') + beforeEach(function () { + this.clock.now = new Date('2023-06-15T12:00:00Z') }) describe('and current state is paused', function () { - it('should change state to active', async function (ctx) { + it('should change state to active', async function () { const subscription = { - ...ctx.baseSubscription, + ...this.baseSubscription, paymentProvider: { - ...ctx.baseSubscription.paymentProvider, + ...this.baseSubscription.paymentProvider, state: 'paused', }, } const result = - await ctx.SubscriptionHelper.recomputeSubscriptionState( + await this.SubscriptionHelper.recomputeSubscriptionState( subscription ) expect(result.paymentProvider.state).to.equal('active') - expect(ctx.Subscription.updateOne).to.have.been.calledWith( + expect(this.Subscription.updateOne).to.have.been.calledWith( { _id: 'subscription_id' }, { 'paymentProvider.state': 'active' } ) @@ -623,48 +647,48 @@ describe('SubscriptionHelper', function () { }) describe('and current state is already active', function () { - it('should keep state unchanged', async function (ctx) { - const subscription = { ...ctx.baseSubscription } + it('should keep state unchanged', async function () { + const subscription = { ...this.baseSubscription } const result = - await ctx.SubscriptionHelper.recomputeSubscriptionState( + await this.SubscriptionHelper.recomputeSubscriptionState( subscription ) expect(result.paymentProvider.state).to.equal('active') - expect(ctx.Subscription.updateOne.called).to.be.false + expect(this.Subscription.updateOne.called).to.be.false }) }) }) }) describe('when subscription has no pausePeriodEnd (indefinite pause)', function () { - beforeEach(function (ctx) { - ctx.baseSubscription.paymentProvider.pausePeriodEnd = undefined + beforeEach(function () { + this.baseSubscription.paymentProvider.pausePeriodEnd = undefined }) - it('should not transition to paused state when pausePeriodEnd is missing', async function (ctx) { - const subscription = { ...ctx.baseSubscription } + it('should not transition to paused state when pausePeriodEnd is missing', async function () { + const subscription = { ...this.baseSubscription } const result = - await ctx.SubscriptionHelper.recomputeSubscriptionState(subscription) + await this.SubscriptionHelper.recomputeSubscriptionState(subscription) expect(result.paymentProvider.state).to.equal('active') - expect(ctx.Subscription.updateOne.called).to.be.false + expect(this.Subscription.updateOne.called).to.be.false }) - it('should keep paused state when already paused and no end date', async function (ctx) { + it('should keep paused state when already paused and no end date', async function () { const subscription = { - ...ctx.baseSubscription, + ...this.baseSubscription, paymentProvider: { - ...ctx.baseSubscription.paymentProvider, + ...this.baseSubscription.paymentProvider, state: 'paused', pausePeriodEnd: undefined, }, } const result = - await ctx.SubscriptionHelper.recomputeSubscriptionState(subscription) + await this.SubscriptionHelper.recomputeSubscriptionState(subscription) expect(result.paymentProvider.state).to.equal('paused') - expect(ctx.Subscription.updateOne.called).to.be.false + expect(this.Subscription.updateOne.called).to.be.false }) }) }) diff --git a/services/web/test/unit/src/Subscription/SubscriptionViewModelBuilder.test.mjs b/services/web/test/unit/src/Subscription/SubscriptionViewModelBuilder.test.mjs index 336679b070..90737cf3df 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.mjs' +import SubscriptionHelper from '../../../../app/src/Features/Subscription/SubscriptionHelper.js' 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 f7562f787a..b1f2fdb545 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 11aa7bc7bd..64c7782c3f 100644 --- a/services/web/test/unit/src/ThirdPartyDataStore/TpdsProjectFlusher.test.mjs +++ b/services/web/test/unit/src/ThirdPartyDataStore/TpdsProjectFlusher.test.mjs @@ -1,7 +1,9 @@ import { vi, expect } from 'vitest' import sinon from 'sinon' import mongodb from 'mongodb-legacy' -import { Project } from '../../../../app/src/models/Project.mjs' +import indirectlyImportModels from '../helpers/indirectlyImportModels.js' + +const { Project } = indirectlyImportModels(['Project']) 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 7bda3b03f8..7e3bb5bbb4 100644 --- a/services/web/test/unit/src/User/UserAuditLogHandler.test.mjs +++ b/services/web/test/unit/src/User/UserAuditLogHandler.test.mjs @@ -1,7 +1,9 @@ import { vi, expect } from 'vitest' import sinon from 'sinon' import mongodb from 'mongodb-legacy' -import { UserAuditLogEntry } from '../../../../app/src/models/UserAuditLogEntry.mjs' +import indirectlyImportModels from '../helpers/indirectlyImportModels.js' + +const { UserAuditLogEntry } = indirectlyImportModels(['UserAuditLogEntry']) 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 5e41c89a80..3baf70edd3 100644 --- a/services/web/test/unit/src/User/UserDeleter.test.mjs +++ b/services/web/test/unit/src/User/UserDeleter.test.mjs @@ -4,8 +4,9 @@ import tk from 'timekeeper' import moment from 'moment' import Errors from '../../../../app/src/Features/Errors/Errors.js' import mongoose from 'mongoose' -import { DeletedUser } from '../../../../app/src/models/DeletedUser.mjs' -import { User } from '../../../../app/src/models/User.mjs' +import indirectlyImportModels from '../helpers/indirectlyImportModels.js' + +const { User, DeletedUser } = indirectlyImportModels(['User', 'DeletedUser']) 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 6ed79d7874..9c23805a9c 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.mjs' +import EmailHelper from '../../../../app/src/Features/Helpers/EmailHelper.js' 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 ce1f478fbf..f8e7e50826 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.mjs' +import EmailHelper from '../../../../app/src/Features/Helpers/EmailHelper.js' 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 7885d1fa8f..d06510fc44 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', () => ({ - Institution: ctx.Institution, + default: { Institution: ctx.Institution }, })) vi.doMock('../../../../app/src/models/Subscription', () => ({ - Subscription: ctx.Subscription, + default: { Subscription: ctx.Subscription }, })) vi.doMock('../../../../app/src/models/Publisher', () => ({ - Publisher: ctx.Publisher, + default: { 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 new file mode 100644 index 0000000000..764dd5240a --- /dev/null +++ b/services/web/test/unit/src/helpers/MockModel.js @@ -0,0 +1,39 @@ +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 new file mode 100644 index 0000000000..cfa4706b49 --- /dev/null +++ b/services/web/test/unit/src/helpers/indirectlyImportModels.js @@ -0,0 +1,19 @@ +// 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 new file mode 100644 index 0000000000..f3537bcb43 --- /dev/null +++ b/services/web/test/unit/src/helpers/models/DeletedProject.js @@ -0,0 +1,5 @@ +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 new file mode 100644 index 0000000000..92d932c784 --- /dev/null +++ b/services/web/test/unit/src/helpers/models/DeletedUser.js @@ -0,0 +1,5 @@ +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 new file mode 100644 index 0000000000..ac7bed3683 --- /dev/null +++ b/services/web/test/unit/src/helpers/models/Doc.js @@ -0,0 +1,3 @@ +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 new file mode 100644 index 0000000000..3c57aa363e --- /dev/null +++ b/services/web/test/unit/src/helpers/models/File.js @@ -0,0 +1,3 @@ +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 new file mode 100644 index 0000000000..3abf588ff9 --- /dev/null +++ b/services/web/test/unit/src/helpers/models/Folder.js @@ -0,0 +1,6 @@ +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 new file mode 100644 index 0000000000..508db37d85 --- /dev/null +++ b/services/web/test/unit/src/helpers/models/Project.js @@ -0,0 +1,5 @@ +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 new file mode 100644 index 0000000000..fa6c2aa1f5 --- /dev/null +++ b/services/web/test/unit/src/helpers/models/Tag.js @@ -0,0 +1,3 @@ +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 new file mode 100644 index 0000000000..7190fd6640 --- /dev/null +++ b/services/web/test/unit/src/helpers/models/User.js @@ -0,0 +1,5 @@ +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 new file mode 100644 index 0000000000..f31838ba3d --- /dev/null +++ b/services/web/test/unit/src/helpers/models/UserAuditLogEntry.js @@ -0,0 +1,3 @@ +const mockModel = require('../MockModel') + +module.exports = mockModel('UserAuditLogEntry') diff --git a/services/web/test/unit/src/infrastructure/Mongodb.test.mjs b/services/web/test/unit/src/infrastructure/MongodbTests.js similarity index 98% rename from services/web/test/unit/src/infrastructure/Mongodb.test.mjs rename to services/web/test/unit/src/infrastructure/MongodbTests.js index 28ae2c6171..65cab5f7b6 100644 --- a/services/web/test/unit/src/infrastructure/Mongodb.test.mjs +++ b/services/web/test/unit/src/infrastructure/MongodbTests.js @@ -1,8 +1,6 @@ -import mongodb from 'mongodb-legacy' -import { expect } from 'vitest' -import sinon from 'sinon' - -const { ObjectId } = mongodb +const { ObjectId } = require('mongodb-legacy') +const { expect } = require('chai') +const sinon = require('sinon') 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 cc057bd1f0..50ff559bc9 100644 --- a/services/web/test/unit/vitest_bootstrap.mjs +++ b/services/web/test/unit/vitest_bootstrap.mjs @@ -4,7 +4,35 @@ import sinon from 'sinon' import logger from '@overleaf/logger' import sinonChai from 'sinon-chai' import chaiAsPromised from 'chai-as-promised' -import mongoose from 'mongoose' +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('") + }, + }, +}) /* * Chai configuration @@ -52,8 +80,4 @@ afterEach(() => { vi.restoreAllMocks() vi.resetModules() sinon.restore() - const modelNames = mongoose.modelNames() - modelNames.forEach(name => { - delete mongoose.connection.models[name] - }) })