@seliseblocks/genesis-os 4.4.3 → 4.4.5

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 (45) hide show
  1. package/dist/{chunk-VAWEXEJZ.cjs → chunk-4CMIWUZW.cjs} +185 -7
  2. package/dist/chunk-4CMIWUZW.cjs.map +1 -0
  3. package/dist/{chunk-MLPOREJO.cjs → chunk-CGVT7IFM.cjs} +203 -111
  4. package/dist/chunk-CGVT7IFM.cjs.map +1 -0
  5. package/dist/{chunk-3EGBCU4W.cjs → chunk-IRIDGVV2.cjs} +229 -78
  6. package/dist/chunk-IRIDGVV2.cjs.map +1 -0
  7. package/dist/{chunk-5ILZSG2E.js → chunk-NPMO67H6.js} +112 -20
  8. package/dist/chunk-NPMO67H6.js.map +1 -0
  9. package/dist/{chunk-SG6FH72W.js → chunk-O5ACQLWB.js} +183 -8
  10. package/dist/chunk-O5ACQLWB.js.map +1 -0
  11. package/dist/{chunk-M3VJ7FLT.js → chunk-ZR6LRRN6.js} +202 -55
  12. package/dist/chunk-ZR6LRRN6.js.map +1 -0
  13. package/dist/components/index.cjs +342 -342
  14. package/dist/components/index.js +3 -3
  15. package/dist/guards/index.cjs +9 -9
  16. package/dist/guards/index.js +3 -3
  17. package/dist/hooks/index.cjs +68 -56
  18. package/dist/hooks/index.d.cts +30 -2
  19. package/dist/hooks/index.d.ts +30 -2
  20. package/dist/hooks/index.js +2 -2
  21. package/dist/index.cjs +455 -435
  22. package/dist/index.d.cts +3 -3
  23. package/dist/index.d.ts +3 -3
  24. package/dist/index.js +3 -3
  25. package/dist/layouts/index.cjs +10 -10
  26. package/dist/layouts/index.js +3 -3
  27. package/dist/lib/index.cjs +30 -22
  28. package/dist/lib/index.d.cts +38 -3
  29. package/dist/lib/index.d.ts +38 -3
  30. package/dist/lib/index.js +1 -1
  31. package/dist/observability/index.d.cts +1 -1
  32. package/dist/observability/index.d.ts +1 -1
  33. package/dist/pages/index.cjs +8 -8
  34. package/dist/pages/index.js +3 -3
  35. package/dist/{types-CxmwyESB.d.cts → types-CQX9_ck-.d.cts} +21 -1
  36. package/dist/{types-R-boAdbM.d.ts → types-D9odiLzd.d.ts} +21 -1
  37. package/dist/utils/index.cjs +1 -1
  38. package/dist/utils/index.js +1 -1
  39. package/package.json +1 -1
  40. package/dist/chunk-3EGBCU4W.cjs.map +0 -1
  41. package/dist/chunk-5ILZSG2E.js.map +0 -1
  42. package/dist/chunk-M3VJ7FLT.js.map +0 -1
  43. package/dist/chunk-MLPOREJO.cjs.map +0 -1
  44. package/dist/chunk-SG6FH72W.js.map +0 -1
  45. package/dist/chunk-VAWEXEJZ.cjs.map +0 -1
@@ -1,11 +1,11 @@
1
- import { HttpClient, clearTenantClaims, IAM_ENDPOINTS, notificationClient, NOTIFICATION_ENDPOINTS, NOTIFICATION_CONFIG_ENDPOINTS, PROJECT_ENDPOINTS, logicClient, claimTenant, iamClient, AUTH_ENDPOINTS, ORGANIZATION_ENDPOINTS, SERVICE_REGISTRY_ENDPOINTS, IMPERSONATE_ENDPOINTS } from './chunk-SG6FH72W.js';
1
+ import { HttpClient, IAM_ENDPOINTS, notificationClient, NOTIFICATION_ENDPOINTS, NOTIFICATION_CONFIG_ENDPOINTS, PROJECT_ENDPOINTS, logicClient, iamClient, IMPERSONATE_ENDPOINTS, claimTenant, clearTenantClaims, announceSignOut, AUTH_ENDPOINTS, ORGANIZATION_ENDPOINTS, SERVICE_REGISTRY_ENDPOINTS, timeoutSignal } from './chunk-O5ACQLWB.js';
2
2
  import { getRuntimeEnv, HttpError } from './chunk-JUVLHPQI.js';
