@eluvio/elv-client-js 4.0.11 → 4.0.13

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