1
- import { url } from "./url/index" ;
2
- import { upload } from "./upload/index" ;
3
1
import { version } from "../package.json" ;
4
- import transformationUtils from "./utils/transformation" ;
5
2
import 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" ;
7
7
8
8
function mandatoryParametersAvailable ( options : ImageKitOptions ) {
9
9
return options . urlEndpoint ;
@@ -13,46 +13,52 @@ function privateKeyPassed(options: ImageKitOptions) {
13
13
return typeof ( options as any ) . privateKey != "undefined" ;
14
14
}
15
15
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 = {
27
18
sdkVersion : `javascript-${ version } ` ,
28
19
publicKey : "" ,
29
20
urlEndpoint : "" ,
30
21
transformationPosition : transformationUtils . getDefault ( ) ,
31
22
} ;
32
23
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
+ }
37
32
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
+ }
43
36
}
44
37
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 {
51
48
return url ( urlOptions , this . options ) ;
52
- } ;
49
+ }
53
50
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 (
56
62
uploadOptions : UploadOptions ,
57
63
callback ?: ( err : Error | null , response : UploadResponse | null ) => void ,
58
64
options ?: Partial < ImageKitOptions > ,
@@ -62,7 +68,7 @@ const ImageKit = function (
62
68
...options ,
63
69
} ;
64
70
return upload ( uploadOptions , mergedOptions , callback ) ;
65
- } ;
66
- } ;
71
+ }
72
+ }
67
73
68
74
export default ImageKit ;
0 commit comments