@imagekit/nodejs 7.0.1 → 7.1.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.
Files changed (53) hide show
  1. package/CHANGELOG.md +74 -0
  2. package/README.md +54 -6
  3. package/internal/to-file.d.mts +1 -1
  4. package/internal/to-file.d.ts +1 -1
  5. package/internal/to-file.js +1 -1
  6. package/internal/to-file.mjs +1 -1
  7. package/lib/transformation-utils.d.mts.map +1 -1
  8. package/lib/transformation-utils.d.ts.map +1 -1
  9. package/lib/transformation-utils.js +1 -0
  10. package/lib/transformation-utils.js.map +1 -1
  11. package/lib/transformation-utils.mjs +1 -0
  12. package/lib/transformation-utils.mjs.map +1 -1
  13. package/package.json +1 -1
  14. package/resources/beta/v2/files.d.mts +63 -1
  15. package/resources/beta/v2/files.d.mts.map +1 -1
  16. package/resources/beta/v2/files.d.ts +63 -1
  17. package/resources/beta/v2/files.d.ts.map +1 -1
  18. package/resources/custom-metadata-fields.d.mts +13 -1
  19. package/resources/custom-metadata-fields.d.mts.map +1 -1
  20. package/resources/custom-metadata-fields.d.ts +13 -1
  21. package/resources/custom-metadata-fields.d.ts.map +1 -1
  22. package/resources/custom-metadata-fields.js +5 -0
  23. package/resources/custom-metadata-fields.js.map +1 -1
  24. package/resources/custom-metadata-fields.mjs +5 -0
  25. package/resources/custom-metadata-fields.mjs.map +1 -1
  26. package/resources/files/files.d.mts +125 -1
  27. package/resources/files/files.d.mts.map +1 -1
  28. package/resources/files/files.d.ts +125 -1
  29. package/resources/files/files.d.ts.map +1 -1
  30. package/resources/files/files.js.map +1 -1
  31. package/resources/files/files.mjs.map +1 -1
  32. package/resources/helper.d.mts.map +1 -1
  33. package/resources/helper.d.ts.map +1 -1
  34. package/resources/helper.js +22 -20
  35. package/resources/helper.js.map +1 -1
  36. package/resources/helper.mjs +22 -20
  37. package/resources/helper.mjs.map +1 -1
  38. package/resources/webhooks.d.mts +62 -0
  39. package/resources/webhooks.d.mts.map +1 -1
  40. package/resources/webhooks.d.ts +62 -0
  41. package/resources/webhooks.d.ts.map +1 -1
  42. package/src/internal/to-file.ts +1 -1
  43. package/src/lib/transformation-utils.ts +1 -0
  44. package/src/resources/beta/v2/files.ts +72 -0
  45. package/src/resources/custom-metadata-fields.ts +14 -1
  46. package/src/resources/files/files.ts +143 -0
  47. package/src/resources/helper.ts +28 -19
  48. package/src/resources/webhooks.ts +71 -0
  49. package/src/version.ts +1 -1
  50. package/version.d.mts +1 -1
  51. package/version.d.ts +1 -1
  52. package/version.js +1 -1
  53. package/version.mjs +1 -1
