@@ -50,7 +50,12 @@ class Core {
50
50
} ) ;
51
51
}
52
52
}
53
- module . exports = Core ;
53
+ try {
54
+ module . exports = Core ;
55
+ }
56
+ catch ( error ) {
57
+ console . log ( "[corejs] starting plain vanilla instance, as nodejs exports were not available" ) ;
58
+ }
54
59
class ConnectionHash extends Core {
55
60
constructor ( core , network , uuid , hash , player ) {
56
61
super ( core . getKey ( ) ) ;
@@ -79,6 +84,7 @@ class ConnectionHash extends Core {
79
84
requestSession ( ) {
80
85
return __awaiter ( this , void 0 , void 0 , function * ( ) {
81
86
var key = this . core . getKey ( ) ;
87
+ var core = this . core ;
82
88
var hash = this . hash ;
83
89
return new Promise ( function ( resolve , reject ) {
84
90
try {
@@ -89,7 +95,10 @@ class ConnectionHash extends Core {
89
95
throw new Error ( jsonresponse . error + ". " + jsonresponse . msg ) ;
90
96
}
91
97
else {
92
- resolve ( new SessionRequest ( new Core ( key ) , jsonresponse . uuid , jsonresponse . token , jsonresponse . validated , new Player ( new Core ( key ) , jsonresponse . player . coreid , jsonresponse . player . username , jsonresponse . player . uuid , jsonresponse . player . verified ) , new Network ( new Core ( key ) , new Instance ( new Core ( key ) , jsonresponse . network . uuid , jsonresponse . network . name , "NTW" ) ) , "player" ) ) ;
98
+ var player = new Player ( core , jsonresponse . player . coreid , jsonresponse . player . username , jsonresponse . player . uuid , jsonresponse . player . verified ) ;
99
+ var instance = new Network ( core , new Instance ( core , jsonresponse . network . uuid , jsonresponse . network . name , "NTW" ) ) ;
100
+ var sessionRequest = new SessionRequest ( core , jsonresponse . uuid , jsonresponse . token , jsonresponse . validated , player , instance , "player" ) ;
101
+ resolve ( sessionRequest ) ;
93
102
}
94
103
} ) . catch ( function ( error ) {
95
104
throw new Error ( error ) ;
@@ -102,7 +111,6 @@ class ConnectionHash extends Core {
102
111
} ) ;
103
112
}
104
113
}
105
- module . exports . ConnectionHash ;
106
114
class CheckoutElement extends Core {
107
115
constructor ( core , products , successFunction ) {
108
116
super ( core . getKey ( ) ) ;
@@ -125,7 +133,6 @@ class CheckoutElement extends Core {
125
133
} ) ;
126
134
}
127
135
}
128
- module . exports . CheckoutElement ;
129
136
class Elements extends Core {
130
137
constructor ( core ) {
131
138
super ( core . getKey ( ) ) ;
@@ -135,7 +142,6 @@ class Elements extends Core {
135
142
return new CheckoutElement ( this . core , products , successFunction ) ;
136
143
}
137
144
}
138
- module . exports . Elements ;
139
145
class Instance extends Core {
140
146
constructor ( core , uuid , name , type ) {
141
147
super ( core . getKey ( ) ) ;
@@ -154,7 +160,6 @@ class Instance extends Core {
154
160
return new Network ( this . core , this ) ;
155
161
}
156
162
}
157
- module . exports . Instance ;
158
163
class Network extends Core {
159
164
constructor ( core , instance ) {
160
165
super ( core . getKey ( ) ) ;
@@ -235,8 +240,9 @@ class Network extends Core {
235
240
}
236
241
else {
237
242
var response = new Array ( ) ;
238
- jsonresponse . forEach ( ConnectionHash => {
239
- response . push ( new ConnectionHash ( ) . fromArray ( ConnectionHash ) ) ;
243
+ jsonresponse . forEach ( hashData => {
244
+ var hash = new ConnectionHash ( new Core ( key ) ) ;
245
+ response . push ( hash . fromArray ( hashData ) ) ;
240
246
} ) ;
241
247
resolve ( response ) ;
242
248
}
@@ -251,17 +257,96 @@ class Network extends Core {
251
257
} ) ;
252
258
}
253
259
}
254
- module . exports . Network ;
260
+ class Session extends Core {
261
+ constructor ( core , uuid , hash , device , location , usage , network , player ) {
262
+ super ( core . getKey ( ) ) ;
263
+ this . core = core ;
264
+ this . uuid = uuid ;
265
+ this . hash = hash ;
266
+ this . device = device ;
267
+ this . location = location ;
268
+ this . usage = usage ;
269
+ this . network = network ;
270
+ this . player = player ;
271
+ }
272
+ fromArray ( array ) {
273
+ this . uuid = array . uuid ;
274
+ this . hash = array . hash ;
275
+ this . device = new SessionDevice ( array . device . brand , array . device . device , array . device . model , array . device . os ) ;
276
+ this . location = new SessionLocation ( array . location . city , array . location . state , array . location . country_code ) ;
277
+ this . usage = new SessionUsage ( array . usage . creation , array . usage . uses ) ;
278
+ this . network = new Network ( this . core , new Instance ( this . core , array . network . uuid , array . network . name , "NTW" ) ) ;
279
+ this . player = new Player ( this . core , array . player . coreid , array . player . username , array . player . uuid , array . player . verified ) ;
280
+ return this ;
281
+ }
282
+ }
283
+ class SessionDevice {
284
+ constructor ( brand , device , model , os ) {
285
+ this . brand = brand ;
286
+ this . device = device ;
287
+ this . model = model ;
288
+ this . os = os ;
289
+ }
290
+ }
291
+ class SessionLocation {
292
+ constructor ( city , state , country_code ) {
293
+ this . city = city ;
294
+ this . state = state ;
295
+ this . country_code = country_code ;
296
+ }
297
+ }
255
298
class SessionRequest extends Core {
256
299
constructor ( core , uuid , token , validated , player , network , type ) {
257
300
super ( core . getKey ( ) ) ;
301
+ this . core = core ;
258
302
this . uuid = uuid ;
259
303
this . token = token ;
260
304
this . validated = validated ;
261
305
this . player = player ;
262
306
this . network = network ;
263
307
this . type = type ;
264
308
}
309
+ isValidated ( ) {
310
+ return this . validated ;
311
+ }
312
+ getValidationUrl ( ) {
313
+ return "https://api.purecore.io/link/discord/redirect/?uuid=" + this . uuid + "&hash=" + this . token ;
314
+ }
315
+ getToken ( ) {
316
+ return this . token ;
317
+ }
318
+ getSession ( ) {
319
+ return __awaiter ( this , void 0 , void 0 , function * ( ) {
320
+ var key = this . core . getKey ( ) ;
321
+ var core = this . core ;
322
+ var token = this . token ;
323
+ return new Promise ( function ( resolve , reject ) {
324
+ try {
325
+ return fetch ( "https://api.purecore.io/rest/2/session/hash/token/exchange/?key=" + key + "&token=" + token , { method : "GET" } ) . then ( function ( response ) {
326
+ return response . json ( ) ;
327
+ } ) . then ( function ( jsonresponse ) {
328
+ if ( "error" in jsonresponse ) {
329
+ throw new Error ( jsonresponse . error + ". " + jsonresponse . msg ) ;
330
+ }
331
+ else {
332
+ resolve ( new Session ( core ) . fromArray ( jsonresponse ) ) ;
333
+ }
334
+ } ) . catch ( function ( error ) {
335
+ throw new Error ( error ) ;
336
+ } ) ;
337
+ }
338
+ catch ( e ) {
339
+ throw new Error ( e . message ) ;
340
+ }
341
+ } ) ;
342
+ } ) ;
343
+ }
344
+ }
345
+ class SessionUsage {
346
+ constructor ( creation , uses ) {
347
+ this . creation = creation ;
348
+ this . uses = uses ;
349
+ }
265
350
}
266
351
class StoreCategory {
267
352
constructor ( uuid , name , description , network , upgradable ) {
@@ -272,7 +357,6 @@ class StoreCategory {
272
357
this . upgradable = upgradable ;
273
358
}
274
359
}
275
- module . exports . StoreCategory ;
276
360
class StoreItem {
277
361
constructor ( uuid , name , description , category , network , price , contextualizedPerks ) {
278
362
this . uuid = uuid ;
@@ -287,7 +371,6 @@ class StoreItem {
287
371
return this . uuid ;
288
372
}
289
373
}
290
- module . exports . StoreItem ;
291
374
class Perk {
292
375
constructor ( uuid , network , name , description , type , category ) {
293
376
this . uuid = uuid ;
@@ -298,22 +381,19 @@ class Perk {
298
381
this . category = category ;
299
382
}
300
383
}
301
- module . exports . Perk ;
302
384
class PerkCategory {
303
385
constructor ( uuid , name , network ) {
304
386
this . uuid = uuid ;
305
387
this . name = name ;
306
388
this . network = network ;
307
389
}
308
390
}
309
- module . exports . PerkCategory ;
310
391
class PerkContextualized {
311
392
constructor ( perk , quantity ) {
312
393
this . perk = perk ;
313
394
this . quantity = quantity ;
314
395
}
315
396
}
316
- module . exports . PerkContextualized ;
317
397
class Player extends Core {
318
398
constructor ( core , id , username , uuid , verified ) {
319
399
super ( core . getKey ( ) ) ;
@@ -333,4 +413,3 @@ class Player extends Core {
333
413
return this . username ;
334
414
}
335
415
}
336
- module . exports . Player ;
0 commit comments