sliccy 1.46.0 → 1.47.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,2 +1,43 @@
1
1
  import{t as e}from"./logger-B-No_qN_.js";var t=[`/workspace`,`/shared`];async function n(e){let n=[],i=new Set;for(let a of t)await e.exists(a)&&await r(e,a,n,i);return n}async function r(e,t,n,r){for await(let o of e.walk(t)){if(!o.endsWith(`.bsh`)||r.has(o))continue;r.add(o);let t=i(o);if(!t)continue;let s=await e.readFile(o,{encoding:`utf-8`}),c=a(typeof s==`string`?s:new TextDecoder().decode(s));n.push({path:o,hostnamePattern:t,matchPatterns:c})}}function i(e){let t=e.split(`/`).pop()??``;if(!t.endsWith(`.bsh`))return null;let n=t.slice(0,-4);return n?n.startsWith(`-.`)?`*`+n.slice(1):n:null}function a(e){let t=e.split(`
2
- `).slice(0,10),n=[];for(let e of t){let t=e.match(/^\s*\/\/\s*@match\s+(.+)$/);t&&n.push(t[1].trim())}return n}function o(e,t){if(t.startsWith(`*.`)){let n=t.slice(1);return e===t.slice(2)||e.endsWith(n)&&e.length>n.length}return e===t}function s(e,t){try{let n=new URL(e),r=t.match(/^(\*|https?):\/\/([^/]+)(\/.*)?$/);if(!r)return!1;let[,i,a,s]=r;return i!==`*`&&n.protocol.slice(0,-1)!==i||!o(n.hostname,a)?!1:s?c(n.pathname+n.search,s):!0}catch{return!1}}function c(e,t){let n=`^`+t.replace(/[.+^${}()|[\]\\]/g,`\\$&`).replace(/\*/g,`.*`)+`$`;return new RegExp(n).test(e)}function l(e,t){try{let n=new URL(t);return e.filter(e=>o(n.hostname,e.hostnamePattern)?e.matchPatterns.length>0?e.matchPatterns.some(e=>s(t,e)):!0:!1)}catch{return[]}}var u=e(`bsh-watchdog`),d=class{transport;browserAPI;fs;discoveryIntervalMs;entries=[];discoveryTimer=null;running=!1;executing=new Set;constructor(e){if(!e.transport&&!e.browserAPI)throw Error(`BshWatchdog requires either transport or browserAPI`);this.browserAPI=e.browserAPI,this.transport=e.transport??e.browserAPI.getTransport(),this.fs=e.fs,this.discoveryIntervalMs=e.discoveryIntervalMs??1e4}async start(){this.running||(this.running=!0,await this.discover(),this.discoveryTimer=setInterval(()=>{this.discover()},this.discoveryIntervalMs),this.transport.on(`Page.frameNavigated`,this.onFrameNavigated),this.browserAPI&&this.browserAPI.setSessionChangeCallback((e,t)=>{t!==this.transport&&this.setTransport(t)}),u.info(`BSH watchdog started`,{scriptCount:this.entries.length}))}stop(){this.running&&(this.running=!1,this.transport.off(`Page.frameNavigated`,this.onFrameNavigated),this.discoveryTimer&&=(clearInterval(this.discoveryTimer),null),this.browserAPI&&this.browserAPI.setSessionChangeCallback(void 0),this.entries=[],this.executing.clear(),u.info(`BSH watchdog stopped`))}setTransport(e){e!==this.transport&&(this.transport.off(`Page.frameNavigated`,this.onFrameNavigated),this.transport=e,this.running&&this.transport.on(`Page.frameNavigated`,this.onFrameNavigated),u.info(`BSH watchdog transport swapped`))}async discover(){try{this.entries=await n(this.fs),u.debug(`BSH discovery complete`,{count:this.entries.length})}catch(e){u.error(`BSH discovery failed`,{error:e instanceof Error?e.message:String(e)})}}getEntries(){return this.entries}onFrameNavigated=e=>{let t=e.frame;if(t?.parentId||!t?.url)return;let n=t.url,r=e.sessionId;if(!n.startsWith(`http://`)&&!n.startsWith(`https://`))return;if(!r){u.warn(`BSH watchdog: no sessionId in Page.frameNavigated params, skipping`,{url:n});return}if(this.entries.length===0)return;let i=l(this.entries,n);if(i.length!==0)for(let e of i){let t=`${e.path}::${n}`;this.executing.has(t)||(this.executing.add(t),u.info(`BSH watchdog executing script`,{script:e.path,url:n}),this.executeInTargetPage(e.path,n,r).then(()=>{u.info(`BSH script completed`,{script:e.path,url:n})}).catch(t=>{u.error(`BSH script execution error`,{script:e.path,url:n,error:t instanceof Error?t.message:String(t)})}).finally(()=>{this.executing.delete(t)}))}};async executeInTargetPage(e,t,n){let r=await this.fs.readFile(e),i=`(async () => { try {\n${typeof r==`string`?r:new TextDecoder().decode(r)}\n} catch(e) { console.error('[bsh]', e); } })()`;await this.transport.send(`Runtime.enable`,{},n);let a=(await this.transport.send(`Runtime.evaluate`,{expression:i,awaitPromise:!0,returnByValue:!0},n)).exceptionDetails;if(a){let n=a.exception?.description??a.text;u.warn(`BSH script evaluation error`,{script:e,url:t,error:n})}}};export{d as BshWatchdog};
2
+ `).slice(0,10),n=[];for(let e of t){let t=e.match(/^\s*\/\/\s*@match\s+(.+)$/);t&&n.push(t[1].trim())}return n}function o(e,t){if(t.startsWith(`*.`)){let n=t.slice(1);return e===t.slice(2)||e.endsWith(n)&&e.length>n.length}return e===t}function s(e,t){try{let n=new URL(e),r=t.match(/^(\*|https?):\/\/([^/]+)(\/.*)?$/);if(!r)return!1;let[,i,a,s]=r;return i!==`*`&&n.protocol.slice(0,-1)!==i||!o(n.hostname,a)?!1:s?c(n.pathname+n.search,s):!0}catch{return!1}}function c(e,t){let n=`^`+t.replace(/[.+^${}()|[\]\\]/g,`\\$&`).replace(/\*/g,`.*`)+`$`;return new RegExp(n).test(e)}function l(e,t){try{let n=new URL(t);return e.filter(e=>o(n.hostname,e.hostnamePattern)?e.matchPatterns.length>0?e.matchPatterns.some(e=>s(t,e)):!0:!1)}catch{return[]}}var u=e(`bsh-watchdog`),d=class{transport;browserAPI;fs;discoveryIntervalMs;entries=[];discoveryTimer=null;running=!1;executing=new Set;constructor(e){if(!e.transport&&!e.browserAPI)throw Error(`BshWatchdog requires either transport or browserAPI`);this.browserAPI=e.browserAPI,this.transport=e.transport??e.browserAPI.getTransport(),this.fs=e.fs,this.discoveryIntervalMs=e.discoveryIntervalMs??1e4}async start(){this.running||(this.running=!0,await this.discover(),this.discoveryTimer=setInterval(()=>{this.discover()},this.discoveryIntervalMs),this.transport.on(`Page.frameNavigated`,this.onFrameNavigated),this.browserAPI&&this.browserAPI.setSessionChangeCallback((e,t)=>{t!==this.transport&&this.setTransport(t)}),u.info(`BSH watchdog started`,{scriptCount:this.entries.length}))}stop(){this.running&&(this.running=!1,this.transport.off(`Page.frameNavigated`,this.onFrameNavigated),this.discoveryTimer&&=(clearInterval(this.discoveryTimer),null),this.browserAPI&&this.browserAPI.setSessionChangeCallback(void 0),this.entries=[],this.executing.clear(),u.info(`BSH watchdog stopped`))}setTransport(e){e!==this.transport&&(this.transport.off(`Page.frameNavigated`,this.onFrameNavigated),this.transport=e,this.running&&this.transport.on(`Page.frameNavigated`,this.onFrameNavigated),u.info(`BSH watchdog transport swapped`))}async discover(){try{this.entries=await n(this.fs),u.debug(`BSH discovery complete`,{count:this.entries.length})}catch(e){u.error(`BSH discovery failed`,{error:e instanceof Error?e.message:String(e)})}}getEntries(){return this.entries}onFrameNavigated=e=>{let t=e.frame;if(t?.parentId||!t?.url)return;let n=t.url,r=e.sessionId;if(!n.startsWith(`http://`)&&!n.startsWith(`https://`))return;if(!r){u.warn(`BSH watchdog: no sessionId in Page.frameNavigated params, skipping`,{url:n});return}if(this.entries.length===0)return;let i=l(this.entries,n);if(i.length!==0)for(let e of i){let t=`${e.path}::${n}`;this.executing.has(t)||(this.executing.add(t),u.info(`BSH watchdog executing script`,{script:e.path,url:n}),this.executeInTargetPage(e.path,n,r).then(()=>{u.info(`BSH script completed`,{script:e.path,url:n})}).catch(t=>{u.error(`BSH script execution error`,{script:e.path,url:n,error:t instanceof Error?t.message:String(t)})}).finally(()=>{this.executing.delete(t)}))}};async executeInTargetPage(e,t,n){let r=await this.fs.readFile(e),i=typeof r==`string`?r:new TextDecoder().decode(r),a=`(async () => {
3
+ const __requireSpecifiers = (function() {
4
+ const re = /require\\s*\\(\\s*['"]([^'"]+)['"]\\s*\\)/g;
5
+ const code = ${JSON.stringify(i)};
6
+ const specs = [];
7
+ let m;
8
+ while ((m = re.exec(code)) !== null) specs.push(m[1]);
9
+ return [...new Set(specs)];
10
+ })();
11
+ const __NODE_BUILTINS_UNAVAILABLE = new Set([
12
+ 'http', 'https', 'net', 'tls', 'dgram', 'dns', 'cluster',
13
+ 'worker_threads', 'child_process', 'crypto', 'os', 'stream',
14
+ 'zlib', 'vm', 'v8', 'perf_hooks', 'readline', 'repl', 'tty', 'inspector',
15
+ 'fs'
16
+ ]);
17
+ const __requireCache = Object.create(null);
18
+ const __uncached = __requireSpecifiers.filter(id => {
19
+ const bare = id.startsWith('node:') ? id.slice(5) : id;
20
+ return !__NODE_BUILTINS_UNAVAILABLE.has(bare) && bare !== 'buffer';
21
+ });
22
+ await Promise.allSettled(__uncached.map(async (id) => {
23
+ try {
24
+ const mod = await import('https://esm.sh/' + id);
25
+ __requireCache[id] = mod.default !== undefined ? mod.default : mod;
26
+ } catch(e) { /* will throw at require() call time */ }
27
+ }));
28
+ const require = (id) => {
29
+ const bareId = id.startsWith('node:') ? id.slice(5) : id;
30
+ if (bareId === 'buffer' && typeof Buffer !== 'undefined') return { Buffer };
31
+ if (__NODE_BUILTINS_UNAVAILABLE.has(bareId)) {
32
+ const __suggestions = { http: ' Use fetch() instead.', https: ' Use fetch() instead.', crypto: ' Use globalThis.crypto (Web Crypto API) instead.' };
33
+ const __hint = __suggestions[bareId] || '';
34
+ throw new Error("require('" + id + "'): Node built-in '" + bareId + "' is not available in the browser environment." + __hint);
35
+ }
36
+ if (bareId in __requireCache) return __requireCache[bareId];
37
+ if (id in __requireCache) return __requireCache[id];
38
+ throw new Error("require('" + id + "'): module not pre-loaded. Use a string literal or await import('https://esm.sh/" + id + "') directly.");
39
+ };
40
+ try {
41
+ ${i}
42
+ } catch(e) { console.error('[bsh]', e); }
43
+ })()`;await this.transport.send(`Runtime.enable`,{},n);let o=(await this.transport.send(`Runtime.evaluate`,{expression:a,awaitPromise:!0,returnByValue:!0},n)).exceptionDetails;if(o){let n=o.exception?.description??o.text;u.warn(`BSH script evaluation error`,{script:e,url:t,error:n})}}};export{d as BshWatchdog};