Skip to content

Commit 524ee78

Browse files
authored
Merge pull request #3 from imagekit-developer/test-case
Test cases & onError & onSuccess callbacks
2 parents 86342d5 + 3aec927 commit 524ee78

36 files changed

+603
-226
lines changed

.github/workflows/nodejs.yml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,8 @@ jobs:
1919
node-version: ${{ matrix.node-version }}
2020
- name: npm install, build, and test
2121
run: |
22-
npm i -g yarn
23-
yarn install
24-
yarn test:unit
22+
npm install
23+
npm run test:unit
2524
env:
2625
CI: true
2726
VUE_APP_PUBLIC_KEY: ${{ secrets.ik_public_key }}

.github/workflows/npmpublish.yml

Lines changed: 29 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -4,50 +4,46 @@ on:
44
release:
55
types: [published]
66

7-
87
jobs:
98
build:
10-
119
runs-on: ubuntu-latest
1210

1311
strategy:
1412
matrix:
1513
node-version: [8.x, 10.x, 12.x]
1614

1715
steps:
18-
- uses: actions/checkout@v1
19-
- name: Use Node.js ${{ matrix.node-version }}
20-
uses: actions/setup-node@v1
21-
with:
22-
node-version: ${{ matrix.node-version }}
23-
- name: npm install, build, and test
24-
run: |
25-
npm i -g yarn
26-
yarn
27-
yarn test:unit
28-
yarn build
29-
env:
30-
CI: true
31-
VUE_APP_PUBLIC_KEY: ${{ secrets.ik_public_key }}
32-
VUE_APP_PRIVATE_KEY: ${{ secrets.ik_private_key }}
33-
VUE_APP_URL_ENDPOINT: ${{ secrets.ik_url_endopint }}
16+
- uses: actions/checkout@v1
17+
- name: Use Node.js ${{ matrix.node-version }}
18+
uses: actions/setup-node@v1
19+
with:
20+
node-version: ${{ matrix.node-version }}
21+
- name: npm install, build, and test
22+
run: |
23+
npm i
24+
npm run test:unit
25+
npm run build
26+
env:
27+
CI: true
28+
VUE_APP_PUBLIC_KEY: ${{ secrets.ik_public_key }}
29+
VUE_APP_PRIVATE_KEY: ${{ secrets.ik_private_key }}
30+
VUE_APP_URL_ENDPOINT: ${{ secrets.ik_url_endopint }}
3431

3532
publish:
3633
needs: build
3734
runs-on: ubuntu-latest
3835
steps:
39-
- uses: actions/checkout@v1
40-
- uses: actions/setup-node@v1
41-
with:
42-
node-version: 12
43-
registry-url: https://registry.npmjs.org/
44-
- name: yarn publish
45-
run: |
46-
npm i -g yarn
47-
yarn
48-
yarn build
49-
yarn config set //registry.npmjs.org/:_authToken=$NODE_AUTH_TOKEN
50-
yarn publish
51-
env:
52-
NODE_AUTH_TOKEN: ${{secrets.npm_token}}
53-
CI: true
36+
- uses: actions/checkout@v1
37+
- uses: actions/setup-node@v1
38+
with:
39+
node-version: 12
40+
registry-url: https://registry.npmjs.org/
41+
- name: npm publish
42+
run: |
43+
npm i
44+
npm run build
45+
npm config set //registry.npmjs.org/:_authToken=$NODE_AUTH_TOKEN
46+
npm publish
47+
env:
48+
NODE_AUTH_TOKEN: ${{secrets.npm_token}}
49+
CI: true

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,3 @@ node_modules
33
.vscode/launch.json
44
.env
55
/dist
6-
tests/__snapshots__

DEVELOPMENT.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
## Building package
2+
3+
Execute following command from the root folder to build the library. This creates a package in `dist` folder.
4+
```sh
5+
npm install # for first time
6+
npm run build
7+
```
8+
9+
## Running test cases
10+
11+
The designated directory for tests is `/tests` folder. All tests will be run against the assertion present in the `/tests/__snapshot__` folder. To create this file you need to just run below command just once. Any update in the tests can be updated to by pressing `u` while the test environment is running.
12+
13+
Execute following command from the root folder to start testing.
14+
```sh
15+
npm run test:dev
16+
```
17+
18+
## Running sample frontend Vue app
19+
20+
Please refer to the sample app `Readme.md` for details.
21+
22+
## Running sample backend server
23+
24+
Please refer to the sample app `Readme.md` for details.

