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,135 +1,226 @@
1
- import { getErrorMessage } from '../../utils/errors.js';
2
- /**
3
- * Run an API operation and prefix failures with endpoint-specific context.
4
- */
5
- export async function withApiError(failureMessage, operation) {
6
- try {
7
- return await operation();
8
- }
9
- catch (error) {
10
- throw new Error(`${failureMessage}: ${getErrorMessage(error)}`);
1
+ import { Data, Effect } from 'effect';
2
+ /** Tagged failure returned by migrated eBay API endpoint Effects. */
3
+ export class EbayApiError extends Data.TaggedError('EbayApiError') {
4
+ get message() {
5
+ const detail = this.cause instanceof Error ? this.cause.message : String(this.cause);
6
+ return `eBay ${this.method} ${this.path} failed: ${detail}`;
11
7
  }
12
8
  }
9
+ /** Tagged validation failure returned before an endpoint request is sent. */
10
+ export class EndpointInputError extends Data.TaggedError('EndpointInputError') {
11
+ }
13
12
  /**
14
- * Require a tool argument or API field to be a non-empty string.
13
+ * Builds query params from an endpoint-owned allow-list.
14
+ *
15
+ * @param params - Camel-case local parameter names mapped to their eBay wire names and values.
16
+ * @returns A query object for the request adapter, or undefined when every value is omitted.
17
+ *
18
+ * @example
19
+ * ```ts
20
+ * const params = buildEndpointParams({
21
+ * policyTypes: { wireName: 'policy_types', value: input.policyTypes },
22
+ * });
23
+ * ```
15
24
  */
16
- export function requireString(value, name) {
17
- if (!value || typeof value !== 'string') {
18
- throw new Error(`${name} is required and must be a string`);
25
+ export const buildEndpointParams = (params) => {
26
+ const query = {};
27
+ for (const param of Object.values(params)) {
28
+ if (param.value !== undefined && param.value !== '') {
29
+ query[param.wireName] = param.value;
30
+ }
19
31
  }
20
- }
32
+ return Object.keys(query).length > 0 ? query : undefined;
33
+ };
21
34
  /**
22
- * Require a tool argument or API payload field to be an object.
35
+ * Require a tool argument or API field to be a non-empty string inside Effect code.
36
+ *
37
+ * @param value - Unknown value supplied by a caller or transport boundary.
38
+ * @param name - Parameter name used in the validation message.
39
+ * @returns An Effect that succeeds with the string or fails with a tagged input error.
40
+ *
41
+ * @example
42
+ * ```ts
43
+ * const signingKeyId = yield* requireStringEffect(input.signingKeyId, 'signingKeyId');
44
+ * ```
23
45
  */
24
- export function requireObject(value, name) {
25
- if (!value || typeof value !== 'object') {
26
- throw new Error(`${name} is required and must be an object`);
46
+ export const requireStringEffect = (value, name) => {
47
+ if (!value || typeof value !== 'string') {
48
+ return Effect.fail(new EndpointInputError({
49
+ parameter: name,
50
+ message: `${name} is required and must be a string`,
51
+ }));
27
52
  }
28
- }
53
+ return Effect.succeed(value);
54
+ };
29
55
  /**
30
- * Validate an optional string query parameter.
56
+ * Validate an optional string inside Effect code.
57
+ *
58
+ * @param value - Optional value supplied for an endpoint query parameter.
59
+ * @param name - Parameter name used in the validation message.
60
+ * @returns An Effect that succeeds with the string, undefined, or a tagged input error.
61
+ *
62
+ * @example
63
+ * ```ts
64
+ * const sort = yield* optionalStringEffect(input.sort, 'sort');
65
+ * ```
31
66
  */
32
- export function optionalStringParam(value, name) {
67
+ export const optionalStringEffect = (value, name) => {
33
68
  if (value === undefined) {
34
- return undefined;
69
+ return Effect.succeed(undefined);
35
70
  }
36
71
  if (typeof value !== 'string') {
37
- throw new Error(`${name} must be a string when provided`);
72
+ return Effect.fail(new EndpointInputError({
73
+ parameter: name,
74
+ message: `${name} must be a string when provided`,
75
+ }));
38
76
  }
39
- return value;
40
- }
41
- /**
42
- * Build a query object from provided optional string parameters.
43
- */
44
- export function buildOptionalStringParams(params) {
45
- const query = {};
46
- for (const [name, value] of Object.entries(params)) {
47
- const stringValue = optionalStringParam(value, name);
48
- if (stringValue) {
49
- query[name] = stringValue;
50
- }
51
- }
52
- return query;
53
- }
77
+ return Effect.succeed(value);
78
+ };
54
79
  /**
55
- * Validate an optional positive numeric query parameter such as page size.
80
+ * Validate an optional positive numeric query parameter inside Effect code.
81
+ *
82
+ * @param value - Optional value supplied for an endpoint query parameter.
83
+ * @param name - Parameter name used in the validation message.
84
+ * @returns An Effect that succeeds with the number, undefined, or a tagged input error.
85
+ *
86
+ * @example
87
+ * ```ts
88
+ * const limit = yield* optionalPositiveNumberEffect(input.limit, 'limit');
89
+ * ```
56
90
  */
57
- export function optionalPositiveNumberParam(value, name) {
91
+ export const optionalPositiveNumberEffect = (value, name) => {
58
92
  if (value === undefined) {
59
- return undefined;
93
+ return Effect.succeed(undefined);
60
94
  }
61
95
  if (typeof value !== 'number' || value < 1) {
62
- throw new Error(`${name} must be a positive number when provided`);
96
+ return Effect.fail(new EndpointInputError({
97
+ parameter: name,
98
+ message: `${name} must be a positive number when provided`,
99
+ }));
63
100
  }
64
- return value;
65
- }
101
+ return Effect.succeed(value);
102
+ };
66
103
  /**
67
- * Validate an optional non-negative numeric query parameter such as an offset.
104
+ * Validate an optional non-negative numeric query parameter inside Effect code.
105
+ *
106
+ * @param value - Optional value supplied for an endpoint query parameter.
107
+ * @param name - Parameter name used in the validation message.
108
+ * @returns An Effect that succeeds with the number, undefined, or a tagged input error.
109
+ *
110
+ * @example
111
+ * ```ts
112
+ * const offset = yield* optionalNonNegativeNumberEffect(input.offset, 'offset');
113
+ * ```
68
114
  */
69
- export function optionalNonNegativeNumberParam(value, name) {
115
+ export const optionalNonNegativeNumberEffect = (value, name) => {
70
116
  if (value === undefined) {
71
- return undefined;
117
+ return Effect.succeed(undefined);
72
118
  }
73
119
  if (typeof value !== 'number' || value < 0) {
74
- throw new Error(`${name} must be a non-negative number when provided`);
120
+ return Effect.fail(new EndpointInputError({
121
+ parameter: name,
122
+ message: `${name} must be a non-negative number when provided`,
123
+ }));
75
124
  }
76
- return value;
77
- }
125
+ return Effect.succeed(value);
126
+ };
78
127
  /**
79
- * Build validated filter/limit/offset query parameters for paginated eBay APIs.
128
+ * Require a tool argument or API payload field to be an object inside Effect code.
129
+ *
130
+ * @param value - Unknown value supplied by a caller or transport boundary.
131
+ * @param name - Parameter name used in the validation message.
132
+ * @returns An Effect that succeeds with the expected object shape or fails with a tagged input error.
133
+ *
134
+ * @example
135
+ * ```ts
136
+ * const request = yield* requireObjectEffect<CreateOffersRequest>(body, 'offerData');
137
+ * ```
80
138
  */
81
- export function buildValidatedPaginatedParams(filter, limit, offset) {
82
- const params = {};
83
- const validatedFilter = optionalStringParam(filter, 'filter');
84
- const validatedLimit = optionalPositiveNumberParam(limit, 'limit');
85
- const validatedOffset = optionalNonNegativeNumberParam(offset, 'offset');
86
- if (validatedFilter !== undefined) {
87
- params.filter = validatedFilter;
88
- }
89
- if (validatedLimit !== undefined) {
90
- params.limit = validatedLimit;
91
- }
92
- if (validatedOffset !== undefined) {
93
- params.offset = validatedOffset;
94
- }
95
- return params;
96
- }
97
- /**
98
- * Build validated continuation-token query parameters for cursor-based eBay APIs.
99
- */
100
- export function buildContinuationParams(limit, continuationToken) {
101
- const params = {};
102
- const validatedLimit = optionalPositiveNumberParam(limit, 'limit');
103
- const validatedContinuationToken = optionalStringParam(continuationToken, 'continuationToken');
104
- if (validatedLimit !== undefined) {
105
- params.limit = validatedLimit;
106
- }
107
- if (validatedContinuationToken !== undefined) {
108
- params.continuation_token = validatedContinuationToken;
139
+ export const requireObjectEffect = (value, name) => {
140
+ if (!value || typeof value !== 'object') {
141
+ return Effect.fail(new EndpointInputError({
142
+ parameter: name,
143
+ message: `${name} is required and must be an object`,
144
+ }));
109
145
  }
110
- return params;
111
- }
146
+ return Effect.succeed(value);
147
+ };
112
148
  /**
113
- * Execute a GET request with consistent eBay API error context.
149
+ * Execute a GET request as an Effect with typed eBay API errors.
150
+ *
151
+ * @param client - eBay REST client that owns auth and transport details.
152
+ * @param path - eBay REST path to request.
153
+ * @param params - Optional query parameters already mapped to eBay wire names.
154
+ * @param config - Optional per-request headers or params, used for endpoint-specific headers.
155
+ * @returns An Effect that succeeds with the generated eBay response DTO.
156
+ *
157
+ * @example
158
+ * ```ts
159
+ * const response = await Effect.runPromise(requestGetEffect(client, path, params));
160
+ * ```
114
161
  */
115
- export async function getWithApiError(client, path, failureMessage, params) {
116
- return await withApiError(failureMessage, () => params === undefined ? client.get(path) : client.get(path, params));
117
- }
162
+ export const requestGetEffect = (client, path, params, config) => Effect.tryPromise({
163
+ try: () => {
164
+ if (config !== undefined) {
165
+ return client.get(path, params, config);
166
+ }
167
+ return params === undefined ? client.get(path) : client.get(path, params);
168
+ },
169
+ catch: (cause) => new EbayApiError({ method: 'GET', path, cause }),
170
+ });
118
171
  /**
119
- * Execute a POST request with consistent eBay API error context.
172
+ * Execute a POST request as an Effect with typed eBay API errors.
173
+ *
174
+ * @param client - eBay REST client that owns auth and transport details.
175
+ * @param path - eBay REST path to request.
176
+ * @param body - Optional JSON body to send.
177
+ * @param config - Optional per-request headers or params, used for endpoint-specific headers.
178
+ * @returns An Effect that succeeds with the generated eBay response DTO.
179
+ *
180
+ * @example
181
+ * ```ts
182
+ * const response = await Effect.runPromise(requestPostEffect(client, path, body));
183
+ * ```
120
184
  */
121
- export async function postWithApiError(client, path, failureMessage, body) {
122
- return await withApiError(failureMessage, () => client.post(path, body));
123
- }
185
+ export const requestPostEffect = (client, path, body, config) => Effect.tryPromise({
186
+ try: () => {
187
+ if (config !== undefined) {
188
+ return client.post(path, body, config);
189
+ }
190
+ return body === undefined ? client.post(path) : client.post(path, body);
191
+ },
192
+ catch: (cause) => new EbayApiError({ method: 'POST', path, cause }),
193
+ });
124
194
  /**
125
- * Execute a PUT request with consistent eBay API error context.
195
+ * Execute a PUT request as an Effect with typed eBay API errors.
196
+ *
197
+ * @param client - eBay REST client that owns auth and transport details.
198
+ * @param path - eBay REST path to request.
199
+ * @param body - Optional JSON body to send.
200
+ * @returns An Effect that succeeds with the generated eBay response DTO.
201
+ *
202
+ * @example
203
+ * ```ts
204
+ * const response = await Effect.runPromise(requestPutEffect(client, path, body));
205
+ * ```
126
206
  */
127
- export async function putWithApiError(client, path, failureMessage, body) {
128
- return await withApiError(failureMessage, () => client.put(path, body));
129
- }
207
+ export const requestPutEffect = (client, path, body) => Effect.tryPromise({
208
+ try: () => client.put(path, body),
209
+ catch: (cause) => new EbayApiError({ method: 'PUT', path, cause }),
210
+ });
130
211
  /**
131
- * Execute a DELETE request with consistent eBay API error context.
212
+ * Execute a DELETE request as an Effect with typed eBay API errors.
213
+ *
214
+ * @param client - eBay REST client that owns auth and transport details.
215
+ * @param path - eBay REST path to request.
216
+ * @returns An Effect that succeeds with the generated eBay response DTO.
217
+ *
218
+ * @example
219
+ * ```ts
220
+ * await Effect.runPromise(requestDeleteEffect(client, path));
221
+ * ```
132
222
  */
133
- export async function deleteWithApiError(client, path, failureMessage) {
134
- return await withApiError(failureMessage, () => client.delete(path));
135
- }
223
+ export const requestDeleteEffect = (client, path) => Effect.tryPromise({
224
+ try: () => client.delete(path),
225
+ catch: (cause) => new EbayApiError({ method: 'DELETE', path, cause }),
226
+ });
@@ -1,18 +1,12 @@
1
- import { isRecord } from '../../utils/type-guards.js';
2
- function asRecord(value) {
3
- return isRecord(value) ? value : undefined;
4
- }
5
- function asRecordArray(value) {
1
+ import { optionalPositiveNumberEffect, optionalStringEffect, requireObjectEffect, requireStringEffect, } from '../../api/shared/request.js';
2
+ import { isRecord } from '../../utils/typeGuards.js';
3
+ import { Effect } from 'effect';
4
+ const asRecordArray = (value) => {
6
5
  if (!Array.isArray(value)) {
7
6
  return [];
8
7
  }
9
- return value.filter((entry) => typeof entry === 'object' && entry !== null && !Array.isArray(entry));
10
- }
11
- function stringValue(value) {
12
- return typeof value === 'string' || typeof value === 'number' || typeof value === 'boolean'
13
- ? String(value)
14
- : '';
15
- }
8
+ return value.filter(isRecord);
9
+ };
16
10
  /**
17
11
  * High-level wrapper for seller listing operations backed by eBay Trading API calls.
18
12
  */
@@ -22,96 +16,169 @@ export class TradingApi {
22
16
  this.client = client;
23
17
  }
24
18
  /**
25
- * Fetch active seller listings with Trading API pagination metadata.
19
+ * Fetches active seller listings with Trading API pagination metadata.
20
+ *
21
+ * @param input - Optional page number and entries-per-page values.
22
+ * @returns An Effect that succeeds with the parsed GetMyeBaySelling response payload.
23
+ *
24
+ * @example
25
+ * ```ts
26
+ * const response = await Effect.runPromise(
27
+ * tradingApi.getActiveListings({ page: 2, entriesPerPage: 25 }),
28
+ * );
29
+ * ```
30
+ *
31
+ * @see https://developer.ebay.com/devzone/xml/docs/reference/ebay/getmyebayselling.html
26
32
  */
27
- async getActiveListings(page = 1, entriesPerPage = 50) {
28
- const result = await this.client.execute('GetMyeBaySelling', {
29
- ActiveList: {
30
- Sort: 'TimeLeft',
31
- Pagination: {
32
- EntriesPerPage: entriesPerPage,
33
- PageNumber: page,
33
+ getActiveListings = (input = {}) => {
34
+ const tradingClient = this.client;
35
+ return Effect.gen(function* () {
36
+ const request = yield* requireObjectEffect(input, 'input');
37
+ const inputPage = yield* optionalPositiveNumberEffect(request.page, 'page');
38
+ const inputEntriesPerPage = yield* optionalPositiveNumberEffect(request.entriesPerPage, 'entriesPerPage');
39
+ const page = inputPage === undefined ? 1 : inputPage;
40
+ const entriesPerPage = inputEntriesPerPage === undefined ? 50 : inputEntriesPerPage;
41
+ return yield* tradingClient.execute('GetMyeBaySelling', {
42
+ ActiveList: {
43
+ Sort: 'TimeLeft',
44
+ Pagination: {
45
+ EntriesPerPage: entriesPerPage,
46
+ PageNumber: page,
47
+ },
34
48
  },
35
- },
49
+ });
36
50
  });
37
- const activeList = asRecord(result.ActiveList);
38
- const itemArray = asRecord(activeList?.ItemArray);
39
- const items = asRecordArray(itemArray?.Item);
40
- const pagination = asRecord(activeList?.PaginationResult);
41
- const listings = items.map((item) => {
42
- const sellingStatus = asRecord(item.SellingStatus);
43
- const currentPriceRaw = sellingStatus?.CurrentPrice;
44
- const currentPrice = typeof currentPriceRaw === 'number' || isRecord(currentPriceRaw)
45
- ? currentPriceRaw
46
- : undefined;
47
- const priceValue = typeof currentPrice === 'object' && currentPrice !== null
48
- ? Number(currentPrice['#text'] || 0)
49
- : Number(currentPrice || 0);
50
- return {
51
- itemId: stringValue(item.ItemID),
52
- title: stringValue(item.Title),
53
- sku: stringValue(item.SKU),
54
- quantity: Number(item.Quantity || 0),
55
- quantityAvailable: Number(item.QuantityAvailable || 0),
56
- currentPrice: priceValue,
57
- watchCount: Number(item.WatchCount || 0),
58
- listingType: stringValue(item.ListingType),
59
- };
60
- });
61
- return {
62
- listings,
63
- total: Number(pagination?.TotalNumberOfEntries || 0),
64
- totalPages: Number(pagination?.TotalNumberOfPages || 0),
65
- };
66
- }
51
+ };
67
52
  /**
68
- * Fetch a single listing by eBay item ID with full Trading API detail.
53
+ * Fetches a single listing by eBay item ID with full Trading API detail.
54
+ *
55
+ * @param input - eBay item identifier.
56
+ * @returns An Effect that succeeds with the parsed Trading API item payload.
57
+ *
58
+ * @example
59
+ * ```ts
60
+ * const listing = await Effect.runPromise(tradingApi.getListing({ itemId: '12345' }));
61
+ * ```
62
+ *
63
+ * @see https://developer.ebay.com/devzone/xml/docs/reference/ebay/getitem.html
69
64
  */
70
- async getListing(itemId) {
71
- if (!itemId)
72
- throw new Error('itemId is required');
73
- const result = await this.client.execute('GetItem', {
74
- ItemID: itemId,
75
- DetailLevel: 'ReturnAll',
65
+ getListing = (input) => {
66
+ const tradingClient = this.client;
67
+ return Effect.gen(function* () {
68
+ const request = yield* requireObjectEffect(input, 'input');
69
+ const itemId = yield* requireStringEffect(request.itemId, 'itemId');
70
+ const result = yield* tradingClient.execute('GetItem', {
71
+ ItemID: itemId,
72
+ DetailLevel: 'ReturnAll',
73
+ });
74
+ const items = asRecordArray(result.Item);
75
+ return items.length > 0 ? items[0] : result;
76
76
  });
77
- const items = asRecordArray(result.Item);
78
- return items?.[0] || result;
79
- }
77
+ };
80
78
  /**
81
- * Create a fixed-price listing using the supplied Trading API item payload.
79
+ * Creates a fixed-price listing using the supplied Trading API item payload.
80
+ *
81
+ * @param input - Trading API Item payload nested under `item`.
82
+ * @returns An Effect that succeeds with the parsed AddFixedPriceItem response.
83
+ *
84
+ * @example
85
+ * ```ts
86
+ * const listing = await Effect.runPromise(
87
+ * tradingApi.createListing({ item: { Title: 'New item', StartPrice: 9.99 } }),
88
+ * );
89
+ * ```
90
+ *
91
+ * @see https://developer.ebay.com/devzone/xml/docs/reference/ebay/AddFixedPriceItem.html
82
92
  */
83
- async createListing(item) {
84
- return await this.client.execute('AddFixedPriceItem', { Item: item });
85
- }
93
+ createListing = (input) => {
94
+ const tradingClient = this.client;
95
+ return Effect.gen(function* () {
96
+ const request = yield* requireObjectEffect(input, 'input');
97
+ const item = yield* requireObjectEffect(request.item, 'item');
98
+ return yield* tradingClient.execute('AddFixedPriceItem', { Item: item });
99
+ });
100
+ };
86
101
  /**
87
- * Revise a fixed-price listing by merging changes with the eBay item ID.
102
+ * Revises a fixed-price listing by merging changes with the eBay item ID.
103
+ *
104
+ * @param input - eBay item identifier plus Trading API Item fields to update.
105
+ * @returns An Effect that succeeds with the parsed ReviseFixedPriceItem response.
106
+ *
107
+ * @example
108
+ * ```ts
109
+ * const listing = await Effect.runPromise(
110
+ * tradingApi.reviseListing({ itemId: '12345', fields: { Quantity: 10 } }),
111
+ * );
112
+ * ```
113
+ *
114
+ * @see https://developer.ebay.com/devzone/xml/docs/reference/ebay/ReviseFixedPriceItem.html
88
115
  */
89
- async reviseListing(itemId, fields) {
90
- if (!itemId)
91
- throw new Error('itemId is required');
92
- return await this.client.execute('ReviseFixedPriceItem', {
93
- Item: { ...fields, ItemID: itemId },
116
+ reviseListing = (input) => {
117
+ const tradingClient = this.client;
118
+ return Effect.gen(function* () {
119
+ const request = yield* requireObjectEffect(input, 'input');
120
+ const itemId = yield* requireStringEffect(request.itemId, 'itemId');
121
+ const fields = yield* requireObjectEffect(request.fields, 'fields');
122
+ return yield* tradingClient.execute('ReviseFixedPriceItem', {
123
+ Item: { ...fields, ItemID: itemId },
124
+ });
94
125
  });
95
- }
126
+ };
96
127
  /**
97
- * End a fixed-price listing with the provided Trading API ending reason.
128
+ * Ends a fixed-price listing with the provided Trading API ending reason.
129
+ *
130
+ * @param input - eBay item identifier plus optional Trading API ending reason.
131
+ * @returns An Effect that succeeds with the parsed EndFixedPriceItem response.
132
+ *
133
+ * @example
134
+ * ```ts
135
+ * await Effect.runPromise(
136
+ * tradingApi.endListing({ itemId: '12345', reason: 'NotAvailable' }),
137
+ * );
138
+ * ```
139
+ *
140
+ * @see https://developer.ebay.com/devzone/xml/docs/reference/ebay/endfixedpriceitem.html
98
141
  */
99
- async endListing(itemId, reason = 'NotAvailable') {
100
- if (!itemId)
101
- throw new Error('itemId is required');
102
- return await this.client.execute('EndFixedPriceItem', {
103
- ItemID: itemId,
104
- EndingReason: reason,
142
+ endListing = (input) => {
143
+ const tradingClient = this.client;
144
+ return Effect.gen(function* () {
145
+ const request = yield* requireObjectEffect(input, 'input');
146
+ const itemId = yield* requireStringEffect(request.itemId, 'itemId');
147
+ const inputReason = yield* optionalStringEffect(request.reason, 'reason');
148
+ const reason = inputReason === undefined ? 'NotAvailable' : inputReason;
149
+ return yield* tradingClient.execute('EndFixedPriceItem', {
150
+ ItemID: itemId,
151
+ EndingReason: reason,
152
+ });
105
153
  });
106
- }
154
+ };
107
155
  /**
108
- * Relist an ended fixed-price item with optional listing modifications.
156
+ * Relists an ended fixed-price item with optional listing modifications.
157
+ *
158
+ * @param input - eBay item identifier plus optional Trading API Item modifications.
159
+ * @returns An Effect that succeeds with the parsed RelistFixedPriceItem response.
160
+ *
161
+ * @example
162
+ * ```ts
163
+ * const listing = await Effect.runPromise(
164
+ * tradingApi.relistItem({ itemId: '12345', modifications: { Quantity: 20 } }),
165
+ * );
166
+ * ```
167
+ *
168
+ * @see https://developer.ebay.com/devzone/xml/docs/reference/ebay/relistfixedpriceitem.html
109
169
  */
110
- async relistItem(itemId, modifications) {
111
- if (!itemId)
112
- throw new Error('itemId is required');
113
- return await this.client.execute('RelistFixedPriceItem', {
114
- Item: { ...modifications, ItemID: itemId },
170
+ relistItem = (input) => {
171
+ const tradingClient = this.client;
172
+ return Effect.gen(function* () {
173
+ const request = yield* requireObjectEffect(input, 'input');
174
+ const itemId = yield* requireStringEffect(request.itemId, 'itemId');
175
+ let modifications = {};
176
+ if (request.modifications !== undefined) {
177
+ modifications = yield* requireObjectEffect(request.modifications, 'modifications');
178
+ }
179
+ return yield* tradingClient.execute('RelistFixedPriceItem', {
180
+ Item: { ...modifications, ItemID: itemId },
181
+ });
115
182
  });
116
- }
183
+ };
117
184
  }