creatorriver 0.8.1 → 0.8.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -21,6 +21,9 @@ Behind a proxy, set `HTTPS_PROXY` (and `NO_PROXY` for hosts to reach directly).
21
21
  ## Use
22
22
 
23
23
  ```bash
24
+ creatorriver doctor
25
+ creatorriver schema
26
+ creatorriver schema creators search
24
27
  creatorriver account
25
28
  creatorriver pricing --charged-only
26
29
  creatorriver credits --days 30
@@ -52,6 +55,6 @@ Saving creators to custom lists (`lists create`, `lists add`, `creators save`) i
52
55
 
53
56
  To find new prospects, pass `--exclude-contacted` to `creators search`, `creators browse` or `creators similar`. Use `--exclude-exported` or `--exclude-uploaded` to also omit past exports or the list uploaded on the website, and `--has-recent-viral` to narrow `creators search` or `creators browse` to creators with a 10x+ breakout video in the last 30 days. Filtered browsing counts toward the search allowance shown by `account` (paging the same filtered list that day with `--offset`, or expanding a same-day search with `searches expand`, uses no extra allowance). Unpaid accounts with less than 0.5 credits drop to 5 searches a day until any purchase. Free and one-time credit-pack accounts can send up to 100 free outreach emails/day; active Pro subscriptions allow up to 200/day (emails 101-200 cost 0.1 credits each). For a follow-up in an existing conversation you can omit `--subject`. Boolean flags also accept `--no-<flag>` (e.g. `--no-include-email`, `--no-archived`).
54
57
 
55
- Every command prints one line of JSON: `{"ok":true,"data":...}` on stdout, or `{"ok":false,"error":{"code","message","requestId"}}` on stderr with an exit code per error: 1 internal, 2 invalid_input, 3 unauthorized, 4 not_found, 5 conflict, 6 insufficient_credits, 7 rate_limited, 8 network_error, 9 login_pending. Each command's `--help` lists its flags, what it costs and what it needs first. `--input-json '{...}'` passes the whole input as JSON, and `--dry-run` previews the request and upper-bound credit cost locally.
58
+ Every command prints one line of JSON: `{"ok":true,"data":...}` on stdout, or `{"ok":false,"error":{"code","message","requestId"}}` on stderr with an exit code per error: 1 internal, 2 invalid_input, 3 unauthorized, 4 not_found, 5 conflict, 6 insufficient_credits, 7 rate_limited, 8 network_error, 9 login_pending. Use `creatorriver schema` (or `creatorriver schema <command>`) to inspect machine-readable flags, JSON Schemas and costs offline, and `creatorriver doctor` to check credentials, API reachability and account status in one run. `--input-file <path>` (or `-` for stdin) and `--input-json '{...}'` pass the whole input as JSON (flags override its fields), and `--dry-run` previews the request and upper-bound credit cost locally.
56
59
 
57
60
  The same operations are available as an MCP server at `https://www.creatorriver.com/api/mcp` and as a REST API at `https://www.creatorriver.com/api/v1`, both with `Authorization: Bearer <key>`.
@@ -1,5 +1,8 @@
1
1
  #!/usr/bin/env node
2
2
 
3
+ // src/cli.ts
4
+ import { readFile as readTextFile } from "fs/promises";
5
+
3
6
  // ../contract/src/fields.ts
4
7
  import { z } from "zod";
