@eluvio/elv-client-js 3.2.40 → 3.2.41
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 +1 -1
- package/dist/ElvClient-node-min.js +1 -1
- package/dist/ElvWalletClient-min.js +1 -1
- package/dist/ElvWalletClient-node-min.js +9 -9
- package/dist/src/client/ContentManagement.js +1 -2
- package/dist/src/walletClient/Notifications.js +191 -0
- package/dist/src/walletClient/index.js +1 -0
- package/package.json +1 -1
- package/src/client/ContentManagement.js +1 -2
- package/src/walletClient/Notifications.js +109 -0
- package/src/walletClient/index.js +1 -0
|
@@ -2728,8 +2728,7 @@ exports.CreateLinks = /*#__PURE__*/function () {
|
|
|
2728
2728
|
linkMetadata = _context32.sent;
|
|
2729
2729
|
|
|
2730
2730
|
if (linkMetadata) {
|
|
2731
|
-
link
|
|
2732
|
-
link["."] = linkMetadata["."];
|
|
2731
|
+
link = linkMetadata;
|
|
2733
2732
|
}
|
|
2734
2733
|
|
|
2735
2734
|
if (!link["."]) link["."] = {};
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
var _regeneratorRuntime = require("@babel/runtime/regenerator");
|
|
2
|
+
|
|
3
|
+
var _asyncToGenerator = require("@babel/runtime/helpers/asyncToGenerator");
|
|
4
|
+
|
|
5
|
+
var Utils = require("../Utils");
|
|
6
|
+
|
|
7
|
+
var UrlJoin = require("url-join");
|
|
8
|
+
|
|
9
|
+
var NotificationPath = function NotificationPath(_ref) {
|
|
10
|
+
var network = _ref.network,
|
|
11
|
+
path = _ref.path;
|
|
12
|
+
return UrlJoin("/push", network === "main" ? "/main" : "/dv3", path);
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* Push a notification to the current user
|
|
16
|
+
*
|
|
17
|
+
* @methodGroup Notifications
|
|
18
|
+
* @param {string} tenantId - The tenant associated with this notification
|
|
19
|
+
* @param {string} eventType - The type of the notification
|
|
20
|
+
* @param {(Object | string)=} data - Data associated with this notification
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
exports.PushNotification = /*#__PURE__*/function () {
|
|
25
|
+
var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(_ref2) {
|
|
26
|
+
var tenantId, eventType, data;
|
|
27
|
+
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
28
|
+
while (1) {
|
|
29
|
+
switch (_context.prev = _context.next) {
|
|
30
|
+
case 0:
|
|
31
|
+
tenantId = _ref2.tenantId, eventType = _ref2.eventType, data = _ref2.data;
|
|
32
|
+
_context.next = 3;
|
|
33
|
+
return this.stateStoreClient.Request({
|
|
34
|
+
method: "POST",
|
|
35
|
+
path: NotificationPath({
|
|
36
|
+
network: this.network,
|
|
37
|
+
path: UrlJoin("notify_user", this.UserAddress(), tenantId, eventType)
|
|
38
|
+
}),
|
|
39
|
+
body: data,
|
|
40
|
+
headers: {
|
|
41
|
+
Authorization: "Bearer ".concat(this.AuthToken())
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
case 3:
|
|
46
|
+
case "end":
|
|
47
|
+
return _context.stop();
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}, _callee, this);
|
|
51
|
+
}));
|
|
52
|
+
|
|
53
|
+
return function (_x) {
|
|
54
|
+
return _ref3.apply(this, arguments);
|
|
55
|
+
};
|
|
56
|
+
}();
|
|
57
|
+
/**
|
|
58
|
+
* Add a listener to receive new notifications.
|
|
59
|
+
*
|
|
60
|
+
* @methodGroup Notifications
|
|
61
|
+
* @param {function} onMessage - Callback invoked when a new notification is received
|
|
62
|
+
*
|
|
63
|
+
* @returns {Promise<EventSource>} - An EventSource instance listening for notifications. Use source.close() to close the listener.
|
|
64
|
+
*/
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
exports.AddNotificationListener = /*#__PURE__*/function () {
|
|
68
|
+
var _ref5 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(_ref4) {
|
|
69
|
+
var onMessage, url, source;
|
|
70
|
+
return _regeneratorRuntime.wrap(function _callee2$(_context2) {
|
|
71
|
+
while (1) {
|
|
72
|
+
switch (_context2.prev = _context2.next) {
|
|
73
|
+
case 0:
|
|
74
|
+
onMessage = _ref4.onMessage;
|
|
75
|
+
|
|
76
|
+
if (onMessage) {
|
|
77
|
+
_context2.next = 3;
|
|
78
|
+
break;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
throw Error("Eluvio Wallet Client: No onMessage callback provided to AddNotificationListener");
|
|
82
|
+
|
|
83
|
+
case 3:
|
|
84
|
+
url = new URL(this.stateStoreClient.BaseURI().toString());
|
|
85
|
+
url.pathname = NotificationPath({
|
|
86
|
+
network: this.network,
|
|
87
|
+
path: UrlJoin("register", this.UserAddress(), this.AuthToken())
|
|
88
|
+
});
|
|
89
|
+
source = new EventSource(url);
|
|
90
|
+
|
|
91
|
+
source.onmessage = function (event) {
|
|
92
|
+
var parsedMessage = JSON.parse(event.data);
|
|
93
|
+
|
|
94
|
+
try {
|
|
95
|
+
parsedMessage.data = JSON.parse(parsedMessage.data); // eslint-disable-next-line no-empty
|
|
96
|
+
} catch (error) {}
|
|
97
|
+
|
|
98
|
+
onMessage(parsedMessage);
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
return _context2.abrupt("return", source);
|
|
102
|
+
|
|
103
|
+
case 8:
|
|
104
|
+
case "end":
|
|
105
|
+
return _context2.stop();
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}, _callee2, this);
|
|
109
|
+
}));
|
|
110
|
+
|
|
111
|
+
return function (_x2) {
|
|
112
|
+
return _ref5.apply(this, arguments);
|
|
113
|
+
};
|
|
114
|
+
}();
|
|
115
|
+
/**
|
|
116
|
+
* Retrieve notifications for the current user.
|
|
117
|
+
*
|
|
118
|
+
* @methodGroup Notifications
|
|
119
|
+
* @param {integer=} limit=10 - The maximum number of notifications to return
|
|
120
|
+
* @param {string=} tenantId - Filter notifications to only those related to the specified tenant
|
|
121
|
+
* @param {Array<string>=} types - Filter notifications to only the specified types
|
|
122
|
+
* @param {string=} offsetId - Return notifications older than the specified ID
|
|
123
|
+
*
|
|
124
|
+
* @returns {Promise<Array<Object>>} - A list of notifications for the specified parameters
|
|
125
|
+
*/
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
exports.Notifications = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3() {
|
|
129
|
+
var _ref7,
|
|
130
|
+
tenantId,
|
|
131
|
+
types,
|
|
132
|
+
offsetId,
|
|
133
|
+
_ref7$limit,
|
|
134
|
+
limit,
|
|
135
|
+
queryParams,
|
|
136
|
+
_yield$Utils$Response,
|
|
137
|
+
records,
|
|
138
|
+
_args3 = arguments;
|
|
139
|
+
|
|
140
|
+
return _regeneratorRuntime.wrap(function _callee3$(_context3) {
|
|
141
|
+
while (1) {
|
|
142
|
+
switch (_context3.prev = _context3.next) {
|
|
143
|
+
case 0:
|
|
144
|
+
_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;
|
|
145
|
+
queryParams = {
|
|
146
|
+
limit: limit
|
|
147
|
+
};
|
|
148
|
+
|
|
149
|
+
if (tenantId) {
|
|
150
|
+
queryParams.tenant_id = tenantId;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
if (types) {
|
|
154
|
+
queryParams.types = Array.isArray(types) ? types.join(",") : types;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
if (offsetId) {
|
|
158
|
+
queryParams.offset_by = offsetId;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
_context3.next = 7;
|
|
162
|
+
return Utils.ResponseToJson(this.stateStoreClient.Request({
|
|
163
|
+
method: "GET",
|
|
164
|
+
path: NotificationPath({
|
|
165
|
+
network: this.network,
|
|
166
|
+
path: UrlJoin("history", this.UserAddress())
|
|
167
|
+
}),
|
|
168
|
+
queryParams: queryParams,
|
|
169
|
+
headers: {
|
|
170
|
+
Authorization: "Bearer ".concat(this.AuthToken())
|
|
171
|
+
}
|
|
172
|
+
}));
|
|
173
|
+
|
|
174
|
+
case 7:
|
|
175
|
+
_yield$Utils$Response = _context3.sent;
|
|
176
|
+
records = _yield$Utils$Response.records;
|
|
177
|
+
return _context3.abrupt("return", records.map(function (record) {
|
|
178
|
+
try {
|
|
179
|
+
record.data = JSON.parse(record.data); // eslint-disable-next-line no-empty
|
|
180
|
+
} catch (error) {}
|
|
181
|
+
|
|
182
|
+
return record;
|
|
183
|
+
}));
|
|
184
|
+
|
|
185
|
+
case 10:
|
|
186
|
+
case "end":
|
|
187
|
+
return _context3.stop();
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
}, _callee3, this);
|
|
191
|
+
}));
|
|
@@ -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
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Methods related to notifications for the current user.
|
|
3
|
+
*
|
|
4
|
+
* @module Notifications
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
const Utils = require("../Utils");
|
|
9
|
+
const UrlJoin = require("url-join");
|
|
10
|
+
|
|
11
|
+
const NotificationPath = ({network, path}) => {
|
|
12
|
+
return UrlJoin("/push", network === "main" ? "/main" : "/dv3", path);
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Push a notification to the current user
|
|
17
|
+
*
|
|
18
|
+
* @methodGroup Notifications
|
|
19
|
+
* @param {string} tenantId - The tenant associated with this notification
|
|
20
|
+
* @param {string} eventType - The type of the notification
|
|
21
|
+
* @param {(Object | string)=} data - Data associated with this notification
|
|
22
|
+
*/
|
|
23
|
+
exports.PushNotification = async function({tenantId, eventType, data}) {
|
|
24
|
+
await this.stateStoreClient.Request({
|
|
25
|
+
method: "POST",
|
|
26
|
+
path: NotificationPath({network: this.network, path: UrlJoin("notify_user", this.UserAddress(), tenantId, eventType)}),
|
|
27
|
+
body: data,
|
|
28
|
+
headers: {
|
|
29
|
+
Authorization: `Bearer ${this.AuthToken()}`
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Add a listener to receive new notifications.
|
|
36
|
+
*
|
|
37
|
+
* @methodGroup Notifications
|
|
38
|
+
* @param {function} onMessage - Callback invoked when a new notification is received
|
|
39
|
+
*
|
|
40
|
+
* @returns {Promise<EventSource>} - An EventSource instance listening for notifications. Use source.close() to close the listener.
|
|
41
|
+
*/
|
|
42
|
+
exports.AddNotificationListener = async function({onMessage}) {
|
|
43
|
+
if(!onMessage) {
|
|
44
|
+
throw Error("Eluvio Wallet Client: No onMessage callback provided to AddNotificationListener");
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const url = new URL(this.stateStoreClient.BaseURI().toString());
|
|
48
|
+
url.pathname = NotificationPath({network: this.network, path: UrlJoin("register", this.UserAddress(), this.AuthToken())});
|
|
49
|
+
const source = new EventSource(url);
|
|
50
|
+
source.onmessage = event => {
|
|
51
|
+
let parsedMessage = JSON.parse(event.data);
|
|
52
|
+
|
|
53
|
+
try {
|
|
54
|
+
parsedMessage.data = JSON.parse(parsedMessage.data);
|
|
55
|
+
// eslint-disable-next-line no-empty
|
|
56
|
+
} catch(error) {}
|
|
57
|
+
|
|
58
|
+
onMessage(parsedMessage);
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
return source;
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Retrieve notifications for the current user.
|
|
66
|
+
*
|
|
67
|
+
* @methodGroup Notifications
|
|
68
|
+
* @param {integer=} limit=10 - The maximum number of notifications to return
|
|
69
|
+
* @param {string=} tenantId - Filter notifications to only those related to the specified tenant
|
|
70
|
+
* @param {Array<string>=} types - Filter notifications to only the specified types
|
|
71
|
+
* @param {string=} offsetId - Return notifications older than the specified ID
|
|
72
|
+
*
|
|
73
|
+
* @returns {Promise<Array<Object>>} - A list of notifications for the specified parameters
|
|
74
|
+
*/
|
|
75
|
+
exports.Notifications = async function({tenantId, types, offsetId, limit=10}={}) {
|
|
76
|
+
let queryParams = { limit };
|
|
77
|
+
|
|
78
|
+
if(tenantId) {
|
|
79
|
+
queryParams.tenant_id = tenantId;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
if(types) {
|
|
83
|
+
queryParams.types = Array.isArray(types) ? types.join(",") : types;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
if(offsetId) {
|
|
87
|
+
queryParams.offset_by = offsetId;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
const {records} = await Utils.ResponseToJson(
|
|
91
|
+
this.stateStoreClient.Request({
|
|
92
|
+
method: "GET",
|
|
93
|
+
path: NotificationPath({network: this.network, path: UrlJoin("history", this.UserAddress())}),
|
|
94
|
+
queryParams,
|
|
95
|
+
headers: {
|
|
96
|
+
Authorization: `Bearer ${this.AuthToken()}`
|
|
97
|
+
}
|
|
98
|
+
})
|
|
99
|
+
);
|
|
100
|
+
|
|
101
|
+
return records.map(record => {
|
|
102
|
+
try {
|
|
103
|
+
record.data = JSON.parse(record.data);
|
|
104
|
+
// eslint-disable-next-line no-empty
|
|
105
|
+
} catch(error) {}
|
|
106
|
+
|
|
107
|
+
return record;
|
|
108
|
+
});
|
|
109
|
+
};
|
|
@@ -1146,5 +1146,6 @@ class ElvWalletClient {
|
|
|
1146
1146
|
|
|
1147
1147
|
Object.assign(ElvWalletClient.prototype, require("./ClientMethods"));
|
|
1148
1148
|
Object.assign(ElvWalletClient.prototype, require("./Profile"));
|
|
1149
|
+
Object.assign(ElvWalletClient.prototype, require("./Notifications"));
|
|
1149
1150
|
|
|
1150
1151
|
exports.ElvWalletClient = ElvWalletClient;
|