@eluvio/elv-client-js 3.2.15 → 3.2.19

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.
@@ -1,6 +1,7 @@
1
1
  var WalletConfiguration = {
2
2
  demo: {
3
3
  configUrl: "https://demov3.net955210.contentfabric.io/config",
4
+ stateStoreUrls: ["https://appsvc.svc.eluv.io/dv3"],
4
5
  staging: {
5
6
  siteId: "iq__2gkNh8CCZqFFnoRpEUmz7P3PaBQG",
6
7
  purchaseMode: "develop",
@@ -9,6 +10,7 @@ var WalletConfiguration = {
9
10
  },
10
11
  main: {
11
12
  configUrl: "https://main.net955305.contentfabric.io/config",
13
+ stateStoreUrls: ["https://appsvc.svc.eluv.io/main"],
12
14
  staging: {
13
15
  siteId: "iq__inauxD1KLyKWPHargCWjdCh2ayr",
14
16
  purchaseMode: "production",
@@ -0,0 +1,368 @@
1
+ var _typeof = require("@babel/runtime/helpers/typeof");
2
+
3
+ var _regeneratorRuntime = require("@babel/runtime/regenerator");
4
+
5
+ var _asyncToGenerator = require("@babel/runtime/helpers/asyncToGenerator");
6
+
7
+ var Utils = require("../Utils");
8
+
9
+ var UrlJoin = require("url-join");
10
+
11
+ var StateStorePath = function StateStorePath(_ref) {
12
+ var network = _ref.network,
13
+ path = _ref.path;
14
+ return UrlJoin(network === "main" ? "/main" : "/dv3", path);
15
+ };
16
+
17
+ var UserProfilePath = function UserProfilePath(_ref2) {
18
+ var network = _ref2.network,
19
+ appId = _ref2.appId,
20
+ userAddress = _ref2.userAddress,
21
+ key = _ref2.key,
22
+ type = _ref2.type,
23
+ mode = _ref2.mode;
24
+ return StateStorePath({
25
+ network: network,
26
+ path: UrlJoin(type === "app" ? "app" : "usr", type === "app" ? appId : "", userAddress, mode === "public" ? "pub" : "pri", key || "")
27
+ });
28
+ };
29
+ /**
30
+ * Methods related to getting and setting user profile data.
31
+ *
32
+ * @module ProfileMethods
33
+ */
34
+
35
+ /**
36
+ * Retrieve user profile metadata for the specified user
37
+ *
38
+ * @methodGroup ProfileMetadata
39
+ * @namedParams
40
+ * @param {string=} type="app" - Specify `app` or `user` metadata.
41
+ * @param {string=} mode="public" - Specify `public` or `private` metadata. If private is specified, you may only retrieve metadata for the current user.
42
+ * @param {string=} appId - Namespace to use for the metadata, if retrieving app metadata. Uses the app ID specified on client initialization by default.
43
+ * @param {string=} userAddress - User to retrieve metadata for. If not specified, will retrieve metadata for the current user
44
+ * @param {string=} key - The metadata key to retrieve
45
+ *
46
+ * @returns {Promise<Object|String>} - Returns the specified metadata
47
+ */
48
+
49
+
50
+ exports.ProfileMetadata = /*#__PURE__*/function () {
51
+ var _ref4 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(_ref3) {
52
+ var _ref3$type, type, _ref3$mode, mode, appId, userAddress, key, response;
53
+
54
+ return _regeneratorRuntime.wrap(function _callee$(_context) {
55
+ while (1) {
56
+ switch (_context.prev = _context.next) {
57
+ case 0:
58
+ _ref3$type = _ref3.type, type = _ref3$type === void 0 ? "app" : _ref3$type, _ref3$mode = _ref3.mode, mode = _ref3$mode === void 0 ? "public" : _ref3$mode, appId = _ref3.appId, userAddress = _ref3.userAddress, key = _ref3.key;
59
+ _context.prev = 1;
60
+ _context.next = 4;
61
+ return this.stateStoreClient.Request({
62
+ path: UserProfilePath({
63
+ network: this.network,
64
+ appId: appId || this.appId,
65
+ userAddress: userAddress || this.UserAddress(),
66
+ type: type,
67
+ mode: mode,
68
+ key: key
69
+ }),
70
+ headers: mode === "private" ? {
71
+ Authorization: "Bearer ".concat(this.AuthToken())
72
+ } : undefined
73
+ });
74
+
75
+ case 4:
76
+ response = _context.sent;
77
+
78
+ if (response.ok) {
79
+ _context.next = 7;
80
+ break;
81
+ }
82
+
83
+ throw response;
84
+
85
+ case 7:
86
+ _context.next = 9;
87
+ return Utils.ResponseToJson(response);
88
+
89
+ case 9:
90
+ _context.t0 = key;
91
+ return _context.abrupt("return", _context.sent[_context.t0]);
92
+
93
+ case 13:
94
+ _context.prev = 13;
95
+ _context.t1 = _context["catch"](1);
96
+
97
+ if (!(_context.t1.status === 404)) {
98
+ _context.next = 17;
99
+ break;
100
+ }
101
+
102
+ return _context.abrupt("return", undefined);
103
+
104
+ case 17:
105
+ throw _context.t1;
106
+
107
+ case 18:
108
+ case "end":
109
+ return _context.stop();
110
+ }
111
+ }
112
+ }, _callee, this, [[1, 13]]);
113
+ }));
114
+
115
+ return function (_x) {
116
+ return _ref4.apply(this, arguments);
117
+ };
118
+ }();
119
+ /**
120
+ * Set user profile metadata for the current user
121
+ *
122
+ * @methodGroup ProfileMetadata
123
+ * @namedParams
124
+ * @param {string=} type="app" - Specify `app` or `user` metadata.
125
+ * @param {string=} mode="public" - Specify `public` or `private` metadata.
126
+ * @param {string=} appId - Namespace to use for the metadata, if retrieving app metadata. Uses the app ID specified on client initialization by default.
127
+ * @param {string} key - The metadata key to set
128
+ * @param {string} value - The metadata value to set
129
+ */
130
+
131
+
132
+ exports.SetProfileMetadata = /*#__PURE__*/function () {
133
+ var _ref6 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(_ref5) {
134
+ var _ref5$type, type, _ref5$mode, mode, appId, key, value;
135
+
136
+ return _regeneratorRuntime.wrap(function _callee2$(_context2) {
137
+ while (1) {
138
+ switch (_context2.prev = _context2.next) {
139
+ case 0:
140
+ _ref5$type = _ref5.type, type = _ref5$type === void 0 ? "app" : _ref5$type, _ref5$mode = _ref5.mode, mode = _ref5$mode === void 0 ? "public" : _ref5$mode, appId = _ref5.appId, key = _ref5.key, value = _ref5.value;
141
+ _context2.next = 3;
142
+ return this.stateStoreClient.Request({
143
+ method: "POST",
144
+ path: UserProfilePath({
145
+ network: this.network,
146
+ appId: appId || this.appId,
147
+ userAddress: this.UserAddress(),
148
+ type: type,
149
+ mode: mode,
150
+ key: key
151
+ }),
152
+ body: value,
153
+ bodyType: _typeof(value) === "object" ? "JSON" : "string",
154
+ headers: {
155
+ Authorization: "Bearer ".concat(this.AuthToken())
156
+ }
157
+ });
158
+
159
+ case 3:
160
+ case "end":
161
+ return _context2.stop();
162
+ }
163
+ }
164
+ }, _callee2, this);
165
+ }));
166
+
167
+ return function (_x2) {
168
+ return _ref6.apply(this, arguments);
169
+ };
170
+ }();
171
+ /**
172
+ * Remove user profile metadata for the current user
173
+ *
174
+ * @methodGroup ProfileMetadata
175
+ * @namedParams
176
+ * @param {string=} type="app" - Specify `app` or `user` metadata.
177
+ * @param {string=} mode="public" - Specify `public` or `private` metadata.
178
+ * @param {string=} appId - Namespace to use for the metadata, if retrieving app metadata.. Uses the app ID specified on client initialization by default.
179
+ * @param {string} key - The metadata key to set
180
+ * @param {string} value - The metadata value to set
181
+ */
182
+
183
+
184
+ exports.RemoveProfileMetadata = /*#__PURE__*/function () {
185
+ var _ref8 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(_ref7) {
186
+ var _ref7$type, type, _ref7$mode, mode, appId, key, value;
187
+
188
+ return _regeneratorRuntime.wrap(function _callee3$(_context3) {
189
+ while (1) {
190
+ switch (_context3.prev = _context3.next) {
191
+ case 0:
192
+ _ref7$type = _ref7.type, type = _ref7$type === void 0 ? "app" : _ref7$type, _ref7$mode = _ref7.mode, mode = _ref7$mode === void 0 ? "public" : _ref7$mode, appId = _ref7.appId, key = _ref7.key, value = _ref7.value;
193
+ _context3.next = 3;
194
+ return this.stateStoreClient.Request({
195
+ method: "DELETE",
196
+ path: UserProfilePath({
197
+ network: this.network,
198
+ appId: appId || this.appId,
199
+ userAddress: this.UserAddress(),
200
+ type: type,
201
+ mode: mode,
202
+ key: key
203
+ }),
204
+ body: value,
205
+ headers: {
206
+ Authorization: "Bearer ".concat(this.AuthToken())
207
+ }
208
+ });
209
+
210
+ case 3:
211
+ case "end":
212
+ return _context3.stop();
213
+ }
214
+ }
215
+ }, _callee3, this);
216
+ }));
217
+
218
+ return function (_x3) {
219
+ return _ref8.apply(this, arguments);
220
+ };
221
+ }();
222
+ /**
223
+ * Retrieve profile info for the specified user, including address, username and profile image (if set)
224
+ *
225
+ * @methodGroup Profile
226
+ * @param {string=} userAddress - Address of the user
227
+ * @param {string=} userName - Username of the user
228
+ *
229
+ * @returns {Promise<Object>} - Profile info of the specified user
230
+ */
231
+
232
+
233
+ exports.Profile = /*#__PURE__*/function () {
234
+ var _ref10 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4(_ref9) {
235
+ var userAddress, userName, imageUrl;
236
+ return _regeneratorRuntime.wrap(function _callee4$(_context4) {
237
+ while (1) {
238
+ switch (_context4.prev = _context4.next) {
239
+ case 0:
240
+ userAddress = _ref9.userAddress, userName = _ref9.userName;
241
+
242
+ if (!userName) {
243
+ _context4.next = 5;
244
+ break;
245
+ }
246
+
247
+ _context4.next = 4;
248
+ return this.UserNameToAddress({
249
+ userName: userName
250
+ });
251
+
252
+ case 4:
253
+ userAddress = _context4.sent;
254
+
255
+ case 5:
256
+ if (userAddress) {
257
+ _context4.next = 7;
258
+ break;
259
+ }
260
+
261
+ throw Error("Eluvio Wallet Client: Unable to determine profile - user address not specified");
262
+
263
+ case 7:
264
+ if (userName) {
265
+ _context4.next = 11;
266
+ break;
267
+ }
268
+
269
+ _context4.next = 10;
270
+ return this.ProfileMetadata({
271
+ type: "user",
272
+ userAddress: userAddress,
273
+ key: "username"
274
+ });
275
+
276
+ case 10:
277
+ userName = _context4.sent;
278
+
279
+ case 11:
280
+ _context4.next = 13;
281
+ return this.ProfileMetadata({
282
+ type: "user",
283
+ userAddress: userAddress,
284
+ key: "icon_url"
285
+ });
286
+
287
+ case 13:
288
+ imageUrl = _context4.sent;
289
+ return _context4.abrupt("return", {
290
+ userAddress: Utils.FormatAddress(userAddress),
291
+ userName: userName,
292
+ imageUrl: imageUrl
293
+ });
294
+
295
+ case 15:
296
+ case "end":
297
+ return _context4.stop();
298
+ }
299
+ }
300
+ }, _callee4, this);
301
+ }));
302
+
303
+ return function (_x4) {
304
+ return _ref10.apply(this, arguments);
305
+ };
306
+ }();
307
+
308
+ exports.UserNameToAddress = /*#__PURE__*/function () {
309
+ var _ref12 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee5(_ref11) {
310
+ var userName, response;
311
+ return _regeneratorRuntime.wrap(function _callee5$(_context5) {
312
+ while (1) {
313
+ switch (_context5.prev = _context5.next) {
314
+ case 0:
315
+ userName = _ref11.userName;
316
+ _context5.prev = 1;
317
+ _context5.next = 4;
318
+ return this.stateStoreClient.Request({
319
+ method: "GET",
320
+ path: StateStorePath({
321
+ network: this.network,
322
+ path: UrlJoin("usr", "profile_for_username", userName)
323
+ })
324
+ });
325
+
326
+ case 4:
327
+ response = _context5.sent;
328
+
329
+ if (response.ok) {
330
+ _context5.next = 7;
331
+ break;
332
+ }
333
+
334
+ throw response;
335
+
336
+ case 7:
337
+ _context5.next = 9;
338
+ return Utils.ResponseToJson(response);
339
+
340
+ case 9:
341
+ return _context5.abrupt("return", _context5.sent.address);
342
+
343
+ case 12:
344
+ _context5.prev = 12;
345
+ _context5.t0 = _context5["catch"](1);
346
+
347
+ if (!(_context5.t0.status !== 404)) {
348
+ _context5.next = 16;
349
+ break;
350
+ }
351
+
352
+ throw _context5.t0;
353
+
354
+ case 16:
355
+ return _context5.abrupt("return", undefined);
356
+
357
+ case 17:
358
+ case "end":
359
+ return _context5.stop();
360
+ }
361
+ }
362
+ }, _callee5, this, [[1, 12]]);
363
+ }));
364
+
365
+ return function (_x5) {
366
+ return _ref12.apply(this, arguments);
367
+ };
368
+ }();
@@ -37,8 +37,29 @@ var RarityToPercentage = function RarityToPercentage(rarity) {
37
37
  }
