|
1 | 1 | import { Command } from "commander" |
2 | 2 | import type { OpenSeaClient } from "../client.js" |
3 | 3 | import type { OutputFormat } from "../output.js" |
4 | | -import { outputGet } from "../output.js" |
5 | | -import { addPaginationOptions, parseIntOption } from "../parse.js" |
6 | | -import type { TokenBalanceSortBy } from "../types/index.js" |
| 4 | +import { formatOutput, outputGet } from "../output.js" |
| 5 | +import { |
| 6 | + addPaginationOptions, |
| 7 | + parseIntOption, |
| 8 | + readJsonBodyOption, |
| 9 | +} from "../parse.js" |
| 10 | +import type { |
| 11 | + FavoriteResponse, |
| 12 | + TokenBalanceSortBy, |
| 13 | + WatchlistRequest, |
| 14 | +} from "../types/index.js" |
7 | 15 |
|
8 | 16 | export function accountsCommand( |
9 | 17 | getClient: () => OpenSeaClient, |
@@ -373,5 +381,186 @@ export function accountsCommand( |
373 | 381 | }, |
374 | 382 | ) |
375 | 383 |
|
| 384 | + cmd |
| 385 | + .command("relationship") |
| 386 | + .description( |
| 387 | + "Get the authenticated wallet's follow/watch relationship with an account (wallet auth required)", |
| 388 | + ) |
| 389 | + .argument("<address_or_username>", "Wallet address or OpenSea username") |
| 390 | + .action(async (addressOrUsername: string) => { |
| 391 | + const client = getClient() |
| 392 | + await outputGet( |
| 393 | + client, |
| 394 | + getFormat(), |
| 395 | + `/api/v2/accounts/${addressOrUsername}/relationship`, |
| 396 | + ) |
| 397 | + }) |
| 398 | + |
| 399 | + addPaginationOptions( |
| 400 | + cmd |
| 401 | + .command("followers") |
| 402 | + .description("List an account's followers") |
| 403 | + .argument("<address_or_username>", "Wallet address or OpenSea username"), |
| 404 | + ).action( |
| 405 | + async ( |
| 406 | + addressOrUsername: string, |
| 407 | + options: { limit: string; next?: string }, |
| 408 | + ) => { |
| 409 | + const client = getClient() |
| 410 | + await outputGet( |
| 411 | + client, |
| 412 | + getFormat(), |
| 413 | + `/api/v2/accounts/${addressOrUsername}/followers`, |
| 414 | + { |
| 415 | + limit: parseIntOption(options.limit, "--limit"), |
| 416 | + cursor: options.next, |
| 417 | + }, |
| 418 | + ) |
| 419 | + }, |
| 420 | + ) |
| 421 | + |
| 422 | + addPaginationOptions( |
| 423 | + cmd |
| 424 | + .command("following") |
| 425 | + .description("List the accounts an account is following") |
| 426 | + .argument("<address_or_username>", "Wallet address or OpenSea username"), |
| 427 | + ).action( |
| 428 | + async ( |
| 429 | + addressOrUsername: string, |
| 430 | + options: { limit: string; next?: string }, |
| 431 | + ) => { |
| 432 | + const client = getClient() |
| 433 | + await outputGet( |
| 434 | + client, |
| 435 | + getFormat(), |
| 436 | + `/api/v2/accounts/${addressOrUsername}/following`, |
| 437 | + { |
| 438 | + limit: parseIntOption(options.limit, "--limit"), |
| 439 | + cursor: options.next, |
| 440 | + }, |
| 441 | + ) |
| 442 | + }, |
| 443 | + ) |
| 444 | + |
| 445 | + cmd |
| 446 | + .command("follow") |
| 447 | + .description("Follow an account as the authenticated wallet") |
| 448 | + .argument("<address_or_username>", "Wallet address or OpenSea username") |
| 449 | + .action(async (addressOrUsername: string) => { |
| 450 | + const client = getClient() |
| 451 | + const result = await client.post( |
| 452 | + `/api/v2/accounts/${addressOrUsername}/follow`, |
| 453 | + ) |
| 454 | + console.log(formatOutput(result, getFormat())) |
| 455 | + }) |
| 456 | + |
| 457 | + cmd |
| 458 | + .command("unfollow") |
| 459 | + .description("Unfollow an account as the authenticated wallet") |
| 460 | + .argument("<address_or_username>", "Wallet address or OpenSea username") |
| 461 | + .action(async (addressOrUsername: string) => { |
| 462 | + const client = getClient() |
| 463 | + const result = await client.delete( |
| 464 | + `/api/v2/accounts/${addressOrUsername}/follow`, |
| 465 | + ) |
| 466 | + console.log(formatOutput(result, getFormat())) |
| 467 | + }) |
| 468 | + |
| 469 | + cmd |
| 470 | + .command("watch") |
| 471 | + .description("Watch an account as the authenticated wallet") |
| 472 | + .argument("<address_or_username>", "Wallet address or OpenSea username") |
| 473 | + .action(async (addressOrUsername: string) => { |
| 474 | + const client = getClient() |
| 475 | + const result = await client.post( |
| 476 | + `/api/v2/accounts/${addressOrUsername}/watch`, |
| 477 | + ) |
| 478 | + console.log(formatOutput(result, getFormat())) |
| 479 | + }) |
| 480 | + |
| 481 | + cmd |
| 482 | + .command("unwatch") |
| 483 | + .description("Unwatch an account as the authenticated wallet") |
| 484 | + .argument("<address_or_username>", "Wallet address or OpenSea username") |
| 485 | + .action(async (addressOrUsername: string) => { |
| 486 | + const client = getClient() |
| 487 | + const result = await client.delete( |
| 488 | + `/api/v2/accounts/${addressOrUsername}/watch`, |
| 489 | + ) |
| 490 | + console.log(formatOutput(result, getFormat())) |
| 491 | + }) |
| 492 | + |
| 493 | + cmd |
| 494 | + .command("token-watchlist") |
| 495 | + .description( |
| 496 | + "Get the authenticated wallet's token watchlist (wallet auth required)", |
| 497 | + ) |
| 498 | + .argument("<address>", "Wallet address") |
| 499 | + .action(async (address: string) => { |
| 500 | + const client = getClient() |
| 501 | + await outputGet( |
| 502 | + client, |
| 503 | + getFormat(), |
| 504 | + `/api/v2/account/${address}/token_watchlist`, |
| 505 | + ) |
| 506 | + }) |
| 507 | + |
| 508 | + cmd |
| 509 | + .command("perpetual-watchlist") |
| 510 | + .description( |
| 511 | + "Get the authenticated wallet's perpetual watchlist (wallet auth required)", |
| 512 | + ) |
| 513 | + .argument("<address>", "Wallet address") |
| 514 | + .action(async (address: string) => { |
| 515 | + const client = getClient() |
| 516 | + await outputGet( |
| 517 | + client, |
| 518 | + getFormat(), |
| 519 | + `/api/v2/account/${address}/perpetual_watchlist`, |
| 520 | + ) |
| 521 | + }) |
| 522 | + |
| 523 | + cmd |
| 524 | + .command("watchlist-add") |
| 525 | + .description( |
| 526 | + "Add an item, collection, or token to the authenticated wallet's watchlist", |
| 527 | + ) |
| 528 | + .requiredOption( |
| 529 | + "--body <path>", |
| 530 | + "Path to JSON file with the WatchlistRequest body", |
| 531 | + ) |
| 532 | + .action(async (options: { body: string }) => { |
| 533 | + const client = getClient() |
| 534 | + const request = readJsonBodyOption<WatchlistRequest>( |
| 535 | + options.body, |
| 536 | + "--body", |
| 537 | + ) |
| 538 | + const result = await client.post<FavoriteResponse>( |
| 539 | + "/api/v2/watchlist", |
| 540 | + request, |
| 541 | + ) |
| 542 | + console.log(formatOutput(result, getFormat())) |
| 543 | + }) |
| 544 | + |
| 545 | + cmd |
| 546 | + .command("watchlist-remove") |
| 547 | + .description("Remove an entry from the authenticated wallet's watchlist") |
| 548 | + .requiredOption( |
| 549 | + "--body <path>", |
| 550 | + "Path to JSON file with the WatchlistRequest body", |
| 551 | + ) |
| 552 | + .action(async (options: { body: string }) => { |
| 553 | + const client = getClient() |
| 554 | + const request = readJsonBodyOption<WatchlistRequest>( |
| 555 | + options.body, |
| 556 | + "--body", |
| 557 | + ) |
| 558 | + const result = await client.delete<FavoriteResponse>( |
| 559 | + "/api/v2/watchlist", |
| 560 | + request, |
| 561 | + ) |
| 562 | + console.log(formatOutput(result, getFormat())) |
| 563 | + }) |
| 564 | + |
376 | 565 | return cmd |
377 | 566 | } |
0 commit comments