ebay-mcp 1.13.2 → 1.14.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 (169) hide show
  1. package/README.de.md +3 -3
  2. package/README.es.md +3 -3
  3. package/README.fr.md +3 -3
  4. package/README.ja.md +3 -3
  5. package/README.ko.md +3 -3
  6. package/README.md +163 -41
  7. package/README.pt-BR.md +3 -3
  8. package/README.ru.md +3 -3
  9. package/README.zh-CN.md +3 -3
  10. package/build/api/account-management/account.js +633 -297
  11. package/build/api/analytics-and-report/analytics.js +111 -65
  12. package/build/api/client.js +199 -140
  13. package/build/api/clientRequestError.js +23 -0
  14. package/build/api/clientTrading.js +213 -0
  15. package/build/api/clientTradingError.js +4 -0
  16. package/build/api/communication/feedback.js +147 -59
  17. package/build/api/communication/message.js +134 -81
  18. package/build/api/communication/negotiation.js +65 -53
  19. package/build/api/communication/notification.js +458 -164
  20. package/build/api/developer/developer.js +99 -45
  21. package/build/api/index.js +23 -8
  22. package/build/api/listing-management/inventory.js +884 -338
  23. package/build/api/listing-metadata/metadata.js +416 -170
  24. package/build/api/listing-metadata/taxonomy.js +187 -42
  25. package/build/api/marketing-and-promotions/marketing.js +1392 -598
  26. package/build/api/marketing-and-promotions/recommendation.js +49 -24
  27. package/build/api/order-management/dispute.js +226 -45
  28. package/build/api/order-management/fulfillment.js +144 -71
  29. package/build/api/order-management/orderIssueHelpers.js +61 -0
  30. package/build/api/other/compliance.js +50 -38
  31. package/build/api/other/edelivery.js +603 -159
  32. package/build/api/other/finding.js +280 -0
  33. package/build/api/other/identity.js +30 -15
  34. package/build/api/other/translation.js +29 -14
  35. package/build/api/other/vero.js +113 -27
  36. package/build/api/rateLimitTracker.js +55 -0
  37. package/build/api/shared/request.js +189 -98
  38. package/build/api/trading/trading.js +154 -87
  39. package/build/auth/credentialSession.js +250 -0
  40. package/build/auth/oauth.js +298 -171
  41. package/build/auth/{oauth-metadata.js → oauthMetadata.js} +22 -6
  42. package/build/auth/oauthMiddleware.js +104 -0
  43. package/build/auth/{scope-utils.js → scopeUtils.js} +101 -28
  44. package/build/auth/tokenVerifier.js +243 -0
  45. package/build/auth/tokenVerifierError.js +21 -0
  46. package/build/config/environment.js +148 -113
  47. package/build/config/{tool-families.js → toolFamilies.js} +30 -14
  48. package/build/index.js +25 -19
  49. package/build/mcp/{http-transport.js → httpTransport.js} +102 -52
  50. package/build/mcp/readOnlyFilter.js +67 -0
  51. package/build/mcp/runtime.js +31 -13
  52. package/build/mcp/{tool-gating.js → toolGating.js} +77 -49
  53. package/build/mcp/{ui-bridge.js → uiBridge.js} +80 -23
  54. package/build/schemas/account-management/account.js +144 -6
  55. package/build/schemas/analytics/analytics.js +33 -19
  56. package/build/schemas/communication/messages.js +12 -42
  57. package/build/schemas/developer/developer.js +135 -0
  58. package/build/schemas/fulfillment/orders.js +183 -21
  59. package/build/schemas/index.js +27 -19
  60. package/build/schemas/inventory-management/inventory.js +17 -9
  61. package/build/schemas/marketing/marketing.js +480 -25
  62. package/build/schemas/metadata/metadata.js +11 -6
  63. package/build/schemas/other/finding.js +27 -0
  64. package/build/schemas/other/otherApis.js +424 -0
  65. package/build/schemas/taxonomy/taxonomy.js +11 -5
  66. package/build/scripts/{auto-setup.js → autoSetup.js} +87 -74
  67. package/build/scripts/{build-ui.js → buildUi.js} +6 -1
  68. package/build/scripts/{dev-sync.js → devSync.js} +169 -110
  69. package/build/scripts/diagnostics.js +52 -44
  70. package/build/scripts/{download-specs.js → downloadSpecs.js} +29 -21
  71. package/build/scripts/{interactive-setup.js → interactiveSetup.js} +84 -78
  72. package/build/scripts/setup.js +241 -178
  73. package/build/scripts/{setup-shared.js → setupShared.js} +29 -7
  74. package/build/scripts/skills.js +35 -27
  75. package/build/scripts/updateApiStatusDoc.js +71 -0
  76. package/build/serverHttp.js +90 -0
  77. package/build/skills/content.js +124 -118
  78. package/build/skills/index.js +22 -10
  79. package/build/skills/install.js +21 -10
  80. package/build/skills/markers.js +50 -15
  81. package/build/skills/{registry-snapshot.js → registrySnapshot.js} +8 -2
  82. package/build/skills/render.js +41 -14
  83. package/build/skills/targets.js +49 -17
  84. package/build/tools/categories/account.js +166 -264
  85. package/build/tools/categories/analytics.js +11 -22
  86. package/build/tools/categories/browse.js +17 -0
  87. package/build/tools/categories/communication.js +124 -399
  88. package/build/tools/categories/connector.js +23 -20
  89. package/build/tools/categories/developer.js +46 -159
  90. package/build/tools/categories/fulfillment.js +84 -215
  91. package/build/tools/categories/index.js +6 -14
  92. package/build/tools/categories/inventory.js +238 -293
  93. package/build/tools/categories/marketing.js +677 -39
  94. package/build/tools/categories/metadata.js +190 -117
  95. package/build/tools/categories/other.js +81 -208
  96. package/build/tools/categories/taxonomy.js +29 -20
  97. package/build/tools/categories/{token-management.js → tokenManagement.js} +187 -192
  98. package/build/tools/categories/trading.js +16 -47
  99. package/build/tools/contracts.js +34 -24
  100. package/build/tools/{define-tool.js → defineTool.js} +44 -29
  101. package/build/tools/registry.js +87 -29
  102. package/build/tools/schemas.js +3 -57
  103. package/build/tools/ui/archetypes.js +1 -0
  104. package/build/tools/ui/{map-helpers.js → mapHelpers.js} +69 -19
  105. package/build/tools/ui/maps.js +294 -80
  106. package/build/types/index.js +1 -1
  107. package/build/ui/card.html +14 -14
  108. package/build/ui/chart.html +14 -14
  109. package/build/ui/stat.html +87 -0
  110. package/build/ui/table.html +14 -14
  111. package/build/utils/apiStatusFeed.js +95 -0
  112. package/build/utils/cliOutput.js +15 -0
  113. package/build/utils/cliUi.js +108 -0
  114. package/build/utils/communication/feedback.js +57 -77
  115. package/build/utils/communication/message.js +69 -98
  116. package/build/utils/communication/negotiation.js +30 -57
  117. package/build/utils/communication/notification.js +112 -252
  118. package/build/utils/{date-converter.js → dateConverter.js} +62 -30
  119. package/build/utils/effectSchema.js +203 -0
  120. package/build/utils/effectSchemaAdapter.js +121 -0
  121. package/build/utils/effectSchemaChainMethods.js +146 -0
  122. package/build/utils/effectSchemaRefinements.js +104 -0
  123. package/build/utils/effectSchemaStringMethods.js +63 -0
  124. package/build/utils/effectSchemaTypes.js +47 -0
  125. package/build/utils/{env-parser.js → envParser.js} +10 -2
  126. package/build/utils/errors.js +7 -3
  127. package/build/utils/http.js +148 -89
  128. package/build/utils/{llm-client-detector.js → llmClientDetector.js} +295 -274
  129. package/build/utils/logger.js +127 -51
  130. package/build/utils/{oauth-helper.js → oauthHelper.js} +127 -90
  131. package/build/utils/other/compliance.js +18 -38
  132. package/build/utils/other/identity.js +2 -2
  133. package/build/utils/other/translation.js +4 -4
  134. package/build/utils/other/vero.js +36 -20
  135. package/build/utils/schemaHelpers.js +22 -0
  136. package/build/utils/scopeHelper.js +270 -0
  137. package/build/utils/securityChecker.js +316 -0
  138. package/build/utils/{setup-validator.js → setupValidator.js} +113 -94
  139. package/build/utils/{setup-wizard.js → setupWizard.js} +57 -46
  140. package/build/utils/{token-utils.js → tokenUtils.js} +2 -2
  141. package/build/utils/trading/trading.js +35 -0
  142. package/build/utils/typeGuards.js +12 -0
  143. package/build/utils/version.js +65 -29
  144. package/package.json +10 -8
  145. package/build/api/client-trading.js +0 -124
  146. package/build/api/communication/shared.js +0 -59
  147. package/build/api/shared/query-params.js +0 -16
  148. package/build/auth/credential-session.js +0 -166
  149. package/build/auth/oauth-middleware.js +0 -100
  150. package/build/auth/token-verifier.js +0 -186
  151. package/build/schemas/other/other-apis.js +0 -390
  152. package/build/scripts/update-api-status-doc.js +0 -44
  153. package/build/server-http.js +0 -85
  154. package/build/tools/definitions/marketing.js +0 -1381
  155. package/build/tools/tool-handlers/marketing.js +0 -312
  156. package/build/utils/account-management/account.js +0 -818
  157. package/build/utils/api-status-feed.js +0 -84
  158. package/build/utils/cli-ui.js +0 -47
  159. package/build/utils/order-management/dispute.js +0 -369
  160. package/build/utils/order-management/fulfillment.js +0 -205
  161. package/build/utils/other/edelivery.js +0 -235
  162. package/build/utils/schema-helpers.js +0 -13
  163. package/build/utils/scope-helper.js +0 -207
  164. package/build/utils/security-checker.js +0 -248
  165. package/build/utils/type-guards.js +0 -6
  166. /package/build/auth/{oauth-types.js → oauthTypes.js} +0 -0
  167. /package/build/{server-http.d.ts → serverHttp.d.ts} +0 -0
  168. /package/build/tools/ui/{view-models.js → viewModels.js} +0 -0
  169. /package/build/types/{ebay-enums.js → ebayEnums.js} +0 -0
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * Tool-result → {@link ViewModel} projections for the interactive MCP Apps layer.
3
3
  *
