Skip to content

Commit dbfa380

Browse files
committed
optional params and its related fixes
1 parent 31fa2dc commit dbfa380

File tree

7 files changed

+18
-27
lines changed

7 files changed

+18
-27
lines changed

src/constants/errorMessages.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ export default {
66
MISSING_UPLOAD_FILE_PARAMETER: { message: "Missing file parameter for upload", help: "" },
77
MISSING_UPLOAD_FILENAME_PARAMETER: { message: "Missing fileName parameter for upload", help: "" },
88
MISSING_AUTHENTICATION_ENDPOINT: { message: "Missing authentication endpoint for upload", help: "" },
9+
MISSING_PUBLIC_KEY : { message: "Missing public key for upload", help: "" },
910
AUTH_ENDPOINT_TIMEOUT: { message: "The authenticationEndpoint you provided timed out in 60 seconds", help: "" },
1011
AUTH_ENDPOINT_NETWORK_ERROR: { message: "Request to authenticationEndpoint failed due to network error", help: "" },
1112
UPLOAD_ENDPOINT_NETWORK_ERROR: {

src/index.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { upload } from "./upload/index";
33
import { version } from "../package.json";
44
import transformationUtils from "./utils/transformation";
55
import errorMessages from "./constants/errorMessages";
6-
import { IImageKit, ImageKitOptions, TransformationPosition, UploadOptions, UploadResponse, UrlOptions } from "./interfaces";
6+
import { IImageKit, ImageKitOptions, UploadOptions, UploadResponse, UrlOptions } from "./interfaces";
77

88
function mandatoryParametersAvailable(options: ImageKitOptions) {
99
return options.urlEndpoint;
@@ -15,12 +15,7 @@ function privateKeyPassed(options: ImageKitOptions) {
1515

1616
const ImageKit = function (
1717
this: IImageKit,
18-
opts: {
19-
publicKey: string;
20-
urlEndpoint: string;
21-
authenticationEndpoint?: string;
22-
transformationPosition?: TransformationPosition;
23-
},
18+
opts: ImageKitOptions,
2419
) {
2520
opts = opts || {};
2621
this.options = {

src/interfaces/ImageKitOptions.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import { TransformationPosition } from ".";
22

33
export interface ImageKitOptions {
4-
sdkVersion: string;
5-
publicKey: string;
64
urlEndpoint: string;
5+
sdkVersion?: string;
6+
publicKey?: string;
77
authenticationEndpoint?: string;
8-
transformationPosition: TransformationPosition;
8+
transformationPosition?: TransformationPosition;
99
}

src/interfaces/UrlOptions.ts

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,6 @@ export interface UrlOptionsBase {
2525
* If not specified, the URL Endpoint specified at the time of SDK initialization is used.
2626
*/
2727
urlEndpoint?: string;
28-
/**
29-
* Default is false. If set to true, the SDK generates a signed image URL adding the image signature to the image URL.
30-
* If you are creating URL using src parameter instead of path then do correct urlEndpoint for this to work.
31-
* Otherwise returned URL will have wrong signature.
32-
*/
33-
signed?: boolean;
34-
/**
35-
* Meant to be used along with the signed parameter to specify the time in seconds from now when the URL should expire.
36-
* If specified, the URL contains the expiry timestamp in the URL and the image signature is modified accordingly.
37-
*/
38-
expireSeconds?: number;
3928
}
4029

4130
export interface UrlOptionsSrc extends UrlOptionsBase {

src/upload/index.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ export const upload = (
2828
return;
2929
}
3030

31+
if (!options.publicKey) {
32+
respond(true, errorMessages.MISSING_PUBLIC_KEY, callback);
33+
return;
34+
}
35+
3136
var formData = new FormData();
3237
let i: keyof typeof uploadOptions;
3338
for (i in uploadOptions) {

src/utils/request.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ export const uploadFile = (formData: FormData, callback: (err: Error | null, res
7878
else if (uploadFileXHR.status !== 200) {
7979
try {
8080
callback(JSON.parse(uploadFileXHR.responseText), null);
81-
} catch (ex) {
81+
} catch (ex : any) {
8282
callback(ex, null);
8383
}
8484
}

src/utils/transformation.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import supportedTransforms from "../constants/supportedTransforms";
22
import { ImageKitOptions, TransformationPosition } from "../interfaces";
33

4-
const DEFAULT_TRANSFORMATION_POSITION = "path";
5-
const QUERY_TRANSFORMATION_POSITION = "query";
4+
const DEFAULT_TRANSFORMATION_POSITION : TransformationPosition = "path";
5+
const QUERY_TRANSFORMATION_POSITION : TransformationPosition = "query";
66
const VALID_TRANSFORMATION_POSITIONS = [DEFAULT_TRANSFORMATION_POSITION, QUERY_TRANSFORMATION_POSITION];
7-
const CHAIN_TRANSFORM_DELIMITER = ":";
8-
const TRANSFORM_DELIMITER = ",";
9-
const TRANSFORM_KEY_VALUE_DELIMITER = "-";
7+
const CHAIN_TRANSFORM_DELIMITER : string = ":";
8+
const TRANSFORM_DELIMITER : string = ",";
9+
const TRANSFORM_KEY_VALUE_DELIMITER : string = "-";
1010

1111
export default {
1212
getDefault: (): TransformationPosition => {
@@ -16,6 +16,7 @@ export default {
1616
return options.transformationPosition === QUERY_TRANSFORMATION_POSITION;
1717
},
1818
validParameters: (options: ImageKitOptions) => {
19+
if(typeof options.transformationPosition == "undefined") return false;
1920
return VALID_TRANSFORMATION_POSITIONS.indexOf(options.transformationPosition) != -1;
2021
},
2122
getTransformKey: function (transform: string) {

0 commit comments

Comments
 (0)