@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.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
- // NOTE: We don't attempt to de-dupe session/network operations because there are cases where we
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;
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
  /**