4
- * Each exported `map*` function is referenced by exactly one tool's `ui.map` in
4
+ * Each exported `map*` const is referenced by exactly one tool's `ui.map` in
5
5
  * `src/tools/categories/*`. Keeping them here (rather than inline in the category
6
6
  * files) does two things: it keeps the tool definitions terse, and it lets the
7
7
  * unit tests import every projection directly. Drift protection still holds — the
@@ -10,22 +10,37 @@
10
10
  *
11
11
  * Every input type is the exact generated OpenAPI schema the matching handler
12
12
  * returns; every output is the archetype view model the React app in `ui/`
13
- * renders. Formatting lives in `./map-helpers.js` so these stay declarative.
13
+ * renders. Formatting lives in `./mapHelpers.js` so these stay declarative.
14
14
  */
15
- import { formatAmount, humanizeStatus, statusTone, toLabel, toNumber, truncate, } from '../../tools/ui/map-helpers.js';
15
+ import { formatAmount, humanizeStatus, statusTone, toLabel, toNumber, truncate, } from '../../tools/ui/mapHelpers.js';
16
16
  /**
17
17
  * Builds a table's contextual footnote from how many rows are shown versus the
18
18
  * server's reported total, e.g. `"Showing 25 of 240"`. Returns `undefined` when
19
19
  * the response carries no total so the table renders without a footnote.
20
20
  */
