@eluvio/elv-client-js 3.2.4 → 3.2.5

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 (46) hide show
  1. package/dist/ElvClient-min.js +15 -11
  2. package/dist/ElvClient-node-min.js +17 -13
  3. package/dist/ElvFrameClient-min.js +12 -8
  4. package/dist/ElvPermissionsClient-min.js +13 -9
  5. package/dist/ElvWalletClient-min.js +58 -0
  6. package/dist/ElvWalletClient-node-min.js +78 -0
  7. package/dist/src/AuthorizationClient.js +2248 -1990
  8. package/dist/src/ContentObjectVerification.js +164 -173
  9. package/dist/src/Crypto.js +376 -324
  10. package/dist/src/ElvClient.js +1185 -1019
  11. package/dist/src/ElvWallet.js +119 -95
  12. package/dist/src/EthClient.js +1040 -896
  13. package/dist/src/FrameClient.js +331 -300
  14. package/dist/src/HttpClient.js +153 -147
  15. package/dist/src/Id.js +1 -3
  16. package/dist/src/PermissionsClient.js +1294 -1168
  17. package/dist/src/RemoteSigner.js +263 -211
  18. package/dist/src/UserProfileClient.js +1164 -1023
  19. package/dist/src/Utils.js +229 -184
  20. package/dist/src/client/ABRPublishing.js +895 -858
  21. package/dist/src/client/AccessGroups.js +1102 -959
  22. package/dist/src/client/ContentAccess.js +3724 -3431
  23. package/dist/src/client/ContentManagement.js +2252 -2068
  24. package/dist/src/client/Contracts.js +647 -563
  25. package/dist/src/client/Files.js +1886 -1757
  26. package/dist/src/client/NFT.js +126 -112
  27. package/dist/src/client/NTP.js +478 -422
  28. package/dist/src/index.js +11 -0
  29. package/dist/src/marketplaceClient/ClientMethods.js +1918 -0
  30. package/dist/src/marketplaceClient/Configuration.js +29 -0
  31. package/dist/src/marketplaceClient/Utils.js +304 -0
  32. package/dist/src/marketplaceClient/index.js +1553 -0
  33. package/dist/src/walletClient/ClientMethods.js +1978 -0
  34. package/dist/src/walletClient/Configuration.js +29 -0
  35. package/dist/src/walletClient/Utils.js +304 -0
  36. package/dist/src/walletClient/index.js +1571 -0
  37. package/package.json +8 -4
  38. package/src/ElvClient.js +4 -1
  39. package/src/Utils.js +22 -4
  40. package/src/index.js +7 -0
  41. package/src/walletClient/ClientMethods.js +1048 -0
  42. package/src/walletClient/Configuration.js +40 -0
  43. package/src/walletClient/README.md +185 -0
  44. package/src/walletClient/Utils.js +234 -0
  45. package/src/walletClient/index.js +884 -0
  46. package/testScripts/TestMarketplaceClient.js +25 -0
