@dimension-studios/shop-browser 1.167.0 → 1.168.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/index.d.mts CHANGED
@@ -1 +1 @@
1
- export { };
1
+ import "dotenv/config";
package/dist/index.mjs CHANGED
@@ -1,3 +1,3 @@
1
1
  #!/usr/bin/env node
2
- import{readFileSync as e}from"node:fs";import{dirname as t,join as n}from"node:path";import{fileURLToPath as r}from"node:url";import{logger as i}from"@rharkor/logger";import{program as a}from"commander";import"dotenv/config";import o from"conf";import{setTimeout as s}from"node:timers/promises";import{Separator as c,search as l,select as u}from"@inquirer/prompts";import{chromium as d}from"playwright";const f=[{id:`seller`,name:`Seller Center`,url:`https://seller-us.tiktok.com/homepage`},{id:`affiliate`,name:`Affiliate Center`,url:`https://affiliate-us.tiktok.com`},{id:`support`,name:`Support Messages`,url:`https://seller-us.tiktok.com/chat/inbox/current`}];typeof __APP_API_ORIGIN__==`string`&&__APP_API_ORIGIN__.length>0&&__APP_API_ORIGIN__;function p(e){return e.replace(/\/+$/,``)}const m=new o({projectName:`dimension-shop-browser`});function h(){let e=m.get(`apiUrl`),t=m.get(`apiKey`),n=m.get(`apiSecret`);if(!e||!t||!n)throw Error("Missing API configuration. Run `shop-browser config` or set TTK_FETCH_API_URL, TTK_FETCH_API_KEY, and TTK_FETCH_API_SECRET.");return{apiUrl:p(e),apiKey:t,apiSecret:n}}function g(e){e.apiUrl&&m.set(`apiUrl`,p(e.apiUrl)),e.apiKey&&m.set(`apiKey`,e.apiKey),e.apiSecret&&m.set(`apiSecret`,e.apiSecret)}function _(){let e=process.env.TTK_FETCH_API_URL,t=process.env.TTK_FETCH_API_KEY,n=process.env.TTK_FETCH_API_SECRET;e&&m.set(`apiUrl`,p(e)),t&&m.set(`apiKey`,t),n&&m.set(`apiSecret`,n)}function v(e){try{if(e.clear){m.clear(),i.success(`✅ Configuration cleared`);return}if(e.show){let e=m.store;i.info(`📋 Current configuration:`),console.log(JSON.stringify(e,null,2));return}_();let t=m.get(`apiUrl`),n=m.get(`apiKey`),r=m.get(`apiSecret`);(!t||!n||!r)&&(i.error(`❌ Missing configuration`),i.info(`Please set the following environment variables:`),i.info(` - TTK_FETCH_API_URL`),i.info(` - TTK_FETCH_API_KEY`),i.info(` - TTK_FETCH_API_SECRET`),i.info(`Or manually set them using:`),i.info(` shop-browser config:set apiUrl "your-url"`),i.info(` shop-browser config:set apiKey "your-key"`),i.info(` shop-browser config:set apiSecret "your-secret"`),process.exit(1));let a=t,o=n,s=r;i.success(`✅ Configuration loaded successfully`),i.info(`📋 Current configuration:`),i.info(` API URL: ${a}`),i.info(` API Key: ${o}`),i.info(` API Secret: ${c(s)}`);function c(e){return!e||e.length<8?`*`.repeat(e.length):`${e.slice(0,4)}${`*`.repeat(e.length-8)}${e.slice(-4)}`}}catch(e){i.error(`❌ Failed to manage configuration`),e instanceof Error?i.error(e.message):i.error(String(e)),process.exit(1)}}function y(e,t){try{[`apiUrl`,`apiKey`,`apiSecret`].includes(e)||(i.error(`❌ Invalid config key: ${e}`),i.info(`Valid keys: apiUrl, apiKey, apiSecret`),process.exit(1)),g({[e]:t}),i.success(`✅ Set ${e} successfully`)}catch(e){i.error(`❌ Failed to set configuration`),e instanceof Error?i.error(e.message):i.error(String(e)),process.exit(1)}}function b(e){return{"X-Api-Key":e.apiKey,"X-Api-Secret":e.apiSecret}}function x(e){return p(e.apiUrl)}async function S(e,t){let n=new URLSearchParams({q:t.trim()}),r=x(e),i=await fetch(`${r}/ttk-proxy/shops/search?${n}`,{method:`GET`,headers:b(e),signal:AbortSignal.timeout(15e3)});if(!i.ok){let e=await i.text();throw Error(`Shop search failed (${i.status}): ${e||i.statusText}`)}return(await i.json()).shops}async function C(e,t){let n=x(e),r=await fetch(`${n}/ttk-proxy/get-cookies`,{method:`POST`,headers:{"Content-Type":`application/json`,...b(e)},body:JSON.stringify({shopId:t}),signal:AbortSignal.timeout(15e3)});if(!r.ok){let e=await r.text();throw Error(`Could not fetch cookies (${r.status}): ${e||r.statusText}`)}return(await r.json()).cookies??[]}async function w(e){return S(h(),e)}async function T(e){return C(h(),e)}function E(){h()}function D(){let e=process.env.HEADLESS?.toLowerCase();return e===`true`||e===`1`}function O(){let e=process.env.EXECUTABLE_PATH?.trim();return e?.length?e:void 0}function k(){let e=process.env.REMOTE_DEBUGGING_PORT?.trim();return e?.length?e:void 0}async function A(){E();let e=await T((await l({message:`Select a shop:`,source:async(e,{signal:t})=>{let n=e?.trim();if(t.aborted||!n)return[];if(n.length<2)return[new c(`Enter at least 2 characters to search`)];await s(300);let r=await w(n).catch(e=>(console.error(e instanceof Error?e.message:e),[]));return t.aborted?[]:r.length===0?[new c(`No shops found — try another search`)]:r.map(e=>({name:`${e.name} (${e.slug})`,value:{id:e.id,slug:e.slug,name:e.name}}))}})).id);if(!Array.isArray(e)||e.length===0)throw Error(`No cookies returned for this shop. Check TTK proxy access for this shop.`);let t=e,n=await u({message:`Select the page you want to navigate to:`,choices:f.map(e=>({name:e.name,value:e.url}))}),r=k(),i=await d.launch({headless:D(),executablePath:O(),args:[`--no-sandbox`,`--disable-setuid-sandbox`,`--disable-popup-blocking`,`--disable-external-protocol-handling`,...r?[`--remote-debugging-port=${r}`]:[]]}),a=await i.newContext({viewport:null});await a.addCookies(t);let o=await a.newPage();await o.goto(n),console.warn(`Browser opened. Close the browser window to end the process.`),r&&console.warn(`DevTools endpoint: http://127.0.0.1:${r}`),o.on(`close`,()=>i.close()),process.on(`SIGINT`,()=>{console.warn(`
2
+ import{readFileSync as e}from"node:fs";import{dirname as t,join as n}from"node:path";import{fileURLToPath as r}from"node:url";import{logger as i}from"@rharkor/logger";import{program as a}from"commander";import"dotenv/config";import o from"conf";import{setTimeout as s}from"node:timers/promises";import{Separator as c,search as l,select as u}from"@inquirer/prompts";import{chromium as d}from"playwright";const f=[{id:`seller`,name:`Seller Center`,url:`https://seller-us.tiktok.com/homepage`},{id:`affiliate`,name:`Affiliate Center`,url:`https://affiliate-us.tiktok.com`},{id:`support`,name:`Support Messages`,url:`https://seller-us.tiktok.com/chat/inbox/current`}];typeof __APP_API_ORIGIN__==`string`&&__APP_API_ORIGIN__.length>0&&__APP_API_ORIGIN__;function p(e){return e.replace(/\/+$/,``)}const m=new o({projectName:`dimension-shop-browser`});function h(){let e=m.get(`apiUrl`),t=m.get(`apiKey`),n=m.get(`apiSecret`);if(!e||!t||!n)throw Error("Missing API configuration. Run `shop-browser config` or set TTK_FETCH_API_URL, TTK_FETCH_API_KEY, and TTK_FETCH_API_SECRET.");return{apiUrl:p(e),apiKey:t,apiSecret:n}}function g(e){e.apiUrl&&m.set(`apiUrl`,p(e.apiUrl)),e.apiKey&&m.set(`apiKey`,e.apiKey),e.apiSecret&&m.set(`apiSecret`,e.apiSecret)}function _(){let e=process.env.TTK_FETCH_API_URL,t=process.env.TTK_FETCH_API_KEY,n=process.env.TTK_FETCH_API_SECRET;e&&m.set(`apiUrl`,p(e)),t&&m.set(`apiKey`,t),n&&m.set(`apiSecret`,n)}function v(e){try{if(e.clear){m.clear(),i.success(`✅ Configuration cleared`);return}if(e.show){let e=m.store;i.info(`📋 Current configuration:`),console.log(JSON.stringify(e,null,2));return}_();let t=m.get(`apiUrl`),n=m.get(`apiKey`),r=m.get(`apiSecret`);(!t||!n||!r)&&(i.error(`❌ Missing configuration`),i.info(`Please set the following environment variables:`),i.info(` - TTK_FETCH_API_URL`),i.info(` - TTK_FETCH_API_KEY`),i.info(` - TTK_FETCH_API_SECRET`),i.info(`Or manually set them using:`),i.info(` shop-browser config:set apiUrl "your-url"`),i.info(` shop-browser config:set apiKey "your-key"`),i.info(` shop-browser config:set apiSecret "your-secret"`),process.exit(1));let a=t,o=n,s=r;i.success(`✅ Configuration loaded successfully`),i.info(`📋 Current configuration:`),i.info(` API URL: ${a}`),i.info(` API Key: ${o}`),i.info(` API Secret: ${c(s)}`);function c(e){return!e||e.length<8?`*`.repeat(e.length):`${e.slice(0,4)}${`*`.repeat(e.length-8)}${e.slice(-4)}`}}catch(e){i.error(`❌ Failed to manage configuration`),e instanceof Error?i.error(e.message):i.error(String(e)),process.exit(1)}}function y(e,t){try{[`apiUrl`,`apiKey`,`apiSecret`].includes(e)||(i.error(`❌ Invalid config key: ${e}`),i.info(`Valid keys: apiUrl, apiKey, apiSecret`),process.exit(1)),g({[e]:t}),i.success(`✅ Set ${e} successfully`)}catch(e){i.error(`❌ Failed to set configuration`),e instanceof Error?i.error(e.message):i.error(String(e)),process.exit(1)}}function b(e){return{"X-Api-Key":e.apiKey,"X-Api-Secret":e.apiSecret}}function x(e){return p(e.apiUrl)}async function S(e,t){let n=new URLSearchParams({q:t.trim()}),r=x(e),i=await fetch(`${r}/ttk-proxy/shops/search?${n}`,{method:`GET`,headers:b(e),signal:AbortSignal.timeout(15e3)});if(!i.ok){let e=await i.text();throw Error(`Shop search failed (${i.status}): ${e||i.statusText}`)}return(await i.json()).shops}async function C(e,t){let n=x(e),r=await fetch(`${n}/ttk-proxy/get-cookies`,{method:`POST`,headers:{"Content-Type":`application/json`,...b(e)},body:JSON.stringify({shopId:t}),signal:AbortSignal.timeout(15e3)});if(!r.ok){let e=await r.text();throw Error(`Could not fetch cookies (${r.status}): ${e||r.statusText}`)}return(await r.json()).cookies}async function w(e){return S(h(),e)}async function T(e){return C(h(),e)}function E(){h()}function D(){let e=process.env.HEADLESS?.toLowerCase();return e===`true`||e===`1`}function O(){let e=process.env.EXECUTABLE_PATH?.trim();return e?.length?e:void 0}function k(){let e=process.env.REMOTE_DEBUGGING_PORT?.trim();return e?.length?e:void 0}async function A(){E();let e=await T((await l({message:`Select a shop:`,source:async(e,{signal:t})=>{let n=e?.trim();if(t.aborted||!n)return[];if(n.length<2)return[new c(`Enter at least 2 characters to search`)];await s(300);let r=await w(n).catch(e=>(console.error(e instanceof Error?e.message:e),[]));return t.aborted?[]:r.length===0?[new c(`No shops found — try another search`)]:r.map(e=>({name:`${e.name} (${e.slug})`,value:{id:e.id,slug:e.slug,name:e.name}}))}})).id);if(!Array.isArray(e)||e.length===0)throw Error(`No cookies returned for this shop. Check TTK proxy access for this shop.`);let t=e,n=await u({message:`Select the page you want to navigate to:`,choices:f.map(e=>({name:e.name,value:e.url}))}),r=k(),i=await d.launch({headless:D(),executablePath:O(),args:[`--no-sandbox`,`--disable-setuid-sandbox`,`--disable-popup-blocking`,`--disable-external-protocol-handling`,...r?[`--remote-debugging-port=${r}`]:[]]}),a=await i.newContext({viewport:null});await a.addCookies(t);let o=await a.newPage();await o.goto(n),console.warn(`Browser opened. Close the browser window to end the process.`),r&&console.warn(`DevTools endpoint: http://127.0.0.1:${r}`),o.on(`close`,()=>i.close()),process.on(`SIGINT`,()=>{console.warn(`
3
3
  Received SIGINT. Closing browser...`),i.close()}),await new Promise(e=>i.on(`disconnected`,e)),console.warn(`Browser closed by user. Exiting...`),process.exit(0)}const j=n(t(r(import.meta.url)),`..`,`package.json`),M=JSON.parse(e(j,`utf8`));await i.init(),_(),a.name(`shop-browser`).description(`Open TikTok shop pages using TTK proxy cookies`).version(M.version),a.command(`config`).description(`Manage TTK Fetch API credentials`).option(`-s, --show`,`Show current configuration`).option(`-c, --clear`,`Clear all configuration`).action(e=>{v(e)}),a.command(`config:set`).description(`Set a configuration value`).argument(`<key>`,`Configuration key (apiUrl, apiKey, apiSecret)`).argument(`<value>`,`Configuration value`).action((e,t)=>{y(e,t)});const N=process.argv.slice(2),P=N[0];if(N.length===0)try{await A()}catch(e){i.error(e instanceof Error?e.message:String(e)),process.exit(1)}else P===`config`||P===`config:set`?a.parse(process.argv):P===`-h`||P===`--help`?(i.info(`\n${a.helpInformation()}`),i.info(`Run "${a.name()}" with no arguments to search for a shop and open Chromium with cookies.\n`)):P===`-V`||P===`--version`?i.info(M.version):(i.error(`Unknown argument: ${P??``}`),process.exit(1));export{};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dimension-studios/shop-browser",
3
- "version": "1.167.0",
3
+ "version": "1.168.0",
4
4
  "description": "Open TikTok shop pages in Chromium using TTK proxy cookies",
5
5
  "keywords": [
6
6
  "tiktok",
@@ -58,15 +58,15 @@
58
58
  "conf": "15.1.0",
59
59
  "dotenv": "17.4.2",
60
60
  "playwright": "1.61.1",
61
- "tsdown": "0.22.3",
61
+ "tsdown": "0.22.4",
62
62
  "webextension-polyfill": "0.12.0"
63
63
  },
64
64
  "devDependencies": {
65
- "@types/node": "24.13.2",
65
+ "@types/node": "24.13.3",
66
66
  "@types/webextension-polyfill": "0.12.5",
67
67
  "@typescript/native-preview": "7.0.0-dev.20260707.2",
68
68
  "dotenv-cli": "11.0.0",
69
69
  "tsx": "4.23.0",
70
- "vite": "8.1.3"
70
+ "vite": "8.1.4"
71
71
  }
72
72
  }