nzk-react-components 0.4.2 → 0.4.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -5,6 +5,6 @@ export interface Props {
5
5
  }
6
6
  declare const useCloudinary: (props?: Props | undefined) => {
7
7
  uploadImage: (file: Blob | string, onComplete?: ((imageUrl: string) => void) | undefined) => void;
8
- promiseUploadImage: (file: Blob | string) => Promise<unknown>;
8
+ promiseUploadImage: (file: Blob | string) => Promise<string>;
9
9
  };
10
10
  export default useCloudinary;
@@ -44,23 +44,22 @@ var useCloudinary = function (props) {
44
44
  var xhr = new XMLHttpRequest();
45
45
  var fd = new FormData();
46
46
  xhr.addEventListener('error', function () {
47
- reject(new Error("Couldn't reach cloudinary to upload image"));
47
+ return reject(new Error("Couldn't reach cloudinary to upload image"));
48
48
  });
49
49
  xhr.open('POST', url, true);
50
50
  xhr.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
51
51
  xhr.onreadystatechange = function () {
52
- if (xhr.readyState === 4 && xhr.status < 300) {
52
+ if (xhr.readyState === 4 && xhr.status >= 200 && xhr.status < 300) {
53
53
  var response = JSON.parse(xhr.responseText);
54
- if (response.secure_url) {
55
- resolve(response.secure_url);
56
- }
57
- else {
58
- reject(new Error("No secure_url returned by cloudinary"));
54
+ if (!response.secure_url) {
55
+ return reject(new Error("No secure_url returned by cloudinary"));
59
56
  }
57
+ return resolve(response.secure_url);
60
58
  }
61
- else if (xhr.readyState === 4 && xhr.status >= 300) {
62
- reject(new Error("Cloudinary returned error code: " + xhr.status));
59
+ if (xhr.readyState === 4 && xhr.status >= 300) {
60
+ return reject(new Error("Cloudinary returned error code: " + xhr.status));
63
61
  }
62
+ return null;
64
63
  };
65
64
  fd.append('upload_preset', unsignedUploadPreset);
66
65
  if (uploadTag)
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nzk-react-components",
3
- "version": "0.4.2",
3
+ "version": "0.4.3",
4
4
  "license": "MIT",
5
5
  "main": "dist/index.js",
6
6
  "files": [