Skip to content

Commit 75c0a11

Browse files
authored
Merge pull request #94 from imagekit-developer/improve-type-defination
Improve type defination
2 parents 727dae4 + 7530fd3 commit 75c0a11

14 files changed

+1446
-582
lines changed

CHANGELOG.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Changelog
2+
3+
## SDK Version 3.0.0
4+
5+
### Breaking Changes
6+
7+
- **Overlay Syntax Update**
8+
In version 3.0.0, the old overlay syntax parameters for transformations (e.g., `oi`, `ot`, `obg`, and others as detailed [here](https://imagekit.io/docs/add-overlays-on-images)) have been removed. These parameters are deprecated and will now return errors when used in URLs.
9+
10+
**Action Required:**
11+
Migrate to the new layers syntax which supports overlay nesting, offers improved positional control, and allows more transformations at the layer level. For a quick start, refer to the [examples](https://imagekit.io/docs/add-overlays-on-images). Use the `raw` transformation parameter to implement this migration.
12+
13+
---
14+
15+
## SDK Version 2.0.0
16+
17+
### Breaking Changes
18+
19+
- **Authentication Process Update**
20+
Previously, client-side file uploads required the SDK to be initialized with both the `publicKey` and `authenticationEndpoint` to fetch security parameters (`signature`, `token`, and `expire`).
21+
22+
**Action Required:**
23+
With version 2.0.0, you must now generate the security parameters (`signature`, `token`, and `expire`) yourself, eliminating the need for the `authenticationEndpoint`. When invoking the SDK's upload method, be sure to include these parameters along with other [upload options](https://imagekit.io/docs/api-reference/upload-file/upload-file#Request). For further details, consult the documentation [here](https://imagekit.io/docs/api-reference/upload-file/upload-file#how-to-implement-client-side-file-upload).

README.md

Lines changed: 212 additions & 380 deletions
Large diffs are not rendered by default.

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "imagekit-javascript",
3-
"version": "3.0.2",
3+
"version": "3.1.0",
44
"description": "Javascript SDK for using ImageKit.io in the browser",
55
"main": "dist/imagekit.cjs.js",
66
"module": "dist/imagekit.esm.js",

samples/sample-app/server/server.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ const path = require('path');
88
const pugTemplatePath = path.join(__dirname, "../views/index.pug");
99

1010
const app = express();
11+
app.use(express.static('static'))
1112
app.use(cors());
1213
app.set('view engine', 'pug');
1314

samples/sample-app/views/index.pug

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
html
22
body
3+
img(id="my-image")
34
h3 Imagekit Demo
45
form(action='#' onSubmit='upload(event)')
56
input(type='file' id='file1')
@@ -18,16 +19,29 @@ html
1819
p
1920
img(src="")
2021

21-
script(type='text/javascript' src="https://unpkg.com/imagekit-javascript/dist/imagekit.min.js")
22+
// Copy paste manually from dist
23+
script(type='text/javascript' src="./imagekit.min.js")
2224
script.
2325
try {
2426
var imagekit = new ImageKit({
2527
publicKey: "!{publicKey}",
2628
urlEndpoint: "!{urlEndpoint}",
2729
});
2830

31+
2932
window.imagekit = imagekit;
3033

34+
var url = imagekit.url({
35+
src: "https://ik.imagekit.io/demo/default-image.jpg",
36+
transformation: [{
37+
height: 100
38+
}]
39+
})
40+
41+
var img = document.getElementById("my-image");
42+
console.log(url);
43+
img.src = url;
44+
3145

3246
function upload(e) {
3347
e.preventDefault();
@@ -119,4 +133,4 @@ html
119133
}
120134
} catch(ex) {
121135
console.log(ex);
122-
}
136+
}

src/constants/supportedTransforms.ts

Lines changed: 48 additions & 140 deletions
Original file line numberDiff line numberDiff line change
@@ -1,167 +1,75 @@
11
/**
2-
* @link https://docs.imagekit.io/features/image-transformations
2+
* {@link https://imagekit.io/docs/transformations}
33
*/
4-
const supportedTransforms: { [key: string]: string } = {
5-
/**
6-
* @link https://docs.imagekit.io/features/image-transformations/resize-crop-and-other-transformations#width-w
7-
*/
4+
export const supportedTransforms: { [key: string]: string } = {
5+
// Basic sizing & layout
86
width: "w",
9-
10-
/**
11-
* @link https://docs.imagekit.io/features/image-transformations/resize-crop-and-other-transformations#height-h
12-
*/
137
height: "h",
14-
15-
/**
16-
* @link https://docs.imagekit.io/features/image-transformations/resize-crop-and-other-transformations#aspect-ratio-ar
17-
*/
188
aspectRatio: "ar",
19-
20-
/**
21-
* @link https://docs.imagekit.io/features/image-transformations/resize-crop-and-other-transformations#quality-q
22-
*/
23-
quality: "q",
24-
25-
/**
26-
* @link https://docs.imagekit.io/features/image-transformations/resize-crop-and-other-transformations#crop-crop-modes-and-focus
27-
*/
9+
background: "bg",
10+
border: "b",
2811
crop: "c",
29-
30-
/**
31-
* @link https://docs.imagekit.io/features/image-transformations/resize-crop-and-other-transformations#crop-crop-modes-and-focus
32-
*/
3312
cropMode: "cm",
34-
35-
/**
36-
* @link https://docs.imagekit.io/features/image-transformations/resize-crop-and-other-transformations#focus-fo
37-
*/
13+
dpr: "dpr",
3814
focus: "fo",
39-
40-
/**
41-
* @link https://docs.imagekit.io/features/image-transformations/resize-crop-and-other-transformations#examples-focus-using-cropped-image-coordinates
42-
*/
15+
quality: "q",
4316
x: "x",
44-
45-
/**
46-
* @link https://docs.imagekit.io/features/image-transformations/resize-crop-and-other-transformations#examples-focus-using-cropped-image-coordinates
47-
*/
17+
xCenter: "xc",
4818
y: "y",
49-
50-
/**
51-
* @link https://docs.imagekit.io/features/image-transformations/resize-crop-and-other-transformations#format-f
52-
*/
19+
yCenter: "yc",
5320
format: "f",
54-
55-
/**
56-
* @link https://docs.imagekit.io/features/image-transformations/resize-crop-and-other-transformations#radius-r
57-
*/
21+
videoCodec: "vc",
22+
audioCodec: "ac",
5823
radius: "r",
59-
60-
/**
61-
* @link https://docs.imagekit.io/features/image-transformations/resize-crop-and-other-transformations#background-color-bg
62-
*/
63-
background: "bg",
64-
65-
/**
66-
* @link https://docs.imagekit.io/features/image-transformations/resize-crop-and-other-transformations#border-b
67-
*/
68-
border: "b",
69-
70-
/**
71-
* @link https://docs.imagekit.io/features/image-transformations/resize-crop-and-other-transformations#rotate-rt
72-
*/
7324
rotation: "rt",
74-
75-
/**
76-
* @link https://docs.imagekit.io/features/image-transformations/resize-crop-and-other-transformations#rotate-rt
77-
*/
78-
rotate: "rt",
79-
80-
/**
81-
* @link https://docs.imagekit.io/features/image-transformations/resize-crop-and-other-transformations#blur-bl
82-
*/
8325
blur: "bl",
84-
85-
/**
86-
* @link https://docs.imagekit.io/features/image-transformations/resize-crop-and-other-transformations#named-transformation-n
87-
*/
8826
named: "n",
89-
90-
/**
91-
* @link https://docs.imagekit.io/features/image-transformations/resize-crop-and-other-transformations#progressive-image-pr
92-
*/
93-
progressive: "pr",
94-
95-
/**
96-
* @link https://docs.imagekit.io/features/image-transformations/resize-crop-and-other-transformations#lossless-webp-and-png-lo
97-
*/
98-
lossless: "lo",
99-
100-
/**
101-
* @link https://docs.imagekit.io/features/image-transformations/resize-crop-and-other-transformations#trim-edges-t
102-
*/
103-
trim: "t",
104-
105-
/**
106-
* @link https://docs.imagekit.io/features/image-transformations/resize-crop-and-other-transformations#image-metadata-md
107-
*/
108-
metadata: "md",
109-
110-
/**
111-
* @link https://docs.imagekit.io/features/image-transformations/resize-crop-and-other-transformations#color-profile-cp
112-
*/
113-
colorProfile: "cp",
114-
115-
/**
116-
* @link https://docs.imagekit.io/features/image-transformations/resize-crop-and-other-transformations#default-image-di
117-
*/
11827
defaultImage: "di",
28+
flip: "fl",
29+
original: "orig",
30+
startOffset: "so",
31+
endOffset: "eo",
32+
duration: "du",
33+
streamingResolutions: "sr",
11934

120-
/**
121-
* @link https://docs.imagekit.io/features/image-transformations/resize-crop-and-other-transformations#dpr-dpr
122-
*/
123-
dpr: "dpr",
124-
125-
/**
126-
* @link https://docs.imagekit.io/features/image-transformations/image-enhancement-and-color-manipulation#sharpen-e-sharpen
127-
*/
35+
// Old deprecated mappings
12836
effectSharpen: "e-sharpen",
129-
130-
/**
131-
* @link https://docs.imagekit.io/features/image-transformations/image-enhancement-and-color-manipulation#unsharp-mask-e-usm
132-
*/
13337
effectUSM: "e-usm",
134-
135-
/**
136-
* @link https://docs.imagekit.io/features/image-transformations/image-enhancement-and-color-manipulation#contrast-stretch-e-contrast
137-
*/
13838
effectContrast: "e-contrast",
139-
140-
/**
141-
* @link https://docs.imagekit.io/features/image-transformations/resize-crop-and-other-transformations#grayscale-e-grayscale
142-
*/
14339
effectGray: "e-grayscale",
144-
145-
/**
146-
* @link https://docs.imagekit.io/features/image-transformations/resize-crop-and-other-transformations#original-image-orig
147-
*/
148-
original: "orig",
149-
150-
/**
151-
* @link https://docs.imagekit.io/features/image-transformations/image-enhancement-and-color-manipulation#shadow-e-shadow
152-
*/
15340
effectShadow: "e-shadow",
154-
155-
/**
156-
* @link https://docs.imagekit.io/features/image-transformations/image-enhancement-and-color-manipulation#gradient-e-gradient
157-
*/
15841
effectGradient: "e-gradient",
42+
rotate: "rt",
43+
44+
// AI & advanced effects
45+
grayscale: "e-grayscale",
46+
aiUpscale: "e-upscale",
47+
aiRetouch: "e-retouch",
48+
aiVariation: "e-genvar",
49+
aiDropShadow: "e-dropshadow",
50+
aiChangeBackground: "e-changebg",
51+
aiRemoveBackground: "e-bgremove",
52+
aiRemoveBackgroundExternal: "e-removedotbg",
53+
contrastStretch: "e-contrast",
54+
shadow: "e-shadow",
55+
sharpen: "e-sharpen",
56+
unsharpMask: "e-usm",
57+
gradient: "e-gradient",
58+
59+
// Other flags & finishing
60+
progressive: "pr",
61+
lossless: "lo",
62+
colorProfile: "cp",
63+
metadata: "md",
64+
opacity: "o",
65+
trim: "t",
66+
zoom: "z",
67+
page: "pg",
68+
69+
// Raw pass-through
70+
raw: "raw",
71+
};
15972

160-
/**
161-
* @link https://docs.imagekit.io/features/image-transformations/conditional-transformations
162-
*/
163-
raw: "raw",
164-
}
16573

16674

16775
export default supportedTransforms

src/index.ts

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -55,27 +55,16 @@ class ImageKit {
5555
}
5656

5757
/**
58-
* You can add multiple origins in the same ImageKit.io account.
59-
* URL endpoints allow you to configure which origins are accessible through your account and set their preference order as well.
60-
*
61-
* @see {@link https://github.com/imagekit-developer/imagekit-nodejs#url-generation}
62-
* @see {@link https://docs.imagekit.io/integration/url-endpoints}
63-
*
64-
* @param urlOptions
58+
* A utility function to generate asset URL. It applies the specified transformations and other parameters to the URL.
6559
*/
6660
url(urlOptions: UrlOptions): string {
6761
return url(urlOptions, this.options);
6862
}
6963

7064
/**
71-
* You can upload files to ImageKit.io media library from your server-side using private API key authentication.
72-
*
73-
* File size limit
74-
* The maximum upload file size is limited to 25MB.
75-
*
76-
* @see {@link https://docs.imagekit.io/api-reference/upload-file-api/server-side-file-upload}
65+
* For uploading files directly from the browser to ImageKit.io.
7766
*
78-
* @param uploadOptions
67+
* {@link https://imagekit.io/docs/api-reference/upload-file/upload-file#how-to-implement-client-side-file-upload}
7968
*/
8069
upload(uploadOptions: UploadOptions, options?: Partial<ImageKitOptions>): Promise<IKResponse<UploadResponse>>
8170
upload(uploadOptions: UploadOptions, callback: (err: Error | null, response: IKResponse<UploadResponse> | null) => void, options?: Partial<ImageKitOptions>): void;

0 commit comments

Comments
 (0)