21
- function footnoteFor(shown, total) {
21
+ const footnoteFor = (shown, total) => {
22
22
  if (total == null) {
23
- return undefined;
23
+ return;
24
24
  }
25
25
  return total > shown ? `Showing ${shown} of ${total}` : `${total} total`;
26
- }
27
- /** Projects a seller's orders into a table; rows drill into a single-order card. */
28
- export function mapOrdersToTable(result) {
26
+ };
27
+ /** Builds a status badge only when eBay returned a status value to display. */
28
+ const statusBadge = (status) => {
29
+ const label = humanizeStatus(status);
30
+ return label ? { label, tone: statusTone(status) } : undefined;
31
+ };
32
+ /**
33
+ * Projects a seller's orders into a table; rows drill into a single-order card.
34
+ *
35
+ * @param result - Generated fulfillment order search response from eBay.
36
+ * @returns A table view model whose rows preserve order fields at the projection layer.
37
+ *
38
+ * @example
39
+ * ```ts
40
+ * const view = mapOrdersToTable({ orders: [{ orderId: '12-3456' }], total: 1 });
41
+ * ```
42
+ */
43
+ export const mapOrdersToTable = (result) => {
29
44
  const orders = result.orders ?? [];
30
45
  return {
31
46
  archetype: 'table',
@@ -54,9 +69,19 @@ export function mapOrdersToTable(result) {
54
69
  })),
55
70
  footnote: footnoteFor(orders.length, result.total),
56
71
  };
