couplus-cli 1.0.0
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/core/curl-executor.js +1 -0
- package/dist/index.js +2 -0
- package/dist/postinstall.js +1 -0
- package/package.json +26 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const{execFile:e}=require("child_process");function r(r){return new Promise((s,o)=>{const t=["-s","--compressed","--max-time","30"];if(r.method&&"GET"!==r.method&&t.push("-X",r.method),r.headers)for(const[e,s]of Object.entries(r.headers))t.push("-H",`${e}: ${s}`);r.body&&t.push("-d","string"==typeof r.body?r.body:JSON.stringify(r.body)),t.push(r.url),e("curl.exe",t,{maxBuffer:52428800,encoding:"utf8"},(e,r,t)=>{if(e)return o(new Error(`curl 실행 실패: ${e.message}`));try{const e=JSON.parse(r);s(e)}catch(e){s({_raw:r.substring(0,5e3),_parseError:e.message})}})})}module.exports={executeCurl:r};
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
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",()=>{});
|
|
@@ -0,0 +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){}
|
package/package.json
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "couplus-cli",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "couplus local agent",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"bin": {
|
|
7
|
+
"couplus-cli": "dist/index.js"
|
|
8
|
+
},
|
|
9
|
+
"files": [
|
|
10
|
+
"dist/"
|
|
11
|
+
],
|
|
12
|
+
"scripts": {
|
|
13
|
+
"start": "node dist/index.js",
|
|
14
|
+
"dev": "node index.js",
|
|
15
|
+
"build": "node scripts/build.js",
|
|
16
|
+
"prepublishOnly": "npm run build",
|
|
17
|
+
"postinstall": "node dist/postinstall.js"
|
|
18
|
+
},
|
|
19
|
+
"os": ["win32"],
|
|
20
|
+
"author": "couplus",
|
|
21
|
+
"license": "MIT",
|
|
22
|
+
"devDependencies": {
|
|
23
|
+
"terser": "^5.39.0"
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|