38
38
 
39
39
  return percentage;
40
- }; // Format NFT or listing result into consistent format
40
+ };
41
41
 
42
+ var LinkTargetHash = function LinkTargetHash(link) {
43
+ if (!link) {
44
+ return;
45
+ }
46
+
47
+ if (link["."] && link["."].source) {
48
+ return link["."].source;
49
+ }
50
+
51
+ if (link["/"] && link["/"].startsWith("/qfab/")) {
52
+ return link["/"].split("/").find(function (segment) {
53
+ return segment.startsWith("hq__");
54
+ });
55
+ }
56
+
57
+ if (link["."] && link["."].container) {
58
+ return link["."].container;
59
+ }
60
+ };
61
+
62
+ exports.LinkTargetHash = LinkTargetHash; // Format NFT or listing result into consistent format
42
63
 
43
64
  var FormatNFTDetails = function FormatNFTDetails(entry) {
44
65
  var isListing = !!entry.id;
@@ -88,7 +109,7 @@ var FormatNFTDetails = function FormatNFTDetails(entry) {
88
109
 
89
110
  exports.FormatNFTDetails = FormatNFTDetails;
90
111
 
91
- var FormatNFTMetadata = function FormatNFTMetadata(nft) {
112
+ var FormatNFTMetadata = function FormatNFTMetadata(walletClient, nft) {
92
113
  nft.formatted = true; // Surface relevant details to top level
93
114
 
94
115
  nft.contractAddress = nft.details.ContractAddr;
@@ -125,10 +146,13 @@ var FormatNFTMetadata = function FormatNFTMetadata(nft) {
125
146
 
126
147
  var embedUrl = new URL("https://embed.v3.contentfabric.io");
127
148
  embedUrl.searchParams.set("p", "");
128
- embedUrl.searchParams.set("net", rootStore.network === "demo" ? "demo" : "main");
129
- embedUrl.searchParams.set("ath", rootStore.authToken);
149
+ embedUrl.searchParams.set("net", walletClient.network === "demo" ? "demo" : "main");
130
150
 
131
- if (mediaType === "video") {
151
+ if (media.requires_permissions) {
152
+ embedUrl.searchParams.set("ath", walletClient.AuthToken());
153
+ }
154
+
155
+ if (["video", "audio"].includes(mediaType)) {
132
156
  embedUrl.searchParams.set("vid", LinkTargetHash(media.media_link));
133
157
  embedUrl.searchParams.set("ct", "h");
134
158
  embedUrl.searchParams.set("ap", "");
@@ -142,6 +166,7 @@ var FormatNFTMetadata = function FormatNFTMetadata(nft) {
142
166
  embed_url: embedUrl.toString()
143
167
  });
144
168
  } catch (error) {
169
+ walletClient.Log(error, true);
145
170
  return media;
146
171
  }
147
172
  });
@@ -153,8 +178,7 @@ var FormatNFTMetadata = function FormatNFTMetadata(nft) {
153
178
  if (nft.metadata.pack_options && nft.metadata.pack_options[key]) {
154
179
  var embedUrl = new URL("https://embed.v3.contentfabric.io");
155
180
  embedUrl.searchParams.set("p", "");
156
- embedUrl.searchParams.set("net", rootStore.network === "demo" ? "demo" : "main");
157
- embedUrl.searchParams.set("ath", rootStore.authToken || rootStore.staticToken);
181
+ embedUrl.searchParams.set("net", walletClient.network === "demo" ? "demo" : "main");
158
182
  embedUrl.searchParams.set("vid", LinkTargetHash(nft.metadata.pack_options[key]));
159
183
  embedUrl.searchParams.set("ap", "");
160
184
 
@@ -173,28 +197,8 @@ var FormatNFTMetadata = function FormatNFTMetadata(nft) {
173
197
 
174
198
  exports.FormatNFTMetadata = FormatNFTMetadata;
175
199
 
176
- exports.FormatNFT = function (item) {
177
- return FormatNFTMetadata(FormatNFTDetails(item));
178
- };
179
-
180
- exports.LinkTargetHash = function (link) {
181
- if (!link) {
182
- return;
183
- }
184
-
185
- if (link["."] && link["."].source) {
186
- return link["."].source;
187
- }
188
-
189
- if (link["/"] && link["/"].startsWith("/qfab/")) {
190
- return link["/"].split("/").find(function (segment) {
191
- return segment.startsWith("hq__");
192
- });
193
- }
194
-
195
- if (link["."] && link["."].container) {
196
- return link["."].container;
197
- }
200
+ exports.FormatNFT = function (walletClient, item) {
201
+ return FormatNFTMetadata(walletClient, FormatNFTDetails(item));
198
202
  }; // https://stackoverflow.com/questions/4068373/center-a-popup-window-on-screen
199
203
 
200
204