57
- }
58
- /** Projects an order's shipping fulfillments (tracking/carrier) into a table. */
59
- export function mapFulfillmentsToTable(result) {
72
+ };
73
+ /**
74
+ * Projects an order's shipping fulfillments (tracking/carrier) into a table.
75
+ *
76
+ * @param result - Generated fulfillment page from eBay.
77
+ * @returns A table view model with one row per fulfillment.
78
+ *
79
+ * @example
80
+ * ```ts
81
+ * const view = mapFulfillmentsToTable({ fulfillments: [{ fulfillmentId: 'f1' }] });
82
+ * ```
83
+ */
84
+ export const mapFulfillmentsToTable = (result) => {
60
85
  const fulfillments = result.fulfillments ?? [];
61
86
  return {
62
87
  archetype: 'table',
@@ -78,9 +103,19 @@ export function mapFulfillmentsToTable(result) {
78
103
  })),
79
104
  footnote: footnoteFor(fulfillments.length, result.total),
80
105
  };
81
- }
82
- /** Projects a seller's offers into a table; rows drill into a single-offer card. */
83
- export function mapOffersToTable(result) {
106
+ };
107
+ /**
108
+ * Projects a seller's offers into a table; rows drill into a single-offer card.
109
+ *
110
+ * @param result - Generated inventory offers response from eBay.
111
+ * @returns A table view model with offer rows and optional drill refs.
112
+ *
113
+ * @example
114
+ * ```ts
115
+ * const view = mapOffersToTable({ offers: [{ offerId: 'o1', sku: 'SKU-1' }] });
116
+ * ```
117
+ */
118
+ export const mapOffersToTable = (result) => {
84
119
  const offers = result.offers ?? [];
85
120
  return {
86
121
  archetype: 'table',
@@ -111,9 +146,19 @@ export function mapOffersToTable(result) {
111
146
  })),
112
147
  footnote: footnoteFor(offers.length, result.total),
113
148
  };
114
- }
115
- /** Projects inventory items into a table; rows drill into a single-item card. */
116
- export function mapInventoryItemsToTable(result) {
149
+ };
150
+ /**
151
+ * Projects inventory items into a table; rows drill into a single-item card.
152
+ *
153
+ * @param result - Generated inventory item collection from eBay.
154
+ * @returns A table view model with one row per inventory item.
155
+ *
156
+ * @example
157
+ * ```ts
158
+ * const view = mapInventoryItemsToTable({ inventoryItems: [{ sku: 'SKU-1' }] });
159
+ * ```
160
+ */
161
+ export const mapInventoryItemsToTable = (result) => {
117
162
  const items = result.inventoryItems ?? [];
118
163
  return {
119
164
  archetype: 'table',
@@ -138,9 +183,19 @@ export function mapInventoryItemsToTable(result) {
138
183
  })),
139
184
  footnote: footnoteFor(items.length, result.total),
140
185
  };
141
- }
142
- /** Projects a seller's inventory locations into a table. */
143
- export function mapLocationsToTable(result) {
186
+ };
187
+ /**
188
+ * Projects a seller's inventory locations into a table.
189
+ *
190
+ * @param result - Generated inventory location response from eBay.
191
+ * @returns A table view model with location rows.
192
+ *
193
+ * @example
194
+ * ```ts
195
+ * const view = mapLocationsToTable({ locations: [{ merchantLocationKey: 'WAREHOUSE-1' }] });
196
+ * ```
197
+ */
198
+ export const mapLocationsToTable = (result) => {
144
199
  const locations = result.locations ?? [];
145
200
  return {
146
201
  archetype: 'table',
@@ -164,9 +219,21 @@ export function mapLocationsToTable(result) {
164
219
  })),
