@overmap-ai/core 1.0.65-mapbox.1 → 1.0.65-org-projs-only.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- export declare const OUTBOX_RETRY_DELAY = 5000;
1
+ export declare const OUTBOX_RETRY_DELAY = 60000;
@@ -11,7 +11,7 @@ import { offline as offline$1 } from "@redux-offline/redux-offline";
11
11
  import offlineConfig from "@redux-offline/redux-offline/lib/defaults";
12
12
  import localforage from "localforage";
13
13
  import createMigration from "redux-persist-migrate";
14
- import { createSlice, createSelector, combineReducers, createNextState } from "@reduxjs/toolkit";
14
+ import { createSlice, createSelector, combineReducers } from "@reduxjs/toolkit";
15
15
  import request from "superagent";
16
16
  import { saveAs } from "file-saver";
17
17
  import React, { useRef, useEffect } from "react";
@@ -409,21 +409,70 @@ const { setTokens, clearTokens, setLoggedIn } = authSlice.actions;
409
409
  const selectAccessToken = (state) => state.authReducer.accessToken;
410
410
  const selectIsLoggedIn = (state) => state.authReducer.isLoggedIn;
411
411
  const authReducer = authSlice.reducer;
412
- const createPointGeometry = (position) => {
412
+ const coordinatesToLiteral = (coordinates) => {
413
+ return { lng: coordinates[0], lat: coordinates[1] };
414
+ };
415
+ const literalToCoordinates = (literal) => {
416
+ return [literal.lng, literal.lat];
417
+ };
418
+ const flipCoordinates = (coordinates) => {
419
+ return [coordinates[1], coordinates[0]];
420
+ };
421
+ const flipBounds = (bounds) => {
422
+ return [flipCoordinates(bounds[0]), flipCoordinates(bounds[1])];
423
+ };
424
+ function offsetPositionByMeters(originalPosition, latMeters, lngMeters) {
425
+ const { lat, lng } = originalPosition;
426
+ const earthRadius = 6378137;
427
+ const metersPerDegree = 2 * Math.PI * earthRadius / 360;
428
+ const newLng = lng + lngMeters / metersPerDegree / Math.cos(lat * Math.PI / 180);
429
+ const newLat = lat - latMeters / metersPerDegree;
430
+ return { lat: newLat, lng: newLng };
431
+ }
432
+ const createPointGeometry = (coordinates) => {
413
433
  return {
414
434
  type: "Point",
415
- coordinates: position
435
+ coordinates
416
436
  };
417
437
  };
438
+ const coordinatesAreEqual = (a, b) => {
439
+ return a[0] === b[0] && a[1] === b[1];
440
+ };
441
+ const coordinatesToText = (coordinates, decimalPlaces) => {
442
+ if (!coordinates)
443
+ return "(No Location)";
444
+ const { lat, lng } = coordinatesToLiteral(coordinates);
445
+ if (decimalPlaces)
446
+ return `${lat.toFixed(decimalPlaces)}, ${lng.toFixed(decimalPlaces)}`;
447
+ return `${lat}, ${lng}`;
448
+ };
449
+ const coordinatesToUrlText = (coordinates) => {
450
+ const { lat, lng } = coordinatesToLiteral(coordinates);
451
+ return `${lat}%2C${lng}`;
452
+ };
453
+ const openCoordsInGoogleMaps = (coordinates) => {
454
+ const url = `https://www.google.com/maps/search/?api=1&query=${coordinatesToUrlText(coordinates)}`;
455
+ window.open(url);
456
+ };
457
+ const openDirectionsInGoogleMaps = (startingPoint, destination) => {
458
+ const startingPointUrl = coordinatesToUrlText(startingPoint);
459
+ const destinationUrl = coordinatesToUrlText(destination);
460
+ const url = `https://www.google.com/maps/dir/?api=1&origin=${startingPointUrl}&destination=${destinationUrl}`;
461
+ window.open(url);
462
+ };
463
+ const worldBounds = {
464
+ type: "MultiPoint",
465
+ coordinates: [
466
+ [90, -180],
467
+ [-90, 180]
468
+ ]
469
+ };
418
470
  const createMultiPointGeometry = (coordinates) => {
419
471
  return {
420
472
  type: "MultiPoint",
421
473
  coordinates
422
474
  };
423
475
  };
424
- const coordinatesAreEqual = (a, b) => {
425
- return a[0] === b[0] && a[1] === b[1];
426
- };
427
476
  function classNames(...args) {
428
477
  const classes = [];
429
478
  for (const arg of args) {
@@ -601,11 +650,14 @@ function onlyUniqueHashes(value, index, self) {
601
650
  return v.file_sha1 === value.file_sha1;
602
651
  }) === index;
603
652
  }
653
+ function boundsContainPoint(bounds, coordinates) {
654
+ return bounds[0][0] > coordinates[0] && bounds[1][0] < coordinates[0] && bounds[0][1] > coordinates[1] && bounds[1][1] < coordinates[1];
655
+ }
604
656
  const emailRegex = /^.+@.+\..+$/;
605
657
  const fullAssetMarkerSize = 45;
606
658
  const DEFAULT_ISSUE_STATUS = IssueStatus.BACKLOG;
607
659
  const DEFAULT_ISSUE_PRIORITY = IssuePriority.MEDIUM;
608
- const OUTBOX_RETRY_DELAY = 5e3;
660
+ const OUTBOX_RETRY_DELAY = 6e4;
609
661
  const EMPTY_ARRAY = Object.freeze([]);
610
662
  let debug = false;
611
663
  const REACT_APP_DEBUG_MEMOIZATION = {}.REACT_APP_DEBUG_MEMOIZATION || "";
@@ -2323,29 +2375,18 @@ const selectFilteredForms = restructureCreateSelectorWithArgs(
2323
2375
  (_state, search) => search
2324
2376
  ],
2325
2377
  (formsMapping, revisions, search) => {
2326
- const { searchTerm, maxResults, favorites, organization } = search;
2327
- const favoriteMatches = [];
2378
+ const { searchTerm, maxResults, organization } = search;
2328
2379
  const regularMatches = [];
2329
2380
  for (const [formId, form] of Object.entries(formsMapping)) {
2330
- if (favorites !== void 0 && form.favorite != favorites)
2331
- continue;
2332
2381
  if (Number.isInteger(organization) && organization !== form.organization) {
2333
2382
  continue;
2334
2383
  }
2335
2384
  const latestRevision = _selectLatestFormRevision(revisions, formId);
2336
2385
  if (latestRevision.title.toLowerCase().includes(searchTerm.toLowerCase())) {
2337
- if (form.favorite) {
2338
- favoriteMatches.push({ ...form, latestRevision });
2339
- } else {
2340
- regularMatches.push({ ...form, latestRevision });
2341
- }
2342
- }
2343
- if (favoriteMatches.length >= maxResults) {
2344
- break;
2386
+ regularMatches.push({ ...form, latestRevision });
2345
2387
  }
2346
2388
  }
2347
- const maxRegularMatches = maxResults - favoriteMatches.length;
2348
- return [...favoriteMatches, ...regularMatches.slice(0, maxRegularMatches)];
2389
+ return [...regularMatches.slice(0, maxResults)];
2349
2390
  },
2350
2391
  // as the argument is an object, we check the first level of properties for equality
2351
2392
  { memoizeOptions: { equalityCheck: shallowEqual } }
@@ -3372,62 +3413,11 @@ const overmapReducers = {
3372
3413
  };
3373
3414
  const overmapReducer = combineReducers(overmapReducers);
3374
3415
  const resetStore = "RESET";
3375
- function handleWorkspaceRemoval(draft, action) {
3376
- const workspaceId = action.payload;
3377
- const issuesVisibleInWorkspace = Object.values(draft.issueReducer.instances).filter(
3378
- (issue) => issue.visible_in_workspaces.includes(workspaceId)
3379
- );
3380
- const mainWorkspace = selectMainWorkspace(draft);
3381
- if (!mainWorkspace) {
3382
- throw new Error("Main workspace not found");
3383
- }
3384
- if (action.payload === mainWorkspace.offline_id) {
3385
- throw new Error("Tried to delete main workspace");
3386
- }
3387
- const categoriesInThisWorkspace = new Set(
3388
- selectCategoriesOfWorkspace(workspaceId)(draft).map((category) => category.offline_id)
3389
- );
3390
- for (const issue of issuesVisibleInWorkspace) {
3391
- if (issue.category && categoriesInThisWorkspace.has(issue.category)) {
3392
- issue.category = null;
3393
- }
3394
- }
3395
- const issuesWithThisWorkspaceIndex = issuesVisibleInWorkspace.filter(
3396
- (issue) => issue.index_workspace === action.payload
3397
- );
3398
- for (const issue of issuesWithThisWorkspaceIndex) {
3399
- issue.index_workspace = mainWorkspace.offline_id;
3400
- if (!issue.visible_in_workspaces.includes(mainWorkspace.offline_id)) {
3401
- issue.visible_in_workspaces.push(mainWorkspace.offline_id);
3402
- }
3403
- }
3404
- for (const issue of issuesVisibleInWorkspace) {
3405
- const indexOfWorkspace = issue.visible_in_workspaces.indexOf(workspaceId);
3406
- if (indexOfWorkspace === -1) {
3407
- throw new Error("Workspace not found in issue's visible_in_workspaces");
3408
- }
3409
- issue.visible_in_workspaces.splice(indexOfWorkspace, 1);
3410
- }
3411
- for (const issue of issuesVisibleInWorkspace) {
3412
- if (issue.visible_in_workspaces.length === 0) {
3413
- throw new Error(`Unexpected error: Issue ${issue.offline_id} has no visible_in_workspaces`);
3414
- }
3415
- if (issue.index_workspace === action.payload || !issue.index_workspace) {
3416
- throw new Error(`Failed to update index_workspace of issue ${issue.offline_id} to main workspace`);
3417
- }
3418
- }
3419
- }
3420
3416
  const overmapRootReducer = (state, action) => {
3421
3417
  if (action.type === "auth/setLoggedIn" && !action.payload) {
3422
3418
  return overmapReducer(void 0, action);
3423
3419
  }
3424
- let mutatedState = state;
3425
- if (state && action.type === "workspace/removeWorkspace") {
3426
- mutatedState = createNextState(state, (draft) => {
3427
- handleWorkspaceRemoval(draft, action);
3428
- });
3429
- }
3430
- return overmapReducer(mutatedState, action);
3420
+ return overmapReducer(state, action);
3431
3421
  };
3432
3422
  let __OUTBOX_COORDINATOR = null;
3433
3423
  function getOutboxCoordinator() {
@@ -4046,10 +4036,17 @@ class BaseApiService extends BaseService {
4046
4036
  }
4047
4037
  }
4048
4038
  class CategoryService extends BaseApiService {
4049
- add(category, workspaceId) {
4050
- const offlineCategory = offline(category);
4051
- const categoryWithWorkspace = { ...offlineCategory, workspace: workspaceId };
4052
- this.dispatch(addCategory(categoryWithWorkspace));
4039
+ add(payload, workspaceId) {
4040
+ const { store } = this.client;
4041
+ const createdBy = store.getState().userReducer.currentUser.id;
4042
+ const submittedAt = (/* @__PURE__ */ new Date()).toISOString();
4043
+ const offlineCategory = offline({
4044
+ ...payload,
4045
+ created_by: createdBy,
4046
+ submitted_at: submittedAt,
4047
+ workspace: workspaceId
4048
+ });
4049
+ this.dispatch(addCategory(offlineCategory));
4053
4050
  const promise = this.enqueueRequest({
4054
4051
  description: "Create Category",
4055
4052
  method: HttpMethod.POST,
@@ -4058,10 +4055,10 @@ class CategoryService extends BaseApiService {
4058
4055
  workspace_id: workspaceId.toString()
4059
4056
  },
4060
4057
  payload: offlineCategory,
4061
- blockers: [],
4058
+ blockers: [workspaceId],
4062
4059
  blocks: [offlineCategory.offline_id]
4063
4060
  });
4064
- return [categoryWithWorkspace, promise];
4061
+ return [offlineCategory, promise];
4065
4062
  }
4066
4063
  update(category, workspaceId) {
4067
4064
  const state = this.client.store.getState();
@@ -4931,11 +4928,7 @@ class IssueService extends BaseApiService {
4931
4928
  ...issueType ? { issue_type: issueType } : {}
4932
4929
  },
4933
4930
  payload: issuePayload,
4934
- blockers: [
4935
- "add-issue",
4936
- ...issuePayload.index_workspace ? [issuePayload.index_workspace] : [],
4937
- ...issuePayload.visible_in_workspaces
4938
- ],
4931
+ blockers: ["add-issue", ...issuePayload.index_workspace ? [issuePayload.index_workspace] : []],
4939
4932
  blocks: [issuePayload.offline_id]
4940
4933
  });
4941
4934
  void promise.then((result) => {
@@ -5382,23 +5375,17 @@ class ProjectService extends BaseApiService {
5382
5375
  * @throws An APIError if the server returns an error, or any other error that may occur.
5383
5376
  */
5384
5377
  async add(project) {
5385
- if (!project.organization_owner && !project.user_owner) {
5386
- throw new Error("Project type was not chosen when trying to create a project");
5387
- }
5388
5378
  if (!project.bounds && !project.canvas_bounds) {
5389
5379
  throw new Error("Project must either have bounds or canvas_bounds set");
5390
5380
  }
5391
- const isOrganizationProject = !!project.organization_owner;
5392
- const url = isOrganizationProject ? `/organizations/${project.organization_owner}/projects/` : "/projects/";
5393
- const projectType = isOrganizationProject ? { organization_owner: project.organization_owner } : { user_owner: project.user_owner };
5394
5381
  return await this.enqueueRequest({
5395
5382
  description: "Create project",
5396
5383
  method: HttpMethod.POST,
5397
- url,
5384
+ url: "/projects/",
5398
5385
  payload: {
5399
5386
  name: project.name,
5400
5387
  bounds: project.bounds,
5401
- ...projectType
5388
+ organization_owner: project.organization_owner
5402
5389
  },
5403
5390
  blockers: [],
5404
5391
  blocks: []
@@ -5716,48 +5703,6 @@ class FormService extends BaseUploadService {
5716
5703
  });
5717
5704
  return [fullRevision, offlineFormRevisionAttachments, promise, attachmentsPromise];
5718
5705
  }
5719
- async favorite(formId, projectId) {
5720
- const { store } = this.client;
5721
- const state = store.getState();
5722
- const form = state.formReducer.instances[formId];
5723
- if (!form) {
5724
- throw new Error(`Expected form to exist, got ${form}`);
5725
- }
5726
- this.dispatch(updateForm({ ...form, favorite: true }));
5727
- try {
5728
- await this.enqueueRequest({
5729
- description: "Favorite form",
5730
- method: HttpMethod.POST,
5731
- url: `/forms/${formId}/favorite/${projectId}/`,
5732
- blockers: [formId, `favorite-${formId}`],
5733
- blocks: [`favorite-${formId}`]
5734
- });
5735
- } catch (e) {
5736
- this.dispatch(updateForm(form));
5737
- throw e;
5738
- }
5739
- }
5740
- async unfavorite(formId, projectId) {
5741
- const { store } = this.client;
5742
- const state = store.getState();
5743
- const form = state.formReducer.instances[formId];
5744
- if (!form) {
5745
- throw new Error(`Expected form to exist, got ${form}`);
5746
- }
5747
- this.dispatch(updateForm({ ...form, favorite: false }));
5748
- try {
5749
- return await this.enqueueRequest({
5750
- description: "Unfavorite form",
5751
- method: HttpMethod.DELETE,
5752
- url: `/forms/${formId}/unfavorite/${projectId}/`,
5753
- blockers: [formId, `favorite-${formId}`],
5754
- blocks: [`favorite-${formId}`]
5755
- });
5756
- } catch (e) {
5757
- this.dispatch(updateForm(form));
5758
- throw e;
5759
- }
5760
- }
5761
5706
  async delete(formId) {
5762
5707
  const { store } = this.client;
5763
5708
  const state = store.getState();
@@ -6218,13 +6163,19 @@ class FormSubmissionService extends BaseUploadService {
6218
6163
  }
6219
6164
  }
6220
6165
  class WorkspaceService extends BaseApiService {
6221
- add(workspace) {
6222
- const offlineWorkspace = offline(workspace);
6166
+ add(payload) {
6167
+ const { store } = this.client;
6168
+ const createdBy = store.getState().userReducer.currentUser.id;
6169
+ const offlineWorkspace = offline({
6170
+ ...payload,
6171
+ submitted_at: (/* @__PURE__ */ new Date()).toISOString(),
6172
+ created_by: createdBy
6173
+ });
6223
6174
  this.dispatch(addWorkspace(offlineWorkspace));
6224
6175
  const promise = this.enqueueRequest({
6225
6176
  description: "Create Workspace",
6226
6177
  method: HttpMethod.POST,
6227
- url: `/projects/${workspace.project}/workspaces/`,
6178
+ url: `/projects/${payload.project}/workspaces/`,
6228
6179
  payload: offlineWorkspace,
6229
6180
  blockers: ["add-workspace"],
6230
6181
  blocks: [offlineWorkspace.offline_id]
@@ -6641,9 +6592,7 @@ class LicenseService extends BaseApiService {
6641
6592
  method: HttpMethod.GET,
6642
6593
  url: `/billing/${license.offline_id}/`,
6643
6594
  isAuthNeeded: true,
6644
- blockers: [
6645
- license.organization_owner ? license.organization_owner.toString() : license.user_owner ? license.user_owner.toString() : ""
6646
- ],
6595
+ blockers: [license.organization_owner ? license.organization_owner.toString() : ""],
6647
6596
  blocks: []
6648
6597
  });
6649
6598
  this.dispatch(updateLicense(result));
@@ -6655,9 +6604,7 @@ class LicenseService extends BaseApiService {
6655
6604
  method: HttpMethod.DELETE,
6656
6605
  url: `/billing/${license.offline_id}/suspend/`,
6657
6606
  isAuthNeeded: true,
6658
- blockers: [
6659
- license.organization_owner ? license.organization_owner.toString() : license.user_owner ? license.user_owner.toString() : ""
6660
- ],
6607
+ blockers: [license.organization_owner ? license.organization_owner.toString() : ""],
6661
6608
  blocks: []
6662
6609
  });
6663
6610
  this.dispatch(updateLicense(result));
@@ -6669,9 +6616,7 @@ class LicenseService extends BaseApiService {
6669
6616
  method: HttpMethod.PATCH,
6670
6617
  url: `/billing/${license.offline_id}/suspend/`,
6671
6618
  isAuthNeeded: true,
6672
- blockers: [
6673
- license.organization_owner ? license.organization_owner.toString() : license.user_owner ? license.user_owner.toString() : ""
6674
- ],
6619
+ blockers: [license.organization_owner ? license.organization_owner.toString() : ""],
6675
6620
  blocks: []
6676
6621
  });
6677
6622
  this.dispatch(updateLicense(result));
@@ -6683,9 +6628,7 @@ class LicenseService extends BaseApiService {
6683
6628
  method: HttpMethod.DELETE,
6684
6629
  url: `/billing/${license.offline_id}/`,
6685
6630
  isAuthNeeded: true,
6686
- blockers: [
6687
- license.organization_owner ? license.organization_owner.toString() : license.user_owner ? license.user_owner.toString() : ""
6688
- ],
6631
+ blockers: [license.organization_owner ? license.organization_owner.toString() : ""],
6689
6632
  blocks: []
6690
6633
  });
6691
6634
  this.dispatch(updateLicense(result));
@@ -6699,7 +6642,7 @@ class LicenseService extends BaseApiService {
6699
6642
  isAuthNeeded: true,
6700
6643
  payload: { project: project.id },
6701
6644
  blockers: [
6702
- license.organization_owner ? license.organization_owner.toString() : license.user_owner ? license.user_owner.toString() : "",
6645
+ license.organization_owner ? license.organization_owner.toString() : "",
6703
6646
  project.id ? project.id.toString() : ""
6704
6647
  ],
6705
6648
  blocks: ["add-issue", "add-form-entry", "change-access-level", "add-workspace"]
@@ -6713,9 +6656,7 @@ class LicenseService extends BaseApiService {
6713
6656
  method: HttpMethod.DELETE,
6714
6657
  url: `/billing/${license.offline_id}/project/`,
6715
6658
  isAuthNeeded: true,
6716
- blockers: [
6717
- license.organization_owner ? license.organization_owner.toString() : license.user_owner ? license.user_owner.toString() : ""
6718
- ],
6659
+ blockers: [license.organization_owner ? license.organization_owner.toString() : ""],
6719
6660
  blocks: ["add-issue", "add-form-entry", "change-access-level", "add-workspace"]
6720
6661
  });
6721
6662
  this.dispatch(updateLicense(result));
@@ -7637,6 +7578,7 @@ export {
7637
7578
  authReducer,
7638
7579
  authSlice,
7639
7580
  blobToBase64,
7581
+ boundsContainPoint,
7640
7582
  categoryReducer,
7641
7583
  categorySlice,
7642
7584
  classNames,
@@ -7644,6 +7586,9 @@ export {
7644
7586
  clearTokens,
7645
7587
  constructUploadedFilePayloads,
7646
7588
  coordinatesAreEqual,
7589
+ coordinatesToLiteral,
7590
+ coordinatesToText,
7591
+ coordinatesToUrlText,
7647
7592
  createMultiPointGeometry,
7648
7593
  createOfflineAction,
7649
7594
  createPointGeometry,
@@ -7706,6 +7651,8 @@ export {
7706
7651
  fileReducer,
7707
7652
  fileSlice,
7708
7653
  fileToBlob,
7654
+ flipBounds,
7655
+ flipCoordinates,
7709
7656
  formReducer,
7710
7657
  formRevisionAttachmentReducer,
7711
7658
  formRevisionAttachmentSlice,
@@ -7772,14 +7719,18 @@ export {
7772
7719
  issueUpdateSlice,
7773
7720
  licenseReducer,
7774
7721
  licenseSlice,
7722
+ literalToCoordinates,
7775
7723
  logOnlyOnce,
7776
7724
  markAsDeleted,
7777
7725
  markForDeletion,
7778
7726
  memoize,
7779
7727
  moveDocument,
7780
7728
  offline,
7729
+ offsetPositionByMeters,
7781
7730
  onlyUniqueHashes,
7782
7731
  onlyUniqueOfflineIds,
7732
+ openCoordsInGoogleMaps,
7733
+ openDirectionsInGoogleMaps,
7783
7734
  organizationAccessReducer,
7784
7735
  organizationAccessSlice,
7785
7736
  organizationReducer,
@@ -8094,6 +8045,7 @@ export {
8094
8045
  versioningSlice,
8095
8046
  warningColor,
8096
8047
  workspaceReducer,
8097
- workspaceSlice
8048
+ workspaceSlice,
8049
+ worldBounds
8098
8050
  };
8099
8051
  //# sourceMappingURL=overmap-core.js.map