Add depreciation warning system, begin depreciation of session_data.hasCap()

This commit is contained in:
zefie
2025-08-13 00:45:04 -04:00
parent f87f4c2eb6
commit 005bd377a2
12 changed files with 83 additions and 16 deletions

View File

@@ -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.

View File

@@ -57,7 +57,7 @@ To write an e-mail message, follow these steps:
<spacer type=vertical height=20>
First, if you're not already in Mail, choose <b>Mail</b> 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 <b>Mail</b> key on your keyboard.
<td width=10>
<td width=267 valign=top>
<table align=right cellpadding=0 cellspacing=0 background="`;
if (session_data.hasCap("client-has-tv-experience"))
if (session_data.capabilities.get("client-has-tv-experience"))
data += "wtv-guide:/images/home-plus.jpg"
else
data += "wtv-guide:/images/home-classic.jpg"

View File

@@ -65,7 +65,7 @@ Here's an example of an e-mail address:
<td width=10>
<td width=267 valign=top>
<table align=right cellpadding=0 cellspacing=0 background="`;
if (session_data.hasCap("client-has-tv-experience"))
if (session_data.capabilities.get("client-has-tv-experience"))
data += "wtv-guide:/images/help/mail/sendmail-plus.jpg"
else
data += "wtv-guide:/images/help/mail/sendmail-classic.jpg"

View File

@@ -64,7 +64,7 @@ mailbox, they'll see it first.
<td width=10>
<td width=267 valign=top>
<table align=right cellpadding=0 cellspacing=0 background="`;
if (session_data.hasCap("client-has-tv-experience"))
if (session_data.capabilities.get("client-has-tv-experience"))
data += "wtv-guide:/images/help/mail/sendmail-plus.jpg"
else
data += "wtv-guide:/images/help/mail/sendmail-classic.jpg"

View File

@@ -61,7 +61,7 @@ type in the message itself.
<td width=10>
<td width=267 valign=top>
<table align=right cellpadding=0 cellspacing=0 background="`;
if (session_data.hasCap("client-has-tv-experience"))
if (session_data.capabilities.get("client-has-tv-experience"))
data += "wtv-guide:/images/help/mail/sendmail-plus.jpg"
else
data += "wtv-guide:/images/help/mail/sendmail-classic.jpg"

View File

@@ -61,7 +61,7 @@ message will be sent.
<td width=10>
<td width=267 valign=top>
<table align=right cellpadding=0 cellspacing=0 background="`;
if (session_data.hasCap("client-has-tv-experience"))
if (session_data.capabilities.get("client-has-tv-experience"))
data += "wtv-guide:/images/help/mail/sendmail-plus.jpg"
else
data += "wtv-guide:/images/help/mail/sendmail-classic.jpg"

View File

@@ -361,7 +361,7 @@ document.theForm.submit();
</SCRIPT>
<input type=file device=video name=photoBlockPhoto src="cache:snapshot.jpg" invisible disabled=true>
`
if (session_data.hasCap("client-can-do-av-capture")) {
if (session_data.capabilities.get("client-can-do-av-capture")) {
data += `<tr>
<td height=32>
<img src=wtv-author:/ROMCache/pointer.gif align=absmiddle width=13 height=22 hspace=0>

View File

@@ -413,7 +413,7 @@ document.theForm.submit();
</SCRIPT>
<input type=file device=video name=photoBlockPhoto src="cache:snapshot.jpg" invisible disabled=true>
`
if (session_data.hasCap("client-can-do-av-capture")) {
if (session_data.capabilities.get("client-can-do-av-capture")) {
data += `<tr>
<td height=32>
<img src=wtv-author:/ROMCache/pointer.gif align=absmiddle width=13 height=22 hspace=0>

View File

@@ -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

View File

@@ -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 {

View File

@@ -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(/\<boxname\>/g, boxname);
}
// replaces <boxname_plus> with either "WebTV" or "WebTV Plus" depending on user box type
while (definition.indexOf("<boxname_plus>") >= 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(/\<boxname\_plus\>/g, boxname);
}
// replaces <webhome> with either "Home" or "Web Home" depending on user box type
while (definition.indexOf("<webhome>") >= 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(/\<webhome\>/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;

View File

@@ -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."
}
]
}