-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcollections.ts
More file actions
95 lines (89 loc) · 2.95 KB
/
collections.ts
File metadata and controls
95 lines (89 loc) · 2.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
import { Command } from "commander"
import type { OpenSeaClient } from "../client.js"
import type { OutputFilterOptions, OutputFormat } from "../output.js"
import { formatOutput } from "../output.js"
import { parseIntOption } from "../parse.js"
import type {
Chain,
Collection,
CollectionOrderBy,
CollectionStats,
GetTraitsResponse,
} from "../types/index.js"
export function collectionsCommand(
getClient: () => OpenSeaClient,
getFormat: () => OutputFormat,
getFilters?: () => OutputFilterOptions,
): Command {
const cmd = new Command("collections").description(
"Manage and query NFT collections",
)
cmd
.command("get")
.description("Get a single collection by slug")
.argument("<slug>", "Collection slug")
.action(async (slug: string) => {
const client = getClient()
const result = await client.get<Collection>(`/api/v2/collections/${slug}`)
console.log(formatOutput(result, getFormat(), getFilters?.()))
})
cmd
.command("list")
.description("List collections")
.option("--chain <chain>", "Filter by chain")
.option(
"--order-by <orderBy>",
"Order by field (created_date, one_day_change, seven_day_volume, seven_day_change, num_owners, market_cap)",
)
.option("--creator <username>", "Filter by creator username")
.option("--include-hidden", "Include hidden collections")
.option("--limit <limit>", "Number of results", "20")
.option("--next <cursor>", "Pagination cursor")
.action(
async (options: {
chain?: string
orderBy?: string
creator?: string
includeHidden?: boolean
limit: string
next?: string
}) => {
const client = getClient()
const result = await client.get<{
collections: Collection[]
next?: string
}>("/api/v2/collections", {
chain: options.chain as Chain | undefined,
order_by: options.orderBy as CollectionOrderBy | undefined,
creator_username: options.creator,
include_hidden: options.includeHidden,
limit: parseIntOption(options.limit, "--limit"),
next: options.next,
})
console.log(formatOutput(result, getFormat(), getFilters?.()))
},
)
cmd
.command("stats")
.description("Get collection stats")
.argument("<slug>", "Collection slug")
.action(async (slug: string) => {
const client = getClient()
const result = await client.get<CollectionStats>(
`/api/v2/collections/${slug}/stats`,
)
console.log(formatOutput(result, getFormat(), getFilters?.()))
})
cmd
.command("traits")
.description("Get collection traits")
.argument("<slug>", "Collection slug")
.action(async (slug: string) => {
const client = getClient()
const result = await client.get<GetTraitsResponse>(
`/api/v2/traits/${slug}`,
)
console.log(formatOutput(result, getFormat(), getFilters?.()))
})
return cmd
}