@sendsafely/sendsafely 1.1.6 → 1.1.8

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.
Files changed (2) hide show
  1. package/lib/SendSafely.js +50 -1
  2. package/package.json +1 -1
package/lib/SendSafely.js CHANGED
@@ -353,7 +353,7 @@ function SendSafely(url, apiKeyId, apiKeySecret, requestAPI){
353
353
  };
354
354
 
355
355
  this.shouldNotifyRecipients = function() {
356
- var notifyRecipients = (myself.notifyRecipients === undefined) ? true : myself.notifyRecipients;
356
+ var notifyRecipients = (myself.notifyRecipients === undefined) ? false : myself.notifyRecipients;
357
357
  return notifyRecipients;
358
358
  };
359
359
 
@@ -916,6 +916,21 @@ function SendSafely(url, apiKeyId, apiKeySecret, requestAPI){
916
916
  handler.execute(ciphertext, packageId, keyCode, serverSecret, finished);
917
917
  };
918
918
 
919
+ /**
920
+ * Gets a given package's message for use based on package id and checksum provided
921
+ * @param packageId {String} The package id of the package.
922
+ * @param packageCode {String} The package code value for the given package
923
+ * @param keyCode {String} The package key code value
924
+ * @param finished {function} function ()
925
+ * @fires {sendsafely#error}
926
+ * @returns {void}
927
+ */
928
+ this.getPackageMessage = function (packageId, packageCode, keyCode, finished) {
929
+ try { this.checkAPIInitialized();}
930
+ catch (err) {myself.eventHandler.raiseError(myself.NOT_INITIALIZED_ERROR, err.message); return;}
931
+ new GetPackageMessage(myself.eventHandler, myself.request).execute(packageId, packageCode, keyCode, myself.async, finished);
932
+ };
933
+
919
934
  /*
920
935
  * INTERNAL FUNCTIONS BELOW THIS POINT
921
936
  */
@@ -4797,6 +4812,40 @@ function VerifyVersion (eventHandler, request) {
4797
4812
 
4798
4813
  }
4799
4814
 
4815
+ function GetPackageMessage (eventHandler, request) {
4816
+ this.request = request;
4817
+ this.endpoint = { "url": '/package/{packageId}/message/{checksum}', "HTTPMethod" : "GET", "mimetype": "application/json"};
4818
+ this.eventHandler = eventHandler;
4819
+ this.customErrorEvent = 'package.message.failed';
4820
+ this.responseParser = new ResponseParser(eventHandler);
4821
+ var myself = this;
4822
+ this.execute = function (packageId, packageCode, keyCode, async, finished) {
4823
+ var checksum = createChecksum(keyCode, packageCode);
4824
+ if (packageId === undefined) {
4825
+ throw new Error("Unable to get package message without package ID");
4826
+ } else if (checksum === undefined) {
4827
+ throw new Error("Unable to get package message without checksum");
4828
+ } else {
4829
+ var endpoint = myself.request.extend({}, myself.endpoint);
4830
+ endpoint.url = endpoint.url.replace("{packageId}", packageId);
4831
+ endpoint.url = endpoint.url.replace("{checksum}", checksum);
4832
+ var response = myself.request.sendRequest(endpoint, null, async);
4833
+ myself.responseParser.processAjaxData(response, function (res) {
4834
+ var data = {};
4835
+ data.message = res.message;
4836
+ finished(data);
4837
+ }, myself.customErrorEvent);
4838
+ }
4839
+ }
4840
+
4841
+ function createChecksum(keyCode, packageCode) {
4842
+ keyCode = sjcl.codec.utf8String.toBits(urlSafeBase64(keyCode));
4843
+ packageCode = sjcl.codec.utf8String.toBits(urlSafeBase64(packageCode));
4844
+
4845
+ return sjcl.codec.hex.fromBits(sjcl.misc.pbkdf2(keyCode, packageCode, 1024, 256));
4846
+ }
4847
+ }
4848
+
4800
4849
  SendSafely.SendSafelyDropzone = function SendSafelyDropzone(url, dropzoneId) {
4801
4850
  const myself = new SendSafely(url, dropzoneId, null);
4802
4851
  myself.notifyRecipients = false;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sendsafely/sendsafely",
3
- "version": "1.1.6",
3
+ "version": "1.1.8",
4
4
  "main": "./lib/SendSafely.js",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1"