@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.d.mts
CHANGED
|
@@ -1099,7 +1099,7 @@ declare class VerdocsEndpoint {
|
|
|
1099
1099
|
* endpoint.setToken(accessToken);
|
|
1100
1100
|
* ```
|
|
1101
1101
|
*/
|
|
1102
|
-
setToken(token: string | null): VerdocsEndpoint;
|
|
1102
|
+
setToken(token: string | null, sessionType?: TSessionType): VerdocsEndpoint;
|
|
1103
1103
|
/**
|
|
1104
1104
|
* Retrieves the current session token, if any. Tokens should rarely be used for direct actions, but this is
|
|
1105
1105
|
* required by the `<VerdocsView>` and other components to authorize requests to raw PDF files.
|
package/dist/index.d.ts
CHANGED
|
@@ -1099,7 +1099,7 @@ declare class VerdocsEndpoint {
|
|
|
1099
1099
|
* endpoint.setToken(accessToken);
|
|
1100
1100
|
* ```
|
|
1101
1101
|
*/
|
|
1102
|
-
setToken(token: string | null): VerdocsEndpoint;
|
|
1102
|
+
setToken(token: string | null, sessionType?: TSessionType): VerdocsEndpoint;
|
|
1103
1103
|
/**
|
|
1104
1104
|
* Retrieves the current session token, if any. Tokens should rarely be used for direct actions, but this is
|
|
1105
1105
|
* required by the `<VerdocsView>` and other components to authorize requests to raw PDF files.
|
package/dist/index.js
CHANGED
|
@@ -1304,48 +1304,50 @@ class VerdocsEndpoint {
|
|
|
1304
1304
|
* endpoint.setToken(accessToken);
|
|
1305
1305
|
* ```
|
|
1306
1306
|
*/
|
|
1307
|
-
setToken(token) {
|
|
1307
|
+
setToken(token, sessionType = 'user') {
|
|
1308
1308
|
if (!token) {
|
|
1309
1309
|
window.console.log('[JS_SDK] Clearing token');
|
|
1310
1310
|
return this.clearSession();
|
|
1311
1311
|
}
|
|
1312
|
-
window.console.log('[JS_SDK] Setting token', token.length);
|
|
1313
1312
|
const session = decodeAccessTokenBody(token);
|
|
1314
1313
|
if (session === null || (session.exp && session.exp * 1000 < new Date().getTime())) {
|
|
1315
1314
|
window.console.warn('[JS_SDK] Ignoring attempt to use expired session token');
|
|
1316
1315
|
return this.clearSession();
|
|
1317
1316
|
}
|
|
1317
|
+
window.console.log('[JS_SDK] Setting token', sessionType);
|
|
1318
1318
|
this.token = token;
|
|
1319
1319
|
this.session = session;
|
|
1320
|
+
this.sub = session.sub;
|
|
1321
|
+
this.sessionType = sessionType;
|
|
1320
1322
|
if (this.sessionType === 'user') {
|
|
1321
1323
|
this.api.defaults.headers.common.Authorization = `Bearer ${token}`;
|
|
1324
|
+
if (this.persist) {
|
|
1325
|
+
localStorage.setItem(this.sessionStorageKey(), token);
|
|
1326
|
+
}
|
|
1322
1327
|
}
|
|
1323
1328
|
else {
|
|
1329
|
+
// Required for legacy calls to rForm
|
|
1324
1330
|
this.api.defaults.headers.common.signer = `Bearer ${token}`;
|
|
1331
|
+
this.api.defaults.headers.common.Authorization = `Bearer ${token}`;
|
|
1325
1332
|
}
|
|
1326
|
-
if (this.
|
|
1327
|
-
|
|
1333
|
+
if (this.sessionType === 'user') {
|
|
1334
|
+
window?.console?.debug('[JS_SDK] Loading current profile...', this.endpointId, 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;
|
|
1339
|
+
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
|
+
});
|
|
1328
1347
|
}
|
|
1329
|
-
|
|
1330
|
-
// operate within an IFRAME and multiple siblings need to operate on the same session. This happens
|
|
1331
|
-
// a lot in Storybook but may also happen in other environments as well. Rather than try to coordinate
|
|
1332
|
-
// something weird that might break (e.g. in a mobile app), we just allow the dupe calls. We generate
|
|
1333
|
-
// a unique ID for each endpoint just to help with debugging. It should not be taken as a bug if more
|
|
1334
|
-
// than one endpoint ID is seen within the app's logs.
|
|
1335
|
-
window?.console?.debug('[JS_SDK] Loading current profile...', this.endpointId, this.sub, session.sub);
|
|
1336
|
-
this.sub = session.sub;
|
|
1337
|
-
getCurrentProfile(this)
|
|
1338
|
-
.then((r) => {
|
|
1339
|
-
window?.console?.debug('[JS_SDK] Loaded profile', this.endpointId, r);
|
|
1340
|
-
this.profile = r || null;
|
|
1348
|
+
else {
|
|
1341
1349
|
this.notifySessionListeners();
|
|
1342
|
-
}
|
|
1343
|
-
.catch((e) => {
|
|
1344
|
-
this.profile = null;
|
|
1345
|
-
this.sub = null;
|
|
1346
|
-
window?.console?.warn('Unable to load profile', e);
|
|
1347
|
-
this.clearSession();
|
|
1348
|
-
});
|
|
1350
|
+
}
|
|
1349
1351
|
return this;
|
|
1350
1352
|
}
|
|
1351
1353
|
/**
|
|
@@ -1678,7 +1680,7 @@ const startSigningSession = async (endpoint, envelope_id, role_name, key) => {
|
|
|
1678
1680
|
return endpoint.api //
|
|
1679
1681
|
.post(`/v2/sign/unauth/${envelope_id}/${encodeURIComponent(role_name)}/${key}`)
|
|
1680
1682
|
.then((r) => {
|
|
1681
|
-
endpoint.setToken(r.data.access_token);
|
|
1683
|
+
endpoint.setToken(r.data.access_token, 'signing');
|
|
1682
1684
|
return r.data;
|
|
1683
1685
|
});
|
|
1684
1686
|
};
|