1- import { url } from "./url/index" ;
2- import { upload } from "./upload/index" ;
31import { version } from "../package.json" ;
4- import transformationUtils from "./utils/transformation" ;
52import errorMessages from "./constants/errorMessages" ;
6- import { IImageKit , ImageKitOptions , TransformationPosition , UploadOptions , UploadResponse , UrlOptions } from "./interfaces" ;
3+ import { ImageKitOptions , UploadOptions , UploadResponse , UrlOptions } from "./interfaces" ;
4+ import { upload } from "./upload/index" ;
5+ import { url } from "./url/index" ;
6+ import transformationUtils from "./utils/transformation" ;
77
88function mandatoryParametersAvailable ( options : ImageKitOptions ) {
99 return options . urlEndpoint ;
@@ -13,46 +13,52 @@ function privateKeyPassed(options: ImageKitOptions) {
1313 return typeof ( options as any ) . privateKey != "undefined" ;
1414}
1515
16- const ImageKit = function (
17- this : IImageKit ,
18- opts : {
19- publicKey : string ;
20- urlEndpoint : string ;
21- authenticationEndpoint ?: string ;
22- transformationPosition ?: TransformationPosition ;
23- } ,
24- ) {
25- opts = opts || { } ;
26- this . options = {
16+ class ImageKit {
17+ options : ImageKitOptions = {
2718 sdkVersion : `javascript-${ version } ` ,
2819 publicKey : "" ,
2920 urlEndpoint : "" ,
3021 transformationPosition : transformationUtils . getDefault ( ) ,
3122 } ;
3223
33- this . options = {
34- ...this . options ,
35- ...opts ,
36- } ;
24+ constructor ( opts : Omit < ImageKitOptions , "sdkVersion" > ) {
25+ this . options = { ...this . options , ...( opts || { } ) } ;
26+ if ( ! mandatoryParametersAvailable ( this . options ) ) {
27+ throw errorMessages . MANDATORY_INITIALIZATION_MISSING ;
28+ }
29+ if ( privateKeyPassed ( this . options ) ) {
30+ throw errorMessages . PRIVATE_KEY_CLIENT_SIDE ;
31+ }
3732
38- if ( ! mandatoryParametersAvailable ( this . options ) ) {
39- throw errorMessages . MANDATORY_INITIALIZATION_MISSING ;
40- }
41- if ( privateKeyPassed ( this . options ) ) {
42- throw errorMessages . PRIVATE_KEY_CLIENT_SIDE ;
33+ if ( ! transformationUtils . validParameters ( this . options ) ) {
34+ throw errorMessages . INVALID_TRANSFORMATION_POSITION ;
35+ }
4336 }
4437
45- if ( ! transformationUtils . validParameters ( this . options ) ) {
46- throw errorMessages . INVALID_TRANSFORMATION_POSITION ;
47- }
48-
49- /* URL Builder */
50- this . url = function ( urlOptions : UrlOptions ) : string {
38+ /**
39+ * You can add multiple origins in the same ImageKit.io account.
40+ * URL endpoints allow you to configure which origins are accessible through your account and set their preference order as well.
41+ *
42+ * @see {@link https://github.com/imagekit-developer/imagekit-nodejs#url-generation }
43+ * @see {@link https://docs.imagekit.io/integration/url-endpoints }
44+ *
45+ * @param urlOptions
46+ */
47+ url ( urlOptions : UrlOptions ) : string {
5148 return url ( urlOptions , this . options ) ;
52- } ;
49+ }
5350
54- /* Upload API */
55- this . upload = function (
51+ /**
52+ * You can upload files to ImageKit.io media library from your server-side using private API key authentication.
53+ *
54+ * File size limit
55+ * The maximum upload file size is limited to 25MB.
56+ *
57+ * @see {@link https://docs.imagekit.io/api-reference/upload-file-api/server-side-file-upload }
58+ *
59+ * @param uploadOptions
60+ */
61+ upload (
5662 uploadOptions : UploadOptions ,
5763 callback ?: ( err : Error | null , response : UploadResponse | null ) => void ,
5864 options ?: Partial < ImageKitOptions > ,
@@ -62,7 +68,7 @@ const ImageKit = function (
6268 ...options ,
6369 } ;
6470 return upload ( uploadOptions , mergedOptions , callback ) ;
65- } ;
66- } ;
71+ }
72+ }
6773
6874export default ImageKit ;
0 commit comments