@mapbox/mcp-server 0.2.0-issue.11.0 → 0.2.0-issue.11.1
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/dist/index.js +1 -0
- package/dist/utils/requestUtils.d.ts.map +1 -1
- package/dist/utils/requestUtils.js +23 -10
- package/dist/utils/requestUtils.js.map +1 -1
- package/dist/utils/requestUtils.test.d.ts +2 -0
- package/dist/utils/requestUtils.test.d.ts.map +1 -0
- package/dist/utils/requestUtils.test.js +114 -0
- package/dist/utils/requestUtils.test.js.map +1 -0
- package/dist/version.json +4 -4
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"requestUtils.d.ts","sourceRoot":"","sources":["../../src/utils/requestUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"requestUtils.d.ts","sourceRoot":"","sources":["../../src/utils/requestUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAqBhD,wBAAgB,gBAAgB,CAAC,WAAW,EAAE,WAAW,GAAG;IAC1D,YAAY,EAAE,MAAM,CAAC;CACtB,CAgCA;AAED,wBAAgB,OAAO,SAKtB"}
|
|
@@ -1,20 +1,25 @@
|
|
|
1
1
|
let isPatched = false;
|
|
2
2
|
let originalFetch;
|
|
3
|
+
// Initialize originalFetch immediately at module load
|
|
4
|
+
if (typeof global !== 'undefined' && typeof global.fetch === 'function') {
|
|
5
|
+
originalFetch = global.fetch;
|
|
6
|
+
}
|
|
7
|
+
else if (typeof fetch === 'function') {
|
|
8
|
+
originalFetch = fetch;
|
|
9
|
+
}
|
|
10
|
+
else {
|
|
11
|
+
// In test environment or when fetch is not available, create a stub
|
|
12
|
+
// This will be replaced when global.fetch is properly mocked
|
|
13
|
+
originalFetch = (() => {
|
|
14
|
+
throw new Error('No fetch implementation available');
|
|
15
|
+
});
|
|
16
|
+
}
|
|
3
17
|
export function patchGlobalFetch(versionInfo) {
|
|
4
|
-
originalFetch = global.abc;
|
|
5
|
-
// Check if global.fetch exists, fallback to native fetch if available
|
|
6
|
-
// if (typeof global.fetch === 'function') {
|
|
7
|
-
// originalFetch = global.fetch;
|
|
8
|
-
// } else if (typeof fetch === 'function') {
|
|
9
|
-
// originalFetch = fetch;
|
|
10
|
-
// } else {
|
|
11
|
-
// throw new Error('No fetch implementation available');
|
|
12
|
-
// }
|
|
13
18
|
const headers = {
|
|
14
19
|
'User-Agent': `${versionInfo.name}/${versionInfo.version} (${versionInfo.branch}, ${versionInfo.tag}, ${versionInfo.sha})`
|
|
15
20
|
};
|
|
16
21
|
if (!isPatched) {
|
|
17
|
-
|
|
22
|
+
const patchedFetch = async function (input, init) {
|
|
18
23
|
const modifiedInit = {
|
|
19
24
|
...init,
|
|
20
25
|
headers: {
|
|
@@ -24,6 +29,14 @@ export function patchGlobalFetch(versionInfo) {
|
|
|
24
29
|
};
|
|
25
30
|
return originalFetch(input, modifiedInit);
|
|
26
31
|
};
|
|
32
|
+
// Patch fetch in the same way we detected it during initialization
|
|
33
|
+
if (typeof global !== 'undefined' && typeof global.fetch === 'function') {
|
|
34
|
+
global.fetch = patchedFetch;
|
|
35
|
+
}
|
|
36
|
+
else if (typeof globalThis !== 'undefined' &&
|
|
37
|
+
typeof globalThis.fetch === 'function') {
|
|
38
|
+
globalThis.fetch = patchedFetch;
|
|
39
|
+
}
|
|
27
40
|
isPatched = true;
|
|
28
41
|
}
|
|
29
42
|
return headers;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"requestUtils.js","sourceRoot":"","sources":["../../src/utils/requestUtils.ts"],"names":[],"mappings":"AAEA,IAAI,SAAS,GAAG,KAAK,CAAC;AACtB,IAAI,aAGkB,CAAC;AAEvB,MAAM,UAAU,
|
|
1
|
+
{"version":3,"file":"requestUtils.js","sourceRoot":"","sources":["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AAK,WAAW;YACjC,OAAO,UAAU,CAAC,KAAK,KAAK,UAAU,EACtC,CAAC;YACA,UAAkB,CAAC,KAAK,GAAG,YAAY,CAAC;QAC3C,CAAC;QACD,SAAS,GAAG,IAAI,CAAC;IACnB,CAAC;IAED,OAAO,OAAO,CAAC;AACjB,CAAC;AAED,MAAM,UAAU,OAAO;IACrB,IAAI,SAAS,EAAE,CAAC;QACd,MAAM,CAAC,KAAK,GAAG,aAAa,CAAC;QAC7B,SAAS,GAAG,KAAK,CAAC;IACpB,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"requestUtils.test.d.ts","sourceRoot":"","sources":["../../src/utils/requestUtils.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { patchGlobalFetch, cleanup } from './requestUtils.js';
|
|
2
|
+
describe('requestUtils', () => {
|
|
3
|
+
let originalGlobalFetch;
|
|
4
|
+
beforeEach(() => {
|
|
5
|
+
// Save original fetch
|
|
6
|
+
originalGlobalFetch = global.fetch;
|
|
7
|
+
});
|
|
8
|
+
afterEach(() => {
|
|
9
|
+
// Restore original fetch
|
|
10
|
+
global.fetch = originalGlobalFetch;
|
|
11
|
+
cleanup();
|
|
12
|
+
});
|
|
13
|
+
describe('patchGlobalFetch', () => {
|
|
14
|
+
it('should handle case when global.fetch is undefined at module load time', () => {
|
|
15
|
+
// Simulate scenario where global.fetch doesn't exist initially
|
|
16
|
+
delete global.fetch;
|
|
17
|
+
// This should not throw "originalFetch is not a function" error
|
|
18
|
+
expect(() => {
|
|
19
|
+
patchGlobalFetch({
|
|
20
|
+
name: 'TestServer',
|
|
21
|
+
version: '1.0.0',
|
|
22
|
+
sha: 'abcdef',
|
|
23
|
+
tag: 'no-tag',
|
|
24
|
+
branch: 'default'
|
|
25
|
+
});
|
|
26
|
+
}).not.toThrow();
|
|
27
|
+
});
|
|
28
|
+
it('should properly initialize originalFetch before patching', async () => {
|
|
29
|
+
// Mock fetch function
|
|
30
|
+
const mockFetch = jest.fn().mockResolvedValue({
|
|
31
|
+
ok: true,
|
|
32
|
+
status: 200,
|
|
33
|
+
json: async () => ({ success: true })
|
|
34
|
+
});
|
|
35
|
+
global.fetch = mockFetch;
|
|
36
|
+
// Patch global fetch
|
|
37
|
+
patchGlobalFetch({
|
|
38
|
+
name: 'TestServer',
|
|
39
|
+
version: '1.0.0',
|
|
40
|
+
sha: 'abcdef',
|
|
41
|
+
tag: 'no-tag',
|
|
42
|
+
branch: 'default'
|
|
43
|
+
});
|
|
44
|
+
// Make a fetch call
|
|
45
|
+
await global.fetch('https://example.com', {
|
|
46
|
+
headers: { 'Custom-Header': 'test' }
|
|
47
|
+
});
|
|
48
|
+
// Verify that the original fetch was called with User-Agent added
|
|
49
|
+
expect(mockFetch).toHaveBeenCalledWith('https://example.com', {
|
|
50
|
+
headers: {
|
|
51
|
+
'Custom-Header': 'test',
|
|
52
|
+
'User-Agent': 'TestServer/1.0.0 (default, no-tag, abcdef)'
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
});
|
|
56
|
+
it('should not throw originalFetch is not a function error', async () => {
|
|
57
|
+
// Mock a scenario where fetch might be called before proper initialization
|
|
58
|
+
const mockFetch = jest.fn().mockResolvedValue({
|
|
59
|
+
ok: true,
|
|
60
|
+
status: 200,
|
|
61
|
+
json: async () => ({ success: true })
|
|
62
|
+
});
|
|
63
|
+
global.fetch = mockFetch;
|
|
64
|
+
patchGlobalFetch({
|
|
65
|
+
name: 'TestServer',
|
|
66
|
+
version: '1.0.0',
|
|
67
|
+
sha: 'abcdef',
|
|
68
|
+
tag: 'no-tag',
|
|
69
|
+
branch: 'default'
|
|
70
|
+
});
|
|
71
|
+
// This should not throw "originalFetch is not a function"
|
|
72
|
+
await expect(global.fetch('https://example.com')).resolves.toBeDefined();
|
|
73
|
+
});
|
|
74
|
+
it('should handle multiple patch calls without breaking', () => {
|
|
75
|
+
const mockFetch = jest.fn();
|
|
76
|
+
global.fetch = mockFetch;
|
|
77
|
+
// First patch
|
|
78
|
+
patchGlobalFetch({
|
|
79
|
+
name: 'TestServer',
|
|
80
|
+
version: '1.0.0',
|
|
81
|
+
sha: 'abcdef',
|
|
82
|
+
tag: 'no-tag',
|
|
83
|
+
branch: 'default'
|
|
84
|
+
});
|
|
85
|
+
// Second patch (should not break)
|
|
86
|
+
patchGlobalFetch({
|
|
87
|
+
name: 'TestServer2',
|
|
88
|
+
version: '2.0.0',
|
|
89
|
+
sha: 'abcdef2',
|
|
90
|
+
tag: 'v2',
|
|
91
|
+
branch: 'main'
|
|
92
|
+
});
|
|
93
|
+
// Should still work
|
|
94
|
+
expect(typeof global.fetch).toBe('function');
|
|
95
|
+
});
|
|
96
|
+
it('should restore original fetch on cleanup', () => {
|
|
97
|
+
const mockFetch = jest.fn();
|
|
98
|
+
global.fetch = mockFetch;
|
|
99
|
+
patchGlobalFetch({
|
|
100
|
+
name: 'TestServer',
|
|
101
|
+
version: '1.0.0',
|
|
102
|
+
sha: 'abcdef',
|
|
103
|
+
tag: 'no-tag',
|
|
104
|
+
branch: 'default'
|
|
105
|
+
});
|
|
106
|
+
// Verify fetch was patched
|
|
107
|
+
expect(global.fetch).not.toBe(mockFetch);
|
|
108
|
+
// Cleanup should restore original
|
|
109
|
+
cleanup();
|
|
110
|
+
expect(global.fetch).toBe(mockFetch);
|
|
111
|
+
});
|
|
112
|
+
});
|
|
113
|
+
});
|
|
114
|
+
//# sourceMappingURL=requestUtils.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"requestUtils.test.js","sourceRoot":"","sources":["../../src/utils/requestUtils.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAE9D,QAAQ,CAAC,cAAc,EAAE,GAAG,EAAE;IAC5B,IAAI,mBAAwC,CAAC;IAE7C,UAAU,CAAC,GAAG,EAAE;QACd,sBAAsB;QACtB,mBA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ACf,IAAI,EAAE,aAAa;gBACnB,OAAO,EAAE,OAAO;gBAChB,GAAG,EAAE,SAAS;gBACd,GAAG,EAAE,IAAI;gBACT,MAAM,EAAE,MAAM;aACf,CAAC,CAAC;YAEH,oBAAoB;YACpB,MAAM,CAAC,OAAO,MAAM,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;QAC/C,CAAC,CAAC,CAAC;QAEH,EAAE,CAAC,0CAA0C,EAAE,GAAG,EAAE;YAClD,MAAM,SAAS,GAAG,IAAI,CAAC,EAAE,EAAE,CAAC;YAC5B,MAAM,CAAC,KAAK,GAAG,SAAS,CAAC;YAEzB,gBAAgB,CAAC;gBACf,IAAI,EAAE,YAAY;gBAClB,OAAO,EAAE,OAAO;gBAChB,GAAG,EAAE,QAAQ;gBACb,GAAG,EAAE,QAAQ;gBACb,MAAM,EAAE,SAAS;aAClB,CAAC,CAAC;YAEH,2BAA2B;YAC3B,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;YAEzC,kCAAkC;YAClC,OAAO,EAAE,CAAC;YACV,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;QACvC,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
package/dist/version.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
|
-
"sha": "
|
|
3
|
-
"tag": "v0.0.
|
|
4
|
-
"branch": "
|
|
5
|
-
"version": "0.2.0"
|
|
2
|
+
"sha": "ffa4e74a94b651fe95e02d6d430b9033b66aa4fc",
|
|
3
|
+
"tag": "v0.2.0-issue.11.0-2-gffa4e74",
|
|
4
|
+
"branch": "fix-fetch-issue-11",
|
|
5
|
+
"version": "0.2.0-issue.11.1"
|
|
6
6
|
}
|