@antelopejs/dms 0.20.3 → 0.20.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.
- package/CHANGELOG.md +33 -0
- package/README.md +1 -1
- package/dist/implementations/dms-builder/engine/compose-page.js +3 -2
- package/dist/implementations/dms-builder/engine/compose-page.js.map +1 -1
- package/dist/implementations/dms-builder/engine/database-access.d.ts +1 -16
- package/dist/implementations/dms-builder/engine/database-access.js +13 -44
- package/dist/implementations/dms-builder/engine/database-access.js.map +1 -1
- package/dist/implementations/dms-builder/engine/database-check.d.ts +1 -2
- package/dist/implementations/dms-builder/engine/database-check.js +28 -15
- package/dist/implementations/dms-builder/engine/database-check.js.map +1 -1
- package/dist/implementations/dms-builder/engine/driver-packages.d.ts +1 -0
- package/dist/implementations/dms-builder/engine/driver-packages.js +4 -0
- package/dist/implementations/dms-builder/engine/driver-packages.js.map +1 -1
- package/dist/implementations/dms-builder/engine/driver-probe.d.ts +27 -0
- package/dist/implementations/dms-builder/engine/driver-probe.js +53 -0
- package/dist/implementations/dms-builder/engine/driver-probe.js.map +1 -0
- package/dist/implementations/dms-builder/engine/index.d.ts +2 -6
- package/dist/implementations/dms-builder/engine/index.js +2 -6
- package/dist/implementations/dms-builder/engine/index.js.map +1 -1
- package/dist/implementations/dms-builder/engine/probe-answer.d.ts +4 -0
- package/dist/implementations/dms-builder/engine/probe-answer.js +90 -0
- package/dist/implementations/dms-builder/engine/probe-answer.js.map +1 -0
- package/dist/implementations/dms-builder/engine/probe-child.d.ts +1 -0
- package/dist/implementations/dms-builder/engine/probe-child.js +70 -0
- package/dist/implementations/dms-builder/engine/probe-child.js.map +1 -0
- package/dist/implementations/dms-builder/engine/probe-process.d.ts +2 -0
- package/dist/implementations/dms-builder/engine/probe-process.js +132 -0
- package/dist/implementations/dms-builder/engine/probe-process.js.map +1 -0
- package/dist/implementations/dms-builder/engine/probe-protocol.d.ts +46 -0
- package/dist/implementations/dms-builder/engine/probe-protocol.js +18 -0
- package/dist/implementations/dms-builder/engine/probe-protocol.js.map +1 -0
- package/dist/mcp/page-verify/index.d.ts +1 -0
- package/dist/mcp/page-verify/index.js +1 -0
- package/dist/mcp/page-verify/index.js.map +1 -1
- package/dist/mcp/page-verify/redact-report.d.ts +2 -0
- package/dist/mcp/page-verify/redact-report.js +120 -0
- package/dist/mcp/page-verify/redact-report.js.map +1 -0
- package/dist/mcp/page-verify/render.js +4 -1
- package/dist/mcp/page-verify/render.js.map +1 -1
- package/dist/mcp/redact.d.ts +87 -0
- package/dist/mcp/redact.js +139 -0
- package/dist/mcp/redact.js.map +1 -0
- package/dist/mcp/tools/builder-compose.js +11 -2
- package/dist/mcp/tools/builder-compose.js.map +1 -1
- package/dist/mcp/tools/builder-project.js +56 -23
- package/dist/mcp/tools/builder-project.js.map +1 -1
- package/dist/mcp/tools/builder-queries.js +41 -4
- package/dist/mcp/tools/builder-queries.js.map +1 -1
- package/dist/mcp/tools/builder-shared.d.ts +3 -1
- package/dist/mcp/tools/builder-shared.js +5 -0
- package/dist/mcp/tools/builder-shared.js.map +1 -1
- package/dist/mcp/tools/database.js +3 -2
- package/dist/mcp/tools/database.js.map +1 -1
- package/dist/mcp/tools/page-verify.js +3 -2
- package/dist/mcp/tools/page-verify.js.map +1 -1
- package/dist/mockup/fixtures.d.ts +1 -1
- package/dist/routes/system-state.d.ts +1 -1
- package/frontend-vue/eslint-globals.generated.mjs +259 -942
- package/frontend-vue/layers/dms-core/app/build/composables/api-error.ts +46 -23
- package/frontend-vue/layers/dms-core/app/build/composables/auth/usePermissionPreview.ts +34 -23
- package/frontend-vue/layers/dms-core/app/build/composables/user/preferencesCookie.ts +8 -2
- package/frontend-vue/layers/dms-core/app/build/composables/user/tablePreferences.ts +11 -5
- package/frontend-vue/layers/dms-core/app/build/utils/crossTab.ts +4 -2
- package/frontend-vue/layers/dms-core/app/build/utils/json.ts +31 -0
- package/frontend-vue/layers/dms-core/app/build/utils/permission-preview.ts +6 -11
- package/frontend-vue/layers/dms-core/app/build/utils/record.ts +4 -0
- package/frontend-vue/layers/dms-core/app/build/utils/sharedRealtimeConnection.ts +56 -36
- package/frontend-vue/layers/dms-core/app/composables/auth/useApiData.ts +2 -2
- package/frontend-vue/layers/dms-core/app/composables/auth/useAuthFetch.ts +6 -1
- package/frontend-vue/layers/dms-core/app/composables/auth/useCurrentUser.ts +3 -2
- package/frontend-vue/layers/dms-core/app/composables/auth/useLogout.ts +3 -2
- package/frontend-vue/layers/dms-core/app/composables/auth/useMultiAccount.ts +15 -14
- package/frontend-vue/layers/dms-core/app/composables/auth/useSessionRecovery.ts +21 -8
- package/frontend-vue/layers/dms-core/app/composables/data-types/useDataType.ts +3 -3
- package/frontend-vue/layers/dms-core/app/composables/page/useSiteLayout.ts +11 -9
- package/frontend-vue/layers/dms-core/app/composables/period/periodLink.ts +3 -2
- package/frontend-vue/layers/dms-core/app/composables/period/usePeriod.ts +2 -2
- package/frontend-vue/layers/dms-core/app/composables/realtime/usePageRealtime.ts +10 -3
- package/frontend-vue/layers/dms-core/app/composables/realtime/useSseStream.ts +22 -16
- package/frontend-vue/layers/dms-core/app/composables/realtime/useUserRealtime.ts +68 -46
- package/frontend-vue/layers/dms-core/app/composables/useApiErrorPresenter.ts +22 -11
- package/frontend-vue/layers/dms-core/app/composables/useEventedAction.ts +4 -1
- package/frontend-vue/layers/dms-core/app/composables/useFieldErrors.ts +14 -6
- package/frontend-vue/layers/dms-core/app/composables/user/usePreferences.ts +8 -3
- package/frontend-vue/layers/dms-core/app/composables/watch/useWatch.ts +17 -8
- package/frontend-vue/layers/dms-core/app/types/module-store.ts +3 -1
- package/frontend-vue/layers/dms-core/app/types/page.ts +3 -1
- package/frontend-vue/layers/dms-core/app/utils/dedupedRefresh.ts +2 -2
- package/frontend-vue/layers/dms-core/app/utils/formatter.ts +5 -5
- package/frontend-vue/layers/dms-core/app/utils/menu.ts +12 -4
- package/frontend-vue/layers/dms-core/app/utils/pageQuery.ts +7 -4
- package/frontend-vue/layers/dms-core/app/utils/row-action-rule-evaluator.ts +7 -3
- package/frontend-vue/layers/dms-core/app/utils/stringTypeParser.ts +8 -10
- package/frontend-vue/layers/dms-core/app/utils/type-check.ts +25 -12
- package/frontend-vue/layers/dms-ui/app/build/components/block-preview/MockupEditOverlay.vue +2 -2
- package/frontend-vue/layers/dms-ui/app/build/components/block-preview/MockupIndex.vue +1 -1
- package/frontend-vue/layers/dms-ui/app/build/components/block-preview/MockupInspector.vue +3 -2
- package/frontend-vue/layers/dms-ui/app/build/components/block-preview/MockupInspectorField.vue +5 -2
- package/frontend-vue/layers/dms-ui/app/build/components/containers/drawer/DynamicDrawer.vue +4 -3
- package/frontend-vue/layers/dms-ui/app/build/components/containers/modal/DynamicModal.vue +3 -2
- package/frontend-vue/layers/dms-ui/app/build/components/containers/row/RowHeader.vue +2 -1
- package/frontend-vue/layers/dms-ui/app/build/components/period/PeriodRangeCalendar.vue +10 -7
- package/frontend-vue/layers/dms-ui/app/build/components/sortable/SortableList.vue +2 -2
- package/frontend-vue/layers/dms-ui/app/build/components/table/FiltersRow.vue +20 -18
- package/frontend-vue/layers/dms-ui/app/build/components/table/MenuColumns.vue +2 -5
- package/frontend-vue/layers/dms-ui/app/build/components/table/MenuDensity.vue +3 -4
- package/frontend-vue/layers/dms-ui/app/build/components/table/MenuFilter.vue +3 -4
- package/frontend-vue/layers/dms-ui/app/build/components/table/MenuImport.vue +2 -5
- package/frontend-vue/layers/dms-ui/app/build/components/table/MenuPage.vue +2 -5
- package/frontend-vue/layers/dms-ui/app/build/components/table/MenuRoot.vue +3 -4
- package/frontend-vue/layers/dms-ui/app/build/components/table/MenuSort.vue +2 -5
- package/frontend-vue/layers/dms-ui/app/build/components/table/MenuViewMode.vue +21 -19
- package/frontend-vue/layers/dms-ui/app/build/components/table/RowSelection.vue +3 -4
- package/frontend-vue/layers/dms-ui/app/build/components/table/Table.types.ts +4 -4
- package/frontend-vue/layers/dms-ui/app/build/components/table/TableActions.vue +3 -4
- package/frontend-vue/layers/dms-ui/app/build/components/table/TableMenu.vue +3 -4
- package/frontend-vue/layers/dms-ui/app/build/components/table/TablePagination.vue +3 -4
- package/frontend-vue/layers/dms-ui/app/build/components/table/TableRoot.vue +3 -5
- package/frontend-vue/layers/dms-ui/app/build/components/table/TableTabs.vue +2 -5
- package/frontend-vue/layers/dms-ui/app/build/components/table/TableViews.vue +3 -4
- package/frontend-vue/layers/dms-ui/app/build/components/table/tableComponentFilters.ts +4 -4
- package/frontend-vue/layers/dms-ui/app/build/components/table/tableComponentPreferences.ts +4 -3
- package/frontend-vue/layers/dms-ui/app/build/components/table/tableComponentRows.ts +4 -3
- package/frontend-vue/layers/dms-ui/app/build/components/table/tableComponentTheme.ts +11 -0
- package/frontend-vue/layers/dms-ui/app/build/components/table-view/CardsDisplay.vue +35 -9
- package/frontend-vue/layers/dms-ui/app/build/mockups/MockupCards.vue +1 -1
- package/frontend-vue/layers/dms-ui/app/build/mockups/resync.ts +9 -1
- package/frontend-vue/layers/dms-ui/app/build/utils/blockPreview.ts +34 -25
- package/frontend-vue/layers/dms-ui/app/build/utils/blockPreviewMessages.ts +52 -26
- package/frontend-vue/layers/dms-ui/app/build/utils/calendarDay.ts +4 -1
- package/frontend-vue/layers/dms-ui/app/build/utils/characterCount.ts +1 -1
- package/frontend-vue/layers/dms-ui/app/build/utils/dispatchQuickActionTarget.ts +16 -11
- package/frontend-vue/layers/dms-ui/app/build/utils/fieldOptionsI18n.ts +23 -21
- package/frontend-vue/layers/dms-ui/app/build/utils/json.ts +74 -0
- package/frontend-vue/layers/dms-ui/app/build/utils/link.ts +2 -2
- package/frontend-vue/layers/dms-ui/app/build/utils/mockup.ts +4 -4
- package/frontend-vue/layers/dms-ui/app/build/utils/mockupCatalog.ts +59 -50
- package/frontend-vue/layers/dms-ui/app/build/utils/mockupDrop.ts +1 -1
- package/frontend-vue/layers/dms-ui/app/build/utils/mockupEdit.ts +8 -6
- package/frontend-vue/layers/dms-ui/app/build/utils/mockupSpec.ts +34 -28
- package/frontend-vue/layers/dms-ui/app/build/utils/mockupStamp.ts +11 -3
- package/frontend-vue/layers/dms-ui/app/build/utils/mockupStream.ts +5 -2
- package/frontend-vue/layers/dms-ui/app/build/utils/streamHighlight.ts +8 -6
- package/frontend-vue/layers/dms-ui/app/build/utils/urlVariables.ts +2 -1
- package/frontend-vue/layers/dms-ui/app/components/RecursiveComponent.vue +3 -6
- package/frontend-vue/layers/dms-ui/app/components/block-preview/BlockPreview.vue +5 -4
- package/frontend-vue/layers/dms-ui/app/components/blocks/BannerBlock.vue +1 -2
- package/frontend-vue/layers/dms-ui/app/components/card/NavCard.vue +4 -1
- package/frontend-vue/layers/dms-ui/app/components/chart/ApexChartHost.vue +62 -13
- package/frontend-vue/layers/dms-ui/app/components/chart/ChartBlock.vue +18 -6
- package/frontend-vue/layers/dms-ui/app/components/code-snippet/CodeSnippet.vue +9 -4
- package/frontend-vue/layers/dms-ui/app/components/confirm/ConfirmModal.vue +9 -6
- package/frontend-vue/layers/dms-ui/app/components/flow-canvas/FlowCanvas.vue +16 -18
- package/frontend-vue/layers/dms-ui/app/components/form/FormBlock.vue +4 -9
- package/frontend-vue/layers/dms-ui/app/components/form/LocalizedField.vue +2 -2
- package/frontend-vue/layers/dms-ui/app/components/form/components/InputAddress.vue +2 -2
- package/frontend-vue/layers/dms-ui/app/components/form/components/InputImage.vue +5 -8
- package/frontend-vue/layers/dms-ui/app/components/form/components/RichText.vue +3 -2
- package/frontend-vue/layers/dms-ui/app/components/master-detail/MasterDetail.vue +3 -1
- package/frontend-vue/layers/dms-ui/app/components/period/usePeriodSelectorInteraction.ts +9 -7
- package/frontend-vue/layers/dms-ui/app/components/table-view/KanbanBoard.vue +11 -6
- package/frontend-vue/layers/dms-ui/app/components/table-view/KanbanDisplay.vue +40 -3
- package/frontend-vue/layers/dms-ui/app/composables/chart/apexDatetimeBuckets.ts +9 -5
- package/frontend-vue/layers/dms-ui/app/composables/chart/events.ts +6 -3
- package/frontend-vue/layers/dms-ui/app/composables/chart/heatmapColors.ts +1 -1
- package/frontend-vue/layers/dms-ui/app/composables/chart/localizeSeries.ts +13 -2
- package/frontend-vue/layers/dms-ui/app/composables/chart/useApexChart.ts +27 -4
- package/frontend-vue/layers/dms-ui/app/composables/chart/useApexChart.types.ts +3 -2
- package/frontend-vue/layers/dms-ui/app/composables/chart/useChartFetch.ts +3 -4
- package/frontend-vue/layers/dms-ui/app/composables/confirm/types.ts +5 -1
- package/frontend-vue/layers/dms-ui/app/composables/containers/openDynamicContainer.ts +6 -6
- package/frontend-vue/layers/dms-ui/app/composables/containers/types.ts +1 -1
- package/frontend-vue/layers/dms-ui/app/composables/containers/useDrawer.ts +8 -5
- package/frontend-vue/layers/dms-ui/app/composables/containers/useModal.ts +1 -1
- package/frontend-vue/layers/dms-ui/app/composables/form/types/props.ts +5 -2
- package/frontend-vue/layers/dms-ui/app/composables/form/useForm.ts +80 -39
- package/frontend-vue/layers/dms-ui/app/composables/live/usePageLiveRefresh.ts +1 -1
- package/frontend-vue/layers/dms-ui/app/composables/resolveDmsComponent.ts +9 -2
- package/frontend-vue/layers/dms-ui/app/composables/tab/useTab.ts +2 -2
- package/frontend-vue/layers/dms-ui/app/composables/table-view/shortcuts/tableViewShiftA.ts +2 -2
- package/frontend-vue/layers/dms-ui/app/composables/table-view/types/action-target.ts +2 -1
- package/frontend-vue/layers/dms-ui/app/composables/table-view/types/column.ts +3 -1
- package/frontend-vue/layers/dms-ui/app/composables/table-view/types/display.ts +6 -2
- package/frontend-vue/layers/dms-ui/app/composables/table-view/useTableViewExport.ts +6 -5
- package/frontend-vue/layers/dms-ui/app/composables/unsaved-changes/useUnsavedChanges.ts +1 -1
- package/frontend-vue/layers/dms-ui/app/composables/useExportJob.ts +21 -9
- package/frontend-vue/layers/dms-ui/app/utils/blockRefresh.ts +8 -2
- package/frontend-vue/layers/dms-ui/app/utils/cascader.ts +18 -8
- package/frontend-vue/layers/dms-ui/app/utils/metadataRetry.ts +1 -1
- package/frontend-vue/package.json +2 -1
- package/frontend-vue/scripts/check-api-error-presentation.mjs +257 -117
- package/frontend-vue/scripts/check-autoimport-boundaries.mjs +143 -27
- package/frontend-vue/scripts/check-disable-blocks.mjs +26 -4
- package/frontend-vue/scripts/check-dms-components.mjs +152 -246
- package/frontend-vue/scripts/check-invariants.mjs +100 -42
- package/frontend-vue/scripts/check-page-invariants.mjs +103 -40
- package/frontend-vue/scripts/dms-components-dependencies.mjs +106 -13
- package/frontend-vue/scripts/dms-components-script.mjs +375 -0
- package/frontend-vue/scripts/eslint-test-quality.mjs +126 -0
- package/frontend-vue/scripts/jsconfig.json +10 -0
- package/frontend-vue/scripts/probes/capture-frontend-probe.cjs +4 -2
- package/frontend-vue/scripts/probes/frontend-behavior.cjs +217 -47
- package/frontend-vue/scripts/probes/frontend-legacy.cjs +159 -8
- package/frontend-vue/scripts/probes/frontend-probe-controls.cjs +89 -10
- package/frontend-vue/scripts/prove-comment-emit.mjs +33 -4
- package/frontend-vue/scripts/prove-component-registration.mjs +110 -24
- package/frontend-vue/scripts/test-autoimport-boundaries.mjs +37 -6
- package/frontend-vue/scripts/test-dms-components.mjs +51 -2
- package/package.json +5 -19
- package/dist/implementations/dms-builder/engine/access-mongodb.d.ts +0 -20
- package/dist/implementations/dms-builder/engine/access-mongodb.js +0 -30
- package/dist/implementations/dms-builder/engine/access-mongodb.js.map +0 -1
- package/dist/implementations/dms-builder/engine/access-mysql.d.ts +0 -8
- package/dist/implementations/dms-builder/engine/access-mysql.js +0 -11
- package/dist/implementations/dms-builder/engine/access-mysql.js.map +0 -1
- package/dist/implementations/dms-builder/engine/access-postgres.d.ts +0 -8
- package/dist/implementations/dms-builder/engine/access-postgres.js +0 -11
- package/dist/implementations/dms-builder/engine/access-postgres.js.map +0 -1
- package/dist/implementations/dms-builder/engine/probe-client.d.ts +0 -19
- package/dist/implementations/dms-builder/engine/probe-client.js +0 -50
- package/dist/implementations/dms-builder/engine/probe-client.js.map +0 -1
- package/dist/implementations/dms-builder/engine/probe-connections.d.ts +0 -10
- package/dist/implementations/dms-builder/engine/probe-connections.js +0 -43
- package/dist/implementations/dms-builder/engine/probe-connections.js.map +0 -1
- package/dist/implementations/dms-builder/engine/probe-mongodb.d.ts +0 -2
- package/dist/implementations/dms-builder/engine/probe-mongodb.js +0 -148
- package/dist/implementations/dms-builder/engine/probe-mongodb.js.map +0 -1
- package/dist/implementations/dms-builder/engine/probe-mysql.d.ts +0 -2
- package/dist/implementations/dms-builder/engine/probe-mysql.js +0 -189
- package/dist/implementations/dms-builder/engine/probe-mysql.js.map +0 -1
- package/dist/implementations/dms-builder/engine/probe-postgres.d.ts +0 -2
- package/dist/implementations/dms-builder/engine/probe-postgres.js +0 -164
- package/dist/implementations/dms-builder/engine/probe-postgres.js.map +0 -1
- package/dist/implementations/dms-builder/engine/probe-rethinkdb.d.ts +0 -2
- package/dist/implementations/dms-builder/engine/probe-rethinkdb.js +0 -92
- package/dist/implementations/dms-builder/engine/probe-rethinkdb.js.map +0 -1
- package/dist/implementations/dms-builder/engine/rethinkdb-client.d.ts +0 -34
- package/dist/implementations/dms-builder/engine/rethinkdb-client.js +0 -3
- package/dist/implementations/dms-builder/engine/rethinkdb-client.js.map +0 -1
- package/dist/implementations/dms-builder/engine/scram-bound.d.ts +0 -5
- package/dist/implementations/dms-builder/engine/scram-bound.js +0 -60
- package/dist/implementations/dms-builder/engine/scram-bound.js.map +0 -1
- package/frontend-vue/eslint-test-quality.mjs +0 -62
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { toRaw } from "vue";
|
|
2
2
|
import { z } from "zod";
|
|
3
|
+
import { isString } from "../../utils/type-check";
|
|
4
|
+
import { isRecord } from "../utils/record";
|
|
3
5
|
import type {
|
|
4
6
|
ApiErrorParams,
|
|
5
7
|
ApiErrorSeverity,
|
|
@@ -46,18 +48,29 @@ export interface DecodedApiFailure {
|
|
|
46
48
|
severity: ApiErrorSeverity;
|
|
47
49
|
}
|
|
48
50
|
|
|
49
|
-
|
|
51
|
+
/** What a failure is read from: anything thrown, as the schemas parse it. */
|
|
52
|
+
type FailureInput = Parameters<typeof recordSchema.safeParse>[0];
|
|
53
|
+
type FailureRecord = z.infer<typeof recordSchema>;
|
|
54
|
+
|
|
55
|
+
/** A response the backend answered with a failure status. */
|
|
56
|
+
interface FailedResponse {
|
|
57
|
+
raw: object;
|
|
58
|
+
data: FailureRecord["_data"];
|
|
59
|
+
status: number;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function record(value: FailureInput): FailureRecord | undefined {
|
|
50
63
|
return recordSchema.safeParse(value).data;
|
|
51
64
|
}
|
|
52
65
|
|
|
53
|
-
function decodeBody(input:
|
|
66
|
+
function decodeBody(input: FailureInput): DecodedBody {
|
|
54
67
|
let value = input;
|
|
55
68
|
let status: number | undefined;
|
|
56
69
|
const seen = new Set<unknown>();
|
|
57
70
|
for (let depth = 0; depth < MAX_DEPTH; depth++) {
|
|
58
71
|
if (seen.has(value)) return { status };
|
|
59
72
|
seen.add(value);
|
|
60
|
-
if (
|
|
73
|
+
if (isString(value)) {
|
|
61
74
|
const text = value;
|
|
62
75
|
try {
|
|
63
76
|
const parsed: unknown = JSON.parse(text);
|
|
@@ -85,12 +98,30 @@ function decodeBody(input: unknown): DecodedBody {
|
|
|
85
98
|
return { status };
|
|
86
99
|
}
|
|
87
100
|
|
|
101
|
+
function failedResponseOf(entry: FailureRecord): FailedResponse | undefined {
|
|
102
|
+
const response = record(entry.response);
|
|
103
|
+
const status = statusSchema.safeParse(response?.status).data;
|
|
104
|
+
if (!response || status === undefined || !isRecord(entry.response))
|
|
105
|
+
return undefined;
|
|
106
|
+
return { raw: entry.response, data: response._data, status };
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
function severityOf(
|
|
110
|
+
body: DecodedBody,
|
|
111
|
+
status: number | undefined,
|
|
112
|
+
): ApiErrorSeverity {
|
|
113
|
+
if (body.severity) return body.severity;
|
|
114
|
+
return status !== undefined && status <= HTTP_CLIENT_MAX
|
|
115
|
+
? "warning"
|
|
116
|
+
: "error";
|
|
117
|
+
}
|
|
118
|
+
|
|
88
119
|
/** @internal */
|
|
89
|
-
export function decodeApiFailure(error:
|
|
120
|
+
export function decodeApiFailure(error: FailureInput): DecodedApiFailure {
|
|
90
121
|
let current = error;
|
|
91
122
|
let identity: object | null = null;
|
|
92
123
|
let request: DecodedBody | undefined;
|
|
93
|
-
let local:
|
|
124
|
+
let local: FailureInput = error;
|
|
94
125
|
let status: number | undefined;
|
|
95
126
|
let cancelled = false;
|
|
96
127
|
let hasFailedResponse = false;
|
|
@@ -103,27 +134,21 @@ export function decodeApiFailure(error: unknown): DecodedApiFailure {
|
|
|
103
134
|
local = current;
|
|
104
135
|
break;
|
|
105
136
|
}
|
|
106
|
-
if (current
|
|
107
|
-
identity = toRaw(current);
|
|
137
|
+
if (isRecord(current)) identity = toRaw(current);
|
|
108
138
|
local = entry.message;
|
|
109
139
|
params ??= paramsSchema.safeParse(entry.params).data;
|
|
110
140
|
cancelled ||= entry.name === "AbortError";
|
|
111
|
-
const
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
if (
|
|
117
|
-
entry.response &&
|
|
118
|
-
responseStatus !== undefined &&
|
|
119
|
-
typeof entry.response === "object"
|
|
120
|
-
) {
|
|
121
|
-
identity = toRaw(entry.response);
|
|
122
|
-
request = decodeBody(entry.data ?? response?._data);
|
|
123
|
-
status = responseStatus;
|
|
141
|
+
const failed = failedResponseOf(entry);
|
|
142
|
+
if (failed) {
|
|
143
|
+
identity = toRaw(failed.raw);
|
|
144
|
+
request = decodeBody(entry.data ?? failed.data);
|
|
145
|
+
status = failed.status;
|
|
124
146
|
hasFailedResponse = true;
|
|
125
147
|
break;
|
|
126
148
|
}
|
|
149
|
+
const entryStatus = statusSchema.safeParse(
|
|
150
|
+
entry.statusCode ?? entry.status,
|
|
151
|
+
).data;
|
|
127
152
|
if (entry.data !== undefined || entryStatus !== undefined) {
|
|
128
153
|
request = decodeBody(entry.data);
|
|
129
154
|
status = entryStatus;
|
|
@@ -138,8 +163,6 @@ export function decodeApiFailure(error: unknown): DecodedApiFailure {
|
|
|
138
163
|
identity,
|
|
139
164
|
key: body.key,
|
|
140
165
|
params: { ...params, ...body.params },
|
|
141
|
-
severity:
|
|
142
|
-
body.severity ??
|
|
143
|
-
(status !== undefined && status <= HTTP_CLIENT_MAX ? "warning" : "error"),
|
|
166
|
+
severity: severityOf(body, status),
|
|
144
167
|
};
|
|
145
168
|
}
|
|
@@ -154,6 +154,33 @@ function createPreviewSharing() {
|
|
|
154
154
|
return { start, update, readSession, takeIdFromLocation };
|
|
155
155
|
}
|
|
156
156
|
|
|
157
|
+
/**
|
|
158
|
+
* Turn this tab into a preview when it was opened as one (or reloaded while
|
|
159
|
+
* being one), and follow the session other tabs write. Returns whether it did.
|
|
160
|
+
*/
|
|
161
|
+
function activatePreviewTab(
|
|
162
|
+
state: ReturnType<typeof usePreviewState>,
|
|
163
|
+
sharing: ReturnType<typeof createPreviewSharing>,
|
|
164
|
+
): boolean {
|
|
165
|
+
const id =
|
|
166
|
+
sharing.takeIdFromLocation() ??
|
|
167
|
+
readStorage(sessionStorage, PERMISSION_PREVIEW_TAB_KEY);
|
|
168
|
+
if (!id) return false;
|
|
169
|
+
const session = sharing.readSession(id);
|
|
170
|
+
if (!session) {
|
|
171
|
+
removeStorage(sessionStorage, PERMISSION_PREVIEW_TAB_KEY);
|
|
172
|
+
return false;
|
|
173
|
+
}
|
|
174
|
+
writeStorage(sessionStorage, PERMISSION_PREVIEW_TAB_KEY, id);
|
|
175
|
+
state.session.value = session;
|
|
176
|
+
window.addEventListener("storage", (event) => {
|
|
177
|
+
if (event.key !== storageKey(id) || !state.session.value) return;
|
|
178
|
+
const next = parsePreviewSession(event.newValue);
|
|
179
|
+
if (next) state.session.value = next;
|
|
180
|
+
});
|
|
181
|
+
return true;
|
|
182
|
+
}
|
|
183
|
+
|
|
157
184
|
/**
|
|
158
185
|
* "Preview as role": the roles editor opens a tab that browses the real
|
|
159
186
|
* dashboard as a role would see it — its unsaved edits included. The server
|
|
@@ -166,7 +193,7 @@ function createPreviewSharing() {
|
|
|
166
193
|
*/
|
|
167
194
|
export function usePermissionPreview() {
|
|
168
195
|
const state = usePreviewState();
|
|
169
|
-
const
|
|
196
|
+
const errorPresenter = useApiErrorPresenter();
|
|
170
197
|
const isActive = computed(() => state.session.value !== null);
|
|
171
198
|
const hiddenEntries = computed(
|
|
172
199
|
() => new Set(state.result.value?.hiddenEntries ?? []),
|
|
@@ -219,31 +246,15 @@ export function usePermissionPreview() {
|
|
|
219
246
|
return isPreviewEntryLocked(isActive.value, hiddenQuickActions.value, key);
|
|
220
247
|
}
|
|
221
248
|
|
|
222
|
-
const
|
|
223
|
-
|
|
249
|
+
const sharing = createPreviewSharing();
|
|
250
|
+
const { start, update } = sharing;
|
|
224
251
|
|
|
225
252
|
/**
|
|
226
253
|
* Turn this tab into a preview when it was opened as one (or reloaded while
|
|
227
254
|
* being one). Returns whether it did.
|
|
228
255
|
*/
|
|
229
256
|
function activate(): boolean {
|
|
230
|
-
|
|
231
|
-
takeIdFromLocation() ??
|
|
232
|
-
readStorage(sessionStorage, PERMISSION_PREVIEW_TAB_KEY);
|
|
233
|
-
if (!id) return false;
|
|
234
|
-
const session = readSession(id);
|
|
235
|
-
if (!session) {
|
|
236
|
-
removeStorage(sessionStorage, PERMISSION_PREVIEW_TAB_KEY);
|
|
237
|
-
return false;
|
|
238
|
-
}
|
|
239
|
-
writeStorage(sessionStorage, PERMISSION_PREVIEW_TAB_KEY, id);
|
|
240
|
-
state.session.value = session;
|
|
241
|
-
window.addEventListener("storage", (event) => {
|
|
242
|
-
if (event.key !== storageKey(id) || !state.session.value) return;
|
|
243
|
-
const next = parsePreviewSession(event.newValue);
|
|
244
|
-
if (next) state.session.value = next;
|
|
245
|
-
});
|
|
246
|
-
return true;
|
|
257
|
+
return activatePreviewTab(state, sharing);
|
|
247
258
|
}
|
|
248
259
|
|
|
249
260
|
/** Ask the server what the role changes on the menu and on `path`. */
|
|
@@ -264,7 +275,7 @@ export function usePermissionPreview() {
|
|
|
264
275
|
} catch (error) {
|
|
265
276
|
if (current !== refreshGeneration) return;
|
|
266
277
|
state.failed.value = true;
|
|
267
|
-
presentError(error, {
|
|
278
|
+
errorPresenter.presentError(error, {
|
|
268
279
|
fallbackKey: "page.settings.roles.preview.failed",
|
|
269
280
|
});
|
|
270
281
|
} finally {
|
|
@@ -282,8 +293,8 @@ export function usePermissionPreview() {
|
|
|
282
293
|
removeStorage(localStorage, storageKey(session.id));
|
|
283
294
|
window.close();
|
|
284
295
|
|
|
285
|
-
setTimeout(() => {
|
|
286
|
-
|
|
296
|
+
setTimeout(async () => {
|
|
297
|
+
await navigateDms(session.returnTo);
|
|
287
298
|
}, CLOSE_FALLBACK_DELAY_MS);
|
|
288
299
|
}
|
|
289
300
|
|
|
@@ -134,8 +134,14 @@ export const writeAt = (
|
|
|
134
134
|
const lastKey = keys.at(-1)!;
|
|
135
135
|
let current = tree;
|
|
136
136
|
for (const key of keys.slice(0, -1)) {
|
|
137
|
-
|
|
138
|
-
|
|
137
|
+
const next = current[key];
|
|
138
|
+
if (isBranch(next)) {
|
|
139
|
+
current = next;
|
|
140
|
+
continue;
|
|
141
|
+
}
|
|
142
|
+
const branch: PreferencesTree = {};
|
|
143
|
+
current[key] = branch;
|
|
144
|
+
current = branch;
|
|
139
145
|
}
|
|
140
146
|
current[lastKey] = value;
|
|
141
147
|
};
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { isRecord } from "../../utils/record";
|
|
1
2
|
import { isBranch, type PreferencesTree } from "./preferencesCookie";
|
|
2
3
|
import { isNumber, isString } from "../../../utils/type-check";
|
|
3
4
|
|
|
@@ -154,10 +155,10 @@ const isSameValue = (
|
|
|
154
155
|
const encodeFilters: ServerFieldCodec["encode"] = (value) =>
|
|
155
156
|
(Array.isArray(value) ? value : [])
|
|
156
157
|
.filter(
|
|
157
|
-
(filter) =>
|
|
158
|
+
(filter: FilterEntry) =>
|
|
158
159
|
!filter.pinned || !isSameValue(filter.value, filter.initialValue),
|
|
159
160
|
)
|
|
160
|
-
.map((filter) =>
|
|
161
|
+
.map((filter: FilterEntry) =>
|
|
161
162
|
filter.mode === DEFAULT_FILTER_MODE
|
|
162
163
|
? [filter.accessorKey, filter.value ?? null]
|
|
163
164
|
: [filter.accessorKey, filter.value ?? null, filter.mode],
|
|
@@ -196,17 +197,22 @@ const decodeVisibility: ServerFieldCodec["decode"] = (stored, defaultValue) => {
|
|
|
196
197
|
return { ...visibilityOf(defaultValue), ...Object.fromEntries(changes) };
|
|
197
198
|
};
|
|
198
199
|
|
|
200
|
+
const isPaginationEntry = (value: unknown): value is PaginationEntry =>
|
|
201
|
+
isRecord(value) && isNumber(value.pageIndex) && isNumber(value.pageSize);
|
|
202
|
+
|
|
199
203
|
const encodePagination: ServerFieldCodec["encode"] = (value) => {
|
|
200
|
-
|
|
204
|
+
if (!isPaginationEntry(value)) return undefined;
|
|
205
|
+
const { pageIndex, pageSize } = value;
|
|
201
206
|
return pageIndex === FIRST_PAGE_INDEX ? pageSize : [pageSize, pageIndex];
|
|
202
207
|
};
|
|
203
208
|
|
|
204
209
|
const decodePagination = (
|
|
205
210
|
stored: Parameters<ServerFieldCodec["decode"]>[0],
|
|
206
211
|
): PaginationEntry => {
|
|
207
|
-
const [
|
|
212
|
+
const pair: unknown[] = Array.isArray(stored)
|
|
208
213
|
? stored
|
|
209
214
|
: [stored, FIRST_PAGE_INDEX];
|
|
215
|
+
const [pageSize, pageIndex] = pair;
|
|
210
216
|
if (!isNumber(pageSize) || !isNumber(pageIndex)) {
|
|
211
217
|
throw new TypeError("pagination");
|
|
212
218
|
}
|
|
@@ -245,7 +251,7 @@ export const SERVER_TABLE_FIELDS: Record<ServerTableField, ServerFieldCodec> = {
|
|
|
245
251
|
/** @internal Whether `field` is kept in the cookie. */
|
|
246
252
|
export const isServerTableField = (
|
|
247
253
|
field: TableField,
|
|
248
|
-
): field is ServerTableField => field
|
|
254
|
+
): field is ServerTableField => Object.hasOwn(SERVER_TABLE_FIELDS, field);
|
|
249
255
|
|
|
250
256
|
/**
|
|
251
257
|
* @internal
|
|
@@ -61,7 +61,7 @@ export function openTabBus(
|
|
|
61
61
|
): TabBus {
|
|
62
62
|
const listeners = new Set<TabMessageHandler>();
|
|
63
63
|
const deliver = (message: Parameters<TabMessageHandler>[0]) => {
|
|
64
|
-
for (const listener of
|
|
64
|
+
for (const listener of Array.from(listeners)) listener(message);
|
|
65
65
|
};
|
|
66
66
|
const channel = canShareAcrossTabs(environment)
|
|
67
67
|
? environment.createChannel!(name)
|
|
@@ -190,7 +190,9 @@ export function shareAcrossTabs(
|
|
|
190
190
|
): () => void {
|
|
191
191
|
const bus = openTabBus(name, environment);
|
|
192
192
|
const unlisten = bus.listen(onMessage);
|
|
193
|
-
const resign = electLeader(name, environment, () =>
|
|
193
|
+
const resign = electLeader(name, environment, () =>
|
|
194
|
+
open((message) => bus.post(message)),
|
|
195
|
+
);
|
|
194
196
|
return () => {
|
|
195
197
|
resign();
|
|
196
198
|
unlisten();
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { JsonValue } from "../../types/json";
|
|
2
|
+
|
|
3
|
+
/** A JSON object: each value it holds is JSON. */
|
|
4
|
+
export type JsonObject = { [key: string]: JsonValue };
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Whether `value` and every value it holds is JSON, walked without recursion
|
|
8
|
+
* so that no nesting depth `JSON.parse` accepts exhausts the stack.
|
|
9
|
+
*/
|
|
10
|
+
export function isJsonValue(value: unknown): value is JsonValue {
|
|
11
|
+
const pending: unknown[] = [value];
|
|
12
|
+
while (pending.length > 0) {
|
|
13
|
+
const next = pending.pop();
|
|
14
|
+
if (next === null || ["string", "number", "boolean"].includes(typeof next))
|
|
15
|
+
continue;
|
|
16
|
+
if (typeof next !== "object") return false;
|
|
17
|
+
for (const held of Array.isArray(next) ? next : Object.values(next))
|
|
18
|
+
pending.push(held);
|
|
19
|
+
}
|
|
20
|
+
return true;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/** Whether `value` is a JSON object, not an array or a primitive. */
|
|
24
|
+
export function isJsonObject(value: unknown): value is JsonObject {
|
|
25
|
+
return (
|
|
26
|
+
typeof value === "object" &&
|
|
27
|
+
value !== null &&
|
|
28
|
+
!Array.isArray(value) &&
|
|
29
|
+
isJsonValue(value)
|
|
30
|
+
);
|
|
31
|
+
}
|
|
@@ -183,12 +183,11 @@ export function quickActionKey(action: {
|
|
|
183
183
|
|
|
184
184
|
/**
|
|
185
185
|
* What `applyPreviewLocks` reads from a menu entry. Children are walked as
|
|
186
|
-
* entries of the same kind
|
|
187
|
-
* same `fullId` at runtime).
|
|
186
|
+
* entries of the same kind, `Child`.
|
|
188
187
|
*/
|
|
189
|
-
export interface PreviewLockableEntry {
|
|
188
|
+
export interface PreviewLockableEntry<Child = object> {
|
|
190
189
|
fullId?: string;
|
|
191
|
-
children?: readonly
|
|
190
|
+
children?: readonly Child[];
|
|
192
191
|
}
|
|
193
192
|
|
|
194
193
|
/**
|
|
@@ -196,7 +195,7 @@ export interface PreviewLockableEntry {
|
|
|
196
195
|
* pass each entry the preview locks to `lock`. Labels, collapsed groups and
|
|
197
196
|
* nested entries are all visited; an entry without a `fullId` is left as is.
|
|
198
197
|
*/
|
|
199
|
-
export function applyPreviewLocks<T extends PreviewLockableEntry
|
|
198
|
+
export function applyPreviewLocks<T extends PreviewLockableEntry<T>>(
|
|
200
199
|
items: readonly T[],
|
|
201
200
|
isLocked: (fullId: string | undefined) => boolean,
|
|
202
201
|
lock: (item: T) => T,
|
|
@@ -212,18 +211,14 @@ export function applyPreviewLocks<T extends PreviewLockableEntry>(
|
|
|
212
211
|
* Walk a menu like `applyPreviewLocks`, passing each entry with a preview
|
|
213
212
|
* state (refused or partial) to `decorate` along with that state.
|
|
214
213
|
*/
|
|
215
|
-
export function applyPreviewEntryStates<T extends PreviewLockableEntry
|
|
214
|
+
export function applyPreviewEntryStates<T extends PreviewLockableEntry<T>>(
|
|
216
215
|
items: readonly T[],
|
|
217
216
|
stateOf: (fullId: string | undefined) => PreviewEntryState | null,
|
|
218
217
|
decorate: (item: T, state: PreviewEntryState) => T,
|
|
219
218
|
): T[] {
|
|
220
219
|
return items.map((item) => {
|
|
221
220
|
const children = item.children
|
|
222
|
-
? applyPreviewEntryStates(
|
|
223
|
-
item.children as readonly T[],
|
|
224
|
-
stateOf,
|
|
225
|
-
decorate,
|
|
226
|
-
)
|
|
221
|
+
? applyPreviewEntryStates(item.children, stateOf, decorate)
|
|
227
222
|
: undefined;
|
|
228
223
|
const visited = children ? { ...item, children } : item;
|
|
229
224
|
const state = stateOf(item.fullId);
|
|
@@ -4,7 +4,7 @@ import {
|
|
|
4
4
|
type SseEventHandler,
|
|
5
5
|
type SseStreamHandle,
|
|
6
6
|
} from "../../composables/realtime/useSseStream";
|
|
7
|
-
import { isString } from "../../utils/type-check";
|
|
7
|
+
import { isString, isUndefined } from "../../utils/type-check";
|
|
8
8
|
import {
|
|
9
9
|
browserCrossTabEnvironment,
|
|
10
10
|
type CrossTabEnvironment,
|
|
@@ -15,6 +15,7 @@ import {
|
|
|
15
15
|
tabLockName,
|
|
16
16
|
whenReleased,
|
|
17
17
|
} from "./crossTab";
|
|
18
|
+
import { isRecord } from "./record";
|
|
18
19
|
|
|
19
20
|
/**
|
|
20
21
|
* The realtime connection one browser shares between its tabs: the elected tab
|
|
@@ -77,6 +78,33 @@ type HubMessage =
|
|
|
77
78
|
| SessionMessage
|
|
78
79
|
| ReopenMessage;
|
|
79
80
|
|
|
81
|
+
/** Whether `value` is a message of the hub, with the fields its `kind` has. */
|
|
82
|
+
function isHubMessage(value: unknown): value is HubMessage {
|
|
83
|
+
if (!isRecord(value)) return false;
|
|
84
|
+
switch (value.kind) {
|
|
85
|
+
case "query":
|
|
86
|
+
return true;
|
|
87
|
+
case "connection":
|
|
88
|
+
return value.connectionId === null || isString(value.connectionId);
|
|
89
|
+
case "reopen":
|
|
90
|
+
return isString(value.connectionId);
|
|
91
|
+
case "session":
|
|
92
|
+
return (
|
|
93
|
+
isString(value.connectionId) &&
|
|
94
|
+
isString(value.sessionId) &&
|
|
95
|
+
isString(value.tabId)
|
|
96
|
+
);
|
|
97
|
+
case "frame":
|
|
98
|
+
return (
|
|
99
|
+
isString(value.connectionId) &&
|
|
100
|
+
isString(value.event) &&
|
|
101
|
+
(isUndefined(value.sessionId) || isString(value.sessionId))
|
|
102
|
+
);
|
|
103
|
+
default:
|
|
104
|
+
return false;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
80
108
|
export interface StreamRecovery {
|
|
81
109
|
refreshSession: () => Promise<boolean>;
|
|
82
110
|
redirectToAuth: () => Promise<void>;
|
|
@@ -159,13 +187,12 @@ export const recoverFromError = (
|
|
|
159
187
|
retry();
|
|
160
188
|
return;
|
|
161
189
|
}
|
|
162
|
-
void recovery
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
}, retry);
|
|
190
|
+
void recovery
|
|
191
|
+
.refreshSession()
|
|
192
|
+
.then(
|
|
193
|
+
(isRefreshed) => (isRefreshed ? retry() : recovery.redirectToAuth()),
|
|
194
|
+
retry,
|
|
195
|
+
);
|
|
169
196
|
};
|
|
170
197
|
|
|
171
198
|
interface StreamCallbacks extends StreamRecovery {
|
|
@@ -237,17 +264,11 @@ const connectWithBackoff = (
|
|
|
237
264
|
const readConnectionId = (
|
|
238
265
|
data: Parameters<SseEventHandler>[1],
|
|
239
266
|
): string | null => {
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
267
|
+
return isRecord(data) && isString(data.connectionId)
|
|
268
|
+
? data.connectionId
|
|
269
|
+
: null;
|
|
243
270
|
};
|
|
244
271
|
|
|
245
|
-
interface SessionFrame {
|
|
246
|
-
sessionId?: unknown;
|
|
247
|
-
event?: unknown;
|
|
248
|
-
data?: unknown;
|
|
249
|
-
}
|
|
250
|
-
|
|
251
272
|
interface LeaderContext {
|
|
252
273
|
options: SharedRealtimeConnectionOptions;
|
|
253
274
|
environment: CrossTabEnvironment;
|
|
@@ -309,8 +330,8 @@ const lead = ({ options, environment, bus, tabId }: LeaderContext) => {
|
|
|
309
330
|
);
|
|
310
331
|
};
|
|
311
332
|
|
|
312
|
-
const unlisten = bus.listen((
|
|
313
|
-
|
|
333
|
+
const unlisten = bus.listen((message) => {
|
|
334
|
+
if (!isHubMessage(message)) return;
|
|
314
335
|
if (message.kind === "query")
|
|
315
336
|
bus.post({ kind: "connection", connectionId });
|
|
316
337
|
if (message.kind === "session") watchSession(message);
|
|
@@ -336,15 +357,15 @@ const lead = ({ options, environment, bus, tabId }: LeaderContext) => {
|
|
|
336
357
|
bus.post({ kind: "frame", connectionId, event: eventName, data });
|
|
337
358
|
return;
|
|
338
359
|
}
|
|
339
|
-
|
|
340
|
-
if (!isString(
|
|
341
|
-
if (!isString(
|
|
360
|
+
if (!isRecord(data)) return;
|
|
361
|
+
if (!isString(data.sessionId)) return;
|
|
362
|
+
if (!isString(data.event)) return;
|
|
342
363
|
bus.post({
|
|
343
364
|
kind: "frame",
|
|
344
365
|
connectionId,
|
|
345
|
-
sessionId:
|
|
346
|
-
event:
|
|
347
|
-
data:
|
|
366
|
+
sessionId: data.sessionId,
|
|
367
|
+
event: data.event,
|
|
368
|
+
data: data.data,
|
|
348
369
|
});
|
|
349
370
|
},
|
|
350
371
|
onDisconnected: () => publish(null),
|
|
@@ -378,8 +399,8 @@ export function joinSharedRealtimeConnection(
|
|
|
378
399
|
const tabLock = holdLock(tabLockName(options.name, tabId), environment);
|
|
379
400
|
let connectionId: string | undefined;
|
|
380
401
|
|
|
381
|
-
const unlisten = bus.listen((
|
|
382
|
-
|
|
402
|
+
const unlisten = bus.listen((message) => {
|
|
403
|
+
if (!isHubMessage(message)) return;
|
|
383
404
|
if (message.kind === "connection") {
|
|
384
405
|
const next = message.connectionId ?? undefined;
|
|
385
406
|
if (next === connectionId) return;
|
|
@@ -398,15 +419,14 @@ export function joinSharedRealtimeConnection(
|
|
|
398
419
|
bus.post({ kind: "query" });
|
|
399
420
|
|
|
400
421
|
return {
|
|
401
|
-
announceSession: (sessionConnectionId, sessionId) => {
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
);
|
|
422
|
+
announceSession: async (sessionConnectionId, sessionId) => {
|
|
423
|
+
await tabLock.held;
|
|
424
|
+
bus.post({
|
|
425
|
+
kind: "session",
|
|
426
|
+
connectionId: sessionConnectionId,
|
|
427
|
+
sessionId,
|
|
428
|
+
tabId,
|
|
429
|
+
});
|
|
410
430
|
},
|
|
411
431
|
reopen: (reopenedConnectionId) =>
|
|
412
432
|
bus.post({ kind: "reopen", connectionId: reopenedConnectionId }),
|
|
@@ -144,7 +144,7 @@ function followLivePause<
|
|
|
144
144
|
>(result: R, options: PolledReadOptions | undefined): R {
|
|
145
145
|
if (typeof window === "undefined" || !isGatedPolling(options)) return result;
|
|
146
146
|
let pausedAt = 0;
|
|
147
|
-
watch(useLivePauseSource(), (isPaused) => {
|
|
147
|
+
watch(useLivePauseSource(), async (isPaused) => {
|
|
148
148
|
if (isPaused) {
|
|
149
149
|
pausedAt = Date.now();
|
|
150
150
|
return;
|
|
@@ -153,7 +153,7 @@ function followLivePause<
|
|
|
153
153
|
if (!period || period <= 0 || Date.now() - pausedAt < period) return;
|
|
154
154
|
|
|
155
155
|
if (result.status.value === "idle" && options.immediate === false) return;
|
|
156
|
-
|
|
156
|
+
await result.refresh({ dedupe: "defer" });
|
|
157
157
|
});
|
|
158
158
|
return result;
|
|
159
159
|
}
|
|
@@ -30,7 +30,12 @@ function withRetryHeader(
|
|
|
30
30
|
return merged;
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
-
|
|
33
|
+
/** A failed request the backend answered with a 401. */
|
|
34
|
+
interface UnauthorizedError {
|
|
35
|
+
response: { status: typeof HTTP_UNAUTHORIZED };
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function isUnauthorized(error: unknown): error is UnauthorizedError {
|
|
34
39
|
if (!isObject(error) || error === null) return false;
|
|
35
40
|
const { response } = error;
|
|
36
41
|
return (
|
|
@@ -8,11 +8,12 @@
|
|
|
8
8
|
* profile edit propagates immediately without re-logging in.
|
|
9
9
|
*/
|
|
10
10
|
export function useCurrentUser() {
|
|
11
|
-
const
|
|
11
|
+
const userSession = useDmsUserSession<User>();
|
|
12
|
+
const { user } = userSession;
|
|
12
13
|
const { syncActiveAccount } = useMultiAccount();
|
|
13
14
|
|
|
14
15
|
async function refresh(): Promise<void> {
|
|
15
|
-
await
|
|
16
|
+
await userSession.fetch();
|
|
16
17
|
syncActiveAccount();
|
|
17
18
|
}
|
|
18
19
|
|
|
@@ -13,7 +13,8 @@ const FALLBACK_AUTH_ROUTE = "/auth";
|
|
|
13
13
|
* Any "Preview as role" state goes too.
|
|
14
14
|
*/
|
|
15
15
|
export function useLogout() {
|
|
16
|
-
const
|
|
16
|
+
const userSession = useDmsUserSession<User>();
|
|
17
|
+
const { user } = userSession;
|
|
17
18
|
const { accounts, removeAccount } = useMultiAccount();
|
|
18
19
|
const { purge: purgePermissionPreviews } = usePermissionPreview();
|
|
19
20
|
|
|
@@ -21,7 +22,7 @@ export function useLogout() {
|
|
|
21
22
|
const userId = user.value?._id;
|
|
22
23
|
|
|
23
24
|
purgePermissionPreviews();
|
|
24
|
-
await
|
|
25
|
+
await userSession.clear();
|
|
25
26
|
if (userId) {
|
|
26
27
|
await removeAccount(userId);
|
|
27
28
|
}
|
|
@@ -5,6 +5,7 @@ import type {
|
|
|
5
5
|
ValidateAccountResponse,
|
|
6
6
|
} from "../../types/auth";
|
|
7
7
|
import { uniqueAccounts, withAccount } from "../../build/utils/storedAccounts";
|
|
8
|
+
import { isNumber } from "../../utils/type-check";
|
|
8
9
|
|
|
9
10
|
const STORAGE_KEY = "antelopejs-accounts";
|
|
10
11
|
const SWITCH_ACCOUNT_ENDPOINT = "/auth/switch-account";
|
|
@@ -59,16 +60,18 @@ interface BrowserSession {
|
|
|
59
60
|
|
|
60
61
|
const TOKEN_REJECTION_STATUSES = new Set([400, 401, 403]);
|
|
61
62
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
statusCode?: number;
|
|
65
|
-
}
|
|
63
|
+
/** A thrown value whose upstream status, `statusCode` or else `status`, is a number. */
|
|
64
|
+
type UpstreamError = { statusCode: number } | { status: number };
|
|
66
65
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
66
|
+
/** Whether `error` is the backend refusing the account's tokens: a 400, 401 or 403. */
|
|
67
|
+
function isTokenRejection(error: unknown): error is UpstreamError {
|
|
68
|
+
if (typeof error !== "object" && typeof error !== "function") return false;
|
|
69
|
+
if (error === null) return false;
|
|
70
|
+
const statusCode = "statusCode" in error ? error.statusCode : undefined;
|
|
71
|
+
const upstreamStatus =
|
|
72
|
+
statusCode ?? ("status" in error ? error.status : undefined);
|
|
70
73
|
return (
|
|
71
|
-
upstreamStatus
|
|
74
|
+
isNumber(upstreamStatus) && TOKEN_REJECTION_STATUSES.has(upstreamStatus)
|
|
72
75
|
);
|
|
73
76
|
}
|
|
74
77
|
|
|
@@ -122,7 +125,7 @@ async function requestAccountSwitch(account: StoredAccount) {
|
|
|
122
125
|
* @internal
|
|
123
126
|
*/
|
|
124
127
|
export async function refreshSessionSurfaces(
|
|
125
|
-
refreshUser: () => Promise<
|
|
128
|
+
refreshUser: () => Promise<any>,
|
|
126
129
|
): Promise<void> {
|
|
127
130
|
await refreshUser();
|
|
128
131
|
|
|
@@ -192,11 +195,9 @@ function createValidateAllAccounts(
|
|
|
192
195
|
|
|
193
196
|
export function useMultiAccount() {
|
|
194
197
|
const accounts = useAccountsStorage();
|
|
195
|
-
const
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
fetch: refreshUser,
|
|
199
|
-
} = useDmsUserSession<User, BrowserSession>();
|
|
198
|
+
const userSession = useDmsUserSession<User, BrowserSession>();
|
|
199
|
+
const { user, session } = userSession;
|
|
200
|
+
const refreshUser = () => userSession.fetch();
|
|
200
201
|
|
|
201
202
|
const getActiveAccount = (): StoredAccount | undefined =>
|
|
202
203
|
buildActiveAccount(user.value, session.value?.accountId);
|