Skip to content

Commit 21fe6ee

Browse files
chore(internal): codegen related update
1 parent d7c26d7 commit 21fe6ee

87 files changed

Lines changed: 5523 additions & 4258 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.prettierignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ CHANGELOG.md
22
/ecosystem-tests/*/**
33
/node_modules
44
/deno
5-
/packages/mcp-server/cloudflare-worker/worker-configuration.d.ts
65

76
# don't format tsc output, will break source maps
87
dist

eslint.config.mjs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// @ts-check
22
import tseslint from 'typescript-eslint';
33
import unusedImports from 'eslint-plugin-unused-imports';
4+
import prettier from 'eslint-plugin-prettier';
45

56
export default tseslint.config(
67
{
@@ -13,9 +14,11 @@ export default tseslint.config(
1314
plugins: {
1415
'@typescript-eslint': tseslint.plugin,
1516
'unused-imports': unusedImports,
17+
prettier,
1618
},
1719
rules: {
1820
'no-unused-vars': 'off',
21+
'prettier/prettier': 'error',
1922
'unused-imports/no-unused-imports': 'error',
2023
'no-restricted-imports': [
2124
'error',

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
"@typescript-eslint/eslint-plugin": "8.31.1",
3939
"@typescript-eslint/parser": "8.31.1",
4040
"eslint": "^9.39.1",
41+
"eslint-plugin-prettier": "^5.4.1",
4142
"eslint-plugin-unused-imports": "^4.1.4",
4243
"iconv-lite": "^0.6.3",
4344
"jest": "^29.4.0",

packages/mcp-server/cloudflare-worker/worker-configuration.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
1+
/* eslint-disable */
22
// Generated by Wrangler by running `wrangler types` (hash: fc286f4a60f8eb63b1e0d82ea1f34233)
33
// Runtime types generated with workerd@1.20260124.0 2025-03-10 nodejs_compat
44
declare namespace Cloudflare {
@@ -29,7 +29,7 @@ MERCHANTABLITY OR NON-INFRINGEMENT.
2929
See the Apache Version 2.0 License for specific language governing permissions
3030
and limitations under the License.
3131
***************************************************************************** */
32-
32+
/* eslint-disable */
3333
// noinspection JSUnusedGlobalSymbols
3434
declare var onmessage: never;
3535
/**

packages/mcp-server/jest.config.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@ const config: JestConfigWithTsJest = {
1010
'^@imagekit/api-mcp$': '<rootDir>/src/index.ts',
1111
'^@imagekit/api-mcp/(.*)$': '<rootDir>/src/$1',
1212
},
13-
modulePathIgnorePatterns: [
14-
'<rootDir>/dist/',
15-
],
13+
modulePathIgnorePatterns: ['<rootDir>/dist/'],
1614
testPathIgnorePatterns: ['scripts'],
1715
};
1816

packages/mcp-server/src/auth.ts

Lines changed: 35 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,50 @@
11
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
22

3-
import { IncomingMessage } from 'node:http'
4-
import { ClientOptions } from '@imagekit/nodejs'
3+
import { IncomingMessage } from 'node:http';
4+
import { ClientOptions } from '@imagekit/nodejs';
55
import { McpOptions } from './options';
66

7-
export const parseClientAuthHeaders = (req: IncomingMessage, required?: boolean): Partial<ClientOptions> => { if (req.headers.authorization) {
8-
const scheme = req.headers.authorization.split(" ")[0]!;
9-
const value = req.headers.authorization.slice(scheme.length + 1);
10-
switch (scheme) {
11-
case 'Basic':
12-
const rawValue = Buffer.from(value, 'base64').toString();
13-
return { privateKey: rawValue.slice(0, rawValue.search(':')), password: rawValue.slice(rawValue.search(':') + 1) }
14-
default:
15-
throw new Error('Unsupported authorization scheme. Expected the "Authorization" header to be a supported scheme (Basic).');
7+
export const parseClientAuthHeaders = (req: IncomingMessage, required?: boolean): Partial<ClientOptions> => {
8+
if (req.headers.authorization) {
9+
const scheme = req.headers.authorization.split(' ')[0]!;
10+
const value = req.headers.authorization.slice(scheme.length + 1);
11+
switch (scheme) {
12+
case 'Basic':
13+
const rawValue = Buffer.from(value, 'base64').toString();
14+
return {
15+
privateKey: rawValue.slice(0, rawValue.search(':')),
16+
password: rawValue.slice(rawValue.search(':') + 1),
17+
};
18+
default:
19+
throw new Error(
20+
'Unsupported authorization scheme. Expected the "Authorization" header to be a supported scheme (Basic).',
21+
);
22+
}
23+
} else if (required) {
24+
throw new Error('Missing required Authorization header; see WWW-Authenticate header for details.');
1625
}
17-
} else if (required) {
18-
throw new Error('Missing required Authorization header; see WWW-Authenticate header for details.');
19-
}
2026

21-
const privateKey = Array.isArray(req.headers['x-imagekit-private-key']) ? req.headers['x-imagekit-private-key'][0] : req.headers['x-imagekit-private-key']
22-
const password = Array.isArray(req.headers['x-optional-imagekit-ignores-this']) ? req.headers['x-optional-imagekit-ignores-this'][0] : req.headers['x-optional-imagekit-ignores-this']
23-
return {privateKey, password}; }
27+
const privateKey =
28+
Array.isArray(req.headers['x-imagekit-private-key']) ?
29+
req.headers['x-imagekit-private-key'][0]
30+
: req.headers['x-imagekit-private-key'];
31+
const password =
32+
Array.isArray(req.headers['x-optional-imagekit-ignores-this']) ?
33+
req.headers['x-optional-imagekit-ignores-this'][0]
34+
: req.headers['x-optional-imagekit-ignores-this'];
35+
return { privateKey, password };
36+
};
2437

2538
export const getStainlessApiKey = (req: IncomingMessage, mcpOptions: McpOptions): string | undefined => {
2639
// Try to get the key from the x-stainless-api-key header
27-
const headerKey = Array.isArray(req.headers['x-stainless-api-key']) ?
28-
req.headers['x-stainless-api-key'][0]
29-
: req.headers['x-stainless-api-key'];
40+
const headerKey =
41+
Array.isArray(req.headers['x-stainless-api-key']) ?
42+
req.headers['x-stainless-api-key'][0]
43+
: req.headers['x-stainless-api-key'];
3044
if (headerKey && typeof headerKey === 'string') {
3145
return headerKey;
3246
}
3347

3448
// Fall back to value set in the mcpOptions (e.g. from environment variable), if provided
3549
return mcpOptions.stainlessApiKey;
36-
}
50+
};

packages/mcp-server/src/code-tool-types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
22

3-
import { ClientOptions } from '@imagekit/nodejs'
3+
import { ClientOptions } from '@imagekit/nodejs';
44

55
export type WorkerInput = {
66
project_name: string;

packages/mcp-server/src/code-tool-worker.ts

Lines changed: 61 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ function getTSDiagnostics(code: string): string[] {
5959
const codeWithImport = [
6060
'import { ImageKit } from "@imagekit/nodejs";',
6161
functionSource.type === 'declaration' ?
62-
`async function run(${functionSource.client}: ImageKit)` :
63-
`const run: (${functionSource.client}: ImageKit) => Promise<unknown> =`,
62+
`async function run(${functionSource.client}: ImageKit)`
63+
: `const run: (${functionSource.client}: ImageKit) => Promise<unknown> =`,
6464
functionSource.code,
6565
].join('\n');
6666
const sourcePath = path.resolve('code.ts');
@@ -108,55 +108,55 @@ function getTSDiagnostics(code: string): string[] {
108108

109109
const fuse = new Fuse(
110110
[
111-
"client.customMetadataFields.create",
112-
"client.customMetadataFields.delete",
113-
"client.customMetadataFields.list",
114-
"client.customMetadataFields.update",
115-
"client.files.copy",
116-
"client.files.delete",
117-
"client.files.get",
118-
"client.files.move",
119-
"client.files.rename",
120-
"client.files.update",
121-
"client.files.upload",
122-
"client.files.bulk.addTags",
123-
"client.files.bulk.delete",
124-
"client.files.bulk.removeAITags",
125-
"client.files.bulk.removeTags",
126-
"client.files.versions.delete",
127-
"client.files.versions.get",
128-
"client.files.versions.list",
129-
"client.files.versions.restore",
130-
"client.files.metadata.get",
131-
"client.files.metadata.getFromURL",
132-
"client.savedExtensions.create",
133-
"client.savedExtensions.delete",
134-
"client.savedExtensions.get",
135-
"client.savedExtensions.list",
136-
"client.savedExtensions.update",
137-
"client.assets.list",
138-
"client.cache.invalidation.create",
139-
"client.cache.invalidation.get",
140-
"client.folders.copy",
141-
"client.folders.create",
142-
"client.folders.delete",
143-
"client.folders.move",
144-
"client.folders.rename",
145-
"client.folders.job.get",
146-
"client.accounts.usage.get",
147-
"client.accounts.origins.create",
148-
"client.accounts.origins.delete",
149-
"client.accounts.origins.get",
150-
"client.accounts.origins.list",
151-
"client.accounts.origins.update",
152-
"client.accounts.urlEndpoints.create",
153-
"client.accounts.urlEndpoints.delete",
154-
"client.accounts.urlEndpoints.get",
155-
"client.accounts.urlEndpoints.list",
156-
"client.accounts.urlEndpoints.update",
157-
"client.beta.v2.files.upload",
158-
"client.webhooks.unsafeUnwrap",
159-
"client.webhooks.unwrap"
111+
'client.customMetadataFields.create',
112+
'client.customMetadataFields.delete',
113+
'client.customMetadataFields.list',
114+
'client.customMetadataFields.update',
115+
'client.files.copy',
116+
'client.files.delete',
117+
'client.files.get',
118+
'client.files.move',
119+
'client.files.rename',
120+
'client.files.update',
121+
'client.files.upload',
122+
'client.files.bulk.addTags',
123+
'client.files.bulk.delete',
124+
'client.files.bulk.removeAITags',
125+
'client.files.bulk.removeTags',
126+
'client.files.versions.delete',
127+
'client.files.versions.get',
128+
'client.files.versions.list',
129+
'client.files.versions.restore',
130+
'client.files.metadata.get',
131+
'client.files.metadata.getFromURL',
132+
'client.savedExtensions.create',
133+
'client.savedExtensions.delete',
134+
'client.savedExtensions.get',
135+
'client.savedExtensions.list',
136+
'client.savedExtensions.update',
137+
'client.assets.list',
138+
'client.cache.invalidation.create',
139+
'client.cache.invalidation.get',
140+
'client.folders.copy',
141+
'client.folders.create',
142+
'client.folders.delete',
143+
'client.folders.move',
144+
'client.folders.rename',
145+
'client.folders.job.get',
146+
'client.accounts.usage.get',
147+
'client.accounts.origins.create',
148+
'client.accounts.origins.delete',
149+
'client.accounts.origins.get',
150+
'client.accounts.origins.list',
151+
'client.accounts.origins.update',
152+
'client.accounts.urlEndpoints.create',
153+
'client.accounts.urlEndpoints.delete',
154+
'client.accounts.urlEndpoints.get',
155+
'client.accounts.urlEndpoints.list',
156+
'client.accounts.urlEndpoints.update',
157+
'client.beta.v2.files.upload',
158+
'client.webhooks.unsafeUnwrap',
159+
'client.webhooks.unwrap',
160160
],
161161
{ threshold: 1, shouldSort: true },
162162
);
@@ -239,7 +239,12 @@ function parseError(code: string, error: unknown): string | undefined {
239239
// Deno uses V8; the first "<anonymous>:LINE:COLUMN" is the top of stack.
240240
const lineNumber = error.stack?.match(/<anonymous>:([0-9]+):[0-9]+/)?.[1];
241241
// -1 for the zero-based indexing
242-
const line = lineNumber && code.split('\n').at(parseInt(lineNumber, 10) - 1)?.trim();
242+
const line =
243+
lineNumber &&
244+
code
245+
.split('\n')
246+
.at(parseInt(lineNumber, 10) - 1)
247+
?.trim();
243248
return line ? `${message}\n at line ${lineNumber}\n ${line}` : message;
244249
} catch {
245250
return message;
@@ -251,8 +256,9 @@ const fetch = async (req: Request): Promise<Response> => {
251256

252257
const runFunctionSource = code ? getRunFunctionSource(code) : null;
253258
if (!runFunctionSource) {
254-
const message = code
255-
? 'The code is missing a top-level `run` function.'
259+
const message =
260+
code ?
261+
'The code is missing a top-level `run` function.'
256262
: 'The code argument is missing. Provide one containing a top-level `run` function.';
257263
return Response.json(
258264
{
@@ -297,7 +303,7 @@ const fetch = async (req: Request): Promise<Response> => {
297303
try {
298304
let run_ = async (client: any) => {};
299305
run_ = (await tseval(`${code}\nexport default run;`)).default;
300-
const result = await run_(makeSdkProxy(client, { path: ["client"] }));
306+
const result = await run_(makeSdkProxy(client, { path: ['client'] }));
301307
return Response.json({
302308
is_error: false,
303309
result,

0 commit comments

Comments
 (0)