Skip to content

Commit b5a5b24

Browse files
committed
moved all js files to ts
1 parent 8aeef4a commit b5a5b24

27 files changed

+480
-272
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@ node_modules/*
33
.nyc_output
44
coverage.lcov
55
coverage
6-
.DS_Store
6+
.DS_Store
7+
dist/*

index.ts

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
/*
22
Helper Modules
33
*/
4-
var _ = require('lodash');
4+
import _ from "lodash";
55

66
/*
77
Implementations
88
*/
9-
var url = require('./libs/url');
10-
var upload = require('./libs/upload');
11-
var manage = require('./libs/manage');
12-
var signature = require('./libs/signature');
9+
import url from "./libs/url";
10+
import upload from "./libs/upload";
11+
import manage from "./libs/manage";
12+
import signature from "./libs/signature";
1313

1414
/*
1515
Utils
@@ -22,7 +22,6 @@ import { IKCallback } from "./libs/interfaces/IKCallback";
2222
import {
2323
IImageKit,
2424
ImageKitOptions,
25-
TransformationPosition,
2625
UploadOptions,
2726
UploadResponse,
2827
UrlOptions,
@@ -35,12 +34,7 @@ import {
3534

3635
var ImageKit = function(
3736
this: IImageKit,
38-
opts: {
39-
publicKey: string;
40-
privateKey: string;
41-
urlEndpoint: string;
42-
transformationPosition?: TransformationPosition;
43-
},
37+
opts: ImageKitOptions,
4438
) {
4539
opts = opts || {};
4640
this.options = {

libs/interfaces/IKCallback.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
export interface IKCallback<T, E extends Error = Error> {
2-
(error?: E, response?: T): void;
2+
(err: E | null, response: T): void;
33
}

libs/interfaces/UploadOptions.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export interface UploadOptions {
1212
* Downloading file from URL might take longer, so it is recommended that you pass the binary or base64 content of the file.
1313
* Pass the full URL, for example - https://www.example.com/rest-of-the-image-path.jpg.
1414
*/
15-
file: string | Buffer | File;
15+
file: string | Buffer;
1616
/**
1717
* The name with which the file has to be uploaded.
1818
* The file name can contain:

libs/interfaces/UrlOptions.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export interface UrlOptionsBase {
1919
* These can be any query parameters and not necessarily related to ImageKit.
2020
* Especially useful, if you want to add some versioning parameter to your URLs.
2121
*/
22-
queryParameters?: { [key: string]: string | number };
22+
queryParameters?: { [key: string]: string };
2323
/**
2424
* The base URL to be appended before the path of the image.
2525
* If not specified, the URL Endpoint specified at the time of SDK initialization is used.

libs/interfaces/index.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { IKCallback } from "./IKCallback";
22
import { ImageKitOptions } from "./ImageKitOptions";
3-
import { TransformationPosition } from "./Transformation";
3+
import { Transformation, TransformationPosition } from "./Transformation";
44
import { UploadOptions } from "./UploadOptions";
55
import { UploadResponse } from "./UploadResponse";
66
import { FileType } from "./FileType";
@@ -222,13 +222,16 @@ export interface IImageKit {
222222
pHashDistance: (firstPHash: string, secondPHash: string) => number;
223223
}
224224

225+
type FinalUrlOptions = ImageKitOptions & UrlOptions; //actual options used to construct url
226+
225227
export {
226228
ImageKitOptions,
227-
TransformationPosition,
229+
Transformation, TransformationPosition,
228230
UploadOptions,
229231
UploadResponse,
230232
FileType,
231233
UrlOptions,
234+
FinalUrlOptions,
232235
ListFileOptions, ListFileResponse,
233236
FileDetailsOptions, FileDetailsResponse,
234237
FileMetadataResponse,

libs/manage/cache.js

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

libs/manage/cache.ts

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/*
2+
Constants
3+
*/
4+
import errorMessages from "../constants/errorMessages";
5+
6+
/*
7+
Utils
8+
*/
9+
import respond from "../../utils/respond";
10+
import request from "../../utils/request";
11+
12+
/*
13+
Interfaces
14+
*/
15+
import { IKCallback } from "../interfaces/IKCallback";
16+
import { ImageKitOptions, PurgeCacheResponse, PurgeCacheStatusResponse } from "../interfaces/";
17+
18+
const purgeCache = function(
19+
url : string,
20+
defaultOptions : ImageKitOptions,
21+
callback? : IKCallback<PurgeCacheResponse>
22+
) {
23+
if(!url) {
24+
respond(true, errorMessages.CACHE_PURGE_URL_MISSING, callback);
25+
return;
26+
}
27+
28+
var requestOptions = {
29+
url : "https://api.imagekit.io/v1/files/purge",
30+
method : "POST",
31+
json : {
32+
"url" : url
33+
}
34+
};
35+
36+
request(requestOptions, defaultOptions, callback);
37+
};
38+
39+
const getPurgeCacheStatus = function(
40+
requestId : string,
41+
defaultOptions : ImageKitOptions,
42+
callback? : IKCallback<PurgeCacheStatusResponse>
43+
) {
44+
if(!requestId) {
45+
respond(true, errorMessages.CACHE_PURGE_STATUS_ID_MISSING, callback);
46+
return;
47+
}
48+
49+
var requestOptions = {
50+
url : "https://api.imagekit.io/v1/files/purge/" + requestId,
51+
method : "GET",
52+
json : true
53+
};
54+
55+
request(requestOptions, defaultOptions, callback);
56+
};
57+
58+
export default { purgeCache, getPurgeCacheStatus }

0 commit comments

Comments
 (0)