@imagekit/nodejs 7.2.2 → 7.4.0

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.
Files changed (66) hide show
  1. package/CHANGELOG.md +96 -0
  2. package/client.d.mts +2 -1
  3. package/client.d.mts.map +1 -1
  4. package/client.d.ts +2 -1
  5. package/client.d.ts.map +1 -1
  6. package/client.js +23 -19
  7. package/client.js.map +1 -1
  8. package/client.mjs +23 -19
  9. package/client.mjs.map +1 -1
  10. package/internal/parse.d.mts.map +1 -1
  11. package/internal/parse.d.ts.map +1 -1
  12. package/internal/parse.js +5 -0
  13. package/internal/parse.js.map +1 -1
  14. package/internal/parse.mjs +5 -0
  15. package/internal/parse.mjs.map +1 -1
  16. package/internal/utils/query.d.mts +5 -0
  17. package/internal/utils/query.d.mts.map +1 -0
  18. package/internal/utils/query.d.ts +5 -0
  19. package/internal/utils/query.d.ts.map +1 -0
  20. package/internal/utils/query.js +23 -0
  21. package/internal/utils/query.js.map +1 -0
  22. package/internal/utils/query.mjs +20 -0
  23. package/internal/utils/query.mjs.map +1 -0
  24. package/internal/utils.d.mts +1 -0
  25. package/internal/utils.d.ts +1 -0
  26. package/internal/utils.js +1 -0
  27. package/internal/utils.js.map +1 -1
  28. package/internal/utils.mjs +1 -0
  29. package/package.json +12 -1
  30. package/resources/beta/v2/files.d.mts +5 -4
  31. package/resources/beta/v2/files.d.mts.map +1 -1
  32. package/resources/beta/v2/files.d.ts +5 -4
  33. package/resources/beta/v2/files.d.ts.map +1 -1
  34. package/resources/beta/v2/files.js +5 -4
  35. package/resources/beta/v2/files.js.map +1 -1
  36. package/resources/beta/v2/files.mjs +5 -4
  37. package/resources/beta/v2/files.mjs.map +1 -1
  38. package/resources/files/files.d.mts +35 -4
  39. package/resources/files/files.d.mts.map +1 -1
  40. package/resources/files/files.d.ts +35 -4
  41. package/resources/files/files.d.ts.map +1 -1
  42. package/resources/files/files.js +5 -4
  43. package/resources/files/files.js.map +1 -1
  44. package/resources/files/files.mjs +5 -4
  45. package/resources/files/files.mjs.map +1 -1
  46. package/resources/helper.js +10 -1
  47. package/resources/helper.js.map +1 -1
  48. package/resources/helper.mjs +10 -1
  49. package/resources/helper.mjs.map +1 -1
  50. package/resources/shared.d.mts +41 -8
  51. package/resources/shared.d.mts.map +1 -1
  52. package/resources/shared.d.ts +41 -8
  53. package/resources/shared.d.ts.map +1 -1
  54. package/src/client.ts +28 -24
  55. package/src/internal/parse.ts +6 -0
  56. package/src/internal/utils/query.ts +23 -0
  57. package/src/internal/utils.ts +1 -0
  58. package/src/resources/beta/v2/files.ts +5 -4
  59. package/src/resources/files/files.ts +37 -4
  60. package/src/resources/helper.ts +10 -1
  61. package/src/resources/shared.ts +53 -8
  62. package/src/version.ts +1 -1
  63. package/version.d.mts +1 -1
  64. package/version.d.ts +1 -1
  65. package/version.js +1 -1
  66. package/version.mjs +1 -1
package/src/client.ts CHANGED
@@ -11,6 +11,7 @@ import type { APIResponseProps } from './internal/parse';
11
11
  import { getPlatformHeaders } from './internal/detect-platform';
12
12
  import * as Shims from './internal/shims';
13
13
  import * as Opts from './internal/request-options';
14
+ import { stringifyQuery } from './internal/utils/query';
14
15
  import { VERSION } from './version';
