@newgameplusinc/odyssey-sso 2.0.12 → 2.1.2
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/config.d.ts +10 -0
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +10 -0
- package/dist/config.js.map +1 -1
- package/dist/main.d.ts +144 -1
- package/dist/main.d.ts.map +1 -1
- package/dist/main.js +392 -60
- package/dist/main.js.map +1 -1
- package/dist/types.d.ts +265 -1
- package/dist/types.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/main.js
CHANGED
|
@@ -74,26 +74,28 @@ export default class SSO {
|
|
|
74
74
|
});
|
|
75
75
|
return { ...profileData.data, tokens: data.data.tokens };
|
|
76
76
|
};
|
|
77
|
+
// todo: fix
|
|
77
78
|
this.fetchProfile = async () => {
|
|
78
79
|
if (!isBrowser()) {
|
|
79
80
|
if (this.config.debug)
|
|
80
81
|
console.log(`SSO-SDK: Not in browser.`);
|
|
81
82
|
return;
|
|
82
83
|
}
|
|
83
|
-
const
|
|
84
|
+
const res = await this.withRefresh(async (aT) => {
|
|
84
85
|
return await fetch(`${this.ssoServerUrl}/users/profile`, {
|
|
85
86
|
headers: {
|
|
86
87
|
"Content-Type": "application/json",
|
|
87
88
|
Authorization: `Bearer ${aT}`,
|
|
89
|
+
"x-sdk-key": this.config.sdkKey,
|
|
88
90
|
},
|
|
89
91
|
});
|
|
90
92
|
});
|
|
91
|
-
if (!
|
|
93
|
+
if (!res?.ok) {
|
|
92
94
|
if (this.config.debug)
|
|
93
95
|
console.log(`SSO-SDK: Profile fetch failed.`);
|
|
94
96
|
return;
|
|
95
97
|
}
|
|
96
|
-
const { data } = (await
|
|
98
|
+
const { data } = (await res.json());
|
|
97
99
|
this.cb({
|
|
98
100
|
type: c.actions.profile_fetch,
|
|
99
101
|
payload: data,
|
|
@@ -113,7 +115,7 @@ export default class SSO {
|
|
|
113
115
|
console.log(`SSO-SDK: No user found in DB.`);
|
|
114
116
|
return;
|
|
115
117
|
}
|
|
116
|
-
const
|
|
118
|
+
const res = await fetch(`${this.ssoServerUrl}/users/refresh`, {
|
|
117
119
|
method: "POST",
|
|
118
120
|
body: JSON.stringify({
|
|
119
121
|
token: dbUser.tokens.refreshToken,
|
|
@@ -122,12 +124,12 @@ export default class SSO {
|
|
|
122
124
|
"Content-Type": "application/json",
|
|
123
125
|
},
|
|
124
126
|
});
|
|
125
|
-
if (!
|
|
127
|
+
if (!res.ok) {
|
|
126
128
|
if (this.config.debug)
|
|
127
129
|
console.log(`SSO-SDK: Refresh failed.`);
|
|
128
130
|
return;
|
|
129
131
|
}
|
|
130
|
-
const { data } = (await
|
|
132
|
+
const { data } = (await res.json());
|
|
131
133
|
await this.db.update(this.dbId, {
|
|
132
134
|
...dbUser,
|
|
133
135
|
tokens: {
|
|
@@ -141,13 +143,14 @@ export default class SSO {
|
|
|
141
143
|
});
|
|
142
144
|
return data;
|
|
143
145
|
};
|
|
146
|
+
// todo: fix
|
|
144
147
|
this.logout = async () => {
|
|
145
148
|
if (!isBrowser()) {
|
|
146
149
|
if (this.config.debug)
|
|
147
150
|
console.log(`SSO-SDK: Not in browser.`);
|
|
148
151
|
return;
|
|
149
152
|
}
|
|
150
|
-
const
|
|
153
|
+
const res = await this.withRefresh(async (aT) => {
|
|
151
154
|
return await fetch(`${this.ssoServerUrl}/users/logout`, {
|
|
152
155
|
method: "DELETE",
|
|
153
156
|
headers: {
|
|
@@ -156,7 +159,7 @@ export default class SSO {
|
|
|
156
159
|
},
|
|
157
160
|
});
|
|
158
161
|
});
|
|
159
|
-
if (!
|
|
162
|
+
if (!res?.ok) {
|
|
160
163
|
if (this.config.debug)
|
|
161
164
|
console.log(`SSO-SDK: Logout failed.`);
|
|
162
165
|
return;
|
|
@@ -187,7 +190,7 @@ export default class SSO {
|
|
|
187
190
|
const r = await api(dbUser.tokens.accessToken);
|
|
188
191
|
if (r.status !== 401)
|
|
189
192
|
return r;
|
|
190
|
-
const
|
|
193
|
+
const res = await fetch(`${this.ssoServerUrl}/users/refresh`, {
|
|
191
194
|
method: "POST",
|
|
192
195
|
body: JSON.stringify({
|
|
193
196
|
token: dbUser.tokens.refreshToken,
|
|
@@ -196,13 +199,13 @@ export default class SSO {
|
|
|
196
199
|
"Content-Type": "application/json",
|
|
197
200
|
},
|
|
198
201
|
});
|
|
199
|
-
if (!
|
|
202
|
+
if (!res.ok) {
|
|
200
203
|
if (this.config.debug)
|
|
201
204
|
console.log(`SSO-SDK: Refresh failed.`);
|
|
202
205
|
await this.db.delete(this.dbId);
|
|
203
206
|
return;
|
|
204
207
|
}
|
|
205
|
-
const { data } = (await
|
|
208
|
+
const { data } = (await res.json());
|
|
206
209
|
await this.db.update(this.dbId, {
|
|
207
210
|
...dbUser,
|
|
208
211
|
tokens: {
|
|
@@ -217,13 +220,14 @@ export default class SSO {
|
|
|
217
220
|
const nR = await api(data.accessToken);
|
|
218
221
|
return nR;
|
|
219
222
|
};
|
|
223
|
+
// todo: fix
|
|
220
224
|
this.profileUpdate = async (payload) => {
|
|
221
225
|
if (!isBrowser()) {
|
|
222
226
|
if (this.config.debug)
|
|
223
227
|
console.log(`SSO-SDK: Not in browser.`);
|
|
224
228
|
return;
|
|
225
229
|
}
|
|
226
|
-
const
|
|
230
|
+
const res = await this.withRefresh(async (aT) => {
|
|
227
231
|
return await fetch(`${this.ssoServerUrl}/users/profile`, {
|
|
228
232
|
method: "PATCH",
|
|
229
233
|
body: JSON.stringify(payload),
|
|
@@ -234,12 +238,12 @@ export default class SSO {
|
|
|
234
238
|
},
|
|
235
239
|
});
|
|
236
240
|
});
|
|
237
|
-
if (!
|
|
241
|
+
if (!res?.ok) {
|
|
238
242
|
if (this.config.debug)
|
|
239
243
|
console.log(`SSO-SDK: Profile update failed.`);
|
|
240
244
|
return;
|
|
241
245
|
}
|
|
242
|
-
const { data } = (await
|
|
246
|
+
const { data } = (await res.json());
|
|
243
247
|
const { id, ...rest } = data;
|
|
244
248
|
await this.db.update(this.dbId, {
|
|
245
249
|
...rest,
|
|
@@ -263,7 +267,7 @@ export default class SSO {
|
|
|
263
267
|
console.log(`SSO-SDK: File upload failed.`);
|
|
264
268
|
return;
|
|
265
269
|
}
|
|
266
|
-
const
|
|
270
|
+
const res = await this.withRefresh(async (aT) => {
|
|
267
271
|
return await fetch(`${this.ssoServerUrl}/users/profile/avatar`, {
|
|
268
272
|
method: "PUT",
|
|
269
273
|
body: JSON.stringify({
|
|
@@ -276,12 +280,12 @@ export default class SSO {
|
|
|
276
280
|
},
|
|
277
281
|
});
|
|
278
282
|
});
|
|
279
|
-
if (!
|
|
283
|
+
if (!res?.ok) {
|
|
280
284
|
if (this.config.debug)
|
|
281
285
|
console.log(`SSO-SDK: Profile update failed.`);
|
|
282
286
|
return;
|
|
283
287
|
}
|
|
284
|
-
const { data } = (await
|
|
288
|
+
const { data } = (await res.json());
|
|
285
289
|
const { id, ...rest } = data;
|
|
286
290
|
await this.db.update(this.dbId, {
|
|
287
291
|
...rest,
|
|
@@ -356,7 +360,7 @@ export default class SSO {
|
|
|
356
360
|
console.log(`SSO-SDK: No user found in DB.`);
|
|
357
361
|
return;
|
|
358
362
|
}
|
|
359
|
-
const
|
|
363
|
+
const res = await this.withRefresh(async (aT) => {
|
|
360
364
|
return await fetch(`${this.ssoServerUrl}/clothings`, {
|
|
361
365
|
method: "POST",
|
|
362
366
|
body: JSON.stringify(jsonPayload),
|
|
@@ -367,12 +371,12 @@ export default class SSO {
|
|
|
367
371
|
},
|
|
368
372
|
});
|
|
369
373
|
});
|
|
370
|
-
if (!
|
|
374
|
+
if (!res?.ok) {
|
|
371
375
|
if (this.config.debug)
|
|
372
376
|
console.log(`SSO-SDK: Profile update failed.`);
|
|
373
377
|
return;
|
|
374
378
|
}
|
|
375
|
-
const { data } = (await
|
|
379
|
+
const { data } = (await res.json());
|
|
376
380
|
this.cb({
|
|
377
381
|
type: c.actions.cloth_add,
|
|
378
382
|
payload: data,
|
|
@@ -390,7 +394,7 @@ export default class SSO {
|
|
|
390
394
|
limit: Math.ceil(options?.limit ?? 10).toString(),
|
|
391
395
|
sort: options?.sort ?? "asc",
|
|
392
396
|
});
|
|
393
|
-
const
|
|
397
|
+
const res = await this.withRefresh(async (aT) => {
|
|
394
398
|
return await fetch(`${this.ssoServerUrl}/clothings?${queryParams.toString()}`, {
|
|
395
399
|
headers: {
|
|
396
400
|
"Content-Type": "application/json",
|
|
@@ -399,12 +403,12 @@ export default class SSO {
|
|
|
399
403
|
},
|
|
400
404
|
});
|
|
401
405
|
});
|
|
402
|
-
if (!
|
|
406
|
+
if (!res?.ok) {
|
|
403
407
|
if (this.config.debug)
|
|
404
408
|
console.log(`SSO-SDK: Get all cloths failed.`);
|
|
405
409
|
return;
|
|
406
410
|
}
|
|
407
|
-
const { data } = (await
|
|
411
|
+
const { data } = (await res.json());
|
|
408
412
|
this.cb({
|
|
409
413
|
type: c.actions.cloth_fetch_all,
|
|
410
414
|
payload: data,
|
|
@@ -417,7 +421,7 @@ export default class SSO {
|
|
|
417
421
|
console.log(`SSO-SDK: Not in browser.`);
|
|
418
422
|
return;
|
|
419
423
|
}
|
|
420
|
-
const
|
|
424
|
+
const res = await this.withRefresh(async (aT) => {
|
|
421
425
|
return await fetch(`${this.ssoServerUrl}/clothings/${clothId}`, {
|
|
422
426
|
headers: {
|
|
423
427
|
"Content-Type": "application/json",
|
|
@@ -426,12 +430,12 @@ export default class SSO {
|
|
|
426
430
|
},
|
|
427
431
|
});
|
|
428
432
|
});
|
|
429
|
-
if (!
|
|
433
|
+
if (!res?.ok) {
|
|
430
434
|
if (this.config.debug)
|
|
431
435
|
console.log(`SSO-SDK: Get cloth by id failed.`);
|
|
432
436
|
return;
|
|
433
437
|
}
|
|
434
|
-
const { data } = (await
|
|
438
|
+
const { data } = (await res.json());
|
|
435
439
|
this.cb({
|
|
436
440
|
type: c.actions.cloth_fetch,
|
|
437
441
|
payload: data,
|
|
@@ -444,7 +448,7 @@ export default class SSO {
|
|
|
444
448
|
console.log(`SSO-SDK: Not in browser.`);
|
|
445
449
|
return;
|
|
446
450
|
}
|
|
447
|
-
const
|
|
451
|
+
const res = await this.withRefresh(async (aT) => {
|
|
448
452
|
return await fetch(`${this.ssoServerUrl}/clothings/${clothId}`, {
|
|
449
453
|
method: "PATCH",
|
|
450
454
|
body: JSON.stringify(payload),
|
|
@@ -455,12 +459,12 @@ export default class SSO {
|
|
|
455
459
|
},
|
|
456
460
|
});
|
|
457
461
|
});
|
|
458
|
-
if (!
|
|
462
|
+
if (!res?.ok) {
|
|
459
463
|
if (this.config.debug)
|
|
460
464
|
console.log(`SSO-SDK: Cloth update failed.`);
|
|
461
465
|
return;
|
|
462
466
|
}
|
|
463
|
-
const { data } = (await
|
|
467
|
+
const { data } = (await res.json());
|
|
464
468
|
this.cb({
|
|
465
469
|
type: c.actions.cloth_update,
|
|
466
470
|
payload: data,
|
|
@@ -480,7 +484,7 @@ export default class SSO {
|
|
|
480
484
|
console.log(`SSO-SDK: No user found in DB.`);
|
|
481
485
|
return;
|
|
482
486
|
}
|
|
483
|
-
const
|
|
487
|
+
const res = await this.withRefresh(async (aT) => {
|
|
484
488
|
return await fetch(`${this.ssoServerUrl}/clothings/${clothId}`, {
|
|
485
489
|
method: "DELETE",
|
|
486
490
|
headers: {
|
|
@@ -490,12 +494,12 @@ export default class SSO {
|
|
|
490
494
|
},
|
|
491
495
|
});
|
|
492
496
|
});
|
|
493
|
-
if (!
|
|
497
|
+
if (!res?.ok) {
|
|
494
498
|
if (this.config.debug)
|
|
495
499
|
console.log(`SSO-SDK: Cloth delete failed.`);
|
|
496
500
|
return;
|
|
497
501
|
}
|
|
498
|
-
await
|
|
502
|
+
await res.json();
|
|
499
503
|
this.cb({
|
|
500
504
|
type: c.actions.cloth_delete,
|
|
501
505
|
payload: {
|
|
@@ -521,7 +525,7 @@ export default class SSO {
|
|
|
521
525
|
...payload,
|
|
522
526
|
thumb: thumb,
|
|
523
527
|
};
|
|
524
|
-
const
|
|
528
|
+
const res = await this.withRefresh(async (aT) => {
|
|
525
529
|
return await fetch(`${this.ssoServerUrl}/clothings/materials`, {
|
|
526
530
|
method: "POST",
|
|
527
531
|
body: JSON.stringify(jsonPayload),
|
|
@@ -532,12 +536,12 @@ export default class SSO {
|
|
|
532
536
|
},
|
|
533
537
|
});
|
|
534
538
|
});
|
|
535
|
-
if (!
|
|
539
|
+
if (!res?.ok) {
|
|
536
540
|
if (this.config.debug)
|
|
537
541
|
console.log(`SSO-SDK: Material add failed.`);
|
|
538
542
|
return;
|
|
539
543
|
}
|
|
540
|
-
const { data } = (await
|
|
544
|
+
const { data } = (await res.json());
|
|
541
545
|
this.cb({
|
|
542
546
|
type: c.actions.material_add,
|
|
543
547
|
payload: data,
|
|
@@ -555,7 +559,7 @@ export default class SSO {
|
|
|
555
559
|
limit: options?.limit?.toString() || "10",
|
|
556
560
|
sort: options?.sort || "asc",
|
|
557
561
|
});
|
|
558
|
-
const
|
|
562
|
+
const res = await this.withRefresh(async (aT) => {
|
|
559
563
|
return await fetch(`${this.ssoServerUrl}/clothings/materials?${params}`, {
|
|
560
564
|
method: "GET",
|
|
561
565
|
headers: {
|
|
@@ -565,12 +569,12 @@ export default class SSO {
|
|
|
565
569
|
},
|
|
566
570
|
});
|
|
567
571
|
});
|
|
568
|
-
if (!
|
|
572
|
+
if (!res?.ok) {
|
|
569
573
|
if (this.config.debug)
|
|
570
574
|
console.log(`SSO-SDK: Materials fetch failed.`);
|
|
571
575
|
return;
|
|
572
576
|
}
|
|
573
|
-
const { data } = (await
|
|
577
|
+
const { data } = (await res.json());
|
|
574
578
|
this.cb({
|
|
575
579
|
type: c.actions.material_fetch_all,
|
|
576
580
|
payload: data,
|
|
@@ -583,7 +587,7 @@ export default class SSO {
|
|
|
583
587
|
console.log(`SSO-SDK: Not in browser.`);
|
|
584
588
|
return;
|
|
585
589
|
}
|
|
586
|
-
const
|
|
590
|
+
const res = await this.withRefresh(async (aT) => {
|
|
587
591
|
return await fetch(`${this.ssoServerUrl}/clothings/materials/${materialId}`, {
|
|
588
592
|
method: "GET",
|
|
589
593
|
headers: {
|
|
@@ -593,12 +597,12 @@ export default class SSO {
|
|
|
593
597
|
},
|
|
594
598
|
});
|
|
595
599
|
});
|
|
596
|
-
if (!
|
|
600
|
+
if (!res?.ok) {
|
|
597
601
|
if (this.config.debug)
|
|
598
602
|
console.log(`SSO-SDK: Material fetch failed.`);
|
|
599
603
|
return;
|
|
600
604
|
}
|
|
601
|
-
const { data } = (await
|
|
605
|
+
const { data } = (await res.json());
|
|
602
606
|
this.cb({
|
|
603
607
|
type: c.actions.material_fetch,
|
|
604
608
|
payload: data,
|
|
@@ -611,7 +615,7 @@ export default class SSO {
|
|
|
611
615
|
console.log(`SSO-SDK: Not in browser.`);
|
|
612
616
|
return;
|
|
613
617
|
}
|
|
614
|
-
const
|
|
618
|
+
const res = await this.withRefresh(async (aT) => {
|
|
615
619
|
return await fetch(`${this.ssoServerUrl}/clothings/materials/${materialId}`, {
|
|
616
620
|
method: "PATCH",
|
|
617
621
|
body: JSON.stringify(payload),
|
|
@@ -622,12 +626,12 @@ export default class SSO {
|
|
|
622
626
|
},
|
|
623
627
|
});
|
|
624
628
|
});
|
|
625
|
-
if (!
|
|
629
|
+
if (!res?.ok) {
|
|
626
630
|
if (this.config.debug)
|
|
627
631
|
console.log(`SSO-SDK: Material update failed.`);
|
|
628
632
|
return;
|
|
629
633
|
}
|
|
630
|
-
const { data } = (await
|
|
634
|
+
const { data } = (await res.json());
|
|
631
635
|
this.cb({
|
|
632
636
|
type: c.actions.material_update,
|
|
633
637
|
payload: data,
|
|
@@ -640,7 +644,7 @@ export default class SSO {
|
|
|
640
644
|
console.log(`SSO-SDK: Not in browser.`);
|
|
641
645
|
return;
|
|
642
646
|
}
|
|
643
|
-
const
|
|
647
|
+
const res = await this.withRefresh(async (aT) => {
|
|
644
648
|
return await fetch(`${this.ssoServerUrl}/clothings/materials/${materialId}`, {
|
|
645
649
|
method: "DELETE",
|
|
646
650
|
headers: {
|
|
@@ -650,7 +654,7 @@ export default class SSO {
|
|
|
650
654
|
},
|
|
651
655
|
});
|
|
652
656
|
});
|
|
653
|
-
if (!
|
|
657
|
+
if (!res?.ok) {
|
|
654
658
|
if (this.config.debug)
|
|
655
659
|
console.log(`SSO-SDK: Material delete failed.`);
|
|
656
660
|
return;
|
|
@@ -680,7 +684,7 @@ export default class SSO {
|
|
|
680
684
|
previewUrl: preview,
|
|
681
685
|
url3d: model,
|
|
682
686
|
};
|
|
683
|
-
const
|
|
687
|
+
const res = await this.withRefresh(async (aT) => {
|
|
684
688
|
return await fetch(`${this.ssoServerUrl}/skulls`, {
|
|
685
689
|
method: "POST",
|
|
686
690
|
body: JSON.stringify(jsonPayload),
|
|
@@ -691,12 +695,12 @@ export default class SSO {
|
|
|
691
695
|
},
|
|
692
696
|
});
|
|
693
697
|
});
|
|
694
|
-
if (!
|
|
698
|
+
if (!res?.ok) {
|
|
695
699
|
if (this.config.debug)
|
|
696
700
|
console.log(`SSO-SDK: Skull add failed.`);
|
|
697
701
|
return;
|
|
698
702
|
}
|
|
699
|
-
const { data } = (await
|
|
703
|
+
const { data } = (await res.json());
|
|
700
704
|
this.cb({
|
|
701
705
|
type: c.actions.skull_add,
|
|
702
706
|
payload: data,
|
|
@@ -709,7 +713,7 @@ export default class SSO {
|
|
|
709
713
|
console.log(`SSO-SDK: Not in browser.`);
|
|
710
714
|
return;
|
|
711
715
|
}
|
|
712
|
-
const
|
|
716
|
+
const res = await this.withRefresh(async (aT) => {
|
|
713
717
|
return await fetch(`${this.ssoServerUrl}/skulls/${skullId}`, {
|
|
714
718
|
method: "PATCH",
|
|
715
719
|
body: JSON.stringify(payload),
|
|
@@ -720,12 +724,12 @@ export default class SSO {
|
|
|
720
724
|
},
|
|
721
725
|
});
|
|
722
726
|
});
|
|
723
|
-
if (!
|
|
727
|
+
if (!res?.ok) {
|
|
724
728
|
if (this.config.debug)
|
|
725
729
|
console.log(`SSO-SDK: Skull update failed.`);
|
|
726
730
|
return;
|
|
727
731
|
}
|
|
728
|
-
const { data } = (await
|
|
732
|
+
const { data } = (await res.json());
|
|
729
733
|
this.cb({
|
|
730
734
|
type: c.actions.skull_update,
|
|
731
735
|
payload: data,
|
|
@@ -738,7 +742,7 @@ export default class SSO {
|
|
|
738
742
|
console.log(`SSO-SDK: Not in browser.`);
|
|
739
743
|
return;
|
|
740
744
|
}
|
|
741
|
-
const
|
|
745
|
+
const res = await this.withRefresh(async (aT) => {
|
|
742
746
|
return await fetch(`${this.ssoServerUrl}/skulls`, {
|
|
743
747
|
method: "GET",
|
|
744
748
|
headers: {
|
|
@@ -748,12 +752,12 @@ export default class SSO {
|
|
|
748
752
|
},
|
|
749
753
|
});
|
|
750
754
|
});
|
|
751
|
-
if (!
|
|
755
|
+
if (!res?.ok) {
|
|
752
756
|
if (this.config.debug)
|
|
753
757
|
console.log(`SSO-SDK: Skull get all failed.`);
|
|
754
758
|
return;
|
|
755
759
|
}
|
|
756
|
-
const { data } = (await
|
|
760
|
+
const { data } = (await res.json());
|
|
757
761
|
this.cb({
|
|
758
762
|
type: c.actions.skull_fetch_all,
|
|
759
763
|
payload: data,
|
|
@@ -766,7 +770,7 @@ export default class SSO {
|
|
|
766
770
|
console.log(`SSO-SDK: Not in browser.`);
|
|
767
771
|
return;
|
|
768
772
|
}
|
|
769
|
-
const
|
|
773
|
+
const res = await this.withRefresh(async (aT) => {
|
|
770
774
|
return await fetch(`${this.ssoServerUrl}/skulls/${skullId}`, {
|
|
771
775
|
method: "GET",
|
|
772
776
|
headers: {
|
|
@@ -776,12 +780,12 @@ export default class SSO {
|
|
|
776
780
|
},
|
|
777
781
|
});
|
|
778
782
|
});
|
|
779
|
-
if (!
|
|
783
|
+
if (!res?.ok) {
|
|
780
784
|
if (this.config.debug)
|
|
781
785
|
console.log(`SSO-SDK: Skull get by id failed.`);
|
|
782
786
|
return;
|
|
783
787
|
}
|
|
784
|
-
const { data } = (await
|
|
788
|
+
const { data } = (await res.json());
|
|
785
789
|
this.cb({
|
|
786
790
|
type: c.actions.skull_fetch,
|
|
787
791
|
payload: data,
|
|
@@ -794,7 +798,7 @@ export default class SSO {
|
|
|
794
798
|
console.log(`SSO-SDK: Not in browser.`);
|
|
795
799
|
return;
|
|
796
800
|
}
|
|
797
|
-
const
|
|
801
|
+
const res = await this.withRefresh(async (aT) => {
|
|
798
802
|
return await fetch(`${this.ssoServerUrl}/skulls/${skullId}`, {
|
|
799
803
|
method: "DELETE",
|
|
800
804
|
headers: {
|
|
@@ -804,7 +808,7 @@ export default class SSO {
|
|
|
804
808
|
},
|
|
805
809
|
});
|
|
806
810
|
});
|
|
807
|
-
if (!
|
|
811
|
+
if (!res?.ok) {
|
|
808
812
|
if (this.config.debug)
|
|
809
813
|
console.log(`SSO-SDK: Skull delete failed.`);
|
|
810
814
|
return;
|
|
@@ -817,6 +821,334 @@ export default class SSO {
|
|
|
817
821
|
});
|
|
818
822
|
return skullId;
|
|
819
823
|
};
|
|
824
|
+
// skull material
|
|
825
|
+
this.skullMaterialAdd = async (payload) => {
|
|
826
|
+
if (!isBrowser()) {
|
|
827
|
+
if (this.config.debug)
|
|
828
|
+
console.log(`SSO-SDK: Not in browser.`);
|
|
829
|
+
return;
|
|
830
|
+
}
|
|
831
|
+
const { file3d, previewFile, ...rest } = payload;
|
|
832
|
+
const preview = await this.fileUpload(previewFile);
|
|
833
|
+
const model = await this.fileUpload(file3d);
|
|
834
|
+
if (!preview || !model) {
|
|
835
|
+
if (this.config.debug)
|
|
836
|
+
console.log(`SSO-SDK: File upload failed.`);
|
|
837
|
+
return;
|
|
838
|
+
}
|
|
839
|
+
const jsonPayload = {
|
|
840
|
+
...rest,
|
|
841
|
+
previewUrl: preview,
|
|
842
|
+
url3d: model,
|
|
843
|
+
};
|
|
844
|
+
const res = await this.withRefresh(async (aT) => {
|
|
845
|
+
return await fetch(`${this.ssoServerUrl}/skulls/materials`, {
|
|
846
|
+
method: "POST",
|
|
847
|
+
body: JSON.stringify(jsonPayload),
|
|
848
|
+
headers: {
|
|
849
|
+
"Content-Type": "application/json",
|
|
850
|
+
Authorization: `Bearer ${aT}`,
|
|
851
|
+
"x-sdk-key": this.config.sdkKey,
|
|
852
|
+
},
|
|
853
|
+
});
|
|
854
|
+
});
|
|
855
|
+
if (!res?.ok) {
|
|
856
|
+
if (this.config.debug)
|
|
857
|
+
console.log(`SSO-SDK: Skull material add failed.`);
|
|
858
|
+
return;
|
|
859
|
+
}
|
|
860
|
+
const { data } = (await res.json());
|
|
861
|
+
this.cb({
|
|
862
|
+
type: c.actions.skull_material_add,
|
|
863
|
+
payload: data,
|
|
864
|
+
});
|
|
865
|
+
return data;
|
|
866
|
+
};
|
|
867
|
+
this.skullMaterialGetAll = async () => {
|
|
868
|
+
if (!isBrowser()) {
|
|
869
|
+
if (this.config.debug)
|
|
870
|
+
console.log(`SSO-SDK: Not in browser.`);
|
|
871
|
+
return;
|
|
872
|
+
}
|
|
873
|
+
const res = await this.withRefresh(async (aT) => {
|
|
874
|
+
return await fetch(`${this.ssoServerUrl}/skulls/materials`, {
|
|
875
|
+
method: "GET",
|
|
876
|
+
headers: {
|
|
877
|
+
"Content-Type": "application/json",
|
|
878
|
+
Authorization: `Bearer ${aT}`,
|
|
879
|
+
"x-sdk-key": this.config.sdkKey,
|
|
880
|
+
},
|
|
881
|
+
});
|
|
882
|
+
});
|
|
883
|
+
if (!res?.ok) {
|
|
884
|
+
if (this.config.debug)
|
|
885
|
+
console.log(`SSO-SDK: Skull materials get failed.`);
|
|
886
|
+
return;
|
|
887
|
+
}
|
|
888
|
+
const { data } = (await res.json());
|
|
889
|
+
this.cb({
|
|
890
|
+
type: c.actions.skull_material_fetch_all,
|
|
891
|
+
payload: data,
|
|
892
|
+
});
|
|
893
|
+
return data;
|
|
894
|
+
};
|
|
895
|
+
this.skullMaterialGetById = async (id) => {
|
|
896
|
+
if (!isBrowser()) {
|
|
897
|
+
if (this.config.debug)
|
|
898
|
+
console.log(`SSO-SDK: Not in browser.`);
|
|
899
|
+
return;
|
|
900
|
+
}
|
|
901
|
+
const res = await this.withRefresh(async (aT) => {
|
|
902
|
+
return await fetch(`${this.ssoServerUrl}/skulls/materials/${id}`, {
|
|
903
|
+
method: "GET",
|
|
904
|
+
headers: {
|
|
905
|
+
"Content-Type": "application/json",
|
|
906
|
+
Authorization: `Bearer ${aT}`,
|
|
907
|
+
"x-sdk-key": this.config.sdkKey,
|
|
908
|
+
},
|
|
909
|
+
});
|
|
910
|
+
});
|
|
911
|
+
if (!res?.ok) {
|
|
912
|
+
if (this.config.debug)
|
|
913
|
+
console.log(`SSO-SDK: Skull materials get all failed.`);
|
|
914
|
+
return;
|
|
915
|
+
}
|
|
916
|
+
const { data } = (await res.json());
|
|
917
|
+
this.cb({
|
|
918
|
+
type: c.actions.skull_material_fetch,
|
|
919
|
+
payload: data,
|
|
920
|
+
});
|
|
921
|
+
return data;
|
|
922
|
+
};
|
|
923
|
+
this.skullMaterialUpdate = async (id, payload) => {
|
|
924
|
+
if (!isBrowser()) {
|
|
925
|
+
if (this.config.debug)
|
|
926
|
+
console.log(`SSO-SDK: Not in browser.`);
|
|
927
|
+
return;
|
|
928
|
+
}
|
|
929
|
+
const { file3d, previewFile, ...rest } = payload;
|
|
930
|
+
const preview = previewFile && (await this.fileUpload(previewFile));
|
|
931
|
+
const model = file3d && (await this.fileUpload(file3d));
|
|
932
|
+
const jsonPayload = {
|
|
933
|
+
...rest,
|
|
934
|
+
previewUrl: preview,
|
|
935
|
+
url3d: model,
|
|
936
|
+
};
|
|
937
|
+
const res = await this.withRefresh(async (aT) => {
|
|
938
|
+
return await fetch(`${this.ssoServerUrl}/skulls/materials/${id}`, {
|
|
939
|
+
method: "PATCH",
|
|
940
|
+
body: JSON.stringify(jsonPayload),
|
|
941
|
+
headers: {
|
|
942
|
+
"Content-Type": "application/json",
|
|
943
|
+
Authorization: `Bearer ${aT}`,
|
|
944
|
+
"x-sdk-key": this.config.sdkKey,
|
|
945
|
+
},
|
|
946
|
+
});
|
|
947
|
+
});
|
|
948
|
+
if (!res?.ok) {
|
|
949
|
+
if (this.config.debug)
|
|
950
|
+
console.log(`SSO-SDK: Skull materials get all failed.`);
|
|
951
|
+
return;
|
|
952
|
+
}
|
|
953
|
+
const { data } = (await res.json());
|
|
954
|
+
this.cb({
|
|
955
|
+
type: c.actions.skull_material_update,
|
|
956
|
+
payload: data,
|
|
957
|
+
});
|
|
958
|
+
return data;
|
|
959
|
+
};
|
|
960
|
+
this.skullMaterialDelete = async (id) => {
|
|
961
|
+
if (!isBrowser()) {
|
|
962
|
+
if (this.config.debug)
|
|
963
|
+
console.log(`SSO-SDK: Not in browser.`);
|
|
964
|
+
return;
|
|
965
|
+
}
|
|
966
|
+
const res = await this.withRefresh(async (aT) => {
|
|
967
|
+
return await fetch(`${this.ssoServerUrl}/skulls/materials/${id}`, {
|
|
968
|
+
method: "DELETE",
|
|
969
|
+
headers: {
|
|
970
|
+
"Content-Type": "application/json",
|
|
971
|
+
Authorization: `Bearer ${aT}`,
|
|
972
|
+
"x-sdk-key": this.config.sdkKey,
|
|
973
|
+
},
|
|
974
|
+
});
|
|
975
|
+
});
|
|
976
|
+
if (!res?.ok) {
|
|
977
|
+
if (this.config.debug)
|
|
978
|
+
console.log(`SSO-SDK: Skull materials get all failed.`);
|
|
979
|
+
return;
|
|
980
|
+
}
|
|
981
|
+
const { data } = (await res.json());
|
|
982
|
+
this.cb({
|
|
983
|
+
type: c.actions.skull_material_delete,
|
|
984
|
+
payload: data,
|
|
985
|
+
});
|
|
986
|
+
return data;
|
|
987
|
+
};
|
|
988
|
+
// body
|
|
989
|
+
this.bodyAdd = async (payload) => {
|
|
990
|
+
if (!isBrowser()) {
|
|
991
|
+
if (this.config.debug)
|
|
992
|
+
console.log(`SSO-SDK: Not in browser.`);
|
|
993
|
+
return;
|
|
994
|
+
}
|
|
995
|
+
const { file3d, previewFile, ...rest } = payload;
|
|
996
|
+
const preview = await this.fileUpload(previewFile);
|
|
997
|
+
const model = await this.fileUpload(file3d);
|
|
998
|
+
if (!preview || !model) {
|
|
999
|
+
if (this.config.debug)
|
|
1000
|
+
console.log(`SSO-SDK: File upload failed.`);
|
|
1001
|
+
return;
|
|
1002
|
+
}
|
|
1003
|
+
const jsonPayload = {
|
|
1004
|
+
...rest,
|
|
1005
|
+
previewUrl: preview,
|
|
1006
|
+
url3d: model,
|
|
1007
|
+
};
|
|
1008
|
+
const res = await this.withRefresh(async (aT) => {
|
|
1009
|
+
return await fetch(`${this.ssoServerUrl}/bodies`, {
|
|
1010
|
+
method: "POST",
|
|
1011
|
+
body: JSON.stringify(jsonPayload),
|
|
1012
|
+
headers: {
|
|
1013
|
+
"Content-Type": "application/json",
|
|
1014
|
+
Authorization: `Bearer ${aT}`,
|
|
1015
|
+
"x-sdk-key": this.config.sdkKey,
|
|
1016
|
+
},
|
|
1017
|
+
});
|
|
1018
|
+
});
|
|
1019
|
+
if (!res?.ok) {
|
|
1020
|
+
if (this.config.debug)
|
|
1021
|
+
console.log(`SSO-SDK: Body add failed.`);
|
|
1022
|
+
return;
|
|
1023
|
+
}
|
|
1024
|
+
const { data } = (await res.json());
|
|
1025
|
+
this.cb({
|
|
1026
|
+
type: c.actions.body_add,
|
|
1027
|
+
payload: data,
|
|
1028
|
+
});
|
|
1029
|
+
return data;
|
|
1030
|
+
};
|
|
1031
|
+
this.bodyGetAll = async () => {
|
|
1032
|
+
if (!isBrowser()) {
|
|
1033
|
+
if (this.config.debug)
|
|
1034
|
+
console.log(`SSO-SDK: Not in browser.`);
|
|
1035
|
+
return;
|
|
1036
|
+
}
|
|
1037
|
+
const res = await this.withRefresh(async (aT) => {
|
|
1038
|
+
return await fetch(`${this.ssoServerUrl}/bodies`, {
|
|
1039
|
+
method: "GET",
|
|
1040
|
+
headers: {
|
|
1041
|
+
"Content-Type": "application/json",
|
|
1042
|
+
Authorization: `Bearer ${aT}`,
|
|
1043
|
+
"x-sdk-key": this.config.sdkKey,
|
|
1044
|
+
},
|
|
1045
|
+
});
|
|
1046
|
+
});
|
|
1047
|
+
if (!res?.ok) {
|
|
1048
|
+
if (this.config.debug)
|
|
1049
|
+
console.log(`SSO-SDK: Body add failed.`);
|
|
1050
|
+
return;
|
|
1051
|
+
}
|
|
1052
|
+
const { data } = (await res.json());
|
|
1053
|
+
this.cb({
|
|
1054
|
+
type: c.actions.body_fetch_all,
|
|
1055
|
+
payload: data,
|
|
1056
|
+
});
|
|
1057
|
+
return data;
|
|
1058
|
+
};
|
|
1059
|
+
this.bodyGetById = async (id) => {
|
|
1060
|
+
if (!isBrowser()) {
|
|
1061
|
+
if (this.config.debug)
|
|
1062
|
+
console.log(`SSO-SDK: Not in browser.`);
|
|
1063
|
+
return;
|
|
1064
|
+
}
|
|
1065
|
+
const res = await this.withRefresh(async (aT) => {
|
|
1066
|
+
return await fetch(`${this.ssoServerUrl}/bodies/${id}`, {
|
|
1067
|
+
method: "GET",
|
|
1068
|
+
headers: {
|
|
1069
|
+
"Content-Type": "application/json",
|
|
1070
|
+
Authorization: `Bearer ${aT}`,
|
|
1071
|
+
"x-sdk-key": this.config.sdkKey,
|
|
1072
|
+
},
|
|
1073
|
+
});
|
|
1074
|
+
});
|
|
1075
|
+
if (!res?.ok) {
|
|
1076
|
+
if (this.config.debug)
|
|
1077
|
+
console.log(`SSO-SDK: Body add failed.`);
|
|
1078
|
+
return;
|
|
1079
|
+
}
|
|
1080
|
+
const { data } = (await res.json());
|
|
1081
|
+
this.cb({
|
|
1082
|
+
type: c.actions.body_fetch,
|
|
1083
|
+
payload: data,
|
|
1084
|
+
});
|
|
1085
|
+
return data;
|
|
1086
|
+
};
|
|
1087
|
+
this.bodyUpdate = async (id, payload) => {
|
|
1088
|
+
if (!isBrowser()) {
|
|
1089
|
+
if (this.config.debug)
|
|
1090
|
+
console.log(`SSO-SDK: Not in browser.`);
|
|
1091
|
+
return;
|
|
1092
|
+
}
|
|
1093
|
+
const { file3d, previewFile, ...rest } = payload;
|
|
1094
|
+
const preview = previewFile && (await this.fileUpload(previewFile));
|
|
1095
|
+
const model = file3d && (await this.fileUpload(file3d));
|
|
1096
|
+
const jsonPayload = {
|
|
1097
|
+
...rest,
|
|
1098
|
+
previewUrl: preview,
|
|
1099
|
+
url3d: model,
|
|
1100
|
+
};
|
|
1101
|
+
const res = await this.withRefresh(async (aT) => {
|
|
1102
|
+
return await fetch(`${this.ssoServerUrl}/bodies/${id}`, {
|
|
1103
|
+
method: "PATCH",
|
|
1104
|
+
body: JSON.stringify(jsonPayload),
|
|
1105
|
+
headers: {
|
|
1106
|
+
"Content-Type": "application/json",
|
|
1107
|
+
Authorization: `Bearer ${aT}`,
|
|
1108
|
+
"x-sdk-key": this.config.sdkKey,
|
|
1109
|
+
},
|
|
1110
|
+
});
|
|
1111
|
+
});
|
|
1112
|
+
if (!res?.ok) {
|
|
1113
|
+
if (this.config.debug)
|
|
1114
|
+
console.log(`SSO-SDK: Body add failed.`);
|
|
1115
|
+
return;
|
|
1116
|
+
}
|
|
1117
|
+
const { data } = (await res.json());
|
|
1118
|
+
this.cb({
|
|
1119
|
+
type: c.actions.body_update,
|
|
1120
|
+
payload: data,
|
|
1121
|
+
});
|
|
1122
|
+
return data;
|
|
1123
|
+
};
|
|
1124
|
+
this.bodyDelete = async (id) => {
|
|
1125
|
+
if (!isBrowser()) {
|
|
1126
|
+
if (this.config.debug)
|
|
1127
|
+
console.log(`SSO-SDK: Not in browser.`);
|
|
1128
|
+
return;
|
|
1129
|
+
}
|
|
1130
|
+
const res = await this.withRefresh(async (aT) => {
|
|
1131
|
+
return await fetch(`${this.ssoServerUrl}/bodies/${id}`, {
|
|
1132
|
+
method: "DELETE",
|
|
1133
|
+
headers: {
|
|
1134
|
+
"Content-Type": "application/json",
|
|
1135
|
+
Authorization: `Bearer ${aT}`,
|
|
1136
|
+
"x-sdk-key": this.config.sdkKey,
|
|
1137
|
+
},
|
|
1138
|
+
});
|
|
1139
|
+
});
|
|
1140
|
+
if (!res?.ok) {
|
|
1141
|
+
if (this.config.debug)
|
|
1142
|
+
console.log(`SSO-SDK: Body add failed.`);
|
|
1143
|
+
return;
|
|
1144
|
+
}
|
|
1145
|
+
const { data } = (await res.json());
|
|
1146
|
+
this.cb({
|
|
1147
|
+
type: c.actions.body_delete,
|
|
1148
|
+
payload: data,
|
|
1149
|
+
});
|
|
1150
|
+
return data;
|
|
1151
|
+
};
|
|
820
1152
|
if (config.debug)
|
|
821
1153
|
console.log(`SSO-SDK: Debug mode enabled.`);
|
|
822
1154
|
}
|