feat(script): add warning if trying to render an unavailable protected server-side note (closes #21)

This commit is contained in:
Elian Doran
2026-04-11 11:17:58 +03:00
parent 1121ee0133
commit fb33921308

View File

@@ -21,7 +21,11 @@ export interface Bundle {
type ScriptParams = any[];
function executeNote(note: BNote, apiParams: ApiParams) {
if (!note.isJavaScript() || note.getScriptEnv() !== "backend" || !note.isContentAvailable()) {
if (!note.isContentAvailable()) {
throw new Error(`Cannot execute script note '${note.noteId}' because it is protected and protected session is not available. Enter protected session and try again.`);
}
if (!note.isJavaScript() || note.getScriptEnv() !== "backend") {
log.info(`Cannot execute note ${note.noteId} "${note.title}", note must be of type "Code: JS backend"`);
// Warn the user if they're trying to run a frontend script in the backend
@@ -171,7 +175,7 @@ function getScriptBundleForFrontend(note: BNote, script?: string, params?: Scrip
export function getScriptBundle(note: BNote, root: boolean = true, scriptEnv: string | null = null, includedNoteIds: string[] = [], overrideContent: string | null = null): Bundle | undefined {
if (!note.isContentAvailable()) {
return;
throw new Error(`Cannot execute script note '${note.noteId}' because it is protected and protected session is not available. Enter protected session and try again.`);
}
if (!(note.isJavaScript() || note.isHtml() || note.isJsx())) {