@overmap-ai/core 1.0.50-document-attachments.2 → 1.0.50-fix-error-messaging.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 +133 -181
- package/dist/overmap-core.js.map +1 -1
- package/dist/overmap-core.umd.cjs +133 -181
- package/dist/overmap-core.umd.cjs.map +1 -1
- package/dist/sdk/errors.d.ts +6 -3
- package/dist/sdk/services/AttachmentService.d.ts +5 -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/slices/componentSlice.d.ts +0 -1
- package/dist/store/slices/componentTypeSlice.d.ts +0 -1
- package/dist/store/slices/documentSlice.d.ts +2 -35
- package/dist/store/slices/issueSlice.d.ts +0 -1
- package/dist/store/store.d.ts +1 -1
- package/dist/typings/models/attachments.d.ts +0 -4
- 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 {
|
|
@@ -1515,7 +1561,6 @@ const selectHiddenCategoryCount = (state) => {
|
|
|
1515
1561
|
};
|
|
1516
1562
|
const categoryReducer = categorySlice.reducer;
|
|
1517
1563
|
function setAttachments(state, action) {
|
|
1518
|
-
state.attachments = {};
|
|
1519
1564
|
for (const attachment of action.payload) {
|
|
1520
1565
|
state.attachments[attachment.offline_id] = attachment;
|
|
1521
1566
|
}
|
|
@@ -1670,9 +1715,6 @@ const selectAllComponentAttachments = createSelector(
|
|
|
1670
1715
|
[selectComponentAttachmentMapping],
|
|
1671
1716
|
(mapping) => Object.values(mapping)
|
|
1672
1717
|
);
|
|
1673
|
-
const selectComponentAttachment = (attachmentId) => (state) => {
|
|
1674
|
-
return state.componentReducer.attachments[attachmentId];
|
|
1675
|
-
};
|
|
1676
1718
|
const selectAttachmentsOfComponent = restructureCreateSelectorWithArgs(
|
|
1677
1719
|
createSelector(
|
|
1678
1720
|
[selectAllComponentAttachments, (_state, componentId) => componentId],
|
|
@@ -1962,9 +2004,6 @@ const selectAllComponentTypeAttachments = createSelector(
|
|
|
1962
2004
|
[selectComponentTypeAttachmentMapping],
|
|
1963
2005
|
(mapping) => Object.values(mapping)
|
|
1964
2006
|
);
|
|
1965
|
-
const selectComponentTypeAttachment = (attachmentId) => (state) => {
|
|
1966
|
-
return state.componentTypeReducer.attachments[attachmentId];
|
|
1967
|
-
};
|
|
1968
2007
|
const selectAttachmentsOfComponentType = restructureCreateSelectorWithArgs(
|
|
1969
2008
|
createSelector(
|
|
1970
2009
|
[selectAllComponentTypeAttachments, (_state, componentTypeId) => componentTypeId],
|
|
@@ -2359,9 +2398,6 @@ const selectAttachmentsOfIssue = restructureCreateSelectorWithArgs(
|
|
|
2359
2398
|
}
|
|
2360
2399
|
)
|
|
2361
2400
|
);
|
|
2362
|
-
const selectIssueAttachment = (attachmentId) => (root) => {
|
|
2363
|
-
return root.issueReducer.attachments[attachmentId];
|
|
2364
|
-
};
|
|
2365
2401
|
const selectAttachmentsOfIssueByType = restructureCreateSelectorWithArgs(
|
|
2366
2402
|
createSelector(
|
|
2367
2403
|
[selectIssueAttachments, (_state, issueId) => issueId],
|
|
@@ -3816,8 +3852,7 @@ const selectSortedEmailDomains = (state) => Object.values(state.emailDomainsRedu
|
|
|
3816
3852
|
);
|
|
3817
3853
|
const emailDomainsReducer = emailDomainsSlice.reducer;
|
|
3818
3854
|
const initialState$1 = {
|
|
3819
|
-
documents: {}
|
|
3820
|
-
attachments: {}
|
|
3855
|
+
documents: {}
|
|
3821
3856
|
};
|
|
3822
3857
|
const documentSlice = createSlice({
|
|
3823
3858
|
name: "documents",
|
|
@@ -3954,28 +3989,10 @@ const documentSlice = createSlice({
|
|
|
3954
3989
|
}
|
|
3955
3990
|
delete state.documents[documentId];
|
|
3956
3991
|
}
|
|
3957
|
-
}
|
|
3958
|
-
setDocumentAttachments: setAttachments,
|
|
3959
|
-
addDocumentAttachment: addAttachment,
|
|
3960
|
-
addDocumentAttachments: addAttachments,
|
|
3961
|
-
updateDocumentAttachment: updateAttachment,
|
|
3962
|
-
removeDocumentAttachment: removeAttachment,
|
|
3963
|
-
removeDocumentAttachments: removeAttachments
|
|
3992
|
+
}
|
|
3964
3993
|
}
|
|
3965
3994
|
});
|
|
3966
|
-
const {
|
|
3967
|
-
setDocuments,
|
|
3968
|
-
addDocuments,
|
|
3969
|
-
updateDocuments,
|
|
3970
|
-
moveDocument,
|
|
3971
|
-
removeDocuments,
|
|
3972
|
-
setDocumentAttachments,
|
|
3973
|
-
addDocumentAttachment,
|
|
3974
|
-
addDocumentAttachments,
|
|
3975
|
-
updateDocumentAttachment,
|
|
3976
|
-
removeDocumentAttachment,
|
|
3977
|
-
removeDocumentAttachments
|
|
3978
|
-
} = documentSlice.actions;
|
|
3995
|
+
const { setDocuments, addDocuments, updateDocuments, moveDocument, removeDocuments } = documentSlice.actions;
|
|
3979
3996
|
const selectDocumentsMapping = (state) => state.documentsReducer.documents;
|
|
3980
3997
|
const selectDocuments = createSelector(
|
|
3981
3998
|
[selectDocumentsMapping],
|
|
@@ -4005,39 +4022,6 @@ const selectRootDocuments = createSelector(
|
|
|
4005
4022
|
[selectDocuments],
|
|
4006
4023
|
(documents) => documents.filter((document2) => !document2.parent_document)
|
|
4007
4024
|
);
|
|
4008
|
-
const selectDocumentAttachmentMapping = (state) => state.documentsReducer.attachments;
|
|
4009
|
-
const selectAllDocumentAttachments = createSelector(
|
|
4010
|
-
[selectDocumentAttachmentMapping],
|
|
4011
|
-
(mapping) => Object.values(mapping)
|
|
4012
|
-
);
|
|
4013
|
-
const selectDocumentAttachment = (attachmentId) => (state) => {
|
|
4014
|
-
return state.documentsReducer.attachments[attachmentId];
|
|
4015
|
-
};
|
|
4016
|
-
const selectAttachmentsOfDocument = restructureCreateSelectorWithArgs(
|
|
4017
|
-
createSelector(
|
|
4018
|
-
[selectAllDocumentAttachments, (_state, documentId) => documentId],
|
|
4019
|
-
(attachments, documentId) => {
|
|
4020
|
-
return attachments.filter(({ document: document2 }) => documentId === document2);
|
|
4021
|
-
}
|
|
4022
|
-
)
|
|
4023
|
-
);
|
|
4024
|
-
const selectAttachmentsOfDocumentByType = restructureCreateSelectorWithArgs(
|
|
4025
|
-
createSelector(
|
|
4026
|
-
[selectAllDocumentAttachments, (_state, documentId) => documentId],
|
|
4027
|
-
(attachments, documentId) => {
|
|
4028
|
-
const attachmentsOfProject = attachments.filter(({ document: document2 }) => documentId === document2);
|
|
4029
|
-
const fileAttachments = attachmentsOfProject.filter(
|
|
4030
|
-
// this null check here is necessary, there are cases where file_type is null or undefined
|
|
4031
|
-
({ file_type }) => !file_type || !file_type.startsWith("image/")
|
|
4032
|
-
);
|
|
4033
|
-
const imageAttachments = attachmentsOfProject.filter(
|
|
4034
|
-
// this null check here is necessary, there are cases where file_type is null or undefined
|
|
4035
|
-
({ file_type }) => file_type && file_type.startsWith("image/")
|
|
4036
|
-
);
|
|
4037
|
-
return { fileAttachments, imageAttachments };
|
|
4038
|
-
}
|
|
4039
|
-
)
|
|
4040
|
-
);
|
|
4041
4025
|
const documentsReducer = documentSlice.reducer;
|
|
4042
4026
|
const initialState = {
|
|
4043
4027
|
version: 0
|
|
@@ -4239,35 +4223,6 @@ function extractResponseFromError(error2) {
|
|
|
4239
4223
|
}
|
|
4240
4224
|
return void 0;
|
|
4241
4225
|
}
|
|
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
4226
|
async function performRequest(action, client) {
|
|
4272
4227
|
async function checkToken() {
|
|
4273
4228
|
if (client.auth.tokenIsExpiringSoon()) {
|
|
@@ -4370,19 +4325,29 @@ async function performRequest(action, client) {
|
|
|
4370
4325
|
console.warn("No signed-in user to sign out.");
|
|
4371
4326
|
}
|
|
4372
4327
|
await client.auth.logout();
|
|
4373
|
-
throw new APIError(
|
|
4374
|
-
|
|
4328
|
+
throw new APIError({
|
|
4329
|
+
message: "You have been signed out due to inactivity.",
|
|
4330
|
+
response: errorResponse,
|
|
4331
|
+
discard: true,
|
|
4332
|
+
innerError: error2
|
|
4333
|
+
});
|
|
4334
|
+
}
|
|
4335
|
+
if (state.authReducer.isLoggedIn) {
|
|
4336
|
+
console.debug("Forbidden; renewing tokens and retrying.");
|
|
4337
|
+
await client.auth.renewTokens();
|
|
4338
|
+
console.debug("Successfully renewed tokens; retrying request.");
|
|
4339
|
+
return requestToSend.query(queryParams);
|
|
4340
|
+
} else {
|
|
4341
|
+
console.debug("Forbidden; user is not logged in.");
|
|
4342
|
+
throw new APIError({
|
|
4343
|
+
message: "Incorrect username or password.",
|
|
4344
|
+
response: errorResponse,
|
|
4345
|
+
discard: true,
|
|
4346
|
+
innerError: error2
|
|
4375
4347
|
});
|
|
4376
4348
|
}
|
|
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
4349
|
}
|
|
4382
|
-
|
|
4383
|
-
throw new APIError(apiErrorMessage, errorResponse, {
|
|
4384
|
-
discard: discardStatuses.includes(status)
|
|
4385
|
-
});
|
|
4350
|
+
throw new APIError({ response: errorResponse, innerError: error2, discard: discardStatuses.includes(status) });
|
|
4386
4351
|
}
|
|
4387
4352
|
}
|
|
4388
4353
|
class MiddlewareChainerPrivate {
|
|
@@ -4593,18 +4558,29 @@ class BaseApiService {
|
|
|
4593
4558
|
if (response) {
|
|
4594
4559
|
promise.resolve(response.body);
|
|
4595
4560
|
} else {
|
|
4596
|
-
const error2 = new APIError(
|
|
4597
|
-
"Could not get a response from the server.",
|
|
4561
|
+
const error2 = new APIError({
|
|
4562
|
+
message: "Could not get a response from the server.",
|
|
4598
4563
|
response,
|
|
4599
|
-
|
|
4600
|
-
|
|
4601
|
-
}
|
|
4602
|
-
);
|
|
4564
|
+
discard: true
|
|
4565
|
+
});
|
|
4603
4566
|
promise.reject(error2);
|
|
4604
4567
|
}
|
|
4605
4568
|
};
|
|
4606
4569
|
const errorHandler = (error2) => {
|
|
4607
|
-
error2
|
|
4570
|
+
if (error2 instanceof APIError) {
|
|
4571
|
+
error2.options.discard = true;
|
|
4572
|
+
} else {
|
|
4573
|
+
console.error(
|
|
4574
|
+
"Received an unexpected error while processing a request:",
|
|
4575
|
+
error2,
|
|
4576
|
+
"\nConverting error to APIError and discarding."
|
|
4577
|
+
);
|
|
4578
|
+
error2 = new APIError({
|
|
4579
|
+
message: "An error occurred while processing the request.",
|
|
4580
|
+
innerError: error2,
|
|
4581
|
+
discard: true
|
|
4582
|
+
});
|
|
4583
|
+
}
|
|
4608
4584
|
promise.reject(error2);
|
|
4609
4585
|
};
|
|
4610
4586
|
innerPromise.then(successOrUndefinedHandler, errorHandler);
|
|
@@ -4626,8 +4602,7 @@ class AttachmentService extends BaseApiService {
|
|
|
4626
4602
|
issue_attachments: Object.values(state.issueReducer.attachments),
|
|
4627
4603
|
component_attachments: Object.values(state.componentReducer.attachments),
|
|
4628
4604
|
component_type_attachments: Object.values(state.componentTypeReducer.attachments),
|
|
4629
|
-
project_attachments: Object.values(state.projectReducer.attachments)
|
|
4630
|
-
document_attachments: Object.values(state.documentsReducer.attachments)
|
|
4605
|
+
project_attachments: Object.values(state.projectReducer.attachments)
|
|
4631
4606
|
};
|
|
4632
4607
|
return [allAttachments, promise];
|
|
4633
4608
|
}
|
|
@@ -4731,8 +4706,8 @@ class AttachmentService extends BaseApiService {
|
|
|
4731
4706
|
});
|
|
4732
4707
|
return [offlineAttachment, promise];
|
|
4733
4708
|
}
|
|
4734
|
-
async
|
|
4735
|
-
const { description: description2,
|
|
4709
|
+
async addProjectAttachment(attachmentPayload) {
|
|
4710
|
+
const { description: description2, project, file_sha1, offline_id } = attachmentPayload;
|
|
4736
4711
|
if (!attachmentPayload.file.objectURL) {
|
|
4737
4712
|
throw new Error("Expected attachmentPayload.file.objectURL to be defined.");
|
|
4738
4713
|
}
|
|
@@ -4745,24 +4720,24 @@ class AttachmentService extends BaseApiService {
|
|
|
4745
4720
|
created_by: this.client.store.getState().userReducer.currentUser.id
|
|
4746
4721
|
};
|
|
4747
4722
|
await this.client.files.addCache(attachmentPayload.file, file_sha1);
|
|
4748
|
-
this.client.store.dispatch(
|
|
4723
|
+
this.client.store.dispatch(addProjectAttachment(offlineAttachment));
|
|
4749
4724
|
const [fileProps] = await this.client.files.uploadFileToS3(file_sha1);
|
|
4750
4725
|
const promise = this.enqueueRequest({
|
|
4751
4726
|
description: "Create attachment",
|
|
4752
4727
|
method: HttpMethod.POST,
|
|
4753
|
-
url: `/
|
|
4754
|
-
blocks: [offline_id,
|
|
4728
|
+
url: `/projects/${project}/attach/`,
|
|
4729
|
+
blocks: [offline_id, project.toString()],
|
|
4755
4730
|
blockers: [file_sha1],
|
|
4756
4731
|
payload: {
|
|
4757
4732
|
offline_id,
|
|
4758
|
-
|
|
4733
|
+
project,
|
|
4759
4734
|
description: description2 ?? "",
|
|
4760
4735
|
submitted_at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
4761
4736
|
...fileProps
|
|
4762
4737
|
}
|
|
4763
4738
|
});
|
|
4764
4739
|
promise.catch((error2) => {
|
|
4765
|
-
this.client.store.dispatch(
|
|
4740
|
+
this.client.store.dispatch(removeProjectAttachment(offlineAttachment.offline_id));
|
|
4766
4741
|
throw error2;
|
|
4767
4742
|
});
|
|
4768
4743
|
return [offlineAttachment, promise];
|
|
@@ -4833,7 +4808,7 @@ class AttachmentService extends BaseApiService {
|
|
|
4833
4808
|
return photoAttachmentPromise(file);
|
|
4834
4809
|
});
|
|
4835
4810
|
}
|
|
4836
|
-
|
|
4811
|
+
attachFilesToProject(filesToSubmit, projectId) {
|
|
4837
4812
|
return filesToSubmit.map((file) => {
|
|
4838
4813
|
if (!(file instanceof File)) {
|
|
4839
4814
|
throw new Error("Expected a File instance.");
|
|
@@ -4844,12 +4819,12 @@ class AttachmentService extends BaseApiService {
|
|
|
4844
4819
|
file: file2,
|
|
4845
4820
|
file_name: file2.name,
|
|
4846
4821
|
file_type: file2.type,
|
|
4847
|
-
|
|
4822
|
+
project: projectId,
|
|
4848
4823
|
file_sha1: hash,
|
|
4849
4824
|
submitted_at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
4850
4825
|
created_by: this.client.store.getState().userReducer.currentUser.id
|
|
4851
4826
|
});
|
|
4852
|
-
return this.
|
|
4827
|
+
return this.addProjectAttachment(attachment);
|
|
4853
4828
|
};
|
|
4854
4829
|
return photoAttachmentPromise(file);
|
|
4855
4830
|
});
|
|
@@ -5029,9 +5004,9 @@ class AttachmentService extends BaseApiService {
|
|
|
5029
5004
|
const promise = performRequest2();
|
|
5030
5005
|
return [offlineAttachment, promise];
|
|
5031
5006
|
}
|
|
5032
|
-
async
|
|
5007
|
+
async replaceProjectAttachmentFile(attachmentId, newFile) {
|
|
5033
5008
|
const { store } = this.client;
|
|
5034
|
-
const attachment = store.getState().
|
|
5009
|
+
const attachment = store.getState().projectReducer.attachments[attachmentId];
|
|
5035
5010
|
if (!attachment)
|
|
5036
5011
|
throw new Error(`Attachment ${attachmentId} not found`);
|
|
5037
5012
|
let oldFile = void 0;
|
|
@@ -5045,7 +5020,7 @@ class AttachmentService extends BaseApiService {
|
|
|
5045
5020
|
throw new Error(`newFile["objectURL"] is unexpectedly ${newFile.objectURL}`);
|
|
5046
5021
|
}
|
|
5047
5022
|
store.dispatch(
|
|
5048
|
-
|
|
5023
|
+
updateProjectAttachment({
|
|
5049
5024
|
...attachment,
|
|
5050
5025
|
file_sha1: newSha1,
|
|
5051
5026
|
file: URL.createObjectURL(newFile)
|
|
@@ -5053,13 +5028,13 @@ class AttachmentService extends BaseApiService {
|
|
|
5053
5028
|
);
|
|
5054
5029
|
await this.client.files.addCache(newFile, newSha1);
|
|
5055
5030
|
const [fileProps] = await this.client.files.uploadFileToS3(newSha1).catch((e) => {
|
|
5056
|
-
store.dispatch(
|
|
5031
|
+
store.dispatch(updateProjectAttachment(attachment));
|
|
5057
5032
|
throw e;
|
|
5058
5033
|
});
|
|
5059
5034
|
const promise2 = this.enqueueRequest({
|
|
5060
5035
|
description: "Edit attachment",
|
|
5061
5036
|
method: HttpMethod.PATCH,
|
|
5062
|
-
url: `/attachments/
|
|
5037
|
+
url: `/attachments/projects/${attachment.offline_id}/`,
|
|
5063
5038
|
isResponseBlob: false,
|
|
5064
5039
|
payload: fileProps,
|
|
5065
5040
|
blockers: [attachmentId, newSha1],
|
|
@@ -5072,7 +5047,7 @@ class AttachmentService extends BaseApiService {
|
|
|
5072
5047
|
} catch (e) {
|
|
5073
5048
|
if (oldFile) {
|
|
5074
5049
|
store.dispatch(
|
|
5075
|
-
|
|
5050
|
+
updateProjectAttachment({
|
|
5076
5051
|
...attachment,
|
|
5077
5052
|
file_sha1: attachment.file_sha1,
|
|
5078
5053
|
file: URL.createObjectURL(oldFile)
|
|
@@ -5142,20 +5117,20 @@ class AttachmentService extends BaseApiService {
|
|
|
5142
5117
|
blocks: [componentTypeAttachmentId]
|
|
5143
5118
|
});
|
|
5144
5119
|
}
|
|
5145
|
-
|
|
5120
|
+
deleteProjectAttachment(projectAttachmentId) {
|
|
5146
5121
|
const { store } = this.client;
|
|
5147
|
-
const attachment = store.getState()
|
|
5122
|
+
const attachment = selectProjectAttachmentMapping(store.getState())[projectAttachmentId];
|
|
5148
5123
|
if (!attachment) {
|
|
5149
|
-
throw new Error(`Attachment ${
|
|
5124
|
+
throw new Error(`Attachment ${projectAttachmentId} not found`);
|
|
5150
5125
|
}
|
|
5151
|
-
store.dispatch(
|
|
5126
|
+
store.dispatch(removeProjectAttachment(projectAttachmentId));
|
|
5152
5127
|
void this.client.files.removeCache(attachment.file_sha1);
|
|
5153
5128
|
return this.enqueueRequest({
|
|
5154
|
-
description: "Delete
|
|
5129
|
+
description: "Delete attachment",
|
|
5155
5130
|
method: HttpMethod.DELETE,
|
|
5156
|
-
url: `/attachments/
|
|
5157
|
-
blockers: [
|
|
5158
|
-
blocks: [
|
|
5131
|
+
url: `/attachments/projects/${projectAttachmentId}/`,
|
|
5132
|
+
blockers: [projectAttachmentId],
|
|
5133
|
+
blocks: [projectAttachmentId]
|
|
5159
5134
|
});
|
|
5160
5135
|
}
|
|
5161
5136
|
}
|
|
@@ -5185,24 +5160,23 @@ class AuthService extends BaseApiService {
|
|
|
5185
5160
|
*/
|
|
5186
5161
|
__publicField(this, "_getTokenPair", (credentials, logoutOnFailure = true) => {
|
|
5187
5162
|
const uuid = v4();
|
|
5188
|
-
|
|
5189
|
-
|
|
5190
|
-
|
|
5191
|
-
|
|
5192
|
-
|
|
5193
|
-
|
|
5194
|
-
|
|
5195
|
-
|
|
5196
|
-
|
|
5197
|
-
|
|
5198
|
-
|
|
5199
|
-
return [responsePromise.then(parseTokens), uuid];
|
|
5200
|
-
} catch (e) {
|
|
5163
|
+
const responsePromise = this.enqueueRequest({
|
|
5164
|
+
uuid,
|
|
5165
|
+
description: "Get token pair",
|
|
5166
|
+
method: HttpMethod.POST,
|
|
5167
|
+
url: "/api/token/",
|
|
5168
|
+
payload: credentials,
|
|
5169
|
+
isAuthNeeded: false,
|
|
5170
|
+
checkAuth: false,
|
|
5171
|
+
blockers: [],
|
|
5172
|
+
blocks: []
|
|
5173
|
+
}).then(parseTokens).catch((e) => {
|
|
5201
5174
|
if (logoutOnFailure) {
|
|
5202
5175
|
void this.logout().then();
|
|
5203
5176
|
}
|
|
5204
5177
|
throw e;
|
|
5205
|
-
}
|
|
5178
|
+
});
|
|
5179
|
+
return [responsePromise, uuid];
|
|
5206
5180
|
});
|
|
5207
5181
|
/**
|
|
5208
5182
|
* Takes refresh token and gets a new token pair
|
|
@@ -5263,7 +5237,7 @@ class AuthService extends BaseApiService {
|
|
|
5263
5237
|
timedOut = true;
|
|
5264
5238
|
store.dispatch(markForDeletion(uuid));
|
|
5265
5239
|
store.dispatch(markForDeletion(initialDataUuid));
|
|
5266
|
-
reject(new
|
|
5240
|
+
reject(new APIError({ message: `Request timed out after ${timeout} seconds` }));
|
|
5267
5241
|
}, timeout * 1e3);
|
|
5268
5242
|
});
|
|
5269
5243
|
const successPromise = promise.then((tokens) => {
|
|
@@ -6393,18 +6367,11 @@ class MainService extends BaseApiService {
|
|
|
6393
6367
|
if (currentProjectId) {
|
|
6394
6368
|
const [_offlineAttachments, promise] = this.client.attachments.fetchAll(currentProjectId);
|
|
6395
6369
|
void promise.then((result) => {
|
|
6396
|
-
const {
|
|
6397
|
-
issue_attachments,
|
|
6398
|
-
component_type_attachments,
|
|
6399
|
-
component_attachments,
|
|
6400
|
-
project_attachments,
|
|
6401
|
-
document_attachments
|
|
6402
|
-
} = result;
|
|
6370
|
+
const { issue_attachments, component_type_attachments, component_attachments, project_attachments } = result;
|
|
6403
6371
|
store.dispatch(setIssueAttachments(issue_attachments));
|
|
6404
6372
|
store.dispatch(setComponentAttachments(component_attachments));
|
|
6405
6373
|
store.dispatch(setComponentTypeAttachments(component_type_attachments));
|
|
6406
6374
|
store.dispatch(setProjectAttachments(project_attachments));
|
|
6407
|
-
store.dispatch(setDocumentAttachments(document_attachments));
|
|
6408
6375
|
});
|
|
6409
6376
|
void this.client.documents.refreshStore();
|
|
6410
6377
|
void this.client.issueUpdates.refreshStore();
|
|
@@ -7239,8 +7206,7 @@ class OrganizationAccessService extends BaseApiService {
|
|
|
7239
7206
|
blockers: [],
|
|
7240
7207
|
blocks: []
|
|
7241
7208
|
});
|
|
7242
|
-
|
|
7243
|
-
store.dispatch(setOrganizationAccesses(organizationAccesses));
|
|
7209
|
+
store.dispatch(setOrganizationAccesses(result));
|
|
7244
7210
|
}
|
|
7245
7211
|
}
|
|
7246
7212
|
const cachedRequestPromises = {};
|
|
@@ -15665,8 +15631,6 @@ export {
|
|
|
15665
15631
|
addComponentTypeAttachment,
|
|
15666
15632
|
addComponentTypeAttachments,
|
|
15667
15633
|
addComponentsInBatches,
|
|
15668
|
-
addDocumentAttachment,
|
|
15669
|
-
addDocumentAttachments,
|
|
15670
15634
|
addDocuments,
|
|
15671
15635
|
addEmailDomain,
|
|
15672
15636
|
addFavouriteProjectId,
|
|
@@ -15830,8 +15794,6 @@ export {
|
|
|
15830
15794
|
removeComponentAttachments,
|
|
15831
15795
|
removeComponentTypeAttachment,
|
|
15832
15796
|
removeComponentTypeAttachments,
|
|
15833
|
-
removeDocumentAttachment,
|
|
15834
|
-
removeDocumentAttachments,
|
|
15835
15797
|
removeDocuments,
|
|
15836
15798
|
removeEmailDomain,
|
|
15837
15799
|
removeFavouriteProjectId,
|
|
@@ -15879,7 +15841,6 @@ export {
|
|
|
15879
15841
|
selectAllAttachments,
|
|
15880
15842
|
selectAllComponentAttachments,
|
|
15881
15843
|
selectAllComponentTypeAttachments,
|
|
15882
|
-
selectAllDocumentAttachments,
|
|
15883
15844
|
selectAllProjectAttachments,
|
|
15884
15845
|
selectAncestorIdsOfDocument,
|
|
15885
15846
|
selectAppearance,
|
|
@@ -15887,8 +15848,6 @@ export {
|
|
|
15887
15848
|
selectAttachmentsOfComponentByType,
|
|
15888
15849
|
selectAttachmentsOfComponentType,
|
|
15889
15850
|
selectAttachmentsOfComponentTypeByType,
|
|
15890
|
-
selectAttachmentsOfDocument,
|
|
15891
|
-
selectAttachmentsOfDocumentByType,
|
|
15892
15851
|
selectAttachmentsOfIssue,
|
|
15893
15852
|
selectAttachmentsOfIssueByType,
|
|
15894
15853
|
selectAttachmentsOfProject,
|
|
@@ -15904,11 +15863,9 @@ export {
|
|
|
15904
15863
|
selectCompletedStageIdsForComponent,
|
|
15905
15864
|
selectCompletedStages,
|
|
15906
15865
|
selectComponent,
|
|
15907
|
-
selectComponentAttachment,
|
|
15908
15866
|
selectComponentAttachmentMapping,
|
|
15909
15867
|
selectComponentSubmissionMapping,
|
|
15910
15868
|
selectComponentType,
|
|
15911
|
-
selectComponentTypeAttachment,
|
|
15912
15869
|
selectComponentTypeAttachmentMapping,
|
|
15913
15870
|
selectComponentTypeForm,
|
|
15914
15871
|
selectComponentTypeFromComponent,
|
|
@@ -15926,8 +15883,6 @@ export {
|
|
|
15926
15883
|
selectCurrentUser,
|
|
15927
15884
|
selectDeletedRequests,
|
|
15928
15885
|
selectDocument,
|
|
15929
|
-
selectDocumentAttachment,
|
|
15930
|
-
selectDocumentAttachmentMapping,
|
|
15931
15886
|
selectDocuments,
|
|
15932
15887
|
selectDocumentsMapping,
|
|
15933
15888
|
selectEmailDomainsAsMapping,
|
|
@@ -15949,7 +15904,6 @@ export {
|
|
|
15949
15904
|
selectIsLoading,
|
|
15950
15905
|
selectIsLoggedIn,
|
|
15951
15906
|
selectIssue,
|
|
15952
|
-
selectIssueAttachment,
|
|
15953
15907
|
selectIssueAttachmentMapping,
|
|
15954
15908
|
selectIssueAttachments,
|
|
15955
15909
|
selectIssueMapping,
|
|
@@ -16043,7 +15997,6 @@ export {
|
|
|
16043
15997
|
setComponents,
|
|
16044
15998
|
setCreateProjectType,
|
|
16045
15999
|
setCurrentUser,
|
|
16046
|
-
setDocumentAttachments,
|
|
16047
16000
|
setDocuments,
|
|
16048
16001
|
setEmailDomains,
|
|
16049
16002
|
setEnableClustering,
|
|
@@ -16098,7 +16051,6 @@ export {
|
|
|
16098
16051
|
updateComponent,
|
|
16099
16052
|
updateComponentAttachment,
|
|
16100
16053
|
updateComponentTypeAttachment,
|
|
16101
|
-
updateDocumentAttachment,
|
|
16102
16054
|
updateDocuments,
|
|
16103
16055
|
updateIssue,
|
|
16104
16056
|
updateIssueAttachment,
|