groovectl 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.
Files changed (206) hide show
  1. package/CHANGELOG.md +79 -0
  2. package/LICENSE +201 -0
  3. package/NOTICE +4 -0
  4. package/README.md +424 -2
  5. package/SECURITY.md +10 -0
  6. package/dist/app/collection-service.d.ts +24 -0
  7. package/dist/app/collection-service.d.ts.map +1 -0
  8. package/dist/app/collection-service.js +129 -0
  9. package/dist/app/collection-service.js.map +1 -0
  10. package/dist/app/database-service.d.ts +26 -0
  11. package/dist/app/database-service.d.ts.map +1 -0
  12. package/dist/app/database-service.js +242 -0
  13. package/dist/app/database-service.js.map +1 -0
  14. package/dist/app/marketplace-offers.d.ts +25 -0
  15. package/dist/app/marketplace-offers.d.ts.map +1 -0
  16. package/dist/app/marketplace-offers.js +237 -0
  17. package/dist/app/marketplace-offers.js.map +1 -0
  18. package/dist/app/marketplace-service.d.ts +37 -0
  19. package/dist/app/marketplace-service.d.ts.map +1 -0
  20. package/dist/app/marketplace-service.js +270 -0
  21. package/dist/app/marketplace-service.js.map +1 -0
  22. package/dist/app/user-mappers.d.ts +4 -0
  23. package/dist/app/user-mappers.d.ts.map +1 -0
  24. package/dist/app/user-mappers.js +21 -0
  25. package/dist/app/user-mappers.js.map +1 -0
  26. package/dist/app/user-service.d.ts +11 -0
  27. package/dist/app/user-service.d.ts.map +1 -0
  28. package/dist/app/user-service.js +73 -0
  29. package/dist/app/user-service.js.map +1 -0
  30. package/dist/app/wantlist-service.d.ts +12 -0
  31. package/dist/app/wantlist-service.d.ts.map +1 -0
  32. package/dist/app/wantlist-service.js +32 -0
  33. package/dist/app/wantlist-service.js.map +1 -0
  34. package/dist/auth/keyring.d.ts +8 -0
  35. package/dist/auth/keyring.d.ts.map +1 -0
  36. package/dist/auth/keyring.js +39 -0
  37. package/dist/auth/keyring.js.map +1 -0
  38. package/dist/auth/prompt.d.ts +3 -0
  39. package/dist/auth/prompt.d.ts.map +1 -0
  40. package/dist/auth/prompt.js +8 -0
  41. package/dist/auth/prompt.js.map +1 -0
  42. package/dist/auth/token-provider.d.ts +31 -0
  43. package/dist/auth/token-provider.d.ts.map +1 -0
  44. package/dist/auth/token-provider.js +94 -0
  45. package/dist/auth/token-provider.js.map +1 -0
  46. package/dist/bin/groovectl.d.ts +3 -0
  47. package/dist/bin/groovectl.d.ts.map +1 -0
  48. package/dist/bin/groovectl.js +9 -0
  49. package/dist/bin/groovectl.js.map +1 -0
  50. package/dist/cli/commands/artist.d.ts +5 -0
  51. package/dist/cli/commands/artist.d.ts.map +1 -0
  52. package/dist/cli/commands/artist.js +72 -0
  53. package/dist/cli/commands/artist.js.map +1 -0
  54. package/dist/cli/commands/auth.d.ts +5 -0
  55. package/dist/cli/commands/auth.d.ts.map +1 -0
  56. package/dist/cli/commands/auth.js +49 -0
  57. package/dist/cli/commands/auth.js.map +1 -0
  58. package/dist/cli/commands/collection.d.ts +5 -0
  59. package/dist/cli/commands/collection.d.ts.map +1 -0
  60. package/dist/cli/commands/collection.js +391 -0
  61. package/dist/cli/commands/collection.js.map +1 -0
  62. package/dist/cli/commands/config.d.ts +5 -0
  63. package/dist/cli/commands/config.d.ts.map +1 -0
  64. package/dist/cli/commands/config.js +79 -0
  65. package/dist/cli/commands/config.js.map +1 -0
  66. package/dist/cli/commands/database-common.d.ts +19 -0
  67. package/dist/cli/commands/database-common.d.ts.map +1 -0
  68. package/dist/cli/commands/database-common.js +53 -0
  69. package/dist/cli/commands/database-common.js.map +1 -0
  70. package/dist/cli/commands/label.d.ts +5 -0
  71. package/dist/cli/commands/label.d.ts.map +1 -0
  72. package/dist/cli/commands/label.js +59 -0
  73. package/dist/cli/commands/label.js.map +1 -0
  74. package/dist/cli/commands/list.d.ts +5 -0
  75. package/dist/cli/commands/list.d.ts.map +1 -0
  76. package/dist/cli/commands/list.js +58 -0
  77. package/dist/cli/commands/list.js.map +1 -0
  78. package/dist/cli/commands/marketplace.d.ts +5 -0
  79. package/dist/cli/commands/marketplace.d.ts.map +1 -0
  80. package/dist/cli/commands/marketplace.js +661 -0
  81. package/dist/cli/commands/marketplace.js.map +1 -0
  82. package/dist/cli/commands/master.d.ts +5 -0
  83. package/dist/cli/commands/master.d.ts.map +1 -0
  84. package/dist/cli/commands/master.js +96 -0
  85. package/dist/cli/commands/master.js.map +1 -0
  86. package/dist/cli/commands/release.d.ts +5 -0
  87. package/dist/cli/commands/release.d.ts.map +1 -0
  88. package/dist/cli/commands/release.js +158 -0
  89. package/dist/cli/commands/release.js.map +1 -0
  90. package/dist/cli/commands/schema.d.ts +38 -0
  91. package/dist/cli/commands/schema.d.ts.map +1 -0
  92. package/dist/cli/commands/schema.js +125 -0
  93. package/dist/cli/commands/schema.js.map +1 -0
  94. package/dist/cli/commands/search.d.ts +5 -0
  95. package/dist/cli/commands/search.d.ts.map +1 -0
  96. package/dist/cli/commands/search.js +144 -0
  97. package/dist/cli/commands/search.js.map +1 -0
  98. package/dist/cli/commands/user.d.ts +5 -0
  99. package/dist/cli/commands/user.d.ts.map +1 -0
  100. package/dist/cli/commands/user.js +43 -0
  101. package/dist/cli/commands/user.js.map +1 -0
  102. package/dist/cli/commands/wantlist.d.ts +5 -0
  103. package/dist/cli/commands/wantlist.d.ts.map +1 -0
  104. package/dist/cli/commands/wantlist.js +158 -0
  105. package/dist/cli/commands/wantlist.js.map +1 -0
  106. package/dist/cli/confirmation.d.ts +3 -0
  107. package/dist/cli/confirmation.d.ts.map +1 -0
  108. package/dist/cli/confirmation.js +21 -0
  109. package/dist/cli/confirmation.js.map +1 -0
  110. package/dist/cli/create-program.d.ts +10 -0
  111. package/dist/cli/create-program.d.ts.map +1 -0
  112. package/dist/cli/create-program.js +121 -0
  113. package/dist/cli/create-program.js.map +1 -0
  114. package/dist/cli/global-options.d.ts +18 -0
  115. package/dist/cli/global-options.d.ts.map +1 -0
  116. package/dist/cli/global-options.js +25 -0
  117. package/dist/cli/global-options.js.map +1 -0
  118. package/dist/cli/run-cli.d.ts +7 -0
  119. package/dist/cli/run-cli.d.ts.map +1 -0
  120. package/dist/cli/run-cli.js +84 -0
  121. package/dist/cli/run-cli.js.map +1 -0
  122. package/dist/cli/runtime.d.ts +34 -0
  123. package/dist/cli/runtime.d.ts.map +1 -0
  124. package/dist/cli/runtime.js +93 -0
  125. package/dist/cli/runtime.js.map +1 -0
  126. package/dist/config/paths.d.ts +2 -0
  127. package/dist/config/paths.d.ts.map +1 -0
  128. package/dist/config/paths.js +18 -0
  129. package/dist/config/paths.js.map +1 -0
  130. package/dist/config/schema.d.ts +20 -0
  131. package/dist/config/schema.d.ts.map +1 -0
  132. package/dist/config/schema.js +15 -0
  133. package/dist/config/schema.js.map +1 -0
  134. package/dist/config/store.d.ts +10 -0
  135. package/dist/config/store.d.ts.map +1 -0
  136. package/dist/config/store.js +88 -0
  137. package/dist/config/store.js.map +1 -0
  138. package/dist/discogs/client.d.ts +247 -0
  139. package/dist/discogs/client.d.ts.map +1 -0
  140. package/dist/discogs/client.js +331 -0
  141. package/dist/discogs/client.js.map +1 -0
  142. package/dist/discogs/database-schemas.d.ts +162 -0
  143. package/dist/discogs/database-schemas.d.ts.map +1 -0
  144. package/dist/discogs/database-schemas.js +92 -0
  145. package/dist/discogs/database-schemas.js.map +1 -0
  146. package/dist/discogs/marketplace-page.d.ts +10 -0
  147. package/dist/discogs/marketplace-page.d.ts.map +1 -0
  148. package/dist/discogs/marketplace-page.js +140 -0
  149. package/dist/discogs/marketplace-page.js.map +1 -0
  150. package/dist/discogs/marketplace-schemas.d.ts +378 -0
  151. package/dist/discogs/marketplace-schemas.d.ts.map +1 -0
  152. package/dist/discogs/marketplace-schemas.js +184 -0
  153. package/dist/discogs/marketplace-schemas.js.map +1 -0
  154. package/dist/discogs/schemas.d.ts +142 -0
  155. package/dist/discogs/schemas.d.ts.map +1 -0
  156. package/dist/discogs/schemas.js +120 -0
  157. package/dist/discogs/schemas.js.map +1 -0
  158. package/dist/discogs/user-schemas.d.ts +325 -0
  159. package/dist/discogs/user-schemas.d.ts.map +1 -0
  160. package/dist/discogs/user-schemas.js +140 -0
  161. package/dist/discogs/user-schemas.js.map +1 -0
  162. package/dist/domain/database-resource.d.ts +72 -0
  163. package/dist/domain/database-resource.d.ts.map +1 -0
  164. package/dist/domain/database-resource.js +2 -0
  165. package/dist/domain/database-resource.js.map +1 -0
  166. package/dist/domain/marketplace.d.ts +165 -0
  167. package/dist/domain/marketplace.d.ts.map +1 -0
  168. package/dist/domain/marketplace.js +91 -0
  169. package/dist/domain/marketplace.js.map +1 -0
  170. package/dist/domain/release.d.ts +61 -0
  171. package/dist/domain/release.d.ts.map +1 -0
  172. package/dist/domain/release.js +2 -0
  173. package/dist/domain/release.js.map +1 -0
  174. package/dist/domain/search-result.d.ts +17 -0
  175. package/dist/domain/search-result.d.ts.map +1 -0
  176. package/dist/domain/search-result.js +2 -0
  177. package/dist/domain/search-result.js.map +1 -0
  178. package/dist/domain/user-resource.d.ts +117 -0
  179. package/dist/domain/user-resource.d.ts.map +1 -0
  180. package/dist/domain/user-resource.js +2 -0
  181. package/dist/domain/user-resource.js.map +1 -0
  182. package/dist/errors/app-error.d.ts +19 -0
  183. package/dist/errors/app-error.d.ts.map +1 -0
  184. package/dist/errors/app-error.js +55 -0
  185. package/dist/errors/app-error.js.map +1 -0
  186. package/dist/http/marketplace-request.d.ts +3 -0
  187. package/dist/http/marketplace-request.d.ts.map +1 -0
  188. package/dist/http/marketplace-request.js +67 -0
  189. package/dist/http/marketplace-request.js.map +1 -0
  190. package/dist/http/rate-limit.d.ts +12 -0
  191. package/dist/http/rate-limit.d.ts.map +1 -0
  192. package/dist/http/rate-limit.js +27 -0
  193. package/dist/http/rate-limit.js.map +1 -0
  194. package/dist/http/request.d.ts +19 -0
  195. package/dist/http/request.d.ts.map +1 -0
  196. package/dist/http/request.js +165 -0
  197. package/dist/http/request.js.map +1 -0
  198. package/dist/output/records.d.ts +14 -0
  199. package/dist/output/records.d.ts.map +1 -0
  200. package/dist/output/records.js +110 -0
  201. package/dist/output/records.js.map +1 -0
  202. package/dist/version.d.ts +11 -0
  203. package/dist/version.d.ts.map +1 -0
  204. package/dist/version.js +16 -0
  205. package/dist/version.js.map +1 -0
  206. package/package.json +72 -4