15
16
  import * as Errors from './core/error';
16
17
  import * as Uploads from './core/uploads';
@@ -323,21 +324,8 @@ export class ImageKit {
323
324
  /**
324
325
  * Basic re-implementation of `qs.stringify` for primitive types.
325
326
  */
326
- protected stringifyQuery(query: Record<string, unknown>): string {
327
- return Object.entries(query)
328
- .filter(([_, value]) => typeof value !== 'undefined')
329
- .map(([key, value]) => {
330
- if (typeof value === 'string' || typeof value === 'number' || typeof value === 'boolean') {
331
- return `${encodeURIComponent(key)}=${encodeURIComponent(value)}`;
332
- }
333
- if (value === null) {
334
- return `${encodeURIComponent(key)}=`;
335
- }
336
- throw new Errors.ImageKitError(
337
- `Cannot stringify type ${typeof value}; Expected string, number, boolean, or null. If you need to pass nested query parameters, you can manually encode them, e.g. { query: { 'foo[key1]': value1, 'foo[key2]': value2 } }, and please open a GitHub issue requesting better support for your use case.`,
338
- );
339
- })
340
- .join('&');
327
+ protected stringifyQuery(query: object | Record<string, unknown>): string {
328
+ return stringifyQuery(query);
341
329
  }
342
330
 
343
331
  private getUserAgent(): string {
@@ -369,12 +357,13 @@ export class ImageKit {
369
357
  : new URL(baseURL + (baseURL.endsWith('/') && path.startsWith('/') ? path.slice(1) : path));
370
358
 
371
359
  const defaultQuery = this.defaultQuery();
372
- if (!isEmptyObj(defaultQuery)) {
373
- query = { ...defaultQuery, ...query };
360
+ const pathQuery = Object.fromEntries(url.searchParams);
361
+ if (!isEmptyObj(defaultQuery) || !isEmptyObj(pathQuery)) {
362
+ query = { ...pathQuery, ...defaultQuery, ...query };
374
363
  }
375
364
 
376
365
  if (typeof query === 'object' && query && !Array.isArray(query)) {
377
- url.search = this.stringifyQuery(query as Record<string, unknown>);
366
+ url.search = this.stringifyQuery(query);
378
367
  }
379
368
 
380
369
  return url.toString();
@@ -558,7 +547,7 @@ export class ImageKit {
558
547
  loggerFor(this).info(`${responseInfo} - ${retryMessage}`);
559
548
 
560
549
  const errText = await response.text().catch((err: any) => castToError(err).message);
561
- const errJSON = safeJSON(errText);
550
+ const errJSON = safeJSON(errText) as any;
562
551
  const errMessage = errJSON ? undefined : errText;
563
552
 
564
553
  loggerFor(this).debug(
@@ -599,9 +588,10 @@ export class ImageKit {
599
588
  controller: AbortController,
600
589
  ): Promise<Response> {
601
590
  const { signal, method, ...options } = init || {};
602
- if (signal) signal.addEventListener('abort', () => controller.abort());
591
+ const abort = this._makeAbort(controller);
592
+ if (signal) signal.addEventListener('abort', abort, { once: true });
603
593
 
604
- const timeout = setTimeout(() => controller.abort(), ms);
594
+ const timeout = setTimeout(abort, ms);
605
595
 
606
596
  const isReadableBody =
607
597
  ((globalThis as any).ReadableStream && options.body instanceof (globalThis as any).ReadableStream) ||
@@ -678,9 +668,9 @@ export class ImageKit {
678
668
  }
679
669
  }
680
670
 
681
- // If the API asks us to wait a certain amount of time (and it's a reasonable amount),
682
- // just do what it says, but otherwise calculate a default
683
- if (!(timeoutMillis && 0 <= timeoutMillis && timeoutMillis < 60 * 1000)) {
671
+ // If the API asks us to wait a certain amount of time, just do what it
672
+ // says, but otherwise calculate a default
673
+ if (timeoutMillis === undefined) {
684
674
  const maxRetries = options.maxRetries ?? this.maxRetries;
685
675
  timeoutMillis = this.calculateDefaultRetryTimeoutMillis(retriesRemaining, maxRetries);
686
676
  }
@@ -768,6 +758,12 @@ export class ImageKit {
768
758
  return headers.values;
769
759
  }
770
760
 
761
+ private _makeAbort(controller: AbortController) {
762
+ // note: we can't just inline this method inside `fetchWithTimeout()` because then the closure
763
+ // would capture all request options, and cause a memory leak.
764
+ return () => controller.abort();
765
+ }
766
+
771
767
  private buildBody({ options: { body, headers: rawHeaders } }: { options: FinalRequestOptions }): {
772
768
  bodyHeaders: HeadersLike;
773
769
  body: BodyInit | undefined;
@@ -800,6 +796,14 @@ export class ImageKit {
800
796
  (Symbol.iterator in body && 'next' in body && typeof body.next === 'function'))
801
797
  ) {
802
798
  return { bodyHeaders: undefined, body: Shims.ReadableStreamFrom(body as AsyncIterable<Uint8Array>) };
799
+ } else if (
800
+ typeof body === 'object' &&
801
+ headers.values.get('content-type') === 'application/x-www-form-urlencoded'
802
+ ) {
803
+ return {
804
+ bodyHeaders: { 'content-type': 'application/x-www-form-urlencoded' },
805
+ body: this.stringifyQuery(body),
806
+ };
803
807
  } else {
804
808
  return this.#encoder({ body, headers });
805
809
  }
@@ -29,6 +29,12 @@ export async function defaultParseResponse<T>(client: ImageKit, props: APIRespon
29
29
  const mediaType = contentType?.split(';')[0]?.trim();
30
30
  const isJSON = mediaType?.includes('application/json') || mediaType?.endsWith('+json');
31
31
  if (isJSON) {
32
+ const contentLength = response.headers.get('content-length');
33
+ if (contentLength === '0') {
34
+ // if there is no content we can't do anything
35
+ return undefined as T;
36
+ }
37
+
32
38
  const json = await response.json();
33
39
  return json as T;
34
40
  }
@@ -0,0 +1,23 @@
1
+ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
+
3
+ import { ImageKitError } from '../../core/error';
4
+
5
+ /**
6
+ * Basic re-implementation of `qs.stringify` for primitive types.
7
+ */
8
+ export function stringifyQuery(query: object | Record<string, unknown>) {
9
+ return Object.entries(query)
10
+ .filter(([_, value]) => typeof value !== 'undefined')
11
+ .map(([key, value]) => {
12
+ if (typeof value === 'string' || typeof value === 'number' || typeof value === 'boolean') {
13
+ return `${encodeURIComponent(key)}=${encodeURIComponent(value)}`;
14
+ }
15
+ if (value === null) {
16
+ return `${encodeURIComponent(key)}=`;
17
+ }
18
+ throw new ImageKitError(
19
+ `Cannot stringify type ${typeof value}; Expected string, number, boolean, or null. If you need to pass nested query parameters, you can manually encode them, e.g. { query: { 'foo[key1]': value1, 'foo[key2]': value2 } }, and please open a GitHub issue requesting better support for your use case.`,
20
+ );
21
+ })
22
+ .join('&');
23
+ }
@@ -6,3 +6,4 @@ export * from './utils/env';
6
6
  export * from './utils/log';
7
7
  export * from './utils/uuid';
8
8
  export * from './utils/sleep';
9
+ export * from './utils/query';
@@ -22,10 +22,11 @@ export class Files extends APIResource {
22
22
  * about how to implement secure client-side file upload.
23
23
  *
24
24
  * **File size limit** \
25
- * On the free plan, the maximum upload file sizes are 20MB for images, audio, and raw
26
- * files, and 100MB for videos. On the paid plan, these limits increase to 40MB for
27
- * images, audio, and raw files, and 2GB for videos. These limits can be further increased
28
- * with higher-tier plans.
25
+ * On the free plan, the maximum upload file sizes are 25MB for images, audio, and raw
26
+ * files, and 100MB for videos. On the Lite paid plan, these limits increase to 40MB
27
+ * for images, audio, and raw files and 300MB for videos, whereas on the Pro paid plan,
28
+ * these limits increase to 50MB for images, audio, and raw files and 2GB for videos.
29
+ * These limits can be further increased with enterprise plans.
29
30
  *
30
31
  * **Version limit** \
31
32
  * A file can have a maximum of 100 versions.
@@ -152,10 +152,11 @@ export class Files extends APIResource {
152
152
  * by verifying the entire payload using JWT.
153
153
  *
154
154
  * **File size limit** \
155
- * On the free plan, the maximum upload file sizes are 20MB for images, audio, and raw
156
- * files and 100MB for videos. On the paid plan, these limits increase to 40MB for images,
157
- * audio, and raw files and 2GB for videos. These limits can be further increased with
158
- * higher-tier plans.
155
+ * On the free plan, the maximum upload file sizes are 25MB for images, audio, and raw
156
+ * files and 100MB for videos. On the Lite paid plan, these limits increase to 40MB
157
+ * for images, audio, and raw files and 300MB for videos, whereas on the Pro paid plan,
158
+ * these limits increase to 50MB for images, audio, and raw files and 2GB for videos.
159
+ * These limits can be further increased with enterprise plans.
159
160
  *
160
161
  * **Version limit** \
161
162
  * A file can have a maximum of 100 versions.
@@ -199,6 +200,16 @@ export interface File {
199
200
  */
200
201
  AITags?: Array<File.AITag> | null;
201
202
 
203
+ /**
204
+ * The audio codec used in the video (only for video/audio).
205
+ */
206
+ audioCodec?: string;
207
+
208
+ /**
209
+ * The bit rate of the video in kbps (only for video).
210
+ */
211
+ bitRate?: number;
212
+
202
213
  /**
203
214
  * Date and time when the file was uploaded. The date and time is in ISO8601
204
215
  * format.
@@ -221,6 +232,17 @@ export interface File {
221
232
  */
222
233
  description?: string;
223
234
 
235
+ /**
236
+ * The duration of the video in seconds (only for video).
237
+ */
238
+ duration?: number;
239
+
240
+ /**
241
+ * Consolidated embedded metadata associated with the file. It includes exif, iptc,
242
+ * and xmp data.
243
+ */
244
+ embeddedMetadata?: { [key: string]: unknown };
245
+
224
246
  /**
225
247
  * Unique identifier of the asset.
226
248
  */
@@ -318,6 +340,11 @@ export interface File {
318
340
  */
319
341
  versionInfo?: File.VersionInfo;
320
342
 
343
+ /**
344
+ * The video codec used in the video (only for video).
345
+ */
346
+ videoCodec?: string;
347
+
321
348
  /**
322
349
  * Width of the file.
323
350
  */
@@ -426,6 +453,12 @@ export interface Folder {
426
453
  */
427
454
  createdAt?: string;
428
455
 
456
+ /**
457
+ * An object with custom metadata for the folder. Returns empty object if no custom
458
+ * metadata is set.
459
+ */
460
+ customMetadata?: { [key: string]: unknown };
461
+
429
462
  /**
430
463
  * Unique identifier of the asset.
431
464
  */
@@ -314,16 +314,25 @@ function processOverlay(overlay: Transformation['overlay']): string | undefined
314
314
  entries.push(`lm-${overlay.layerMode}`);
315
315
  }
316
316
 
317
- const { x, y, focus } = position;
317
+ const { x, y, xCenter, yCenter, focus, anchorPoint } = position;
318
318
  if (x) {
319
319
  entries.push(`lx-${x}`);
320
320
  }
321
321
  if (y) {
322
322
  entries.push(`ly-${y}`);
323
323
  }
324
+ if (xCenter) {
325
+ entries.push(`lxc-${xCenter}`);
326
+ }
327
+ if (yCenter) {
328
+ entries.push(`lyc-${yCenter}`);
329
+ }
324
330
  if (focus) {
325
331
  entries.push(`lfo-${focus}`);
326
332
  }
333
+ if (anchorPoint) {
334
+ entries.push(`lap-${anchorPoint}`);
335
+ }
327
336
 
328
337
  const { start, end, duration } = timing;
329
338
  if (start) {
@@ -147,8 +147,10 @@ export namespace ExtensionConfig {
147
147
  min_selections?: number;
148
148
 
149
149
  /**
150
- * Array of possible tag values. Combined length of all strings must not exceed 500
151
- * characters. Cannot contain the `%` character.
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.
152
154
  */
153
155
  vocabulary?: Array<string>;
154
156
  }
@@ -181,7 +183,10 @@ export namespace ExtensionConfig {
181
183
  min_selections?: number;
182
184
 
183
185
  /**
184
- * Array of possible values matching the custom metadata field type.
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.
185
190
  */
186
191
  vocabulary?: Array<string | number | boolean>;
187
192
  }
@@ -468,8 +473,10 @@ export namespace Extensions {
468
473
  min_selections?: number;
469
474
 
470
475
  /**
471
- * Array of possible tag values. Combined length of all strings must not exceed 500
472
- * characters. Cannot contain the `%` character.
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.
473
480
  */
474
481
  vocabulary?: Array<string>;
475
482
  }
@@ -502,7 +509,10 @@ export namespace Extensions {
502
509
  min_selections?: number;
503
510
 
504
511
  /**
505
- * Array of possible values matching the custom metadata field type.
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.
506
516
  */
507
517
  vocabulary?: Array<string | number | boolean>;
508
518
  }
@@ -782,8 +792,25 @@ export type Overlay = TextOverlay | ImageOverlay | VideoOverlay | SubtitleOverla
782
792
 
783
793
  export interface OverlayPosition {
784
794
  /**
785
- * Specifies the position of the overlay relative to the parent image or video.
786
- * Maps to `lfo` in the URL.
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.
787
814
  */
788
815
  focus?:
789
816
  | 'center'
@@ -805,6 +832,15 @@ export interface OverlayPosition {
805
832
  */
806
833
  x?: number | string;
807
834
 
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
+
808
844
  /**
809
845
  * Specifies the y-coordinate of the top-left corner of the base asset where the
810
846
  * overlay's top-left corner will be positioned. It also accepts arithmetic
@@ -813,6 +849,15 @@ export interface OverlayPosition {
813
849
  * [Arithmetic expressions](https://imagekit.io/docs/arithmetic-expressions-in-transformations).
814
850
  */
815
851
  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;
816
861
  }
817
862
 
818
863
  export interface OverlayTiming {
package/src/version.ts CHANGED
@@ -1 +1 @@
1
- export const VERSION = '7.2.2'; // x-release-please-version
1
+ export const VERSION = '7.4.0'; // x-release-please-version
package/version.d.mts CHANGED
@@ -1,2 +1,2 @@
1
- export declare const VERSION = "7.2.2";
1
+ export declare const VERSION = "7.4.0";
2
2
  //# sourceMappingURL=version.d.mts.map
package/version.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- export declare const VERSION = "7.2.2";
1
+ export declare const VERSION = "7.4.0";
2
2
  //# sourceMappingURL=version.d.ts.map
package/version.js CHANGED
@@ -1,5 +1,5 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.VERSION = void 0;
4
- exports.VERSION = '7.2.2'; // x-release-please-version
4
+ exports.VERSION = '7.4.0'; // x-release-please-version
5
5
  //# sourceMappingURL=version.js.map
package/version.mjs CHANGED
@@ -1,2 +1,2 @@
1
- export const VERSION = '7.2.2'; // x-release-please-version
1
+ export const VERSION = '7.4.0'; // x-release-please-version
2
2
  //# sourceMappingURL=version.mjs.map