From 902ae750dce7b70ed390dbf48a05b39fcdaed51d Mon Sep 17 00:00:00 2001 From: Liangjun Song <146005915+adai26@users.noreply.github.com> Date: Tue, 22 Oct 2024 09:21:39 +0100 Subject: [PATCH] Merge pull request #21202 from overleaf/ls-scripts-to-esm-2 Migrate scripts folder to esm 2/x GitOrigin-RevId: 1698bc4f13e026fa281d37a4914a2f997849c761 --- .../20190730093801_script_example.mjs | 2 +- services/web/migrations/README.md | 2 +- ...ueryHelper.js => GoogleBigQueryHelper.mjs} | 4 +- ...> sync_group_subscription_memberships.mjs} | 37 +++++++++---------- ...te_test_dupes.js => delete_test_dupes.mjs} | 4 +- ...haned-docs.js => delete-orphaned-docs.mjs} | 18 ++++----- ..._migration.js => script_for_migration.mjs} | 21 ++++++----- ...tory_data.js => clean_sl_history_data.mjs} | 9 +++-- ..._support.js => migrate_ranges_support.mjs} | 23 ++++++------ ...s => merge_group_subscription_members.mjs} | 24 ++++++------ ...secrets.js => backfill_hashed_secrets.mjs} | 23 +++++------- .../{create_token.js => create_token.mjs} | 23 +++++------- ...register_client.js => register_client.mjs} | 27 +++++++------- .../{remove_client.js => remove_client.mjs} | 21 +++++------ ...ns.js => purge_non_logged_in_sessions.mjs} | 17 +++++---- ...m_redis.js => recover_docs_from_redis.mjs} | 30 +++++++-------- ...js => collect_paypal_past_due_invoice.mjs} | 30 +++++++-------- ...nts_csv.js => get_paypal_accounts_csv.mjs} | 6 +-- ...prices.js => get_recurly_group_prices.mjs} | 22 +++++------ ...users.js => refresh_institution_users.mjs} | 21 ++++++----- .../src/CollectPayPalPastDueInvoiceTest.mjs | 4 +- 21 files changed, 184 insertions(+), 184 deletions(-) rename services/web/scripts/analytics/helpers/{GoogleBigQueryHelper.js => GoogleBigQueryHelper.mjs} (86%) rename services/web/scripts/analytics/{sync_group_subscription_memberships.js => sync_group_subscription_memberships.mjs} (92%) rename services/web/scripts/delete-duplicate-splittest-versions/{delete_test_dupes.js => delete_test_dupes.mjs} (95%) rename services/web/scripts/delete-orphaned-docs/{delete-orphaned-docs.js => delete-orphaned-docs.mjs} (90%) rename services/web/scripts/example/{script_for_migration.js => script_for_migration.mjs} (62%) rename services/web/scripts/history/{clean_sl_history_data.js => clean_sl_history_data.mjs} (87%) rename services/web/scripts/history/{migrate_ranges_support.js => migrate_ranges_support.mjs} (86%) rename services/web/scripts/{merge_group_subscription_members.js => merge_group_subscription_members.mjs} (86%) rename services/web/scripts/oauth/{backfill_hashed_secrets.js => backfill_hashed_secrets.mjs} (79%) rename services/web/scripts/oauth/{create_token.js => create_token.mjs} (85%) rename services/web/scripts/oauth/{register_client.js => register_client.mjs} (88%) rename services/web/scripts/oauth/{remove_client.js => remove_client.mjs} (93%) rename services/web/scripts/{purge_non_logged_in_sessions.js => purge_non_logged_in_sessions.mjs} (88%) rename services/web/scripts/{recover_docs_from_redis.js => recover_docs_from_redis.mjs} (88%) rename services/web/scripts/recurly/{collect_paypal_past_due_invoice.js => collect_paypal_past_due_invoice.mjs} (86%) rename services/web/scripts/recurly/{get_paypal_accounts_csv.js => get_paypal_accounts_csv.mjs} (94%) rename services/web/scripts/recurly/{get_recurly_group_prices.js => get_recurly_group_prices.mjs} (81%) rename services/web/scripts/{refresh_institution_users.js => refresh_institution_users.mjs} (72%) diff --git a/services/web/migrations/20190730093801_script_example.mjs b/services/web/migrations/20190730093801_script_example.mjs index e4542d8508..fda971a242 100644 --- a/services/web/migrations/20190730093801_script_example.mjs +++ b/services/web/migrations/20190730093801_script_example.mjs @@ -8,7 +8,7 @@ * or "hello ", when User.findOne() finds something. */ -import runScript from '../scripts/example/script_for_migration.js' +import runScript from '../scripts/example/script_for_migration.mjs' const tags = [] diff --git a/services/web/migrations/README.md b/services/web/migrations/README.md index e30cec744c..13a0865077 100644 --- a/services/web/migrations/README.md +++ b/services/web/migrations/README.md @@ -46,7 +46,7 @@ undo the changes made in `migrate`. #### Running scripts as a migration To run a script in a migration file, look at `migrations/20190730093801_script_example.js`, which runs the script -`scripts/example/script_for_migration.js`. This uses a method where the script can be run standalone via `node`, or +`scripts/example/script_for_migration.mjs`. This uses a method where the script can be run standalone via `node`, or through the migrations' mechanism. ### Running migrations diff --git a/services/web/scripts/analytics/helpers/GoogleBigQueryHelper.js b/services/web/scripts/analytics/helpers/GoogleBigQueryHelper.mjs similarity index 86% rename from services/web/scripts/analytics/helpers/GoogleBigQueryHelper.js rename to services/web/scripts/analytics/helpers/GoogleBigQueryHelper.mjs index 1a79ab0329..84ff5f2caf 100644 --- a/services/web/scripts/analytics/helpers/GoogleBigQueryHelper.js +++ b/services/web/scripts/analytics/helpers/GoogleBigQueryHelper.mjs @@ -1,4 +1,4 @@ -const GoogleBigQuery = require('@google-cloud/bigquery').BigQuery +import { BigQuery as GoogleBigQuery } from '@google-cloud/bigquery' let dataset = null @@ -25,6 +25,6 @@ async function query(query) { return rows } -module.exports = { +export default { query, } diff --git a/services/web/scripts/analytics/sync_group_subscription_memberships.js b/services/web/scripts/analytics/sync_group_subscription_memberships.mjs similarity index 92% rename from services/web/scripts/analytics/sync_group_subscription_memberships.js rename to services/web/scripts/analytics/sync_group_subscription_memberships.mjs index dd3f848528..fc448cc2c7 100644 --- a/services/web/scripts/analytics/sync_group_subscription_memberships.js +++ b/services/web/scripts/analytics/sync_group_subscription_memberships.mjs @@ -1,13 +1,13 @@ -const GoogleBigQueryHelper = require('./helpers/GoogleBigQueryHelper') -const { Subscription } = require('../../app/src/models/Subscription') -const { waitForDb } = require('../../app/src/infrastructure/mongodb') -const AnalyticsManager = require('../../app/src/Features/Analytics/AnalyticsManager') -const { - DeletedSubscription, -} = require('../../app/src/models/DeletedSubscription') -const minimist = require('minimist') -const _ = require('lodash') -const { ObjectId } = require('mongodb-legacy') +import GoogleBigQueryHelper from './helpers/GoogleBigQueryHelper.mjs' +import { Subscription } from '../../app/src/models/Subscription.js' +import { waitForDb } from '../../app/src/infrastructure/mongodb.js' +import AnalyticsManager from '../../app/src/Features/Analytics/AnalyticsManager.js' +import { DeletedSubscription } from '../../app/src/models/DeletedSubscription.js' +import minimist from 'minimist' +import _ from 'lodash' +import mongodb from 'mongodb-legacy' + +const { ObjectId } = mongodb let FETCH_LIMIT, COMMIT, VERBOSE @@ -260,12 +260,11 @@ const setup = () => { } setup() -main() - .then(() => { - console.error('Done.') - process.exit(0) - }) - .catch(error => { - console.error({ error }) - process.exit(1) - }) +try { + await main() + console.error('Done.') + process.exit(0) +} catch (error) { + console.error({ error }) + process.exit(1) +} diff --git a/services/web/scripts/delete-duplicate-splittest-versions/delete_test_dupes.js b/services/web/scripts/delete-duplicate-splittest-versions/delete_test_dupes.mjs similarity index 95% rename from services/web/scripts/delete-duplicate-splittest-versions/delete_test_dupes.js rename to services/web/scripts/delete-duplicate-splittest-versions/delete_test_dupes.mjs index 40e06f2635..b81432b3c0 100644 --- a/services/web/scripts/delete-duplicate-splittest-versions/delete_test_dupes.js +++ b/services/web/scripts/delete-duplicate-splittest-versions/delete_test_dupes.mjs @@ -1,5 +1,5 @@ -const { db, waitForDb } = require('../../app/src/infrastructure/mongodb') -const minimist = require('minimist') +import { db, waitForDb } from '../../app/src/infrastructure/mongodb.js' +import minimist from 'minimist' const argv = minimist(process.argv.slice(2)) const commit = argv.commit !== undefined diff --git a/services/web/scripts/delete-orphaned-docs/delete-orphaned-docs.js b/services/web/scripts/delete-orphaned-docs/delete-orphaned-docs.mjs similarity index 90% rename from services/web/scripts/delete-orphaned-docs/delete-orphaned-docs.js rename to services/web/scripts/delete-orphaned-docs/delete-orphaned-docs.mjs index 967761672a..47252ef186 100644 --- a/services/web/scripts/delete-orphaned-docs/delete-orphaned-docs.js +++ b/services/web/scripts/delete-orphaned-docs/delete-orphaned-docs.mjs @@ -1,16 +1,14 @@ -'use strict' - -const fs = require('fs') -const minimist = require('minimist') -const readline = require('readline') - -const { +import fs from 'fs' +import minimist from 'minimist' +import readline from 'readline' +import { db, ObjectId, waitForDb, -} = require('../../app/src/infrastructure/mongodb') -const DocstoreManager = - require('../../app/src/Features/Docstore/DocstoreManager').promises +} from '../../app/src/infrastructure/mongodb.js' +import DocstoreManagerModule from '../../app/src/Features/Docstore/DocstoreManager.js' + +const { promises: DocstoreManager } = DocstoreManagerModule const argv = minimist(process.argv.slice(2)) const commit = argv.commit !== undefined diff --git a/services/web/scripts/example/script_for_migration.js b/services/web/scripts/example/script_for_migration.mjs similarity index 62% rename from services/web/scripts/example/script_for_migration.js rename to services/web/scripts/example/script_for_migration.mjs index 5ac3f826cb..ed1d288aa8 100644 --- a/services/web/scripts/example/script_for_migration.js +++ b/services/web/scripts/example/script_for_migration.mjs @@ -6,7 +6,9 @@ * in the migrations directory. */ -const { User } = require('../../app/src/models/User') +import { User } from '../../app/src/models/User.js' +import { fileURLToPath } from 'url' + // const somePackage = require('some-package') const runScript = async () => { @@ -15,13 +17,14 @@ const runScript = async () => { console.log(`Hello ${name}!`) } -if (require.main === module) { - runScript() - .then(() => process.exit()) - .catch(err => { - console.error(err) - process.exit(1) - }) +if (fileURLToPath(import.meta.url) === process.argv[1]) { + try { + await runScript() + process.exit() + } catch (error) { + console.error(error) + process.exit(1) + } } -module.exports = runScript +export default runScript diff --git a/services/web/scripts/history/clean_sl_history_data.js b/services/web/scripts/history/clean_sl_history_data.mjs similarity index 87% rename from services/web/scripts/history/clean_sl_history_data.js rename to services/web/scripts/history/clean_sl_history_data.mjs index a7497c826f..2cab756600 100644 --- a/services/web/scripts/history/clean_sl_history_data.js +++ b/services/web/scripts/history/clean_sl_history_data.mjs @@ -1,6 +1,9 @@ -// Increase default mongo query timeout from 1min to 1h -process.env.MONGO_SOCKET_TIMEOUT = process.env.MONGO_SOCKET_TIMEOUT || '360000' -const { waitForDb, db } = require('../../app/src/infrastructure/mongodb') +import { waitForDb, db } from '../../app/src/infrastructure/mongodb.js' +import { ensureMongoTimeout } from '../helpers/env_variable_helper.mjs' +// Ensure default mongo query timeout has been increased 1h +if (!process.env.MONGO_SOCKET_TIMEOUT) { + ensureMongoTimeout(360000) +} async function main() { await checkAllProjectsAreMigrated() diff --git a/services/web/scripts/history/migrate_ranges_support.js b/services/web/scripts/history/migrate_ranges_support.mjs similarity index 86% rename from services/web/scripts/history/migrate_ranges_support.js rename to services/web/scripts/history/migrate_ranges_support.mjs index 616c31c808..a4a769656f 100644 --- a/services/web/scripts/history/migrate_ranges_support.js +++ b/services/web/scripts/history/migrate_ranges_support.mjs @@ -1,6 +1,6 @@ -const HistoryRangesSupportMigration = require('../../app/src/Features/History/HistoryRangesSupportMigration') -const { waitForDb } = require('../../app/src/infrastructure/mongodb') -const minimist = require('minimist') +import HistoryRangesSupportMigration from '../../app/src/Features/History/HistoryRangesSupportMigration.mjs' +import { waitForDb } from '../../app/src/infrastructure/mongodb.js' +import minimist from 'minimist' async function main() { await waitForDb() @@ -31,7 +31,7 @@ async function main() { } function usage() { - console.error(`Usage: migrate_ranges_support.js [OPTIONS] + console.error(`Usage: migrate_ranges_support.mjs [OPTIONS] Options: @@ -112,11 +112,10 @@ function arrayOpt(value) { } } -main() - .then(() => { - process.exit(0) - }) - .catch(err => { - console.error(err) - process.exit(1) - }) +try { + await main() + process.exit(0) +} catch (error) { + console.error(error) + process.exit(1) +} diff --git a/services/web/scripts/merge_group_subscription_members.js b/services/web/scripts/merge_group_subscription_members.mjs similarity index 86% rename from services/web/scripts/merge_group_subscription_members.js rename to services/web/scripts/merge_group_subscription_members.mjs index a212d3b69a..da1cbd0f59 100644 --- a/services/web/scripts/merge_group_subscription_members.js +++ b/services/web/scripts/merge_group_subscription_members.mjs @@ -6,9 +6,10 @@ // node scripts/merge_group_subscription_members \ // --target [targetSubscriptionId] --source [sourceSubscriptionId] --commit -const { db, ObjectId, waitForDb } = require('../app/src/infrastructure/mongodb') -const SubscriptionUpdater = require('../app/src/Features/Subscription/SubscriptionUpdater') -const minimist = require('minimist') +import { db, ObjectId, waitForDb } from '../app/src/infrastructure/mongodb.js' + +import SubscriptionUpdater from '../app/src/Features/Subscription/SubscriptionUpdater.js' +import minimist from 'minimist' const argv = minimist(process.argv.slice(2), { string: ['target', 'source'], boolean: ['commit'], @@ -93,12 +94,11 @@ async function main() { } } -main() - .then(() => { - console.error('Done.') - process.exit(0) - }) - .catch(error => { - console.error({ error }) - process.exit(1) - }) +try { + await main() + console.error('Done.') + process.exit(0) +} catch (error) { + console.error({ error }) + process.exit(1) +} diff --git a/services/web/scripts/oauth/backfill_hashed_secrets.js b/services/web/scripts/oauth/backfill_hashed_secrets.mjs similarity index 79% rename from services/web/scripts/oauth/backfill_hashed_secrets.js rename to services/web/scripts/oauth/backfill_hashed_secrets.mjs index e5d497958e..7f09cfc7f6 100644 --- a/services/web/scripts/oauth/backfill_hashed_secrets.js +++ b/services/web/scripts/oauth/backfill_hashed_secrets.mjs @@ -1,11 +1,9 @@ -const { +import { db, waitForDb, READ_PREFERENCE_SECONDARY, -} = require('../../app/src/infrastructure/mongodb') -const { - hashSecret, -} = require('../../modules/oauth2-server/app/src/SecretsHelper') +} from '../../app/src/infrastructure/mongodb.js' +import { hashSecret } from '../../modules/oauth2-server/app/src/SecretsHelper.js' async function main() { await waitForDb() @@ -38,11 +36,10 @@ async function hashSecrets(collection, field) { console.log(`${hashedCount} secrets hashed`) } -main() - .then(() => { - process.exit(0) - }) - .catch(err => { - console.error(err) - process.exit(1) - }) +try { + await main() + process.exit(0) +} catch (error) { + console.error(error) + process.exit(1) +} diff --git a/services/web/scripts/oauth/create_token.js b/services/web/scripts/oauth/create_token.mjs similarity index 85% rename from services/web/scripts/oauth/create_token.js rename to services/web/scripts/oauth/create_token.mjs index 6b3af8c8e1..36dde27395 100644 --- a/services/web/scripts/oauth/create_token.js +++ b/services/web/scripts/oauth/create_token.mjs @@ -1,8 +1,6 @@ -const minimist = require('minimist') -const { waitForDb, db } = require('../../app/src/infrastructure/mongodb') -const { - hashSecret, -} = require('../../modules/oauth2-server/app/src/SecretsHelper') +import minimist from 'minimist' +import { waitForDb, db } from '../../app/src/infrastructure/mongodb.js' +import { hashSecret } from '../../modules/oauth2-server/app/src/SecretsHelper.js' async function main() { const opts = parseArgs() @@ -91,11 +89,10 @@ Options: `) } -main() - .then(() => { - process.exit(0) - }) - .catch(err => { - console.error(err) - process.exit(1) - }) +try { + await main() + process.exit(0) +} catch (error) { + console.error(error) + process.exit(1) +} diff --git a/services/web/scripts/oauth/register_client.js b/services/web/scripts/oauth/register_client.mjs similarity index 88% rename from services/web/scripts/oauth/register_client.js rename to services/web/scripts/oauth/register_client.mjs index 87fa7c0116..b14e6da659 100644 --- a/services/web/scripts/oauth/register_client.js +++ b/services/web/scripts/oauth/register_client.mjs @@ -1,9 +1,9 @@ -const minimist = require('minimist') -const { ObjectId } = require('mongodb-legacy') -const { waitForDb, db } = require('../../app/src/infrastructure/mongodb') -const { - hashSecret, -} = require('../../modules/oauth2-server/app/src/SecretsHelper') +import minimist from 'minimist' +import mongodb from 'mongodb-legacy' +import { waitForDb, db } from '../../app/src/infrastructure/mongodb.js' +import { hashSecret } from '../../modules/oauth2-server/app/src/SecretsHelper.js' + +const { ObjectId } = mongodb async function main() { const opts = parseArgs() @@ -121,11 +121,10 @@ function toArray(value) { } } -main() - .then(() => { - process.exit(0) - }) - .catch(err => { - console.error(err) - process.exit(1) - }) +try { + await main() + process.exit(0) +} catch (error) { + console.error(error) + process.exit(1) +} diff --git a/services/web/scripts/oauth/remove_client.js b/services/web/scripts/oauth/remove_client.mjs similarity index 93% rename from services/web/scripts/oauth/remove_client.js rename to services/web/scripts/oauth/remove_client.mjs index 777de91455..3cd3ae7119 100644 --- a/services/web/scripts/oauth/remove_client.js +++ b/services/web/scripts/oauth/remove_client.mjs @@ -1,9 +1,9 @@ -const minimist = require('minimist') -const { +import minimist from 'minimist' +import { waitForDb, db, READ_PREFERENCE_SECONDARY, -} = require('../../app/src/infrastructure/mongodb') +} from '../../app/src/infrastructure/mongodb.js' async function main() { const opts = parseArgs() @@ -114,11 +114,10 @@ Options: `) } -main() - .then(() => { - process.exit(0) - }) - .catch(err => { - console.error(err) - process.exit(1) - }) +try { + await main() + process.exit(0) +} catch (error) { + console.error(error) + process.exit(1) +} diff --git a/services/web/scripts/purge_non_logged_in_sessions.js b/services/web/scripts/purge_non_logged_in_sessions.mjs similarity index 88% rename from services/web/scripts/purge_non_logged_in_sessions.js rename to services/web/scripts/purge_non_logged_in_sessions.mjs index 10758edc5b..21565360f9 100644 --- a/services/web/scripts/purge_non_logged_in_sessions.js +++ b/services/web/scripts/purge_non_logged_in_sessions.mjs @@ -1,10 +1,11 @@ -const RedisWrapper = require('@overleaf/redis-wrapper') -const Settings = require('@overleaf/settings') -const SessionManager = require('../app/src/Features/Authentication/SessionManager') +import RedisWrapper from '@overleaf/redis-wrapper' +import Settings from '@overleaf/settings' +import SessionManager from '../app/src/Features/Authentication/SessionManager.js' +import minimist from 'minimist' const redis = RedisWrapper.createClient(Settings.redis.websessions) -const argv = require('minimist')(process.argv.slice(2), { +const argv = minimist(process.argv.slice(2), { string: ['count'], boolean: ['dry-run', 'help'], alias: { @@ -92,7 +93,9 @@ async function scanAndPurge() { redis.quit() } -scanAndPurge().catch(err => { - console.error(err) +try { + await scanAndPurge() +} catch (error) { + console.error(error) process.exit() -}) +} diff --git a/services/web/scripts/recover_docs_from_redis.js b/services/web/scripts/recover_docs_from_redis.mjs similarity index 88% rename from services/web/scripts/recover_docs_from_redis.js rename to services/web/scripts/recover_docs_from_redis.mjs index 77bcf9ab11..d52c0a55ec 100644 --- a/services/web/scripts/recover_docs_from_redis.js +++ b/services/web/scripts/recover_docs_from_redis.mjs @@ -1,12 +1,13 @@ // recover docs from redis where there is no doc in mongo but the project exists -const minimist = require('minimist') -const { db, waitForDb, ObjectId } = require('../app/src/infrastructure/mongodb') -const ProjectEntityUpdateHandler = require('../app/src/Features/Project/ProjectEntityUpdateHandler') -const ProjectEntityRestoreHandler = require('../app/src/Features/Project/ProjectEntityRestoreHandler') -const RedisWrapper = require('@overleaf/redis-wrapper') -const Settings = require('@overleaf/settings') -const logger = require('@overleaf/logger') +import minimist from 'minimist' + +import { db, waitForDb, ObjectId } from '../app/src/infrastructure/mongodb.js' +import ProjectEntityUpdateHandler from '../app/src/Features/Project/ProjectEntityUpdateHandler.js' +import ProjectEntityRestoreHandler from '../app/src/Features/Project/ProjectEntityRestoreHandler.js' +import RedisWrapper from '@overleaf/redis-wrapper' +import Settings from '@overleaf/settings' +import logger from '@overleaf/logger' const opts = parseArgs() const redis = RedisWrapper.createClient(Settings.redis.web) @@ -172,11 +173,10 @@ async function deleteDocFromRedis(projectId, docId) { await redis.srem(`DocsIn:{${projectId}}`, projectId) } -main() - .then(() => { - process.exit(0) - }) - .catch(err => { - console.error(err) - process.exit(1) - }) +try { + await main() + process.exit(0) +} catch (error) { + console.error(error) + process.exit(1) +} diff --git a/services/web/scripts/recurly/collect_paypal_past_due_invoice.js b/services/web/scripts/recurly/collect_paypal_past_due_invoice.mjs similarity index 86% rename from services/web/scripts/recurly/collect_paypal_past_due_invoice.js rename to services/web/scripts/recurly/collect_paypal_past_due_invoice.mjs index 650285e3ac..ba07d2040e 100644 --- a/services/web/scripts/recurly/collect_paypal_past_due_invoice.js +++ b/services/web/scripts/recurly/collect_paypal_past_due_invoice.mjs @@ -1,9 +1,10 @@ -const RecurlyWrapper = require('../../app/src/Features/Subscription/RecurlyWrapper') -const minimist = require('minimist') -const logger = require('@overleaf/logger') +import RecurlyWrapper from '../../app/src/Features/Subscription/RecurlyWrapper.js' +import minimist from 'minimist' +import logger from '@overleaf/logger' +import { fileURLToPath } from 'url' const waitMs = - require.main === module + fileURLToPath(import.meta.url) === process.argv[1] ? timeout => new Promise(resolve => setTimeout(() => resolve(), timeout)) : () => Promise.resolve() @@ -116,16 +117,15 @@ const main = async () => { } } -if (require.main === module) { - main() - .then(() => { - logger.info('Done.') - process.exit(0) - }) - .catch(err => { - logger.error({ err }, 'Error') - process.exit(1) - }) +if (fileURLToPath(import.meta.url) === process.argv[1]) { + try { + await main() + logger.info('Done.') + process.exit(0) + } catch (error) { + logger.error({ error }, 'Error') + process.exit(1) + } } -module.exports = { main } +export default { main } diff --git a/services/web/scripts/recurly/get_paypal_accounts_csv.js b/services/web/scripts/recurly/get_paypal_accounts_csv.mjs similarity index 94% rename from services/web/scripts/recurly/get_paypal_accounts_csv.js rename to services/web/scripts/recurly/get_paypal_accounts_csv.mjs index 1ca79c38ad..d94b3fe033 100644 --- a/services/web/scripts/recurly/get_paypal_accounts_csv.js +++ b/services/web/scripts/recurly/get_paypal_accounts_csv.mjs @@ -1,6 +1,6 @@ -const RecurlyWrapper = require('../../app/src/Features/Subscription/RecurlyWrapper') -const async = require('async') -const CSVParser = require('json2csv').Parser +import RecurlyWrapper from '../../app/src/Features/Subscription/RecurlyWrapper.js' +import async from 'async' +import { Parser as CSVParser } from 'json2csv' const NOW = new Date() diff --git a/services/web/scripts/recurly/get_recurly_group_prices.js b/services/web/scripts/recurly/get_recurly_group_prices.mjs similarity index 81% rename from services/web/scripts/recurly/get_recurly_group_prices.js rename to services/web/scripts/recurly/get_recurly_group_prices.mjs index 2d8a16d630..e00a1e4c66 100644 --- a/services/web/scripts/recurly/get_recurly_group_prices.js +++ b/services/web/scripts/recurly/get_recurly_group_prices.mjs @@ -2,10 +2,11 @@ // app/templates/plans/groups.json // // Usage example: -// node scripts/recurly/get_recurly_group_prices.js +// node scripts/recurly/get_recurly_group_prices.mjs -const recurly = require('recurly') -const Settings = require('@overleaf/settings') +import recurly from 'recurly' + +import Settings from '@overleaf/settings' const recurlySettings = Settings.apis.recurly const recurlyApiKey = recurlySettings ? recurlySettings.apiKey : undefined @@ -37,11 +38,10 @@ async function main() { console.log(JSON.stringify(prices, undefined, 2)) } -main() - .then(() => { - process.exit(0) - }) - .catch(error => { - console.error({ error }) - process.exit(1) - }) +try { + await main() + process.exit(0) +} catch (error) { + console.error({ error }) + process.exit(1) +} diff --git a/services/web/scripts/refresh_institution_users.js b/services/web/scripts/refresh_institution_users.mjs similarity index 72% rename from services/web/scripts/refresh_institution_users.js rename to services/web/scripts/refresh_institution_users.mjs index 0a0555b6a1..330331b7b5 100644 --- a/services/web/scripts/refresh_institution_users.js +++ b/services/web/scripts/refresh_institution_users.mjs @@ -1,18 +1,11 @@ -const { waitForDb } = require('../app/src/infrastructure/mongodb') -const minimist = require('minimist') -const InstitutionsManager = require('../app/src/Features/Institutions/InstitutionsManager') +import { waitForDb } from '../app/src/infrastructure/mongodb.js' +import minimist from 'minimist' +import InstitutionsManager from '../app/src/Features/Institutions/InstitutionsManager.js' const institutionId = parseInt(process.argv[2]) if (isNaN(institutionId)) throw new Error('No institution id') console.log('Refreshing users at institution', institutionId) -waitForDb() - .then(main) - .catch(err => { - console.error(err) - process.exit(1) - }) - function main() { const argv = minimist(process.argv.slice(2)) if (!argv.notify) { @@ -37,3 +30,11 @@ function main() { } ) } + +try { + await waitForDb() + await main() +} catch (error) { + console.error(error) + process.exit(1) +} diff --git a/services/web/test/acceptance/src/CollectPayPalPastDueInvoiceTest.mjs b/services/web/test/acceptance/src/CollectPayPalPastDueInvoiceTest.mjs index a6256ae860..db75aa6a47 100644 --- a/services/web/test/acceptance/src/CollectPayPalPastDueInvoiceTest.mjs +++ b/services/web/test/acceptance/src/CollectPayPalPastDueInvoiceTest.mjs @@ -2,10 +2,12 @@ import sinon from 'sinon' import chai, { expect } from 'chai' import chaiAsPromised from 'chai-as-promised' import sinonChai from 'sinon-chai' -import { main } from '../../../scripts/recurly/collect_paypal_past_due_invoice.js' +import CollectPaypalPastDueInvoice from '../../../scripts/recurly/collect_paypal_past_due_invoice.mjs' import RecurlyWrapper from '../../../app/src/Features/Subscription/RecurlyWrapper.js' import OError from '@overleaf/o-error' +const { main } = CollectPaypalPastDueInvoice + chai.use(chaiAsPromised) chai.use(sinonChai)