@eluvio/elv-client-js 3.2.40 → 3.2.42
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/dist/ElvClient-min.js +4 -4
- package/dist/ElvClient-node-min.js +6 -6
- package/dist/ElvWalletClient-min.js +4 -4
- package/dist/ElvWalletClient-node-min.js +9 -9
- package/dist/src/AuthorizationClient.js +507 -599
- package/dist/src/client/ContentManagement.js +153 -54
- package/dist/src/walletClient/Notifications.js +196 -0
- package/dist/src/walletClient/index.js +1 -0
- package/package.json +1 -1
- package/src/AuthorizationClient.js +0 -43
- package/src/client/ContentAccess.js +0 -1
- package/src/client/ContentManagement.js +72 -10
- package/src/walletClient/Notifications.js +109 -0
- package/src/walletClient/index.js +1 -0
|
@@ -20,6 +20,8 @@ var UrlJoin = require("url-join");
|
|
|
20
20
|
var ImageType = require("image-type");
|
|
21
21
|
|
|
22
22
|
var Ethers = require("ethers");
|
|
23
|
+
|
|
24
|
+
var Pako = require("pako");
|
|
23
25
|
/*
|
|
24
26
|
const LibraryContract = require("../contracts/BaseLibrary");
|
|
25
27
|
const ContentContract = require("../contracts/BaseContent");
|
|
@@ -1283,10 +1285,11 @@ exports.CopyContentObject = /*#__PURE__*/function () {
|
|
|
1283
1285
|
}
|
|
1284
1286
|
|
|
1285
1287
|
_context13.next = 38;
|
|
1286
|
-
return this.
|
|
1288
|
+
return this.CreateEncryptionConk({
|
|
1289
|
+
libraryId: libraryId,
|
|
1287
1290
|
objectId: objectId,
|
|
1288
|
-
|
|
1289
|
-
|
|
1291
|
+
writeToken: writeToken,
|
|
1292
|
+
createKMSConk: true
|
|
1290
1293
|
});
|
|
1291
1294
|
|
|
1292
1295
|
case 38:
|
|
@@ -2633,6 +2636,103 @@ exports.UpdateContentObjectGraph = /*#__PURE__*/function () {
|
|
|
2633
2636
|
return _ref52.apply(this, arguments);
|
|
2634
2637
|
};
|
|
2635
2638
|
}();
|
|
2639
|
+
/**
|
|
2640
|
+
* Generate a signed link token.
|
|
2641
|
+
*
|
|
2642
|
+
* @methodGroup Access Requests
|
|
2643
|
+
* @namedParams
|
|
2644
|
+
* @param {string=} containerId - ID of the container object
|
|
2645
|
+
* @param {string=} versionHash - Version hash of the object
|
|
2646
|
+
* @param {string=} link - Path
|
|
2647
|
+
* @param {string=} duration - How long the link should last in milliseconds
|
|
2648
|
+
*
|
|
2649
|
+
* @return {Promise<string>} - The state channel token
|
|
2650
|
+
*/
|
|
2651
|
+
|
|
2652
|
+
|
|
2653
|
+
exports.GenerateSignedLinkToken = /*#__PURE__*/function () {
|
|
2654
|
+
var _ref56 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee31(_ref55) {
|
|
2655
|
+
var containerId, versionHash, link, duration, canEdit, _this$utils$DecodeVer2, objectId, signerAddress, token, compressedToken, signature;
|
|
2656
|
+
|
|
2657
|
+
return _regeneratorRuntime.wrap(function _callee31$(_context32) {
|
|
2658
|
+
while (1) {
|
|
2659
|
+
switch (_context32.prev = _context32.next) {
|
|
2660
|
+
case 0:
|
|
2661
|
+
containerId = _ref55.containerId, versionHash = _ref55.versionHash, link = _ref55.link, duration = _ref55.duration;
|
|
2662
|
+
ValidateObject(containerId);
|
|
2663
|
+
_context32.next = 4;
|
|
2664
|
+
return this.CallContractMethod({
|
|
2665
|
+
contractAddress: this.utils.HashToAddress(containerId),
|
|
2666
|
+
methodName: "canEdit"
|
|
2667
|
+
});
|
|
2668
|
+
|
|
2669
|
+
case 4:
|
|
2670
|
+
canEdit = _context32.sent;
|
|
2671
|
+
_this$utils$DecodeVer2 = this.utils.DecodeVersionHash(versionHash), objectId = _this$utils$DecodeVer2.objectId;
|
|
2672
|
+
|
|
2673
|
+
if (canEdit) {
|
|
2674
|
+
_context32.next = 8;
|
|
2675
|
+
break;
|
|
2676
|
+
}
|
|
2677
|
+
|
|
2678
|
+
throw Error("Current user does not have permission to edit content object ".concat(objectId));
|
|
2679
|
+
|
|
2680
|
+
case 8:
|
|
2681
|
+
signerAddress = this.CurrentAccountAddress();
|
|
2682
|
+
_context32.t0 = this.utils.B64(signerAddress.replace("0x", ""), "hex");
|
|
2683
|
+
_context32.next = 12;
|
|
2684
|
+
return this.ContentSpaceId();
|
|
2685
|
+
|
|
2686
|
+
case 12:
|
|
2687
|
+
_context32.t1 = _context32.sent;
|
|
2688
|
+
_context32.next = 15;
|
|
2689
|
+
return this.ContentObjectLibraryId({
|
|
2690
|
+
objectId: objectId
|
|
2691
|
+
});
|
|
2692
|
+
|
|
2693
|
+
case 15:
|
|
2694
|
+
_context32.t2 = _context32.sent;
|
|
2695
|
+
_context32.t3 = objectId;
|
|
2696
|
+
_context32.t4 = "iusr".concat(this.utils.AddressToHash(signerAddress));
|
|
2697
|
+
_context32.t5 = Date.now();
|
|
2698
|
+
_context32.t6 = duration ? Date.now() + duration : "";
|
|
2699
|
+
_context32.t7 = {
|
|
2700
|
+
elv: {
|
|
2701
|
+
lnk: link,
|
|
2702
|
+
src: containerId
|
|
2703
|
+
}
|
|
2704
|
+
};
|
|
2705
|
+
token = {
|
|
2706
|
+
adr: _context32.t0,
|
|
2707
|
+
spc: _context32.t1,
|
|
2708
|
+
lib: _context32.t2,
|
|
2709
|
+
qid: _context32.t3,
|
|
2710
|
+
sub: _context32.t4,
|
|
2711
|
+
gra: "read",
|
|
2712
|
+
iat: _context32.t5,
|
|
2713
|
+
exp: _context32.t6,
|
|
2714
|
+
ctx: _context32.t7
|
|
2715
|
+
};
|
|
2716
|
+
compressedToken = Pako.deflateRaw(Buffer.from(JSON.stringify(token), "utf-8"));
|
|
2717
|
+
_context32.next = 25;
|
|
2718
|
+
return this.authClient.Sign(Ethers.utils.keccak256(compressedToken));
|
|
2719
|
+
|
|
2720
|
+
case 25:
|
|
2721
|
+
signature = _context32.sent;
|
|
2722
|
+
return _context32.abrupt("return", "aslsjc".concat(this.utils.B58(Buffer.concat([Buffer.from(signature.replace(/^0x/, ""), "hex"), Buffer.from(compressedToken)]))));
|
|
2723
|
+
|
|
2724
|
+
case 27:
|
|
2725
|
+
case "end":
|
|
2726
|
+
return _context32.stop();
|
|
2727
|
+
}
|
|
2728
|
+
}
|
|
2729
|
+
}, _callee31, this);
|
|
2730
|
+
}));
|
|
2731
|
+
|
|
2732
|
+
return function (_x29) {
|
|
2733
|
+
return _ref56.apply(this, arguments);
|
|
2734
|
+
};
|
|
2735
|
+
}();
|
|
2636
2736
|
/**
|
|
2637
2737
|
* Create links to files, metadata and/or representations of this or or other
|
|
2638
2738
|
* content objects.
|
|
@@ -2661,28 +2761,28 @@ exports.UpdateContentObjectGraph = /*#__PURE__*/function () {
|
|
|
2661
2761
|
|
|
2662
2762
|
|
|
2663
2763
|
exports.CreateLinks = /*#__PURE__*/function () {
|
|
2664
|
-
var
|
|
2764
|
+
var _ref58 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee33(_ref57) {
|
|
2665
2765
|
var _this6 = this;
|
|
2666
2766
|
|
|
2667
|
-
var libraryId, objectId, writeToken,
|
|
2767
|
+
var libraryId, objectId, writeToken, _ref57$links, links;
|
|
2668
2768
|
|
|
2669
|
-
return _regeneratorRuntime.wrap(function
|
|
2769
|
+
return _regeneratorRuntime.wrap(function _callee33$(_context34) {
|
|
2670
2770
|
while (1) {
|
|
2671
|
-
switch (
|
|
2771
|
+
switch (_context34.prev = _context34.next) {
|
|
2672
2772
|
case 0:
|
|
2673
|
-
libraryId =
|
|
2773
|
+
libraryId = _ref57.libraryId, objectId = _ref57.objectId, writeToken = _ref57.writeToken, _ref57$links = _ref57.links, links = _ref57$links === void 0 ? [] : _ref57$links;
|
|
2674
2774
|
ValidateParameters({
|
|
2675
2775
|
libraryId: libraryId,
|
|
2676
2776
|
objectId: objectId
|
|
2677
2777
|
});
|
|
2678
2778
|
ValidateWriteToken(writeToken);
|
|
2679
|
-
|
|
2779
|
+
_context34.next = 5;
|
|
2680
2780
|
return this.utils.LimitedMap(10, links, /*#__PURE__*/function () {
|
|
2681
|
-
var
|
|
2781
|
+
var _ref59 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee32(info) {
|
|
2682
2782
|
var path, type, target, authTarget, link, linkMetadata;
|
|
2683
|
-
return _regeneratorRuntime.wrap(function
|
|
2783
|
+
return _regeneratorRuntime.wrap(function _callee32$(_context33) {
|
|
2684
2784
|
while (1) {
|
|
2685
|
-
switch (
|
|
2785
|
+
switch (_context33.prev = _context33.next) {
|
|
2686
2786
|
case 0:
|
|
2687
2787
|
path = info.path.replace(/^(\/|\.)+/, "");
|
|
2688
2788
|
type = (info.type || "file") === "file" ? "files" : info.type;
|
|
@@ -2713,11 +2813,11 @@ exports.CreateLinks = /*#__PURE__*/function () {
|
|
|
2713
2813
|
|
|
2714
2814
|
|
|
2715
2815
|
if (!info.authContainer) {
|
|
2716
|
-
|
|
2816
|
+
_context33.next = 17;
|
|
2717
2817
|
break;
|
|
2718
2818
|
}
|
|
2719
2819
|
|
|
2720
|
-
|
|
2820
|
+
_context33.next = 10;
|
|
2721
2821
|
return _this6.ContentObjectMetadata({
|
|
2722
2822
|
libraryId: libraryId,
|
|
2723
2823
|
objectId: objectId,
|
|
@@ -2725,32 +2825,31 @@ exports.CreateLinks = /*#__PURE__*/function () {
|
|
|
2725
2825
|
});
|
|
2726
2826
|
|
|
2727
2827
|
case 10:
|
|
2728
|
-
linkMetadata =
|
|
2828
|
+
linkMetadata = _context33.sent;
|
|
2729
2829
|
|
|
2730
2830
|
if (linkMetadata) {
|
|
2731
|
-
link
|
|
2732
|
-
link["."] = linkMetadata["."];
|
|
2831
|
+
link = linkMetadata;
|
|
2733
2832
|
}
|
|
2734
2833
|
|
|
2735
2834
|
if (!link["."]) link["."] = {};
|
|
2736
2835
|
|
|
2737
2836
|
if (linkMetadata["."]["authorization"]) {
|
|
2738
|
-
|
|
2837
|
+
_context33.next = 17;
|
|
2739
2838
|
break;
|
|
2740
2839
|
}
|
|
2741
2840
|
|
|
2742
|
-
|
|
2743
|
-
return _this6.
|
|
2841
|
+
_context33.next = 16;
|
|
2842
|
+
return _this6.GenerateSignedLinkToken({
|
|
2744
2843
|
containerId: info.authContainer,
|
|
2745
2844
|
versionHash: info.targetHash,
|
|
2746
2845
|
link: "./".concat(type, "/").concat(authTarget)
|
|
2747
2846
|
});
|
|
2748
2847
|
|
|
2749
2848
|
case 16:
|
|
2750
|
-
link["."]["authorization"] =
|
|
2849
|
+
link["."]["authorization"] = _context33.sent;
|
|
2751
2850
|
|
|
2752
2851
|
case 17:
|
|
2753
|
-
|
|
2852
|
+
_context33.next = 19;
|
|
2754
2853
|
return _this6.ReplaceMetadata({
|
|
2755
2854
|
libraryId: libraryId,
|
|
2756
2855
|
objectId: objectId,
|
|
@@ -2761,27 +2860,27 @@ exports.CreateLinks = /*#__PURE__*/function () {
|
|
|
2761
2860
|
|
|
2762
2861
|
case 19:
|
|
2763
2862
|
case "end":
|
|
2764
|
-
return
|
|
2863
|
+
return _context33.stop();
|
|
2765
2864
|
}
|
|
2766
2865
|
}
|
|
2767
|
-
},
|
|
2866
|
+
}, _callee32);
|
|
2768
2867
|
}));
|
|
2769
2868
|
|
|
2770
|
-
return function (
|
|
2771
|
-
return
|
|
2869
|
+
return function (_x31) {
|
|
2870
|
+
return _ref59.apply(this, arguments);
|
|
2772
2871
|
};
|
|
2773
2872
|
}());
|
|
2774
2873
|
|
|
2775
2874
|
case 5:
|
|
2776
2875
|
case "end":
|
|
2777
|
-
return
|
|
2876
|
+
return _context34.stop();
|
|
2778
2877
|
}
|
|
2779
2878
|
}
|
|
2780
|
-
},
|
|
2879
|
+
}, _callee33, this);
|
|
2781
2880
|
}));
|
|
2782
2881
|
|
|
2783
|
-
return function (
|
|
2784
|
-
return
|
|
2882
|
+
return function (_x30) {
|
|
2883
|
+
return _ref58.apply(this, arguments);
|
|
2785
2884
|
};
|
|
2786
2885
|
}();
|
|
2787
2886
|
/**
|
|
@@ -2801,14 +2900,14 @@ exports.CreateLinks = /*#__PURE__*/function () {
|
|
|
2801
2900
|
|
|
2802
2901
|
|
|
2803
2902
|
exports.InitializeAuthPolicy = /*#__PURE__*/function () {
|
|
2804
|
-
var
|
|
2805
|
-
var libraryId, objectId, writeToken,
|
|
2903
|
+
var _ref61 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee34(_ref60) {
|
|
2904
|
+
var libraryId, objectId, writeToken, _ref60$target, target, body, version, description, id, authPolicy, string;
|
|
2806
2905
|
|
|
2807
|
-
return _regeneratorRuntime.wrap(function
|
|
2906
|
+
return _regeneratorRuntime.wrap(function _callee34$(_context35) {
|
|
2808
2907
|
while (1) {
|
|
2809
|
-
switch (
|
|
2908
|
+
switch (_context35.prev = _context35.next) {
|
|
2810
2909
|
case 0:
|
|
2811
|
-
libraryId =
|
|
2910
|
+
libraryId = _ref60.libraryId, objectId = _ref60.objectId, writeToken = _ref60.writeToken, _ref60$target = _ref60.target, target = _ref60$target === void 0 ? "auth_policy_spec" : _ref60$target, body = _ref60.body, version = _ref60.version, description = _ref60.description, id = _ref60.id;
|
|
2812
2911
|
authPolicy = {
|
|
2813
2912
|
type: "epl-ast",
|
|
2814
2913
|
version: version,
|
|
@@ -2821,14 +2920,14 @@ exports.InitializeAuthPolicy = /*#__PURE__*/function () {
|
|
|
2821
2920
|
id: id || ""
|
|
2822
2921
|
};
|
|
2823
2922
|
string = "".concat(authPolicy.type, "|").concat(authPolicy.version, "|").concat(authPolicy.body, "|").concat(authPolicy.data["/"]);
|
|
2824
|
-
|
|
2825
|
-
|
|
2923
|
+
_context35.t0 = this.utils;
|
|
2924
|
+
_context35.next = 6;
|
|
2826
2925
|
return this.authClient.Sign(Ethers.utils.keccak256(Ethers.utils.toUtf8Bytes(string)));
|
|
2827
2926
|
|
|
2828
2927
|
case 6:
|
|
2829
|
-
|
|
2830
|
-
authPolicy.signature =
|
|
2831
|
-
|
|
2928
|
+
_context35.t1 = _context35.sent;
|
|
2929
|
+
authPolicy.signature = _context35.t0.FormatSignature.call(_context35.t0, _context35.t1);
|
|
2930
|
+
_context35.next = 10;
|
|
2832
2931
|
return this.ReplaceMetadata({
|
|
2833
2932
|
libraryId: libraryId,
|
|
2834
2933
|
objectId: objectId,
|
|
@@ -2838,7 +2937,7 @@ exports.InitializeAuthPolicy = /*#__PURE__*/function () {
|
|
|
2838
2937
|
});
|
|
2839
2938
|
|
|
2840
2939
|
case 10:
|
|
2841
|
-
|
|
2940
|
+
_context35.next = 12;
|
|
2842
2941
|
return this.SetAuthPolicy({
|
|
2843
2942
|
objectId: objectId,
|
|
2844
2943
|
policyId: objectId
|
|
@@ -2846,14 +2945,14 @@ exports.InitializeAuthPolicy = /*#__PURE__*/function () {
|
|
|
2846
2945
|
|
|
2847
2946
|
case 12:
|
|
2848
2947
|
case "end":
|
|
2849
|
-
return
|
|
2948
|
+
return _context35.stop();
|
|
2850
2949
|
}
|
|
2851
2950
|
}
|
|
2852
|
-
},
|
|
2951
|
+
}, _callee34, this);
|
|
2853
2952
|
}));
|
|
2854
2953
|
|
|
2855
|
-
return function (
|
|
2856
|
-
return
|
|
2954
|
+
return function (_x32) {
|
|
2955
|
+
return _ref61.apply(this, arguments);
|
|
2857
2956
|
};
|
|
2858
2957
|
}();
|
|
2859
2958
|
/**
|
|
@@ -2867,14 +2966,14 @@ exports.InitializeAuthPolicy = /*#__PURE__*/function () {
|
|
|
2867
2966
|
|
|
2868
2967
|
|
|
2869
2968
|
exports.SetAuthPolicy = /*#__PURE__*/function () {
|
|
2870
|
-
var
|
|
2969
|
+
var _ref63 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee35(_ref62) {
|
|
2871
2970
|
var objectId, policyId;
|
|
2872
|
-
return _regeneratorRuntime.wrap(function
|
|
2971
|
+
return _regeneratorRuntime.wrap(function _callee35$(_context36) {
|
|
2873
2972
|
while (1) {
|
|
2874
|
-
switch (
|
|
2973
|
+
switch (_context36.prev = _context36.next) {
|
|
2875
2974
|
case 0:
|
|
2876
|
-
objectId =
|
|
2877
|
-
|
|
2975
|
+
objectId = _ref62.objectId, policyId = _ref62.policyId;
|
|
2976
|
+
_context36.next = 3;
|
|
2878
2977
|
return this.MergeContractMetadata({
|
|
2879
2978
|
contractAddress: this.utils.HashToAddress(objectId),
|
|
2880
2979
|
metadataKey: "_AUTH_CONTEXT",
|
|
@@ -2885,13 +2984,13 @@ exports.SetAuthPolicy = /*#__PURE__*/function () {
|
|
|
2885
2984
|
|
|
2886
2985
|
case 3:
|
|
2887
2986
|
case "end":
|
|
2888
|
-
return
|
|
2987
|
+
return _context36.stop();
|
|
2889
2988
|
}
|
|
2890
2989
|
}
|
|
2891
|
-
},
|
|
2990
|
+
}, _callee35, this);
|
|
2892
2991
|
}));
|
|
2893
2992
|
|
|
2894
|
-
return function (
|
|
2895
|
-
return
|
|
2993
|
+
return function (_x33) {
|
|
2994
|
+
return _ref63.apply(this, arguments);
|
|
2896
2995
|
};
|
|
2897
2996
|
}();
|
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
var _regeneratorRuntime = require("@babel/runtime/regenerator");
|
|
2
|
+
|
|
3
|
+
var _asyncToGenerator = require("@babel/runtime/helpers/asyncToGenerator");
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Methods related to notifications for the current user.
|
|
7
|
+
*
|
|
8
|
+
* @module Notifications
|
|
9
|
+
*/
|
|
10
|
+
var Utils = require("../Utils");
|
|
11
|
+
|
|
12
|
+
var UrlJoin = require("url-join");
|
|
13
|
+
|
|
14
|
+
var NotificationPath = function NotificationPath(_ref) {
|
|
15
|
+
var network = _ref.network,
|
|
16
|
+
path = _ref.path;
|
|
17
|
+
return UrlJoin("/push", network === "main" ? "/main" : "/dv3", path);
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* Push a notification to the current user
|
|
21
|
+
*
|
|
22
|
+
* @methodGroup Notifications
|
|
23
|
+
* @param {string} tenantId - The tenant associated with this notification
|
|
24
|
+
* @param {string} eventType - The type of the notification
|
|
25
|
+
* @param {(Object | string)=} data - Data associated with this notification
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
exports.PushNotification = /*#__PURE__*/function () {
|
|
30
|
+
var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(_ref2) {
|
|
31
|
+
var tenantId, eventType, data;
|
|
32
|
+
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
33
|
+
while (1) {
|
|
34
|
+
switch (_context.prev = _context.next) {
|
|
35
|
+
case 0:
|
|
36
|
+
tenantId = _ref2.tenantId, eventType = _ref2.eventType, data = _ref2.data;
|
|
37
|
+
_context.next = 3;
|
|
38
|
+
return this.stateStoreClient.Request({
|
|
39
|
+
method: "POST",
|
|
40
|
+
path: NotificationPath({
|
|
41
|
+
network: this.network,
|
|
42
|
+
path: UrlJoin("notify_user", this.UserAddress(), tenantId, eventType)
|
|
43
|
+
}),
|
|
44
|
+
body: data,
|
|
45
|
+
headers: {
|
|
46
|
+
Authorization: "Bearer ".concat(this.AuthToken())
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
case 3:
|
|
51
|
+
case "end":
|
|
52
|
+
return _context.stop();
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}, _callee, this);
|
|
56
|
+
}));
|
|
57
|
+
|
|
58
|
+
return function (_x) {
|
|
59
|
+
return _ref3.apply(this, arguments);
|
|
60
|
+
};
|
|
61
|
+
}();
|
|
62
|
+
/**
|
|
63
|
+
* Add a listener to receive new notifications.
|
|
64
|
+
*
|
|
65
|
+
* @methodGroup Notifications
|
|
66
|
+
* @param {function} onMessage - Callback invoked when a new notification is received
|
|
67
|
+
*
|
|
68
|
+
* @returns {Promise<EventSource>} - An EventSource instance listening for notifications. Use source.close() to close the listener.
|
|
69
|
+
*/
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
exports.AddNotificationListener = /*#__PURE__*/function () {
|
|
73
|
+
var _ref5 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(_ref4) {
|
|
74
|
+
var onMessage, url, source;
|
|
75
|
+
return _regeneratorRuntime.wrap(function _callee2$(_context2) {
|
|
76
|
+
while (1) {
|
|
77
|
+
switch (_context2.prev = _context2.next) {
|
|
78
|
+
case 0:
|
|
79
|
+
onMessage = _ref4.onMessage;
|
|
80
|
+
|
|
81
|
+
if (onMessage) {
|
|
82
|
+
_context2.next = 3;
|
|
83
|
+
break;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
throw Error("Eluvio Wallet Client: No onMessage callback provided to AddNotificationListener");
|
|
87
|
+
|
|
88
|
+
case 3:
|
|
89
|
+
url = new URL(this.stateStoreClient.BaseURI().toString());
|
|
90
|
+
url.pathname = NotificationPath({
|
|
91
|
+
network: this.network,
|
|
92
|
+
path: UrlJoin("register", this.UserAddress(), this.AuthToken())
|
|
93
|
+
});
|
|
94
|
+
source = new EventSource(url);
|
|
95
|
+
|
|
96
|
+
source.onmessage = function (event) {
|
|
97
|
+
var parsedMessage = JSON.parse(event.data);
|
|
98
|
+
|
|
99
|
+
try {
|
|
100
|
+
parsedMessage.data = JSON.parse(parsedMessage.data); // eslint-disable-next-line no-empty
|
|
101
|
+
} catch (error) {}
|
|
102
|
+
|
|
103
|
+
onMessage(parsedMessage);
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
return _context2.abrupt("return", source);
|
|
107
|
+
|
|
108
|
+
case 8:
|
|
109
|
+
case "end":
|
|
110
|
+
return _context2.stop();
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
}, _callee2, this);
|
|
114
|
+
}));
|
|
115
|
+
|
|
116
|
+
return function (_x2) {
|
|
117
|
+
return _ref5.apply(this, arguments);
|
|
118
|
+
};
|
|
119
|
+
}();
|
|
120
|
+
/**
|
|
121
|
+
* Retrieve notifications for the current user.
|
|
122
|
+
*
|
|
123
|
+
* @methodGroup Notifications
|
|
124
|
+
* @param {integer=} limit=10 - The maximum number of notifications to return
|
|
125
|
+
* @param {string=} tenantId - Filter notifications to only those related to the specified tenant
|
|
126
|
+
* @param {Array<string>=} types - Filter notifications to only the specified types
|
|
127
|
+
* @param {string=} offsetId - Return notifications older than the specified ID
|
|
128
|
+
*
|
|
129
|
+
* @returns {Promise<Array<Object>>} - A list of notifications for the specified parameters
|
|
130
|
+
*/
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
exports.Notifications = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3() {
|
|
134
|
+
var _ref7,
|
|
135
|
+
tenantId,
|
|
136
|
+
types,
|
|
137
|
+
offsetId,
|
|
138
|
+
_ref7$limit,
|
|
139
|
+
limit,
|
|
140
|
+
queryParams,
|
|
141
|
+
_yield$Utils$Response,
|
|
142
|
+
records,
|
|
143
|
+
_args3 = arguments;
|
|
144
|
+
|
|
145
|
+
return _regeneratorRuntime.wrap(function _callee3$(_context3) {
|
|
146
|
+
while (1) {
|
|
147
|
+
switch (_context3.prev = _context3.next) {
|
|
148
|
+
case 0:
|
|
149
|
+
_ref7 = _args3.length > 0 && _args3[0] !== undefined ? _args3[0] : {}, tenantId = _ref7.tenantId, types = _ref7.types, offsetId = _ref7.offsetId, _ref7$limit = _ref7.limit, limit = _ref7$limit === void 0 ? 10 : _ref7$limit;
|
|
150
|
+
queryParams = {
|
|
151
|
+
limit: limit
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
if (tenantId) {
|
|
155
|
+
queryParams.tenant_id = tenantId;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
if (types) {
|
|
159
|
+
queryParams.types = Array.isArray(types) ? types.join(",") : types;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
if (offsetId) {
|
|
163
|
+
queryParams.offset_by = offsetId;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
_context3.next = 7;
|
|
167
|
+
return Utils.ResponseToJson(this.stateStoreClient.Request({
|
|
168
|
+
method: "GET",
|
|
169
|
+
path: NotificationPath({
|
|
170
|
+
network: this.network,
|
|
171
|
+
path: UrlJoin("history", this.UserAddress())
|
|
172
|
+
}),
|
|
173
|
+
queryParams: queryParams,
|
|
174
|
+
headers: {
|
|
175
|
+
Authorization: "Bearer ".concat(this.AuthToken())
|
|
176
|
+
}
|
|
177
|
+
}));
|
|
178
|
+
|
|
179
|
+
case 7:
|
|
180
|
+
_yield$Utils$Response = _context3.sent;
|
|
181
|
+
records = _yield$Utils$Response.records;
|
|
182
|
+
return _context3.abrupt("return", records.map(function (record) {
|
|
183
|
+
try {
|
|
184
|
+
record.data = JSON.parse(record.data); // eslint-disable-next-line no-empty
|
|
185
|
+
} catch (error) {}
|
|
186
|
+
|
|
187
|
+
return record;
|
|
188
|
+
}));
|
|
189
|
+
|
|
190
|
+
case 10:
|
|
191
|
+
case "end":
|
|
192
|
+
return _context3.stop();
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
}, _callee3, this);
|
|
196
|
+
}));
|
|
@@ -1971,4 +1971,5 @@ var ElvWalletClient = /*#__PURE__*/function () {
|
|
|
1971
1971
|
|
|
1972
1972
|
Object.assign(ElvWalletClient.prototype, require("./ClientMethods"));
|
|
1973
1973
|
Object.assign(ElvWalletClient.prototype, require("./Profile"));
|
|
1974
|
+
Object.assign(ElvWalletClient.prototype, require("./Notifications"));
|
|
1974
1975
|
exports.ElvWalletClient = ElvWalletClient;
|
package/package.json
CHANGED
|
@@ -3,8 +3,6 @@ const Ethers = require("ethers");
|
|
|
3
3
|
const Utils = require("./Utils");
|
|
4
4
|
const UrlJoin = require("url-join");
|
|
5
5
|
const {LogMessage} = require("./LogMessage");
|
|
6
|
-
const {ValidateObject} = require("./Validation");
|
|
7
|
-
const Pako = require("pako");
|
|
8
6
|
|
|
9
7
|
/*
|
|
10
8
|
// -- Contract javascript files built using build/BuildContracts.js
|
|
@@ -242,47 +240,6 @@ class AuthorizationClient {
|
|
|
242
240
|
return `${token}.${Utils.B64(multiSig)}`;
|
|
243
241
|
}
|
|
244
242
|
|
|
245
|
-
async GenerateSignedLinkToken({containerId, versionHash, link}) {
|
|
246
|
-
ValidateObject(containerId);
|
|
247
|
-
const canEdit = await this.client.CallContractMethod({
|
|
248
|
-
contractAddress: Utils.HashToAddress(containerId),
|
|
249
|
-
methodName: "canEdit"
|
|
250
|
-
});
|
|
251
|
-
|
|
252
|
-
const { objectId } = Utils.DecodeVersionHash(versionHash);
|
|
253
|
-
|
|
254
|
-
if(!canEdit) {
|
|
255
|
-
throw Error(`Current user does not have permission to edit content object ${objectId}`);
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
const signerAddress = this.client.CurrentAccountAddress();
|
|
259
|
-
|
|
260
|
-
let token = {
|
|
261
|
-
adr: Utils.B64(signerAddress.replace("0x", ""), "hex"),
|
|
262
|
-
spc: await this.client.ContentSpaceId(),
|
|
263
|
-
lib: await this.client.ContentObjectLibraryId({objectId}),
|
|
264
|
-
qid: objectId,
|
|
265
|
-
sub: Utils.FormatAddress(signerAddress),
|
|
266
|
-
gra: "read",
|
|
267
|
-
iat: Date.now(),
|
|
268
|
-
exp: Date.now() + 3600000,
|
|
269
|
-
ctx: {
|
|
270
|
-
elv: {
|
|
271
|
-
lnk: link,
|
|
272
|
-
src: containerId
|
|
273
|
-
}
|
|
274
|
-
}
|
|
275
|
-
};
|
|
276
|
-
|
|
277
|
-
const compressedToken = Pako.deflateRaw(Buffer.from(JSON.stringify(token), "utf-8"));
|
|
278
|
-
const signature = await this.Sign(Ethers.utils.keccak256(compressedToken));
|
|
279
|
-
|
|
280
|
-
return `aslsjc${Utils.B58(Buffer.concat([
|
|
281
|
-
Buffer.from(signature.replace(/^0x/, ""), "hex"),
|
|
282
|
-
Buffer.from(compressedToken)
|
|
283
|
-
]))}`;
|
|
284
|
-
}
|
|
285
|
-
|
|
286
243
|
async MakeAccessRequest({
|
|
287
244
|
libraryId,
|
|
288
245
|
objectId,
|