3
3
  import { BlocksAppLayoutContext } from './chunk-AHCHUUXM.js';
4
4
  import { useAppSettingsStore, useImpersonateStore } from './chunk-JITR3QYC.js';
5
- import { useProjectStore } from './chunk-4UHGGHI6.js';
5
+ import { useProjectStore, useAuthStore } from './chunk-4UHGGHI6.js';
6
6
  import { useMemo, useState, useEffect, useCallback, useRef, useContext } from 'react';
7
7
  import { useQueryStates } from 'nuqs';
8
- import { useQueryClient, useMutation, useQuery } from '@tanstack/react-query';
8
+ import { useQueryClient, useMutation, useQuery, focusManager } from '@tanstack/react-query';
9
9
  import Fuse from 'fuse.js';
10
10
  import { useStore } from 'zustand';
11
11
  import { jsx, jsxs } from 'react/jsx-runtime';
@@ -465,14 +465,26 @@ var AuthService = class {
465
465
  }
466
466
  };
467
467
  var authService = new AuthService();
468
+ var forgetSession = () => {
469
+ clearTenantClaims();
470
+ announceSignOut();
471
+ };
468
472
  var useLogout = () => {
469
473
  return useMutation({
470
474
  mutationKey: ["logout"],
471
475
  mutationFn: authService.logout,
472
476
  // Done here rather than in each logout control, so every way out of the app clears it.
473
- onSuccess: () => clearTenantClaims()
477
+ onSuccess: forgetSession
474
478
  });
475
479
  };
