@sinch/cli 0.1.15-beta.0-dev.2172714504 → 0.1.15-beta.0-dev.2177695159
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.
- package/dist/index.js +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -45,7 +45,7 @@ ${e}`))}list(e,n={}){let{indent:i=" ",bullet:s="\u2022"}=n;e.forEach(r=>{consol
|
|
|
45
45
|
`);for(let h of g){let w=h.match(/^([^=]+)\s*=\s*(.+)$/);if(w&&w[1]&&w[2]&&w[1].trim()===r){l=w[2].trim(),c=!0,t.debug(`Found ${r} in dotnet user-secrets`);break}}}catch{}!l&&n&&(r==="PROJECT_ID"&&n.projectId?l=n.projectId:r==="PROJECT_ID_API_KEY"&&n.keyId?l=n.keyId:r==="PROJECT_ID_API_SECRET"&&n.keySecret?(l=n.keySecret,c=!0):r==="VOICE_APPLICATION_KEY"&&n.applicationKey?l=n.applicationKey:r==="VOICE_APPLICATION_SECRET"&&n.applicationSecret&&(l=n.applicationSecret,c=!0)),l&&(e[r]={Value:l,Secret:c})}else e[r]={Value:String(a),Secret:!1}}}catch(s){t.debug("Could not read appsettings.json: "+s.message)}}else{let i=me.default.join(process.cwd(),".env");if(await ee.default.pathExists(i))try{let s=await ee.default.readFile(i,"utf8"),r={};s.split(`
|
|
46
46
|
`).forEach(a=>{if(a.trim()&&!a.trim().startsWith("#")){let[l,...c]=a.split("=");l&&(r[l.trim()]=c.join("=").trim())}});for(let[a,l]of Object.entries(r))if(l===""||l===null||l===void 0){let c="",u=!1;n&&(a==="PROJECT_ID"&&n.projectId?c=n.projectId:a==="PROJECT_ID_API_KEY"&&n.keyId?c=n.keyId:a==="PROJECT_ID_API_SECRET"&&n.keySecret?(c=n.keySecret,u=!0):a==="VOICE_APPLICATION_KEY"&&n.applicationKey?c=n.applicationKey:a==="VOICE_APPLICATION_SECRET"&&n.applicationSecret&&(c=n.applicationSecret,u=!0)),c&&(e[a]={Value:c,Secret:u})}else e[a]={Value:l,Secret:!1}}catch(s){t.debug("Could not read .env file: "+s.message)}}return e}async function fo(o,e){let i=Date.now(),s=!1,r;return t.newline(),d.start("\u23F3 Connecting to deployment stream..."),new Promise((a,l)=>{let c,u;o.streamDeployment(e,g=>{let h=Math.floor((Date.now()-i)/1e3);switch(g.type){case"connected":d.text="\u23F3 Deployment stream connected, waiting for updates...";break;case"status":let w=g.data.data.message;d.text=`\u23F3 ${w} (${h}s)`;break;case"progress":let C=g.data.data.message,D=g.data.data.percentComplete;D?d.text=`\u23F3 ${C} (${D}%, ${h}s)`:d.text=`\u23F3 ${C} (${h}s)`;break;case"completed":s=!0,r=g.data.data.url,d.succeed("\u2705 Function deployed successfully"),o.getFunction(e).then(async $=>{if(t.newline(),t.info("\u{1F389} Deployment Complete!"),t.info(` Function: ${v.default.cyan($.name)}`),t.info(` Status: ${lt("Running")}`),t.info(` URL: ${v.default.blue(r)}`),r){t.newline(),t.info("\u{1F4DE} Voice Integration:");try{d.start("Updating Sinch Voice callback URL..."),await st(r),d.succeed("Voice callback URL updated automatically"),t.info(` Callback URL set to: ${v.default.cyan(r)}`)}catch(S){d.fail("Failed to update callback URL automatically"),t.warn(` Error: ${S.message}`),t.info(` Manual setup: ${v.default.cyan(`sinch voice callback-url ${r}`)}`)}t.info(` Test function: ${v.default.cyan(`curl ${r}`)}`)}t.newline(),t.info("\u{1F4A1} Next steps:"),t.info(` \u2022 View logs: ${v.default.cyan(`sinch functions logs ${e} --follow`)}`),t.info(` \u2022 Check status: ${v.default.cyan(`sinch functions status ${e}`)}`),c&&c(),u&&clearTimeout(u),a()}).catch($=>{t.error(`Failed to get function details: ${$.message}`),c&&c(),u&&clearTimeout(u),a()});break;case"failed":s=!0;let q=g.data.data.errorMessage;d.fail("\u274C Deployment failed"),t.newline(),t.error("Deployment failed:"),q&&t.error(` ${q}`),t.newline(),t.info("\u{1F4A1} Troubleshooting:"),t.info(` \u2022 Check logs: ${v.default.cyan(`sinch functions logs ${e}`)}`),t.info(` \u2022 Check status: ${v.default.cyan(`sinch functions status ${e}`)}`),c&&c(),u&&clearTimeout(u),process.exit(1);break}},g=>{t.debug("SSE stream error, falling back to polling:",g),d.text="\u23F3 Deployment stream unavailable, checking status...",c&&c(),Jt(o,e,i,3e5).then(a).catch(l)}).then(g=>{t.debug("SSE stream setup successful, cleanup function received"),c=g,u=setTimeout(()=>{s||(d.fail("\u23F0 Deployment timeout"),t.newline(),t.warn("Deployment is taking longer than expected"),t.info("\u{1F4A1} Check deployment progress with:"),t.info(` ${v.default.cyan(`sinch functions status ${e}`)}`),c&&c(),a())},3e5)}).catch(g=>{t.debug(`Failed to set up SSE stream, falling back to polling: ${g.message}`),Jt(o,e,i,3e5).then(a).catch(l)})})}async function Jt(o,e,n,i){for(;Date.now()-n<i;){try{let a=(await o.getFunctionStatus(e)).function;if(a.status==="Running"){if(d.succeed("\u2705 Function deployed successfully"),t.newline(),t.info("\u{1F389} Deployment Complete!"),t.info(` Function: ${v.default.cyan(a.name)}`),t.info(` Status: ${lt(a.status)}`),t.info(` URL: ${v.default.blue(a.containerAppUrl)}`),a.containerAppUrl){t.newline(),t.info("\u{1F4DE} Voice Integration:");try{d.start("Updating Sinch Voice callback URL..."),await st(a.containerAppUrl),d.succeed("Voice callback URL updated automatically"),t.info(` Callback URL set to: ${v.default.cyan(a.containerAppUrl)}`)}catch(c){d.fail("Failed to update callback URL automatically"),t.warn(` Error: ${c.message}`),t.info(` Manual setup: ${v.default.cyan(`sinch voice callback-url ${a.containerAppUrl}`)}`)}t.info(` Test function: ${v.default.cyan(`curl ${a.containerAppUrl}`)}`)}t.newline(),t.info("\u{1F4A1} Next steps:"),t.info(` \u2022 View logs: ${v.default.cyan(`sinch functions logs ${e} --follow`)}`),t.info(` \u2022 Check status: ${v.default.cyan(`sinch functions status ${e}`)}`);return}a.status==="Failed"&&(d.fail("\u274C Deployment failed"),t.newline(),t.error("Deployment failed:"),a.errorMessage&&t.error(` ${a.errorMessage}`),t.newline(),t.info("\u{1F4A1} Troubleshooting:"),t.info(` \u2022 Check logs: ${v.default.cyan(`sinch functions logs ${e}`)}`),t.info(` \u2022 Check status: ${v.default.cyan(`sinch functions status ${e}`)}`),process.exit(1));let l=Math.floor((Date.now()-n)/1e3);d.text=`\u23F3 Deploying function... (${a.status}, ${l}s)`}catch(r){t.debug(`Status check failed: ${r.message}`)}await new Promise(r=>setTimeout(r,3e3))}d.fail("\u23F0 Deployment timeout"),t.newline(),t.warn("Deployment is taking longer than expected"),t.info("\u{1F4A1} Check deployment progress with:"),t.info(` ${v.default.cyan(`sinch functions status ${e}`)}`)}function lt(o){return{Running:v.default.green("\u2705 Running"),Failed:v.default.red("\u274C Failed"),Pending:v.default.yellow("\u23F3 Pending"),Building:v.default.blue("\u{1F528} Building")}[o]||v.default.gray(o)}async function go(o,e){let n=!1;if(e.docs===!1){t.info("Skipping documentation generation (--no-docs flag)");return}if(e.nonInteractive)t.info("Generating documentation (non-interactive mode)"),n=!0;else{if(o.docsPreference==="never")return;if(mo(o))n=!0;else{let i=await Gt.default.prompt([{type:"list",name:"docsChoice",message:"Generate/update documentation before deployment?",choices:[{name:"Yes - Generate documentation this time",value:"yes"},{name:"No - Skip documentation this time",value:"no"},{name:"Always - Generate documentation and remember preference",value:"always"},{name:"Never - Don't generate documentation and remember preference",value:"never"}],default:"yes"}]);i.docsChoice==="yes"?n=!0:i.docsChoice==="no"?n=!1:i.docsChoice==="always"?(n=!0,f.set("docsPreference","always",!0),await f.saveProjectConfig()):i.docsChoice==="never"&&(n=!1,f.set("docsPreference","never",!0),await f.saveProjectConfig())}}if(n)try{d.start("\u{1F4DD} Generating documentation...");let{generateDocsFromLocal:i,saveDocumentationToFile:s}=(ct(),T(Vt)),r=await i(),a=me.default.basename(process.cwd());await s(r,"README.md",a),d.succeed("\u{1F4DD} Documentation updated in README.md")}catch(i){d.warn(`\u26A0\uFE0F Failed to generate documentation: ${i.message}`),t.warn("Continuing with deployment...")}}function mo(o){return o.docsPreference==="always"}Qt.exports=zt});var sn=x((Yi,on)=>{"use strict";var A=m(require("fs-extra")),G=m(require("path")),Fe=m(require("chalk")),ut=require("child_process"),Xt=m(require("chokidar")),en=require("commander"),tn=m(require("inquirer"));R();U();F();var nn=new en.Command("dev");nn.description("Start local development server").option("-p, --port <port>","Port to run on","3000").option("--no-watch","Disable file watching").option("-d, --debug","Enable debugging with --inspect").option("--tunnel","Force tunnel creation").option("--no-tunnel",'Disable tunnel and reset "always" preference').action(async o=>{try{if(await f.load(),!f.isInProject())throw new Error('Not in a Sinch Functions project directory. Run "sinch functions init" first.');let e=f.getProjectConfig();if(!e)throw new Error("No project configuration found");if((e.runtime||"node")==="csharp"){if((await A.default.readdir(process.cwd()).then(s=>s.filter(r=>r.endsWith(".csproj")))).length===0)throw new Error("No .csproj file found. Make sure you're in a valid C# function directory.")}else{let i=G.default.join(process.cwd(),"host.js");if(!await A.default.pathExists(i))throw new Error("host.js not found. Make sure you're in a valid Node.js function directory.")}t.title(`Starting ${e.name} (${e.runtime})`),t.info(`Port: ${o.port}`),t.info(`Watch: ${o.watch?"enabled":"disabled"}`),o.debug&&t.info("Debug: enabled on port 9229"),t.newline(),await yo(o,e)}catch(e){d.stop(),t.error(`Failed to start development server: ${e.message}`),process.exit(1)}});async function ho(o,e){if(e==="node"){let n=G.default.join(process.cwd(),".env");if(await A.default.pathExists(n)){let i=await A.default.readFile(n,"utf-8"),s=`SINCH_TUNNEL=${o}`;i.includes("SINCH_TUNNEL=")?i=i.replace(/SINCH_TUNNEL=(true|false)/g,s):i+=`
|
|
47
47
|
${s}
|
|
48
|
-
`,await A.default.writeFile(n,i,"utf-8"),t.debug(`Updated .env: SINCH_TUNNEL=${o}`)}}else if(e==="csharp"){let n=G.default.join(process.cwd(),"appsettings.Development.json");if(await A.default.pathExists(n)){let i=await A.default.readJson(n);i.SinchTunnel=o,await A.default.writeJson(n,i,{spaces:2}),t.debug(`Updated appsettings.Development.json: SinchTunnel=${o}`)}}}async function yo(o,e){let n=e.runtime||"node",i=!1;if(o.tunnel===!0)i=!0;else if(o.tunnel===!1)i=!1,e.tunnel?.preference==="always"&&(f.set("tunnel",{...e.tunnel,preference:"no"},!0),await f.saveProjectConfig());else if(e.tunnel?.preference==="never")i=!1;else if(vo(e))i=!0;else{let{tunnelChoice:c}=await tn.default.prompt([{type:"list",name:"tunnelChoice",message:"Enable Sinch tunnel for external access?",choices:[{name:"Yes - Enable tunnel this time",value:"yes"},{name:"No - Local only this time",value:"no"},{name:"Always - Enable tunnel and remember preference",value:"always"},{name:"Never - Don't enable tunnel and remember preference",value:"never"}],default:"no"}]);c==="yes"?i=!0:c==="no"?i=!1:c==="always"?(i=!0,f.set("tunnel",{...e.tunnel,preference:"always"},!0),await f.saveProjectConfig()):c==="never"&&(i=!1,f.set("tunnel",{...e.tunnel,preference:"never"},!0),await f.saveProjectConfig())}await ho(i,n);let s={...process.env,PORT:o.port,NODE_ENV:"development",SINCH_FUNCTIONS_LOCAL:"true",SINCH_TUNNEL:i?"true":"false"};e.variables&&Object.entries(e.variables).forEach(([c,u])=>{s[c]=u});try{let c=await f.getApplicationCredentials(e.voiceAppKey);c?(s.SINCH_APPLICATION_KEY=c.applicationKey,s.SINCH_APPLICATION_SECRET=c.applicationSecret,t.debug("\u2705 Injected application credentials for voice operations")):t.debug("\u26A0\uFE0F No application credentials found - voice features may not work")}catch(c){t.debug(`\u26A0\uFE0F Could not load application credentials: ${c.message}`)}t.info("\u{1F680} Starting local server...");let r=null,a=!1;function l(){if(r&&r.kill(),n==="csharp"){let c=["run"];o.port&&c.push("--urls",`http://localhost:${o.port}`),o.debug&&(s.ASPNETCORE_ENVIRONMENT="Development",s.ASPNETCORE_URLS=`http://localhost:${o.port}`),r=(0,ut.spawn)("dotnet",c,{env:s,stdio:"inherit",cwd:process.cwd()})}else{let c=G.default.join(process.cwd(),"host.js"),u=[];o.debug&&u.push("--inspect=9229"),u.push(c),r=(0,ut.spawn)("node",u,{env:s,stdio:"inherit",cwd:process.cwd()})}r.on("spawn",async()=>{a||(a=!0,t.newline(),t.success(`\u2705 Server running on http://localhost:${o.port}`),o.debug&&(t.newline(),n==="csharp"?$o():Co()),t.newline(),t.info("\u{1F4A1} Development commands:"),t.info(` \u2022 Test function: ${Fe.default.cyan(`curl http://localhost:${o.port}`)}`),t.info(` \u2022 View in browser: ${Fe.default.cyan(`http://localhost:${o.port}`)}`),t.info(` \u2022 Stop server: ${Fe.default.gray("Ctrl+C")}`),o.watch&&t.info(` \u2022 File watching: ${Fe.default.green("enabled")}`))}),r.on("error",c=>{t.error(`Server error: ${c.message}`)}),r.on("exit",(c,u)=>{u!=="SIGTERM"&&u!=="SIGKILL"&&t.error(`Server exited with code ${c}`)})}l(),o.watch&&wo(()=>{t.info("\u{1F4DD} Files changed, restarting server..."),l()},n),process.on("SIGINT",()=>{t.newline(),t.info("\u{1F534} Stopping development server..."),r&&r.kill("SIGTERM"),process.exit(0)}),await new Promise(()=>{})}function wo(o,e="node"){let n=[".git/**",".DS_Store","*.tmp",".sinch-tmp/**"];e==="csharp"?n.push("bin/**","obj/**","*.user",".vs/**"):n.push("node_modules/**");let i=Xt.default.watch(".",{ignored:n,ignoreInitial:!0,awaitWriteFinish:{stabilityThreshold:100,pollInterval:10}});i.on("change",s=>{t.debug(`File changed: ${s}`),o()}),i.on("add",s=>{t.debug(`File added: ${s}`),o()}),i.on("unlink",s=>{t.debug(`File removed: ${s}`),o()})}async function Co(){try{let o=await Ee("code",".vscode"),e=await Ee("cursor",".cursor"),n=await Ee("webstorm",".idea");if(o||e){let i=o?"VS Code":"Cursor",s=".vscode";if(t.info(`\u{1F41B} ${i} detected! Debug setup:`),await So(s))t.info(" 1. \u2705 Created .vscode/launch.json for you");else{let a=G.default.join(process.cwd(),s,"launch.json");await A.default.pathExists(a)?t.info(" 1. \u2705 Found existing .vscode/launch.json"):t.info(" 1. \u26A0\uFE0F Could not create .vscode/launch.json")}t.info(" 2. \u{1F50D} Press F5 to attach debugger"),t.info(" 3. \u{1F534} Set breakpoints in your function.js"),t.info(" 4. \u{1F4DE} Test your function to hit breakpoints")}else n?(t.info("\u{1F41B} WebStorm detected! Debug setup:"),t.info(" 1. \u{1F50D} Run \u2192 Attach to Node.js/Chrome \u2192 localhost:9229"),t.info(" 2. \u{1F534} Set breakpoints in your function.js")):(t.info("\u{1F41B} Manual debug setup:"),t.info(' \u2022 VS Code/Cursor: Open "Run and Debug" \u2192 "Attach to Node.js Process"'),t.info(' \u2022 Chrome DevTools: Visit chrome://inspect \u2192 Click "inspect"'),t.info(" \u2022 Manual: Connect debugger to ws://localhost:9229"))}catch{t.info("\u{1F41B} Debug instructions:"),t.info(" \u2022 Connect your debugger to ws://localhost:9229"),t.info(" \u2022 Set breakpoints and test your function")}}async function Ee(o,e){try{if(o==="code"&&bo())return!0;let{spawn:n}=require("child_process"),i=await new Promise(r=>{let a=n(o,["--version"],{stdio:"pipe"});a.on("close",l=>r(l===0)),a.on("error",()=>r(!1))}),s=e?await A.default.pathExists(e):!1;return i||s}catch{return!1}}function bo(){return process.env.TERM_PROGRAM==="vscode"||!!process.env.VSCODE_IPC_HOOK||!!process.env.VSCODE_PID}async function So(o=".vscode"){try{let e=G.default.join(process.cwd(),o),n=G.default.join(e,"launch.json");if(await A.default.pathExists(n))return!1;await A.default.ensureDir(e);let i={version:"0.2.0",configurations:[{name:"Attach to Sinch Function",type:"node",request:"attach",port:9229,localRoot:"${workspaceFolder}",remoteRoot:"${workspaceFolder}",skipFiles:["<node_internals>/**","node_modules/**"]}]};return await A.default.writeJson(n,i,{spaces:2}),!!await A.default.pathExists(n)}catch{return!1}}function vo(o){return o.tunnel?o.tunnel.preference==="always":!1}async function $o(){try{let o=await Ee("code",".vscode"),e=await Ee("devenv"),n=await Ee("rider",".idea");o?(t.info("\u{1F41B} VS Code detected! Debug setup:"),await Po(".vscode")?t.info(" 1. \u2705 Created .vscode/launch.json for C#"):t.info(" 1. \u2705 Found existing .vscode/launch.json"),t.info(" 2. \u{1F50D} Press F5 to attach debugger"),t.info(" 3. \u{1F534} Set breakpoints in your Function.cs"),t.info(" 4. \u{1F4DE} Test your function to hit breakpoints")):e?(t.info("\u{1F41B} Visual Studio detected! Debug setup:"),t.info(" 1. \u{1F50D} Debug \u2192 Attach to Process \u2192 dotnet.exe"),t.info(" 2. \u{1F534} Set breakpoints in your Function.cs"),t.info(" 3. \u{1F4DE} Test your function to hit breakpoints")):n?(t.info("\u{1F41B} JetBrains Rider detected! Debug setup:"),t.info(" 1. \u{1F50D} Run \u2192 Attach to Process \u2192 dotnet"),t.info(" 2. \u{1F534} Set breakpoints in your Function.cs")):(t.info("\u{1F41B} C# Debug setup:"),t.info(" \u2022 Visual Studio: Debug \u2192 Attach to Process \u2192 dotnet.exe"),t.info(" \u2022 VS Code: Install C# extension, then F5 to debug"),t.info(" \u2022 Rider: Run \u2192 Attach to Process"))}catch{t.info("\u{1F41B} C# Debug instructions:"),t.info(" \u2022 Attach your debugger to the dotnet process"),t.info(" \u2022 Set breakpoints in Function.cs")}}async function Po(o=".vscode"){try{let e=G.default.join(process.cwd(),o),n=G.default.join(e,"launch.json");if(await A.default.pathExists(n))return!1;await A.default.ensureDir(e);let i={version:"0.2.0",configurations:[{name:".NET Core Launch (web)",type:"coreclr",request:"launch",preLaunchTask:"build",program:"${workspaceFolder}/bin/Debug/net8.0/Function.dll",args:[],cwd:"${workspaceFolder}",stopAtEntry:!1,serverReadyAction:{action:"openExternally",pattern:"\\bNow listening on:\\s+(https?://\\S+)"},env:{ASPNETCORE_ENVIRONMENT:"Development"},sourceFileMap:{"/Views":"${workspaceFolder}/Views"}},{name:".NET Core Attach",type:"coreclr",request:"attach"}]};await A.default.writeJson(n,i,{spaces:2});let s=G.default.join(e,"tasks.json");if(!await A.default.pathExists(s)){let r={version:"2.0.0",tasks:[{label:"build",command:"dotnet",type:"process",args:["build","${workspaceFolder}/Function.csproj","/property:GenerateFullPaths=true","/consoleloggerparameters:NoSummary"],problemMatcher:"$msCompile"}]};await A.default.writeJson(s,r,{spaces:2})}return await A.default.pathExists(n)}catch{return!1}}on.exports=nn});var un=x((es,ln)=>{"use strict";var K=m(require("chalk")),rn=require("commander");_();R();U();F();var an=new rn.Command("status");an.description("Show function status and details").argument("[function-id]","Function ID to check (optional if sinch.json exists)").option("-f, --follow","Watch status changes in real-time").option("--json","Output raw JSON").action(async(o,e)=>{try{await f.load();let n=new E(f.getApiConfig()),i=o;if(!i){if(!f.isInProject())throw new Error("Function ID required. Provide as argument or run from function directory with sinch.json");if(i=f.getProjectConfig()?.functionId,!i)throw new Error("No function ID found in sinch.json. Deploy the function first or provide function ID as argument.")}e.follow?await Eo(n,i):await ko(n,i,e)}catch(n){d.stop(),t.error(`Failed to get function status: ${n.message}`),process.exit(1)}});async function ko(o,e,n){d.start("\u{1F4E1} Loading function status...");try{let i=await o.getFunction(e),s=await o.getFunctionStatus(e);if(d.stop(),n.json){console.log(JSON.stringify({function:i,deployment:s},null,2));return}let r=i,a=s.status,l=s.error;t.newline(),t.title(`Function Status: ${r.name}`),t.newline(),t.info("\u{1F4CB} Function Details:"),t.info(` ID: ${K.default.gray(r.id)}`),t.info(` Name: ${K.default.cyan(r.name)}`),t.info(` Runtime: ${K.default.yellow(r.runtime)}`),t.info(` Deployment Status: ${cn(a)}`),r.created&&t.info(` Created: ${new Date(r.created).toLocaleString()}`),r.updated&&t.info(` Updated: ${new Date(r.updated).toLocaleString()}`),r.url&&t.info(` URL: ${K.default.blue(r.url)}`),a==="Failed"&&l&&(t.newline(),t.error("Deployment Error:"),t.error(` ${l}`)),t.newline(),t.info("\u{1F4A1} Commands:"),t.info(` \u2022 View logs: ${K.default.cyan(`sinch functions logs ${e}`)}`),t.info(` \u2022 Redeploy: ${K.default.cyan("sinch functions deploy")}`),t.info(` \u2022 Delete: ${K.default.cyan(`sinch functions delete ${e}`)}`)}catch(i){throw d.stop(),i}}async function Eo(o,e){t.info("\u{1F440} Watching deployment status (press Ctrl+C to stop)..."),t.newline();let n=null,i=setInterval(async()=>{try{let s=await o.getFunctionStatus(e),r=s.status;if(r!==n){let a=new Date().toLocaleTimeString();if(t.info(`[${a}] Status: ${cn(r)}`),n=r,r==="Running"){t.success("Function deployment is now running!");try{let l=await o.getFunction(e);l.url&&t.info(`URL: ${K.default.blue(l.url)}`)}catch{}}else r==="Failed"&&(t.error("Function deployment failed!"),s.error&&t.error(`Error: ${s.error}`),clearInterval(i))}}catch(s){t.error(`Error checking status: ${s.message}`)}},3e3);process.on("SIGINT",()=>{clearInterval(i),t.newline(),t.info("Stopped watching function status"),process.exit(0)})}function cn(o){return{Running:K.default.green("\u2705 Running"),Failed:K.default.red("\u274C Failed"),Pending:K.default.yellow("\u23F3 Pending"),Building:K.default.blue("\u{1F528} Building")}[o]||K.default.gray(o)}ln.exports=an});var Cn=x((ss,wn)=>{"use strict";var he=m(require("chalk")),fn=require("commander");_();R();U();F();var dt=require("child_process"),Oe=m(require("fs")),_e=m(require("os")),Le=m(require("path")),pt=new fn.Command("logs");pt.description("View function logs").argument("[function-id]","Function ID to get logs for (optional if sinch.json exists)").option("-f, --follow","Follow log output in real-time").option("-n, --lines <number>","Number of historical lines to show","50").option("--level <level>","Filter by log level (debug, info, warning, error)").option("--search <text>","Search for text in log messages").option("--since <duration>","Show logs since duration (e.g., 1h, 30m, 5s)").action(async(o,e)=>{try{await f.load();let n=new E(f.getApiConfig()),i=o;if(!i){if(!f.isInProject())throw new Error("Function ID required. Provide as argument or run from function directory with sinch.json");let r=f.getProjectConfig();if(!r)throw new Error("No project configuration found");if(i=r.functionId,!i)throw new Error("No function ID found in sinch.json. Deploy the function first or provide function ID as argument.")}d.start("Loading function details...");let s=await n.getFunction(i);d.stop(),t.info(`\u{1F4CB} Logs for function: ${he.default.cyan(s.name)} (${Ao(s.status)})`),t.newline(),e.follow?await gn(n,i,s.name,e):await No(n,i,e)}catch(n){d.stop(),t.error(`Failed to get logs: ${n.message}`),process.exit(1)}});pt.command("stream").description("Stream function logs in real-time").argument("[function-id]","Function ID to stream logs for (optional if sinch.json exists)").option("--level <level>","Filter by log level (debug, info, warning, error)").option("--search <text>","Search for text in log messages").action(async(o,e)=>{try{await f.load();let n=new E(f.getApiConfig()),i=o;if(!i){if(!f.isInProject())throw new Error("Function ID required. Provide as argument or run from function directory with sinch.json");let r=f.getProjectConfig();if(!r)throw new Error("No project configuration found");if(i=r.functionId,!i)throw new Error("No function ID found in sinch.json. Deploy the function first or provide function ID as argument.")}d.start("Connecting to log stream...");let s=await Io(n,i);d.stop(),await gn(n,i,s.name,{...e,follow:!0})}catch(n){d.stop(),t.error(`Failed to stream logs: ${n.message}`),process.exit(1)}});async function Io(o,e){return await o.getFunction(e)}async function gn(o,e,n,i){let s=o.baseUrl.replace(/\/+$/,""),r=o.projectId,a=`${s}/v1/projects/${r}/functions/${e}/logs/stream`,l=o.credentials,c=[],u=hn(c,"STREAMING",n),g={Accept:"text/event-stream","Cache-Control":"no-cache"};if(l)try{let w=await l.retrieve();if(w&&w.keyId&&w.keySecret){let C=Buffer.from(`${w.keyId}:${w.keySecret}`).toString("base64");g.Authorization=`Basic ${C}`}}catch(w){t.debug("Failed to add authentication:",w)}let h=new AbortController;try{let w=await fetch(a,{method:"GET",headers:g,signal:h.signal});if(!w.ok)throw new Error(`SSE connection failed: ${w.status} ${w.statusText}`);if(!w.body)throw new Error("Response body is null");dn(u.statusBar,"CONNECTED",n),u.screen.render();let C=w.body.getReader(),D=new TextDecoder,q="";(async()=>{try{for(;;){let{done:S,value:b}=await C.read();if(S)break;q+=D.decode(b,{stream:!0});let y=q.split(`
|
|
48
|
+
`,await A.default.writeFile(n,i,"utf-8"),t.debug(`Updated .env: SINCH_TUNNEL=${o}`)}}else if(e==="csharp"){let n=G.default.join(process.cwd(),"appsettings.Development.json");if(await A.default.pathExists(n)){let i=await A.default.readJson(n);i.SinchTunnel=o,await A.default.writeJson(n,i,{spaces:2}),t.debug(`Updated appsettings.Development.json: SinchTunnel=${o}`)}}}async function yo(o,e){let n=e.runtime||"node",i=!1;if(o.tunnel===!0)i=!0;else if(o.tunnel===!1)i=!1,e.tunnel?.preference==="always"&&(f.set("tunnel",{...e.tunnel,preference:"no"},!0),await f.saveProjectConfig());else if(e.tunnel?.preference==="never")i=!1;else if(vo(e))i=!0;else{let{tunnelChoice:c}=await tn.default.prompt([{type:"list",name:"tunnelChoice",message:"Enable Sinch tunnel for external access?",choices:[{name:"Yes - Enable tunnel this time",value:"yes"},{name:"No - Local only this time",value:"no"},{name:"Always - Enable tunnel and remember preference",value:"always"},{name:"Never - Don't enable tunnel and remember preference",value:"never"}],default:"no"}]);c==="yes"?i=!0:c==="no"?i=!1:c==="always"?(i=!0,f.set("tunnel",{...e.tunnel,preference:"always"},!0),await f.saveProjectConfig()):c==="never"&&(i=!1,f.set("tunnel",{...e.tunnel,preference:"never"},!0),await f.saveProjectConfig())}await ho(i,n);let s={...process.env,PORT:o.port,NODE_ENV:"development",SINCH_FUNCTIONS_LOCAL:"true",SINCH_TUNNEL:i?"true":"false"};e.variables&&Object.entries(e.variables).forEach(([c,u])=>{s[c]=u});try{let c=await f.getApplicationCredentials(e.voiceAppKey);c?(s.SINCH_APPLICATION_KEY=c.applicationKey,s.SINCH_APPLICATION_SECRET=c.applicationSecret,t.debug("\u2705 Injected application credentials for voice operations")):t.debug("\u26A0\uFE0F No application credentials found - voice features may not work")}catch(c){t.debug(`\u26A0\uFE0F Could not load application credentials: ${c.message}`)}t.info("\u{1F680} Starting local server...");let r=null,a=!1;function l(){if(r&&r.kill(),n==="csharp"){let c=["run","--no-launch-profile"];o.port&&c.push("--urls",`http://localhost:${o.port}`),s.ASPNETCORE_ENVIRONMENT="Development",s.ASPNETCORE_URLS=`http://localhost:${o.port}`,r=(0,ut.spawn)("dotnet",c,{env:s,stdio:"inherit",cwd:process.cwd()})}else{let c=G.default.join(process.cwd(),"host.js"),u=[];o.debug&&u.push("--inspect=9229"),u.push(c),r=(0,ut.spawn)("node",u,{env:s,stdio:"inherit",cwd:process.cwd()})}r.on("spawn",async()=>{a||(a=!0,t.newline(),t.success(`\u2705 Server running on http://localhost:${o.port}`),o.debug&&(t.newline(),n==="csharp"?$o():Co()),t.newline(),t.info("\u{1F4A1} Development commands:"),t.info(` \u2022 Test function: ${Fe.default.cyan(`curl http://localhost:${o.port}`)}`),t.info(` \u2022 View in browser: ${Fe.default.cyan(`http://localhost:${o.port}`)}`),t.info(` \u2022 Stop server: ${Fe.default.gray("Ctrl+C")}`),o.watch&&t.info(` \u2022 File watching: ${Fe.default.green("enabled")}`))}),r.on("error",c=>{t.error(`Server error: ${c.message}`)}),r.on("exit",(c,u)=>{u!=="SIGTERM"&&u!=="SIGKILL"&&t.error(`Server exited with code ${c}`)})}l(),o.watch&&wo(()=>{t.info("\u{1F4DD} Files changed, restarting server..."),l()},n),process.on("SIGINT",()=>{t.newline(),t.info("\u{1F534} Stopping development server..."),r&&r.kill("SIGTERM"),process.exit(0)}),await new Promise(()=>{})}function wo(o,e="node"){let n=[".git/**",".DS_Store","*.tmp",".sinch-tmp/**"];e==="csharp"?n.push("bin/**","obj/**","*.user",".vs/**"):n.push("node_modules/**");let i=Xt.default.watch(".",{ignored:n,ignoreInitial:!0,awaitWriteFinish:{stabilityThreshold:100,pollInterval:10}});i.on("change",s=>{t.debug(`File changed: ${s}`),o()}),i.on("add",s=>{t.debug(`File added: ${s}`),o()}),i.on("unlink",s=>{t.debug(`File removed: ${s}`),o()})}async function Co(){try{let o=await Ee("code",".vscode"),e=await Ee("cursor",".cursor"),n=await Ee("webstorm",".idea");if(o||e){let i=o?"VS Code":"Cursor",s=".vscode";if(t.info(`\u{1F41B} ${i} detected! Debug setup:`),await So(s))t.info(" 1. \u2705 Created .vscode/launch.json for you");else{let a=G.default.join(process.cwd(),s,"launch.json");await A.default.pathExists(a)?t.info(" 1. \u2705 Found existing .vscode/launch.json"):t.info(" 1. \u26A0\uFE0F Could not create .vscode/launch.json")}t.info(" 2. \u{1F50D} Press F5 to attach debugger"),t.info(" 3. \u{1F534} Set breakpoints in your function.js"),t.info(" 4. \u{1F4DE} Test your function to hit breakpoints")}else n?(t.info("\u{1F41B} WebStorm detected! Debug setup:"),t.info(" 1. \u{1F50D} Run \u2192 Attach to Node.js/Chrome \u2192 localhost:9229"),t.info(" 2. \u{1F534} Set breakpoints in your function.js")):(t.info("\u{1F41B} Manual debug setup:"),t.info(' \u2022 VS Code/Cursor: Open "Run and Debug" \u2192 "Attach to Node.js Process"'),t.info(' \u2022 Chrome DevTools: Visit chrome://inspect \u2192 Click "inspect"'),t.info(" \u2022 Manual: Connect debugger to ws://localhost:9229"))}catch{t.info("\u{1F41B} Debug instructions:"),t.info(" \u2022 Connect your debugger to ws://localhost:9229"),t.info(" \u2022 Set breakpoints and test your function")}}async function Ee(o,e){try{if(o==="code"&&bo())return!0;let{spawn:n}=require("child_process"),i=await new Promise(r=>{let a=n(o,["--version"],{stdio:"pipe"});a.on("close",l=>r(l===0)),a.on("error",()=>r(!1))}),s=e?await A.default.pathExists(e):!1;return i||s}catch{return!1}}function bo(){return process.env.TERM_PROGRAM==="vscode"||!!process.env.VSCODE_IPC_HOOK||!!process.env.VSCODE_PID}async function So(o=".vscode"){try{let e=G.default.join(process.cwd(),o),n=G.default.join(e,"launch.json");if(await A.default.pathExists(n))return!1;await A.default.ensureDir(e);let i={version:"0.2.0",configurations:[{name:"Attach to Sinch Function",type:"node",request:"attach",port:9229,localRoot:"${workspaceFolder}",remoteRoot:"${workspaceFolder}",skipFiles:["<node_internals>/**","node_modules/**"]}]};return await A.default.writeJson(n,i,{spaces:2}),!!await A.default.pathExists(n)}catch{return!1}}function vo(o){return o.tunnel?o.tunnel.preference==="always":!1}async function $o(){try{let o=await Ee("code",".vscode"),e=await Ee("devenv"),n=await Ee("rider",".idea");o?(t.info("\u{1F41B} VS Code detected! Debug setup:"),await Po(".vscode")?t.info(" 1. \u2705 Created .vscode/launch.json for C#"):t.info(" 1. \u2705 Found existing .vscode/launch.json"),t.info(" 2. \u{1F50D} Press F5 to attach debugger"),t.info(" 3. \u{1F534} Set breakpoints in your Function.cs"),t.info(" 4. \u{1F4DE} Test your function to hit breakpoints")):e?(t.info("\u{1F41B} Visual Studio detected! Debug setup:"),t.info(" 1. \u{1F50D} Debug \u2192 Attach to Process \u2192 dotnet.exe"),t.info(" 2. \u{1F534} Set breakpoints in your Function.cs"),t.info(" 3. \u{1F4DE} Test your function to hit breakpoints")):n?(t.info("\u{1F41B} JetBrains Rider detected! Debug setup:"),t.info(" 1. \u{1F50D} Run \u2192 Attach to Process \u2192 dotnet"),t.info(" 2. \u{1F534} Set breakpoints in your Function.cs")):(t.info("\u{1F41B} C# Debug setup:"),t.info(" \u2022 Visual Studio: Debug \u2192 Attach to Process \u2192 dotnet.exe"),t.info(" \u2022 VS Code: Install C# extension, then F5 to debug"),t.info(" \u2022 Rider: Run \u2192 Attach to Process"))}catch{t.info("\u{1F41B} C# Debug instructions:"),t.info(" \u2022 Attach your debugger to the dotnet process"),t.info(" \u2022 Set breakpoints in Function.cs")}}async function Po(o=".vscode"){try{let e=G.default.join(process.cwd(),o),n=G.default.join(e,"launch.json");if(await A.default.pathExists(n))return!1;await A.default.ensureDir(e);let i={version:"0.2.0",configurations:[{name:".NET Core Launch (web)",type:"coreclr",request:"launch",preLaunchTask:"build",program:"${workspaceFolder}/bin/Debug/net8.0/Function.dll",args:[],cwd:"${workspaceFolder}",stopAtEntry:!1,serverReadyAction:{action:"openExternally",pattern:"\\bNow listening on:\\s+(https?://\\S+)"},env:{ASPNETCORE_ENVIRONMENT:"Development"},sourceFileMap:{"/Views":"${workspaceFolder}/Views"}},{name:".NET Core Attach",type:"coreclr",request:"attach"}]};await A.default.writeJson(n,i,{spaces:2});let s=G.default.join(e,"tasks.json");if(!await A.default.pathExists(s)){let r={version:"2.0.0",tasks:[{label:"build",command:"dotnet",type:"process",args:["build","${workspaceFolder}/Function.csproj","/property:GenerateFullPaths=true","/consoleloggerparameters:NoSummary"],problemMatcher:"$msCompile"}]};await A.default.writeJson(s,r,{spaces:2})}return await A.default.pathExists(n)}catch{return!1}}on.exports=nn});var un=x((es,ln)=>{"use strict";var K=m(require("chalk")),rn=require("commander");_();R();U();F();var an=new rn.Command("status");an.description("Show function status and details").argument("[function-id]","Function ID to check (optional if sinch.json exists)").option("-f, --follow","Watch status changes in real-time").option("--json","Output raw JSON").action(async(o,e)=>{try{await f.load();let n=new E(f.getApiConfig()),i=o;if(!i){if(!f.isInProject())throw new Error("Function ID required. Provide as argument or run from function directory with sinch.json");if(i=f.getProjectConfig()?.functionId,!i)throw new Error("No function ID found in sinch.json. Deploy the function first or provide function ID as argument.")}e.follow?await Eo(n,i):await ko(n,i,e)}catch(n){d.stop(),t.error(`Failed to get function status: ${n.message}`),process.exit(1)}});async function ko(o,e,n){d.start("\u{1F4E1} Loading function status...");try{let i=await o.getFunction(e),s=await o.getFunctionStatus(e);if(d.stop(),n.json){console.log(JSON.stringify({function:i,deployment:s},null,2));return}let r=i,a=s.status,l=s.error;t.newline(),t.title(`Function Status: ${r.name}`),t.newline(),t.info("\u{1F4CB} Function Details:"),t.info(` ID: ${K.default.gray(r.id)}`),t.info(` Name: ${K.default.cyan(r.name)}`),t.info(` Runtime: ${K.default.yellow(r.runtime)}`),t.info(` Deployment Status: ${cn(a)}`),r.created&&t.info(` Created: ${new Date(r.created).toLocaleString()}`),r.updated&&t.info(` Updated: ${new Date(r.updated).toLocaleString()}`),r.url&&t.info(` URL: ${K.default.blue(r.url)}`),a==="Failed"&&l&&(t.newline(),t.error("Deployment Error:"),t.error(` ${l}`)),t.newline(),t.info("\u{1F4A1} Commands:"),t.info(` \u2022 View logs: ${K.default.cyan(`sinch functions logs ${e}`)}`),t.info(` \u2022 Redeploy: ${K.default.cyan("sinch functions deploy")}`),t.info(` \u2022 Delete: ${K.default.cyan(`sinch functions delete ${e}`)}`)}catch(i){throw d.stop(),i}}async function Eo(o,e){t.info("\u{1F440} Watching deployment status (press Ctrl+C to stop)..."),t.newline();let n=null,i=setInterval(async()=>{try{let s=await o.getFunctionStatus(e),r=s.status;if(r!==n){let a=new Date().toLocaleTimeString();if(t.info(`[${a}] Status: ${cn(r)}`),n=r,r==="Running"){t.success("Function deployment is now running!");try{let l=await o.getFunction(e);l.url&&t.info(`URL: ${K.default.blue(l.url)}`)}catch{}}else r==="Failed"&&(t.error("Function deployment failed!"),s.error&&t.error(`Error: ${s.error}`),clearInterval(i))}}catch(s){t.error(`Error checking status: ${s.message}`)}},3e3);process.on("SIGINT",()=>{clearInterval(i),t.newline(),t.info("Stopped watching function status"),process.exit(0)})}function cn(o){return{Running:K.default.green("\u2705 Running"),Failed:K.default.red("\u274C Failed"),Pending:K.default.yellow("\u23F3 Pending"),Building:K.default.blue("\u{1F528} Building")}[o]||K.default.gray(o)}ln.exports=an});var Cn=x((ss,wn)=>{"use strict";var he=m(require("chalk")),fn=require("commander");_();R();U();F();var dt=require("child_process"),Oe=m(require("fs")),_e=m(require("os")),Le=m(require("path")),pt=new fn.Command("logs");pt.description("View function logs").argument("[function-id]","Function ID to get logs for (optional if sinch.json exists)").option("-f, --follow","Follow log output in real-time").option("-n, --lines <number>","Number of historical lines to show","50").option("--level <level>","Filter by log level (debug, info, warning, error)").option("--search <text>","Search for text in log messages").option("--since <duration>","Show logs since duration (e.g., 1h, 30m, 5s)").action(async(o,e)=>{try{await f.load();let n=new E(f.getApiConfig()),i=o;if(!i){if(!f.isInProject())throw new Error("Function ID required. Provide as argument or run from function directory with sinch.json");let r=f.getProjectConfig();if(!r)throw new Error("No project configuration found");if(i=r.functionId,!i)throw new Error("No function ID found in sinch.json. Deploy the function first or provide function ID as argument.")}d.start("Loading function details...");let s=await n.getFunction(i);d.stop(),t.info(`\u{1F4CB} Logs for function: ${he.default.cyan(s.name)} (${Ao(s.status)})`),t.newline(),e.follow?await gn(n,i,s.name,e):await No(n,i,e)}catch(n){d.stop(),t.error(`Failed to get logs: ${n.message}`),process.exit(1)}});pt.command("stream").description("Stream function logs in real-time").argument("[function-id]","Function ID to stream logs for (optional if sinch.json exists)").option("--level <level>","Filter by log level (debug, info, warning, error)").option("--search <text>","Search for text in log messages").action(async(o,e)=>{try{await f.load();let n=new E(f.getApiConfig()),i=o;if(!i){if(!f.isInProject())throw new Error("Function ID required. Provide as argument or run from function directory with sinch.json");let r=f.getProjectConfig();if(!r)throw new Error("No project configuration found");if(i=r.functionId,!i)throw new Error("No function ID found in sinch.json. Deploy the function first or provide function ID as argument.")}d.start("Connecting to log stream...");let s=await Io(n,i);d.stop(),await gn(n,i,s.name,{...e,follow:!0})}catch(n){d.stop(),t.error(`Failed to stream logs: ${n.message}`),process.exit(1)}});async function Io(o,e){return await o.getFunction(e)}async function gn(o,e,n,i){let s=o.baseUrl.replace(/\/+$/,""),r=o.projectId,a=`${s}/v1/projects/${r}/functions/${e}/logs/stream`,l=o.credentials,c=[],u=hn(c,"STREAMING",n),g={Accept:"text/event-stream","Cache-Control":"no-cache"};if(l)try{let w=await l.retrieve();if(w&&w.keyId&&w.keySecret){let C=Buffer.from(`${w.keyId}:${w.keySecret}`).toString("base64");g.Authorization=`Basic ${C}`}}catch(w){t.debug("Failed to add authentication:",w)}let h=new AbortController;try{let w=await fetch(a,{method:"GET",headers:g,signal:h.signal});if(!w.ok)throw new Error(`SSE connection failed: ${w.status} ${w.statusText}`);if(!w.body)throw new Error("Response body is null");dn(u.statusBar,"CONNECTED",n),u.screen.render();let C=w.body.getReader(),D=new TextDecoder,q="";(async()=>{try{for(;;){let{done:S,value:b}=await C.read();if(S)break;q+=D.decode(b,{stream:!0});let y=q.split(`
|
|
49
49
|
`);q=y.pop()||"";for(let k of y)if(!k.startsWith("event:")&&k.startsWith("data:")){let Z=k.substring(5).trim();if(Z)try{let M=JSON.parse(Z);M.type==="request"&&M.request&&(c.push(M.request),mn(u.table,M.request,c),u.table.focus(),u.screen.render())}catch{}}}}catch(S){S.name!=="AbortError"&&(dn(u.statusBar,"RECONNECTING",n),u.screen.render())}})(),u.screen.key(["q","C-c"],()=>{h.abort(),process.exit(0)}),await new Promise(()=>{})}catch(w){h.abort(),t.error(`\u274C Streaming failed: ${w.message}`),process.exit(1)}}function Ao(o){return{Running:he.default.green("\u2705 Running"),Failed:he.default.red("\u274C Failed"),Pending:he.default.yellow("\u23F3 Pending"),Building:he.default.blue("\u{1F528} Building")}[o]||he.default.gray(o)}var ye=[];function mn(o,e,n){let i=new Date(e.startTime),s=i.getFullYear()+"-"+String(i.getMonth()+1).padStart(2,"0")+"-"+String(i.getDate()).padStart(2,"0")+" "+String(i.getHours()).padStart(2,"0")+":"+String(i.getMinutes()).padStart(2,"0")+":"+String(i.getSeconds()).padStart(2,"0"),r=xo(e),a=`${e.executionTimeMs}ms`,l=e.statusCode.toString(),c=process.stdout.columns||120,g=Math.max(30,c-35),h=e.url.length>g?e.url.substring(0,g-2)+"..":e.url;ye.push([s,r,a,l,h]),ye.length>100&&(ye=ye.slice(-100),n&&n.length>100&&n.splice(0,n.length-100));let w=[["Time","Callback","Duration","Status","Path"],...ye];o.setData(w)}function Ro(o,e,n,i,s){try{let r=require("blessed");t.debug(`Showing request details for ${o.httpMethod} ${o.url}`);let a=r.box({parent:e,top:0,left:0,width:"100%",height:"100%",border:{type:"line"},style:{border:{fg:"cyan"},bg:"black",fg:"white"},scrollable:!0,alwaysScroll:!0,keys:!0,vi:!0,tags:!0,label:" Request Details "}),l=r.box({parent:a,top:1,left:2,width:"100%-4",height:1,content:"{gray-fg}[Esc/Q] Close [\u2191\u2193] Scroll [J/1] JSON [C/2] cURL{/}",tags:!0,style:{bg:"blue",fg:"white"}});r.box({parent:a,top:2,left:2,width:"100%-4",height:1,content:`{bold}{cyan-fg}${o.httpMethod}{/} {blue-fg}${o.url}{/} - {${_o(o.statusCode)}}${o.statusCode}{/} - {yellow-fg}${o.executionTimeMs}ms{/} - {magenta-fg}${o.memoryUsedMB||0}MB{/}`,tags:!0,style:{bg:"black"}});let c=r.box({parent:a,top:4,left:2,width:"100%-4",height:"100%-5",scrollable:!0,alwaysScroll:!0,keys:!0,vi:!0,tags:!0,content:jo(o)});c.focus(),e.render();let u=!0,g=()=>{u&&(u=!1,a.destroy(),n.focus(),e.render())};e.key(["escape","q"],()=>{u&&g()}),e.key(["up","k"],()=>{u&&(c.scroll(-1),e.render())}),e.key(["down","j"],()=>{u&&(c.scroll(1),e.render())}),e.on("keypress",(h,w)=>{u&&t.debug(`Key pressed: ch="${h}" key=${JSON.stringify(w)}`)}),e.key(["J","j"],()=>{u&&(t.debug("J/j key pressed - attempting JSON copy"),l.setContent("{black-bg}{yellow-fg} J KEY PRESSED - COPYING JSON... {/}"),e.render(),setTimeout(()=>{try{let h=JSON.stringify(o,null,2);t.debug(`JSON content length: ${h.length}`),t.debug("Attempting native clipboard copy"),He(h).then(()=>{l.setContent("{green-fg}\u2713 Request JSON copied to clipboard!{/}"),t.debug("Native clipboard copy succeeded"),e.render(),setTimeout(()=>{u&&(l.setContent("{gray-fg}[Esc/Q] Close [\u2191\u2193] Scroll [J] JSON [C] cURL{/}"),e.render())},3e3)}).catch(w=>{t.debug(`Native clipboard failed: ${w.message}`);let C=Le.default.join(_e.default.tmpdir(),`sinch-request-${Date.now()}.json`);Oe.default.writeFileSync(C,h),l.setContent(`{yellow-fg}\u2713 JSON saved to: ${C}{/}`),t.debug(`Saved to temp file: ${C}`),e.render(),setTimeout(()=>{u&&(l.setContent("{gray-fg}[Esc/Q] Close [\u2191\u2193] Scroll [J] JSON [C] cURL{/}"),e.render())},3e3)})}catch(h){t.debug(`JSON copy error: ${h.message}`),l.setContent(`{red-fg}\u2717 Copy failed: ${h.message}{/}`),e.render(),setTimeout(()=>{u&&(l.setContent("{gray-fg}[Esc/Q] Close [\u2191\u2193] Scroll [J] JSON [C] cURL{/}"),e.render())},3e3)}},100))}),e.key(["C","c"],()=>{u&&(t.debug("C/c key pressed - attempting cURL copy"),l.setContent("{black-bg}{yellow-fg} C KEY PRESSED - COPYING CURL... {/}"),e.render(),setTimeout(()=>{try{let h=pn(o);t.debug("Attempting native clipboard copy for cURL"),He(h).then(()=>{l.setContent("{green-fg}\u2713 cURL command copied to clipboard!{/}"),t.debug("Native clipboard copy succeeded for cURL"),e.render(),setTimeout(()=>{u&&(l.setContent("{gray-fg}[Esc/Q] Close [\u2191\u2193] Scroll [J] JSON [C] cURL{/}"),e.render())},3e3)}).catch(w=>{t.debug(`Native clipboard failed for cURL: ${w.message}`);let C=Le.default.join(_e.default.tmpdir(),`sinch-curl-${Date.now()}.sh`);Oe.default.writeFileSync(C,h),l.setContent(`{yellow-fg}\u2713 cURL saved to: ${C}{/}`),e.render(),setTimeout(()=>{u&&(l.setContent("{gray-fg}[Esc/Q] Close [\u2191\u2193] Scroll [J] JSON [C] cURL{/}"),e.render())},3e3)})}catch(h){t.debug(`cURL copy error: ${h.message}`),l.setContent(`{red-fg}\u2717 Copy failed: ${h.message}{/}`),e.render(),setTimeout(()=>{u&&(l.setContent("{gray-fg}[Esc/Q] Close [\u2191\u2193] Scroll [J] JSON [C] cURL{/}"),e.render())},3e3)}},100))}),e.key(["1"],()=>{u&&(t.debug("1 key pressed - copying JSON (alternative binding)"),l.setContent("{black-bg}{yellow-fg} 1 KEY - COPYING JSON... {/}"),e.render(),setTimeout(()=>{try{let h=JSON.stringify(o,null,2);He(h).then(()=>{l.setContent("{green-fg}\u2713 Request JSON copied to clipboard!{/}"),e.render(),setTimeout(()=>{u&&(l.setContent("{gray-fg}[Esc/Q] Close [\u2191\u2193] Scroll [J] JSON [C] cURL{/}"),e.render())},3e3)}).catch(w=>{let C=Le.default.join(_e.default.tmpdir(),`sinch-request-${Date.now()}.json`);Oe.default.writeFileSync(C,h),l.setContent(`{yellow-fg}\u2713 JSON saved to: ${C}{/}`),e.render(),setTimeout(()=>{u&&(l.setContent("{gray-fg}[Esc/Q] Close [\u2191\u2193] Scroll [J] JSON [C] cURL{/}"),e.render())},3e3)})}catch(h){l.setContent(`{red-fg}\u2717 Copy failed: ${h.message}{/}`),e.render(),setTimeout(()=>{u&&(l.setContent("{gray-fg}[Esc/Q] Close [\u2191\u2193] Scroll [J] JSON [C] cURL{/}"),e.render())},3e3)}},100))}),e.key(["2"],()=>{u&&(t.debug("2 key pressed - copying cURL (alternative binding)"),l.setContent("{black-bg}{yellow-fg} 2 KEY - COPYING CURL... {/}"),e.render(),setTimeout(()=>{try{let h=pn(o);He(h).then(()=>{l.setContent("{green-fg}\u2713 cURL command copied to clipboard!{/}"),e.render(),setTimeout(()=>{u&&(l.setContent("{gray-fg}[Esc/Q] Close [\u2191\u2193] Scroll [J] JSON [C] cURL{/}"),e.render())},3e3)}).catch(w=>{let C=Le.default.join(_e.default.tmpdir(),`sinch-curl-${Date.now()}.sh`);Oe.default.writeFileSync(C,h),l.setContent(`{yellow-fg}\u2713 cURL saved to: ${C}{/}`),e.render(),setTimeout(()=>{u&&(l.setContent("{gray-fg}[Esc/Q] Close [\u2191\u2193] Scroll [J] JSON [C] cURL{/}"),e.render())},3e3)})}catch(h){l.setContent(`{red-fg}\u2717 Copy failed: ${h.message}{/}`),e.render(),setTimeout(()=>{u&&(l.setContent("{gray-fg}[Esc/Q] Close [\u2191\u2193] Scroll [J] JSON [C] cURL{/}"),e.render())},3e3)}},100))})}catch(r){t.debug(`Error in showBlessedZoomedRequest: ${r.message}`)}}function jo(o){let e="";return e+=`
|
|
50
50
|
`,e+=Do(o),e+=`
|
|
51
51
|
`,e+=To(o),e+=`
|
package/package.json
CHANGED