@newgameplusinc/odyssey-sso 2.0.11 → 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/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 +414 -209
- 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,33 +74,27 @@ 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
|
-
await this.
|
|
84
|
-
const dbUser = (await this.db.getById(this.dbId));
|
|
85
|
-
if (!dbUser) {
|
|
86
|
-
if (this.config.debug)
|
|
87
|
-
console.log(`SSO-SDK: No user found in DB.`);
|
|
88
|
-
return;
|
|
89
|
-
}
|
|
90
|
-
const user = await this.withRefresh(async (aT) => {
|
|
84
|
+
const res = await this.withRefresh(async (aT) => {
|
|
91
85
|
return await fetch(`${this.ssoServerUrl}/users/profile`, {
|
|
92
86
|
headers: {
|
|
93
87
|
"Content-Type": "application/json",
|
|
94
|
-
Authorization: `Bearer ${aT
|
|
88
|
+
Authorization: `Bearer ${aT}`,
|
|
95
89
|
},
|
|
96
90
|
});
|
|
97
91
|
});
|
|
98
|
-
if (!
|
|
92
|
+
if (!res?.ok) {
|
|
99
93
|
if (this.config.debug)
|
|
100
94
|
console.log(`SSO-SDK: Profile fetch failed.`);
|
|
101
95
|
return;
|
|
102
96
|
}
|
|
103
|
-
const { data } = (await
|
|
97
|
+
const { data } = (await res.json());
|
|
104
98
|
this.cb({
|
|
105
99
|
type: c.actions.profile_fetch,
|
|
106
100
|
payload: data,
|
|
@@ -120,7 +114,7 @@ export default class SSO {
|
|
|
120
114
|
console.log(`SSO-SDK: No user found in DB.`);
|
|
121
115
|
return;
|
|
122
116
|
}
|
|
123
|
-
const
|
|
117
|
+
const res = await fetch(`${this.ssoServerUrl}/users/refresh`, {
|
|
124
118
|
method: "POST",
|
|
125
119
|
body: JSON.stringify({
|
|
126
120
|
token: dbUser.tokens.refreshToken,
|
|
@@ -129,12 +123,12 @@ export default class SSO {
|
|
|
129
123
|
"Content-Type": "application/json",
|
|
130
124
|
},
|
|
131
125
|
});
|
|
132
|
-
if (!
|
|
126
|
+
if (!res.ok) {
|
|
133
127
|
if (this.config.debug)
|
|
134
128
|
console.log(`SSO-SDK: Refresh failed.`);
|
|
135
129
|
return;
|
|
136
130
|
}
|
|
137
|
-
const { data } = (await
|
|
131
|
+
const { data } = (await res.json());
|
|
138
132
|
await this.db.update(this.dbId, {
|
|
139
133
|
...dbUser,
|
|
140
134
|
tokens: {
|
|
@@ -148,29 +142,23 @@ export default class SSO {
|
|
|
148
142
|
});
|
|
149
143
|
return data;
|
|
150
144
|
};
|
|
145
|
+
// todo: fix
|
|
151
146
|
this.logout = async () => {
|
|
152
147
|
if (!isBrowser()) {
|
|
153
148
|
if (this.config.debug)
|
|
154
149
|
console.log(`SSO-SDK: Not in browser.`);
|
|
155
150
|
return;
|
|
156
151
|
}
|
|
157
|
-
await this.
|
|
158
|
-
const dbUser = (await this.db.getById(this.dbId));
|
|
159
|
-
if (!dbUser) {
|
|
160
|
-
if (this.config.debug)
|
|
161
|
-
console.log(`SSO-SDK: No user found in DB.`);
|
|
162
|
-
return;
|
|
163
|
-
}
|
|
164
|
-
const user = await this.withRefresh(async (aT) => {
|
|
152
|
+
const res = await this.withRefresh(async (aT) => {
|
|
165
153
|
return await fetch(`${this.ssoServerUrl}/users/logout`, {
|
|
166
154
|
method: "DELETE",
|
|
167
155
|
headers: {
|
|
168
156
|
"Content-Type": "application/json",
|
|
169
|
-
Authorization: `Bearer ${aT
|
|
157
|
+
Authorization: `Bearer ${aT}`,
|
|
170
158
|
},
|
|
171
159
|
});
|
|
172
160
|
});
|
|
173
|
-
if (!
|
|
161
|
+
if (!res?.ok) {
|
|
174
162
|
if (this.config.debug)
|
|
175
163
|
console.log(`SSO-SDK: Logout failed.`);
|
|
176
164
|
return;
|
|
@@ -186,10 +174,6 @@ export default class SSO {
|
|
|
186
174
|
this.cb = cb;
|
|
187
175
|
};
|
|
188
176
|
this.withRefresh = async (api) => {
|
|
189
|
-
const r = await api();
|
|
190
|
-
if (r.status !== 401)
|
|
191
|
-
return r;
|
|
192
|
-
// refresh token
|
|
193
177
|
if (!isBrowser()) {
|
|
194
178
|
if (this.config.debug)
|
|
195
179
|
console.log(`SSO-SDK: Not in browser.`);
|
|
@@ -202,7 +186,10 @@ export default class SSO {
|
|
|
202
186
|
console.log(`SSO-SDK: No user found in DB.`);
|
|
203
187
|
return;
|
|
204
188
|
}
|
|
205
|
-
const
|
|
189
|
+
const r = await api(dbUser.tokens.accessToken);
|
|
190
|
+
if (r.status !== 401)
|
|
191
|
+
return r;
|
|
192
|
+
const res = await fetch(`${this.ssoServerUrl}/users/refresh`, {
|
|
206
193
|
method: "POST",
|
|
207
194
|
body: JSON.stringify({
|
|
208
195
|
token: dbUser.tokens.refreshToken,
|
|
@@ -211,12 +198,13 @@ export default class SSO {
|
|
|
211
198
|
"Content-Type": "application/json",
|
|
212
199
|
},
|
|
213
200
|
});
|
|
214
|
-
if (!
|
|
201
|
+
if (!res.ok) {
|
|
215
202
|
if (this.config.debug)
|
|
216
203
|
console.log(`SSO-SDK: Refresh failed.`);
|
|
204
|
+
await this.db.delete(this.dbId);
|
|
217
205
|
return;
|
|
218
206
|
}
|
|
219
|
-
const { data } = (await
|
|
207
|
+
const { data } = (await res.json());
|
|
220
208
|
await this.db.update(this.dbId, {
|
|
221
209
|
...dbUser,
|
|
222
210
|
tokens: {
|
|
@@ -231,36 +219,30 @@ export default class SSO {
|
|
|
231
219
|
const nR = await api(data.accessToken);
|
|
232
220
|
return nR;
|
|
233
221
|
};
|
|
222
|
+
// todo: fix
|
|
234
223
|
this.profileUpdate = async (payload) => {
|
|
235
224
|
if (!isBrowser()) {
|
|
236
225
|
if (this.config.debug)
|
|
237
226
|
console.log(`SSO-SDK: Not in browser.`);
|
|
238
227
|
return;
|
|
239
228
|
}
|
|
240
|
-
await this.
|
|
241
|
-
const dbUser = (await this.db.getById(this.dbId));
|
|
242
|
-
if (!dbUser) {
|
|
243
|
-
if (this.config.debug)
|
|
244
|
-
console.log(`SSO-SDK: No user found in DB.`);
|
|
245
|
-
return;
|
|
246
|
-
}
|
|
247
|
-
const user = await this.withRefresh(async (aT) => {
|
|
229
|
+
const res = await this.withRefresh(async (aT) => {
|
|
248
230
|
return await fetch(`${this.ssoServerUrl}/users/profile`, {
|
|
249
231
|
method: "PATCH",
|
|
250
232
|
body: JSON.stringify(payload),
|
|
251
233
|
headers: {
|
|
252
234
|
"Content-Type": "application/json",
|
|
253
|
-
Authorization: `Bearer ${aT
|
|
235
|
+
Authorization: `Bearer ${aT}`,
|
|
254
236
|
"x-sdk-key": this.config.sdkKey,
|
|
255
237
|
},
|
|
256
238
|
});
|
|
257
239
|
});
|
|
258
|
-
if (!
|
|
240
|
+
if (!res?.ok) {
|
|
259
241
|
if (this.config.debug)
|
|
260
242
|
console.log(`SSO-SDK: Profile update failed.`);
|
|
261
243
|
return;
|
|
262
244
|
}
|
|
263
|
-
const { data } = (await
|
|
245
|
+
const { data } = (await res.json());
|
|
264
246
|
const { id, ...rest } = data;
|
|
265
247
|
await this.db.update(this.dbId, {
|
|
266
248
|
...rest,
|
|
@@ -284,14 +266,7 @@ export default class SSO {
|
|
|
284
266
|
console.log(`SSO-SDK: File upload failed.`);
|
|
285
267
|
return;
|
|
286
268
|
}
|
|
287
|
-
await this.
|
|
288
|
-
const dbUser = (await this.db.getById(this.dbId));
|
|
289
|
-
if (!dbUser) {
|
|
290
|
-
if (this.config.debug)
|
|
291
|
-
console.log(`SSO-SDK: No user found in DB.`);
|
|
292
|
-
return;
|
|
293
|
-
}
|
|
294
|
-
const user = await this.withRefresh(async (aT) => {
|
|
269
|
+
const res = await this.withRefresh(async (aT) => {
|
|
295
270
|
return await fetch(`${this.ssoServerUrl}/users/profile/avatar`, {
|
|
296
271
|
method: "PUT",
|
|
297
272
|
body: JSON.stringify({
|
|
@@ -299,17 +274,17 @@ export default class SSO {
|
|
|
299
274
|
}),
|
|
300
275
|
headers: {
|
|
301
276
|
"Content-Type": "application/json",
|
|
302
|
-
Authorization: `Bearer ${aT
|
|
277
|
+
Authorization: `Bearer ${aT}`,
|
|
303
278
|
"x-sdk-key": this.config.sdkKey,
|
|
304
279
|
},
|
|
305
280
|
});
|
|
306
281
|
});
|
|
307
|
-
if (!
|
|
282
|
+
if (!res?.ok) {
|
|
308
283
|
if (this.config.debug)
|
|
309
284
|
console.log(`SSO-SDK: Profile update failed.`);
|
|
310
285
|
return;
|
|
311
286
|
}
|
|
312
|
-
const { data } = (await
|
|
287
|
+
const { data } = (await res.json());
|
|
313
288
|
const { id, ...rest } = data;
|
|
314
289
|
await this.db.update(this.dbId, {
|
|
315
290
|
...rest,
|
|
@@ -327,24 +302,17 @@ export default class SSO {
|
|
|
327
302
|
console.log(`SSO-SDK: Not in browser.`);
|
|
328
303
|
return;
|
|
329
304
|
}
|
|
330
|
-
await this.db.open();
|
|
331
|
-
const dbUser = (await this.db.getById(this.dbId));
|
|
332
|
-
if (!dbUser) {
|
|
333
|
-
if (this.config.debug)
|
|
334
|
-
console.log(`SSO-SDK: No user found in DB.`);
|
|
335
|
-
return;
|
|
336
|
-
}
|
|
337
305
|
const { type } = file;
|
|
338
306
|
const url = await this.withRefresh(async (aT) => {
|
|
339
307
|
return await fetch(`${this.ssoServerUrl}/uploads/url?fileType=${type}`, {
|
|
340
308
|
headers: {
|
|
341
309
|
"Content-Type": "application/json",
|
|
342
|
-
Authorization: `Bearer ${aT
|
|
310
|
+
Authorization: `Bearer ${aT}`,
|
|
343
311
|
"x-sdk-key": this.config.sdkKey,
|
|
344
312
|
},
|
|
345
313
|
});
|
|
346
314
|
});
|
|
347
|
-
if (!url
|
|
315
|
+
if (!url?.ok) {
|
|
348
316
|
if (this.config.debug)
|
|
349
317
|
console.log(`SSO-SDK: could not get upload url.`);
|
|
350
318
|
return;
|
|
@@ -391,7 +359,7 @@ export default class SSO {
|
|
|
391
359
|
console.log(`SSO-SDK: No user found in DB.`);
|
|
392
360
|
return;
|
|
393
361
|
}
|
|
394
|
-
const
|
|
362
|
+
const res = await this.withRefresh(async (aT) => {
|
|
395
363
|
return await fetch(`${this.ssoServerUrl}/clothings`, {
|
|
396
364
|
method: "POST",
|
|
397
365
|
body: JSON.stringify(jsonPayload),
|
|
@@ -402,12 +370,12 @@ export default class SSO {
|
|
|
402
370
|
},
|
|
403
371
|
});
|
|
404
372
|
});
|
|
405
|
-
if (!
|
|
373
|
+
if (!res?.ok) {
|
|
406
374
|
if (this.config.debug)
|
|
407
375
|
console.log(`SSO-SDK: Profile update failed.`);
|
|
408
376
|
return;
|
|
409
377
|
}
|
|
410
|
-
const { data } = (await
|
|
378
|
+
const { data } = (await res.json());
|
|
411
379
|
this.cb({
|
|
412
380
|
type: c.actions.cloth_add,
|
|
413
381
|
payload: data,
|
|
@@ -420,33 +388,26 @@ export default class SSO {
|
|
|
420
388
|
console.log(`SSO-SDK: Not in browser.`);
|
|
421
389
|
return;
|
|
422
390
|
}
|
|
423
|
-
await this.db.open();
|
|
424
|
-
const dbUser = (await this.db.getById(this.dbId));
|
|
425
|
-
if (!dbUser) {
|
|
426
|
-
if (this.config.debug)
|
|
427
|
-
console.log(`SSO-SDK: No user found in DB.`);
|
|
428
|
-
return;
|
|
429
|
-
}
|
|
430
391
|
const queryParams = new URLSearchParams({
|
|
431
392
|
skip: Math.ceil(options?.skip ?? 0).toString(),
|
|
432
393
|
limit: Math.ceil(options?.limit ?? 10).toString(),
|
|
433
394
|
sort: options?.sort ?? "asc",
|
|
434
395
|
});
|
|
435
|
-
const
|
|
396
|
+
const res = await this.withRefresh(async (aT) => {
|
|
436
397
|
return await fetch(`${this.ssoServerUrl}/clothings?${queryParams.toString()}`, {
|
|
437
398
|
headers: {
|
|
438
399
|
"Content-Type": "application/json",
|
|
439
|
-
Authorization: `Bearer ${aT
|
|
400
|
+
Authorization: `Bearer ${aT}`,
|
|
440
401
|
"x-sdk-key": this.config.sdkKey,
|
|
441
402
|
},
|
|
442
403
|
});
|
|
443
404
|
});
|
|
444
|
-
if (!
|
|
405
|
+
if (!res?.ok) {
|
|
445
406
|
if (this.config.debug)
|
|
446
407
|
console.log(`SSO-SDK: Get all cloths failed.`);
|
|
447
408
|
return;
|
|
448
409
|
}
|
|
449
|
-
const { data } = (await
|
|
410
|
+
const { data } = (await res.json());
|
|
450
411
|
this.cb({
|
|
451
412
|
type: c.actions.cloth_fetch_all,
|
|
452
413
|
payload: data,
|
|
@@ -459,28 +420,21 @@ export default class SSO {
|
|
|
459
420
|
console.log(`SSO-SDK: Not in browser.`);
|
|
460
421
|
return;
|
|
461
422
|
}
|
|
462
|
-
await this.
|
|
463
|
-
const dbUser = (await this.db.getById(this.dbId));
|
|
464
|
-
if (!dbUser) {
|
|
465
|
-
if (this.config.debug)
|
|
466
|
-
console.log(`SSO-SDK: No user found in DB.`);
|
|
467
|
-
return;
|
|
468
|
-
}
|
|
469
|
-
const user = await this.withRefresh(async (aT) => {
|
|
423
|
+
const res = await this.withRefresh(async (aT) => {
|
|
470
424
|
return await fetch(`${this.ssoServerUrl}/clothings/${clothId}`, {
|
|
471
425
|
headers: {
|
|
472
426
|
"Content-Type": "application/json",
|
|
473
|
-
Authorization: `Bearer ${aT
|
|
427
|
+
Authorization: `Bearer ${aT}`,
|
|
474
428
|
"x-sdk-key": this.config.sdkKey,
|
|
475
429
|
},
|
|
476
430
|
});
|
|
477
431
|
});
|
|
478
|
-
if (!
|
|
432
|
+
if (!res?.ok) {
|
|
479
433
|
if (this.config.debug)
|
|
480
434
|
console.log(`SSO-SDK: Get cloth by id failed.`);
|
|
481
435
|
return;
|
|
482
436
|
}
|
|
483
|
-
const { data } = (await
|
|
437
|
+
const { data } = (await res.json());
|
|
484
438
|
this.cb({
|
|
485
439
|
type: c.actions.cloth_fetch,
|
|
486
440
|
payload: data,
|
|
@@ -493,30 +447,23 @@ export default class SSO {
|
|
|
493
447
|
console.log(`SSO-SDK: Not in browser.`);
|
|
494
448
|
return;
|
|
495
449
|
}
|
|
496
|
-
await this.
|
|
497
|
-
const dbUser = (await this.db.getById(this.dbId));
|
|
498
|
-
if (!dbUser) {
|
|
499
|
-
if (this.config.debug)
|
|
500
|
-
console.log(`SSO-SDK: No user found in DB.`);
|
|
501
|
-
return;
|
|
502
|
-
}
|
|
503
|
-
const user = await this.withRefresh(async (aT) => {
|
|
450
|
+
const res = await this.withRefresh(async (aT) => {
|
|
504
451
|
return await fetch(`${this.ssoServerUrl}/clothings/${clothId}`, {
|
|
505
452
|
method: "PATCH",
|
|
506
453
|
body: JSON.stringify(payload),
|
|
507
454
|
headers: {
|
|
508
455
|
"Content-Type": "application/json",
|
|
509
|
-
Authorization: `Bearer ${aT
|
|
456
|
+
Authorization: `Bearer ${aT}`,
|
|
510
457
|
"x-sdk-key": this.config.sdkKey,
|
|
511
458
|
},
|
|
512
459
|
});
|
|
513
460
|
});
|
|
514
|
-
if (!
|
|
461
|
+
if (!res?.ok) {
|
|
515
462
|
if (this.config.debug)
|
|
516
463
|
console.log(`SSO-SDK: Cloth update failed.`);
|
|
517
464
|
return;
|
|
518
465
|
}
|
|
519
|
-
const { data } = (await
|
|
466
|
+
const { data } = (await res.json());
|
|
520
467
|
this.cb({
|
|
521
468
|
type: c.actions.cloth_update,
|
|
522
469
|
payload: data,
|
|
@@ -536,7 +483,7 @@ export default class SSO {
|
|
|
536
483
|
console.log(`SSO-SDK: No user found in DB.`);
|
|
537
484
|
return;
|
|
538
485
|
}
|
|
539
|
-
const
|
|
486
|
+
const res = await this.withRefresh(async (aT) => {
|
|
540
487
|
return await fetch(`${this.ssoServerUrl}/clothings/${clothId}`, {
|
|
541
488
|
method: "DELETE",
|
|
542
489
|
headers: {
|
|
@@ -546,12 +493,12 @@ export default class SSO {
|
|
|
546
493
|
},
|
|
547
494
|
});
|
|
548
495
|
});
|
|
549
|
-
if (!
|
|
496
|
+
if (!res?.ok) {
|
|
550
497
|
if (this.config.debug)
|
|
551
498
|
console.log(`SSO-SDK: Cloth delete failed.`);
|
|
552
499
|
return;
|
|
553
500
|
}
|
|
554
|
-
await
|
|
501
|
+
await res.json();
|
|
555
502
|
this.cb({
|
|
556
503
|
type: c.actions.cloth_delete,
|
|
557
504
|
payload: {
|
|
@@ -577,30 +524,23 @@ export default class SSO {
|
|
|
577
524
|
...payload,
|
|
578
525
|
thumb: thumb,
|
|
579
526
|
};
|
|
580
|
-
await this.
|
|
581
|
-
const dbUser = (await this.db.getById(this.dbId));
|
|
582
|
-
if (!dbUser) {
|
|
583
|
-
if (this.config.debug)
|
|
584
|
-
console.log(`SSO-SDK: No user found in DB.`);
|
|
585
|
-
return;
|
|
586
|
-
}
|
|
587
|
-
const user = await this.withRefresh(async (aT) => {
|
|
527
|
+
const res = await this.withRefresh(async (aT) => {
|
|
588
528
|
return await fetch(`${this.ssoServerUrl}/clothings/materials`, {
|
|
589
529
|
method: "POST",
|
|
590
530
|
body: JSON.stringify(jsonPayload),
|
|
591
531
|
headers: {
|
|
592
532
|
"Content-Type": "application/json",
|
|
593
|
-
Authorization: `Bearer ${aT
|
|
533
|
+
Authorization: `Bearer ${aT}`,
|
|
594
534
|
"x-sdk-key": this.config.sdkKey,
|
|
595
535
|
},
|
|
596
536
|
});
|
|
597
537
|
});
|
|
598
|
-
if (!
|
|
538
|
+
if (!res?.ok) {
|
|
599
539
|
if (this.config.debug)
|
|
600
540
|
console.log(`SSO-SDK: Material add failed.`);
|
|
601
541
|
return;
|
|
602
542
|
}
|
|
603
|
-
const { data } = (await
|
|
543
|
+
const { data } = (await res.json());
|
|
604
544
|
this.cb({
|
|
605
545
|
type: c.actions.material_add,
|
|
606
546
|
payload: data,
|
|
@@ -613,34 +553,27 @@ export default class SSO {
|
|
|
613
553
|
console.log(`SSO-SDK: Not in browser.`);
|
|
614
554
|
return;
|
|
615
555
|
}
|
|
616
|
-
await this.db.open();
|
|
617
|
-
const dbUser = (await this.db.getById(this.dbId));
|
|
618
|
-
if (!dbUser) {
|
|
619
|
-
if (this.config.debug)
|
|
620
|
-
console.log(`SSO-SDK: No user found in DB.`);
|
|
621
|
-
return;
|
|
622
|
-
}
|
|
623
556
|
const params = new URLSearchParams({
|
|
624
557
|
skip: options?.skip?.toString() || "0",
|
|
625
558
|
limit: options?.limit?.toString() || "10",
|
|
626
559
|
sort: options?.sort || "asc",
|
|
627
560
|
});
|
|
628
|
-
const
|
|
561
|
+
const res = await this.withRefresh(async (aT) => {
|
|
629
562
|
return await fetch(`${this.ssoServerUrl}/clothings/materials?${params}`, {
|
|
630
563
|
method: "GET",
|
|
631
564
|
headers: {
|
|
632
565
|
"Content-Type": "application/json",
|
|
633
|
-
Authorization: `Bearer ${aT
|
|
566
|
+
Authorization: `Bearer ${aT}`,
|
|
634
567
|
"x-sdk-key": this.config.sdkKey,
|
|
635
568
|
},
|
|
636
569
|
});
|
|
637
570
|
});
|
|
638
|
-
if (!
|
|
571
|
+
if (!res?.ok) {
|
|
639
572
|
if (this.config.debug)
|
|
640
573
|
console.log(`SSO-SDK: Materials fetch failed.`);
|
|
641
574
|
return;
|
|
642
575
|
}
|
|
643
|
-
const { data } = (await
|
|
576
|
+
const { data } = (await res.json());
|
|
644
577
|
this.cb({
|
|
645
578
|
type: c.actions.material_fetch_all,
|
|
646
579
|
payload: data,
|
|
@@ -653,29 +586,22 @@ export default class SSO {
|
|
|
653
586
|
console.log(`SSO-SDK: Not in browser.`);
|
|
654
587
|
return;
|
|
655
588
|
}
|
|
656
|
-
await this.
|
|
657
|
-
const dbUser = (await this.db.getById(this.dbId));
|
|
658
|
-
if (!dbUser) {
|
|
659
|
-
if (this.config.debug)
|
|
660
|
-
console.log(`SSO-SDK: No user found in DB.`);
|
|
661
|
-
return;
|
|
662
|
-
}
|
|
663
|
-
const user = await this.withRefresh(async (aT) => {
|
|
589
|
+
const res = await this.withRefresh(async (aT) => {
|
|
664
590
|
return await fetch(`${this.ssoServerUrl}/clothings/materials/${materialId}`, {
|
|
665
591
|
method: "GET",
|
|
666
592
|
headers: {
|
|
667
593
|
"Content-Type": "application/json",
|
|
668
|
-
Authorization: `Bearer ${aT
|
|
594
|
+
Authorization: `Bearer ${aT}`,
|
|
669
595
|
"x-sdk-key": this.config.sdkKey,
|
|
670
596
|
},
|
|
671
597
|
});
|
|
672
598
|
});
|
|
673
|
-
if (!
|
|
599
|
+
if (!res?.ok) {
|
|
674
600
|
if (this.config.debug)
|
|
675
601
|
console.log(`SSO-SDK: Material fetch failed.`);
|
|
676
602
|
return;
|
|
677
603
|
}
|
|
678
|
-
const { data } = (await
|
|
604
|
+
const { data } = (await res.json());
|
|
679
605
|
this.cb({
|
|
680
606
|
type: c.actions.material_fetch,
|
|
681
607
|
payload: data,
|
|
@@ -688,30 +614,23 @@ export default class SSO {
|
|
|
688
614
|
console.log(`SSO-SDK: Not in browser.`);
|
|
689
615
|
return;
|
|
690
616
|
}
|
|
691
|
-
await this.
|
|
692
|
-
const dbUser = (await this.db.getById(this.dbId));
|
|
693
|
-
if (!dbUser) {
|
|
694
|
-
if (this.config.debug)
|
|
695
|
-
console.log(`SSO-SDK: No user found in DB.`);
|
|
696
|
-
return;
|
|
697
|
-
}
|
|
698
|
-
const user = await this.withRefresh(async (aT) => {
|
|
617
|
+
const res = await this.withRefresh(async (aT) => {
|
|
699
618
|
return await fetch(`${this.ssoServerUrl}/clothings/materials/${materialId}`, {
|
|
700
619
|
method: "PATCH",
|
|
701
620
|
body: JSON.stringify(payload),
|
|
702
621
|
headers: {
|
|
703
622
|
"Content-Type": "application/json",
|
|
704
|
-
Authorization: `Bearer ${aT
|
|
623
|
+
Authorization: `Bearer ${aT}`,
|
|
705
624
|
"x-sdk-key": this.config.sdkKey,
|
|
706
625
|
},
|
|
707
626
|
});
|
|
708
627
|
});
|
|
709
|
-
if (!
|
|
628
|
+
if (!res?.ok) {
|
|
710
629
|
if (this.config.debug)
|
|
711
630
|
console.log(`SSO-SDK: Material update failed.`);
|
|
712
631
|
return;
|
|
713
632
|
}
|
|
714
|
-
const { data } = (await
|
|
633
|
+
const { data } = (await res.json());
|
|
715
634
|
this.cb({
|
|
716
635
|
type: c.actions.material_update,
|
|
717
636
|
payload: data,
|
|
@@ -724,24 +643,17 @@ export default class SSO {
|
|
|
724
643
|
console.log(`SSO-SDK: Not in browser.`);
|
|
725
644
|
return;
|
|
726
645
|
}
|
|
727
|
-
await this.
|
|
728
|
-
const dbUser = (await this.db.getById(this.dbId));
|
|
729
|
-
if (!dbUser) {
|
|
730
|
-
if (this.config.debug)
|
|
731
|
-
console.log(`SSO-SDK: No user found in DB.`);
|
|
732
|
-
return;
|
|
733
|
-
}
|
|
734
|
-
const user = await this.withRefresh(async (aT) => {
|
|
646
|
+
const res = await this.withRefresh(async (aT) => {
|
|
735
647
|
return await fetch(`${this.ssoServerUrl}/clothings/materials/${materialId}`, {
|
|
736
648
|
method: "DELETE",
|
|
737
649
|
headers: {
|
|
738
650
|
"Content-Type": "application/json",
|
|
739
|
-
Authorization: `Bearer ${aT
|
|
651
|
+
Authorization: `Bearer ${aT}`,
|
|
740
652
|
"x-sdk-key": this.config.sdkKey,
|
|
741
653
|
},
|
|
742
654
|
});
|
|
743
655
|
});
|
|
744
|
-
if (!
|
|
656
|
+
if (!res?.ok) {
|
|
745
657
|
if (this.config.debug)
|
|
746
658
|
console.log(`SSO-SDK: Material delete failed.`);
|
|
747
659
|
return;
|
|
@@ -771,30 +683,23 @@ export default class SSO {
|
|
|
771
683
|
previewUrl: preview,
|
|
772
684
|
url3d: model,
|
|
773
685
|
};
|
|
774
|
-
await this.
|
|
775
|
-
const dbUser = (await this.db.getById(this.dbId));
|
|
776
|
-
if (!dbUser) {
|
|
777
|
-
if (this.config.debug)
|
|
778
|
-
console.log(`SSO-SDK: No user found in DB.`);
|
|
779
|
-
return;
|
|
780
|
-
}
|
|
781
|
-
const user = await this.withRefresh(async (aT) => {
|
|
686
|
+
const res = await this.withRefresh(async (aT) => {
|
|
782
687
|
return await fetch(`${this.ssoServerUrl}/skulls`, {
|
|
783
688
|
method: "POST",
|
|
784
689
|
body: JSON.stringify(jsonPayload),
|
|
785
690
|
headers: {
|
|
786
691
|
"Content-Type": "application/json",
|
|
787
|
-
Authorization: `Bearer ${aT
|
|
692
|
+
Authorization: `Bearer ${aT}`,
|
|
788
693
|
"x-sdk-key": this.config.sdkKey,
|
|
789
694
|
},
|
|
790
695
|
});
|
|
791
696
|
});
|
|
792
|
-
if (!
|
|
697
|
+
if (!res?.ok) {
|
|
793
698
|
if (this.config.debug)
|
|
794
699
|
console.log(`SSO-SDK: Skull add failed.`);
|
|
795
700
|
return;
|
|
796
701
|
}
|
|
797
|
-
const { data } = (await
|
|
702
|
+
const { data } = (await res.json());
|
|
798
703
|
this.cb({
|
|
799
704
|
type: c.actions.skull_add,
|
|
800
705
|
payload: data,
|
|
@@ -807,30 +712,23 @@ export default class SSO {
|
|
|
807
712
|
console.log(`SSO-SDK: Not in browser.`);
|
|
808
713
|
return;
|
|
809
714
|
}
|
|
810
|
-
await this.
|
|
811
|
-
const dbUser = (await this.db.getById(this.dbId));
|
|
812
|
-
if (!dbUser) {
|
|
813
|
-
if (this.config.debug)
|
|
814
|
-
console.log(`SSO-SDK: No user found in DB.`);
|
|
815
|
-
return;
|
|
816
|
-
}
|
|
817
|
-
const user = await this.withRefresh(async (aT) => {
|
|
715
|
+
const res = await this.withRefresh(async (aT) => {
|
|
818
716
|
return await fetch(`${this.ssoServerUrl}/skulls/${skullId}`, {
|
|
819
717
|
method: "PATCH",
|
|
820
718
|
body: JSON.stringify(payload),
|
|
821
719
|
headers: {
|
|
822
720
|
"Content-Type": "application/json",
|
|
823
|
-
Authorization: `Bearer ${aT
|
|
721
|
+
Authorization: `Bearer ${aT}`,
|
|
824
722
|
"x-sdk-key": this.config.sdkKey,
|
|
825
723
|
},
|
|
826
724
|
});
|
|
827
725
|
});
|
|
828
|
-
if (!
|
|
726
|
+
if (!res?.ok) {
|
|
829
727
|
if (this.config.debug)
|
|
830
728
|
console.log(`SSO-SDK: Skull update failed.`);
|
|
831
729
|
return;
|
|
832
730
|
}
|
|
833
|
-
const { data } = (await
|
|
731
|
+
const { data } = (await res.json());
|
|
834
732
|
this.cb({
|
|
835
733
|
type: c.actions.skull_update,
|
|
836
734
|
payload: data,
|
|
@@ -843,29 +741,22 @@ export default class SSO {
|
|
|
843
741
|
console.log(`SSO-SDK: Not in browser.`);
|
|
844
742
|
return;
|
|
845
743
|
}
|
|
846
|
-
await this.
|
|
847
|
-
const dbUser = (await this.db.getById(this.dbId));
|
|
848
|
-
if (!dbUser) {
|
|
849
|
-
if (this.config.debug)
|
|
850
|
-
console.log(`SSO-SDK: No user found in DB.`);
|
|
851
|
-
return;
|
|
852
|
-
}
|
|
853
|
-
const user = await this.withRefresh(async (aT) => {
|
|
744
|
+
const res = await this.withRefresh(async (aT) => {
|
|
854
745
|
return await fetch(`${this.ssoServerUrl}/skulls`, {
|
|
855
746
|
method: "GET",
|
|
856
747
|
headers: {
|
|
857
748
|
"Content-Type": "application/json",
|
|
858
|
-
Authorization: `Bearer ${aT
|
|
749
|
+
Authorization: `Bearer ${aT}`,
|
|
859
750
|
"x-sdk-key": this.config.sdkKey,
|
|
860
751
|
},
|
|
861
752
|
});
|
|
862
753
|
});
|
|
863
|
-
if (!
|
|
754
|
+
if (!res?.ok) {
|
|
864
755
|
if (this.config.debug)
|
|
865
756
|
console.log(`SSO-SDK: Skull get all failed.`);
|
|
866
757
|
return;
|
|
867
758
|
}
|
|
868
|
-
const { data } = (await
|
|
759
|
+
const { data } = (await res.json());
|
|
869
760
|
this.cb({
|
|
870
761
|
type: c.actions.skull_fetch_all,
|
|
871
762
|
payload: data,
|
|
@@ -878,29 +769,22 @@ export default class SSO {
|
|
|
878
769
|
console.log(`SSO-SDK: Not in browser.`);
|
|
879
770
|
return;
|
|
880
771
|
}
|
|
881
|
-
await this.
|
|
882
|
-
const dbUser = (await this.db.getById(this.dbId));
|
|
883
|
-
if (!dbUser) {
|
|
884
|
-
if (this.config.debug)
|
|
885
|
-
console.log(`SSO-SDK: No user found in DB.`);
|
|
886
|
-
return;
|
|
887
|
-
}
|
|
888
|
-
const user = await this.withRefresh(async (aT) => {
|
|
772
|
+
const res = await this.withRefresh(async (aT) => {
|
|
889
773
|
return await fetch(`${this.ssoServerUrl}/skulls/${skullId}`, {
|
|
890
774
|
method: "GET",
|
|
891
775
|
headers: {
|
|
892
776
|
"Content-Type": "application/json",
|
|
893
|
-
Authorization: `Bearer ${aT
|
|
777
|
+
Authorization: `Bearer ${aT}`,
|
|
894
778
|
"x-sdk-key": this.config.sdkKey,
|
|
895
779
|
},
|
|
896
780
|
});
|
|
897
781
|
});
|
|
898
|
-
if (!
|
|
782
|
+
if (!res?.ok) {
|
|
899
783
|
if (this.config.debug)
|
|
900
784
|
console.log(`SSO-SDK: Skull get by id failed.`);
|
|
901
785
|
return;
|
|
902
786
|
}
|
|
903
|
-
const { data } = (await
|
|
787
|
+
const { data } = (await res.json());
|
|
904
788
|
this.cb({
|
|
905
789
|
type: c.actions.skull_fetch,
|
|
906
790
|
payload: data,
|
|
@@ -913,24 +797,17 @@ export default class SSO {
|
|
|
913
797
|
console.log(`SSO-SDK: Not in browser.`);
|
|
914
798
|
return;
|
|
915
799
|
}
|
|
916
|
-
await this.
|
|
917
|
-
const dbUser = (await this.db.getById(this.dbId));
|
|
918
|
-
if (!dbUser) {
|
|
919
|
-
if (this.config.debug)
|
|
920
|
-
console.log(`SSO-SDK: No user found in DB.`);
|
|
921
|
-
return;
|
|
922
|
-
}
|
|
923
|
-
const user = await this.withRefresh(async (aT) => {
|
|
800
|
+
const res = await this.withRefresh(async (aT) => {
|
|
924
801
|
return await fetch(`${this.ssoServerUrl}/skulls/${skullId}`, {
|
|
925
802
|
method: "DELETE",
|
|
926
803
|
headers: {
|
|
927
804
|
"Content-Type": "application/json",
|
|
928
|
-
Authorization: `Bearer ${aT
|
|
805
|
+
Authorization: `Bearer ${aT}`,
|
|
929
806
|
"x-sdk-key": this.config.sdkKey,
|
|
930
807
|
},
|
|
931
808
|
});
|
|
932
809
|
});
|
|
933
|
-
if (!
|
|
810
|
+
if (!res?.ok) {
|
|
934
811
|
if (this.config.debug)
|
|
935
812
|
console.log(`SSO-SDK: Skull delete failed.`);
|
|
936
813
|
return;
|
|
@@ -943,6 +820,334 @@ export default class SSO {
|
|
|
943
820
|
});
|
|
944
821
|
return skullId;
|
|
945
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
|
+
};
|
|
946
1151
|
if (config.debug)
|
|
947
1152
|
console.log(`SSO-SDK: Debug mode enabled.`);
|
|
948
1153
|
}
|