website-api 1.0.6 → 1.1.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/dist/bin/cli.js +1 -1
- package/dist/src/capabilities/browser.d.ts +23 -0
- package/dist/src/capabilities/browser.js +1 -0
- package/dist/src/capabilities/cookies.d.ts +24 -0
- package/dist/src/capabilities/cookies.js +1 -0
- package/dist/src/capabilities/download.d.ts +11 -0
- package/dist/src/capabilities/download.js +1 -0
- package/dist/src/capabilities/fingerprint.d.ts +14 -0
- package/dist/src/capabilities/fingerprint.js +1 -0
- package/dist/src/capabilities/http.d.ts +18 -0
- package/dist/src/capabilities/http.js +1 -0
- package/dist/src/{util → capabilities/login}/login-helper.d.ts +12 -5
- package/dist/src/capabilities/login/login-helper.js +1 -0
- package/dist/src/capabilities/login/login-strategy.d.ts +15 -0
- package/dist/src/capabilities/login/login-strategy.js +1 -0
- package/dist/src/core/context.d.ts +24 -0
- package/dist/src/core/context.js +1 -0
- package/dist/src/core/define-site.d.ts +9 -0
- package/dist/src/core/define-site.js +1 -0
- package/dist/src/core/loader.d.ts +21 -0
- package/dist/src/core/loader.js +1 -0
- package/dist/src/core/runtime.d.ts +20 -0
- package/dist/src/core/runtime.js +1 -0
- package/dist/src/{website → sites}/chase.com/download-helper.d.ts +5 -4
- package/dist/src/sites/chase.com/download-helper.js +1 -0
- package/dist/src/sites/chase.com/index.d.ts +2 -0
- package/dist/src/sites/chase.com/index.js +1 -0
- package/dist/src/sites/chatgpt.com/index.d.ts +10 -0
- package/dist/src/sites/chatgpt.com/index.js +1 -0
- package/dist/src/sites/cursor.com/index.d.ts +6 -0
- package/dist/src/sites/cursor.com/index.js +1 -0
- package/dist/src/sites/gemini.google.com/index.d.ts +5 -0
- package/dist/src/sites/gemini.google.com/index.js +1 -0
- package/dist/src/sites/google.com/google-helpers.d.ts +24 -0
- package/dist/src/sites/google.com/google-helpers.js +1 -0
- package/dist/src/sites/google.com/index.d.ts +2 -0
- package/dist/src/sites/google.com/index.js +1 -0
- package/dist/src/sites/ollama.com/index.d.ts +9 -0
- package/dist/src/sites/ollama.com/index.js +1 -0
- package/dist/src/sites/perplexity.ai/index.d.ts +50 -0
- package/dist/src/sites/perplexity.ai/index.js +1 -0
- package/dist/src/sites/pseg.com/index.d.ts +2 -0
- package/dist/src/sites/pseg.com/index.js +1 -0
- package/dist/src/sites/pseg.com/pseg-helpers.d.ts +13 -0
- package/dist/src/sites/pseg.com/pseg-helpers.js +1 -0
- package/dist/src/types.d.ts +194 -46
- package/dist/src/util/args-parser.js +1 -1
- package/dist/src/website-api.d.ts +7 -34
- package/dist/src/website-api.js +1 -1
- package/package.json +10 -1
- package/dist/src/adapter/base-adapter.d.ts +0 -41
- package/dist/src/adapter/base-adapter.js +0 -1
- package/dist/src/adapter/playwright-attatch-chrome-adapter.d.ts +0 -16
- package/dist/src/adapter/playwright-attatch-chrome-adapter.js +0 -1
- package/dist/src/adapter/playwright-core.d.ts +0 -35
- package/dist/src/adapter/playwright-core.js +0 -1
- package/dist/src/adapter/universal-adapter.d.ts +0 -10
- package/dist/src/adapter/universal-adapter.js +0 -1
- package/dist/src/util/login-helper.js +0 -1
- package/dist/src/website/chase.com/account-helper.d.ts +0 -20
- package/dist/src/website/chase.com/account-helper.js +0 -1
- package/dist/src/website/chase.com/chase-adapter.d.ts +0 -43
- package/dist/src/website/chase.com/chase-adapter.js +0 -1
- package/dist/src/website/chase.com/download-helper.js +0 -1
- package/dist/src/website/chatgpt.com/chatgpt-adapter.d.ts +0 -11
- package/dist/src/website/chatgpt.com/chatgpt-adapter.js +0 -1
- package/dist/src/website/cursor.com/cursor-adapter.d.ts +0 -6
- package/dist/src/website/cursor.com/cursor-adapter.js +0 -1
- package/dist/src/website/example.com/example-adapter.d.ts +0 -12
- package/dist/src/website/example.com/example-adapter.js +0 -1
- package/dist/src/website/gemini.google.com/gemini-adapter.d.ts +0 -12
- package/dist/src/website/gemini.google.com/gemini-adapter.js +0 -1
- package/dist/src/website/google.com/google-adapter.d.ts +0 -62
- package/dist/src/website/google.com/google-adapter.js +0 -1
- package/dist/src/website/ollama.com/ollama-adapter.d.ts +0 -2
- package/dist/src/website/ollama.com/ollama-adapter.js +0 -1
- package/dist/src/website/perplexity.ai/perplexity-adapter.d.ts +0 -2
- package/dist/src/website/perplexity.ai/perplexity-adapter.js +0 -1
- package/dist/src/website/pseg.com/pseg-adapter.d.ts +0 -45
- package/dist/src/website/pseg.com/pseg-adapter.js +0 -1
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export interface PsegProperty {
|
|
2
|
+
propertyId: string;
|
|
3
|
+
propertyType: string;
|
|
4
|
+
title: string;
|
|
5
|
+
owner: string;
|
|
6
|
+
address: string;
|
|
7
|
+
isCurrent: boolean;
|
|
8
|
+
}
|
|
9
|
+
export declare function normalizeInterval(value: string): string;
|
|
10
|
+
export declare function intervalToValue(interval: string): string;
|
|
11
|
+
export declare function inferServiceTypeFromPropertyTitle(title: string): "Gas" | "Electric";
|
|
12
|
+
export declare function extractAddressNumber(address: string): string;
|
|
13
|
+
export declare function formatPropertyLabel(property: Omit<PsegProperty, "isCurrent">): string;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const e={15:"15-Minute","15-minute":"15-Minute",30:"30-Minute","30-minute":"30-Minute",hourly:"Hourly",daily:"Daily",weekly:"Weekly",monthly:"Monthly",billing:"Billing"},r={"15-Minute":"3","30-Minute":"4",Hourly:"5",Daily:"6",Weekly:"8",Monthly:"9",Billing:"7"};export function normalizeInterval(r){const t=String(r||"").trim().toLowerCase(),n=e[t];if(!n)throw new Error(`Invalid interval: ${r}. Use 15, 30, hourly, daily, weekly, monthly, or billing.`);return n}export function intervalToValue(e){return r[e]}export function inferServiceTypeFromPropertyTitle(e){if(/\bgas\b/i.test(e))return"Gas";if(/\belectric\b/i.test(e))return"Electric";throw new Error(`Could not infer service type from property title: ${e}`)}export function extractAddressNumber(e){const r=String(e||"").match(/^(\d+)/);return r?r[1]:""}export function formatPropertyLabel(e){const r=String(e.title||"").trim();if(r)return r;const t=e.propertyType||inferServiceTypeFromPropertyTitle(e.title);return`${extractAddressNumber(e.address)||e.propertyId||"Unknown"} ${t}`}
|
package/dist/src/types.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { CookieEntry } from "chrome-tools";
|
|
2
|
+
import type { Page } from "playwright-core";
|
|
2
3
|
export interface ParameterDefinition {
|
|
3
4
|
/** Option name (e.g. "model", "timeout"). Matches option flag `--<name>`. */
|
|
4
5
|
name: string;
|
|
@@ -23,8 +24,137 @@ export interface PositionalDefinition {
|
|
|
23
24
|
/** If true, collects all remaining positional arguments. */
|
|
24
25
|
variadic?: boolean;
|
|
25
26
|
}
|
|
27
|
+
/** Resolved Chrome credentials for the target site. */
|
|
28
|
+
export interface Credentials {
|
|
29
|
+
username: string;
|
|
30
|
+
password: string;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Context handed to a login strategy by the framework.
|
|
34
|
+
*
|
|
35
|
+
* `getCredentials` is a lazy thunk: it is only invoked once the strategy decides
|
|
36
|
+
* a login is actually required, so an already-authenticated session never
|
|
37
|
+
* triggers a credential lookup (and never fails when no password is saved).
|
|
38
|
+
*/
|
|
39
|
+
export interface LoginContext {
|
|
40
|
+
page: Page;
|
|
41
|
+
debug?: boolean;
|
|
42
|
+
getCredentials: () => Credentials;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* A pluggable authentication approach. Implementations must be idempotent:
|
|
46
|
+
* detect the current session state and only log in when needed.
|
|
47
|
+
*/
|
|
48
|
+
export interface LoginStrategy {
|
|
49
|
+
/** @returns true if a login was performed, false if already logged in. */
|
|
50
|
+
ensureLoggedIn(ctx: LoginContext): Promise<boolean>;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Declarative configuration for a standard single-page username/password form.
|
|
54
|
+
* Only selectors / URLs — no credentials, no business logic. A site may pass
|
|
55
|
+
* this plain object as `auth`; the framework wraps it in a FormLoginStrategy.
|
|
56
|
+
*/
|
|
57
|
+
export interface FormLoginConfig {
|
|
58
|
+
/** Discriminator so a config object is distinguishable from a strategy. */
|
|
59
|
+
type?: "form";
|
|
60
|
+
/** URL to land on before checking session state (e.g. the dashboard). */
|
|
61
|
+
intendedUrl?: string;
|
|
62
|
+
/** Optional explicit login page URL. */
|
|
63
|
+
loginUrl?: string;
|
|
64
|
+
/** Primary username/email input selector. */
|
|
65
|
+
emailSelector: string;
|
|
66
|
+
/** Primary password input selector. */
|
|
67
|
+
passwordSelector: string;
|
|
68
|
+
/** Submit button selector. */
|
|
69
|
+
submitButtonSelector: string;
|
|
70
|
+
/** Site-specific fallback selectors, tried after the primary if not visible. */
|
|
71
|
+
usernameSelectors?: string[];
|
|
72
|
+
passwordSelectors?: string[];
|
|
73
|
+
submitSelectors?: string[];
|
|
74
|
+
/** Selector used to detect a visible login form (defaults to a password input). */
|
|
75
|
+
pwdSelector?: string;
|
|
76
|
+
/** Selectors that, when visible, indicate an already-authenticated dashboard. */
|
|
77
|
+
dashboardSelectors?: string[];
|
|
78
|
+
/** Delay before submitting, in ms. */
|
|
79
|
+
delayMs?: number;
|
|
80
|
+
/** URL pattern to await after submit (defaults to intendedUrl). */
|
|
81
|
+
expectedRedirectUrlPattern?: string;
|
|
82
|
+
}
|
|
83
|
+
export interface FingerprintConfig {
|
|
84
|
+
/** Override navigator.userAgent / UA string used by the browser session. */
|
|
85
|
+
userAgent?: string;
|
|
86
|
+
/** navigator.languages (e.g. ["en-US", "en"]). */
|
|
87
|
+
languages?: string[];
|
|
88
|
+
/** navigator.platform (e.g. "MacIntel"). */
|
|
89
|
+
platform?: string;
|
|
90
|
+
/** Hardware concurrency reported to the page. */
|
|
91
|
+
hardwareConcurrency?: number;
|
|
92
|
+
/** Device memory (GB) reported to the page. */
|
|
93
|
+
deviceMemory?: number;
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* `"stealth"` applies the default anti-bot evasion profile, `false` disables all
|
|
97
|
+
* fingerprint shaping, and an object customizes individual fields.
|
|
98
|
+
*/
|
|
99
|
+
export type FingerprintOption = "stealth" | false | FingerprintConfig;
|
|
100
|
+
export interface SSEResult {
|
|
101
|
+
status: number;
|
|
102
|
+
contentType: string;
|
|
103
|
+
/** Parsed JSON payload of every `data:` frame (non-JSON frames are skipped). */
|
|
104
|
+
frames: any[];
|
|
105
|
+
/** The raw, undecoded stream body. */
|
|
106
|
+
raw: string;
|
|
107
|
+
}
|
|
108
|
+
export interface HttpCapability {
|
|
109
|
+
/** GET (or `init.method`) and parse JSON. Cookie + User-Agent auto-injected. */
|
|
110
|
+
json(url: string, init?: RequestInit): Promise<any>;
|
|
111
|
+
/** Fetch and return the response body as text. */
|
|
112
|
+
text(url: string, init?: RequestInit): Promise<string>;
|
|
113
|
+
/** Alias of `text`, semantically for HTML documents. */
|
|
114
|
+
html(url: string, init?: RequestInit): Promise<string>;
|
|
115
|
+
/** Fetch a Server-Sent-Events stream and collect its frames. */
|
|
116
|
+
sse(url: string, init?: RequestInit): Promise<SSEResult>;
|
|
117
|
+
/** Escape hatch: the raw Response plus its already-read text body. */
|
|
118
|
+
raw(url: string, init?: RequestInit): Promise<{
|
|
119
|
+
response: Response;
|
|
120
|
+
text: string;
|
|
121
|
+
}>;
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* The single object every site's `run()` receives. Each capability is lazy:
|
|
125
|
+
* touch `ctx.browser()` and Chrome is launched; never touch it and it isn't.
|
|
126
|
+
* The runtime owns setup and teardown — sites never manage lifecycle.
|
|
127
|
+
*/
|
|
128
|
+
export interface SiteContext {
|
|
129
|
+
/** The site being run. */
|
|
130
|
+
readonly site: Site;
|
|
131
|
+
/** Cookie/credential domain for this site. */
|
|
132
|
+
readonly domain: string;
|
|
133
|
+
/** The parsed query options (CLI flags + positionals). */
|
|
134
|
+
readonly options: QueryOptions;
|
|
135
|
+
/** Convenience for `!!options.debug`. */
|
|
136
|
+
readonly debug: boolean;
|
|
137
|
+
/** Resolved output directory for `save()`, or null to use cwd. */
|
|
138
|
+
readonly outDir: string | null;
|
|
139
|
+
/** Resolve decrypted Chrome cookies for `domain` (lazy, memoized). */
|
|
140
|
+
cookies(): CookieEntry[];
|
|
141
|
+
/** Cookies as a `name=value; ...` header string. */
|
|
142
|
+
cookieString(): string;
|
|
143
|
+
/** Resolve a saved Chrome username/password for `domain`. */
|
|
144
|
+
credentials(): Credentials;
|
|
145
|
+
/** Resolve the User-Agent (options → env → default). */
|
|
146
|
+
userAgent(): string;
|
|
147
|
+
/** HTTP capability with cookie + User-Agent auto-injection. */
|
|
148
|
+
readonly http: HttpCapability;
|
|
149
|
+
/** Connect to Chrome over CDP, applying fingerprint + auth. Memoized. */
|
|
150
|
+
browser(): Promise<Page>;
|
|
151
|
+
/** Sugar for `(await browser()).evaluate(fn)`. */
|
|
152
|
+
eval<T>(fn: () => T | Promise<T>): Promise<T>;
|
|
153
|
+
/** Write a file to `outDir` (or cwd) and return its absolute path. */
|
|
154
|
+
save(filename: string, content: string | Buffer): Promise<string>;
|
|
155
|
+
}
|
|
26
156
|
/**
|
|
27
|
-
* Defines an API endpoint
|
|
157
|
+
* Defines an API endpoint for the default declarative fetch flow.
|
|
28
158
|
*/
|
|
29
159
|
export interface Endpoint {
|
|
30
160
|
/** Full URL of the API endpoint. */
|
|
@@ -33,72 +163,90 @@ export interface Endpoint {
|
|
|
33
163
|
method?: string;
|
|
34
164
|
/** Additional headers to include in the request. */
|
|
35
165
|
headers?: Record<string, string>;
|
|
36
|
-
/**
|
|
37
|
-
|
|
38
|
-
* Use "html" for text/html responses that need parsing.
|
|
39
|
-
* Use "sse" for server-sent event stream responses.
|
|
40
|
-
*/
|
|
41
|
-
responseType?: "auto" | "json" | "text" | "html" | "sse";
|
|
166
|
+
/** Expected response body type. Defaults to auto-detect from content-type. */
|
|
167
|
+
responseType?: "auto" | "json" | "text" | "html";
|
|
42
168
|
/** Optional post-processing step for the parsed response body. */
|
|
43
|
-
transform?: (
|
|
169
|
+
transform?: (body: unknown, ctx: SiteContext) => unknown | Promise<unknown>;
|
|
44
170
|
}
|
|
45
171
|
/**
|
|
46
|
-
*
|
|
47
|
-
*
|
|
48
|
-
*
|
|
172
|
+
* The minimal, declarative shape an author writes. A site is either:
|
|
173
|
+
* • declarative — set `endpoints` and get an automatic fetch flow, or
|
|
174
|
+
* • imperative — set `run(ctx)` and drive capabilities directly.
|
|
175
|
+
*
|
|
176
|
+
* External sites in the user's extensions folder export a plain object of this
|
|
177
|
+
* shape as their default export — no imports from the package are required.
|
|
49
178
|
*/
|
|
50
|
-
export interface
|
|
51
|
-
/** Unique identifier, typically
|
|
179
|
+
export interface SiteDef {
|
|
180
|
+
/** Unique identifier, typically a slug (e.g. "cursor-usage"). */
|
|
52
181
|
id: string;
|
|
53
|
-
/** Human-readable name
|
|
182
|
+
/** Human-readable name. */
|
|
54
183
|
name: string;
|
|
55
|
-
/** Cookie domain
|
|
184
|
+
/** Cookie/credential domain (e.g. "cursor.com"). */
|
|
56
185
|
domain: string;
|
|
57
|
-
/** Short description of what data this
|
|
186
|
+
/** Short description of what data this site fetches. */
|
|
58
187
|
description: string;
|
|
59
|
-
/**
|
|
60
|
-
|
|
61
|
-
/**
|
|
62
|
-
|
|
63
|
-
/**
|
|
64
|
-
|
|
65
|
-
/**
|
|
188
|
+
/** Transport used to reach the site. Defaults to "http". */
|
|
189
|
+
transport?: "http" | "browser";
|
|
190
|
+
/** Whether valid cookies are required. Defaults to "required". */
|
|
191
|
+
cookies?: "required" | "optional";
|
|
192
|
+
/** Browser fingerprint profile (browser transport only). Defaults to "stealth". */
|
|
193
|
+
fingerprint?: FingerprintOption;
|
|
194
|
+
/**
|
|
195
|
+
* Keep a tab opened by this site open after the run finishes, instead of
|
|
196
|
+
* closing it on teardown. Use for login sites so the authenticated session
|
|
197
|
+
* (and any 2FA state) stays warm for the next command. Defaults to false.
|
|
198
|
+
* The `--keep-open` CLI flag overrides this per-invocation.
|
|
199
|
+
*/
|
|
200
|
+
keepBrowserOpen?: boolean;
|
|
201
|
+
/** Declarative login config or a custom strategy (browser transport). */
|
|
202
|
+
auth?: LoginStrategy | FormLoginConfig;
|
|
203
|
+
/** Declares custom CLI flags for this site. */
|
|
66
204
|
parameters?: ParameterDefinition[];
|
|
67
|
-
/** Declares expected positional arguments for this
|
|
205
|
+
/** Declares expected positional arguments for this site. */
|
|
68
206
|
positionals?: PositionalDefinition[];
|
|
207
|
+
/** Declarative single-fetch flow. First endpoint is used. */
|
|
208
|
+
endpoints?: Endpoint[];
|
|
209
|
+
/** Imperative flow. Receives the full capability context. */
|
|
210
|
+
run?: (ctx: SiteContext) => unknown | Promise<unknown>;
|
|
69
211
|
}
|
|
70
212
|
/**
|
|
71
|
-
* A fully-
|
|
213
|
+
* A normalized, fully-defaulted site produced by `defineSite()`.
|
|
72
214
|
*/
|
|
73
|
-
export interface
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
215
|
+
export interface Site {
|
|
216
|
+
id: string;
|
|
217
|
+
name: string;
|
|
218
|
+
domain: string;
|
|
219
|
+
description: string;
|
|
220
|
+
transport: "http" | "browser";
|
|
221
|
+
cookies: "required" | "optional";
|
|
222
|
+
fingerprint: FingerprintOption;
|
|
223
|
+
keepBrowserOpen: boolean;
|
|
224
|
+
auth?: LoginStrategy;
|
|
225
|
+
parameters: ParameterDefinition[];
|
|
226
|
+
positionals: PositionalDefinition[];
|
|
227
|
+
/** URL the browser transport lands on (from endpoints[0] or https://domain). */
|
|
228
|
+
landingUrl: string;
|
|
229
|
+
run: (ctx: SiteContext) => Promise<unknown>;
|
|
230
|
+
/** Set by the loader: where this site was discovered. */
|
|
231
|
+
origin?: "bundled" | "extension";
|
|
232
|
+
/** Marker used to detect an already-normalized site. */
|
|
233
|
+
readonly __site: true;
|
|
91
234
|
}
|
|
92
235
|
/**
|
|
93
|
-
* Options passed when querying a
|
|
236
|
+
* Options passed when querying a site. CLI flags and positionals land here as
|
|
237
|
+
* camelCase keys (e.g. `--out-dir` → `outDir`).
|
|
94
238
|
*/
|
|
95
239
|
export interface QueryOptions {
|
|
96
240
|
/** Chrome profile directory name (e.g. "Default", "Profile 1"). */
|
|
97
241
|
profile?: string;
|
|
242
|
+
/** Chrome profile path override. */
|
|
243
|
+
profilePath?: string;
|
|
98
244
|
/** Custom User-Agent header for HTTP requests. */
|
|
99
245
|
userAgent?: string;
|
|
100
|
-
/** When true, print full HTTP request
|
|
246
|
+
/** When true, print full HTTP request/response details for debugging. */
|
|
101
247
|
debug?: boolean;
|
|
102
|
-
/**
|
|
248
|
+
/** Directory to write downloads to. */
|
|
249
|
+
outDir?: string;
|
|
250
|
+
/** Allows passing custom site-specific parameters. */
|
|
103
251
|
[key: string]: any;
|
|
104
252
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
const e=[{name:"profile",type:"string",description:"specific Chrome profile directory (e.g., 'Default')"},{name:"user-agent",type:"string",description:"custom User-Agent header for HTTP requests",short:"u"},{name:"debug",type:"boolean",description:"Print full HTTP request and response bodies for debugging"},{name:"out",type:"string",description:"Write decoded response JSON/text to file instead of stdout",short:"o"}];export function parseArgsForWebsite(r=[],n=[],o){let i=!1;const s={},a=[...n,...e];for(const e of a){const r=t(e.name);void 0!==e.default?s[r]=e.default:"boolean"===e.type&&(s[r]=!1)}const c={};for(const e of r)c[e.name]=[];let
|
|
1
|
+
const e=[{name:"profile",type:"string",description:"specific Chrome profile directory (e.g., 'Default')"},{name:"user-agent",type:"string",description:"custom User-Agent header for HTTP requests",short:"u"},{name:"debug",type:"boolean",description:"Print full HTTP request and response bodies for debugging"},{name:"keep-open",type:"boolean",description:"Leave the browser tab open after running (preserve the logged-in session)"},{name:"out",type:"string",description:"Write decoded response JSON/text to file instead of stdout",short:"o"}];export function parseArgsForWebsite(r=[],n=[],o){let i=!1;const s={},a=[...n,...e];for(const e of a){const r=t(e.name);void 0!==e.default?s[r]=e.default:"boolean"===e.type&&(s[r]=!1)}const c={};for(const e of r)c[e.name]=[];let p=0;for(let e=0;e<o.length;e++){const n=o[e];if("--help"!==n&&"-h"!==n)if(n.startsWith("-")){let r;const i=!n.startsWith("--"),c=i?n.slice(1):n.slice(2);if(r=i?a.find(e=>e.short===c):a.find(e=>e.name===c),!r)throw new Error(`Unknown option: ${n}`);const p=t(r.name);if("boolean"===r.type)s[p]=!0;else if("string"===r.type){const t=o[e+1];if(void 0===t||t.startsWith("-"))throw new Error(`Option ${n} requires a value`);s[p]=t,e++}else if("number"===r.type){const t=o[e+1];if(void 0===t||t.startsWith("-"))throw new Error(`Option ${n} requires a numeric value`);const r=Number(t);if(isNaN(r))throw new Error(`Option ${n} requires a valid numeric value, received: "${t}"`);s[p]=r,e++}}else if(p<r.length){const e=r[p];c[e.name].push(n),e.variadic||p++}else{const e=r[r.length-1];if(!e?.variadic)throw new Error(`Unexpected extra argument: "${n}"`);c[e.name].push(n)}else i=!0}for(const e of r){const r=c[e.name];if(e.required&&0===r.length&&!i)throw new Error(`Missing required argument: <${e.name}>`);s[t(e.name)]=r.length>0?r.join(" "):null}for(const e of a){const r=t(e.name);if(e.required&&void 0===s[r]&&!i)throw new Error(`Missing required option: --${e.name}`)}return{options:s,helpRequested:i}}function t(e){return e.replace(/-([a-z])/g,(e,t)=>t.toUpperCase())}
|
|
@@ -1,34 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
export
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
*
|
|
9
|
-
* Scans each subdirectory for a file matching `*-adapter.js` and dynamically
|
|
10
|
-
* imports it. Each adapter module must have a default export that is a
|
|
11
|
-
* WebsiteAdapter (created via `defineAdapter()`).
|
|
12
|
-
*
|
|
13
|
-
* This is called once on first use — no manual imports needed when adding
|
|
14
|
-
* new adapters.
|
|
15
|
-
*/
|
|
16
|
-
export declare function loadAdapters(): Promise<void>;
|
|
17
|
-
/**
|
|
18
|
-
* Finds an adapter by ID or partial domain match.
|
|
19
|
-
*
|
|
20
|
-
* @param id - Website identifier (e.g. "chatgpt.com", "chatgpt", "cursor")
|
|
21
|
-
* @returns The matching adapter or null
|
|
22
|
-
*/
|
|
23
|
-
export declare function getWebsite(id: string): WebsiteAdapter | null;
|
|
24
|
-
/**
|
|
25
|
-
* Queries a registered website API using decrypted Google Chrome cookies on macOS.
|
|
26
|
-
*
|
|
27
|
-
* Cookie retrieval is simplified to a single `getCookies({ domain })` call —
|
|
28
|
-
* no manual extraction or domain matching needed.
|
|
29
|
-
*
|
|
30
|
-
* @param websiteId - The domain or identifier of the website (e.g. "chatgpt.com")
|
|
31
|
-
* @param options - Retrieval options (profile, userAgent)
|
|
32
|
-
* @returns The structured website API response
|
|
33
|
-
*/
|
|
34
|
-
export declare function queryWebsite(websiteId: string, options?: QueryOptions): Promise<unknown>;
|
|
1
|
+
export { defineSite, isSite } from "./core/define-site.js";
|
|
2
|
+
export type { Site, SiteDef, SiteContext, Endpoint, QueryOptions, ParameterDefinition, PositionalDefinition, FingerprintOption, FingerprintConfig, FormLoginConfig, LoginStrategy, LoginContext, Credentials, HttpCapability, SSEResult, } from "./types.js";
|
|
3
|
+
export { FormLoginStrategy } from "./capabilities/login/login-strategy.js";
|
|
4
|
+
export { sites, loadSites, setSites, getSite, queryWebsite, createUniversalSite, } from "./core/runtime.js";
|
|
5
|
+
export { discoverSites, extensionRoots, BUNDLED_SITES_DIR } from "./core/loader.js";
|
|
6
|
+
export { createContext } from "./core/context.js";
|
|
7
|
+
export type { ContextProviders, ManagedContext } from "./core/context.js";
|
package/dist/src/website-api.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{loadEnv as e}from"./env.js";e();export{defineSite,isSite}from"./core/define-site.js";export{FormLoginStrategy}from"./capabilities/login/login-strategy.js";export{sites,loadSites,setSites,getSite,queryWebsite,createUniversalSite}from"./core/runtime.js";export{discoverSites,extensionRoots,BUNDLED_SITES_DIR}from"./core/loader.js";export{createContext}from"./core/context.js";
|
package/package.json
CHANGED
|
@@ -1,9 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "website-api",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.1",
|
|
4
4
|
"description": "CLI and library to fetch website API data",
|
|
5
5
|
"main": "./dist/src/website-api.js",
|
|
6
|
+
"types": "./dist/src/website-api.d.ts",
|
|
6
7
|
"type": "module",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/src/website-api.d.ts",
|
|
11
|
+
"default": "./dist/src/website-api.js"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
7
14
|
"bin": {
|
|
8
15
|
"website-api": "./dist/bin/cli.js",
|
|
9
16
|
"chrome-website-api": "./dist/bin/cli.js"
|
|
@@ -36,6 +43,8 @@
|
|
|
36
43
|
],
|
|
37
44
|
"scripts": {
|
|
38
45
|
"build": "node scripts/build.mjs",
|
|
46
|
+
"typecheck": "tsc --noEmit",
|
|
47
|
+
"test": "tsc -p tsconfig.test.json && node --test \"dist/test/**/*.test.js\"",
|
|
39
48
|
"check:secrets": "node scripts/check-secrets.mjs",
|
|
40
49
|
"release": "pnpm version patch && pnpm publish --access public",
|
|
41
50
|
"start": "node dist/bin/cli.js"
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import { type CookieEntry } from "chrome-tools";
|
|
2
|
-
import type { AdapterConfig, QueryOptions, WebsiteAdapter, Endpoint } from "../types.js";
|
|
3
|
-
/**
|
|
4
|
-
* Base class for all website adapters, enabling class-based inheritance and clean reuse.
|
|
5
|
-
*/
|
|
6
|
-
export declare class BaseAdapter implements WebsiteAdapter {
|
|
7
|
-
id: string;
|
|
8
|
-
name: string;
|
|
9
|
-
domain: string;
|
|
10
|
-
description: string;
|
|
11
|
-
endpoints?: Endpoint[];
|
|
12
|
-
optionalCookies?: boolean;
|
|
13
|
-
/**
|
|
14
|
-
* Internal reference to transient options. Used to check the debug flag during fetch calls.
|
|
15
|
-
*/
|
|
16
|
-
_lastQueryOptions?: QueryOptions;
|
|
17
|
-
buildCookieString(cookies: CookieEntry[]): string;
|
|
18
|
-
resolveUserAgent(options: QueryOptions): string;
|
|
19
|
-
resolveCredentials(options: QueryOptions): {
|
|
20
|
-
username: string;
|
|
21
|
-
password: string;
|
|
22
|
-
};
|
|
23
|
-
resolveCookies(options: QueryOptions): CookieEntry[];
|
|
24
|
-
/**
|
|
25
|
-
* Centralized HTTP fetch handler.
|
|
26
|
-
* Unifies request setup, response parsing, debug logging, and error handling.
|
|
27
|
-
*/
|
|
28
|
-
private _fetch;
|
|
29
|
-
fetchText(url: string, init?: RequestInit): Promise<string>;
|
|
30
|
-
fetchHtml(url: string, init?: RequestInit): Promise<string>;
|
|
31
|
-
fetchJson(url: string, init?: RequestInit): Promise<any>;
|
|
32
|
-
/**
|
|
33
|
-
* Internal helper to fetch a specific endpoint with type-based accepting headers and content-type parsing.
|
|
34
|
-
*/
|
|
35
|
-
private _fetchEndpoint;
|
|
36
|
-
fetchData(cookies: CookieEntry[], options: QueryOptions): Promise<unknown>;
|
|
37
|
-
}
|
|
38
|
-
/**
|
|
39
|
-
* Factory function to create a fully-equipped WebsiteAdapter from a minimal config.
|
|
40
|
-
*/
|
|
41
|
-
export declare function defineAdapter(config: AdapterConfig): WebsiteAdapter;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{getCookies as e,getPasswords as t}from"chrome-tools";export class BaseAdapter{id;name;domain;description;endpoints;optionalCookies;_lastQueryOptions;buildCookieString(e){return e.map(e=>`${e.name}=${e.value}`).join("; ")}resolveUserAgent(e){return e.userAgent||process.env.userAgent||process.env.USER_AGENT||"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/148.0.0.0 Safari/537.36"}resolveCredentials(e){const o=e.profilePath||process.env.PROFILE_PATH||process.env.CHROME_PROFILE_PATH||void 0,s=e.profile||process.env.PROFILE_NAME||void 0;let r=t({chromeDir:o,profile:s,search:this.domain});if(!r||0===r.length){const e=this.domain.split("."),n=e[e.length-2]||this.domain;r=t({chromeDir:o,profile:s,search:n})}if(!r||0===r.length)throw new Error(`No saved passwords found in Chrome for '${this.domain}'`);const{username:n,password:i}=r[0];if(!n||!i)throw new Error(`Found credentials for '${this.domain}' but username or password was empty`);return{username:n,password:i}}resolveCookies(t){const o=t.profilePath||process.env.PROFILE_PATH||process.env.CHROME_PROFILE_PATH||void 0,s=t.profile||process.env.PROFILE_NAME||void 0;let r=[];try{r=e({chromeDir:o,profile:s,domain:this.domain,decrypt:!0})}catch(e){if(!this.optionalCookies)throw new Error("No login found in browser")}if(!(r&&0!==r.length||this.optionalCookies))throw new Error("No login found in browser");return r}async _fetch(e,t){const o=this._lastQueryOptions?.debug;o&&console.log("[debug] Request:",{url:e,init:t});const s=await fetch(e,t),r=await s.text();if(o&&console.log("[debug] Response:",{url:e,status:s.status,statusText:s.statusText,headers:Array.from(s.headers.entries()),body:r}),!s.ok)throw new Error(`HTTP ${s.status}: ${s.statusText}`);return{response:s,text:r}}async fetchText(e,t){const{text:o}=await this._fetch(e,t);return o}async fetchHtml(e,t){return this.fetchText(e,t)}async fetchJson(e,t){const{text:o}=await this._fetch(e,t);try{return JSON.parse(o)}catch{return{response:o}}}async _fetchEndpoint(e,t,o){const s="html"===e.responseType?"text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8":"text"===e.responseType?"text/plain,*/*;q=0.8":"application/json, text/plain, */*",{response:r,text:n}=await this._fetch(e.url,{method:e.method||"GET",headers:{Cookie:t,"User-Agent":o,Accept:s,...e.headers}}),i=r.headers.get("content-type")?.toLowerCase()??"";if("json"===e.responseType||"text"!==e.responseType&&"html"!==e.responseType&&(i.includes("application/json")||i.includes("+json")))try{return JSON.parse(n)}catch(t){throw new Error(`Expected JSON from ${e.url}, but received invalid JSON: ${t instanceof Error?t.message:String(t)}`)}return n}async fetchData(e,t){if(!this.endpoints||0===this.endpoints.length)throw new Error(`Adapter "${this.id}" has no endpoints defined and no fetchData override`);const o=this.endpoints[0],s=this.buildCookieString(e),r=this.resolveUserAgent(t),n=await this._fetchEndpoint(o,s,r);return o.transform?o.transform.call(this,n,e,t):n}}export function defineAdapter(e){const t=new BaseAdapter;return Object.assign(t,e),e.fetchData&&(t.fetchData=e.fetchData.bind(t)),t}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { BaseAdapter } from "./base-adapter.js";
|
|
2
|
-
import type { Page } from "playwright-core";
|
|
3
|
-
import type { QueryOptions } from "../types.js";
|
|
4
|
-
/**
|
|
5
|
-
* Specialized base class for adapters that use Playwright CDP tab reuse.
|
|
6
|
-
* Provides a clean `connect(options)` method returning a disposable Page proxy.
|
|
7
|
-
*/
|
|
8
|
-
export declare class PlaywrightAdapter extends BaseAdapter {
|
|
9
|
-
/**
|
|
10
|
-
* Connects to Chrome over CDP using the first endpoint's URL, returning a disposable Page proxy
|
|
11
|
-
* which automatically captures HTML and disposes of the connection upon scope exit.
|
|
12
|
-
*
|
|
13
|
-
* @param options The adapter options containing the debug flag.
|
|
14
|
-
*/
|
|
15
|
-
connect(options: QueryOptions): Promise<Page>;
|
|
16
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{BaseAdapter as t}from"./base-adapter.js";import{runWithPlaywright as r}from"./playwright-core.js";export class PlaywrightAdapter extends t{async connect(t){const e=await r(this.endpoints,t);return await e.addInitScript(()=>{Object.defineProperty(navigator,"webdriver",{get:()=>{}})}),e}}
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import { type Browser, type Page } from "playwright-core";
|
|
2
|
-
export interface PlaywrightOptions {
|
|
3
|
-
cdpEndpoint?: string;
|
|
4
|
-
debug?: boolean;
|
|
5
|
-
close?: boolean;
|
|
6
|
-
}
|
|
7
|
-
export interface PlaywrightTabResult {
|
|
8
|
-
page: Page;
|
|
9
|
-
browser: Browser;
|
|
10
|
-
[Symbol.asyncDispose](): Promise<void>;
|
|
11
|
-
}
|
|
12
|
-
/**
|
|
13
|
-
* Connects to an existing Chrome instance via CDP and retrieves or creates a tab for the target URL.
|
|
14
|
-
*
|
|
15
|
-
* @param targetUrl The website URL to open/connect to.
|
|
16
|
-
* @param options Connection options.
|
|
17
|
-
*/
|
|
18
|
-
export declare function connectChrome(targetUrl: string, options?: PlaywrightOptions): Promise<PlaywrightTabResult>;
|
|
19
|
-
/**
|
|
20
|
-
* Runs or prepares a Playwright task on a target URL inside an existing Chrome tab.
|
|
21
|
-
*
|
|
22
|
-
* Supports two modes:
|
|
23
|
-
* 1. Callback Mode (3 arguments): Connects, runs action, extracts HTML, and returns { html }.
|
|
24
|
-
* 2. Disposable Page Mode (2 arguments): Connects and returns a Page proxy implementing [Symbol.asyncDispose]
|
|
25
|
-
* which automatically extracts the HTML into options.htmlResult on disposal.
|
|
26
|
-
*
|
|
27
|
-
* @param endpoints The endpoints configuration of the adapter.
|
|
28
|
-
* @param options Query and debug options.
|
|
29
|
-
* @param action Optional action callback to interact with the page.
|
|
30
|
-
*/
|
|
31
|
-
export declare function runWithPlaywright(endpoints: {
|
|
32
|
-
url: string;
|
|
33
|
-
}[] | undefined, options: {
|
|
34
|
-
debug?: boolean;
|
|
35
|
-
}, action?: (page: Page) => Promise<void>): Promise<any>;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
var e=this&&this.__addDisposableResource||function(e,r,o){if(null!=r){if("object"!=typeof r&&"function"!=typeof r)throw new TypeError("Object expected.");var t,n;if(o){if(!Symbol.asyncDispose)throw new TypeError("Symbol.asyncDispose is not defined.");t=r[Symbol.asyncDispose]}if(void 0===t){if(!Symbol.dispose)throw new TypeError("Symbol.dispose is not defined.");t=r[Symbol.dispose],o&&(n=t)}if("function"!=typeof t)throw new TypeError("Object not disposable.");n&&(t=function(){try{n.call(this)}catch(e){return Promise.reject(e)}}),e.stack.push({value:r,dispose:t,async:o})}else o&&e.stack.push({async:!0});return r},r=this&&this.__disposeResources||function(e){return function(r){function o(o){r.error=r.hasError?new e(o,r.error,"An error was suppressed during disposal."):o,r.hasError=!0}var t,n=0;return function e(){for(;t=r.stack.pop();)try{if(!t.async&&1===n)return n=0,r.stack.push(t),Promise.resolve().then(e);if(t.dispose){var s=t.dispose.call(t.value);if(t.async)return n|=2,Promise.resolve(s).then(e,function(r){return o(r),e()})}else n|=1}catch(e){o(e)}if(1===n)return r.hasError?Promise.reject(r.error):Promise.resolve();if(r.hasError)throw r.error}()}}("function"==typeof SuppressedError?SuppressedError:function(e,r,o){var t=new Error(o);return t.name="SuppressedError",t.error=e,t.suppressed=r,t});import{chromium as o}from"playwright-core";export async function connectChrome(e,r={}){const t=r.cdpEndpoint||process.env.CDP_ENDPOINT||"http://localhost:9222",n=!!r.debug,s=await o.connectOverCDP(t),i=s.contexts()[0];if(!i)throw new Error("No active browser context found. Is Chrome running with remote debugging enabled?");let c=i.pages().find(r=>{try{const o=new URL(e).hostname.replace("www.","");return new URL(r.url()).hostname.endsWith(o)||r.url().startsWith(e)}catch{return r.url().startsWith(e)}}),a=!1;return c?n&&console.log(`Found existing tab with target URL: ${e}. Reusing it...`):(n&&console.log(`Target URL not found. Opening a new tab for: ${e}...`),c=await i.newPage(),await c.goto(e,{waitUntil:"domcontentloaded"}),a=!0),{page:c,browser:s,async[Symbol.asyncDispose](){if(a&&!1!==r.close){n&&console.log("Closing newly opened tab...");try{await c.close()}catch{}}n&&console.log("Disconnecting from Chrome CDP..."),await s.close()}}}export async function runWithPlaywright(o,t,n){if(!o||0===o.length)throw new Error("No endpoints defined in adapter.");const s=o[0].url;if(!n){const e=await connectChrome(s,{cdpEndpoint:process.env.CDP_ENDPOINT,debug:t.debug,close:t.close});return new Proxy(e.page,{get(r,o,n){if(o===Symbol.asyncDispose)return async()=>{try{const e=await r.content();t.htmlResult=e}catch(e){t.debug&&console.error("Failed to extract page content in disposable:",e)}await e[Symbol.asyncDispose]()};const s=Reflect.get(r,o,n);return"function"==typeof s?s.bind(r):s}})}{const o={stack:[],error:void 0,hasError:!1};try{const r=e(o,await connectChrome(s,{cdpEndpoint:process.env.CDP_ENDPOINT,debug:t.debug,close:t.close}),!0);await n(r.page);return{html:await r.page.content()}}catch(e){o.error=e,o.hasError=!0}finally{const e=r(o);e&&await e}}}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import type { WebsiteAdapter } from "../types.js";
|
|
2
|
-
/**
|
|
3
|
-
* Creates a universal fallback adapter for any domain that doesn't have
|
|
4
|
-
* a dedicated adapter. Parses the websiteId as a URL and uses the default
|
|
5
|
-
* single-endpoint fetch flow.
|
|
6
|
-
*
|
|
7
|
-
* @param websiteId - A URL or domain string (e.g. "example.com/api/data")
|
|
8
|
-
* @returns A WebsiteAdapter if the URL is valid, or null otherwise.
|
|
9
|
-
*/
|
|
10
|
-
export declare function createUniversalAdapter(websiteId: string): WebsiteAdapter | null;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{defineAdapter as t}from"./base-adapter.js";export function createUniversalAdapter(r){let e=r;e.startsWith("http://")||e.startsWith("https://")||(e="https://"+e);try{const a=new URL(e);return t({id:r,name:r,domain:a.hostname,description:`Universal adapter for ${a.hostname}`,endpoints:[{url:a.href}]})}catch{return null}}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export async function performFormLogin(t){const{page:i,emailSelector:e,emailValue:o,passwordSelector:a,passwordValue:n,submitButtonSelector:r,delayMs:s=1e3,intendedUrl:l,loginUrl:c,expectedRedirectUrlPattern:u=l,debug:p=!1,pwdSelector:d='input[type="password"]',dashboardSelectors:f=[]}=t;if(l){if(!i.url().includes(l)){p&&console.log(`[LoginHelper] Navigating to intended URL: ${l}`);try{await i.goto(l,{waitUntil:"domcontentloaded"})}catch(t){p&&console.warn(`[LoginHelper] Warning navigating to ${l}:`,t)}}}try{await i.waitForLoadState("domcontentloaded")}catch(t){}let g=!1,w=i;p&&console.log("[LoginHelper] Waiting for session state to settle (detecting logon form or dashboard)...");const b=Date.now();for(;Date.now()-b<15e3;){try{if(await i.locator(d).first().isVisible()){g=!0,w=i;break}}catch{}let t=!1;for(const e of i.frames())try{if(await e.locator(d).first().isVisible()){g=!0,w=e,t=!0;break}}catch{}if(t)break;let e=!1;for(const t of f)try{if(await i.locator(t).first().isVisible()){g=!1,e=!0;break}}catch{}if(e)break;await i.waitForTimeout(500)}if(!g&&Date.now()-b>=15e3)try{await i.waitForSelector(e,{state:"visible",timeout:1e3}),g=!0,w=i}catch{try{await i.waitForSelector(a,{state:"visible",timeout:1e3}),g=!0,w=i}catch{g=!1}}if(!g)return p&&console.log("[LoginHelper] Already logged in (Dashboard active). Skipping login flow."),!1;let m=e,y=a,h=r;const L=[e,"input#userId-input","input#userId",'input[name="usr_name"]','input[type="text"][id*="user"]','input[type="text"][id*="Id"]','input[type="text"]','input[type="email"]'];for(const t of L)try{const i=w.locator(t).first();if(await i.isVisible()){m=t;break}}catch{}const k=[a,"input#password-input","input#password",'input[type="password"]','input[name*="password"]'];for(const t of k)try{const i=w.locator(t).first();if(await i.isVisible()){y=t;break}}catch{}const S=[r,'button[type="submit"]',"#signin-button","button#signin-button",'input[type="submit"]'];for(const t of S)try{const i=w.locator(t).first();if(await i.isVisible()){h=t;break}}catch{}if(p&&console.log(`[LoginHelper] Login form detected inside frame: ${w===i?"main":w.url()}. Proceeding using email='${m}', password='${y}', submit='${h}'...`),await w.fill(m,o),await w.fill(y,n),s>0&&(p&&console.log(`[LoginHelper] Waiting ${s}ms before submission...`),await w.waitForTimeout(s)),p&&console.log(`[LoginHelper] Clicking submit button '${h}'...`),await w.click(h),u){p&&console.log(`[LoginHelper] Waiting for redirection matching '${u}'...`);try{await i.waitForURL(u,{timeout:15e3})}catch{try{await i.waitForNavigation({waitUntil:"networkidle",timeout:8e3})}catch{}}}return!0}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
export interface ChaseAccount {
|
|
2
|
-
name: string;
|
|
3
|
-
last4: string;
|
|
4
|
-
balance: number | string;
|
|
5
|
-
type: string;
|
|
6
|
-
category: string;
|
|
7
|
-
raw?: any;
|
|
8
|
-
}
|
|
9
|
-
export interface ChaseAccountGroup {
|
|
10
|
-
groupName: string;
|
|
11
|
-
accounts: ChaseAccount[];
|
|
12
|
-
}
|
|
13
|
-
/**
|
|
14
|
-
* Recursively parses and extracts account-like elements from the Chase REST API JSON payload.
|
|
15
|
-
*/
|
|
16
|
-
export declare function decodeChaseAccounts(jsonResult: any): ChaseAccountGroup[];
|
|
17
|
-
/**
|
|
18
|
-
* Returns a beautiful, premium explained summary of the decoded Chase bank accounts.
|
|
19
|
-
*/
|
|
20
|
-
export declare function explainAccounts(groups: ChaseAccountGroup[], rawJson?: any): string;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export function decodeChaseAccounts(t){const e=[];if(!t||"object"!=typeof t)return e;const a=t=>{if(!t||"object"!=typeof t)return[];let e=[];Array.isArray(t.productInfos)&&(e=e.concat(t.productInfos));for(const n of Object.keys(t))"object"==typeof t[n]&&(e=e.concat(a(t[n])));return e},n=a(t),c=new Map;for(const t of n)t.accountId&&c.set(String(t.accountId),t),t.mask&&c.set(String(t.mask),t);const o=t=>{if(!t||"object"!=typeof t)return[];let e=[];const a=c.get(String(t.accountId||t.id||""))||(t.mask?c.get(String(t.mask)):void 0),n="string"==typeof(t.nickname||t.accountName||t.name||t.displayName||a?.nickName||a?.cardDefaultNickName),i=function(t){if(!t||"object"!=typeof t)return;const e=t.ledgerBalance??t.availableBalance??t.currentBalance??t.balance??t.amount??t.accountValue;if("number"==typeof e)return e;const a=t.bankingAccountDetail?.availableBalance??t.bankingAccountDetail?.currentBalance??t.cardAccountDetail?.currentBalance??t.detail?.accountValue??t.detail?.currentBalance;return"number"==typeof a?a:void 0}(t);if(n&&void 0!==i)return[{...t,balance:i}];for(const a of Object.keys(t)){const n=t[a];if(Array.isArray(n))for(const t of n)e=e.concat(o(t));else"object"==typeof n&&(e=e.concat(o(n)))}return e},i=new Set,r=o(t),s=[],u=[],l=[],p=[];for(const t of r){const e=t.mask||t.last4||t.accountNumberLast4Digits||t.suffix||"N/A",a=c.get(String(t.accountId||t.id||""))||c.get(e),n=t.nickname||t.accountName||t.name||t.displayName||a?.nickName||a?.cardDefaultNickName||"Account",o=t.mask||t.last4||t.accountNumberLast4Digits||t.suffix||a?.mask||"N/A",r=`${n.toLowerCase()}_${o}`;if(i.has(r))continue;i.add(r);let m=t.accountType||t.accountTileDetailType||t.detailType||"Unknown",f=t.accountCategoryType||t.categoryType||t.accountTileType||t.groupType||"Unknown";if(a&&a.productId){const t=a.productId.split("-");t.length>=2&&(f=t[0],m=t[1])}const g={name:n,last4:o,balance:t.balance,type:m,category:f,raw:t};"DDA"===f||"CHK"===m?s.push(g):"CARD"===f||"BAC"===m?u.push(g):"INVESTMENT"===f||"BR2"===m?l.push(g):p.push(g)}return s.length>0&&e.push({groupName:"Bank accounts",accounts:s}),l.length>0&&e.push({groupName:"Investment accounts by J.P. Morgan",accounts:l}),u.length>0&&e.push({groupName:"Credit cards",accounts:u}),p.length>0&&e.push({groupName:"Other accounts",accounts:p}),e}export function explainAccounts(t,e){const a=["💼 Chase Account Summary (REST API Decoded):"];if(0===t.length)a.push("\n⚠️ No accounts could be successfully decoded from the JSON response."),e&&a.push("Please check the raw response below to verify the payload structure.");else{let e=0,n=0;for(const c of t){a.push(`\n📁 ${c.groupName}:`);for(const t of c.accounts){const c="number"==typeof t.balance?`$${t.balance.toLocaleString(void 0,{minimumFractionDigits:2,maximumFractionDigits:2})}`:String(t.balance);if(a.push(` 🔹 ${t.name} (...${t.last4}) - Balance: ${c} [Type: ${t.type}]`),"number"==typeof t.balance){("CARD"===t.category||"BAC"===t.type||"CARD"===t.raw?.categoryType||"CARD"===t.raw?.accountCategoryType||"CARD"===t.raw?.accountTileType)&&"CHK"!==t.type||t.category.toLowerCase().includes("debt")||t.balance<0?n+=Math.abs(t.balance):e+=t.balance}}}if(e>0||n>0){a.push("\n📈 Portfolio Overview:"),a.push(` 💸 Total Liquid Assets: $${e.toLocaleString(void 0,{minimumFractionDigits:2,maximumFractionDigits:2})}`),a.push(` 💳 Total Credit Debts: $${n.toLocaleString(void 0,{minimumFractionDigits:2,maximumFractionDigits:2})}`);const t=e-n;a.push(` 💎 Net Cash/Portfolio Value: $${t.toLocaleString(void 0,{minimumFractionDigits:2,maximumFractionDigits:2})}`)}}return e&&(a.push("\n📋 Raw REST API JSON Response:"),a.push(JSON.stringify(e,null,2))),a.join("\n")}
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import { PlaywrightAdapter } from "../../adapter/playwright-attatch-chrome-adapter.js";
|
|
2
|
-
export default class extends PlaywrightAdapter {
|
|
3
|
-
id: string;
|
|
4
|
-
name: string;
|
|
5
|
-
domain: string;
|
|
6
|
-
description: string;
|
|
7
|
-
optionalCookies: boolean;
|
|
8
|
-
endpoints: {
|
|
9
|
-
url: string;
|
|
10
|
-
}[];
|
|
11
|
-
positionals: {
|
|
12
|
-
name: string;
|
|
13
|
-
description: string;
|
|
14
|
-
required: boolean;
|
|
15
|
-
variadic: boolean;
|
|
16
|
-
}[];
|
|
17
|
-
parameters: ({
|
|
18
|
-
name: string;
|
|
19
|
-
type: "boolean";
|
|
20
|
-
description: string;
|
|
21
|
-
short: string;
|
|
22
|
-
default: boolean;
|
|
23
|
-
} | {
|
|
24
|
-
name: string;
|
|
25
|
-
type: "number";
|
|
26
|
-
description: string;
|
|
27
|
-
short?: undefined;
|
|
28
|
-
default?: undefined;
|
|
29
|
-
} | {
|
|
30
|
-
name: string;
|
|
31
|
-
type: "boolean";
|
|
32
|
-
description: string;
|
|
33
|
-
default: boolean;
|
|
34
|
-
short?: undefined;
|
|
35
|
-
} | {
|
|
36
|
-
name: string;
|
|
37
|
-
type: "string";
|
|
38
|
-
description: string;
|
|
39
|
-
short?: undefined;
|
|
40
|
-
default?: undefined;
|
|
41
|
-
})[];
|
|
42
|
-
fetchData(cookies: any, options: any): Promise<string>;
|
|
43
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
var e=this&&this.__addDisposableResource||function(e,o,r){if(null!=o){if("object"!=typeof o&&"function"!=typeof o)throw new TypeError("Object expected.");var t,s;if(r){if(!Symbol.asyncDispose)throw new TypeError("Symbol.asyncDispose is not defined.");t=o[Symbol.asyncDispose]}if(void 0===t){if(!Symbol.dispose)throw new TypeError("Symbol.dispose is not defined.");t=o[Symbol.dispose],r&&(s=t)}if("function"!=typeof t)throw new TypeError("Object not disposable.");s&&(t=function(){try{s.call(this)}catch(e){return Promise.reject(e)}}),e.stack.push({value:o,dispose:t,async:r})}else r&&e.stack.push({async:!0});return o},o=this&&this.__disposeResources||function(e){return function(o){function r(r){o.error=o.hasError?new e(r,o.error,"An error was suppressed during disposal."):r,o.hasError=!0}var t,s=0;return function e(){for(;t=o.stack.pop();)try{if(!t.async&&1===s)return s=0,o.stack.push(t),Promise.resolve().then(e);if(t.dispose){var n=t.dispose.call(t.value);if(t.async)return s|=2,Promise.resolve(n).then(e,function(o){return r(o),e()})}else s|=1}catch(e){r(e)}if(1===s)return o.hasError?Promise.reject(o.error):Promise.resolve();if(o.hasError)throw o.error}()}}("function"==typeof SuppressedError?SuppressedError:function(e,o,r){var t=new Error(r);return t.name="SuppressedError",t.error=e,t.suppressed=o,t});import{PlaywrightAdapter as r}from"../../adapter/playwright-attatch-chrome-adapter.js";import{performFormLogin as t}from"../../util/login-helper.js";import{downloadAccounts as s}from"./download-helper.js";export default class extends r{id="chase";name="Chase Bank";domain="chase.com";description="Logs into Chase, lists downloadable accounts, and downloads statement/transaction CSV files.";optionalCookies=!0;endpoints=[{url:"https://www.chase.com/"}];positionals=[{name:"accounts",description:"Account indexes to select (e.g. 1 3). Leave empty for all.",required:!1,variadic:!0}];parameters=[{name:"list",type:"boolean",description:"List downloadable accounts only",short:"l",default:!1},{name:"download",type:"boolean",description:"Save selected account CSV file(s) in the current directory or --out-dir",short:"d",default:!1},{name:"limit",type:"number",description:"Only process the first n accounts"},{name:"first",type:"boolean",description:"Shortcut for --limit 1",default:!1},{name:"filename",type:"string",description:"Save one selected account to this filename (requires --download and exactly one account)"},{name:"activity",type:"string",description:"Activity option: current-display, all-transactions, date-range (default: all)"},{name:"range",type:"string",description:"Alias for --activity"},{name:"from",type:"string",description:"Start date for date-range (mm/dd/yyyy)"},{name:"to",type:"string",description:"End date for date-range (mm/dd/yyyy)"},{name:"out-dir",type:"string",description:"Write each CSV to <dir> instead of returning it"}];async fetchData(r,n){const a={stack:[],error:void 0,hasError:!1};try{const o=!!n.debug,{username:r,password:i}=this.resolveCredentials(n);o&&console.log(`[ChaseAdapter] Resolved credentials for ${r}`);const c=e(a,await this.connect({...n,close:!1}),!0);return o&&console.log("[ChaseAdapter] Performing form login using login helper..."),await t({page:c,intendedUrl:"https://secure.chase.com/web/auth/dashboard#/dashboard/overview",emailSelector:".public-logon.input.logon-xs-toggle",emailValue:r,passwordSelector:".public-logon.input-password.logon-xs-toggle",passwordValue:i,submitButtonSelector:"#signin-button",delayMs:1e3,pwdSelector:'input[type="password"], input[name*="password"], input[id*="password"], .public-logon.input-password',dashboardSelectors:[".accounts-group-container-bc","#account-groups-component-bc",'[data-testid="accounts-group-container"]',".innerTile","#DDA_ACCOUNTS"],debug:o}),await c.waitForTimeout(3e3),o&&console.log("[ChaseAdapter] Running statement downloader flow..."),await s(c,n)}catch(e){a.error=e,a.hasError=!0}finally{const e=o(a);e&&await e}}}
|