@@ -0,0 +1,661 @@
1
+ import { Command, InvalidArgumentError, Option } from "commander";
2
+ import { MarketplaceService, } from "../../app/marketplace-service.js";
3
+ import { AppError } from "../../errors/app-error.js";
4
+ import { marketplaceCurrencies, marketplaceInventorySorts, marketplaceListingStatuses, marketplaceOfferSorts, marketplaceOrderSorts, mediaGrades, normalizeMediaCondition, normalizeSleeveCondition, } from "../../domain/marketplace.js";
5
+ import { renderRecord, renderRecords, validateOutputFields, } from "../../output/records.js";
6
+ import { confirmDestructiveAction } from "../confirmation.js";
7
+ import { nonNegativeInteger, positiveInteger } from "../create-program.js";
8
+ import { fieldsFor, isQuiet, tokenRequestFor } from "../global-options.js";
9
+ import { addListOptions, addOutputOptions, asAsync, outputFormat, validateListOptions, } from "./database-common.js";
10
+ const statsColumns = columnsFor([
11
+ "releaseId",
12
+ "lowestPrice",
13
+ "numForSale",
14
+ "blockedFromSale",
15
+ "resourceUrl",
16
+ "marketplaceUrl",
17
+ ]);
18
+ const priceSuggestionColumns = columnsFor([
19
+ "releaseId",
20
+ "grade",
21
+ "condition",
22
+ "price",
23
+ ]);
24
+ const listingColumns = columnsFor([
25
+ "id",
26
+ "status",
27
+ "price",
28
+ "originalPrice",
29
+ "shippingPrice",
30
+ "condition",
31
+ "sleeveCondition",
32
+ "comments",
33
+ "postedAt",
34
+ "shipsFrom",
35
+ "seller",
36
+ "release",
37
+ "resourceUrl",
38
+ "marketplaceUrl",
39
+ ]);
40
+ const inventoryColumns = columnsFor([
41
+ "id",
42
+ "status",
43
+ "price",
44
+ "originalPrice",
45
+ "shippingPrice",
46
+ "condition",
47
+ "sleeveCondition",
48
+ "allowOffers",
49
+ "shipsFrom",
50
+ "seller",
51
+ "release",
52
+ "comments",
53
+ "postedAt",
54
+ "marketplaceUrl",
55
+ "resourceUrl",
56
+ ]);
57
+ const listingMutationColumns = columnsFor([
58
+ "action",
59
+ "listingId",
60
+ "releaseId",
61
+ "status",
62
+ "condition",
63
+ "sleeveCondition",
64
+ "price",
65
+ "allowOffers",
66
+ "comments",
67
+ "marketplaceUrl",
68
+ "resourceUrl",
69
+ "dryRun",
70
+ ]);
71
+ const orderColumns = columnsFor([
72
+ "id",
73
+ "status",
74
+ "nextStatus",
75
+ "created",
76
+ "lastActivity",
77
+ "archived",
78
+ "buyer",
79
+ "seller",
80
+ "items",
81
+ "shipping",
82
+ "fee",
83
+ "total",
84
+ "shippingAddress",
85
+ "additionalInstructions",
86
+ "marketplaceUrl",
87
+ "resourceUrl",
88
+ ]);
89
+ const orderMessageColumns = columnsFor([
90
+ "timestamp",
91
+ "type",
92
+ "from",
93
+ "subject",
94
+ "message",
95
+ ]);
96
+ const feeColumns = columnsFor(["price", "fee"]);
97
+ const offerColumns = columnsFor([
98
+ "id",
99
+ "releaseId",
100
+ "price",
101
+ "condition",
102
+ "sleeveCondition",
103
+ "shipsFrom",
104
+ "seller",
105
+ "comments",
106
+ "shippingText",
107
+ "availability",
108
+ "marketplaceUrl",
109
+ "source",
110
+ "sourceUrl",
111
+ "readAt",
112
+ ]);
113
+ export function createMarketplaceCommand(io, runtime) {
114
+ const marketplace = new Command("marketplace")
115
+ .description("Read Discogs Marketplace prices, offers, inventory, listings, and orders.")
116
+ .addHelpText("after", "\nData provided by Discogs. One-shot commands; no monitoring or stored market data.");
117
+ addOptions(marketplace
118
+ .command("stats")
119
+ .description("Get a release's current lowest item price, sale count and blocked status (excludes shipping/tax).")
120
+ .argument("<release-id>", "Discogs release ID", positiveInteger)).action(async (id, options, command) => {
121
+ await read(command, options, statsColumns, (service) => service.getStats(id, options.currency));
122
+ });
123
+ addOutputOptions(marketplace
124
+ .command("price-suggestions")
125
+ .description("Get Discogs suggested market prices by media condition for a release (requires a User Token with seller settings).")
126
+ .argument("<release-id>", "Discogs release ID", positiveInteger)).action(async (id, options, command) => {
127
+ const requestedFormat = outputFormat(options, command);
128
+ const fields = fieldsFor(command);
129
+ validateOutputFields(priceSuggestionColumns, fields);
130
+ const format = await runtime.formatFor(command, requestedFormat, options.json);
131
+ const resolved = await runtime.tokens.resolve(tokenRequestFor(command, "token_required"));
132
+ const client = await runtime.clientFor(command, resolved?.token);
133
+ const suggestions = await new MarketplaceService(client).getPriceSuggestions(id);
134
+ await renderRecords(asAsync(suggestions), format, priceSuggestionColumns, io.stdout, fields);
135
+ });
136
+ const listing = marketplace
137
+ .command("listing")
138
+ .description("Read or manage individual Marketplace listings.");
139
+ addOptions(listing
140
+ .command("get")
141
+ .description("Get public details by listing ID. Does not search listings by release.")
142
+ .argument("<listing-id>", "Discogs listing ID", positiveInteger)).action(async (id, options, command) => {
143
+ await read(command, options, listingColumns, (service) => service.getListing(id, options.currency));
144
+ });
145
+ addOutputOptions(listing
146
+ .command("create")
147
+ .description("Create a new Marketplace listing for a release (defaults to Draft status for safety).")
148
+ .argument("<release-id>", "Discogs release ID", positiveInteger))
149
+ .requiredOption("--condition <grade>", "Media condition (M, NM, VG+, VG, G+, G, F, P or full Discogs name).", mediaConditionArg)
150
+ .requiredOption("--price <amount>", "Non-negative decimal listing price in your seller currency.", decimalPrice)
151
+ .addOption(new Option("--status <status>", "Initial listing status")
152
+ .choices(["Draft", "For Sale"])
153
+ .default("Draft"))
154
+ .option("--sleeve-condition <grade>", "Sleeve condition (M..P, Generic, Not Graded, No Cover, or full Discogs name).", sleeveConditionArg)
155
+ .option("--comments <text>", "Public seller comments for buyers")
156
+ .option("--allow-offers", "Allow buyers to make offers on this listing")
157
+ .option("--external-id <id>", "Seller external SKU or inventory reference")
158
+ .option("--location <text>", "Seller shelf or storage location")
159
+ .option("--weight <grams>", "Weight in grams", nonNegativeInteger)
160
+ .option("--format-quantity <count>", "Item count for shipping calculation", positiveInteger)
161
+ .option("--dry-run", "Show the intended listing without writing.")
162
+ .action(async (releaseId, options, command) => {
163
+ const format = await runtime.formatFor(command, outputFormat(options, command), options.json);
164
+ const fields = fieldsFor(command);
165
+ validateOutputFields(listingMutationColumns, fields);
166
+ const payload = {
167
+ release_id: releaseId,
168
+ condition: options.condition,
169
+ price: Number(options.price),
170
+ status: options.status,
171
+ ...(options.sleeveCondition === undefined
172
+ ? {}
173
+ : { sleeve_condition: options.sleeveCondition }),
174
+ ...(options.comments === undefined
175
+ ? {}
176
+ : { comments: options.comments }),
177
+ ...(options.allowOffers === undefined
178
+ ? {}
179
+ : { allow_offers: options.allowOffers }),
180
+ ...(options.externalId === undefined
181
+ ? {}
182
+ : { external_id: options.externalId }),
183
+ ...(options.location === undefined
184
+ ? {}
185
+ : { location: options.location }),
186
+ ...(options.weight === undefined ? {} : { weight: options.weight }),
187
+ ...(options.formatQuantity === undefined
188
+ ? {}
189
+ : { format_quantity: options.formatQuantity }),
190
+ };
191
+ const resolved = await runtime.tokens.resolve(tokenRequestFor(command, "token_required"));
192
+ const client = await runtime.clientFor(command, resolved?.token);
193
+ if (options.dryRun === true) {
194
+ renderRecord({
195
+ action: "marketplace.listing.create",
196
+ releaseId,
197
+ status: payload.status,
198
+ condition: payload.condition,
199
+ sleeveCondition: payload.sleeve_condition ?? null,
200
+ price: payload.price,
201
+ ...(payload.allow_offers === undefined
202
+ ? {}
203
+ : { allowOffers: payload.allow_offers }),
204
+ ...(payload.comments === undefined
205
+ ? {}
206
+ : { comments: payload.comments }),
207
+ dryRun: true,
208
+ }, format, listingMutationColumns, io.stdout, fields);
209
+ return;
210
+ }
211
+ const created = await new MarketplaceService(client).createListing(payload);
212
+ renderRecord(created, format, listingMutationColumns, io.stdout, fields);
213
+ });
214
+ addOutputOptions(listing
215
+ .command("update")
216
+ .description("Update an existing Marketplace listing (merges with current listing fields).")
217
+ .argument("<listing-id>", "Discogs listing ID", positiveInteger))
218
+ .option("--condition <grade>", "Media condition (M..P or full Discogs name).", mediaConditionArg)
219
+ .option("--sleeve-condition <grade>", "Sleeve condition (M..P, Generic, Not Graded, No Cover, or full Discogs name).", sleeveConditionArg)
220
+ .option("--price <amount>", "Updated listing price", decimalPrice)
221
+ .addOption(new Option("--status <status>", "Listing status").choices([
222
+ "Draft",
223
+ "For Sale",
224
+ ]))
225
+ .option("--comments <text>", "Updated seller comments")
226
+ .option("--allow-offers", "Allow buyer offers")
227
+ .option("--no-allow-offers", "Disallow buyer offers")
228
+ .option("--external-id <id>", "Seller external SKU or inventory reference")
229
+ .option("--location <text>", "Seller storage location")
230
+ .option("--weight <grams>", "Weight in grams", nonNegativeInteger)
231
+ .option("--format-quantity <count>", "Item count for shipping calculation", positiveInteger)
232
+ .option("--dry-run", "Show the merged listing update without writing.")
233
+ .action(async (listingId, options, command) => {
234
+ const allowOffersSource = command.getOptionValueSource("allowOffers");
235
+ const allowOffers = allowOffersSource === "cli" ? options.allowOffers : undefined;
236
+ const patch = {
237
+ ...(options.condition === undefined
238
+ ? {}
239
+ : { condition: options.condition }),
240
+ ...(options.sleeveCondition === undefined
241
+ ? {}
242
+ : { sleeveCondition: options.sleeveCondition }),
243
+ ...(options.price === undefined
244
+ ? {}
245
+ : { price: Number(options.price) }),
246
+ ...(options.status === undefined ? {} : { status: options.status }),
247
+ ...(options.comments === undefined
248
+ ? {}
249
+ : { comments: options.comments }),
250
+ ...(allowOffers === undefined ? {} : { allowOffers }),
251
+ ...(options.externalId === undefined
252
+ ? {}
253
+ : { externalId: options.externalId }),
254
+ ...(options.location === undefined
255
+ ? {}
256
+ : { location: options.location }),
257
+ ...(options.weight === undefined ? {} : { weight: options.weight }),
258
+ ...(options.formatQuantity === undefined
259
+ ? {}
260
+ : { formatQuantity: options.formatQuantity }),
261
+ };
262
+ if (Object.keys(patch).length === 0) {
263
+ throw new AppError({
264
+ kind: "usage",
265
+ code: "GROOVECTL_USAGE",
266
+ message: "Provide at least one field to update (for example --price, --status, --condition, or --comments).",
267
+ });
268
+ }
269
+ const format = await runtime.formatFor(command, outputFormat(options, command), options.json);
270
+ const fields = fieldsFor(command);
271
+ validateOutputFields(listingMutationColumns, fields);
272
+ const resolved = await runtime.tokens.resolve(tokenRequestFor(command, "token_required"));
273
+ const client = await runtime.clientFor(command, resolved?.token);
274
+ const service = new MarketplaceService(client);
275
+ const merged = await service.prepareListingUpdate(listingId, patch);
276
+ if (options.dryRun !== true) {
277
+ await service.updateListing(listingId, merged);
278
+ }
279
+ renderRecord({
280
+ action: "marketplace.listing.update",
281
+ listingId,
282
+ releaseId: merged.release_id,
283
+ status: merged.status,
284
+ condition: merged.condition,
285
+ sleeveCondition: merged.sleeve_condition ?? null,
286
+ price: merged.price,
287
+ ...(merged.allow_offers === undefined
288
+ ? {}
289
+ : { allowOffers: merged.allow_offers }),
290
+ ...(merged.comments === undefined
291
+ ? {}
292
+ : { comments: merged.comments }),
293
+ marketplaceUrl: `https://www.discogs.com/sell/item/${String(listingId)}`,
294
+ resourceUrl: `https://api.discogs.com/marketplace/listings/${String(listingId)}`,
295
+ dryRun: options.dryRun === true,
296
+ }, format, listingMutationColumns, io.stdout, fields);
297
+ });
298
+ addOutputOptions(listing
299
+ .command("delete")
300
+ .description("Delete a Marketplace listing.")
301
+ .argument("<listing-id>", "Discogs listing ID", positiveInteger))
302
+ .option("--yes", "Skip the confirmation prompt.")
303
+ .option("--dry-run", "Show the intended deletion without writing.")
304
+ .action(async (listingId, options, command) => {
305
+ const format = await runtime.formatFor(command, outputFormat(options, command), options.json);
306
+ const fields = fieldsFor(command);
307
+ validateOutputFields(listingMutationColumns, fields);
308
+ const resolved = await runtime.tokens.resolve(tokenRequestFor(command, "token_required"));
309
+ const client = await runtime.clientFor(command, resolved?.token);
310
+ if (options.dryRun !== true) {
311
+ await confirmDestructiveAction(runtime, options.yes === true, `Delete Marketplace listing ${String(listingId)}?`);
312
+ await new MarketplaceService(client).deleteListing(listingId);
313
+ }
314
+ renderRecord({
315
+ action: "marketplace.listing.delete",
316
+ listingId,
317
+ marketplaceUrl: `https://www.discogs.com/sell/item/${String(listingId)}`,
318
+ resourceUrl: `https://api.discogs.com/marketplace/listings/${String(listingId)}`,
319
+ dryRun: options.dryRun === true,
320
+ }, format, listingMutationColumns, io.stdout, fields);
321
+ });
322
+ addListOptions(marketplace
323
+ .command("listings")
324
+ .description("Read a release's website offers (best-effort HTML, not the official API).")
325
+ .argument("<release-id>", "Discogs release ID", positiveInteger))
326
+ .option("--html <file>", "Read a saved English release Marketplace page instead of the network.")
327
+ .addOption(new Option("--sort <order>", "Offer sort order for live reads")
328
+ .choices([...marketplaceOfferSorts])
329
+ .default("price-asc"))
330
+ .option("--ships-from <country>", "Seller country, e.g. United Kingdom (not the release country).", nonEmpty)
331
+ .addOption(new Option("--currency <code>", "Keep prices in this original currency; no conversion.").choices([...marketplaceCurrencies]))
332
+ .addOption(new Option("--min-media <grade>", "Minimum media grade.").choices([
333
+ ...mediaGrades,
334
+ ]))
335
+ .addOption(new Option("--min-sleeve <grade>", "Minimum sleeve grade; unknown/generic sleeves do not match.").choices([...mediaGrades]))
336
+ .option("--max-price <amount>", "Maximum item price; requires --currency, excludes shipping and tax.", decimalPrice)
337
+ .option("--min-seller-rating <percent>", "Minimum seller positive feedback percentage (0–100).", percentage)
338
+ .option("--include-unavailable", "Include offers the page marks unavailable to its destination.")
339
+ .action(async (id, options, command) => {
340
+ validateListOptions(options, command);
341
+ if (options.html !== undefined &&
342
+ (options.all === true ||
343
+ options.page !== undefined ||
344
+ command.getOptionValueSource("sort") === "cli")) {
345
+ throw new AppError({
346
+ kind: "usage",
347
+ code: "GROOVECTL_HTML_PAGINATION_CONFLICT",
348
+ message: "--html reads one saved page; do not combine it with --all, --page, or --sort.",
349
+ });
350
+ }
351
+ if (options.maxPrice !== undefined && options.currency === undefined) {
352
+ throw new AppError({
353
+ kind: "usage",
354
+ code: "GROOVECTL_CURRENCY_REQUIRED",
355
+ message: "--max-price requires --currency to avoid comparing different currencies.",
356
+ });
357
+ }
358
+ const fields = fieldsFor(command);
359
+ validateOutputFields(offerColumns, fields);
360
+ const format = await runtime.formatFor(command, options.format, options.json);
361
+ const service = await runtime.marketplaceOffersFor(command);
362
+ if (!isQuiet(command) && runtime.errorFormat !== "json") {
363
+ io.stderr.write(options.html !== undefined
364
+ ? "Source: saved HTML (freshness and destination unknown); only that page is read. Filters apply locally.\n"
365
+ : `Source: Discogs website, not API-verified. ${options.all === true ? "Reading pages serially." : "Reading one page; use --all for all pages."} Filters apply to the pages read. Shipping/tax are not included.\n`);
366
+ }
367
+ await renderRecords(service.list(id, options), format, offerColumns, io.stdout, fields, options.limit);
368
+ });
369
+ addListOptions(marketplace
370
+ .command("inventory")
371
+ .description("List a seller's Marketplace inventory (defaults to the authenticated user when username is omitted).")
372
+ .argument("[username]", "Seller username", nonEmpty))
373
+ .addOption(new Option("--status <status>", "Filter by listing status").choices([
374
+ ...marketplaceListingStatuses,
375
+ ]))
376
+ .addOption(new Option("--sort <field>", "Sort inventory by field").choices([
377
+ ...marketplaceInventorySorts,
378
+ ]))
379
+ .addOption(new Option("--sort-order <order>", "Sort order").choices(["asc", "desc"]))
380
+ .action(async (username, options, command) => {
381
+ validateListOptions(options, command);
382
+ const fields = fieldsFor(command);
383
+ validateOutputFields(inventoryColumns, fields);
384
+ const format = await runtime.formatFor(command, outputFormat(options, command), options.json);
385
+ const policy = username === undefined ? "token_required" : "token_optional";
386
+ const resolved = await runtime.tokens.resolve(tokenRequestFor(command, policy));
387
+ const client = await runtime.clientFor(command, resolved?.token);
388
+ const targetUsername = username ?? (await client.getIdentity()).username;
389
+ const service = new MarketplaceService(client);
390
+ const shared = {
391
+ per_page: options.perPage,
392
+ ...(options.status === undefined ? {} : { status: options.status }),
393
+ ...(options.sort === undefined ? {} : { sort: options.sort }),
394
+ ...(options.sortOrder === undefined
395
+ ? {}
396
+ : { sort_order: options.sortOrder }),
397
+ };
398
+ try {
399
+ const values = options.all === true
400
+ ? service.getInventoryAll(targetUsername, shared)
401
+ : asAsync(await service.getInventory(targetUsername, {
402
+ ...shared,
403
+ ...(options.page === undefined
404
+ ? {}
405
+ : { page: options.page }),
406
+ }));
407
+ await renderRecords(values, format, inventoryColumns, io.stdout, fields, options.limit);
408
+ }
409
+ catch (error) {
410
+ rethrowAnonymousAuthError(resolved, error);
411
+ }
412
+ });
413
+ const orders = marketplace
414
+ .command("orders")
415
+ .description("Read and manage authenticated seller Marketplace orders.");
416
+ addListOptions(orders.command("list").description("List Marketplace orders."))
417
+ .option("--status <status>", "Filter orders by status")
418
+ .option("--created-after <iso>", "Filter orders created after ISO timestamp")
419
+ .option("--created-before <iso>", "Filter orders created before ISO timestamp")
420
+ .option("--archived", "Include archived orders")
421
+ .addOption(new Option("--sort <field>", "Sort orders by field").choices([
422
+ ...marketplaceOrderSorts,
423
+ ]))
424
+ .addOption(new Option("--sort-order <order>", "Sort order").choices(["asc", "desc"]))
425
+ .action(async (options, command) => {
426
+ validateListOptions(options, command);
427
+ const fields = fieldsFor(command);
428
+ validateOutputFields(orderColumns, fields);
429
+ const format = await runtime.formatFor(command, outputFormat(options, command), options.json);
430
+ const resolved = await runtime.tokens.resolve(tokenRequestFor(command, "token_required"));
431
+ const client = await runtime.clientFor(command, resolved?.token);
432
+ const service = new MarketplaceService(client);
433
+ const shared = {
434
+ per_page: options.perPage,
435
+ ...(options.status === undefined ? {} : { status: options.status }),
436
+ ...(options.createdAfter === undefined
437
+ ? {}
438
+ : { created_after: options.createdAfter }),
439
+ ...(options.createdBefore === undefined
440
+ ? {}
441
+ : { created_before: options.createdBefore }),
442
+ ...(options.archived === true ? { archived: true } : {}),
443
+ ...(options.sort === undefined ? {} : { sort: options.sort }),
444
+ ...(options.sortOrder === undefined
445
+ ? {}
446
+ : { sort_order: options.sortOrder }),
447
+ };
448
+ const values = options.all === true
449
+ ? service.getOrdersAll(shared)
450
+ : asAsync(await service.getOrders({
451
+ ...shared,
452
+ ...(options.page === undefined ? {} : { page: options.page }),
453
+ }));
454
+ await renderRecords(values, format, orderColumns, io.stdout, fields, options.limit);
455
+ });
456
+ addOutputOptions(orders
457
+ .command("get")
458
+ .description("Get details for one Marketplace order.")
459
+ .argument("<order-id>", "Discogs order ID (for example: 12345-1)", nonEmpty)).action(async (orderId, options, command) => {
460
+ const requestedFormat = outputFormat(options, command);
461
+ const fields = fieldsFor(command);
462
+ validateOutputFields(orderColumns, fields);
463
+ const format = await runtime.formatFor(command, requestedFormat, options.json);
464
+ const resolved = await runtime.tokens.resolve(tokenRequestFor(command, "token_required"));
465
+ const client = await runtime.clientFor(command, resolved?.token);
466
+ const order = await new MarketplaceService(client).getOrder(orderId);
467
+ renderRecord(order, format, orderColumns, io.stdout, fields);
468
+ });
469
+ addOutputOptions(orders
470
+ .command("update")
471
+ .description("Update a Marketplace order's status and/or shipping amount.")
472
+ .argument("<order-id>", "Discogs order ID", nonEmpty))
473
+ .option("--status <status>", "New order status", nonEmpty)
474
+ .option("--shipping <amount>", "New shipping amount", decimalPrice)
475
+ .option("--dry-run", "Show the intended update without writing.")
476
+ .action(async (orderId, options, command) => {
477
+ if (options.status === undefined && options.shipping === undefined) {
478
+ throw new AppError({
479
+ kind: "usage",
480
+ code: "GROOVECTL_USAGE",
481
+ message: "Provide --status and/or --shipping.",
482
+ });
483
+ }
484
+ const dryRunColumns = columnsFor(["action", "orderId", "status", "shipping", "dryRun"]);
485
+ const requestedFormat = outputFormat(options, command);
486
+ const fields = fieldsFor(command);
487
+ const dryRun = options.dryRun === true;
488
+ validateOutputFields(dryRun ? dryRunColumns : orderColumns, fields);
489
+ const format = await runtime.formatFor(command, requestedFormat, options.json);
490
+ const payload = {
491
+ ...(options.status === undefined ? {} : { status: options.status }),
492
+ ...(options.shipping === undefined
493
+ ? {}
494
+ : { shipping: Number(options.shipping) }),
495
+ };
496
+ const resolved = await runtime.tokens.resolve(tokenRequestFor(command, "token_required"));
497
+ const client = await runtime.clientFor(command, resolved?.token);
498
+ if (dryRun) {
499
+ renderRecord({
500
+ action: "marketplace.orders.update",
501
+ orderId,
502
+ ...(payload.status === undefined
503
+ ? {}
504
+ : { status: payload.status }),
505
+ ...(payload.shipping === undefined
506
+ ? {}
507
+ : { shipping: payload.shipping }),
508
+ dryRun: true,
509
+ }, format, dryRunColumns, io.stdout, fields);
510
+ return;
511
+ }
512
+ const updated = await new MarketplaceService(client).updateOrder(orderId, payload);
513
+ renderRecord(updated, format, orderColumns, io.stdout, fields);
514
+ });
515
+ addListOptions(orders
516
+ .command("messages")
517
+ .description("List messages on a Marketplace order.")
518
+ .argument("<order-id>", "Discogs order ID", nonEmpty)).action(async (orderId, options, command) => {
519
+ validateListOptions(options, command);
520
+ const fields = fieldsFor(command);
521
+ validateOutputFields(orderMessageColumns, fields);
522
+ const format = await runtime.formatFor(command, outputFormat(options, command), options.json);
523
+ const resolved = await runtime.tokens.resolve(tokenRequestFor(command, "token_required"));
524
+ const client = await runtime.clientFor(command, resolved?.token);
525
+ const service = new MarketplaceService(client);
526
+ const values = options.all === true
527
+ ? service.getOrderMessagesAll(orderId, { per_page: options.perPage })
528
+ : asAsync(await service.getOrderMessages(orderId, {
529
+ per_page: options.perPage,
530
+ ...(options.page === undefined ? {} : { page: options.page }),
531
+ }));
532
+ await renderRecords(values, format, orderMessageColumns, io.stdout, fields, options.limit);
533
+ });
534
+ addOutputOptions(orders
535
+ .command("message")
536
+ .description("Post a message (and optionally update status) on a Marketplace order.")
537
+ .argument("<order-id>", "Discogs order ID", nonEmpty))
538
+ .option("--message <text>", "Message text to post", nonEmpty)
539
+ .option("--status <status>", "Optional new order status", nonEmpty)
540
+ .option("--dry-run", "Show the intended message without writing.")
541
+ .action(async (orderId, options, command) => {
542
+ if (options.message === undefined && options.status === undefined) {
543
+ throw new AppError({
544
+ kind: "usage",
545
+ code: "GROOVECTL_USAGE",
546
+ message: "Provide --message and/or --status.",
547
+ });
548
+ }
549
+ const dryRunColumns = columnsFor(["action", "orderId", "message", "status", "dryRun"]);
550
+ const requestedFormat = outputFormat(options, command);
551
+ const fields = fieldsFor(command);
552
+ const dryRun = options.dryRun === true;
553
+ validateOutputFields(dryRun ? dryRunColumns : orderMessageColumns, fields);
554
+ const format = await runtime.formatFor(command, requestedFormat, options.json);
555
+ const payload = {
556
+ ...(options.message === undefined
557
+ ? {}
558
+ : { message: options.message }),
559
+ ...(options.status === undefined ? {} : { status: options.status }),
560
+ };
561
+ const resolved = await runtime.tokens.resolve(tokenRequestFor(command, "token_required"));
562
+ const client = await runtime.clientFor(command, resolved?.token);
563
+ if (dryRun) {
564
+ renderRecord({
565
+ action: "marketplace.orders.message",
566
+ orderId,
567
+ ...(payload.message === undefined
568
+ ? {}
569
+ : { message: payload.message }),
570
+ ...(payload.status === undefined
571
+ ? {}
572
+ : { status: payload.status }),
573
+ dryRun: true,
574
+ }, format, dryRunColumns, io.stdout, fields);
575
+ return;
576
+ }
577
+ const posted = await new MarketplaceService(client).addOrderMessage(orderId, payload);
578
+ renderRecord(posted, format, orderMessageColumns, io.stdout, fields);
579
+ });
580
+ addOptions(marketplace
581
+ .command("fee")
582
+ .description("Ask Discogs for the selling fee for an item price (default currency: USD).")
583
+ .argument("<price>", "Non-negative decimal item price", decimalPrice)).action(async (price, options, command) => {
584
+ await read(command, options, feeColumns, (service) => service.getFee(price, options.currency));
585
+ });
586
+ async function read(command, options, columns, request) {
587
+ outputFormat(options, command);
588
+ const fields = fieldsFor(command);
589
+ validateOutputFields(columns, fields);
590
+ const format = await runtime.formatFor(command, options.format, options.json);
591
+ const resolved = await runtime.tokens.resolve(tokenRequestFor(command, "token_optional"));
592
+ const client = await runtime.clientFor(command, resolved?.token);
593
+ let value;
594
+ try {
595
+ value = await request(new MarketplaceService(client));
596
+ }
597
+ catch (error) {
598
+ rethrowAnonymousAuthError(resolved, error);
599
+ }
600
+ renderRecord(value, format, columns, io.stdout, fields);
601
+ }
602
+ return marketplace;
603
+ }
604
+ function rethrowAnonymousAuthError(resolved, error) {
605
+ if (resolved === undefined &&
606
+ error instanceof AppError &&
607
+ error.httpStatus === 401) {
608
+ throw new AppError({
609
+ kind: "auth_required",
610
+ code: "GROOVECTL_AUTH_REQUIRED",
611
+ message: "Discogs requires a User Token for this Marketplace request.",
612
+ remediation: "Use --token to enter one securely, --token-stdin, DISCOGS_TOKEN, or auth login, then retry.",
613
+ httpStatus: 401,
614
+ });
615
+ }
616
+ throw error;
617
+ }
618
+ function columnsFor(keys) {
619
+ return keys.map((key) => ({ key, value: (item) => item[key] }));
620
+ }
621
+ function nonEmpty(value) {
622
+ if (!value.trim()) {
623
+ throw new InvalidArgumentError("expected a non-empty value");
624
+ }
625
+ return value.trim();
626
+ }
627
+ function mediaConditionArg(value) {
628
+ const normalized = normalizeMediaCondition(value);
629
+ if (normalized === undefined) {
630
+ throw new InvalidArgumentError(`expected a Discogs media grade (${mediaGrades.join(", ")}) or full condition name`);
631
+ }
632
+ return normalized;
633
+ }
634
+ function sleeveConditionArg(value) {
635
+ const normalized = normalizeSleeveCondition(value);
636
+ if (normalized === undefined) {
637
+ throw new InvalidArgumentError(`expected a Discogs sleeve grade (${mediaGrades.join(", ")}, Generic, Not Graded, No Cover) or full condition name`);
638
+ }
639
+ return normalized;
640
+ }
641
+ function percentage(value) {
642
+ if (!/^\d+(?:\.\d+)?$/u.test(value) || Number(value) > 100) {
643
+ throw new InvalidArgumentError("expected a percentage between 0 and 100");
644
+ }
645
+ return Number(value);
646
+ }
647
+ function addOptions(command) {
648
+ return addOutputOptions(command).addOption(new Option("--currency <code>", "Currency for the response; omit to use the API default.").choices([...marketplaceCurrencies]));
649
+ }
650
+ // Preserve the decimal spelling in the URL; reject exponent and path syntax.
651
+ function decimalPrice(value) {
652
+ const number = Number(value);
653
+ if (!/^\d+(?:\.\d+)?$/u.test(value) ||
654
+ !Number.isFinite(number) ||
655
+ number > Number.MAX_SAFE_INTEGER ||
656
+ (number === 0 && /[1-9]/u.test(value))) {
657
+ throw new InvalidArgumentError("expected a non-negative finite decimal price within the safe numeric range");
658
+ }
659
+ return value;
660
+ }
661
+ //# sourceMappingURL=marketplace.js.map