@overmap-ai/core 1.0.50-document-attachments.2 → 1.0.50
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/README.md +4 -4
- package/dist/overmap-core.js +104 -68
- package/dist/overmap-core.js.map +1 -1
- package/dist/overmap-core.umd.cjs +104 -68
- package/dist/overmap-core.umd.cjs.map +1 -1
- package/dist/sdk/errors.d.ts +6 -3
- package/dist/sdk/services/CategoryService.d.ts +2 -2
- package/dist/sdk/services/ComponentStageCompletionService.d.ts +2 -2
- package/dist/sdk/services/WorkspaceService.d.ts +2 -2
- package/dist/store/store.d.ts +1 -1
- package/package.json +152 -152
|
@@ -208,18 +208,64 @@ var __publicField = (obj, key, value) => {
|
|
|
208
208
|
this.requestAttemptCounter[uuid2] = (this.requestAttemptCounter[uuid2] || 0) + 1;
|
|
209
209
|
}
|
|
210
210
|
}
|
|
211
|
+
const UNKNOWN_ERROR_MESSAGE = "An unknown error occurred";
|
|
212
|
+
const MAX_ERROR_MESSAGE_LENGTH = 500;
|
|
213
|
+
const _SPECIAL_KEYS = ["non_field_errors", "detail"];
|
|
214
|
+
function extractErrorMessage(errorRes, err) {
|
|
215
|
+
let ret;
|
|
216
|
+
if (errorRes == null ? void 0 : errorRes.body) {
|
|
217
|
+
if (typeof errorRes.body === "object") {
|
|
218
|
+
const responseBody = errorRes.body;
|
|
219
|
+
if (typeof responseBody.error === "string") {
|
|
220
|
+
ret = responseBody.error;
|
|
221
|
+
} else if (typeof responseBody.message === "string") {
|
|
222
|
+
ret = responseBody.message;
|
|
223
|
+
} else if (responseBody.body) {
|
|
224
|
+
try {
|
|
225
|
+
ret = Object.entries(responseBody.body).map(([key, value]) => {
|
|
226
|
+
if (typeof value === "string") {
|
|
227
|
+
if (_SPECIAL_KEYS.includes(key))
|
|
228
|
+
return value;
|
|
229
|
+
return `${key}: ${value}`;
|
|
230
|
+
}
|
|
231
|
+
if (Array.isArray(value)) {
|
|
232
|
+
if (_SPECIAL_KEYS.includes(key))
|
|
233
|
+
return value.join("\n");
|
|
234
|
+
return value.map((v) => `${key}: ${v}`).join("\n");
|
|
235
|
+
}
|
|
236
|
+
return `${key}: ${JSON.stringify(value)}`;
|
|
237
|
+
}).join("\n");
|
|
238
|
+
} catch (e) {
|
|
239
|
+
console.error("Failed to extract error message from response body", e);
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
} else if (typeof errorRes.body === "string") {
|
|
243
|
+
ret = errorRes.body;
|
|
244
|
+
}
|
|
245
|
+
} else if (errorRes == null ? void 0 : errorRes.text) {
|
|
246
|
+
ret = errorRes.text;
|
|
247
|
+
} else if (err instanceof Error) {
|
|
248
|
+
ret = err.message;
|
|
249
|
+
}
|
|
250
|
+
if (!ret || ret.length > MAX_ERROR_MESSAGE_LENGTH) {
|
|
251
|
+
return UNKNOWN_ERROR_MESSAGE;
|
|
252
|
+
}
|
|
253
|
+
return ret;
|
|
254
|
+
}
|
|
211
255
|
class APIError extends Error {
|
|
212
|
-
constructor(
|
|
213
|
-
super(
|
|
256
|
+
constructor(options) {
|
|
257
|
+
super(UNKNOWN_ERROR_MESSAGE);
|
|
214
258
|
// NOTE: Needs to conform to NetworkError in @redux-offline/redux-offline, which has `status` and `response`.
|
|
215
259
|
__publicField(this, "status");
|
|
216
|
-
__publicField(this, "message");
|
|
217
260
|
__publicField(this, "response");
|
|
261
|
+
__publicField(this, "message");
|
|
218
262
|
__publicField(this, "options");
|
|
219
|
-
|
|
263
|
+
const { response, innerError } = options;
|
|
264
|
+
this.message = options.message ?? extractErrorMessage(response, innerError) ?? UNKNOWN_ERROR_MESSAGE;
|
|
220
265
|
this.status = (response == null ? void 0 : response.status) ?? 0;
|
|
221
266
|
this.response = response;
|
|
222
|
-
|
|
267
|
+
options.discard = options.discard ?? false;
|
|
268
|
+
this.options = options;
|
|
223
269
|
}
|
|
224
270
|
}
|
|
225
271
|
class DeferredPromise {
|
|
@@ -4230,35 +4276,6 @@ var __publicField = (obj, key, value) => {
|
|
|
4230
4276
|
}
|
|
4231
4277
|
return void 0;
|
|
4232
4278
|
}
|
|
4233
|
-
function extractErrorMessage(errorRes, err) {
|
|
4234
|
-
if (errorRes == null ? void 0 : errorRes.body) {
|
|
4235
|
-
if (typeof errorRes.body === "object") {
|
|
4236
|
-
if (typeof errorRes.body.error === "string")
|
|
4237
|
-
return errorRes.body.error;
|
|
4238
|
-
if (typeof errorRes.body.message === "string")
|
|
4239
|
-
return errorRes.body.message;
|
|
4240
|
-
try {
|
|
4241
|
-
return Object.entries(errorRes.body).map(([key, value]) => {
|
|
4242
|
-
if (typeof value === "string") {
|
|
4243
|
-
return `${key}: ${value}`;
|
|
4244
|
-
}
|
|
4245
|
-
if (Array.isArray(value)) {
|
|
4246
|
-
return value.map((v) => `${key}: ${v}`).join("\n");
|
|
4247
|
-
}
|
|
4248
|
-
return `${key}: ${JSON.stringify(value)}`;
|
|
4249
|
-
}).join("\n");
|
|
4250
|
-
} catch (e) {
|
|
4251
|
-
console.error("Failed to extract error message from response body", e);
|
|
4252
|
-
}
|
|
4253
|
-
} else if (typeof errorRes.body === "string")
|
|
4254
|
-
return errorRes.body;
|
|
4255
|
-
} else if (errorRes == null ? void 0 : errorRes.text) {
|
|
4256
|
-
return errorRes.text;
|
|
4257
|
-
} else if (err instanceof Error) {
|
|
4258
|
-
return err.message;
|
|
4259
|
-
}
|
|
4260
|
-
return void 0;
|
|
4261
|
-
}
|
|
4262
4279
|
async function performRequest(action, client) {
|
|
4263
4280
|
async function checkToken() {
|
|
4264
4281
|
if (client.auth.tokenIsExpiringSoon()) {
|
|
@@ -4361,19 +4378,29 @@ var __publicField = (obj, key, value) => {
|
|
|
4361
4378
|
console.warn("No signed-in user to sign out.");
|
|
4362
4379
|
}
|
|
4363
4380
|
await client.auth.logout();
|
|
4364
|
-
throw new APIError(
|
|
4365
|
-
|
|
4381
|
+
throw new APIError({
|
|
4382
|
+
message: "You have been signed out due to inactivity.",
|
|
4383
|
+
response: errorResponse,
|
|
4384
|
+
discard: true,
|
|
4385
|
+
innerError: error2
|
|
4386
|
+
});
|
|
4387
|
+
}
|
|
4388
|
+
if (state.authReducer.isLoggedIn) {
|
|
4389
|
+
console.debug("Forbidden; renewing tokens and retrying.");
|
|
4390
|
+
await client.auth.renewTokens();
|
|
4391
|
+
console.debug("Successfully renewed tokens; retrying request.");
|
|
4392
|
+
return requestToSend.query(queryParams);
|
|
4393
|
+
} else {
|
|
4394
|
+
console.debug("Forbidden; user is not logged in.");
|
|
4395
|
+
throw new APIError({
|
|
4396
|
+
message: "Incorrect username or password.",
|
|
4397
|
+
response: errorResponse,
|
|
4398
|
+
discard: true,
|
|
4399
|
+
innerError: error2
|
|
4366
4400
|
});
|
|
4367
4401
|
}
|
|
4368
|
-
console.debug("Forbidden; renewing tokens and retrying.");
|
|
4369
|
-
await client.auth.renewTokens();
|
|
4370
|
-
console.debug("Successfully renewed tokens; retrying request.");
|
|
4371
|
-
return requestToSend.query(queryParams);
|
|
4372
4402
|
}
|
|
4373
|
-
|
|
4374
|
-
throw new APIError(apiErrorMessage, errorResponse, {
|
|
4375
|
-
discard: discardStatuses.includes(status)
|
|
4376
|
-
});
|
|
4403
|
+
throw new APIError({ response: errorResponse, innerError: error2, discard: discardStatuses.includes(status) });
|
|
4377
4404
|
}
|
|
4378
4405
|
}
|
|
4379
4406
|
class MiddlewareChainerPrivate {
|
|
@@ -4584,18 +4611,29 @@ var __publicField = (obj, key, value) => {
|
|
|
4584
4611
|
if (response) {
|
|
4585
4612
|
promise.resolve(response.body);
|
|
4586
4613
|
} else {
|
|
4587
|
-
const error2 = new APIError(
|
|
4588
|
-
"Could not get a response from the server.",
|
|
4614
|
+
const error2 = new APIError({
|
|
4615
|
+
message: "Could not get a response from the server.",
|
|
4589
4616
|
response,
|
|
4590
|
-
|
|
4591
|
-
|
|
4592
|
-
}
|
|
4593
|
-
);
|
|
4617
|
+
discard: true
|
|
4618
|
+
});
|
|
4594
4619
|
promise.reject(error2);
|
|
4595
4620
|
}
|
|
4596
4621
|
};
|
|
4597
4622
|
const errorHandler = (error2) => {
|
|
4598
|
-
error2
|
|
4623
|
+
if (error2 instanceof APIError) {
|
|
4624
|
+
error2.options.discard = true;
|
|
4625
|
+
} else {
|
|
4626
|
+
console.error(
|
|
4627
|
+
"Received an unexpected error while processing a request:",
|
|
4628
|
+
error2,
|
|
4629
|
+
"\nConverting error to APIError and discarding."
|
|
4630
|
+
);
|
|
4631
|
+
error2 = new APIError({
|
|
4632
|
+
message: "An error occurred while processing the request.",
|
|
4633
|
+
innerError: error2,
|
|
4634
|
+
discard: true
|
|
4635
|
+
});
|
|
4636
|
+
}
|
|
4599
4637
|
promise.reject(error2);
|
|
4600
4638
|
};
|
|
4601
4639
|
innerPromise.then(successOrUndefinedHandler, errorHandler);
|
|
@@ -5176,24 +5214,23 @@ var __publicField = (obj, key, value) => {
|
|
|
5176
5214
|
*/
|
|
5177
5215
|
__publicField(this, "_getTokenPair", (credentials, logoutOnFailure = true) => {
|
|
5178
5216
|
const uuid$1 = uuid.v4();
|
|
5179
|
-
|
|
5180
|
-
|
|
5181
|
-
|
|
5182
|
-
|
|
5183
|
-
|
|
5184
|
-
|
|
5185
|
-
|
|
5186
|
-
|
|
5187
|
-
|
|
5188
|
-
|
|
5189
|
-
|
|
5190
|
-
return [responsePromise.then(parseTokens), uuid$1];
|
|
5191
|
-
} catch (e) {
|
|
5217
|
+
const responsePromise = this.enqueueRequest({
|
|
5218
|
+
uuid: uuid$1,
|
|
5219
|
+
description: "Get token pair",
|
|
5220
|
+
method: HttpMethod.POST,
|
|
5221
|
+
url: "/api/token/",
|
|
5222
|
+
payload: credentials,
|
|
5223
|
+
isAuthNeeded: false,
|
|
5224
|
+
checkAuth: false,
|
|
5225
|
+
blockers: [],
|
|
5226
|
+
blocks: []
|
|
5227
|
+
}).then(parseTokens).catch((e) => {
|
|
5192
5228
|
if (logoutOnFailure) {
|
|
5193
5229
|
void this.logout().then();
|
|
5194
5230
|
}
|
|
5195
5231
|
throw e;
|
|
5196
|
-
}
|
|
5232
|
+
});
|
|
5233
|
+
return [responsePromise, uuid$1];
|
|
5197
5234
|
});
|
|
5198
5235
|
/**
|
|
5199
5236
|
* Takes refresh token and gets a new token pair
|
|
@@ -5254,7 +5291,7 @@ var __publicField = (obj, key, value) => {
|
|
|
5254
5291
|
timedOut = true;
|
|
5255
5292
|
store.dispatch(markForDeletion(uuid$1));
|
|
5256
5293
|
store.dispatch(markForDeletion(initialDataUuid));
|
|
5257
|
-
reject(new
|
|
5294
|
+
reject(new APIError({ message: `Request timed out after ${timeout} seconds` }));
|
|
5258
5295
|
}, timeout * 1e3);
|
|
5259
5296
|
});
|
|
5260
5297
|
const successPromise = promise.then((tokens) => {
|
|
@@ -7230,8 +7267,7 @@ var __publicField = (obj, key, value) => {
|
|
|
7230
7267
|
blockers: [],
|
|
7231
7268
|
blocks: []
|
|
7232
7269
|
});
|
|
7233
|
-
|
|
7234
|
-
store.dispatch(setOrganizationAccesses(organizationAccesses));
|
|
7270
|
+
store.dispatch(setOrganizationAccesses(result));
|
|
7235
7271
|
}
|
|
7236
7272
|
}
|
|
7237
7273
|
const cachedRequestPromises = {};
|