@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
package/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# @overmap-ai/core
|
|
2
|
-
|
|
3
|
-
The `core` package contains core functionality for the Overmap platform. It is a peer dependency of all other overmap
|
|
4
|
-
packages.
|
|
1
|
+
# @overmap-ai/core
|
|
2
|
+
|
|
3
|
+
The `core` package contains core functionality for the Overmap platform. It is a peer dependency of all other overmap
|
|
4
|
+
packages.
|
package/dist/overmap-core.js
CHANGED
|
@@ -217,18 +217,64 @@ class OutboxCoordinator {
|
|
|
217
217
|
this.requestAttemptCounter[uuid] = (this.requestAttemptCounter[uuid] || 0) + 1;
|
|
218
218
|
}
|
|
219
219
|
}
|
|
220
|
+
const UNKNOWN_ERROR_MESSAGE = "An unknown error occurred";
|
|
221
|
+
const MAX_ERROR_MESSAGE_LENGTH = 500;
|
|
222
|
+
const _SPECIAL_KEYS = ["non_field_errors", "detail"];
|
|
223
|
+
function extractErrorMessage(errorRes, err) {
|
|
224
|
+
let ret;
|
|
225
|
+
if (errorRes == null ? void 0 : errorRes.body) {
|
|
226
|
+
if (typeof errorRes.body === "object") {
|
|
227
|
+
const responseBody = errorRes.body;
|
|
228
|
+
if (typeof responseBody.error === "string") {
|
|
229
|
+
ret = responseBody.error;
|
|
230
|
+
} else if (typeof responseBody.message === "string") {
|
|
231
|
+
ret = responseBody.message;
|
|
232
|
+
} else if (responseBody.body) {
|
|
233
|
+
try {
|
|
234
|
+
ret = Object.entries(responseBody.body).map(([key, value]) => {
|
|
235
|
+
if (typeof value === "string") {
|
|
236
|
+
if (_SPECIAL_KEYS.includes(key))
|
|
237
|
+
return value;
|
|
238
|
+
return `${key}: ${value}`;
|
|
239
|
+
}
|
|
240
|
+
if (Array.isArray(value)) {
|
|
241
|
+
if (_SPECIAL_KEYS.includes(key))
|
|
242
|
+
return value.join("\n");
|
|
243
|
+
return value.map((v) => `${key}: ${v}`).join("\n");
|
|
244
|
+
}
|
|
245
|
+
return `${key}: ${JSON.stringify(value)}`;
|
|
246
|
+
}).join("\n");
|
|
247
|
+
} catch (e) {
|
|
248
|
+
console.error("Failed to extract error message from response body", e);
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
} else if (typeof errorRes.body === "string") {
|
|
252
|
+
ret = errorRes.body;
|
|
253
|
+
}
|
|
254
|
+
} else if (errorRes == null ? void 0 : errorRes.text) {
|
|
255
|
+
ret = errorRes.text;
|
|
256
|
+
} else if (err instanceof Error) {
|
|
257
|
+
ret = err.message;
|
|
258
|
+
}
|
|
259
|
+
if (!ret || ret.length > MAX_ERROR_MESSAGE_LENGTH) {
|
|
260
|
+
return UNKNOWN_ERROR_MESSAGE;
|
|
261
|
+
}
|
|
262
|
+
return ret;
|
|
263
|
+
}
|
|
220
264
|
class APIError extends Error {
|
|
221
|
-
constructor(
|
|
222
|
-
super(
|
|
265
|
+
constructor(options) {
|
|
266
|
+
super(UNKNOWN_ERROR_MESSAGE);
|
|
223
267
|
// NOTE: Needs to conform to NetworkError in @redux-offline/redux-offline, which has `status` and `response`.
|
|
224
268
|
__publicField(this, "status");
|
|
225
|
-
__publicField(this, "message");
|
|
226
269
|
__publicField(this, "response");
|
|
270
|
+
__publicField(this, "message");
|
|
227
271
|
__publicField(this, "options");
|
|
228
|
-
|
|
272
|
+
const { response, innerError } = options;
|
|
273
|
+
this.message = options.message ?? extractErrorMessage(response, innerError) ?? UNKNOWN_ERROR_MESSAGE;
|
|
229
274
|
this.status = (response == null ? void 0 : response.status) ?? 0;
|
|
230
275
|
this.response = response;
|
|
231
|
-
|
|
276
|
+
options.discard = options.discard ?? false;
|
|
277
|
+
this.options = options;
|
|
232
278
|
}
|
|
233
279
|
}
|
|
234
280
|
class DeferredPromise {
|
|
@@ -4239,35 +4285,6 @@ function extractResponseFromError(error2) {
|
|
|
4239
4285
|
}
|
|
4240
4286
|
return void 0;
|
|
4241
4287
|
}
|
|
4242
|
-
function extractErrorMessage(errorRes, err) {
|
|
4243
|
-
if (errorRes == null ? void 0 : errorRes.body) {
|
|
4244
|
-
if (typeof errorRes.body === "object") {
|
|
4245
|
-
if (typeof errorRes.body.error === "string")
|
|
4246
|
-
return errorRes.body.error;
|
|
4247
|
-
if (typeof errorRes.body.message === "string")
|
|
4248
|
-
return errorRes.body.message;
|
|
4249
|
-
try {
|
|
4250
|
-
return Object.entries(errorRes.body).map(([key, value]) => {
|
|
4251
|
-
if (typeof value === "string") {
|
|
4252
|
-
return `${key}: ${value}`;
|
|
4253
|
-
}
|
|
4254
|
-
if (Array.isArray(value)) {
|
|
4255
|
-
return value.map((v) => `${key}: ${v}`).join("\n");
|
|
4256
|
-
}
|
|
4257
|
-
return `${key}: ${JSON.stringify(value)}`;
|
|
4258
|
-
}).join("\n");
|
|
4259
|
-
} catch (e) {
|
|
4260
|
-
console.error("Failed to extract error message from response body", e);
|
|
4261
|
-
}
|
|
4262
|
-
} else if (typeof errorRes.body === "string")
|
|
4263
|
-
return errorRes.body;
|
|
4264
|
-
} else if (errorRes == null ? void 0 : errorRes.text) {
|
|
4265
|
-
return errorRes.text;
|
|
4266
|
-
} else if (err instanceof Error) {
|
|
4267
|
-
return err.message;
|
|
4268
|
-
}
|
|
4269
|
-
return void 0;
|
|
4270
|
-
}
|
|
4271
4288
|
async function performRequest(action, client) {
|
|
4272
4289
|
async function checkToken() {
|
|
4273
4290
|
if (client.auth.tokenIsExpiringSoon()) {
|
|
@@ -4370,19 +4387,29 @@ async function performRequest(action, client) {
|
|
|
4370
4387
|
console.warn("No signed-in user to sign out.");
|
|
4371
4388
|
}
|
|
4372
4389
|
await client.auth.logout();
|
|
4373
|
-
throw new APIError(
|
|
4374
|
-
|
|
4390
|
+
throw new APIError({
|
|
4391
|
+
message: "You have been signed out due to inactivity.",
|
|
4392
|
+
response: errorResponse,
|
|
4393
|
+
discard: true,
|
|
4394
|
+
innerError: error2
|
|
4395
|
+
});
|
|
4396
|
+
}
|
|
4397
|
+
if (state.authReducer.isLoggedIn) {
|
|
4398
|
+
console.debug("Forbidden; renewing tokens and retrying.");
|
|
4399
|
+
await client.auth.renewTokens();
|
|
4400
|
+
console.debug("Successfully renewed tokens; retrying request.");
|
|
4401
|
+
return requestToSend.query(queryParams);
|
|
4402
|
+
} else {
|
|
4403
|
+
console.debug("Forbidden; user is not logged in.");
|
|
4404
|
+
throw new APIError({
|
|
4405
|
+
message: "Incorrect username or password.",
|
|
4406
|
+
response: errorResponse,
|
|
4407
|
+
discard: true,
|
|
4408
|
+
innerError: error2
|
|
4375
4409
|
});
|
|
4376
4410
|
}
|
|
4377
|
-
console.debug("Forbidden; renewing tokens and retrying.");
|
|
4378
|
-
await client.auth.renewTokens();
|
|
4379
|
-
console.debug("Successfully renewed tokens; retrying request.");
|
|
4380
|
-
return requestToSend.query(queryParams);
|
|
4381
4411
|
}
|
|
4382
|
-
|
|
4383
|
-
throw new APIError(apiErrorMessage, errorResponse, {
|
|
4384
|
-
discard: discardStatuses.includes(status)
|
|
4385
|
-
});
|
|
4412
|
+
throw new APIError({ response: errorResponse, innerError: error2, discard: discardStatuses.includes(status) });
|
|
4386
4413
|
}
|
|
4387
4414
|
}
|
|
4388
4415
|
class MiddlewareChainerPrivate {
|
|
@@ -4593,18 +4620,29 @@ class BaseApiService {
|
|
|
4593
4620
|
if (response) {
|
|
4594
4621
|
promise.resolve(response.body);
|
|
4595
4622
|
} else {
|
|
4596
|
-
const error2 = new APIError(
|
|
4597
|
-
"Could not get a response from the server.",
|
|
4623
|
+
const error2 = new APIError({
|
|
4624
|
+
message: "Could not get a response from the server.",
|
|
4598
4625
|
response,
|
|
4599
|
-
|
|
4600
|
-
|
|
4601
|
-
}
|
|
4602
|
-
);
|
|
4626
|
+
discard: true
|
|
4627
|
+
});
|
|
4603
4628
|
promise.reject(error2);
|
|
4604
4629
|
}
|
|
4605
4630
|
};
|
|
4606
4631
|
const errorHandler = (error2) => {
|
|
4607
|
-
error2
|
|
4632
|
+
if (error2 instanceof APIError) {
|
|
4633
|
+
error2.options.discard = true;
|
|
4634
|
+
} else {
|
|
4635
|
+
console.error(
|
|
4636
|
+
"Received an unexpected error while processing a request:",
|
|
4637
|
+
error2,
|
|
4638
|
+
"\nConverting error to APIError and discarding."
|
|
4639
|
+
);
|
|
4640
|
+
error2 = new APIError({
|
|
4641
|
+
message: "An error occurred while processing the request.",
|
|
4642
|
+
innerError: error2,
|
|
4643
|
+
discard: true
|
|
4644
|
+
});
|
|
4645
|
+
}
|
|
4608
4646
|
promise.reject(error2);
|
|
4609
4647
|
};
|
|
4610
4648
|
innerPromise.then(successOrUndefinedHandler, errorHandler);
|
|
@@ -5185,24 +5223,23 @@ class AuthService extends BaseApiService {
|
|
|
5185
5223
|
*/
|
|
5186
5224
|
__publicField(this, "_getTokenPair", (credentials, logoutOnFailure = true) => {
|
|
5187
5225
|
const uuid = v4();
|
|
5188
|
-
|
|
5189
|
-
|
|
5190
|
-
|
|
5191
|
-
|
|
5192
|
-
|
|
5193
|
-
|
|
5194
|
-
|
|
5195
|
-
|
|
5196
|
-
|
|
5197
|
-
|
|
5198
|
-
|
|
5199
|
-
return [responsePromise.then(parseTokens), uuid];
|
|
5200
|
-
} catch (e) {
|
|
5226
|
+
const responsePromise = this.enqueueRequest({
|
|
5227
|
+
uuid,
|
|
5228
|
+
description: "Get token pair",
|
|
5229
|
+
method: HttpMethod.POST,
|
|
5230
|
+
url: "/api/token/",
|
|
5231
|
+
payload: credentials,
|
|
5232
|
+
isAuthNeeded: false,
|
|
5233
|
+
checkAuth: false,
|
|
5234
|
+
blockers: [],
|
|
5235
|
+
blocks: []
|
|
5236
|
+
}).then(parseTokens).catch((e) => {
|
|
5201
5237
|
if (logoutOnFailure) {
|
|
5202
5238
|
void this.logout().then();
|
|
5203
5239
|
}
|
|
5204
5240
|
throw e;
|
|
5205
|
-
}
|
|
5241
|
+
});
|
|
5242
|
+
return [responsePromise, uuid];
|
|
5206
5243
|
});
|
|
5207
5244
|
/**
|
|
5208
5245
|
* Takes refresh token and gets a new token pair
|
|
@@ -5263,7 +5300,7 @@ class AuthService extends BaseApiService {
|
|
|
5263
5300
|
timedOut = true;
|
|
5264
5301
|
store.dispatch(markForDeletion(uuid));
|
|
5265
5302
|
store.dispatch(markForDeletion(initialDataUuid));
|
|
5266
|
-
reject(new
|
|
5303
|
+
reject(new APIError({ message: `Request timed out after ${timeout} seconds` }));
|
|
5267
5304
|
}, timeout * 1e3);
|
|
5268
5305
|
});
|
|
5269
5306
|
const successPromise = promise.then((tokens) => {
|
|
@@ -7239,8 +7276,7 @@ class OrganizationAccessService extends BaseApiService {
|
|
|
7239
7276
|
blockers: [],
|
|
7240
7277
|
blocks: []
|
|
7241
7278
|
});
|
|
7242
|
-
|
|
7243
|
-
store.dispatch(setOrganizationAccesses(organizationAccesses));
|
|
7279
|
+
store.dispatch(setOrganizationAccesses(result));
|
|
7244
7280
|
}
|
|
7245
7281
|
}
|
|
7246
7282
|
const cachedRequestPromises = {};
|