Skip to content

Commit d2bc9ce

Browse files
feat(api): dam related webhook events
1 parent 7f1ff53 commit d2bc9ce

26 files changed

Lines changed: 532 additions & 606 deletions

.stats.yml

Lines changed: 3 additions & 3 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-63aff1629530786015da3c86131afa8a9b60545d488884b77641f1d4b89c6e9d.yml
3-
openapi_spec_hash: 586d357bd7e5217d240a99e0d83c6d1f
4-
config_hash: 47cb702ee2cb52c58d803ae39ade9b44
2+
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/imagekit-inc%2Fimagekit-1422f7513f230162270b197061e5768c2e0c803b94b8cd03a5e72544ac75a27f.yml
3+
openapi_spec_hash: 41175e752e6f6ce900b36aecba687fa7
4+
config_hash: 17e408231b0b01676298010c7405f483

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,7 @@ You can use the `maxRetries` option to configure or disable this:
430430
```js
431431
// Configure the default for all requests:
432432
const client = new ImageKit({
433+
privateKey: 'My Private Key',
433434
maxRetries: 0, // default is 2
434435
});
435436

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

api.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,11 @@ Methods:
229229
Types:
230230

231231
- <code><a href="./src/resources/webhooks.ts">BaseWebhookEvent</a></code>
232+
- <code><a href="./src/resources/webhooks.ts">DamFileCreateEvent</a></code>
233+
- <code><a href="./src/resources/webhooks.ts">DamFileDeleteEvent</a></code>
234+
- <code><a href="./src/resources/webhooks.ts">DamFileUpdateEvent</a></code>
235+
- <code><a href="./src/resources/webhooks.ts">DamFileVersionCreateEvent</a></code>
236+
- <code><a href="./src/resources/webhooks.ts">DamFileVersionDeleteEvent</a></code>
232237
- <code><a href="./src/resources/webhooks.ts">UploadPostTransformErrorEvent</a></code>
233238
- <code><a href="./src/resources/webhooks.ts">UploadPostTransformSuccessEvent</a></code>
234239
- <code><a href="./src/resources/webhooks.ts">UploadPreTransformErrorEvent</a></code>

packages/mcp-server/README.md

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -80,24 +80,13 @@ 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-
9183
A configuration JSON for this server might look like this, assuming the server is hosted at `http://localhost:3000`:
9284