480
+ var useSignOut = () => useCallback(() => {
481
+ void authService.logout().catch(() => void 0).finally(() => {
482
+ forgetSession();
483
+ useProjectStore.getState().resetProjectStore();
484
+ useAuthStore.getState().resetAuthStore();
485
+ window.location.replace(`${window.location.origin}/login`);
486
+ });
487
+ }, []);
476
488
  var useBlocksAppConfigStore = (selector) => {
477
489
  const context = useContext(BlocksAppLayoutContext);
478
490
  if (!context) {
@@ -1067,46 +1079,174 @@ var useGetAllServices = (options) => {
1067
1079
 
1068
1080
  // src/services/impersonation.service.ts
1069
1081
  var ImpersonationService = class {
1070
- startImpersonation(request) {
1071
- return iamClient.post(IMPERSONATE_ENDPOINTS.IMPERSONATE, request);
1082
+ startImpersonation(request, options) {
1083
+ return iamClient.post(
1084
+ IMPERSONATE_ENDPOINTS.IMPERSONATE,
1085
+ request,
1086
+ void 0,
1087
+ options
1088
+ );
1072
1089
  }
1073
- stopImpersonation() {
1090
+ stopImpersonation(options) {
1074
1091
  return iamClient.post(
1075
1092
  IMPERSONATE_ENDPOINTS.STOP_IMPERSONATION,
1076
1093
  {},
1077
1094
  void 0,
1078
- { skipTokenRotation: true }
1095
+ options
1079
1096
  );
1080
1097
  }
1081
- impersonationStatus() {
1082
- return iamClient.post(IMPERSONATE_ENDPOINTS.IMPERSONATION_STATUS, null);
1098
+ impersonationStatus(options) {
1099
+ return iamClient.post(
1100
+ IMPERSONATE_ENDPOINTS.IMPERSONATION_STATUS,
1101
+ null,
1102
+ void 0,
1103
+ options
1104
+ );
1083
1105
  }
1084
1106
  };
1085
1107
  var impersonationService = new ImpersonationService();
1086
1108
  var IMPERSONATION_STATUS_QUERY_KEY = ["blocks-kit-impersonation", "status"];
1109
+ var LOCKED_CALL_TIMEOUT_MS = 2e4;
1110
+ var insideSessionLock = () => ({
1111
+ skipTokenRotation: true,
1112
+ skipSessionCheck: true,
1113
+ signal: timeoutSignal(LOCKED_CALL_TIMEOUT_MS)
1114
+ });
1115
+ var RETURN_STATUS_WAIT_MS = 5e3;
1116
+ var FOCUS_REFETCH_DELAY_MS = 50;
1117
+ var rootTenantId = () => getRuntimeEnv("BLOCKS_X_BLOCKS_KEY") || "";
1087
1118
  var buildStoppedStatus = () => ({
1088
1119
  impersonated: false,
1089
- originalTenantId: getRuntimeEnv("BLOCKS_X_BLOCKS_KEY") || "",
1120
+ originalTenantId: rootTenantId(),
1090
1121
  impersonatedTenantId: null
1091
1122
  });
1123
+ var isSameTenant = (a, b) => !!a && !!b && a.toLowerCase() === b.toLowerCase();
1124
+ var tenantOfStatus = (status) => {
1125
+ if (!status) return null;
1126
+ return status.impersonated ? status.impersonatedTenantId ?? null : rootTenantId() || null;
1127
+ };
1128
+ var tenantShown = () => {
1129
+ const { isInitialized, isImpersonated, impersonatedTenantId } = useImpersonateStore.getState();
1130
+ if (!isInitialized) return null;
1131
+ return isImpersonated ? impersonatedTenantId : rootTenantId() || null;
1132
+ };
1133
+ var errorCodeOf = (error) => {
1134
+ if (!(error instanceof HttpError)) return null;
1135
+ const code = error.errors?.error;
1136
+ return typeof code === "string" ? code : null;
1137
+ };
1138
+ var isExpiredAccessToken = (error) => error instanceof HttpError && error.status === 401 && !errorCodeOf(error);
1139
+ var withRefreshedToken = async (call) => {
1140
+ try {
1141
+ return await call();
1142
+ } catch (error) {
1143
+ if (!isExpiredAccessToken(error)) throw error;
1144
+ await iamClient.refreshWithinSessionLock();
1145
+ return call();
1146
+ }
1147
+ };
1148
+ var isStatusQuery = (query) => query.queryKey[0] === IMPERSONATION_STATUS_QUERY_KEY[0];
1149
+ var dropDataFromBeforeTheMove = (queryClient) => {
1150
+ void queryClient.cancelQueries({ predicate: (q) => !isStatusQuery(q) });
1151
+ setTimeout(() => {
1152
+ queryClient.removeQueries({
1153
+ predicate: (q) => !isStatusQuery(q),
1154
+ type: "inactive"
1155
+ });
1156
+ void queryClient.invalidateQueries({
1157
+ predicate: (q) => !isStatusQuery(q),
1158
+ refetchType: "none"
1159
+ });
1160
+ }, FOCUS_REFETCH_DELAY_MS);
1161
+ };
1162
+ var applyServerStatus = (queryClient, status) => {
1163
+ const shown = tenantShown();
1164
+ queryClient.setQueryData(IMPERSONATION_STATUS_QUERY_KEY, status);
1165
+ const actual = tenantOfStatus(status);
1166
+ if (shown && actual && !isSameTenant(shown, actual)) {
1167
+ dropDataFromBeforeTheMove(queryClient);
1168
+ }
1169
+ return actual;
1170
+ };
1092
1171
  var useImpersonationStatusChecker = () => {
1093
1172
  return useQuery({
1094
1173
  queryKey: IMPERSONATION_STATUS_QUERY_KEY,
1095
- queryFn: () => impersonationService.impersonationStatus(),
1174
+ // The status is what decides the tenant, so it is never held back for disagreeing with it.
1175
+ queryFn: () => impersonationService.impersonationStatus({ skipSessionCheck: true }),
1096
1176
  staleTime: 0,
1097
1177
  refetchOnMount: "always",
1098
- refetchOnWindowFocus: "always"
1178
+ // A returning tab asks first and refetches its data after; see useStatusFirstOnTabReturn.
1179
+ refetchOnWindowFocus: false
1099
1180
  });
1100
1181
  };
1182
+ var useSessionTenantGuard = () => {
1183
+ const queryClient = useQueryClient();
1184
+ useEffect(
1185
+ () => HttpClient.setSessionGuard({
1186
+ expectedTenant: tenantShown,
1187
+ confirmTenant: async () => applyServerStatus(
1188
+ queryClient,
1189
+ await impersonationService.impersonationStatus(insideSessionLock())
1190
+ )
1191
+ }),
1192
+ [queryClient]
1193
+ );
1194
+ };
1195
+ var listenForVisibility = (onFocus) => {
1196
+ if (typeof window === "undefined" || !window.addEventListener) {
1197
+ return void 0;
1198
+ }
1199
+ const listener = () => onFocus();
1200
+ window.addEventListener("visibilitychange", listener, false);
1201
+ return () => window.removeEventListener("visibilitychange", listener);
1202
+ };
1203
+ var confirmTenantOnReturn = async (queryClient) => {
1204
+ let timer;
1205
+ try {
1206
+ const status = await Promise.race([
1207
+ impersonationService.impersonationStatus({ skipSessionCheck: true }),
1208
+ new Promise((_, reject) => {
1209
+ timer = setTimeout(
1210
+ () => reject(new Error("Impersonation status timed out")),
1211
+ RETURN_STATUS_WAIT_MS
1212
+ );
1213
+ })
1214
+ ]);
1215
+ applyServerStatus(queryClient, status);
1216
+ } catch {
1217
+ } finally {
1218
+ clearTimeout(timer);
1219
+ }
1220
+ };
1221
+ var useStatusFirstOnTabReturn = () => {
1222
+ const queryClient = useQueryClient();
1223
+ useEffect(() => {
1224
+ if (typeof window === "undefined") return;
1225
+ focusManager.setEventListener((onFocus) => {
1226
+ const listener = () => {
1227
+ if (document.visibilityState === "hidden") {
1228
+ onFocus();
1229
+ return;
1230
+ }
1231
+ void confirmTenantOnReturn(queryClient).finally(() => {
1232
+ setTimeout(() => onFocus(), FOCUS_REFETCH_DELAY_MS);
1233
+ });
1234
+ };
1235
+ window.addEventListener("visibilitychange", listener, false);
1236
+ return () => window.removeEventListener("visibilitychange", listener);
1237
+ });
1238
+ return () => focusManager.setEventListener(listenForVisibility);
1239
+ }, [queryClient]);
1240
+ };
1101
1241
  var useRecordClaimedTenant = () => {
1102
1242
  const queryClient = useQueryClient();
1103
1243
  return useCallback(
1104
- (tenantId, rootTenantId) => {
1244
+ (tenantId, rootTenantId2) => {
1105
1245
  queryClient.setQueryData(
1106
1246
  IMPERSONATION_STATUS_QUERY_KEY,
1107
- tenantId === rootTenantId ? buildStoppedStatus() : (current) => ({
1247
+ tenantId === rootTenantId2 ? buildStoppedStatus() : (current) => ({
1108
1248
  impersonated: true,
1109
- originalTenantId: current?.originalTenantId || rootTenantId,
1249
+ originalTenantId: current?.originalTenantId || rootTenantId2,
1110
1250
  impersonatedTenantId: tenantId
1111
1251
  })
1112
1252
  );
@@ -1114,41 +1254,37 @@ var useRecordClaimedTenant = () => {
1114
1254
  [queryClient]
1115
1255
  );
1116
1256
  };
1257
+ var stopAndConfirm = () => iamClient.withSessionLock(async () => {
1258
+ let stopError = null;
1259
+ try {
1260
+ await withRefreshedToken(
1261
+ () => impersonationService.stopImpersonation(insideSessionLock())
1262
+ );
1263
+ } catch (error) {
1264
+ stopError = error;
1265
+ }
1266
+ const status = await withRefreshedToken(
1267
+ () => impersonationService.impersonationStatus(insideSessionLock())
1268
+ );
1269
+ return { status, stopError };
1270
+ });
1117
1271
  var useStopImpersonation = () => {
1118
1272
  const queryClient = useQueryClient();
1119
1273
  return useMutation({
1120
1274
  mutationKey: ["impersonation", "stop"],
1121
- mutationFn: impersonationService.stopImpersonation,
1122
- onSuccess: () => {
1275
+ mutationFn: stopAndConfirm,
1276
+ onSuccess: ({ status }) => {
1123
1277
  queryClient.setQueryData(
1124
1278
  IMPERSONATION_STATUS_QUERY_KEY,
1125
- buildStoppedStatus()
1279
+ status
1126
1280
  );
1127
- },
1128
- // This used to be `onSettled`, which recorded "stopped" for failures too. A stop that 500s or
1129
- // never leaves the browser leaves the session impersonated server-side, so writing the stopped
1130
- // status there put the client into a state the server did not share -- the UI left the project
1131
- // while the cookie stayed pointed at it.
1132
- //
1133
- // 401 is the one failure that still means stopped: IAM answers it when the refresh token names
1134
- // no live impersonated session, so there is nothing left to stop either way. Every other failure
1135
- // is unknown, and unknown is resolved by asking the server rather than by guessing.
1136
- onError: (error) => {
1137
- if (error instanceof HttpError && error.status === 401) {
1138
- queryClient.setQueryData(
1139
- IMPERSONATION_STATUS_QUERY_KEY,
1140
- buildStoppedStatus()
1141
- );
1142
- return;
1143
- }
1144
- void queryClient.invalidateQueries({
1145
- queryKey: IMPERSONATION_STATUS_QUERY_KEY
1146
- });
1147
1281
  }
1148
1282
  });
1149
1283
  };
1150
- var startImpersonation = async (request) => {
1151
- const result = await impersonationService.startImpersonation(request);
1284
+ var startAndConfirm = (request) => iamClient.withSessionLock(async () => {
1285
+ const result = await withRefreshedToken(
1286
+ () => impersonationService.startImpersonation(request, insideSessionLock())
1287
+ );
1152
1288
  if (result?.cookie_set !== true) {
1153
1289
  throw new HttpError(500, {
1154
1290
  errors: {
@@ -1156,23 +1292,34 @@ var startImpersonation = async (request) => {
1156
1292
  }
1157
1293
  });
1158
1294
  }
1159
- return result;
1160
- };
1295
+ const status = await withRefreshedToken(
1296
+ () => impersonationService.impersonationStatus(insideSessionLock())
1297
+ ).catch(() => null);
1298
+ return { result, status };
1299
+ });
1161
1300
  var useStartImpersonation = () => {
1162
1301
  const queryClient = useQueryClient();
1163
1302
  return useMutation({
1164
1303
  mutationKey: ["impersonation", "start"],
1165
- mutationFn: startImpersonation,
1304
+ mutationFn: async (request) => {
1305
+ const { result, status } = await startAndConfirm(request);
1306
+ if (status) {
1307
+ queryClient.setQueryData(
1308
+ IMPERSONATION_STATUS_QUERY_KEY,
1309
+ status
1310
+ );
1311
+ }
1312
+ if (!status?.impersonated || !isSameTenant(status.impersonatedTenantId, request.targeted_tenant_id)) {
1313
+ throw new HttpError(409, {
1314
+ errors: {
1315
+ general: "The server did not confirm that the session is in the project"
1316
+ }
1317
+ });
1318
+ }
1319
+ return result;
1320
+ },
1166
1321
  onSuccess: (_data, variables) => {
1167
1322
  claimTenant(variables.targeted_tenant_id);
1168
- queryClient.setQueryData(
1169
- IMPERSONATION_STATUS_QUERY_KEY,
1170
- (current) => ({
1171
- impersonated: true,
1172
- originalTenantId: current?.originalTenantId || getRuntimeEnv("BLOCKS_X_BLOCKS_KEY") || "",
1173
- impersonatedTenantId: variables.targeted_tenant_id
1174
- })
1175
- );
1176
1323
  },
1177
1324
  onError: () => {
1178
1325
  void queryClient.invalidateQueries({
@@ -1182,6 +1329,6 @@ var useStartImpersonation = () => {
1182
1329
  });
1183
1330
  };
1184
1331
 
1185
- export { PROJECTS_STALE_TIME_MS, applyColumnFuseFilters, createFuseSearcher, createQueryKeyFactory, defaultFuseSearchOptions, defaultPathSegmentFormatter, fuseFilter, fuseSearch, fuseSearchWithIndex, getPathSegments, initiateService, notificationService, projectService, useBlocksAppConfigStore, useBoolean, useCopyToClipboard, useCountDown, useDebounce, useDebouncedFuseFilter, useDisableProject, useFuseIndex, useFuseSearch, useGetAllServices, useGetBlocksNotificationConfig, useGetEnvRepositories, useGetMyOrganizations, useGetNotifications, useGetProject, useGetProjects, useIcon, useImpersonationStatusChecker, useInitiateRedirect, useKeyboardShortcut, useLanguage, useLanguageSwitcher, useLogin, useLogo, useLogout, useMarkAllAsRead, useMarkAsRead, useMediaQuery, usePathSegments, usePopoverWidth, usePrefetchRedirect, useQueryClientKit, useQueryStatesKit, useRecordClaimedTenant, useScopedPath, useSignUpAffordance, useSignUpRedirect, useStartImpersonation, useStopImpersonation, useTheme, useUpdateProject, useUpdateRepositories, useUpdateTenantGroup, useValidateCNameProject };
1186
- //# sourceMappingURL=chunk-M3VJ7FLT.js.map
1187
- //# sourceMappingURL=chunk-M3VJ7FLT.js.map
1332
+ export { PROJECTS_STALE_TIME_MS, applyColumnFuseFilters, createFuseSearcher, createQueryKeyFactory, defaultFuseSearchOptions, defaultPathSegmentFormatter, fuseFilter, fuseSearch, fuseSearchWithIndex, getPathSegments, impersonationService, initiateService, notificationService, projectService, useBlocksAppConfigStore, useBoolean, useCopyToClipboard, useCountDown, useDebounce, useDebouncedFuseFilter, useDisableProject, useFuseIndex, useFuseSearch, useGetAllServices, useGetBlocksNotificationConfig, useGetEnvRepositories, useGetMyOrganizations, useGetNotifications, useGetProject, useGetProjects, useIcon, useImpersonationStatusChecker, useInitiateRedirect, useKeyboardShortcut, useLanguage, useLanguageSwitcher, useLogin, useLogo, useLogout, useMarkAllAsRead, useMarkAsRead, useMediaQuery, usePathSegments, usePopoverWidth, usePrefetchRedirect, useQueryClientKit, useQueryStatesKit, useRecordClaimedTenant, useScopedPath, useSessionTenantGuard, useSignOut, useSignUpAffordance, useSignUpRedirect, useStartImpersonation, useStatusFirstOnTabReturn, useStopImpersonation, useTheme, useUpdateProject, useUpdateRepositories, useUpdateTenantGroup, useValidateCNameProject };
1333
+ //# sourceMappingURL=chunk-ZR6LRRN6.js.map
1334
+ //# sourceMappingURL=chunk-ZR6LRRN6.js.map