@overmap-ai/core 1.0.65 → 1.0.66

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.
Files changed (88) hide show
  1. package/dist/constants/index.d.ts +0 -1
  2. package/dist/enums/access.d.ts +8 -0
  3. package/dist/enums/attachments.d.ts +7 -0
  4. package/dist/enums/index.d.ts +3 -0
  5. package/dist/enums/issue.d.ts +9 -0
  6. package/dist/enums/licenses.d.ts +14 -0
  7. package/dist/overmap-core.js +1006 -1203
  8. package/dist/overmap-core.js.map +1 -1
  9. package/dist/overmap-core.umd.cjs +1015 -1211
  10. package/dist/overmap-core.umd.cjs.map +1 -1
  11. package/dist/sdk/base.d.ts +1 -1
  12. package/dist/sdk/globals.d.ts +2 -2
  13. package/dist/sdk/sdk.d.ts +3 -3
  14. package/dist/sdk/services/AgentService.d.ts +1 -1
  15. package/dist/sdk/services/AssetAttachmentService.d.ts +3 -2
  16. package/dist/sdk/services/AssetService.d.ts +6 -7
  17. package/dist/sdk/services/AssetStageCompletionService.d.ts +6 -12
  18. package/dist/sdk/services/AssetStageService.d.ts +5 -4
  19. package/dist/sdk/services/AssetTypeAttachmentService.d.ts +3 -2
  20. package/dist/sdk/services/AssetTypeService.d.ts +4 -4
  21. package/dist/sdk/services/BaseApiService.d.ts +1 -1
  22. package/dist/sdk/services/BaseAttachmentService.d.ts +4 -3
  23. package/dist/sdk/services/BaseAuthService.d.ts +1 -1
  24. package/dist/sdk/services/BaseService.d.ts +2 -2
  25. package/dist/sdk/services/BaseUploadService.d.ts +2 -2
  26. package/dist/sdk/services/CategoryService.d.ts +5 -9
  27. package/dist/sdk/services/DocumentAttachmentService.d.ts +3 -2
  28. package/dist/sdk/services/DocumentService.d.ts +5 -5
  29. package/dist/sdk/services/EmailDomainsService.d.ts +1 -1
  30. package/dist/sdk/services/EmailVerificationService.d.ts +1 -1
  31. package/dist/sdk/services/FileService.d.ts +1 -1
  32. package/dist/sdk/services/FormService.d.ts +1 -4
  33. package/dist/sdk/services/FormSubmissionService.d.ts +3 -4
  34. package/dist/sdk/services/GeoImageService.d.ts +2 -2
  35. package/dist/sdk/services/IssueAttachmentService.d.ts +3 -2
  36. package/dist/sdk/services/IssueCommentService.d.ts +5 -5
  37. package/dist/sdk/services/IssueService.d.ts +4 -4
  38. package/dist/sdk/services/IssueTypeService.d.ts +5 -5
  39. package/dist/sdk/services/IssueUpdateService.d.ts +1 -1
  40. package/dist/sdk/services/JWTAuthService.d.ts +2 -2
  41. package/dist/sdk/services/LicenseService.d.ts +1 -1
  42. package/dist/sdk/services/OrganizationAccessService.d.ts +1 -1
  43. package/dist/sdk/services/OrganizationService.d.ts +1 -1
  44. package/dist/sdk/services/ProjectAccessService.d.ts +2 -3
  45. package/dist/sdk/services/ProjectAttachmentService.d.ts +3 -2
  46. package/dist/sdk/services/ProjectFileService.d.ts +3 -4
  47. package/dist/sdk/services/ProjectService.d.ts +2 -9
  48. package/dist/sdk/services/TeamService.d.ts +4 -4
  49. package/dist/sdk/services/UserService.d.ts +2 -2
  50. package/dist/sdk/services/WorkspaceService.d.ts +4 -6
  51. package/dist/store/slices/assetStageCompletionSlice.d.ts +41 -11
  52. package/dist/store/slices/assetStageSlice.d.ts +20 -9
  53. package/dist/store/slices/assetTypeSlice.d.ts +27 -3
  54. package/dist/store/slices/documentSlice.d.ts +3 -3
  55. package/dist/store/slices/formSlice.d.ts +2 -4
  56. package/dist/store/slices/issueCommentSlice.d.ts +2 -1
  57. package/dist/store/slices/issueSlice.d.ts +4 -20
  58. package/dist/store/slices/userSlice.d.ts +13 -33
  59. package/dist/store/slices/workspaceSlice.d.ts +11 -11
  60. package/dist/typings/models/access.d.ts +2 -9
  61. package/dist/typings/models/agents.d.ts +1 -1
  62. package/dist/typings/models/assets.d.ts +8 -9
  63. package/dist/typings/models/attachments.d.ts +2 -9
  64. package/dist/typings/models/base.d.ts +3 -3
  65. package/dist/typings/models/categories.d.ts +3 -3
  66. package/dist/typings/models/documents.d.ts +1 -2
  67. package/dist/typings/models/emailDomain.d.ts +1 -1
  68. package/dist/typings/models/emailVerification.d.ts +2 -2
  69. package/dist/typings/models/forms.d.ts +5 -13
  70. package/dist/typings/models/geoImages.d.ts +3 -3
  71. package/dist/typings/models/issueTypes.d.ts +2 -3
  72. package/dist/typings/models/issues.d.ts +9 -22
  73. package/dist/typings/models/license.d.ts +2 -15
  74. package/dist/typings/models/organizations.d.ts +1 -1
  75. package/dist/typings/models/projects.d.ts +4 -6
  76. package/dist/typings/models/store.d.ts +1 -1
  77. package/dist/typings/models/teams.d.ts +3 -4
  78. package/dist/typings/models/users.d.ts +1 -1
  79. package/dist/typings/models/workspace.d.ts +3 -3
  80. package/dist/typings/store.d.ts +1 -1
  81. package/dist/utils/colors.d.ts +0 -2
  82. package/dist/utils/index.d.ts +0 -2
  83. package/dist/utils/optimization.d.ts +0 -3
  84. package/package.json +1 -1
  85. package/dist/constants/ui.d.ts +0 -1
  86. package/dist/typings/base.d.ts +0 -0
  87. package/dist/utils/css.d.ts +0 -5
  88. package/dist/utils/search.d.ts +0 -3
@@ -5,8 +5,8 @@ var __publicField = (obj, key, value) => {
5
5
  return value;
6
6
  };
