@overmap-ai/core 1.0.60-sdk-refactor.6 → 1.0.60-sdk-refactor.8
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/overmap-core.js +20 -22
- package/dist/overmap-core.js.map +1 -1
- package/dist/overmap-core.umd.cjs +20 -22
- package/dist/overmap-core.umd.cjs.map +1 -1
- package/dist/sdk/services/BaseApiService.d.ts +3 -8
- package/dist/sdk/services/BaseAuthService.d.ts +4 -8
- package/dist/sdk/services/BaseService.d.ts +15 -0
- package/dist/sdk/services/JWTAuthService.d.ts +1 -1
- package/package.json +1 -1
package/dist/overmap-core.js
CHANGED
|
@@ -15071,11 +15071,12 @@ async function performRequest(action, client) {
|
|
|
15071
15071
|
if (!serviceOfRequest) {
|
|
15072
15072
|
throw new Error(`Service ${action.meta.offline.effect.serviceName} not found`);
|
|
15073
15073
|
}
|
|
15074
|
+
const isApiService = serviceOfRequest instanceof BaseApiService;
|
|
15074
15075
|
const state = client.store.getState();
|
|
15075
15076
|
if (state.outboxReducer.deletedRequests.includes(action.payload.uuid)) {
|
|
15076
15077
|
throw new Error("Request was marked for deletion");
|
|
15077
15078
|
}
|
|
15078
|
-
if (action.payload.checkAuth !== false) {
|
|
15079
|
+
if (isApiService && action.payload.checkAuth !== false) {
|
|
15079
15080
|
await serviceOfRequest.auth.prepareAuth();
|
|
15080
15081
|
}
|
|
15081
15082
|
const defaultSettings = {
|
|
@@ -15141,7 +15142,7 @@ async function performRequest(action, client) {
|
|
|
15141
15142
|
};
|
|
15142
15143
|
const selectedRequest = methodRequestMapping[method];
|
|
15143
15144
|
let requestToSend = selectedRequest();
|
|
15144
|
-
if (isAuthNeeded) {
|
|
15145
|
+
if (isAuthNeeded && isApiService) {
|
|
15145
15146
|
const authHeader = serviceOfRequest.auth.getAuthHeader();
|
|
15146
15147
|
requestToSend = requestToSend.set("Authorization", authHeader);
|
|
15147
15148
|
}
|
|
@@ -15153,7 +15154,7 @@ async function performRequest(action, client) {
|
|
|
15153
15154
|
} catch (error2) {
|
|
15154
15155
|
const errorResponse = extractResponseFromError(error2);
|
|
15155
15156
|
const status = errorResponse == null ? void 0 : errorResponse.status;
|
|
15156
|
-
if (status === 401) {
|
|
15157
|
+
if (isApiService && status === 401) {
|
|
15157
15158
|
await serviceOfRequest.auth.handleUnauthorized(requestToSend, errorResponse);
|
|
15158
15159
|
return requestToSend.query(queryParams);
|
|
15159
15160
|
}
|
|
@@ -15409,9 +15410,11 @@ const initSDK = (store, sdk) => {
|
|
|
15409
15410
|
setClientStore(store);
|
|
15410
15411
|
return sdkInstance;
|
|
15411
15412
|
};
|
|
15412
|
-
|
|
15413
|
+
const CLASS_NAME_TO_SERVICE$1 = {};
|
|
15414
|
+
class BaseService {
|
|
15413
15415
|
constructor(sdk) {
|
|
15414
15416
|
__publicField(this, "client");
|
|
15417
|
+
CLASS_NAME_TO_SERVICE$1[this.constructor.name] = this;
|
|
15415
15418
|
this.client = sdk;
|
|
15416
15419
|
}
|
|
15417
15420
|
async enqueueRequest(requestDetails) {
|
|
@@ -15421,6 +15424,11 @@ class BaseAuthService {
|
|
|
15421
15424
|
this.client.store.dispatch(action);
|
|
15422
15425
|
}
|
|
15423
15426
|
}
|
|
15427
|
+
class BaseAuthService extends BaseService {
|
|
15428
|
+
constructor(sdk) {
|
|
15429
|
+
super(sdk);
|
|
15430
|
+
}
|
|
15431
|
+
}
|
|
15424
15432
|
const EXPIRING_SOON_THRESHOLD = 1800;
|
|
15425
15433
|
function parseTokens(response) {
|
|
15426
15434
|
if (!response.access)
|
|
@@ -15456,14 +15464,14 @@ class JWTService extends BaseAuthService {
|
|
|
15456
15464
|
immediate: true
|
|
15457
15465
|
}).catch((e) => {
|
|
15458
15466
|
console.error("Could not renew tokens; logging out due to error:", e);
|
|
15459
|
-
|
|
15467
|
+
this.clearAuth();
|
|
15460
15468
|
return void 0;
|
|
15461
15469
|
});
|
|
15462
15470
|
let response = void 0;
|
|
15463
15471
|
try {
|
|
15464
15472
|
response = await promise;
|
|
15465
15473
|
} catch (e) {
|
|
15466
|
-
|
|
15474
|
+
this.clearAuth();
|
|
15467
15475
|
}
|
|
15468
15476
|
if (!response)
|
|
15469
15477
|
return void 0;
|
|
@@ -15477,15 +15485,13 @@ class JWTService extends BaseAuthService {
|
|
|
15477
15485
|
/**
|
|
15478
15486
|
* Logs the user out
|
|
15479
15487
|
*/
|
|
15480
|
-
|
|
15488
|
+
clearAuth() {
|
|
15481
15489
|
this.dispatch(setLoggedIn(false));
|
|
15482
15490
|
this.clearTokens();
|
|
15483
15491
|
this.dispatch(setActiveProjectId(null));
|
|
15484
15492
|
this.dispatch(setActiveWorkspaceId(null));
|
|
15485
15493
|
this.dispatch({ type: RESET_STATE });
|
|
15486
15494
|
this.dispatch({ type: resetStore });
|
|
15487
|
-
await localforage.clear();
|
|
15488
|
-
window.location.reload();
|
|
15489
15495
|
}
|
|
15490
15496
|
/**
|
|
15491
15497
|
* Attempts to renew tokens
|
|
@@ -15504,7 +15510,7 @@ class JWTService extends BaseAuthService {
|
|
|
15504
15510
|
this.setTokens(tokens);
|
|
15505
15511
|
} catch (e) {
|
|
15506
15512
|
console.error("Could not renew tokens; logging out.");
|
|
15507
|
-
|
|
15513
|
+
this.clearAuth();
|
|
15508
15514
|
throw e;
|
|
15509
15515
|
}
|
|
15510
15516
|
}
|
|
@@ -15538,7 +15544,7 @@ class JWTService extends BaseAuthService {
|
|
|
15538
15544
|
await this.renewTokens();
|
|
15539
15545
|
} catch (e) {
|
|
15540
15546
|
if (e instanceof APIError) {
|
|
15541
|
-
|
|
15547
|
+
this.clearAuth();
|
|
15542
15548
|
}
|
|
15543
15549
|
return Promise.reject(e);
|
|
15544
15550
|
}
|
|
@@ -15550,7 +15556,7 @@ class JWTService extends BaseAuthService {
|
|
|
15550
15556
|
if (state.authReducer.isLoggedIn) {
|
|
15551
15557
|
console.warn("No signed-in user to sign out.");
|
|
15552
15558
|
}
|
|
15553
|
-
|
|
15559
|
+
this.clearAuth();
|
|
15554
15560
|
throw new APIError({
|
|
15555
15561
|
message: "You have been signed out due to inactivity.",
|
|
15556
15562
|
response,
|
|
@@ -15607,20 +15613,12 @@ class JWTService extends BaseAuthService {
|
|
|
15607
15613
|
}
|
|
15608
15614
|
}
|
|
15609
15615
|
const CLASS_NAME_TO_SERVICE = {};
|
|
15610
|
-
class BaseApiService {
|
|
15616
|
+
class BaseApiService extends BaseService {
|
|
15611
15617
|
constructor(sdk, auth) {
|
|
15612
|
-
|
|
15618
|
+
super(sdk);
|
|
15613
15619
|
__publicField(this, "auth");
|
|
15614
|
-
CLASS_NAME_TO_SERVICE[this.constructor.name] = this;
|
|
15615
|
-
this.client = sdk;
|
|
15616
15620
|
this.auth = auth;
|
|
15617
15621
|
}
|
|
15618
|
-
async enqueueRequest(requestDetails) {
|
|
15619
|
-
return this.client.enqueueRequest(requestDetails, this.host, this.constructor.name);
|
|
15620
|
-
}
|
|
15621
|
-
dispatch(action) {
|
|
15622
|
-
this.client.store.dispatch(action);
|
|
15623
|
-
}
|
|
15624
15622
|
}
|
|
15625
15623
|
class CategoryService extends BaseApiService {
|
|
15626
15624
|
add(category, workspaceId) {
|