@crossly/buyer-cli 0.0.0-stage → 0.2.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/LICENSE +21 -0
- package/README.md +103 -2
- package/dist/auth.d.ts +22 -0
- package/dist/auth.d.ts.map +1 -0
- package/dist/auth.js +71 -0
- package/dist/auth.js.map +1 -0
- package/dist/commands.d.ts +30 -0
- package/dist/commands.d.ts.map +1 -0
- package/dist/commands.js +173 -0
- package/dist/commands.js.map +1 -0
- package/dist/exit.d.ts +38 -0
- package/dist/exit.d.ts.map +1 -0
- package/dist/exit.js +53 -0
- package/dist/exit.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +236 -0
- package/dist/index.js.map +1 -0
- package/dist/output.d.ts +14 -0
- package/dist/output.d.ts.map +1 -0
- package/dist/output.js +88 -0
- package/dist/output.js.map +1 -0
- package/package.json +67 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Crossly
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,104 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @crossly/buyer-cli
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Your Crossly shopping, from the terminal.
|
|
4
|
+
|
|
5
|
+
> **Not on npm yet.** `@crossly/buyer-cli` is unreleased — the install command below
|
|
6
|
+
> will 404 until the first publish. To try it now, clone this repo and build from
|
|
7
|
+
> source. Star or watch to hear when it lands.
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm i -g @crossly/buyer-cli
|
|
11
|
+
crossly-buyer login --token crossly_oat_...
|
|
12
|
+
crossly-buyer cart get
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Two binaries, because two APIs
|
|
16
|
+
|
|
17
|
+
| | |
|
|
18
|
+
|---|---|
|
|
19
|
+
| `crossly` ([@crossly/cli](https://github.com/crossly-dev/crossly-cli)) | a seller's **store** — <!-- generated:cli-commands -->2,917<!-- /generated:cli-commands --> commands |
|
|
20
|
+
| `crossly-buyer` (this) | a person's **own shopping** — <!-- generated:buyer-cli-commands -->114<!-- /generated:buyer-cli-commands --> commands |
|
|
21
|
+
|
|
22
|
+
Different credentials, so different binaries rather than one with a `--buyer` flag. If only `CROSSLY_PAT` is set, this CLI says so and points you at the other one instead of failing with an opaque 403.
|
|
23
|
+
|
|
24
|
+
## Commands
|
|
25
|
+
|
|
26
|
+
```
|
|
27
|
+
profile get
|
|
28
|
+
orders list
|
|
29
|
+
cashback list
|
|
30
|
+
cart get add remove quote
|
|
31
|
+
wishlists list items create add
|
|
32
|
+
activity report list preferences
|
|
33
|
+
offers make
|
|
34
|
+
agent list start get delete say react act
|
|
35
|
+
vault worth holdings history watchlist exits exit indexes index
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
Every command takes `--help`, and **`--help` never touches the network or needs a token** — it works on a plane.
|
|
39
|
+
|
|
40
|
+
```bash
|
|
41
|
+
crossly-buyer offers make --help
|
|
42
|
+
crossly-buyer offers make --listingSlug vintage-levis-501 --amountCents 4500
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
## Nothing here spends money
|
|
46
|
+
|
|
47
|
+
`cart quote` prices a basket. `offers make` proposes a number. No command completes a purchase — paying happens on Crossly, with you present.
|
|
48
|
+
|
|
49
|
+
## For scripts and agents
|
|
50
|
+
|
|
51
|
+
`--json` on everything, byte-faithful to what the API returned. `--ndjson` on lists, one object per line. `--dry-run` prints what would be sent and sends nothing.
|
|
52
|
+
|
|
53
|
+
Exit codes distinguish **remedies**, which is the point:
|
|
54
|
+
|
|
55
|
+
| code | meaning | what to do |
|
|
56
|
+
|---|---|---|
|
|
57
|
+
| `0` | ok | |
|
|
58
|
+
| `1` | the API said no, or the network failed | read the message |
|
|
59
|
+
| `2` | you typed something wrong | nothing was sent |
|
|
60
|
+
| `4` | not authenticated | `crossly-buyer login` |
|
|
61
|
+
| `5` | authenticated, but missing a scope | re-consent — **not** re-login |
|
|
62
|
+
|
|
63
|
+
Code `5` exists because "your token expired" and "you were never granted `buyer:cashback:read`" need different fixes, and a wrapper that collapses them will guess wrong on the scope case.
|
|
64
|
+
|
|
65
|
+
## Money renders as money
|
|
66
|
+
|
|
67
|
+
Columns ending in `Cents` are formatted as `$45.00` in table output. `--json` leaves the raw integer alone — a script piping to `jq` is the second-biggest consumer of this tool, and reshaping "helpfully" breaks it silently.
|
|
68
|
+
|
|
69
|
+
## Auth
|
|
70
|
+
|
|
71
|
+
```bash
|
|
72
|
+
crossly-buyer login --token crossly_oat_... # stored 0600 at ~/.crossly/buyer-auth.json
|
|
73
|
+
crossly-buyer whoami
|
|
74
|
+
crossly-buyer logout
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
`CROSSLY_BUYER_TOKEN` in the environment takes precedence, so CI needs no file and a shell can override a stale token without logging out.
|
|
78
|
+
|
|
79
|
+
Stored separately from the seller CLI's `~/.crossly/auth.json` on purpose — sharing one file would mean `crossly login` and `crossly-buyer login` silently overwrite each other.
|
|
80
|
+
|
|
81
|
+
A seller PAT is refused **at login**, not at first use. Storing it would make every later command fail with an unrelated-looking 403.
|
|
82
|
+
|
|
83
|
+
## Also available
|
|
84
|
+
|
|
85
|
+
- [`@crossly/buyer-sdk`](https://github.com/crossly-dev/crossly-sdk/tree/main/buyer) — TypeScript client
|
|
86
|
+
- [`@crossly/buyer-mcp`](https://github.com/crossly-dev/crossly-mcp/tree/main/buyer) — the same surface as MCP tools
|
|
87
|
+
|
|
88
|
+
## Building from source
|
|
89
|
+
|
|
90
|
+
The command tree is generated from the [`@crossly/buyer-mcp`](https://github.com/crossly-dev/crossly-mcp/tree/main/buyer) tool registry, so a tool added there is a command here with no second list (a test fails if the map and the registry drift).
|
|
91
|
+
|
|
92
|
+
In the Crossly monorepo:
|
|
93
|
+
|
|
94
|
+
```bash
|
|
95
|
+
pnpm --filter @crossly/buyer-cli test # no build needed: the tests read buyer-mcp and buyer-sdk from source
|
|
96
|
+
pnpm --filter @crossly/buyer-cli build:deps # builds buyer-sdk, then buyer-mcp (what the binary imports at run time)
|
|
97
|
+
pnpm --filter @crossly/buyer-cli build
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
`pnpm -r build` does the same in dependency order.
|
|
101
|
+
|
|
102
|
+
## License
|
|
103
|
+
|
|
104
|
+
MIT
|
package/dist/auth.d.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export declare const AUTH_PATH: string;
|
|
2
|
+
export interface StoredAuth {
|
|
3
|
+
token: string;
|
|
4
|
+
/** Scopes the token was granted, when the issuer told us. */
|
|
5
|
+
scopes?: string[];
|
|
6
|
+
baseUrl?: string;
|
|
7
|
+
savedAt?: string;
|
|
8
|
+
}
|
|
9
|
+
export declare function save(auth: StoredAuth): void;
|
|
10
|
+
export declare function load(): StoredAuth | null;
|
|
11
|
+
export declare function clear(): boolean;
|
|
12
|
+
/**
|
|
13
|
+
* The token to use, preferring the environment.
|
|
14
|
+
*
|
|
15
|
+
* Env first so CI can inject one without writing a file, and so a shell can
|
|
16
|
+
* override a stale stored token without logging out.
|
|
17
|
+
*/
|
|
18
|
+
export declare function resolveToken(): {
|
|
19
|
+
token: string;
|
|
20
|
+
baseUrl?: string;
|
|
21
|
+
};
|
|
22
|
+
//# sourceMappingURL=auth.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../src/auth.ts"],"names":[],"mappings":"AAoBA,eAAO,MAAM,SAAS,QAAiD,CAAC;AAExE,MAAM,WAAW,UAAU;IACzB,KAAK,EAAE,MAAM,CAAC;IACd,6DAA6D;IAC7D,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;IAClB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,wBAAgB,IAAI,CAAC,IAAI,EAAE,UAAU,GAAG,IAAI,CAU3C;AAED,wBAAgB,IAAI,IAAI,UAAU,GAAG,IAAI,CAOxC;AAED,wBAAgB,KAAK,IAAI,OAAO,CAI/B;AAED;;;;;GAKG;AACH,wBAAgB,YAAY,IAAI;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,OAAO,CAAC,EAAE,MAAM,CAAA;CAAE,CAoBlE"}
|
package/dist/auth.js
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Where the buyer token lives.
|
|
3
|
+
*
|
|
4
|
+
* ── A FILE, NOT THE OS KEYCHAIN ──────────────────────────────────────
|
|
5
|
+
* Same reasoning as @crossly/cli: every keychain binding is a native module,
|
|
6
|
+
* and a native module in a globally-installed CLI turns `npm i -g` into a
|
|
7
|
+
* compiler error on someone's laptop. A 0600 file in the user's home directory
|
|
8
|
+
* is what gh, aws and stripe ship, and it is the right trade.
|
|
9
|
+
*
|
|
10
|
+
* ── SEPARATE FILE FROM THE SELLER CLI ────────────────────────────────
|
|
11
|
+
* `~/.crossly/auth.json` holds a seller token, this holds a buyer one. Sharing
|
|
12
|
+
* one file would mean `crossly login` and `crossly-buyer login` overwrite each
|
|
13
|
+
* other, and the symptom — every other command 403s until you log in again —
|
|
14
|
+
* would be maddening to diagnose.
|
|
15
|
+
*/
|
|
16
|
+
import { chmodSync, existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
|
|
17
|
+
import { homedir } from 'node:os';
|
|
18
|
+
import { dirname, join } from 'node:path';
|
|
19
|
+
import { CliError, EXIT } from './exit.js';
|
|
20
|
+
export const AUTH_PATH = join(homedir(), '.crossly', 'buyer-auth.json');
|
|
21
|
+
export function save(auth) {
|
|
22
|
+
mkdirSync(dirname(AUTH_PATH), { recursive: true });
|
|
23
|
+
writeFileSync(AUTH_PATH, JSON.stringify({ ...auth, savedAt: new Date().toISOString() }, null, 2));
|
|
24
|
+
// Best-effort: chmod is a no-op on Windows, which is why the file also lives
|
|
25
|
+
// under the user profile rather than anywhere shared.
|
|
26
|
+
try {
|
|
27
|
+
chmodSync(AUTH_PATH, 0o600);
|
|
28
|
+
}
|
|
29
|
+
catch {
|
|
30
|
+
/* windows */
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
export function load() {
|
|
34
|
+
if (!existsSync(AUTH_PATH))
|
|
35
|
+
return null;
|
|
36
|
+
try {
|
|
37
|
+
return JSON.parse(readFileSync(AUTH_PATH, 'utf8'));
|
|
38
|
+
}
|
|
39
|
+
catch {
|
|
40
|
+
return null;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
export function clear() {
|
|
44
|
+
if (!existsSync(AUTH_PATH))
|
|
45
|
+
return false;
|
|
46
|
+
rmSync(AUTH_PATH);
|
|
47
|
+
return true;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* The token to use, preferring the environment.
|
|
51
|
+
*
|
|
52
|
+
* Env first so CI can inject one without writing a file, and so a shell can
|
|
53
|
+
* override a stale stored token without logging out.
|
|
54
|
+
*/
|
|
55
|
+
export function resolveToken() {
|
|
56
|
+
const fromEnv = process.env.CROSSLY_BUYER_TOKEN;
|
|
57
|
+
if (fromEnv)
|
|
58
|
+
return { token: fromEnv, baseUrl: process.env.CROSSLY_API_BASE_URL };
|
|
59
|
+
const stored = load();
|
|
60
|
+
if (stored?.token) {
|
|
61
|
+
return { token: stored.token, baseUrl: process.env.CROSSLY_API_BASE_URL ?? stored.baseUrl };
|
|
62
|
+
}
|
|
63
|
+
// Name the seller token explicitly: someone with CROSSLY_PAT already exported
|
|
64
|
+
// will otherwise assume this CLI should have picked it up.
|
|
65
|
+
const hint = process.env.CROSSLY_PAT
|
|
66
|
+
? '\n\nNote: CROSSLY_PAT is set, but that is a SELLER token. The buyer API is a ' +
|
|
67
|
+
'separate principal and will reject it — use `crossly` for store commands.'
|
|
68
|
+
: '';
|
|
69
|
+
throw new CliError(`Not authenticated. Run \`crossly-buyer login\`, or set CROSSLY_BUYER_TOKEN.${hint}`, EXIT.unauthenticated);
|
|
70
|
+
}
|
|
71
|
+
//# sourceMappingURL=auth.js.map
|
package/dist/auth.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth.js","sourceRoot":"","sources":["../src/auth.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AACH,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAChG,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAClC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW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AAO,CAAC,GAAG,CAAC,oBAAoB,EAAE,CAAC;IAElF,MAAM,MAAM,GAAG,IAAI,EAAE,CAAC;IACtB,IAAI,MAAM,EAAE,KAAK,EAAE,CAAC;QAClB,OAAO,EAAE,KAAK,EAAE,MAAM,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,CAAC,GAAG,CAAC,oBAAoB,IAAI,MAAM,CAAC,OAAO,EAAE,CAAC;IAC9F,CAAC;IAED,8EAA8E;IAC9E,2DAA2D;IAC3D,MAAM,IAAI,GAAG,OAAO,CAAC,GAAG,CAAC,WAAW;QAClC,CAAC,CAAC,+EAA+E;YAC/E,2EAA2E;QAC7E,CAAC,CAAC,EAAE,CAAC;IAEP,MAAM,IAAI,QAAQ,CAChB,8EAA8E,IAAI,EAAE,EACpF,IAAI,CAAC,eAAe,CACrB,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The command tree, derived from the buyer MCP registry.
|
|
3
|
+
*
|
|
4
|
+
* ── WHY THE MAP IS EXPLICIT HERE ─────────────────────────────────────
|
|
5
|
+
* `@crossly/cli` derives 287 commands from tool names by rule, because at that
|
|
6
|
+
* size a rule is the only maintainable option and a wrong guess costs one odd
|
|
7
|
+
* verb. There are THIRTY buyer tools. A rule over that few names would produce
|
|
8
|
+
* `crossly-buyer my get-my-cart` and similar, which is worse in every way than
|
|
9
|
+
* writing `cart get` down once.
|
|
10
|
+
*
|
|
11
|
+
* The guard test asserts this map covers the registry exactly, so adding a tool
|
|
12
|
+
* without a command here fails the build rather than silently shipping a CLI
|
|
13
|
+
* that is missing an endpoint.
|
|
14
|
+
*/
|
|
15
|
+
import { ALL_TOOLS, type ToolDef } from '@crossly/buyer-mcp/registry';
|
|
16
|
+
export interface Command {
|
|
17
|
+
/** Noun the user types first, e.g. `cart`. */
|
|
18
|
+
group: string;
|
|
19
|
+
/** Verb after the noun, e.g. `get`. */
|
|
20
|
+
verb: string;
|
|
21
|
+
/** The MCP tool this runs. */
|
|
22
|
+
tool: string;
|
|
23
|
+
}
|
|
24
|
+
export declare const COMMANDS: Command[];
|
|
25
|
+
export declare const TOOL_BY_COMMAND: Map<string, ToolDef>;
|
|
26
|
+
/** Groups in a stable order, for help output. */
|
|
27
|
+
export declare function groups(): Map<string, Command[]>;
|
|
28
|
+
export { ALL_TOOLS };
|
|
29
|
+
export type { ToolDef };
|
|
30
|
+
//# sourceMappingURL=commands.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"commands.d.ts","sourceRoot":"","sources":["../src/commands.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,OAAO,EAAE,SAAS,EAAE,KAAK,OAAO,EAAE,MAAM,6BAA6B,CAAC;AAEtE,MAAM,WAAW,OAAO;IACtB,8CAA8C;IAC9C,KAAK,EAAE,MAAM,CAAC;IACd,uCAAuC;IACvC,IAAI,EAAE,MAAM,CAAC;IACb,8BAA8B;IAC9B,IAAI,EAAE,MAAM,CAAC;CACd;AAkJD,eAAO,MAAM,QAAQ,EAAE,OAAO,EAG5B,CAAC;AAEH,eAAO,MAAM,eAAe,sBAM3B,CAAC;AAEF,iDAAiD;AACjD,wBAAgB,MAAM,IAAI,GAAG,CAAC,MAAM,EAAE,OAAO,EAAE,CAAC,CAO/C;AAED,OAAO,EAAE,SAAS,EAAE,CAAC;AACrB,YAAY,EAAE,OAAO,EAAE,CAAC"}
|
package/dist/commands.js
ADDED
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The command tree, derived from the buyer MCP registry.
|
|
3
|
+
*
|
|
4
|
+
* ── WHY THE MAP IS EXPLICIT HERE ─────────────────────────────────────
|
|
5
|
+
* `@crossly/cli` derives 287 commands from tool names by rule, because at that
|
|
6
|
+
* size a rule is the only maintainable option and a wrong guess costs one odd
|
|
7
|
+
* verb. There are THIRTY buyer tools. A rule over that few names would produce
|
|
8
|
+
* `crossly-buyer my get-my-cart` and similar, which is worse in every way than
|
|
9
|
+
* writing `cart get` down once.
|
|
10
|
+
*
|
|
11
|
+
* The guard test asserts this map covers the registry exactly, so adding a tool
|
|
12
|
+
* without a command here fails the build rather than silently shipping a CLI
|
|
13
|
+
* that is missing an endpoint.
|
|
14
|
+
*/
|
|
15
|
+
import { ALL_TOOLS } from '@crossly/buyer-mcp/registry';
|
|
16
|
+
/**
|
|
17
|
+
* tool name → `<group> <verb>`.
|
|
18
|
+
*
|
|
19
|
+
* Read the right-hand column aloud: "cart get", "cart add", "offers make".
|
|
20
|
+
* That is the whole test for whether a name is right.
|
|
21
|
+
*/
|
|
22
|
+
const MAP = {
|
|
23
|
+
get_my_shopping_profile: 'profile get',
|
|
24
|
+
list_my_purchases: 'orders list',
|
|
25
|
+
get_my_cashback: 'cashback list',
|
|
26
|
+
get_my_cart: 'cart get',
|
|
27
|
+
add_to_my_cart: 'cart add',
|
|
28
|
+
remove_from_my_cart: 'cart remove',
|
|
29
|
+
quote_my_cart: 'cart quote',
|
|
30
|
+
list_my_wishlists: 'wishlists list',
|
|
31
|
+
get_my_wishlist_items: 'wishlists items',
|
|
32
|
+
create_my_wishlist: 'wishlists create',
|
|
33
|
+
add_to_my_wishlist: 'wishlists add',
|
|
34
|
+
report_shopping_activity: 'activity report',
|
|
35
|
+
list_my_shopping_activity: 'activity list',
|
|
36
|
+
// Saved cards (express checkout): list them, pick the default. Adding a card stays in the browser/app.
|
|
37
|
+
list_my_saved_cards: 'cards list',
|
|
38
|
+
set_my_default_card: 'cards default',
|
|
39
|
+
get_my_shopping_preferences: 'activity preferences',
|
|
40
|
+
offer_on_listing: 'offers make',
|
|
41
|
+
list_shopping_agent_sessions: 'agent list',
|
|
42
|
+
start_shopping_agent: 'agent start',
|
|
43
|
+
get_shopping_agent_session: 'agent get',
|
|
44
|
+
delete_shopping_agent_session: 'agent delete',
|
|
45
|
+
talk_to_shopping_agent: 'agent say',
|
|
46
|
+
react_to_agent_option: 'agent react',
|
|
47
|
+
act_on_agent_option: 'agent act',
|
|
48
|
+
// Vault Markets, read only: what the vault is worth, and the quotes behind it.
|
|
49
|
+
get_my_vault_worth: 'vault worth',
|
|
50
|
+
list_my_vault_holdings: 'vault holdings',
|
|
51
|
+
get_my_vault_history: 'vault history',
|
|
52
|
+
list_my_vault_watchlist: 'vault watchlist',
|
|
53
|
+
list_my_instant_exit_quotes: 'vault exits',
|
|
54
|
+
get_my_instant_exit_quote: 'vault exit',
|
|
55
|
+
list_vault_indexes: 'vault indexes',
|
|
56
|
+
get_vault_index: 'vault index',
|
|
57
|
+
// Vault Shares, read only.
|
|
58
|
+
get_my_vault_shares: 'vault shares',
|
|
59
|
+
list_vault_share_series: 'vault share-series',
|
|
60
|
+
get_vault_share_series: 'vault share-series-get',
|
|
61
|
+
// Fractional options, read only.
|
|
62
|
+
list_vault_option_series: 'options series',
|
|
63
|
+
get_vault_option_chain: 'options chain',
|
|
64
|
+
get_vault_option_implied_vol: 'options iv',
|
|
65
|
+
list_my_vault_option_positions: 'options positions',
|
|
66
|
+
list_vault_option_strategies: 'options strategies',
|
|
67
|
+
get_vault_options_analytics: 'options analytics',
|
|
68
|
+
get_my_vault_options_risk: 'options risk',
|
|
69
|
+
list_my_vault_option_strategies: 'options my-strategies',
|
|
70
|
+
list_my_vault_option_notices: 'options notices',
|
|
71
|
+
list_vault_prediction_markets: 'vault predictions',
|
|
72
|
+
get_vault_prediction_market: 'vault prediction',
|
|
73
|
+
list_my_prediction_positions: 'vault prediction-positions',
|
|
74
|
+
get_vault_predictions_board: 'vault prediction-board',
|
|
75
|
+
get_vault_prediction_history: 'vault prediction-history',
|
|
76
|
+
get_vault_prediction_event: 'vault prediction-event',
|
|
77
|
+
get_vault_prediction_leaderboard: 'vault prediction-leaderboard',
|
|
78
|
+
list_vault_prediction_comments: 'vault prediction-comments',
|
|
79
|
+
// Vault Shares round 14, read only.
|
|
80
|
+
get_vault_share_drops: 'vault share-drops',
|
|
81
|
+
list_vault_share_baskets: 'vault share-baskets',
|
|
82
|
+
get_vault_share_basket: 'vault share-basket',
|
|
83
|
+
get_vault_share_price_history: 'vault share-history',
|
|
84
|
+
get_vault_share_perks: 'vault share-perks',
|
|
85
|
+
list_my_vault_share_auto_invest: 'vault share-auto-invest',
|
|
86
|
+
list_my_vault_share_gifts: 'vault share-gifts',
|
|
87
|
+
// Loyalty clubs: tiers, progress, typed perks; join or leave.
|
|
88
|
+
list_my_loyalty_clubs: 'loyalty list',
|
|
89
|
+
get_seller_loyalty_club: 'loyalty club',
|
|
90
|
+
join_seller_loyalty_club: 'loyalty join',
|
|
91
|
+
leave_seller_loyalty_club: 'loyalty leave',
|
|
92
|
+
// Points history (E2) and the rewards shelf (E3): spend points on typed perks.
|
|
93
|
+
list_my_loyalty_points: 'loyalty points',
|
|
94
|
+
list_loyalty_rewards_shelf: 'loyalty rewards',
|
|
95
|
+
redeem_loyalty_reward: 'loyalty redeem',
|
|
96
|
+
// Group buys (E4): the tier share link.
|
|
97
|
+
get_group_buy_share_link: 'group-buys share',
|
|
98
|
+
// Store browsing: a store's listings with program chips.
|
|
99
|
+
browse_store_listings: 'stores listings',
|
|
100
|
+
// Wholesale buying (W3): quotes, order sheets, reorder, CSV / PO, the trade cart, suppliers, statement.
|
|
101
|
+
list_my_wholesale_quotes: 'trade quotes',
|
|
102
|
+
request_wholesale_quote: 'trade request-quote',
|
|
103
|
+
get_my_wholesale_quote: 'trade quote',
|
|
104
|
+
accept_wholesale_quote: 'trade accept-quote',
|
|
105
|
+
withdraw_wholesale_quote: 'trade withdraw-quote',
|
|
106
|
+
list_my_order_sheets: 'trade sheets',
|
|
107
|
+
get_my_order_sheet: 'trade sheet',
|
|
108
|
+
save_order_sheet: 'trade save-sheet',
|
|
109
|
+
update_order_sheet: 'trade update-sheet',
|
|
110
|
+
delete_order_sheet: 'trade delete-sheet',
|
|
111
|
+
list_my_wholesale_orders: 'trade orders',
|
|
112
|
+
reorder_wholesale_order: 'trade reorder',
|
|
113
|
+
validate_wholesale_upload: 'trade validate-upload',
|
|
114
|
+
get_my_wholesale_cart: 'trade cart',
|
|
115
|
+
set_wholesale_po_reference: 'trade set-po',
|
|
116
|
+
list_my_suppliers: 'trade suppliers',
|
|
117
|
+
get_my_trade_statement: 'trade statement',
|
|
118
|
+
list_my_freight_requests: 'trade freight-requests',
|
|
119
|
+
request_freight_quote: 'trade request-freight',
|
|
120
|
+
get_catalog_application_form: 'trade apply-form',
|
|
121
|
+
apply_to_wholesale_catalog: 'trade apply',
|
|
122
|
+
// Product passports: verify an item by its tag's code, claim it as its new owner.
|
|
123
|
+
get_product_passport: 'passports verify',
|
|
124
|
+
claim_product_passport: 'passports claim',
|
|
125
|
+
// Your World home (WD8: it lives on the buyer account): the home, what can go in it, its co-builders, the guestbook.
|
|
126
|
+
get_my_home: 'home get',
|
|
127
|
+
update_my_home: 'home update',
|
|
128
|
+
set_my_home_layout: 'home set-layout',
|
|
129
|
+
list_my_home_placeable: 'home placeable',
|
|
130
|
+
list_my_home_builders: 'home builders',
|
|
131
|
+
set_my_home_builders: 'home set-builders',
|
|
132
|
+
hide_my_home_guestbook_entry: 'home hide-guestbook-entry',
|
|
133
|
+
list_homes_i_co_build: 'home co-building',
|
|
134
|
+
list_my_pets: 'home pets',
|
|
135
|
+
set_my_active_pet: 'home set-pet',
|
|
136
|
+
// Your wallets: the perks (holder discounts) the NFTs in them unlock.
|
|
137
|
+
list_my_wallet_perks: 'wallets perks',
|
|
138
|
+
// W7 buyer companies: teammates, roles, approval limits, spend approvals, shared addresses; paying an invoice.
|
|
139
|
+
get_my_company: 'company get',
|
|
140
|
+
create_company: 'company create',
|
|
141
|
+
update_company: 'company update',
|
|
142
|
+
invite_company_member: 'company invite',
|
|
143
|
+
update_company_member: 'company update-member',
|
|
144
|
+
remove_company_member: 'company remove-member',
|
|
145
|
+
set_company_addresses: 'company set-addresses',
|
|
146
|
+
list_spend_approvals: 'company approvals',
|
|
147
|
+
request_spend_approval: 'company request-approval',
|
|
148
|
+
decide_spend_approval: 'company decide-approval',
|
|
149
|
+
get_invoice_pay_quote: 'trade invoice-pay-quote',
|
|
150
|
+
get_invoice_pay_link: 'trade invoice-pay-link',
|
|
151
|
+
};
|
|
152
|
+
export const COMMANDS = Object.entries(MAP).map(([tool, path]) => {
|
|
153
|
+
const [group, verb] = path.split(' ');
|
|
154
|
+
return { group: group, verb: verb, tool };
|
|
155
|
+
});
|
|
156
|
+
export const TOOL_BY_COMMAND = new Map(COMMANDS.map((c) => {
|
|
157
|
+
const tool = ALL_TOOLS.find((t) => t.name === c.tool);
|
|
158
|
+
if (!tool)
|
|
159
|
+
throw new Error(`commands.ts maps ${c.tool}, which is not in the registry`);
|
|
160
|
+
return [`${c.group} ${c.verb}`, tool];
|
|
161
|
+
}));
|
|
162
|
+
/** Groups in a stable order, for help output. */
|
|
163
|
+
export function groups() {
|
|
164
|
+
const out = new Map();
|
|
165
|
+
for (const c of COMMANDS) {
|
|
166
|
+
if (!out.has(c.group))
|
|
167
|
+
out.set(c.group, []);
|
|
168
|
+
out.get(c.group).push(c);
|
|
169
|
+
}
|
|
170
|
+
return out;
|
|
171
|
+
}
|
|
172
|
+
export { ALL_TOOLS };
|
|
173
|
+
//# sourceMappingURL=commands.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"commands.js","sourceRoot":"","sources":["../src/commands.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,OAAO,EAAE,SAAS,EAAgB,MAAM,6BAA6B,CAAC;AAWtE;;;;;GAKG;AACH,MAAM,GAAG,GAA2B;IAClC,uBAAuB,EAAE,aAAa;IACtC,iBAAiB,EAAE,aAAa;IAChC,eAAe,EAAE,eAAe;IAEhC,WAAW,EAAE,UAAU;IACvB,cAAc,EAAE,UAAU;IAC1B,mBAAmB,EAAE,aAAa;IAClC,aAAa,EAAE,YAAY;IAE3B,iBAAiB,EAAE,gBAAgB;IACnC,qBAAqB,EAAE,iBAAiB;IACxC,kBAAkB,EAAE,kBAAkB;IACt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C,CAAC,IAAI,CAAC,CAAC;IACtD,IAAI,CAAC,IAAI;QAAE,MAAM,IAAI,KAAK,CAAC,oBAAoB,CAAC,CAAC,IAAI,gCAAgC,CAAC,CAAC;IACvF,OAAO,CAAC,GAAG,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,IAAI,CAAC,CAAC;AACxC,CAAC,CAAC,CACH,CAAC;AAEF,iDAAiD;AACjD,MAAM,UAAU,MAAM;IACpB,MAAM,GAAG,GAAG,IAAI,GAAG,EAAqB,CAAC;IACzC,KAAK,MAAM,CAAC,IAAI,QAAQ,EAAE,CAAC;QACzB,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,KAAK,CAAC;YAAE,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;QAC5C,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,KAAK,CAAE,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAC5B,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC;AAED,OAAO,EAAE,SAAS,EAAE,CAAC"}
|
package/dist/exit.d.ts
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Exit codes.
|
|
3
|
+
*
|
|
4
|
+
* Distinct codes for distinct remedies — that is the whole point. A script
|
|
5
|
+
* wrapping this needs to tell "your token expired, re-auth" from "you asked for
|
|
6
|
+
* a scope you were never granted, send the user back through consent" from "the
|
|
7
|
+
* listing does not exist". Collapsing all of those into 1 makes the wrapper
|
|
8
|
+
* guess, and it will guess wrong on the scope case.
|
|
9
|
+
*
|
|
10
|
+
* Matches @crossly/cli so a script can treat both the same way.
|
|
11
|
+
*/
|
|
12
|
+
export declare const EXIT: {
|
|
13
|
+
readonly ok: 0;
|
|
14
|
+
/** The request was well-formed and the API said no, or the network failed. */
|
|
15
|
+
readonly failure: 1;
|
|
16
|
+
/** The user typed something wrong. Nothing was sent. */
|
|
17
|
+
readonly usage: 2;
|
|
18
|
+
/** No token, or the token is rejected. Remedy: authenticate. */
|
|
19
|
+
readonly unauthenticated: 4;
|
|
20
|
+
/** Authenticated, but the token lacks the scope. Remedy: re-consent. */
|
|
21
|
+
readonly forbiddenScope: 5;
|
|
22
|
+
};
|
|
23
|
+
export type ExitCode = (typeof EXIT)[keyof typeof EXIT];
|
|
24
|
+
export declare class CliError extends Error {
|
|
25
|
+
readonly code: ExitCode;
|
|
26
|
+
/** The API's correlation id, when there was one — the thread back to logs. */
|
|
27
|
+
readonly correlationId?: string;
|
|
28
|
+
constructor(message: string, code?: ExitCode, correlationId?: string);
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Map a thrown error onto an exit code.
|
|
32
|
+
*
|
|
33
|
+
* The scope case is why this is a function rather than a constant: a 403 whose
|
|
34
|
+
* body mentions a scope is a DIFFERENT problem from a 403 that does not, and
|
|
35
|
+
* only the message distinguishes them.
|
|
36
|
+
*/
|
|
37
|
+
export declare function exitCodeFor(err: unknown): ExitCode;
|
|
38
|
+
//# sourceMappingURL=exit.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"exit.d.ts","sourceRoot":"","sources":["../src/exit.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,eAAO,MAAM,IAAI;;IAEf,8EAA8E;;IAE9E,wDAAwD;;IAExD,gEAAgE;;IAEhE,wEAAwE;;CAEhE,CAAC;AAEX,MAAM,MAAM,QAAQ,GAAG,CAAC,OAAO,IAAI,CAAC,CAAC,MAAM,OAAO,IAAI,CAAC,CAAC;AAExD,qBAAa,QAAS,SAAQ,KAAK;IACjC,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC;IACxB,8EAA8E;IAC9E,QAAQ,CAAC,aAAa,CAAC,EAAE,MAAM,CAAC;gBAEpB,OAAO,EAAE,MAAM,EAAE,IAAI,GAAE,QAAuB,EAAE,aAAa,CAAC,EAAE,MAAM;CAMnF;AAED;;;;;;GAMG;AACH,wBAAgB,WAAW,CAAC,GAAG,EAAE,OAAO,GAAG,QAAQ,CAUlD"}
|
package/dist/exit.js
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Exit codes.
|
|
3
|
+
*
|
|
4
|
+
* Distinct codes for distinct remedies — that is the whole point. A script
|
|
5
|
+
* wrapping this needs to tell "your token expired, re-auth" from "you asked for
|
|
6
|
+
* a scope you were never granted, send the user back through consent" from "the
|
|
7
|
+
* listing does not exist". Collapsing all of those into 1 makes the wrapper
|
|
8
|
+
* guess, and it will guess wrong on the scope case.
|
|
9
|
+
*
|
|
10
|
+
* Matches @crossly/cli so a script can treat both the same way.
|
|
11
|
+
*/
|
|
12
|
+
export const EXIT = {
|
|
13
|
+
ok: 0,
|
|
14
|
+
/** The request was well-formed and the API said no, or the network failed. */
|
|
15
|
+
failure: 1,
|
|
16
|
+
/** The user typed something wrong. Nothing was sent. */
|
|
17
|
+
usage: 2,
|
|
18
|
+
/** No token, or the token is rejected. Remedy: authenticate. */
|
|
19
|
+
unauthenticated: 4,
|
|
20
|
+
/** Authenticated, but the token lacks the scope. Remedy: re-consent. */
|
|
21
|
+
forbiddenScope: 5,
|
|
22
|
+
};
|
|
23
|
+
export class CliError extends Error {
|
|
24
|
+
code;
|
|
25
|
+
/** The API's correlation id, when there was one — the thread back to logs. */
|
|
26
|
+
correlationId;
|
|
27
|
+
constructor(message, code = EXIT.failure, correlationId) {
|
|
28
|
+
super(message);
|
|
29
|
+
this.name = 'CliError';
|
|
30
|
+
this.code = code;
|
|
31
|
+
this.correlationId = correlationId;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Map a thrown error onto an exit code.
|
|
36
|
+
*
|
|
37
|
+
* The scope case is why this is a function rather than a constant: a 403 whose
|
|
38
|
+
* body mentions a scope is a DIFFERENT problem from a 403 that does not, and
|
|
39
|
+
* only the message distinguishes them.
|
|
40
|
+
*/
|
|
41
|
+
export function exitCodeFor(err) {
|
|
42
|
+
if (err instanceof CliError)
|
|
43
|
+
return err.code;
|
|
44
|
+
const status = err?.status;
|
|
45
|
+
if (status === 401)
|
|
46
|
+
return EXIT.unauthenticated;
|
|
47
|
+
if (status === 403) {
|
|
48
|
+
const text = `${err?.code ?? ''} ${err?.message ?? ''}`;
|
|
49
|
+
return /scope/i.test(text) ? EXIT.forbiddenScope : EXIT.failure;
|
|
50
|
+
}
|
|
51
|
+
return EXIT.failure;
|
|
52
|
+
}
|
|
53
|
+
//# sourceMappingURL=exit.js.map
|
package/dist/exit.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"exit.js","sourceRoot":"","sources":["../src/exit.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,MAAM,CAAC,MAAM,IAAI,GAAG;IAClB,EAAE,EAAE,CAAC;IACL,8EAA8E;IAC9E,OAAO,EAAE,CAAC;IACV,wDAAwD;IACxD,KAAK,EAAE,CAAC;IACR,gEAAgE;IAChE,eAAe,EAAE,CAAC;IAClB,wEAAwE;IACxE,cAAc,EAAE,CAAC;CACT,CAAC;AAIX,MAAM,OAAO,QAAS,SAAQ,KAAK;IACxB,IAAI,CAAW;IACxB,8EAA8E;IACrE,aAAa,CAAU;IAEhC,YAAY,OAAe,EAAE,OAAiB,IAAI,CAAC,OAAO,EAAE,aAAsB;QAChF,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,UAAU,CAAC;QACvB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,aAAa,GAAG,aAAa,CAAC;IACrC,CAAC;CACF;AAED;;;;;;GAMG;AACH,MAAM,UAAU,WAAW,CAAC,GAAY;IACtC,IAAI,GAAG,YAAY,QAAQ;QAAE,OAAO,GAAG,CAAC,IAAI,CAAC;IAE7C,MAAM,MAAM,GAAI,GAA2B,EAAE,MAAM,CAAC;IACpD,IAAI,MAAM,KAAK,GAAG;QAAE,OAAO,IAAI,CAAC,eAAe,CAAC;IAChD,IAAI,MAAM,KAAK,GAAG,EAAE,CAAC;QACnB,MAAM,IAAI,GAAG,GAAI,GAAyB,EAAE,IAAI,IAAI,EAAE,IAAK,GAAa,EAAE,OAAO,IAAI,EAAE,EAAE,CAAC;QAC1F,OAAO,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC;IAClE,CAAC;IACD,OAAO,IAAI,CAAC,OAAO,CAAC;AACtB,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAqMA,wBAAsB,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,MAAM,CAAC,CAwD1D"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* crossly-buyer — the Crossly Buyer API from the terminal.
|
|
4
|
+
*
|
|
5
|
+
* A shopper's account: cart, orders, wishlists, offers, cashback. For a
|
|
6
|
+
* seller's store — listings, crossposting, fulfilment — use `crossly`
|
|
7
|
+
* (@crossly/cli). They are different APIs with different credentials, which is
|
|
8
|
+
* why they are different binaries rather than one with a `--buyer` flag.
|
|
9
|
+
*
|
|
10
|
+
* NOTHING HERE SPENDS MONEY. `cart quote` prices a basket and `offers make`
|
|
11
|
+
* proposes a number; `agent act --type buy` returns a quote; no command
|
|
12
|
+
* completes a purchase.
|
|
13
|
+
*/
|
|
14
|
+
import { realpathSync } from 'node:fs';
|
|
15
|
+
import { fileURLToPath } from 'node:url';
|
|
16
|
+
import { configureClient } from '@crossly/buyer-mcp/api';
|
|
17
|
+
import { createBuyerClient } from '@crossly/buyer-sdk';
|
|
18
|
+
import * as auth from './auth.js';
|
|
19
|
+
import { groups, TOOL_BY_COMMAND } from './commands.js';
|
|
20
|
+
import { CliError, EXIT, exitCodeFor } from './exit.js';
|
|
21
|
+
import { render } from './output.js';
|
|
22
|
+
const BIN = 'crossly-buyer';
|
|
23
|
+
/** Flags the CLI consumes itself; everything else belongs to the tool schema. */
|
|
24
|
+
const GLOBAL_FLAGS = new Set(['json', 'ndjson', 'help', 'version', 'dry-run']);
|
|
25
|
+
function parseArgv(argv) {
|
|
26
|
+
const positional = [];
|
|
27
|
+
const flags = {};
|
|
28
|
+
for (let i = 0; i < argv.length; i += 1) {
|
|
29
|
+
const arg = argv[i];
|
|
30
|
+
if (!arg.startsWith('--')) {
|
|
31
|
+
positional.push(arg);
|
|
32
|
+
continue;
|
|
33
|
+
}
|
|
34
|
+
const body = arg.slice(2);
|
|
35
|
+
const eq = body.indexOf('=');
|
|
36
|
+
if (eq !== -1) {
|
|
37
|
+
flags[body.slice(0, eq)] = body.slice(eq + 1);
|
|
38
|
+
continue;
|
|
39
|
+
}
|
|
40
|
+
const next = argv[i + 1];
|
|
41
|
+
if (next !== undefined && !next.startsWith('--')) {
|
|
42
|
+
flags[body] = next;
|
|
43
|
+
i += 1;
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
flags[body] = true;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return { positional, flags };
|
|
50
|
+
}
|
|
51
|
+
/** `--limit 25` arrives as a string; the schema says integer. Coerce by schema. */
|
|
52
|
+
function coerce(tool, flags) {
|
|
53
|
+
const props = tool.inputSchema.properties;
|
|
54
|
+
const out = {};
|
|
55
|
+
for (const [key, raw] of Object.entries(flags)) {
|
|
56
|
+
if (GLOBAL_FLAGS.has(key))
|
|
57
|
+
continue;
|
|
58
|
+
const spec = props[key];
|
|
59
|
+
if (!spec) {
|
|
60
|
+
const known = Object.keys(props).sort();
|
|
61
|
+
throw new CliError(`Unknown flag --${key}. ` +
|
|
62
|
+
(known.length
|
|
63
|
+
? `This command accepts: ${known.map((k) => `--${k}`).join(', ')}`
|
|
64
|
+
: 'This command takes no flags.'), EXIT.usage);
|
|
65
|
+
}
|
|
66
|
+
if (spec.type === 'integer' || spec.type === 'number') {
|
|
67
|
+
const n = Number(raw);
|
|
68
|
+
if (!Number.isFinite(n))
|
|
69
|
+
throw new CliError(`--${key} expects a number, got "${raw}".`, EXIT.usage);
|
|
70
|
+
out[key] = n;
|
|
71
|
+
}
|
|
72
|
+
else if (spec.type === 'boolean') {
|
|
73
|
+
out[key] = raw === true || raw === 'true';
|
|
74
|
+
}
|
|
75
|
+
else {
|
|
76
|
+
out[key] = String(raw);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
const missing = (tool.inputSchema.required ?? []).filter((k) => out[k] === undefined);
|
|
80
|
+
if (missing.length) {
|
|
81
|
+
throw new CliError(`Missing required flag${missing.length > 1 ? 's' : ''}: ${missing.map((m) => `--${m}`).join(', ')}`, EXIT.usage);
|
|
82
|
+
}
|
|
83
|
+
return out;
|
|
84
|
+
}
|
|
85
|
+
function topHelp() {
|
|
86
|
+
const lines = [
|
|
87
|
+
`${BIN} — your Crossly shopping, from the terminal`,
|
|
88
|
+
'',
|
|
89
|
+
` ${BIN} <group> <command> [flags]`,
|
|
90
|
+
'',
|
|
91
|
+
];
|
|
92
|
+
for (const [group, cmds] of groups()) {
|
|
93
|
+
lines.push(` ${group}`);
|
|
94
|
+
for (const c of cmds) {
|
|
95
|
+
const tool = TOOL_BY_COMMAND.get(`${c.group} ${c.verb}`);
|
|
96
|
+
// One line each: the first sentence of the tool description.
|
|
97
|
+
const first = tool.description.split(/(?<=\.)\s/)[0] ?? tool.description;
|
|
98
|
+
lines.push(` ${c.verb.padEnd(13)} ${first.slice(0, 92)}`);
|
|
99
|
+
}
|
|
100
|
+
lines.push('');
|
|
101
|
+
}
|
|
102
|
+
lines.push(' auth', ' login Store a buyer OAuth token', ' logout Forget the stored token', ' whoami Show who the stored token belongs to', '', ' Global flags: --json --ndjson --dry-run --help --version', '', ` Managing a STORE rather than shopping? That is \`crossly\` (@crossly/cli) —`, ' a different API with a different token.', '');
|
|
103
|
+
return lines.join('\n');
|
|
104
|
+
}
|
|
105
|
+
function commandHelp(group, verb, tool) {
|
|
106
|
+
const props = tool.inputSchema.properties;
|
|
107
|
+
const required = new Set(tool.inputSchema.required ?? []);
|
|
108
|
+
const lines = [`${BIN} ${group} ${verb}`, '', ` ${tool.description}`, ''];
|
|
109
|
+
const keys = Object.keys(props);
|
|
110
|
+
if (keys.length) {
|
|
111
|
+
lines.push(' Flags:');
|
|
112
|
+
for (const k of keys) {
|
|
113
|
+
const spec = props[k];
|
|
114
|
+
const tag = required.has(k) ? ' (required)' : '';
|
|
115
|
+
lines.push(` --${k} <${spec.type ?? 'string'}>${tag}`);
|
|
116
|
+
if (spec.description)
|
|
117
|
+
lines.push(` ${spec.description}`);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
else {
|
|
121
|
+
lines.push(' Takes no flags.');
|
|
122
|
+
}
|
|
123
|
+
lines.push('');
|
|
124
|
+
return lines.join('\n');
|
|
125
|
+
}
|
|
126
|
+
async function runAuth(verb, flags) {
|
|
127
|
+
if (verb === 'logout') {
|
|
128
|
+
process.stdout.write(auth.clear() ? 'Logged out.\n' : 'Was not logged in.\n');
|
|
129
|
+
return EXIT.ok;
|
|
130
|
+
}
|
|
131
|
+
if (verb === 'login') {
|
|
132
|
+
const token = typeof flags.token === 'string' ? flags.token : undefined;
|
|
133
|
+
if (!token) {
|
|
134
|
+
process.stdout.write('Pass a buyer OAuth token:\n\n' +
|
|
135
|
+
` ${BIN} login --token <Atlas access token, or a legacy crossly_oat_...>\n\n` +
|
|
136
|
+
'Buyer tokens come from the Crossly OAuth consent screen — there is no\n' +
|
|
137
|
+
'buyer equivalent of a personal access token, because the scopes are\n' +
|
|
138
|
+
'granted by a person agreeing to them.\n');
|
|
139
|
+
return EXIT.usage;
|
|
140
|
+
}
|
|
141
|
+
// Validate by constructing a client: wrong-kind tokens throw here with a
|
|
142
|
+
// message that names the mistake, rather than being stored and failing
|
|
143
|
+
// on every subsequent command.
|
|
144
|
+
createBuyerClient({ token });
|
|
145
|
+
auth.save({ token });
|
|
146
|
+
process.stdout.write(`Saved to ${auth.AUTH_PATH}\n`);
|
|
147
|
+
return EXIT.ok;
|
|
148
|
+
}
|
|
149
|
+
if (verb === 'whoami') {
|
|
150
|
+
const { token, baseUrl } = auth.resolveToken();
|
|
151
|
+
const client = createBuyerClient({ token, ...(baseUrl ? { baseUrl } : {}) });
|
|
152
|
+
const profile = await client.profile.get();
|
|
153
|
+
process.stdout.write(render(profile, { json: flags.json === true }) + '\n');
|
|
154
|
+
return EXIT.ok;
|
|
155
|
+
}
|
|
156
|
+
throw new CliError(`Unknown auth command: ${verb}`, EXIT.usage);
|
|
157
|
+
}
|
|
158
|
+
export async function main(argv) {
|
|
159
|
+
const { positional, flags } = parseArgv(argv);
|
|
160
|
+
if (flags.version === true) {
|
|
161
|
+
process.stdout.write('0.1.0\n');
|
|
162
|
+
return EXIT.ok;
|
|
163
|
+
}
|
|
164
|
+
if (!positional.length) {
|
|
165
|
+
process.stdout.write(topHelp());
|
|
166
|
+
// Asked for help: success. No command at all: a usage error, so a script that typo'd it away does not see 0.
|
|
167
|
+
return flags.help === true ? EXIT.ok : EXIT.usage;
|
|
168
|
+
}
|
|
169
|
+
const [first, second] = positional;
|
|
170
|
+
// `login` / `logout` / `whoami` read better without an `auth` prefix.
|
|
171
|
+
if (first === 'login' || first === 'logout' || first === 'whoami') {
|
|
172
|
+
return runAuth(first, flags);
|
|
173
|
+
}
|
|
174
|
+
if (first === 'auth' && second)
|
|
175
|
+
return runAuth(second, flags);
|
|
176
|
+
if (!second) {
|
|
177
|
+
const cmds = groups().get(first);
|
|
178
|
+
if (!cmds)
|
|
179
|
+
throw new CliError(`Unknown group: ${first}. Run \`${BIN}\` to see them.`, EXIT.usage);
|
|
180
|
+
process.stdout.write(`${BIN} ${first} <command>\n\n` + cmds.map((c) => ` ${c.verb}`).join('\n') + '\n\n');
|
|
181
|
+
return EXIT.usage;
|
|
182
|
+
}
|
|
183
|
+
const key = `${first} ${second}`;
|
|
184
|
+
const tool = TOOL_BY_COMMAND.get(key);
|
|
185
|
+
if (!tool) {
|
|
186
|
+
throw new CliError(`Unknown command: ${key}. Run \`${BIN}\` to see them.`, EXIT.usage);
|
|
187
|
+
}
|
|
188
|
+
// --help must never touch the network or require a token. This is the bug
|
|
189
|
+
// that shipped in the seller CLI: two branches missed the check and
|
|
190
|
+
// `inventory export --help` exited 4 for anyone not logged in.
|
|
191
|
+
if (flags.help === true) {
|
|
192
|
+
process.stdout.write(commandHelp(first, second, tool));
|
|
193
|
+
return EXIT.ok;
|
|
194
|
+
}
|
|
195
|
+
const args = coerce(tool, flags);
|
|
196
|
+
if (flags['dry-run'] === true) {
|
|
197
|
+
process.stdout.write(render({ tool: tool.name, args, wouldSend: true }, { json: flags.json === true }) + '\n');
|
|
198
|
+
return EXIT.ok;
|
|
199
|
+
}
|
|
200
|
+
const { token, baseUrl } = auth.resolveToken();
|
|
201
|
+
configureClient(createBuyerClient({ token, ...(baseUrl ? { baseUrl } : {}) }));
|
|
202
|
+
const result = await tool.handler(args);
|
|
203
|
+
process.stdout.write(render(result, { json: flags.json === true, ndjson: flags.ndjson === true }) + '\n');
|
|
204
|
+
return EXIT.ok;
|
|
205
|
+
}
|
|
206
|
+
/**
|
|
207
|
+
* Is this module the program being run (not imported by a test or a bundled binary)? Compared by real path: the
|
|
208
|
+
* old test was a regex on `buyer-cli/(dist|src)/index.js`, so a renamed install directory, or a bin symlink npm
|
|
209
|
+
* resolves elsewhere, never started at all.
|
|
210
|
+
*/
|
|
211
|
+
function isEntry() {
|
|
212
|
+
if (!process.argv[1])
|
|
213
|
+
return false;
|
|
214
|
+
try {
|
|
215
|
+
return realpathSync(process.argv[1]) === realpathSync(fileURLToPath(import.meta.url));
|
|
216
|
+
}
|
|
217
|
+
catch {
|
|
218
|
+
// argv[1] is not a file on disk (a REPL, `node -e`): not run as the CLI.
|
|
219
|
+
return false;
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
// Only run when executed, not when imported by a test.
|
|
223
|
+
if (isEntry()) {
|
|
224
|
+
main(process.argv.slice(2))
|
|
225
|
+
.then((code) => process.exit(code))
|
|
226
|
+
.catch((err) => {
|
|
227
|
+
const code = exitCodeFor(err);
|
|
228
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
229
|
+
process.stderr.write(`${msg}\n`);
|
|
230
|
+
const correlationId = err?.correlationId;
|
|
231
|
+
if (correlationId)
|
|
232
|
+
process.stderr.write(`correlationId: ${correlationId}\n`);
|
|
233
|
+
process.exit(code);
|
|
234
|
+
});
|
|
235
|
+
}
|
|
236
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AACA;;;;;;;;;;;GAWG;AACH,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAEzC,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AAEvD,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAClC,OAAO,EAAE,MAAM,EAAE,eAAe,EAAgB,MAAM,eAAe,CAAC;AACtE,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAiB,WAAW,EAAE,MAAM,WAAW,CAAC;AACvE,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAErC,MAAM,GAAG,GAAG,eAAe,CAAC;AAE5B,iFAAiF;AACjF,MAAM,YAAY,GAAG,IAAI,GAAG,CAAC,CAAC,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,SAAS,CAAC,CAAC,CAAC;AAO/E,SA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H,OAAO,YAAY,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,KAAK,YAAY,CAAC,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;IACxF,CAAC;IAAC,MAAM,CAAC;QACP,yEAAyE;QACzE,OAAO,KAAK,CAAC;IACf,CAAC;AACH,CAAC;AAED,uDAAuD;AACvD,IAAI,OAAO,EAAE,EAAE,CAAC;IACd,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;SACxB,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;SAClC,KAAK,CAAC,CAAC,GAAY,EAAE,EAAE;QACtB,MAAM,IAAI,GAAa,WAAW,CAAC,GAAG,CAAC,CAAC;QACxC,MAAM,GAAG,GAAG,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;QAC7D,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,GAAG,IAAI,CAAC,CAAC;QACjC,MAAM,aAAa,GAAI,GAAkC,EAAE,aAAa,CAAC;QACzE,IAAI,aAAa;YAAE,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,kBAAkB,aAAa,IAAI,CAAC,CAAC;QAC7E,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACrB,CAAC,CAAC,CAAC;AACP,CAAC"}
|
package/dist/output.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Rendering.
|
|
3
|
+
*
|
|
4
|
+
* Two modes and no cleverness: `--json` prints exactly what the API returned,
|
|
5
|
+
* anything else prints a table a person can read. The JSON mode must stay
|
|
6
|
+
* byte-faithful — a script piping to `jq` is the second-biggest consumer of
|
|
7
|
+
* this tool after a human, and reshaping "helpfully" breaks it silently.
|
|
8
|
+
*/
|
|
9
|
+
export interface RenderOpts {
|
|
10
|
+
json?: boolean;
|
|
11
|
+
ndjson?: boolean;
|
|
12
|
+
}
|
|
13
|
+
export declare function render(value: unknown, opts?: RenderOpts): string;
|
|
14
|
+
//# sourceMappingURL=output.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"output.d.ts","sourceRoot":"","sources":["../src/output.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,MAAM,WAAW,UAAU;IACzB,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB;AAyDD,wBAAgB,MAAM,CAAC,KAAK,EAAE,OAAO,EAAE,IAAI,GAAE,UAAe,GAAG,MAAM,CA+BpE"}
|
package/dist/output.js
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Rendering.
|
|
3
|
+
*
|
|
4
|
+
* Two modes and no cleverness: `--json` prints exactly what the API returned,
|
|
5
|
+
* anything else prints a table a person can read. The JSON mode must stay
|
|
6
|
+
* byte-faithful — a script piping to `jq` is the second-biggest consumer of
|
|
7
|
+
* this tool after a human, and reshaping "helpfully" breaks it silently.
|
|
8
|
+
*/
|
|
9
|
+
/** The rows inside a `{ data, meta }` envelope, or the value itself. */
|
|
10
|
+
function rowsOf(value) {
|
|
11
|
+
if (Array.isArray(value))
|
|
12
|
+
return value;
|
|
13
|
+
if (value && typeof value === 'object') {
|
|
14
|
+
const data = value.data;
|
|
15
|
+
if (Array.isArray(data))
|
|
16
|
+
return data;
|
|
17
|
+
}
|
|
18
|
+
return null;
|
|
19
|
+
}
|
|
20
|
+
function cell(v) {
|
|
21
|
+
if (v === null || v === undefined)
|
|
22
|
+
return '';
|
|
23
|
+
if (typeof v === 'object')
|
|
24
|
+
return Array.isArray(v) ? `[${v.length}]` : '{…}';
|
|
25
|
+
return String(v);
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Money arrives from this API in CENTS, always. Rendering 4500 as "4500" in a
|
|
29
|
+
* column headed `amountCents` is technically honest and reads as $4,500 to
|
|
30
|
+
* every human who glances at it, so columns ending in `Cents` are formatted.
|
|
31
|
+
*/
|
|
32
|
+
function isMoneyColumn(key) {
|
|
33
|
+
return /cents$/i.test(key);
|
|
34
|
+
}
|
|
35
|
+
function formatMoney(v) {
|
|
36
|
+
const n = typeof v === 'number' ? v : Number(v);
|
|
37
|
+
if (!Number.isFinite(n))
|
|
38
|
+
return cell(v);
|
|
39
|
+
return `$${(n / 100).toFixed(2)}`;
|
|
40
|
+
}
|
|
41
|
+
function table(rows) {
|
|
42
|
+
if (!rows.length)
|
|
43
|
+
return '(none)';
|
|
44
|
+
// Union of keys, so a row missing a field still lines up.
|
|
45
|
+
const keys = [];
|
|
46
|
+
for (const row of rows)
|
|
47
|
+
for (const k of Object.keys(row))
|
|
48
|
+
if (!keys.includes(k))
|
|
49
|
+
keys.push(k);
|
|
50
|
+
const render = (row, k) => isMoneyColumn(k) ? formatMoney(row[k]) : cell(row[k]);
|
|
51
|
+
const widths = keys.map((k) => Math.max(k.length, ...rows.map((r) => render(r, k).length)));
|
|
52
|
+
const line = (cells) => cells.map((c, i) => c.padEnd(widths[i])).join(' ').replace(/\s+$/, '');
|
|
53
|
+
return [
|
|
54
|
+
line(keys),
|
|
55
|
+
line(widths.map((w) => '─'.repeat(w))),
|
|
56
|
+
...rows.map((r) => line(keys.map((k) => render(r, k)))),
|
|
57
|
+
].join('\n');
|
|
58
|
+
}
|
|
59
|
+
export function render(value, opts = {}) {
|
|
60
|
+
if (opts.json)
|
|
61
|
+
return JSON.stringify(value, null, 2);
|
|
62
|
+
if (opts.ndjson) {
|
|
63
|
+
const rows = rowsOf(value);
|
|
64
|
+
if (rows)
|
|
65
|
+
return rows.map((r) => JSON.stringify(r)).join('\n');
|
|
66
|
+
return JSON.stringify(value);
|
|
67
|
+
}
|
|
68
|
+
const rows = rowsOf(value);
|
|
69
|
+
if (rows) {
|
|
70
|
+
const objects = rows.filter((r) => !!r && typeof r === 'object' && !Array.isArray(r));
|
|
71
|
+
if (objects.length === rows.length)
|
|
72
|
+
return table(objects);
|
|
73
|
+
}
|
|
74
|
+
// A single object renders as key/value pairs rather than a one-row table —
|
|
75
|
+
// a profile with twelve fields is unreadable sideways.
|
|
76
|
+
if (value && typeof value === 'object' && !Array.isArray(value)) {
|
|
77
|
+
const obj = value.data ?? value;
|
|
78
|
+
if (obj && typeof obj === 'object' && !Array.isArray(obj)) {
|
|
79
|
+
const entries = Object.entries(obj);
|
|
80
|
+
const w = Math.max(...entries.map(([k]) => k.length), 0);
|
|
81
|
+
return entries
|
|
82
|
+
.map(([k, v]) => `${k.padEnd(w)} ${isMoneyColumn(k) ? formatMoney(v) : cell(v)}`)
|
|
83
|
+
.join('\n');
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
return String(value);
|
|
87
|
+
}
|
|
88
|
+
//# sourceMappingURL=output.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"output.js","sourceRoot":"","sources":["../src/output.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAOH,wEAAwE;AACxE,SAAS,MAAM,CAAC,KAAc;IAC5B,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;QAAE,OAAO,KAAK,CAAC;IACvC,IAAI,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QACvC,MAAM,IAAI,GAAI,KAA4B,CAAC,IAAI,CAAC;QAChD,IAAI,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC;YAAE,OAAO,IAAI,CAAC;IACvC,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC;AAED,SAAS,IAAI,CAAC,CAAU;IACtB,IAAI,CAAC,KAAK,IAAI,IAAI,CAAC,KAAK,SAAS;QAAE,OAAO,EAAE,CAAC;IAC7C,IAAI,OAAO,CAAC,KAAK,QAAQ;QAAE,OAAO,K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,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC;iBACjF,IAAI,CAAC,IAAI,CAAC,CAAC;QAChB,CAAC;IACH,CAAC;IAED,OAAO,MAAM,CAAC,KAAK,CAAC,CAAC;AACvB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,69 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@crossly/buyer-cli",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "Your Crossly shopping from the terminal — cart, orders, wishlists, offers and cashback.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"homepage": "https://crossly.net",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+https://github.com/crossly-dev/crossly-cli.git",
|
|
10
|
+
"directory": "buyer"
|
|
11
|
+
},
|
|
12
|
+
"bugs": {
|
|
13
|
+
"url": "https://github.com/crossly-dev/crossly-cli/issues"
|
|
14
|
+
},
|
|
15
|
+
"keywords": [
|
|
16
|
+
"crossly",
|
|
17
|
+
"buyer",
|
|
18
|
+
"cli",
|
|
19
|
+
"shopping",
|
|
20
|
+
"cart",
|
|
21
|
+
"cashback",
|
|
22
|
+
"marketplace"
|
|
23
|
+
],
|
|
24
|
+
"type": "module",
|
|
25
|
+
"bin": {
|
|
26
|
+
"crossly-buyer": "./dist/index.js"
|
|
27
|
+
},
|
|
28
|
+
"exports": {
|
|
29
|
+
".": {
|
|
30
|
+
"types": "./dist/index.d.ts",
|
|
31
|
+
"import": "./dist/index.js"
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
"files": [
|
|
35
|
+
"dist",
|
|
36
|
+
"README.md"
|
|
37
|
+
],
|
|
38
|
+
"scripts": {
|
|
39
|
+
"build": "tsc",
|
|
40
|
+
"prepack": "tsc",
|
|
41
|
+
"_typecheck_note": "buyer-mcp's and buyer-sdk's dist/ are gitignored and their exports maps type there, so `tsc --noEmit` alone fails on a fresh clone (TS2307 on @crossly/buyer-mcp/registry) or checks against a stale registry (the round-6 vault tools missing). `pnpm -r build` gets away with it because it is topologically ordered AND emits; `pnpm -r typecheck` is ordered but emits nothing, so both dependencies are built here, SDK first (pnpm runs a filtered set in dependency order). Tests need no build: vitest.config.ts reads both packages from source.",
|
|
42
|
+
"typecheck": "pnpm --filter @crossly/buyer-sdk --filter @crossly/buyer-mcp build && tsgo --noEmit",
|
|
43
|
+
"typecheck:tsc": "tsc --noEmit",
|
|
44
|
+
"build:deps": "pnpm --filter @crossly/buyer-sdk --filter @crossly/buyer-mcp build",
|
|
45
|
+
"test": "vitest run",
|
|
46
|
+
"test:watch": "vitest",
|
|
47
|
+
"lint": "node ../../tools/lint/lint.mjs",
|
|
48
|
+
"lint:typed": "node ../../tools/lint/lint.mjs --type-aware",
|
|
49
|
+
"lint:prune": "node ../../tools/lint/lint.mjs --prune"
|
|
50
|
+
},
|
|
51
|
+
"dependencies": {
|
|
52
|
+
"@crossly/buyer-sdk": "^0.2.0",
|
|
53
|
+
"@crossly/buyer-mcp": "^0.2.0"
|
|
54
|
+
},
|
|
55
|
+
"devDependencies": {
|
|
56
|
+
"@types/node": "^22.10.0",
|
|
57
|
+
"typescript": "^5.7.2",
|
|
58
|
+
"vitest": "^5.0.5"
|
|
59
|
+
},
|
|
60
|
+
"engines": {
|
|
61
|
+
"node": ">=18"
|
|
62
|
+
},
|
|
63
|
+
"publishConfig": {
|
|
64
|
+
"access": "public"
|
|
65
|
+
},
|
|
66
|
+
"crossly": {
|
|
67
|
+
"sourceHash": "817ef0d7138134ba02edb086171a7ba6a20dc306efd785c566aa6a441fc537b3"
|
|
68
|
+
}
|
|
69
|
+
}
|