-
-
Notifications
You must be signed in to change notification settings - Fork 56
Expand file tree
/
Copy pathfulfillment.ts
More file actions
295 lines (293 loc) · 13 KB
/
Copy pathfulfillment.ts
File metadata and controls
295 lines (293 loc) · 13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
import { zodToJsonSchema } from 'zod-to-json-schema';
import { defineTool } from '@/tools/defineTool.js';
import type { OutputArgs } from '@/tools/types.js';
import type { ToolEntry } from '@/tools/registry.js';
import {
mapDisputeSummariesToTable,
mapDisputeToCard,
mapFulfillmentsToTable,
mapOrdersToTable,
mapOrderToCard,
} from '@/tools/ui/maps.js';
import {
filterOrdersWithCancellationRequests,
filterRefundedOrders,
} from '@/api/order-management/orderIssueHelpers.js';
import {
acceptPaymentDisputeInputSchema,
addEvidenceInputSchema,
contestPaymentDisputeInputSchema,
createShippingFulfillmentInputSchema,
getCancellationRequestsInputSchema,
getOrdersOutputSchema,
getOrdersInputSchema,
getOrderOutputSchema,
getOrderInputSchema,
createShippingFulfillmentOutputSchema,
fetchEvidenceContentInputSchema,
getActivitiesInputSchema,
getRefundedOrdersInputSchema,
getShippingFulfillmentsOutputSchema,
getShippingFulfillmentsInputSchema,
getShippingFulfillmentOutputSchema,
getShippingFulfillmentInputSchema,
getPaymentDisputeInputSchema,
issueRefundOutputSchema,
issueRefundInputSchema,
getPaymentDisputeSummariesOutputSchema,
getPaymentDisputeSummariesInputSchema,
uploadEvidenceFileInputSchema,
updateEvidenceInputSchema,
} from '@/schemas/fulfillment/orders.js';
import { Effect } from 'effect';
/** Default number of recent orders scanned by cancellation/refund helpers. */
const DEFAULT_ORDER_SCAN_LIMIT = 50;
/** Fulfillment API tools for orders, shipping fulfillments, refunds, and payment disputes. */
export const fulfillmentEntries: ToolEntry[] = [
defineTool({
name: 'ebay_get_orders',
description:
'Retrieve orders for the seller.\n\nRequired OAuth Scope: sell.fulfillment.readonly or sell.fulfillment\nMinimum Scope: https://api.ebay.com/oauth/api_scope/sell.fulfillment.readonly',
inputSchema: getOrdersInputSchema.shape,
outputSchema: zodToJsonSchema(getOrdersOutputSchema, {
name: 'GetOrdersResponse',
$refStrategy: 'none',
}) as OutputArgs,
handler: (api, args) => Effect.runPromise(api.fulfillment.getOrders(args)),
ui: { archetype: 'table', map: mapOrdersToTable },
}),
defineTool({
name: 'ebay_get_order',
description:
'Get details of a specific order.\n\nRequired OAuth Scope: sell.fulfillment.readonly or sell.fulfillment\nMinimum Scope: https://api.ebay.com/oauth/api_scope/sell.fulfillment.readonly',
inputSchema: getOrderInputSchema.shape,
outputSchema: zodToJsonSchema(getOrderOutputSchema, {
name: 'GetOrderResponse',
$refStrategy: 'none',
}) as OutputArgs,
handler: (api, args) => Effect.runPromise(api.fulfillment.getOrder(args)),
ui: { archetype: 'card', map: mapOrderToCard },
}),
defineTool({
name: 'ebay_create_shipping_fulfillment',
description:
'Create a shipping fulfillment for an order.\n\nRequired OAuth Scope: sell.fulfillment\nMinimum Scope: https://api.ebay.com/oauth/api_scope/sell.fulfillment',
inputSchema: createShippingFulfillmentInputSchema.shape,
outputSchema: zodToJsonSchema(createShippingFulfillmentOutputSchema, {
name: 'CreateShippingFulfillmentResponse',
$refStrategy: 'none',
}) as OutputArgs,
handler: (api, args) => Effect.runPromise(api.fulfillment.createShippingFulfillment(args)),
}),
defineTool({
name: 'ebay_get_shipping_fulfillments',
description:
'Get all shipping fulfillments for an order.\n\nRequired OAuth Scope: sell.fulfillment.readonly or sell.fulfillment\nMinimum Scope: https://api.ebay.com/oauth/api_scope/sell.fulfillment.readonly',
inputSchema: getShippingFulfillmentsInputSchema.shape,
outputSchema: zodToJsonSchema(getShippingFulfillmentsOutputSchema, {
name: 'GetShippingFulfillmentsResponse',
$refStrategy: 'none',
}) as OutputArgs,
handler: (api, args) => Effect.runPromise(api.fulfillment.getShippingFulfillments(args)),
ui: { archetype: 'table', map: mapFulfillmentsToTable },
}),
defineTool({
name: 'ebay_get_shipping_fulfillment',
description:
'Get a specific shipping fulfillment by ID.\n\nRequired OAuth Scope: sell.fulfillment.readonly or sell.fulfillment\nMinimum Scope: https://api.ebay.com/oauth/api_scope/sell.fulfillment.readonly',
inputSchema: getShippingFulfillmentInputSchema.shape,
outputSchema: zodToJsonSchema(getShippingFulfillmentOutputSchema, {
name: 'GetShippingFulfillmentResponse',
$refStrategy: 'none',
}) as OutputArgs,
handler: (api, args) => Effect.runPromise(api.fulfillment.getShippingFulfillment(args)),
}),
defineTool({
name: 'ebay_issue_refund',
description:
'Issue a full or partial refund for an eBay order. Use this to refund buyers for orders, including specifying the refund amount and reason.\n\nRequired OAuth Scope: sell.fulfillment\nMinimum Scope: https://api.ebay.com/oauth/api_scope/sell.fulfillment',
inputSchema: issueRefundInputSchema.shape,
outputSchema: zodToJsonSchema(issueRefundOutputSchema, {
name: 'IssueRefundResponse',
$refStrategy: 'none',
}) as OutputArgs,
handler: (api, args) => Effect.runPromise(api.fulfillment.issueRefund(args)),
}),
defineTool({
name: 'ebay_get_cancellation_requests',
description:
'Scan recent seller orders for cancellation requests. Calls Fulfillment API getOrders and returns orders whose cancelState is not NONE_REQUESTED (or that list cancel requests). Read-only helper — does not use the deprecated Post-Order API.\n\nRequired OAuth Scope: sell.fulfillment.readonly or sell.fulfillment\nMinimum Scope: https://api.ebay.com/oauth/api_scope/sell.fulfillment.readonly',
inputSchema: getCancellationRequestsInputSchema.shape,
annotations: { readOnlyHint: true },
handler: (api, args) =>
Effect.runPromise(
api.fulfillment
.getOrders({
filter: args.filter,
limit: args.maxResults ?? DEFAULT_ORDER_SCAN_LIMIT,
})
.pipe(
Effect.map((result) => {
const orders = result.orders ?? [];
const matches = filterOrdersWithCancellationRequests(orders);
return {
totalScanned: orders.length,
totalMatched: matches.length,
orders: matches,
};
}),
),
),
}),
defineTool({
name: 'ebay_get_refunded_orders',
description:
'Scan recent seller orders for refunds. Calls Fulfillment API getOrders and returns orders with a non-empty paymentSummary.refunds array. Read-only helper — does not issue refunds or call the Post-Order API.\n\nRequired OAuth Scope: sell.fulfillment.readonly or sell.fulfillment\nMinimum Scope: https://api.ebay.com/oauth/api_scope/sell.fulfillment.readonly',
inputSchema: getRefundedOrdersInputSchema.shape,
annotations: { readOnlyHint: true },
handler: (api, args) =>
Effect.runPromise(
api.fulfillment
.getOrders({
filter: args.filter,
limit: args.maxResults ?? DEFAULT_ORDER_SCAN_LIMIT,
})
.pipe(
Effect.map((result) => {
const orders = result.orders ?? [];
const matches = filterRefundedOrders(orders);
return {
totalScanned: orders.length,
totalMatched: matches.length,
orders: matches,
};
}),
),
),
}),
// Payment Dispute Tools
defineTool({
name: 'ebay_get_payment_dispute_summaries',
description:
'Get summaries of all payment disputes. Use filters to narrow results by dispute status, buyer username, or order ID.\n\nRequired OAuth Scope: sell.fulfillment\nMinimum Scope: https://api.ebay.com/oauth/api_scope/sell.fulfillment',
inputSchema: getPaymentDisputeSummariesInputSchema.shape,
outputSchema: zodToJsonSchema(getPaymentDisputeSummariesOutputSchema, {
name: 'GetPaymentDisputeSummariesResponse',
$refStrategy: 'none',
}) as OutputArgs,
handler: (api, args) => Effect.runPromise(api.dispute.getPaymentDisputeSummaries(args)),
ui: { archetype: 'table', map: mapDisputeSummariesToTable },
}),
defineTool({
name: 'ebay_get_payment_dispute',
description:
'Get detailed information about a specific payment dispute.\n\nRequired OAuth Scope: sell.fulfillment\nMinimum Scope: https://api.ebay.com/oauth/api_scope/sell.fulfillment',
inputSchema: getPaymentDisputeInputSchema.shape,
outputSchema: {
type: 'object',
properties: {
paymentDisputeId: { type: 'string' },
orderId: { type: 'string' },
paymentDisputeStatus: { type: 'string' },
reason: { type: 'string' },
amount: { type: 'object' },
},
description: 'Payment dispute details',
},
handler: (api, args) => Effect.runPromise(api.dispute.getPaymentDispute(args)),
ui: { archetype: 'card', map: mapDisputeToCard },
}),
defineTool({
name: 'ebay_get_payment_dispute_activities',
description:
'Get activity history for a payment dispute, including all actions taken by buyer, seller, and eBay.\n\nRequired OAuth Scope: sell.fulfillment\nMinimum Scope: https://api.ebay.com/oauth/api_scope/sell.fulfillment',
inputSchema: getActivitiesInputSchema.shape,
outputSchema: {
type: 'object',
properties: {
activity: { type: 'array' },
},
description: 'Payment dispute activity history',
},
handler: (api, args) => Effect.runPromise(api.dispute.getActivities(args)),
}),
defineTool({
name: 'ebay_accept_payment_dispute',
description:
'Accept a payment dispute and allow eBay to refund the buyer. Use this when you agree with the buyer claim.\n\nRequired OAuth Scope: sell.fulfillment\nMinimum Scope: https://api.ebay.com/oauth/api_scope/sell.fulfillment',
inputSchema: acceptPaymentDisputeInputSchema.shape,
outputSchema: {
type: 'object',
properties: {},
description: 'Empty response on successful acceptance (HTTP 204)',
},
handler: (api, args) => Effect.runPromise(api.dispute.acceptPaymentDispute(args)),
}),
defineTool({
name: 'ebay_contest_payment_dispute',
description:
'Contest a payment dispute by providing evidence. Use this when you disagree with the buyer claim and want to provide proof.\n\nRequired OAuth Scope: sell.fulfillment\nMinimum Scope: https://api.ebay.com/oauth/api_scope/sell.fulfillment',
inputSchema: contestPaymentDisputeInputSchema.shape,
outputSchema: {
type: 'object',
properties: {},
description: 'Empty response on successful contest (HTTP 204)',
},
handler: (api, args) => Effect.runPromise(api.dispute.contestPaymentDispute(args)),
}),
defineTool({
name: 'ebay_add_payment_dispute_evidence',
description:
'Add evidence to support your case in a payment dispute. Provide evidence files and supporting information.\n\nRequired OAuth Scope: sell.fulfillment\nMinimum Scope: https://api.ebay.com/oauth/api_scope/sell.fulfillment',
inputSchema: addEvidenceInputSchema.shape,
outputSchema: {
type: 'object',
properties: {
evidenceId: { type: 'string' },
},
description: 'Evidence set response returned after adding payment dispute evidence',
},
handler: (api, args) => Effect.runPromise(api.dispute.addEvidence(args)),
}),
defineTool({
name: 'ebay_update_payment_dispute_evidence',
description:
'Update existing evidence in a payment dispute.\n\nRequired OAuth Scope: sell.fulfillment\nMinimum Scope: https://api.ebay.com/oauth/api_scope/sell.fulfillment',
inputSchema: updateEvidenceInputSchema.shape,
outputSchema: {
type: 'object',
properties: {},
description: 'Empty response on successful evidence update (HTTP 204)',
},
handler: (api, args) => Effect.runPromise(api.dispute.updateEvidence(args)),
}),
defineTool({
name: 'ebay_upload_payment_dispute_evidence_file',
description:
'Upload a file as evidence for a payment dispute (e.g., shipping receipt, photos). Returns a file ID to use with add_evidence.\n\nRequired OAuth Scope: sell.fulfillment\nMinimum Scope: https://api.ebay.com/oauth/api_scope/sell.fulfillment',
inputSchema: uploadEvidenceFileInputSchema.shape,
outputSchema: {
type: 'object',
properties: {
fileId: { type: 'string' },
},
description: 'File upload response with file ID',
},
handler: (api, args) => Effect.runPromise(api.dispute.uploadEvidenceFile(args)),
}),
defineTool({
name: 'ebay_fetch_payment_dispute_evidence_content',
description:
'Download evidence file content from a payment dispute.\n\nRequired OAuth Scope: sell.fulfillment\nMinimum Scope: https://api.ebay.com/oauth/api_scope/sell.fulfillment',
inputSchema: fetchEvidenceContentInputSchema.shape,
outputSchema: {
type: 'object',
properties: {
content: { type: 'string' },
contentType: { type: 'string' },
},
description: 'File content and content type',
},
handler: (api, args) => Effect.runPromise(api.dispute.fetchEvidenceContent(args)),
}),
];