@overmap-ai/core 1.0.60-sdk-refactor.3 → 1.0.60-sdk-refactor.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/overmap-core.js +126 -210
- package/dist/overmap-core.js.map +1 -1
- package/dist/overmap-core.umd.cjs +127 -211
- package/dist/overmap-core.umd.cjs.map +1 -1
- package/dist/sdk/base.d.ts +2 -13
- package/dist/sdk/sdk.d.ts +2 -1
- package/dist/sdk/services/BaseApiService.d.ts +4 -6
- package/dist/sdk/services/BaseAuthService.d.ts +16 -0
- package/dist/sdk/services/EmailVerificationService.d.ts +2 -1
- package/dist/sdk/services/JWTAuthService.d.ts +45 -0
- package/dist/sdk/services/index.d.ts +1 -1
- package/dist/sdk/typings.d.ts +1 -0
- package/dist/store/slices/index.d.ts +1 -0
- package/dist/store/slices/outboxSlice.d.ts +3 -1
- package/dist/store/store.d.ts +2 -3
- package/package.json +1 -1
- package/dist/sdk/services/AuthService.d.ts +0 -54
|
@@ -5,8 +5,8 @@ var __publicField = (obj, key, value) => {
|
|
|
5
5
|
return value;
|
|
6
6
|
};
|
|
7
7
|
(function(global, factory) {
|
|
8
|
-
typeof exports === "object" && typeof module !== "undefined" ? factory(exports, require("react/jsx-runtime"), require("react"), require("@overmap-ai/blocks"), require("file-saver"), require("formik"), require("react-dom"), require("react-icons/ri"), require("lodash.get"), require("linkify-react"), require("uuid"), require("color"), require("@hello-pangea/dnd"), require("qr-scanner"), require("xlsx"), require("react-pdf"), require("react-pdf/dist/Page/AnnotationLayer.css"), require("react-pdf/dist/Page/TextLayer.css"), require("react-sketch-canvas"), require("lodash.set"), require("lodash.clonedeep"), require("dependency-graph"), require("@redux-offline/redux-offline"), require("@redux-offline/redux-offline/lib/defaults"), require("localforage"), require("redux-persist-migrate"), require("@reduxjs/toolkit"), require("superagent"), require("react-redux"), require("
|
|
9
|
-
})(this, function(exports2, jsxRuntime, React, blocks, saveAs, formik, ReactDOM, ri, get, Linkify, uuid, ColorCls, dnd, QrScannerAPI, xlsx, reactPdf, AnnotationLayer_css, TextLayer_css, reactSketchCanvas, set, cloneDeep, dependencyGraph, reduxOffline, offlineConfig, localforage, createMigration, toolkit, request, reactRedux,
|
|
8
|
+
typeof exports === "object" && typeof module !== "undefined" ? factory(exports, require("react/jsx-runtime"), require("react"), require("@overmap-ai/blocks"), require("file-saver"), require("formik"), require("react-dom"), require("react-icons/ri"), require("lodash.get"), require("linkify-react"), require("uuid"), require("color"), require("@hello-pangea/dnd"), require("qr-scanner"), require("xlsx"), require("react-pdf"), require("react-pdf/dist/Page/AnnotationLayer.css"), require("react-pdf/dist/Page/TextLayer.css"), require("react-sketch-canvas"), require("lodash.set"), require("lodash.clonedeep"), require("dependency-graph"), require("@redux-offline/redux-offline"), require("@redux-offline/redux-offline/lib/defaults"), require("localforage"), require("redux-persist-migrate"), require("@reduxjs/toolkit"), require("superagent"), require("react-redux"), require("@redux-offline/redux-offline/lib/constants"), require("jwt-decode"), require("idb")) : typeof define === "function" && define.amd ? define(["exports", "react/jsx-runtime", "react", "@overmap-ai/blocks", "file-saver", "formik", "react-dom", "react-icons/ri", "lodash.get", "linkify-react", "uuid", "color", "@hello-pangea/dnd", "qr-scanner", "xlsx", "react-pdf", "react-pdf/dist/Page/AnnotationLayer.css", "react-pdf/dist/Page/TextLayer.css", "react-sketch-canvas", "lodash.set", "lodash.clonedeep", "dependency-graph", "@redux-offline/redux-offline", "@redux-offline/redux-offline/lib/defaults", "localforage", "redux-persist-migrate", "@reduxjs/toolkit", "superagent", "react-redux", "@redux-offline/redux-offline/lib/constants", "jwt-decode", "idb"], factory) : (global = typeof globalThis !== "undefined" ? globalThis : global || self, factory(global["overmap-core"] = {}, global.jsxRuntime, global.React, global.blocks, global.saveAs, global.formik, global.ReactDOM, global.ri, global.get, global.Linkify, global.uuid, global.ColorCls, global.dnd, global.QrScannerAPI, global.xlsx, global.reactPdf, null, null, global.reactSketchCanvas, global.set, global.cloneDeep, global.dependencyGraph, global.reduxOffline, global.offlineConfig, global.localforage, global.createMigration, global.toolkit, global.request, global.reactRedux, global.constants, global.jwtDecode, global.idb));
|
|
9
|
+
})(this, function(exports2, jsxRuntime, React, blocks, saveAs, formik, ReactDOM, ri, get, Linkify, uuid, ColorCls, dnd, QrScannerAPI, xlsx, reactPdf, AnnotationLayer_css, TextLayer_css, reactSketchCanvas, set, cloneDeep, dependencyGraph, reduxOffline, offlineConfig, localforage, createMigration, toolkit, request, reactRedux, constants, jwtDecode, idb) {
|
|
10
10
|
var _a;
|
|
11
11
|
"use strict";
|
|
12
12
|
function _interopNamespaceDefault(e) {
|
|
@@ -13699,7 +13699,7 @@ Defaulting to \`${$89eedd556c436f6a$var$DEFAULT_ORIENTATION}\`.`;
|
|
|
13699
13699
|
return state.organizationReducer.organizations[id];
|
|
13700
13700
|
};
|
|
13701
13701
|
const organizationReducer = organizationSlice.reducer;
|
|
13702
|
-
const createOfflineAction = (request2, baseUrl) => {
|
|
13702
|
+
const createOfflineAction = (request2, baseUrl, serviceName) => {
|
|
13703
13703
|
const requestWithUuid = request2.uuid ? request2 : { ...request2, uuid: uuid.v4() };
|
|
13704
13704
|
return {
|
|
13705
13705
|
payload: requestWithUuid,
|
|
@@ -13709,7 +13709,8 @@ Defaulting to \`${$89eedd556c436f6a$var$DEFAULT_ORIENTATION}\`.`;
|
|
|
13709
13709
|
effect: {
|
|
13710
13710
|
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
13711
13711
|
request: requestWithUuid,
|
|
13712
|
-
BASE_URL: baseUrl
|
|
13712
|
+
BASE_URL: baseUrl,
|
|
13713
|
+
serviceName
|
|
13713
13714
|
}
|
|
13714
13715
|
}
|
|
13715
13716
|
}
|
|
@@ -13733,8 +13734,8 @@ Defaulting to \`${$89eedd556c436f6a$var$DEFAULT_ORIENTATION}\`.`;
|
|
|
13733
13734
|
},
|
|
13734
13735
|
prepare: (payload) => {
|
|
13735
13736
|
console.debug("Preparing to enqueue request", payload);
|
|
13736
|
-
const { BASE_URL, ...rest } = payload;
|
|
13737
|
-
return createOfflineAction(rest, BASE_URL);
|
|
13737
|
+
const { BASE_URL, serviceName, ...rest } = payload;
|
|
13738
|
+
return createOfflineAction(rest, BASE_URL, serviceName);
|
|
13738
13739
|
}
|
|
13739
13740
|
},
|
|
13740
13741
|
markForDeletion(state, action) {
|
|
@@ -15055,24 +15056,16 @@ Defaulting to \`${$89eedd556c436f6a$var$DEFAULT_ORIENTATION}\`.`;
|
|
|
15055
15056
|
return void 0;
|
|
15056
15057
|
}
|
|
15057
15058
|
async function performRequest(action, client) {
|
|
15058
|
-
|
|
15059
|
-
|
|
15060
|
-
|
|
15061
|
-
}
|
|
15059
|
+
const serviceOfRequest = CLASS_NAME_TO_SERVICE[action.meta.offline.effect.serviceName];
|
|
15060
|
+
if (!serviceOfRequest) {
|
|
15061
|
+
throw new Error(`Service ${action.meta.offline.effect.serviceName} not found`);
|
|
15062
15062
|
}
|
|
15063
15063
|
const state = client.store.getState();
|
|
15064
15064
|
if (state.outboxReducer.deletedRequests.includes(action.payload.uuid)) {
|
|
15065
15065
|
throw new Error("Request was marked for deletion");
|
|
15066
15066
|
}
|
|
15067
15067
|
if (action.payload.checkAuth !== false) {
|
|
15068
|
-
|
|
15069
|
-
await checkToken();
|
|
15070
|
-
} catch (e) {
|
|
15071
|
-
if (e instanceof APIError) {
|
|
15072
|
-
await client.auth.logout();
|
|
15073
|
-
return Promise.reject(e);
|
|
15074
|
-
}
|
|
15075
|
-
}
|
|
15068
|
+
await serviceOfRequest.auth.prepareAuth();
|
|
15076
15069
|
}
|
|
15077
15070
|
const defaultSettings = {
|
|
15078
15071
|
queryParams: "",
|
|
@@ -15086,7 +15079,6 @@ Defaulting to \`${$89eedd556c436f6a$var$DEFAULT_ORIENTATION}\`.`;
|
|
|
15086
15079
|
const requestDetails = offlineEffect.request;
|
|
15087
15080
|
let url = requestDetails.url;
|
|
15088
15081
|
const file = attachmentHash ? await client.files.fetchCache(attachmentHash) : void 0;
|
|
15089
|
-
const accessToken = selectAccessToken(state);
|
|
15090
15082
|
if (attachmentHash && !file) {
|
|
15091
15083
|
throw new Error(`Cannot upload file ${attachmentHash} because it's not cached.`);
|
|
15092
15084
|
}
|
|
@@ -15139,7 +15131,8 @@ Defaulting to \`${$89eedd556c436f6a$var$DEFAULT_ORIENTATION}\`.`;
|
|
|
15139
15131
|
const selectedRequest = methodRequestMapping[method];
|
|
15140
15132
|
let requestToSend = selectedRequest();
|
|
15141
15133
|
if (isAuthNeeded) {
|
|
15142
|
-
|
|
15134
|
+
const authHeader = serviceOfRequest.auth.getAuthHeader();
|
|
15135
|
+
requestToSend = requestToSend.set("Authorization", authHeader);
|
|
15143
15136
|
}
|
|
15144
15137
|
if (headers) {
|
|
15145
15138
|
requestToSend = requestToSend.set(headers);
|
|
@@ -15150,32 +15143,8 @@ Defaulting to \`${$89eedd556c436f6a$var$DEFAULT_ORIENTATION}\`.`;
|
|
|
15150
15143
|
const errorResponse = extractResponseFromError(error2);
|
|
15151
15144
|
const status = errorResponse == null ? void 0 : errorResponse.status;
|
|
15152
15145
|
if (status === 401) {
|
|
15153
|
-
|
|
15154
|
-
|
|
15155
|
-
console.warn("No signed-in user to sign out.");
|
|
15156
|
-
}
|
|
15157
|
-
await client.auth.logout();
|
|
15158
|
-
throw new APIError({
|
|
15159
|
-
message: "You have been signed out due to inactivity.",
|
|
15160
|
-
response: errorResponse,
|
|
15161
|
-
discard: true,
|
|
15162
|
-
innerError: error2
|
|
15163
|
-
});
|
|
15164
|
-
}
|
|
15165
|
-
if (state.authReducer.isLoggedIn) {
|
|
15166
|
-
console.debug("Forbidden; renewing tokens and retrying.");
|
|
15167
|
-
await client.auth.renewTokens();
|
|
15168
|
-
console.debug("Successfully renewed tokens; retrying request.");
|
|
15169
|
-
return requestToSend.query(queryParams);
|
|
15170
|
-
} else {
|
|
15171
|
-
console.debug("Forbidden; user is not logged in.");
|
|
15172
|
-
throw new APIError({
|
|
15173
|
-
message: "Incorrect username or password.",
|
|
15174
|
-
response: errorResponse,
|
|
15175
|
-
discard: true,
|
|
15176
|
-
innerError: error2
|
|
15177
|
-
});
|
|
15178
|
-
}
|
|
15146
|
+
await serviceOfRequest.auth.handleUnauthorized(requestToSend, errorResponse);
|
|
15147
|
+
return requestToSend.query(queryParams);
|
|
15179
15148
|
}
|
|
15180
15149
|
throw new APIError({ response: errorResponse, innerError: error2, discard: discardStatuses.includes(status) });
|
|
15181
15150
|
}
|
|
@@ -15348,27 +15317,17 @@ Defaulting to \`${$89eedd556c436f6a$var$DEFAULT_ORIENTATION}\`.`;
|
|
|
15348
15317
|
__publicField(this, "store");
|
|
15349
15318
|
this.store = store;
|
|
15350
15319
|
}
|
|
15351
|
-
|
|
15352
|
-
|
|
15353
|
-
* @param requestDetails An SDKRequest object containing the details of the request.
|
|
15354
|
-
* @param host The base URL of the API to send the request to.
|
|
15355
|
-
* @protected
|
|
15356
|
-
*/
|
|
15357
|
-
async enqueueRequest(requestDetails, host) {
|
|
15358
|
-
return this._enqueueRequest(requestDetails, host).then((result) => {
|
|
15320
|
+
async enqueueRequest(requestDetails, host, serviceName) {
|
|
15321
|
+
return this._enqueueRequest(requestDetails, host, serviceName).then((result) => {
|
|
15359
15322
|
if (result instanceof APIError) {
|
|
15360
15323
|
throw result;
|
|
15361
15324
|
}
|
|
15362
15325
|
return result;
|
|
15363
15326
|
});
|
|
15364
15327
|
}
|
|
15365
|
-
|
|
15366
|
-
* Enqueues an API request to the Redux Offline outbox
|
|
15367
|
-
* @protected
|
|
15368
|
-
*/
|
|
15369
|
-
_enqueueRequest(requestDetails, host) {
|
|
15328
|
+
_enqueueRequest(requestDetails, host, serviceName) {
|
|
15370
15329
|
const promise = new DeferredPromise();
|
|
15371
|
-
const requestDetailsWithBaseUrl = { ...requestDetails, BASE_URL: host };
|
|
15330
|
+
const requestDetailsWithBaseUrl = { ...requestDetails, BASE_URL: host, serviceName };
|
|
15372
15331
|
if (requestDetails.immediate) {
|
|
15373
15332
|
const requestWithUuid = {
|
|
15374
15333
|
...requestDetailsWithBaseUrl,
|
|
@@ -15382,7 +15341,8 @@ Defaulting to \`${$89eedd556c436f6a$var$DEFAULT_ORIENTATION}\`.`;
|
|
|
15382
15341
|
effect: {
|
|
15383
15342
|
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
15384
15343
|
request: requestWithUuid,
|
|
15385
|
-
BASE_URL: host
|
|
15344
|
+
BASE_URL: host,
|
|
15345
|
+
serviceName
|
|
15386
15346
|
}
|
|
15387
15347
|
}
|
|
15388
15348
|
}
|
|
@@ -15438,18 +15398,13 @@ Defaulting to \`${$89eedd556c436f6a$var$DEFAULT_ORIENTATION}\`.`;
|
|
|
15438
15398
|
setClientStore(store);
|
|
15439
15399
|
return sdkInstance;
|
|
15440
15400
|
};
|
|
15441
|
-
class
|
|
15401
|
+
class BaseAuthService {
|
|
15442
15402
|
constructor(sdk) {
|
|
15443
15403
|
__publicField(this, "client");
|
|
15444
15404
|
this.client = sdk;
|
|
15445
15405
|
}
|
|
15446
|
-
/**
|
|
15447
|
-
* Enqueues an API request to the offline outbox.
|
|
15448
|
-
* @param requestDetails An SDKRequest object containing the details of the request.
|
|
15449
|
-
* @protected
|
|
15450
|
-
*/
|
|
15451
15406
|
async enqueueRequest(requestDetails) {
|
|
15452
|
-
return this.client.enqueueRequest(requestDetails, this.host);
|
|
15407
|
+
return this.client.enqueueRequest(requestDetails, this.host, this.constructor.name);
|
|
15453
15408
|
}
|
|
15454
15409
|
dispatch(action) {
|
|
15455
15410
|
this.client.store.dispatch(action);
|
|
@@ -15463,42 +15418,12 @@ Defaulting to \`${$89eedd556c436f6a$var$DEFAULT_ORIENTATION}\`.`;
|
|
|
15463
15418
|
throw new Error("Missing refresh token");
|
|
15464
15419
|
return { accessToken: response.access, refreshToken: response.refresh };
|
|
15465
15420
|
}
|
|
15466
|
-
class
|
|
15421
|
+
class JWTService extends BaseAuthService {
|
|
15467
15422
|
constructor() {
|
|
15468
15423
|
super(...arguments);
|
|
15469
|
-
__publicField(this, "_getAccessToken", () => this.client.store.getState().authReducer.accessToken);
|
|
15470
|
-
__publicField(this, "_getRefreshToken", () => this.client.store.getState().authReducer.refreshToken);
|
|
15471
15424
|
// _getTokenPair and _getRenewedTokens don't need to use enqueueRequest from the BaseApiService because
|
|
15472
15425
|
// they are very simple. However, if we need robust error handling or want these operations to queue in the Outbox,
|
|
15473
15426
|
// we will use enqueueRequest.
|
|
15474
|
-
/**
|
|
15475
|
-
* Takes credentials and gets a token pair
|
|
15476
|
-
* @async
|
|
15477
|
-
* @param credentials The username and password for obtaining a token pair
|
|
15478
|
-
* @param logoutOnFailure Whether to log out if the request fails
|
|
15479
|
-
* @returns An array containing two elements: 1) a Promise for the access and refresh tokens, and 2) the UUID of the
|
|
15480
|
-
* request, so the request can be cancelled if necessary.
|
|
15481
|
-
*/
|
|
15482
|
-
__publicField(this, "_getTokenPair", (credentials, logoutOnFailure = true) => {
|
|
15483
|
-
const uuid$1 = uuid.v4();
|
|
15484
|
-
const responsePromise = this.enqueueRequest({
|
|
15485
|
-
uuid: uuid$1,
|
|
15486
|
-
description: "Get token pair",
|
|
15487
|
-
method: HttpMethod.POST,
|
|
15488
|
-
url: "/api/token/",
|
|
15489
|
-
payload: credentials,
|
|
15490
|
-
isAuthNeeded: false,
|
|
15491
|
-
checkAuth: false,
|
|
15492
|
-
blockers: [],
|
|
15493
|
-
blocks: []
|
|
15494
|
-
}).then(parseTokens).catch((e) => {
|
|
15495
|
-
if (logoutOnFailure) {
|
|
15496
|
-
void this.logout().then();
|
|
15497
|
-
}
|
|
15498
|
-
throw e;
|
|
15499
|
-
});
|
|
15500
|
-
return [responsePromise, uuid$1];
|
|
15501
|
-
});
|
|
15502
15427
|
/**
|
|
15503
15428
|
* Takes refresh token and gets a new token pair
|
|
15504
15429
|
* @async
|
|
@@ -15509,7 +15434,7 @@ Defaulting to \`${$89eedd556c436f6a$var$DEFAULT_ORIENTATION}\`.`;
|
|
|
15509
15434
|
const promise = this.enqueueRequest({
|
|
15510
15435
|
description: "Get renewed tokens",
|
|
15511
15436
|
method: HttpMethod.POST,
|
|
15512
|
-
url:
|
|
15437
|
+
url: this.refreshTokensUrl,
|
|
15513
15438
|
payload: { refresh: refreshToken },
|
|
15514
15439
|
isAuthNeeded: false,
|
|
15515
15440
|
blockers: [],
|
|
@@ -15520,14 +15445,14 @@ Defaulting to \`${$89eedd556c436f6a$var$DEFAULT_ORIENTATION}\`.`;
|
|
|
15520
15445
|
immediate: true
|
|
15521
15446
|
}).catch((e) => {
|
|
15522
15447
|
console.error("Could not renew tokens; logging out due to error:", e);
|
|
15523
|
-
void this.
|
|
15448
|
+
void this.clearAuth();
|
|
15524
15449
|
return void 0;
|
|
15525
15450
|
});
|
|
15526
15451
|
let response = void 0;
|
|
15527
15452
|
try {
|
|
15528
15453
|
response = await promise;
|
|
15529
15454
|
} catch (e) {
|
|
15530
|
-
await this.
|
|
15455
|
+
await this.clearAuth();
|
|
15531
15456
|
}
|
|
15532
15457
|
if (!response)
|
|
15533
15458
|
return void 0;
|
|
@@ -15538,40 +15463,12 @@ Defaulting to \`${$89eedd556c436f6a$var$DEFAULT_ORIENTATION}\`.`;
|
|
|
15538
15463
|
return { accessToken: response.access, refreshToken: response.refresh };
|
|
15539
15464
|
});
|
|
15540
15465
|
}
|
|
15541
|
-
/**
|
|
15542
|
-
* Attempts to log into Hemora using given credentials
|
|
15543
|
-
* @param {string} username
|
|
15544
|
-
* @param {string} password
|
|
15545
|
-
*/
|
|
15546
|
-
async login(username, password) {
|
|
15547
|
-
const [promise, uuid$1] = this._getTokenPair({ username, password }, false);
|
|
15548
|
-
const initialDataUuid = uuid.v4();
|
|
15549
|
-
const timeout = 5;
|
|
15550
|
-
let timedOut = false;
|
|
15551
|
-
const timeoutPromise = new Promise((_, reject) => {
|
|
15552
|
-
setTimeout(() => {
|
|
15553
|
-
timedOut = true;
|
|
15554
|
-
this.dispatch(markForDeletion(uuid$1));
|
|
15555
|
-
this.dispatch(markForDeletion(initialDataUuid));
|
|
15556
|
-
reject(new APIError({ message: `Request timed out after ${timeout} seconds` }));
|
|
15557
|
-
}, timeout * 1e3);
|
|
15558
|
-
});
|
|
15559
|
-
const successPromise = promise.then((tokens) => {
|
|
15560
|
-
if (timedOut) {
|
|
15561
|
-
return void 0;
|
|
15562
|
-
}
|
|
15563
|
-
this.dispatch(setTokens(tokens));
|
|
15564
|
-
this.dispatch(setLoggedIn(true));
|
|
15565
|
-
this.dispatch({ type: "rehydrated/setRehydrated", payload: true });
|
|
15566
|
-
});
|
|
15567
|
-
return Promise.race([timeoutPromise, successPromise]);
|
|
15568
|
-
}
|
|
15569
15466
|
/**
|
|
15570
15467
|
* Logs the user out
|
|
15571
15468
|
*/
|
|
15572
|
-
async
|
|
15469
|
+
async clearAuth() {
|
|
15573
15470
|
this.dispatch(setLoggedIn(false));
|
|
15574
|
-
this.
|
|
15471
|
+
this.clearTokens();
|
|
15575
15472
|
this.dispatch(setActiveProjectId(null));
|
|
15576
15473
|
this.dispatch(setActiveWorkspaceId(null));
|
|
15577
15474
|
this.dispatch({ type: constants.RESET_STATE });
|
|
@@ -15583,7 +15480,7 @@ Defaulting to \`${$89eedd556c436f6a$var$DEFAULT_ORIENTATION}\`.`;
|
|
|
15583
15480
|
* Attempts to renew tokens
|
|
15584
15481
|
*/
|
|
15585
15482
|
async renewTokens() {
|
|
15586
|
-
const dyingRefreshToken = this.
|
|
15483
|
+
const dyingRefreshToken = this.getRefreshToken();
|
|
15587
15484
|
if (!dyingRefreshToken) {
|
|
15588
15485
|
throw new Error("No refresh token found");
|
|
15589
15486
|
}
|
|
@@ -15592,48 +15489,20 @@ Defaulting to \`${$89eedd556c436f6a$var$DEFAULT_ORIENTATION}\`.`;
|
|
|
15592
15489
|
if (!tokens) {
|
|
15593
15490
|
return void 0;
|
|
15594
15491
|
}
|
|
15595
|
-
const { accessToken, refreshToken } = tokens;
|
|
15596
15492
|
console.log("Got renewed tokens");
|
|
15597
|
-
this.
|
|
15493
|
+
this.setTokens(tokens);
|
|
15598
15494
|
} catch (e) {
|
|
15599
15495
|
console.error("Could not renew tokens; logging out.");
|
|
15600
|
-
await this.
|
|
15496
|
+
await this.clearAuth();
|
|
15601
15497
|
throw e;
|
|
15602
15498
|
}
|
|
15603
15499
|
}
|
|
15604
|
-
/**
|
|
15605
|
-
* Register a new user
|
|
15606
|
-
*/
|
|
15607
|
-
register(payload) {
|
|
15608
|
-
return this.enqueueRequest({
|
|
15609
|
-
description: "Register",
|
|
15610
|
-
method: HttpMethod.POST,
|
|
15611
|
-
url: "/authentication/users/register/",
|
|
15612
|
-
isAuthNeeded: false,
|
|
15613
|
-
payload,
|
|
15614
|
-
blockers: [],
|
|
15615
|
-
blocks: []
|
|
15616
|
-
});
|
|
15617
|
-
}
|
|
15618
|
-
async resetPassword(email) {
|
|
15619
|
-
return this.enqueueRequest({
|
|
15620
|
-
description: "Reset password",
|
|
15621
|
-
method: HttpMethod.PATCH,
|
|
15622
|
-
url: "/authentication/users/reset-password/",
|
|
15623
|
-
isAuthNeeded: false,
|
|
15624
|
-
payload: {
|
|
15625
|
-
email
|
|
15626
|
-
},
|
|
15627
|
-
blockers: [],
|
|
15628
|
-
blocks: []
|
|
15629
|
-
});
|
|
15630
|
-
}
|
|
15631
15500
|
/**
|
|
15632
15501
|
* Checks whether the tokens will be expiring soon
|
|
15633
15502
|
* @returns {boolean}
|
|
15634
15503
|
*/
|
|
15635
15504
|
tokenIsExpiringSoon() {
|
|
15636
|
-
const accessToken = this.
|
|
15505
|
+
const accessToken = this.getAccessToken();
|
|
15637
15506
|
if (!accessToken) {
|
|
15638
15507
|
return false;
|
|
15639
15508
|
}
|
|
@@ -15647,53 +15516,99 @@ Defaulting to \`${$89eedd556c436f6a$var$DEFAULT_ORIENTATION}\`.`;
|
|
|
15647
15516
|
const secondsUntilExpiry = expiryDate - currentDate;
|
|
15648
15517
|
return secondsUntilExpiry < EXPIRING_SOON_THRESHOLD;
|
|
15649
15518
|
}
|
|
15650
|
-
|
|
15651
|
-
const
|
|
15652
|
-
|
|
15653
|
-
const [fileProps] = await this.client.files.uploadFileToS3(hash);
|
|
15654
|
-
this.dispatch(setProfilePicture({ file: `/files/${fileProps.file}`, file_sha1: hash }));
|
|
15655
|
-
return this.enqueueRequest({
|
|
15656
|
-
description: "Replace profile picture",
|
|
15657
|
-
method: HttpMethod.PATCH,
|
|
15658
|
-
url: "/authentication/users/profile-details/",
|
|
15659
|
-
payload: fileProps,
|
|
15660
|
-
blockers: [],
|
|
15661
|
-
blocks: []
|
|
15662
|
-
});
|
|
15519
|
+
getAuthHeader() {
|
|
15520
|
+
const accesseToken = selectAccessToken(this.client.store.getState());
|
|
15521
|
+
return `Bearer ${accesseToken}`;
|
|
15663
15522
|
}
|
|
15664
|
-
async
|
|
15665
|
-
this.
|
|
15666
|
-
|
|
15667
|
-
|
|
15668
|
-
|
|
15669
|
-
|
|
15670
|
-
|
|
15671
|
-
|
|
15672
|
-
|
|
15523
|
+
async prepareAuth() {
|
|
15524
|
+
if (!this.tokenIsExpiringSoon())
|
|
15525
|
+
return;
|
|
15526
|
+
try {
|
|
15527
|
+
await this.renewTokens();
|
|
15528
|
+
} catch (e) {
|
|
15529
|
+
if (e instanceof APIError) {
|
|
15530
|
+
await this.clearAuth();
|
|
15531
|
+
}
|
|
15532
|
+
return Promise.reject(e);
|
|
15533
|
+
}
|
|
15673
15534
|
}
|
|
15674
|
-
|
|
15675
|
-
|
|
15676
|
-
|
|
15677
|
-
|
|
15678
|
-
|
|
15679
|
-
|
|
15680
|
-
|
|
15681
|
-
|
|
15682
|
-
|
|
15535
|
+
/* if not successfull in gracefully handling an unauthorized response, throw and APIError */
|
|
15536
|
+
async handleUnauthorized(request2, response) {
|
|
15537
|
+
const state = this.client.store.getState();
|
|
15538
|
+
if (request2.url.endsWith("/token/refresh/")) {
|
|
15539
|
+
if (state.authReducer.isLoggedIn) {
|
|
15540
|
+
console.warn("No signed-in user to sign out.");
|
|
15541
|
+
}
|
|
15542
|
+
await this.clearAuth();
|
|
15543
|
+
throw new APIError({
|
|
15544
|
+
message: "You have been signed out due to inactivity.",
|
|
15545
|
+
response,
|
|
15546
|
+
discard: true
|
|
15547
|
+
});
|
|
15548
|
+
}
|
|
15549
|
+
if (state.authReducer.isLoggedIn) {
|
|
15550
|
+
await this.renewTokens();
|
|
15551
|
+
} else {
|
|
15552
|
+
console.debug("Forbidden; user is not logged in.");
|
|
15553
|
+
throw new APIError({
|
|
15554
|
+
message: "Incorrect username or password.",
|
|
15555
|
+
response,
|
|
15556
|
+
discard: true
|
|
15557
|
+
});
|
|
15558
|
+
}
|
|
15683
15559
|
}
|
|
15684
|
-
|
|
15685
|
-
|
|
15686
|
-
|
|
15687
|
-
|
|
15688
|
-
|
|
15689
|
-
|
|
15690
|
-
|
|
15691
|
-
|
|
15692
|
-
|
|
15560
|
+
/**
|
|
15561
|
+
* Attempts to log into Hemora using given credentials
|
|
15562
|
+
* @param {string} username
|
|
15563
|
+
* @param {string} password
|
|
15564
|
+
*/
|
|
15565
|
+
async initAuth(username, password) {
|
|
15566
|
+
const uuid$1 = uuid.v4();
|
|
15567
|
+
const promise = this.enqueueRequest({
|
|
15568
|
+
uuid: uuid$1,
|
|
15569
|
+
description: "Get token pair",
|
|
15570
|
+
method: HttpMethod.POST,
|
|
15571
|
+
url: this.initTokensUrl,
|
|
15572
|
+
payload: { username, password },
|
|
15693
15573
|
isAuthNeeded: false,
|
|
15574
|
+
checkAuth: false,
|
|
15694
15575
|
blockers: [],
|
|
15695
15576
|
blocks: []
|
|
15577
|
+
}).then(parseTokens);
|
|
15578
|
+
const timeout = 5;
|
|
15579
|
+
let timedOut = false;
|
|
15580
|
+
const timeoutPromise = new Promise((_, reject) => {
|
|
15581
|
+
setTimeout(() => {
|
|
15582
|
+
timedOut = true;
|
|
15583
|
+
this.dispatch(markForDeletion(uuid$1));
|
|
15584
|
+
reject(new APIError({ message: `Request timed out after ${timeout} seconds` }));
|
|
15585
|
+
}, timeout * 1e3);
|
|
15586
|
+
});
|
|
15587
|
+
const successPromise = promise.then((tokens) => {
|
|
15588
|
+
if (timedOut) {
|
|
15589
|
+
return void 0;
|
|
15590
|
+
}
|
|
15591
|
+
this.setTokens(tokens);
|
|
15592
|
+
this.dispatch(setLoggedIn(true));
|
|
15593
|
+
this.dispatch({ type: "rehydrated/setRehydrated", payload: true });
|
|
15696
15594
|
});
|
|
15595
|
+
return Promise.race([timeoutPromise, successPromise]);
|
|
15596
|
+
}
|
|
15597
|
+
}
|
|
15598
|
+
const CLASS_NAME_TO_SERVICE = {};
|
|
15599
|
+
class BaseApiService {
|
|
15600
|
+
constructor(sdk, auth) {
|
|
15601
|
+
__publicField(this, "client");
|
|
15602
|
+
__publicField(this, "auth");
|
|
15603
|
+
CLASS_NAME_TO_SERVICE[this.constructor.name] = this;
|
|
15604
|
+
this.client = sdk;
|
|
15605
|
+
this.auth = auth;
|
|
15606
|
+
}
|
|
15607
|
+
async enqueueRequest(requestDetails) {
|
|
15608
|
+
return this.client.enqueueRequest(requestDetails, this.host, this.constructor.name);
|
|
15609
|
+
}
|
|
15610
|
+
dispatch(action) {
|
|
15611
|
+
this.client.store.dispatch(action);
|
|
15697
15612
|
}
|
|
15698
15613
|
}
|
|
15699
15614
|
class CategoryService extends BaseApiService {
|
|
@@ -18094,18 +18009,17 @@ Defaulting to \`${$89eedd556c436f6a$var$DEFAULT_ORIENTATION}\`.`;
|
|
|
18094
18009
|
}
|
|
18095
18010
|
class EmailVerificationService extends BaseApiService {
|
|
18096
18011
|
async getVerificationCode(verificationCode) {
|
|
18097
|
-
|
|
18012
|
+
return this.enqueueRequest({
|
|
18098
18013
|
description: "Get verification code",
|
|
18099
18014
|
method: HttpMethod.GET,
|
|
18100
18015
|
url: `/verification/email-verification/${verificationCode}/`,
|
|
18101
18016
|
isAuthNeeded: false,
|
|
18102
18017
|
blockers: [],
|
|
18103
18018
|
blocks: []
|
|
18104
|
-
};
|
|
18105
|
-
return this.enqueueRequest(requestDetails);
|
|
18019
|
+
});
|
|
18106
18020
|
}
|
|
18107
18021
|
validateVerificationCode(verificationCode, payload = void 0) {
|
|
18108
|
-
|
|
18022
|
+
return this.enqueueRequest({
|
|
18109
18023
|
description: "Validate verification code",
|
|
18110
18024
|
method: HttpMethod.POST,
|
|
18111
18025
|
url: `/verification/email-verification/${verificationCode}/`,
|
|
@@ -18113,8 +18027,7 @@ Defaulting to \`${$89eedd556c436f6a$var$DEFAULT_ORIENTATION}\`.`;
|
|
|
18113
18027
|
payload,
|
|
18114
18028
|
blockers: [],
|
|
18115
18029
|
blocks: []
|
|
18116
|
-
};
|
|
18117
|
-
return this.enqueueRequest(requestDetails);
|
|
18030
|
+
});
|
|
18118
18031
|
}
|
|
18119
18032
|
}
|
|
18120
18033
|
class EmailDomainsService extends BaseApiService {
|
|
@@ -18758,13 +18671,13 @@ Defaulting to \`${$89eedd556c436f6a$var$DEFAULT_ORIENTATION}\`.`;
|
|
|
18758
18671
|
exports2.AssetTypeAttachmentService = AssetTypeAttachmentService;
|
|
18759
18672
|
exports2.AssetTypeService = AssetTypeService;
|
|
18760
18673
|
exports2.AttachmentModel = AttachmentModel;
|
|
18761
|
-
exports2.AuthService = AuthService;
|
|
18762
18674
|
exports2.BaseApiService = BaseApiService;
|
|
18763
18675
|
exports2.BaseField = BaseField;
|
|
18764
18676
|
exports2.BaseFormElement = BaseFormElement;
|
|
18765
18677
|
exports2.BaseSDK = BaseSDK;
|
|
18766
18678
|
exports2.BooleanField = BooleanField;
|
|
18767
18679
|
exports2.BooleanInput = BooleanInput;
|
|
18680
|
+
exports2.CLASS_NAME_TO_SERVICE = CLASS_NAME_TO_SERVICE;
|
|
18768
18681
|
exports2.CategoryService = CategoryService;
|
|
18769
18682
|
exports2.ColorPicker = ColorPicker;
|
|
18770
18683
|
exports2.Colors = Colors;
|
|
@@ -18802,6 +18715,7 @@ Defaulting to \`${$89eedd556c436f6a$var$DEFAULT_ORIENTATION}\`.`;
|
|
|
18802
18715
|
exports2.IssueTypeService = IssueTypeService;
|
|
18803
18716
|
exports2.IssueUpdateChange = IssueUpdateChange;
|
|
18804
18717
|
exports2.IssueUpdateService = IssueUpdateService;
|
|
18718
|
+
exports2.JWTService = JWTService;
|
|
18805
18719
|
exports2.LicenseLevel = LicenseLevel;
|
|
18806
18720
|
exports2.LicenseService = LicenseService;
|
|
18807
18721
|
exports2.LicenseStatus = LicenseStatus;
|
|
@@ -19398,6 +19312,8 @@ Defaulting to \`${$89eedd556c436f6a$var$DEFAULT_ORIENTATION}\`.`;
|
|
|
19398
19312
|
exports2.userSlice = userSlice;
|
|
19399
19313
|
exports2.validateForm = validateForm;
|
|
19400
19314
|
exports2.valueIsFile = valueIsFile;
|
|
19315
|
+
exports2.versioningReducer = versioningReducer;
|
|
19316
|
+
exports2.versioningSlice = versioningSlice;
|
|
19401
19317
|
exports2.warningColor = warningColor;
|
|
19402
19318
|
exports2.workspaceReducer = workspaceReducer;
|
|
19403
19319
|
exports2.workspaceSlice = workspaceSlice;
|