@overmap-ai/core 1.0.25 → 1.0.26

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.
@@ -605,15 +605,15 @@ var __publicField = (obj, key, value) => {
605
605
  };
606
606
  const migrations = [initialVersioning, signOut, signOut, createOutboxState];
607
607
  const manifest = Object.fromEntries(migrations.map((migration2, i) => [i, wrapMigration(migration2)]));
608
- const initialState$k = {
608
+ const initialState$l = {
609
609
  accessToken: "",
610
610
  refreshToken: "",
611
611
  isLoggedIn: false
612
612
  };
613
613
  const authSlice = toolkit.createSlice({
614
614
  name: "auth",
615
- initialState: initialState$k,
616
- extraReducers: (builder) => builder.addCase("RESET", (state) => Object.assign(state, initialState$k)),
615
+ initialState: initialState$l,
616
+ extraReducers: (builder) => builder.addCase("RESET", (state) => Object.assign(state, initialState$l)),
617
617
  reducers: {
618
618
  setTokens: (state, action) => {
619
619
  state.accessToken = action.payload.accessToken;
@@ -1316,7 +1316,7 @@ var __publicField = (obj, key, value) => {
1316
1316
  return getLocalDateString(date);
1317
1317
  return relative.format(days, "days");
1318
1318
  });
1319
- const initialState$j = {
1319
+ const initialState$k = {
1320
1320
  categories: {},
1321
1321
  usedCategoryColors: [],
1322
1322
  categoryVisibility: {
@@ -1326,8 +1326,8 @@ var __publicField = (obj, key, value) => {
1326
1326
  };
1327
1327
  const categorySlice = toolkit.createSlice({
1328
1328
  name: "categories",
1329
- initialState: initialState$j,
1330
- extraReducers: (builder) => builder.addCase("RESET", (state) => Object.assign(state, initialState$j)),
1329
+ initialState: initialState$k,
1330
+ extraReducers: (builder) => builder.addCase("RESET", (state) => Object.assign(state, initialState$k)),
1331
1331
  reducers: {
1332
1332
  setCategories: (state, action) => {
1333
1333
  if (!Array.isArray(action.payload))
@@ -1460,13 +1460,13 @@ var __publicField = (obj, key, value) => {
1460
1460
  return hiddenCategoryCount;
1461
1461
  };
1462
1462
  const categoryReducer = categorySlice.reducer;
1463
- const initialState$i = {
1463
+ const initialState$j = {
1464
1464
  components: {}
1465
1465
  };
1466
1466
  const componentSlice = toolkit.createSlice({
1467
1467
  name: "components",
1468
- initialState: initialState$i,
1469
- extraReducers: (builder) => builder.addCase("RESET", (state) => Object.assign(state, initialState$i)),
1468
+ initialState: initialState$j,
1469
+ extraReducers: (builder) => builder.addCase("RESET", (state) => Object.assign(state, initialState$j)),
1470
1470
  reducers: {
1471
1471
  addComponent: (state, action) => {
1472
1472
  state.components[action.payload.offline_id] = action.payload;
@@ -1578,13 +1578,13 @@ var __publicField = (obj, key, value) => {
1578
1578
  removeAllComponentsOfType
1579
1579
  } = componentSlice.actions;
1580
1580
  const componentReducer = componentSlice.reducer;
1581
- const initialState$h = {
1581
+ const initialState$i = {
1582
1582
  completionsByComponentId: {}
1583
1583
  };
1584
1584
  const componentStageCompletionSlice = toolkit.createSlice({
1585
1585
  name: "componentStageCompletions",
1586
- initialState: initialState$h,
1587
- extraReducers: (builder) => builder.addCase("RESET", (state) => Object.assign(state, initialState$h)),
1586
+ initialState: initialState$i,
1587
+ extraReducers: (builder) => builder.addCase("RESET", (state) => Object.assign(state, initialState$i)),
1588
1588
  reducers: {
1589
1589
  addStageCompletion: (state, action) => {
1590
1590
  let stageToCompletionDateMapping = state.completionsByComponentId[action.payload.component];
@@ -1635,13 +1635,13 @@ var __publicField = (obj, key, value) => {
1635
1635
  return Object.keys(state.componentStageCompletionReducer.completionsByComponentId[component.offline_id] ?? {});
1636
1636
  };
1637
1637
  const componentStageCompletionReducer = componentStageCompletionSlice.reducer;
1638
- const initialState$g = {
1638
+ const initialState$h = {
1639
1639
  stages: {}
1640
1640
  };
1641
1641
  const componentStageSlice = toolkit.createSlice({
1642
1642
  name: "componentStages",
1643
- initialState: initialState$g,
1644
- extraReducers: (builder) => builder.addCase("RESET", (state) => Object.assign(state, initialState$g)),
1643
+ initialState: initialState$h,
1644
+ extraReducers: (builder) => builder.addCase("RESET", (state) => Object.assign(state, initialState$h)),
1645
1645
  reducers: {
1646
1646
  addStages: (state, action) => {
1647
1647
  Object.assign(state.stages, toOfflineIdRecord(action.payload));
@@ -1701,14 +1701,14 @@ var __publicField = (obj, key, value) => {
1701
1701
  );
1702
1702
  const { addStages, updateStages, removeStages } = componentStageSlice.actions;
1703
1703
  const componentStageReducer = componentStageSlice.reducer;
1704
- const initialState$f = {
1704
+ const initialState$g = {
1705
1705
  componentTypes: {},
1706
1706
  hiddenComponentTypeIds: {}
1707
1707
  };
1708
1708
  const componentTypeSlice = toolkit.createSlice({
1709
1709
  name: "componentTypes",
1710
- initialState: initialState$f,
1711
- extraReducers: (builder) => builder.addCase("RESET", (state) => Object.assign(state, initialState$f)),
1710
+ initialState: initialState$g,
1711
+ extraReducers: (builder) => builder.addCase("RESET", (state) => Object.assign(state, initialState$g)),
1712
1712
  reducers: {
1713
1713
  addComponentType: (state, action) => {
1714
1714
  state.componentTypes[action.payload.offline_id] = action.payload;
@@ -1767,13 +1767,13 @@ var __publicField = (obj, key, value) => {
1767
1767
  const selectHiddenComponentTypeIds = (state) => state.componentTypeReducer.hiddenComponentTypeIds;
1768
1768
  const { addComponentType, setComponentTypes, toggleComponentTypeVisibility, deleteComponentType } = componentTypeSlice.actions;
1769
1769
  const componentTypeReducer = componentTypeSlice.reducer;
1770
- const initialState$e = {
1770
+ const initialState$f = {
1771
1771
  workspaces: {},
1772
1772
  activeWorkspaceId: null
1773
1773
  };
1774
1774
  const workspaceSlice = toolkit.createSlice({
1775
1775
  name: "workspace",
1776
- initialState: initialState$e,
1776
+ initialState: initialState$f,
1777
1777
  // The `reducers` field lets us define reducers and generate associated actions
1778
1778
  reducers: {
1779
1779
  setWorkspaces: (state, action) => {
@@ -1830,7 +1830,7 @@ var __publicField = (obj, key, value) => {
1830
1830
  );
1831
1831
  const workspaceReducer = workspaceSlice.reducer;
1832
1832
  const maxRecentIssues = 10;
1833
- const initialState$d = {
1833
+ const initialState$e = {
1834
1834
  issues: {},
1835
1835
  attachments: {},
1836
1836
  comments: {},
@@ -1842,9 +1842,9 @@ var __publicField = (obj, key, value) => {
1842
1842
  };
1843
1843
  const issueSlice = toolkit.createSlice({
1844
1844
  name: "issues",
1845
- initialState: initialState$d,
1845
+ initialState: initialState$e,
1846
1846
  extraReducers: (builder) => builder.addCase("RESET", (state) => {
1847
- Object.assign(state, initialState$d);
1847
+ Object.assign(state, initialState$e);
1848
1848
  }),
1849
1849
  reducers: {
1850
1850
  setIssues: (state, action) => {
@@ -2175,15 +2175,15 @@ var __publicField = (obj, key, value) => {
2175
2175
  }
2176
2176
  );
2177
2177
  const issueReducer = issueSlice.reducer;
2178
- const initialState$c = {
2178
+ const initialState$d = {
2179
2179
  s3Urls: {}
2180
2180
  };
2181
2181
  const msPerHour = 1e3 * 60 * 60;
2182
2182
  const msPerWeek = msPerHour * 24 * 7;
2183
2183
  const fileSlice = toolkit.createSlice({
2184
2184
  name: "file",
2185
- initialState: initialState$c,
2186
- extraReducers: (builder) => builder.addCase("RESET", (state) => Object.assign(state, initialState$c)),
2185
+ initialState: initialState$d,
2186
+ extraReducers: (builder) => builder.addCase("RESET", (state) => Object.assign(state, initialState$d)),
2187
2187
  reducers: {
2188
2188
  setUploadUrl: (state, action) => {
2189
2189
  const { url, fields, sha1 } = action.payload;
@@ -2210,7 +2210,7 @@ var __publicField = (obj, key, value) => {
2210
2210
  return url;
2211
2211
  };
2212
2212
  const fileReducer = fileSlice.reducer;
2213
- const initialState$b = {
2213
+ const initialState$c = {
2214
2214
  // TODO: Change first MapStyle.SATELLITE to MaptStyle.None when project creation map is fixed
2215
2215
  mapStyle: MapStyle.SATELLITE,
2216
2216
  showTooltips: false,
@@ -2218,8 +2218,8 @@ var __publicField = (obj, key, value) => {
2218
2218
  };
2219
2219
  const mapSlice = toolkit.createSlice({
2220
2220
  name: "map",
2221
- initialState: initialState$b,
2222
- extraReducers: (builder) => builder.addCase("RESET", (state) => Object.assign(state, initialState$b)),
2221
+ initialState: initialState$c,
2222
+ extraReducers: (builder) => builder.addCase("RESET", (state) => Object.assign(state, initialState$c)),
2223
2223
  reducers: {
2224
2224
  setMapStyle: (state, action) => {
2225
2225
  state.mapStyle = action.payload;
@@ -2237,26 +2237,209 @@ var __publicField = (obj, key, value) => {
2237
2237
  const selectShowTooltips = (state) => state.mapReducer.showTooltips;
2238
2238
  const selectCenterMapToProject = (state) => state.mapReducer.centerMapToProject;
2239
2239
  const mapReducer = mapSlice.reducer;
2240
+ var ProjectAccessLevel = /* @__PURE__ */ ((ProjectAccessLevel2) => {
2241
+ ProjectAccessLevel2[ProjectAccessLevel2["BASIC"] = 0] = "BASIC";
2242
+ ProjectAccessLevel2[ProjectAccessLevel2["ADMIN"] = 2] = "ADMIN";
2243
+ return ProjectAccessLevel2;
2244
+ })(ProjectAccessLevel || {});
2245
+ var OrganizationAccessLevel = /* @__PURE__ */ ((OrganizationAccessLevel2) => {
2246
+ OrganizationAccessLevel2[OrganizationAccessLevel2["BASIC"] = 0] = "BASIC";
2247
+ OrganizationAccessLevel2[OrganizationAccessLevel2["ADMIN"] = 2] = "ADMIN";
2248
+ return OrganizationAccessLevel2;
2249
+ })(OrganizationAccessLevel || {});
2250
+ var ProjectType = /* @__PURE__ */ ((ProjectType2) => {
2251
+ ProjectType2[ProjectType2["PERSONAL"] = 0] = "PERSONAL";
2252
+ ProjectType2[ProjectType2["ORGANIZATION"] = 2] = "ORGANIZATION";
2253
+ return ProjectType2;
2254
+ })(ProjectType || {});
2255
+ var VerificationCodeType = /* @__PURE__ */ ((VerificationCodeType2) => {
2256
+ VerificationCodeType2[VerificationCodeType2["USER_REGISTRATION"] = 0] = "USER_REGISTRATION";
2257
+ VerificationCodeType2[VerificationCodeType2["APPLICATION_INVITE"] = 2] = "APPLICATION_INVITE";
2258
+ VerificationCodeType2[VerificationCodeType2["PROJECT_INVITE"] = 4] = "PROJECT_INVITE";
2259
+ VerificationCodeType2[VerificationCodeType2["ORGANIZATION_INVITE"] = 6] = "ORGANIZATION_INVITE";
2260
+ VerificationCodeType2[VerificationCodeType2["ADD_EMAIL_DOMAIN"] = 8] = "ADD_EMAIL_DOMAIN";
2261
+ VerificationCodeType2[VerificationCodeType2["RESET_PASSWORD"] = 10] = "RESET_PASSWORD";
2262
+ return VerificationCodeType2;
2263
+ })(VerificationCodeType || {});
2264
+ const initialState$b = {
2265
+ users: {},
2266
+ currentUser: {
2267
+ id: 0,
2268
+ username: "",
2269
+ email: "",
2270
+ profile: { file: null, file_sha1: null, favourite_project_ids: [], tour_step: -1 }
2271
+ }
2272
+ };
2273
+ const userSlice = toolkit.createSlice({
2274
+ name: "users",
2275
+ initialState: initialState$b,
2276
+ extraReducers: (builder) => builder.addCase("RESET", (state) => Object.assign(state, initialState$b)),
2277
+ reducers: {
2278
+ setUsers: (state, action) => {
2279
+ const usersMapping = {};
2280
+ action.payload.forEach((user) => {
2281
+ usersMapping[user.id] = user;
2282
+ });
2283
+ state.users = usersMapping;
2284
+ },
2285
+ addUsers: (state, action) => {
2286
+ for (const user of action.payload) {
2287
+ state.users[user.id] = user;
2288
+ }
2289
+ },
2290
+ setCurrentUser: (state, action) => {
2291
+ state.currentUser = action.payload;
2292
+ },
2293
+ setProfilePicture: (state, action) => {
2294
+ state.currentUser.profile.file = action.payload.file ?? null;
2295
+ state.currentUser.profile.file_sha1 = action.payload.file_sha1 ?? null;
2296
+ const currentUser = state.users[state.currentUser.id];
2297
+ if (!currentUser) {
2298
+ throw new Error("Unable to find current user in users slice");
2299
+ }
2300
+ currentUser.profile.file = action.payload.file ?? null;
2301
+ currentUser.profile.file_sha1 = action.payload.file_sha1 ?? null;
2302
+ },
2303
+ addFavouriteProjectId: (state, action) => {
2304
+ state.currentUser.profile.favourite_project_ids.push(action.payload);
2305
+ },
2306
+ removeFavouriteProjectId: (state, action) => {
2307
+ state.currentUser.profile.favourite_project_ids = state.currentUser.profile.favourite_project_ids.filter(
2308
+ (id) => id !== action.payload
2309
+ );
2310
+ },
2311
+ setTourStep: (state, action) => {
2312
+ state.currentUser.profile.tour_step = action.payload;
2313
+ },
2314
+ removeUser: (state, action) => {
2315
+ delete state.users[action.payload];
2316
+ }
2317
+ }
2318
+ });
2319
+ const {
2320
+ setCurrentUser,
2321
+ setProfilePicture,
2322
+ setUsers,
2323
+ addUsers,
2324
+ addFavouriteProjectId,
2325
+ removeFavouriteProjectId,
2326
+ setTourStep,
2327
+ removeUser
2328
+ } = userSlice.actions;
2329
+ const selectCurrentUser = (state) => state.userReducer.currentUser;
2330
+ const selectUser = (userId) => (state) => {
2331
+ if (userId === null)
2332
+ return void 0;
2333
+ return state.userReducer.users[userId];
2334
+ };
2335
+ const selectUsersAsMapping = (state) => state.userReducer.users;
2336
+ const selectFavouriteProjects = (state) => state.userReducer.currentUser.profile.favourite_project_ids;
2337
+ const userReducer = userSlice.reducer;
2240
2338
  const initialState$a = {
2339
+ organizationAccesses: {},
2340
+ activeOrganizationAccessId: null
2341
+ };
2342
+ const organizationAccessSlice = toolkit.createSlice({
2343
+ name: "organizationAccess",
2344
+ initialState: initialState$a,
2345
+ extraReducers: (builder) => builder.addCase("RESET", (state) => Object.assign(state, initialState$a)),
2346
+ reducers: {
2347
+ setOrganizationAccesses: (state, action) => {
2348
+ if (!Array.isArray(action.payload))
2349
+ throw new Error("Expected an array of OrganizationAccess");
2350
+ if (action.payload.filter(onlyUniqueOfflineIds).length !== action.payload.length) {
2351
+ throw new Error("Tried to use setOrganizationAccesses reducer with duplicate ID's");
2352
+ }
2353
+ const organizationAccesses = {};
2354
+ for (const organizationAccess of action.payload) {
2355
+ organizationAccesses[organizationAccess.offline_id] = organizationAccess;
2356
+ }
2357
+ state.organizationAccesses = organizationAccesses;
2358
+ },
2359
+ updateOrganizationAccess: (state, action) => {
2360
+ if (action.payload.offline_id in state.organizationAccesses) {
2361
+ state.organizationAccesses[action.payload.offline_id] = action.payload;
2362
+ } else {
2363
+ throw new Error(
2364
+ `Tried to update organization access with ID that doesn't exist: ${action.payload.offline_id}`
2365
+ );
2366
+ }
2367
+ },
2368
+ removeOrganizationAccess: (state, action) => {
2369
+ if (action.payload.offline_id in state.organizationAccesses) {
2370
+ delete state.organizationAccesses[action.payload.offline_id];
2371
+ } else {
2372
+ throw new Error(
2373
+ `Tried to remove organization access with ID that doesn't exist: ${action.payload.offline_id}`
2374
+ );
2375
+ }
2376
+ },
2377
+ setActiveOrganizationAccessId: (state, action) => {
2378
+ state.activeOrganizationAccessId = action.payload;
2379
+ }
2380
+ }
2381
+ });
2382
+ const {
2383
+ setOrganizationAccesses,
2384
+ updateOrganizationAccess,
2385
+ removeOrganizationAccess,
2386
+ setActiveOrganizationAccessId
2387
+ } = organizationAccessSlice.actions;
2388
+ const selectOrganizationAccesses = (state) => {
2389
+ return state.organizationAccessReducer.organizationAccesses;
2390
+ };
2391
+ const selectOrganizationAccess = (organizationAccessId) => (state) => {
2392
+ return state.organizationAccessReducer.organizationAccesses[organizationAccessId];
2393
+ };
2394
+ const selectActiveOrganizationAccess = (state) => {
2395
+ const activeOrganizationAccessId = state.organizationAccessReducer.activeOrganizationAccessId;
2396
+ if (!activeOrganizationAccessId) {
2397
+ return null;
2398
+ }
2399
+ return state.organizationAccessReducer.organizationAccesses[activeOrganizationAccessId] ?? null;
2400
+ };
2401
+ const selectOrganizationAccessForUser = (user) => (state) => {
2402
+ return Object.values(state.organizationAccessReducer.organizationAccesses).find(
2403
+ (organizationAccess) => organizationAccess.user === user.id
2404
+ );
2405
+ };
2406
+ const selectOrganizationAccessUserMapping = (state) => {
2407
+ const organizationAccesses = {};
2408
+ for (const organizationAccess of Object.values(state.organizationAccessReducer.organizationAccesses)) {
2409
+ organizationAccesses[organizationAccess.user] = organizationAccess;
2410
+ }
2411
+ return organizationAccesses;
2412
+ };
2413
+ const organizationAccessReducer = organizationAccessSlice.reducer;
2414
+ const initialState$9 = {
2241
2415
  organizations: {},
2242
2416
  activeOrganizationId: null
2243
2417
  };
2244
2418
  const organizationSlice = toolkit.createSlice({
2245
2419
  name: "organizations",
2246
- initialState: initialState$a,
2247
- extraReducers: (builder) => builder.addCase("RESET", (state) => Object.assign(state, initialState$a)),
2420
+ initialState: initialState$9,
2421
+ extraReducers: (builder) => builder.addCase("RESET", (state) => Object.assign(state, initialState$9)),
2248
2422
  reducers: {
2249
2423
  setOrganizations: (state, action) => {
2250
2424
  for (const org of action.payload) {
2251
2425
  state.organizations[org.id] = org;
2252
2426
  }
2253
2427
  },
2428
+ updateActiveOrganization: (state, action) => {
2429
+ if (!state.activeOrganizationId) {
2430
+ throw new Error("Cannot update name of active organization. Active organization ID does not exist");
2431
+ }
2432
+ if (state.activeOrganizationId !== action.payload.id) {
2433
+ throw new Error("Tried updating active organization with different organization");
2434
+ }
2435
+ state.organizations[state.activeOrganizationId] = action.payload;
2436
+ },
2254
2437
  setActiveOrganizationId: (state, action) => {
2255
2438
  state.activeOrganizationId = action.payload;
2256
2439
  }
2257
2440
  }
2258
2441
  });
2259
- const { setOrganizations, setActiveOrganizationId } = organizationSlice.actions;
2442
+ const { setOrganizations, setActiveOrganizationId, updateActiveOrganization } = organizationSlice.actions;
2260
2443
  const selectActiveOrganizationId = (state) => {
2261
2444
  return state.organizationReducer.activeOrganizationId;
2262
2445
  };
@@ -2274,6 +2457,35 @@ var __publicField = (obj, key, value) => {
2274
2457
  }
2275
2458
  return organization;
2276
2459
  };
2460
+ const selectOrganizationUsersIds = toolkit.createSelector(
2461
+ [selectOrganizationAccesses],
2462
+ (organizationAccesses) => Object.values(organizationAccesses).map((organizationAccess) => organizationAccess.user)
2463
+ );
2464
+ const selectOrganizationUsersAsMapping = toolkit.createSelector(
2465
+ [selectOrganizationUsersIds, selectUsersAsMapping],
2466
+ (organizationUserIds, users) => organizationUserIds.reduce((accum, userId) => ({ ...accum, [userId]: users[userId] }), {})
2467
+ );
2468
+ const selectSortedOrganizationUsers = toolkit.createSelector(
2469
+ [selectCurrentUser, selectOrganizationUsersAsMapping, selectOrganizationAccessUserMapping],
2470
+ (currentUser, userMapping, organizationAccessMapping) => {
2471
+ return Object.values(userMapping).sort((userA, userB) => {
2472
+ if (userA.id === currentUser.id) {
2473
+ return -1;
2474
+ } else if (userB.id === currentUser.id) {
2475
+ return 1;
2476
+ }
2477
+ const organizationAccessesA = organizationAccessMapping[userA.id];
2478
+ const organizationAccessesB = organizationAccessMapping[userB.id];
2479
+ if ((organizationAccessesA == null ? void 0 : organizationAccessesA.access_level) === (organizationAccessesB == null ? void 0 : organizationAccessesB.access_level)) {
2480
+ return userA.username.localeCompare(userB.username);
2481
+ }
2482
+ if ((organizationAccessesA == null ? void 0 : organizationAccessesA.access_level) === OrganizationAccessLevel.ADMIN) {
2483
+ return -1;
2484
+ }
2485
+ return 1;
2486
+ });
2487
+ }
2488
+ );
2277
2489
  const selectOrganization = (id) => (state) => {
2278
2490
  return state.organizationReducer.organizations[id];
2279
2491
  };
@@ -2294,14 +2506,14 @@ var __publicField = (obj, key, value) => {
2294
2506
  }
2295
2507
  };
2296
2508
  };
2297
- const initialState$9 = {
2509
+ const initialState$8 = {
2298
2510
  deletedRequests: [],
2299
2511
  latestRetryTime: 0
2300
2512
  };
2301
2513
  const outboxSlice = toolkit.createSlice({
2302
2514
  name: "outbox",
2303
- initialState: initialState$9,
2304
- extraReducers: (builder) => builder.addCase("RESET", (state) => Object.assign(state, initialState$9)),
2515
+ initialState: initialState$8,
2516
+ extraReducers: (builder) => builder.addCase("RESET", (state) => Object.assign(state, initialState$8)),
2305
2517
  reducers: {
2306
2518
  // enqueueActions is a reducer that does nothing but enqueue API request to the Redux Offline outbox
2307
2519
  // Whenever an issue is being created, a reducer addIssue() is responsible for adding it to the offline store
@@ -2333,13 +2545,13 @@ var __publicField = (obj, key, value) => {
2333
2545
  const selectLatestRetryTime = (state) => state.outboxReducer.latestRetryTime;
2334
2546
  const { enqueueRequest, markForDeletion, markAsDeleted, _setLatestRetryTime } = outboxSlice.actions;
2335
2547
  const outboxReducer = outboxSlice.reducer;
2336
- const initialState$8 = {
2548
+ const initialState$7 = {
2337
2549
  projectAccesses: {}
2338
2550
  };
2339
2551
  const projectAccessSlice = toolkit.createSlice({
2340
2552
  name: "projectAccess",
2341
- initialState: initialState$8,
2342
- extraReducers: (builder) => builder.addCase("RESET", (state) => Object.assign(state, initialState$8)),
2553
+ initialState: initialState$7,
2554
+ extraReducers: (builder) => builder.addCase("RESET", (state) => Object.assign(state, initialState$7)),
2343
2555
  reducers: {
2344
2556
  setProjectAccesses: (state, action) => {
2345
2557
  if (!Array.isArray(action.payload))
@@ -2407,31 +2619,7 @@ var __publicField = (obj, key, value) => {
2407
2619
  return projectAccesses;
2408
2620
  };
2409
2621
  const projectAccessReducer = projectAccessSlice.reducer;
2410
- var ProjectAccessLevel = /* @__PURE__ */ ((ProjectAccessLevel2) => {
2411
- ProjectAccessLevel2[ProjectAccessLevel2["BASIC"] = 0] = "BASIC";
2412
- ProjectAccessLevel2[ProjectAccessLevel2["ADMIN"] = 2] = "ADMIN";
2413
- return ProjectAccessLevel2;
2414
- })(ProjectAccessLevel || {});
2415
- var OrganizationAccessLevel = /* @__PURE__ */ ((OrganizationAccessLevel2) => {
2416
- OrganizationAccessLevel2[OrganizationAccessLevel2["BASIC"] = 0] = "BASIC";
2417
- OrganizationAccessLevel2[OrganizationAccessLevel2["ADMIN"] = 2] = "ADMIN";
2418
- return OrganizationAccessLevel2;
2419
- })(OrganizationAccessLevel || {});
2420
- var ProjectType = /* @__PURE__ */ ((ProjectType2) => {
2421
- ProjectType2[ProjectType2["PERSONAL"] = 0] = "PERSONAL";
2422
- ProjectType2[ProjectType2["ORGANIZATION"] = 2] = "ORGANIZATION";
2423
- return ProjectType2;
2424
- })(ProjectType || {});
2425
- var VerificationCodeType = /* @__PURE__ */ ((VerificationCodeType2) => {
2426
- VerificationCodeType2[VerificationCodeType2["USER_REGISTRATION"] = 0] = "USER_REGISTRATION";
2427
- VerificationCodeType2[VerificationCodeType2["APPLICATION_INVITE"] = 2] = "APPLICATION_INVITE";
2428
- VerificationCodeType2[VerificationCodeType2["PROJECT_INVITE"] = 4] = "PROJECT_INVITE";
2429
- VerificationCodeType2[VerificationCodeType2["ORGANIZATION_INVITE"] = 6] = "ORGANIZATION_INVITE";
2430
- VerificationCodeType2[VerificationCodeType2["ADD_EMAIL_DOMAIN"] = 8] = "ADD_EMAIL_DOMAIN";
2431
- VerificationCodeType2[VerificationCodeType2["RESET_PASSWORD"] = 10] = "RESET_PASSWORD";
2432
- return VerificationCodeType2;
2433
- })(VerificationCodeType || {});
2434
- const initialState$7 = {
2622
+ const initialState$6 = {
2435
2623
  projects: {},
2436
2624
  activeProjectId: null,
2437
2625
  recentProjectIds: [],
@@ -2440,7 +2628,7 @@ var __publicField = (obj, key, value) => {
2440
2628
  };
2441
2629
  const projectSlice = toolkit.createSlice({
2442
2630
  name: "projects",
2443
- initialState: initialState$7,
2631
+ initialState: initialState$6,
2444
2632
  reducers: {
2445
2633
  setProjects: (state, action) => {
2446
2634
  const projectsMap = {};
@@ -2497,14 +2685,43 @@ var __publicField = (obj, key, value) => {
2497
2685
  if (!activeProjectId) {
2498
2686
  return null;
2499
2687
  }
2500
- return state.projectReducer.projects[activeProjectId] ?? null;
2501
- };
2502
- const selectRecentProjects = (state) => {
2503
- return state.projectReducer.recentProjectIds;
2504
- };
2505
- const selectCreateProjectType = (state) => state.projectReducer.createProjectType;
2506
- const projectReducer = projectSlice.reducer;
2507
- const initialState$6 = {
2688
+ return state.projectReducer.projects[activeProjectId] ?? null;
2689
+ };
2690
+ const selectRecentProjects = (state) => {
2691
+ return state.projectReducer.recentProjectIds;
2692
+ };
2693
+ const selectCreateProjectType = (state) => state.projectReducer.createProjectType;
2694
+ const projectReducer = projectSlice.reducer;
2695
+ const selectProjectUsersIds = toolkit.createSelector(
2696
+ [selectProjectAccesses],
2697
+ (projectAccesses) => Object.values(projectAccesses).map((projectAccess) => projectAccess.user)
2698
+ );
2699
+ const selectProjectUsersAsMapping = toolkit.createSelector(
2700
+ [selectProjectUsersIds, selectUsersAsMapping],
2701
+ (projectUserIds, users) => projectUserIds.reduce((accum, userId) => ({ ...accum, [userId]: users[userId] }), {})
2702
+ );
2703
+ const selectSortedProjectUsers = toolkit.createSelector(
2704
+ [selectCurrentUser, selectProjectUsersAsMapping, selectProjectAccessUserMapping],
2705
+ (currentUser, userMapping, projectAccessMapping) => {
2706
+ return Object.values(userMapping).sort((userA, userB) => {
2707
+ if (userA.id === currentUser.id) {
2708
+ return -1;
2709
+ } else if (userB.id === currentUser.id) {
2710
+ return 1;
2711
+ }
2712
+ const projectAccessesA = projectAccessMapping[userA.id];
2713
+ const projectAccessesB = projectAccessMapping[userB.id];
2714
+ if ((projectAccessesA == null ? void 0 : projectAccessesA.access_level) === (projectAccessesB == null ? void 0 : projectAccessesB.access_level)) {
2715
+ return userA.username.localeCompare(userB.username);
2716
+ }
2717
+ if ((projectAccessesA == null ? void 0 : projectAccessesA.access_level) === ProjectAccessLevel.ADMIN) {
2718
+ return -1;
2719
+ }
2720
+ return 1;
2721
+ });
2722
+ }
2723
+ );
2724
+ const initialState$5 = {
2508
2725
  projectFiles: {},
2509
2726
  activeProjectFileId: null,
2510
2727
  isImportingProjectFile: false,
@@ -2512,8 +2729,8 @@ var __publicField = (obj, key, value) => {
2512
2729
  };
2513
2730
  const projectFileSlice = toolkit.createSlice({
2514
2731
  name: "projectFiles",
2515
- initialState: initialState$6,
2516
- extraReducers: (builder) => builder.addCase("RESET", (state) => Object.assign(state, initialState$6)),
2732
+ initialState: initialState$5,
2733
+ extraReducers: (builder) => builder.addCase("RESET", (state) => Object.assign(state, initialState$5)),
2517
2734
  reducers: {
2518
2735
  addOrReplaceProjectFiles: (state, action) => {
2519
2736
  for (let fileObj of action.payload) {
@@ -2614,12 +2831,12 @@ var __publicField = (obj, key, value) => {
2614
2831
  const selectActiveProjectFileId = (state) => state.projectFileReducer.activeProjectFileId;
2615
2832
  const selectIsImportingProjectFile = (state) => state.projectFileReducer.isImportingProjectFile;
2616
2833
  const projectFileReducer = projectFileSlice.reducer;
2617
- const initialState$5 = {
2834
+ const initialState$4 = {
2618
2835
  isRehydrated: false
2619
2836
  };
2620
2837
  const rehydratedSlice = toolkit.createSlice({
2621
2838
  name: "rehydrated",
2622
- initialState: initialState$5,
2839
+ initialState: initialState$4,
2623
2840
  // The `reducers` field lets us define reducers and generate associated actions
2624
2841
  reducers: {
2625
2842
  setRehydrated: (state, action) => {
@@ -2629,7 +2846,7 @@ var __publicField = (obj, key, value) => {
2629
2846
  });
2630
2847
  const selectRehydrated = (state) => state.rehydratedReducer.isRehydrated;
2631
2848
  const rehydratedReducer = rehydratedSlice.reducer;
2632
- const initialState$4 = {
2849
+ const initialState$3 = {
2633
2850
  useIssueTemplate: false,
2634
2851
  placementMode: false,
2635
2852
  enableClustering: true,
@@ -2644,8 +2861,8 @@ var __publicField = (obj, key, value) => {
2644
2861
  };
2645
2862
  const settingSlice = toolkit.createSlice({
2646
2863
  name: "settings",
2647
- initialState: initialState$4,
2648
- extraReducers: (builder) => builder.addCase("RESET", (state) => Object.assign(state, initialState$4)),
2864
+ initialState: initialState$3,
2865
+ extraReducers: (builder) => builder.addCase("RESET", (state) => Object.assign(state, initialState$3)),
2649
2866
  reducers: {
2650
2867
  setEnableDuplicateIssues: (state, action) => {
2651
2868
  state.useIssueTemplate = action.payload;
@@ -2708,7 +2925,7 @@ var __publicField = (obj, key, value) => {
2708
2925
  function getLatestRevisionFromCache(formId) {
2709
2926
  return LATEST_REVISION_CACHE[formId];
2710
2927
  }
2711
- const initialState$3 = {
2928
+ const initialState$2 = {
2712
2929
  userForms: {},
2713
2930
  revisions: {},
2714
2931
  submissions: {},
@@ -2716,8 +2933,8 @@ var __publicField = (obj, key, value) => {
2716
2933
  };
2717
2934
  const userFormSlice = toolkit.createSlice({
2718
2935
  name: "userForms",
2719
- initialState: initialState$3,
2720
- extraReducers: (builder) => builder.addCase("RESET", (state) => Object.assign(state, initialState$3)),
2936
+ initialState: initialState$2,
2937
+ extraReducers: (builder) => builder.addCase("RESET", (state) => Object.assign(state, initialState$2)),
2721
2938
  reducers: {
2722
2939
  setUserForms: (state, action) => {
2723
2940
  state.userForms = {};
@@ -2965,171 +3182,38 @@ var __publicField = (obj, key, value) => {
2965
3182
  return Object.keys(userForms).length;
2966
3183
  });
2967
3184
  const userFormReducer = userFormSlice.reducer;
2968
- const initialState$2 = {
2969
- users: {},
2970
- currentUser: {
2971
- id: 0,
2972
- username: "",
2973
- email: "",
2974
- profile: { file: null, file_sha1: null, favourite_project_ids: [], tour_step: -1 }
2975
- }
2976
- };
2977
- const userSlice = toolkit.createSlice({
2978
- name: "users",
2979
- initialState: initialState$2,
2980
- extraReducers: (builder) => builder.addCase("RESET", (state) => Object.assign(state, initialState$2)),
2981
- reducers: {
2982
- setUsers: (state, action) => {
2983
- const usersMapping = {};
2984
- action.payload.forEach((user) => {
2985
- usersMapping[user.id] = user;
2986
- });
2987
- state.users = usersMapping;
2988
- },
2989
- setCurrentUser: (state, action) => {
2990
- state.currentUser = action.payload;
2991
- },
2992
- setProfilePicture: (state, action) => {
2993
- state.currentUser.profile.file = action.payload.file ?? null;
2994
- state.currentUser.profile.file_sha1 = action.payload.file_sha1 ?? null;
2995
- const currentUser = state.users[state.currentUser.id];
2996
- if (!currentUser) {
2997
- throw new Error("Unable to find current user in users slice");
2998
- }
2999
- currentUser.profile.file = action.payload.file ?? null;
3000
- currentUser.profile.file_sha1 = action.payload.file_sha1 ?? null;
3001
- },
3002
- addFavouriteProjectId: (state, action) => {
3003
- state.currentUser.profile.favourite_project_ids.push(action.payload);
3004
- },
3005
- removeFavouriteProjectId: (state, action) => {
3006
- state.currentUser.profile.favourite_project_ids = state.currentUser.profile.favourite_project_ids.filter(
3007
- (id) => id !== action.payload
3008
- );
3009
- },
3010
- setTourStep: (state, action) => {
3011
- state.currentUser.profile.tour_step = action.payload;
3012
- },
3013
- removeUser: (state, action) => {
3014
- delete state.users[action.payload];
3015
- }
3016
- }
3017
- });
3018
- const {
3019
- setCurrentUser,
3020
- setProfilePicture,
3021
- setUsers,
3022
- addFavouriteProjectId,
3023
- removeFavouriteProjectId,
3024
- setTourStep,
3025
- removeUser
3026
- } = userSlice.actions;
3027
- const selectCurrentUser = (state) => state.userReducer.currentUser;
3028
- const selectUser = (userId) => (state) => {
3029
- if (userId === null)
3030
- return void 0;
3031
- return state.userReducer.users[userId];
3032
- };
3033
- const selectUsersAsMapping = (state) => state.userReducer.users;
3034
- const selectFavouriteProjects = (state) => state.userReducer.currentUser.profile.favourite_project_ids;
3035
- const selectSortedUsers = toolkit.createSelector(
3036
- [selectCurrentUser, selectUsersAsMapping, selectProjectAccessUserMapping],
3037
- (currentUser, userMapping, projectAccessMapping) => {
3038
- return Object.values(userMapping).sort((userA, userB) => {
3039
- if (userA.id === currentUser.id) {
3040
- return -1;
3041
- } else if (userB.id === currentUser.id) {
3042
- return 1;
3043
- }
3044
- const projectAccessesA = projectAccessMapping[userA.id];
3045
- const projectAccessesB = projectAccessMapping[userB.id];
3046
- if ((projectAccessesA == null ? void 0 : projectAccessesA.access_level) === (projectAccessesB == null ? void 0 : projectAccessesB.access_level)) {
3047
- return userA.username.localeCompare(userB.username);
3048
- }
3049
- if ((projectAccessesA == null ? void 0 : projectAccessesA.access_level) === ProjectAccessLevel.ADMIN) {
3050
- return -1;
3051
- }
3052
- return 1;
3053
- });
3054
- }
3055
- );
3056
- const userReducer = userSlice.reducer;
3057
3185
  const initialState$1 = {
3058
- organizationAccesses: {},
3059
- activeOrganizationAccessId: null
3186
+ emailDomains: {}
3060
3187
  };
3061
- const organizationAccessSlice = toolkit.createSlice({
3062
- name: "organizationAccess",
3188
+ const emailDomainsSlice = toolkit.createSlice({
3189
+ name: "emailDomains",
3063
3190
  initialState: initialState$1,
3064
- extraReducers: (builder) => builder.addCase("RESET", (state) => Object.assign(state, initialState$1)),
3065
3191
  reducers: {
3066
- setOrganizationAccesses: (state, action) => {
3067
- if (!Array.isArray(action.payload))
3068
- throw new Error("Expected an array of OrganizationAccess");
3069
- if (action.payload.filter(onlyUniqueOfflineIds).length !== action.payload.length) {
3070
- throw new Error("Tried to use setOrganizationAccesses reducer with duplicate ID's");
3071
- }
3072
- const organizationAccesses = {};
3073
- for (const organizationAccess of action.payload) {
3074
- organizationAccesses[organizationAccess.offline_id] = organizationAccess;
3075
- }
3076
- state.organizationAccesses = organizationAccesses;
3192
+ setEmailDomains: (state, action) => {
3193
+ const emailDomains = {};
3194
+ action.payload.forEach((emailDomain) => {
3195
+ emailDomains[emailDomain.offline_id] = emailDomain;
3196
+ });
3197
+ state.emailDomains = emailDomains;
3077
3198
  },
3078
- updateOrganizationAccess: (state, action) => {
3079
- if (action.payload.offline_id in state.organizationAccesses) {
3080
- state.organizationAccesses[action.payload.offline_id] = action.payload;
3081
- } else {
3082
- throw new Error(
3083
- `Tried to update organization access with ID that doesn't exist: ${action.payload.offline_id}`
3084
- );
3085
- }
3199
+ addEmailDomain: (state, action) => {
3200
+ state.emailDomains[action.payload.offline_id] = action.payload;
3086
3201
  },
3087
- removeOrganizationAccess: (state, action) => {
3088
- if (action.payload.offline_id in state.organizationAccesses) {
3089
- delete state.organizationAccesses[action.payload.offline_id];
3202
+ removeEmailDomain: (state, action) => {
3203
+ if (action.payload.offline_id in state.emailDomains) {
3204
+ delete state.emailDomains[action.payload.offline_id];
3090
3205
  } else {
3091
- throw new Error(
3092
- `Tried to remove organization access with ID that doesn't exist: ${action.payload.offline_id}`
3093
- );
3206
+ throw new Error(`Tried to remove email domain with ID that doesn't exist: ${action.payload.offline_id}`);
3094
3207
  }
3095
- },
3096
- setActiveOrganizationAccessId: (state, action) => {
3097
- state.activeOrganizationAccessId = action.payload;
3098
3208
  }
3099
3209
  }
3100
3210
  });
3101
- const {
3102
- setOrganizationAccesses,
3103
- updateOrganizationAccess,
3104
- removeOrganizationAccess,
3105
- setActiveOrganizationAccessId
3106
- } = organizationAccessSlice.actions;
3107
- const selectOrganizationAccesses = (state) => {
3108
- return state.organizationAccessReducer.organizationAccesses;
3109
- };
3110
- const selectOrganizationAccess = (organizationAccessId) => (state) => {
3111
- return state.organizationAccessReducer.organizationAccesses[organizationAccessId];
3112
- };
3113
- const selectActiveOrganizationAccess = (state) => {
3114
- const activeOrganizationAccessId = state.organizationAccessReducer.activeOrganizationAccessId;
3115
- if (!activeOrganizationAccessId) {
3116
- return null;
3117
- }
3118
- return state.organizationAccessReducer.organizationAccesses[activeOrganizationAccessId] ?? null;
3119
- };
3120
- const selectOrganizationAccessForUser = (user) => (state) => {
3121
- return Object.values(state.organizationAccessReducer.organizationAccesses).find(
3122
- (organizationAccess) => organizationAccess.user === user.id
3123
- );
3124
- };
3125
- const selectOrganizationAccessUserMapping = (state) => {
3126
- const organizationAccesses = {};
3127
- Object.values(state.organizationAccessReducer.organizationAccesses).forEach((organizationAccess) => {
3128
- organizationAccesses[organizationAccess.user] = organizationAccess;
3129
- });
3130
- return organizationAccesses;
3131
- };
3132
- const organizationAccessReducer = organizationAccessSlice.reducer;
3211
+ const { setEmailDomains, addEmailDomain, removeEmailDomain } = emailDomainsSlice.actions;
3212
+ const selectEmailDomainsAsMapping = (state) => state.emailDomainsReducer.emailDomains;
3213
+ const selectSortedEmailDomains = (state) => Object.values(state.emailDomainsReducer.emailDomains).sort(
3214
+ (ed1, ed2) => ed1.domain.localeCompare(ed2.domain)
3215
+ );
3216
+ const emailDomainsReducer = emailDomainsSlice.reducer;
3133
3217
  const initialState = {
3134
3218
  version: 0
3135
3219
  };
@@ -3166,7 +3250,8 @@ var __publicField = (obj, key, value) => {
3166
3250
  settingReducer,
3167
3251
  userFormReducer,
3168
3252
  userReducer,
3169
- workspaceReducer
3253
+ workspaceReducer,
3254
+ emailDomainsReducer
3170
3255
  };
3171
3256
  const overmapReducer = toolkit.combineReducers(overmapReducers);
3172
3257
  const resetStore = "RESET";
@@ -4720,7 +4805,7 @@ var __publicField = (obj, key, value) => {
4720
4805
  return result;
4721
4806
  });
4722
4807
  }
4723
- async fetchUsers(projectId) {
4808
+ async fetchProjectUsers(projectId) {
4724
4809
  return this.enqueueRequest({
4725
4810
  description: "Fetch users",
4726
4811
  method: HttpMethod.GET,
@@ -4729,6 +4814,15 @@ var __publicField = (obj, key, value) => {
4729
4814
  blocks: []
4730
4815
  });
4731
4816
  }
4817
+ async fetchOrganizationUsers(orgId) {
4818
+ return this.enqueueRequest({
4819
+ description: "Fetch organization users",
4820
+ method: HttpMethod.GET,
4821
+ url: `/organizations/${orgId}/users/`,
4822
+ blockers: [],
4823
+ blocks: []
4824
+ });
4825
+ }
4732
4826
  // TODO:
4733
4827
  // Don't accept updateStore in ComponentService.list. Just return the offline objects and promise. Here, if
4734
4828
  // overwrite, use setComponents. Otherwise, use bulkAddComponents.
@@ -4747,8 +4841,8 @@ var __publicField = (obj, key, value) => {
4747
4841
  projects.push({
4748
4842
  id: projectData.id,
4749
4843
  name: projectData.name,
4750
- owner_organization: projectData.owner_organization,
4751
- owner_user: projectData.owner_user,
4844
+ owner_organization: projectData.organization_owner,
4845
+ owner_user: projectData.user_owner,
4752
4846
  bounds: projectData.bounds
4753
4847
  });
4754
4848
  if (currentProjectId === projectData.id) {
@@ -4771,13 +4865,22 @@ var __publicField = (obj, key, value) => {
4771
4865
  const firstOrg = organizationsData[0];
4772
4866
  const currProjObj = projects.find((project) => project.id === currentProjectId);
4773
4867
  const isOrgProject = !!(currProjObj == null ? void 0 : currProjObj.owner_organization);
4868
+ let currentOrgId = -1;
4774
4869
  if (isOrgProject && currProjObj.owner_organization) {
4775
- store.dispatch(setActiveOrganizationId(currProjObj.owner_organization));
4870
+ currentOrgId = currProjObj.owner_organization;
4776
4871
  } else if (firstOrg) {
4777
4872
  console.warn(
4778
4873
  "No active organization; using the first available one. TODO: No active organization in personal projects."
4779
4874
  );
4780
- store.dispatch(setActiveOrganizationId(firstOrg.id));
4875
+ currentOrgId = firstOrg.id;
4876
+ }
4877
+ if (currentOrgId !== -1) {
4878
+ store.dispatch(setActiveOrganizationId(currentOrgId));
4879
+ const orgUsersResultPromise = this.fetchOrganizationUsers(currentOrgId);
4880
+ const organizationAccessRefreshPromise = this.client.organizationAccess.refreshStore();
4881
+ const orgUsersResult = await orgUsersResultPromise;
4882
+ await organizationAccessRefreshPromise;
4883
+ store.dispatch(addUsers(orgUsersResult));
4781
4884
  }
4782
4885
  if (!isProjectIdValid) {
4783
4886
  if (projects.length !== 0) {
@@ -4800,13 +4903,11 @@ var __publicField = (obj, key, value) => {
4800
4903
  }
4801
4904
  }
4802
4905
  if (currentProjectId) {
4803
- const usersResultPromise = this.fetchUsers(currentProjectId);
4906
+ const usersResultPromise = this.fetchProjectUsers(currentProjectId);
4804
4907
  const projectAccessRefreshPromise = this.client.projectAccesses.refreshStore();
4805
- const organizationAccessRefreshPromise = this.client.organizationAccess.refreshStore();
4806
4908
  const usersResult = await usersResultPromise;
4807
4909
  await projectAccessRefreshPromise;
4808
- await organizationAccessRefreshPromise;
4809
- store.dispatch(setUsers(usersResult));
4910
+ store.dispatch(addUsers(usersResult));
4810
4911
  }
4811
4912
  let currentWorkspaceId;
4812
4913
  const oldWorkspaceId = this.client.store.getState().workspaceReducer.activeWorkspaceId;
@@ -4832,6 +4933,7 @@ var __publicField = (obj, key, value) => {
4832
4933
  void this.client.userForms.refreshStore().then(() => {
4833
4934
  void this.client.userFormSubmissions.refreshStore().then();
4834
4935
  });
4936
+ void this.client.emailDomains.refreshStore().then();
4835
4937
  }
4836
4938
  if (currentProjectId) {
4837
4939
  const [_offlineAttachments, promise] = this.client.attachments.fetchAll(currentProjectId);
@@ -4855,21 +4957,18 @@ var __publicField = (obj, key, value) => {
4855
4957
  }
4856
4958
  }
4857
4959
  class ProjectAccessService extends BaseApiService {
4858
- fetchAll(projectId) {
4859
- const { store } = this.client;
4860
- const promise = this.enqueueRequest({
4960
+ async fetchAll(projectId) {
4961
+ return this.enqueueRequest({
4861
4962
  description: "Get project accesses",
4862
4963
  method: HttpMethod.GET,
4863
4964
  url: `/projects/${projectId}/access/`,
4864
4965
  blockers: [],
4865
4966
  blocks: []
4866
4967
  });
4867
- const offlineProjectAccesses = Object.values(store.getState().projectAccessReducer.projectAccesses);
4868
- return [offlineProjectAccesses, promise];
4869
4968
  }
4870
- update(projectAccess) {
4969
+ async update(projectAccess) {
4871
4970
  this.client.store.dispatch(updateProjectAccess(projectAccess));
4872
- const promise = this.enqueueRequest({
4971
+ return this.enqueueRequest({
4873
4972
  description: "Edit project access",
4874
4973
  method: HttpMethod.PATCH,
4875
4974
  url: `/access/${projectAccess.offline_id}/`,
@@ -4877,10 +4976,9 @@ var __publicField = (obj, key, value) => {
4877
4976
  blockers: [projectAccess.offline_id],
4878
4977
  blocks: [projectAccess.offline_id]
4879
4978
  });
4880
- return [projectAccess, promise];
4881
4979
  }
4882
4980
  // TODO: Re-add user to project if removal fails
4883
- remove(projectAccess) {
4981
+ async remove(projectAccess) {
4884
4982
  const { store } = this.client;
4885
4983
  store.dispatch(removeProjectAccess(projectAccess));
4886
4984
  store.dispatch(removeUser(projectAccess.user));
@@ -4900,7 +4998,7 @@ var __publicField = (obj, key, value) => {
4900
4998
  if (!projectId) {
4901
4999
  throw new Error("No active project");
4902
5000
  }
4903
- const [_offlineProjectAccesses, promise] = this.fetchAll(projectId);
5001
+ const promise = this.fetchAll(projectId);
4904
5002
  const result = await promise;
4905
5003
  const activeProjectAccess = result.find((projectAccess) => projectAccess.user === currentUser.id);
4906
5004
  if (!activeProjectAccess) {
@@ -5497,6 +5595,31 @@ var __publicField = (obj, key, value) => {
5497
5595
  }
5498
5596
  }
5499
5597
  class OrganizationAccessService extends BaseApiService {
5598
+ async update(organizationAccess) {
5599
+ const promise = this.enqueueRequest({
5600
+ description: "Edit organization access",
5601
+ method: HttpMethod.PATCH,
5602
+ url: `/organizations/${organizationAccess.organization}/access/${organizationAccess.offline_id}/`,
5603
+ payload: organizationAccess,
5604
+ blockers: [organizationAccess.offline_id],
5605
+ blocks: [organizationAccess.offline_id]
5606
+ });
5607
+ void promise.then(() => {
5608
+ this.client.store.dispatch(updateOrganizationAccess(organizationAccess));
5609
+ });
5610
+ return promise;
5611
+ }
5612
+ async remove(organizationAccess) {
5613
+ this.client.store.dispatch(removeOrganizationAccess(organizationAccess));
5614
+ this.client.store.dispatch(removeUser(organizationAccess.user));
5615
+ return this.enqueueRequest({
5616
+ description: "Remove organization access",
5617
+ method: HttpMethod.DELETE,
5618
+ url: `/organizations/${organizationAccess.organization}/access/${organizationAccess.offline_id}/`,
5619
+ blockers: [organizationAccess.offline_id],
5620
+ blocks: []
5621
+ });
5622
+ }
5500
5623
  async refreshStore() {
5501
5624
  const { store } = this.client;
5502
5625
  const state = store.getState();
@@ -5744,6 +5867,86 @@ var __publicField = (obj, key, value) => {
5744
5867
  return this.enqueueRequest(requestDetails);
5745
5868
  }
5746
5869
  }
5870
+ class EmailDomainsService extends BaseApiService {
5871
+ async fetchAll(orgId) {
5872
+ return this.enqueueRequest({
5873
+ description: "Fetch email domains for organization",
5874
+ method: HttpMethod.GET,
5875
+ url: `/organizations/${orgId}/email-domains/`,
5876
+ blockers: [orgId.toString()],
5877
+ blocks: []
5878
+ });
5879
+ }
5880
+ async add(orgId, email) {
5881
+ return this.enqueueRequest({
5882
+ description: "Add email domain to organization",
5883
+ method: HttpMethod.POST,
5884
+ url: `/organizations/${orgId}/email-domains/`,
5885
+ payload: { email },
5886
+ blockers: [orgId.toString(), "create-org"],
5887
+ blocks: []
5888
+ });
5889
+ }
5890
+ async remove(emailDomain) {
5891
+ this.client.store.dispatch(removeEmailDomain(emailDomain));
5892
+ return this.enqueueRequest({
5893
+ description: "Remove email domain from organization",
5894
+ method: HttpMethod.DELETE,
5895
+ url: `/organizations/${emailDomain.organization}/email-domains/${emailDomain.offline_id}/`,
5896
+ blockers: [emailDomain.domain],
5897
+ blocks: []
5898
+ }).catch((e) => {
5899
+ this.client.store.dispatch(addEmailDomain(emailDomain));
5900
+ throw e;
5901
+ });
5902
+ }
5903
+ async refreshStore() {
5904
+ const organizationId = this.client.store.getState().organizationReducer.activeOrganizationId;
5905
+ if (!organizationId) {
5906
+ throw new Error("No active organization");
5907
+ }
5908
+ const promise = this.fetchAll(organizationId);
5909
+ const result = await promise;
5910
+ this.client.store.dispatch(setEmailDomains(result));
5911
+ }
5912
+ }
5913
+ class OrganizationService extends BaseApiService {
5914
+ async create(name) {
5915
+ const result = await this.enqueueRequest({
5916
+ description: "Create organization",
5917
+ method: HttpMethod.POST,
5918
+ url: "/organizations/",
5919
+ payload: { name },
5920
+ blockers: [],
5921
+ blocks: [`add-org-${name}`, "create-org"]
5922
+ });
5923
+ await this.client.main.fetchInitialData(true);
5924
+ return result;
5925
+ }
5926
+ async update(organization) {
5927
+ const promise = this.enqueueRequest({
5928
+ description: "Edit organization",
5929
+ method: HttpMethod.PATCH,
5930
+ url: `/organizations/${organization.id}/`,
5931
+ payload: organization,
5932
+ blockers: [`add-org-${organization.name}`, organization.id.toString()],
5933
+ blocks: [organization.id.toString()]
5934
+ });
5935
+ return promise.then((result) => {
5936
+ this.client.store.dispatch(updateActiveOrganization(organization));
5937
+ return result;
5938
+ });
5939
+ }
5940
+ async invite(organizationId, email) {
5941
+ return this.enqueueRequest({
5942
+ description: "Invite user to organization",
5943
+ method: HttpMethod.POST,
5944
+ url: `/organizations/${organizationId}/invite/${email}/`,
5945
+ blockers: [],
5946
+ blocks: []
5947
+ });
5948
+ }
5949
+ }
5747
5950
  class OvermapSDK {
5748
5951
  constructor(apiUrl, store) {
5749
5952
  __publicField(this, "API_URL");
@@ -5753,6 +5956,7 @@ var __publicField = (obj, key, value) => {
5753
5956
  __publicField(this, "auth", new AuthService(this));
5754
5957
  __publicField(this, "categories", new CategoryService(this));
5755
5958
  __publicField(this, "projectAccesses", new ProjectAccessService(this));
5959
+ __publicField(this, "organizations", new OrganizationService(this));
5756
5960
  __publicField(this, "organizationAccess", new OrganizationAccessService(this));
5757
5961
  __publicField(this, "issues", new IssueService(this));
5758
5962
  __publicField(this, "issueComments", new IssueCommentService(this));
@@ -5767,6 +5971,7 @@ var __publicField = (obj, key, value) => {
5767
5971
  __publicField(this, "projects", new ProjectService(this));
5768
5972
  __publicField(this, "projectFiles", new ProjectFileService(this));
5769
5973
  __publicField(this, "emailVerification", new EmailVerificationService(this));
5974
+ __publicField(this, "emailDomains", new EmailDomainsService(this));
5770
5975
  this.API_URL = apiUrl;
5771
5976
  this.store = store;
5772
5977
  }
@@ -5808,6 +6013,7 @@ var __publicField = (obj, key, value) => {
5808
6013
  exports2.ComponentTypeService = ComponentTypeService;
5809
6014
  exports2.DEFAULT_ISSUE_PRIORITY = DEFAULT_ISSUE_PRIORITY;
5810
6015
  exports2.DEFAULT_ISSUE_STATUS = DEFAULT_ISSUE_STATUS;
6016
+ exports2.EmailDomainsService = EmailDomainsService;
5811
6017
  exports2.EmailVerificationService = EmailVerificationService;
5812
6018
  exports2.FileService = FileService;
5813
6019
  exports2.GREEN = GREEN;
@@ -5821,6 +6027,7 @@ var __publicField = (obj, key, value) => {
5821
6027
  exports2.OUTBOX_RETRY_DELAY = OUTBOX_RETRY_DELAY;
5822
6028
  exports2.OrganizationAccessLevel = OrganizationAccessLevel;
5823
6029
  exports2.OrganizationAccessService = OrganizationAccessService;
6030
+ exports2.OrganizationService = OrganizationService;
5824
6031
  exports2.OutboxCoordinator = OutboxCoordinator;
5825
6032
  exports2.OvermapContext = OvermapContext;
5826
6033
  exports2.OvermapProvider = OvermapProvider;
@@ -5844,6 +6051,7 @@ var __publicField = (obj, key, value) => {
5844
6051
  exports2.addComponent = addComponent;
5845
6052
  exports2.addComponentType = addComponentType;
5846
6053
  exports2.addComponentsInBatches = addComponentsInBatches;
6054
+ exports2.addEmailDomain = addEmailDomain;
5847
6055
  exports2.addFavouriteProjectId = addFavouriteProjectId;
5848
6056
  exports2.addIssue = addIssue;
5849
6057
  exports2.addOrReplaceCategories = addOrReplaceCategories;
@@ -5863,6 +6071,7 @@ var __publicField = (obj, key, value) => {
5863
6071
  exports2.addUserFormSubmissionAttachment = addUserFormSubmissionAttachment;
5864
6072
  exports2.addUserFormSubmissions = addUserFormSubmissions;
5865
6073
  exports2.addUserForms = addUserForms;
6074
+ exports2.addUsers = addUsers;
5866
6075
  exports2.addWorkspace = addWorkspace;
5867
6076
  exports2.areArraysEqual = areArraysEqual;
5868
6077
  exports2.authReducer = authReducer;
@@ -5901,6 +6110,8 @@ var __publicField = (obj, key, value) => {
5901
6110
  exports2.dequeue = dequeue;
5902
6111
  exports2.discard = discard;
5903
6112
  exports2.downloadInMemoryFile = downloadInMemoryFile;
6113
+ exports2.emailDomainsReducer = emailDomainsReducer;
6114
+ exports2.emailDomainsSlice = emailDomainsSlice;
5904
6115
  exports2.emailRegex = emailRegex;
5905
6116
  exports2.enqueue = enqueue;
5906
6117
  exports2.enqueueRequest = enqueueRequest;
@@ -5969,6 +6180,7 @@ var __publicField = (obj, key, value) => {
5969
6180
  exports2.removeCategory = removeCategory;
5970
6181
  exports2.removeColor = removeColor;
5971
6182
  exports2.removeComponent = removeComponent;
6183
+ exports2.removeEmailDomain = removeEmailDomain;
5972
6184
  exports2.removeFavouriteProjectId = removeFavouriteProjectId;
5973
6185
  exports2.removeIssue = removeIssue;
5974
6186
  exports2.removeIssueComment = removeIssueComment;
@@ -6027,6 +6239,7 @@ var __publicField = (obj, key, value) => {
6027
6239
  exports2.selectCreateProjectType = selectCreateProjectType;
6028
6240
  exports2.selectCurrentUser = selectCurrentUser;
6029
6241
  exports2.selectDeletedRequests = selectDeletedRequests;
6242
+ exports2.selectEmailDomainsAsMapping = selectEmailDomainsAsMapping;
6030
6243
  exports2.selectEnableClustering = selectEnableClustering;
6031
6244
  exports2.selectEnableDuplicateIssues = selectEnableDuplicateIssues;
6032
6245
  exports2.selectEnablePlacementMode = selectEnablePlacementMode;
@@ -6061,6 +6274,8 @@ var __publicField = (obj, key, value) => {
6061
6274
  exports2.selectOrganizationAccessForUser = selectOrganizationAccessForUser;
6062
6275
  exports2.selectOrganizationAccessUserMapping = selectOrganizationAccessUserMapping;
6063
6276
  exports2.selectOrganizationAccesses = selectOrganizationAccesses;
6277
+ exports2.selectOrganizationUsersAsMapping = selectOrganizationUsersAsMapping;
6278
+ exports2.selectOrganizationUsersIds = selectOrganizationUsersIds;
6064
6279
  exports2.selectOrganizations = selectOrganizations;
6065
6280
  exports2.selectPermittedWorkspaceIds = selectPermittedWorkspaceIds;
6066
6281
  exports2.selectPhotoAttachmentsOfIssue = selectPhotoAttachmentsOfIssue;
@@ -6070,6 +6285,8 @@ var __publicField = (obj, key, value) => {
6070
6285
  exports2.selectProjectAccesses = selectProjectAccesses;
6071
6286
  exports2.selectProjectFileVisibility = selectProjectFileVisibility;
6072
6287
  exports2.selectProjectFiles = selectProjectFiles;
6288
+ exports2.selectProjectUsersAsMapping = selectProjectUsersAsMapping;
6289
+ exports2.selectProjectUsersIds = selectProjectUsersIds;
6073
6290
  exports2.selectProjects = selectProjects;
6074
6291
  exports2.selectRecentIssueIds = selectRecentIssueIds;
6075
6292
  exports2.selectRecentIssuesAsSearchResults = selectRecentIssuesAsSearchResults;
@@ -6077,7 +6294,9 @@ var __publicField = (obj, key, value) => {
6077
6294
  exports2.selectRehydrated = selectRehydrated;
6078
6295
  exports2.selectRevisionsForForm = selectRevisionsForForm;
6079
6296
  exports2.selectShowTooltips = selectShowTooltips;
6080
- exports2.selectSortedUsers = selectSortedUsers;
6297
+ exports2.selectSortedEmailDomains = selectSortedEmailDomains;
6298
+ exports2.selectSortedOrganizationUsers = selectSortedOrganizationUsers;
6299
+ exports2.selectSortedProjectUsers = selectSortedProjectUsers;
6081
6300
  exports2.selectStageMapping = selectStageMapping;
6082
6301
  exports2.selectStages = selectStages;
6083
6302
  exports2.selectStagesFromComponentType = selectStagesFromComponentType;
@@ -6112,6 +6331,7 @@ var __publicField = (obj, key, value) => {
6112
6331
  exports2.setComponents = setComponents;
6113
6332
  exports2.setCreateProjectType = setCreateProjectType;
6114
6333
  exports2.setCurrentUser = setCurrentUser;
6334
+ exports2.setEmailDomains = setEmailDomains;
6115
6335
  exports2.setEnableClustering = setEnableClustering;
6116
6336
  exports2.setEnableDuplicateIssues = setEnableDuplicateIssues;
6117
6337
  exports2.setEnablePlacementMode = setEnablePlacementMode;
@@ -6152,6 +6372,7 @@ var __publicField = (obj, key, value) => {
6152
6372
  exports2.unfavoriteForm = unfavoriteForm;
6153
6373
  exports2.unhideAllCategories = unhideAllCategories;
6154
6374
  exports2.unhideCategory = unhideCategory;
6375
+ exports2.updateActiveOrganization = updateActiveOrganization;
6155
6376
  exports2.updateAttachment = updateAttachment;
6156
6377
  exports2.updateComponent = updateComponent;
6157
6378
  exports2.updateIssue = updateIssue;