README.md

Lines changed: 98 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -5,64 +5,82 @@
55
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
66
[![Twitter Follow](https://img.shields.io/twitter/follow/imagekitio?label=Follow&style=social)](https://twitter.com/ImagekitIo)
77

8-
Vue SDK for [ImageKit.io](https://imagekit.io) which implements client-side upload and URL generation for use inside a vue application.
8+
Vue SDK for [ImageKit.io](https://imagekit.io), which implements client-side upload and URL generation for use inside a vue application.
99

10-
ImageKit is a complete image optimization and transformation solution that comes with an [image CDN](https://imagekit.io/features/imagekit-infrastructure) and media storage. It can be integrated with your existing infrastructure - storages like AWS S3, web servers, your CDN and custom domain names, allowing you to deliver optimized images in minutes with minimal code changes.
10+
ImageKit is a complete image optimization and transformation solution that comes with an [image CDN](https://imagekit.io/features/imagekit-infrastructure) and media storage. 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.
1111

1212
## Installation
1313

14-
`npm install --save imagekitio-vue`
14+
`npm install --save imagekitio-vue`
1515

1616
Include the components in your code:
1717

18-
`import {IKContext} from "imagekitio-vue"`
18+
`import {IKContext} from "imagekitio-vue"`
1919

2020
## Usage
2121

2222
The library includes 3 Components:
2323
* [IKContext](#IKContext)
2424

25-
* [IKImage](#IKImage)
25+
* [IKImage - URL generation](#ikimage---url-generation)
2626

27-
* [IKUpload](#file-upload)
27+
* [IKUpload - File upload](#ikupload---file-upload)
2828

2929
### IKContext
3030

3131
In order to use the SDK, you need to provide it with a few configuration parameters. The configuration parameters can be applied directly to the `Image` component or using an `IKContext` component. example:
3232

3333
```js
34-
template: <IKContext publicKey="your_public_api_key" urlEndpoint="<https://ik.imagekit.io/your_imagekit_id>"><IKImage src="<full_image_url_from_db>"/></IKContext>
34+
<IKContext
35+
publicKey="your_public_api_key"
36+
urlEndpoint="<https://ik.imagekit.io/your_imagekit_id>">
37+
<IKImage src="<full_image_url_from_db>"/>
38+
</IKContext>
3539
```
3640

3741
`publicKey` and `urlEndpoint` are mandatory parameters for SDK initialization.
3842
`authenticationEndpoint` is essential if you want to use the SDK for client-side uploads.
39-
`transformationPosition` is optional. The default value for the parametere is `path`. Acceptable values are `path` & `query`
43+
`transformationPosition` is optional. The default value for this parameter is `path`. Acceptable values are `path` & `query`
4044

41-
_Note: Do not include your Private Key in any client side code, including this SDK or its initialization. If you pass the `privateKey` parameter while initializing this SDK, it throws an error_
45+
_Note: Do not include your Private Key in any client-side code, including this SDK or its initialization. If you pass the `privateKey` parameter while initializing this SDK, it throws an error_
4246

43-
### IKImage
47+
### IKImage - URL generation
4448

45-
The image component component defines a ImageKit Image tag. example usage:
49+
The image component defines an IKImage tag. Example usage:
4650

4751
#### Using image path and image hostname or endpoint
4852

4953
```js
50-
template: '<IKImage publicKey="your_public_api_key" urlEndpoint="https://ik.imagekit.io/your_imagekit_id" path="/path_to_file"/>'
54+
<IKImage
55+
publicKey="your_public_api_key"
56+
urlEndpoint="https://ik.imagekit.io/your_imagekit_id"
57+
path="/path_to_file"/>
58+
```
5159

52-
```
5360
#### Using full image URL
5461

55-
```js
56-
template: '<IKImage publicKey="your_public_api_key" urlEndpoint="https://ik.imagekit.io/your_imagekit_id" src="<full_image_url_from_db>"/>'
57-
```
58-
59-
`src` is the complete URL that is already mapped to ImageKit.
60-
`path` is the location of the image in the ImageKit cloud. `urlEndpoint` + `path` makes the complete url.
61-
`transformations` is optional. The transformations to be applied to a given image. It is declared in the form of an array of objects, where each object specifies the transformation you need. The values are mentioned below.
62+
```js
63+
<IKImage
64+
publicKey="your_public_api_key"
65+
urlEndpoint="https://ik.imagekit.io/your_imagekit_id"
66+
src="<full_image_url_from_db>"/>'
67+
```
68+
69+
#### Supported options:
70+
71+
| Option | Description |
72+
| :----------------| :----------------------------- |
73+
| urlEndpoint | Optional. The base URL to be appended before the path of the image. If not specified, the URL Endpoint specified at the time of SDK initialization is used. For example, https://ik.imagekit.io/your_imagekit_id/endpoint/ |
74+
| path | Conditional. This is the path at which the image exists. For example, `/path/to/image.jpg`. Either the `path` or `src` parameter need to be specified for URL generation. |
75+
| src | Conditional. This is the complete URL of an image already mapped to ImageKit. For example, `https://ik.imagekit.io/your_imagekit_id/endpoint/path/to/image.jpg`. Either the `path` or `src` parameter need to be specified for URL generation. |
76+
| transformation | Optional. An array of objects specifying the transformation to be applied in the URL. The transformation name and the value should be specified as a key-value pair in the object. Different steps of a [chained transformation](https://docs.imagekit.io/features/image-transformations/chained-transformations) can be specified as different objects of the array. The complete list of supported transformations in the SDK and some examples of using them are given later. If you use a transformation name that is not specified in the SDK, it gets applied as it is in the URL. |
77+
| transformationPostion | Optional. The default value is `path` that places the transformation string as a path parameter in the URL. It can also be specified as `query` which adds the transformation string as the query parameter `tr` in the URL. If you use `src` parameter to create the URL, then the transformation string is always added as a query parameter. |
78+
| queryParameters | Optional. These are the other query parameters that you want to add to the final URL. These can be any query parameters and not necessarily related to ImageKit. Especially useful if you want to add some versioning parameter to your URLs. |
79+
6280
6381
#### List of supported transformations
6482
65-
The complete list of transformations supported and their usage in ImageKit can be found [here](https://docs.imagekit.io/imagekit-docs/image-transformations). The SDK gives a name to each transformation parameter, making the code simpler and readable. If a transformation is supported in ImageKit, but a name for it cannot be found in the table below, then use the transformation code from ImageKit docs as the name when using in the `url` function.
83+
The complete list of transformations supported and their usage in ImageKit can be found [here](https://docs.imagekit.io/features/image-transformations). The SDK gives a name to each transformation parameter, making the code simpler and readable. If a transformation is supported in ImageKit, but a name for it cannot be found in the table below, then use the transformation code from ImageKit docs as the name when using in the `url` function.
6684
6785
| Supported Transformation Name | Translates to parameter |
6886
| ----------------------------- | ----------------------- |
@@ -112,42 +130,87 @@ The complete list of transformations supported and their usage in ImageKit can b
112130
#### Applying Transforms
113131
```js
114132
115-
template: '<IKImage publicKey="your_public_api_key" urlEndpoint="https://ik.imagekit.io/gqyojxcwzxj/" src="<full_image_url_from_db>" v-bind:transformation="[{height:300,width:400}]" />'
133+
<IKImage
134+
publicKey="your_public_api_key"
135+
urlEndpoint="https://ik.imagekit.io/gqyojxcwzxj/"
136+
src="<full_image_url_from_db>"
137+
v-bind:transformation="[{height:300,width:400}]" />
116138
```
117139
The above image will apply transformation of width = 90 and height = 180 on the image. Since some transformatinos are destructive you might want to control the order in which the transforms are applied.
118140
119141
##### Chained Transforms
120142
Chained transforms make it easy to specify the order the transform are applied. example:
121143
122144
```js
123-
template: '<IKImage publicKey="your_public_api_key" urlEndpoint="https://ik.imagekit.io/your_imagekit_id" src="<full_image_url_from_db>" v-bind:transformation="[{height:300,width:400},{rotation:90}]"
145+
<IKImage
146+
publicKey="your_public_api_key"
147+
urlEndpoint="https://ik.imagekit.io/your_imagekit_id"
148+
src="<full_image_url_from_db>"
149+
v-bind:transformation="[{height:300,width:400},{rotation:90}]" />
124150
```
125151
In the above case, rotation will be performed first and resizing according to width and aspect ratio will be performed afterwards.
126152
127-
#### Low Quality Image Placeholders (LQIP) for images
128-
The SDK supports automatic support for LQIP for your images, if you set lqip to true in the image component. example:
153+
#### Low-Quality Image Placeholders (LQIP) for images
154+
The SDK supports automatic support for LQIP for your images if you set lqip to true in the image component. example:
155+
156+
```js
157+
<IKImage
158+
publicKey="your_public_api_key"
159+
urlEndpoint="https://ik.imagekit.io/your_imagekit_id"
160+
v-bind:lqip="{active:true,threshold:20}" />
161+
```
129162
130-
```js
131-
<IKImage publicKey="your_public_api_key" urlEndpoint="https://ik.imagekit.io/your_imagekit_id" v-bind:lqip="{active:true,threshold:20}"/>
132-
```
133-
`active` tells the status for lqip, it can be either, `true` or `false`
134-
`threshold` decided the quaility of placeholder image. It can be any numeric value, a low number means low quality, and high number means high quality.
163+
`active` tells the status for lqip. It can be either, `true` or `false`.
164+
`threshold` decides the quality of the placeholder image. It can be any numeric value, a low number means low quality, and a high number means high quality.
135165
136166
##### How does the lqip work?
137-
The component tries to keep the it simple, it loads a lower quality image using the quality parameter to load a lower quality image, which is then replaced with the actual quality image later.
167+
The component tries to keep it simple. It loads a lower quality image using the quality parameter to load a lower quality image, which is then replaced with the actual quality image later.
138168
139-
#### File Upload
169+
### IKUpload - File Upload
140170
The SDK provides a simple Component to upload files to the ImageKit Media Library. It accepts `fileName` parameter as a prop. The file parameter is provided as an input from the user.
141171
142-
Also make sure that you have specified `authenticationEndpoint` during SDK initialization. The SDK makes an HTTP GET request to this endpoint and expects a JSON response with three fields i.e. `signature`, `token` and `expire`.
172+
Also, make sure that you have specified `authenticationEndpoint` during SDK initialization. The SDK makes an HTTP GET request to this endpoint and expects a JSON response with three fields i.e. `signature`, `token` and `expire`.
143173
144174
[Learn how to implement authenticationEndpoint](https://docs.imagekit.io/api-reference/upload-file-api/client-side-file-upload#how-to-implement-authenticationendpoint-endpoint) on your server.
145175
146176
An example of this server is provided in the samples folder of the SDK.
147177
148178
Sample Usage
149179
```js
150-
template: '<IKContext publicKey="your_public_api_key" urlEndpoint="https://ik.imagekit.io/your_imagekit_id" authenticationEndpoint="http://www.yourserver.com/auth"><IKUpload fileName="your_desired_filename"/></IKContext>'
180+
<IKContext
181+
publicKey="your_public_api_key"
182+
urlEndpoint="https://ik.imagekit.io/your_imagekit_id"
183+
authenticationEndpoint="http://www.yourserver.com/auth">
184+
<IKUpload fileName="your_desired_filename"/>
185+
</IKContext>
186+
```
187+
188+
`IKUpload` component accepts all the parameters supported by the [ImageKit Upload API](https://docs.imagekit.io/api-reference/upload-file-api/client-side-file-upload#request-structure-multipart-form-data) e.g. `tags`, `useUniqueFileName`, `folder` etc.
189+
190+
You can also use `onSuccess` and `onError` callbacks to handle success and falure respectively, you can simply pass your custom functions to handle the response from API.
191+
192+
```js
193+
template: `<IKContext publicKey="${publicKey}" urlEndpoint="https://ik.imagekit.io/your_imagekit_id" authenticationEndpoint="http://www.yourserver.com/auth"><IKUpload fileName="your_desired_filename" :onError="onError" :onSuccess = "onSuccess" /></IKContext>`,
194+
195+
methods: {
196+
onError(err) {
197+
console.log(err);
198+
}, onSuccess(res) {
199+
console.log(res);
200+
}},
151201
```
152202
153-
`IKUpload` component accepts all the parameters supported by the [ImageKit Upload API](https://docs.imagekit.io/api-reference/upload-file-api/client-side-file-upload#request-structure-multipart-form-data) as props e.g. `tags`, `useUniqueFileName`, `folder` etc.
203+
## Demo Application
204+
The fastest way to get started is by running the demo application. You can run the code locally. The source code is in samples/sample-app. For the instructions in [readme.md](https://github.com/imagekit-developer/imagekit-vuejs/blob/master/samples/sample-app/README.md) file within [samples/sample-app](https://github.com/imagekit-developer/imagekit-vuejs/tree/master/samples/sample-app) folder.
205+
206+
## Support
207+
208+
For any feedback or to report any issues or general implementation support please reach out to [[email protected]](mailto:[email protected])
209+
210+
## Links
211+
* [Documentation](https://docs.imagekit.io)
212+
* [Main website](https://imagekit.io)
213+
214+
## License
215+
216+
Released under the MIT license.

example/sample-app/sample.env

Lines changed: 0 additions & 3 deletions
This file was deleted.

example/sample-app/server/sample.env

Lines changed: 0 additions & 1 deletion
This file was deleted.

package-lock.json

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
{
22
"name": "imagekitio-vue",
3-
"version": "1.0.2",
3+
"version": "1.0.3",
44
"scripts": {
55
"build:lib": "./node_modules/.bin/vue-cli-service build --target lib src/index.js",
66
"build": "./node_modules/.bin/vue-cli-service lint --fix; npm run build:lib",
77
"serve": "./node_modules/.bin/vue-cli-service serve",
88
"lint": "./node_modules/.bin/vue-cli-service lint",
9-
"test:unit": "./node_modules/.bin/vue-cli-service test:unit -u",
9+
"test:unit": "export VUE_APP_PUBLIC_KEY=your_public_key;export VUE_APP_URL_ENDPOINT=https://ik.imagekit.io/your_imagekit_id;export VUE_APP_AUTHENTICATION_ENDPOINT=https://www.example.com/auth;./node_modules/.bin/vue-cli-service test:unit --watchAll=false;unset VUE_APP_PUBLIC_KEY;unset VUE_APP_URL_ENDPOINT;unset VUE_APP_AUTHENTICATION_ENDPOINT",
10+
"test:dev": "export VUE_APP_PUBLIC_KEY=your_public_key;export VUE_APP_URL_ENDPOINT=https://ik.imagekit.io/your_imagekit_id;export VUE_APP_AUTHENTICATION_ENDPOINT=https://www.example.com/auth;./node_modules/.bin/vue-cli-service test:unit --watchAll=true;unset VUE_APP_PUBLIC_KEY;unset VUE_APP_URL_ENDPOINT;unset VUE_APP_AUTHENTICATION_ENDPOINT",
1011
"storybook": "start-storybook -p 6006",
1112
"build-storybook": "build-storybook"
1213
},
@@ -23,7 +24,7 @@
2324
"dependencies": {
2425
"babel-plugin-require-context-hook": "^1.0.0",
2526
"core-js": "^3.4.3",
26-
"imagekit-javascript": "^1.0.3",
27+
"imagekit-javascript": "^1.2.0",
2728
"jest-vue-preprocessor": "^1.7.0",
2829
"vue": "^2.6.11"
2930
},

0 commit comments

Comments
 (0)