@dimension-studios/ttk-proxy 1.209.0 → 1.210.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.
package/README.md CHANGED
@@ -107,12 +107,7 @@ This is useful when copying request bodies from logs or other sources where the
107
107
 
108
108
  ## Output
109
109
 
110
- The CLI provides beautiful, color-coded output using `@rharkor/logger`:
111
-
112
- - ✅ Success messages in green
113
- - ❌ Error messages in red
114
- - ℹ️ Info messages in blue
115
- - ⚠️ Warning messages in yellow
110
+ The CLI prints plain messages to stdout, and errors to stderr.
116
111
 
117
112
  Example output:
118
113
 
package/dist/index.mjs CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
- import{logger as e}from"@rharkor/logger";import{program as t}from"commander";import"dotenv/config";import n from"conf";const r=new n({projectName:`ttk-proxy`});function i(){let e=r.get(`apiUrl`),t=r.get(`apiKey`),n=r.get(`apiSecret`);if(!e||!t||!n)throw Error(`Missing configuration. Please set apiUrl, apiKey, and apiSecret using environment variables or the config command.`);return{apiUrl:e,apiKey:t,apiSecret:n}}function a(e){e.apiUrl&&r.set(`apiUrl`,e.apiUrl),e.apiKey&&r.set(`apiKey`,e.apiKey),e.apiSecret&&r.set(`apiSecret`,e.apiSecret)}function o(){let e=process.env.TTK_FETCH_API_URL,t=process.env.TTK_FETCH_API_KEY,n=process.env.TTK_FETCH_API_SECRET;e&&r.set(`apiUrl`,e),t&&r.set(`apiKey`,t),n&&r.set(`apiSecret`,n)}const s=e=>!(e.length<4||!/^[A-Za-z0-9+/]*={0,2}$/.test(e)||e.startsWith(`{`)||e.startsWith(`[`)),c=e=>{try{let t=Buffer.from(e,`base64`).toString(`utf-8`);return JSON.parse(t)}catch{return null}},l=t=>{if(s(t)){let n=c(t);if(n!==null)return e.debug(`🔓 Detected and decoded base64 input`),n}try{return JSON.parse(t)}catch{let e=`"${t}"`;return JSON.parse(JSON.parse(e))}};async function u(t,{allowInvalid:n=!1}={}){let r=i();try{let e=await fetch(`${r.apiUrl}/ttk-proxy/get-cookies`,{method:`POST`,headers:{"Content-Type":`application/json`,"X-Api-Key":r.apiKey,"X-Api-Secret":r.apiSecret},body:JSON.stringify({shopId:t,allowInvalid:n}),signal:AbortSignal.timeout(1e4)});if(!e.ok)throw Error(`HTTP ${e.status}: ${e.statusText}`);return await e.json()}catch(t){throw e.error(`Failed to get cookies`,t),t}}async function d(t){let n=i();try{let e=new URLSearchParams({q:t.trim()}),r=await fetch(`${n.apiUrl}/ttk-proxy/shops/search?${e}`,{method:`GET`,headers:{"X-Api-Key":n.apiKey,"X-Api-Secret":n.apiSecret},signal:AbortSignal.timeout(1e4)});if(!r.ok){let e=await r.text();throw Error(`HTTP ${r.status}: ${e||r.statusText}`)}return(await r.json()).shops}catch(t){throw e.error(`Failed to search shops`,t),t}}async function f(t){let n=i();try{let r=l(t),i=await fetch(`${n.apiUrl}/ttk-proxy/get-curl`,{method:`POST`,headers:{"Content-Type":`application/json`,"X-Api-Key":n.apiKey,"X-Api-Secret":n.apiSecret},body:JSON.stringify(r),signal:AbortSignal.timeout(1e4)});if(i.ok){let e=await i.json();console.log(`
3
- 📋 Curl command:`),console.log(e.curl),console.log(``)}else i.status===403&&e.warn(`⚠️ Curl command not available (requires all shops access)`);let a=await fetch(`${n.apiUrl}/ttk-proxy`,{method:`POST`,headers:{"Content-Type":`application/json`,"X-Api-Key":n.apiKey,"X-Api-Secret":n.apiSecret},body:JSON.stringify(r),signal:AbortSignal.timeout(1e4)}),o=await a.text(),s;try{s=JSON.parse(o)}catch{s=o}return{status:a.status,statusText:a.statusText,body:s}}catch(t){throw e.error(`Failed to call TikTok proxy API`,t),t}}async function p(){let t=i();try{e.debug(`Listing TikTok proxy tokens`,{url:t.apiUrl});let n=await fetch(`${t.apiUrl}/ttk-proxy/list`,{method:`GET`,headers:{"X-Api-Key":t.apiKey,"X-Api-Secret":t.apiSecret},signal:AbortSignal.timeout(1e4)});if(!n.ok){let e=await n.text();throw Error(`HTTP ${n.status}: ${e}`)}return await n.json()}catch(t){throw e.error(`Failed to list TikTok proxy tokens`,t),t}}async function m(t){try{let n=i();e.info(`🚀 Calling TikTok Proxy API at ${n.apiUrl}...`);let r=await f(t);e.success(`✅ Status: ${r.status} ${r.statusText}`),e.info(`
4
- 📦 Response:`),console.log(JSON.stringify(r.body,null,2))}catch(t){e.error(`❌ Failed to call TikTok Proxy API`),t instanceof Error?e.error(t.message):e.error(String(t)),process.exit(1)}}function h(t){try{if(t.clear){r.clear(),e.success(`✅ Configuration cleared`);return}if(t.show){let t=r.store;e.info(`📋 Current configuration:`),console.log(JSON.stringify(t,null,2));return}o();let n=r.get(`apiUrl`),i=r.get(`apiKey`),a=r.get(`apiSecret`);(!n||!i||!a)&&(e.error(`❌ Missing configuration`),e.info(`Please set the following environment variables:`),e.info(` - TTK_FETCH_API_URL`),e.info(` - TTK_FETCH_API_KEY`),e.info(` - TTK_FETCH_API_SECRET`),e.info(`Or manually set them using:`),e.info(` config:set apiUrl 'your-url'`),e.info(` config:set apiKey 'your-key'`),e.info(` config:set apiSecret 'your-secret'`),process.exit(1)),e.success(`✅ Configuration loaded successfully`),e.info(`📋 Current configuration:`),e.info(` API URL: ${n}`),e.info(` API Key: ${i}`),e.info(` API Secret: ${s(a)}`);function s(e){return!e||e.length<8?`*`.repeat(e.length):`${e.slice(0,4)}${`*`.repeat(e.length-8)}${e.slice(-4)}`}}catch(t){e.error(`❌ Failed to manage configuration`),t instanceof Error?e.error(t.message):e.error(String(t)),process.exit(1)}}function g(t,n){try{[`apiUrl`,`apiKey`,`apiSecret`].includes(t)||(e.error(`❌ Invalid config key: ${t}`),e.info(`Valid keys: apiUrl, apiKey, apiSecret`),process.exit(1)),a({[t]:n}),e.success(`✅ Set ${t} successfully`)}catch(t){e.error(`❌ Failed to set configuration`),t instanceof Error?e.error(t.message):e.error(String(t)),process.exit(1)}}async function _(t,n){try{e.info(`🔍 Listing TikTok Proxy tokens...`);let{cookies:r}=await u(t,n);if(r.length===0){e.warn(`⚠️ No tokens found`);return}e.success(`✅ Found ${r.length} cookie(s)`),e.info(`
5
- 📋 Cookies:`),console.log(JSON.stringify(r,null,2))}catch(t){e.error(`❌ Failed to list TikTok Proxy tokens`),t instanceof Error?e.error(t.message):e.error(String(t)),process.exit(1)}}async function v(){try{e.info(`🔍 Listing TikTok Proxy tokens...`);let t=await p();if(t.length===0){e.warn(`⚠️ No tokens found`);return}e.success(`✅ Found ${t.length} token(s)`),e.info(`
6
- 📋 Tokens:`),console.log(JSON.stringify(t,null,2))}catch(t){e.error(`❌ Failed to list TikTok Proxy tokens`),t instanceof Error?e.error(t.message):e.error(String(t)),process.exit(1)}}async function y(t){try{let n=t.trim();n.length<2&&(e.warn(`⚠️ Enter at least 2 characters to search`),process.exit(1)),e.info(`🔍 Searching shops for "${n}"...`);let r=await d(n);if(r.length===0){e.warn(`⚠️ No shops found`);return}e.success(`✅ Found ${r.length} shop(s)`),e.info(`
7
- 📋 Shops:`),console.log(JSON.stringify(r,null,2))}catch(t){e.error(`❌ Failed to search shops`),t instanceof Error?e.error(t.message):e.error(String(t)),process.exit(1)}}await e.init(),o(),t.name(`ttk-proxy`).description(`CLI tool for TikTok Proxy API`).version(`1.0.0`),t.command(`call`).description(`Call the TikTok Proxy API with a JSON body (supports base64-encoded input)`).argument(`<body>`,`Stringified JSON body for the request (raw JSON or base64-encoded)`).action(async e=>{await m(e)}),t.command(`list`).description(`List all TikTok Proxy tokens`).action(async()=>{await v()}),t.command(`get-cookies`).description(`Get cookies for a given shop ID`).argument(`<shopId>`,`Shop ID`).option(`-i, --allow-invalid`,`Return the stored cookie even if no slot is marked valid`).action(async(e,t)=>{await _(e,t)}),t.command(`shops`).description(`Search shops visible to your API token by name or slug`).argument(`<query>`,`Search string (minimum 2 characters)`).action(async e=>{await y(e)}),t.command(`config`).description(`Manage configuration`).option(`-s, --show`,`Show current configuration`).option(`-c, --clear`,`Clear all configuration`).action(e=>{h(e)}),t.command(`config:set`).description(`Set a configuration value`).argument(`<key>`,`Configuration key (apiUrl, apiKey, apiSecret)`).argument(`<value>`,`Configuration value`).action((e,t)=>{g(e,t)}),t.parse();export{};
2
+ import{program as e}from"commander";import"dotenv/config";import t from"conf";const n=new t({projectName:`ttk-proxy`});function r(){let e=n.get(`apiUrl`),t=n.get(`apiKey`),r=n.get(`apiSecret`);if(!e||!t||!r)throw Error(`Missing configuration. Please set apiUrl, apiKey, and apiSecret using environment variables or the config command.`);return{apiUrl:e,apiKey:t,apiSecret:r}}function i(e){e.apiUrl&&n.set(`apiUrl`,e.apiUrl),e.apiKey&&n.set(`apiKey`,e.apiKey),e.apiSecret&&n.set(`apiSecret`,e.apiSecret)}function a(){let e=process.env.TTK_FETCH_API_URL,t=process.env.TTK_FETCH_API_KEY,r=process.env.TTK_FETCH_API_SECRET;e&&n.set(`apiUrl`,e),t&&n.set(`apiKey`,t),r&&n.set(`apiSecret`,r)}const o=e=>!(e.length<4||!/^[A-Za-z0-9+/]*={0,2}$/.test(e)||e.startsWith(`{`)||e.startsWith(`[`)),s=e=>{try{let t=Buffer.from(e,`base64`).toString(`utf-8`);return JSON.parse(t)}catch{return null}},c=e=>{if(o(e)){let t=s(e);if(t!==null)return t}try{return JSON.parse(e)}catch{let t=`"${e}"`;return JSON.parse(JSON.parse(t))}};async function l(e,{allowInvalid:t=!1}={}){let n=r();try{let r=await fetch(`${n.apiUrl}/ttk-proxy/get-cookies`,{method:`POST`,headers:{"Content-Type":`application/json`,"X-Api-Key":n.apiKey,"X-Api-Secret":n.apiSecret},body:JSON.stringify({shopId:e,allowInvalid:t}),signal:AbortSignal.timeout(1e4)});if(!r.ok)throw Error(`HTTP ${r.status}: ${r.statusText}`);return await r.json()}catch(e){throw console.error(`Failed to get cookies`,e),e}}async function u(e){let t=r();try{let n=new URLSearchParams({q:e.trim()}),r=await fetch(`${t.apiUrl}/ttk-proxy/shops/search?${n}`,{method:`GET`,headers:{"X-Api-Key":t.apiKey,"X-Api-Secret":t.apiSecret},signal:AbortSignal.timeout(1e4)});if(!r.ok){let e=await r.text();throw Error(`HTTP ${r.status}: ${e||r.statusText}`)}return(await r.json()).shops}catch(e){throw console.error(`Failed to search shops`,e),e}}async function d(e){let t=r();try{let n=c(e),r=await fetch(`${t.apiUrl}/ttk-proxy/get-curl`,{method:`POST`,headers:{"Content-Type":`application/json`,"X-Api-Key":t.apiKey,"X-Api-Secret":t.apiSecret},body:JSON.stringify(n),signal:AbortSignal.timeout(1e4)});if(r.ok){let e=await r.json();console.log(`
3
+ 📋 Curl command:`),console.log(e.curl),console.log(``)}else r.status===403&&console.warn(`⚠️ Curl command not available (requires all shops access)`);let i=await fetch(`${t.apiUrl}/ttk-proxy`,{method:`POST`,headers:{"Content-Type":`application/json`,"X-Api-Key":t.apiKey,"X-Api-Secret":t.apiSecret},body:JSON.stringify(n),signal:AbortSignal.timeout(1e4)}),a=await i.text(),o;try{o=JSON.parse(a)}catch{o=a}return{status:i.status,statusText:i.statusText,body:o}}catch(e){throw console.error(`Failed to call TikTok proxy API`,e),e}}async function f(){let e=r();try{let t=await fetch(`${e.apiUrl}/ttk-proxy/list`,{method:`GET`,headers:{"X-Api-Key":e.apiKey,"X-Api-Secret":e.apiSecret},signal:AbortSignal.timeout(1e4)});if(!t.ok){let e=await t.text();throw Error(`HTTP ${t.status}: ${e}`)}return await t.json()}catch(e){throw console.error(`Failed to list TikTok proxy tokens`,e),e}}async function p(e){try{let t=r();console.info(`🚀 Calling TikTok Proxy API at ${t.apiUrl}...`);let n=await d(e);console.info(`✅ Status: ${n.status} ${n.statusText}`),console.info(`
4
+ 📦 Response:`),console.log(JSON.stringify(n.body,null,2))}catch(e){console.error(`❌ Failed to call TikTok Proxy API`),e instanceof Error?console.error(e.message):console.error(String(e)),process.exit(1)}}function m(e){try{if(e.clear){n.clear(),console.info(`✅ Configuration cleared`);return}if(e.show){let e=n.store;console.info(`📋 Current configuration:`),console.log(JSON.stringify(e,null,2));return}a();let t=n.get(`apiUrl`),r=n.get(`apiKey`),i=n.get(`apiSecret`);(!t||!r||!i)&&(console.error(`❌ Missing configuration`),console.info(`Please set the following environment variables:`),console.info(` - TTK_FETCH_API_URL`),console.info(` - TTK_FETCH_API_KEY`),console.info(` - TTK_FETCH_API_SECRET`),console.info(`Or manually set them using:`),console.info(` config:set apiUrl 'your-url'`),console.info(` config:set apiKey 'your-key'`),console.info(` config:set apiSecret 'your-secret'`),process.exit(1)),console.info(`✅ Configuration loaded successfully`),console.info(`📋 Current configuration:`),console.info(` API URL: ${t}`),console.info(` API Key: ${r}`),console.info(` API Secret: ${o(i)}`);function o(e){return!e||e.length<8?`*`.repeat(e.length):`${e.slice(0,4)}${`*`.repeat(e.length-8)}${e.slice(-4)}`}}catch(e){console.error(`❌ Failed to manage configuration`),e instanceof Error?console.error(e.message):console.error(String(e)),process.exit(1)}}function h(e,t){try{[`apiUrl`,`apiKey`,`apiSecret`].includes(e)||(console.error(`❌ Invalid config key: ${e}`),console.info(`Valid keys: apiUrl, apiKey, apiSecret`),process.exit(1)),i({[e]:t}),console.info(`✅ Set ${e} successfully`)}catch(e){console.error(`❌ Failed to set configuration`),e instanceof Error?console.error(e.message):console.error(String(e)),process.exit(1)}}async function g(e,t){try{console.info(`🔍 Listing TikTok Proxy tokens...`);let{cookies:n}=await l(e,t);if(n.length===0){console.warn(`⚠️ No tokens found`);return}console.info(`✅ Found ${n.length} cookie(s)`),console.info(`
5
+ 📋 Cookies:`),console.log(JSON.stringify(n,null,2))}catch(e){console.error(`❌ Failed to list TikTok Proxy tokens`),e instanceof Error?console.error(e.message):console.error(String(e)),process.exit(1)}}async function _(){try{console.info(`🔍 Listing TikTok Proxy tokens...`);let e=await f();if(e.length===0){console.warn(`⚠️ No tokens found`);return}console.info(`✅ Found ${e.length} token(s)`),console.info(`
6
+ 📋 Tokens:`),console.log(JSON.stringify(e,null,2))}catch(e){console.error(`❌ Failed to list TikTok Proxy tokens`),e instanceof Error?console.error(e.message):console.error(String(e)),process.exit(1)}}async function v(e){try{let t=e.trim();t.length<2&&(console.warn(`⚠️ Enter at least 2 characters to search`),process.exit(1)),console.info(`🔍 Searching shops for "${t}"...`);let n=await u(t);if(n.length===0){console.warn(`⚠️ No shops found`);return}console.info(`✅ Found ${n.length} shop(s)`),console.info(`
7
+ 📋 Shops:`),console.log(JSON.stringify(n,null,2))}catch(e){console.error(`❌ Failed to search shops`),e instanceof Error?console.error(e.message):console.error(String(e)),process.exit(1)}}a(),e.name(`ttk-proxy`).description(`CLI tool for TikTok Proxy API`).version(`1.0.0`),e.command(`call`).description(`Call the TikTok Proxy API with a JSON body (supports base64-encoded input)`).argument(`<body>`,`Stringified JSON body for the request (raw JSON or base64-encoded)`).action(async e=>{await p(e)}),e.command(`list`).description(`List all TikTok Proxy tokens`).action(async()=>{await _()}),e.command(`get-cookies`).description(`Get cookies for a given shop ID`).argument(`<shopId>`,`Shop ID`).option(`-i, --allow-invalid`,`Return the stored cookie even if no slot is marked valid`).action(async(e,t)=>{await g(e,t)}),e.command(`shops`).description(`Search shops visible to your API token by name or slug`).argument(`<query>`,`Search string (minimum 2 characters)`).action(async e=>{await v(e)}),e.command(`config`).description(`Manage configuration`).option(`-s, --show`,`Show current configuration`).option(`-c, --clear`,`Clear all configuration`).action(e=>{m(e)}),e.command(`config:set`).description(`Set a configuration value`).argument(`<key>`,`Configuration key (apiUrl, apiKey, apiSecret)`).argument(`<value>`,`Configuration value`).action((e,t)=>{h(e,t)}),e.parse();export{};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dimension-studios/ttk-proxy",
3
- "version": "1.209.0",
3
+ "version": "1.210.1",
4
4
  "description": "CLI tool for TikTok proxy API",
5
5
  "keywords": [
6
6
  "api",
@@ -41,7 +41,6 @@
41
41
  "prepublishOnly": "bun run build"
42
42
  },
43
43
  "dependencies": {
44
- "@rharkor/logger": "1.3.3",
45
44
  "commander": "15.0.0",
46
45
  "conf": "15.1.0",
47
46
  "dotenv": "17.4.2"