7
7
  (function(global, factory) {
8
- typeof exports === "object" && typeof module !== "undefined" ? factory(exports, require("dependency-graph"), require("uuid"), require("@redux-offline/redux-offline"), require("@redux-offline/redux-offline/lib/defaults"), require("localforage"), require("redux-persist-migrate"), require("@reduxjs/toolkit"), require("superagent"), require("file-saver"), require("react"), require("color"), require("@radix-ui/colors"), require("@redux-offline/redux-offline/lib/constants"), require("jwt-decode"), require("@overmap-ai/blocks"), require("idb")) : typeof define === "function" && define.amd ? define(["exports", "dependency-graph", "uuid", "@redux-offline/redux-offline", "@redux-offline/redux-offline/lib/defaults", "localforage", "redux-persist-migrate", "@reduxjs/toolkit", "superagent", "file-saver", "react", "color", "@radix-ui/colors", "@redux-offline/redux-offline/lib/constants", "jwt-decode", "@overmap-ai/blocks", "idb"], factory) : (global = typeof globalThis !== "undefined" ? globalThis : global || self, factory(global["overmap-core"] = {}, global.dependencyGraph, global.uuid, global.reduxOffline, global.offlineConfig, global.localforage, global.createMigration, global.toolkit, global.request, global.fileSaver, global.React, global.ColorCls, global.colors, global.constants, global.jwtDecode, global.blocks, global.idb));
9
- })(this, function(exports2, dependencyGraph, uuid, reduxOffline, offlineConfig, localforage, createMigration, toolkit, request, fileSaver, React, ColorCls, colors, constants, jwtDecode, blocks, idb) {
8
+ typeof exports === "object" && typeof module !== "undefined" ? factory(exports, require("dependency-graph"), require("uuid"), require("file-saver"), require("color"), require("@radix-ui/colors"), require("@redux-offline/redux-offline"), require("@redux-offline/redux-offline/lib/defaults"), require("localforage"), require("redux-persist-migrate"), require("@reduxjs/toolkit"), require("superagent"), require("@redux-offline/redux-offline/lib/constants"), require("jwt-decode"), require("idb"), require("@overmap-ai/blocks")) : typeof define === "function" && define.amd ? define(["exports", "dependency-graph", "uuid", "file-saver", "color", "@radix-ui/colors", "@redux-offline/redux-offline", "@redux-offline/redux-offline/lib/defaults", "localforage", "redux-persist-migrate", "@reduxjs/toolkit", "superagent", "@redux-offline/redux-offline/lib/constants", "jwt-decode", "idb", "@overmap-ai/blocks"], factory) : (global = typeof globalThis !== "undefined" ? globalThis : global || self, factory(global["overmap-core"] = {}, global.dependencyGraph, global.uuid, global.fileSaver, global.ColorCls, global.colors, global.reduxOffline, global.offlineConfig, global.localforage, global.createMigration, global.toolkit, global.request, global.constants, global.jwtDecode, global.idb, global.blocks));
9
+ })(this, function(exports2, dependencyGraph, uuid, fileSaver, ColorCls, colors, reduxOffline, offlineConfig, localforage, createMigration, toolkit, request, constants, jwtDecode, idb, blocks) {
10
10
  var _a;
11
11
  "use strict";
12
12
  var HttpMethod = /* @__PURE__ */ ((HttpMethod2) => {
@@ -17,6 +17,14 @@ var __publicField = (obj, key, value) => {
17
17
  HttpMethod2["DELETE"] = "DELETE";
18
18
  return HttpMethod2;
19
19
  })(HttpMethod || {});
20
+ var AttachmentModel = /* @__PURE__ */ ((AttachmentModel2) => {
21
+ AttachmentModel2["Issue"] = "issue";
22
+ AttachmentModel2["Asset"] = "asset";
23
+ AttachmentModel2["AssetType"] = "asset_type";
24
+ AttachmentModel2["Project"] = "project";
25
+ AttachmentModel2["Document"] = "document";
26
+ return AttachmentModel2;
27
+ })(AttachmentModel || {});
20
28
  var IssuePriority = /* @__PURE__ */ ((IssuePriority2) => {
21
29
  IssuePriority2[IssuePriority2["LOWEST"] = 0] = "LOWEST";
22
30
  IssuePriority2[IssuePriority2["LOW"] = 2] = "LOW";
@@ -31,6 +39,43 @@ var __publicField = (obj, key, value) => {
31
39
  IssueStatus2[IssueStatus2["DONE"] = 4] = "DONE";
32
40
  return IssueStatus2;
33
41
  })(IssueStatus || {});
42
+ var IssueUpdateChange = /* @__PURE__ */ ((IssueUpdateChange2) => {
43
+ IssueUpdateChange2["STATUS"] = "status";
44
+ IssueUpdateChange2["PRIORITY"] = "priority";
45
+ IssueUpdateChange2["CATEGORY"] = "category";
46
+ IssueUpdateChange2["DESCRIPTION"] = "description";
47
+ IssueUpdateChange2["TITLE"] = "title";
48
+ IssueUpdateChange2["ASSIGNED_TO"] = "assigned_to";
49
+ IssueUpdateChange2["DUE_DATE"] = "due_date";
50
+ return IssueUpdateChange2;
51
+ })(IssueUpdateChange || {});
52
+ var ProjectAccessLevel = /* @__PURE__ */ ((ProjectAccessLevel2) => {
53
+ ProjectAccessLevel2[ProjectAccessLevel2["BASIC"] = 0] = "BASIC";
54
+ ProjectAccessLevel2[ProjectAccessLevel2["ADMIN"] = 2] = "ADMIN";
55
+ return ProjectAccessLevel2;
56
+ })(ProjectAccessLevel || {});
57
+ var OrganizationAccessLevel = /* @__PURE__ */ ((OrganizationAccessLevel2) => {
58
+ OrganizationAccessLevel2[OrganizationAccessLevel2["BASIC"] = 0] = "BASIC";
59
+ OrganizationAccessLevel2[OrganizationAccessLevel2["ADMIN"] = 2] = "ADMIN";
60
+ return OrganizationAccessLevel2;
61
+ })(OrganizationAccessLevel || {});
62
+ var PaddleCheckoutEvent = /* @__PURE__ */ ((PaddleCheckoutEvent2) => {
63
+ PaddleCheckoutEvent2["COMPLETED"] = "checkout.completed";
64
+ PaddleCheckoutEvent2["CLOSED"] = "checkout.closed";
65
+ return PaddleCheckoutEvent2;
66
+ })(PaddleCheckoutEvent || {});
67
+ var LicenseLevel = /* @__PURE__ */ ((LicenseLevel2) => {
68
+ LicenseLevel2[LicenseLevel2["PRO"] = 0] = "PRO";
69
+ return LicenseLevel2;
70
+ })(LicenseLevel || {});
71
+ var LicenseStatus = /* @__PURE__ */ ((LicenseStatus2) => {
72
+ LicenseStatus2[LicenseStatus2["ACTIVE"] = 0] = "ACTIVE";
73
+ LicenseStatus2[LicenseStatus2["PAUSED"] = 2] = "PAUSED";
74
+ LicenseStatus2[LicenseStatus2["CANCELLED"] = 4] = "CANCELLED";
75
+ LicenseStatus2[LicenseStatus2["INACTIVE"] = 6] = "INACTIVE";
76
+ LicenseStatus2[LicenseStatus2["PAST_DUE"] = 8] = "PAST_DUE";
77
+ return LicenseStatus2;
78
+ })(LicenseStatus || {});
34
79
  class OutboxCoordinator {
35
80
  constructor() {
36
81
  __publicField(this, "graph");
@@ -273,130 +318,6 @@ var __publicField = (obj, key, value) => {
273
318
  this.options = options;
274
319
  }
275
320
  }
276
- class DeferredPromise {
277
- constructor() {
278
- __publicField(this, _a, "Promise");
279
- __publicField(this, "_promise");
280
- __publicField(this, "_resolve");
281
- __publicField(this, "_reject");
282
- __publicField(this, "_state", "pending");
283
- this._resolve = null;
284
- this._reject = null;
285
- this._promise = new Promise((resolve, reject) => {
286
- this._resolve = resolve;
287
- this._reject = reject;
288
- });
289
- }
290
- get state() {
291
- return this._state;
292
- }
293
- then(onFulfilled, onRejected) {
294
- return this._promise.then(onFulfilled, onRejected);
295
- }
296
- catch(onRejected) {
297
- return this._promise.catch(onRejected);
298
- }
299
- resolve(value) {
300
- if (!this._resolve)
301
- throw new Error("No resolve callback");
302
- this._resolve(value);
303
- this._state = "fulfilled";
304
- }
305
- reject(reason) {
306
- if (!this._reject)
307
- throw reason;
308
- this._reject(reason);
309
- this._state = "rejected";
310
- }
311
- finally(_onFinally) {
312
- throw new Error("`finally` not implemented");
313
- }
314
- }
315
- _a = Symbol.toStringTag;
316
- var randomString = function randomString2() {
317
- return Math.random().toString(36).substring(7).split("").join(".");
318
- };
319
- ({
320
- INIT: "@@redux/INIT" + randomString(),
321
- REPLACE: "@@redux/REPLACE" + randomString(),
322
- PROBE_UNKNOWN_ACTION: function PROBE_UNKNOWN_ACTION() {
323
- return "@@redux/PROBE_UNKNOWN_ACTION" + randomString();
324
- }
325
- });
326
- function compose() {
327
- for (var _len = arguments.length, funcs = new Array(_len), _key = 0; _key < _len; _key++) {
328
- funcs[_key] = arguments[_key];
329
- }
330
- if (funcs.length === 0) {
331
- return function(arg) {
332
- return arg;
333
- };
334
- }
335
- if (funcs.length === 1) {
336
- return funcs[0];
337
- }
338
- return funcs.reduce(function(a, b) {
339
- return function() {
340
- return a(b.apply(void 0, arguments));
341
- };
342
- });
343
- }
344
- const VERSION_REDUCER_KEY$1 = "versioning";
345
- const latestVersion = () => migrations.length - 1;
346
- const initialVersioning = (state) => {
347
- state[VERSION_REDUCER_KEY$1] = { version: latestVersion() };
348
- return state;
349
- };
350
- const signOut = () => {
351
- return initialVersioning({});
352
- };
353
- const createOutboxState = (state) => {
354
- if (state.outboxReducer) {
355
- state.outboxReducer.deletedRequests = [];
356
- }
357
- return state;
358
- };
359
- const wrapMigration = (migrator) => (state) => {
360
- var _a2;
361
- if (state === void 0) {
362
- state = {};
363
- }
364
- if (((_a2 = state[VERSION_REDUCER_KEY$1]) == null ? void 0 : _a2.version) === latestVersion())
365
- return state;
366
- return migrator(state);
367
- };
368
- const migrations = [initialVersioning, signOut, signOut, createOutboxState];
369
- const manifest = Object.fromEntries(migrations.map((migration2, i) => [i, wrapMigration(migration2)]));
370
- const initialState$B = {
371
- accessToken: "",
372
- refreshToken: "",
373
- isLoggedIn: false
374
- };
375
- const authSlice = toolkit.createSlice({
376
- name: "auth",
377
- initialState: initialState$B,
378
- extraReducers: (builder) => builder.addCase("RESET", (state) => Object.assign(state, initialState$B)),
379
- reducers: {
380
- setTokens: (state, action) => {
381
- state.accessToken = action.payload.accessToken;
382
- state.refreshToken = action.payload.refreshToken;
383
- },
384
- clearTokens: (state) => {
385
- state.accessToken = "";
386
- state.refreshToken = "";
387
- },
388
- setLoggedIn: (state, action) => {
389
- if (!action.payload) {
390
- authSlice.caseReducers.clearTokens(state);
391
- }
392
- state.isLoggedIn = action.payload;
393
- }
394
- }
395
- });
396
- const { setTokens, clearTokens, setLoggedIn } = authSlice.actions;
397
- const selectAccessToken = (state) => state.authReducer.accessToken;
398
- const selectIsLoggedIn = (state) => state.authReducer.isLoggedIn;
399
- const authReducer = authSlice.reducer;
400
321
  const coordinatesToLiteral = (coordinates) => {
401
322
  return { lng: coordinates[0], lat: coordinates[1] };
402
323
  };
@@ -461,24 +382,6 @@ var __publicField = (obj, key, value) => {
461
382
  coordinates
462
383
  };
463
384
  };
464
- function classNames(...args) {
465
- const classes = [];
466
- for (const arg of args) {
467
- if (!arg) {
468
- continue;
469
- }
470
- if (typeof arg === "string") {
471
- classes.push(arg);
472
- } else if (typeof arg === "object") {
473
- for (const [key, value] of Object.entries(arg)) {
474
- if (value) {
475
- classes.push(key);
476
- }
477
- }
478
- }
479
- }
480
- return classes.join(" ");
481
- }
482
385
  function hex(buffer) {
483
386
  const hashArray = new Uint8Array(buffer);
484
387
  return hashArray.reduce((data, byte) => data + byte.toString(16).padStart(2, "0"), "");
@@ -591,14 +494,6 @@ var __publicField = (obj, key, value) => {
591
494
  }
592
495
  return asMapping;
593
496
  }
594
- const issueToSearchResult = (issue, tag) => {
595
- return {
596
- label: issue.title || "",
597
- typeLabel: "issue",
598
- tag,
599
- item: issue
600
- };
601
- };
602
497
  function toFileNameSafeString(str, extension = void 0, maxLength = 255) {
603
498
  let ret = str.replace(/[^a-z0-9_\-.]/gi, "_").replace(/_{2,}/g, "_");
604
499
  if (!extension) {
@@ -642,7 +537,6 @@ var __publicField = (obj, key, value) => {
642
537
  return bounds[0][0] > coordinates[0] && bounds[1][0] < coordinates[0] && bounds[0][1] > coordinates[1] && bounds[1][1] < coordinates[1];
643
538
  }
644
539
  const emailRegex = /^.+@.+\..+$/;
645
- const fullAssetMarkerSize = 45;
646
540
  const DEFAULT_ISSUE_STATUS = IssueStatus.BACKLOG;
647
541
  const DEFAULT_ISSUE_PRIORITY = IssuePriority.MEDIUM;
648
542
  const OUTBOX_RETRY_DELAY = 6e4;
@@ -688,17 +582,6 @@ var __publicField = (obj, key, value) => {
688
582
  }
689
583
  };
690
584
  }
691
- function useMemoCompare(next, compare) {
692
- const previousRef = React.useRef(void 0);
693
- const previous = previousRef.current;
694
- const isEqual = compare(previous, next);
695
- React.useEffect(() => {
696
- if (!isEqual) {
697
- previousRef.current = next;
698
- }
699
- });
700
- return isEqual ? previous : next;
701
- }
702
585
  function areArraysEqual(first, second) {
703
586
  if (first.length !== second.length)
704
587
  return false;
@@ -708,7 +591,6 @@ var __publicField = (obj, key, value) => {
708
591
  }
709
592
  return true;
710
593
  }
711
- const genericMemo = React.memo;
712
594
  const fallbackToEmptyArray = (array) => {
713
595
  return array.length === 0 ? EMPTY_ARRAY : array;
714
596
  };
@@ -741,19 +623,6 @@ var __publicField = (obj, key, value) => {
741
623
  mint: colors.mint.mint9,
742
624
  sky: colors.sky.sky9
743
625
  };
744
- const AssetStageColors = {
745
- indigo: colors.indigo.indigo9,
746
- red: colors.red.red9,
747
- violet: colors.violet.violet9,
748
- yellow: colors.yellow.yellow9,
749
- jade: colors.jade.jade9,
750
- cyan: colors.cyan.cyan9,
751
- gold: colors.gold.gold9,
752
- orange: colors.orange.orange9,
753
- lime: colors.lime.lime9,
754
- sky: colors.sky.sky9,
755
- pink: colors.pink.pink9
756
- };
757
626
  const defaultBadgeColor = "#868686";
758
627
  const generateBadgeColors = (rawColor) => {
759
628
  const color = ColorCls(rawColor);
@@ -762,9 +631,6 @@ var __publicField = (obj, key, value) => {
762
631
  const textColor = color.hex() === safety.hex() ? "#000000" : "#FFFFFF";
763
632
  return { backgroundColor, textColor };
764
633
  };
765
- function getStageColor(index) {
766
- return Object.values(AssetStageColors)[index % Object.keys(AssetStageColors).length];
767
- }
768
634
  const getLocalDateString = memoize((date) => {
769
635
  if (!date)
770
636
  return "";
@@ -787,71 +653,195 @@ var __publicField = (obj, key, value) => {
787
653
  return getLocalDateString(date);
788
654
  return relative.format(days, "days");
789
655
  });
790
- function createModelAdapter(computeModelId) {
791
- const addOne = (state, action) => {
792
- const id = computeModelId(action.payload);
793
- state.instances[id] = action.payload;
794
- };
795
- const addMany = (state, action) => {
796
- for (const model of action.payload) {
797
- const id = computeModelId(model);
798
- state.instances[id] = model;
799
- }
800
- };
801
- const setOne = (state, action) => {
802
- const id = computeModelId(action.payload);
803
- state.instances[id] = action.payload;
804
- };
805
- const setMany = (state, action) => {
806
- for (const model of action.payload) {
807
- const id = computeModelId(model);
808
- state.instances[id] = model;
809
- }
810
- };
811
- const updateOne = (state, action) => {
812
- const id = computeModelId(action.payload);
813
- state.instances[id] = action.payload;
814
- };
815
- const updateMany = (state, action) => {
816
- for (const model of action.payload) {
817
- const id = computeModelId(model);
818
- state.instances[id] = model;
819
- }
820
- };
821
- const deleteOne = (state, action) => {
822
- delete state.instances[action.payload];
823
- };
824
- const deleteMany = (state, action) => {
825
- for (const id of action.payload) {
826
- delete state.instances[id];
827
- }
828
- };
829
- const initialize = (state, action) => {
830
- state.instances = {};
831
- for (const model of action.payload) {
832
- const id = computeModelId(model);
833
- state.instances[id] = model;
834
- }
835
- };
836
- const getInitialState = (state) => {
837
- return {
838
- ...state,
839
- instances: {}
840
- };
841
- };
842
- return {
843
- addOne,
844
- addMany,
845
- setOne,
846
- setMany,
847
- updateOne,
848
- updateMany,
849
- deleteOne,
850
- deleteMany,
851
- initialize,
852
- getInitialState
853
- };
854
- }
656
+ class DeferredPromise {
657
+ constructor() {
658
+ __publicField(this, _a, "Promise");
659
+ __publicField(this, "_promise");
660
+ __publicField(this, "_resolve");
661
+ __publicField(this, "_reject");
662
+ __publicField(this, "_state", "pending");
663
+ this._resolve = null;
664
+ this._reject = null;
665
+ this._promise = new Promise((resolve, reject) => {
666
+ this._resolve = resolve;
667
+ this._reject = reject;
668
+ });
669
+ }
670
+ get state() {
671
+ return this._state;
672
+ }
673
+ then(onFulfilled, onRejected) {
674
+ return this._promise.then(onFulfilled, onRejected);
675
+ }
676
+ catch(onRejected) {
677
+ return this._promise.catch(onRejected);
678
+ }
679
+ resolve(value) {
680
+ if (!this._resolve)
681
+ throw new Error("No resolve callback");
682
+ this._resolve(value);
683
+ this._state = "fulfilled";
684
+ }
685
+ reject(reason) {
686
+ if (!this._reject)
687
+ throw reason;
688
+ this._reject(reason);
689
+ this._state = "rejected";
690
+ }
691
+ finally(_onFinally) {
692
+ throw new Error("`finally` not implemented");
693
+ }
694
+ }
695
+ _a = Symbol.toStringTag;
696
+ var randomString = function randomString2() {
697
+ return Math.random().toString(36).substring(7).split("").join(".");
698
+ };
699
+ ({
700
+ INIT: "@@redux/INIT" + randomString(),
701
+ REPLACE: "@@redux/REPLACE" + randomString(),
702
+ PROBE_UNKNOWN_ACTION: function PROBE_UNKNOWN_ACTION() {
703
+ return "@@redux/PROBE_UNKNOWN_ACTION" + randomString();
704
+ }
705
+ });
706
+ function compose() {
707
+ for (var _len = arguments.length, funcs = new Array(_len), _key = 0; _key < _len; _key++) {
708
+ funcs[_key] = arguments[_key];
709
+ }
710
+ if (funcs.length === 0) {
711
+ return function(arg) {
712
+ return arg;
713
+ };
714
+ }
715
+ if (funcs.length === 1) {
716
+ return funcs[0];
717
+ }
718
+ return funcs.reduce(function(a, b) {
719
+ return function() {
720
+ return a(b.apply(void 0, arguments));
721
+ };
722
+ });
723
+ }
724
+ const VERSION_REDUCER_KEY$1 = "versioning";
725
+ const latestVersion = () => migrations.length - 1;
726
+ const initialVersioning = (state) => {
727
+ state[VERSION_REDUCER_KEY$1] = { version: latestVersion() };
728
+ return state;
729
+ };
730
+ const signOut = () => {
731
+ return initialVersioning({});
732
+ };
733
+ const createOutboxState = (state) => {
734
+ if (state.outboxReducer) {
735
+ state.outboxReducer.deletedRequests = [];
736
+ }
737
+ return state;
738
+ };
739
+ const wrapMigration = (migrator) => (state) => {
740
+ var _a2;
741
+ if (state === void 0) {
742
+ state = {};
743
+ }
744
+ if (((_a2 = state[VERSION_REDUCER_KEY$1]) == null ? void 0 : _a2.version) === latestVersion())
745
+ return state;
746
+ return migrator(state);
747
+ };
748
+ const migrations = [initialVersioning, signOut, signOut, createOutboxState];
749
+ const manifest = Object.fromEntries(migrations.map((migration2, i) => [i, wrapMigration(migration2)]));
750
+ const initialState$B = {
751
+ accessToken: "",
752
+ refreshToken: "",
753
+ isLoggedIn: false
754
+ };
755
+ const authSlice = toolkit.createSlice({
756
+ name: "auth",
757
+ initialState: initialState$B,
758
+ extraReducers: (builder) => builder.addCase("RESET", (state) => Object.assign(state, initialState$B)),
759
+ reducers: {
760
+ setTokens: (state, action) => {
761
+ state.accessToken = action.payload.accessToken;
762
+ state.refreshToken = action.payload.refreshToken;
763
+ },
764
+ clearTokens: (state) => {
765
+ state.accessToken = "";
766
+ state.refreshToken = "";
767
+ },
768
+ setLoggedIn: (state, action) => {
769
+ if (!action.payload) {
770
+ authSlice.caseReducers.clearTokens(state);
771
+ }
772
+ state.isLoggedIn = action.payload;
773
+ }
774
+ }
775
+ });
776
+ const { setTokens, clearTokens, setLoggedIn } = authSlice.actions;
777
+ const selectAccessToken = (state) => state.authReducer.accessToken;
778
+ const selectIsLoggedIn = (state) => state.authReducer.isLoggedIn;
779
+ const authReducer = authSlice.reducer;
780
+ function createModelAdapter(computeModelId) {
781
+ const addOne = (state, action) => {
782
+ const id = computeModelId(action.payload);
783
+ state.instances[id] = action.payload;
784
+ };
785
+ const addMany = (state, action) => {
786
+ for (const model of action.payload) {
787
+ const id = computeModelId(model);
788
+ state.instances[id] = model;
789
+ }
790
+ };
791
+ const setOne = (state, action) => {
792
+ const id = computeModelId(action.payload);
793
+ state.instances[id] = action.payload;
794
+ };
795
+ const setMany = (state, action) => {
796
+ for (const model of action.payload) {
797
+ const id = computeModelId(model);
798
+ state.instances[id] = model;
799
+ }
800
+ };
801
+ const updateOne = (state, action) => {
802
+ const id = computeModelId(action.payload);
803
+ state.instances[id] = action.payload;
804
+ };
805
+ const updateMany = (state, action) => {
806
+ for (const model of action.payload) {
807
+ const id = computeModelId(model);
808
+ state.instances[id] = model;
809
+ }
810
+ };
811
+ const deleteOne = (state, action) => {
812
+ delete state.instances[action.payload];
813
+ };
814
+ const deleteMany = (state, action) => {
815
+ for (const id of action.payload) {
816
+ delete state.instances[id];
817
+ }
818
+ };
819
+ const initialize = (state, action) => {
820
+ state.instances = {};
821
+ for (const model of action.payload) {
822
+ const id = computeModelId(model);
823
+ state.instances[id] = model;
824
+ }
825
+ };
826
+ const getInitialState = (state) => {
827
+ return {
828
+ ...state,
829
+ instances: {}
830
+ };
831
+ };
832
+ return {
833
+ addOne,
834
+ addMany,
835
+ setOne,
836
+ setMany,
837
+ updateOne,
838
+ updateMany,
839
+ deleteOne,
840
+ deleteMany,
841
+ initialize,
842
+ getInitialState
843
+ };
844
+ }
855
845
  const categoryAdapter = createModelAdapter((category) => category.offline_id);
856
846
  const initialState$A = categoryAdapter.getInitialState({});
857
847
  const categorySlice = toolkit.createSlice({
@@ -1019,61 +1009,72 @@ var __publicField = (obj, key, value) => {
1019
1009
  )
1020
1010
  );
1021
1011
  const assetAttachmentReducer = assetAttachmentSlice.reducer;
1022
- const initialState$x = {
1023
- completionsByAssetId: {}
1024
- };
1012
+ const assetStageCompletionAdapter = createModelAdapter(
1013
+ (stageCompletion) => stageCompletion.offline_id
1014
+ );
1015
+ const initialState$x = assetStageCompletionAdapter.getInitialState({});
1025
1016
  const assetStageCompletionSlice = toolkit.createSlice({
1026
1017
  name: "assetStageCompletions",
1027
1018
  initialState: initialState$x,
1028
1019
  extraReducers: (builder) => builder.addCase("RESET", (state) => Object.assign(state, initialState$x)),
1029
1020
  reducers: {
1030
- addStageCompletion: (state, action) => {
1031
- let stageToCompletionDateMapping = state.completionsByAssetId[action.payload.asset];
1032
- if (!stageToCompletionDateMapping) {
1033
- stageToCompletionDateMapping = {};
1034
- state.completionsByAssetId[action.payload.asset] = stageToCompletionDateMapping;
1035
- }
1036
- stageToCompletionDateMapping[action.payload.stage] = (/* @__PURE__ */ new Date()).toISOString();
1037
- },
1038
- addStageCompletions: (state, action) => {
1039
- for (const [assetId, stageIdToCompletionDateMapping] of Object.entries(action.payload)) {
1040
- if (Object.keys(stageIdToCompletionDateMapping).length === 0)
1041
- throw new Error(`Encountered empty stageIdToCompletionDateMapping argument for asset ${assetId}`);
1042
- let thisAssetCompletions = state.completionsByAssetId[assetId];
1043
- if (thisAssetCompletions === void 0) {
1044
- thisAssetCompletions = {};
1045
- }
1046
- for (const [stageId, completionDate] of Object.entries(stageIdToCompletionDateMapping)) {
1047
- thisAssetCompletions[stageId] = completionDate;
1048
- }
1049
- state.completionsByAssetId[assetId] = thisAssetCompletions;
1050
- }
1051
- },
1052
- removeStageCompletions: (state, action) => {
1053
- for (const completion of action.payload) {
1054
- const thisAssetCompletions = state.completionsByAssetId[completion.asset];
1055
- if (!thisAssetCompletions || !(completion.stage in thisAssetCompletions)) {
1056
- console.warn(
1057
- "Skipping removal of uncompleted stage. This message indicates completion objects are created unnecessarily."
1058
- );
1059
- continue;
1060
- }
1061
- delete thisAssetCompletions[completion.stage];
1062
- }
1063
- },
1064
- setStageCompletions: (state, action) => {
1065
- state.completionsByAssetId = action.payload;
1066
- }
1021
+ initializeAssetStageCompletions: assetStageCompletionAdapter.initialize,
1022
+ addAssetStageCompletion: assetStageCompletionAdapter.addOne,
1023
+ addAssetStageCompletions: assetStageCompletionAdapter.addMany,
1024
+ updateAssetStageCompletion: assetStageCompletionAdapter.updateOne,
1025
+ updateAssetStageCompletions: assetStageCompletionAdapter.updateMany,
1026
+ deleteAssetStageCompletion: assetStageCompletionAdapter.deleteOne,
1027
+ deleteAssetStageCompletions: assetStageCompletionAdapter.deleteMany
1067
1028
  }
1068
1029
  });
1069
- const { addStageCompletion, addStageCompletions, removeStageCompletions, setStageCompletions } = assetStageCompletionSlice.actions;
1070
- const selectCompletedStages = (state) => {
1071
- return state.assetStageCompletionReducer.completionsByAssetId;
1030
+ const {
1031
+ initializeAssetStageCompletions,
1032
+ addAssetStageCompletion,
1033
+ addAssetStageCompletions,
1034
+ updateAssetStageCompletion,
1035
+ updateAssetStageCompletions,
1036
+ deleteAssetStageCompletion,
1037
+ deleteAssetStageCompletions
1038
+ } = assetStageCompletionSlice.actions;
1039
+ const selectAssetStageCompletionMapping = (state) => {
1040
+ return state.assetStageCompletionReducer.instances;
1072
1041
  };
1042
+ const selectCompletedStagesByAsset = toolkit.createSelector(
1043
+ [selectAssetStageCompletionMapping],
1044
+ (completedStagesMapping) => {
1045
+ const completedStagesByAsset = {};
1046
+ for (const stageCompletion of Object.values(completedStagesMapping)) {
1047
+ const { asset, stage, submitted_at } = stageCompletion;
1048
+ if (!completedStagesByAsset[asset])
1049
+ completedStagesByAsset[asset] = {};
1050
+ completedStagesByAsset[asset][stage] = submitted_at;
1051
+ }
1052
+ return completedStagesByAsset;
1053
+ }
1054
+ );
1073
1055
  const selectCompletedStageIdsForAsset = restructureCreateSelectorWithArgs(
1074
- toolkit.createSelector([selectCompletedStages, (_state, asset) => asset], (completedStages, asset) => {
1075
- return Object.keys(completedStages[asset.offline_id] ?? {});
1076
- })
1056
+ toolkit.createSelector(
1057
+ [selectAssetStageCompletionMapping, (_state, asset) => asset],
1058
+ (completedStages, asset) => {
1059
+ return Object.keys(completedStages[asset.offline_id] ?? {});
1060
+ }
1061
+ )
1062
+ );
1063
+ const selectAssetStageCompletionById = (id) => (state) => {
1064
+ return state.assetStageCompletionReducer.instances[id];
1065
+ };
1066
+ const selectAssetStageCompletionsByIds = restructureCreateSelectorWithArgs(
1067
+ toolkit.createSelector(
1068
+ [selectAssetStageCompletionMapping, (_, stageCompletionIds) => stageCompletionIds],
1069
+ (stageCompletionMapping, stageCompletionIds) => {
1070
+ const stageCompletionIdsSet = new Set(stageCompletionIds);
1071
+ return fallbackToEmptyArray(
1072
+ Object.values(stageCompletionMapping).filter(
1073
+ (stageCompletion) => stageCompletionIdsSet.has(stageCompletion.offline_id)
1074
+ )
1075
+ );
1076
+ }
1077
+ )
1077
1078
  );
1078
1079
  const assetStageCompletionReducer = assetStageCompletionSlice.reducer;
1079
1080
  const assetStageAdapter = createModelAdapter((assetStage) => assetStage.offline_id);
@@ -1083,14 +1084,29 @@ var __publicField = (obj, key, value) => {
1083
1084
  initialState: initialState$w,
1084
1085
  extraReducers: (builder) => builder.addCase("RESET", (state) => Object.assign(state, initialState$w)),
1085
1086
  reducers: {
1086
- initializeStages: assetStageAdapter.initialize,
1087
- setStage: assetStageAdapter.setOne,
1088
- addStages: assetStageAdapter.addMany,
1089
- updateStage: assetStageAdapter.updateOne,
1090
- updateStages: assetStageAdapter.updateMany,
1091
- removeStages: assetStageAdapter.deleteMany
1087
+ initializeAssetStages: assetStageAdapter.initialize,
1088
+ setAssetStage: assetStageAdapter.setOne,
1089
+ setAssetStages: assetStageAdapter.setMany,
1090
+ addAssetStage: assetStageAdapter.addOne,
1091
+ addAssetStages: assetStageAdapter.addMany,
1092
+ updateAssetStage: assetStageAdapter.updateOne,
1093
+ updateAssetStages: assetStageAdapter.updateMany,
1094
+ deleteAssetStage: assetStageAdapter.deleteOne,
1095
+ deleteAssetStages: assetStageAdapter.deleteMany
1092
1096
  }
1093
1097
  });
1098
+ const {
1099
+ initializeAssetStages,
1100
+ setAssetStage,
1101
+ setAssetStages,
1102
+ addAssetStage,
1103
+ addAssetStages,
1104
+ updateAssetStage,
1105
+ updateAssetStages,
1106
+ deleteAssetStage,
1107
+ deleteAssetStages
1108
+ } = assetStageSlice.actions;
1109
+ const assetStageReducer = assetStageSlice.reducer;
1094
1110
  const selectStageMapping = (state) => state.assetStageReducer.instances;
1095
1111
  const selectAssetStageById = (id) => (state) => {
1096
1112
  return state.assetStageReducer.instances[id];
@@ -1098,24 +1114,6 @@ var __publicField = (obj, key, value) => {
1098
1114
  const selectAssetStages = toolkit.createSelector([selectStageMapping], (stageMapping) => {
1099
1115
  return Object.values(stageMapping);
1100
1116
  });
1101
- const selectStagesFromAssetTypeIds = restructureCreateSelectorWithArgs(
1102
- toolkit.createSelector([selectAssetStages, (_state, assetTypeIds) => assetTypeIds], (stages, assetTypeIds) => {
1103
- const assetTypeIdsSet = new Set(assetTypeIds);
1104
- const ret = {};
1105
- for (const stage of stages) {
1106
- if (assetTypeIdsSet.has(stage.asset_type)) {
1107
- if (!ret[stage.asset_type]) {
1108
- ret[stage.asset_type] = [];
1109
- }
1110
- ret[stage.asset_type].push(stage);
1111
- }
1112
- }
1113
- for (const key in ret) {
1114
- ret[key] = ret[key].sort((a, b) => a.priority - b.priority);
1115
- }
1116
- return ret;
1117
- })
1118
- );
1119
1117
  const selectAssetTypeStagesMapping = restructureCreateSelectorWithArgs(
1120
1118
  toolkit.createSelector([selectStageMapping, (_state, assetTypeId) => assetTypeId], (stagesMapping, assetTypeId) => {
1121
1119
  const assetTypeStagesMapping = {};
@@ -1163,8 +1161,6 @@ var __publicField = (obj, key, value) => {
1163
1161
  return ret;
1164
1162
  })
1165
1163
  );
1166
- const { initializeStages, setStage, addStages, updateStages, removeStages, updateStage } = assetStageSlice.actions;
1167
- const assetStageReducer = assetStageSlice.reducer;
1168
1164
  const assetTypeAdapter = createModelAdapter((assetType) => assetType.offline_id);
1169
1165
  const initialState$v = assetTypeAdapter.getInitialState({});
1170
1166
  const assetTypeSlice = toolkit.createSlice({
@@ -1173,11 +1169,27 @@ var __publicField = (obj, key, value) => {
1173
1169
  extraReducers: (builder) => builder.addCase("RESET", (state) => Object.assign(state, initialState$v)),
1174
1170
  reducers: {
1175
1171
  initializeAssetTypes: assetTypeAdapter.initialize,
1172
+ setAssetType: assetTypeAdapter.setOne,
1173
+ setAssetTypes: assetTypeAdapter.setMany,
1176
1174
  addAssetType: assetTypeAdapter.addOne,
1177
- deleteAssetType: assetTypeAdapter.deleteOne
1175
+ addAssetTypes: assetTypeAdapter.addMany,
1176
+ updateAssetType: assetTypeAdapter.updateOne,
1177
+ updateAssetTypes: assetTypeAdapter.updateMany,
1178
+ deleteAssetType: assetTypeAdapter.deleteOne,
1179
+ deleteAssetTypes: assetTypeAdapter.deleteMany
1178
1180
  }
1179
1181
  });
1180
- const { addAssetType, initializeAssetTypes, deleteAssetType } = assetTypeSlice.actions;
1182
+ const {
1183
+ initializeAssetTypes,
1184
+ setAssetType,
1185
+ setAssetTypes,
1186
+ addAssetType,
1187
+ addAssetTypes,
1188
+ updateAssetType,
1189
+ updateAssetTypes,
1190
+ deleteAssetType,
1191
+ deleteAssetTypes
1192
+ } = assetTypeSlice.actions;
1181
1193
  const selectAssetTypesMapping = (state) => state.assetTypeReducer.instances;
1182
1194
  const selectAssetTypes = toolkit.createSelector(
1183
1195
  [selectAssetTypesMapping],
@@ -1269,50 +1281,13 @@ var __publicField = (obj, key, value) => {
1269
1281
  )
1270
1282
  );
1271
1283
  const assetTypeAttachmentReducer = assetTypeAttachmentSlice.reducer;
1272
- const workspaceAdapter = createModelAdapter((workspace) => workspace.offline_id);
1273
- const initialState$t = workspaceAdapter.getInitialState({});
1274
- const workspaceSlice = toolkit.createSlice({
1275
- name: "workspace",
1276
- initialState: initialState$t,
1277
- reducers: {
1278
- initializeWorkspaces: workspaceAdapter.initialize,
1279
- setWorkspaces: workspaceAdapter.setMany,
1280
- addWorkspace: workspaceAdapter.addOne,
1281
- updateWorkspace: workspaceAdapter.updateOne,
1282
- deleteWorkspace: workspaceAdapter.deleteOne
1283
- }
1284
- });
1285
- const { initializeWorkspaces, setWorkspaces, addWorkspace, updateWorkspace, deleteWorkspace } = workspaceSlice.actions;
1286
- const selectWorkspaceMapping = (state) => state.workspaceReducer.instances;
1287
- const selectWorkspaces = toolkit.createSelector([selectWorkspaceMapping], (mapping) => Object.values(mapping));
1288
- const selectMainWorkspace = toolkit.createSelector(
1289
- [selectWorkspaces],
1290
- (workspaces) => {
1291
- return workspaces.find((workspace) => workspace.name.toLowerCase() === "main");
1292
- }
1293
- );
1294
- const selectWorkspaceById = (id) => (state) => {
1295
- return state.workspaceReducer.instances[id];
1296
- };
1297
- const selectPermittedWorkspaceIds = toolkit.createSelector(
1298
- [selectWorkspaceMapping],
1299
- (mapping) => {
1300
- return new Set(
1301
- Object.values(mapping).filter((workspace) => workspace.permitted).map((workspace) => workspace.offline_id)
1302
- );
1303
- }
1304
- );
1305
- const workspaceReducer = workspaceSlice.reducer;
1306
- const maxRecentIssues = 10;
1307
1284
  const issueAdapter = createModelAdapter((issue) => issue.offline_id);
1308
- const initialState$s = issueAdapter.getInitialState({
1309
- recentIssueIds: []
1310
- });
1285
+ const initialState$t = issueAdapter.getInitialState({});
1311
1286
  const issueSlice = toolkit.createSlice({
1312
1287
  name: "issues",
1313
- initialState: initialState$s,
1288
+ initialState: initialState$t,
1314
1289
  extraReducers: (builder) => builder.addCase("RESET", (state) => {
1315
- Object.assign(state, initialState$s);
1290
+ Object.assign(state, initialState$t);
1316
1291
  }),
1317
1292
  reducers: {
1318
1293
  initializeIssues: issueAdapter.initialize,
@@ -1320,104 +1295,14 @@ var __publicField = (obj, key, value) => {
1320
1295
  addIssues: issueAdapter.addMany,
1321
1296
  updateIssue: issueAdapter.updateOne,
1322
1297
  deleteIssue: issueAdapter.deleteOne,
1323
- deleteIssues: issueAdapter.deleteMany,
1324
- cleanRecentIssues: (state) => {
1325
- state.recentIssueIds = state.recentIssueIds.filter((recentIssue) => state.instances[recentIssue.offlineId]);
1326
- },
1327
- addToRecentIssues: (state, action) => {
1328
- state.recentIssueIds = state.recentIssueIds.filter(
1329
- (recentIssue) => recentIssue.offlineId !== action.payload
1330
- );
1331
- state.recentIssueIds.push({ offlineId: action.payload.toLowerCase(), lastOpenedEpochTime: Date.now() });
1332
- if (state.recentIssueIds.length > maxRecentIssues) {
1333
- state.recentIssueIds.shift();
1334
- }
1335
- },
1336
- resetRecentIssues: (state) => {
1337
- state.recentIssueIds = [];
1338
- },
1339
- removeRecentIssue: (state, action) => {
1340
- const indexToRemove = state.recentIssueIds.findIndex((item) => {
1341
- return item.offlineId == action.payload;
1342
- });
1343
- if (indexToRemove !== -1) {
1344
- state.recentIssueIds.splice(indexToRemove, 1);
1345
- }
1346
- }
1298
+ deleteIssues: issueAdapter.deleteMany
1347
1299
  }
1348
1300
  });
1349
- const {
1350
- initializeIssues,
1351
- addIssue,
1352
- addIssues,
1353
- updateIssue,
1354
- deleteIssue,
1355
- deleteIssues,
1356
- addToRecentIssues,
1357
- cleanRecentIssues,
1358
- removeRecentIssue,
1359
- resetRecentIssues
1360
- } = issueSlice.actions;
1301
+ const { initializeIssues, addIssue, addIssues, updateIssue, deleteIssue, deleteIssues } = issueSlice.actions;
1361
1302
  const selectIssueMapping = (state) => state.issueReducer.instances;
1362
- const selectRecentIssueIds = (state) => state.issueReducer.recentIssueIds;
1363
1303
  const selectIssueById = (id) => (state) => {
1364
1304
  return state.issueReducer.instances[id];
1365
1305
  };
1366
- const searchIssues = restructureCreateSelectorWithArgs(
1367
- toolkit.createSelector(
1368
- [selectIssueMapping, selectWorkspaceMapping, (_state, searchArgs) => searchArgs],
1369
- (mapping, workspaceMapping, searchArgs) => {
1370
- let searchTerm = searchArgs.searchTerm;
1371
- const maxResults = searchArgs.maxResults;
1372
- searchTerm = searchTerm.toLowerCase();
1373
- const ret = [];
1374
- const issues = Object.values(mapping);
1375
- let nbResults = 0;
1376
- for (const issue of issues) {
1377
- if (!issue.index_workspace) {
1378
- logOnlyOnce(
1379
- "issue-has-no-index-workspace",
1380
- issue.offline_id,
1381
- "warn",
1382
- `Issue ${issue.offline_id} has no index_workspace and cannot be searched.`
1383
- );
1384
- continue;
1385
- }
1386
- const workspace = workspaceMapping[issue.index_workspace];
1387
- if (!workspace) {
1388
- logOnlyOnce(
1389
- "issue-has-non-existent-index-workspace",
1390
- issue.offline_id,
1391
- "warn",
1392
- `Encountered issue with an index_workspace that doesn't exist. Issue ${issue.offline_id} has
1393
- index_workspace = ${issue.index_workspace}, which does not exist in:`,
1394
- Object.keys(workspaceMapping)
1395
- );
1396
- continue;
1397
- }
1398
- const workspaceAbbreviation = workspace.abbreviation;
1399
- if (!workspaceAbbreviation) {
1400
- logOnlyOnce(
1401
- "workspace-has-no-abbreviation",
1402
- workspace.offline_id,
1403
- "error",
1404
- `Workspace ${workspace.name} has no abbreviation. Not including any issues in search.`
1405
- );
1406
- continue;
1407
- }
1408
- const tag = "index" in issue ? `${workspaceAbbreviation.toUpperCase()}-${issue.index}` : null;
1409
- if ((issue.title || "").toLowerCase().includes(searchTerm) || tag && tag.toLowerCase().includes(searchTerm)) {
1410
- ret.push(issueToSearchResult(issue, tag));
1411
- nbResults++;
1412
- if (maxResults && nbResults >= maxResults) {
1413
- return ret;
1414
- }
1415
- }
1416
- }
1417
- return ret;
1418
- }
1419
- )
1420
- );
1421
1306
  const selectIssuesByIds = restructureCreateSelectorWithArgs(
1422
1307
  toolkit.createSelector([selectIssueMapping, (_, issueIds) => issueIds], (issuesMapping, issueIds) => {
1423
1308
  const issues = [];
@@ -1432,48 +1317,14 @@ var __publicField = (obj, key, value) => {
1432
1317
  return fallbackToEmptyArray(issues);
1433
1318
  })
1434
1319
  );
1435
- const selectRecentIssuesAsSearchResults = toolkit.createSelector(
1436
- [selectIssueMapping, selectRecentIssueIds, selectWorkspaceMapping],
1437
- (issueMapping, recentIssueIds, workspaceMapping) => {
1438
- const ret = [];
1439
- for (const recentIssueResult of recentIssueIds) {
1440
- const issue = issueMapping[recentIssueResult.offlineId];
1441
- if (!issue) {
1442
- console.info("Recent issue no longer exists");
1443
- continue;
1444
- }
1445
- if ("index" in issue && issue.index_workspace) {
1446
- const indexWorkspace = workspaceMapping[issue.index_workspace];
1447
- if (!indexWorkspace) {
1448
- logOnlyOnce(
1449
- "issue-has-index-but-not-index-workspace",
1450
- issue.offline_id,
1451
- "warn",
1452
- `Issue ${issue.offline_id} has an index but no index_workspace. This may be because the
1453
- workspace has been deleted, but the new index has not been returned by the server yet. It will not
1454
- be included in search results.`
1455
- );
1456
- continue;
1457
- }
1458
- const workspaceTag = `${indexWorkspace.abbreviation}-${issue.index}`;
1459
- const searchResult = {
1460
- ...issueToSearchResult(issue, workspaceTag),
1461
- lastOpenedEpochTime: recentIssueResult.lastOpenedEpochTime
1462
- };
1463
- ret.push(searchResult);
1464
- }
1465
- }
1466
- return ret;
1467
- }
1468
- );
1469
1320
  const issueReducer = issueSlice.reducer;
1470
1321
  const issueTypeAdapter = createModelAdapter((issueType) => issueType.offline_id);
1471
- const initialState$r = issueTypeAdapter.getInitialState({});
1322
+ const initialState$s = issueTypeAdapter.getInitialState({});
1472
1323
  const issueTypeSlice = toolkit.createSlice({
1473
1324
  name: "issueTypes",
1474
- initialState: initialState$r,
1325
+ initialState: initialState$s,
1475
1326
  extraReducers: (builder) => builder.addCase("RESET", (state) => {
1476
- Object.assign(state, initialState$r);
1327
+ Object.assign(state, initialState$s);
1477
1328
  }),
1478
1329
  reducers: {
1479
1330
  initializeIssueTypes: issueTypeAdapter.initialize,
@@ -1515,123 +1366,64 @@ var __publicField = (obj, key, value) => {
1515
1366
  return fallbackToEmptyArray(issueTypes.filter((issueType) => issueType.organization === organizationId));
1516
1367
  }
1517
1368
  )
1518
- );
1519
- const selectIssuesOfIssueType = restructureCreateSelectorWithArgs(
1520
- toolkit.createSelector(
1521
- [(state) => state.issueReducer.instances, (_, issueTypeId) => issueTypeId],
1522
- (issuesMapping, issueTypeId) => {
1523
- return fallbackToEmptyArray(
1524
- Object.values(issuesMapping).filter((issue) => issue.issue_type === issueTypeId)
1525
- );
1526
- }
1527
- )
1528
- );
1529
- const selectIssuesOfIssueTypeCount = (issueTypeId) => (state) => {
1530
- return selectIssuesOfIssueType(issueTypeId)(state).length;
1531
- };
1532
- const issueTypeReducer = issueTypeSlice.reducer;
1533
- const initialState$q = {
1534
- s3Urls: {}
1535
- };
1536
- const msPerHour = 1e3 * 60 * 60;
1537
- const msPerWeek = msPerHour * 24 * 7;
1538
- const fileSlice = toolkit.createSlice({
1539
- name: "file",
1540
- initialState: initialState$q,
1541
- extraReducers: (builder) => builder.addCase("RESET", (state) => Object.assign(state, initialState$q)),
1542
- reducers: {
1543
- setUploadUrl: (state, action) => {
1544
- const { url, fields, sha1 } = action.payload;
1545
- const today2 = /* @__PURE__ */ new Date();
1546
- const weekFromToday = new Date(today2.getTime() + msPerWeek);
1547
- state.s3Urls[sha1] = {
1548
- url,
1549
- fields,
1550
- exp: weekFromToday.getTime()
1551
- };
1552
- }
1553
- }
1554
- });
1555
- const { setUploadUrl } = fileSlice.actions;
1556
- const selectUploadUrl = (sha1) => (state) => {
1557
- const url = state.fileReducer.s3Urls[sha1];
1558
- if (!url) {
1559
- return void 0;
1560
- }
1561
- const today2 = (/* @__PURE__ */ new Date()).getTime();
1562
- const expiringWithinAnHour = (url.exp ?? today2) - today2 < msPerHour;
1563
- if (expiringWithinAnHour)
1564
- return void 0;
1565
- return url;
1566
- };
1567
- const fileReducer = fileSlice.reducer;
1568
- var ProjectAccessLevel = /* @__PURE__ */ ((ProjectAccessLevel2) => {
1569
- ProjectAccessLevel2[ProjectAccessLevel2["BASIC"] = 0] = "BASIC";
1570
- ProjectAccessLevel2[ProjectAccessLevel2["ADMIN"] = 2] = "ADMIN";
1571
- return ProjectAccessLevel2;
1572
- })(ProjectAccessLevel || {});
1573
- var OrganizationAccessLevel = /* @__PURE__ */ ((OrganizationAccessLevel2) => {
1574
- OrganizationAccessLevel2[OrganizationAccessLevel2["BASIC"] = 0] = "BASIC";
1575
- OrganizationAccessLevel2[OrganizationAccessLevel2["ADMIN"] = 2] = "ADMIN";
1576
- return OrganizationAccessLevel2;
1577
- })(OrganizationAccessLevel || {});
1578
- var AttachmentModel = /* @__PURE__ */ ((AttachmentModel2) => {
1579
- AttachmentModel2["Issue"] = "issue";
1580
- AttachmentModel2["Asset"] = "asset";
1581
- AttachmentModel2["AssetType"] = "asset_type";
1582
- AttachmentModel2["Project"] = "project";
1583
- AttachmentModel2["Document"] = "document";
1584
- return AttachmentModel2;
1585
- })(AttachmentModel || {});
1586
- var IssueUpdateChange = /* @__PURE__ */ ((IssueUpdateChange2) => {
1587
- IssueUpdateChange2["STATUS"] = "status";
1588
- IssueUpdateChange2["PRIORITY"] = "priority";
1589
- IssueUpdateChange2["CATEGORY"] = "category";
1590
- IssueUpdateChange2["DESCRIPTION"] = "description";
1591
- IssueUpdateChange2["TITLE"] = "title";
1592
- IssueUpdateChange2["ASSIGNED_TO"] = "assigned_to";
1593
- IssueUpdateChange2["DUE_DATE"] = "due_date";
1594
- return IssueUpdateChange2;
1595
- })(IssueUpdateChange || {});
1596
- var VerificationCodeType = /* @__PURE__ */ ((VerificationCodeType2) => {
1597
- VerificationCodeType2[VerificationCodeType2["USER_REGISTRATION"] = 0] = "USER_REGISTRATION";
1598
- VerificationCodeType2[VerificationCodeType2["APPLICATION_INVITE"] = 2] = "APPLICATION_INVITE";
1599
- VerificationCodeType2[VerificationCodeType2["PROJECT_INVITE"] = 4] = "PROJECT_INVITE";
1600
- VerificationCodeType2[VerificationCodeType2["ORGANIZATION_INVITE"] = 6] = "ORGANIZATION_INVITE";
1601
- VerificationCodeType2[VerificationCodeType2["ADD_EMAIL_DOMAIN"] = 8] = "ADD_EMAIL_DOMAIN";
1602
- VerificationCodeType2[VerificationCodeType2["RESET_PASSWORD"] = 10] = "RESET_PASSWORD";
1603
- return VerificationCodeType2;
1604
- })(VerificationCodeType || {});
1605
- var PaddleCheckoutEvent = /* @__PURE__ */ ((PaddleCheckoutEvent2) => {
1606
- PaddleCheckoutEvent2["COMPLETED"] = "checkout.completed";
1607
- PaddleCheckoutEvent2["CLOSED"] = "checkout.closed";
1608
- return PaddleCheckoutEvent2;
1609
- })(PaddleCheckoutEvent || {});
1610
- var LicenseLevel = /* @__PURE__ */ ((LicenseLevel2) => {
1611
- LicenseLevel2[LicenseLevel2["PRO"] = 0] = "PRO";
1612
- return LicenseLevel2;
1613
- })(LicenseLevel || {});
1614
- var LicenseStatus = /* @__PURE__ */ ((LicenseStatus2) => {
1615
- LicenseStatus2[LicenseStatus2["ACTIVE"] = 0] = "ACTIVE";
1616
- LicenseStatus2[LicenseStatus2["PAUSED"] = 2] = "PAUSED";
1617
- LicenseStatus2[LicenseStatus2["CANCELLED"] = 4] = "CANCELLED";
1618
- LicenseStatus2[LicenseStatus2["INACTIVE"] = 6] = "INACTIVE";
1619
- LicenseStatus2[LicenseStatus2["PAST_DUE"] = 8] = "PAST_DUE";
1620
- return LicenseStatus2;
1621
- })(LicenseStatus || {});
1622
- const initialState$p = {
1623
- users: {},
1624
- currentUser: {
1625
- id: 0,
1626
- username: "",
1627
- email: "",
1628
- profile: { file: null, file_sha1: null, favourite_project_ids: [], tour_step: -1 }
1369
+ );
1370
+ const selectIssuesOfIssueType = restructureCreateSelectorWithArgs(
1371
+ toolkit.createSelector(
1372
+ [(state) => state.issueReducer.instances, (_, issueTypeId) => issueTypeId],
1373
+ (issuesMapping, issueTypeId) => {
1374
+ return fallbackToEmptyArray(
1375
+ Object.values(issuesMapping).filter((issue) => issue.issue_type === issueTypeId)
1376
+ );
1377
+ }
1378
+ )
1379
+ );
1380
+ const selectIssuesOfIssueTypeCount = (issueTypeId) => (state) => {
1381
+ return selectIssuesOfIssueType(issueTypeId)(state).length;
1382
+ };
1383
+ const issueTypeReducer = issueTypeSlice.reducer;
1384
+ const initialState$r = {
1385
+ s3Urls: {}
1386
+ };
1387
+ const msPerHour = 1e3 * 60 * 60;
1388
+ const msPerWeek = msPerHour * 24 * 7;
1389
+ const fileSlice = toolkit.createSlice({
1390
+ name: "file",
1391
+ initialState: initialState$r,
1392
+ extraReducers: (builder) => builder.addCase("RESET", (state) => Object.assign(state, initialState$r)),
1393
+ reducers: {
1394
+ setUploadUrl: (state, action) => {
1395
+ const { url, fields, sha1 } = action.payload;
1396
+ const today2 = /* @__PURE__ */ new Date();
1397
+ const weekFromToday = new Date(today2.getTime() + msPerWeek);
1398
+ state.s3Urls[sha1] = {
1399
+ url,
1400
+ fields,
1401
+ exp: weekFromToday.getTime()
1402
+ };
1403
+ }
1404
+ }
1405
+ });
1406
+ const { setUploadUrl } = fileSlice.actions;
1407
+ const selectUploadUrl = (sha1) => (state) => {
1408
+ const url = state.fileReducer.s3Urls[sha1];
1409
+ if (!url) {
1410
+ return void 0;
1629
1411
  }
1412
+ const today2 = (/* @__PURE__ */ new Date()).getTime();
1413
+ const expiringWithinAnHour = (url.exp ?? today2) - today2 < msPerHour;
1414
+ if (expiringWithinAnHour)
1415
+ return void 0;
1416
+ return url;
1417
+ };
1418
+ const fileReducer = fileSlice.reducer;
1419
+ const initialState$q = {
1420
+ users: {},
1421
+ currentUser: null
1630
1422
  };
1631
1423
  const userSlice = toolkit.createSlice({
1632
1424
  name: "users",
1633
- initialState: initialState$p,
1634
- extraReducers: (builder) => builder.addCase("RESET", (state) => Object.assign(state, initialState$p)),
1425
+ initialState: initialState$q,
1426
+ extraReducers: (builder) => builder.addCase("RESET", (state) => Object.assign(state, initialState$q)),
1635
1427
  reducers: {
1636
1428
  setUsers: (state, action) => {
1637
1429
  const usersMapping = {};
@@ -1649,6 +1441,8 @@ var __publicField = (obj, key, value) => {
1649
1441
  state.currentUser = action.payload;
1650
1442
  },
1651
1443
  setProfilePicture: (state, action) => {
1444
+ if (!state.currentUser)
1445
+ return;
1652
1446
  state.currentUser.profile.file = action.payload.file ?? null;
1653
1447
  state.currentUser.profile.file_sha1 = action.payload.file_sha1 ?? null;
1654
1448
  const currentUser = state.users[state.currentUser.id];
@@ -1658,32 +1452,12 @@ var __publicField = (obj, key, value) => {
1658
1452
  currentUser.profile.file = action.payload.file ?? null;
1659
1453
  currentUser.profile.file_sha1 = action.payload.file_sha1 ?? null;
1660
1454
  },
1661
- addFavouriteProjectId: (state, action) => {
1662
- state.currentUser.profile.favourite_project_ids.push(action.payload);
1663
- },
1664
- removeFavouriteProjectId: (state, action) => {
1665
- state.currentUser.profile.favourite_project_ids = state.currentUser.profile.favourite_project_ids.filter(
1666
- (id) => id !== action.payload
1667
- );
1668
- },
1669
- setTourStep: (state, action) => {
1670
- state.currentUser.profile.tour_step = action.payload;
1671
- },
1672
1455
  removeUser: (state, action) => {
1673
1456
  delete state.users[action.payload];
1674
1457
  }
1675
1458
  }
1676
1459
  });
1677
- const {
1678
- setCurrentUser,
1679
- setProfilePicture,
1680
- setUsers,
1681
- addUsers,
1682
- addFavouriteProjectId,
1683
- removeFavouriteProjectId,
1684
- setTourStep,
1685
- removeUser
1686
- } = userSlice.actions;
1460
+ const { setCurrentUser, setProfilePicture, setUsers, addUsers, removeUser } = userSlice.actions;
1687
1461
  const userReducer = userSlice.reducer;
1688
1462
  const selectCurrentUser = (state) => state.userReducer.currentUser;
1689
1463
  const selectUsersMapping = (state) => state.userReducer.users;
@@ -1704,15 +1478,14 @@ var __publicField = (obj, key, value) => {
1704
1478
  return fallbackToEmptyArray(users);
1705
1479
  })
1706
1480
  );
1707
- const selectFavouriteProjects = (state) => state.userReducer.currentUser.profile.favourite_project_ids;
1708
1481
  const organizationAccessAdapter = createModelAdapter(
1709
1482
  (organizationAccess) => organizationAccess.offline_id
1710
1483
  );
1711
- const initialState$o = organizationAccessAdapter.getInitialState({});
1484
+ const initialState$p = organizationAccessAdapter.getInitialState({});
1712
1485
  const organizationAccessSlice = toolkit.createSlice({
1713
1486
  name: "organizationAccess",
1714
- initialState: initialState$o,
1715
- extraReducers: (builder) => builder.addCase("RESET", (state) => Object.assign(state, initialState$o)),
1487
+ initialState: initialState$p,
1488
+ extraReducers: (builder) => builder.addCase("RESET", (state) => Object.assign(state, initialState$p)),
1716
1489
  reducers: {
1717
1490
  initializeOrganizationAccesses: organizationAccessAdapter.initialize,
1718
1491
  updateOrganizationAccess: organizationAccessAdapter.updateOne,
@@ -1730,7 +1503,7 @@ var __publicField = (obj, key, value) => {
1730
1503
  [selectCurrentUser, selectOrganizationAccesses],
1731
1504
  (currentUser, organizationAccesses) => {
1732
1505
  const activeOrganizationAccess = Object.values(organizationAccesses).find(
1733
- (organizationAccess) => organizationAccess.user === currentUser.id
1506
+ (organizationAccess) => organizationAccess.user === (currentUser == null ? void 0 : currentUser.id)
1734
1507
  );
1735
1508
  return activeOrganizationAccess ?? null;
1736
1509
  }
@@ -1749,11 +1522,11 @@ var __publicField = (obj, key, value) => {
1749
1522
  };
1750
1523
  const organizationAccessReducer = organizationAccessSlice.reducer;
1751
1524
  const licenseAdapter = createModelAdapter((license) => license.offline_id);
1752
- const initialState$n = licenseAdapter.getInitialState({});
1525
+ const initialState$o = licenseAdapter.getInitialState({});
1753
1526
  const licenseSlice = toolkit.createSlice({
1754
1527
  name: "license",
1755
- initialState: initialState$n,
1756
- extraReducers: (builder) => builder.addCase("RESET", (state) => Object.assign(state, initialState$n)),
1528
+ initialState: initialState$o,
1529
+ extraReducers: (builder) => builder.addCase("RESET", (state) => Object.assign(state, initialState$o)),
1757
1530
  reducers: {
1758
1531
  initializeLicences: licenseAdapter.initialize,
1759
1532
  addLicenses: licenseAdapter.addMany,
@@ -1778,11 +1551,11 @@ var __publicField = (obj, key, value) => {
1778
1551
  );
1779
1552
  const licenseReducer = licenseSlice.reducer;
1780
1553
  const projectAccessAdapter = createModelAdapter((projectAccess) => projectAccess.offline_id);
1781
- const initialState$m = projectAccessAdapter.getInitialState({});
1554
+ const initialState$n = projectAccessAdapter.getInitialState({});
1782
1555
  const projectAccessSlice = toolkit.createSlice({
1783
1556
  name: "projectAccess",
1784
- initialState: initialState$m,
1785
- extraReducers: (builder) => builder.addCase("RESET", (state) => Object.assign(state, initialState$m)),
1557
+ initialState: initialState$n,
1558
+ extraReducers: (builder) => builder.addCase("RESET", (state) => Object.assign(state, initialState$n)),
1786
1559
  reducers: {
1787
1560
  initializeProjectAccesses: projectAccessAdapter.initialize,
1788
1561
  updateProjectAccess: projectAccessAdapter.updateOne,
@@ -1807,7 +1580,7 @@ var __publicField = (obj, key, value) => {
1807
1580
  const currentUser = state.userReducer.currentUser;
1808
1581
  const activeProjectId = state.projectReducer.activeProjectId;
1809
1582
  return Object.values(state.projectAccessReducer.instances).find((projectAccess) => {
1810
- return projectAccess.user === currentUser.id && projectAccess.project === activeProjectId;
1583
+ return projectAccess.user === (currentUser == null ? void 0 : currentUser.id) && projectAccess.project === activeProjectId;
1811
1584
  }) ?? null;
1812
1585
  };
1813
1586
  const selectProjectAccessForUser = (user) => (state) => {
@@ -1823,14 +1596,14 @@ var __publicField = (obj, key, value) => {
1823
1596
  return projectAccesses;
1824
1597
  };
1825
1598
  const projectAccessReducer = projectAccessSlice.reducer;
1826
- const initialState$l = {
1599
+ const initialState$m = {
1827
1600
  projects: {},
1828
1601
  activeProjectId: null
1829
1602
  };
1830
1603
  const projectSlice = toolkit.createSlice({
1831
1604
  name: "projects",
1832
- initialState: initialState$l,
1833
- extraReducers: (builder) => builder.addCase("RESET", (state) => Object.assign(state, initialState$l)),
1605
+ initialState: initialState$m,
1606
+ extraReducers: (builder) => builder.addCase("RESET", (state) => Object.assign(state, initialState$m)),
1834
1607
  reducers: {
1835
1608
  setProjects: (state, action) => {
1836
1609
  const projectsMap = {};
@@ -1920,9 +1693,9 @@ var __publicField = (obj, key, value) => {
1920
1693
  [selectCurrentUser, selectProjectUsersAsMapping, selectProjectAccessUserMapping],
1921
1694
  (currentUser, userMapping, projectAccessMapping) => {
1922
1695
  return Object.values(userMapping).sort((userA, userB) => {
1923
- if (userA.id === currentUser.id) {
1696
+ if (userA.id === (currentUser == null ? void 0 : currentUser.id)) {
1924
1697
  return -1;
1925
- } else if (userB.id === currentUser.id) {
1698
+ } else if (userB.id === (currentUser == null ? void 0 : currentUser.id)) {
1926
1699
  return 1;
1927
1700
  }
1928
1701
  const projectAccessesA = projectAccessMapping[userA.id];
@@ -1937,13 +1710,13 @@ var __publicField = (obj, key, value) => {
1937
1710
  });
1938
1711
  }
1939
1712
  );
1940
- const initialState$k = {
1713
+ const initialState$l = {
1941
1714
  organizations: {}
1942
1715
  };
1943
1716
  const organizationSlice = toolkit.createSlice({
1944
1717
  name: "organizations",
1945
- initialState: initialState$k,
1946
- extraReducers: (builder) => builder.addCase("RESET", (state) => Object.assign(state, initialState$k)),
1718
+ initialState: initialState$l,
1719
+ extraReducers: (builder) => builder.addCase("RESET", (state) => Object.assign(state, initialState$l)),
1947
1720
  reducers: {
1948
1721
  setOrganizations: (state, action) => {
1949
1722
  for (const org of action.payload) {
@@ -1999,9 +1772,9 @@ var __publicField = (obj, key, value) => {
1999
1772
  [selectCurrentUser, selectOrganizationUsersAsMapping, selectOrganizationAccessUserMapping],
2000
1773
  (currentUser, userMapping, organizationAccessMapping) => {
2001
1774
  return Object.values(userMapping).sort((userA, userB) => {
2002
- if (userA.id === currentUser.id) {
1775
+ if (userA.id === (currentUser == null ? void 0 : currentUser.id)) {
2003
1776
  return -1;
2004
- } else if (userB.id === currentUser.id) {
1777
+ } else if (userB.id === (currentUser == null ? void 0 : currentUser.id)) {
2005
1778
  return 1;
2006
1779
  }
2007
1780
  const organizationAccessesA = organizationAccessMapping[userA.id];
@@ -2034,14 +1807,14 @@ var __publicField = (obj, key, value) => {
2034
1807
  }
2035
1808
  };
2036
1809
  };
2037
- const initialState$j = {
1810
+ const initialState$k = {
2038
1811
  deletedRequests: [],
2039
1812
  latestRetryTime: 0
2040
1813
  };
2041
1814
  const outboxSlice = toolkit.createSlice({
2042
1815
  name: "outbox",
2043
- initialState: initialState$j,
2044
- extraReducers: (builder) => builder.addCase("RESET", (state) => Object.assign(state, initialState$j)),
1816
+ initialState: initialState$k,
1817
+ extraReducers: (builder) => builder.addCase("RESET", (state) => Object.assign(state, initialState$k)),
2045
1818
  reducers: {
2046
1819
  // enqueueActions is a reducer that does nothing but enqueue API request to the Redux Offline outbox
2047
1820
  // Whenever an issue is being created, a reducer addIssue() is responsible for adding it to the offline store
@@ -2073,15 +1846,15 @@ var __publicField = (obj, key, value) => {
2073
1846
  const selectLatestRetryTime = (state) => state.outboxReducer.latestRetryTime;
2074
1847
  const { enqueueRequest, markForDeletion, markAsDeleted, _setLatestRetryTime } = outboxSlice.actions;
2075
1848
  const outboxReducer = outboxSlice.reducer;
2076
- const initialState$i = {
1849
+ const initialState$j = {
2077
1850
  projectFiles: {},
2078
1851
  activeProjectFileId: null,
2079
1852
  isImportingProjectFile: false
2080
1853
  };
2081
1854
  const projectFileSlice = toolkit.createSlice({
2082
1855
  name: "projectFiles",
2083
- initialState: initialState$i,
2084
- extraReducers: (builder) => builder.addCase("RESET", (state) => Object.assign(state, initialState$i)),
1856
+ initialState: initialState$j,
1857
+ extraReducers: (builder) => builder.addCase("RESET", (state) => Object.assign(state, initialState$j)),
2085
1858
  reducers: {
2086
1859
  addOrReplaceProjectFiles: (state, action) => {
2087
1860
  for (let fileObj of action.payload) {
@@ -2168,11 +1941,11 @@ var __publicField = (obj, key, value) => {
2168
1941
  };
2169
1942
  const projectFileReducer = projectFileSlice.reducer;
2170
1943
  const projectAttachmentAdapter = createModelAdapter((attachment) => attachment.offline_id);
2171
- const initialState$h = projectAttachmentAdapter.getInitialState({});
1944
+ const initialState$i = projectAttachmentAdapter.getInitialState({});
2172
1945
  const projectAttachmentSlice = toolkit.createSlice({
2173
1946
  name: "projectAttachments",
2174
- initialState: initialState$h,
2175
- extraReducers: (builder) => builder.addCase("RESET", (state) => Object.assign(state, initialState$h)),
1947
+ initialState: initialState$i,
1948
+ extraReducers: (builder) => builder.addCase("RESET", (state) => Object.assign(state, initialState$i)),
2176
1949
  reducers: {
2177
1950
  initializeProjectAttachments: projectAttachmentAdapter.initialize,
2178
1951
  addProjectAttachment: projectAttachmentAdapter.addOne,
@@ -2227,12 +2000,12 @@ var __publicField = (obj, key, value) => {
2227
2000
  )
2228
2001
  );
2229
2002
  const projectAttachmentReducer = projectAttachmentSlice.reducer;
2230
- const initialState$g = {
2003
+ const initialState$h = {
2231
2004
  isRehydrated: false
2232
2005
  };
2233
2006
  const rehydratedSlice = toolkit.createSlice({
2234
2007
  name: "rehydrated",
2235
- initialState: initialState$g,
2008
+ initialState: initialState$h,
2236
2009
  // The `reducers` field lets us define reducers and generate associated actions
2237
2010
  reducers: {
2238
2011
  setRehydrated: (state, action) => {
@@ -2257,11 +2030,11 @@ var __publicField = (obj, key, value) => {
2257
2030
  }
2258
2031
  };
2259
2032
  const formRevisionAdapter = createModelAdapter((revision) => revision.offline_id);
2260
- const initialState$f = formRevisionAdapter.getInitialState({});
2033
+ const initialState$g = formRevisionAdapter.getInitialState({});
2261
2034
  const formRevisionsSlice = toolkit.createSlice({
2262
2035
  name: "formRevisions",
2263
- initialState: initialState$f,
2264
- extraReducers: (builder) => builder.addCase("RESET", (state) => Object.assign(state, initialState$f)),
2036
+ initialState: initialState$g,
2037
+ extraReducers: (builder) => builder.addCase("RESET", (state) => Object.assign(state, initialState$g)),
2265
2038
  reducers: {
2266
2039
  initializeFormRevisions: formRevisionAdapter.initialize,
2267
2040
  setFormRevision: formRevisionAdapter.setOne,
@@ -2333,11 +2106,11 @@ var __publicField = (obj, key, value) => {
2333
2106
  });
2334
2107
  const formRevisionReducer = formRevisionsSlice.reducer;
2335
2108
  const formAdapter = createModelAdapter((form) => form.offline_id);
2336
- const initialState$e = formAdapter.getInitialState({});
2109
+ const initialState$f = formAdapter.getInitialState({});
2337
2110
  const formSlice = toolkit.createSlice({
2338
2111
  name: "forms",
2339
- initialState: initialState$e,
2340
- extraReducers: (builder) => builder.addCase("RESET", (state) => Object.assign(state, initialState$e)),
2112
+ initialState: initialState$f,
2113
+ extraReducers: (builder) => builder.addCase("RESET", (state) => Object.assign(state, initialState$f)),
2341
2114
  reducers: {
2342
2115
  initializeForms: formAdapter.initialize,
2343
2116
  setForm: formAdapter.setOne,
@@ -2363,29 +2136,18 @@ var __publicField = (obj, key, value) => {
2363
2136
  (_state, search) => search
2364
2137
  ],
2365
2138
  (formsMapping, revisions, search) => {
2366
- const { searchTerm, maxResults, favorites, organization } = search;
2367
- const favoriteMatches = [];
2139
+ const { searchTerm, maxResults, organization } = search;
2368
2140
  const regularMatches = [];
2369
2141
  for (const [formId, form] of Object.entries(formsMapping)) {
2370
- if (favorites !== void 0 && form.favorite != favorites)
2371
- continue;
2372
2142
  if (Number.isInteger(organization) && organization !== form.organization) {
2373
2143
  continue;
2374
2144
  }
2375
2145
  const latestRevision = _selectLatestFormRevision(revisions, formId);
2376
2146
  if (latestRevision.title.toLowerCase().includes(searchTerm.toLowerCase())) {
2377
- if (form.favorite) {
2378
- favoriteMatches.push({ ...form, latestRevision });
2379
- } else {
2380
- regularMatches.push({ ...form, latestRevision });
2381
- }
2382
- }
2383
- if (favoriteMatches.length >= maxResults) {
2384
- break;
2147
+ regularMatches.push(form);
2385
2148
  }
2386
2149
  }
2387
- const maxRegularMatches = maxResults - favoriteMatches.length;
2388
- return [...favoriteMatches, ...regularMatches.slice(0, maxRegularMatches)];
2150
+ return [...regularMatches.slice(0, maxResults)];
2389
2151
  },
2390
2152
  // as the argument is an object, we check the first level of properties for equality
2391
2153
  { memoizeOptions: { equalityCheck: shallowEqual } }
@@ -2417,11 +2179,11 @@ var __publicField = (obj, key, value) => {
2417
2179
  return Object.values(formsMapping).filter((form) => !form.asset_type).length;
2418
2180
  });
2419
2181
  const submissionAdapter = createModelAdapter((submission) => submission.offline_id);
2420
- const initialState$d = submissionAdapter.getInitialState({});
2182
+ const initialState$e = submissionAdapter.getInitialState({});
2421
2183
  const formSubmissionSlice = toolkit.createSlice({
2422
2184
  name: "formSubmissions",
2423
- initialState: initialState$d,
2424
- extraReducers: (builder) => builder.addCase("RESET", (state) => Object.assign(state, initialState$d)),
2185
+ initialState: initialState$e,
2186
+ extraReducers: (builder) => builder.addCase("RESET", (state) => Object.assign(state, initialState$e)),
2425
2187
  reducers: {
2426
2188
  initializeFormSubmissions: submissionAdapter.initialize,
2427
2189
  setFormSubmission: submissionAdapter.setOne,
@@ -2633,11 +2395,11 @@ var __publicField = (obj, key, value) => {
2633
2395
  const formSubmissionAttachmentAdapter = createModelAdapter(
2634
2396
  (attachment) => attachment.offline_id
2635
2397
  );
2636
- const initialState$c = formSubmissionAttachmentAdapter.getInitialState({});
2398
+ const initialState$d = formSubmissionAttachmentAdapter.getInitialState({});
2637
2399
  const formSubmissionAttachmentSlice = toolkit.createSlice({
2638
2400
  name: "formSubmissionAttachments",
2639
- initialState: initialState$c,
2640
- extraReducers: (builder) => builder.addCase("RESET", (state) => Object.assign(state, initialState$c)),
2401
+ initialState: initialState$d,
2402
+ extraReducers: (builder) => builder.addCase("RESET", (state) => Object.assign(state, initialState$d)),
2641
2403
  reducers: {
2642
2404
  initializeFormSubmissionAttachments: formSubmissionAttachmentAdapter.initialize,
2643
2405
  addFormSubmissionAttachment: formSubmissionAttachmentAdapter.addOne,
@@ -2689,11 +2451,11 @@ var __publicField = (obj, key, value) => {
2689
2451
  const formRevisionAttachmentAdapter = createModelAdapter(
2690
2452
  (attachment) => attachment.offline_id
2691
2453
  );
2692
- const initialState$b = formRevisionAttachmentAdapter.getInitialState({});
2454
+ const initialState$c = formRevisionAttachmentAdapter.getInitialState({});
2693
2455
  const formRevisionAttachmentSlice = toolkit.createSlice({
2694
2456
  name: "formRevisionAttachments",
2695
- initialState: initialState$b,
2696
- extraReducers: (builder) => builder.addCase("RESET", (state) => Object.assign(state, initialState$b)),
2457
+ initialState: initialState$c,
2458
+ extraReducers: (builder) => builder.addCase("RESET", (state) => Object.assign(state, initialState$c)),
2697
2459
  reducers: {
2698
2460
  initializeFormRevisionAttachments: formRevisionAttachmentAdapter.initialize,
2699
2461
  addFormRevisionAttachment: formRevisionAttachmentAdapter.addOne,
@@ -2731,6 +2493,40 @@ var __publicField = (obj, key, value) => {
2731
2493
  )
2732
2494
  );
2733
2495
  const formRevisionAttachmentReducer = formRevisionAttachmentSlice.reducer;
2496
+ const workspaceAdapter = createModelAdapter((workspace) => workspace.offline_id);
2497
+ const initialState$b = workspaceAdapter.getInitialState({});
2498
+ const workspaceSlice = toolkit.createSlice({
2499
+ name: "workspace",
2500
+ initialState: initialState$b,
2501
+ reducers: {
2502
+ initializeWorkspaces: workspaceAdapter.initialize,
2503
+ setWorkspaces: workspaceAdapter.setMany,
2504
+ addWorkspace: workspaceAdapter.addOne,
2505
+ updateWorkspace: workspaceAdapter.updateOne,
2506
+ deleteWorkspace: workspaceAdapter.deleteOne
2507
+ }
2508
+ });
2509
+ const { initializeWorkspaces, setWorkspaces, addWorkspace, updateWorkspace, deleteWorkspace } = workspaceSlice.actions;
2510
+ const selectWorkspaceMapping = (state) => state.workspaceReducer.instances;
2511
+ const selectWorkspaces = toolkit.createSelector([selectWorkspaceMapping], (mapping) => Object.values(mapping));
2512
+ const selectMainWorkspace = toolkit.createSelector(
2513
+ [selectWorkspaces],
2514
+ (workspaces) => {
2515
+ return workspaces.find((workspace) => workspace.name.toLowerCase() === "main");
2516
+ }
2517
+ );
2518
+ const selectWorkspaceById = (id) => (state) => {
2519
+ return state.workspaceReducer.instances[id];
2520
+ };
2521
+ const selectPermittedWorkspaceIds = toolkit.createSelector(
2522
+ [selectWorkspaceMapping],
2523
+ (mapping) => {
2524
+ return new Set(
2525
+ Object.values(mapping).filter((workspace) => workspace.permitted).map((workspace) => workspace.offline_id)
2526
+ );
2527
+ }
2528
+ );
2529
+ const workspaceReducer = workspaceSlice.reducer;
2734
2530
  const emailDomainAdapter = createModelAdapter((emailDomain) => emailDomain.offline_id);
2735
2531
  const initialState$a = emailDomainAdapter.getInitialState({});
2736
2532
  const emailDomainsSlice = toolkit.createSlice({
@@ -3119,13 +2915,13 @@ var __publicField = (obj, key, value) => {
3119
2915
  deleteIssueComments
3120
2916
  } = issueCommentSlice.actions;
3121
2917
  const selectIssueCommentMapping = (state) => state.issueCommentReducer.instances;
2918
+ const selectIssueCommentById = (id) => (state) => {
2919
+ return state.issueCommentReducer.instances[id];
2920
+ };
3122
2921
  const selectCommentsOfIssue = restructureCreateSelectorWithArgs(
3123
- toolkit.createSelector(
3124
- [selectIssueCommentMapping, (_state, issueId) => issueId],
3125
- (commentMapping, issueId) => {
3126
- return fallbackToEmptyArray(Object.values(commentMapping).filter((comment) => comment.issue === issueId));
3127
- }
3128
- )
2922
+ toolkit.createSelector([selectIssueCommentMapping, (_state, issueId) => issueId], (commentMapping, issueId) => {
2923
+ return fallbackToEmptyArray(Object.values(commentMapping).filter((comment) => comment.issue === issueId));
2924
+ })
3129
2925
  );
3130
2926
  const issueCommentReducer = issueCommentSlice.reducer;
3131
2927
  const issueUpdateAdapter = createModelAdapter((issueUpdate) => issueUpdate.offline_id);
@@ -3412,62 +3208,11 @@ var __publicField = (obj, key, value) => {
3412
3208
  };
3413
3209
  const overmapReducer = toolkit.combineReducers(overmapReducers);
3414
3210
  const resetStore = "RESET";
3415
- function handleWorkspaceRemoval(draft, action) {
3416
- const workspaceId = action.payload;
3417
- const issuesVisibleInWorkspace = Object.values(draft.issueReducer.instances).filter(
3418
- (issue) => issue.visible_in_workspaces.includes(workspaceId)
3419
- );
3420
- const mainWorkspace = selectMainWorkspace(draft);
3421
- if (!mainWorkspace) {
3422
- throw new Error("Main workspace not found");
3423
- }
3424
- if (action.payload === mainWorkspace.offline_id) {
3425
- throw new Error("Tried to delete main workspace");
3426
- }
3427
- const categoriesInThisWorkspace = new Set(
3428
- selectCategoriesOfWorkspace(workspaceId)(draft).map((category) => category.offline_id)
3429
- );
3430
- for (const issue of issuesVisibleInWorkspace) {
3431
- if (issue.category && categoriesInThisWorkspace.has(issue.category)) {
3432
- issue.category = null;
3433
- }
3434
- }
3435
- const issuesWithThisWorkspaceIndex = issuesVisibleInWorkspace.filter(
3436
- (issue) => issue.index_workspace === action.payload
3437
- );
3438
- for (const issue of issuesWithThisWorkspaceIndex) {
3439
- issue.index_workspace = mainWorkspace.offline_id;
3440
- if (!issue.visible_in_workspaces.includes(mainWorkspace.offline_id)) {
3441
- issue.visible_in_workspaces.push(mainWorkspace.offline_id);
3442
- }
3443
- }
3444
- for (const issue of issuesVisibleInWorkspace) {
3445
- const indexOfWorkspace = issue.visible_in_workspaces.indexOf(workspaceId);
3446
- if (indexOfWorkspace === -1) {
3447
- throw new Error("Workspace not found in issue's visible_in_workspaces");
3448
- }
3449
- issue.visible_in_workspaces.splice(indexOfWorkspace, 1);
3450
- }
3451
- for (const issue of issuesVisibleInWorkspace) {
3452
- if (issue.visible_in_workspaces.length === 0) {
3453
- throw new Error(`Unexpected error: Issue ${issue.offline_id} has no visible_in_workspaces`);
3454
- }
3455
- if (issue.index_workspace === action.payload || !issue.index_workspace) {
3456
- throw new Error(`Failed to update index_workspace of issue ${issue.offline_id} to main workspace`);
3457
- }
3458
- }
3459
- }
3460
3211
  const overmapRootReducer = (state, action) => {
3461
3212
  if (action.type === "auth/setLoggedIn" && !action.payload) {
3462
3213
  return overmapReducer(void 0, action);
3463
3214
  }
3464
- let mutatedState = state;
3465
- if (state && action.type === "workspace/removeWorkspace") {
3466
- mutatedState = toolkit.createNextState(state, (draft) => {
3467
- handleWorkspaceRemoval(draft, action);
3468
- });
3469
- }
3470
- return overmapReducer(mutatedState, action);
3215
+ return overmapReducer(state, action);
3471
3216
  };
3472
3217
  let __OUTBOX_COORDINATOR = null;
3473
3218
  function getOutboxCoordinator() {
@@ -4086,57 +3831,66 @@ var __publicField = (obj, key, value) => {
4086
3831
  }
4087
3832
  }
4088
3833
  class CategoryService extends BaseApiService {
4089
- add(category, workspaceId) {
4090
- const offlineCategory = offline(category);
4091
- const categoryWithWorkspace = { ...offlineCategory, workspace: workspaceId };
4092
- this.dispatch(addCategory(categoryWithWorkspace));
3834
+ add(payload) {
3835
+ var _a2;
3836
+ const { store } = this.client;
3837
+ const createdBy = (_a2 = store.getState().userReducer.currentUser) == null ? void 0 : _a2.id;
3838
+ const submittedAt = (/* @__PURE__ */ new Date()).toISOString();
3839
+ const offlineCategory = offline({
3840
+ ...payload,
3841
+ created_by: createdBy,
3842
+ submitted_at: submittedAt
3843
+ });
3844
+ this.dispatch(addCategory(offlineCategory));
4093
3845
  const promise = this.enqueueRequest({
4094
3846
  description: "Create Category",
4095
3847
  method: HttpMethod.POST,
4096
3848
  url: "/categories/",
4097
3849
  queryParams: {
4098
- workspace_id: workspaceId.toString()
3850
+ workspace_id: payload.workspace.toString()
4099
3851
  },
4100
3852
  payload: offlineCategory,
4101
- blockers: [],
3853
+ blockers: [payload.workspace],
4102
3854
  blocks: [offlineCategory.offline_id]
4103
3855
  });
4104
- return [categoryWithWorkspace, promise];
3856
+ return [offlineCategory, promise];
4105
3857
  }
4106
- update(category, workspaceId) {
3858
+ update(payload) {
4107
3859
  const state = this.client.store.getState();
4108
- const existingCategory = selectCategoryById(category.offline_id)(state);
3860
+ const existingCategory = selectCategoryById(payload.offline_id)(state);
4109
3861
  if (!existingCategory) {
4110
- throw new Error(`Expected an existing category with offline_id ${category.offline_id}`);
3862
+ throw new Error(`Expected an existing category with offline_id ${payload.offline_id}`);
4111
3863
  }
4112
- const optimisticCategory = { ...existingCategory, ...category };
3864
+ const optimisticCategory = { ...existingCategory, ...payload };
4113
3865
  this.dispatch(updateCategory(optimisticCategory));
4114
3866
  const promise = this.enqueueRequest({
4115
3867
  description: "Edit Category",
4116
3868
  method: HttpMethod.PATCH,
4117
- url: `/categories/${category.offline_id}/`,
4118
- queryParams: {
4119
- workspace_id: workspaceId.toString()
4120
- },
4121
- payload: category,
4122
- blockers: [category.offline_id],
4123
- blocks: [category.offline_id]
3869
+ url: `/categories/${payload.offline_id}/`,
3870
+ payload,
3871
+ blockers: [payload.offline_id],
3872
+ blocks: [payload.offline_id]
4124
3873
  });
4125
3874
  return [optimisticCategory, promise];
4126
3875
  }
4127
- remove(category, workspaceId) {
4128
- this.dispatch(deleteCategory(category.offline_id));
4129
- return this.enqueueRequest({
3876
+ remove(id) {
3877
+ const { store } = this.client;
3878
+ const category = selectCategoryById(id)(store.getState());
3879
+ if (!category) {
3880
+ throw new Error(`No category with id ${id} found in the store`);
3881
+ }
3882
+ this.dispatch(deleteCategory(id));
3883
+ const promise = this.enqueueRequest({
4130
3884
  description: "Delete Category",
4131
3885
  method: HttpMethod.DELETE,
4132
3886
  url: `/categories/${category.offline_id}/`,
4133
- // TODO: Shouldn't be necessary to specify workspace_id here
4134
- queryParams: {
4135
- workspace_id: workspaceId.toString()
4136
- },
4137
3887
  blockers: [category.offline_id],
4138
3888
  blocks: []
4139
3889
  });
3890
+ promise.catch(() => {
3891
+ this.dispatch(addCategory(category));
3892
+ });
3893
+ return promise;
4140
3894
  }
4141
3895
  async refreshStore(projectId) {
4142
3896
  const result = await this.enqueueRequest({
@@ -4160,53 +3914,81 @@ var __publicField = (obj, key, value) => {
4160
3914
  }
4161
3915
  class AssetService extends BaseApiService {
4162
3916
  // Basic CRUD functions
4163
- add(asset, workspaceId) {
4164
- if (!asset.canvas_marker && !asset.geo_marker) {
3917
+ add(payload) {
3918
+ const { store } = this.client;
3919
+ if (!payload.canvas_marker && !payload.geo_marker) {
4165
3920
  throw new Error("Asset must have either a canvas_marker or geo_marker");
4166
3921
  }
4167
- const offlineAsset = offline(asset);
3922
+ const createdBy = store.getState().userReducer.currentUser.id;
3923
+ const submittedAt = (/* @__PURE__ */ new Date()).toISOString();
3924
+ const offlineAsset = offline({
3925
+ ...payload,
3926
+ created_by: createdBy,
3927
+ submitted_at: submittedAt
3928
+ });
4168
3929
  this.dispatch(addAsset(offlineAsset));
4169
3930
  const promise = this.enqueueRequest({
4170
3931
  description: "Create asset",
4171
3932
  method: HttpMethod.POST,
4172
- url: `/assets/types/${offlineAsset.asset_type}/add-assets/`,
4173
- queryParams: {
4174
- workspace_id: workspaceId.toString()
3933
+ url: "/assets/",
3934
+ payload: {
3935
+ offline_id: offlineAsset.offline_id,
3936
+ submitted_at: offlineAsset.submitted_at,
3937
+ geo_marker: offlineAsset.geo_marker,
3938
+ canvas_marker: offlineAsset.canvas_marker,
3939
+ label: offlineAsset.label,
3940
+ description: offlineAsset.description,
3941
+ asset_type: offlineAsset.asset_type
4175
3942
  },
4176
- payload: { assets: [offlineAsset] },
4177
- blockers: [],
3943
+ blockers: [offlineAsset.asset_type],
4178
3944
  blocks: [offlineAsset.offline_id]
4179
3945
  });
3946
+ promise.then((createdAsset) => {
3947
+ this.dispatch(updateAsset(createdAsset));
3948
+ }).catch(() => {
3949
+ this.dispatch(deleteAsset(offlineAsset.offline_id));
3950
+ });
4180
3951
  return [offlineAsset, promise];
4181
3952
  }
4182
- update(asset, workspaceId) {
4183
- if (!asset.canvas_marker && !asset.geo_marker) {
3953
+ update(payload) {
3954
+ const { store } = this.client;
3955
+ if (!payload.canvas_marker && !payload.geo_marker) {
4184
3956
  throw new Error("Asset must have either a canvas_marker or geo_marker");
4185
3957
  }
4186
- this.client.store.dispatch(updateAsset(asset));
3958
+ const asset = selectAssetById(payload.offline_id)(store.getState());
3959
+ if (!asset) {
3960
+ throw new Error(`No asset with id ${payload.offline_id} found in the store`);
3961
+ }
3962
+ const updatedAsset = {
3963
+ ...asset,
3964
+ ...payload
3965
+ };
3966
+ this.dispatch(updateAsset(updatedAsset));
4187
3967
  const promise = this.enqueueRequest({
4188
3968
  description: "Edit asset",
4189
3969
  method: HttpMethod.PATCH,
4190
- url: `/assets/${asset.offline_id}/`,
4191
- queryParams: {
4192
- workspace_id: workspaceId.toString()
4193
- },
4194
- payload: asset,
4195
- blockers: [asset.offline_id],
4196
- blocks: [asset.offline_id]
3970
+ url: `/assets/${payload.offline_id}/`,
3971
+ payload,
3972
+ blockers: [payload.offline_id],
3973
+ blocks: [payload.offline_id]
3974
+ });
3975
+ promise.then((result) => {
3976
+ this.dispatch(updateAsset(result));
3977
+ }).catch(() => {
3978
+ this.dispatch(updateAsset(asset));
4197
3979
  });
4198
- return [asset, promise];
3980
+ return [updatedAsset, promise];
4199
3981
  }
4200
- async remove(assetId) {
3982
+ async remove(id) {
4201
3983
  const { store } = this.client;
4202
3984
  const state = store.getState();
4203
- const assetToBeDeleted = selectAssetById(assetId)(state);
3985
+ const assetToBeDeleted = selectAssetById(id)(state);
4204
3986
  if (!assetToBeDeleted)
4205
- throw new Error(`No asset with id ${assetId} found in the store`);
4206
- const attachmentsOfAssets = selectAttachmentsOfAsset(assetId)(state);
4207
- const formSubmissionsOfAssets = selectFormSubmissionsOfAsset(assetId)(state);
4208
- const issueAssociations = selectIssueAssociationsOfAsset(assetId)(state);
4209
- this.dispatch(deleteAsset(assetId));
3987
+ throw new Error(`No asset with id ${id} found in the store`);
3988
+ const attachmentsOfAssets = selectAttachmentsOfAsset(id)(state);
3989
+ const formSubmissionsOfAssets = selectFormSubmissionsOfAsset(id)(state);
3990
+ const issueAssociations = selectIssueAssociationsOfAsset(id)(state);
3991
+ this.dispatch(deleteAsset(id));
4210
3992
  if (attachmentsOfAssets.length > 0) {
4211
3993
  const attachmentsOfAssetIds = attachmentsOfAssets.map(({ offline_id }) => offline_id);
4212
3994
  this.dispatch(deleteAssetAttachments(attachmentsOfAssetIds));
@@ -4222,8 +4004,8 @@ var __publicField = (obj, key, value) => {
4222
4004
  return this.enqueueRequest({
4223
4005
  description: "Delete asset",
4224
4006
  method: HttpMethod.DELETE,
4225
- url: `/assets/${assetId}/`,
4226
- blockers: [assetId],
4007
+ url: `/assets/${id}/`,
4008
+ blockers: [id],
4227
4009
  blocks: []
4228
4010
  }).catch((err) => {
4229
4011
  this.dispatch(addAsset(assetToBeDeleted));
@@ -4233,39 +4015,17 @@ var __publicField = (obj, key, value) => {
4233
4015
  throw err;
4234
4016
  });
4235
4017
  }
4236
- async deleteAllAssetsOfAssetType(assetTypeId) {
4237
- const { store } = this.client;
4238
- const state = store.getState();
4239
- const allAssetsOfAssetType = selectAssetsOfAssetType(assetTypeId)(state);
4240
- const allAssetsOfAssetTypeIds = allAssetsOfAssetType.map((c) => c.offline_id);
4241
- const affectedOfflineIds = [assetTypeId, ...allAssetsOfAssetTypeIds];
4242
- store.dispatch(deleteAssets(allAssetsOfAssetTypeIds));
4243
- return this.enqueueRequest({
4244
- description: "Delete all assets of asset type",
4245
- method: HttpMethod.DELETE,
4246
- url: `/assets/types/${assetTypeId}/delete-all-of-type/`,
4247
- blockers: affectedOfflineIds,
4248
- blocks: affectedOfflineIds
4249
- }).catch((err) => {
4250
- store.dispatch(addAssets(allAssetsOfAssetType));
4251
- throw err;
4252
- });
4253
- }
4254
- // TODO: payload does not require asset_type
4255
- bulkAdd(assetsToCreate, workspaceId, assetTypeId, batchSize) {
4018
+ bulkAdd(payloads, assetTypeId, batchSize) {
4256
4019
  const submittedAt = (/* @__PURE__ */ new Date()).toISOString();
4257
4020
  const transactionId = uuid.v4();
4258
- const assetBatches = chunkArray(assetsToCreate, batchSize).map((assetBatch) => {
4259
- const assetPayloads = assetBatch.map((assetPayload) => {
4260
- return offline({
4261
- ...assetPayload,
4262
- submitted_at: submittedAt
4263
- });
4264
- });
4021
+ const assetBatches = chunkArray(payloads, batchSize).map((assetBatch) => {
4022
+ const assetPayloads = assetBatch.map((assetPayload) => offline(assetPayload));
4265
4023
  return {
4266
4024
  batchId: uuid.v4(),
4267
4025
  payload: {
4268
4026
  transaction_id: transactionId,
4027
+ submitted_at: submittedAt,
4028
+ asset_type: assetTypeId,
4269
4029
  assets: assetPayloads
4270
4030
  }
4271
4031
  };
@@ -4283,10 +4043,7 @@ var __publicField = (obj, key, value) => {
4283
4043
  const promise = this.enqueueRequest({
4284
4044
  description: "Batch create assets",
4285
4045
  method: HttpMethod.POST,
4286
- url: `/assets/types/${assetTypeId}/add-assets/`,
4287
- queryParams: {
4288
- workspace_id: workspaceId.toString()
4289
- },
4046
+ url: "/assets/bulk/",
4290
4047
  payload,
4291
4048
  blockers,
4292
4049
  blocks: blocks2
@@ -4312,117 +4069,152 @@ var __publicField = (obj, key, value) => {
4312
4069
  }
4313
4070
  }
4314
4071
  class AssetStageCompletionService extends BaseApiService {
4315
- add(assetId, stageId) {
4316
- var _a2;
4072
+ add(payload) {
4317
4073
  const { store } = this.client;
4318
- const assetTypeId = (_a2 = selectAssetById(assetId)(store.getState())) == null ? void 0 : _a2.asset_type;
4319
- if (!assetTypeId) {
4320
- throw new Error(`Asset with offline_id ${assetId} not found`);
4321
- }
4074
+ const createdBy = store.getState().userReducer.currentUser.id;
4075
+ const submittedAt = (/* @__PURE__ */ new Date()).toISOString();
4322
4076
  const offlineStageCompletion = offline({
4323
- asset: assetId,
4324
- stage: stageId
4077
+ ...payload,
4078
+ created_by: createdBy,
4079
+ submitted_at: submittedAt
4325
4080
  });
4326
- this.dispatch(addStageCompletion(offlineStageCompletion));
4081
+ this.dispatch(addAssetStageCompletion(offlineStageCompletion));
4327
4082
  const promise = this.enqueueRequest({
4328
- description: "Complete stage",
4083
+ description: "Add asset stage completion",
4329
4084
  method: HttpMethod.POST,
4330
- url: `/assets/types/${assetTypeId}/complete-stages/`,
4331
- // TODO: Add submitted_at to model
4332
- payload: { completions: [{ ...offlineStageCompletion, submitted_at: (/* @__PURE__ */ new Date()).getTime() / 1e3 }] },
4333
- blockers: [assetId, stageId],
4085
+ url: "/assets/completions/",
4086
+ payload: {
4087
+ offline_id: offlineStageCompletion.offline_id,
4088
+ submitted_at: submittedAt,
4089
+ asset: payload.asset,
4090
+ stage: payload.stage
4091
+ },
4092
+ blockers: [payload.asset, payload.stage],
4334
4093
  blocks: [offlineStageCompletion.offline_id]
4335
4094
  });
4095
+ promise.then((result) => {
4096
+ this.dispatch(updateAssetStageCompletion(result));
4097
+ }).catch(() => {
4098
+ this.dispatch(deleteAssetStageCompletion(offlineStageCompletion.offline_id));
4099
+ });
4336
4100
  return [offlineStageCompletion, promise];
4337
- }
4338
- async refreshStore(projectId) {
4339
- const result = await this.enqueueRequest({
4340
- description: "Get stage completions",
4341
- method: HttpMethod.GET,
4342
- url: `/projects/${projectId}/asset-stage-completions/`,
4343
- blockers: [],
4101
+ }
4102
+ delete(id) {
4103
+ const { store } = this.client;
4104
+ const assetStageCompletion = selectAssetStageCompletionById(id)(store.getState());
4105
+ if (!assetStageCompletion) {
4106
+ throw new Error(`Expected asset stage completion with id ${id} to exist`);
4107
+ }
4108
+ this.dispatch(deleteAssetStageCompletion(id));
4109
+ const promise = this.enqueueRequest({
4110
+ description: "Delete asset stage completion",
4111
+ method: HttpMethod.DELETE,
4112
+ url: `/assets/completions/${id}/`,
4113
+ blockers: [id],
4344
4114
  blocks: []
4345
4115
  });
4346
- this.dispatch(addStageCompletions(result));
4116
+ promise.catch(() => {
4117
+ this.dispatch(addAssetStageCompletion(assetStageCompletion));
4118
+ });
4119
+ return promise;
4347
4120
  }
4348
- /**
4349
- * Creates a collection of AssetStageCompletions, marking the referenced stages as completed for the referenced
4350
- * assets. It's REQUIRED that all assets referenced all have the SAME asset type.
4351
- * @param assetTypeId The ID of the asset type for which we are completing stages (we can only complete
4352
- * stages for one asset type at a time)
4353
- * @param stageCompletions
4354
- */
4355
- async bulkAdd(assetTypeId, stageCompletions) {
4356
- const offlineStageCompletions = stageCompletions.map((completion) => {
4357
- return offline(completion);
4358
- });
4359
- const asMapping = {};
4360
- for (const completion of stageCompletions) {
4361
- const stageToCompletionDateMapping = asMapping[completion.asset] || {};
4362
- stageToCompletionDateMapping[completion.stage] = (/* @__PURE__ */ new Date()).toISOString();
4363
- asMapping[completion.asset] = stageToCompletionDateMapping;
4364
- }
4365
- this.dispatch(addStageCompletions(asMapping));
4366
- await this.enqueueRequest({
4367
- description: "Bulk complete stages",
4121
+ bulkAdd(payloads) {
4122
+ const { store } = this.client;
4123
+ const submittedAt = (/* @__PURE__ */ new Date()).toISOString();
4124
+ const createdBy = store.getState().userReducer.currentUser.id;
4125
+ const payload = payloads.map((payload2) => offline(payload2));
4126
+ const offlineStageCompletions = payload.map((completion) => {
4127
+ return {
4128
+ ...completion,
4129
+ created_by: createdBy,
4130
+ submitted_at: submittedAt
4131
+ };
4132
+ });
4133
+ const offlineIds = offlineStageCompletions.map(({ offline_id }) => offline_id);
4134
+ this.dispatch(addAssetStageCompletions(offlineStageCompletions));
4135
+ const promise = this.enqueueRequest({
4136
+ description: "Bulk create asset stage completions",
4368
4137
  method: HttpMethod.POST,
4369
- url: `/assets/types/${assetTypeId}/complete-stages/`,
4138
+ url: "/assets/completions/bulk/",
4370
4139
  payload: {
4371
- completions: offlineStageCompletions
4140
+ submitted_at: submittedAt,
4141
+ completions: payload
4372
4142
  },
4373
- blockers: [assetTypeId, ...stageCompletions.map((c) => c.asset), ...stageCompletions.map((c) => c.stage)],
4374
- blocks: offlineStageCompletions.map((c) => c.offline_id)
4143
+ blockers: [...payloads.map((c) => c.asset), ...payloads.map((c) => c.stage)],
4144
+ blocks: offlineIds
4375
4145
  });
4376
- }
4377
- bulkDelete(stageId, assetIds) {
4378
- const stageCompletionsToRemove = assetIds.map((assetId) => {
4379
- return {
4380
- asset: assetId,
4381
- stage: stageId
4382
- };
4146
+ promise.then((result) => {
4147
+ this.dispatch(updateAssetStageCompletions(result));
4148
+ }).catch(() => {
4149
+ this.dispatch(deleteAssetStageCompletions(offlineIds));
4383
4150
  });
4384
- this.dispatch(removeStageCompletions(stageCompletionsToRemove));
4385
- return this.enqueueRequest({
4386
- description: `Undo stage for ${assetIds.length} assets(s)`,
4387
- // TODO: Rename to setCompletedStages
4151
+ return [offlineStageCompletions, promise];
4152
+ }
4153
+ bulkDelete(ids) {
4154
+ const { store } = this.client;
4155
+ const assetStageCompletions = selectAssetStageCompletionsByIds(ids)(store.getState());
4156
+ this.dispatch(deleteAssetStageCompletions(ids));
4157
+ const promise = this.enqueueRequest({
4158
+ description: "Deleting asset stage completions",
4388
4159
  method: HttpMethod.DELETE,
4389
- url: `/assets/stages/${stageId}/undo-stages/`,
4160
+ url: "/assets/completions/bulk/",
4390
4161
  payload: {
4391
- assets: assetIds
4162
+ completion_ids: ids
4392
4163
  },
4393
- blockers: [stageId, ...assetIds],
4164
+ blockers: ids,
4165
+ blocks: []
4166
+ });
4167
+ promise.catch(() => {
4168
+ this.dispatch(addAssetStageCompletions(assetStageCompletions));
4169
+ });
4170
+ return promise;
4171
+ }
4172
+ async refreshStore(projectId) {
4173
+ const result = await this.enqueueRequest({
4174
+ description: "Get asset stage completions",
4175
+ method: HttpMethod.GET,
4176
+ url: `/projects/${projectId}/asset-stage-completions/`,
4177
+ blockers: [],
4394
4178
  blocks: []
4395
4179
  });
4180
+ this.dispatch(initializeAssetStageCompletions(result));
4396
4181
  }
4397
4182
  }
4398
4183
  class AssetStageService extends BaseApiService {
4399
- async bulkCreateStages(stagesToSubmit, assetTypeId, workspaceId) {
4184
+ bulkAdd(stagesToSubmit, assetTypeId) {
4185
+ const submittedAt = (/* @__PURE__ */ new Date()).toISOString();
4186
+ const createdBy = this.client.store.getState().userReducer.currentUser.id;
4400
4187
  const payload = stagesToSubmit.map((stage) => {
4401
4188
  return offline(stage);
4402
4189
  });
4403
- const fullStages = payload.map((stage) => {
4404
- return { ...stage, asset_type: assetTypeId };
4190
+ const offlineStages = payload.map((stage) => {
4191
+ return { ...stage, asset_type: assetTypeId, created_by: createdBy, submitted_at: submittedAt };
4405
4192
  });
4406
- this.dispatch(addStages(fullStages));
4407
- return this.enqueueRequest({
4193
+ this.dispatch(addAssetStages(offlineStages));
4194
+ const promise = this.enqueueRequest({
4408
4195
  description: "Add asset stages",
4409
4196
  method: HttpMethod.POST,
4410
- url: `/assets/types/${assetTypeId}/add-stages/`,
4197
+ url: "/assets/stages/bulk/",
4411
4198
  payload: {
4199
+ submitted_at: submittedAt,
4200
+ asset_type: assetTypeId,
4412
4201
  stages: payload
4413
4202
  },
4414
- queryParams: {
4415
- workspace_id: workspaceId.toString()
4416
- },
4417
- blockers: [assetTypeId, workspaceId],
4203
+ blockers: [assetTypeId],
4418
4204
  blocks: payload.map(({ offline_id }) => offline_id)
4419
4205
  });
4206
+ promise.then((result) => {
4207
+ this.dispatch(updateAssetStages(result));
4208
+ }).catch(() => {
4209
+ this.dispatch(deleteAssetStages(offlineStages.map(({ offline_id }) => offline_id)));
4210
+ });
4211
+ return [offlineStages, promise];
4420
4212
  }
4421
- async bulkUpdateStages(stagesToUpdate, assetTypeId) {
4213
+ async bulkUpdate(stagesToUpdate, assetTypeId) {
4422
4214
  const store = this.client.store;
4423
4215
  const state = store.getState();
4424
4216
  const prevStages = selectAssetStagesByIds(stagesToUpdate.map(({ offline_id }) => offline_id))(state);
4425
- this.dispatch(updateStages(stagesToUpdate));
4217
+ this.dispatch(updateAssetStages(stagesToUpdate));
4426
4218
  return this.enqueueRequest({
4427
4219
  description: "Edit asset stages",
4428
4220
  method: HttpMethod.PATCH,
@@ -4433,33 +4225,58 @@ var __publicField = (obj, key, value) => {
4433
4225
  blockers: [assetTypeId],
4434
4226
  blocks: stagesToUpdate.map(({ offline_id }) => offline_id)
4435
4227
  }).catch((e) => {
4436
- store.dispatch(updateStages(prevStages));
4228
+ this.dispatch(updateAssetStages(prevStages));
4437
4229
  throw e;
4438
4230
  });
4439
4231
  }
4440
4232
  async bulkDelete(idsToDelete) {
4441
- this.dispatch(removeStages(idsToDelete));
4442
- return this.enqueueRequest({
4233
+ const { store } = this.client;
4234
+ const assetStages = selectAssetStagesByIds(idsToDelete)(store.getState());
4235
+ this.dispatch(deleteAssetStages(idsToDelete));
4236
+ const promise = this.enqueueRequest({
4443
4237
  description: "Delete asset stages",
4444
4238
  method: HttpMethod.DELETE,
4445
- url: "/assets/stages/bulk-delete/",
4239
+ url: "/assets/stages/bulk/",
4446
4240
  payload: {
4447
4241
  stage_ids: idsToDelete
4448
4242
  },
4449
4243
  blockers: idsToDelete,
4450
4244
  blocks: []
4451
4245
  });
4246
+ promise.catch(() => {
4247
+ this.dispatch(addAssetStages(assetStages));
4248
+ });
4249
+ return promise;
4452
4250
  }
4453
- async update(assetStage) {
4454
- this.dispatch(addStages([assetStage]));
4455
- return this.enqueueRequest({
4251
+ update(payload) {
4252
+ const { store } = this.client;
4253
+ const assetStage = selectAssetStageById(payload.offline_id)(store.getState());
4254
+ if (!assetStage)
4255
+ throw new Error(`No asset stage with id ${payload.offline_id} found in the store`);
4256
+ const updatedAssetStage = {
4257
+ ...assetStage,
4258
+ ...payload
4259
+ };
4260
+ this.dispatch(updateAssetStage(updatedAssetStage));
4261
+ const promise = this.enqueueRequest({
4456
4262
  description: "Update asset stage",
4457
4263
  method: HttpMethod.PATCH,
4458
4264
  url: `/assets/stages/${assetStage.offline_id}/`,
4459
- payload: assetStage,
4265
+ payload: {
4266
+ name: payload.name,
4267
+ description: payload.description,
4268
+ priority: payload.priority,
4269
+ color: payload.color
4270
+ },
4460
4271
  blockers: [assetStage.offline_id],
4461
4272
  blocks: [assetStage.offline_id]
4462
4273
  });
4274
+ promise.then((result) => {
4275
+ this.dispatch(updateAssetStage(result));
4276
+ }).catch(() => {
4277
+ this.dispatch(setAssetStage(assetStage));
4278
+ });
4279
+ return [updatedAssetStage, promise];
4463
4280
  }
4464
4281
  async linkForm(stageId, formId) {
4465
4282
  const { store } = this.client;
@@ -4467,7 +4284,7 @@ var __publicField = (obj, key, value) => {
4467
4284
  if (!stage) {
4468
4285
  throw new Error(`No asset stage with id ${stageId} found in the store`);
4469
4286
  }
4470
- this.dispatch(updateStage({ ...stage, form: formId }));
4287
+ this.dispatch(updateAssetStage({ ...stage, form: formId }));
4471
4288
  try {
4472
4289
  await this.enqueueRequest({
4473
4290
  description: "Link asset stage to form",
@@ -4478,7 +4295,7 @@ var __publicField = (obj, key, value) => {
4478
4295
  blocks: [stageId]
4479
4296
  });
4480
4297
  } catch (e) {
4481
- this.dispatch(setStage(stage));
4298
+ this.dispatch(setAssetStage(stage));
4482
4299
  throw e;
4483
4300
  }
4484
4301
  }
@@ -4488,7 +4305,7 @@ var __publicField = (obj, key, value) => {
4488
4305
  if (!stage) {
4489
4306
  throw new Error(`No asset stage with id ${stageId} found in the store`);
4490
4307
  }
4491
- this.dispatch(updateStage({ ...stage, form: void 0 }));
4308
+ this.dispatch(updateAssetStage({ ...stage, form: void 0 }));
4492
4309
  try {
4493
4310
  await this.enqueueRequest({
4494
4311
  description: "Unlink asset stage from form",
@@ -4498,7 +4315,7 @@ var __publicField = (obj, key, value) => {
4498
4315
  blocks: [stageId]
4499
4316
  });
4500
4317
  } catch (e) {
4501
- this.dispatch(setStage(stage));
4318
+ this.dispatch(setAssetStage(stage));
4502
4319
  throw e;
4503
4320
  }
4504
4321
  }
@@ -4510,7 +4327,7 @@ var __publicField = (obj, key, value) => {
4510
4327
  blockers: [],
4511
4328
  blocks: []
4512
4329
  });
4513
- this.dispatch(initializeStages(result));
4330
+ this.dispatch(initializeAssetStages(result));
4514
4331
  }
4515
4332
  }
4516
4333
  class BaseUploadService extends BaseApiService {
@@ -4590,8 +4407,9 @@ var __publicField = (obj, key, value) => {
4590
4407
  };
4591
4408
  class BaseAttachmentService extends BaseUploadService {
4592
4409
  async attachFiles(files, modelId, buildOfflineAttachment) {
4410
+ var _a2;
4593
4411
  const { store } = this.client;
4594
- const currentUser = store.getState().userReducer.currentUser;
4412
+ const createdBy = (_a2 = store.getState().userReducer.currentUser) == null ? void 0 : _a2.id;
4595
4413
  const submittedAt = (/* @__PURE__ */ new Date()).toISOString();
4596
4414
  const offlineAttachments = [];
4597
4415
  const attachmentPayloads = [];
@@ -4611,7 +4429,7 @@ var __publicField = (obj, key, value) => {
4611
4429
  file,
4612
4430
  sha1,
4613
4431
  submittedAt,
4614
- createdBy: currentUser.id,
4432
+ createdBy,
4615
4433
  description: "",
4616
4434
  modelId
4617
4435
  });
@@ -4717,29 +4535,61 @@ var __publicField = (obj, key, value) => {
4717
4535
  }
4718
4536
  }
4719
4537
  class AssetTypeService extends BaseApiService {
4720
- add(assetType) {
4721
- const offlineAssetType = offline(assetType);
4538
+ add(payload) {
4539
+ const { store } = this.client;
4540
+ const createdBy = store.getState().userReducer.currentUser.id;
4541
+ const submittedAt = (/* @__PURE__ */ new Date()).toISOString();
4542
+ const offlineAssetType = offline({
4543
+ ...payload,
4544
+ created_by: createdBy,
4545
+ submitted_at: submittedAt
4546
+ });
4722
4547
  this.dispatch(addAssetType(offlineAssetType));
4723
4548
  const promise = this.enqueueRequest({
4724
4549
  description: "Create asset type",
4725
4550
  method: HttpMethod.POST,
4726
- url: `/projects/${assetType.project}/asset-types/`,
4551
+ url: `/projects/${payload.project}/asset-types/`,
4727
4552
  payload: { ...offlineAssetType },
4728
4553
  blockers: [],
4729
4554
  blocks: [offlineAssetType.offline_id]
4730
4555
  });
4556
+ promise.then((result) => {
4557
+ this.dispatch(updateAssetType(result));
4558
+ }).catch(() => {
4559
+ this.dispatch(deleteAssetType(offlineAssetType.offline_id));
4560
+ });
4731
4561
  return [offlineAssetType, promise];
4732
4562
  }
4733
- update(assetType) {
4734
- this.dispatch(addAssetType(assetType));
4735
- return this.enqueueRequest({
4563
+ update(payload) {
4564
+ const { store } = this.client;
4565
+ const assetType = selectAssetTypeById(payload.offline_id)(store.getState());
4566
+ if (!assetType) {
4567
+ throw new Error(`Expected asset type with offline_id ${payload.offline_id} to exist`);
4568
+ }
4569
+ const updatedAssetType = {
4570
+ ...assetType,
4571
+ ...payload
4572
+ };
4573
+ this.dispatch(updateAssetType(updatedAssetType));
4574
+ const promise = this.enqueueRequest({
4736
4575
  description: "Update asset type",
4737
4576
  method: HttpMethod.PATCH,
4738
- url: `/assets/types/${assetType.offline_id}/`,
4739
- payload: assetType,
4577
+ url: `/assets/types/${payload.offline_id}/`,
4578
+ payload: {
4579
+ icon: payload.icon,
4580
+ color: payload.color,
4581
+ name: payload.name,
4582
+ description: payload.description
4583
+ },
4740
4584
  blockers: [assetType.offline_id],
4741
4585
  blocks: [assetType.offline_id]
4742
4586
  });
4587
+ promise.then((result) => {
4588
+ this.dispatch(updateAssetType(result));
4589
+ }).catch(() => {
4590
+ this.dispatch(updateAssetType(assetType));
4591
+ });
4592
+ return [updatedAssetType, promise];
4743
4593
  }
4744
4594
  async delete(assetTypeId) {
4745
4595
  const { store } = this.client;
@@ -4748,17 +4598,13 @@ var __publicField = (obj, key, value) => {
4748
4598
  if (!assetType) {
4749
4599
  throw new Error(`Expected asset type with offline_id ${assetTypeId} to exist`);
4750
4600
  }
4601
+ const assetsOfAssetType = selectAssetsOfAssetType(assetTypeId)(state);
4751
4602
  const stagesOfAssetType = selectStagesOfAssetType(assetTypeId)(state);
4752
4603
  const attachmentsOfAssetType = selectAttachmentsOfAssetType(assetTypeId)(state);
4753
4604
  this.dispatch(deleteAssetType(assetTypeId));
4754
- if (stagesOfAssetType.length > 0) {
4755
- const stagesOfAssetTypeIds = stagesOfAssetType.map((assetStage) => assetStage.offline_id);
4756
- this.dispatch(removeStages(stagesOfAssetTypeIds));
4757
- }
4758
- if (attachmentsOfAssetType.length > 0) {
4759
- const attachmentsOfAssetTypeIds = attachmentsOfAssetType.map(({ offline_id }) => offline_id);
4760
- this.dispatch(deleteAssetTypeAttachments(attachmentsOfAssetTypeIds));
4761
- }
4605
+ this.dispatch(deleteAssets(assetsOfAssetType.map((asset) => asset.offline_id)));
4606
+ this.dispatch(deleteAssetStages(stagesOfAssetType.map((assetStage) => assetStage.offline_id)));
4607
+ this.dispatch(deleteAssetTypeAttachments(attachmentsOfAssetType.map(({ offline_id }) => offline_id)));
4762
4608
  return this.enqueueRequest({
4763
4609
  description: "Delete asset type",
4764
4610
  method: HttpMethod.DELETE,
@@ -4767,7 +4613,8 @@ var __publicField = (obj, key, value) => {
4767
4613
  blocks: []
4768
4614
  }).catch((e) => {
4769
4615
  this.dispatch(addAssetType(assetType));
4770
- this.dispatch(addStages(stagesOfAssetType));
4616
+ this.dispatch(addAssets(assetsOfAssetType));
4617
+ this.dispatch(addAssetStages(stagesOfAssetType));
4771
4618
  this.dispatch(addAssetTypeAttachments(attachmentsOfAssetType));
4772
4619
  throw e;
4773
4620
  });
@@ -4815,21 +4662,21 @@ var __publicField = (obj, key, value) => {
4815
4662
  }
4816
4663
  }
4817
4664
  class IssueCommentService extends BaseApiService {
4818
- // Omit author and submitted_at since these will always be set internally
4819
- add(comment) {
4665
+ add(payload) {
4666
+ var _a2;
4820
4667
  const { store } = this.client;
4821
4668
  const offlineComment = offline({
4822
- ...comment,
4823
- author: store.getState().userReducer.currentUser.id,
4669
+ ...payload,
4670
+ author: (_a2 = store.getState().userReducer.currentUser) == null ? void 0 : _a2.id,
4824
4671
  submitted_at: (/* @__PURE__ */ new Date()).toISOString()
4825
4672
  });
4826
4673
  this.dispatch(addIssueComment(offlineComment));
4827
4674
  const promise = this.enqueueRequest({
4828
- description: `${truncate(comment.content, 80)}`,
4675
+ description: "Add issue comment",
4829
4676
  method: HttpMethod.POST,
4830
- url: `/issues/${comment.issue}/comment/`,
4677
+ url: `/issues/${payload.issue}/comment/`,
4831
4678
  payload: offlineComment,
4832
- blockers: [comment.issue],
4679
+ blockers: [payload.issue],
4833
4680
  blocks: [offlineComment.offline_id]
4834
4681
  });
4835
4682
  promise.catch(() => {
@@ -4837,37 +4684,41 @@ var __publicField = (obj, key, value) => {
4837
4684
  });
4838
4685
  return [offlineComment, promise];
4839
4686
  }
4840
- update(comment) {
4687
+ update(payload) {
4841
4688
  const { store } = this.client;
4842
- const commentToUpdate = store.getState().issueCommentReducer.instances[comment.offline_id];
4689
+ const commentToUpdate = selectIssueCommentById(payload.offline_id)(store.getState());
4843
4690
  if (!commentToUpdate) {
4844
- throw new Error(`Comment with offline_id ${comment.offline_id} not found in store`);
4691
+ throw new Error(`Comment with offline_id ${payload.offline_id} not found in store`);
4845
4692
  }
4846
- this.dispatch(setIssueComment(comment));
4693
+ const updatedComment = {
4694
+ ...commentToUpdate,
4695
+ ...payload
4696
+ };
4697
+ this.dispatch(setIssueComment(updatedComment));
4847
4698
  const promise = this.enqueueRequest({
4848
- description: `Edit comment: ${truncate(comment.content, 80)}`,
4699
+ description: "Edit issue comment",
4849
4700
  method: HttpMethod.PATCH,
4850
- url: `/issues/comments/${comment.offline_id}/`,
4851
- payload: comment,
4852
- blockers: [comment.issue],
4853
- blocks: [comment.offline_id]
4701
+ url: `/issues/comments/${payload.offline_id}/`,
4702
+ payload,
4703
+ blockers: [payload.offline_id],
4704
+ blocks: [payload.offline_id]
4854
4705
  });
4855
4706
  promise.catch(() => {
4856
4707
  this.dispatch(setIssueComment(commentToUpdate));
4857
4708
  });
4858
- return [comment, promise];
4709
+ return [updatedComment, promise];
4859
4710
  }
4860
- remove(offline_id) {
4861
- const commentToRemove = this.client.store.getState().issueCommentReducer.instances[offline_id];
4711
+ remove(id) {
4712
+ const commentToRemove = this.client.store.getState().issueCommentReducer.instances[id];
4862
4713
  if (!commentToRemove) {
4863
- throw new Error(`Comment with offline_id ${offline_id} not found in store`);
4714
+ throw new Error(`Comment with offline_id ${id} not found in store`);
4864
4715
  }
4865
- this.dispatch(deleteIssueComment(offline_id));
4716
+ this.dispatch(deleteIssueComment(id));
4866
4717
  const promise = this.enqueueRequest({
4867
4718
  description: "Delete comment",
4868
4719
  method: HttpMethod.DELETE,
4869
- url: `/issues/comments/${offline_id}/`,
4870
- blockers: [offline_id],
4720
+ url: `/issues/comments/${id}/`,
4721
+ blockers: [id],
4871
4722
  blocks: []
4872
4723
  });
4873
4724
  promise.catch(() => {
@@ -4940,71 +4791,50 @@ var __publicField = (obj, key, value) => {
4940
4791
  }
4941
4792
  class IssueService extends BaseApiService {
4942
4793
  // Basic CRUD functions
4943
- // TODO: Once all models are represented in `Created<TModel>`, use `Created` in `OptimisticModelResult`, so we don't
4944
- // have to repeat it for all optimistic model results (all optimistic results are created).
4945
- add(issue, workspaceId, issueType = null) {
4794
+ add(payload) {
4795
+ var _a2;
4946
4796
  const { store } = this.client;
4947
- const dateWithoutMilliseconds = /* @__PURE__ */ new Date();
4948
4797
  const state = store.getState();
4949
- const currentUserId = state.userReducer.currentUser.id;
4950
- dateWithoutMilliseconds.setMilliseconds(0);
4951
- if (!workspaceId) {
4952
- throw new Error("No active workspace ID while creating issue.");
4953
- }
4954
- const issuePayload = offline({
4955
- ...issue,
4956
- submitted_at: dateWithoutMilliseconds.toISOString(),
4957
- index_workspace: workspaceId,
4958
- created_by: currentUserId,
4959
- status: issue.status ?? DEFAULT_ISSUE_STATUS,
4960
- priority: issue.priority ?? DEFAULT_ISSUE_PRIORITY
4961
- });
4962
- this.dispatch(addIssue(issuePayload));
4963
- this.dispatch(addToRecentIssues(issuePayload.offline_id));
4798
+ const submittedAt = (/* @__PURE__ */ new Date()).toISOString();
4799
+ const createdBy = (_a2 = state.userReducer.currentUser) == null ? void 0 : _a2.id;
4800
+ const offlineIssue = offline({
4801
+ ...payload,
4802
+ submitted_at: submittedAt,
4803
+ created_by: createdBy
4804
+ });
4805
+ this.dispatch(addIssue(offlineIssue));
4964
4806
  this.dispatch(addActiveProjectIssuesCount(1));
4965
4807
  const promise = this.enqueueRequest({
4966
4808
  description: "Create issue",
4967
4809
  method: HttpMethod.POST,
4968
4810
  url: "/issues/",
4969
4811
  queryParams: {
4970
- workspace_id: workspaceId,
4971
- ...issueType ? { issue_type: issueType } : {}
4812
+ workspace_id: payload.index_workspace,
4813
+ ...payload.issue_type ? { issue_type: payload.issue_type } : {}
4972
4814
  },
4973
- payload: issuePayload,
4974
- blockers: [
4975
- "add-issue",
4976
- ...issuePayload.index_workspace ? [issuePayload.index_workspace] : [],
4977
- ...issuePayload.visible_in_workspaces
4978
- ],
4979
- blocks: [issuePayload.offline_id]
4815
+ payload: offlineIssue,
4816
+ blockers: ["add-issue", ...offlineIssue.index_workspace ? [offlineIssue.index_workspace] : []],
4817
+ blocks: [offlineIssue.offline_id]
4980
4818
  });
4981
4819
  void promise.then((result) => {
4982
4820
  this.dispatch(updateIssue(result));
4983
4821
  }).catch((error) => {
4984
- var _a2;
4985
- console.error(error);
4986
- if (error instanceof APIError) {
4987
- (_a2 = blocks.unsafeShowToast) == null ? void 0 : _a2.call(blocks, {
4988
- title: "Could not create issue",
4989
- description: error.message,
4990
- accentColor: "red"
4991
- });
4992
- }
4993
- this.dispatch(deleteIssue(issuePayload.offline_id));
4822
+ this.dispatch(deleteIssue(offlineIssue.offline_id));
4994
4823
  this.dispatch(addActiveProjectIssuesCount(-1));
4995
4824
  throw error;
4996
4825
  });
4997
- return [issuePayload, promise];
4826
+ return [offlineIssue, promise];
4998
4827
  }
4999
- update(issue) {
4828
+ update(payload) {
4829
+ var _a2;
5000
4830
  const state = this.client.store.getState();
5001
- const issueToBeUpdated = selectIssueById(issue.offline_id)(state);
4831
+ const issueToBeUpdated = selectIssueById(payload.offline_id)(state);
5002
4832
  if (!issueToBeUpdated) {
5003
4833
  throw new Error(
5004
- `Attempting to update an issue with offline_id ${issue.offline_id} that doesn't exist in the store`
4834
+ `Attempting to update an issue with offline_id ${payload.offline_id} that doesn't exist in the store`
5005
4835
  );
5006
4836
  }
5007
- const updatedIssue = { ...issueToBeUpdated, ...issue };
4837
+ const updatedIssue = { ...issueToBeUpdated, ...payload };
5008
4838
  this.dispatch(updateIssue(updatedIssue));
5009
4839
  const changes = {};
5010
4840
  for (const issueUpdateChange of [
@@ -5016,11 +4846,11 @@ var __publicField = (obj, key, value) => {
5016
4846
  IssueUpdateChange.ASSIGNED_TO,
5017
4847
  IssueUpdateChange.DUE_DATE
5018
4848
  ]) {
5019
- if (issueUpdateChange in issue && issue[issueUpdateChange] !== issueToBeUpdated[issueUpdateChange]) {
4849
+ if (issueUpdateChange in payload && payload[issueUpdateChange] !== issueToBeUpdated[issueUpdateChange]) {
5020
4850
  switch (issueUpdateChange) {
5021
4851
  case "category": {
5022
4852
  let categoryOrNull = null;
5023
- const categoryIdOrNull = issue[issueUpdateChange];
4853
+ const categoryIdOrNull = payload[issueUpdateChange];
5024
4854
  if (categoryIdOrNull) {
5025
4855
  categoryOrNull = state.categoryReducer.instances[categoryIdOrNull] ?? null;
5026
4856
  if (!categoryOrNull)
@@ -5037,7 +4867,7 @@ var __publicField = (obj, key, value) => {
5037
4867
  }
5038
4868
  case "assigned_to": {
5039
4869
  let userOrNull = null;
5040
- const userIdOrNull = issue[issueUpdateChange];
4870
+ const userIdOrNull = payload[issueUpdateChange];
5041
4871
  if (userIdOrNull) {
5042
4872
  userOrNull = state.userReducer.users[userIdOrNull] ?? null;
5043
4873
  if (!userOrNull)
@@ -5052,24 +4882,24 @@ var __publicField = (obj, key, value) => {
5052
4882
  break;
5053
4883
  }
5054
4884
  case "description":
5055
- changes[issueUpdateChange] = issue[issueUpdateChange] ?? null;
4885
+ changes[issueUpdateChange] = payload[issueUpdateChange] ?? null;
5056
4886
  break;
5057
4887
  case "title":
5058
- changes[issueUpdateChange] = issue[issueUpdateChange] ?? null;
4888
+ changes[issueUpdateChange] = payload[issueUpdateChange] ?? null;
5059
4889
  break;
5060
4890
  case "priority":
5061
- changes[issueUpdateChange] = issue[issueUpdateChange];
4891
+ changes[issueUpdateChange] = payload[issueUpdateChange];
5062
4892
  break;
5063
4893
  case "status":
5064
- changes[issueUpdateChange] = issue[issueUpdateChange];
4894
+ changes[issueUpdateChange] = payload[issueUpdateChange];
5065
4895
  break;
5066
4896
  case "due_date":
5067
- changes[issueUpdateChange] = issue[issueUpdateChange] ? issue[issueUpdateChange] : null;
4897
+ changes[issueUpdateChange] = payload[issueUpdateChange] ? payload[issueUpdateChange] : null;
5068
4898
  }
5069
4899
  }
5070
4900
  }
5071
4901
  const offlineIssueUpdate = offline({
5072
- created_by: state.userReducer.currentUser.id,
4902
+ created_by: (_a2 = state.userReducer.currentUser) == null ? void 0 : _a2.id,
5073
4903
  submitted_at: (/* @__PURE__ */ new Date()).toISOString(),
5074
4904
  issue: issueToBeUpdated.offline_id,
5075
4905
  changes
@@ -5078,10 +4908,10 @@ var __publicField = (obj, key, value) => {
5078
4908
  const promise = this.enqueueRequest({
5079
4909
  description: "Edit issue",
5080
4910
  method: HttpMethod.PATCH,
5081
- url: `/issues/${issue.offline_id}/`,
5082
- payload: issue,
5083
- blockers: [issue.offline_id],
5084
- blocks: [issue.offline_id]
4911
+ url: `/issues/${payload.offline_id}/`,
4912
+ payload,
4913
+ blockers: [payload.offline_id],
4914
+ blocks: [payload.offline_id]
5085
4915
  });
5086
4916
  promise.catch(() => {
5087
4917
  this.dispatch(updateIssue(issueToBeUpdated));
@@ -5133,7 +4963,6 @@ var __publicField = (obj, key, value) => {
5133
4963
  throw e;
5134
4964
  }
5135
4965
  }
5136
- // Special functions
5137
4966
  async refreshStore(projectId) {
5138
4967
  const result = await this.enqueueRequest({
5139
4968
  description: "Get issues",
@@ -5141,33 +4970,24 @@ var __publicField = (obj, key, value) => {
5141
4970
  url: `/projects/${projectId}/issues/`,
5142
4971
  blockers: [],
5143
4972
  blocks: []
5144
- }).then((result2) => {
5145
- const filteredResult = result2.filter(onlyUniqueOfflineIds);
5146
- if (result2.length !== filteredResult.length) {
5147
- console.error(
5148
- `Received duplicate issues from the API (new length ${filteredResult.length});
5149
- filtered in browser.`
5150
- );
5151
- }
5152
- return filteredResult;
5153
4973
  });
5154
4974
  this.dispatch(initializeIssues(result));
5155
4975
  }
5156
4976
  }
5157
4977
  class IssueTypeService extends BaseApiService {
5158
- add(payload, organizationId) {
4978
+ add(payload) {
4979
+ var _a2;
5159
4980
  const { store } = this.client;
5160
4981
  const state = store.getState();
5161
4982
  const offlineIssueType = offline({
5162
4983
  ...payload,
5163
4984
  submitted_at: (/* @__PURE__ */ new Date()).toISOString(),
5164
- created_by: state.userReducer.currentUser.id,
5165
- organization: organizationId
4985
+ created_by: (_a2 = state.userReducer.currentUser) == null ? void 0 : _a2.id
5166
4986
  });
5167
4987
  this.dispatch(addIssueType(offlineIssueType));
5168
4988
  const promise = this.enqueueRequest({
5169
4989
  method: HttpMethod.POST,
5170
- url: `/organizations/${organizationId}/issue-types/`,
4990
+ url: `/organizations/${payload.organization}/issue-types/`,
5171
4991
  // Sending only whats needed here
5172
4992
  payload: {
5173
4993
  offline_id: offlineIssueType.offline_id,
@@ -5213,20 +5033,20 @@ var __publicField = (obj, key, value) => {
5213
5033
  });
5214
5034
  return [offlineUpdatedIssueType, promise];
5215
5035
  }
5216
- delete(issueTypeId) {
5036
+ delete(id) {
5217
5037
  const { store } = this.client;
5218
5038
  const state = store.getState();
5219
- const issueTypeToDelete = selectIssueTypeById(issueTypeId)(state);
5039
+ const issueTypeToDelete = selectIssueTypeById(id)(state);
5220
5040
  if (!issueTypeToDelete) {
5221
- throw new Error(`IssueType with offline_id ${issueTypeId} does not exist in the store.`);
5041
+ throw new Error(`IssueType with offline_id ${id} does not exist in the store.`);
5222
5042
  }
5223
- const issuesOfIssueType = selectIssuesOfIssueType(issueTypeId)(state);
5224
- this.dispatch(removeIssueType(issueTypeId));
5043
+ const issuesOfIssueType = selectIssuesOfIssueType(id)(state);
5044
+ this.dispatch(removeIssueType(id));
5225
5045
  this.dispatch(deleteIssues(issuesOfIssueType.map((issue) => issue.offline_id)));
5226
5046
  const promise = this.enqueueRequest({
5227
5047
  method: HttpMethod.DELETE,
5228
- url: `/issues/types/${issueTypeId}/`,
5229
- blockers: [issueTypeId],
5048
+ url: `/issues/types/${id}/`,
5049
+ blockers: [id],
5230
5050
  blocks: []
5231
5051
  });
5232
5052
  promise.catch(() => {
@@ -5246,15 +5066,6 @@ var __publicField = (obj, key, value) => {
5246
5066
  }
5247
5067
  }
5248
5068
  class ProjectAccessService extends BaseApiService {
5249
- async fetchAll(projectId) {
5250
- return this.enqueueRequest({
5251
- description: "Get project accesses",
5252
- method: HttpMethod.GET,
5253
- url: `/projects/${projectId}/access/`,
5254
- blockers: [],
5255
- blocks: []
5256
- });
5257
- }
5258
5069
  async update(projectAccess) {
5259
5070
  this.dispatch(updateProjectAccess(projectAccess));
5260
5071
  return this.enqueueRequest({
@@ -5267,34 +5078,28 @@ var __publicField = (obj, key, value) => {
5267
5078
  });
5268
5079
  }
5269
5080
  // TODO: Re-add user to project if removal fails
5270
- async remove(projectAccess) {
5271
- this.dispatch(deleteProjectAccess(projectAccess.offline_id));
5081
+ async remove(id) {
5082
+ this.dispatch(deleteProjectAccess(id));
5272
5083
  return this.enqueueRequest({
5273
5084
  description: "Delete project access",
5274
5085
  method: HttpMethod.DELETE,
5275
- url: `/access/${projectAccess.offline_id}/`,
5276
- blockers: [projectAccess.offline_id],
5086
+ url: `/access/${id}/`,
5087
+ blockers: [id],
5277
5088
  blocks: []
5278
5089
  });
5279
5090
  }
5280
- async refreshStore(projectId) {
5281
- const promise = this.fetchAll(projectId);
5282
- const result = await promise;
5283
- this.dispatch(initializeProjectAccesses(result));
5284
- }
5285
- }
5286
- class ProjectFileService extends BaseApiService {
5287
5091
  async refreshStore(projectId) {
5288
5092
  const result = await this.enqueueRequest({
5289
- description: "Get project files",
5093
+ description: "Get project accesses",
5290
5094
  method: HttpMethod.GET,
5291
- url: `/projects/${projectId}/files/`,
5095
+ url: `/projects/${projectId}/access/`,
5292
5096
  blockers: [],
5293
5097
  blocks: []
5294
5098
  });
5295
- this.dispatch(addOrReplaceProjectFiles([]));
5296
- this.dispatch(addOrReplaceProjectFiles(result));
5099
+ this.dispatch(initializeProjectAccesses(result));
5297
5100
  }
5101
+ }
5102
+ class ProjectFileService extends BaseApiService {
5298
5103
  async saveExisting(file) {
5299
5104
  if (!file.offline_id) {
5300
5105
  throw new Error(
@@ -5382,6 +5187,17 @@ var __publicField = (obj, key, value) => {
5382
5187
  blocks: []
5383
5188
  });
5384
5189
  }
5190
+ async refreshStore(projectId) {
5191
+ const result = await this.enqueueRequest({
5192
+ description: "Get project files",
5193
+ method: HttpMethod.GET,
5194
+ url: `/projects/${projectId}/files/`,
5195
+ blockers: [],
5196
+ blocks: []
5197
+ });
5198
+ this.dispatch(addOrReplaceProjectFiles([]));
5199
+ this.dispatch(addOrReplaceProjectFiles(result));
5200
+ }
5385
5201
  }
5386
5202
  class ProjectAttachmentService extends BaseAttachmentService {
5387
5203
  constructor() {
@@ -5415,29 +5231,23 @@ var __publicField = (obj, key, value) => {
5415
5231
  }
5416
5232
  }
5417
5233
  class ProjectService extends BaseApiService {
5418
- /**
5419
- * Creates a new project. Due to the nature of project creation,
5420
- * @param project A Payload<Project> object containing project attributes.
5421
- * @returns A promise that resolves to a Project.
5422
- * @throws An APIError if the server returns an error, or any other error that may occur.
5423
- */
5424
- async add(project) {
5425
- if (!project.organization_owner && !project.user_owner) {
5234
+ async add(payload) {
5235
+ if (!payload.organization_owner && !payload.user_owner) {
5426
5236
  throw new Error("Project type was not chosen when trying to create a project");
5427
5237
  }
5428
- if (!project.bounds && !project.canvas_bounds) {
5238
+ if (!payload.bounds && !payload.canvas_bounds) {
5429
5239
  throw new Error("Project must either have bounds or canvas_bounds set");
5430
5240
  }
5431
- const isOrganizationProject = !!project.organization_owner;
5432
- const url = isOrganizationProject ? `/organizations/${project.organization_owner}/projects/` : "/projects/";
5433
- const projectType = isOrganizationProject ? { organization_owner: project.organization_owner } : { user_owner: project.user_owner };
5241
+ const isOrganizationProject = !!payload.organization_owner;
5242
+ const url = isOrganizationProject ? `/organizations/${payload.organization_owner}/projects/` : "/projects/";
5243
+ const projectType = isOrganizationProject ? { organization_owner: payload.organization_owner } : { user_owner: payload.user_owner };
5434
5244
  return await this.enqueueRequest({
5435
5245
  description: "Create project",
5436
5246
  method: HttpMethod.POST,
5437
5247
  url,
5438
5248
  payload: {
5439
- name: project.name,
5440
- bounds: project.bounds,
5249
+ name: payload.name,
5250
+ bounds: payload.bounds,
5441
5251
  ...projectType
5442
5252
  },
5443
5253
  blockers: [],
@@ -5567,8 +5377,9 @@ var __publicField = (obj, key, value) => {
5567
5377
  };
5568
5378
  class FormService extends BaseUploadService {
5569
5379
  async bulkAddRevisionAttachments(revisionId, files) {
5380
+ var _a2;
5570
5381
  const submittedAt = (/* @__PURE__ */ new Date()).toISOString();
5571
- const createdBy = this.client.store.getState().userReducer.currentUser.id;
5382
+ const createdBy = (_a2 = this.client.store.getState().userReducer.currentUser) == null ? void 0 : _a2.id;
5572
5383
  const filePayloads = {};
5573
5384
  const offlineFormRevisionAttachments = [];
5574
5385
  const attachmentPayloads = [];
@@ -5670,10 +5481,11 @@ var __publicField = (obj, key, value) => {
5670
5481
  return [form, offlineFormRevision, offlineFormRevisionAttachments, formPromise, attachmentsPromise];
5671
5482
  }
5672
5483
  addForOrganization(organizationId, initialRevision) {
5484
+ var _a2;
5673
5485
  const state = this.client.store.getState();
5674
5486
  const offlineForm = offline({
5675
5487
  favorite: false,
5676
- created_by: state.userReducer.currentUser.id,
5488
+ created_by: (_a2 = state.userReducer.currentUser) == null ? void 0 : _a2.id,
5677
5489
  submitted_at: (/* @__PURE__ */ new Date()).toISOString(),
5678
5490
  organization: organizationId
5679
5491
  });
@@ -5685,45 +5497,49 @@ var __publicField = (obj, key, value) => {
5685
5497
  );
5686
5498
  }
5687
5499
  addForProject(projectId, initialRevision) {
5500
+ var _a2;
5688
5501
  const state = this.client.store.getState();
5689
5502
  const offlineForm = offline({
5690
5503
  favorite: false,
5691
- created_by: state.userReducer.currentUser.id,
5504
+ created_by: (_a2 = state.userReducer.currentUser) == null ? void 0 : _a2.id,
5692
5505
  submitted_at: (/* @__PURE__ */ new Date()).toISOString(),
5693
5506
  project: projectId
5694
5507
  });
5695
5508
  return this.add(projectId.toString(), offlineForm, initialRevision, `/projects/${projectId}/create-form/`);
5696
5509
  }
5697
5510
  addForIssueType(issueTypeId, initialRevision) {
5511
+ var _a2;
5698
5512
  const state = this.client.store.getState();
5699
5513
  const offlineForm = offline({
5700
5514
  favorite: false,
5701
- created_by: state.userReducer.currentUser.id,
5515
+ created_by: (_a2 = state.userReducer.currentUser) == null ? void 0 : _a2.id,
5702
5516
  submitted_at: (/* @__PURE__ */ new Date()).toISOString(),
5703
5517
  issue_type: issueTypeId
5704
5518
  });
5705
5519
  return this.add(issueTypeId, offlineForm, initialRevision, `/issues/types/${issueTypeId}/create-form/`);
5706
5520
  }
5707
5521
  addForAssetType(assetTypeId, initialRevision) {
5522
+ var _a2;
5708
5523
  const state = this.client.store.getState();
5709
5524
  const offlineForm = offline({
5710
5525
  favorite: false,
5711
- created_by: state.userReducer.currentUser.id,
5526
+ created_by: (_a2 = state.userReducer.currentUser) == null ? void 0 : _a2.id,
5712
5527
  submitted_at: (/* @__PURE__ */ new Date()).toISOString(),
5713
5528
  asset_type: assetTypeId
5714
5529
  });
5715
5530
  return this.add(assetTypeId, offlineForm, initialRevision, `/assets/types/${assetTypeId}/create-form/`);
5716
5531
  }
5717
5532
  async createRevision(formId, revision) {
5533
+ var _a2;
5718
5534
  const offlineRevision = offline(revision);
5719
5535
  const { store } = this.client;
5720
5536
  const state = store.getState();
5721
- const currentUserId = state.userReducer.currentUser.id;
5537
+ const createdBy = (_a2 = state.userReducer.currentUser) == null ? void 0 : _a2.id;
5722
5538
  const { fields, images } = await separateImageFromFields(offlineRevision.fields);
5723
5539
  const fullRevision = {
5724
5540
  ...offlineRevision,
5725
5541
  fields,
5726
- created_by: currentUserId,
5542
+ created_by: createdBy,
5727
5543
  revision: "Pending",
5728
5544
  form: formId,
5729
5545
  submitted_at: (/* @__PURE__ */ new Date()).toISOString()
@@ -5756,48 +5572,6 @@ var __publicField = (obj, key, value) => {
5756
5572
  });
5757
5573
  return [fullRevision, offlineFormRevisionAttachments, promise, attachmentsPromise];
5758
5574
  }
5759
- async favorite(formId, projectId) {
5760
- const { store } = this.client;
5761
- const state = store.getState();
5762
- const form = state.formReducer.instances[formId];
5763
- if (!form) {
5764
- throw new Error(`Expected form to exist, got ${form}`);
5765
- }
5766
- this.dispatch(updateForm({ ...form, favorite: true }));
5767
- try {
5768
- await this.enqueueRequest({
5769
- description: "Favorite form",
5770
- method: HttpMethod.POST,
5771
- url: `/forms/${formId}/favorite/${projectId}/`,
5772
- blockers: [formId, `favorite-${formId}`],
5773
- blocks: [`favorite-${formId}`]
5774
- });
5775
- } catch (e) {
5776
- this.dispatch(updateForm(form));
5777
- throw e;
5778
- }
5779
- }
5780
- async unfavorite(formId, projectId) {
5781
- const { store } = this.client;
5782
- const state = store.getState();
5783
- const form = state.formReducer.instances[formId];
5784
- if (!form) {
5785
- throw new Error(`Expected form to exist, got ${form}`);
5786
- }
5787
- this.dispatch(updateForm({ ...form, favorite: false }));
5788
- try {
5789
- return await this.enqueueRequest({
5790
- description: "Unfavorite form",
5791
- method: HttpMethod.DELETE,
5792
- url: `/forms/${formId}/unfavorite/${projectId}/`,
5793
- blockers: [formId, `favorite-${formId}`],
5794
- blocks: [`favorite-${formId}`]
5795
- });
5796
- } catch (e) {
5797
- this.dispatch(updateForm(form));
5798
- throw e;
5799
- }
5800
- }
5801
5575
  async delete(formId) {
5802
5576
  const { store } = this.client;
5803
5577
  const state = store.getState();
@@ -5914,8 +5688,9 @@ var __publicField = (obj, key, value) => {
5914
5688
  };
5915
5689
  class FormSubmissionService extends BaseUploadService {
5916
5690
  async bulkAddSubmissionAttachments(submissionId, files) {
5691
+ var _a2;
5917
5692
  const submittedAt = (/* @__PURE__ */ new Date()).toISOString();
5918
- const createdBy = this.client.store.getState().userReducer.currentUser.id;
5693
+ const createdBy = (_a2 = this.client.store.getState().userReducer.currentUser) == null ? void 0 : _a2.id;
5919
5694
  const filePayloads = {};
5920
5695
  const offlineFormSubmissionAttachments = [];
5921
5696
  const attachmentPayloads = [];
@@ -5997,13 +5772,14 @@ var __publicField = (obj, key, value) => {
5997
5772
  }
5998
5773
  // Outer promise is for hashing and caching files for submission attachments
5999
5774
  async add(payload) {
5775
+ var _a2;
6000
5776
  const { store } = this.client;
6001
5777
  const state = store.getState();
6002
5778
  const { values, files } = separateFilesFromValues(payload.values);
6003
5779
  const offlineSubmission = offline({
6004
5780
  ...payload,
6005
5781
  values,
6006
- created_by: state.userReducer.currentUser.id,
5782
+ created_by: (_a2 = state.userReducer.currentUser) == null ? void 0 : _a2.id,
6007
5783
  submitted_at: (/* @__PURE__ */ new Date()).toISOString()
6008
5784
  });
6009
5785
  const promise = this.enqueueRequest({
@@ -6152,7 +5928,7 @@ var __publicField = (obj, key, value) => {
6152
5928
  description: "Delete user form submissions",
6153
5929
  method: HttpMethod.PATCH,
6154
5930
  url: `/forms/submissions/${updatedSubmission.offline_id}/`,
6155
- payload: updatedSubmission,
5931
+ payload,
6156
5932
  blockers: [updatedSubmission.offline_id],
6157
5933
  blocks: [updatedSubmission.offline_id]
6158
5934
  });
@@ -6258,13 +6034,20 @@ var __publicField = (obj, key, value) => {
6258
6034
  }
6259
6035
  }
6260
6036
  class WorkspaceService extends BaseApiService {
6261
- add(workspace) {
6262
- const offlineWorkspace = offline(workspace);
6037
+ add(payload) {
6038
+ var _a2;
6039
+ const { store } = this.client;
6040
+ const createdBy = (_a2 = store.getState().userReducer.currentUser) == null ? void 0 : _a2.id;
6041
+ const offlineWorkspace = offline({
6042
+ ...payload,
6043
+ submitted_at: (/* @__PURE__ */ new Date()).toISOString(),
6044
+ created_by: createdBy
6045
+ });
6263
6046
  this.dispatch(addWorkspace(offlineWorkspace));
6264
6047
  const promise = this.enqueueRequest({
6265
6048
  description: "Create Workspace",
6266
6049
  method: HttpMethod.POST,
6267
- url: `/projects/${workspace.project}/workspaces/`,
6050
+ url: `/projects/${payload.project}/workspaces/`,
6268
6051
  payload: offlineWorkspace,
6269
6052
  blockers: ["add-workspace"],
6270
6053
  blocks: [offlineWorkspace.offline_id]
@@ -6276,20 +6059,33 @@ var __publicField = (obj, key, value) => {
6276
6059
  });
6277
6060
  return [offlineWorkspace, promise];
6278
6061
  }
6279
- update(workspace) {
6280
- this.dispatch(addWorkspace(workspace));
6062
+ update(payload) {
6063
+ const { store } = this.client;
6064
+ const workspace = selectWorkspaceById(payload.offline_id)(store.getState());
6065
+ if (!workspace) {
6066
+ throw new Error(`Expected an existing workspace with offline_id ${payload.offline_id}`);
6067
+ }
6068
+ const updatedWorkspace = { ...workspace, ...payload };
6069
+ this.dispatch(updateWorkspace(updatedWorkspace));
6281
6070
  const promise = this.enqueueRequest({
6282
6071
  description: "Update Workspace",
6283
6072
  method: HttpMethod.PATCH,
6284
6073
  url: `/workspaces/${workspace.offline_id}/`,
6285
- payload: workspace,
6074
+ payload,
6286
6075
  blockers: [workspace.offline_id],
6287
6076
  blocks: [workspace.offline_id]
6288
6077
  });
6078
+ promise.then((result) => {
6079
+ this.dispatch(updateWorkspace(result));
6080
+ }).catch(() => {
6081
+ this.dispatch(updateWorkspace(workspace));
6082
+ });
6289
6083
  return [workspace, promise];
6290
6084
  }
6291
6085
  delete(workspaceId) {
6292
6086
  const { store } = this.client;
6087
+ const originalWorkspace = selectWorkspaceById(workspaceId)(store.getState());
6088
+ this.dispatch(deleteWorkspace(workspaceId));
6293
6089
  const promise = this.enqueueRequest({
6294
6090
  description: "Delete Workspace",
6295
6091
  method: HttpMethod.DELETE,
@@ -6297,8 +6093,6 @@ var __publicField = (obj, key, value) => {
6297
6093
  blockers: [workspaceId],
6298
6094
  blocks: []
6299
6095
  });
6300
- const originalWorkspace = store.getState().workspaceReducer.instances[workspaceId];
6301
- this.dispatch(deleteWorkspace(workspaceId));
6302
6096
  void promise.then(() => {
6303
6097
  }).catch((reason) => {
6304
6098
  if (originalWorkspace) {
@@ -6800,12 +6594,13 @@ var __publicField = (obj, key, value) => {
6800
6594
  }
6801
6595
  class DocumentService extends BaseApiService {
6802
6596
  add(payload) {
6597
+ var _a2;
6803
6598
  const { store } = this.client;
6804
- const currentUserId = store.getState().userReducer.currentUser.id;
6599
+ const createdBy = (_a2 = store.getState().userReducer.currentUser) == null ? void 0 : _a2.id;
6805
6600
  const submittedAt = (/* @__PURE__ */ new Date()).toISOString();
6806
6601
  const offlineDocument = offline({
6807
6602
  ...payload,
6808
- created_by: currentUserId,
6603
+ created_by: createdBy,
6809
6604
  submitted_at: submittedAt
6810
6605
  });
6811
6606
  this.dispatch(addDocuments([offlineDocument]));
@@ -6826,28 +6621,31 @@ var __publicField = (obj, key, value) => {
6826
6621
  });
6827
6622
  return [offlineDocument, promise];
6828
6623
  }
6829
- update(document2) {
6624
+ update(payload) {
6830
6625
  const { store } = this.client;
6831
- const documentToBeUpdated = store.getState().documentsReducer.documents[document2.offline_id];
6626
+ const documentToBeUpdated = store.getState().documentsReducer.documents[payload.offline_id];
6832
6627
  if (!documentToBeUpdated) {
6833
6628
  throw new Error(
6834
- `attempting to update a document with offline_id ${document2.offline_id} that does not exist in store.documents`
6629
+ `attempting to update a document with offline_id ${payload.offline_id} that does not exist in store.documents`
6835
6630
  );
6836
6631
  }
6837
- this.dispatch(updateDocuments([document2]));
6632
+ const updatedDocument = {
6633
+ ...documentToBeUpdated,
6634
+ ...payload
6635
+ };
6636
+ this.dispatch(updateDocuments([updatedDocument]));
6838
6637
  const promise = this.enqueueRequest({
6839
6638
  description: "Update Document",
6840
6639
  method: HttpMethod.PATCH,
6841
- url: `/documents/${document2.offline_id}/`,
6842
- payload: document2,
6843
- blockers: [document2.offline_id],
6844
- blocks: [document2.offline_id]
6640
+ url: `/documents/${payload.offline_id}/`,
6641
+ payload,
6642
+ blockers: [payload.offline_id],
6643
+ blocks: [payload.offline_id]
6845
6644
  });
6846
6645
  promise.catch(() => {
6847
6646
  updateDocuments([documentToBeUpdated]);
6848
6647
  });
6849
- const fullDocument = store.getState().documentsReducer.documents[document2.offline_id];
6850
- return [fullDocument, promise];
6648
+ return [updatedDocument, promise];
6851
6649
  }
6852
6650
  move(documentId, targetDocumentId, position) {
6853
6651
  const { store } = this.client;
@@ -6894,22 +6692,22 @@ var __publicField = (obj, key, value) => {
6894
6692
  });
6895
6693
  return promise;
6896
6694
  }
6897
- delete(documentId) {
6695
+ delete(id) {
6898
6696
  const { store } = this.client;
6899
6697
  const documentsMapping = selectDocumentsMapping(store.getState());
6900
- const documentToBeDeleted = documentsMapping[documentId];
6698
+ const documentToBeDeleted = selectDocumentById(id)(store.getState());
6901
6699
  if (!documentToBeDeleted) {
6902
6700
  throw new Error(
6903
- `attempting to delete a document with offline_id ${documentId} that does not exist in store.documents`
6701
+ `attempting to delete a document with offline_id ${id} that does not exist in store.documents`
6904
6702
  );
6905
6703
  }
6906
6704
  const parentDocument = documentToBeDeleted.parent_document ? documentsMapping[documentToBeDeleted.parent_document] : void 0;
6907
- this.dispatch(removeDocuments([documentId]));
6705
+ this.dispatch(removeDocuments([id]));
6908
6706
  const promise = this.enqueueRequest({
6909
6707
  description: "Delete Document",
6910
6708
  method: HttpMethod.DELETE,
6911
- url: `/documents/${documentId}/`,
6912
- blockers: [documentId],
6709
+ url: `/documents/${id}/`,
6710
+ blockers: [id],
6913
6711
  blocks: []
6914
6712
  });
6915
6713
  promise.then((documentsToUpdate) => {
@@ -6967,8 +6765,9 @@ var __publicField = (obj, key, value) => {
6967
6765
  }
6968
6766
  // NOTE: overriding the method from BaseAttachmentService since document attachments get vectorized
6969
6767
  async attachFilesToDocument(files, documentId) {
6768
+ var _a2;
6970
6769
  const { store } = this.client;
6971
- const currentUser = store.getState().userReducer.currentUser;
6770
+ const createdBy = (_a2 = store.getState().userReducer.currentUser) == null ? void 0 : _a2.id;
6972
6771
  const submittedAt = (/* @__PURE__ */ new Date()).toISOString();
6973
6772
  const offlineAttachments = [];
6974
6773
  const attachmentPayloads = [];
@@ -6990,7 +6789,7 @@ var __publicField = (obj, key, value) => {
6990
6789
  file,
6991
6790
  sha1,
6992
6791
  submittedAt,
6993
- createdBy: currentUser.id,
6792
+ createdBy,
6994
6793
  description: "",
6995
6794
  modelId: documentId
6996
6795
  });
@@ -7153,10 +6952,9 @@ var __publicField = (obj, key, value) => {
7153
6952
  }
7154
6953
  }
7155
6954
  class TeamService extends BaseApiService {
7156
- add(teamPayload, organizationId) {
6955
+ add(payload) {
7157
6956
  const offlineTeam = offline({
7158
- ...teamPayload,
7159
- organization: organizationId,
6957
+ ...payload,
7160
6958
  submitted_at: (/* @__PURE__ */ new Date()).toISOString()
7161
6959
  // TODO: uncomment once supported
7162
6960
  // created_by: state.userReducer.currentUser.id,
@@ -7165,7 +6963,7 @@ var __publicField = (obj, key, value) => {
7165
6963
  const promise = this.enqueueRequest({
7166
6964
  description: "Create team",
7167
6965
  method: HttpMethod.POST,
7168
- url: `/organizations/${organizationId}/teams/`,
6966
+ url: `/organizations/${payload.organization}/teams/`,
7169
6967
  payload: offlineTeam,
7170
6968
  // No blocks since users and organizations are not offline
7171
6969
  blockers: [],
@@ -7178,25 +6976,24 @@ var __publicField = (obj, key, value) => {
7178
6976
  });
7179
6977
  return [offlineTeam, promise];
7180
6978
  }
7181
- // TODO: @Audiopolis / Magnus - should we pass a offline_id as one arg and a UpdatedTeamProps as a second arg instead of this set up?
7182
- update(team) {
6979
+ update(payload) {
7183
6980
  const { store } = this.client;
7184
- const teamToBeUpdated = selectTeamById(team.offline_id)(store.getState());
6981
+ const teamToBeUpdated = selectTeamById(payload.offline_id)(store.getState());
7185
6982
  if (!teamToBeUpdated) {
7186
- throw new Error(`Expected team with offline_id ${team.offline_id} to exist`);
6983
+ throw new Error(`Expected team with offline_id ${payload.offline_id} to exist`);
7187
6984
  }
7188
6985
  const offlineUpdatedTeam = {
7189
6986
  ...teamToBeUpdated,
7190
- ...team
6987
+ ...payload
7191
6988
  };
7192
6989
  this.dispatch(updateTeam(offlineUpdatedTeam));
7193
6990
  const promise = this.enqueueRequest({
7194
6991
  description: "Update team",
7195
6992
  method: HttpMethod.PATCH,
7196
- url: `/organizations/teams/${team.offline_id}/`,
7197
- payload: offlineUpdatedTeam,
7198
- blockers: [team.offline_id],
7199
- blocks: [team.offline_id]
6993
+ url: `/organizations/teams/${payload.offline_id}/`,
6994
+ payload,
6995
+ blockers: [payload.offline_id],
6996
+ blocks: [payload.offline_id]
7200
6997
  });
7201
6998
  promise.then((updatedTeam) => {
7202
6999
  this.dispatch(setTeam(updatedTeam));
@@ -7308,10 +7105,11 @@ var __publicField = (obj, key, value) => {
7308
7105
  }
7309
7106
  class GeoImageService extends BaseUploadService {
7310
7107
  async add(payload) {
7108
+ var _a2;
7311
7109
  const { store } = this.client;
7312
7110
  const { file, ...payloadWithoutFile } = payload;
7313
7111
  const submittedAt = (/* @__PURE__ */ new Date()).toISOString();
7314
- const currentUser = store.getState().userReducer.currentUser;
7112
+ const createdBy = (_a2 = store.getState().userReducer.currentUser) == null ? void 0 : _a2.id;
7315
7113
  const projectId = payloadWithoutFile.project;
7316
7114
  const sha1 = await hashFile(file);
7317
7115
  const filePayload = {
@@ -7326,9 +7124,9 @@ var __publicField = (obj, key, value) => {
7326
7124
  file_sha1: sha1,
7327
7125
  file: URL.createObjectURL(file),
7328
7126
  submitted_at: submittedAt,
7329
- created_by: currentUser.id
7127
+ created_by: createdBy
7330
7128
  });
7331
- store.dispatch(addGeoImage(offlineMapImage));
7129
+ this.dispatch(addGeoImage(offlineMapImage));
7332
7130
  const promise = this.enqueueRequest({
7333
7131
  description: "Add geo image",
7334
7132
  method: HttpMethod.POST,
@@ -7352,16 +7150,17 @@ var __publicField = (obj, key, value) => {
7352
7150
  });
7353
7151
  promise.then((result) => {
7354
7152
  this.processPresignedUrls(result.presigned_urls);
7355
- store.dispatch(setGeoImage(result.geo_image));
7153
+ this.dispatch(setGeoImage(result.geo_image));
7356
7154
  }).catch(() => {
7357
- store.dispatch(deleteGeoImage(offlineMapImage.offline_id));
7155
+ this.dispatch(deleteGeoImage(offlineMapImage.offline_id));
7358
7156
  });
7359
7157
  return [offlineMapImage, promise.then((result) => result.geo_image)];
7360
7158
  }
7361
7159
  async bulkAdd(payloads, projectId) {
7160
+ var _a2;
7362
7161
  const { store } = this.client;
7363
7162
  const submittedAt = (/* @__PURE__ */ new Date()).toISOString();
7364
- const currentUser = store.getState().userReducer.currentUser;
7163
+ const createdBy = (_a2 = store.getState().userReducer.currentUser) == null ? void 0 : _a2.id;
7365
7164
  const offlineGeoImages = [];
7366
7165
  const offlineIds = [];
7367
7166
  const geoImagePayloads = [];
@@ -7384,7 +7183,7 @@ var __publicField = (obj, key, value) => {
7384
7183
  file_sha1: sha1,
7385
7184
  file: URL.createObjectURL(file),
7386
7185
  submitted_at: submittedAt,
7387
- created_by: currentUser.id,
7186
+ created_by: createdBy,
7388
7187
  project: projectId
7389
7188
  });
7390
7189
  offlineGeoImages.push(offlineMapImage);
@@ -7401,7 +7200,7 @@ var __publicField = (obj, key, value) => {
7401
7200
  original_date: offlineMapImage.original_date
7402
7201
  });
7403
7202
  }
7404
- store.dispatch(addGeoImages(offlineGeoImages));
7203
+ this.dispatch(addGeoImages(offlineGeoImages));
7405
7204
  const promise = this.enqueueRequest({
7406
7205
  description: "Bulk add geo images",
7407
7206
  method: HttpMethod.POST,
@@ -7417,9 +7216,9 @@ var __publicField = (obj, key, value) => {
7417
7216
  });
7418
7217
  promise.then((result) => {
7419
7218
  this.processPresignedUrls(result.presigned_urls);
7420
- store.dispatch(setGeoImages(result.geo_images));
7219
+ this.dispatch(setGeoImages(result.geo_images));
7421
7220
  }).catch(() => {
7422
- store.dispatch(deleteGeoImages(offlineIds));
7221
+ this.dispatch(deleteGeoImages(offlineIds));
7423
7222
  });
7424
7223
  return [offlineGeoImages, promise.then((result) => result.geo_images)];
7425
7224
  }
@@ -7431,7 +7230,7 @@ var __publicField = (obj, key, value) => {
7431
7230
  throw new Error(`Map image with offline_id ${payload.offline_id} does not exist in the store`);
7432
7231
  }
7433
7232
  const updatedGeoImage = { ...geoImageToUpdate, ...payload };
7434
- store.dispatch(updateGeoImage(updatedGeoImage));
7233
+ this.dispatch(updateGeoImage(updatedGeoImage));
7435
7234
  const promise = this.enqueueRequest({
7436
7235
  description: "Update geo image",
7437
7236
  method: HttpMethod.PATCH,
@@ -7441,9 +7240,9 @@ var __publicField = (obj, key, value) => {
7441
7240
  blockers: [payload.offline_id]
7442
7241
  });
7443
7242
  promise.then((result) => {
7444
- store.dispatch(setGeoImage(result));
7243
+ this.dispatch(setGeoImage(result));
7445
7244
  }).catch(() => {
7446
- store.dispatch(setGeoImage(geoImageToUpdate));
7245
+ this.dispatch(setGeoImage(geoImageToUpdate));
7447
7246
  });
7448
7247
  return [updatedGeoImage, promise];
7449
7248
  }
@@ -7454,7 +7253,7 @@ var __publicField = (obj, key, value) => {
7454
7253
  if (!geoImageToDelete) {
7455
7254
  throw new Error(`Map image with offline_id ${geoImageId} does not exist in the store`);
7456
7255
  }
7457
- store.dispatch(deleteGeoImage(geoImageId));
7256
+ this.dispatch(deleteGeoImage(geoImageId));
7458
7257
  const promise = this.enqueueRequest({
7459
7258
  description: "Delete geo image",
7460
7259
  method: HttpMethod.DELETE,
@@ -7463,12 +7262,11 @@ var __publicField = (obj, key, value) => {
7463
7262
  blockers: [geoImageId]
7464
7263
  });
7465
7264
  promise.catch(() => {
7466
- store.dispatch(setGeoImage(geoImageToDelete));
7265
+ this.dispatch(setGeoImage(geoImageToDelete));
7467
7266
  });
7468
7267
  return promise;
7469
7268
  }
7470
7269
  async refreshStore(projectId) {
7471
- const { store } = this.client;
7472
7270
  const result = await this.enqueueRequest({
7473
7271
  description: "Get geo images",
7474
7272
  method: HttpMethod.GET,
@@ -7476,14 +7274,15 @@ var __publicField = (obj, key, value) => {
7476
7274
  blocks: [projectId.toString()],
7477
7275
  blockers: []
7478
7276
  });
7479
- store.dispatch(initializeGeoImages(result));
7277
+ this.dispatch(initializeGeoImages(result));
7480
7278
  }
7481
7279
  }
7482
7280
  class IssueAssociationService extends BaseUploadService {
7483
7281
  add(payload) {
7282
+ var _a2;
7484
7283
  const { store } = this.client;
7485
7284
  const submittedAt = (/* @__PURE__ */ new Date()).toISOString();
7486
- const createdBy = store.getState().userReducer.currentUser.id;
7285
+ const createdBy = (_a2 = store.getState().userReducer.currentUser) == null ? void 0 : _a2.id;
7487
7286
  const offlineIssueAssociation = offline({
7488
7287
  ...payload,
7489
7288
  submitted_at: submittedAt,
@@ -7497,7 +7296,6 @@ var __publicField = (obj, key, value) => {
7497
7296
  payload: {
7498
7297
  offline_id: offlineIssueAssociation.offline_id,
7499
7298
  submitted_at: submittedAt,
7500
- created_by: createdBy,
7501
7299
  ...payload
7502
7300
  },
7503
7301
  blockers: [
@@ -7545,11 +7343,19 @@ var __publicField = (obj, key, value) => {
7545
7343
  this.dispatch(initializeIssueAssociations(issueAssociations));
7546
7344
  }
7547
7345
  }
7346
+ var VerificationCodeType = /* @__PURE__ */ ((VerificationCodeType2) => {
7347
+ VerificationCodeType2[VerificationCodeType2["USER_REGISTRATION"] = 0] = "USER_REGISTRATION";
7348
+ VerificationCodeType2[VerificationCodeType2["APPLICATION_INVITE"] = 2] = "APPLICATION_INVITE";
7349
+ VerificationCodeType2[VerificationCodeType2["PROJECT_INVITE"] = 4] = "PROJECT_INVITE";
7350
+ VerificationCodeType2[VerificationCodeType2["ORGANIZATION_INVITE"] = 6] = "ORGANIZATION_INVITE";
7351
+ VerificationCodeType2[VerificationCodeType2["ADD_EMAIL_DOMAIN"] = 8] = "ADD_EMAIL_DOMAIN";
7352
+ VerificationCodeType2[VerificationCodeType2["RESET_PASSWORD"] = 10] = "RESET_PASSWORD";
7353
+ return VerificationCodeType2;
7354
+ })(VerificationCodeType || {});
7548
7355
  exports2.APIError = APIError;
7549
7356
  exports2.AgentService = AgentService;
7550
7357
  exports2.AssetAttachmentService = AssetAttachmentService;
7551
7358
  exports2.AssetService = AssetService;
7552
- exports2.AssetStageColors = AssetStageColors;
7553
7359
  exports2.AssetStageCompletionService = AssetStageCompletionService;
7554
7360
  exports2.AssetStageService = AssetStageService;
7555
7361
  exports2.AssetTypeAttachmentService = AssetTypeAttachmentService;
@@ -7611,9 +7417,14 @@ var __publicField = (obj, key, value) => {
7611
7417
  exports2.addAsset = addAsset;
7612
7418
  exports2.addAssetAttachment = addAssetAttachment;
7613
7419
  exports2.addAssetAttachments = addAssetAttachments;
7420
+ exports2.addAssetStage = addAssetStage;
7421
+ exports2.addAssetStageCompletion = addAssetStageCompletion;
7422
+ exports2.addAssetStageCompletions = addAssetStageCompletions;
7423
+ exports2.addAssetStages = addAssetStages;
7614
7424
  exports2.addAssetType = addAssetType;
7615
7425
  exports2.addAssetTypeAttachment = addAssetTypeAttachment;
7616
7426
  exports2.addAssetTypeAttachments = addAssetTypeAttachments;
7427
+ exports2.addAssetTypes = addAssetTypes;
7617
7428
  exports2.addAssets = addAssets;
7618
7429
  exports2.addCategory = addCategory;
7619
7430
  exports2.addConversation = addConversation;
@@ -7621,7 +7432,6 @@ var __publicField = (obj, key, value) => {
7621
7432
  exports2.addDocumentAttachments = addDocumentAttachments;
7622
7433
  exports2.addDocuments = addDocuments;
7623
7434
  exports2.addEmailDomain = addEmailDomain;
7624
- exports2.addFavouriteProjectId = addFavouriteProjectId;
7625
7435
  exports2.addForm = addForm;
7626
7436
  exports2.addFormRevision = addFormRevision;
7627
7437
  exports2.addFormRevisionAttachment = addFormRevisionAttachment;
@@ -7651,11 +7461,7 @@ var __publicField = (obj, key, value) => {
7651
7461
  exports2.addOrReplaceProjects = addOrReplaceProjects;
7652
7462
  exports2.addProjectAttachment = addProjectAttachment;
7653
7463
  exports2.addProjectAttachments = addProjectAttachments;
7654
- exports2.addStageCompletion = addStageCompletion;
7655
- exports2.addStageCompletions = addStageCompletions;
7656
- exports2.addStages = addStages;
7657
7464
  exports2.addTeam = addTeam;
7658
- exports2.addToRecentIssues = addToRecentIssues;
7659
7465
  exports2.addUsers = addUsers;
7660
7466
  exports2.addWorkspace = addWorkspace;
7661
7467
  exports2.agentsReducer = agentsReducer;
@@ -7679,8 +7485,6 @@ var __publicField = (obj, key, value) => {
7679
7485
  exports2.boundsContainPoint = boundsContainPoint;
7680
7486
  exports2.categoryReducer = categoryReducer;
7681
7487
  exports2.categorySlice = categorySlice;
7682
- exports2.classNames = classNames;
7683
- exports2.cleanRecentIssues = cleanRecentIssues;
7684
7488
  exports2.clearTokens = clearTokens;
7685
7489
  exports2.constructUploadedFilePayloads = constructUploadedFilePayloads;
7686
7490
  exports2.coordinatesAreEqual = coordinatesAreEqual;
@@ -7694,9 +7498,14 @@ var __publicField = (obj, key, value) => {
7694
7498
  exports2.deleteAsset = deleteAsset;
7695
7499
  exports2.deleteAssetAttachment = deleteAssetAttachment;
7696
7500
  exports2.deleteAssetAttachments = deleteAssetAttachments;
7501
+ exports2.deleteAssetStage = deleteAssetStage;
7502
+ exports2.deleteAssetStageCompletion = deleteAssetStageCompletion;
7503
+ exports2.deleteAssetStageCompletions = deleteAssetStageCompletions;
7504
+ exports2.deleteAssetStages = deleteAssetStages;
7697
7505
  exports2.deleteAssetType = deleteAssetType;
7698
7506
  exports2.deleteAssetTypeAttachment = deleteAssetTypeAttachment;
7699
7507
  exports2.deleteAssetTypeAttachments = deleteAssetTypeAttachments;
7508
+ exports2.deleteAssetTypes = deleteAssetTypes;
7700
7509
  exports2.deleteAssets = deleteAssets;
7701
7510
  exports2.deleteCategory = deleteCategory;
7702
7511
  exports2.deleteDocumentAttachment = deleteDocumentAttachment;
@@ -7761,9 +7570,7 @@ var __publicField = (obj, key, value) => {
7761
7570
  exports2.formSubmissionAttachmentSlice = formSubmissionAttachmentSlice;
7762
7571
  exports2.formSubmissionReducer = formSubmissionReducer;
7763
7572
  exports2.formSubmissionSlice = formSubmissionSlice;
7764
- exports2.fullAssetMarkerSize = fullAssetMarkerSize;
7765
7573
  exports2.generateBadgeColors = generateBadgeColors;
7766
- exports2.genericMemo = genericMemo;
7767
7574
  exports2.geoImageReducer = geoImageReducer;
7768
7575
  exports2.geoImageSlice = geoImageSlice;
7769
7576
  exports2.getFileIdentifier = getFileIdentifier;
@@ -7772,10 +7579,11 @@ var __publicField = (obj, key, value) => {
7772
7579
  exports2.getLocalRelativeDateString = getLocalRelativeDateString;
7773
7580
  exports2.getOutboxCoordinator = getOutboxCoordinator;
7774
7581
  exports2.getRenamedFile = getRenamedFile;
7775
- exports2.getStageColor = getStageColor;
7776
7582
  exports2.hashFile = hashFile;
7777
7583
  exports2.initSDK = initSDK;
7778
7584
  exports2.initializeAssetAttachments = initializeAssetAttachments;
7585
+ exports2.initializeAssetStageCompletions = initializeAssetStageCompletions;
7586
+ exports2.initializeAssetStages = initializeAssetStages;
7779
7587
  exports2.initializeAssetTypeAttachments = initializeAssetTypeAttachments;
7780
7588
  exports2.initializeAssetTypes = initializeAssetTypes;
7781
7589
  exports2.initializeAssets = initializeAssets;
@@ -7798,7 +7606,6 @@ var __publicField = (obj, key, value) => {
7798
7606
  exports2.initializeOrganizationAccesses = initializeOrganizationAccesses;
7799
7607
  exports2.initializeProjectAccesses = initializeProjectAccesses;
7800
7608
  exports2.initializeProjectAttachments = initializeProjectAttachments;
7801
- exports2.initializeStages = initializeStages;
7802
7609
  exports2.initializeTeams = initializeTeams;
7803
7610
  exports2.initializeWorkspaces = initializeWorkspaces;
7804
7611
  exports2.isToday = isToday;
@@ -7810,7 +7617,6 @@ var __publicField = (obj, key, value) => {
7810
7617
  exports2.issueCommentSlice = issueCommentSlice;
7811
7618
  exports2.issueReducer = issueReducer;
7812
7619
  exports2.issueSlice = issueSlice;
7813
- exports2.issueToSearchResult = issueToSearchResult;
7814
7620
  exports2.issueTypeReducer = issueTypeReducer;
7815
7621
  exports2.issueTypeSlice = issueTypeSlice;
7816
7622
  exports2.issueUpdateReducer = issueUpdateReducer;
@@ -7851,20 +7657,14 @@ var __publicField = (obj, key, value) => {
7851
7657
  exports2.rehydratedReducer = rehydratedReducer;
7852
7658
  exports2.rehydratedSlice = rehydratedSlice;
7853
7659
  exports2.removeDocuments = removeDocuments;
7854
- exports2.removeFavouriteProjectId = removeFavouriteProjectId;
7855
7660
  exports2.removeIssueType = removeIssueType;
7856
7661
  exports2.removeProjectFile = removeProjectFile;
7857
7662
  exports2.removeProjectFilesOfProject = removeProjectFilesOfProject;
7858
- exports2.removeRecentIssue = removeRecentIssue;
7859
- exports2.removeStageCompletions = removeStageCompletions;
7860
- exports2.removeStages = removeStages;
7861
7663
  exports2.removeUser = removeUser;
7862
7664
  exports2.resetProjectFileObjectUrls = resetProjectFileObjectUrls;
7863
- exports2.resetRecentIssues = resetRecentIssues;
7864
7665
  exports2.resetStore = resetStore;
7865
7666
  exports2.restructureCreateSelectorWithArgs = restructureCreateSelectorWithArgs;
7866
7667
  exports2.saveActiveProjectFileBounds = saveActiveProjectFileBounds;
7867
- exports2.searchIssues = searchIssues;
7868
7668
  exports2.selectAccessToken = selectAccessToken;
7869
7669
  exports2.selectActiveOrganizationAccess = selectActiveOrganizationAccess;
7870
7670
  exports2.selectActiveProject = selectActiveProject;
@@ -7880,6 +7680,9 @@ var __publicField = (obj, key, value) => {
7880
7680
  exports2.selectAssetAttachments = selectAssetAttachments;
7881
7681
  exports2.selectAssetById = selectAssetById;
7882
7682
  exports2.selectAssetStageById = selectAssetStageById;
7683
+ exports2.selectAssetStageCompletionById = selectAssetStageCompletionById;
7684
+ exports2.selectAssetStageCompletionMapping = selectAssetStageCompletionMapping;
7685
+ exports2.selectAssetStageCompletionsByIds = selectAssetStageCompletionsByIds;
7883
7686
  exports2.selectAssetStages = selectAssetStages;
7884
7687
  exports2.selectAssetStagesByIds = selectAssetStagesByIds;
7885
7688
  exports2.selectAssetTypeAttachmentById = selectAssetTypeAttachmentById;
@@ -7915,7 +7718,7 @@ var __publicField = (obj, key, value) => {
7915
7718
  exports2.selectCategoryMapping = selectCategoryMapping;
7916
7719
  exports2.selectCommentsOfIssue = selectCommentsOfIssue;
7917
7720
  exports2.selectCompletedStageIdsForAsset = selectCompletedStageIdsForAsset;
7918
- exports2.selectCompletedStages = selectCompletedStages;
7721
+ exports2.selectCompletedStagesByAsset = selectCompletedStagesByAsset;
7919
7722
  exports2.selectConversation = selectConversation;
7920
7723
  exports2.selectConversationMapping = selectConversationMapping;
7921
7724
  exports2.selectConversations = selectConversations;
@@ -7930,7 +7733,6 @@ var __publicField = (obj, key, value) => {
7930
7733
  exports2.selectEmailDomains = selectEmailDomains;
7931
7734
  exports2.selectEmailDomainsAsMapping = selectEmailDomainsAsMapping;
7932
7735
  exports2.selectEmailDomainsOfOrganization = selectEmailDomainsOfOrganization;
7933
- exports2.selectFavouriteProjects = selectFavouriteProjects;
7934
7736
  exports2.selectFilteredForms = selectFilteredForms;
7935
7737
  exports2.selectFormById = selectFormById;
7936
7738
  exports2.selectFormMapping = selectFormMapping;
@@ -7971,6 +7773,7 @@ var __publicField = (obj, key, value) => {
7971
7773
  exports2.selectIssueAttachmentMapping = selectIssueAttachmentMapping;
7972
7774
  exports2.selectIssueAttachments = selectIssueAttachments;
7973
7775
  exports2.selectIssueById = selectIssueById;
7776
+ exports2.selectIssueCommentById = selectIssueCommentById;
7974
7777
  exports2.selectIssueCommentMapping = selectIssueCommentMapping;
7975
7778
  exports2.selectIssueCountOfCategory = selectIssueCountOfCategory;
7976
7779
  exports2.selectIssueMapping = selectIssueMapping;
@@ -8020,8 +7823,6 @@ var __publicField = (obj, key, value) => {
8020
7823
  exports2.selectProjectUsersAsMapping = selectProjectUsersAsMapping;
8021
7824
  exports2.selectProjectUsersIds = selectProjectUsersIds;
8022
7825
  exports2.selectProjectsOfOrganization = selectProjectsOfOrganization;
8023
- exports2.selectRecentIssueIds = selectRecentIssueIds;
8024
- exports2.selectRecentIssuesAsSearchResults = selectRecentIssuesAsSearchResults;
8025
7826
  exports2.selectRehydrated = selectRehydrated;
8026
7827
  exports2.selectRootDocuments = selectRootDocuments;
8027
7828
  exports2.selectSortedFormSubmissionsOfForm = selectSortedFormSubmissionsOfForm;
@@ -8029,7 +7830,6 @@ var __publicField = (obj, key, value) => {
8029
7830
  exports2.selectSortedProjectUsers = selectSortedProjectUsers;
8030
7831
  exports2.selectStageFormIdsFromStageIds = selectStageFormIdsFromStageIds;
8031
7832
  exports2.selectStageMapping = selectStageMapping;
8032
- exports2.selectStagesFromAssetTypeIds = selectStagesFromAssetTypeIds;
8033
7833
  exports2.selectStagesOfAssetType = selectStagesOfAssetType;
8034
7834
  exports2.selectTeamById = selectTeamById;
8035
7835
  exports2.selectTeams = selectTeams;
@@ -8049,8 +7849,12 @@ var __publicField = (obj, key, value) => {
8049
7849
  exports2.setAsset = setAsset;
8050
7850
  exports2.setAssetAttachment = setAssetAttachment;
8051
7851
  exports2.setAssetAttachments = setAssetAttachments;
7852
+ exports2.setAssetStage = setAssetStage;
7853
+ exports2.setAssetStages = setAssetStages;
7854
+ exports2.setAssetType = setAssetType;
8052
7855
  exports2.setAssetTypeAttachment = setAssetTypeAttachment;
8053
7856
  exports2.setAssetTypeAttachments = setAssetTypeAttachments;
7857
+ exports2.setAssetTypes = setAssetTypes;
8054
7858
  exports2.setAssets = setAssets;
8055
7859
  exports2.setConversation = setConversation;
8056
7860
  exports2.setCurrentUser = setCurrentUser;
@@ -8083,11 +7887,8 @@ var __publicField = (obj, key, value) => {
8083
7887
  exports2.setProjectAttachments = setProjectAttachments;
8084
7888
  exports2.setProjects = setProjects;
8085
7889
  exports2.setRehydrated = setRehydrated;
8086
- exports2.setStage = setStage;
8087
- exports2.setStageCompletions = setStageCompletions;
8088
7890
  exports2.setTeam = setTeam;
8089
7891
  exports2.setTokens = setTokens;
8090
- exports2.setTourStep = setTourStep;
8091
7892
  exports2.setUploadUrl = setUploadUrl;
8092
7893
  exports2.setUsers = setUsers;
8093
7894
  exports2.setWorkspaces = setWorkspaces;
@@ -8103,8 +7904,14 @@ var __publicField = (obj, key, value) => {
8103
7904
  exports2.updateAsset = updateAsset;
8104
7905
  exports2.updateAssetAttachment = updateAssetAttachment;
8105
7906
  exports2.updateAssetAttachments = updateAssetAttachments;
7907
+ exports2.updateAssetStage = updateAssetStage;
7908
+ exports2.updateAssetStageCompletion = updateAssetStageCompletion;
7909
+ exports2.updateAssetStageCompletions = updateAssetStageCompletions;
7910
+ exports2.updateAssetStages = updateAssetStages;
7911
+ exports2.updateAssetType = updateAssetType;
8106
7912
  exports2.updateAssetTypeAttachment = updateAssetTypeAttachment;
8107
7913
  exports2.updateAssetTypeAttachments = updateAssetTypeAttachments;
7914
+ exports2.updateAssetTypes = updateAssetTypes;
8108
7915
  exports2.updateAssets = updateAssets;
8109
7916
  exports2.updateCategory = updateCategory;
8110
7917
  exports2.updateConversation = updateConversation;
@@ -8132,11 +7939,8 @@ var __publicField = (obj, key, value) => {
8132
7939
  exports2.updateProjectAccess = updateProjectAccess;
8133
7940
  exports2.updateProjectAttachment = updateProjectAttachment;
8134
7941
  exports2.updateProjectAttachments = updateProjectAttachments;
8135
- exports2.updateStage = updateStage;
8136
- exports2.updateStages = updateStages;
8137
7942
  exports2.updateTeam = updateTeam;
8138
7943
  exports2.updateWorkspace = updateWorkspace;
8139
- exports2.useMemoCompare = useMemoCompare;
8140
7944
  exports2.userReducer = userReducer;
8141
7945
  exports2.userSlice = userSlice;
8142
7946
  exports2.versioningReducer = versioningReducer;