From 1acf7ff093acf0fadbf2b4e790ee0b4c3165949c Mon Sep 17 00:00:00 2001 From: Damian Zehnder Date: Wed, 11 Oct 2023 12:01:26 +0200 Subject: [PATCH] fix: convert CJS modules to ES modules --- src/db.js | 7 ++++--- src/edge-delivery-service-admin-client.js | 9 +++++++-- src/github-client.js | 6 +++--- src/index.js | 13 +++++++++---- src/psi-client.js | 6 +++--- src/s3.js | 6 +++--- src/util.js | 2 +- 7 files changed, 30 insertions(+), 19 deletions(-) diff --git a/src/db.js b/src/db.js index a14eb5f0..2bddba77 100644 --- a/src/db.js +++ b/src/db.js @@ -9,8 +9,8 @@ * OF ANY KIND, either express or implied. See the License for the specific language * governing permissions and limitations under the License. */ -const AWS = require('aws-sdk'); -const { log } = require('./util.js'); +import AWS from 'aws-sdk'; +import { log } from './util.js'; const TABLE_SITES = 'sites'; const TABLE_AUDITS = 'audits'; @@ -117,4 +117,5 @@ function DB(config) { saveAuditError, }; } -module.exports = DB; + +export default DB; diff --git a/src/edge-delivery-service-admin-client.js b/src/edge-delivery-service-admin-client.js index 265522c4..901094eb 100644 --- a/src/edge-delivery-service-admin-client.js +++ b/src/edge-delivery-service-admin-client.js @@ -10,6 +10,7 @@ * governing permissions and limitations under the License. */ const BASE_URL = 'https://www.hlx.live/'; + /** * Retrieve the status of the admin endpoint. * @returns {Promise} - The lastModification property. @@ -17,7 +18,6 @@ const BASE_URL = 'https://www.hlx.live/'; * or some other error while fetching data. */ function EdgeDeliveryServiceAdminClient() { - const getLastModification = async () => { try { const response = await fetch(`${BASE_URL}docs/status.json`); @@ -34,6 +34,11 @@ function EdgeDeliveryServiceAdminClient() { throw error; } }; + + // Return the function from within the EdgeDeliveryServiceAdminClient + return { + getLastModification, + }; } -module.exports = EdgeDeliveryServiceAdminClient; +export default EdgeDeliveryServiceAdminClient; diff --git a/src/github-client.js b/src/github-client.js index a9ae877a..630de767 100644 --- a/src/github-client.js +++ b/src/github-client.js @@ -9,8 +9,8 @@ * OF ANY KIND, either express or implied. See the License for the specific language * governing permissions and limitations under the License. */ -const axios = require('axios'); -const { log } = require('./util.js'); +import axios from 'axios'; +import { log } from './util.js'; const SECONDS_IN_A_DAY = 86400; // Number of seconds in a day @@ -120,4 +120,4 @@ function GithubClient(config) { }; } -module.exports = GithubClient; +export default GithubClient; diff --git a/src/index.js b/src/index.js index d363c7d9..79d7c114 100644 --- a/src/index.js +++ b/src/index.js @@ -13,9 +13,8 @@ import secrets from '@adobe/helix-shared-secrets'; import wrap from '@adobe/helix-shared-wrap'; import { logger } from '@adobe/helix-universal-logger'; import { helixStatus } from '@adobe/helix-status'; - -const DB = require('./db'); -const PSIClient = require('./psi-client'); +import DB from './db.js'; // Assuming the exported content of './db' is default exported +import PSIClient from './psi-client.js'; // Assuming the exported content of './psi-client' is default exported /** * This is the main function @@ -24,11 +23,17 @@ const PSIClient = require('./psi-client'); * @returns {Response} a response */ async function run(request, context) { - const db = DB({ region: process.env.REGION, accessKeyId: process.env.ACCESS_KEY_ID, secretAccessKey: process.env.SECRET_ACCESS_KEY }); + const db = DB({ + region: process.env.REGION, + accessKeyId: process.env.ACCESS_KEY_ID, + secretAccessKey: process.env.SECRET_ACCESS_KEY, + }); + const psiClient = PSIClient({ apiKey: process.env.PAGESPEED_API_KEY, baseUrl: process.env.PAGESPEED_API_BASE_URL, }); + const auditResult = await psiClient.runAudit('https://www.bamboohr.com/'); await db.saveAuditIndex(auditResult); } diff --git a/src/psi-client.js b/src/psi-client.js index 8c2f8bc3..37289858 100644 --- a/src/psi-client.js +++ b/src/psi-client.js @@ -9,8 +9,8 @@ * OF ANY KIND, either express or implied. See the License for the specific language * governing permissions and limitations under the License. */ -const axios = require('axios'); -const { log } = require('./util.js'); +import axios from 'axios'; +import { log } from './util.js'; function PSIClient(config) { const AUDIT_TYPE = 'PSI'; @@ -182,4 +182,4 @@ function PSIClient(config) { }; } -module.exports = PSIClient; +export default PSIClient; diff --git a/src/s3.js b/src/s3.js index 684b0375..6ad6bd23 100644 --- a/src/s3.js +++ b/src/s3.js @@ -9,8 +9,8 @@ * OF ANY KIND, either express or implied. See the License for the specific language * governing permissions and limitations under the License. */ -const AWS = require('aws-sdk'); -const { log } = require('util'); +import AWS from 'aws-sdk'; +import { log } from 'util'; const s3 = new AWS.S3(); @@ -35,4 +35,4 @@ function S3(config) { } } -module.exports = { S3 }; +export { S3 }; diff --git a/src/util.js b/src/util.js index fb756bc7..b2c184ad 100644 --- a/src/util.js +++ b/src/util.js @@ -28,6 +28,6 @@ const log = (level, message, ...args) => { } }; -module.exports = { +export { log, };