9385
```json
9486
{
9587
"mcpServers": {
9688
"imagekit_nodejs_api": {
97-
"url": "http://localhost:3000",
98-
"headers": {
99-
"Authorization": "Basic <auth value>"
100-
}
89+
"url": "http://localhost:3000"
10190
}
10291
}
10392
}

packages/mcp-server/src/auth.ts

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

77
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.');
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 };
8+
return {};
369
};
3710

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

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

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

src/client.ts

Lines changed: 11 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@ import {
3535
} from './resources/saved-extensions';
3636
import {
3737
BaseWebhookEvent,
38+
DamFileCreateEvent,
39+
DamFileDeleteEvent,
40+
DamFileUpdateEvent,
41+
DamFileVersionCreateEvent,
42+
DamFileVersionDeleteEvent,
3843
UnsafeUnwrapWebhookEvent,
3944
UnwrapWebhookEvent,
4045
UploadPostTransformErrorEvent,
@@ -82,7 +87,6 @@ import {
8287
import { type Fetch } from './internal/builtin-types';
8388
import { HeadersLike, NullableHeaders, buildHeaders } from './internal/headers';
8489
import { FinalRequestOptions, RequestOptions } from './internal/request-options';
85-
import { toBase64 } from './internal/utils/base64';
8690
import { readEnv } from './internal/utils/env';
8791
import {
8892
type LogLevel,
@@ -295,30 +299,7 @@ export class ImageKit {
295299
}
296300

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

324305
/**
@@ -747,7 +728,6 @@ export class ImageKit {
747728
...(options.timeout ? { 'X-Stainless-Timeout': String(Math.trunc(options.timeout / 1000)) } : {}),
748729
...getPlatformHeaders(),
749730
},
750-
await this.authHeaders(options),
751731
this._options.defaultHeaders,
752732
bodyHeaders,
753733
options.headers,
@@ -917,6 +897,11 @@ export declare namespace ImageKit {
917897
export {
918898
Webhooks as Webhooks,
919899
type BaseWebhookEvent as BaseWebhookEvent,
900+
type DamFileCreateEvent as DamFileCreateEvent,
901+
type DamFileDeleteEvent as DamFileDeleteEvent,
902+
type DamFileUpdateEvent as DamFileUpdateEvent,
903+
type DamFileVersionCreateEvent as DamFileVersionCreateEvent,
904+
type DamFileVersionDeleteEvent as DamFileVersionDeleteEvent,
920905
type UploadPostTransformErrorEvent as UploadPostTransformErrorEvent,
921906
type UploadPostTransformSuccessEvent as UploadPostTransformSuccessEvent,
922907
type UploadPreTransformErrorEvent as UploadPreTransformErrorEvent,

src/resources/index.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,11 @@ export {
5353
export {
5454
Webhooks,
5555
type BaseWebhookEvent,
56+
type DamFileCreateEvent,
57+
type DamFileDeleteEvent,
58+
type DamFileUpdateEvent,
59+
type DamFileVersionCreateEvent,
60+
type DamFileVersionDeleteEvent,
5661
type UploadPostTransformErrorEvent,
5762
type UploadPostTransformSuccessEvent,
5863
type UploadPreTransformErrorEvent,

src/resources/shared.ts

Lines changed: 8 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -147,10 +147,8 @@ export namespace ExtensionConfig {
147147
min_selections?: number;
148148

149149
/**
150-
* Array of possible tag values. The combined length of all strings must not exceed
151-
* 500 characters, and values cannot include the `%` character. When providing
152-
* large vocabularies (more than 30 items), the AI may not follow the list
153-
* strictly.
150+
* Array of possible tag values. Combined length of all strings must not exceed 500
151+
* characters. Cannot contain the `%` character.
154152
*/
155153
vocabulary?: Array<string>;
156154
}
@@ -183,10 +181,7 @@ export namespace ExtensionConfig {
183181
min_selections?: number;
184182

185183
/**
186-
* An array of possible values matching the custom metadata field type. If not
187-
* provided for SingleSelect or MultiSelect field types, all values from the custom
188-
* metadata field definition will be used. When providing large vocabularies (above
189-
* 30 items), the AI may not strictly adhere to the list.
184+
* Array of possible values matching the custom metadata field type.
190185
*/
191186
vocabulary?: Array<string | number | boolean>;
192187
}
@@ -473,10 +468,8 @@ export namespace Extensions {
473468
min_selections?: number;
474469

475470
/**
476-
* Array of possible tag values. The combined length of all strings must not exceed
477-
* 500 characters, and values cannot include the `%` character. When providing
478-
* large vocabularies (more than 30 items), the AI may not follow the list
479-
* strictly.
471+
* Array of possible tag values. Combined length of all strings must not exceed 500
472+
* characters. Cannot contain the `%` character.
480473
*/
481474
vocabulary?: Array<string>;
482475
}
@@ -509,10 +502,7 @@ export namespace Extensions {
509502
min_selections?: number;
510503

511504
/**
512-
* An array of possible values matching the custom metadata field type. If not
513-
* provided for SingleSelect or MultiSelect field types, all values from the custom
514-
* metadata field definition will be used. When providing large vocabularies (above
515-
* 30 items), the AI may not strictly adhere to the list.
505+
* Array of possible values matching the custom metadata field type.
516506
*/
517507
vocabulary?: Array<string | number | boolean>;
518508
}
@@ -792,25 +782,8 @@ export type Overlay = TextOverlay | ImageOverlay | VideoOverlay | SubtitleOverla
792782

793783
export interface OverlayPosition {
794784
/**
795-
* Sets the anchor point on the base asset from which the overlay offset is
796-
* calculated. The default value is `top_left`. Maps to `lap` in the URL. Can only
797-
* be used with one or more of `x`, `y`, `xCenter`, or `yCenter`.
798-
*/
799-
anchorPoint?:
800-
| 'top'
801-
| 'left'
802-
| 'right'
803-
| 'bottom'
804-
| 'top_left'
805-
| 'top_right'
806-
| 'bottom_left'
807-
| 'bottom_right'
808-
| 'center';
809-
810-
/**
811-
* Specifies the position of the overlay relative to the parent image or video. If
812-
* one or more of `x`, `y`, `xCenter`, or `yCenter` parameters are specified, this
813-
* parameter is ignored. Maps to `lfo` in the URL.
785+
* Specifies the position of the overlay relative to the parent image or video.
786+
* Maps to `lfo` in the URL.
814787
*/
815788
focus?:
816789
| 'center'
@@ -832,15 +805,6 @@ export interface OverlayPosition {
832805
*/
833806
x?: number | string;
834807

835-
/**
836-
* Specifies the x-coordinate on the base asset where the overlay's center will be
837-
* positioned. It also accepts arithmetic expressions such as `bw_mul_0.4` or
838-
* `bw_sub_cw`. Maps to `lxc` in the URL. Cannot be used together with `x`, but can
839-
* be used with `y`. Learn about
840-
* [Arithmetic expressions](https://imagekit.io/docs/arithmetic-expressions-in-transformations).
841-
*/
842-
xCenter?: number | string;
843-
844808
/**
845809
* Specifies the y-coordinate of the top-left corner of the base asset where the
846810
* overlay's top-left corner will be positioned. It also accepts arithmetic
@@ -849,15 +813,6 @@ export interface OverlayPosition {
849813
* [Arithmetic expressions](https://imagekit.io/docs/arithmetic-expressions-in-transformations).
850814
*/
851815
y?: number | string;
852-
853-
/**
854-
* Specifies the y-coordinate on the base asset where the overlay's center will be
855-
* positioned. It also accepts arithmetic expressions such as `bh_mul_0.4` or
856-
* `bh_sub_ch`. Maps to `lyc` in the URL. Cannot be used together with `y`, but can
857-
* be used with `x`. Learn about
858-
* [Arithmetic expressions](https://imagekit.io/docs/arithmetic-expressions-in-transformations).
859-
*/
860-
yCenter?: number | string;
861816
}
862817

863818
export interface OverlayTiming {

0 commit comments

Comments
 (0)