@overmap-ai/core 1.0.49-fix-error-messaging.3 → 1.0.49-update-presigned-url-payload.0
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 +74 -95
- package/dist/overmap-core.js.map +1 -1
- package/dist/overmap-core.umd.cjs +74 -95
- package/dist/overmap-core.umd.cjs.map +1 -1
- package/dist/sdk/errors.d.ts +3 -6
- 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,54 +217,18 @@ class OutboxCoordinator {
|
|
|
217
217
|
this.requestAttemptCounter[uuid] = (this.requestAttemptCounter[uuid] || 0) + 1;
|
|
218
218
|
}
|
|
219
219
|
}
|
|
220
|
-
function extractErrorMessage(errorRes, err) {
|
|
221
|
-
if (errorRes == null ? void 0 : errorRes.body) {
|
|
222
|
-
if (typeof errorRes.body === "object") {
|
|
223
|
-
if (typeof errorRes.body.error === "string")
|
|
224
|
-
return errorRes.body.error;
|
|
225
|
-
if (typeof errorRes.body.message === "string")
|
|
226
|
-
return errorRes.body.message;
|
|
227
|
-
try {
|
|
228
|
-
return Object.entries(errorRes.body).map(([key, value]) => {
|
|
229
|
-
if (typeof value === "string") {
|
|
230
|
-
if (key === "non_field_errors")
|
|
231
|
-
return value;
|
|
232
|
-
return `${key}: ${value}`;
|
|
233
|
-
}
|
|
234
|
-
if (Array.isArray(value)) {
|
|
235
|
-
if (key === "non_field_errors")
|
|
236
|
-
return value.join("\n");
|
|
237
|
-
return value.map((v) => `${key}: ${v}`).join("\n");
|
|
238
|
-
}
|
|
239
|
-
return `${key}: ${JSON.stringify(value)}`;
|
|
240
|
-
}).join("\n");
|
|
241
|
-
} catch (e) {
|
|
242
|
-
console.error("Failed to extract error message from response body", e);
|
|
243
|
-
}
|
|
244
|
-
} else if (typeof errorRes.body === "string")
|
|
245
|
-
return errorRes.body;
|
|
246
|
-
} else if (errorRes == null ? void 0 : errorRes.text) {
|
|
247
|
-
return errorRes.text;
|
|
248
|
-
} else if (err instanceof Error) {
|
|
249
|
-
return err.message;
|
|
250
|
-
}
|
|
251
|
-
return void 0;
|
|
252
|
-
}
|
|
253
220
|
class APIError extends Error {
|
|
254
|
-
constructor(options) {
|
|
255
|
-
|
|
256
|
-
super(unknownMessage);
|
|
221
|
+
constructor(message, response, options) {
|
|
222
|
+
super(response == null ? void 0 : response.text);
|
|
257
223
|
// NOTE: Needs to conform to NetworkError in @redux-offline/redux-offline, which has `status` and `response`.
|
|
258
224
|
__publicField(this, "status");
|
|
259
|
-
__publicField(this, "response");
|
|
260
225
|
__publicField(this, "message");
|
|
226
|
+
__publicField(this, "response");
|
|
261
227
|
__publicField(this, "options");
|
|
262
|
-
|
|
263
|
-
this.message = options.message ?? extractErrorMessage(response, innerError) ?? unknownMessage;
|
|
228
|
+
this.message = message;
|
|
264
229
|
this.status = (response == null ? void 0 : response.status) ?? 0;
|
|
265
230
|
this.response = response;
|
|
266
|
-
options
|
|
267
|
-
this.options = options;
|
|
231
|
+
this.options = options ?? { discard: false };
|
|
268
232
|
}
|
|
269
233
|
}
|
|
270
234
|
class DeferredPromise {
|
|
@@ -4213,6 +4177,35 @@ function extractResponseFromError(error2) {
|
|
|
4213
4177
|
}
|
|
4214
4178
|
return void 0;
|
|
4215
4179
|
}
|
|
4180
|
+
function extractErrorMessage(errorRes, err) {
|
|
4181
|
+
if (errorRes == null ? void 0 : errorRes.body) {
|
|
4182
|
+
if (typeof errorRes.body === "object") {
|
|
4183
|
+
if (typeof errorRes.body.error === "string")
|
|
4184
|
+
return errorRes.body.error;
|
|
4185
|
+
if (typeof errorRes.body.message === "string")
|
|
4186
|
+
return errorRes.body.message;
|
|
4187
|
+
try {
|
|
4188
|
+
return Object.entries(errorRes.body).map(([key, value]) => {
|
|
4189
|
+
if (typeof value === "string") {
|
|
4190
|
+
return `${key}: ${value}`;
|
|
4191
|
+
}
|
|
4192
|
+
if (Array.isArray(value)) {
|
|
4193
|
+
return value.map((v) => `${key}: ${v}`).join("\n");
|
|
4194
|
+
}
|
|
4195
|
+
return `${key}: ${JSON.stringify(value)}`;
|
|
4196
|
+
}).join("\n");
|
|
4197
|
+
} catch (e) {
|
|
4198
|
+
console.error("Failed to extract error message from response body", e);
|
|
4199
|
+
}
|
|
4200
|
+
} else if (typeof errorRes.body === "string")
|
|
4201
|
+
return errorRes.body;
|
|
4202
|
+
} else if (errorRes == null ? void 0 : errorRes.text) {
|
|
4203
|
+
return errorRes.text;
|
|
4204
|
+
} else if (err instanceof Error) {
|
|
4205
|
+
return err.message;
|
|
4206
|
+
}
|
|
4207
|
+
return void 0;
|
|
4208
|
+
}
|
|
4216
4209
|
async function performRequest(action, client) {
|
|
4217
4210
|
async function checkToken() {
|
|
4218
4211
|
if (client.auth.tokenIsExpiringSoon()) {
|
|
@@ -4315,29 +4308,19 @@ async function performRequest(action, client) {
|
|
|
4315
4308
|
console.warn("No signed-in user to sign out.");
|
|
4316
4309
|
}
|
|
4317
4310
|
await client.auth.logout();
|
|
4318
|
-
throw new APIError({
|
|
4319
|
-
|
|
4320
|
-
response: errorResponse,
|
|
4321
|
-
discard: true,
|
|
4322
|
-
innerError: error2
|
|
4323
|
-
});
|
|
4324
|
-
}
|
|
4325
|
-
if (state.authReducer.isLoggedIn) {
|
|
4326
|
-
console.debug("Forbidden; renewing tokens and retrying.");
|
|
4327
|
-
await client.auth.renewTokens();
|
|
4328
|
-
console.debug("Successfully renewed tokens; retrying request.");
|
|
4329
|
-
return requestToSend.query(queryParams);
|
|
4330
|
-
} else {
|
|
4331
|
-
console.debug("Forbidden; user is not logged in.");
|
|
4332
|
-
throw new APIError({
|
|
4333
|
-
message: "Incorrect username or password.",
|
|
4334
|
-
response: errorResponse,
|
|
4335
|
-
discard: true,
|
|
4336
|
-
innerError: error2
|
|
4311
|
+
throw new APIError("You have been signed out due to inactivity.", errorResponse, {
|
|
4312
|
+
discard: true
|
|
4337
4313
|
});
|
|
4338
4314
|
}
|
|
4315
|
+
console.debug("Forbidden; renewing tokens and retrying.");
|
|
4316
|
+
await client.auth.renewTokens();
|
|
4317
|
+
console.debug("Successfully renewed tokens; retrying request.");
|
|
4318
|
+
return requestToSend.query(queryParams);
|
|
4339
4319
|
}
|
|
4340
|
-
|
|
4320
|
+
const apiErrorMessage = extractErrorMessage(errorResponse, error2) || "An unexpected error occurred.";
|
|
4321
|
+
throw new APIError(apiErrorMessage, errorResponse, {
|
|
4322
|
+
discard: discardStatuses.includes(status)
|
|
4323
|
+
});
|
|
4341
4324
|
}
|
|
4342
4325
|
}
|
|
4343
4326
|
class MiddlewareChainerPrivate {
|
|
@@ -4548,29 +4531,18 @@ class BaseApiService {
|
|
|
4548
4531
|
if (response) {
|
|
4549
4532
|
promise.resolve(response.body);
|
|
4550
4533
|
} else {
|
|
4551
|
-
const error2 = new APIError(
|
|
4552
|
-
|
|
4534
|
+
const error2 = new APIError(
|
|
4535
|
+
"Could not get a response from the server.",
|
|
4553
4536
|
response,
|
|
4554
|
-
|
|
4555
|
-
|
|
4537
|
+
{
|
|
4538
|
+
discard: true
|
|
4539
|
+
}
|
|
4540
|
+
);
|
|
4556
4541
|
promise.reject(error2);
|
|
4557
4542
|
}
|
|
4558
4543
|
};
|
|
4559
4544
|
const errorHandler = (error2) => {
|
|
4560
|
-
|
|
4561
|
-
error2.options.discard = true;
|
|
4562
|
-
} else {
|
|
4563
|
-
console.error(
|
|
4564
|
-
"Received an unexpected error while processing a request:",
|
|
4565
|
-
error2,
|
|
4566
|
-
"\nConverting error to APIError and discarding."
|
|
4567
|
-
);
|
|
4568
|
-
error2 = new APIError({
|
|
4569
|
-
message: "An error occurred while processing the request.",
|
|
4570
|
-
innerError: error2,
|
|
4571
|
-
discard: true
|
|
4572
|
-
});
|
|
4573
|
-
}
|
|
4545
|
+
error2.options.discard = true;
|
|
4574
4546
|
promise.reject(error2);
|
|
4575
4547
|
};
|
|
4576
4548
|
innerPromise.then(successOrUndefinedHandler, errorHandler);
|
|
@@ -5150,23 +5122,24 @@ class AuthService extends BaseApiService {
|
|
|
5150
5122
|
*/
|
|
5151
5123
|
__publicField(this, "_getTokenPair", (credentials, logoutOnFailure = true) => {
|
|
5152
5124
|
const uuid = v4();
|
|
5153
|
-
|
|
5154
|
-
|
|
5155
|
-
|
|
5156
|
-
|
|
5157
|
-
|
|
5158
|
-
|
|
5159
|
-
|
|
5160
|
-
|
|
5161
|
-
|
|
5162
|
-
|
|
5163
|
-
|
|
5125
|
+
try {
|
|
5126
|
+
const responsePromise = this.enqueueRequest({
|
|
5127
|
+
uuid,
|
|
5128
|
+
description: "Get token pair",
|
|
5129
|
+
method: HttpMethod.POST,
|
|
5130
|
+
url: "/api/token/",
|
|
5131
|
+
payload: credentials,
|
|
5132
|
+
isAuthNeeded: false,
|
|
5133
|
+
blockers: [],
|
|
5134
|
+
blocks: []
|
|
5135
|
+
});
|
|
5136
|
+
return [responsePromise.then(parseTokens), uuid];
|
|
5137
|
+
} catch (e) {
|
|
5164
5138
|
if (logoutOnFailure) {
|
|
5165
5139
|
void this.logout().then();
|
|
5166
5140
|
}
|
|
5167
5141
|
throw e;
|
|
5168
|
-
}
|
|
5169
|
-
return [responsePromise, uuid];
|
|
5142
|
+
}
|
|
5170
5143
|
});
|
|
5171
5144
|
/**
|
|
5172
5145
|
* Takes refresh token and gets a new token pair
|
|
@@ -5227,7 +5200,7 @@ class AuthService extends BaseApiService {
|
|
|
5227
5200
|
timedOut = true;
|
|
5228
5201
|
store.dispatch(markForDeletion(uuid));
|
|
5229
5202
|
store.dispatch(markForDeletion(initialDataUuid));
|
|
5230
|
-
reject(new
|
|
5203
|
+
reject(new Error(`Request timed out after ${timeout} seconds`));
|
|
5231
5204
|
}, timeout * 1e3);
|
|
5232
5205
|
});
|
|
5233
5206
|
const successPromise = promise.then((tokens) => {
|
|
@@ -7196,7 +7169,8 @@ class OrganizationAccessService extends BaseApiService {
|
|
|
7196
7169
|
blockers: [],
|
|
7197
7170
|
blocks: []
|
|
7198
7171
|
});
|
|
7199
|
-
|
|
7172
|
+
const organizationAccesses = result;
|
|
7173
|
+
store.dispatch(setOrganizationAccesses(organizationAccesses));
|
|
7200
7174
|
}
|
|
7201
7175
|
}
|
|
7202
7176
|
const cachedRequestPromises = {};
|
|
@@ -7225,7 +7199,12 @@ class FileService extends BaseApiService {
|
|
|
7225
7199
|
description: "Get S3 URL",
|
|
7226
7200
|
method: HttpMethod.GET,
|
|
7227
7201
|
url: "/authentication/files/presigned-upload-url/",
|
|
7228
|
-
queryParams: {
|
|
7202
|
+
queryParams: {
|
|
7203
|
+
sha1: await hashFile(file),
|
|
7204
|
+
file_type: file.type,
|
|
7205
|
+
extension: file.name.split(".").pop(),
|
|
7206
|
+
size: file.size.toString()
|
|
7207
|
+
},
|
|
7229
7208
|
blockers: [],
|
|
7230
7209
|
blocks: [`s3-${key}`]
|
|
7231
7210
|
});
|