@verdocs/js-sdk 4.2.89 → 4.2.90
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/index.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +24 -22
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +24 -22
- package/dist/index.mjs.map +1 -1
- package/dist/package.json +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -1302,48 +1302,50 @@ class VerdocsEndpoint {
|
|
|
1302
1302
|
* endpoint.setToken(accessToken);
|
|
1303
1303
|
* ```
|
|
1304
1304
|
*/
|
|
1305
|
-
setToken(token) {
|
|
1305
|
+
setToken(token, sessionType = 'user') {
|
|
1306
1306
|
if (!token) {
|
|
1307
1307
|
window.console.log('[JS_SDK] Clearing token');
|
|
1308
1308
|
return this.clearSession();
|
|
1309
1309
|
}
|
|
1310
|
-
window.console.log('[JS_SDK] Setting token', token.length);
|
|
1311
1310
|
const session = decodeAccessTokenBody(token);
|
|
1312
1311
|
if (session === null || (session.exp && session.exp * 1000 < new Date().getTime())) {
|
|
1313
1312
|
window.console.warn('[JS_SDK] Ignoring attempt to use expired session token');
|
|
1314
1313
|
return this.clearSession();
|
|
1315
1314
|
}
|
|
1315
|
+
window.console.log('[JS_SDK] Setting token', sessionType);
|
|
1316
1316
|
this.token = token;
|
|
1317
1317
|
this.session = session;
|
|
1318
|
+
this.sub = session.sub;
|
|
1319
|
+
this.sessionType = sessionType;
|
|
1318
1320
|
if (this.sessionType === 'user') {
|
|
1319
1321
|
this.api.defaults.headers.common.Authorization = `Bearer ${token}`;
|
|
1320
1322
|
}
|
|
1321
1323
|
else {
|
|
1324
|
+
// Required for legacy calls to rForm
|
|
1322
1325
|
this.api.defaults.headers.common.signer = `Bearer ${token}`;
|
|
1326
|
+
this.api.defaults.headers.common.Authorization = `Bearer ${token}`;
|
|
1323
1327
|
}
|
|
1324
|
-
if (this.persist) {
|
|
1328
|
+
if (this.persist && sessionType === 'user') {
|
|
1325
1329
|
localStorage.setItem(this.sessionStorageKey(), token);
|
|
1326
1330
|
}
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1331
|
+
if (this.sessionType === 'user') {
|
|
1332
|
+
window?.console?.debug('[JS_SDK] Loading current profile...', this.endpointId, this.sub, session.sub);
|
|
1333
|
+
getCurrentProfile(this)
|
|
1334
|
+
.then((r) => {
|
|
1335
|
+
window?.console?.debug('[JS_SDK] Loaded profile', this.endpointId, r);
|
|
1336
|
+
this.profile = r || null;
|
|
1337
|
+
this.notifySessionListeners();
|
|
1338
|
+
})
|
|
1339
|
+
.catch((e) => {
|
|
1340
|
+
this.profile = null;
|
|
1341
|
+
this.sub = null;
|
|
1342
|
+
window?.console?.warn('Unable to load profile', e);
|
|
1343
|
+
this.clearSession();
|
|
1344
|
+
});
|
|
1345
|
+
}
|
|
1346
|
+
else {
|
|
1339
1347
|
this.notifySessionListeners();
|
|
1340
|
-
}
|
|
1341
|
-
.catch((e) => {
|
|
1342
|
-
this.profile = null;
|
|
1343
|
-
this.sub = null;
|
|
1344
|
-
window?.console?.warn('Unable to load profile', e);
|
|
1345
|
-
this.clearSession();
|
|
1346
|
-
});
|
|
1348
|
+
}
|
|
1347
1349
|
return this;
|
|
1348
1350
|
}
|
|
1349
1351
|
/**
|