@@ -269,6 +269,17 @@ export interface File {
269
269
  */
270
270
  name?: string;
271
271
 
272
+ /**
273
+ * This field is included in the response only if the Path policy feature is
274
+ * available in the plan. It contains schema definitions for the custom metadata
275
+ * fields selected for the specified file path. Field selection can only be done
276
+ * when the Path policy feature is enabled.
277
+ *
278
+ * Keys are the names of the custom metadata fields; the value object has details
279
+ * about the custom metadata schema.
280
+ */
281
+ selectedFieldsSchema?: { [key: string]: File.SelectedFieldsSchema };
282
+
272
283
  /**
273
284
  * Size of the file in bytes.
274
285
  */
@@ -332,6 +343,66 @@ export namespace File {
332
343
  source?: string;
333
344
  }
334
345
 
346
+ export interface SelectedFieldsSchema {
347
+ /**
348
+ * Type of the custom metadata field.
349
+ */
350
+ type: 'Text' | 'Textarea' | 'Number' | 'Date' | 'Boolean' | 'SingleSelect' | 'MultiSelect';
351
+
352
+ /**
353
+ * The default value for this custom metadata field. The value should match the
354
+ * `type` of custom metadata field.
355
+ */
356
+ defaultValue?: string | number | boolean | Array<string | number | boolean>;
357
+
358
+ /**
359
+ * Specifies if the custom metadata field is required or not.
360
+ */
361
+ isValueRequired?: boolean;
362
+
363
+ /**
364
+ * Maximum length of string. Only set if `type` is set to `Text` or `Textarea`.
365
+ */
366
+ maxLength?: number;
367
+
368
+ /**
369
+ * Maximum value of the field. Only set if field type is `Date` or `Number`. For
370
+ * `Date` type field, the value will be in ISO8601 string format. For `Number` type
371
+ * field, it will be a numeric value.
372
+ */
373
+ maxValue?: string | number;
374
+
375
+ /**
376
+ * Minimum length of string. Only set if `type` is set to `Text` or `Textarea`.
377
+ */
378
+ minLength?: number;
379
+
380
+ /**
381
+ * Minimum value of the field. Only set if field type is `Date` or `Number`. For
382
+ * `Date` type field, the value will be in ISO8601 string format. For `Number` type
383
+ * field, it will be a numeric value.
384
+ */
385
+ minValue?: string | number;
386
+
387
+ /**
388
+ * Indicates whether the custom metadata field is read only. A read only field
389
+ * cannot be modified after being set. This field is configurable only via the
390
+ * **Path policy** feature.
391
+ */
392
+ readOnly?: boolean;
393
+
394
+ /**
395
+ * An array of allowed values when field type is `SingleSelect` or `MultiSelect`.
396
+ */
397
+ selectOptions?: Array<string | number | boolean>;
398
+
399
+ /**
400
+ * Specifies if the selectOptions array is truncated. It is truncated when number
401
+ * of options are > 100.
402
+ */
403
+ selectOptionsTruncated?: boolean;
404
+ }
405
+
335
406
  /**
336
407
  * An object with details of the file version.
337
408
  */
@@ -838,6 +909,17 @@ export interface FileUploadResponse {
838
909
  */
839
910
  name?: string;
840
911
 
912
+ /**
913
+ * This field is included in the response only if the Path policy feature is
914
+ * available in the plan. It contains schema definitions for the custom metadata
915
+ * fields selected for the specified file path. Field selection can only be done
916
+ * when the Path policy feature is enabled.
917
+ *
918
+ * Keys are the names of the custom metadata fields; the value object has details
919
+ * about the custom metadata schema.
920
+ */
921
+ selectedFieldsSchema?: { [key: string]: FileUploadResponse.SelectedFieldsSchema };
922
+
841
923
  /**
842
924
  * Size of the image file in Bytes.
843
925
  */
@@ -917,6 +999,66 @@ export namespace FileUploadResponse {
917
999
  'remove-bg'?: 'success' | 'pending' | 'failed';
918
1000
  }
919
1001
 
1002
+ export interface SelectedFieldsSchema {
1003
+ /**
1004
+ * Type of the custom metadata field.
1005
+ */
1006
+ type: 'Text' | 'Textarea' | 'Number' | 'Date' | 'Boolean' | 'SingleSelect' | 'MultiSelect';
1007
+
1008
+ /**
1009
+ * The default value for this custom metadata field. The value should match the
1010
+ * `type` of custom metadata field.
1011
+ */
1012
+ defaultValue?: string | number | boolean | Array<string | number | boolean>;
1013
+
1014
+ /**
1015
+ * Specifies if the custom metadata field is required or not.
1016
+ */
1017
+ isValueRequired?: boolean;
1018
+
1019
+ /**
1020
+ * Maximum length of string. Only set if `type` is set to `Text` or `Textarea`.
1021
+ */
1022
+ maxLength?: number;
1023
+
1024
+ /**
1025
+ * Maximum value of the field. Only set if field type is `Date` or `Number`. For
1026
+ * `Date` type field, the value will be in ISO8601 string format. For `Number` type
1027
+ * field, it will be a numeric value.
1028
+ */
1029
+ maxValue?: string | number;
1030
+
1031
+ /**
1032
+ * Minimum length of string. Only set if `type` is set to `Text` or `Textarea`.
1033
+ */
1034
+ minLength?: number;
1035
+
1036
+ /**
1037
+ * Minimum value of the field. Only set if field type is `Date` or `Number`. For
1038
+ * `Date` type field, the value will be in ISO8601 string format. For `Number` type
1039
+ * field, it will be a numeric value.
1040
+ */
1041
+ minValue?: string | number;
1042
+
1043
+ /**
1044
+ * Indicates whether the custom metadata field is read only. A read only field
1045
+ * cannot be modified after being set. This field is configurable only via the
1046
+ * **Path policy** feature.
1047
+ */
1048
+ readOnly?: boolean;
1049
+
1050
+ /**
1051
+ * An array of allowed values when field type is `SingleSelect` or `MultiSelect`.
1052
+ */
1053
+ selectOptions?: Array<string | number | boolean>;
1054
+
1055
+ /**
1056
+ * Specifies if the selectOptions array is truncated. It is truncated when number
1057
+ * of options are > 100.
1058
+ */
1059
+ selectOptionsTruncated?: boolean;
1060
+ }
1061
+
920
1062
  /**
921
1063
  * An object containing the file or file version's `id` (versionId) and `name`.
922
1064
  */
@@ -1236,6 +1378,7 @@ export interface FileUploadParams {
1236
1378
  | 'isPublished'
1237
1379
  | 'customMetadata'
1238
1380
  | 'metadata'
1381
+ | 'selectedFieldsSchema'
1239
1382
  >;
1240
1383
 
1241
1384
  /**
@@ -45,12 +45,11 @@ export class Helper extends APIResource {
45
45
 
46
46
  const isAbsoluteURL = opts.src.startsWith('http://') || opts.src.startsWith('https://');
47
47
 
48
- var urlObj, isSrcParameterUsedForURL, urlEndpointPattern;
48
+ var urlObj, isSrcParameterUsedForURL;
49
49
 
50
50
  try {
51
51
  if (!isAbsoluteURL) {
52
- urlEndpointPattern = new URL(opts.urlEndpoint).pathname;
53
- urlObj = new URL(pathJoin([opts.urlEndpoint.replace(urlEndpointPattern, ''), opts.src]));
52
+ urlObj = new URL(opts.urlEndpoint);
54
53
  } else {
55
54
  urlObj = new URL(opts.src!);
56
55
  isSrcParameterUsedForURL = true;
@@ -65,19 +64,25 @@ export class Helper extends APIResource {
65
64
 
66
65
  var transformationString = this.buildTransformationString(opts.transformation);
67
66
 
68
- if (transformationString && transformationString.length) {
69
- if (!transformationUtils.addAsQueryParameter(opts) && !isSrcParameterUsedForURL) {
70
- urlObj.pathname = pathJoin([
71
- TRANSFORMATION_PARAMETER + transformationUtils.getChainTransformDelimiter() + transformationString,
72
- urlObj.pathname,
73
- ]);
67
+ const addAsQuery = transformationUtils.addAsQueryParameter(opts) || isSrcParameterUsedForURL;
68
+
69
+ const TRANSFORMATION_PLACEHOLDER = 'PLEASEREPLACEJUSTBEFORESIGN';
70
+
71
+ if (!isAbsoluteURL) {
72
+ // For non-absolute URLs, construct the path: endpoint_path + transformations + src
73
+ const endpointPath = new URL(opts.urlEndpoint).pathname;
74
+ const pathParts = [endpointPath];
75
+
76
+ if (transformationString && transformationString.length && !addAsQuery) {
77
+ pathParts.push(
78
+ TRANSFORMATION_PARAMETER +
79
+ transformationUtils.getChainTransformDelimiter() +
80
+ TRANSFORMATION_PLACEHOLDER,
81
+ );
74
82
  }
75
- }
76
83
 
77
- if (urlEndpointPattern) {
78
- urlObj.pathname = pathJoin([urlEndpointPattern, urlObj.pathname]);
79
- } else {
80
- urlObj.pathname = pathJoin([urlObj.pathname]);
84
+ pathParts.push(opts.src);
85
+ urlObj.pathname = pathJoin(pathParts);
81
86
  }
82
87
 
83
88
  // First, build the complete URL with transformations
@@ -85,12 +90,16 @@ export class Helper extends APIResource {
85
90
 
86
91
  // Add transformation parameter manually to avoid URL encoding
87
92
  // URLSearchParams.set() would encode commas and colons in transformation string,
88
- // It would work correctly but not very readable e.g., "w-300,h-400" is better than "w-300%2Ch-400"
93
+ // It would work correctly but not very readable e.g., "w-300,h-400" is better than "w-300%2Ch-400". Moreover we ensure transformation string is URL safe by encoding individual components while building it.
94
+ if (transformationString && transformationString.length && addAsQuery) {
95
+ const separator = urlObj.searchParams.toString() ? '&' : '?';
96
+ finalUrl = `${finalUrl}${separator}${TRANSFORMATION_PARAMETER}=${TRANSFORMATION_PLACEHOLDER}`;
97
+ }
98
+
99
+ // Replace the placeholder with actual transformation string
100
+ // We don't put actual transformation string before signing to avoid issues with URL encoding. Though in node it works correctly but other libraries use this code as blueprint and can double encode when using URL object .href equivalent.
89
101
  if (transformationString && transformationString.length) {
90
- if (transformationUtils.addAsQueryParameter(opts) || isSrcParameterUsedForURL) {
91
- const separator = urlObj.searchParams.toString() ? '&' : '?';
92
- finalUrl = `${finalUrl}${separator}${TRANSFORMATION_PARAMETER}=${transformationString}`;
93
- }
102
+ finalUrl = finalUrl.replace(TRANSFORMATION_PLACEHOLDER, transformationString);
94
103
  }
95
104
 
96
105
  // Then sign the URL if needed
@@ -383,6 +383,17 @@ export namespace UploadPreTransformSuccessEvent {
383
383
  */
384
384
  name?: string;
385
385
 
386
+ /**
387
+ * This field is included in the response only if the Path policy feature is
388
+ * available in the plan. It contains schema definitions for the custom metadata
389
+ * fields selected for the specified file path. Field selection can only be done
390
+ * when the Path policy feature is enabled.
391
+ *
392
+ * Keys are the names of the custom metadata fields; the value object has details
393
+ * about the custom metadata schema.
394
+ */
395
+ selectedFieldsSchema?: { [key: string]: Data.SelectedFieldsSchema };
396
+
386
397
  /**
387
398
  * Size of the image file in Bytes.
388
399
  */
@@ -462,6 +473,66 @@ export namespace UploadPreTransformSuccessEvent {
462
473
  'remove-bg'?: 'success' | 'pending' | 'failed';
463
474
  }
464
475
 
476
+ export interface SelectedFieldsSchema {
477
+ /**
478
+ * Type of the custom metadata field.
479
+ */
480
+ type: 'Text' | 'Textarea' | 'Number' | 'Date' | 'Boolean' | 'SingleSelect' | 'MultiSelect';
481
+
482
+ /**
483
+ * The default value for this custom metadata field. The value should match the
484
+ * `type` of custom metadata field.
485
+ */
486
+ defaultValue?: string | number | boolean | Array<string | number | boolean>;
487
+
488
+ /**
489
+ * Specifies if the custom metadata field is required or not.
490
+ */
491
+ isValueRequired?: boolean;
492
+
493
+ /**
494
+ * Maximum length of string. Only set if `type` is set to `Text` or `Textarea`.
495
+ */
496
+ maxLength?: number;
497
+
498
+ /**
499
+ * Maximum value of the field. Only set if field type is `Date` or `Number`. For
500
+ * `Date` type field, the value will be in ISO8601 string format. For `Number` type
501
+ * field, it will be a numeric value.
502
+ */
503
+ maxValue?: string | number;
504
+
505
+ /**
506
+ * Minimum length of string. Only set if `type` is set to `Text` or `Textarea`.
507
+ */
508
+ minLength?: number;
509
+
510
+ /**
511
+ * Minimum value of the field. Only set if field type is `Date` or `Number`. For
512
+ * `Date` type field, the value will be in ISO8601 string format. For `Number` type
513
+ * field, it will be a numeric value.
514
+ */
515
+ minValue?: string | number;
516
+
517
+ /**
518
+ * Indicates whether the custom metadata field is read only. A read only field
519
+ * cannot be modified after being set. This field is configurable only via the
520
+ * **Path policy** feature.
521
+ */
522
+ readOnly?: boolean;
523
+
524
+ /**
525
+ * An array of allowed values when field type is `SingleSelect` or `MultiSelect`.
526
+ */
527
+ selectOptions?: Array<string | number | boolean>;
528
+
529
+ /**
530
+ * Specifies if the selectOptions array is truncated. It is truncated when number
531
+ * of options are > 100.
532
+ */
533
+ selectOptionsTruncated?: boolean;
534
+ }
535
+
465
536
  /**
466
537
  * An object containing the file or file version's `id` (versionId) and `name`.
467
538
  */
package/src/version.ts CHANGED
@@ -1 +1 @@
1
- export const VERSION = '7.0.1'; // x-release-please-version
1
+ export const VERSION = '7.1.1'; // x-release-please-version
package/version.d.mts CHANGED
@@ -1,2 +1,2 @@
1
- export declare const VERSION = "7.0.1";
1
+ export declare const VERSION = "7.1.1";
2
2
  //# sourceMappingURL=version.d.mts.map
package/version.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- export declare const VERSION = "7.0.1";
1
+ export declare const VERSION = "7.1.1";
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.0.1'; // x-release-please-version
4
+ exports.VERSION = '7.1.1'; // x-release-please-version
5
5
  //# sourceMappingURL=version.js.map
package/version.mjs CHANGED
@@ -1,2 +1,2 @@
1
- export const VERSION = '7.0.1'; // x-release-please-version
1
+ export const VERSION = '7.1.1'; // x-release-please-version
2
2
  //# sourceMappingURL=version.mjs.map