website-api 1.0.3 → 1.0.4

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/bin/cli.js CHANGED
@@ -1,2 +1,2 @@
1
1
  #!/usr/bin/env node
2
- import{readFileSync as o}from"node:fs";import{dirname as e,join as r}from"node:path";import{fileURLToPath as n}from"node:url";import{program as t}from"commander";import s from"chalk";import i from"cli-table3";import{getDefaultChromeDir as l}from"chrome-tools";import{queryWebsite as c,websites as a,loadAdapters as p}from"../src/website-api.js";const d=r(e(n(import.meta.url)),"..","..","package.json"),{version:m}=JSON.parse(o(d,"utf8"));process.on("unhandledRejection",()=>{console.error("No login found in browser"),process.exit(1)}),t.name("website-api").description("CLI to query website APIs using decrypted Chrome cookies on macOS").version(m),t.option("--profile <name>","specific Chrome profile directory (e.g., 'Default', 'Profile 1')").option("--current-profile","Show the currently resolved/selected Chrome profile directory and name").option("-u, --user-agent <string>","custom User-Agent header for HTTP requests"),t.command("list").description("List all supported website API adapters").action(async()=>{await p(),console.log(s.bold.green("\n🌐 Supported Website APIs:\n"));const o=new i({head:[s.bold.cyan("ID"),s.bold.cyan("Name"),s.bold.cyan("Domain"),s.bold.cyan("Description")],colWidths:[18,25,20,50],wordWrap:!0,style:{head:[],border:[]}});for(const e of a)o.push([s.yellow(e.id),e.name,s.underline(e.domain),e.description]);console.log(o.toString()),console.log(`\nTo run an API query, execute: ${s.bold.cyan("npx website-api <id>")}\n`)}),t.argument("[website]","website ID or domain to query (e.g. 'chatgpt.com')").action(async o=>{const e=t.opts();if(e.currentProfile){const o=process.env.PROFILE_PATH||process.env.CHROME_PROFILE_PATH||l(),r=e.profile||process.env.PROFILE_NAME||"Default";return console.log(s.bold.green("\nšŸ‘¤ Currently Resolved Profile:\n")),console.log(` ${s.bold("Path:")} ${o}`),void console.log(` ${s.bold("Name:")} ${r}\n`)}if(o)try{const r=await c(o,{profile:e.profile,userAgent:e.userAgent});console.log(JSON.stringify(r,null,2))}catch(o){console.error("No login found in browser"),process.exit(1)}else t.outputHelp()}),t.parse(process.argv);
2
+ import{readFileSync as o}from"node:fs";import{dirname as e,join as r}from"node:path";import{fileURLToPath as n}from"node:url";import{program as t}from"commander";import s from"chalk";import i from"cli-table3";import{getDefaultChromeDir as c}from"chrome-tools";import{queryWebsite as l,websites as a,loadAdapters as p}from"../src/website-api.js";const d=r(e(n(import.meta.url)),"..","..","package.json"),{version:m}=JSON.parse(o(d,"utf8"));process.on("unhandledRejection",o=>{console.error(o instanceof Error?o.message:"command not found"),process.exit(1)}),t.name("website-api").description("CLI to query website APIs using decrypted Chrome cookies on macOS").version(m),t.option("--profile <name>","specific Chrome profile directory (e.g., 'Default', 'Profile 1')").option("--current-profile","Show the currently resolved/selected Chrome profile directory and name").option("-u, --user-agent <string>","custom User-Agent header for HTTP requests"),t.command("list").description("List all supported website API adapters").action(async()=>{await p(),console.log(s.bold.green("\n🌐 Supported Website APIs:\n"));const o=new i({head:[s.bold.cyan("ID"),s.bold.cyan("Name"),s.bold.cyan("Domain"),s.bold.cyan("Description")],colWidths:[18,25,20,50],wordWrap:!0,style:{head:[],border:[]}});for(const e of a)o.push([s.yellow(e.id),e.name,s.underline(e.domain),e.description]);console.log(o.toString()),console.log(`\nTo run an API query, execute: ${s.bold.cyan("npx website-api <id>")}\n`)}),t.argument("[website]","website ID or domain to query (e.g. 'chatgpt.com')").action(async o=>{const e=t.opts();if(e.currentProfile){const o=process.env.PROFILE_PATH||process.env.CHROME_PROFILE_PATH||c(),r=e.profile||process.env.PROFILE_NAME||"Default";return console.log(s.bold.green("\nšŸ‘¤ Currently Resolved Profile:\n")),console.log(` ${s.bold("Path:")} ${o}`),void console.log(` ${s.bold("Name:")} ${r}\n`)}if(o)try{const r=await l(o,{profile:e.profile,userAgent:e.userAgent});console.log(JSON.stringify(r,null,2))}catch(o){console.error(o instanceof Error?o.message:"command not found"),process.exit(1)}else t.outputHelp()}),t.parse(process.argv);
@@ -1 +1 @@
1
- import{readdirSync as o}from"node:fs";import{dirname as e,join as r}from"node:path";import{fileURLToPath as t,pathToFileURL as i}from"node:url";import{getCookies as n}from"chrome-tools";import{loadEnv as s}from"./env.js";import{createUniversalAdapter as a}from"./universal-adapter.js";s();const c=e(t(import.meta.url)),f=r(c,"website");export let websites=[];export async function loadAdapters(){if(!(websites.length>0))try{const e=o(f,{withFileTypes:!0});for(const t of e){if(!t.isDirectory())continue;const e=r(f,t.name),n=o(e).find(o=>o.endsWith("-adapter.js"));if(!n)continue;const s=i(r(e,n)).href,a=(await import(s)).default;a?.id&&websites.push(a)}}catch(o){}}export function getWebsite(o){if(!o)return null;const e=o.toLowerCase().trim();return websites.find(o=>o.id.toLowerCase()===e||o.id.toLowerCase().replace(".com","")===e)??null}export async function queryWebsite(o,e={}){await loadAdapters();const r=process.env.PROFILE_PATH||process.env.CHROME_PROFILE_PATH||void 0,t=e.profile||process.env.PROFILE_NAME||void 0;let i,s=getWebsite(o);if(!s&&(s=a(o),!s))throw new Error("No login found in browser");try{i=n({chromeDir:r,profile:t,domain:s.domain,decrypt:!0})}catch{throw new Error("No login found in browser")}if(!i||0===i.length)throw new Error("No login found in browser");return s.fetchData(i,e)}
1
+ import{readdirSync as t}from"node:fs";import{dirname as o,join as e}from"node:path";import{fileURLToPath as r,pathToFileURL as n}from"node:url";import{getCookies as i}from"chrome-tools";import{loadEnv as s}from"./env.js";import{createUniversalAdapter as c}from"./universal-adapter.js";s();const a=o(r(import.meta.url)),f=e(a,"website");export let websites=[];export async function loadAdapters(){if(!(websites.length>0))try{const o=t(f,{withFileTypes:!0});for(const r of o){if(!r.isDirectory())continue;const o=e(f,r.name),i=t(o).find(t=>t.endsWith("-adapter.js"));if(!i)continue;const s=n(e(o,i)).href,c=(await import(s)).default;c?.id&&websites.push(c)}}catch(t){}}export function getWebsite(t){if(!t)return null;const o=t.toLowerCase().trim();return websites.find(t=>t.id.toLowerCase()===o||t.id.toLowerCase().replace(".com","")===o)??null}export async function queryWebsite(t,o={}){await loadAdapters();const e=process.env.PROFILE_PATH||process.env.CHROME_PROFILE_PATH||void 0,r=o.profile||process.env.PROFILE_NAME||void 0;let n,s=getWebsite(t);if(!s){if(!function(t){return t.startsWith("http://")||t.startsWith("https://")||t.includes(".")||t.includes("/")||t.includes(":")}(t))throw new Error("command not found");if(s=c(t),!s)throw new Error("command not found")}try{n=i({chromeDir:e,profile:r,domain:s.domain,decrypt:!0})}catch{throw new Error("No login found in browser")}if(!n||0===n.length)throw new Error("No login found in browser");return s.fetchData(n,o)}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "website-api",
3
- "version": "1.0.3",
3
+ "version": "1.0.4",
4
4
  "description": "CLI and library to fetch website API data",
5
5
  "main": "./dist/src/website-api.js",
6
6
  "type": "module",