@lowdefy/server-dev 7.1.0 → 7.2.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 +87 -135
- 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.test.mjs +1 -0
- 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 +3 -3
- package/lib/docs/observe/evaluateInvariants.test.mjs +1 -0
- package/lib/docs/observe/hasNoEffect.test.mjs +1 -0
- package/lib/docs/observe/withAppErrors.test.mjs +1 -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/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 +158 -27
- package/manager/processes/startProxy.pairing.test.mjs +204 -0
- package/manager/processes/startProxy.test.mjs +127 -2
- 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 +50 -49
- package/package.original.json +50 -49
- 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/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 +13 -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
package/src/app.js
CHANGED
|
@@ -16,6 +16,7 @@
|
|
|
16
16
|
|
|
17
17
|
import { Hono } from 'hono';
|
|
18
18
|
import { bodyLimit } from 'hono/body-limit';
|
|
19
|
+
import { etag } from 'hono/etag';
|
|
19
20
|
import { serveStatic } from '@hono/node-server/serve-static';
|
|
20
21
|
import { runInCredentialScope } from '@lowdefy/node-utils';
|
|
21
22
|
|
|
@@ -32,44 +33,20 @@ import detachedHandler from './routes/detached.js';
|
|
|
32
33
|
import devInspectHandler from './routes/devInspect.js';
|
|
33
34
|
import devRecordingHandler from './routes/devRecording.js';
|
|
34
35
|
import devToolsHandler from './routes/devTools.js';
|
|
35
|
-
import feedbackHandler from './routes/feedback.js';
|
|
36
|
-
import docsAppMapHandler from './routes/docs/appMap.js';
|
|
37
|
-
import docsBuildStatusHandler from './routes/docs/buildStatus.js';
|
|
38
|
-
import docsCheckpointsCreateHandler from './routes/docs/checkpointsCreate.js';
|
|
39
|
-
import docsCheckpointsListHandler from './routes/docs/checkpointsList.js';
|
|
40
|
-
import docsCheckpointsRevertHandler from './routes/docs/checkpointsRevert.js';
|
|
41
|
-
import docsContentHandler from './routes/docs/content.js';
|
|
42
|
-
import docsEvalOperatorHandler from './routes/docs/evalOperator.js';
|
|
43
|
-
import docsEventsHandler from './routes/docs/events.js';
|
|
44
|
-
import docsExamplesHandler from './routes/docs/examples.js';
|
|
45
|
-
import docsFindHandler from './routes/docs/find.js';
|
|
46
|
-
import docsIndexHandler from './routes/docs/index.js';
|
|
47
|
-
import docsInspectStateHandler from './routes/docs/inspectState.js';
|
|
48
|
-
import docsJourneyHandler from './routes/docs/journey.js';
|
|
49
|
-
import docsMutantsHandler from './routes/docs/mutants.js';
|
|
50
|
-
import docsLoadStateHandler from './routes/docs/loadState.js';
|
|
51
|
-
import docsMcpHandler from './routes/docs/mcp.js';
|
|
52
|
-
import docsPageConfigHandler from './routes/docs/pageConfig.js';
|
|
53
|
-
import docsRestartHandler from './routes/docs/restart.js';
|
|
54
|
-
import docsRunEndpointHandler from './routes/docs/runEndpoint.js';
|
|
55
|
-
import docsRunRequestHandler from './routes/docs/runRequest.js';
|
|
56
|
-
import docsSnapshotStateHandler from './routes/docs/snapshotState.js';
|
|
57
|
-
import docsStateCheckpointsListHandler from './routes/docs/stateCheckpointsList.js';
|
|
58
|
-
import docsPluginDocHandler from './routes/docs/pluginDoc.js';
|
|
59
|
-
import docsPluginsHandler from './routes/docs/plugins.js';
|
|
60
|
-
import docsSchemaHandler from './routes/docs/schema.js';
|
|
61
|
-
import docsScreenshotHandler from './routes/docs/screenshot.js';
|
|
62
|
-
import docsIconsHandler from './routes/docs/icons.js';
|
|
63
|
-
import docsSearchHandler from './routes/docs/search.js';
|
|
64
|
-
import docsTypesHandler from './routes/docs/types.js';
|
|
65
36
|
import endpointsHandler from './routes/endpoints.js';
|
|
66
37
|
import getAuth from '../lib/server/auth/getAuth.js';
|
|
67
38
|
import getStrategies from '../lib/server/auth/getStrategies.js';
|
|
68
39
|
import getMockUser from '../lib/server/auth/getMockUser.js';
|
|
40
|
+
import isTabAnswer from './lib/isTabAnswer.js';
|
|
41
|
+
import getRequestSurface from './lib/getRequestSurface.js';
|
|
69
42
|
import jitPageHandler from './routes/jitPage.js';
|
|
43
|
+
import loadDocsRoutes from './routes/docs/loadDocsRoutes.js';
|
|
70
44
|
import localDevToolsOnly from './middleware/localDevToolsOnly.js';
|
|
71
45
|
import lowdefyConfig from '../lib/build/config.js';
|
|
72
46
|
import mcpHandler from './routes/mcp.js';
|
|
47
|
+
import mobileConfig from '../lib/build/mobileConfig.js';
|
|
48
|
+
import mobileRootHandler from './routes/mobileRoot.js';
|
|
49
|
+
import mountMobileWellKnown from './routes/mountMobileWellKnown.js';
|
|
73
50
|
import mountDevPageRoutes from './routes/mountDevPageRoutes.js';
|
|
74
51
|
import mountOauthDiscovery from './routes/mountOauthDiscovery.js';
|
|
75
52
|
import noStore from './middleware/noStore.js';
|
|
@@ -83,7 +60,6 @@ import rootHandler from './routes/root.js';
|
|
|
83
60
|
import staleFlag from './middleware/staleFlag.js';
|
|
84
61
|
import stampCaller from './middleware/stampCaller.js';
|
|
85
62
|
import startIdleGc from '../lib/server/startIdleGc.js';
|
|
86
|
-
import getDocsIndex from '../lib/docs/getDocsIndex.js';
|
|
87
63
|
import usageHandler from './routes/usage.js';
|
|
88
64
|
import userHandler from './routes/user.js';
|
|
89
65
|
import websocketHandler from './routes/websocket.js';
|
|
@@ -94,6 +70,38 @@ const basePath = lowdefyConfig.basePath ?? '';
|
|
|
94
70
|
// the page shows as a generic error, beside the other requests' results) also times out in dev.
|
|
95
71
|
const requestTimeoutMs = lowdefyConfig.requestTimeout ?? 30000;
|
|
96
72
|
|
|
73
|
+
// A docs route handler that loads the docs routes on its first call.
|
|
74
|
+
function docsRoute(name) {
|
|
75
|
+
return async function lazyDocsRoute(c, next) {
|
|
76
|
+
const routes = await loadDocsRoutes();
|
|
77
|
+
return routes[name](c, next);
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// Once the child has answered its first request (the manager's /api/ping
|
|
82
|
+
// readiness probe), the docs routes load and the docs index is built in the
|
|
83
|
+
// background, so neither delays start and the first doc search does not pay
|
|
84
|
+
// for reading every plugin and module's docs. A docs request made before then
|
|
85
|
+
// waits on the same load.
|
|
86
|
+
let docsWarmUpStarted = false;
|
|
87
|
+
|
|
88
|
+
function warmUpDocs() {
|
|
89
|
+
loadDocsRoutes()
|
|
90
|
+
.then((routes) => routes.getDocsIndex())
|
|
91
|
+
.catch(() => {
|
|
92
|
+
// Not kept: the next docs request loads again and answers with the error.
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
function pingAndWarmUpDocs(c) {
|
|
97
|
+
const response = pingHandler(c);
|
|
98
|
+
if (!docsWarmUpStarted) {
|
|
99
|
+
docsWarmUpStarted = true;
|
|
100
|
+
setImmediate(warmUpDocs);
|
|
101
|
+
}
|
|
102
|
+
return response;
|
|
103
|
+
}
|
|
104
|
+
|
|
97
105
|
// Dev Hono app — mounted into Vite via @hono/vite-dev-server (Vite owns HTTP
|
|
98
106
|
// and serves /client/* modules with HMR; everything else lands here).
|
|
99
107
|
// No compression in dev (parity with the old next.config compress: false,
|
|
@@ -108,13 +116,10 @@ function createApp() {
|
|
|
108
116
|
|
|
109
117
|
// No api context: SSE/health routes had no apiWrapper before.
|
|
110
118
|
app.get('/api/reload', reloadHandler);
|
|
111
|
-
app.get('/api/ping',
|
|
119
|
+
app.get('/api/ping', pingAndWarmUpDocs);
|
|
120
|
+
// Dev tools, refused from other machines (localDevToolsOnly).
|
|
121
|
+
app.use('/api/dev-tools', localDevToolsOnly());
|
|
112
122
|
app.get('/api/dev-tools', devToolsHandler);
|
|
113
|
-
// Annotation helper: the in-page overlay (Cmd/Ctrl+/) POSTs annotation
|
|
114
|
-
// batches here and gets back the enriched agent-readable text, which the
|
|
115
|
-
// overlay copies to the clipboard. No api context needed.
|
|
116
|
-
// /lowdefy-feedback is a reserved page-path prefix in dev, like /lowdefy-docs.
|
|
117
|
-
app.post('/lowdefy-feedback', feedbackHandler);
|
|
118
123
|
|
|
119
124
|
const mockUser = getMockUser();
|
|
120
125
|
if (authJson.configured === true && !mockUser) {
|
|
@@ -130,6 +135,7 @@ function createApp() {
|
|
|
130
135
|
app,
|
|
131
136
|
auth: authJson.configured === true && !mockUser ? getAuth({ logger }) : null,
|
|
132
137
|
});
|
|
138
|
+
mountMobileWellKnown({ app, basePath, mobileConfig });
|
|
133
139
|
app.all('/.well-known/*', wellKnownFallbackHandler);
|
|
134
140
|
|
|
135
141
|
// Docs and MCP endpoint for AI coding agents — always on in dev. Serves
|
|
@@ -137,9 +143,7 @@ function createApp() {
|
|
|
137
143
|
// the extracted core docs (@lowdefy/docs-content). Mounted outside /api/*
|
|
138
144
|
// so it can't clash with user API endpoints; /lowdefy-docs is a reserved page
|
|
139
145
|
// prefix in dev. The handlers need no auth protection or api context —
|
|
140
|
-
// they read build artifacts and node_modules directly
|
|
141
|
-
// run-endpoint and eval-operator build a full Lowdefy context (createLowdefyContext),
|
|
142
|
-
// which resolves the caller from the request headers via resolveAuthentication.
|
|
146
|
+
// they read build artifacts and node_modules directly.
|
|
143
147
|
// The MCP transport is registered before staleFlag on purpose: hono
|
|
144
148
|
// dispatches in registration order, so the stale middleware never sees a
|
|
145
149
|
// JSON-RPC envelope. MCP carries its own stale notice, prepended to each
|
|
@@ -150,59 +154,37 @@ function createApp() {
|
|
|
150
154
|
// does not match the bare path.
|
|
151
155
|
app.use('/lowdefy-docs', localDevToolsOnly());
|
|
152
156
|
app.use('/lowdefy-docs/*', localDevToolsOnly());
|
|
153
|
-
app.all('/lowdefy-docs/mcp',
|
|
157
|
+
app.all('/lowdefy-docs/mcp', docsRoute('mcp'));
|
|
154
158
|
// Flags every other docs response while the last build failed. Registered
|
|
155
159
|
// twice: hono's `/*` pattern does not match the bare path.
|
|
156
160
|
app.use('/lowdefy-docs', staleFlag());
|
|
157
161
|
app.use('/lowdefy-docs/*', staleFlag());
|
|
158
|
-
app.get('/lowdefy-docs',
|
|
159
|
-
app.get('/lowdefy-docs/build-status',
|
|
160
|
-
// Push channel for non-MCP clients.
|
|
161
|
-
|
|
162
|
-
app.get('/lowdefy-docs/
|
|
163
|
-
app.get('/lowdefy-docs/
|
|
164
|
-
app.
|
|
165
|
-
app.
|
|
166
|
-
app.post('/lowdefy-docs/
|
|
167
|
-
app.post('/lowdefy-docs/mutants', docsMutantsHandler);
|
|
168
|
-
app.get('/lowdefy-docs/inspect-state/:pageId{.+}', docsInspectStateHandler);
|
|
169
|
-
app.post('/lowdefy-docs/eval-operator', docsEvalOperatorHandler);
|
|
170
|
-
app.post('/lowdefy-docs/run-request', docsRunRequestHandler);
|
|
171
|
-
app.post('/lowdefy-docs/run-endpoint', docsRunEndpointHandler);
|
|
172
|
-
app.get('/lowdefy-docs/app-map', docsAppMapHandler);
|
|
173
|
-
app.get('/lowdefy-docs/checkpoints', docsCheckpointsListHandler);
|
|
174
|
-
app.post('/lowdefy-docs/checkpoints', docsCheckpointsCreateHandler);
|
|
175
|
-
app.post('/lowdefy-docs/checkpoints/revert', docsCheckpointsRevertHandler);
|
|
176
|
-
app.get('/lowdefy-docs/state-checkpoints', docsStateCheckpointsListHandler);
|
|
177
|
-
app.post('/lowdefy-docs/state-checkpoints/snapshot', docsSnapshotStateHandler);
|
|
178
|
-
app.post('/lowdefy-docs/state-checkpoints/load', docsLoadStateHandler);
|
|
179
|
-
app.post('/lowdefy-docs/restart', docsRestartHandler);
|
|
162
|
+
app.get('/lowdefy-docs', docsRoute('index'));
|
|
163
|
+
app.get('/lowdefy-docs/build-status', docsRoute('buildStatus'));
|
|
164
|
+
// Push channel for non-MCP clients.
|
|
165
|
+
app.get('/lowdefy-docs/events', docsRoute('events'));
|
|
166
|
+
app.get('/lowdefy-docs/page-config/:pageId{.+}', docsRoute('pageConfig'));
|
|
167
|
+
app.get('/lowdefy-docs/find/:id', docsRoute('find'));
|
|
168
|
+
app.post('/lowdefy-docs/journey', docsRoute('journey'));
|
|
169
|
+
app.post('/lowdefy-docs/mutants', docsRoute('mutants'));
|
|
170
|
+
app.post('/lowdefy-docs/restart', docsRoute('restart'));
|
|
180
171
|
// Live-tab inspection channel: dev tabs (client/Inspector.jsx) answer
|
|
181
|
-
// targeted SSE events by posting results here; GET lists connected tabs
|
|
182
|
-
//
|
|
183
|
-
//
|
|
184
|
-
//
|
|
185
|
-
|
|
186
|
-
|
|
172
|
+
// targeted SSE events by posting results here; GET lists connected tabs.
|
|
173
|
+
// The live-tab channel acts on the developer's open tabs - the same
|
|
174
|
+
// cross-site guard as the docs tools. A phone paired with `lowdefy dev --lan`
|
|
175
|
+
// is a dev tab too: it may answer what it is asked and post the page it
|
|
176
|
+
// shows (isTabAnswer), nothing else.
|
|
177
|
+
const tabChannelOnly = localDevToolsOnly({ allowPaired: isTabAnswer });
|
|
178
|
+
app.use('/api/dev-inspect', tabChannelOnly);
|
|
179
|
+
app.use('/api/dev-inspect/*', tabChannelOnly);
|
|
187
180
|
app.all('/api/dev-inspect', devInspectHandler);
|
|
188
181
|
app.all('/api/dev-inspect/*', devInspectHandler);
|
|
189
182
|
// The dev recorder (client/Recorder.jsx) posts interaction records here.
|
|
190
183
|
// It needs no Lowdefy context, and registering it before apiContext keeps
|
|
191
184
|
// it out of the request timeout list.
|
|
192
|
-
|
|
185
|
+
// A paired phone's recorder may post too: the route only writes records.
|
|
186
|
+
app.use('/api/dev-recording', localDevToolsOnly({ allowPaired: (c) => c.req.method === 'POST' }));
|
|
193
187
|
app.post('/api/dev-recording', bodyLimit({ maxSize: 1024 * 1024 }), devRecordingHandler);
|
|
194
|
-
// Built now so the first doc search does not pay for reading every plugin
|
|
195
|
-
// and module's docs.
|
|
196
|
-
getDocsIndex();
|
|
197
|
-
app.get('/lowdefy-docs/plugins', docsPluginsHandler);
|
|
198
|
-
app.get('/lowdefy-docs/schema/:kind/:type', docsSchemaHandler);
|
|
199
|
-
app.get('/lowdefy-docs/examples/:type', docsExamplesHandler);
|
|
200
|
-
app.get('/lowdefy-docs/search', docsSearchHandler);
|
|
201
|
-
app.get('/lowdefy-docs/icons', docsIconsHandler);
|
|
202
|
-
app.get('/lowdefy-docs/plugin-doc/:package{.+}', docsPluginDocHandler);
|
|
203
|
-
app.get('/lowdefy-docs/content/:slug{.+}', docsContentHandler);
|
|
204
|
-
app.get('/lowdefy-docs/:kind', docsTypesHandler);
|
|
205
|
-
|
|
206
188
|
// Only the routes that run app logic: JIT page builds, the docs/MCP routes and the SSE streams
|
|
207
189
|
// are dev-only and can legitimately run longer than any production request.
|
|
208
190
|
if (requestTimeoutMs > 0) {
|
|
@@ -221,9 +203,14 @@ function createApp() {
|
|
|
221
203
|
// as in the production server. /api/root is the dev form of the root config the
|
|
222
204
|
// production page embeds. The page routes use the same middleware.
|
|
223
205
|
const noStoreMiddleware = noStore();
|
|
224
|
-
[
|
|
225
|
-
|
|
226
|
-
|
|
206
|
+
[
|
|
207
|
+
'/api/root',
|
|
208
|
+
'/api/mobile/root',
|
|
209
|
+
'/api/page/*',
|
|
210
|
+
'/api/user',
|
|
211
|
+
'/api/request/*',
|
|
212
|
+
'/api/endpoints/*',
|
|
213
|
+
].forEach((route) => app.use(route, noStoreMiddleware));
|
|
227
214
|
// Unified dev get-session: createLowdefyContext resolves the mock or headless
|
|
228
215
|
// caller into context.user on every path, so read it here rather than
|
|
229
216
|
// re-deriving the precedence. context.user is only absent in the real-engine
|
|
@@ -241,7 +228,18 @@ function createApp() {
|
|
|
241
228
|
app.use('/api/request/*', stampCaller());
|
|
242
229
|
app.use('/api/endpoints/*', stampCaller());
|
|
243
230
|
app.use('/api/page/*', stampCaller());
|
|
231
|
+
app.use('/api/mobile/root', stampCaller());
|
|
232
|
+
// A shell revalidates the pages and root config it keeps with If-None-Match.
|
|
233
|
+
// Registered inside noStore and stampCaller, so a 304 still carries both.
|
|
234
|
+
// Browsers never revalidate a no-store page, so their page responses are
|
|
235
|
+
// left as they were, with no ETag.
|
|
236
|
+
const etagMiddleware = etag();
|
|
237
|
+
app.use('/api/page/*', (c, next) =>
|
|
238
|
+
getRequestSurface(c) === 'mobile' ? etagMiddleware(c, next) : next()
|
|
239
|
+
);
|
|
240
|
+
app.use('/api/mobile/root', etagMiddleware);
|
|
244
241
|
app.get('/api/root', rootHandler);
|
|
242
|
+
app.get('/api/mobile/root', mobileRootHandler);
|
|
245
243
|
app.get('/api/page/*', jitPageHandler);
|
|
246
244
|
app.all('/api/request/*', requestHandler);
|
|
247
245
|
// Endpoint payloads may carry base64 file content (emitFileContent + CallAPI);
|
|
@@ -17,6 +17,7 @@
|
|
|
17
17
|
import fs from 'node:fs';
|
|
18
18
|
import os from 'node:os';
|
|
19
19
|
import path from 'node:path';
|
|
20
|
+
import { afterAll, afterEach, beforeAll, describe, expect, test } from 'vitest';
|
|
20
21
|
|
|
21
22
|
const { default: renderDevPage } = await import('./renderDevPage.js');
|
|
22
23
|
const { JOURNEY_COOKIES, writeJourneyCookie } = await import('../../lib/server/journeyCookies.js');
|
|
@@ -14,12 +14,27 @@
|
|
|
14
14
|
limitations under the License.
|
|
15
15
|
*/
|
|
16
16
|
|
|
17
|
+
import { HTTPException } from 'hono/http-exception';
|
|
18
|
+
|
|
17
19
|
// Splits the rest of a catch-all route into decoded segments, independent of
|
|
18
20
|
// any configured basePath. Mirrors the Next.js [...param] query arrays —
|
|
19
21
|
// nested ids (slashes in pageId or endpointId) are real.
|
|
22
|
+
// A malformed percent escape (`%ZZ`, a bare `%`) is the caller's own URL, so it answers 400, not
|
|
23
|
+
// the 500 decodeURIComponent's URIError would raise.
|
|
24
|
+
function decodeSegment(segment) {
|
|
25
|
+
try {
|
|
26
|
+
return decodeURIComponent(segment);
|
|
27
|
+
} catch (error) {
|
|
28
|
+
if (error instanceof URIError) {
|
|
29
|
+
throw new HTTPException(400, { message: 'Malformed URL path.' });
|
|
30
|
+
}
|
|
31
|
+
throw error;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
20
35
|
function getPathSegments(c, prefix) {
|
|
21
36
|
const rest = c.req.path.split(prefix)[1] ?? '';
|
|
22
|
-
return rest.split('/').filter(Boolean).map(
|
|
37
|
+
return rest.split('/').filter(Boolean).map(decodeSegment);
|
|
23
38
|
}
|
|
24
39
|
|
|
25
40
|
export default getPathSegments;
|
|
@@ -14,10 +14,12 @@
|
|
|
14
14
|
limitations under the License.
|
|
15
15
|
*/
|
|
16
16
|
|
|
17
|
-
import
|
|
17
|
+
import { type } from '@lowdefy/helpers';
|
|
18
18
|
|
|
19
|
-
|
|
20
|
-
|
|
19
|
+
// A mobile shell sends x-lowdefy-shell on its requests; a browser never does.
|
|
20
|
+
// The surface picks which pages a page request may serve (getPageConfig).
|
|
21
|
+
function getRequestSurface(c) {
|
|
22
|
+
return type.isNone(c.req.header('x-lowdefy-shell')) ? 'web' : 'mobile';
|
|
21
23
|
}
|
|
22
24
|
|
|
23
|
-
export default
|
|
25
|
+
export default getRequestSurface;
|
|
@@ -0,0 +1,32 @@
|
|
|
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 getPathSegments from './getPathSegments.js';
|
|
18
|
+
|
|
19
|
+
// A dev tab's answer leg of the tab channel: POST /api/dev-inspect with the
|
|
20
|
+
// result of a request the dev server sent it, or POST /api/dev-inspect/page
|
|
21
|
+
// with the page it shows. A phone paired with `lowdefy dev --lan` is a dev tab
|
|
22
|
+
// and may send these; it may not list the tabs, or call any other dev-inspect
|
|
23
|
+
// route, which act on the developer's tabs.
|
|
24
|
+
function isTabAnswer(c) {
|
|
25
|
+
if (c.req.method !== 'POST') {
|
|
26
|
+
return false;
|
|
27
|
+
}
|
|
28
|
+
const segments = getPathSegments(c, '/api/dev-inspect/');
|
|
29
|
+
return segments.length === 0 || (segments.length === 1 && segments[0] === 'page');
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export default isTabAnswer;
|
|
@@ -0,0 +1,35 @@
|
|
|
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
|
+
// A dev tab posting to the tab channel (/api/dev-inspect, /api/dev-recording):
|
|
18
|
+
// a browser tab from its own page, whose Origin is this server, or a phone
|
|
19
|
+
// shell (Lowdefy Dev), which sends no Origin and names itself with
|
|
20
|
+
// x-lowdefy-shell. A page on another site always sends an Origin, so it is
|
|
21
|
+
// refused; and a custom header from it needs a CORS preflight, which the dev
|
|
22
|
+
// server passes for localhost origins only.
|
|
23
|
+
function isTabChannelCaller(c) {
|
|
24
|
+
const origin = c.req.header('origin');
|
|
25
|
+
if (!origin) {
|
|
26
|
+
return c.req.header('x-lowdefy-shell') !== undefined;
|
|
27
|
+
}
|
|
28
|
+
try {
|
|
29
|
+
return new URL(origin).host === c.req.header('host');
|
|
30
|
+
} catch {
|
|
31
|
+
return false;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export default isTabChannelCaller;
|
|
@@ -23,8 +23,10 @@ function apiContext() {
|
|
|
23
23
|
if (c.get('lowdefyContext')) {
|
|
24
24
|
return next();
|
|
25
25
|
}
|
|
26
|
-
|
|
27
|
-
|
|
26
|
+
await createLowdefyContext({
|
|
27
|
+
c,
|
|
28
|
+
onContext: (context) => c.set('lowdefyContext', context),
|
|
29
|
+
});
|
|
28
30
|
return next();
|
|
29
31
|
};
|
|
30
32
|
}
|
|
@@ -17,6 +17,7 @@
|
|
|
17
17
|
import { Hono } from 'hono';
|
|
18
18
|
|
|
19
19
|
import createSameOriginGuard from './createSameOriginGuard.js';
|
|
20
|
+
import { expect, test } from 'vitest';
|
|
20
21
|
|
|
21
22
|
function createApp({ allowNoOrigin } = {}) {
|
|
22
23
|
const guardSameOrigin = createSameOriginGuard({ allowNoOrigin });
|
|
@@ -15,61 +15,49 @@
|
|
|
15
15
|
*/
|
|
16
16
|
|
|
17
17
|
import { redactErrorResponse } from '@lowdefy/api';
|
|
18
|
+
import { isExpectedError } from '@lowdefy/errors';
|
|
18
19
|
import { HTTPException } from 'hono/http-exception';
|
|
19
20
|
|
|
21
|
+
// The HTTP answer to each expected outcome.
|
|
22
|
+
// AuthenticationError: an unauthenticated request to a protected endpoint.
|
|
23
|
+
// AuthorizationError: an authenticated caller whose roles do not permit the resource.
|
|
24
|
+
// TwoFactorEnrolmentRequiredError: an authorized caller who has not enrolled a second factor
|
|
25
|
+
// under auth.twoFactor.required. 403, not 401 - a 401 reads to the client as a dead session
|
|
26
|
+
// and bounces the user to sign-in, which is the loop the gate exists to avoid.
|
|
27
|
+
// UserError: an API client whose payload does not match the endpoint's payloadSchema (or any
|
|
28
|
+
// other UserError raised before a routine starts). A page's CallAPI payload the schema
|
|
29
|
+
// refuses is a ConfigError instead: the page's own config built it (validatePayload). A
|
|
30
|
+
// UserError raised inside a routine never gets here - it returns 200 with success: false
|
|
31
|
+
// through buildEndpointResult.
|
|
32
|
+
const expectedAnswers = {
|
|
33
|
+
AuthenticationError: { status: 401, warning: 'Unauthenticated request', text: 'Unauthorized' },
|
|
34
|
+
AuthorizationError: { status: 403, warning: 'Forbidden', text: 'Forbidden' },
|
|
35
|
+
TwoFactorEnrolmentRequiredError: {
|
|
36
|
+
status: 403,
|
|
37
|
+
warning: 'Two-factor enrolment required',
|
|
38
|
+
text: 'Two-factor enrolment required',
|
|
39
|
+
},
|
|
40
|
+
UserError: { status: 400, warning: 'Bad request', text: 'Bad Request' },
|
|
41
|
+
};
|
|
42
|
+
|
|
20
43
|
// Hono routes every handler error to the app-level error handler — upstream
|
|
21
44
|
// middleware try/catch never sees them. API routes get the serialized error
|
|
22
45
|
// JSON the old apiWrapper returned; page routes get a plain 500.
|
|
23
46
|
function createErrorHandler({ basePath = '', logger }) {
|
|
24
47
|
return async function errorHandler(error, c) {
|
|
25
48
|
const path = basePath ? c.req.path.replace(basePath, '') : c.req.path;
|
|
26
|
-
//
|
|
27
|
-
//
|
|
28
|
-
//
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
}
|
|
35
|
-
return c.text('Unauthorized', 401);
|
|
36
|
-
}
|
|
37
|
-
// An authenticated caller whose roles do not permit the resource. Expected
|
|
38
|
-
// traffic, not a fault: one warning line, no structured error log and no
|
|
39
|
-
// Sentry capture.
|
|
40
|
-
if (error.name === 'AuthorizationError') {
|
|
41
|
-
logger.warn(`Forbidden: ${c.req.method} ${c.req.path}`);
|
|
42
|
-
if (path.startsWith('/api/')) {
|
|
43
|
-
return c.json({ name: error.name, message: error.message }, 403);
|
|
44
|
-
}
|
|
45
|
-
return c.text('Forbidden', 403);
|
|
46
|
-
}
|
|
47
|
-
// An authorized caller who has not enrolled a second factor under
|
|
48
|
-
// auth.twoFactor.required. 403, not 401 - a 401 reads to the client as a dead
|
|
49
|
-
// session and bounces the user to sign-in, which is the loop the gate exists to
|
|
50
|
-
// avoid. Expected traffic under required: true, so one warning line and no
|
|
51
|
-
// Sentry capture, exactly as for AuthenticationError.
|
|
52
|
-
if (error.name === 'TwoFactorEnrolmentRequiredError') {
|
|
53
|
-
logger.warn(`Two-factor enrolment required: ${c.req.method} ${c.req.path}`);
|
|
54
|
-
if (path.startsWith('/api/')) {
|
|
55
|
-
return c.json({ name: error.name, message: error.message }, 403);
|
|
56
|
-
}
|
|
57
|
-
return c.text('Two-factor enrolment required', 403);
|
|
58
|
-
}
|
|
59
|
-
// An API client whose payload does not match the endpoint's declared
|
|
60
|
-
// payloadSchema (or any other UserError raised before a routine starts). A
|
|
61
|
-
// page's CallAPI payload the schema refuses is a ConfigError instead: the
|
|
62
|
-
// page's own config built it (validatePayload). The caller's own
|
|
63
|
-
// request is wrong, not the config or the server: a 400 with the message the
|
|
64
|
-
// caller needs, one warning line, no structured error log and no Sentry
|
|
65
|
-
// capture. A UserError raised inside a routine never gets here - it returns
|
|
66
|
-
// 200 with success: false through buildEndpointResult.
|
|
67
|
-
if (error.name === 'UserError') {
|
|
68
|
-
logger.warn(`Bad request: ${c.req.method} ${c.req.path} - ${error.message}`);
|
|
49
|
+
// An expected outcome - the system worked and said no - is one warning line and its
|
|
50
|
+
// status, with no structured error log and no Sentry capture, so probing cannot flood
|
|
51
|
+
// either. isExpectedError decides which errors those are; the table only gives the answer.
|
|
52
|
+
if (isExpectedError(error)) {
|
|
53
|
+
// A name expectedErrorNames gains before this table does is still a refusal: a 400.
|
|
54
|
+
const { status, warning, text } = expectedAnswers[error.name] ?? expectedAnswers.UserError;
|
|
55
|
+
const detail = error.name === 'UserError' ? ` - ${error.message}` : '';
|
|
56
|
+
logger.warn(`${warning}: ${c.req.method} ${c.req.path}${detail}`);
|
|
69
57
|
if (path.startsWith('/api/')) {
|
|
70
|
-
return c.json({ name: error.name, message: error.message },
|
|
58
|
+
return c.json({ name: error.name, message: error.message }, status);
|
|
71
59
|
}
|
|
72
|
-
return c.text(
|
|
60
|
+
return c.text(text, status);
|
|
73
61
|
}
|
|
74
62
|
// A route or transport that has already decided its own HTTP answer - hono's
|
|
75
63
|
// HTTPException carries the response to send. The MCP transport refuses an
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
|
|
17
17
|
import { Hono } from 'hono';
|
|
18
18
|
import { HTTPException } from 'hono/http-exception';
|
|
19
|
-
import {
|
|
19
|
+
import { vi, expect, test } from 'vitest';
|
|
20
20
|
|
|
21
21
|
import createErrorHandler from './errorHandler.js';
|
|
22
22
|
|
|
@@ -30,7 +30,7 @@ import createErrorHandler from './errorHandler.js';
|
|
|
30
30
|
const SECRET = 'SECRET-RECEIVED-VALUE';
|
|
31
31
|
|
|
32
32
|
function createLogger() {
|
|
33
|
-
return { error:
|
|
33
|
+
return { error: vi.fn(), warn: vi.fn() };
|
|
34
34
|
}
|
|
35
35
|
|
|
36
36
|
// The error handler is only reachable through hono's app-level onError, so the
|
|
@@ -90,7 +90,7 @@ function createErrorWithCause() {
|
|
|
90
90
|
|
|
91
91
|
test('errorHandler returns 401 with only name and message for an AuthenticationError on an api path', async () => {
|
|
92
92
|
const logger = createLogger();
|
|
93
|
-
const context = { handleError:
|
|
93
|
+
const context = { handleError: vi.fn() };
|
|
94
94
|
const res = await createApp({
|
|
95
95
|
context,
|
|
96
96
|
error: createAuthenticationError('Unauthenticated.'),
|
|
@@ -129,7 +129,7 @@ test('errorHandler returns text Unauthorized at 401 for an AuthenticationError o
|
|
|
129
129
|
|
|
130
130
|
test('errorHandler returns 403 with only name and message for an AuthorizationError on an api path', async () => {
|
|
131
131
|
const logger = createLogger();
|
|
132
|
-
const context = { handleError:
|
|
132
|
+
const context = { handleError: vi.fn() };
|
|
133
133
|
const res = await createApp({
|
|
134
134
|
context,
|
|
135
135
|
error: createAuthorizationError('Forbidden.'),
|
|
@@ -170,7 +170,7 @@ test('errorHandler returns text Forbidden at 403 for an AuthorizationError on a
|
|
|
170
170
|
|
|
171
171
|
test('errorHandler returns 403 with only name and message for a TwoFactorEnrolmentRequiredError on an api path', async () => {
|
|
172
172
|
const logger = createLogger();
|
|
173
|
-
const context = { handleError:
|
|
173
|
+
const context = { handleError: vi.fn() };
|
|
174
174
|
const res = await createApp({
|
|
175
175
|
context,
|
|
176
176
|
error: createTwoFactorEnrolmentRequiredError('Two-factor enrolment required.'),
|
|
@@ -200,7 +200,7 @@ test('errorHandler does not send a TwoFactorEnrolmentRequiredError through the r
|
|
|
200
200
|
|
|
201
201
|
test('errorHandler returns text at 403 for a TwoFactorEnrolmentRequiredError on a page path', async () => {
|
|
202
202
|
const logger = createLogger();
|
|
203
|
-
const context = { handleError:
|
|
203
|
+
const context = { handleError: vi.fn() };
|
|
204
204
|
const res = await createApp({
|
|
205
205
|
context,
|
|
206
206
|
error: createTwoFactorEnrolmentRequiredError('Two-factor enrolment required.'),
|
|
@@ -215,7 +215,7 @@ test('errorHandler returns text at 403 for a TwoFactorEnrolmentRequiredError on
|
|
|
215
215
|
|
|
216
216
|
test('errorHandler returns 400 with only name and message for a UserError on an api path', async () => {
|
|
217
217
|
const logger = createLogger();
|
|
218
|
-
const context = { handleError:
|
|
218
|
+
const context = { handleError: vi.fn() };
|
|
219
219
|
const res = await createApp({
|
|
220
220
|
context,
|
|
221
221
|
error: createUserError('Payload for endpoint "x" does not match its payloadSchema.'),
|
|
@@ -312,7 +312,7 @@ test('errorHandler omits the cause chain from the 500 envelope', async () => {
|
|
|
312
312
|
});
|
|
313
313
|
|
|
314
314
|
test('errorHandler adds devError with the full error to the 500 envelope in dev mode', async () => {
|
|
315
|
-
const context = { handleError:
|
|
315
|
+
const context = { handleError: vi.fn(), mode: 'dev', rid: 'rid-1' };
|
|
316
316
|
const res = await createApp({
|
|
317
317
|
context,
|
|
318
318
|
error: createErrorWithCause(),
|
|
@@ -348,7 +348,7 @@ test('errorHandler returns text Internal Server Error at 500 on a page path with
|
|
|
348
348
|
|
|
349
349
|
test('errorHandler awaits context.handleError before serializing the response', async () => {
|
|
350
350
|
const context = {
|
|
351
|
-
handleError:
|
|
351
|
+
handleError: vi.fn(async (error) => {
|
|
352
352
|
await new Promise((resolve) => setTimeout(resolve, 10));
|
|
353
353
|
error.handled = true;
|
|
354
354
|
}),
|
|
@@ -369,7 +369,7 @@ test('errorHandler awaits context.handleError before serializing the response',
|
|
|
369
369
|
// serialization or the error is logged a second time.
|
|
370
370
|
test('errorHandler returns handled true on the 500 envelope after handleError sets it', async () => {
|
|
371
371
|
const context = {
|
|
372
|
-
handleError:
|
|
372
|
+
handleError: vi.fn(async (error) => {
|
|
373
373
|
error.handled = true;
|
|
374
374
|
}),
|
|
375
375
|
};
|
|
@@ -14,6 +14,7 @@
|
|
|
14
14
|
limitations under the License.
|
|
15
15
|
*/
|
|
16
16
|
|
|
17
|
+
import { remoteCallerHeader } from '../../lib/server/pairingHeaders.js';
|
|
17
18
|
import createSameOriginGuard from './createSameOriginGuard.js';
|
|
18
19
|
|
|
19
20
|
// The dev tools under /lowdefy-docs run requests, endpoints and journeys
|
|
@@ -25,8 +26,19 @@ import createSameOriginGuard from './createSameOriginGuard.js';
|
|
|
25
26
|
// reaches here: Vite's host check refuses a Host that is not local first.
|
|
26
27
|
const guardSameOrigin = createSameOriginGuard({ allowNoOrigin: true });
|
|
27
28
|
|
|
28
|
-
|
|
29
|
+
// A phone paired with `lowdefy dev --lan` reaches the app, never the dev tools:
|
|
30
|
+
// the pairing token lets a device in, not a second developer. The manager's
|
|
31
|
+
// proxy marks such a request with remoteCallerHeader. allowPaired names the
|
|
32
|
+
// few tab-channel requests a paired phone makes as a dev tab (answering what
|
|
33
|
+
// the dev server asks it, posting its recording), which it may send.
|
|
34
|
+
function localDevToolsOnly({ allowPaired = () => false } = {}) {
|
|
29
35
|
return async function localDevToolsOnlyMiddleware(c, next) {
|
|
36
|
+
if (c.req.header(remoteCallerHeader) !== undefined && !allowPaired(c)) {
|
|
37
|
+
return c.json(
|
|
38
|
+
{ error: 'The dev tools answer only on the computer running lowdefy dev.' },
|
|
39
|
+
403
|
|
40
|
+
);
|
|
41
|
+
}
|
|
30
42
|
const refusal = guardSameOrigin(c);
|
|
31
43
|
if (refusal !== null) {
|
|
32
44
|
return refusal;
|