ebay-mcp 2.0.5 → 2.0.7
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.
- package/README.md +18 -18
- package/build/auth/credentialSession.js +2 -2
- package/build/auth/oauth.js +6 -6
- package/build/auth/oauthHelper.js +2 -2
- package/build/auth/oauthMiddleware.js +1 -1
- package/build/auth/scopeUtils.js +1 -1
- package/build/{tools/categories/tokenManagement.js → auth/tokenManagementTools.js} +5 -5
- package/build/auth/tokenVerifier.js +2 -2
- package/build/{scripts → cli}/autoSetup.js +2 -2
- package/build/{scripts → cli}/diagnostics.js +10 -10
- package/build/{scripts → cli}/interactiveSetup.js +6 -6
- package/build/{scripts → cli}/scopeHelper.js +2 -2
- package/build/{scripts → cli}/securityChecker.js +1 -1
- package/build/{scripts → cli}/setup.js +10 -10
- package/build/{scripts → cli}/setupValidator.js +4 -4
- package/build/{scripts → cli}/setupWizard.js +1 -1
- package/build/{skills → cli/skills}/content.js +3 -3
- package/build/{skills → cli/skills}/index.js +11 -11
- package/build/{skills → cli/skills}/install.js +1 -1
- package/build/{skills → cli/skills}/registrySnapshot.js +1 -1
- package/build/{skills → cli/skills}/render.js +1 -1
- package/build/{scripts → cli}/skills.js +4 -4
- package/build/{api/account-management/account.js → ebay-apis/account/accountApi.js} +1 -1
- package/build/{schemas/account-management/account.js → ebay-apis/account/accountSchemas.js} +1 -1
- package/build/{tools/categories/account.js → ebay-apis/account/accountTools.js} +2 -2
- package/build/{api/account-management/accountV2.js → ebay-apis/account/accountV2Api.js} +1 -1
- package/build/{schemas/account-management/accountV2.js → ebay-apis/account/accountV2Schemas.js} +1 -1
- package/build/{tools/categories/accountV2.js → ebay-apis/account/accountV2Tools.js} +2 -2
- package/build/{api/analytics-and-report/analytics.js → ebay-apis/analytics/analyticsApi.js} +1 -1
- package/build/{tools/categories/analytics.js → ebay-apis/analytics/analyticsTools.js} +3 -3
- package/build/{api/other/browse.js → ebay-apis/browse/browseApi.js} +5 -5
- package/build/{api/other → ebay-apis/browse}/browseFilter.js +1 -1
- package/build/{api/other → ebay-apis/browse}/browseMappers.js +2 -2
- package/build/{tools/categories/browse.js → ebay-apis/browse/browseTools.js} +2 -2
- package/build/{api/other → ebay-apis/browse}/browseValidators.js +2 -2
- package/build/{tools/categories/communication.js → ebay-apis/communication/communicationTools.js} +5 -5
- package/build/{api/communication/feedback.js → ebay-apis/communication/feedbackApi.js} +1 -1
- package/build/{api/communication/message.js → ebay-apis/communication/messageApi.js} +1 -1
- package/build/{schemas/communication/messages.js → ebay-apis/communication/messageSchemas.js} +1 -1
- package/build/{api/communication/negotiation.js → ebay-apis/communication/negotiationApi.js} +1 -1
- package/build/{api/communication/notification.js → ebay-apis/communication/notificationApi.js} +1 -1
- package/build/{utils/communication/notification.js → ebay-apis/communication/notificationHelpers.js} +1 -1
- package/build/{api/developer/developer.js → ebay-apis/developer/developerApi.js} +2 -2
- package/build/{tools/categories/developer.js → ebay-apis/developer/developerTools.js} +4 -4
- package/build/ebay-apis/ebaySellerApi.js +175 -0
- package/build/{api/listing-management/feed.js → ebay-apis/feed/feedApi.js} +3 -3
- package/build/{api/listing-management/feedReportTasks.js → ebay-apis/feed/feedReportTasksApi.js} +3 -3
- package/build/{api/listing-management/feedRequest.js → ebay-apis/feed/feedRequestApi.js} +3 -3
- package/build/{api/listing-management/feedSchedules.js → ebay-apis/feed/feedSchedulesApi.js} +3 -3
- package/build/{api/listing-management/feedTasks.js → ebay-apis/feed/feedTasksApi.js} +3 -3
- package/build/{tools/categories/feed.js → ebay-apis/feed/feedTools.js} +5 -5
- package/build/{api/account-management/finances.js → ebay-apis/finances/financesApi.js} +3 -3
- package/build/{tools/categories/finances.js → ebay-apis/finances/financesTools.js} +3 -3
- package/build/{api/order-management/dispute.js → ebay-apis/fulfillment/disputeApi.js} +3 -3
- package/build/{api/order-management/fulfillment.js → ebay-apis/fulfillment/fulfillmentApi.js} +1 -1
- package/build/{tools/categories/fulfillment.js → ebay-apis/fulfillment/fulfillmentTools.js} +4 -4
- package/build/{schemas/fulfillment/orders.js → ebay-apis/fulfillment/ordersSchemas.js} +1 -1
- package/build/{api/listing-management/inventory.js → ebay-apis/inventory/inventoryApi.js} +3 -3
- package/build/{schemas/inventory-management/inventory.js → ebay-apis/inventory/inventorySchemas.js} +1 -1
- package/build/{tools/categories/inventory.js → ebay-apis/inventory/inventoryTools.js} +4 -4
- package/build/{api/listing-management/items.js → ebay-apis/inventory/itemsApi.js} +2 -2
- package/build/{api/listing-management/locations.js → ebay-apis/inventory/locationsApi.js} +2 -2
- package/build/{api/listing-management/media.js → ebay-apis/inventory/mediaApi.js} +5 -5
- package/build/{api/listing-management/mediaAttach.js → ebay-apis/inventory/mediaAttachApi.js} +2 -2
- package/build/{api/listing-management/mediaResources.js → ebay-apis/inventory/mediaResourcesApi.js} +4 -4
- package/build/{tools/categories/media.js → ebay-apis/inventory/mediaTools.js} +5 -5
- package/build/{api/listing-management/offerFormat.js → ebay-apis/inventory/offerFormatApi.js} +3 -3
- package/build/{api/listing-management/offers.js → ebay-apis/inventory/offersApi.js} +3 -3
- package/build/{api/order-management/logistics.js → ebay-apis/logistics/logisticsApi.js} +2 -2
- package/build/{schemas/fulfillment/logistics.js → ebay-apis/logistics/logisticsSchemas.js} +2 -2
- package/build/{tools/categories/logistics.js → ebay-apis/logistics/logisticsTools.js} +4 -4
- package/build/{api/marketing-and-promotions/ads.js → ebay-apis/marketing/adsApi.js} +2 -2
- package/build/{schemas/marketing/ads.js → ebay-apis/marketing/adsSchemas.js} +2 -2
- package/build/{api/marketing-and-promotions/campaigns.js → ebay-apis/marketing/campaignsApi.js} +2 -2
- package/build/{schemas/marketing/campaigns.js → ebay-apis/marketing/campaignsSchemas.js} +1 -1
- package/build/{api/marketing-and-promotions/marketing.js → ebay-apis/marketing/marketingApi.js} +4 -4
- package/build/ebay-apis/marketing/marketingSchemas.js +13 -0
- package/build/{tools/categories/marketing.js → ebay-apis/marketing/marketingTools.js} +2 -2
- package/build/{api/marketing-and-promotions/promotions.js → ebay-apis/marketing/promotionsApi.js} +2 -2
- package/build/{schemas/marketing/promotions.js → ebay-apis/marketing/promotionsSchemas.js} +2 -2
- package/build/{api/marketing-and-promotions/recommendation.js → ebay-apis/marketing/recommendationApi.js} +1 -1
- package/build/{api/marketing-and-promotions/reports.js → ebay-apis/marketing/reportsApi.js} +2 -2
- package/build/{schemas/marketing/reports.js → ebay-apis/marketing/reportsSchemas.js} +1 -1
- package/build/{api/listing-metadata/metadata.js → ebay-apis/metadata/metadataApi.js} +2 -2
- package/build/{api/listing-metadata/metadataShipping.js → ebay-apis/metadata/metadataShippingApi.js} +2 -2
- package/build/{schemas/metadata/shipping.js → ebay-apis/metadata/metadataShippingSchemas.js} +1 -1
- package/build/{tools/categories/metadata.js → ebay-apis/metadata/metadataTools.js} +3 -3
- package/build/{api/other/edelivery.js → ebay-apis/other/edelivery/edeliveryApi.js} +1 -1
- package/build/{api/other/identity.js → ebay-apis/other/identity/identityApi.js} +2 -2
- package/build/{utils/other/identity.js → ebay-apis/other/identity/identityHelpers.js} +2 -2
- package/build/{tools/categories/other.js → ebay-apis/other/otherTools.js} +2 -2
- package/build/{api/other/translation.js → ebay-apis/other/translation/translationApi.js} +1 -1
- package/build/{utils/other/translation.js → ebay-apis/other/translation/translationHelpers.js} +2 -2
- package/build/{api/other/vero.js → ebay-apis/other/vero/veroApi.js} +1 -1
- package/build/{utils/other/vero.js → ebay-apis/other/vero/veroHelpers.js} +2 -2
- package/build/{api/listing-management/stores.js → ebay-apis/stores/storesApi.js} +2 -2
- package/build/{tools/categories/stores.js → ebay-apis/stores/storesTools.js} +2 -2
- package/build/{api/listing-metadata/charity.js → ebay-apis/taxonomy/charityApi.js} +2 -2
- package/build/{tools/categories/charity.js → ebay-apis/taxonomy/charityTools.js} +2 -2
- package/build/{api/listing-metadata/taxonomy.js → ebay-apis/taxonomy/taxonomyApi.js} +3 -3
- package/build/{tools/categories/taxonomy.js → ebay-apis/taxonomy/taxonomyTools.js} +3 -3
- package/build/{api/trading/listingFormat.js → ebay-apis/trading/listingFormatHelpers.js} +4 -4
- package/build/{api/trading/trading.js → ebay-apis/trading/tradingApi.js} +4 -4
- package/build/{utils/trading/trading.js → ebay-apis/trading/tradingHelpers.js} +1 -1
- package/build/{tools/categories/trading.js → ebay-apis/trading/tradingTools.js} +2 -2
- package/build/{api/shared → ebay-client}/download.js +1 -1
- package/build/{api/client → ebay-client}/ebayApiClient.js +9 -9
- package/build/{api/shared → ebay-client}/location.js +1 -1
- package/build/{api/shared → ebay-client}/request.js +1 -1
- package/build/{api/client → ebay-client}/tradingApiClient.js +7 -7
- package/build/index.js +8 -8
- package/build/{tools/categories/connector.js → server/connectorTools.js} +1 -1
- package/build/{mcp → server}/httpTransport.js +5 -5
- package/build/{mcp → server}/readOnlyFilter.js +6 -0
- package/build/{mcp → server}/runtime.js +9 -9
- package/build/{mcp → server}/toolGating.js +3 -3
- package/build/{mcp → server}/uiBridge.js +3 -3
- package/build/serverHttp.js +5 -5
- package/build/{utils → shared}/apiStatusFeed.js +1 -1
- package/build/{config → shared}/credentialFile.js +1 -1
- package/build/{config → shared}/environment.js +6 -6
- package/build/{utils → shared}/http.js +2 -2
- package/build/{utils → shared}/localMedia.js +1 -1
- package/build/{utils → shared}/logger.js +2 -2
- package/build/{config → shared}/toolFamilies.js +3 -3
- package/build/{tools → tool-registry}/contracts.js +1 -1
- package/build/{tools → tool-registry}/defineTool.js +3 -3
- package/build/{tools → tool-registry}/index.js +2 -2
- package/build/{tools → tool-registry}/registry.js +1 -1
- package/build/{tools → tool-registry}/schemas.js +16 -1
- package/build/{tools/categories/index.js → tool-registry/toolCategories.js} +21 -21
- package/build/{tools → tool-registry}/ui/maps.js +2 -2
- package/build/{tools → tool-registry}/ui/viewModels.js +1 -1
- package/package.json +14 -18
- package/build/api/ebaySellerApi.js +0 -175
- package/build/schemas/marketing/marketing.js +0 -13
- package/build/scripts/buildMcpApps.js +0 -49
- package/build/scripts/devSync.js +0 -432
- package/build/scripts/specCoverage.js +0 -78
- package/build/scripts/specDownload.js +0 -42
- package/build/scripts/specRefs.js +0 -54
- package/build/scripts/specSources.js +0 -142
- package/build/scripts/specTypeNames.js +0 -23
- /package/build/{scripts → cli}/setupShared.js +0 -0
- /package/build/{skills → cli/skills}/markers.js +0 -0
- /package/build/{skills → cli/skills}/targets.js +0 -0
- /package/build/{skills → cli/skills}/types.js +0 -0
- /package/build/{schemas/analytics/analytics.js → ebay-apis/analytics/analyticsSchemas.js} +0 -0
- /package/build/{schemas/other/browse.js → ebay-apis/browse/browseSchemas.js} +0 -0
- /package/build/{api/other → ebay-apis/browse}/browseTypes.js +0 -0
- /package/build/{utils/communication/feedback.js → ebay-apis/communication/feedbackHelpers.js} +0 -0
- /package/build/{utils/communication/message.js → ebay-apis/communication/messageHelpers.js} +0 -0
- /package/build/{utils/communication/negotiation.js → ebay-apis/communication/negotiationHelpers.js} +0 -0
- /package/build/{schemas/developer/developer.js → ebay-apis/developer/developerSchemas.js} +0 -0
- /package/build/{schemas/inventory-management/feed.js → ebay-apis/feed/feedSchemas.js} +0 -0
- /package/build/{schemas/account-management/finances.js → ebay-apis/finances/financesSchemas.js} +0 -0
- /package/build/{api/order-management → ebay-apis/fulfillment}/orderIssueHelpers.js +0 -0
- /package/build/{api/listing-management/shared.js → ebay-apis/inventory/inventorySharedApi.js} +0 -0
- /package/build/{schemas/inventory-management/mediaDocuments.js → ebay-apis/inventory/mediaDocumentsSchemas.js} +0 -0
- /package/build/{schemas/inventory-management/media.js → ebay-apis/inventory/mediaSchemas.js} +0 -0
- /package/build/{schemas/marketing/common.js → ebay-apis/marketing/marketingCommonSchemas.js} +0 -0
- /package/build/{api/marketing-and-promotions/shared.js → ebay-apis/marketing/marketingSharedApi.js} +0 -0
- /package/build/{schemas/metadata/metadata.js → ebay-apis/metadata/metadataSchemas.js} +0 -0
- /package/build/{schemas/other/otherApis.js → ebay-apis/other/otherApisSchemas.js} +0 -0
- /package/build/{schemas/inventory-management/stores.js → ebay-apis/stores/storesSchemas.js} +0 -0
- /package/build/{schemas/taxonomy/categoryTree.js → ebay-apis/taxonomy/categoryTreeSchemas.js} +0 -0
- /package/build/{schemas/taxonomy/charity.js → ebay-apis/taxonomy/charitySchemas.js} +0 -0
- /package/build/{schemas/taxonomy/taxonomy.js → ebay-apis/taxonomy/taxonomySchemas.js} +0 -0
- /package/build/{api/shared → ebay-client}/auctionPricing.js +0 -0
- /package/build/{api/client → ebay-client}/ebayClientRequestError.js +0 -0
- /package/build/{api/client → ebay-client}/rateLimitTracker.js +0 -0
- /package/build/{api/client → ebay-client}/signEbayRequest.js +0 -0
- /package/build/{api/client → ebay-client}/tradingApiFailure.js +0 -0
- /package/build/{utils → shared}/cliOutput.js +0 -0
- /package/build/{utils → shared}/cliUi.js +0 -0
- /package/build/{utils → shared}/dateConverter.js +0 -0
- /package/build/{types → shared}/ebay.js +0 -0
- /package/build/{types → shared}/ebayEnums.js +0 -0
- /package/build/{utils → shared}/entryModule.js +0 -0
- /package/build/{utils → shared}/envFile.js +0 -0
- /package/build/{utils → shared}/envParser.js +0 -0
- /package/build/{utils → shared}/errors.js +0 -0
- /package/build/{types → shared}/index.js +0 -0
- /package/build/{utils → shared}/llmClientDetector.js +0 -0
- /package/build/{utils → shared}/localFeedFiles.js +0 -0
- /package/build/{utils → shared}/logRedaction.js +0 -0
- /package/build/{config → shared}/mediaAccess.js +0 -0
- /package/build/{config → shared}/oauthScopes.js +0 -0
- /package/build/{utils → shared}/objects.js +0 -0
- /package/build/{utils → shared}/schemaHelpers.js +0 -0
- /package/build/{utils → shared}/tokenUtils.js +0 -0
- /package/build/{utils → shared}/typeGuards.js +0 -0
- /package/build/{utils → shared}/version.js +0 -0
- /package/build/{utils → shared}/zodIssues.js +0 -0
- /package/build/{tools → tool-registry}/fileResult.js +0 -0
- /package/build/{tools → tool-registry}/types.js +0 -0
- /package/build/{tools → tool-registry}/ui/archetypes.js +0 -0
- /package/build/{tools → tool-registry}/ui/mapHelpers.js +0 -0
package/build/scripts/devSync.js
DELETED
|
@@ -1,432 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
import chalk from 'chalk';
|
|
3
|
-
import { existsSync, readFileSync, writeFileSync, mkdirSync, readdirSync } from 'fs';
|
|
4
|
-
import { join, dirname, basename } from 'path';
|
|
5
|
-
import { fileURLToPath } from 'url';
|
|
6
|
-
import { execFileSync, execSync } from 'child_process';
|
|
7
|
-
import { Effect, Either } from 'effect';
|
|
8
|
-
import { getErrorMessage } from '../utils/errors.js';
|
|
9
|
-
import process from 'node:process';
|
|
10
|
-
import { classifyOperation, collectImplementedNames, normalizeForMatching, } from './specCoverage.js';
|
|
11
|
-
import { refreshCachedSpec } from './specDownload.js';
|
|
12
|
-
import { replaceDanglingSchemaRefs } from './specRefs.js';
|
|
13
|
-
import { specFileName, specSources } from './specSources.js';
|
|
14
|
-
import { generatedNamespaceNames, renameGeneratedNamespaces } from './specTypeNames.js';
|
|
15
|
-
const __filename = fileURLToPath(import.meta.url);
|
|
16
|
-
const __dirname = dirname(__filename);
|
|
17
|
-
const PROJECT_ROOT = join(__dirname, '../..');
|
|
18
|
-
/** Local, git-ignored cache of downloaded eBay OpenAPI specs. */
|
|
19
|
-
const SPECS_DIR = join(PROJECT_ROOT, '.cache/ebay-specs');
|
|
20
|
-
const TYPES_DIR = join(PROJECT_ROOT, 'src/types');
|
|
21
|
-
const TOOLS_DIRS = [join(PROJECT_ROOT, 'src/tools/categories')];
|
|
22
|
-
const ui = {
|
|
23
|
-
success: chalk.green,
|
|
24
|
-
warning: chalk.yellow,
|
|
25
|
-
error: chalk.red,
|
|
26
|
-
info: chalk.cyan,
|
|
27
|
-
dim: chalk.dim,
|
|
28
|
-
bold: chalk.bold,
|
|
29
|
-
};
|
|
30
|
-
const applyNamespaceNames = (outputPath, camelCaseName) => {
|
|
31
|
-
const names = generatedNamespaceNames[camelCaseName];
|
|
32
|
-
if (!names) {
|
|
33
|
-
return;
|
|
34
|
-
}
|
|
35
|
-
const generatedTypes = readFileSync(outputPath, 'utf-8');
|
|
36
|
-
const renamedTypes = renameGeneratedNamespaces(generatedTypes, names);
|
|
37
|
-
writeFileSync(outputPath, renamedTypes);
|
|
38
|
-
};
|
|
39
|
-
function showSpinner(message) {
|
|
40
|
-
const frames = ['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏'];
|
|
41
|
-
let i = 0;
|
|
42
|
-
process.stdout.write(` ${ui.info(frames[0])} ${message}`);
|
|
43
|
-
const interval = setInterval(() => {
|
|
44
|
-
i = (i + 1) % frames.length;
|
|
45
|
-
process.stdout.write(`\r ${ui.info(frames[i])} ${message}`);
|
|
46
|
-
}, 80);
|
|
47
|
-
return () => {
|
|
48
|
-
clearInterval(interval);
|
|
49
|
-
process.stdout.write('\r' + ' '.repeat(message.length + 10) + '\r');
|
|
50
|
-
};
|
|
51
|
-
}
|
|
52
|
-
async function downloadSpecs() {
|
|
53
|
-
console.log(ui.bold('\n📥 Downloading OpenAPI Specifications\n'));
|
|
54
|
-
console.log(ui.dim(` Found ${specSources.length} spec URLs\n`));
|
|
55
|
-
let downloaded = 0;
|
|
56
|
-
const unavailable = [];
|
|
57
|
-
for (const source of specSources) {
|
|
58
|
-
const { api, folder, url } = source;
|
|
59
|
-
const fileName = specFileName(source);
|
|
60
|
-
const specPath = join(SPECS_DIR, folder, fileName);
|
|
61
|
-
const stopSpinner = showSpinner(`Downloading ${api} (${fileName})...`);
|
|
62
|
-
const refresh = refreshCachedSpec(url, specPath).pipe(Effect.either);
|
|
63
|
-
const refreshOutcome = await Effect.runPromise(refresh);
|
|
64
|
-
stopSpinner();
|
|
65
|
-
if (Either.isRight(refreshOutcome)) {
|
|
66
|
-
console.log(` ${ui.success('✓')} ${api} (${fileName})`);
|
|
67
|
-
downloaded++;
|
|
68
|
-
continue;
|
|
69
|
-
}
|
|
70
|
-
const reason = refreshOutcome.left.message;
|
|
71
|
-
const cacheNote = existsSync(specPath) ? 'kept the cached copy' : 'no cached copy';
|
|
72
|
-
console.log(` ${ui.error('✗')} ${api} (${fileName}): unavailable, ${reason}; ${cacheNote}`);
|
|
73
|
-
unavailable.push({ api, fileName, url, reason });
|
|
74
|
-
}
|
|
75
|
-
if (unavailable.length > 0 && downloaded === 0) {
|
|
76
|
-
console.log(ui.error(`\n ✗ All ${unavailable.length} spec downloads failed — eBay is likely blocking automated requests (HTTP 403).`));
|
|
77
|
-
}
|
|
78
|
-
return { downloaded, unavailable };
|
|
79
|
-
}
|
|
80
|
-
function generateTypes() {
|
|
81
|
-
console.log(ui.bold('\n🔧 Generating TypeScript Types\n'));
|
|
82
|
-
const generatedPaths = [];
|
|
83
|
-
let skipped = 0;
|
|
84
|
-
function processDirectory(dir) {
|
|
85
|
-
if (!existsSync(dir))
|
|
86
|
-
return;
|
|
87
|
-
const entries = readdirSync(dir, { withFileTypes: true });
|
|
88
|
-
for (const entry of entries) {
|
|
89
|
-
const fullPath = join(dir, entry.name);
|
|
90
|
-
if (entry.isDirectory()) {
|
|
91
|
-
processDirectory(fullPath);
|
|
92
|
-
}
|
|
93
|
-
else if (entry.name.endsWith('.json')) {
|
|
94
|
-
const fileContent = Effect.runSync(Effect.either(Effect.try({
|
|
95
|
-
try: () => readFileSync(fullPath, 'utf-8'),
|
|
96
|
-
catch: (error) => error,
|
|
97
|
-
})));
|
|
98
|
-
if (Either.isLeft(fileContent)) {
|
|
99
|
-
skipped++;
|
|
100
|
-
continue;
|
|
101
|
-
}
|
|
102
|
-
const content = fileContent.right;
|
|
103
|
-
if (!(content.includes('"openapi"') || content.includes('"swagger"'))) {
|
|
104
|
-
skipped++;
|
|
105
|
-
continue;
|
|
106
|
-
}
|
|
107
|
-
const relativePath = fullPath.replace(SPECS_DIR + '/', '');
|
|
108
|
-
const outputDir = join(TYPES_DIR, dirname(relativePath));
|
|
109
|
-
mkdirSync(outputDir, { recursive: true });
|
|
110
|
-
const baseFileName = basename(entry.name, '.json');
|
|
111
|
-
const camelCaseName = baseFileName
|
|
112
|
-
.split(/[_.-]/)
|
|
113
|
-
.map((part, i) => i === 0
|
|
114
|
-
? part.toLowerCase()
|
|
115
|
-
: part.charAt(0).toUpperCase() + part.slice(1).toLowerCase())
|
|
116
|
-
.join('');
|
|
117
|
-
const outputPath = join(outputDir, `${camelCaseName}.ts`);
|
|
118
|
-
const generatedFile = Effect.runSync(Effect.either(Effect.try({
|
|
119
|
-
try: () => {
|
|
120
|
-
const { spec, danglingRefs } = replaceDanglingSchemaRefs(JSON.parse(content));
|
|
121
|
-
if (danglingRefs.length === 0) {
|
|
122
|
-
execSync(`npx openapi-typescript "${fullPath}" -o "${outputPath}" --silent`, {
|
|
123
|
-
stdio: 'pipe',
|
|
124
|
-
cwd: PROJECT_ROOT,
|
|
125
|
-
});
|
|
126
|
-
return;
|
|
127
|
-
}
|
|
128
|
-
// openapi-typescript aborts on the first unresolved $ref, so feed it the
|
|
129
|
-
// rewritten spec on stdin instead of the upstream file.
|
|
130
|
-
console.log(` ${ui.warning('⚠')} ${camelCaseName}: undefined upstream schemas typed as unknown: ${danglingRefs.join(', ')}`);
|
|
131
|
-
execSync(`npx openapi-typescript -o "${outputPath}" --silent`, {
|
|
132
|
-
input: JSON.stringify(spec),
|
|
133
|
-
stdio: 'pipe',
|
|
134
|
-
cwd: PROJECT_ROOT,
|
|
135
|
-
});
|
|
136
|
-
},
|
|
137
|
-
catch: (error) => error,
|
|
138
|
-
})));
|
|
139
|
-
if (Either.isRight(generatedFile)) {
|
|
140
|
-
applyNamespaceNames(outputPath, camelCaseName);
|
|
141
|
-
console.log(` ${ui.success('✓')} ${camelCaseName}.ts`);
|
|
142
|
-
generatedPaths.push(outputPath);
|
|
143
|
-
}
|
|
144
|
-
else {
|
|
145
|
-
console.log(` ${ui.error('✗')} ${camelCaseName}.ts (generation failed): ${getErrorMessage(generatedFile.left)}`);
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
processDirectory(SPECS_DIR);
|
|
151
|
-
// Format with the repo's Biome settings so regenerating unchanged specs leaves no diff.
|
|
152
|
-
if (generatedPaths.length > 0) {
|
|
153
|
-
execFileSync('npx', ['biome', 'format', '--write', ...generatedPaths], {
|
|
154
|
-
stdio: 'pipe',
|
|
155
|
-
cwd: PROJECT_ROOT,
|
|
156
|
-
});
|
|
157
|
-
}
|
|
158
|
-
console.log(ui.dim(`\n Generated: ${generatedPaths.length}, Skipped: ${skipped}`));
|
|
159
|
-
return generatedPaths.length;
|
|
160
|
-
}
|
|
161
|
-
function extractEndpointsFromSpecs() {
|
|
162
|
-
const endpoints = [];
|
|
163
|
-
function processDirectory(dir) {
|
|
164
|
-
if (!existsSync(dir))
|
|
165
|
-
return;
|
|
166
|
-
const entries = readdirSync(dir, { withFileTypes: true });
|
|
167
|
-
for (const entry of entries) {
|
|
168
|
-
const fullPath = join(dir, entry.name);
|
|
169
|
-
if (entry.isDirectory()) {
|
|
170
|
-
processDirectory(fullPath);
|
|
171
|
-
}
|
|
172
|
-
else if (entry.name.endsWith('.json')) {
|
|
173
|
-
const parsedSpec = Effect.runSync(Effect.either(Effect.try({
|
|
174
|
-
try: () => JSON.parse(readFileSync(fullPath, 'utf-8')),
|
|
175
|
-
catch: (error) => error,
|
|
176
|
-
})));
|
|
177
|
-
if (Either.isLeft(parsedSpec)) {
|
|
178
|
-
continue;
|
|
179
|
-
}
|
|
180
|
-
const spec = parsedSpec.right;
|
|
181
|
-
if (!spec.paths)
|
|
182
|
-
continue;
|
|
183
|
-
for (const [path, methods] of Object.entries(spec.paths)) {
|
|
184
|
-
for (const [method, details] of Object.entries(methods)) {
|
|
185
|
-
if (['get', 'post', 'put', 'delete', 'patch'].includes(method.toLowerCase())) {
|
|
186
|
-
endpoints.push({
|
|
187
|
-
path,
|
|
188
|
-
method: method.toUpperCase(),
|
|
189
|
-
operationId: details.operationId || `${method}_${path}`,
|
|
190
|
-
summary: details.summary || '',
|
|
191
|
-
});
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
}
|
|
198
|
-
processDirectory(SPECS_DIR);
|
|
199
|
-
return endpoints;
|
|
200
|
-
}
|
|
201
|
-
function collectToolNames(dir, tools) {
|
|
202
|
-
if (!existsSync(dir))
|
|
203
|
-
return;
|
|
204
|
-
for (const entry of readdirSync(dir, { withFileTypes: true })) {
|
|
205
|
-
const fullPath = join(dir, entry.name);
|
|
206
|
-
if (entry.isDirectory()) {
|
|
207
|
-
collectToolNames(fullPath, tools);
|
|
208
|
-
}
|
|
209
|
-
else if (entry.isFile() && entry.name.endsWith('.ts')) {
|
|
210
|
-
const content = readFileSync(fullPath, 'utf-8');
|
|
211
|
-
const nameMatches = content.matchAll(/name:\s*['"`]([^'"`]+)['"`]/g);
|
|
212
|
-
for (const match of nameMatches) {
|
|
213
|
-
tools.add(match[1]);
|
|
214
|
-
}
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
}
|
|
218
|
-
function getImplementedTools() {
|
|
219
|
-
const tools = new Set();
|
|
220
|
-
for (const dir of TOOLS_DIRS) {
|
|
221
|
-
collectToolNames(dir, tools);
|
|
222
|
-
}
|
|
223
|
-
return tools;
|
|
224
|
-
}
|
|
225
|
-
/**
|
|
226
|
-
* Get all implemented API methods from source files
|
|
227
|
-
*/
|
|
228
|
-
function getImplementedApiMethods() {
|
|
229
|
-
const methods = new Set();
|
|
230
|
-
const apiDir = join(PROJECT_ROOT, 'src/api');
|
|
231
|
-
function processDirectory(dir) {
|
|
232
|
-
if (!existsSync(dir))
|
|
233
|
-
return;
|
|
234
|
-
const entries = readdirSync(dir, { withFileTypes: true });
|
|
235
|
-
for (const entry of entries) {
|
|
236
|
-
const fullPath = join(dir, entry.name);
|
|
237
|
-
if (entry.isDirectory()) {
|
|
238
|
-
processDirectory(fullPath);
|
|
239
|
-
}
|
|
240
|
-
else if (entry.name.endsWith('.ts')) {
|
|
241
|
-
const source = Effect.runSync(Effect.either(Effect.try({
|
|
242
|
-
try: () => readFileSync(fullPath, 'utf-8'),
|
|
243
|
-
catch: (error) => error,
|
|
244
|
-
})));
|
|
245
|
-
if (Either.isRight(source)) {
|
|
246
|
-
// Match async methods and class-field arrow endpoints (`name = (` / `public name = (`).
|
|
247
|
-
// Many area classes omit the `public` keyword (notification, trading, feedback, …).
|
|
248
|
-
const methodMatches = source.right.matchAll(/(?:async\s+(\w+)\s*\(|(?:public\s+)?(\w+)\s*=\s*(?:async\s*)?\()/g);
|
|
249
|
-
for (const match of methodMatches) {
|
|
250
|
-
const name = match[1] || match[2];
|
|
251
|
-
// Skip common non-method bindings that the broader regex can catch.
|
|
252
|
-
if (!name || name === 'const' || name === 'let' || name === 'var')
|
|
253
|
-
continue;
|
|
254
|
-
methods.add(name);
|
|
255
|
-
}
|
|
256
|
-
}
|
|
257
|
-
}
|
|
258
|
-
}
|
|
259
|
-
}
|
|
260
|
-
processDirectory(apiDir);
|
|
261
|
-
return methods;
|
|
262
|
-
}
|
|
263
|
-
function analyzeEndpoints() {
|
|
264
|
-
console.log(ui.bold('\n📊 Analyzing API Coverage\n'));
|
|
265
|
-
const specEndpoints = extractEndpointsFromSpecs();
|
|
266
|
-
const implementedTools = getImplementedTools();
|
|
267
|
-
const implementedApiMethods = getImplementedApiMethods();
|
|
268
|
-
const implemented = collectImplementedNames([...implementedApiMethods], [...implementedTools]);
|
|
269
|
-
// Track unique endpoints (dedupe by operationId)
|
|
270
|
-
const seenOperationIds = new Set();
|
|
271
|
-
const uniqueEndpoints = [];
|
|
272
|
-
for (const endpoint of specEndpoints) {
|
|
273
|
-
const normalizedOpId = normalizeForMatching(endpoint.operationId);
|
|
274
|
-
if (!seenOperationIds.has(normalizedOpId)) {
|
|
275
|
-
seenOperationIds.add(normalizedOpId);
|
|
276
|
-
uniqueEndpoints.push(endpoint);
|
|
277
|
-
}
|
|
278
|
-
}
|
|
279
|
-
const fuzzy = [];
|
|
280
|
-
const missing = [];
|
|
281
|
-
let exact = 0;
|
|
282
|
-
for (const endpoint of uniqueEndpoints) {
|
|
283
|
-
const coverage = classifyOperation(endpoint.operationId, implemented);
|
|
284
|
-
if (coverage === 'exact') {
|
|
285
|
-
exact++;
|
|
286
|
-
}
|
|
287
|
-
else if (coverage === 'fuzzy') {
|
|
288
|
-
fuzzy.push(endpoint);
|
|
289
|
-
}
|
|
290
|
-
else {
|
|
291
|
-
missing.push(endpoint);
|
|
292
|
-
}
|
|
293
|
-
}
|
|
294
|
-
const matchedCount = exact + fuzzy.length;
|
|
295
|
-
const coveragePercent = uniqueEndpoints.length > 0 ? ((matchedCount / uniqueEndpoints.length) * 100).toFixed(1) : '0';
|
|
296
|
-
console.log(` ${ui.info('Total unique endpoints in specs:')} ${uniqueEndpoints.length}`);
|
|
297
|
-
console.log(` ${ui.info('(Raw count with duplicates:')} ${specEndpoints.length}${ui.info(')')}`);
|
|
298
|
-
console.log(` ${ui.success('Tools implemented:')} ${implementedTools.size}`);
|
|
299
|
-
console.log(` ${ui.success('API methods found:')} ${implementedApiMethods.size}`);
|
|
300
|
-
console.log(` ${ui.success('Endpoints covered:')} ${matchedCount} (${coveragePercent}%)`);
|
|
301
|
-
console.log(` ${ui.success('Exact operationId matches:')} ${exact}`);
|
|
302
|
-
console.log(` ${ui.warning('Fuzzy-only matches:')} ${fuzzy.length}`);
|
|
303
|
-
console.log(` ${ui.warning('Potentially missing:')} ${missing.length}`);
|
|
304
|
-
return { total: uniqueEndpoints.length, exact, fuzzy, missing };
|
|
305
|
-
}
|
|
306
|
-
function showFuzzyMatches(fuzzy) {
|
|
307
|
-
if (fuzzy.length === 0) {
|
|
308
|
-
return;
|
|
309
|
-
}
|
|
310
|
-
console.log(ui.bold('\nFuzzy-only Matches\n'));
|
|
311
|
-
console.log(ui.dim(' No API method carries these operationIds exactly; a looser name matched:\n'));
|
|
312
|
-
for (const ep of fuzzy) {
|
|
313
|
-
console.log(` ${ui.dim(ep.method.padEnd(6))} ${ep.path} ${ui.dim(`(${ep.operationId})`)}`);
|
|
314
|
-
}
|
|
315
|
-
}
|
|
316
|
-
function showMissingEndpoints(missing) {
|
|
317
|
-
if (missing.length === 0) {
|
|
318
|
-
console.log(ui.success('\n ✓ All endpoints appear to be implemented!\n'));
|
|
319
|
-
return;
|
|
320
|
-
}
|
|
321
|
-
console.log(ui.bold('\n📋 Potentially Missing Endpoints\n'));
|
|
322
|
-
console.log(ui.dim(' These endpoints were found in specs but may not have corresponding tools:\n'));
|
|
323
|
-
const grouped = missing.reduce((acc, ep) => {
|
|
324
|
-
const key = ep.path.split('/')[1] || 'other';
|
|
325
|
-
if (!acc[key])
|
|
326
|
-
acc[key] = [];
|
|
327
|
-
acc[key].push(ep);
|
|
328
|
-
return acc;
|
|
329
|
-
}, {});
|
|
330
|
-
for (const [group, endpoints] of Object.entries(grouped).slice(0, 10)) {
|
|
331
|
-
console.log(` ${ui.bold(group)}`);
|
|
332
|
-
for (const ep of endpoints.slice(0, 5)) {
|
|
333
|
-
console.log(` ${ui.dim(ep.method.padEnd(6))} ${ep.path}`);
|
|
334
|
-
if (ep.summary) {
|
|
335
|
-
console.log(` ${ui.dim(ep.summary.slice(0, 50))}`);
|
|
336
|
-
}
|
|
337
|
-
}
|
|
338
|
-
if (endpoints.length > 5) {
|
|
339
|
-
console.log(` ${ui.dim(`... and ${endpoints.length - 5} more`)}`);
|
|
340
|
-
}
|
|
341
|
-
console.log('');
|
|
342
|
-
}
|
|
343
|
-
if (Object.keys(grouped).length > 10) {
|
|
344
|
-
console.log(ui.dim(` ... and ${Object.keys(grouped).length - 10} more API groups\n`));
|
|
345
|
-
}
|
|
346
|
-
}
|
|
347
|
-
function generateReport(report) {
|
|
348
|
-
const reportPath = join(PROJECT_ROOT, 'devSyncReport.json');
|
|
349
|
-
writeFileSync(reportPath, JSON.stringify(report, null, 2));
|
|
350
|
-
console.log(ui.dim(`\n Report saved to: ${reportPath}\n`));
|
|
351
|
-
}
|
|
352
|
-
async function main() {
|
|
353
|
-
console.clear();
|
|
354
|
-
console.log(ui.bold.cyan(`
|
|
355
|
-
╔════════════════════════════════════════════════════════════╗
|
|
356
|
-
║ eBay MCP Server - Developer Sync Tool ║
|
|
357
|
-
╚════════════════════════════════════════════════════════════╝
|
|
358
|
-
`));
|
|
359
|
-
const args = process.argv.slice(2);
|
|
360
|
-
const skipDownload = args.includes('--skip-download');
|
|
361
|
-
const skipTypes = args.includes('--skip-types');
|
|
362
|
-
const reportOnly = args.includes('--report');
|
|
363
|
-
if (args.includes('--help') || args.includes('-h')) {
|
|
364
|
-
console.log(`
|
|
365
|
-
${ui.bold('Usage:')}
|
|
366
|
-
npm run sync [options]
|
|
367
|
-
|
|
368
|
-
${ui.bold('Options:')}
|
|
369
|
-
--skip-download Skip downloading OpenAPI specs
|
|
370
|
-
--skip-types Skip generating TypeScript types
|
|
371
|
-
--report Only generate coverage report
|
|
372
|
-
--help, -h Show this help
|
|
373
|
-
|
|
374
|
-
${ui.bold('What this does:')}
|
|
375
|
-
1. Downloads latest OpenAPI specs from eBay
|
|
376
|
-
2. Generates TypeScript types from specs
|
|
377
|
-
3. Analyzes which endpoints are implemented
|
|
378
|
-
4. Reports missing endpoints to implement
|
|
379
|
-
`);
|
|
380
|
-
process.exit(0);
|
|
381
|
-
}
|
|
382
|
-
const report = {
|
|
383
|
-
specsDownloaded: 0,
|
|
384
|
-
unavailableSpecs: [],
|
|
385
|
-
typesGenerated: 0,
|
|
386
|
-
endpointsInSpecs: 0,
|
|
387
|
-
toolsImplemented: 0,
|
|
388
|
-
exactMatches: 0,
|
|
389
|
-
fuzzyMatchedEndpoints: [],
|
|
390
|
-
missingEndpoints: [],
|
|
391
|
-
};
|
|
392
|
-
if (!(reportOnly || skipDownload)) {
|
|
393
|
-
const downloads = await downloadSpecs();
|
|
394
|
-
report.specsDownloaded = downloads.downloaded;
|
|
395
|
-
report.unavailableSpecs = downloads.unavailable;
|
|
396
|
-
}
|
|
397
|
-
// If the download step ran but fetched nothing (for example, blocked
|
|
398
|
-
// requests), the coverage numbers below describe the cached specs on disk —
|
|
399
|
-
// not eBay's current API. Flag it loudly so a stale run is never mistaken for
|
|
400
|
-
// a clean "100% coverage, 0 missing" result.
|
|
401
|
-
const usingStaleSpecs = !(reportOnly || skipDownload) && report.specsDownloaded === 0;
|
|
402
|
-
// Don't regenerate types when nothing was downloaded: the inputs on disk are
|
|
403
|
-
// unchanged, so a regen only risks churn (and can break the build if the
|
|
404
|
-
// generator's interface naming drifts from what the code imports). Use
|
|
405
|
-
// --skip-download to deliberately regenerate from on-disk specs.
|
|
406
|
-
if (!(reportOnly || skipTypes || usingStaleSpecs)) {
|
|
407
|
-
report.typesGenerated = generateTypes();
|
|
408
|
-
}
|
|
409
|
-
const analysis = analyzeEndpoints();
|
|
410
|
-
report.endpointsInSpecs = analysis.total;
|
|
411
|
-
report.toolsImplemented = analysis.exact + analysis.fuzzy.length;
|
|
412
|
-
report.exactMatches = analysis.exact;
|
|
413
|
-
report.fuzzyMatchedEndpoints = analysis.fuzzy;
|
|
414
|
-
report.missingEndpoints = analysis.missing;
|
|
415
|
-
showFuzzyMatches(analysis.fuzzy);
|
|
416
|
-
showMissingEndpoints(analysis.missing);
|
|
417
|
-
generateReport(report);
|
|
418
|
-
if (usingStaleSpecs) {
|
|
419
|
-
console.log(ui.warning('\n ⚠ No specs were downloaded — coverage above reflects the cached specs on disk, not eBay live.'));
|
|
420
|
-
console.log(ui.dim(' Refresh the specs (the eBay docs URLs return 403 to scripts) before trusting these numbers.'));
|
|
421
|
-
}
|
|
422
|
-
console.log(ui.bold.green('\n✓ Sync complete!\n'));
|
|
423
|
-
}
|
|
424
|
-
void Effect.runPromise(Effect.either(Effect.tryPromise({
|
|
425
|
-
try: () => main(),
|
|
426
|
-
catch: (error) => error,
|
|
427
|
-
}))).then((syncOutcome) => {
|
|
428
|
-
if (Either.isLeft(syncOutcome)) {
|
|
429
|
-
console.error(ui.error('\n Sync failed:'), getErrorMessage(syncOutcome.left));
|
|
430
|
-
process.exitCode = 1;
|
|
431
|
-
}
|
|
432
|
-
});
|
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
const KNOWN_OPERATION_MAPPINGS = {
|
|
2
|
-
// Notification API — tools use the ebay_*_notification_* naming convention
|
|
3
|
-
getconfig: ['ebay_get_notification_config'],
|
|
4
|
-
updateconfig: ['ebay_update_notification_config'],
|
|
5
|
-
getdestinations: ['ebay_get_notification_destinations'],
|
|
6
|
-
createdestination: ['ebay_create_notification_destination'],
|
|
7
|
-
getdestination: ['ebay_get_notification_destination'],
|
|
8
|
-
updatedestination: ['ebay_update_notification_destination'],
|
|
9
|
-
deletedestination: ['ebay_delete_notification_destination'],
|
|
10
|
-
getsubscriptions: ['ebay_get_notification_subscriptions'],
|
|
11
|
-
createsubscription: ['ebay_create_notification_subscription'],
|
|
12
|
-
getsubscription: ['ebay_get_notification_subscription'],
|
|
13
|
-
updatesubscription: ['ebay_update_notification_subscription'],
|
|
14
|
-
deletesubscription: ['ebay_delete_notification_subscription'],
|
|
15
|
-
disablesubscription: ['ebay_disable_notification_subscription'],
|
|
16
|
-
enablesubscription: ['ebay_enable_notification_subscription'],
|
|
17
|
-
testsubscription: ['ebay_test_notification_subscription'],
|
|
18
|
-
createsubscriptionfilter: ['ebay_create_notification_subscription_filter'],
|
|
19
|
-
getsubscriptionfilter: ['ebay_get_notification_subscription_filter'],
|
|
20
|
-
deletesubscriptionfilter: ['ebay_delete_notification_subscription_filter'],
|
|
21
|
-
gettopic: ['ebay_get_notification_topic'],
|
|
22
|
-
gettopics: ['ebay_get_notification_topics'],
|
|
23
|
-
getpublickey: ['ebay_get_notification_public_key'],
|
|
24
|
-
// Negotiation API
|
|
25
|
-
findeligibleitems: ['ebay_find_eligible_items'],
|
|
26
|
-
// Marketing API
|
|
27
|
-
createadbylistingid: ['ebay_create_ad_by_listing_id'],
|
|
28
|
-
updatebid: ['ebay_update_bid'],
|
|
29
|
-
bulkcreatekeyword: ['ebay_bulk_create_keyword'],
|
|
30
|
-
bulkupdatekeyword: ['ebay_bulk_update_keyword'],
|
|
31
|
-
bulkcreatenegativekeyword: ['ebay_bulk_create_negative_keyword'],
|
|
32
|
-
bulkupdatenegativekeyword: ['ebay_bulk_update_negative_keyword'],
|
|
33
|
-
getnegativekeywords: ['ebay_get_negative_keywords'],
|
|
34
|
-
createnegativekeyword: ['ebay_create_negative_keyword'],
|
|
35
|
-
getnegativekeyword: ['ebay_get_negative_keyword'],
|
|
36
|
-
updatenegativekeyword: ['ebay_update_negative_keyword'],
|
|
37
|
-
getreportmetadata: ['ebay_get_report_metadata'],
|
|
38
|
-
getreportmetadataforreporttype: ['ebay_get_report_metadata_for_report_type'],
|
|
39
|
-
getpromotionreports: ['ebay_get_promotion_reports'],
|
|
40
|
-
getaudiences: ['ebay_get_audiences'],
|
|
41
|
-
// Dispute/Fulfillment API
|
|
42
|
-
fetchevidencecontent: ['ebay_fetch_evidence_content'],
|
|
43
|
-
getactivities: ['ebay_get_payment_dispute_activities', 'ebay_get_activities'],
|
|
44
|
-
uploadevidencefile: ['ebay_upload_evidence_file'],
|
|
45
|
-
addevidence: ['ebay_add_evidence'],
|
|
46
|
-
updateevidence: ['ebay_update_evidence'],
|
|
47
|
-
};
|
|
48
|
-
const ITEMS_SUFFIX = /items?$/;
|
|
49
|
-
const BY_SUFFIX = /by\w+$/;
|
|
50
|
-
const FOR_SUFFIX = /for\w+$/;
|
|
51
|
-
const singularOrPlural = (name) => name.endsWith('s') && !name.endsWith('ss') ? name.slice(0, -1) : `${name}s`;
|
|
52
|
-
const fuzzyNameVariations = (operationId) => {
|
|
53
|
-
const normalized = normalizeForMatching(operationId);
|
|
54
|
-
const stems = [
|
|
55
|
-
normalized,
|
|
56
|
-
normalized.replace(ITEMS_SUFFIX, ''),
|
|
57
|
-
normalized.replace(BY_SUFFIX, ''),
|
|
58
|
-
normalized.replace(FOR_SUFFIX, ''),
|
|
59
|
-
singularOrPlural(normalized),
|
|
60
|
-
];
|
|
61
|
-
const prefixedStems = stems.map((stem) => `ebay${stem}`);
|
|
62
|
-
const mappedTools = KNOWN_OPERATION_MAPPINGS[normalized] || [];
|
|
63
|
-
const mappedNames = mappedTools.map(normalizeForMatching);
|
|
64
|
-
return new Set([...stems, ...prefixedStems, ...mappedNames]);
|
|
65
|
-
};
|
|
66
|
-
export const normalizeForMatching = (name) => name.toLowerCase().replace(/[^a-z0-9]/g, '');
|
|
67
|
-
export const collectImplementedNames = (apiMethods, toolNames) => {
|
|
68
|
-
const normalizedNames = [...apiMethods, ...toolNames].map(normalizeForMatching);
|
|
69
|
-
return { apiMethods: new Set(apiMethods), normalizedNames: new Set(normalizedNames) };
|
|
70
|
-
};
|
|
71
|
-
export const classifyOperation = (operationId, implemented) => {
|
|
72
|
-
if (implemented.apiMethods.has(operationId)) {
|
|
73
|
-
return 'exact';
|
|
74
|
-
}
|
|
75
|
-
const variations = fuzzyNameVariations(operationId);
|
|
76
|
-
const hasFuzzyMatch = [...variations].some((name) => implemented.normalizedNames.has(name));
|
|
77
|
-
return hasFuzzyMatch ? 'fuzzy' : 'missing';
|
|
78
|
-
};
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import { mkdirSync, renameSync, rmSync, writeFileSync } from 'node:fs';
|
|
2
|
-
import { dirname } from 'node:path';
|
|
3
|
-
import { Data, Effect } from 'effect';
|
|
4
|
-
import { getErrorMessage } from '../utils/errors.js';
|
|
5
|
-
import { httpRequestEffect } from '../utils/http.js';
|
|
6
|
-
const isVersionText = (version) => typeof version === 'string' && version.trim() !== '';
|
|
7
|
-
const hasSpecVersion = (spec) => spec !== null &&
|
|
8
|
-
typeof spec === 'object' &&
|
|
9
|
-
(('openapi' in spec && isVersionText(spec.openapi)) ||
|
|
10
|
-
('swagger' in spec && isVersionText(spec.swagger)));
|
|
11
|
-
export class UnusableSpecError extends Data.TaggedError('UnusableSpecError') {
|
|
12
|
-
}
|
|
13
|
-
export class SpecCacheWriteError extends Data.TaggedError('SpecCacheWriteError') {
|
|
14
|
-
}
|
|
15
|
-
export const checkSpecDownload = (specBytes) => {
|
|
16
|
-
const specText = specBytes.toString('utf-8');
|
|
17
|
-
if (specText.trim() === '') {
|
|
18
|
-
return Effect.fail(new UnusableSpecError({ message: 'empty response' }));
|
|
19
|
-
}
|
|
20
|
-
return Effect.try({
|
|
21
|
-
try: () => JSON.parse(specText),
|
|
22
|
-
catch: () => new UnusableSpecError({ message: 'response is not JSON' }),
|
|
23
|
-
}).pipe(Effect.filterOrFail(hasSpecVersion, () => new UnusableSpecError({ message: 'JSON has no openapi or swagger version' })), Effect.as(specBytes));
|
|
24
|
-
};
|
|
25
|
-
export const refreshCachedSpec = (url, specPath) => httpRequestEffect({ url, responseType: 'arraybuffer', timeoutMs: 20_000 }).pipe(Effect.flatMap((specResponse) => checkSpecDownload(specResponse.data)), Effect.flatMap((specBytes) => {
|
|
26
|
-
// Write beside the cache, then rename, so a failed write never truncates the cached spec.
|
|
27
|
-
const downloadPath = `${specPath}.download`;
|
|
28
|
-
return Effect.try({
|
|
29
|
-
try: () => {
|
|
30
|
-
mkdirSync(dirname(specPath), { recursive: true });
|
|
31
|
-
writeFileSync(downloadPath, specBytes);
|
|
32
|
-
renameSync(downloadPath, specPath);
|
|
33
|
-
},
|
|
34
|
-
catch: (error) => {
|
|
35
|
-
rmSync(downloadPath, { force: true });
|
|
36
|
-
return new SpecCacheWriteError({
|
|
37
|
-
specPath,
|
|
38
|
-
message: getErrorMessage(error, 'write failed'),
|
|
39
|
-
});
|
|
40
|
-
},
|
|
41
|
-
});
|
|
42
|
-
}));
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
/** Prefix shared by every local component-schema reference in an OpenAPI document. */
|
|
2
|
-
const SCHEMA_REF_PREFIX = '#/components/schemas/';
|
|
3
|
-
const definedSchemaNames = (spec) => {
|
|
4
|
-
if (spec === null || typeof spec !== 'object' || !('components' in spec)) {
|
|
5
|
-
return new Set();
|
|
6
|
-
}
|
|
7
|
-
const { components } = spec;
|
|
8
|
-
if (components === null || typeof components !== 'object' || !('schemas' in components)) {
|
|
9
|
-
return new Set();
|
|
10
|
-
}
|
|
11
|
-
const { schemas } = components;
|
|
12
|
-
return new Set(schemas !== null && typeof schemas === 'object' ? Object.keys(schemas) : []);
|
|
13
|
-
};
|
|
14
|
-
/**
|
|
15
|
-
* Replaces references to component schemas the spec never defines with an open schema.
|
|
16
|
-
*
|
|
17
|
-
* eBay occasionally publishes a spec with a dangling `$ref`, and openapi-typescript
|
|
18
|
-
* aborts the whole file on the first unresolved reference. Rewriting only the dangling references
|
|
19
|
-
* keeps every defined type exact, while the undefined payload generates as `unknown`
|
|
20
|
-
* with a description naming the missing schema.
|
|
21
|
-
*
|
|
22
|
-
* @param spec - Parsed OpenAPI document; it is not mutated.
|
|
23
|
-
* @returns The rewritten document and the schema names that could not be resolved.
|
|
24
|
-
*
|
|
25
|
-
* @example
|
|
26
|
-
* ```ts
|
|
27
|
-
* const { spec, danglingRefs } = replaceDanglingSchemaRefs(JSON.parse(content));
|
|
28
|
-
* ```
|
|
29
|
-
*/
|
|
30
|
-
export const replaceDanglingSchemaRefs = (spec) => {
|
|
31
|
-
const defined = definedSchemaNames(spec);
|
|
32
|
-
const dangling = new Set();
|
|
33
|
-
const rewrite = (node) => {
|
|
34
|
-
if (Array.isArray(node)) {
|
|
35
|
-
return node.map(rewrite);
|
|
36
|
-
}
|
|
37
|
-
if (node === null || typeof node !== 'object') {
|
|
38
|
-
return node;
|
|
39
|
-
}
|
|
40
|
-
if ('$ref' in node &&
|
|
41
|
-
typeof node.$ref === 'string' &&
|
|
42
|
-
node.$ref.startsWith(SCHEMA_REF_PREFIX)) {
|
|
43
|
-
// `#/components/schemas/Foo/properties/id` lives under Foo: check only the first token.
|
|
44
|
-
const [name = ''] = node.$ref.slice(SCHEMA_REF_PREFIX.length).split('/');
|
|
45
|
-
if (!defined.has(name)) {
|
|
46
|
-
dangling.add(name);
|
|
47
|
-
return { description: `Undefined upstream schema ${name}` };
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
return Object.fromEntries(Object.entries(node).map(([key, child]) => [key, rewrite(child)]));
|
|
51
|
-
};
|
|
52
|
-
const rewritten = rewrite(spec);
|
|
53
|
-
return { spec: dangling.size > 0 ? rewritten : spec, danglingRefs: [...dangling] };
|
|
54
|
-
};
|