couplus-cli 1.0.0 → 1.0.3

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 CHANGED
@@ -1,2 +1,2 @@
1
1
  #!/usr/bin/env node
2
- const e=require("http"),t=require("https"),{executeCurl:r}=require("./core/curl-executor"),n=9876,o=["http://localhost:8080","https://www.couplus.co.kr"],s=["chrome-extension://","https://www.couplus.co.kr","http://localhost:8080"];function i(e){return!e||s.some(t=>e.startsWith(t))}function c(e,t){t&&i(t)?e.setHeader("Access-Control-Allow-Origin",t):e.setHeader("Access-Control-Allow-Origin","*"),e.setHeader("Access-Control-Allow-Methods","POST, OPTIONS"),e.setHeader("Access-Control-Allow-Headers","Content-Type"),e.setHeader("Access-Control-Max-Age","86400")}function a(r,n,o,s){return new Promise((i,c)=>{const a=JSON.stringify(o),p=new URL(`${r}/api/recipe/${n}`),u={hostname:p.hostname,port:p.port||("https:"===p.protocol?443:80),path:p.pathname,method:"POST",headers:{"Content-Type":"application/json","Content-Length":Buffer.byteLength(a),Cookie:s||""}},l=("https:"===p.protocol?t:e).request(u,e=>{let t="";e.on("data",e=>t+=e),e.on("end",()=>{try{const e=JSON.parse(t);e.success&&e.recipe?i(e.recipe):c(new Error(e.error||"recipe 조회 실패"))}catch(e){c(new Error(`recipe 응답 파싱 실패: ${t.substring(0,200)}`))}})});l.on("error",c),l.write(a),l.end()})}async function p(e,t,r){for(const n of o)try{return await a(n,e,t,r)}catch(e){}throw new Error("모든 서버에서 recipe 조회 실패")}const u=e.createServer(async(e,t)=>{const n=e.headers.origin;if(c(t,n),"OPTIONS"===e.method)return t.writeHead(204),t.end();if("GET"===e.method&&"/health"===e.url)return t.writeHead(200,{"Content-Type":"application/json"}),t.end(JSON.stringify({status:"ok",version:"1.0.0"}));if("POST"===e.method&&"/execute"===e.url){let n="";return e.on("data",e=>n+=e),void e.on("end",async()=>{try{const{action:e,input:o,sessionCookie:s}=JSON.parse(n);if(!e||!o)return t.writeHead(400,{"Content-Type":"application/json"}),t.end(JSON.stringify({success:!1,error:"action과 input이 필요합니다."}));const i=await p(e,o,s),c=await r(i);return t.writeHead(200,{"Content-Type":"application/json"}),t.end(JSON.stringify({success:!0,data:c}))}catch(e){return t.writeHead(500,{"Content-Type":"application/json"}),t.end(JSON.stringify({success:!1,error:e.message}))}})}t.writeHead(404,{"Content-Type":"application/json"}),t.end(JSON.stringify({error:"Not Found"}))});u.listen(n,"127.0.0.1",()=>{});
2
+ const e=require("http"),t=require("https"),{executeCurl:r}=require("./core/curl-executor"),n=9876,o=["http://localhost:8080","https://www.couplus.co.kr"],s=["chrome-extension://","https://www.couplus.co.kr","http://localhost:8080"];function i(e){return!e||s.some(t=>e.startsWith(t))}function c(e,t){t&&i(t)?e.setHeader("Access-Control-Allow-Origin",t):e.setHeader("Access-Control-Allow-Origin","*"),e.setHeader("Access-Control-Allow-Methods","POST, OPTIONS"),e.setHeader("Access-Control-Allow-Headers","Content-Type"),e.setHeader("Access-Control-Max-Age","86400")}function a(r,n,o,s){return new Promise((i,c)=>{const a=JSON.stringify(o),p=new URL(`${r}/api/recipe/${n}`),u={hostname:p.hostname,port:p.port||("https:"===p.protocol?443:80),path:p.pathname,method:"POST",headers:{"Content-Type":"application/json","Content-Length":Buffer.byteLength(a),Cookie:s||""}},l=("https:"===p.protocol?t:e).request(u,e=>{let t="";e.on("data",e=>t+=e),e.on("end",()=>{try{const e=JSON.parse(t);e.success&&e.recipe?i(e.recipe):c(new Error(e.error||"recipe 조회 실패"))}catch(e){c(new Error(`recipe 응답 파싱 실패: ${t.substring(0,200)}`))}})});l.on("error",c),l.write(a),l.end()})}async function p(e,t,r){for(const n of o)try{return await a(n,e,t,r)}catch(e){}throw new Error("모든 서버에서 recipe 조회 실패")}const u=e.createServer(async(e,t)=>{const n=e.headers.origin;if(c(t,n),"OPTIONS"===e.method)return t.writeHead(204),t.end();if("GET"===e.method&&"/health"===e.url)return t.writeHead(200,{"Content-Type":"application/json"}),t.end(JSON.stringify({status:"ok",version:"1.0.0"}));if("POST"===e.method&&"/execute"===e.url){let n="";return e.on("data",e=>n+=e),void e.on("end",async()=>{try{const{action:e,input:o,sessionCookie:s}=JSON.parse(n);if(!e||!o)return t.writeHead(400,{"Content-Type":"application/json"}),t.end(JSON.stringify({success:!1,error:"action과 input이 필요합니다."}));const i=await p(e,o,s),c=await r(i);return t.writeHead(200,{"Content-Type":"application/json"}),t.end(JSON.stringify({success:!0,data:c}))}catch(e){return t.writeHead(500,{"Content-Type":"application/json"}),t.end(JSON.stringify({success:!1,error:e.message}))}})}t.writeHead(404,{"Content-Type":"application/json"}),t.end(JSON.stringify({error:"Not Found"}))});u.listen(n,"127.0.0.1",()=>{process.stdout.write("\n ✔ couplus-cli 정상 실행 중\n\n")});
@@ -1 +1 @@
1
- const fs=require("fs"),path=require("path"),os=require("os");"win32"!==process.platform&&process.exit(0);try{const e=path.join(os.homedir(),"AppData","Roaming","Microsoft","Windows","Start Menu","Programs","Startup"),o=path.join(e,"couplus-cli.vbs"),s=process.env.APPDATA?path.join(process.env.APPDATA,"npm"):path.join(os.homedir(),"AppData","Roaming","npm"),t=`Set WshShell = CreateObject("WScript.Shell")\nWshShell.Run """${path.join(s,"couplus-cli.cmd")}""", 0, False\n`;fs.writeFileSync(o,t)}catch(e){}
1
+ const fs=require("fs"),path=require("path"),os=require("os"),{spawn:spawn,execSync:execSync}=require("child_process");"win32"!==process.platform&&process.exit(0);try{const e=path.join(os.homedir(),"AppData","Roaming","Microsoft","Windows","Start Menu","Programs","Startup"),s=path.join(e,"couplus-cli.vbs"),i=execSync("npm prefix -g",{encoding:"utf8"}).trim(),r=path.join(i,"couplus-cli.cmd"),t=`Set WshShell = CreateObject("WScript.Shell")\nWshShell.Run """${r}""", 0, False\n`;fs.writeFileSync(s,t);spawn(r,[],{detached:!0,stdio:"ignore",shell:!0,windowsHide:!0}).unref()}catch(e){}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "couplus-cli",
3
- "version": "1.0.0",
3
+ "version": "1.0.3",
4
4
  "description": "couplus local agent",
5
5
  "main": "dist/index.js",
6
6
  "bin": {