From 005bd377a2417c9aa275492f8e20e08ab656907c Mon Sep 17 00:00:00 2001 From: zefie Date: Wed, 13 Aug 2025 00:45:04 -0400 Subject: [PATCH] Add depreciation warning system, begin depreciation of session_data.hasCap() --- zefie_wtvp_minisrv/app.js | 58 +++++++++++++++++++ .../prerendered/Mail/Write/Writing.js | 4 +- .../prerendered/Mail/Write/Writing3.js | 2 +- .../prerendered/Mail/Write/Writing4.js | 2 +- .../prerendered/Mail/Write/Writing5.js | 2 +- .../prerendered/Mail/Write/Writing6.js | 2 +- .../ServiceVault/wtv-author/add-block.js | 2 +- .../ServiceVault/wtv-author/edit-block.js | 2 +- .../includes/ServiceVault/wtv-setup/sound.js | 2 +- .../includes/classes/WTVBGMusic.js | 6 +- .../includes/classes/WTVGuide.js | 8 +-- zefie_wtvp_minisrv/test.js | 9 +++ 12 files changed, 83 insertions(+), 16 deletions(-) diff --git a/zefie_wtvp_minisrv/app.js b/zefie_wtvp_minisrv/app.js index fd7f48e1..3cc509e6 100644 --- a/zefie_wtvp_minisrv/app.js +++ b/zefie_wtvp_minisrv/app.js @@ -197,6 +197,61 @@ function moveArrayKey(array, from, to) { return array; }; +// Deprecation warnings configuration +const deprecationWarnings = { + // Array of deprecated patterns with their details + patterns: [ + { + // Example deprecations - you can modify these as needed + pattern: /session\_data\.hasCap\s*\(/g, + message: "session_data.hasCap() is deprecated and will be removed", + removeVersion: "0.9.70", + replacement: "Use session_data.capabilities.get() instead" + } + ], + + // Enable/disable deprecation warnings globally + enabled: true, + + // Log level for deprecation warnings (console.warn, console.log, etc.) + logLevel: 'warn' +}; + +function checkDeprecationWarnings(script_data, filename = null, debug_name = null) { + if (!deprecationWarnings.enabled || !script_data) return; + + const scriptSource = filename || debug_name || 'unknown script'; + const foundDeprecations = []; + + deprecationWarnings.patterns.forEach(deprecation => { + const matches = script_data.match(deprecation.pattern); + if (matches) { + const uniqueMatches = [...new Set(matches)]; // Remove duplicates + uniqueMatches.forEach(match => { + foundDeprecations.push({ + pattern: match.trim(), + message: deprecation.message, + removeVersion: deprecation.removeVersion, + replacement: deprecation.replacement + }); + }); + } + }); + + if (foundDeprecations.length > 0) { + const logFunction = console[deprecationWarnings.logLevel] || console.warn; + + logFunction(`\n⚠️ DEPRECATION WARNING(S) in ${scriptSource}:`); + foundDeprecations.forEach((dep, index) => { + logFunction(` ${index + 1}. ${dep.pattern}: ${dep.message} in version ${dep.removeVersion}`); + if (dep.replacement) { + logFunction(` → ${dep.replacement}`); + } + }); + logFunction(''); // Empty line for readability + } +} + function getServiceString(service, overrides = {}) { return wtvshared.getServiceString(service, overrides); } @@ -213,6 +268,9 @@ async function sendRawFile(socket, path) { } const runScriptInVM = function (script_data, user_contextObj = {}, privileged = false, filename = null, debug_name = null) { + // Check for deprecation warnings before execution + checkDeprecationWarnings(script_data, filename, debug_name); + // Here we define the ServiceVault Script Context Object // The ServiceVault scripts will only be allowed to access the following functions/variables. // Furthermore, only modifications to variables in `updateFromVM` will be saved. diff --git a/zefie_wtvp_minisrv/includes/ServiceDeps/templates/wtv-guide/prerendered/Mail/Write/Writing.js b/zefie_wtvp_minisrv/includes/ServiceDeps/templates/wtv-guide/prerendered/Mail/Write/Writing.js index 30b3492c..f4d6c5e3 100644 --- a/zefie_wtvp_minisrv/includes/ServiceDeps/templates/wtv-guide/prerendered/Mail/Write/Writing.js +++ b/zefie_wtvp_minisrv/includes/ServiceDeps/templates/wtv-guide/prerendered/Mail/Write/Writing.js @@ -57,7 +57,7 @@ To write an e-mail message, follow these steps: First, if you're not already in Mail, choose Mail from `; -if (session_data.hasCap("client-has-tv-experience")) +if (session_data.capabilities.get("client-has-tv-experience")) data += "Web Home" else data += "Home" @@ -66,7 +66,7 @@ data += ` or press the Mail key on your keyboard.
` -if (session_data.hasCap("client-can-do-av-capture")) { +if (session_data.capabilities.get("client-can-do-av-capture")) { data += `
diff --git a/zefie_wtvp_minisrv/includes/ServiceVault/wtv-author/edit-block.js b/zefie_wtvp_minisrv/includes/ServiceVault/wtv-author/edit-block.js index dff48cee..dce72075 100644 --- a/zefie_wtvp_minisrv/includes/ServiceVault/wtv-author/edit-block.js +++ b/zefie_wtvp_minisrv/includes/ServiceVault/wtv-author/edit-block.js @@ -413,7 +413,7 @@ document.theForm.submit(); ` -if (session_data.hasCap("client-can-do-av-capture")) { +if (session_data.capabilities.get("client-can-do-av-capture")) { data += `
diff --git a/zefie_wtvp_minisrv/includes/ServiceVault/wtv-setup/sound.js b/zefie_wtvp_minisrv/includes/ServiceVault/wtv-setup/sound.js index 32028a6e..cd173c9d 100644 --- a/zefie_wtvp_minisrv/includes/ServiceVault/wtv-setup/sound.js +++ b/zefie_wtvp_minisrv/includes/ServiceVault/wtv-setup/sound.js @@ -1,5 +1,5 @@ const minisrv_service_file = true; -const canDoMuzac = session_data.hasCap('client-can-do-muzac'); +const canDoMuzac = session_data.capabilities.get('client-can-do-muzac'); headers = `200 OK Connection: Keep-Alive diff --git a/zefie_wtvp_minisrv/includes/classes/WTVBGMusic.js b/zefie_wtvp_minisrv/includes/classes/WTVBGMusic.js index 969fd905..0d4d3201 100644 --- a/zefie_wtvp_minisrv/includes/classes/WTVBGMusic.js +++ b/zefie_wtvp_minisrv/includes/classes/WTVBGMusic.js @@ -1265,7 +1265,7 @@ class WTVBGMusic { if (setDefaults === true) { // set up defaults - if (this.session_data.hasCap("client-can-do-rmf")) { + if (this.session_data.capabilities.get("client-can-do-rmf")) { // rmf music_obj.enableCategories = ["1", "2", "3", "7", "12", "13", "15", "16"]; music_obj.enableSongs = [ @@ -1318,7 +1318,7 @@ class WTVBGMusic { getSong(songid) { let musiclist; - if (this.session_data.hasCap("client-can-do-rmf")) { + if (this.session_data.capabilities.get("client-can-do-rmf")) { // use rmf list musiclist = this.musiclist_rmf; } else { @@ -1343,7 +1343,7 @@ class WTVBGMusic { getCategorySongList(category) { let musiclist; - if (this.session_data.hasCap("client-can-do-rmf")) { + if (this.session_data.capabilities.get("client-can-do-rmf")) { // use rmf list musiclist = this.musiclist_rmf; } else { diff --git a/zefie_wtvp_minisrv/includes/classes/WTVGuide.js b/zefie_wtvp_minisrv/includes/classes/WTVGuide.js index 6d0f0bde..3c737625 100644 --- a/zefie_wtvp_minisrv/includes/classes/WTVGuide.js +++ b/zefie_wtvp_minisrv/includes/classes/WTVGuide.js @@ -101,20 +101,20 @@ class WTVGuide { const romtype = this.session_data.get("wtv-client-rom-type"); let boxname = ""; if (romtype == "US-WEBSTAR-disk-0MB-16MB-softmodem-CPU5230" || romtype == "US-DTV-disk-0MB-32MB-softmodem-CPU5230") boxname = "satellite receiver" - else if (this.session_data.hasCap("client-has-tv-experience")) boxname = "WebTV Plus receiver"; + else if (this.session_data.capabilities.get("client-has-tv-experience")) boxname = "WebTV Plus receiver"; else boxname = "WebTV Internet terminal"; definition = definition.replace(/\/g, boxname); } // replaces with either "WebTV" or "WebTV Plus" depending on user box type while (definition.indexOf("") >= 0) { let boxname = "WebTV"; - if (this.session_data.hasCap("client-has-tv-experience")) boxname += " Plus"; + if (this.session_data.capabilities.get("client-has-tv-experience")) boxname += " Plus"; definition = definition.replace(/\/g, boxname); } // replaces with either "Home" or "Web Home" depending on user box type while (definition.indexOf("") >= 0) { let homename = "Home"; - if (this.session_data.hasCap("client-has-tv-experience")) homename = "Web " + homename; + if (this.session_data.capabilities.get("client-has-tv-experience")) homename = "Web " + homename; definition = definition.replace(/\/g, homename); } template_args = { @@ -127,7 +127,7 @@ class WTVGuide { // glossary letter word index template =this.wtvshared.getTemplate("wtv-guide", "templates/glossary_word_index.js", true); let isPlusBox = false; - if (this.session_data.hasCap("client-has-tv-experience")) isPlusBox = true; + if (this.session_data.capabilities.get("client-has-tv-experience")) isPlusBox = true; const worddb = []; Object.keys(glossary[subtopic.toUpperCase()]).forEach(function (k) { if (glossary[subtopic.toUpperCase()][k].plusonly && !isPlusBox) return; diff --git a/zefie_wtvp_minisrv/test.js b/zefie_wtvp_minisrv/test.js index 60d4ada6..6a7813e2 100644 --- a/zefie_wtvp_minisrv/test.js +++ b/zefie_wtvp_minisrv/test.js @@ -183,6 +183,15 @@ function checkScopeErrors(file) { { "selector": "CallExpression[callee.type='MemberExpression'][callee.object.name='crypto'][callee.property.name='Credentials']", "message": "crypto.Credentials is deprecated. Use tls.SecureContext instead." + }, + // Custom project-specific deprecations + { + "selector": "CallExpression[callee.type='MemberExpression'][callee.object.name='session_data'][callee.property.name='hasCap']", + "message": "session_data.hasCap() is deprecated. Use session_data.capabilities.get() instead." + }, + { + "selector": "CallExpression[callee.type='MemberExpression'][callee.object.type='MemberExpression'][callee.object.property.name='session_data'][callee.property.name='hasCap']", + "message": "session_data.hasCap() is deprecated. Use session_data.capabilities.get() instead." } ] }