Skip to content

Commit 5e139b5

Browse files
authored
Merge pull request #92 from imagekit-developer/SDK-68
Sdk 68
2 parents 1f828fd + 1fb7fd1 commit 5e139b5

19 files changed

+1143
-1753
lines changed

.github/workflows/nodejs.yml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ jobs:
2222
npm install -g @angular/[email protected]
2323
cd sdk
2424
npm install
25+
cd tests/test-apps/sample-server
26+
echo PRIVATE_KEY=${{ secrets.ik_private_key }} >> .env;
27+
npm install
28+
npm run server &
29+
cd ../../../
2530
npm run test:ci
2631
env:
2732
CI: true
@@ -49,7 +54,6 @@ jobs:
4954
echo production: false, >> environment.ts;
5055
echo URL_ENDPOINT:\"https://ik.imagekit.io/sdktestingik\", >> environment.ts;
5156
echo PUBLIC_KEY:\"${{ secrets.ik_public_key }}\", >> environment.ts;
52-
echo AUTHENTICATION_ENDPOINT:\"http://localhost:3000/auth\" >> environment.ts;
5357
echo '};' >> environment.ts;
5458
less environment.ts
5559
@@ -80,5 +84,4 @@ jobs:
8084
CI: true
8185
PUBLIC_KEY: ${{ secrets.ik_public_key }}
8286
PRIVATE_KEY: ${{ secrets.ik_private_key }}
83-
URL_ENDPOINT: https://ik.imagekit.io/sdktestingik
84-
AUTHENTICATION_ENDPOINT: 'http://localhost:3000/auth'
87+
URL_ENDPOINT: https://ik.imagekit.io/sdktestingik

README.md

Lines changed: 85 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,44 @@ ImageKit Angular SDK allows you to resize, optimize, deliver, and upload images
1111

1212
ImageKit is complete media storage, optimization, and transformation solution that comes with an image and video CDN. It can be integrated with your existing infrastructure - storage like AWS S3, web servers, your CDN, and custom domain names, allowing you to deliver optimized images in minutes with minimal code changes.
1313

14+
## Breaking changes - Upgrading from 2.x to 3.x version
15+
3.x version has breaking changes as listed below.
16+
* In version 3.0.0, we have deprecated the use of the `authenticationEndpoint` parameter. Instead, the SDK now introduces a new parameter named `authenticator`. This parameter expects an asynchronous function that resolves with an object containing the necessary security parameters i.e `signature`, `token`, and `expire`.
17+
18+
Example implementation for `authenticator` using `Fetch API`.
19+
20+
``` javascript
21+
22+
authenticator = async () => {
23+
try {
24+
25+
// You can pass headers as well and later validate the request source in the backend, or you can use headers for any other use case.
26+
const headers = {
27+
'Authorization': 'Bearer your-access-token',
28+
'CustomHeader': 'CustomValue'
29+
};
30+
31+
const response = await fetch('server_endpoint', {
32+
headers
33+
});
34+
35+
if (!response.ok) {
36+
const errorText = await response.text();
37+
throw new Error(`Request failed with status ${response.status}: ${errorText}`);
38+
}
39+
40+
const data = await response.json();
41+
const { signature, expire, token } = data;
42+
return { signature, expire, token };
43+
} catch (error) {
44+
throw new Error(`Authentication request failed: ${error.message}`);
45+
}
46+
};
47+
```
48+
49+
*Note*: Avoid generating security parameters on the client side. Always send a request to your backend to retrieve security parameters, as the generation of these parameters necessitates the use of your Imagekit `privateKey`, which must not be included in client-side code.
50+
51+
1452
## Installation
1553

1654
```shell
@@ -45,7 +83,6 @@ To use the SDK, you need to provide it with a few configuration parameters. The
4583
ImagekitioAngularModule.forRoot({
4684
publicKey: environment.publicKey,
4785
urlEndpoint: environment.urlEndpoint,
48-
authenticationEndpoint: environment.authenticationEndpoint
4986
})
5087
],
5188
providers: [],
@@ -54,7 +91,7 @@ To use the SDK, you need to provide it with a few configuration parameters. The
5491
```
5592

