Skip to content

Commit 3c85be8

Browse files
feat(api): fix spec indentation
1 parent d2bc9ce commit 3c85be8

22 files changed

Lines changed: 554 additions & 373 deletions

.stats.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
configured_endpoints: 47
2-
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/imagekit-inc%2Fimagekit-1422f7513f230162270b197061e5768c2e0c803b94b8cd03a5e72544ac75a27f.yml
3-
openapi_spec_hash: 41175e752e6f6ce900b36aecba687fa7
2+
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/imagekit-inc%2Fimagekit-f4cd00365ba96133e0675eae3d5d3c6ac13874789e2ce69a84310ab64a4f87dd.yml
3+
openapi_spec_hash: dce632cfbb5464a98c0f5d8eb9573d68
44
config_hash: 17e408231b0b01676298010c7405f483

README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,10 @@ Generate authentication parameters for secure client-side file uploads:
337337

338338
```ts
339339
// Generate authentication parameters for client-side uploads
340-
const authParams = client.helper.getAuthenticationParameters();
340+
const authParams = client.helper.getAuthenticationParameters({
341+
privateKey: process.env['IMAGEKIT_PRIVATE_KEY'], // This is the default and can be omitted
342+
password: process.env['OPTIONAL_IMAGEKIT_IGNORES_THIS'], // This is the default and can be omitted
343+
});
341344
console.log(authParams);
342345
// Result: { token: 'uuid-token', expire: timestamp, signature: 'hmac-signature' }
343346

@@ -430,7 +433,6 @@ You can use the `maxRetries` option to configure or disable this:
430433
```js
431434
// Configure the default for all requests:
432435
const client = new ImageKit({
433-
privateKey: 'My Private Key',
434436
maxRetries: 0, // default is 2
435437
});
436438

@@ -448,7 +450,6 @@ Requests time out after 1 minute by default. You can configure this with a `time
448450
```ts
449451
// Configure the default for all requests:
450452
const client = new ImageKit({
451-
privateKey: 'My Private Key',
452453
timeout: 20 * 1000, // 20 seconds (default is 1 minute)
453454
});
454455

packages/mcp-server/README.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,13 +80,24 @@ and repeatably.
8080

8181
Launching the client with `--transport=http` launches the server as a remote server using Streamable HTTP transport. The `--port` setting can choose the port it will run on, and the `--socket` setting allows it to run on a Unix socket.
8282

83+
Authorization can be provided via the `Authorization` header using the Basic scheme.
84+
85+
Additionally, authorization can be provided via the following headers:
86+
| Header | Equivalent client option | Security scheme |
87+
| ---------------------------------- | ------------------------ | --------------- |
88+
| `x-imagekit-private-key` | `privateKey` | basicAuth |
89+
| `x-optional-imagekit-ignores-this` | `password` | basicAuth |
90+
8391
A configuration JSON for this server might look like this, assuming the server is hosted at `http://localhost:3000`:
8492

8593
```json
8694
{
8795
"mcpServers": {
8896
"imagekit_nodejs_api": {
89-
"url": "http://localhost:3000"
97+
"url": "http://localhost:3000",
98+
"headers": {
99+
"Authorization": "Basic <auth value>"
100+
}
90101
}
91102
}
92103
}

packages/mcp-server/src/auth.ts

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,34 @@ import { ClientOptions } from '@imagekit/nodejs';
55
import { McpOptions } from './options';
66

77
export const parseClientAuthHeaders = (req: IncomingMessage, required?: boolean): Partial<ClientOptions> => {
8-
return {};
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.');
25+
}
26+
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 };
936
};
1037

1138
export const getStainlessApiKey = (req: IncomingMessage, mcpOptions: McpOptions): string | undefined => {

packages/mcp-server/src/local-docs-search.ts

Lines changed: 396 additions & 348 deletions
Large diffs are not rendered by default.

src/client.ts

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ import {
8787
import { type Fetch } from './internal/builtin-types';
8888
import { HeadersLike, NullableHeaders, buildHeaders } from './internal/headers';
8989
import { FinalRequestOptions, RequestOptions } from './internal/request-options';
90+
import { toBase64 } from './internal/utils/base64';
9091
import { readEnv } from './internal/utils/env';
9192
import {
9293
type LogLevel,
@@ -299,7 +300,30 @@ export class ImageKit {
299300
}
300301

301302
protected validateHeaders({ values, nulls }: NullableHeaders) {
302-
return;
303+
if (this.privateKey && this.password && values.get('authorization')) {
304+
return;
305+
}
306+
if (nulls.has('authorization')) {
307+
return;
308+
}
309+
310+
throw new Error(
311+
'Could not resolve authentication method. Expected the privateKey or password to be set. Or for the "Authorization" headers to be explicitly omitted',
312+
);
313+
}
314+
315+
protected async authHeaders(opts: FinalRequestOptions): Promise<NullableHeaders | undefined> {
316+
if (!this.privateKey) {
317+
return undefined;
318+
}
319+
320+
if (!this.password) {
321+
return undefined;
322+
}
323+
324+
const credentials = `${this.privateKey}:${this.password}`;
325+
const Authorization = `Basic ${toBase64(credentials)}`;
326+
return buildHeaders([{ Authorization }]);
303327
}
304328

305329
/**
@@ -728,6 +752,7 @@ export class ImageKit {
728752
...(options.timeout ? { 'X-Stainless-Timeout': String(Math.trunc(options.timeout / 1000)) } : {}),
729753
...getPlatformHeaders(),
730754
},
755+
await this.authHeaders(options),
731756
this._options.defaultHeaders,
732757
bodyHeaders,
733758
options.headers,

tests/api-resources/accounts/origins.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import ImageKit from '@imagekit/nodejs';
44

55
const client = new ImageKit({
66
privateKey: 'My Private Key',
7+
password: 'My Password',
78
baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010',
89
});
910

tests/api-resources/accounts/url-endpoints.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import ImageKit from '@imagekit/nodejs';
44

55
const client = new ImageKit({
66
privateKey: 'My Private Key',
7+
password: 'My Password',
78
baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010',
89
});
910

tests/api-resources/accounts/usage.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import ImageKit from '@imagekit/nodejs';
44

55
const client = new ImageKit({
66
privateKey: 'My Private Key',
7+
password: 'My Password',
78
baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010',
89
});
910

tests/api-resources/assets.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import ImageKit from '@imagekit/nodejs';
44

55
const client = new ImageKit({
66
privateKey: 'My Private Key',
7+
password: 'My Password',
78
baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010',
89
});
910

0 commit comments

Comments
 (0)