@@ -0,0 +1,1571 @@
1
+ var _typeof = require("@babel/runtime/helpers/typeof");
2
+
3
+ var _slicedToArray = require("@babel/runtime/helpers/slicedToArray");
4
+
5
+ var _defineProperty = require("@babel/runtime/helpers/defineProperty");
6
+
7
+ var _regeneratorRuntime = require("@babel/runtime/regenerator");
8
+
9
+ var _asyncToGenerator = require("@babel/runtime/helpers/asyncToGenerator");
10
+
11
+ var _classCallCheck = require("@babel/runtime/helpers/classCallCheck");
12
+
13
+ var _createClass = require("@babel/runtime/helpers/createClass");
14
+
15
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
16
+
17
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
18
+
19
+ var _require = require("../ElvClient"),
20
+ ElvClient = _require.ElvClient;
21
+
22
+ var Configuration = require("./Configuration");
23
+
24
+ var _require2 = require("./Utils"),
25
+ LinkTargetHash = _require2.LinkTargetHash,
26
+ FormatNFT = _require2.FormatNFT,
27
+ ActionPopup = _require2.ActionPopup;
28
+
29
+ var UrlJoin = require("url-join");
30
+
31
+ var Utils = require("../Utils");
32
+ /**
33
+ * Use the <a href="#.Initialize">Initialize</a> method to initialize a new client.
34
+ *
35
+ *
36
+ * See the Modules section on the sidebar for all client methods unrelated to login and authorization
37
+ */
38
+
39
+
40
+ var ElvWalletClient = /*#__PURE__*/function () {
41
+ "use strict";
42
+
43
+ function ElvWalletClient(_ref) {
44
+ var client = _ref.client,
45
+ network = _ref.network,
46
+ mode = _ref.mode,
47
+ marketplaceInfo = _ref.marketplaceInfo,
48
+ storeAuthToken = _ref.storeAuthToken;
49
+
50
+ _classCallCheck(this, ElvWalletClient);
51
+
52
+ this.client = client;
53
+ this.loggedIn = false;
54
+ this.network = network;
55
+ this.mode = mode;
56
+ this.purchaseMode = Configuration[network][mode].purchaseMode;
57
+ this.mainSiteId = Configuration[network][mode].siteId;
58
+ this.appUrl = Configuration[network][mode].appUrl;
59
+ this.publicStaticToken = client.staticToken;
60
+ this.storeAuthToken = storeAuthToken;
61
+ this.selectedMarketplaceInfo = marketplaceInfo;
62
+ this.availableMarketplaces = {};
63
+ this.availableMarketplacesById = {};
64
+ this.marketplaceHashes = {}; // Caches
65
+
66
+ this.cachedMarketplaces = {};
67
+ this.cachedCSS = {};
68
+ this.utils = client.utils;
69
+ }
70
+
71
+ _createClass(ElvWalletClient, [{
72
+ key: "Log",
73
+ value: function Log(message) {
74
+ var error = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
75
+
76
+ if (error) {
77
+ // eslint-disable-next-line no-console
78
+ console.error("Eluvio Wallet Client:", message);
79
+ } else {
80
+ // eslint-disable-next-line no-console
81
+ console.log("Eluvio Wallet Client:", message);
82
+ }
83
+ }
84
+ /**
85
+ * Initialize the wallet client.
86
+ *
87
+ * Specify tenantSlug and marketplaceSlug to automatically associate this tenant with a particular marketplace.
88
+ *
89
+ * @methodGroup Initialization
90
+ * @namedParams
91
+ * @param {string} network=main - Name of the Fabric network to use (`main`, `demo`)
92
+ * @param {string} mode=production - Environment to use (`production`, `staging`)
93
+ * @param {Object=} marketplaceParams - Marketplace parameters
94
+ * @param {boolean=} storeAuthToken=true - If specified, auth tokens will be stored in localstorage (if available)
95
+ *
96
+ * @returns {Promise<ElvWalletClient>}
97
+ */
98
+
99
+ }, {
100
+ key: "LogIn",
101
+ value:
102
+ /* Login and authorization */
103
+
104
+ /**
105
+ * Direct the user to the Eluvio Media Wallet login page.
106
+ *
107
+ * <b>NOTE:</b> The domain of the opening window (popup flow) or domain of the `callbackUrl` (redirect flow) MUST be allowed in the metadata of the specified marketplace.
108
+ *
109
+ * @methodGroup Login
110
+ * @namedParams
111
+ * @param {string=} method=redirect - How to present the login page.
112
+ * - `redirect` - Redirect to the wallet login page. Upon login, the page will be redirected back to the specified `redirectUrl` with the authorization token.
113
+ * - `popup` - Open the wallet login page in a new tab. Upon login, authorization information will be sent back to the client via message and the tab will be closed.
114
+ * @param {string=} provider - If logging in via a specific method, specify the provider and mode. Options: `oauth`, `metamask`
115
+ * @param {string=} mode - If logging in via a specific method, specify the mode. Options `login` (Log In), `create` (Sign Up)
116
+ * @param {string=} callbackUrl - If using the redirect flow, the URL to redirect back to after login.
117
+ * @param {Object=} marketplaceParams - Parameters of a marketplace to associate the login with. If not specified, the marketplace parameters used upon client initialization will be used. A marketplace is required when using the redirect flow.
118
+ * @param {boolean=} clearLogin=false - If specified, the user will be prompted to log in anew even if they are already logged in on the Eluvio Media Wallet app
119
+ *
120
+ * @throws - If using the popup flow and the user closes the popup, this method will throw an error.
121
+ */
122
+ function () {
123
+ var _LogIn = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(_ref2) {
124
+ var _this = this;
125
+
126
+ var _ref2$method, method, provider, _ref2$mode, mode, callbackUrl, marketplaceParams, _ref2$clearLogin, clearLogin, callback, loginUrl;
127
+
128
+ return _regeneratorRuntime.wrap(function _callee3$(_context3) {
129
+ while (1) {
130
+ switch (_context3.prev = _context3.next) {
131
+ case 0:
132
+ _ref2$method = _ref2.method, method = _ref2$method === void 0 ? "redirect" : _ref2$method, provider = _ref2.provider, _ref2$mode = _ref2.mode, mode = _ref2$mode === void 0 ? "login" : _ref2$mode, callbackUrl = _ref2.callbackUrl, marketplaceParams = _ref2.marketplaceParams, _ref2$clearLogin = _ref2.clearLogin, clearLogin = _ref2$clearLogin === void 0 ? false : _ref2$clearLogin, callback = _ref2.callback;
133
+ loginUrl = new URL(this.appUrl);
134
+ loginUrl.hash = "/login";
135
+ loginUrl.searchParams.set("origin", window.location.origin);
136
+ loginUrl.searchParams.set("action", "login");
137
+
138
+ if (provider) {
139
+ loginUrl.searchParams.set("provider", provider);
140
+ }
141
+
142
+ if (mode) {
143
+ loginUrl.searchParams.set("mode", mode);
144
+ }
145
+
146
+ if (!marketplaceParams) {
147
+ _context3.next = 15;
148
+ break;
149
+ }
150
+
151
+ _context3.t0 = loginUrl.searchParams;
152
+ _context3.next = 11;
153
+ return this.MarketplaceInfo({
154
+ marketplaceParams: marketplaceParams
155
+ });
156
+
157
+ case 11:
158
+ _context3.t1 = _context3.sent.marketplaceHash;
159
+
160
+ _context3.t0.set.call(_context3.t0, "mid", _context3.t1);
161
+
162
+ _context3.next = 16;
163
+ break;
164
+
165
+ case 15:
166
+ if ((this.selectedMarketplaceInfo || {}).marketplaceHash) {
167
+ loginUrl.searchParams.set("mid", this.selectedMarketplaceInfo.marketplaceHash);
168
+ }
169
+
170
+ case 16:
171
+ if (clearLogin) {
172
+ loginUrl.searchParams.set("clear", "");
173
+ }
174
+
175
+ if (!(method === "redirect")) {
176
+ _context3.next = 24;
177
+ break;
178
+ }
179
+
180
+ loginUrl.searchParams.set("response", "redirect");
181
+ loginUrl.searchParams.set("source", "origin");
182
+ loginUrl.searchParams.set("redirect", callbackUrl);
183
+ window.location = loginUrl;
184
+ _context3.next = 28;
185
+ break;
186
+
187
+ case 24:
188
+ loginUrl.searchParams.set("response", "message");
189
+ loginUrl.searchParams.set("source", "parent");
190
+ _context3.next = 28;
191
+ return new Promise( /*#__PURE__*/function () {
192
+ var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(resolve, reject) {
193
+ return _regeneratorRuntime.wrap(function _callee2$(_context2) {
194
+ while (1) {
195
+ switch (_context2.prev = _context2.next) {
196
+ case 0:
197
+ _context2.next = 2;
198
+ return ActionPopup({
199
+ mode: "tab",
200
+ url: loginUrl.toString(),
201
+ onCancel: function onCancel() {
202
+ return reject("User cancelled login");
203
+ },
204
+ onMessage: function () {
205
+ var _onMessage = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(event, Close) {
206
+ return _regeneratorRuntime.wrap(function _callee$(_context) {
207
+ while (1) {
208
+ switch (_context.prev = _context.next) {
209
+ case 0:
210
+ if (!(!event || !event.data || event.data.type !== "LoginResponse")) {
211
+ _context.next = 2;
212
+ break;
213
+ }
214
+
215
+ return _context.abrupt("return");
216
+
217
+ case 2:
218
+ _context.prev = 2;
219
+
220
+ if (!callback) {
221
+ _context.next = 8;
222
+ break;
223
+ }
224
+
225
+ _context.next = 6;
226
+ return callback(event.data.params);
227
+
228
+ case 6:
229
+ _context.next = 10;
230
+ break;
231
+
232
+ case 8:
233
+ _context.next = 10;
234
+ return _this.Authenticate({
235
+ token: event.data.params.clientSigningToken || event.data.params.clientAuthToken
236
+ });
237
+
238
+ case 10:
239
+ resolve();
240
+ _context.next = 16;
241
+ break;
242
+
243
+ case 13:
244
+ _context.prev = 13;
245
+ _context.t0 = _context["catch"](2);
246
+ reject(_context.t0);
247
+
248
+ case 16:
249
+ _context.prev = 16;
250
+ Close();
251
+ return _context.finish(16);
252
+
253
+ case 19:
254
+ case "end":
255
+ return _context.stop();
256
+ }
257
+ }
258
+ }, _callee, null, [[2, 13, 16, 19]]);
259
+ }));
260
+
261
+ function onMessage(_x4, _x5) {
262
+ return _onMessage.apply(this, arguments);
263
+ }
264
+
265
+ return onMessage;
266
+ }()
267
+ });
268
+
269
+ case 2:
270
+ case "end":
271
+ return _context2.stop();
272
+ }
273
+ }
274
+ }, _callee2);
275
+ }));
276
+
277
+ return function (_x2, _x3) {
278
+ return _ref3.apply(this, arguments);
279
+ };
280
+ }());
281
+
282
+ case 28:
283
+ case "end":
284
+ return _context3.stop();
285
+ }
286
+ }
287
+ }, _callee3, this);
288
+ }));
289
+
290
+ function LogIn(_x) {
291
+ return _LogIn.apply(this, arguments);
292
+ }
293
+
294
+ return LogIn;
295
+ }()
296
+ /**
297
+ * Remove authorization for the current user.
298
+ *
299
+ * @methodGroup Login
300
+ */
301
+
302
+ }, {
303
+ key: "LogOut",
304
+ value: function LogOut() {
305
+ this.__authorization = {};
306
+ this.loggedIn = false;
307
+ this.cachedMarketplaces = {}; // Delete saved auth token
308
+
309
+ if (typeof localStorage !== "undefined") {
310
+ try {
311
+ localStorage.removeItem("__elv-token-".concat(this.network)); // eslint-disable-next-line no-empty
312
+ } catch (error) {}
313
+ }
314
+ }
315
+ /**
316
+ * Authenticate with an ElvWalletClient authorization token
317
+ *
318
+ * @methodGroup Authorization
319
+ * @namedParams
320
+ * @param {string} token - A previously generated ElvWalletClient authorization token;
321
+ */
322
+
323
+ }, {
324
+ key: "Authenticate",
325
+ value: function () {
326
+ var _Authenticate = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4(_ref4) {
327
+ var token, decodedToken;
328
+ return _regeneratorRuntime.wrap(function _callee4$(_context4) {
329
+ while (1) {
330
+ switch (_context4.prev = _context4.next) {
331
+ case 0:
332
+ token = _ref4.token;
333
+ _context4.prev = 1;
334
+ decodedToken = JSON.parse(this.utils.FromB58ToStr(token)) || {};
335
+ _context4.next = 8;
336
+ break;
337
+
338
+ case 5:
339
+ _context4.prev = 5;
340
+ _context4.t0 = _context4["catch"](1);
341
+ throw new Error("Invalid authorization token " + token);
342
+
343
+ case 8:
344
+ if (!(!decodedToken.expiresAt || Date.now() > decodedToken.expiresAt)) {
345
+ _context4.next = 10;
346
+ break;
347
+ }
348
+
349
+ throw Error("ElvWalletClient: Provided authorization token has expired");
350
+
351
+ case 10:
352
+ this.client.SetStaticToken({
353
+ token: decodedToken.fabricToken
354
+ });
355
+
356
+ if (decodedToken.clusterToken) {
357
+ this.client.SetRemoteSigner({
358
+ authToken: decodedToken.clusterToken
359
+ });
360
+ }
361
+
362
+ return _context4.abrupt("return", this.SetAuthorization(decodedToken));
363
+
364
+ case 13:
365
+ case "end":
366
+ return _context4.stop();
367
+ }
368
+ }
369
+ }, _callee4, this, [[1, 5]]);
370
+ }));
371
+
372
+ function Authenticate(_x6) {
373
+ return _Authenticate.apply(this, arguments);
374
+ }
375
+
376
+ return Authenticate;
377
+ }()
378
+ /**
379
+ * Authenticate with an OAuth ID token
380
+ *
381
+ * @methodGroup Authorization
382
+ * @namedParams
383
+ * @param {string} idToken - An OAuth ID token
384
+ * @param {string=} tenantId - ID of tenant with which to associate the user. If marketplace info was set upon initialization, this will be determined automatically.
385
+ * @param {string=} email - Email address of the user. If not specified, this method will attempt to extract the email from the ID token.
386
+ * @param {boolean=} shareEmail=false - Whether or not the user consents to sharing their email
387
+ * @param {number=} tokenDuration=24 - Number of hours the generated authorization token will last before expiring
388
+ *
389
+ * @returns {Promise<Object>} - Returns an authorization tokens that can be used to initialize the client using <a href="#Authenticate">Authenticate</a>.
390
+ * Save this token to avoid having to reauthenticate with OAuth. This token expires after 24 hours.
391
+ *
392
+ * The result includes two tokens:
393
+ * - token - Standard client auth token used to access content and perform actions on behalf of the user.
394
+ * - signingToken - Identical to `authToken`, but also includes the ability to perform arbitrary signatures with the custodial wallet. This token should be protected and should not be
395
+ * shared with third parties.
396
+ */
397
+
398
+ }, {
399
+ key: "AuthenticateOAuth",
400
+ value: function () {
401
+ var _AuthenticateOAuth = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee5(_ref5) {
402
+ var idToken, tenantId, email, _ref5$shareEmail, shareEmail, _ref5$tokenDuration, tokenDuration, expiresAt, fabricToken, address, decodedToken;
403
+
404
+ return _regeneratorRuntime.wrap(function _callee5$(_context5) {
405
+ while (1) {
406
+ switch (_context5.prev = _context5.next) {
407
+ case 0:
408
+ idToken = _ref5.idToken, tenantId = _ref5.tenantId, email = _ref5.email, _ref5$shareEmail = _ref5.shareEmail, shareEmail = _ref5$shareEmail === void 0 ? false : _ref5$shareEmail, _ref5$tokenDuration = _ref5.tokenDuration, tokenDuration = _ref5$tokenDuration === void 0 ? 24 : _ref5$tokenDuration;
409
+
410
+ if (!(!tenantId && this.selectedMarketplaceInfo)) {
411
+ _context5.next = 5;
412
+ break;
413
+ }
414
+
415
+ _context5.next = 4;
416
+ return this.AvailableMarketplaces();
417
+
418
+ case 4:
419
+ tenantId = this.selectedMarketplaceInfo.tenantId;
420
+
421
+ case 5:
422
+ _context5.next = 7;
423
+ return this.client.SetRemoteSigner({
424
+ idToken: idToken,
425
+ tenantId: tenantId,
426
+ extraData: {
427
+ share_email: shareEmail
428
+ },
429
+ unsignedPublicAuth: true
430
+ });
431
+
432
+ case 7:
433
+ expiresAt = Date.now() + tokenDuration * 60 * 60 * 1000;
434
+ _context5.next = 10;
435
+ return this.client.CreateFabricToken({
436
+ duration: tokenDuration * 60 * 60 * 1000
437
+ });
438
+
439
+ case 10:
440
+ fabricToken = _context5.sent;
441
+ address = this.client.utils.FormatAddress(this.client.CurrentAccountAddress());
442
+
443
+ if (email) {
444
+ _context5.next = 21;
445
+ break;
446
+ }
447
+
448
+ _context5.prev = 13;
449
+ decodedToken = JSON.parse(this.utils.FromB64URL(idToken.split(".")[1]));
450
+ email = decodedToken.email;
451
+ _context5.next = 21;
452
+ break;
453
+
454
+ case 18:
455
+ _context5.prev = 18;
456
+ _context5.t0 = _context5["catch"](13);
457
+ throw Error("Failed to decode ID token");
458
+
459
+ case 21:
460
+ this.client.SetStaticToken({
461
+ token: fabricToken
462
+ });
463
+ return _context5.abrupt("return", {
464
+ authToken: this.SetAuthorization({
465
+ fabricToken: fabricToken,
466
+ tenantId: tenantId,
467
+ address: address,
468
+ email: email,
469
+ expiresAt: expiresAt,
470
+ walletType: "Custodial",
471
+ walletName: "Eluvio"
472
+ }),
473
+ signingToken: this.SetAuthorization({
474
+ clusterToken: this.client.signer.authToken,
475
+ fabricToken: fabricToken,
476
+ tenantId: tenantId,
477
+ address: address,
478
+ email: email,
479
+ expiresAt: expiresAt,
480
+ walletType: "Custodial",
481
+ walletName: "Eluvio"
482
+ })
483
+ });
484
+
485
+ case 23:
486
+ case "end":
487
+ return _context5.stop();
488
+ }
489
+ }
490
+ }, _callee5, this, [[13, 18]]);
491
+ }));
492
+
493
+ function AuthenticateOAuth(_x7) {
494
+ return _AuthenticateOAuth.apply(this, arguments);
495
+ }
496
+
497
+ return AuthenticateOAuth;
498
+ }()
499
+ /**
500
+ * Authenticate with an external Ethereum compatible wallet, like Metamask.
501
+ *
502
+ * @methodGroup Authorization
503
+ * @namedParams
504
+ * @param {string} address - The address of the wallet
505
+ * @param {number=} tokenDuration=24 - Number of hours the generated authorization token will last before expiring
506
+ * @param {string=} walletName=Metamask - Name of the external wallet
507
+ * @param {function=} Sign - The method used for signing by the wallet. If not specified, will attempt to sign with Metamask.
508
+ *
509
+ * @returns {Promise<string>} - Returns an authorization token that can be used to initialize the client using <a href="#Authenticate">Authenticate</a>.
510
+ * Save this token to avoid having to reauthenticate. This token expires after 24 hours.
511
+ */
512
+
513
+ }, {
514
+ key: "AuthenticateExternalWallet",
515
+ value: function () {
516
+ var _AuthenticateExternalWallet = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee7(_ref6) {
517
+ var _this2 = this;
518
+
519
+ var address, _ref6$tokenDuration, tokenDuration, _ref6$walletName, walletName, Sign, expiresAt, fabricToken;
520
+
521
+ return _regeneratorRuntime.wrap(function _callee7$(_context7) {
522
+ while (1) {
523
+ switch (_context7.prev = _context7.next) {
524
+ case 0:
525
+ address = _ref6.address, _ref6$tokenDuration = _ref6.tokenDuration, tokenDuration = _ref6$tokenDuration === void 0 ? 24 : _ref6$tokenDuration, _ref6$walletName = _ref6.walletName, walletName = _ref6$walletName === void 0 ? "Metamask" : _ref6$walletName, Sign = _ref6.Sign;
526
+
527
+ if (!address) {
528
+ address = window.ethereum.selectedAddress;
529
+ }
530
+
531
+ address = this.utils.FormatAddress(address);
532
+
533
+ if (!Sign) {
534
+ Sign = /*#__PURE__*/function () {
535
+ var _ref7 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee6(message) {
536
+ return _regeneratorRuntime.wrap(function _callee6$(_context6) {
537
+ while (1) {
538
+ switch (_context6.prev = _context6.next) {
539
+ case 0:
540
+ return _context6.abrupt("return", _this2.SignMetamask({
541
+ message: message,
542
+ address: address
543
+ }));
544
+
545
+ case 1:
546
+ case "end":
547
+ return _context6.stop();
548
+ }
549
+ }
550
+ }, _callee6);
551
+ }));
552
+
553
+ return function Sign(_x9) {
554
+ return _ref7.apply(this, arguments);
555
+ };
556
+ }();
557
+ }
558
+
559
+ expiresAt = Date.now() + tokenDuration * 60 * 60 * 1000;
560
+ _context7.next = 7;
561
+ return this.client.CreateFabricToken({
562
+ address: address,
563
+ duration: tokenDuration * 60 * 60 * 1000,
564
+ Sign: Sign,
565
+ addEthereumPrefix: false
566
+ });
567
+
568
+ case 7:
569
+ fabricToken = _context7.sent;
570
+ return _context7.abrupt("return", this.SetAuthorization({
571
+ fabricToken: fabricToken,
572
+ address: address,
573
+ expiresAt: expiresAt,
574
+ walletType: "External",
575
+ walletName: walletName
576
+ }));
577
+
578
+ case 9:
579
+ case "end":
580
+ return _context7.stop();
581
+ }
582
+ }
583
+ }, _callee7, this);
584
+ }));
585
+
586
+ function AuthenticateExternalWallet(_x8) {
587
+ return _AuthenticateExternalWallet.apply(this, arguments);
588
+ }
589
+
590
+ return AuthenticateExternalWallet;
591
+ }()
592
+ /**
593
+ * <b><i>Requires login</i></b>
594
+ *
595
+ * Retrieve the current client auth token
596
+ *
597
+ * @returns {string} - The client auth token
598
+ */
599
+
600
+ }, {
601
+ key: "ClientAuthToken",
602
+ value: function ClientAuthToken() {
603
+ if (!this.loggedIn) {
604
+ return "";
605
+ }
606
+
607
+ return this.utils.B58(JSON.stringify(this.__authorization));
608
+ }
609
+ }, {
610
+ key: "AuthToken",
611
+ value: function AuthToken() {
612
+ if (!this.loggedIn) {
613
+ return this.publicStaticToken;
614
+ }
615
+
616
+ return this.__authorization.fabricToken;
617
+ }
618
+ }, {
619
+ key: "SetAuthorization",
620
+ value: function SetAuthorization(_ref8) {
621
+ var clusterToken = _ref8.clusterToken,
622
+ fabricToken = _ref8.fabricToken,
623
+ tenantId = _ref8.tenantId,
624
+ address = _ref8.address,
625
+ email = _ref8.email,
626
+ expiresAt = _ref8.expiresAt,
627
+ walletType = _ref8.walletType,
628
+ walletName = _ref8.walletName;
629
+ address = this.client.utils.FormatAddress(address);
630
+ this.__authorization = {
631
+ fabricToken: fabricToken,
632
+ tenantId: tenantId,
633
+ address: address,
634
+ email: email,
635
+ expiresAt: expiresAt,
636
+ walletType: walletType,
637
+ walletName: walletName
638
+ };
639
+
640
+ if (clusterToken) {
641
+ this.__authorization.clusterToken = clusterToken;
642
+ }
643
+
644
+ this.loggedIn = true;
645
+ this.cachedMarketplaces = {};
646
+ var token = this.ClientAuthToken();
647
+
648
+ if (this.storeAuthToken && typeof localStorage !== "undefined") {
649
+ try {
650
+ localStorage.setItem("__elv-token-".concat(this.network), token); // eslint-disable-next-line no-empty
651
+ } catch (error) {}
652
+ }
653
+
654
+ return token;
655
+ }
656
+ }, {
657
+ key: "SignMetamask",
658
+ value: function () {
659
+ var _SignMetamask = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee8(_ref9) {
660
+ var message, address, from;
661
+ return _regeneratorRuntime.wrap(function _callee8$(_context8) {
662
+ while (1) {
663
+ switch (_context8.prev = _context8.next) {
664
+ case 0:
665
+ message = _ref9.message, address = _ref9.address;
666
+
667
+ if (window.ethereum) {
668
+ _context8.next = 3;
669
+ break;
670
+ }
671
+
672
+ throw Error("ElvWalletClient: Unable to initialize - Metamask not available");
673
+
674
+ case 3:
675
+ _context8.next = 5;
676
+ return window.ethereum.request({
677
+ method: "eth_requestAccounts"
678
+ });
679
+
680
+ case 5:
681
+ from = address || window.ethereum.selectedAddress;
682
+ _context8.next = 8;
683
+ return window.ethereum.request({
684
+ method: "personal_sign",
685
+ params: [message, from, ""]
686
+ });
687
+
688
+ case 8:
689
+ return _context8.abrupt("return", _context8.sent);
690
+
691
+ case 9:
692
+ case "end":
693
+ return _context8.stop();
694
+ }
695
+ }
696
+ }, _callee8);
697
+ }));
698
+
699
+ function SignMetamask(_x10) {
700
+ return _SignMetamask.apply(this, arguments);
701
+ }
702
+
703
+ return SignMetamask;
704
+ }() // Internal loading methods
705
+ // If marketplace slug is specified, load only that marketplace. Otherwise load all
706
+
707
+ }, {
708
+ key: "LoadAvailableMarketplaces",
709
+ value: function () {
710
+ var _LoadAvailableMarketplaces = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee9() {
711
+ var _this3 = this;
712
+
713
+ var forceReload,
714
+ mainSiteHash,
715
+ metadata,
716
+ availableMarketplaces,
717
+ availableMarketplacesById,
718
+ _args9 = arguments;
719
+ return _regeneratorRuntime.wrap(function _callee9$(_context9) {
720
+ while (1) {
721
+ switch (_context9.prev = _context9.next) {
722
+ case 0:
723
+ forceReload = _args9.length > 0 && _args9[0] !== undefined ? _args9[0] : false;
724
+
725
+ if (!(!forceReload && Object.keys(this.availableMarketplaces) > 0)) {
726
+ _context9.next = 3;
727
+ break;
728
+ }
729
+
730
+ return _context9.abrupt("return");
731
+
732
+ case 3:
733
+ _context9.next = 5;
734
+ return this.client.LatestVersionHash({
735
+ objectId: this.mainSiteId
736
+ });
737
+
738
+ case 5:
739
+ mainSiteHash = _context9.sent;
740
+ _context9.next = 8;
741
+ return this.client.ContentObjectMetadata({
742
+ versionHash: mainSiteHash,
743
+ metadataSubtree: "public/asset_metadata/tenants",
744
+ resolveLinks: true,
745
+ linkDepthLimit: 2,
746
+ resolveIncludeSource: true,
747
+ resolveIgnoreErrors: true,
748
+ produceLinkUrls: true,
749
+ authorizationToken: this.publicStaticToken,
750
+ noAuth: true,
751
+ select: ["*/.", "*/marketplaces/*/.", "*/marketplaces/*/info/tenant_id", "*/marketplaces/*/info/tenant_name", "*/marketplaces/*/info/branding"],
752
+ remove: ["*/marketplaces/*/info/branding/custom_css"]
753
+ });
754
+
755
+ case 8:
756
+ metadata = _context9.sent;
757
+ availableMarketplaces = _objectSpread({}, this.availableMarketplaces || {});
758
+ availableMarketplacesById = _objectSpread({}, this.availableMarketplacesById || {});
759
+ Object.keys(metadata || {}).forEach(function (tenantSlug) {
760
+ try {
761
+ availableMarketplaces[tenantSlug] = {
762
+ versionHash: metadata[tenantSlug]["."].source
763
+ };
764
+ Object.keys(metadata[tenantSlug].marketplaces || {}).forEach(function (marketplaceSlug) {
765
+ try {
766
+ var versionHash = metadata[tenantSlug].marketplaces[marketplaceSlug]["."].source;
767
+
768
+ var objectId = _this3.utils.DecodeVersionHash(versionHash).objectId;
769
+
770
+ availableMarketplaces[tenantSlug][marketplaceSlug] = _objectSpread(_objectSpread({}, metadata[tenantSlug].marketplaces[marketplaceSlug].info || {}), {}, {
771
+ tenantName: metadata[tenantSlug].marketplaces[marketplaceSlug].info.tenant_name,
772
+ tenantId: metadata[tenantSlug].marketplaces[marketplaceSlug].info.tenant_id,
773
+ tenantSlug: tenantSlug,
774
+ marketplaceSlug: marketplaceSlug,
775
+ marketplaceId: objectId,
776
+ marketplaceHash: versionHash,
777
+ order: Configuration.__MARKETPLACE_ORDER.findIndex(function (slug) {
778
+ return slug === marketplaceSlug;
779
+ })
780
+ });
781
+ availableMarketplacesById[objectId] = availableMarketplaces[tenantSlug][marketplaceSlug];
782
+ _this3.marketplaceHashes[objectId] = versionHash; // Fill out selected marketplace info
783
+
784
+ if (_this3.selectedMarketplaceInfo) {
785
+ if (_this3.selectedMarketplaceInfo.tenantSlug === tenantSlug && _this3.selectedMarketplaceInfo.marketplaceSlug === marketplaceSlug || _this3.selectedMarketplaceInfo.marketplaceId === objectId) {
786
+ _this3.selectedMarketplaceInfo = availableMarketplaces[tenantSlug][marketplaceSlug];
787
+ }
788
+ }
789
+ } catch (error) {
790
+ _this3.Log("Eluvio Wallet Client: Unable to load info for marketplace ".concat(tenantSlug, "/").concat(marketplaceSlug), true);
791
+ }
792
+ });
793
+ } catch (error) {
794
+ _this3.Log("Eluvio Wallet Client: Failed to load tenant info ".concat(tenantSlug), true);
795
+
796
+ _this3.Log(error, true);
797
+ }
798
+ });
799
+ this.availableMarketplaces = availableMarketplaces;
800
+ this.availableMarketplacesById = availableMarketplacesById;
801
+
802
+ case 14:
803
+ case "end":
804
+ return _context9.stop();
805
+ }
806
+ }
807
+ }, _callee9, this);
808
+ }));
809
+
810
+ function LoadAvailableMarketplaces() {
811
+ return _LoadAvailableMarketplaces.apply(this, arguments);
812
+ }
813
+
814
+ return LoadAvailableMarketplaces;
815
+ }() // Get the hash of the currently linked marketplace
816
+
817
+ }, {
818
+ key: "LatestMarketplaceHash",
819
+ value: function () {
820
+ var _LatestMarketplaceHash = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee10(_ref10) {
821
+ var tenantSlug, marketplaceSlug, mainSiteHash, marketplaceLink;
822
+ return _regeneratorRuntime.wrap(function _callee10$(_context10) {
823
+ while (1) {
824
+ switch (_context10.prev = _context10.next) {
825
+ case 0:
826
+ tenantSlug = _ref10.tenantSlug, marketplaceSlug = _ref10.marketplaceSlug;
827
+ _context10.next = 3;
828
+ return this.client.LatestVersionHash({
829
+ objectId: this.mainSiteId
830
+ });
831
+
832
+ case 3:
833
+ mainSiteHash = _context10.sent;
834
+ _context10.next = 6;
835
+ return this.client.ContentObjectMetadata({
836
+ versionHash: mainSiteHash,
837
+ metadataSubtree: UrlJoin("/public", "asset_metadata", "tenants", tenantSlug, "marketplaces", marketplaceSlug),
838
+ resolveLinks: false
839
+ });
840
+
841
+ case 6:
842
+ marketplaceLink = _context10.sent;
843
+ return _context10.abrupt("return", LinkTargetHash(marketplaceLink));
844
+
845
+ case 8:
846
+ case "end":
847
+ return _context10.stop();
848
+ }
849
+ }
850
+ }, _callee10, this);
851
+ }));
852
+
853
+ function LatestMarketplaceHash(_x11) {
854
+ return _LatestMarketplaceHash.apply(this, arguments);
855
+ }
856
+
857
+ return LatestMarketplaceHash;
858
+ }()
859
+ }, {
860
+ key: "LoadMarketplace",
861
+ value: function () {
862
+ var _LoadMarketplace = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee12(marketplaceParams) {
863
+ var _this4 = this;
864
+
865
+ var marketplaceInfo, marketplaceId, marketplaceHash, marketplace;
866
+ return _regeneratorRuntime.wrap(function _callee12$(_context12) {
867
+ while (1) {
868
+ switch (_context12.prev = _context12.next) {
869
+ case 0:
870
+ marketplaceInfo = this.MarketplaceInfo({
871
+ marketplaceParams: marketplaceParams
872
+ });
873
+ marketplaceId = marketplaceInfo.marketplaceId;
874
+ _context12.next = 4;
875
+ return this.LatestMarketplaceHash({
876
+ tenantSlug: marketplaceInfo.tenantSlug,
877
+ marketplaceSlug: marketplaceInfo.marketplaceSlug
878
+ });
879
+
880
+ case 4:
881
+ marketplaceHash = _context12.sent;
882
+
883
+ if (this.cachedMarketplaces[marketplaceId] && this.cachedMarketplaces[marketplaceId].versionHash !== marketplaceHash) {
884
+ delete this.cachedMarketplaces[marketplaceId];
885
+ }
886
+
887
+ if (this.cachedMarketplaces[marketplaceId]) {
888
+ _context12.next = 19;
889
+ break;
890
+ }
891
+
892
+ _context12.next = 9;
893
+ return this.client.ContentObjectMetadata({
894
+ versionHash: marketplaceHash,
895
+ metadataSubtree: "public/asset_metadata/info",
896
+ linkDepthLimit: 2,
897
+ resolveLinks: true,
898
+ resolveIgnoreErrors: true,
899
+ resolveIncludeSource: true,
900
+ produceLinkUrls: true,
901
+ authorizationToken: this.publicStaticToken
902
+ });
903
+
904
+ case 9:
905
+ marketplace = _context12.sent;
906
+ _context12.next = 12;
907
+ return Promise.all(marketplace.items.map( /*#__PURE__*/function () {
908
+ var _ref11 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee11(item, index) {
909
+ return _regeneratorRuntime.wrap(function _callee11$(_context11) {
910
+ while (1) {
911
+ switch (_context11.prev = _context11.next) {
912
+ case 0:
913
+ if (!item.requires_permissions) {
914
+ _context11.next = 14;
915
+ break;
916
+ }
917
+
918
+ if (_this4.loggedIn) {
919
+ _context11.next = 5;
920
+ break;
921
+ }
922
+
923
+ item.authorized = false;
924
+ _context11.next = 14;
925
+ break;
926
+
927
+ case 5:
928
+ _context11.prev = 5;
929
+ _context11.next = 8;
930
+ return _this4.client.ContentObjectMetadata({
931
+ versionHash: LinkTargetHash(item.nft_template),
932
+ metadataSubtree: "permissioned"
933
+ });
934
+
935
+ case 8:
936
+ item.authorized = true;
937
+ _context11.next = 14;
938
+ break;
939
+
940
+ case 11:
941
+ _context11.prev = 11;
942
+ _context11.t0 = _context11["catch"](5);
943
+ item.authorized = false;
944
+
945
+ case 14:
946
+ item.nftTemplateMetadata = (item.nft_template || {}).nft || {};
947
+ item.itemIndex = index;
948
+ return _context11.abrupt("return", item);
949
+
950
+ case 17:
951
+ case "end":
952
+ return _context11.stop();
953
+ }
954
+ }
955
+ }, _callee11, null, [[5, 11]]);
956
+ }));
957
+
958
+ return function (_x13, _x14) {
959
+ return _ref11.apply(this, arguments);
960
+ };
961
+ }()));
962
+
963
+ case 12:
964
+ marketplace.items = _context12.sent;
965
+ marketplace.collections = (marketplace.collections || []).map(function (collection, collectionIndex) {
966
+ return _objectSpread(_objectSpread({}, collection), {}, {
967
+ collectionIndex: collectionIndex
968
+ });
969
+ });
970
+ marketplace.retrievedAt = Date.now();
971
+ marketplace.marketplaceId = marketplaceId;
972
+ marketplace.versionHash = marketplaceHash; // Generate embed URLs for pack opening animations
973
+
974
+ ["purchase_animation", "purchase_animation__mobile", "reveal_animation", "reveal_animation_mobile"].forEach(function (key) {
975
+ try {
976
+ if (marketplace.storefront[key]) {
977
+ var embedUrl = new URL("https://embed.v3.contentfabric.io");
978
+ var targetHash = LinkTargetHash(marketplace.storefront[key]);
979
+ embedUrl.searchParams.set("p", "");
980
+ embedUrl.searchParams.set("net", _this4.network === "main" ? "main" : "demo");
981
+ embedUrl.searchParams.set("ath", (_this4.__authorization || {}).authToken || _this4.publicStaticToken);
982
+ embedUrl.searchParams.set("vid", targetHash);
983
+ embedUrl.searchParams.set("ap", "");
984
+
985
+ if (!key.startsWith("reveal")) {
986
+ embedUrl.searchParams.set("m", "");
987
+ embedUrl.searchParams.set("lp", "");
988
+ }
989
+
990
+ marketplace.storefront["".concat(key, "_embed_url")] = embedUrl.toString();
991
+ } // eslint-disable-next-line no-empty
992
+
993
+ } catch (error) {}
994
+ });
995
+ this.cachedMarketplaces[marketplaceId] = marketplace;
996
+
997
+ case 19:
998
+ return _context12.abrupt("return", this.cachedMarketplaces[marketplaceId]);
999
+
1000
+ case 20:
1001
+ case "end":
1002
+ return _context12.stop();
1003
+ }
1004
+ }
1005
+ }, _callee12, this);
1006
+ }));
1007
+
1008
+ function LoadMarketplace(_x12) {
1009
+ return _LoadMarketplace.apply(this, arguments);
1010
+ }
1011
+
1012
+ return LoadMarketplace;
1013
+ }()
1014
+ }, {
1015
+ key: "FilteredQuery",
1016
+ value: function () {
1017
+ var _FilteredQuery = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee13() {
1018
+ var _ref12,
1019
+ _ref12$mode,
1020
+ mode,
1021
+ _ref12$sortBy,
1022
+ sortBy,
1023
+ _ref12$sortDesc,
1024
+ sortDesc,
1025
+ filter,
1026
+ editionFilter,
1027
+ attributeFilters,
1028
+ contractAddress,
1029
+ tokenId,
1030
+ currency,
1031
+ marketplaceParams,
1032
+ tenantId,
1033
+ _ref12$collectionInde,
1034
+ collectionIndex,
1035
+ sellerAddress,
1036
+ _ref12$lastNDays,
1037
+ lastNDays,
1038
+ _ref12$start,
1039
+ start,
1040
+ _ref12$limit,
1041
+ limit,
1042
+ params,
1043
+ marketplaceInfo,
1044
+ marketplace,
1045
+ filters,
1046
+ collection,
1047
+ path,
1048
+ _ref14,
1049
+ contents,
1050
+ paging,
1051
+ _args13 = arguments;
1052
+
1053
+ return _regeneratorRuntime.wrap(function _callee13$(_context13) {
1054
+ while (1) {
1055
+ switch (_context13.prev = _context13.next) {
1056
+ case 0:
1057
+ _ref12 = _args13.length > 0 && _args13[0] !== undefined ? _args13[0] : {}, _ref12$mode = _ref12.mode, mode = _ref12$mode === void 0 ? "listings" : _ref12$mode, _ref12$sortBy = _ref12.sortBy, sortBy = _ref12$sortBy === void 0 ? "created" : _ref12$sortBy, _ref12$sortDesc = _ref12.sortDesc, sortDesc = _ref12$sortDesc === void 0 ? false : _ref12$sortDesc, filter = _ref12.filter, editionFilter = _ref12.editionFilter, attributeFilters = _ref12.attributeFilters, contractAddress = _ref12.contractAddress, tokenId = _ref12.tokenId, currency = _ref12.currency, marketplaceParams = _ref12.marketplaceParams, tenantId = _ref12.tenantId, _ref12$collectionInde = _ref12.collectionIndex, collectionIndex = _ref12$collectionInde === void 0 ? -1 : _ref12$collectionInde, sellerAddress = _ref12.sellerAddress, _ref12$lastNDays = _ref12.lastNDays, lastNDays = _ref12$lastNDays === void 0 ? -1 : _ref12$lastNDays, _ref12$start = _ref12.start, start = _ref12$start === void 0 ? 0 : _ref12$start, _ref12$limit = _ref12.limit, limit = _ref12$limit === void 0 ? 50 : _ref12$limit;
1058
+ collectionIndex = parseInt(collectionIndex);
1059
+ params = {
1060
+ sort_by: sortBy,
1061
+ sort_descending: sortDesc,
1062
+ start: start,
1063
+ limit: limit
1064
+ };
1065
+
1066
+ if (!marketplaceParams) {
1067
+ _context13.next = 11;
1068
+ break;
1069
+ }
1070
+
1071
+ _context13.next = 6;
1072
+ return this.MarketplaceInfo({
1073
+ marketplaceParams: marketplaceParams
1074
+ });
1075
+
1076
+ case 6:
1077
+ marketplaceInfo = _context13.sent;
1078
+
1079
+ if (!(collectionIndex >= 0)) {
1080
+ _context13.next = 11;
1081
+ break;
1082
+ }
1083
+
1084
+ _context13.next = 10;
1085
+ return this.Marketplace({
1086
+ marketplaceParams: marketplaceParams
1087
+ });
1088
+
1089
+ case 10:
1090
+ marketplace = _context13.sent;
1091
+
1092
+ case 11:
1093
+ _context13.prev = 11;
1094
+ filters = [];
1095
+
1096
+ if (sellerAddress) {
1097
+ filters.push("seller:eq:".concat(this.client.utils.FormatAddress(sellerAddress)));
1098
+ }
1099
+
1100
+ if (!(marketplace && collectionIndex >= 0)) {
1101
+ _context13.next = 25;
1102
+ break;
1103
+ }
1104
+
1105
+ collection = marketplace.collections[collectionIndex];
1106
+ collection.items.forEach(function (sku) {
1107
+ if (!sku) {
1108
+ return;
1109
+ }
1110
+
1111
+ var item = marketplace.items.find(function (item) {
1112
+ return item.sku === sku;
1113
+ });
1114
+
1115
+ if (!item) {
1116
+ return;
1117
+ }
1118
+
1119
+ var address = Utils.SafeTraverse(item, "nft_template", "nft", "address");
1120
+
1121
+ if (address) {
1122
+ filters.push("".concat(mode === "owned" ? "contract_addr" : "contract", ":eq:").concat(Utils.FormatAddress(address)));
1123
+ }
1124
+ }); // No valid items, so there must not be anything relevant in the collection
1125
+
1126
+ if (!(filters.length === 0)) {
1127
+ _context13.next = 23;
1128
+ break;
1129
+ }
1130
+
1131
+ if (!mode.includes("stats")) {
1132
+ _context13.next = 22;
1133
+ break;
1134
+ }
1135
+
1136
+ return _context13.abrupt("return", {});
1137
+
1138
+ case 22:
1139
+ return _context13.abrupt("return", {
1140
+ paging: {
1141
+ start: params.start,
1142
+ limit: params.limit,
1143
+ total: 0,
1144
+ more: false
1145
+ },
1146
+ results: []
1147
+ });
1148
+
1149
+ case 23:
1150
+ _context13.next = 26;
1151
+ break;
1152
+
1153
+ case 25:
1154
+ if (mode !== "owned" && marketplaceInfo || tenantId) {
1155
+ filters.push("tenant:eq:".concat(marketplaceInfo ? marketplaceInfo.tenantId : tenantId));
1156
+ }
1157
+
1158
+ case 26:
1159
+ if (contractAddress) {
1160
+ if (mode === "owned") {
1161
+ filters.push("contract_addr:eq:".concat(Utils.FormatAddress(contractAddress)));
1162
+ } else {
1163
+ filters.push("contract:eq:".concat(Utils.FormatAddress(contractAddress)));
1164
+ }
1165
+
1166
+ if (tokenId) {
1167
+ filters.push("token:eq:".concat(tokenId));
1168
+ }
1169
+ } else if (filter) {
1170
+ if (mode.includes("listing")) {
1171
+ filters.push("nft/display_name:eq:".concat(filter));
1172
+ } else if (mode === "owned") {
1173
+ filters.push("meta:@>:{\"display_name\":\"".concat(filter, "\"}"));
1174
+ params.exact = false;
1175
+ } else {
1176
+ filters.push("name:eq:".concat(filter));
1177
+ }
1178
+ }
1179
+
1180
+ if (editionFilter) {
1181
+ if (mode.includes("listing")) {
1182
+ filters.push("nft/edition_name:eq:".concat(editionFilter));
1183
+ } else if (mode === "owned") {
1184
+ filters.push("meta:@>:{\"edition_name\":\"".concat(editionFilter, "\"}"));
1185
+ params.exact = false;
1186
+ } else {
1187
+ filters.push("edition:eq:".concat(editionFilter));
1188
+ }
1189
+ }
1190
+
1191
+ if (attributeFilters) {
1192
+ attributeFilters.map(function (_ref13) {
1193
+ var name = _ref13.name,
1194
+ value = _ref13.value;
1195
+
1196
+ if (!name || !value) {
1197
+ return;
1198
+ }
1199
+
1200
+ filters.push("nft/attributes/".concat(name, ":eq:").concat(value));
1201
+ });
1202
+ }
1203
+
1204
+ if (currency) {
1205
+ filters.push("link_type:eq:sol");
1206
+ }
1207
+
1208
+ if (lastNDays && lastNDays > 0) {
1209
+ filters.push("created:gt:".concat((Date.now() / 1000 - lastNDays * 24 * 60 * 60).toFixed(0)));
1210
+ }
1211
+
1212
+ _context13.t0 = mode;
1213
+ _context13.next = _context13.t0 === "owned" ? 34 : _context13.t0 === "listings" ? 37 : _context13.t0 === "sales" ? 39 : _context13.t0 === "listing-stats" ? 42 : _context13.t0 === "sales-stats" ? 44 : 46;
1214
+ break;
1215
+
1216
+ case 34:
1217
+ path = UrlJoin("as", "wlt", "nfts");
1218
+
1219
+ if (marketplaceInfo) {
1220
+ path = UrlJoin("as", "wlt", "nfts", marketplaceInfo.tenantId);
1221
+ }
1222
+
1223
+ return _context13.abrupt("break", 46);
1224
+
1225
+ case 37:
1226
+ path = UrlJoin("as", "mkt", "f");
1227
+ return _context13.abrupt("break", 46);
1228
+
1229
+ case 39:
1230
+ path = UrlJoin("as", "mkt", "hst", "f");
1231
+ filters.push("action:eq:SOLD");
1232
+ return _context13.abrupt("break", 46);
1233
+
1234
+ case 42:
1235
+ path = UrlJoin("as", "mkt", "stats", "listed");
1236
+ return _context13.abrupt("break", 46);
1237
+
1238
+ case 44:
1239
+ path = UrlJoin("as", "mkt", "stats", "sold");
1240
+ return _context13.abrupt("break", 46);
1241
+
1242
+ case 46:
1243
+ if (filters.length > 0) {
1244
+ params.filter = filters;
1245
+ }
1246
+
1247
+ if (!mode.includes("stats")) {
1248
+ _context13.next = 51;
1249
+ break;
1250
+ }
1251
+
1252
+ _context13.next = 50;
1253
+ return Utils.ResponseToJson(this.client.authClient.MakeAuthServiceRequest({
1254
+ path: path,
1255
+ method: "GET",
1256
+ queryParams: params
1257
+ }));
1258
+
1259
+ case 50:
1260
+ return _context13.abrupt("return", _context13.sent);
1261
+
1262
+ case 51:
1263
+ _context13.t2 = Utils;
1264
+ _context13.next = 54;
1265
+ return this.client.authClient.MakeAuthServiceRequest({
1266
+ path: path,
1267
+ method: "GET",
1268
+ queryParams: params,
1269
+ headers: mode === "owned" ? {
1270
+ Authorization: "Bearer ".concat(this.AuthToken())
1271
+ } : {}
1272
+ });
1273
+
1274
+ case 54:
1275
+ _context13.t3 = _context13.sent;
1276
+ _context13.next = 57;
1277
+ return _context13.t2.ResponseToJson.call(_context13.t2, _context13.t3);
1278
+
1279
+ case 57:
1280
+ _context13.t1 = _context13.sent;
1281
+
1282
+ if (_context13.t1) {
1283
+ _context13.next = 60;
1284
+ break;
1285
+ }
1286
+
1287
+ _context13.t1 = [];
1288
+
1289
+ case 60:
1290
+ _ref14 = _context13.t1;
1291
+ contents = _ref14.contents;
1292
+ paging = _ref14.paging;
1293
+ return _context13.abrupt("return", {
1294
+ paging: {
1295
+ start: params.start,
1296
+ limit: params.limit,
1297
+ total: paging.total,
1298
+ more: paging.total > start + limit
1299
+ },
1300
+ results: (contents || []).map(function (item) {
1301
+ return ["owned", "listings"].includes(mode) ? FormatNFT(item) : item;
1302
+ })
1303
+ });
1304
+
1305
+ case 66:
1306
+ _context13.prev = 66;
1307
+ _context13.t4 = _context13["catch"](11);
1308
+
1309
+ if (!(_context13.t4.status && _context13.t4.status.toString() === "404")) {
1310
+ _context13.next = 70;
1311
+ break;
1312
+ }
1313
+
1314
+ return _context13.abrupt("return", {
1315
+ paging: {
1316
+ start: params.start,
1317
+ limit: params.limit,
1318
+ total: 0,
1319
+ more: false
1320
+ },
1321
+ results: []
1322
+ });
1323
+
1324
+ case 70:
1325
+ throw _context13.t4;
1326
+
1327
+ case 71:
1328
+ case "end":
1329
+ return _context13.stop();
1330
+ }
1331
+ }
1332
+ }, _callee13, this, [[11, 66]]);
1333
+ }));
1334
+
1335
+ function FilteredQuery() {
1336
+ return _FilteredQuery.apply(this, arguments);
1337
+ }
1338
+
1339
+ return FilteredQuery;
1340
+ }()
1341
+ }, {
1342
+ key: "MintingStatus",
1343
+ value: function () {
1344
+ var _MintingStatus = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee14(_ref15) {
1345
+ var marketplaceParams, tenantId, marketplaceInfo, response;
1346
+ return _regeneratorRuntime.wrap(function _callee14$(_context14) {
1347
+ while (1) {
1348
+ switch (_context14.prev = _context14.next) {
1349
+ case 0:
1350
+ marketplaceParams = _ref15.marketplaceParams, tenantId = _ref15.tenantId;
1351
+
1352
+ if (tenantId) {
1353
+ _context14.next = 6;
1354
+ break;
1355
+ }
1356
+
1357
+ _context14.next = 4;
1358
+ return this.MarketplaceInfo({
1359
+ marketplaceParams: marketplaceParams || this.selectedMarketplaceInfo
1360
+ });
1361
+
1362
+ case 4:
1363
+ marketplaceInfo = _context14.sent;
1364
+ tenantId = marketplaceInfo.tenantId;
1365
+
1366
+ case 6:
1367
+ _context14.prev = 6;
1368
+ _context14.next = 9;
1369
+ return Utils.ResponseToJson(this.client.authClient.MakeAuthServiceRequest({
1370
+ path: UrlJoin("as", "wlt", "status", "act", tenantId),
1371
+ method: "GET",
1372
+ headers: {
1373
+ Authorization: "Bearer ".concat(this.AuthToken())
1374
+ }
1375
+ }));
1376
+
1377
+ case 9:
1378
+ response = _context14.sent;
1379
+ return _context14.abrupt("return", response.map(function (status) {
1380
+ var _status$op$split = status.op.split(":"),
1381
+ _status$op$split2 = _slicedToArray(_status$op$split, 3),
1382
+ op = _status$op$split2[0],
1383
+ address = _status$op$split2[1],
1384
+ id = _status$op$split2[2];
1385
+
1386
+ address = address.startsWith("0x") ? Utils.FormatAddress(address) : address;
1387
+ var confirmationId, tokenId;
1388
+
1389
+ if (op === "nft-buy") {
1390
+ confirmationId = id;
1391
+ } else if (op === "nft-claim") {
1392
+ confirmationId = id;
1393
+ status.marketplaceId = address;
1394
+
1395
+ if (status.extra && status.extra["0"]) {
1396
+ address = status.extra.token_addr;
1397
+ tokenId = status.extra.token_id_str;
1398
+ }
1399
+ } else if (op === "nft-redeem") {
1400
+ confirmationId = status.op.split(":").slice(-1)[0];
1401
+ } else {
1402
+ tokenId = id;
1403
+ }
1404
+
1405
+ if (op === "nft-transfer") {
1406
+ confirmationId = status.extra && status.extra.trans_id;
1407
+ }
1408
+
1409
+ return _objectSpread(_objectSpread({}, status), {}, {
1410
+ timestamp: new Date(status.ts),
1411
+ state: status.state && _typeof(status.state) === "object" ? Object.values(status.state) : status.state,
1412
+ extra: status.extra && _typeof(status.extra) === "object" ? Object.values(status.extra) : status.extra,
1413
+ confirmationId: confirmationId,
1414
+ op: op,
1415
+ address: address,
1416
+ tokenId: tokenId
1417
+ });
1418
+ }).sort(function (a, b) {
1419
+ return a.ts < b.ts ? 1 : -1;
1420
+ }));
1421
+
1422
+ case 13:
1423
+ _context14.prev = 13;
1424
+ _context14.t0 = _context14["catch"](6);
1425
+ this.Log("Failed to retrieve minting status", true);
1426
+ this.Log(_context14.t0);
1427
+ return _context14.abrupt("return", []);
1428
+
1429
+ case 18:
1430
+ case "end":
1431
+ return _context14.stop();
1432
+ }
1433
+ }
1434
+ }, _callee14, this, [[6, 13]]);
1435
+ }));
1436
+
1437
+ function MintingStatus(_x15) {
1438
+ return _MintingStatus.apply(this, arguments);
1439
+ }
1440
+
1441
+ return MintingStatus;
1442
+ }()
1443
+ }], [{
1444
+ key: "Initialize",
1445
+ value: function () {
1446
+ var _Initialize = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee15(_ref16) {
1447
+ var _ref16$network, network, _ref16$mode, mode, marketplaceParams, _ref16$storeAuthToken, storeAuthToken, _ref17, tenantSlug, marketplaceSlug, marketplaceId, marketplaceHash, client, walletClient, url, savedToken;
1448
+
1449
+ return _regeneratorRuntime.wrap(function _callee15$(_context15) {
1450
+ while (1) {
1451
+ switch (_context15.prev = _context15.next) {
1452
+ case 0:
1453
+ _ref16$network = _ref16.network, network = _ref16$network === void 0 ? "main" : _ref16$network, _ref16$mode = _ref16.mode, mode = _ref16$mode === void 0 ? "production" : _ref16$mode, marketplaceParams = _ref16.marketplaceParams, _ref16$storeAuthToken = _ref16.storeAuthToken, storeAuthToken = _ref16$storeAuthToken === void 0 ? true : _ref16$storeAuthToken;
1454
+ _ref17 = marketplaceParams || {}, tenantSlug = _ref17.tenantSlug, marketplaceSlug = _ref17.marketplaceSlug, marketplaceId = _ref17.marketplaceId, marketplaceHash = _ref17.marketplaceHash;
1455
+
1456
+ if (Configuration[network]) {
1457
+ _context15.next = 6;
1458
+ break;
1459
+ }
1460
+
1461
+ throw Error("ElvWalletClient: Invalid network ".concat(network));
1462
+
1463
+ case 6:
1464
+ if (Configuration[network][mode]) {
1465
+ _context15.next = 8;
1466
+ break;
1467
+ }
1468
+
1469
+ throw Error("ElvWalletClient: Invalid mode ".concat(mode));
1470
+
1471
+ case 8:
1472
+ _context15.next = 10;
1473
+ return ElvClient.FromNetworkName({
1474
+ networkName: network,
1475
+ assumeV3: true
1476
+ });
1477
+
1478
+ case 10:
1479
+ client = _context15.sent;
1480
+ walletClient = new ElvWalletClient({
1481
+ client: client,
1482
+ network: network,
1483
+ mode: mode,
1484
+ marketplaceInfo: {
1485
+ tenantSlug: tenantSlug,
1486
+ marketplaceSlug: marketplaceSlug,
1487
+ marketplaceId: marketplaceHash ? client.utils.DecodeVersionHash(marketplaceHash).objectId : marketplaceId,
1488
+ marketplaceHash: marketplaceHash
1489
+ },
1490
+ storeAuthToken: storeAuthToken
1491
+ });
1492
+
1493
+ if (!(window && window.location && window.location.href)) {
1494
+ _context15.next = 31;
1495
+ break;
1496
+ }
1497
+
1498
+ url = new URL(window.location.href);
1499
+
1500
+ if (!url.searchParams.get("elvToken")) {
1501
+ _context15.next = 21;
1502
+ break;
1503
+ }
1504
+
1505
+ _context15.next = 17;
1506
+ return walletClient.Authenticate({
1507
+ token: url.searchParams.get("elvToken")
1508
+ });
1509
+
1510
+ case 17:
1511
+ url.searchParams["delete"]("elvToken");
1512
+ window.history.replaceState("", "", url);
1513
+ _context15.next = 31;
1514
+ break;
1515
+
1516
+ case 21:
1517
+ if (!(storeAuthToken && typeof localStorage !== "undefined")) {
1518
+ _context15.next = 31;
1519
+ break;
1520
+ }
1521
+
1522
+ _context15.prev = 22;
1523
+ // Load saved auth token
1524
+ savedToken = localStorage.getItem("__elv-token-".concat(network));
1525
+
1526
+ if (!savedToken) {
1527
+ _context15.next = 27;
1528
+ break;
1529
+ }
1530
+
1531
+ _context15.next = 27;
1532
+ return walletClient.Authenticate({
1533
+ token: savedToken
1534
+ });
1535
+
1536
+ case 27:
1537
+ _context15.next = 31;
1538
+ break;
1539
+
1540
+ case 29:
1541
+ _context15.prev = 29;
1542
+ _context15.t0 = _context15["catch"](22);
1543
+
1544
+ case 31:
1545
+ _context15.next = 33;
1546
+ return walletClient.LoadAvailableMarketplaces();
1547
+
1548
+ case 33:
1549
+ return _context15.abrupt("return", walletClient);
1550
+
1551
+ case 34:
1552
+ case "end":
1553
+ return _context15.stop();
1554
+ }
1555
+ }
1556
+ }, _callee15, null, [[22, 29]]);
1557
+ }));
1558
+
1559
+ function Initialize(_x16) {
1560
+ return _Initialize.apply(this, arguments);
1561
+ }
1562
+
1563
+ return Initialize;
1564
+ }()
1565
+ }]);
1566
+
1567
+ return ElvWalletClient;
1568
+ }();
1569
+
1570
+ Object.assign(ElvWalletClient.prototype, require("./ClientMethods"));
1571
+ exports.ElvWalletClient = ElvWalletClient;