5693
* `urlEndpoint` is required to use the SDK. You can get URL-endpoint from your ImageKit dashboard - https://imagekit.io/dashboard/url-endpoints.
57-
* `publicKey` and `authenticationEndpoint` parameters are required if you want to use the SDK for client-side file upload. You can get `publicKey` from the developer section in your ImageKit dashboard - https://imagekit.io/dashboard/developer/api-keys.
94+
* `publicKey` and `authenticator` parameters are required if you want to use the SDK for client-side file upload. You can get `publicKey` from the developer section in your ImageKit dashboard - https://imagekit.io/dashboard/developer/api-keys.
5895
* `transformationPosition` is optional. The default value for the parameter is `path`. Acceptable values are `path` & `query`
5996

6097
> Note: Do not include your [private key](https://docs.imagekit.io/api-reference/api-introduction/api-keys#private-key) in any client-side code.
@@ -101,6 +138,12 @@ To use the SDK, you need to provide it with a few configuration parameters. The
101138
}]'
102139
></ik-image>
103140

141+
// Renders an image with text overlaid.
142+
<ik-image
143+
path="/default-image.jpg"
144+
[transformation]='[{ "width": 300, "height": 300 },{ "raw": "l-text,i-Imagekit,rt-90,co-0651D5,fs-50,l-end" }]'>
145+
</ik-image>
146+
104147
// Lazy loading
105148
<ik-image path="/default-image.jpg" loading="lazy"></ik-image>
106149