5
8
  function flagName(fieldName) {
@@ -78,6 +81,9 @@ import { z as z2 } from "zod";
78
81
  function defineOperation(spec) {
79
82
  return spec;
80
83
  }
84
+ function isChargedOrQuotaOperation(operation) {
85
+ return operation.cost.model !== "free";
86
+ }
81
87
  function estimateMaxOperationCredits(operation, input = {}) {
82
88
  const { cost } = operation;
83
89
  if (cost.model === "free" || cost.model === "quota") {
@@ -1022,11 +1028,78 @@ var operations = [
1022
1028
  excludeCreator
1023
1029
  ];
1024
1030
 
1031
+ // ../contract/src/schema.ts
1032
+ import { z as z4 } from "zod";
1033
+ function formatTextForCli(text, operations2) {
1034
+ return operations2.reduce(
1035
+ (result, operation) => result?.replace(
1036
+ new RegExp(`\\b${operation.name}\\b`, "g"),
1037
+ `\`${operation.command.join(" ")}\``
1038
+ ),
1039
+ text
1040
+ );
1041
+ }
1042
+ function summarizeOperationForCli(operation) {
1043
+ return {
1044
+ command: operation.command.join(" "),
1045
+ operation: operation.name,
1046
+ group: operation.command[0],
1047
+ method: operation.method,
1048
+ path: `/api/v1${operation.path}`,
1049
+ kind: operation.kind,
1050
+ cost: {
1051
+ model: operation.cost.model,
1052
+ label: operation.cost.label
1053
+ },
1054
+ summary: operation.summary
1055
+ };
1056
+ }
1057
+ function describeOperationForCli(operation, operations2) {
1058
+ const pathParams = new Set(pathParamNames(operation.path));
1059
+ const defaultLocation = operation.method === "GET" || operation.method === "DELETE" ? "query" : "body";
1060
+ const flags = describeFields(operation.input).map(
1061
+ (field) => {
1062
+ const flag = flagName(field.name);
1063
+ return {
1064
+ flag,
1065
+ ...field.kind === "boolean" ? { negatedFlag: `--no-${flag.slice(2)}` } : {},
1066
+ field: field.name,
1067
+ kind: field.kind,
1068
+ required: pathParams.has(field.name) || field.required,
1069
+ in: pathParams.has(field.name) ? "path" : defaultLocation,
1070
+ ...field.choices ? { choices: field.choices } : {},
1071
+ ...field.description ? { description: formatTextForCli(field.description, operations2) } : {}
1072
+ };
1073
+ }
1074
+ );
1075
+ const inputSchema = z4.toJSONSchema(operation.input, {
1076
+ io: "input"
1077
+ });
1078
+ delete inputSchema.$schema;
1079
+ return {
1080
+ ...summarizeOperationForCli(operation),
1081
+ cost: operation.cost,
1082
+ description: formatTextForCli(operation.description, operations2) ?? "",
1083
+ supportsInputJson: true,
1084
+ supportsInputFile: true,
1085
+ supportsDryRun: true,
1086
+ flags,
1087
+ inputSchema
1088
+ };
1089
+ }
1090
+ function findOperationByCliSelector(selector, operations2) {
1091
+ const normalized = selector.trim().replace(/\./g, " ").replace(/\s+/g, " ");
1092
+ if (!normalized) return void 0;
1093
+ return operations2.find(
1094
+ (operation) => operation.command.join(" ") === normalized || operation.name === normalized
1095
+ );
1096
+ }
1097
+
1025
1098
  // src/cli.ts
1026
1099
  import { Command, CommanderError, Option } from "commander";
1027
1100
 
1028
1101
  // package.json
1029
- var version = "0.8.1";
1102
+ var version = "0.8.2";
1030
1103
 
1031
1104
  // src/http.ts
1032
1105
  var DEFAULT_API_URL = "https://www.creatorriver.com";
@@ -1183,6 +1256,7 @@ function processIo() {
1183
1256
  stdout: (text) => process.stdout.write(text),
1184
1257
  stderr: (text) => process.stderr.write(text),
1185
1258
  readStdin: readAllStdin,
1259
+ readFile: (path) => readFile(path, "utf8"),
1186
1260
  interactive: Boolean(process.stdin.isTTY && process.stderr.isTTY),
1187
1261
  openBrowser,
1188
1262
  sleep: (milliseconds) => new Promise((resolve) => setTimeout(resolve, milliseconds)),
@@ -1269,21 +1343,12 @@ var GROUP_DESCRIPTIONS = {
1269
1343
  conversations: "Read email threads with creators and record their replies",
1270
1344
  searches: "Reopen, expand, rename, archive and export past searches, and list filter values"
1271
1345
  };
1272
- function forCli(text, operations2) {
1273
- return operations2.reduce(
1274
- (result, operation) => result?.replace(
1275
- new RegExp(`\\b${operation.name}\\b`, "g"),
1276
- `\`${operation.command.join(" ")}\``
1277
- ),
1278
- text
1279
- );
1280
- }
1281
1346
  function formatCliSummary(operation) {
1282
1347
  return operation.cost.model === "free" ? operation.summary : `${operation.summary} [${operation.cost.label}]`;
1283
1348
  }
1284
1349
  function formatCliDescription(operation, operations2) {
1285
- const base = forCli(operation.description, operations2) ?? "";
1286
- const note = forCli(operation.cost.note, operations2);
1350
+ const base = formatTextForCli(operation.description, operations2) ?? "";
1351
+ const note = formatTextForCli(operation.cost.note, operations2);
1287
1352
  const costLine = note ? `Cost: ${operation.cost.label} \u2014 ${note}` : `Cost: ${operation.cost.label}`;
1288
1353
  return base ? `${base}
1289
1354
 
@@ -1308,7 +1373,7 @@ function dryRunNote(operation, input) {
1308
1373
  }
1309
1374
  function describeFlag(field, operations2) {
1310
1375
  return [
1311
- forCli(field.description, operations2),
1376
+ formatTextForCli(field.description, operations2),
1312
1377
  field.choices ? `one of: ${field.choices.join(", ")}` : void 0,
1313
1378
  field.kind === "list" ? "comma-separated" : void 0,
1314
1379
  field.required ? "required" : void 0
@@ -1321,19 +1386,47 @@ function toCliError(error) {
1321
1386
  error instanceof Error ? error.message : String(error)
1322
1387
  );
1323
1388
  }
1324
- function buildInput(fields, options) {
1389
+ function parseJsonObject(raw, sourceFlag) {
1390
+ let parsed;
1391
+ try {
1392
+ parsed = JSON.parse(raw);
1393
+ } catch {
1394
+ throw new CliError("invalid_input", `${sourceFlag} must be valid JSON`);
1395
+ }
1396
+ if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
1397
+ throw new CliError("invalid_input", `${sourceFlag} must be a JSON object`);
1398
+ }
1399
+ return { ...parsed };
1400
+ }
1401
+ async function buildInput(fields, options, io) {
1402
+ if (typeof options.inputJson === "string" && typeof options.inputFile === "string") {
1403
+ throw new CliError(
1404
+ "invalid_input",
1405
+ "Pass either --input-json or --input-file, not both"
1406
+ );
1407
+ }
1325
1408
  let input = {};
1326
- if (typeof options.inputJson === "string") {
1327
- let parsed;
1328
- try {
1329
- parsed = JSON.parse(options.inputJson);
1330
- } catch {
1331
- throw new CliError("invalid_input", "--input-json must be valid JSON");
1332
- }
1333
- if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
1334
- throw new CliError("invalid_input", "--input-json must be a JSON object");
1409
+ if (typeof options.inputFile === "string") {
1410
+ const target = options.inputFile;
1411
+ let raw;
1412
+ if (target === "-") {
1413
+ raw = await io.readStdin();
1414
+ } else {
1415
+ try {
1416
+ raw = await (io.readFile ?? ((p) => readTextFile(p, "utf8")))(
1417
+ target
1418
+ );
1419
+ } catch (error) {
1420
+ const reason = error instanceof Error ? error.message : String(error);
1421
+ throw new CliError(
1422
+ "invalid_input",
1423
+ `Cannot read --input-file "${target}": ${reason}`
1424
+ );
1425
+ }
1335
1426
  }
1336
- input = { ...parsed };
1427
+ input = parseJsonObject(raw, "--input-file");
1428
+ } else if (typeof options.inputJson === "string") {
1429
+ input = parseJsonObject(options.inputJson, "--input-json");
1337
1430
  }
1338
1431
  for (const field of fields) {
1339
1432
  const value = options[field.name];
@@ -1426,12 +1519,16 @@ Exit codes: 0 ok, ${Object.entries(EXIT_CODES).sort(([, a], [, b]) => a - b).map
1426
1519
  command.option(
1427
1520
  "--input-json <json>",
1428
1521
  "the whole input as a JSON object; flags override its fields"
1522
+ ).option(
1523
+ "--input-file <path>",
1524
+ "read input JSON object from a file path, or - for stdin; flags override its fields"
1429
1525
  ).option(
1430
1526
  "--dry-run",
1431
1527
  "preview the request and estimated maximum credit cost without calling the API"
1432
1528
  ).action(async (options) => {
1433
1529
  try {
1434
- const parsed = operation.input.strict().safeParse(buildInput(fields, options));
1530
+ const rawInput = await buildInput(fields, options, io);
1531
+ const parsed = operation.input.strict().safeParse(rawInput);
1435
1532
  if (!parsed.success) {
1436
1533
  throw new CliError("invalid_input", "Invalid input", {
1437
1534
  issues: parsed.error.issues.map((issue) => ({
@@ -1476,6 +1573,194 @@ Exit codes: 0 ok, ${Object.entries(EXIT_CODES).sort(([, a], [, b]) => a - b).map
1476
1573
  }
1477
1574
  });
1478
1575
  }
1576
+ program.command("schema [target...]").description(
1577
+ "Inspect machine-readable command schemas, flags and costs offline"
1578
+ ).option(
1579
+ "--all",
1580
+ "include full flag and JSON Schema definitions for every matching command"
1581
+ ).option(
1582
+ "--group <group>",
1583
+ "filter commands by group (e.g. creators, lists, campaigns)"
1584
+ ).option(
1585
+ "--charged-only",
1586
+ "only commands that spend credits or use a daily quota"
1587
+ ).action(
1588
+ (target, options) => {
1589
+ try {
1590
+ if (target.length > 0) {
1591
+ const selector = target.join(" ");
1592
+ const found = findOperationByCliSelector(selector, operations2);
1593
+ if (!found) {
1594
+ throw new CliError(
1595
+ "not_found",
1596
+ `Unknown command "${selector}". Run \`creatorriver schema\` to list all commands.`
1597
+ );
1598
+ }
1599
+ succeed(describeOperationForCli(found, operations2));
1600
+ return;
1601
+ }
1602
+ let filtered = [...operations2];
1603
+ if (options.group !== void 0) {
1604
+ const group = options.group.trim();
1605
+ filtered = filtered.filter(
1606
+ (operation) => operation.command[0] === group
1607
+ );
1608
+ if (filtered.length === 0) {
1609
+ throw new CliError(
1610
+ "invalid_input",
1611
+ `Unknown command group "${group}"`
1612
+ );
1613
+ }
1614
+ }
1615
+ if (options.chargedOnly === true) {
1616
+ filtered = filtered.filter(isChargedOrQuotaOperation);
1617
+ }
1618
+ succeed({
1619
+ version,
1620
+ count: filtered.length,
1621
+ commands: filtered.map(
1622
+ (operation) => options.all ? describeOperationForCli(operation, operations2) : summarizeOperationForCli(operation)
1623
+ )
1624
+ });
1625
+ } catch (error) {
1626
+ fail(error);
1627
+ }
1628
+ }
1629
+ );
1630
+ program.command("doctor").description(
1631
+ "Check CLI version, credentials, API reachability and account status in one run"
1632
+ ).action(async () => {
1633
+ try {
1634
+ const checks = [{ name: "cli", status: "ok", version }];
1635
+ const path = configPath(io.env);
1636
+ const stored = await readConfig(path);
1637
+ const found = await findApiKey(io);
1638
+ if (found) {
1639
+ checks.push({
1640
+ name: "credentials",
1641
+ status: "ok",
1642
+ source: found.source,
1643
+ key: previewKey(found.apiKey),
1644
+ configPath: path,
1645
+ ...found.source === "env" && Boolean(stored.apiKey?.trim()) && {
1646
+ note: "CREATORRIVER_API_KEY overrides saved config key"
1647
+ }
1648
+ });
1649
+ } else {
1650
+ checks.push({
1651
+ name: "credentials",
1652
+ status: "fail",
1653
+ configPath: path,
1654
+ ...stored.pendingLogin && { pendingLogin: true },
1655
+ hint: `Not signed in: ${LOGIN_HINT}`
1656
+ });
1657
+ }
1658
+ const ep = endpoint(io);
1659
+ const probeUrl = new URL(
1660
+ `${ep.baseUrl.replace(/\/+$/, "")}/api/v1/openapi.json`
1661
+ );
1662
+ let apiReachable = false;
1663
+ let reachabilityMessage = `Cannot reach ${probeUrl.origin}`;
1664
+ const startedAt = io.now();
1665
+ try {
1666
+ const response = await ep.fetch(probeUrl, {
1667
+ method: "GET",
1668
+ headers: {
1669
+ accept: "application/json",
1670
+ "user-agent": ep.userAgent
1671
+ }
1672
+ });
1673
+ const latencyMs = Math.max(0, io.now() - startedAt);
1674
+ if (response.ok) {
1675
+ apiReachable = true;
1676
+ checks.push({
1677
+ name: "api_reachable",
1678
+ status: "ok",
1679
+ apiUrl: ep.baseUrl,
1680
+ latencyMs
1681
+ });
1682
+ } else {
1683
+ reachabilityMessage = `Unexpected status from ${probeUrl.origin} (HTTP ${response.status})`;
1684
+ checks.push({
1685
+ name: "api_reachable",
1686
+ status: "fail",
1687
+ apiUrl: ep.baseUrl,
1688
+ statusCode: response.status,
1689
+ latencyMs
1690
+ });
1691
+ }
1692
+ } catch (error) {
1693
+ const reason = error instanceof Error ? error.message : String(error);
1694
+ reachabilityMessage = `Cannot reach ${probeUrl.origin}: ${reason}`;
1695
+ checks.push({
1696
+ name: "api_reachable",
1697
+ status: "fail",
1698
+ apiUrl: ep.baseUrl,
1699
+ detail: reason
1700
+ });
1701
+ }
1702
+ let account;
1703
+ let accountError;
1704
+ if (!found) {
1705
+ checks.push({
1706
+ name: "account",
1707
+ status: "skipped",
1708
+ detail: "No API key configured"
1709
+ });
1710
+ } else if (!apiReachable) {
1711
+ checks.push({
1712
+ name: "account",
1713
+ status: "skipped",
1714
+ detail: "API unreachable"
1715
+ });
1716
+ } else {
1717
+ try {
1718
+ account = await callOperation(
1719
+ getAccount,
1720
+ {},
1721
+ { ...ep, apiKey: found.apiKey }
1722
+ );
1723
+ checks.push({ name: "account", status: "ok" });
1724
+ } catch (error) {
1725
+ accountError = toCliError(error);
1726
+ checks.push({
1727
+ name: "account",
1728
+ status: "fail",
1729
+ code: accountError.code,
1730
+ detail: accountError.message
1731
+ });
1732
+ }
1733
+ }
1734
+ if (apiReachable && found && !accountError) {
1735
+ succeed({ healthy: true, checks, account });
1736
+ return;
1737
+ }
1738
+ if (!apiReachable) {
1739
+ throw new CliError("network_error", reachabilityMessage, {
1740
+ healthy: false,
1741
+ checks
1742
+ });
1743
+ }
1744
+ if (accountError) {
1745
+ throw new CliError(
1746
+ accountError.code,
1747
+ accountError.message,
1748
+ {
1749
+ ...accountError.details ?? {},
1750
+ healthy: false,
1751
+ checks
1752
+ },
1753
+ accountError.requestId
1754
+ );
1755
+ }
1756
+ throw new CliError("unauthorized", `Not signed in: ${LOGIN_HINT}`, {
1757
+ healthy: false,
1758
+ checks
1759
+ });
1760
+ } catch (error) {
1761
+ fail(error);
1762
+ }
1763
+ });
1479
1764
  const auth = program.command("auth").description("Sign in, check the key in use, sign out");
1480
1765
  auth.command("login").description(
1481
1766
  "Sign in through the browser and save a new API key. Under an agent it prints the link and exits; finish with --wait."
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "creatorriver",
3
- "version": "0.8.1",
3
+ "version": "0.8.2",
4
4
  "description": "Creator River CLI: search 10M+ YouTube, TikTok, Instagram and X creators, every one with a contact email, and run outreach from your terminal or AI agent",
5
5
  "keywords": [
6
6
  "creator-river",