Skip to content

Commit

Permalink
feat: Require minimally Node v18 (previously v16)
Browse files Browse the repository at this point in the history
  • Loading branch information
andris9 committed Aug 20, 2024
1 parent b976e53 commit dc8282e
Show file tree
Hide file tree
Showing 18 changed files with 103 additions and 159 deletions.
4 changes: 2 additions & 2 deletions .ncurc.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ module.exports = {
'ical.js',

// api changes, check and fix
'eslint', 'grunt-eslint',
'eslint',
'grunt-eslint',

// no support for Node 16
'marked',
'undici',

// some kind of CVE in later versions. Only needed for license reference, so the actual version does not matter anyway
'startbootstrap-sb-admin-2'
Expand Down
6 changes: 2 additions & 4 deletions lib/api-client/base-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,6 @@ const {
MAX_INLINE_ATTACHMENT_SIZE
} = require('../consts');

let pfStructuredClone = typeof structuredClone === 'function' ? structuredClone : data => JSON.parse(JSON.stringify(data));

const DOWNLOAD_CHUNK_SIZE = getByteSize(readEnvValue('EENGINE_CHUNK_SIZE')) || DEFAULT_DOWNLOAD_CHUNK_SIZE;

async function metricsMeta(meta, logger, key, method, ...args) {
Expand Down Expand Up @@ -357,7 +355,7 @@ class BaseClient {
};

// use more attempts for ElasticSearch updates
const documentJobOptions = Object.assign(pfStructuredClone(defaultJobOptions), { attempts: 16 });
const documentJobOptions = Object.assign(structuredClone(defaultJobOptions), { attempts: 16 });

if (!skipWebhook && addDocumentQueueJob) {
// add both jobs as a Flow
Expand Down Expand Up @@ -474,7 +472,7 @@ class BaseClient {
let messageProcessors = [];

for (let mailMergeEntry of mailMergeList) {
let messageCopy = pfStructuredClone(data);
let messageCopy = structuredClone(data);
if (messageCopy.sendAt) {
// date values do not survive JSON based copying
messageCopy.sendAt = new Date(messageCopy.sendAt);
Expand Down
6 changes: 2 additions & 4 deletions lib/es.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ const { redis } = require('./db');
const { REDIS_PREFIX } = require('./consts');
const assert = require('assert');

let pfStructuredClone = typeof structuredClone === 'function' ? structuredClone : data => JSON.parse(JSON.stringify(data));

const analyzer = {
htmlStripAnalyzer: {
type: 'custom',
Expand Down Expand Up @@ -725,7 +723,7 @@ async function ensureThreadIndex(client, index) {

module.exports = {
async ensureIndex(client, index) {
let localMappings = pfStructuredClone(mappings);
let localMappings = structuredClone(mappings);

let customMappings = (await redis.hgetall(`${REDIS_PREFIX}mappings`)) || {};
for (let key of Object.keys(customMappings)) {
Expand Down Expand Up @@ -755,7 +753,7 @@ module.exports = {
},

// immutable copy
defaultMappings: Object.freeze(pfStructuredClone(mappings))
defaultMappings: Object.freeze(structuredClone(mappings))
};

/*
Expand Down
4 changes: 1 addition & 3 deletions lib/llm-pre-process.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ const { REDIS_PREFIX } = require('./consts');
const settings = require('./settings');
const { SubScript } = require('./sub-script');

let pfStructuredClone = typeof structuredClone === 'function' ? structuredClone : data => JSON.parse(JSON.stringify(data));

class LLMPreProcessHandler {
constructor(options) {
this.options = options || {};
Expand Down Expand Up @@ -119,7 +117,7 @@ class LLMPreProcessHandler {
}

let canUse;
let payload = pfStructuredClone(originalPayload);
let payload = structuredClone(originalPayload);

try {
canUse = await preProcessHandler.filterFn(payload);
Expand Down
4 changes: 2 additions & 2 deletions lib/oauth/gmail.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

const packageData = require('../../package.json');
const { formatPartialSecretKey, pfStructuredClone } = require('../tools');
const { formatPartialSecretKey, structuredClone } = require('../tools');
const crypto = require('crypto');

const { FETCH_TIMEOUT } = require('../consts');
Expand Down Expand Up @@ -125,7 +125,7 @@ const formatFetchResponse = (responseObj, logRaw) => {
return responseObj;
}

let data = pfStructuredClone(responseObj);
let data = structuredClone(responseObj);
for (let key of ['access_token', 'refresh_token']) {
if (data[key]) {
data[key] = logRaw ? data[key] : formatPartialSecretKey(data[key]);
Expand Down
4 changes: 2 additions & 2 deletions lib/oauth/mail-ru.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

const packageData = require('../../package.json');
const { fetch: fetchCmd, Agent } = require('undici');
const { formatPartialSecretKey, pfStructuredClone } = require('../tools');
const { formatPartialSecretKey, structuredClone } = require('../tools');

const { FETCH_TIMEOUT } = require('../consts');

Expand Down Expand Up @@ -38,7 +38,7 @@ const formatFetchResponse = (responseObj, logRaw) => {
return responseObj;
}

let data = pfStructuredClone(responseObj);
let data = structuredClone(responseObj);
for (let key of ['access_token', 'refresh_token']) {
if (data[key]) {
data[key] = logRaw ? data[key] : formatPartialSecretKey(data[key]);
Expand Down
4 changes: 2 additions & 2 deletions lib/oauth/outlook.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

const packageData = require('../../package.json');
const { formatPartialSecretKey, pfStructuredClone } = require('../tools');
const { formatPartialSecretKey, structuredClone } = require('../tools');

const { FETCH_TIMEOUT } = require('../consts');
const MAX_THROTTLING_RETRIES = 5;
Expand Down Expand Up @@ -86,7 +86,7 @@ const formatFetchResponse = (responseObj, logRaw) => {
return responseObj;
}

let data = pfStructuredClone(responseObj);
let data = structuredClone(responseObj);
for (let key of ['access_token', 'refresh_token']) {
if (data[key]) {
data[key] = logRaw ? data[key] : formatPartialSecretKey(data[key]);
Expand Down
4 changes: 1 addition & 3 deletions lib/pre-process.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ const { REDIS_PREFIX } = require('./consts');
const settings = require('./settings');
const { SubScript } = require('./sub-script');

let pfStructuredClone = typeof structuredClone === 'function' ? structuredClone : data => JSON.parse(JSON.stringify(data));

class PreProcessHandler {
constructor(options) {
this.options = options || {};
Expand Down Expand Up @@ -150,7 +148,7 @@ class PreProcessHandler {
}

let canStore;
let payload = pfStructuredClone(originalPayload);
let payload = structuredClone(originalPayload);

try {
canStore = await preProcessHandler.filterFn(payload);
Expand Down
8 changes: 3 additions & 5 deletions lib/routes-ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,6 @@ const base32 = require('base32.js');
const { simpleParser } = require('mailparser');
const libmime = require('libmime');

let pfStructuredClone = typeof structuredClone === 'function' ? structuredClone : data => JSON.parse(JSON.stringify(data));

const {
DEFAULT_MAX_LOG_LINES,
PDKDF2_ITERATIONS,
Expand Down Expand Up @@ -138,7 +136,7 @@ const cachedTemplates = {
};

const getOpenAiModels = async (models, selectedModel) => {
let modelList = (await settings.get('openAiModels')) || pfStructuredClone(models);
let modelList = (await settings.get('openAiModels')) || structuredClone(models);

if (selectedModel && !modelList.find(model => model.id === selectedModel)) {
modelList.unshift({
Expand Down Expand Up @@ -632,7 +630,7 @@ async function getExampleWebhookPayloads() {
let serviceUrl = await settings.get('serviceUrl');
let date = new Date().toISOString();

let examplePayloads = pfStructuredClone(exampleWebhookPayloads);
let examplePayloads = structuredClone(exampleWebhookPayloads);

examplePayloads.forEach(payload => {
if (payload && payload.content) {
Expand All @@ -659,7 +657,7 @@ async function getExampleWebhookPayloads() {
async function getExampleDocumentsPayloads() {
let date = new Date().toISOString();

let examplePayloads = pfStructuredClone(exampleDocumentsPayloads);
let examplePayloads = structuredClone(exampleDocumentsPayloads);

examplePayloads.forEach(payload => {
if (payload && payload.content) {
Expand Down
3 changes: 1 addition & 2 deletions lib/sub-script.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ const { FETCH_TIMEOUT, SUBSCRIPT_RUNTIME_TIMEOUT } = require('./consts');

const { fetch: fetchCmd, Agent } = require('undici');
const fetchAgent = new Agent({ connect: { timeout: FETCH_TIMEOUT } });
let pfStructuredClone = typeof structuredClone === 'function' ? structuredClone : data => JSON.parse(JSON.stringify(data));

const fnCache = new Map();

Expand Down Expand Up @@ -83,7 +82,7 @@ class SubScript {
}

let ctx = {
payload: payload ? pfStructuredClone(payload) : {},
payload: payload ? structuredClone(payload) : {},
fetch: wrappedFetch,
URL,
logger: this.localLogger,
Expand Down
2 changes: 1 addition & 1 deletion lib/tools.js
Original file line number Diff line number Diff line change
Expand Up @@ -1752,7 +1752,7 @@ MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEV3QUiYsp13nD9suD1/ZkEXnuMoSg
return false;
},

pfStructuredClone: typeof structuredClone === 'function' ? structuredClone : data => JSON.parse(JSON.stringify(data)),
structuredClone: typeof structuredClone === 'function' ? structuredClone : data => JSON.parse(JSON.stringify(data)),

loadTlsConfig(ref, envPrefix) {
if (!ref || typeof ref !== 'object') {
Expand Down
6 changes: 2 additions & 4 deletions lib/webhooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ const { REDIS_PREFIX, MESSAGE_NEW_NOTIFY } = require('./consts');
const { SubScript } = require('./sub-script');
const settings = require('./settings');

let pfStructuredClone = typeof structuredClone === 'function' ? structuredClone : data => JSON.parse(JSON.stringify(data));

class WebhooksHandler {
constructor(options) {
this.options = options || {};
Expand Down Expand Up @@ -440,7 +438,7 @@ class WebhooksHandler {
async formatPayload(event, originalPayload) {
// run all normalizations before sending the data

const payload = pfStructuredClone(originalPayload);
const payload = structuredClone(originalPayload);
payload.eventId = payload.eventId || uuid.v4();

if (event === MESSAGE_NEW_NOTIFY && payload && payload.data && payload.data.text) {
Expand Down Expand Up @@ -514,7 +512,7 @@ class WebhooksHandler {
for (let route of webhookRoutes) {
if (route.enabled && route.targetUrl && typeof route.filterFn === 'function') {
let canSend;
let payload = pfStructuredClone(originalPayload);
let payload = structuredClone(originalPayload);

payload._route = {
id: route.id
Expand Down
74 changes: 22 additions & 52 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit dc8282e

Please sign in to comment.