@@ -138,6 +181,15 @@ To use the SDK, you need to provide it with a few configuration parameters. The
138181
fileName= "test.jpg"
139182
(onError)="handleUploadError($event)"
140183
(onSuccess)="handleUploadSuccess($event)"
184+
[tags]='["sample-tag1", "sample-tag2"]'
185+
customCoordinates="10,10,10,10"
186+
[isPrivateFile]="false"
187+
[responseFields]='["tags"]'
188+
folder="/sample-folder"
189+
[validateFile]="validateFileFunction"
190+
[onUploadStart]="onUploadStartFunction"
191+
[onUploadProgress]="onUploadProgressFunction"
192+
[authenticator]="authenticator"
141193
></ik-upload>
142194
```
143195

@@ -178,7 +230,7 @@ The `ik-image` component renders an `img` tag. It is used for rendering and mani
178230
The `transformation` prop is an array of objects. Each object can have the following properties. When you specify more than one object, each object is added as a chained transformation. For example:
179231

180232
```js
181-
// IThe following resizes the image to 300x300px
233+
// The following resizes the image to 300x300px
182234
flexibleTransformationOne: Array<Transformation> = [{
183235
height: "300",
184236
width: "300"
@@ -228,34 +280,6 @@ See the complete list of transformations supported in ImageKit [here](https://do
228280
| rotation | rt |
229281
| blur | bl |
230282
| named | n |
231-
| overlayX | ox |
232-
| overlayY | oy |
233-
| overlayFocus | ofo |
234-
| overlayHeight | oh |
235-
| overlayWidth | ow |
236-
| overlayImage | oi |
237-
| overlayImageTrim | oit |
238-
| overlayImageAspectRatio | oiar |
239-
| overlayImageBackground | oibg |
240-
| overlayImageBorder | oib |
241-
| overlayImageDPR | oidpr |
242-
| overlayImageQuality | oiq |
243-
| overlayImageCropping | oic |
244-
| overlayImageTrim | oit |
245-
| overlayText | ot |
246-
| overlayTextFontSize | ots |
247-
| overlayTextFontFamily | otf |
248-
| overlayTextColor | otc |
249-
| overlayTextTransparency | oa |
250-
| overlayAlpha | oa |
251-
| overlayTextTypography | ott |
252-
| overlayBackground | obg |
253-
| overlayTextEncoded | ote |
254-
| overlayTextWidth | otw |
255-
| overlayTextBackground | otbg |
256-
| overlayTextPadding | otp |
257-
| overlayTextInnerAlignment | otia |
258-
| overlayRadius | or |
259283
| progressive | pr |
260284
| lossless | lo |
261285
| trim | t |
@@ -436,9 +460,9 @@ The SDK provides a component to upload files to the [ImageKit Media Library](htt
436460
| onError | Function callback | Optional. EventEmitter. Called if the upload results in error. The first and only argument is the error received from the upload API |
437461
| urlEndpoint | String | Optional. For example, https://ik.imagekit.io/your_imagekit_id/endpoint/ |
438462
| publicKey | String | Optional |
439-
| authenticationEndpoint | String | Optional |
463+
| authenticator | ()=>Promise<{signature:string,token:string,expiry:number}> | Optional |
440464

441-
Note: All three `urlEndpoint`, `publicKey` and `authenticationEndpoint` must be present in the attribute for them to take effect. Otherwise, the SDK will fall back to the values specified in `app.module.ts`.
465+
Note: `urlEndpoint` and `publicKey` must be present in the attribute for them to take effect. Otherwise, the SDK will fall back to the values specified in `app.module.ts`.
442466

443467
Sample usage
444468

@@ -505,6 +529,32 @@ Custom button example, using buttonRef
505529
</button>
506530
```
507531

532+
Abort upload
533+
534+
```js
535+
// Added to app.component.ts
536+
@ViewChild('upload') uploadComponent:IkUploadComponent;// @ViewChild can be used to get instance of IKUpload component.
537+
538+
onAbortFunction(){
539+
this.uploadComponent && this.uploadComponent.abort();
540+
}
541+
542+
// Added to app.component.html
543+
<ik-upload
544+
#upload
545+
fileName= "test.jpg"
546+
(onError)="handleUploadError($event)"
547+
(onSuccess)="handleUploadSuccess($event)"
548+
[validateFile]="validateFileFunction"
549+
[onUploadStart]="onUploadStartFunction"
550+
[onUploadProgress]="onUploadProgressFunction"
551+
[authenticator]="authenticator"
552+
></ik-upload>
553+
<button
554+
(click)="onAbortFunction()"
555+
>Abort</button>
556+
```
557+
508558
## Accessing Imagekit core JS SDK
509559

510560
Sample usage
@@ -515,17 +565,15 @@ import { ImagekitService } from 'imagekitio-angular';
515565
// Initializing the service with configuration
516566
service = new ImagekitService({
517567
urlEndpoint: "https://ik.imagekit.io/your_imagekit_id/endpoint/",
518-
publicKey: "your_public_key",
519-
authenticationEndpoint: "your_authentication_endpoint"
568+
publicKey: "your_public_key",
520569
});
521570

522571
// Generating URL
523-
// Note: You can choose to override the publicKey and authenticationEndpoint if necessary
572+
// Note: You can choose to override the publicKey if necessary
524573
const url = this.service.ikInstance.url({
525574
path: "/default-image.jpg",
526575
urlEndpoint: "https://ik.imagekit.io/your_imagekit_id/endpoint/",
527576
publicKey: "your_overriding_public_key_if_needed",
528-
authenticationEndpoint: "your_overriding_authentication_endpoint_if_needed"
529577
});
530578

531579
```

sdk/lib/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
{
22
"name": "imagekitio-angular",
3-
"version": "2.0.2",
3+
"version": "3.0.0",
44
"author": "ImageKit",
55
"license": "MIT",
66
"private": false,
77
"dependencies": {
8-
"imagekit-javascript": "^1.5.4"
8+
"imagekit-javascript": "^2.0.0"
99
},
1010
"ngPackage": {
1111
"$schema": "./node_modules/ng-packagr/ng-package.schema.json",

sdk/lib/src/imagekitio-angular/ik-image/ik-image.component.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,11 @@ export class IkImageComponent implements AfterViewInit, OnInit, OnChanges {
5959
}
6060
}
6161

62-
onImageLoaded = (event) => {
63-
if(this.loading != 'lazy' && event.srcElement.src === this.lqipUrl){
64-
this.loadImage(this, this.url);
62+
onImageLoaded = (event: { srcElement: { src: string; }; }) => {
63+
const { loading, lqipUrl, url } = this;
64+
65+
if (loading !== 'lazy' && event.srcElement.src === lqipUrl) {
66+
this.loadImage(this, url);
6567
}
6668
};
6769

0 commit comments

Comments
 (0)