165
220
  footnote: footnoteFor(locations.length, result.total),
166
221
  };
167
- }
168
- /** Projects payment-dispute summaries into a table; rows drill into a dispute card. */
169
- export function mapDisputeSummariesToTable(result) {
222
+ };
223
+ /**
224
+ * Projects payment-dispute summaries into a table; rows drill into a dispute card.
225
+ *
226
+ * @param result - Generated payment dispute summary response from eBay.
227
+ * @returns A table view model with dispute rows and optional drill refs.
228
+ *
229
+ * @example
230
+ * ```ts
231
+ * const view = mapDisputeSummariesToTable({
232
+ * paymentDisputeSummaries: [{ paymentDisputeId: 'd1' }],
233
+ * });
234
+ * ```
235
+ */
236
+ export const mapDisputeSummariesToTable = (result) => {
170
237
  const disputes = result.paymentDisputeSummaries ?? [];
171
238
  return {
172
239
  archetype: 'table',
@@ -201,24 +268,34 @@ export function mapDisputeSummariesToTable(result) {
201
268
  })),
202
269
  footnote: footnoteFor(disputes.length, result.total),
203
270
  };
204
- }
205
- /** Projects a single order into a detail card with status badges and line items. */
206
- export function mapOrderToCard(result) {
271
+ };
272
+ /**
273
+ * Projects a single order into a detail card with status badges and line items.
274
+ *
275
+ * @param result - Generated fulfillment order response from eBay.
276
+ * @returns A card view model with summary and line-item sections.
277
+ *
278
+ * @example
279
+ * ```ts
280
+ * const view = mapOrderToCard({ orderId: '12-3456' });
281
+ * ```
282
+ */
283
+ export const mapOrderToCard = (result) => {
207
284
  const lineItems = result.lineItems ?? [];
285
+ const badges = [];
286
+ const fulfillmentBadge = statusBadge(result.orderFulfillmentStatus);
287
+ if (fulfillmentBadge) {
288
+ badges.push(fulfillmentBadge);
289
+ }
290
+ const paymentBadge = statusBadge(result.orderPaymentStatus);
291
+ if (paymentBadge) {
292
+ badges.push(paymentBadge);
293
+ }
208
294
  return {
209
295
  archetype: 'card',
210
296
  title: result.orderId ? `Order ${result.orderId}` : 'Order',
211
297
  subtitle: result.buyer?.username ? `Buyer: ${result.buyer.username}` : undefined,
212
- badges: [
213
- {
214
- label: humanizeStatus(result.orderFulfillmentStatus),
215
- tone: statusTone(result.orderFulfillmentStatus),
216
- },
217
- {
218
- label: humanizeStatus(result.orderPaymentStatus),
219
- tone: statusTone(result.orderPaymentStatus),
220
- },
221
- ],
298
+ badges,
222
299
  sections: [
223
300
  {
224
301
  heading: 'Summary',
@@ -231,20 +308,35 @@ export function mapOrderToCard(result) {
231
308
  {
232
309
  heading: 'Items',
233
310
  fields: lineItems.map((lineItem) => ({
234
- label: truncate(lineItem.title, 60) || (lineItem.sku ?? 'Item'),
235
- value: lineItem.quantity != null ? `×${lineItem.quantity}` : null,
311
+ label: truncate(lineItem.title, 60) || lineItem.sku || '',
312
+ value: lineItem.quantity == null ? null : `×${lineItem.quantity}`,
236
313
  })),
237
314
  },
238
315
  ],
239
316
  };
240
- }
241
- /** Projects a single offer into a detail card with pricing and listing sections. */
242
- export function mapOfferToCard(result) {
243
- const badges = [
244
- { label: humanizeStatus(result.status), tone: statusTone(result.status) },
245
- ];
317
+ };
318
+ /**
319
+ * Projects a single offer into a detail card with pricing and listing sections.
320
+ *
321
+ * @param result - Generated inventory offer detail response from eBay.
322
+ * @returns A card view model with pricing and listing sections.
323
+ *
324
+ * @example
325
+ * ```ts
326
+ * const view = mapOfferToCard({ offerId: 'o1', sku: 'SKU-1' });
327
+ * ```
328
+ */
329
+ export const mapOfferToCard = (result) => {
330
+ const badges = [];
331
+ const offerStatusBadge = statusBadge(result.status);
332
+ if (offerStatusBadge) {
333
+ badges.push(offerStatusBadge);
334
+ }
246
335
  if (result.format) {
247
- badges.push({ label: humanizeStatus(result.format) });
336
+ const formatLabel = humanizeStatus(result.format);
337
+ if (formatLabel) {
338
+ badges.push({ label: formatLabel });
339
+ }
248
340
  }
249
341
  return {
250
342
  archetype: 'card',
@@ -269,15 +361,26 @@ export function mapOfferToCard(result) {
269
361
  },
270
362
  ],
271
363
  };
272
- }
273
- /** Projects a single inventory item into a detail card (product + availability). */
274
- export function mapInventoryItemToCard(result) {
364
+ };
365
+ /**
366
+ * Projects a single inventory item into a detail card (product + availability).
367
+ *
368
+ * @param result - Generated inventory item detail response from eBay.
369
+ * @returns A card view model with product and availability sections.
370
+ *
371
+ * @example
372
+ * ```ts
373
+ * const view = mapInventoryItemToCard({ sku: 'SKU-1' });
374
+ * ```
375
+ */
376
+ export const mapInventoryItemToCard = (result) => {
275
377
  const product = result.product;
378
+ const conditionBadge = statusBadge(result.condition);
276
379
  return {
277
380
  archetype: 'card',
278
381
  title: result.sku ? `SKU ${result.sku}` : 'Inventory item',
279
382
  subtitle: product?.title ? truncate(product.title, 80) : undefined,
280
- badges: [{ label: humanizeStatus(result.condition), tone: statusTone(result.condition) }],
383
+ badges: conditionBadge ? [conditionBadge] : undefined,
281
384
  sections: [
282
385
  {
283
386
  heading: 'Product',
@@ -298,9 +401,19 @@ export function mapInventoryItemToCard(result) {
298
401
  },
299
402
  ],
300
403
  };
301
- }
302
- /** Projects a single payment dispute into a detail card, listing available actions. */
303
- export function mapDisputeToCard(result) {
404
+ };
405
+ /**
406
+ * Projects a single payment dispute into a detail card, listing available actions.
407
+ *
408
+ * @param result - Generated payment dispute response from eBay.
409
+ * @returns A card view model with detail and available-action sections.
410
+ *
411
+ * @example
412
+ * ```ts
413
+ * const view = mapDisputeToCard({ paymentDisputeId: 'd1' });
414
+ * ```
415
+ */
416
+ export const mapDisputeToCard = (result) => {
304
417
  const sections = [
305
418
  {
306
419
  heading: 'Details',
@@ -318,26 +431,32 @@ export function mapDisputeToCard(result) {
318
431
  sections.push({
319
432
  heading: 'Available actions',
320
433
  fields: result.availableChoices.map((choice) => ({
321
- label: humanizeStatus(choice),
434
+ label: humanizeStatus(choice) ?? '',
322
435
  value: null,
323
436
  })),
324
437
  });
325
438
  }
439
+ const disputeBadge = statusBadge(result.paymentDisputeStatus);
326
440
  return {
327
441
  archetype: 'card',
328
442
  title: result.paymentDisputeId ? `Dispute ${result.paymentDisputeId}` : 'Payment dispute',
329
443
  subtitle: result.orderId ? `Order: ${result.orderId}` : undefined,
330
- badges: [
331
- {
332
- label: humanizeStatus(result.paymentDisputeStatus),
333
- tone: statusTone(result.paymentDisputeStatus),
334
- },
335
- ],
444
+ badges: disputeBadge ? [disputeBadge] : undefined,
336
445
  sections,
337
446
  };
338
- }
339
- /** Projects a seller standards profile into a detail card (cycle + per-metric values). */
340
- export function mapStandardsProfileToCard(result) {
447
+ };
448
+ /**
449
+ * Projects a seller standards profile into a detail card (cycle + per-metric values).
450
+ *
451
+ * @param result - Generated seller standards profile response from eBay.
452
+ * @returns A card view model with profile and metric sections.
453
+ *
454
+ * @example
455
+ * ```ts
456
+ * const view = mapStandardsProfileToCard({ program: 'PROGRAM_US' });
457
+ * ```
458
+ */
459
+ export const mapStandardsProfileToCard = (result) => {
341
460
  const metrics = result.metrics ?? [];
342
461
  const sections = [
343
462
  {
@@ -353,37 +472,44 @@ export function mapStandardsProfileToCard(result) {
353
472
  sections.push({
354
473
  heading: 'Metrics',
355
474
  fields: metrics.map((metric) => ({
356
- label: humanizeStatus(metric.metricKey),
475
+ label: humanizeStatus(metric.metricKey) ?? '',
357
476
  value: metric.value ?? null,
358
477
  })),
359
478
  });
360
479
  }
480
+ const standardsBadge = statusBadge(result.standardsLevel);
361
481
  return {
362
482
  archetype: 'card',
363
- title: result.program ? humanizeStatus(result.program) : 'Seller standards',
364
- subtitle: result.cycle?.cycleType ? humanizeStatus(result.cycle.cycleType) : undefined,
365
- badges: [
366
- { label: humanizeStatus(result.standardsLevel), tone: statusTone(result.standardsLevel) },
367
- ],
483
+ title: humanizeStatus(result.program) ?? 'Seller standards',
484
+ subtitle: humanizeStatus(result.cycle?.cycleType) ?? undefined,
485
+ badges: standardsBadge ? [standardsBadge] : undefined,
368
486
  sections,
369
487
  };
370
- }
488
+ };
371
489
  /**
372
490
  * Projects a traffic report into a line chart: one series per metric column in
373
491
  * the report header, plotted across each record's first dimension value (day or
374
492
  * listing). Falls back to the first record's metric count when the header omits
375
493
  * metric definitions.
494
+ *
495
+ * @param result - Generated analytics report response from eBay.
496
+ * @returns A line chart view model with one series per metric.
497
+ *
498
+ * @example
499
+ * ```ts
500
+ * const view = mapTrafficReportToChart({ records: [] });
501
+ * ```
376
502
  */
377
- export function mapTrafficReportToChart(result) {
503
+ export const mapTrafficReportToChart = (result) => {
378
504
  const records = result.records ?? [];
379
505
  const metricDefs = result.header?.metrics ?? [];
380
506
  const seriesCount = metricDefs.length || records[0]?.metricValues?.length || 0;
381
507
  const series = Array.from({ length: seriesCount }, (_unused, metricIndex) => ({
382
- name: metricDefs[metricIndex]?.key ?? `Metric ${metricIndex + 1}`,
383
- points: records.map((record) => ({
384
- x: toLabel(record.dimensionValues?.[0]?.value),
385
- y: toNumber(record.metricValues?.[metricIndex]?.value),
386
- })),
508
+ name: metricDefs[metricIndex]?.key ?? '',
509
+ points: records.flatMap((record) => {
510
+ const y = toNumber(record.metricValues?.[metricIndex]?.value);
511
+ return y === null ? [] : [{ x: toLabel(record.dimensionValues?.[0]?.value), y }];
512
+ }),
387
513
  }));
388
514
  return {
389
515
  archetype: 'chart',
@@ -391,21 +517,33 @@ export function mapTrafficReportToChart(result) {
391
517
  kind: 'line',
392
518
  series,
393
519
  };
394
- }
520
+ };
395
521
  /**
396
522
  * Projects customer-service metrics into a bar chart: one series per metric key
397
523
  * (e.g. `RATE`, `COUNT`), with a bar per evaluated dimension. Grouping by metric
398
524
  * key keeps related bars in the same series regardless of dimension ordering.
525
+ *
526
+ * @param result - Generated customer-service metric response from eBay.
527
+ * @returns A bar chart view model grouped by metric key.
528
+ *
529
+ * @example
530
+ * ```ts
531
+ * const view = mapCustomerServiceMetricToChart({ dimensionMetrics: [] });
532
+ * ```
399
533
  */
400
- export function mapCustomerServiceMetricToChart(result) {
534
+ export const mapCustomerServiceMetricToChart = (result) => {
401
535
  const dimensionMetrics = result.dimensionMetrics ?? [];
402
536
  const pointsByMetric = new Map();
403
537
  for (const dimensionMetric of dimensionMetrics) {
404
538
  const x = toLabel(dimensionMetric.dimension?.value ?? dimensionMetric.dimension?.name);
405
539
  for (const metric of dimensionMetric.metrics ?? []) {
406
- const key = metric.metricKey ?? 'Value';
540
+ const key = metric.metricKey ?? '';
541
+ const y = toNumber(metric.value);
542
+ if (y === null) {
543
+ continue;
544
+ }
407
545
  const points = pointsByMetric.get(key) ?? [];
408
- points.push({ x, y: toNumber(metric.value) });
546
+ points.push({ x, y });
409
547
  pointsByMetric.set(key, points);
410
548
  }
411
549
  }
@@ -416,4 +554,80 @@ export function mapCustomerServiceMetricToChart(result) {
416
554
  kind: 'bar',
417
555
  series,
418
556
  };
419
- }
557
+ };
558
+ /**
559
+ * Buckets remaining API headroom into a tile tone: healthy above a quarter of
560
+ * the quota, warning as it drains, danger near exhaustion. A missing or zero
561
+ * limit is neutral — there is no meaningful ratio to colour.
562
+ */
563
+ const headroomTone = (remaining, limit) => {
564
+ if (limit <= 0) {
565
+ return 'neutral';
566
+ }
567
+ const ratio = remaining / limit;
568
+ if (ratio <= 0.1) {
569
+ return 'danger';
570
+ }
571
+ if (ratio <= 0.25) {
572
+ return 'warning';
573
+ }
574
+ return 'success';
575
+ };
576
+ /**
577
+ * Flattens a rate-limit response into one tile per API resource, showing calls
578
+ * remaining against the quota with a tone that reflects headroom. Shared by the
579
+ * application- and user-scoped rate-limit tools, which return the same shape.
580
+ */
581
+ const rateLimitTiles = (result) => {
582
+ const tiles = [];
583
+ for (const rateLimit of result.rateLimits ?? []) {
584
+ for (const resource of rateLimit.resources ?? []) {
585
+ const rate = resource.rates?.[0];
586
+ if (!rate) {
587
+ continue;
588
+ }
589
+ const remaining = rate.remaining ?? 0;
590
+ const limit = rate.limit ?? 0;
591
+ const parts = [rateLimit.apiContext, rateLimit.apiName, resource.name].filter(Boolean);
592
+ tiles.push({
593
+ label: parts.length > 0 ? parts.join(' · ') : '',
594
+ value: remaining.toLocaleString('en-US'),
595
+ sub: `of ${limit.toLocaleString('en-US')}`,
596
+ tone: headroomTone(remaining, limit),
597
+ });
598
+ }
599
+ }
600
+ return tiles;
601
+ };
602
+ /**
603
+ * Projects application rate limits into a stat grid (calls remaining per resource).
604
+ *
605
+ * @param result - Generated application rate-limit response from eBay.
606
+ * @returns A stat view model with one tile per rated resource.
607
+ *
608
+ * @example
609
+ * ```ts
610
+ * const view = mapRateLimitsToStat({ rateLimits: [] });
611
+ * ```
612
+ */
613
+ export const mapRateLimitsToStat = (result) => ({
614
+ archetype: 'stat',
615
+ title: 'Application rate limits',
616
+ tiles: rateLimitTiles(result),
617
+ });
618
+ /**
619
+ * Projects user rate limits into a stat grid (per-user calls remaining per resource).
620
+ *
621
+ * @param result - Generated user rate-limit response from eBay.
622
+ * @returns A stat view model with one tile per rated resource.
623
+ *
624
+ * @example
625
+ * ```ts
626
+ * const view = mapUserRateLimitsToStat({ rateLimits: [] });
627
+ * ```
628
+ */
629
+ export const mapUserRateLimitsToStat = (result) => ({
630
+ archetype: 'stat',
631
+ title: 'User rate limits',
632
+ tiles: rateLimitTiles(result),
633
+ });
@@ -5,6 +5,6 @@
5
5
  // Core eBay types
6
6
  export * from './ebay.js';
7
7
  // eBay API enums
8
- export * from './ebay-enums.js';
8
+ export * from './ebayEnums.js';
9
9
  // OpenAPI generated types are imported directly as needed
10
10
  // due to their size and specific usage patterns