@overmap-ai/core 1.0.50-document-attachments.1 → 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 -177
- package/dist/overmap-core.js.map +1 -1
- package/dist/overmap-core.umd.cjs +133 -177
- 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/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],
|
|
@@ -2356,9 +2398,6 @@ const selectAttachmentsOfIssue = restructureCreateSelectorWithArgs(
|
|
|
2356
2398
|
}
|
|
2357
2399
|
)
|
|
2358
2400
|
);
|
|
2359
|
-
const selectIssueAttachment = (attachmentId) => (root) => {
|
|
2360
|
-
return root.issueReducer.attachments[attachmentId];
|
|
2361
|
-
};
|
|
2362
2401
|
const selectAttachmentsOfIssueByType = restructureCreateSelectorWithArgs(
|
|
2363
2402
|
createSelector(
|
|
2364
2403
|
[selectIssueAttachments, (_state, issueId) => issueId],
|
|
@@ -3813,8 +3852,7 @@ const selectSortedEmailDomains = (state) => Object.values(state.emailDomainsRedu
|
|
|
3813
3852
|
);
|
|
3814
3853
|
const emailDomainsReducer = emailDomainsSlice.reducer;
|
|
3815
3854
|
const initialState$1 = {
|
|
3816
|
-
documents: {}
|
|
3817
|
-
attachments: {}
|
|
3855
|
+
documents: {}
|
|
3818
3856
|
};
|
|
3819
3857
|
const documentSlice = createSlice({
|
|
3820
3858
|
name: "documents",
|
|
@@ -3951,28 +3989,10 @@ const documentSlice = createSlice({
|
|
|
3951
3989
|
}
|
|
3952
3990
|
delete state.documents[documentId];
|
|
3953
3991
|
}
|
|
3954
|
-
}
|
|
3955
|
-
setDocumentAttachments: setAttachments,
|
|
3956
|
-
addDocumentAttachment: addAttachment,
|
|
3957
|
-
addDocumentAttachments: addAttachments,
|
|
3958
|
-
updateDocumentAttachment: updateAttachment,
|
|
3959
|
-
removeDocumentAttachment: removeAttachment,
|
|
3960
|
-
removeDocumentAttachments: removeAttachments
|
|
3992
|
+
}
|
|
3961
3993
|
}
|
|
3962
3994
|
});
|
|
3963
|
-
const {
|
|
3964
|
-
setDocuments,
|
|
3965
|
-
addDocuments,
|
|
3966
|
-
updateDocuments,
|
|
3967
|
-
moveDocument,
|
|
3968
|
-
removeDocuments,
|
|
3969
|
-
setDocumentAttachments,
|
|
3970
|
-
addDocumentAttachment,
|
|
3971
|
-
addDocumentAttachments,
|
|
3972
|
-
updateDocumentAttachment,
|
|
3973
|
-
removeDocumentAttachment,
|
|
3974
|
-
removeDocumentAttachments
|
|
3975
|
-
} = documentSlice.actions;
|
|
3995
|
+
const { setDocuments, addDocuments, updateDocuments, moveDocument, removeDocuments } = documentSlice.actions;
|
|
3976
3996
|
const selectDocumentsMapping = (state) => state.documentsReducer.documents;
|
|
3977
3997
|
const selectDocuments = createSelector(
|
|
3978
3998
|
[selectDocumentsMapping],
|
|
@@ -4002,39 +4022,6 @@ const selectRootDocuments = createSelector(
|
|
|
4002
4022
|
[selectDocuments],
|
|
4003
4023
|
(documents) => documents.filter((document2) => !document2.parent_document)
|
|
4004
4024
|
);
|
|
4005
|
-
const selectDocumentAttachmentMapping = (state) => state.documentsReducer.attachments;
|
|
4006
|
-
const selectAllDocumentAttachments = createSelector(
|
|
4007
|
-
[selectDocumentAttachmentMapping],
|
|
4008
|
-
(mapping) => Object.values(mapping)
|
|
4009
|
-
);
|
|
4010
|
-
const selectDocumentAttachment = (attachmentId) => (state) => {
|
|
4011
|
-
return state.documentsReducer.attachments[attachmentId];
|
|
4012
|
-
};
|
|
4013
|
-
const selectAttachmentsOfDocument = restructureCreateSelectorWithArgs(
|
|
4014
|
-
createSelector(
|
|
4015
|
-
[selectAllDocumentAttachments, (_state, documentId) => documentId],
|
|
4016
|
-
(attachments, documentId) => {
|
|
4017
|
-
return attachments.filter(({ document: document2 }) => documentId === document2);
|
|
4018
|
-
}
|
|
4019
|
-
)
|
|
4020
|
-
);
|
|
4021
|
-
const selectAttachmentsOfDocumentByType = restructureCreateSelectorWithArgs(
|
|
4022
|
-
createSelector(
|
|
4023
|
-
[selectAllDocumentAttachments, (_state, documentId) => documentId],
|
|
4024
|
-
(attachments, documentId) => {
|
|
4025
|
-
const attachmentsOfProject = attachments.filter(({ document: document2 }) => documentId === document2);
|
|
4026
|
-
const fileAttachments = attachmentsOfProject.filter(
|
|
4027
|
-
// this null check here is necessary, there are cases where file_type is null or undefined
|
|
4028
|
-
({ file_type }) => !file_type || !file_type.startsWith("image/")
|
|
4029
|
-
);
|
|
4030
|
-
const imageAttachments = attachmentsOfProject.filter(
|
|
4031
|
-
// this null check here is necessary, there are cases where file_type is null or undefined
|
|
4032
|
-
({ file_type }) => file_type && file_type.startsWith("image/")
|
|
4033
|
-
);
|
|
4034
|
-
return { fileAttachments, imageAttachments };
|
|
4035
|
-
}
|
|
4036
|
-
)
|
|
4037
|
-
);
|
|
4038
4025
|
const documentsReducer = documentSlice.reducer;
|
|
4039
4026
|
const initialState = {
|
|
4040
4027
|
version: 0
|
|
@@ -4236,35 +4223,6 @@ function extractResponseFromError(error2) {
|
|
|
4236
4223
|
}
|
|
4237
4224
|
return void 0;
|
|
4238
4225
|
}
|
|
4239
|
-
function extractErrorMessage(errorRes, err) {
|
|
4240
|
-
if (errorRes == null ? void 0 : errorRes.body) {
|
|
4241
|
-
if (typeof errorRes.body === "object") {
|
|
4242
|
-
if (typeof errorRes.body.error === "string")
|
|
4243
|
-
return errorRes.body.error;
|
|
4244
|
-
if (typeof errorRes.body.message === "string")
|
|
4245
|
-
return errorRes.body.message;
|
|
4246
|
-
try {
|
|
4247
|
-
return Object.entries(errorRes.body).map(([key, value]) => {
|
|
4248
|
-
if (typeof value === "string") {
|
|
4249
|
-
return `${key}: ${value}`;
|
|
4250
|
-
}
|
|
4251
|
-
if (Array.isArray(value)) {
|
|
4252
|
-
return value.map((v) => `${key}: ${v}`).join("\n");
|
|
4253
|
-
}
|
|
4254
|
-
return `${key}: ${JSON.stringify(value)}`;
|
|
4255
|
-
}).join("\n");
|
|
4256
|
-
} catch (e) {
|
|
4257
|
-
console.error("Failed to extract error message from response body", e);
|
|
4258
|
-
}
|
|
4259
|
-
} else if (typeof errorRes.body === "string")
|
|
4260
|
-
return errorRes.body;
|
|
4261
|
-
} else if (errorRes == null ? void 0 : errorRes.text) {
|
|
4262
|
-
return errorRes.text;
|
|
4263
|
-
} else if (err instanceof Error) {
|
|
4264
|
-
return err.message;
|
|
4265
|
-
}
|
|
4266
|
-
return void 0;
|
|
4267
|
-
}
|
|
4268
4226
|
async function performRequest(action, client) {
|
|
4269
4227
|
async function checkToken() {
|
|
4270
4228
|
if (client.auth.tokenIsExpiringSoon()) {
|
|
@@ -4367,19 +4325,29 @@ async function performRequest(action, client) {
|
|
|
4367
4325
|
console.warn("No signed-in user to sign out.");
|
|
4368
4326
|
}
|
|
4369
4327
|
await client.auth.logout();
|
|
4370
|
-
throw new APIError(
|
|
4371
|
-
|
|
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
|
|
4372
4347
|
});
|
|
4373
4348
|
}
|
|
4374
|
-
console.debug("Forbidden; renewing tokens and retrying.");
|
|
4375
|
-
await client.auth.renewTokens();
|
|
4376
|
-
console.debug("Successfully renewed tokens; retrying request.");
|
|
4377
|
-
return requestToSend.query(queryParams);
|
|
4378
4349
|
}
|
|
4379
|
-
|
|
4380
|
-
throw new APIError(apiErrorMessage, errorResponse, {
|
|
4381
|
-
discard: discardStatuses.includes(status)
|
|
4382
|
-
});
|
|
4350
|
+
throw new APIError({ response: errorResponse, innerError: error2, discard: discardStatuses.includes(status) });
|
|
4383
4351
|
}
|
|
4384
4352
|
}
|
|
4385
4353
|
class MiddlewareChainerPrivate {
|
|
@@ -4590,18 +4558,29 @@ class BaseApiService {
|
|
|
4590
4558
|
if (response) {
|
|
4591
4559
|
promise.resolve(response.body);
|
|
4592
4560
|
} else {
|
|
4593
|
-
const error2 = new APIError(
|
|
4594
|
-
"Could not get a response from the server.",
|
|
4561
|
+
const error2 = new APIError({
|
|
4562
|
+
message: "Could not get a response from the server.",
|
|
4595
4563
|
response,
|
|
4596
|
-
|
|
4597
|
-
|
|
4598
|
-
}
|
|
4599
|
-
);
|
|
4564
|
+
discard: true
|
|
4565
|
+
});
|
|
4600
4566
|
promise.reject(error2);
|
|
4601
4567
|
}
|
|
4602
4568
|
};
|
|
4603
4569
|
const errorHandler = (error2) => {
|
|
4604
|
-
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
|
+
}
|
|
4605
4584
|
promise.reject(error2);
|
|
4606
4585
|
};
|
|
4607
4586
|
innerPromise.then(successOrUndefinedHandler, errorHandler);
|
|
@@ -4623,8 +4602,7 @@ class AttachmentService extends BaseApiService {
|
|
|
4623
4602
|
issue_attachments: Object.values(state.issueReducer.attachments),
|
|
4624
4603
|
component_attachments: Object.values(state.componentReducer.attachments),
|
|
4625
4604
|
component_type_attachments: Object.values(state.componentTypeReducer.attachments),
|
|
4626
|
-
project_attachments: Object.values(state.projectReducer.attachments)
|
|
4627
|
-
document_attachments: Object.values(state.documentsReducer.attachments)
|
|
4605
|
+
project_attachments: Object.values(state.projectReducer.attachments)
|
|
4628
4606
|
};
|
|
4629
4607
|
return [allAttachments, promise];
|
|
4630
4608
|
}
|
|
@@ -4728,8 +4706,8 @@ class AttachmentService extends BaseApiService {
|
|
|
4728
4706
|
});
|
|
4729
4707
|
return [offlineAttachment, promise];
|
|
4730
4708
|
}
|
|
4731
|
-
async
|
|
4732
|
-
const { description: description2,
|
|
4709
|
+
async addProjectAttachment(attachmentPayload) {
|
|
4710
|
+
const { description: description2, project, file_sha1, offline_id } = attachmentPayload;
|
|
4733
4711
|
if (!attachmentPayload.file.objectURL) {
|
|
4734
4712
|
throw new Error("Expected attachmentPayload.file.objectURL to be defined.");
|
|
4735
4713
|
}
|
|
@@ -4742,24 +4720,24 @@ class AttachmentService extends BaseApiService {
|
|
|
4742
4720
|
created_by: this.client.store.getState().userReducer.currentUser.id
|
|
4743
4721
|
};
|
|
4744
4722
|
await this.client.files.addCache(attachmentPayload.file, file_sha1);
|
|
4745
|
-
this.client.store.dispatch(
|
|
4723
|
+
this.client.store.dispatch(addProjectAttachment(offlineAttachment));
|
|
4746
4724
|
const [fileProps] = await this.client.files.uploadFileToS3(file_sha1);
|
|
4747
4725
|
const promise = this.enqueueRequest({
|
|
4748
4726
|
description: "Create attachment",
|
|
4749
4727
|
method: HttpMethod.POST,
|
|
4750
|
-
url: `/
|
|
4751
|
-
blocks: [offline_id,
|
|
4728
|
+
url: `/projects/${project}/attach/`,
|
|
4729
|
+
blocks: [offline_id, project.toString()],
|
|
4752
4730
|
blockers: [file_sha1],
|
|
4753
4731
|
payload: {
|
|
4754
4732
|
offline_id,
|
|
4755
|
-
|
|
4733
|
+
project,
|
|
4756
4734
|
description: description2 ?? "",
|
|
4757
4735
|
submitted_at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
4758
4736
|
...fileProps
|
|
4759
4737
|
}
|
|
4760
4738
|
});
|
|
4761
4739
|
promise.catch((error2) => {
|
|
4762
|
-
this.client.store.dispatch(
|
|
4740
|
+
this.client.store.dispatch(removeProjectAttachment(offlineAttachment.offline_id));
|
|
4763
4741
|
throw error2;
|
|
4764
4742
|
});
|
|
4765
4743
|
return [offlineAttachment, promise];
|
|
@@ -4830,7 +4808,7 @@ class AttachmentService extends BaseApiService {
|
|
|
4830
4808
|
return photoAttachmentPromise(file);
|
|
4831
4809
|
});
|
|
4832
4810
|
}
|
|
4833
|
-
|
|
4811
|
+
attachFilesToProject(filesToSubmit, projectId) {
|
|
4834
4812
|
return filesToSubmit.map((file) => {
|
|
4835
4813
|
if (!(file instanceof File)) {
|
|
4836
4814
|
throw new Error("Expected a File instance.");
|
|
@@ -4841,12 +4819,12 @@ class AttachmentService extends BaseApiService {
|
|
|
4841
4819
|
file: file2,
|
|
4842
4820
|
file_name: file2.name,
|
|
4843
4821
|
file_type: file2.type,
|
|
4844
|
-
|
|
4822
|
+
project: projectId,
|
|
4845
4823
|
file_sha1: hash,
|
|
4846
4824
|
submitted_at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
4847
4825
|
created_by: this.client.store.getState().userReducer.currentUser.id
|
|
4848
4826
|
});
|
|
4849
|
-
return this.
|
|
4827
|
+
return this.addProjectAttachment(attachment);
|
|
4850
4828
|
};
|
|
4851
4829
|
return photoAttachmentPromise(file);
|
|
4852
4830
|
});
|
|
@@ -5026,9 +5004,9 @@ class AttachmentService extends BaseApiService {
|
|
|
5026
5004
|
const promise = performRequest2();
|
|
5027
5005
|
return [offlineAttachment, promise];
|
|
5028
5006
|
}
|
|
5029
|
-
async
|
|
5007
|
+
async replaceProjectAttachmentFile(attachmentId, newFile) {
|
|
5030
5008
|
const { store } = this.client;
|
|
5031
|
-
const attachment = store.getState().
|
|
5009
|
+
const attachment = store.getState().projectReducer.attachments[attachmentId];
|
|
5032
5010
|
if (!attachment)
|
|
5033
5011
|
throw new Error(`Attachment ${attachmentId} not found`);
|
|
5034
5012
|
let oldFile = void 0;
|
|
@@ -5042,7 +5020,7 @@ class AttachmentService extends BaseApiService {
|
|
|
5042
5020
|
throw new Error(`newFile["objectURL"] is unexpectedly ${newFile.objectURL}`);
|
|
5043
5021
|
}
|
|
5044
5022
|
store.dispatch(
|
|
5045
|
-
|
|
5023
|
+
updateProjectAttachment({
|
|
5046
5024
|
...attachment,
|
|
5047
5025
|
file_sha1: newSha1,
|
|
5048
5026
|
file: URL.createObjectURL(newFile)
|
|
@@ -5050,13 +5028,13 @@ class AttachmentService extends BaseApiService {
|
|
|
5050
5028
|
);
|
|
5051
5029
|
await this.client.files.addCache(newFile, newSha1);
|
|
5052
5030
|
const [fileProps] = await this.client.files.uploadFileToS3(newSha1).catch((e) => {
|
|
5053
|
-
store.dispatch(
|
|
5031
|
+
store.dispatch(updateProjectAttachment(attachment));
|
|
5054
5032
|
throw e;
|
|
5055
5033
|
});
|
|
5056
5034
|
const promise2 = this.enqueueRequest({
|
|
5057
5035
|
description: "Edit attachment",
|
|
5058
5036
|
method: HttpMethod.PATCH,
|
|
5059
|
-
url: `/attachments/
|
|
5037
|
+
url: `/attachments/projects/${attachment.offline_id}/`,
|
|
5060
5038
|
isResponseBlob: false,
|
|
5061
5039
|
payload: fileProps,
|
|
5062
5040
|
blockers: [attachmentId, newSha1],
|
|
@@ -5069,7 +5047,7 @@ class AttachmentService extends BaseApiService {
|
|
|
5069
5047
|
} catch (e) {
|
|
5070
5048
|
if (oldFile) {
|
|
5071
5049
|
store.dispatch(
|
|
5072
|
-
|
|
5050
|
+
updateProjectAttachment({
|
|
5073
5051
|
...attachment,
|
|
5074
5052
|
file_sha1: attachment.file_sha1,
|
|
5075
5053
|
file: URL.createObjectURL(oldFile)
|
|
@@ -5139,20 +5117,20 @@ class AttachmentService extends BaseApiService {
|
|
|
5139
5117
|
blocks: [componentTypeAttachmentId]
|
|
5140
5118
|
});
|
|
5141
5119
|
}
|
|
5142
|
-
|
|
5120
|
+
deleteProjectAttachment(projectAttachmentId) {
|
|
5143
5121
|
const { store } = this.client;
|
|
5144
|
-
const attachment = store.getState()
|
|
5122
|
+
const attachment = selectProjectAttachmentMapping(store.getState())[projectAttachmentId];
|
|
5145
5123
|
if (!attachment) {
|
|
5146
|
-
throw new Error(`Attachment ${
|
|
5124
|
+
throw new Error(`Attachment ${projectAttachmentId} not found`);
|
|
5147
5125
|
}
|
|
5148
|
-
store.dispatch(
|
|
5126
|
+
store.dispatch(removeProjectAttachment(projectAttachmentId));
|
|
5149
5127
|
void this.client.files.removeCache(attachment.file_sha1);
|
|
5150
5128
|
return this.enqueueRequest({
|
|
5151
|
-
description: "Delete
|
|
5129
|
+
description: "Delete attachment",
|
|
5152
5130
|
method: HttpMethod.DELETE,
|
|
5153
|
-
url: `/attachments/
|
|
5154
|
-
blockers: [
|
|
5155
|
-
blocks: [
|
|
5131
|
+
url: `/attachments/projects/${projectAttachmentId}/`,
|
|
5132
|
+
blockers: [projectAttachmentId],
|
|
5133
|
+
blocks: [projectAttachmentId]
|
|
5156
5134
|
});
|
|
5157
5135
|
}
|
|
5158
5136
|
}
|
|
@@ -5182,24 +5160,23 @@ class AuthService extends BaseApiService {
|
|
|
5182
5160
|
*/
|
|
5183
5161
|
__publicField(this, "_getTokenPair", (credentials, logoutOnFailure = true) => {
|
|
5184
5162
|
const uuid = v4();
|
|
5185
|
-
|
|
5186
|
-
|
|
5187
|
-
|
|
5188
|
-
|
|
5189
|
-
|
|
5190
|
-
|
|
5191
|
-
|
|
5192
|
-
|
|
5193
|
-
|
|
5194
|
-
|
|
5195
|
-
|
|
5196
|
-
return [responsePromise.then(parseTokens), uuid];
|
|
5197
|
-
} 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) => {
|
|
5198
5174
|
if (logoutOnFailure) {
|
|
5199
5175
|
void this.logout().then();
|
|
5200
5176
|
}
|
|
5201
5177
|
throw e;
|
|
5202
|
-
}
|
|
5178
|
+
});
|
|
5179
|
+
return [responsePromise, uuid];
|
|
5203
5180
|
});
|
|
5204
5181
|
/**
|
|
5205
5182
|
* Takes refresh token and gets a new token pair
|
|
@@ -5260,7 +5237,7 @@ class AuthService extends BaseApiService {
|
|
|
5260
5237
|
timedOut = true;
|
|
5261
5238
|
store.dispatch(markForDeletion(uuid));
|
|
5262
5239
|
store.dispatch(markForDeletion(initialDataUuid));
|
|
5263
|
-
reject(new
|
|
5240
|
+
reject(new APIError({ message: `Request timed out after ${timeout} seconds` }));
|
|
5264
5241
|
}, timeout * 1e3);
|
|
5265
5242
|
});
|
|
5266
5243
|
const successPromise = promise.then((tokens) => {
|
|
@@ -6390,18 +6367,11 @@ class MainService extends BaseApiService {
|
|
|
6390
6367
|
if (currentProjectId) {
|
|
6391
6368
|
const [_offlineAttachments, promise] = this.client.attachments.fetchAll(currentProjectId);
|
|
6392
6369
|
void promise.then((result) => {
|
|
6393
|
-
const {
|
|
6394
|
-
issue_attachments,
|
|
6395
|
-
component_type_attachments,
|
|
6396
|
-
component_attachments,
|
|
6397
|
-
project_attachments,
|
|
6398
|
-
document_attachments
|
|
6399
|
-
} = result;
|
|
6370
|
+
const { issue_attachments, component_type_attachments, component_attachments, project_attachments } = result;
|
|
6400
6371
|
store.dispatch(setIssueAttachments(issue_attachments));
|
|
6401
6372
|
store.dispatch(setComponentAttachments(component_attachments));
|
|
6402
6373
|
store.dispatch(setComponentTypeAttachments(component_type_attachments));
|
|
6403
6374
|
store.dispatch(setProjectAttachments(project_attachments));
|
|
6404
|
-
store.dispatch(setDocumentAttachments(document_attachments));
|
|
6405
6375
|
});
|
|
6406
6376
|
void this.client.documents.refreshStore();
|
|
6407
6377
|
void this.client.issueUpdates.refreshStore();
|
|
@@ -7236,8 +7206,7 @@ class OrganizationAccessService extends BaseApiService {
|
|
|
7236
7206
|
blockers: [],
|
|
7237
7207
|
blocks: []
|
|
7238
7208
|
});
|
|
7239
|
-
|
|
7240
|
-
store.dispatch(setOrganizationAccesses(organizationAccesses));
|
|
7209
|
+
store.dispatch(setOrganizationAccesses(result));
|
|
7241
7210
|
}
|
|
7242
7211
|
}
|
|
7243
7212
|
const cachedRequestPromises = {};
|
|
@@ -15662,8 +15631,6 @@ export {
|
|
|
15662
15631
|
addComponentTypeAttachment,
|
|
15663
15632
|
addComponentTypeAttachments,
|
|
15664
15633
|
addComponentsInBatches,
|
|
15665
|
-
addDocumentAttachment,
|
|
15666
|
-
addDocumentAttachments,
|
|
15667
15634
|
addDocuments,
|
|
15668
15635
|
addEmailDomain,
|
|
15669
15636
|
addFavouriteProjectId,
|
|
@@ -15827,8 +15794,6 @@ export {
|
|
|
15827
15794
|
removeComponentAttachments,
|
|
15828
15795
|
removeComponentTypeAttachment,
|
|
15829
15796
|
removeComponentTypeAttachments,
|
|
15830
|
-
removeDocumentAttachment,
|
|
15831
|
-
removeDocumentAttachments,
|
|
15832
15797
|
removeDocuments,
|
|
15833
15798
|
removeEmailDomain,
|
|
15834
15799
|
removeFavouriteProjectId,
|
|
@@ -15876,7 +15841,6 @@ export {
|
|
|
15876
15841
|
selectAllAttachments,
|
|
15877
15842
|
selectAllComponentAttachments,
|
|
15878
15843
|
selectAllComponentTypeAttachments,
|
|
15879
|
-
selectAllDocumentAttachments,
|
|
15880
15844
|
selectAllProjectAttachments,
|
|
15881
15845
|
selectAncestorIdsOfDocument,
|
|
15882
15846
|
selectAppearance,
|
|
@@ -15884,8 +15848,6 @@ export {
|
|
|
15884
15848
|
selectAttachmentsOfComponentByType,
|
|
15885
15849
|
selectAttachmentsOfComponentType,
|
|
15886
15850
|
selectAttachmentsOfComponentTypeByType,
|
|
15887
|
-
selectAttachmentsOfDocument,
|
|
15888
|
-
selectAttachmentsOfDocumentByType,
|
|
15889
15851
|
selectAttachmentsOfIssue,
|
|
15890
15852
|
selectAttachmentsOfIssueByType,
|
|
15891
15853
|
selectAttachmentsOfProject,
|
|
@@ -15901,7 +15863,6 @@ export {
|
|
|
15901
15863
|
selectCompletedStageIdsForComponent,
|
|
15902
15864
|
selectCompletedStages,
|
|
15903
15865
|
selectComponent,
|
|
15904
|
-
selectComponentAttachment,
|
|
15905
15866
|
selectComponentAttachmentMapping,
|
|
15906
15867
|
selectComponentSubmissionMapping,
|
|
15907
15868
|
selectComponentType,
|
|
@@ -15922,8 +15883,6 @@ export {
|
|
|
15922
15883
|
selectCurrentUser,
|
|
15923
15884
|
selectDeletedRequests,
|
|
15924
15885
|
selectDocument,
|
|
15925
|
-
selectDocumentAttachment,
|
|
15926
|
-
selectDocumentAttachmentMapping,
|
|
15927
15886
|
selectDocuments,
|
|
15928
15887
|
selectDocumentsMapping,
|
|
15929
15888
|
selectEmailDomainsAsMapping,
|
|
@@ -15945,7 +15904,6 @@ export {
|
|
|
15945
15904
|
selectIsLoading,
|
|
15946
15905
|
selectIsLoggedIn,
|
|
15947
15906
|
selectIssue,
|
|
15948
|
-
selectIssueAttachment,
|
|
15949
15907
|
selectIssueAttachmentMapping,
|
|
15950
15908
|
selectIssueAttachments,
|
|
15951
15909
|
selectIssueMapping,
|
|
@@ -16039,7 +15997,6 @@ export {
|
|
|
16039
15997
|
setComponents,
|
|
16040
15998
|
setCreateProjectType,
|
|
16041
15999
|
setCurrentUser,
|
|
16042
|
-
setDocumentAttachments,
|
|
16043
16000
|
setDocuments,
|
|
16044
16001
|
setEmailDomains,
|
|
16045
16002
|
setEnableClustering,
|
|
@@ -16094,7 +16051,6 @@ export {
|
|
|
16094
16051
|
updateComponent,
|
|
16095
16052
|
updateComponentAttachment,
|
|
16096
16053
|
updateComponentTypeAttachment,
|
|
16097
|
-
updateDocumentAttachment,
|
|
16098
16054
|
updateDocuments,
|
|
16099
16055
|
updateIssue,
|
|
16100
16056
|
updateIssueAttachment,
|