@sendsafely/sendsafely 1.1.8 → 1.1.9
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.
- package/lib/SendSafely.js +30 -0
- package/package.json +1 -1
package/lib/SendSafely.js
CHANGED
|
@@ -42,6 +42,7 @@ function SendSafely(url, apiKeyId, apiKeySecret, requestAPI){
|
|
|
42
42
|
this.uploadAPI = undefined;
|
|
43
43
|
this.url = url;
|
|
44
44
|
this.requestAPI = (requestAPI === undefined) ? "NODE_API" : requestAPI;
|
|
45
|
+
this.wrapperRequest = new FetchRequest({url: url, apiKey: apiKeyId, apiKeySecret: apiKeySecret});
|
|
45
46
|
|
|
46
47
|
sjcl.codec.utf8String.fromBits = function(a) {
|
|
47
48
|
var b = "",
|
|
@@ -969,6 +970,35 @@ function SendSafely(url, apiKeyId, apiKeySecret, requestAPI){
|
|
|
969
970
|
new FeedbackHandler(myself.eventHandler, myself.request).execute(log, stacktrace, systemInfo, myself.async);
|
|
970
971
|
};
|
|
971
972
|
|
|
973
|
+
this.sendSignedRequest = function (endpoint, HTTPMethod, mimeType, requestData, successCallback, customErrorEvent) {
|
|
974
|
+
this.wrapperRequest.sendSignedRequest({
|
|
975
|
+
url: endpoint,
|
|
976
|
+
HTTPMethod: HTTPMethod.toUpperCase(),
|
|
977
|
+
mimetype: mimeType
|
|
978
|
+
}, requestData)
|
|
979
|
+
.then(function (response) {
|
|
980
|
+
if (response.status === 200) {
|
|
981
|
+
// Success
|
|
982
|
+
return response.json();
|
|
983
|
+
} else {
|
|
984
|
+
// HTTP request error
|
|
985
|
+
myself.eventHandler.raiseError(response.status, response.error, customErrorEvent);
|
|
986
|
+
}
|
|
987
|
+
}).then(function (responseData) {
|
|
988
|
+
if (responseData.hasOwnProperty('response') && responseData.response.toUpperCase() === 'SUCCESS') {
|
|
989
|
+
if (successCallback !== undefined) {
|
|
990
|
+
successCallback(responseData);
|
|
991
|
+
}
|
|
992
|
+
} else {
|
|
993
|
+
// SendSafely server returned an error for the user
|
|
994
|
+
myself.eventHandler.raiseError(responseData.response, responseData.message, customErrorEvent);
|
|
995
|
+
}
|
|
996
|
+
}).catch(function (error) {
|
|
997
|
+
// catch errors thrown by fetch
|
|
998
|
+
myself.eventHandler.raiseError(error.code, error.message, customErrorEvent);
|
|
999
|
+
});
|
|
1000
|
+
}
|
|
1001
|
+
|
|
972
1002
|
}
|
|
973
1003
|
|
|
974
1004
|
//Other Functions
|