@newgameplusinc/odyssey-sso 2.0.12 → 2.1.1

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