@verdocs/js-sdk 5.1.3 → 5.1.5

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
@@ -1174,10 +1174,10 @@ const updateProfilePhoto = (endpoint, profileId, file, onUploadProgress) => {
1174
1174
  const ENDPOINT_KEY = Symbol.for('verdocs-default-endpoint');
1175
1175
  const BETA_ORIGINS = ['https://beta.verdocs.com', 'https://stage.verdocs.com', 'http://localhost:6006', 'http://localhost:5173'];
1176
1176
  const requestLogger = (r) => {
1177
- // tslint:disable-next-line
1178
- console.debug(`[JS-SDK] ${r.method.toUpperCase()} ${r.baseURL}${r.url}`, r.data ? JSON.stringify(r.data) : '');
1177
+ // TODO: Re-activate logging via an isomorphic approach
1179
1178
  return r;
1180
1179
  };
1180
+ const isBrowser = typeof globalThis$1.window !== 'undefined';
1181
1181
  /**
1182
1182
  * VerdocsEndpoint is a class wrapper for a specific connection and authorization context for calling the Verdocs APIs.
1183
1183
  * Endpoints can be used for isolated session tasks.
@@ -1203,7 +1203,7 @@ class VerdocsEndpoint {
1203
1203
  environment = 'verdocs';
1204
1204
  sessionType = 'user';
1205
1205
  persist = true;
1206
- baseURL = BETA_ORIGINS.includes(window?.location?.origin || '') ? 'https://stage-api.verdocs.com' : 'https://api.verdocs.com';
1206
+ baseURL = BETA_ORIGINS.includes(globalThis$1.window?.location?.origin || '') ? 'https://stage-api.verdocs.com' : 'https://api.verdocs.com';
1207
1207
  clientID = 'not-set';
1208
1208
  timeout = 60000;
1209
1209
  token = null;
@@ -1248,7 +1248,6 @@ class VerdocsEndpoint {
1248
1248
  }
1249
1249
  setDefault() {
1250
1250
  globalThis$1[ENDPOINT_KEY] = this;
1251
- window?.console?.debug('[JS_SDK] Set default endpoint', this.endpointId);
1252
1251
  }
1253
1252
  static getDefault() {
1254
1253
  if (!globalThis$1[ENDPOINT_KEY]) {
@@ -1409,23 +1408,20 @@ class VerdocsEndpoint {
1409
1408
  */
1410
1409
  setToken(token, sessionType = 'user') {
1411
1410
  if (!token) {
1412
- window?.console?.log('[JS_SDK] Clearing token');
1413
1411
  return this.clearSession();
1414
1412
  }
1415
1413
  const session = decodeAccessTokenBody(token);
1416
1414
  if (session === null || (session.exp && session.exp * 1000 < new Date().getTime())) {
1417
- window?.console?.warn('[JS_SDK] Ignoring attempt to use expired session token');
1418
1415
  return this.clearSession();
1419
1416
  }
1420
- window?.console?.log('[JS_SDK] Setting token', sessionType);
1421
1417
  this.token = token;
1422
1418
  this.session = session;
1423
1419
  this.sub = session.sub;
1424
1420
  this.sessionType = sessionType;
1425
1421
  if (this.sessionType === 'user') {
1426
1422
  this.api.defaults.headers.common.Authorization = `Bearer ${token}`;
1427
- if (this.persist) {
1428
- localStorage.setItem(this.sessionStorageKey(), token);
1423
+ if (this.persist && isBrowser) {
1424
+ globalThis$1.localStorage.setItem(this.sessionStorageKey(), token);
1429
1425
  }
1430
1426
  }
1431
1427
  else {
@@ -1435,17 +1431,14 @@ class VerdocsEndpoint {
1435
1431
  // this.api.defaults.headers.common.Authorization = `Bearer ${token}`;
1436
1432
  }
1437
1433
  if (this.sessionType === 'user') {
1438
- window?.console?.debug('[JS_SDK] Loading current profile...', this.endpointId, this.sub, session.sub);
1439
1434
  getCurrentProfile(this)
1440
1435
  .then((r) => {
1441
- window?.console?.debug('[JS_SDK] Loaded profile', this.endpointId, r);
1442
1436
  this.profile = r || null;
1443
1437
  this.notifySessionListeners();
1444
1438
  })
1445
1439
  .catch((e) => {
1446
1440
  this.profile = null;
1447
1441
  this.sub = null;
1448
- window?.console?.warn('Unable to load profile', e);
1449
1442
  // We can't clear the token verdocs-auth may be using temporarily during registration
1450
1443
  if (this.persist) {
1451
1444
  this.clearSession();
@@ -1471,7 +1464,6 @@ class VerdocsEndpoint {
1471
1464
  * Clear the active session.
1472
1465
  */
1473
1466
  clearSession() {
1474
- window?.console?.debug('[JS_SDK] Clearing session', this.endpointId);
1475
1467
  if (this.persist) {
1476
1468
  localStorage.removeItem(this.sessionStorageKey());
1477
1469
  }
@@ -1488,7 +1480,6 @@ class VerdocsEndpoint {
1488
1480
  * Clear the active signing session.
1489
1481
  */
1490
1482
  clearSignerSession() {
1491
- window?.console?.debug('[JS_SDK] Clearing signer session', this.endpointId);
1492
1483
  if (this.persist) {
1493
1484
  localStorage.removeItem(this.sessionStorageKey());
1494
1485
  }
@@ -1536,7 +1527,6 @@ class VerdocsEndpoint {
1536
1527
  }
1537
1528
  const token = localStorage.getItem(this.sessionStorageKey());
1538
1529
  if (!token) {
1539
- window?.console?.debug('[JS_SDK] No cached session found', this.endpointId);
1540
1530
  return this.clearSession();
1541
1531
  }
1542
1532
  // We sometimes get multiple loadSession calls from stacked components all needing to just ensure
@@ -3343,7 +3333,6 @@ const getTemplates = (endpoint, params) => endpoint.api //
3343
3333
  * @apiSuccess ITemplate . The requested template
3344
3334
  */
3345
3335
  const getTemplate = (endpoint, templateId) => {
3346
- window?.console?.log('[JS_SDK] Loading template', templateId);
3347
3336
  return endpoint.api //
3348
3337
  .get(`/v2/templates/${templateId}`)
3349
3338
  .then((r) => {