@dimension-studios/shop-browser 1.31.0-preprod-release.147
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 +110 -0
- package/bin/cli.js +6 -0
- package/dist/index.d.mts +1 -0
- package/dist/index.mjs +3 -0
- package/package.json +60 -0
package/README.md
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
# @dimension-studios/shop-browser
|
|
2
|
+
|
|
3
|
+
Interactive CLI to pick a TikTok shop (authorized for your API token), load cookies from the Dimension **TTK Fetch** API, open **Chromium** with Playwright, and navigate to common TikTok Seller / Affiliate URLs.
|
|
4
|
+
|
|
5
|
+
Uses the same credentials as **`@dimension-studios/ttk-proxy`**. Publishable tarball includes only compiled `dist/` and `bin/` — no database or internal monorepo code.
|
|
6
|
+
|
|
7
|
+
## Requirements
|
|
8
|
+
|
|
9
|
+
- Node.js ≥ 24 (matching the monorepo; see repo `engines`).
|
|
10
|
+
- Credentials for `/ttk-proxy/*` endpoints (API URL + key + secret).
|
|
11
|
+
- Backend support for **`GET /ttk-proxy/shops/search?q=`** (installed with the Node API that exposes TTK proxy).
|
|
12
|
+
|
|
13
|
+
## Installation (CLI users)
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
npm install -g @dimension-studios/shop-browser
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
Install Playwright browsers once:
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
npx playwright install chromium
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
If Chromium cannot launch, set `EXECUTABLE_PATH` to your Chrome/Chromium executable (documented below).
|
|
26
|
+
|
|
27
|
+
## First-time setup
|
|
28
|
+
|
|
29
|
+
Either set environment variables (e.g. in your shell profile) or persist them via the bundled config (same UX as `@dimension-studios/ttk-proxy`):
|
|
30
|
+
|
|
31
|
+
### Environment variables (recommended)
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
export TTK_FETCH_API_URL="https://your-node-api.example.com"
|
|
35
|
+
export TTK_FETCH_API_KEY="your-api-key"
|
|
36
|
+
export TTK_FETCH_API_SECRET="your-api-secret"
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
Then verify:
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
shop-browser config
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
### Save credentials with config:set
|
|
46
|
+
|
|
47
|
+
```bash
|
|
48
|
+
shop-browser config:set apiUrl "https://your-node-api.example.com"
|
|
49
|
+
shop-browser config:set apiKey "your-api-key"
|
|
50
|
+
shop-browser config:set apiSecret "your-api-secret"
|
|
51
|
+
|
|
52
|
+
shop-browser config --show
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
## Usage
|
|
56
|
+
|
|
57
|
+
Run with **no arguments** to start the flow:
|
|
58
|
+
|
|
59
|
+
```bash
|
|
60
|
+
shop-browser
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
1. Search for a shop by name or slug (at least **2 characters**). Results come from your token’s authorized shops only.
|
|
64
|
+
2. Choose a destination page (Seller Center, Affiliate Center, Support messages).
|
|
65
|
+
3. Close the browser window when done; the process exits.
|
|
66
|
+
|
|
67
|
+
### Optional environment
|
|
68
|
+
|
|
69
|
+
| Variable | Purpose |
|
|
70
|
+
|----------|--------|
|
|
71
|
+
| `HEADLESS` | If `true` or `1`, runs Playwright headless (default: visible window). |
|
|
72
|
+
| `EXECUTABLE_PATH` | Path to Chrome/Chromium if the bundled Playwright browser is not used. |
|
|
73
|
+
|
|
74
|
+
Copy `.env.example` to `.env` only for local development; do not commit real secrets.
|
|
75
|
+
|
|
76
|
+
### Help and version
|
|
77
|
+
|
|
78
|
+
```bash
|
|
79
|
+
shop-browser --help
|
|
80
|
+
shop-browser --version
|
|
81
|
+
shop-browser config --help
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
## Development (in this monorepo)
|
|
85
|
+
|
|
86
|
+
```bash
|
|
87
|
+
npm install
|
|
88
|
+
npm run build -w @dimension-studios/shop-browser
|
|
89
|
+
npm run type-check -w @dimension-studios/shop-browser
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
Run from source (expects env via `dotenv` / linked root `.env`):
|
|
93
|
+
|
|
94
|
+
```bash
|
|
95
|
+
npm run start -w @dimension-studios/shop-browser
|
|
96
|
+
# or from repo root:
|
|
97
|
+
npm run tools:isb
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
## Related packages
|
|
101
|
+
|
|
102
|
+
- **`@dimension-studios/ttk-proxy`** — call TTK proxy APIs from the terminal, including `ttk-proxy shops <query>` for debugging shop search.
|
|
103
|
+
|
|
104
|
+
## License
|
|
105
|
+
|
|
106
|
+
ISC
|
|
107
|
+
|
|
108
|
+
## Author
|
|
109
|
+
|
|
110
|
+
Dimension Studios
|
package/bin/cli.js
ADDED
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { };
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
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=new o({projectName:`dimension-shop-browser`});function p(){let e=f.get(`apiUrl`),t=f.get(`apiKey`),n=f.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:e,apiKey:t,apiSecret:n}}function m(e){e.apiUrl&&f.set(`apiUrl`,e.apiUrl),e.apiKey&&f.set(`apiKey`,e.apiKey),e.apiSecret&&f.set(`apiSecret`,e.apiSecret)}function h(){let e=process.env.TTK_FETCH_API_URL,t=process.env.TTK_FETCH_API_KEY,n=process.env.TTK_FETCH_API_SECRET;e&&f.set(`apiUrl`,e),t&&f.set(`apiKey`,t),n&&f.set(`apiSecret`,n)}function g(e){try{if(e.clear){f.clear(),i.success(`✅ Configuration cleared`);return}if(e.show){let e=f.store;i.info(`📋 Current configuration:`),console.log(JSON.stringify(e,null,2));return}h();let t=f.get(`apiUrl`),n=f.get(`apiKey`),r=f.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 _(e,t){try{[`apiUrl`,`apiKey`,`apiSecret`].includes(e)||(i.error(`❌ Invalid config key: ${e}`),i.info(`Valid keys: apiUrl, apiKey, apiSecret`),process.exit(1)),m({[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)}}async function v(e){let{apiUrl:t,apiKey:n,apiSecret:r}=p(),i=new URLSearchParams({q:e.trim()}),a=await fetch(`${t}/ttk-proxy/shops/search?${i}`,{method:`GET`,headers:{"X-Api-Key":n,"X-Api-Secret":r},signal:AbortSignal.timeout(15e3)});if(!a.ok){let e=await a.text();throw Error(`Shop search failed (${a.status}): ${e||a.statusText}`)}return(await a.json()).shops}async function y(e){let{apiUrl:t,apiKey:n,apiSecret:r}=p(),i=await fetch(`${t}/ttk-proxy/get-cookies`,{method:`POST`,headers:{"Content-Type":`application/json`,"X-Api-Key":n,"X-Api-Secret":r},body:JSON.stringify({shopId:e}),signal:AbortSignal.timeout(15e3)});if(!i.ok){let e=await i.text();throw Error(`Could not fetch cookies (${i.status}): ${e||i.statusText}`)}return(await i.json()).cookies??[]}const b=[{name:`TikTok Seller Center`,value:`https://seller-us.tiktok.com/homepage`},{name:`TikTok Affiliate Center`,value:`https://affiliate-us.tiktok.com`},{name:`TikTok Support Messages`,value:`https://seller-us.tiktok.com/chat/inbox/current`}];function x(){p()}function S(){let e=process.env.HEADLESS?.toLowerCase();return e===`true`||e===`1`}function C(){let e=process.env.EXECUTABLE_PATH?.trim();return e?.length?e:void 0}async function w(){x();let e=await y((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 v(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:[...b]}),r=await d.launch({headless:S(),executablePath:C(),args:[`--no-sandbox`,`--disable-setuid-sandbox`,`--disable-popup-blocking`,`--disable-external-protocol-handling`]}),i=await r.newContext({viewport:null});await i.addCookies(t);let a=await i.newPage();await a.goto(n),console.warn(`Browser opened. Close the browser window to end the process.`),a.on(`close`,()=>r.close()),process.on(`SIGINT`,()=>{console.warn(`
|
|
3
|
+
Received SIGINT. Closing browser...`),r.close()}),await new Promise(e=>r.on(`disconnected`,e)),console.warn(`Browser closed by user. Exiting...`),process.exit(0)}const T=n(t(r(import.meta.url)),`..`,`package.json`),E=JSON.parse(e(T,`utf8`));await i.init(),h(),a.name(`shop-browser`).description(`Open TikTok shop pages using TTK proxy cookies`).version(E.version),a.command(`config`).description(`Manage TTK Fetch API credentials`).option(`-s, --show`,`Show current configuration`).option(`-c, --clear`,`Clear all configuration`).action(e=>{g(e)}),a.command(`config:set`).description(`Set a configuration value`).argument(`<key>`,`Configuration key (apiUrl, apiKey, apiSecret)`).argument(`<value>`,`Configuration value`).action((e,t)=>{_(e,t)});const D=process.argv.slice(2),O=D[0];if(D.length===0)try{await w()}catch(e){i.error(e instanceof Error?e.message:String(e)),process.exit(1)}else O===`config`||O===`config:set`?a.parse(process.argv):O===`-h`||O===`--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`)):O===`-V`||O===`--version`?i.info(E.version):(i.error(`Unknown argument: ${O??``}`),process.exit(1));export{};
|
package/package.json
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@dimension-studios/shop-browser",
|
|
3
|
+
"version": "1.31.0-preprod-release.147",
|
|
4
|
+
"description": "Open TikTok shop pages in Chromium using TTK proxy cookies",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"tiktok",
|
|
7
|
+
"shop",
|
|
8
|
+
"browser",
|
|
9
|
+
"playwright",
|
|
10
|
+
"cli"
|
|
11
|
+
],
|
|
12
|
+
"author": "Dimension Studios",
|
|
13
|
+
"license": "ISC",
|
|
14
|
+
"repository": {
|
|
15
|
+
"type": "git",
|
|
16
|
+
"url": "https://github.com/dimension-studios/dimension.git",
|
|
17
|
+
"directory": "packages/shop-browser"
|
|
18
|
+
},
|
|
19
|
+
"publishConfig": {
|
|
20
|
+
"access": "public"
|
|
21
|
+
},
|
|
22
|
+
"type": "module",
|
|
23
|
+
"bin": {
|
|
24
|
+
"shop-browser": "./bin/cli.js"
|
|
25
|
+
},
|
|
26
|
+
"files": [
|
|
27
|
+
"dist",
|
|
28
|
+
"bin",
|
|
29
|
+
"README.md"
|
|
30
|
+
],
|
|
31
|
+
"exports": {
|
|
32
|
+
".": {
|
|
33
|
+
"types": "./dist/index.d.mts",
|
|
34
|
+
"import": "./dist/index.mjs"
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
"scripts": {
|
|
38
|
+
"build": "tsdown && chmod +x bin/cli.js",
|
|
39
|
+
"clean": "rm -rf dist",
|
|
40
|
+
"dev": "tsdown --watch",
|
|
41
|
+
"start": "dotenv -- tsx src/index.ts",
|
|
42
|
+
"type-check": "tsgo --noEmit",
|
|
43
|
+
"prepublishOnly": "npm run build"
|
|
44
|
+
},
|
|
45
|
+
"dependencies": {
|
|
46
|
+
"@rharkor/logger": "1.3.3",
|
|
47
|
+
"commander": "14.0.3",
|
|
48
|
+
"conf": "15.1.0",
|
|
49
|
+
"dotenv": "17.4.2",
|
|
50
|
+
"@inquirer/prompts": "8.4.1",
|
|
51
|
+
"playwright": "1.59.1",
|
|
52
|
+
"tsdown": "0.21.7"
|
|
53
|
+
},
|
|
54
|
+
"devDependencies": {
|
|
55
|
+
"@types/node": "24.12.2",
|
|
56
|
+
"dotenv-cli": "11.0.0",
|
|
57
|
+
"tsx": "4.21.0",
|
|
58
|
+
"@typescript/native-preview": "7.0.0-dev.20260415.1"
|
|
59
|
+
}
|
|
60
|
+
}
|