@verdocs/js-sdk 4.2.89 → 4.2.91
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 +26 -24
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +26 -24
- 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}`;
|
|
1322
|
+
if (this.persist) {
|
|
1323
|
+
localStorage.setItem(this.sessionStorageKey(), token);
|
|
1324
|
+
}
|
|
1320
1325
|
}
|
|
1321
1326
|
else {
|
|
1327
|
+
// Required for legacy calls to rForm
|
|
1322
1328
|
this.api.defaults.headers.common.signer = `Bearer ${token}`;
|
|
1329
|
+
this.api.defaults.headers.common.Authorization = `Bearer ${token}`;
|
|
1323
1330
|
}
|
|
1324
|
-
if (this.
|
|
1325
|
-
|
|
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
|
+
});
|
|
1326
1345
|
}
|
|
1327
|
-
|
|
1328
|
-
// operate within an IFRAME and multiple siblings need to operate on the same session. This happens
|
|
1329
|
-
// a lot in Storybook but may also happen in other environments as well. Rather than try to coordinate
|
|
1330
|
-
// something weird that might break (e.g. in a mobile app), we just allow the dupe calls. We generate
|
|
1331
|
-
// a unique ID for each endpoint just to help with debugging. It should not be taken as a bug if more
|
|
1332
|
-
// than one endpoint ID is seen within the app's logs.
|
|
1333
|
-
window?.console?.debug('[JS_SDK] Loading current profile...', this.endpointId, this.sub, session.sub);
|
|
1334
|
-
this.sub = session.sub;
|
|
1335
|
-
getCurrentProfile(this)
|
|
1336
|
-
.then((r) => {
|
|
1337
|
-
window?.console?.debug('[JS_SDK] Loaded profile', this.endpointId, r);
|
|
1338
|
-
this.profile = r || null;
|
|
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
|
/**
|
|
@@ -1676,7 +1678,7 @@ const startSigningSession = async (endpoint, envelope_id, role_name, key) => {
|
|
|
1676
1678
|
return endpoint.api //
|
|
1677
1679
|
.post(`/v2/sign/unauth/${envelope_id}/${encodeURIComponent(role_name)}/${key}`)
|
|
1678
1680
|
.then((r) => {
|
|
1679
|
-
endpoint.setToken(r.data.access_token);
|
|
1681
|
+
endpoint.setToken(r.data.access_token, 'signing');
|
|
1680
1682
|
return r.data;
|
|
1681
1683
|
});
|
|
1682
1684
|
};
|