@lowdefy/server-dev 7.1.0 → 7.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/client/Inspector.jsx +24 -75
- package/client/Page.jsx +8 -0
- package/client/Routing.jsx +0 -2
- package/client/clientBuildImports.test.mjs +5 -3
- package/client/devStreamConnections.test.mjs +1 -0
- package/client/journeyObserver/startJourneyObserver.test.mjs +11 -11
- package/client/openInEditor/OpenInEditorListener.jsx +36 -29
- package/client/openInEditor/OpenInEditorListener.test.mjs +116 -0
- package/client/{feedback → openInEditor}/elementInspect.js +9 -44
- package/client/openInEditor/findBlockLocation.js +2 -2
- package/client/openInEditor/openInEditorStyles.js +56 -0
- package/client/recorder/createPairingBuffer.test.mjs +27 -9
- package/client/recorder/createRecorder.js +11 -7
- package/client/recorder/createRecorder.test.mjs +9 -9
- package/client/recorder/isPasswordElement.js +41 -0
- package/client/recorder/keyChord.test.mjs +1 -0
- package/{client/recorder/toJsonSafe.js → lib/build/mobileConfig.js} +9 -12
- package/lib/client/auth/AuthConfigured.jsx +75 -48
- package/lib/client/auth/authNotConfiguredParity.test.mjs +1 -0
- package/lib/client/auth/authTemplateSync.test.mjs +1 -0
- package/lib/client/auth/betterAuthSessionContract.test.mjs +2 -1
- package/lib/client/auth/sessionCaller.js +56 -0
- package/lib/client/auth/sessionCaller.test.mjs +78 -0
- package/lib/client/getPagePath.test.mjs +1 -0
- package/lib/client/utils/formatErrorsForCopy.test.mjs +1 -0
- package/lib/client/utils/getErrorBarColor.test.mjs +1 -0
- package/lib/client/utils/usePageConfig.test.mjs +15 -15
- package/lib/configTree/buildConfigTree.test.mjs +6 -8
- package/lib/configTree/collectConfigText.test.mjs +1 -0
- package/lib/configTree/runConfigTreeBuild.mjs +2 -1
- package/lib/configTree/runConfigTreeBuild.skipPluginChecks.test.mjs +11 -11
- package/lib/configTree/runConfigTreeBuild.test.mjs +2 -2
- package/lib/docs/addNestedEndpoints.test.mjs +1 -0
- package/lib/docs/checkAgentFiles.test.mjs +1 -0
- package/lib/docs/checkStepReferences.test.mjs +3 -3
- package/lib/docs/clientErrorStore.test.mjs +4 -4
- package/lib/docs/createBrowserLifecycle.test.mjs +40 -24
- package/lib/docs/createDocsMcpServer.js +195 -138
- package/lib/docs/createDocsMcpServer.test.mjs +331 -25
- package/lib/docs/createDocsMcpServerRunJourney.test.mjs +5 -5
- package/lib/docs/createJourneyActors.chromium.test.mjs +3 -3
- package/lib/docs/createJourneyActors.test.mjs +4 -4
- package/lib/docs/dataSets/dataSetJourneys.chromium.mongodb.test.mjs +6 -6
- package/lib/docs/dataSets/drainSessionWork.test.mjs +21 -5
- package/lib/docs/dataSets/getDataStore.js +11 -3
- package/lib/docs/dataSets/getDataStore.mongodb.test.mjs +3 -3
- package/lib/docs/dataSets/getDataStore.test.mjs +32 -20
- package/lib/docs/dataSets/mergeCollectionIndexes.test.mjs +1 -0
- package/lib/docs/dataSets/openDataSession.js +4 -2
- package/lib/docs/dataSets/openDataSession.mongodb.test.mjs +25 -7
- package/lib/docs/dataSets/pickDataStorePort.test.mjs +2 -2
- package/lib/docs/dataSets/readDataSession.test.mjs +1 -0
- package/lib/docs/dataSets/readDataSet.test.mjs +1 -0
- package/lib/docs/dataSets/resolveJourneyDataSet.test.mjs +1 -0
- package/lib/docs/dataSets/test/buildTestApp.mjs +1 -1
- package/lib/docs/devEventBus.js +7 -2
- package/lib/docs/devEventBus.test.mjs +12 -10
- package/lib/docs/devToolDefinitions.js +101 -143
- package/lib/docs/device/buildDeviceCommand.js +103 -0
- package/lib/docs/device/buildDeviceCommand.test.mjs +142 -0
- package/lib/docs/device/captureDevice.js +85 -0
- package/lib/docs/device/checkShownPage.js +56 -0
- package/lib/docs/device/createFakePhoneTab.mjs +77 -0
- package/lib/docs/device/deviceAction.js +74 -0
- package/lib/docs/device/deviceTools.test.mjs +604 -0
- package/lib/docs/device/findDeviceTab.js +50 -0
- package/lib/docs/device/findDeviceTarget.js +73 -0
- package/lib/docs/device/injectDevice.js +160 -0
- package/lib/docs/device/listDevices.js +100 -0
- package/lib/docs/device/listDevices.test.mjs +105 -0
- package/lib/docs/device/runDeviceJourney.js +68 -0
- package/lib/docs/device/runDeviceSteps.js +164 -0
- package/lib/docs/device/screenshotDevice.js +68 -0
- package/lib/docs/device/sendDeviceStep.js +52 -0
- package/lib/docs/device/startDevice.js +150 -0
- package/lib/docs/docs.test.mjs +44 -28
- package/lib/docs/docsIndex.test.mjs +1 -0
- package/lib/docs/findConfig.js +3 -4
- package/lib/docs/findPageBlock.js +35 -0
- package/lib/docs/findPageBlock.test.mjs +45 -0
- package/lib/docs/fitResponse.js +18 -17
- package/lib/docs/fitResponse.test.mjs +18 -0
- package/lib/docs/getBrowser.js +3 -3
- package/lib/docs/getBrowser.test.mjs +32 -16
- package/lib/docs/getBuildId.test.mjs +1 -0
- package/lib/docs/getBuildStatus.test.mjs +11 -11
- package/lib/docs/getBuildStatusAfterEdits.test.mjs +8 -8
- package/{src/routes/docs/appMap.js → lib/docs/getConfigDirectory.js} +3 -5
- package/lib/docs/getHazards.js +4 -1
- package/lib/docs/getHazards.test.mjs +9 -7
- package/lib/docs/getOverview.js +20 -42
- package/lib/docs/getOverviewBasePath.test.mjs +1 -0
- package/lib/docs/getStaleStatus.test.mjs +1 -0
- package/lib/docs/inspectState.js +78 -3
- package/lib/docs/inspectState.test.mjs +61 -9
- package/lib/docs/inspectStateFromTab.js +38 -6
- package/lib/docs/inspectStateFromTab.test.mjs +79 -0
- package/lib/docs/inspectStateHeadless.js +98 -34
- package/lib/docs/inspectStateHeadless.test.mjs +17 -5
- package/lib/docs/installHeadlessShell.failure.test.mjs +9 -5
- package/lib/docs/installHeadlessShell.js +5 -2
- package/lib/docs/installHeadlessShell.test.mjs +8 -5
- package/lib/docs/installHeadlessShell.timeout.test.mjs +32 -12
- package/lib/docs/isDeepEqual.js +37 -0
- package/lib/docs/isHeadlessShellIncomplete.js +6 -5
- package/lib/docs/isHeadlessShellIncomplete.test.mjs +4 -1
- package/lib/docs/isPageReady.test.mjs +1 -0
- package/lib/docs/journeyMutantCookie.chromium.test.mjs +3 -3
- package/lib/docs/journeyRunRecording.test.mjs +1 -0
- package/lib/docs/keepEventStreamAlive.test.mjs +1 -0
- package/lib/docs/launchBrowser.test.mjs +8 -8
- package/lib/docs/listTypes.js +58 -8
- package/lib/docs/loadFrameworkHazards.test.mjs +1 -0
- package/lib/docs/matchJourneyRoute.test.mjs +1 -0
- package/lib/docs/observe/createJourneyAppErrors.test.mjs +18 -4
- package/lib/docs/observe/evaluateInvariants.js +23 -0
- package/lib/docs/observe/evaluateInvariants.test.mjs +27 -0
- package/lib/docs/observe/hasNoEffect.test.mjs +1 -0
- package/lib/docs/observe/toAppErrorFailure.js +7 -4
- package/lib/docs/observe/watchJourneyContext.js +1 -0
- package/lib/docs/observe/withAppErrors.test.mjs +22 -0
- package/lib/docs/openJourneyEmail.test.mjs +6 -6
- package/lib/docs/pageBuildStatus.test.mjs +6 -6
- package/lib/docs/pollTab.js +100 -0
- package/lib/docs/pollTab.test.mjs +64 -0
- package/lib/docs/rails/authEngineActions.test.mjs +1 -0
- package/lib/docs/rails/authEngineMethods.test.mjs +2 -1
- package/lib/docs/rails/checkAuthActionsRan.test.mjs +5 -5
- package/lib/docs/rails/createDataSetRails.test.mjs +1 -0
- package/lib/docs/rails/findExternalBlocks.test.mjs +1 -0
- package/lib/docs/readJourneyEmailMatch.test.mjs +2 -2
- package/lib/docs/readJourneySession.js +1 -1
- package/lib/docs/reportDevToolFault.js +29 -0
- package/lib/docs/reportDevToolFault.test.mjs +34 -0
- package/lib/docs/requestRestart.test.mjs +1 -0
- package/lib/docs/resolvePageInstance.test.mjs +1 -0
- package/lib/docs/resolveSource.js +2 -2
- package/lib/docs/resolveSource.test.mjs +6 -6
- package/lib/docs/reviewPageBuilds.test.mjs +2 -2
- package/lib/docs/runCheck.test.mjs +3 -3
- package/lib/docs/runCheckChild.js +2 -1
- package/lib/docs/runEndpoint.js +23 -10
- package/lib/docs/runEndpoint.test.mjs +42 -37
- package/lib/docs/runErrorBuffers.test.mjs +1 -0
- package/lib/docs/runJourney.js +21 -1
- package/lib/docs/runJourney.test.mjs +119 -99
- package/lib/docs/runJourneyDataSet.test.mjs +25 -25
- package/lib/docs/runJourneySteps.js +8 -29
- package/lib/docs/runRequest.js +6 -6
- package/lib/docs/runRequest.test.mjs +22 -22
- package/lib/docs/screenshotPage.js +6 -7
- package/lib/docs/screenshotPage.test.mjs +46 -46
- package/lib/docs/screenshotPageClip.test.mjs +10 -10
- package/lib/docs/searchDocs.test.mjs +1 -0
- package/lib/docs/searchIcons.test.mjs +5 -5
- package/lib/docs/selectFinalState.test.mjs +1 -0
- package/lib/docs/serverErrorStore.test.mjs +4 -4
- package/lib/docs/setupTestFixtures.mjs +25 -0
- package/lib/docs/splitSearchTerms.test.mjs +1 -0
- package/lib/docs/tabAvailable.js +1 -1
- package/lib/docs/tabChannel.js +90 -14
- package/lib/docs/tabChannel.test.mjs +40 -15
- package/lib/docs/validateJourneyTimeout.test.mjs +1 -0
- package/lib/docs/validateStateSelection.test.mjs +1 -0
- package/lib/docs/validateViewport.test.mjs +1 -0
- package/lib/docs/waitForBuild.test.mjs +1 -0
- package/lib/docs/withBrowserSlot.test.mjs +5 -5
- package/lib/server/applyDataSetRedirect.test.mjs +2 -2
- package/lib/server/applyDataSetRedirectTenantReach.test.mjs +1 -0
- package/lib/server/applyDataSetRedirectWalled.test.mjs +1 -0
- package/lib/server/auth/getHeadlessUser.js +6 -0
- package/lib/server/auth/getHeadlessUser.test.mjs +13 -2
- package/lib/server/auth/resolveHeadlessUser.test.mjs +1 -0
- package/lib/server/contextMapBudget.test.mjs +3 -3
- package/lib/server/continueJitKeys.test.mjs +1 -0
- package/lib/server/createLowdefyContext.js +5 -1
- package/lib/server/createLowdefyContext.test.mjs +32 -32
- package/lib/server/getClientAddress.test.mjs +2 -2
- package/lib/server/getPageJitEnrichment.test.mjs +1 -0
- package/lib/server/importAppCode.test.mjs +2 -2
- package/lib/server/jitPageBuilder.js +27 -3
- package/lib/server/jitPageBuilder.mobileTypes.test.mjs +65 -0
- package/lib/server/jitPageBuilder.skipPluginChecks.test.mjs +5 -6
- package/lib/server/jitPageBuilder.test.mjs +4 -4
- package/lib/server/journeyCookies.test.mjs +1 -0
- package/lib/server/loadDynamicJsMap.js +10 -1
- package/lib/server/log/createHandleError.js +10 -5
- package/lib/server/log/createHandleError.test.mjs +19 -8
- package/lib/server/log/createLogger.test.mjs +2 -2
- package/lib/server/mutantDataSetWrappers.test.mjs +1 -0
- package/lib/server/mutants/listMutants.test.mjs +1 -0
- package/lib/server/mutants/mutantRuns.test.mjs +1 -0
- package/lib/server/mutants/operators.test.mjs +1 -0
- package/lib/server/pageBuildRecords.test.mjs +1 -0
- package/lib/server/pageCache.test.mjs +1 -0
- package/lib/server/pageRebuilds.test.mjs +3 -3
- package/{src/routes/docs/examples.js → lib/server/pairingHeaders.js} +8 -15
- package/lib/server/pruneJitMaps.test.mjs +1 -0
- package/lib/server/readBuildApiArtifacts.test.mjs +1 -0
- package/lib/server/readInstanceRecord.test.mjs +24 -8
- package/lib/server/readMergedMaps.test.mjs +1 -0
- package/lib/server/recording/errorRecordingStamp.test.mjs +1 -0
- package/lib/server/recording/readRecordingCookie.test.mjs +2 -0
- package/lib/server/recording/servedBuilds.test.mjs +1 -0
- package/lib/server/sinkExternalConnections.test.mjs +6 -6
- package/lib/server/skipStaleMapWrites.test.mjs +12 -12
- package/lib/server/startIdleGc.test.mjs +25 -9
- package/lib/server/testFixtures/importAppCodeTwice.mjs +2 -2
- package/lib/vite/createDevServerExclude.test.mjs +1 -0
- package/lib/vite/keepIdleConnectionsOpen.js +36 -0
- package/lib/vite/keepIdleConnectionsOpen.test.mjs +104 -0
- package/manager/getContext.mjs +9 -0
- package/manager/processes/checkPendingPlugins.mjs +49 -0
- package/manager/processes/checkPendingPlugins.test.mjs +107 -0
- package/manager/processes/createIdleChild.mjs +141 -0
- package/manager/processes/createIdleChild.test.mjs +209 -0
- package/manager/processes/initialBuild.mjs +2 -15
- package/manager/processes/initialBuild.test.mjs +8 -40
- package/manager/processes/lowdefyBuild.mjs +7 -4
- package/manager/processes/lowdefyBuild.skipPluginChecks.test.mjs +13 -13
- package/manager/processes/lowdefyBuild.test.mjs +17 -15
- package/manager/processes/restartServer.test.mjs +63 -15
- package/manager/processes/shutdownServer.test.mjs +3 -3
- package/manager/processes/startFirstServer.test.mjs +23 -22
- package/manager/processes/startMailSink.mjs +11 -3
- package/manager/processes/startMailSink.test.mjs +28 -2
- package/manager/processes/startProxy.mjs +167 -29
- package/manager/processes/startProxy.pairing.test.mjs +204 -0
- package/manager/processes/startProxy.test.mjs +130 -5
- package/manager/processes/startServer.mjs +5 -7
- package/manager/processes/startServer.test.mjs +10 -9
- package/manager/processes/syncServer.mjs +31 -4
- package/manager/processes/syncServer.test.mjs +71 -6
- package/manager/processes/waitForDevServer.test.mjs +21 -6
- package/manager/run.mjs +32 -8
- package/manager/utils/BatchChanges.mjs +1 -1
- package/manager/utils/BatchChanges.test.mjs +4 -4
- package/manager/utils/acquireDevInstance.test.mjs +1 -0
- package/manager/utils/checkPairing.mjs +45 -0
- package/manager/utils/checkPairing.test.mjs +53 -0
- package/manager/utils/createBuildActivity.mjs +5 -1
- package/manager/utils/createBuildActivity.test.mjs +2 -2
- package/manager/utils/createChangeSignal.test.mjs +5 -5
- package/manager/utils/createCustomPluginMessagesMap.mjs +8 -3
- package/manager/utils/createCustomPluginTypesMap.mjs +48 -12
- package/manager/utils/createCustomPluginTypesMap.test.mjs +181 -19
- package/manager/utils/createDotPathIgnore.test.mjs +1 -0
- package/manager/utils/createGlobIgnore.mjs +45 -0
- package/manager/utils/createGlobIgnore.test.mjs +58 -0
- package/manager/utils/createGlobWatchPaths.mjs +75 -0
- package/manager/utils/createGlobWatchPaths.test.mjs +67 -0
- package/manager/utils/createIdleGc.test.mjs +31 -15
- package/{src/routes/docs/content.js → manager/utils/createLanPairing.mjs} +14 -13
- package/manager/utils/createLanPairing.test.mjs +46 -0
- package/manager/utils/createRequestActivity.mjs +30 -3
- package/manager/utils/createRequestActivity.test.mjs +76 -22
- package/manager/utils/createServerArtifactTracker.mjs +1 -0
- package/manager/utils/createServerArtifactTracker.test.mjs +1 -0
- package/manager/utils/findBuildFilesOutsideWatch.test.mjs +1 -0
- package/{client/recorder/collectEventActions.js → manager/utils/findSignInCode.mjs} +13 -10
- package/manager/utils/findSignInCode.test.mjs +33 -0
- package/manager/utils/formatLanPairing.mjs +32 -0
- package/manager/utils/formatLanPairing.test.mjs +40 -0
- package/manager/utils/getLanAddress.mjs +83 -0
- package/manager/utils/getLanAddress.test.mjs +70 -0
- package/manager/utils/importFresh.test.mjs +1 -0
- package/{src/routes/docs/icons.js → manager/utils/isLoopbackAddress.mjs} +11 -10
- package/manager/utils/pluginTypeCache.mjs +100 -0
- package/manager/utils/pluginTypeCache.test.mjs +141 -0
- package/manager/utils/pruneRecordings.test.mjs +1 -0
- package/manager/utils/publishBuildDirectory.order.test.mjs +2 -2
- package/manager/utils/publishBuildDirectory.test.mjs +6 -7
- package/manager/utils/readBasePath.test.mjs +1 -0
- package/manager/utils/readManagerVersion.test.mjs +1 -0
- package/manager/utils/readPluginDefinitions.mjs +6 -6
- package/manager/utils/renderTerminalQr.mjs +54 -0
- package/manager/utils/resolveDevAuthUrl.test.mjs +1 -0
- package/manager/utils/setupWatcher.mjs +19 -4
- package/manager/utils/startRecordingPruner.test.mjs +24 -8
- package/manager/utils/waitForChildExit.test.mjs +2 -2
- package/manager/utils/writeBuildStatus.test.mjs +1 -0
- package/manager/watchers/envWatcher.mjs +3 -0
- package/manager/watchers/envWatcher.test.mjs +19 -7
- package/manager/watchers/listServerPluginFiles.mjs +188 -0
- package/manager/watchers/listServerPluginFiles.test.mjs +257 -0
- package/manager/watchers/lowdefyBuildWatcher.mjs +5 -0
- package/manager/watchers/lowdefyBuildWatcher.test.mjs +63 -10
- package/manager/watchers/pluginSourceWatcher.mjs +45 -17
- package/manager/watchers/pluginSourceWatcher.test.mjs +97 -21
- package/manager/watchers/resolveFile.mjs +46 -0
- package/manager/watchers/resolveFile.test.mjs +67 -0
- package/manager/watchers/resolvePackageSpecifier.mjs +127 -0
- package/manager/watchers/resolvePackageSpecifier.test.mjs +151 -0
- package/manager/watchers/restartRequestWatcher.mjs +7 -4
- package/manager/watchers/restartRequestWatcher.test.mjs +43 -6
- package/manager/watchers/selectLocalPluginPackages.test.mjs +1 -0
- package/package.json +54 -53
- package/package.original.json +54 -53
- package/src/app.js +83 -85
- package/src/html/renderDevPage.test.mjs +1 -0
- package/src/lib/getPathSegments.js +16 -1
- package/src/{routes/docs/checkpointsList.js → lib/getRequestSurface.js} +6 -4
- package/src/lib/isTabAnswer.js +32 -0
- package/src/lib/isTabChannelCaller.js +35 -0
- package/src/middleware/apiContext.js +4 -2
- package/src/middleware/createSameOriginGuard.test.mjs +1 -0
- package/src/middleware/errorHandler.js +33 -45
- package/src/middleware/errorHandler.test.mjs +10 -10
- package/src/middleware/isRebindingSafeHost.test.mjs +1 -0
- package/src/middleware/localDevToolsOnly.js +13 -1
- package/src/middleware/localDevToolsOnly.test.mjs +36 -2
- package/src/middleware/noStore.test.mjs +1 -0
- package/src/middleware/requestTimeout.js +7 -1
- package/src/middleware/staleFlag.test.mjs +1 -0
- package/src/middleware/stampCaller.test.mjs +1 -0
- package/src/routes/agentBearer.test.mjs +183 -0
- package/src/routes/auth.test.mjs +10 -10
- package/src/routes/clientError.js +21 -4
- package/src/routes/clientError.test.mjs +127 -0
- package/src/routes/devInspect.js +6 -51
- package/src/routes/devInspect.test.mjs +128 -3
- package/src/routes/devRecording.js +6 -17
- package/src/routes/devRecording.test.mjs +54 -3
- package/src/routes/docs/buildStatus.test.mjs +6 -6
- package/src/routes/docs/events.test.mjs +4 -4
- package/src/routes/docs/find.js +3 -3
- package/src/routes/docs/journey.test.mjs +8 -8
- package/src/routes/docs/journeyRefusals.test.mjs +9 -9
- package/src/routes/docs/loadDocsRoutes.js +70 -0
- package/src/routes/docs/loadDocsRoutes.test.mjs +110 -0
- package/src/routes/docs/mcp.test.mjs +5 -5
- package/src/routes/docs/mutants.js +7 -0
- package/src/routes/docs/mutants.test.mjs +20 -6
- package/src/routes/docs/parsePathParamsParam.test.mjs +1 -0
- package/src/routes/docs/parseUserParam.test.mjs +1 -0
- package/src/routes/docs/restart.test.mjs +1 -0
- package/src/routes/endpoints.js +24 -0
- package/src/routes/endpointsLink.test.mjs +111 -0
- package/src/routes/endpointsTextAnswer.test.mjs +8 -8
- package/src/routes/jitPage.js +13 -1
- package/src/routes/jitPage.test.mjs +36 -11
- package/src/routes/mcp.js +6 -0
- package/src/routes/mcp.test.mjs +23 -8
- package/src/routes/mcpMemberToken.test.mjs +8 -8
- package/src/routes/mcpProtectedResourceMetadata.test.mjs +2 -2
- package/src/routes/{docs/checkpointsRevert.js → mobileRoot.js} +10 -13
- package/src/routes/mobileRoutes.test.mjs +223 -0
- package/src/routes/mobileSignIn.js +58 -0
- package/src/routes/mobileSignIn.test.mjs +59 -0
- package/src/routes/mobileSignInCallback.js +34 -0
- package/src/routes/mobileSignInCallback.test.mjs +51 -0
- package/src/routes/mountDevPageRoutes.js +10 -2
- package/src/routes/mountDevPageRoutes.test.mjs +25 -1
- package/src/routes/mountMobileWellKnown.js +35 -0
- package/src/routes/mountMobileWellKnown.test.mjs +79 -0
- package/src/routes/mountOauthDiscovery.test.mjs +5 -5
- package/src/routes/normalizeMcpProtocolVersionHeader.test.mjs +1 -0
- package/src/routes/reload.js +101 -20
- package/src/routes/reload.test.mjs +153 -0
- package/src/routes/request.js +1 -22
- package/src/routes/request.test.mjs +7 -24
- package/src/routes/requestBody.test.mjs +14 -27
- package/src/routes/websocket.test.mjs +2 -2
- package/src/routes/wellKnownFallback.test.mjs +2 -2
- package/src/websocket/devWebSocket.test.mjs +12 -12
- package/vite.config.js +15 -1
- package/client/feedback/FeedbackMount.jsx +0 -83
- package/client/feedback/FeedbackOverlay.jsx +0 -904
- package/client/feedback/captureTabScreenshot.js +0 -84
- package/client/feedback/copyToClipboard.js +0 -45
- package/client/feedback/drawAnnotationsSvg.js +0 -119
- package/client/feedback/feedbackStyles.js +0 -304
- package/client/feedback/pinResponsiveImages.js +0 -59
- package/client/feedback/sendFeedback.js +0 -39
- package/client/feedback/useFeedbackToggle.js +0 -70
- package/client/recorder/buildEngineRecord.js +0 -37
- package/client/recorder/buildInteractionRecord.js +0 -64
- package/client/recorder/buildTraceEvent.js +0 -57
- package/client/recorder/buildTraceEvent.test.mjs +0 -81
- package/client/recorder/chunkRecords.js +0 -69
- package/client/recorder/chunkRecords.test.mjs +0 -59
- package/client/recorder/collectEventEndpoints.js +0 -40
- package/client/recorder/collectEventRequests.js +0 -39
- package/client/recorder/createPairingBuffer.js +0 -187
- package/client/recorder/createPasswordRedactor.js +0 -84
- package/client/recorder/createRecordBatcher.js +0 -54
- package/client/recorder/createRecordBatcher.test.mjs +0 -76
- package/client/recorder/createRecordingSession.js +0 -61
- package/client/recorder/createRecordingSession.test.mjs +0 -72
- package/client/recorder/diffStateWrites.js +0 -77
- package/client/recorder/diffStateWrites.test.mjs +0 -66
- package/client/recorder/isEventCall.js +0 -30
- package/client/recorder/jsonType.js +0 -39
- package/client/recorder/sendRecords.js +0 -40
- package/lib/docs/captureAnnotatedScreenshot.js +0 -99
- package/lib/docs/checkpointPaths.js +0 -91
- package/lib/docs/checkpointStore.js +0 -243
- package/lib/docs/checkpointToMocks.js +0 -65
- package/lib/docs/configCheckpoints.test.mjs +0 -156
- package/lib/docs/createConfigCheckpoint.js +0 -92
- package/lib/docs/devMockRegistry.js +0 -68
- package/lib/docs/enrichFeedback.js +0 -71
- package/lib/docs/evalOperator.js +0 -49
- package/lib/docs/evalOperator.test.mjs +0 -157
- package/lib/docs/evalOperatorHeadless.js +0 -159
- package/lib/docs/evalOperatorHeadless.test.mjs +0 -78
- package/lib/docs/evalOperatorInTab.js +0 -49
- package/lib/docs/formatFeedback.js +0 -142
- package/lib/docs/formatFeedback.test.mjs +0 -252
- package/lib/docs/getPluginDoc.js +0 -53
- package/lib/docs/listConfigCheckpoints.js +0 -55
- package/lib/docs/loadState.js +0 -220
- package/lib/docs/revertConfigCheckpoint.js +0 -73
- package/lib/docs/saveAnnotatedScreenshot.js +0 -43
- package/lib/docs/scaffoldPage.js +0 -77
- package/lib/docs/scaffoldPage.test.mjs +0 -97
- package/lib/docs/snapshotState.js +0 -67
- package/lib/docs/stateCheckpoints.test.mjs +0 -443
- package/manager/watchers/listServerSidePackages.mjs +0 -47
- package/manager/watchers/listServerSidePackages.test.mjs +0 -38
- package/src/routes/docs/checkpointsCreate.js +0 -28
- package/src/routes/docs/evalOperator.js +0 -70
- package/src/routes/docs/inspectState.js +0 -59
- package/src/routes/docs/loadState.js +0 -51
- package/src/routes/docs/pluginDoc.js +0 -33
- package/src/routes/docs/plugins.js +0 -23
- package/src/routes/docs/runEndpoint.js +0 -54
- package/src/routes/docs/runEndpoint.test.mjs +0 -165
- package/src/routes/docs/runRequest.js +0 -53
- package/src/routes/docs/runRequest.test.mjs +0 -92
- package/src/routes/docs/schema.js +0 -37
- package/src/routes/docs/screenshot.js +0 -120
- package/src/routes/docs/screenshot.test.mjs +0 -117
- package/src/routes/docs/search.js +0 -40
- package/src/routes/docs/snapshotState.js +0 -50
- package/src/routes/docs/stateCheckpointsList.js +0 -26
- package/src/routes/docs/types.js +0 -33
- package/src/routes/feedback.js +0 -107
- package/src/routes/feedback.test.mjs +0 -204
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020-2026 Lowdefy, Inc
|
|
3
|
+
|
|
4
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
you may not use this file except in compliance with the License.
|
|
6
|
+
You may obtain a copy of the License at
|
|
7
|
+
|
|
8
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
|
|
10
|
+
Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
See the License for the specific language governing permissions and
|
|
14
|
+
limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
const ACCENT = '#4f9cf9';
|
|
18
|
+
|
|
19
|
+
const fontFamily =
|
|
20
|
+
'-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif';
|
|
21
|
+
|
|
22
|
+
const overlayContainer = {
|
|
23
|
+
position: 'fixed',
|
|
24
|
+
inset: 0,
|
|
25
|
+
zIndex: 2147483000,
|
|
26
|
+
fontFamily,
|
|
27
|
+
fontSize: 13,
|
|
28
|
+
color: '#ffffff',
|
|
29
|
+
pointerEvents: 'none',
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
const highlightBox = {
|
|
33
|
+
position: 'fixed',
|
|
34
|
+
border: `2px solid ${ACCENT}`,
|
|
35
|
+
backgroundColor: 'rgba(79,156,249,0.08)',
|
|
36
|
+
borderRadius: 4,
|
|
37
|
+
pointerEvents: 'none',
|
|
38
|
+
transition: 'top 60ms ease, left 60ms ease, width 60ms ease, height 60ms ease',
|
|
39
|
+
boxSizing: 'border-box',
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
const labelChip = {
|
|
43
|
+
position: 'absolute',
|
|
44
|
+
top: -22,
|
|
45
|
+
left: -2,
|
|
46
|
+
backgroundColor: ACCENT,
|
|
47
|
+
color: '#fff',
|
|
48
|
+
fontSize: 11,
|
|
49
|
+
lineHeight: '16px',
|
|
50
|
+
padding: '2px 6px',
|
|
51
|
+
borderRadius: 4,
|
|
52
|
+
whiteSpace: 'nowrap',
|
|
53
|
+
pointerEvents: 'none',
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
export { highlightBox, labelChip, overlayContainer };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @
|
|
2
|
+
* @vitest-environment jsdom
|
|
3
3
|
*/
|
|
4
4
|
/*
|
|
5
5
|
Copyright 2020-2026 Lowdefy, Inc
|
|
@@ -17,12 +17,13 @@
|
|
|
17
17
|
limitations under the License.
|
|
18
18
|
*/
|
|
19
19
|
|
|
20
|
-
import {
|
|
20
|
+
import { vi, afterEach, beforeEach, expect, test } from 'vitest';
|
|
21
|
+
import createPairingBuffer, { HOLD_MS } from '@lowdefy/client-core/recorder/createPairingBuffer.js';
|
|
22
|
+
import createPasswordRedactor from '@lowdefy/client-core/recorder/createPasswordRedactor.js';
|
|
21
23
|
// Only the validator: the package index loads undici, which needs Node globals jsdom lacks.
|
|
22
24
|
import validateTraceRecord from '@lowdefy/node-utils/journeyTrace/validateTraceRecord.js';
|
|
23
25
|
|
|
24
|
-
import
|
|
25
|
-
import createPasswordRedactor from './createPasswordRedactor.js';
|
|
26
|
+
import isPasswordElement from './isPasswordElement.js';
|
|
26
27
|
|
|
27
28
|
const START = Date.parse('2026-10-03T14:00:00.000Z');
|
|
28
29
|
const SESSION = '20261003T140000Z-k3x9qa';
|
|
@@ -94,12 +95,12 @@ function interact({ element, kind = 'click', at, value }) {
|
|
|
94
95
|
}
|
|
95
96
|
|
|
96
97
|
function event(options) {
|
|
97
|
-
|
|
98
|
+
vi.setSystemTime(START + options.arrive);
|
|
98
99
|
buffer.addEvent(payload(options), { urlAfter: '/tickets' });
|
|
99
100
|
}
|
|
100
101
|
|
|
101
102
|
function closeAll() {
|
|
102
|
-
|
|
103
|
+
vi.advanceTimersByTime(HOLD_MS + 60000);
|
|
103
104
|
}
|
|
104
105
|
|
|
105
106
|
function el(id) {
|
|
@@ -107,14 +108,31 @@ function el(id) {
|
|
|
107
108
|
}
|
|
108
109
|
|
|
109
110
|
beforeEach(() => {
|
|
110
|
-
|
|
111
|
+
vi.useFakeTimers({
|
|
112
|
+
toFake: [
|
|
113
|
+
'Date',
|
|
114
|
+
'hrtime',
|
|
115
|
+
'queueMicrotask',
|
|
116
|
+
'requestAnimationFrame',
|
|
117
|
+
'cancelAnimationFrame',
|
|
118
|
+
'requestIdleCallback',
|
|
119
|
+
'cancelIdleCallback',
|
|
120
|
+
'setImmediate',
|
|
121
|
+
'clearImmediate',
|
|
122
|
+
'setInterval',
|
|
123
|
+
'clearInterval',
|
|
124
|
+
'setTimeout',
|
|
125
|
+
'clearTimeout',
|
|
126
|
+
],
|
|
127
|
+
now: START,
|
|
128
|
+
});
|
|
111
129
|
records = [];
|
|
112
130
|
buffer = createPairingBuffer({
|
|
113
131
|
onRecord: (record) => records.push(record),
|
|
114
132
|
getSession: () => SESSION,
|
|
115
133
|
getRoles: () => ['support'],
|
|
116
134
|
getBuild: () => build,
|
|
117
|
-
redactor: createPasswordRedactor(),
|
|
135
|
+
redactor: createPasswordRedactor({ isPassword: isPasswordElement }),
|
|
118
136
|
});
|
|
119
137
|
build = BUILD_A;
|
|
120
138
|
document.body.innerHTML = `
|
|
@@ -131,7 +149,7 @@ beforeEach(() => {
|
|
|
131
149
|
});
|
|
132
150
|
|
|
133
151
|
afterEach(() => {
|
|
134
|
-
|
|
152
|
+
vi.useRealTimers();
|
|
135
153
|
});
|
|
136
154
|
|
|
137
155
|
test('typing then a debounced trailing onChange pairs the event with the last keystroke only', () => {
|
|
@@ -14,15 +14,19 @@
|
|
|
14
14
|
limitations under the License.
|
|
15
15
|
*/
|
|
16
16
|
|
|
17
|
-
import
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
17
|
+
import {
|
|
18
|
+
createPairingBuffer,
|
|
19
|
+
createPasswordRedactor,
|
|
20
|
+
createRecordBatcher,
|
|
21
|
+
createRecordingSession,
|
|
22
|
+
sendRecords,
|
|
23
|
+
} from '@lowdefy/client-core';
|
|
24
|
+
|
|
25
|
+
import isPasswordElement from './isPasswordElement.js';
|
|
21
26
|
import keyChord from './keyChord.js';
|
|
22
|
-
import sendRecords from './sendRecords.js';
|
|
23
27
|
|
|
24
28
|
// Dev tools draw their own UI over the app; clicks on it are not the app.
|
|
25
|
-
const IGNORED_ROOTS = '[data-lowdefy-
|
|
29
|
+
const IGNORED_ROOTS = '[data-lowdefy-dev-tools]';
|
|
26
30
|
|
|
27
31
|
function elementOf(target) {
|
|
28
32
|
if (target === null || target === undefined) return null;
|
|
@@ -67,7 +71,7 @@ function createRecorder({ basePath, lowdefy, recording, window, getTrace }) {
|
|
|
67
71
|
getSession: () => session.getId(),
|
|
68
72
|
getRoles: () => lowdefy.user?.roles ?? [],
|
|
69
73
|
getBuild: () => lowdefy._devBuildId ?? null,
|
|
70
|
-
redactor: createPasswordRedactor(),
|
|
74
|
+
redactor: createPasswordRedactor({ isPassword: isPasswordElement }),
|
|
71
75
|
});
|
|
72
76
|
let pageId = null;
|
|
73
77
|
// A pageview waits here until the page it shows is on screen, because only
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @
|
|
2
|
+
* @vitest-environment jsdom
|
|
3
3
|
*/
|
|
4
4
|
/*
|
|
5
5
|
Copyright 2020-2026 Lowdefy, Inc
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
limitations under the License.
|
|
18
18
|
*/
|
|
19
19
|
|
|
20
|
-
import {
|
|
20
|
+
import { vi, afterEach, beforeEach, expect, test } from 'vitest';
|
|
21
21
|
|
|
22
22
|
import createRecorder from './createRecorder.js';
|
|
23
23
|
|
|
@@ -29,11 +29,11 @@ function createRegistry() {
|
|
|
29
29
|
const listeners = [];
|
|
30
30
|
return {
|
|
31
31
|
listeners,
|
|
32
|
-
subscribe:
|
|
32
|
+
subscribe: vi.fn((listener, options) => {
|
|
33
33
|
listeners.push({ listener, options });
|
|
34
34
|
return () => listeners.splice(listeners.indexOf(listener), 1);
|
|
35
35
|
}),
|
|
36
|
-
describeElement:
|
|
36
|
+
describeElement: vi.fn((element) => ({
|
|
37
37
|
page_id: 'tickets',
|
|
38
38
|
block_id: element.closest('[id^="bl-"]')?.id.slice(3) ?? null,
|
|
39
39
|
block_type: null,
|
|
@@ -68,7 +68,7 @@ function sentBodies() {
|
|
|
68
68
|
|
|
69
69
|
beforeEach(() => {
|
|
70
70
|
registry = createRegistry();
|
|
71
|
-
fetch =
|
|
71
|
+
fetch = vi.fn(() => Promise.resolve({ status: 204 }));
|
|
72
72
|
window.fetch = fetch;
|
|
73
73
|
window.sessionStorage.clear();
|
|
74
74
|
document.body.innerHTML = '<div id="bl-save"><button id="save">Save</button></div>';
|
|
@@ -77,11 +77,11 @@ beforeEach(() => {
|
|
|
77
77
|
|
|
78
78
|
afterEach(() => {
|
|
79
79
|
recorder?.stop();
|
|
80
|
-
|
|
80
|
+
vi.restoreAllMocks();
|
|
81
81
|
});
|
|
82
82
|
|
|
83
83
|
test('createRecorder with recording off subscribes to nothing and adds no listener', () => {
|
|
84
|
-
const addListener =
|
|
84
|
+
const addListener = vi.spyOn(document, 'addEventListener');
|
|
85
85
|
expect(start({ enabled: false })).toBe(null);
|
|
86
86
|
expect(start(null)).toBe(null);
|
|
87
87
|
expect(registry.subscribe).not.toHaveBeenCalled();
|
|
@@ -210,10 +210,10 @@ test('a throwing trace payload or describeElement leaves the app running', () =>
|
|
|
210
210
|
});
|
|
211
211
|
|
|
212
212
|
test('a throwing sessionStorage leaves the recorder recording under an unremembered session', async () => {
|
|
213
|
-
|
|
213
|
+
vi.spyOn(Storage.prototype, 'getItem').mockImplementation(() => {
|
|
214
214
|
throw new Error('SecurityError');
|
|
215
215
|
});
|
|
216
|
-
|
|
216
|
+
vi.spyOn(Storage.prototype, 'setItem').mockImplementation(() => {
|
|
217
217
|
throw new Error('SecurityError');
|
|
218
218
|
});
|
|
219
219
|
recorder = start();
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020-2026 Lowdefy, Inc
|
|
3
|
+
|
|
4
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
you may not use this file except in compliance with the License.
|
|
6
|
+
You may obtain a copy of the License at
|
|
7
|
+
|
|
8
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
|
|
10
|
+
Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
See the License for the specific language governing permissions and
|
|
14
|
+
limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import { journeyTargetSelectors } from '@lowdefy/helpers';
|
|
18
|
+
|
|
19
|
+
const { blockWrapperPrefix } = journeyTargetSelectors;
|
|
20
|
+
|
|
21
|
+
function isPasswordInput(element) {
|
|
22
|
+
return (
|
|
23
|
+
typeof element?.tagName === 'string' &&
|
|
24
|
+
element.tagName.toLowerCase() === 'input' &&
|
|
25
|
+
element.type === 'password'
|
|
26
|
+
);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// Whether an interaction's element belongs to a password block: the element,
|
|
30
|
+
// or its block's `<blockId>_input` element, is an `<input type="password">`.
|
|
31
|
+
// The visibility toggle turns the input into `type="text"`, so the block's own
|
|
32
|
+
// input is checked too, which a click on the toggle reaches.
|
|
33
|
+
function isPasswordElement(element) {
|
|
34
|
+
if (isPasswordInput(element)) return true;
|
|
35
|
+
const wrapper = element?.closest?.(`[id^="${blockWrapperPrefix}"]`);
|
|
36
|
+
if (!wrapper) return false;
|
|
37
|
+
const blockId = wrapper.id.slice(blockWrapperPrefix.length);
|
|
38
|
+
return isPasswordInput(element.ownerDocument?.getElementById(`${blockId}_input`));
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export default isPasswordElement;
|
|
@@ -14,16 +14,13 @@
|
|
|
14
14
|
limitations under the License.
|
|
15
15
|
*/
|
|
16
16
|
|
|
17
|
-
//
|
|
18
|
-
//
|
|
19
|
-
//
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
try {
|
|
23
|
-
return JSON.parse(JSON.stringify(value ?? null));
|
|
24
|
-
} catch {
|
|
25
|
-
return null;
|
|
26
|
-
}
|
|
27
|
-
}
|
|
17
|
+
// Build artifacts are read from disk because the Hono server runs as
|
|
18
|
+
// unbundled Node.js ESM — JSON imports would need import attributes, and
|
|
19
|
+
// client code imports the build JSON directly through Vite instead.
|
|
20
|
+
import fs from 'node:fs';
|
|
21
|
+
import path from 'node:path';
|
|
28
22
|
|
|
29
|
-
|
|
23
|
+
// {} for an app without a mobile key.
|
|
24
|
+
export default JSON.parse(
|
|
25
|
+
fs.readFileSync(path.join(process.cwd(), 'build/mobile/config.json'), 'utf8')
|
|
26
|
+
);
|
|
@@ -28,10 +28,11 @@ import { oauthProviderClient } from '@better-auth/oauth-provider/client';
|
|
|
28
28
|
import { passkeyClient } from '@better-auth/passkey/client';
|
|
29
29
|
|
|
30
30
|
import claimCallerReload from '@lowdefy/client/claimCallerReload.js';
|
|
31
|
-
import {
|
|
31
|
+
import { type } from '@lowdefy/helpers';
|
|
32
32
|
|
|
33
33
|
import bundleBuildId from '../bundleBuildId.js';
|
|
34
34
|
import createFetchCheckingBuild from './createFetchCheckingBuild.js';
|
|
35
|
+
import sessionCaller from './sessionCaller.js';
|
|
35
36
|
|
|
36
37
|
// The app basePath, from Vite's BASE_URL (`${config.basePath}/`, set in
|
|
37
38
|
// vite.config.js). build/config.json is server-only - it carries every
|
|
@@ -77,6 +78,42 @@ const sessionScoped = (params) => ({
|
|
|
77
78
|
fetchOptions: { ...params?.fetchOptions, disableSignal: true },
|
|
78
79
|
});
|
|
79
80
|
|
|
81
|
+
// Resolves once no refetch is writing the session atom. The atom writes only
|
|
82
|
+
// its latest refetch's answer, and a sign-in fires its own refetch through the
|
|
83
|
+
// session signal 10 ms after the call. A refetch started before that one has
|
|
84
|
+
// its answer dropped, and the atom still holds the session from before the
|
|
85
|
+
// sign-in until the later refetch lands.
|
|
86
|
+
async function sessionAtomSettled(sessionAtom) {
|
|
87
|
+
if (!sessionAtom.get().isRefetching) {
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
await new Promise((resolve) => {
|
|
91
|
+
const unlisten = sessionAtom.listen((value) => {
|
|
92
|
+
if (value.isRefetching) {
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
unlisten();
|
|
96
|
+
resolve();
|
|
97
|
+
});
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
// The server-resolved caller - roles from the active member row and the
|
|
102
|
+
// merged attributes bag - as { user }.
|
|
103
|
+
async function fetchResolvedUser() {
|
|
104
|
+
const response = await fetchCheckingBuild(`${basePath}/api/user`, {
|
|
105
|
+
credentials: 'same-origin',
|
|
106
|
+
});
|
|
107
|
+
if (!response.ok) {
|
|
108
|
+
// /api/user itself always answers 200 { user } - user: null when no
|
|
109
|
+
// caller is admitted, which updateSession branches on. A non-OK
|
|
110
|
+
// response is a transport failure (gateway error page, 5xx) with no
|
|
111
|
+
// parsable body.
|
|
112
|
+
throw new Error(`Failed to fetch the resolved user (HTTP ${response.status}).`);
|
|
113
|
+
}
|
|
114
|
+
return response.json();
|
|
115
|
+
}
|
|
116
|
+
|
|
80
117
|
// The server resolves the caller per request and embeds it in the page
|
|
81
118
|
// config, so the first render never flashes unauthenticated. The BetterAuth
|
|
82
119
|
// client store takes over once its session fetch settles.
|
|
@@ -87,16 +124,43 @@ const sessionScoped = (params) => ({
|
|
|
87
124
|
// for the fields the session does not carry, and UpdateSession refreshes it
|
|
88
125
|
// from /api/user after a change (e.g. SetActiveOrganization). Holding it in
|
|
89
126
|
// state, not a ref, re-renders Session when it changes so _user recomputes -
|
|
90
|
-
// the same reactive footing the session half already stands on.
|
|
91
|
-
//
|
|
92
|
-
// Only the session half is passed through normalizeCaller. BetterAuth's store
|
|
93
|
-
// returns camelCase keys whatever the columns are named, so untransformed it
|
|
94
|
-
// would sit emailVerified beside the resolved caller's email_verified on one
|
|
95
|
-
// object; anything arriving from the server is already snake_case.
|
|
127
|
+
// the same reactive footing the session half already stands on. sessionCaller
|
|
128
|
+
// picks the caller rendered from the two.
|
|
96
129
|
function Session({ children, reloadSuppressedRef, serverUser }) {
|
|
97
130
|
const { data: session, isPending } = authClient.useSession();
|
|
98
131
|
const [resolvedUser, setResolvedUser] = useState(serverUser);
|
|
99
132
|
const wasAuthenticated = useRef(Boolean(serverUser));
|
|
133
|
+
const sessionId = session?.session?.id;
|
|
134
|
+
const sessionIdRef = useRef(sessionId);
|
|
135
|
+
sessionIdRef.current = sessionId;
|
|
136
|
+
const askedSessionIdRef = useRef(null);
|
|
137
|
+
|
|
138
|
+
// A session with no server-resolved caller renders as no caller
|
|
139
|
+
// (sessionCaller). It is a sign-in in another tab, a session the server
|
|
140
|
+
// refused when it served this page, or a sign-in on this page whose Login has
|
|
141
|
+
// not set the caller yet (settleSignIn), so /api/user is asked once per
|
|
142
|
+
// session for the caller the server resolves it to. A null answer - a session the server
|
|
143
|
+
// refuses - leaves the page rendering no caller, matching every response.
|
|
144
|
+
// An answer is dropped once the session changed or UpdateSession set a
|
|
145
|
+
// caller in the meantime. A failed ask is left: the page renders no caller,
|
|
146
|
+
// and if the server does resolve one, the next response reloads the page.
|
|
147
|
+
useEffect(() => {
|
|
148
|
+
if (isPending || type.isNone(sessionId) || !type.isNone(resolvedUser)) {
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
151
|
+
if (askedSessionIdRef.current === sessionId) {
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
154
|
+
askedSessionIdRef.current = sessionId;
|
|
155
|
+
fetchResolvedUser()
|
|
156
|
+
.then(({ user }) => {
|
|
157
|
+
if (type.isNone(user) || sessionIdRef.current !== sessionId) {
|
|
158
|
+
return;
|
|
159
|
+
}
|
|
160
|
+
setResolvedUser((current) => current ?? user);
|
|
161
|
+
})
|
|
162
|
+
.catch(() => {});
|
|
163
|
+
}, [sessionId, isPending, resolvedUser]);
|
|
100
164
|
|
|
101
165
|
useEffect(() => {
|
|
102
166
|
if (session) {
|
|
@@ -130,32 +194,7 @@ function Session({ children, reloadSuppressedRef, serverUser }) {
|
|
|
130
194
|
}
|
|
131
195
|
}, [session, isPending, resolvedUser]);
|
|
132
196
|
|
|
133
|
-
|
|
134
|
-
return children(resolvedUser, setResolvedUser);
|
|
135
|
-
}
|
|
136
|
-
if (!session?.user) {
|
|
137
|
-
return children(null, setResolvedUser);
|
|
138
|
-
}
|
|
139
|
-
const resolved = resolvedUser;
|
|
140
|
-
if (!resolved) {
|
|
141
|
-
return children({ roles: [], ...normalizeCaller(session.user) }, setResolvedUser);
|
|
142
|
-
}
|
|
143
|
-
if (resolved.id !== session.user.id) {
|
|
144
|
-
// The session names another person than the resolved caller; the effect
|
|
145
|
-
// above reloads the page. Until it unloads, render the last resolved
|
|
146
|
-
// caller whole rather than mixing the new session user with the previous
|
|
147
|
-
// person's resolved fields, or falling back to a caller with no roles -
|
|
148
|
-
// blocks re-evaluate operators on render, so a role-guarded page would act
|
|
149
|
-
// on an empty role list.
|
|
150
|
-
return children(resolved, setResolvedUser);
|
|
151
|
-
}
|
|
152
|
-
// _user is one object with one meaning on both sides: the resolved caller is
|
|
153
|
-
// spread whole, so every field resolveAuthentication emits is readable in app
|
|
154
|
-
// config without this file naming it. session.user is the floor - the client
|
|
155
|
-
// store may hold a fresher one than the resolved state, and the resolved
|
|
156
|
-
// object wins wherever both carry a key.
|
|
157
|
-
const user = { ...normalizeCaller(session.user), ...resolved };
|
|
158
|
-
return children(user, setResolvedUser);
|
|
197
|
+
return children(sessionCaller({ isPending, resolvedUser, session }), setResolvedUser);
|
|
159
198
|
}
|
|
160
199
|
|
|
161
200
|
function AuthConfigured({ authConfig, children, serverUser }) {
|
|
@@ -174,24 +213,12 @@ function AuthConfigured({ authConfig, children, serverUser }) {
|
|
|
174
213
|
await sessionAtom
|
|
175
214
|
.get()
|
|
176
215
|
.refetch(disableCookieCache ? { query: { disableCookieCache: true } } : undefined);
|
|
216
|
+
await sessionAtomSettled(sessionAtom);
|
|
177
217
|
const { data, error } = sessionAtom.get();
|
|
178
218
|
return { data, error };
|
|
179
219
|
},
|
|
180
|
-
//
|
|
181
|
-
|
|
182
|
-
getResolvedUser: async () => {
|
|
183
|
-
const response = await fetchCheckingBuild(`${basePath}/api/user`, {
|
|
184
|
-
credentials: 'same-origin',
|
|
185
|
-
});
|
|
186
|
-
if (!response.ok) {
|
|
187
|
-
// /api/user itself always answers 200 { user } - user: null when no
|
|
188
|
-
// caller is admitted, which updateSession branches on. A non-OK
|
|
189
|
-
// response is a transport failure (gateway error page, 5xx) with no
|
|
190
|
-
// parsable body.
|
|
191
|
-
throw new Error(`Failed to fetch the resolved user (HTTP ${response.status}).`);
|
|
192
|
-
}
|
|
193
|
-
return response.json();
|
|
194
|
-
},
|
|
220
|
+
// For re-syncing after session changes.
|
|
221
|
+
getResolvedUser: fetchResolvedUser,
|
|
195
222
|
suppressSessionReload: () => {
|
|
196
223
|
reloadSuppressedRef.current = true;
|
|
197
224
|
},
|
|
@@ -17,6 +17,7 @@
|
|
|
17
17
|
import { readdir, readFile } from 'node:fs/promises';
|
|
18
18
|
import path from 'node:path';
|
|
19
19
|
import { fileURLToPath } from 'node:url';
|
|
20
|
+
import { expect, test } from 'vitest';
|
|
20
21
|
|
|
21
22
|
const devAuthDir = path.dirname(fileURLToPath(import.meta.url));
|
|
22
23
|
const prodAuthDir = path.resolve(devAuthDir, '../../../../server/lib/client/auth');
|
|
@@ -15,6 +15,7 @@
|
|
|
15
15
|
*/
|
|
16
16
|
|
|
17
17
|
import { createAuthClient } from 'better-auth/client';
|
|
18
|
+
import { expect, test } from 'vitest';
|
|
18
19
|
|
|
19
20
|
// AuthConfigured.jsx depends on behaviours of better-auth's client internals
|
|
20
21
|
// that no public API documents:
|
|
@@ -72,7 +73,7 @@ function createClient(handleGetSession) {
|
|
|
72
73
|
// makes the signal subscription live. It also keeps the store mounted for
|
|
73
74
|
// bare .get() calls: on an unmounted onMount store, .get() temporarily
|
|
74
75
|
// mounts it and schedules nanostores' delayed unmount on a timer that
|
|
75
|
-
// outlives the
|
|
76
|
+
// outlives the test worker. The mount's own initial fetch is skipped in
|
|
76
77
|
// node (isServer), so no request is recorded here.
|
|
77
78
|
client.$store.atoms.session.subscribe(() => {});
|
|
78
79
|
const getSessionRequests = () => requests.filter((r) => r.url.includes('/get-session'));
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020-2026 Lowdefy, Inc
|
|
3
|
+
|
|
4
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
you may not use this file except in compliance with the License.
|
|
6
|
+
You may obtain a copy of the License at
|
|
7
|
+
|
|
8
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
|
|
10
|
+
Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
See the License for the specific language governing permissions and
|
|
14
|
+
limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import { normalizeCaller, type } from '@lowdefy/helpers';
|
|
18
|
+
|
|
19
|
+
// The caller Session renders, from the BetterAuth store's session and the last
|
|
20
|
+
// server-resolved caller.
|
|
21
|
+
//
|
|
22
|
+
// The page renders only a caller the server resolved. Every response names the
|
|
23
|
+
// caller the server answered as (x-lowdefy-caller), and a page rendering
|
|
24
|
+
// another caller reloads (shouldReloadForCaller). A session the server resolves
|
|
25
|
+
// to no caller - a removed member, an invitee whose invitation lapsed - renders
|
|
26
|
+
// as no caller, not as the session's user: rendering the session's user would
|
|
27
|
+
// mismatch every response and reload until the loop guard throws.
|
|
28
|
+
//
|
|
29
|
+
// Only the session half is passed through normalizeCaller. BetterAuth's store
|
|
30
|
+
// returns camelCase keys whatever the columns are named, so untransformed it
|
|
31
|
+
// would sit emailVerified beside the resolved caller's email_verified on one
|
|
32
|
+
// object; anything arriving from the server is already snake_case.
|
|
33
|
+
function sessionCaller({ isPending, resolvedUser, session }) {
|
|
34
|
+
if (isPending) {
|
|
35
|
+
return resolvedUser;
|
|
36
|
+
}
|
|
37
|
+
if (type.isNone(session?.user) || type.isNone(resolvedUser)) {
|
|
38
|
+
return null;
|
|
39
|
+
}
|
|
40
|
+
if (resolvedUser.id !== session.user.id) {
|
|
41
|
+
// The session names another person than the resolved caller; Session
|
|
42
|
+
// reloads the page. Until it unloads, render the last resolved caller whole
|
|
43
|
+
// rather than mixing the new session user with the previous person's
|
|
44
|
+
// resolved fields - blocks re-evaluate operators on render, so a
|
|
45
|
+
// role-guarded page would act on a mixed caller.
|
|
46
|
+
return resolvedUser;
|
|
47
|
+
}
|
|
48
|
+
// _user is one object with one meaning on both sides: the resolved caller is
|
|
49
|
+
// spread whole, so every field resolveAuthentication emits is readable in app
|
|
50
|
+
// config without this file naming it. session.user is the floor - the client
|
|
51
|
+
// store may hold a fresher one than the resolved state, and the resolved
|
|
52
|
+
// object wins wherever both carry a key.
|
|
53
|
+
return { ...normalizeCaller(session.user), ...resolvedUser };
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export default sessionCaller;
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020-2026 Lowdefy, Inc
|
|
3
|
+
|
|
4
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
you may not use this file except in compliance with the License.
|
|
6
|
+
You may obtain a copy of the License at
|
|
7
|
+
|
|
8
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
|
|
10
|
+
Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
See the License for the specific language governing permissions and
|
|
14
|
+
limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import { callerHash } from '@lowdefy/helpers';
|
|
18
|
+
import { expect, test } from 'vitest';
|
|
19
|
+
|
|
20
|
+
import sessionCaller from './sessionCaller.js';
|
|
21
|
+
|
|
22
|
+
const RESOLVED = {
|
|
23
|
+
id: 'user-1',
|
|
24
|
+
email: 'user-1@example.com',
|
|
25
|
+
email_verified: true,
|
|
26
|
+
organization_id: 'org-1',
|
|
27
|
+
roles: ['admin'],
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
function sessionFor(user) {
|
|
31
|
+
return { session: { id: 'session-1', userId: user.id }, user };
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
test('while the store is pending, the server-resolved caller renders', () => {
|
|
35
|
+
expect(sessionCaller({ isPending: true, resolvedUser: RESOLVED, session: null })).toBe(RESOLVED);
|
|
36
|
+
expect(sessionCaller({ isPending: true, resolvedUser: null, session: null })).toBe(null);
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
test('with no session, no caller renders', () => {
|
|
40
|
+
expect(sessionCaller({ isPending: false, resolvedUser: RESOLVED, session: null })).toBe(null);
|
|
41
|
+
expect(sessionCaller({ isPending: false, resolvedUser: null, session: { user: null } })).toBe(
|
|
42
|
+
null
|
|
43
|
+
);
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
test('a session the server resolved to no caller renders no caller', () => {
|
|
47
|
+
const session = sessionFor({ id: 'user-1', email: 'user-1@example.com', emailVerified: true });
|
|
48
|
+
const user = sessionCaller({ isPending: false, resolvedUser: null, session });
|
|
49
|
+
expect(user).toBe(null);
|
|
50
|
+
// The server stamps such a response with the empty caller; the rendered
|
|
51
|
+
// caller hashes the same, so the page does not reload.
|
|
52
|
+
expect(callerHash({ user })).toBe('');
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
test('a resolved caller for the session user renders merged over the session user', () => {
|
|
56
|
+
const session = sessionFor({
|
|
57
|
+
id: 'user-1',
|
|
58
|
+
email: 'user-1@example.com',
|
|
59
|
+
emailVerified: true,
|
|
60
|
+
image: 'https://example.com/a.png',
|
|
61
|
+
});
|
|
62
|
+
const user = sessionCaller({ isPending: false, resolvedUser: RESOLVED, session });
|
|
63
|
+
expect(user).toEqual({
|
|
64
|
+
id: 'user-1',
|
|
65
|
+
email: 'user-1@example.com',
|
|
66
|
+
email_verified: true,
|
|
67
|
+
image: 'https://example.com/a.png',
|
|
68
|
+
organization_id: 'org-1',
|
|
69
|
+
roles: ['admin'],
|
|
70
|
+
});
|
|
71
|
+
expect(user).not.toHaveProperty('emailVerified');
|
|
72
|
+
expect(callerHash({ user })).toBe(callerHash({ user: RESOLVED }));
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
test('a resolved caller for another person renders whole until the page reloads', () => {
|
|
76
|
+
const session = sessionFor({ id: 'user-2', email: 'user-2@example.com' });
|
|
77
|
+
expect(sessionCaller({ isPending: false, resolvedUser: RESOLVED, session })).toBe(RESOLVED);
|
|
78
|
+
});
|