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