ontrackd 0.0.0-stage → 0.11.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/LICENSE +14 -0
- package/README.md +128 -2
- package/dist/cli/build.d.ts +1 -0
- package/dist/cli/build.js +172 -0
- package/dist/cli/build.js.map +1 -0
- package/dist/cli/cloud.d.ts +20 -0
- package/dist/cli/cloud.js +395 -0
- package/dist/cli/cloud.js.map +1 -0
- package/dist/cli/feedback.d.ts +4 -0
- package/dist/cli/feedback.js +90 -0
- package/dist/cli/feedback.js.map +1 -0
- package/dist/cli/hugo.d.ts +1 -0
- package/dist/cli/hugo.js +396 -0
- package/dist/cli/hugo.js.map +1 -0
- package/dist/cli/init.d.ts +8 -0
- package/dist/cli/init.js +346 -0
- package/dist/cli/init.js.map +1 -0
- package/dist/cli/invite.d.ts +2 -0
- package/dist/cli/invite.js +65 -0
- package/dist/cli/invite.js.map +1 -0
- package/dist/cli/link.d.ts +20 -0
- package/dist/cli/link.js +287 -0
- package/dist/cli/link.js.map +1 -0
- package/dist/cli/pull.d.ts +31 -0
- package/dist/cli/pull.js +273 -0
- package/dist/cli/pull.js.map +1 -0
- package/dist/cli/push.d.ts +9 -0
- package/dist/cli/push.js +57 -0
- package/dist/cli/push.js.map +1 -0
- package/dist/cli/remote.d.ts +1 -0
- package/dist/cli/remote.js +114 -0
- package/dist/cli/remote.js.map +1 -0
- package/dist/cli/serve.d.ts +1 -0
- package/dist/cli/serve.js +178 -0
- package/dist/cli/serve.js.map +1 -0
- package/dist/cli/sidecar.d.ts +9 -0
- package/dist/cli/sidecar.js +23 -0
- package/dist/cli/sidecar.js.map +1 -0
- package/dist/core/anchorId.d.ts +42 -0
- package/dist/core/anchorId.js +50 -0
- package/dist/core/anchorId.js.map +1 -0
- package/dist/core/apiKind.d.ts +42 -0
- package/dist/core/apiKind.js +83 -0
- package/dist/core/apiKind.js.map +1 -0
- package/dist/core/astroAnchors.d.ts +39 -0
- package/dist/core/astroAnchors.js +217 -0
- package/dist/core/astroAnchors.js.map +1 -0
- package/dist/core/attachmentTypes.d.ts +74 -0
- package/dist/core/attachmentTypes.js +199 -0
- package/dist/core/attachmentTypes.js.map +1 -0
- package/dist/core/elementHints.d.ts +40 -0
- package/dist/core/elementHints.js +116 -0
- package/dist/core/elementHints.js.map +1 -0
- package/dist/core/exportTaskDoc.d.ts +81 -0
- package/dist/core/exportTaskDoc.js +828 -0
- package/dist/core/exportTaskDoc.js.map +1 -0
- package/dist/core/feedbackTypes.d.ts +241 -0
- package/dist/core/feedbackTypes.js +2 -0
- package/dist/core/feedbackTypes.js.map +1 -0
- package/dist/core/fingerprint.d.ts +12 -0
- package/dist/core/fingerprint.js +24 -0
- package/dist/core/fingerprint.js.map +1 -0
- package/dist/core/htmlAnchors.d.ts +18 -0
- package/dist/core/htmlAnchors.js +157 -0
- package/dist/core/htmlAnchors.js.map +1 -0
- package/dist/core/imageSniff.d.ts +7 -0
- package/dist/core/imageSniff.js +12 -0
- package/dist/core/imageSniff.js.map +1 -0
- package/dist/core/ordering.d.ts +16 -0
- package/dist/core/ordering.js +10 -0
- package/dist/core/ordering.js.map +1 -0
- package/dist/core/oxcAst.d.ts +39 -0
- package/dist/core/oxcAst.js +147 -0
- package/dist/core/oxcAst.js.map +1 -0
- package/dist/core/pageUrl.d.ts +10 -0
- package/dist/core/pageUrl.js +27 -0
- package/dist/core/pageUrl.js.map +1 -0
- package/dist/core/participants.d.ts +14 -0
- package/dist/core/participants.js +38 -0
- package/dist/core/participants.js.map +1 -0
- package/dist/core/ports.d.ts +86 -0
- package/dist/core/ports.js +2 -0
- package/dist/core/ports.js.map +1 -0
- package/dist/core/projectSecret.d.ts +9 -0
- package/dist/core/projectSecret.js +57 -0
- package/dist/core/projectSecret.js.map +1 -0
- package/dist/core/recipe.d.ts +117 -0
- package/dist/core/recipe.js +181 -0
- package/dist/core/recipe.js.map +1 -0
- package/dist/core/recordingSummary.d.ts +12 -0
- package/dist/core/recordingSummary.js +150 -0
- package/dist/core/recordingSummary.js.map +1 -0
- package/dist/core/resolveAnchors.d.ts +70 -0
- package/dist/core/resolveAnchors.js +101 -0
- package/dist/core/resolveAnchors.js.map +1 -0
- package/dist/core/scriptImport.d.ts +10 -0
- package/dist/core/scriptImport.js +18 -0
- package/dist/core/scriptImport.js.map +1 -0
- package/dist/core/sourceAnchors.d.ts +62 -0
- package/dist/core/sourceAnchors.js +82 -0
- package/dist/core/sourceAnchors.js.map +1 -0
- package/dist/core/sourceContext.d.ts +62 -0
- package/dist/core/sourceContext.js +182 -0
- package/dist/core/sourceContext.js.map +1 -0
- package/dist/core/sourcePath.d.ts +2 -0
- package/dist/core/sourcePath.js +11 -0
- package/dist/core/sourcePath.js.map +1 -0
- package/dist/core/staleness.d.ts +118 -0
- package/dist/core/staleness.js +155 -0
- package/dist/core/staleness.js.map +1 -0
- package/dist/core/styleOrigin.d.ts +98 -0
- package/dist/core/styleOrigin.js +142 -0
- package/dist/core/styleOrigin.js.map +1 -0
- package/dist/core/svelteAnchors.d.ts +18 -0
- package/dist/core/svelteAnchors.js +125 -0
- package/dist/core/svelteAnchors.js.map +1 -0
- package/dist/core/taskFiles.d.ts +31 -0
- package/dist/core/taskFiles.js +55 -0
- package/dist/core/taskFiles.js.map +1 -0
- package/dist/core/untrusted.d.ts +57 -0
- package/dist/core/untrusted.js +268 -0
- package/dist/core/untrusted.js.map +1 -0
- package/dist/core/vueAnchors.d.ts +21 -0
- package/dist/core/vueAnchors.js +130 -0
- package/dist/core/vueAnchors.js.map +1 -0
- package/dist/expo/app/Avatar.d.ts +6 -0
- package/dist/expo/app/Avatar.js +12 -0
- package/dist/expo/app/Avatar.js.map +1 -0
- package/dist/expo/app/Bars.d.ts +9 -0
- package/dist/expo/app/Bars.js +38 -0
- package/dist/expo/app/Bars.js.map +1 -0
- package/dist/expo/app/CommentThreadSheet.d.ts +35 -0
- package/dist/expo/app/CommentThreadSheet.js +200 -0
- package/dist/expo/app/CommentThreadSheet.js.map +1 -0
- package/dist/expo/app/CommentsSheet.d.ts +22 -0
- package/dist/expo/app/CommentsSheet.js +76 -0
- package/dist/expo/app/CommentsSheet.js.map +1 -0
- package/dist/expo/app/Files.d.ts +16 -0
- package/dist/expo/app/Files.js +62 -0
- package/dist/expo/app/Files.js.map +1 -0
- package/dist/expo/app/Highlight.d.ts +5 -0
- package/dist/expo/app/Highlight.js +12 -0
- package/dist/expo/app/Highlight.js.map +1 -0
- package/dist/expo/app/Icon.d.ts +9 -0
- package/dist/expo/app/Icon.js +22 -0
- package/dist/expo/app/Icon.js.map +1 -0
- package/dist/expo/app/MarkerPins.d.ts +10 -0
- package/dist/expo/app/MarkerPins.js +70 -0
- package/dist/expo/app/MarkerPins.js.map +1 -0
- package/dist/expo/app/Provider.d.ts +13 -0
- package/dist/expo/app/Provider.js +597 -0
- package/dist/expo/app/Provider.js.map +1 -0
- package/dist/expo/app/Sheet.d.ts +53 -0
- package/dist/expo/app/Sheet.js +106 -0
- package/dist/expo/app/Sheet.js.map +1 -0
- package/dist/expo/app/Toolbar.d.ts +26 -0
- package/dist/expo/app/Toolbar.js +71 -0
- package/dist/expo/app/Toolbar.js.map +1 -0
- package/dist/expo/app/adapter.d.ts +55 -0
- package/dist/expo/app/adapter.js +145 -0
- package/dist/expo/app/adapter.js.map +1 -0
- package/dist/expo/app/api.d.ts +68 -0
- package/dist/expo/app/api.js +86 -0
- package/dist/expo/app/api.js.map +1 -0
- package/dist/expo/app/assets/attach.png +0 -0
- package/dist/expo/app/assets/close.png +0 -0
- package/dist/expo/app/assets/comment.png +0 -0
- package/dist/expo/app/assets/edit.png +0 -0
- package/dist/expo/app/assets/file.png +0 -0
- package/dist/expo/app/assets/narrow.png +0 -0
- package/dist/expo/app/assets/panel.png +0 -0
- package/dist/expo/app/assets/pins.png +0 -0
- package/dist/expo/app/assets/pinsOff.png +0 -0
- package/dist/expo/app/assets/remove.png +0 -0
- package/dist/expo/app/assets/reopen.png +0 -0
- package/dist/expo/app/assets/resolve.png +0 -0
- package/dist/expo/app/assets/send.png +0 -0
- package/dist/expo/app/assets/widen.png +0 -0
- package/dist/expo/app/attachments.d.ts +93 -0
- package/dist/expo/app/attachments.js +181 -0
- package/dist/expo/app/attachments.js.map +1 -0
- package/dist/expo/app/cloudApi.d.ts +63 -0
- package/dist/expo/app/cloudApi.js +330 -0
- package/dist/expo/app/cloudApi.js.map +1 -0
- package/dist/expo/app/cloudAuth.d.ts +20 -0
- package/dist/expo/app/cloudAuth.js +71 -0
- package/dist/expo/app/cloudAuth.js.map +1 -0
- package/dist/expo/app/cloudHttp.d.ts +20 -0
- package/dist/expo/app/cloudHttp.js +46 -0
- package/dist/expo/app/cloudHttp.js.map +1 -0
- package/dist/expo/app/cloudSession.d.ts +30 -0
- package/dist/expo/app/cloudSession.js +72 -0
- package/dist/expo/app/cloudSession.js.map +1 -0
- package/dist/expo/app/comments.d.ts +20 -0
- package/dist/expo/app/comments.js +131 -0
- package/dist/expo/app/comments.js.map +1 -0
- package/dist/expo/app/devMenuNone.d.ts +5 -0
- package/dist/expo/app/devMenuNone.js +3 -0
- package/dist/expo/app/devMenuNone.js.map +1 -0
- package/dist/expo/app/devServerNone.d.ts +4 -0
- package/dist/expo/app/devServerNone.js +4 -0
- package/dist/expo/app/devServerNone.js.map +1 -0
- package/dist/expo/app/embeddedConfig.d.ts +1 -0
- package/dist/expo/app/embeddedConfig.js +12 -0
- package/dist/expo/app/embeddedConfig.js.map +1 -0
- package/dist/expo/app/embeddedConfigCloud.d.ts +2 -0
- package/dist/expo/app/embeddedConfigCloud.js +8 -0
- package/dist/expo/app/embeddedConfigCloud.js.map +1 -0
- package/dist/expo/app/embeddedConfigNone.d.ts +2 -0
- package/dist/expo/app/embeddedConfigNone.js +3 -0
- package/dist/expo/app/embeddedConfigNone.js.map +1 -0
- package/dist/expo/app/expo.d.ts +4 -0
- package/dist/expo/app/expo.js +35 -0
- package/dist/expo/app/expo.js.map +1 -0
- package/dist/expo/app/expoGo.d.ts +4 -0
- package/dist/expo/app/expoGo.js +33 -0
- package/dist/expo/app/expoGo.js.map +1 -0
- package/dist/expo/app/expoPickers.d.ts +11 -0
- package/dist/expo/app/expoPickers.js +91 -0
- package/dist/expo/app/expoPickers.js.map +1 -0
- package/dist/expo/app/expoRandom.d.ts +6 -0
- package/dist/expo/app/expoRandom.js +21 -0
- package/dist/expo/app/expoRandom.js.map +1 -0
- package/dist/expo/app/idle.d.ts +4 -0
- package/dist/expo/app/idle.js +7 -0
- package/dist/expo/app/idle.js.map +1 -0
- package/dist/expo/app/index.d.ts +3 -0
- package/dist/expo/app/index.js +3 -0
- package/dist/expo/app/index.js.map +1 -0
- package/dist/expo/app/interactions.d.ts +38 -0
- package/dist/expo/app/interactions.js +40 -0
- package/dist/expo/app/interactions.js.map +1 -0
- package/dist/expo/app/markers.d.ts +28 -0
- package/dist/expo/app/markers.js +187 -0
- package/dist/expo/app/markers.js.map +1 -0
- package/dist/expo/app/movedAnchors.d.ts +46 -0
- package/dist/expo/app/movedAnchors.js +39 -0
- package/dist/expo/app/movedAnchors.js.map +1 -0
- package/dist/expo/app/native.d.ts +12 -0
- package/dist/expo/app/native.js +78 -0
- package/dist/expo/app/native.js.map +1 -0
- package/dist/expo/app/panel.d.ts +27 -0
- package/dist/expo/app/panel.js +37 -0
- package/dist/expo/app/panel.js.map +1 -0
- package/dist/expo/app/payload.d.ts +43 -0
- package/dist/expo/app/payload.js +22 -0
- package/dist/expo/app/payload.js.map +1 -0
- package/dist/expo/app/pick.d.ts +14 -0
- package/dist/expo/app/pick.js +124 -0
- package/dist/expo/app/pick.js.map +1 -0
- package/dist/expo/app/pickerNone.d.ts +1 -0
- package/dist/expo/app/pickerNone.js +2 -0
- package/dist/expo/app/pickerNone.js.map +1 -0
- package/dist/expo/app/placement.d.ts +53 -0
- package/dist/expo/app/placement.js +100 -0
- package/dist/expo/app/placement.js.map +1 -0
- package/dist/expo/app/random.d.ts +13 -0
- package/dist/expo/app/random.js +56 -0
- package/dist/expo/app/random.js.map +1 -0
- package/dist/expo/app/reactNative.d.ts +2 -0
- package/dist/expo/app/reactNative.js +3 -0
- package/dist/expo/app/reactNative.js.map +1 -0
- package/dist/expo/app/runtimeConfig.d.ts +30 -0
- package/dist/expo/app/runtimeConfig.js +104 -0
- package/dist/expo/app/runtimeConfig.js.map +1 -0
- package/dist/expo/app/sheetMotion.d.ts +22 -0
- package/dist/expo/app/sheetMotion.js +39 -0
- package/dist/expo/app/sheetMotion.js.map +1 -0
- package/dist/expo/app/signIn.d.ts +32 -0
- package/dist/expo/app/signIn.js +28 -0
- package/dist/expo/app/signIn.js.map +1 -0
- package/dist/expo/app/state.d.ts +45 -0
- package/dist/expo/app/state.js +32 -0
- package/dist/expo/app/state.js.map +1 -0
- package/dist/expo/app/theme.d.ts +15 -0
- package/dist/expo/app/theme.js +9 -0
- package/dist/expo/app/theme.js.map +1 -0
- package/dist/expo/app/types.d.ts +87 -0
- package/dist/expo/app/types.js +2 -0
- package/dist/expo/app/types.js.map +1 -0
- package/dist/expo/app/useCloudReviewer.d.ts +75 -0
- package/dist/expo/app/useCloudReviewer.js +211 -0
- package/dist/expo/app/useCloudReviewer.js.map +1 -0
- package/dist/expo/app/useComments.d.ts +64 -0
- package/dist/expo/app/useComments.js +156 -0
- package/dist/expo/app/useComments.js.map +1 -0
- package/dist/expo/app/useUploads.d.ts +32 -0
- package/dist/expo/app/useUploads.js +106 -0
- package/dist/expo/app/useUploads.js.map +1 -0
- package/dist/expo/expoGoMetro.cjs +83 -0
- package/dist/expo/expoMetro.cjs +86 -0
- package/dist/expo/metro.cjs +304 -0
- package/dist/expo/metroBuild.d.ts +22 -0
- package/dist/expo/metroBuild.js +169 -0
- package/dist/expo/metroBuild.js.map +1 -0
- package/dist/expo/middleware.d.ts +11 -0
- package/dist/expo/middleware.js +26 -0
- package/dist/expo/middleware.js.map +1 -0
- package/dist/expo/mode.d.ts +20 -0
- package/dist/expo/mode.js +37 -0
- package/dist/expo/mode.js.map +1 -0
- package/dist/expo/publicConfig.d.ts +37 -0
- package/dist/expo/publicConfig.js +87 -0
- package/dist/expo/publicConfig.js.map +1 -0
- package/dist/expo/transform.d.ts +22 -0
- package/dist/expo/transform.js +38 -0
- package/dist/expo/transform.js.map +1 -0
- package/dist/expo/transformer.cjs +73 -0
- package/dist/index.d.ts +21 -0
- package/dist/index.js +17 -0
- package/dist/index.js.map +1 -0
- package/dist/integration/apiRoutes.d.ts +2 -0
- package/dist/integration/apiRoutes.js +3 -0
- package/dist/integration/apiRoutes.js.map +1 -0
- package/dist/integration/buildCredentials.d.ts +12 -0
- package/dist/integration/buildCredentials.js +97 -0
- package/dist/integration/buildCredentials.js.map +1 -0
- package/dist/integration/buildSession.d.ts +8 -0
- package/dist/integration/buildSession.js +96 -0
- package/dist/integration/buildSession.js.map +1 -0
- package/dist/integration/bundleCheck.d.ts +43 -0
- package/dist/integration/bundleCheck.js +111 -0
- package/dist/integration/bundleCheck.js.map +1 -0
- package/dist/integration/commentPull.d.ts +134 -0
- package/dist/integration/commentPull.js +260 -0
- package/dist/integration/commentPull.js.map +1 -0
- package/dist/integration/configuredApi.d.ts +7 -0
- package/dist/integration/configuredApi.js +24 -0
- package/dist/integration/configuredApi.js.map +1 -0
- package/dist/integration/devCloud.d.ts +27 -0
- package/dist/integration/devCloud.js +56 -0
- package/dist/integration/devCloud.js.map +1 -0
- package/dist/integration/devReviewLinks.d.ts +2 -0
- package/dist/integration/devReviewLinks.js +10 -0
- package/dist/integration/devReviewLinks.js.map +1 -0
- package/dist/integration/gitBranch.d.ts +19 -0
- package/dist/integration/gitBranch.js +56 -0
- package/dist/integration/gitBranch.js.map +1 -0
- package/dist/integration/importPlan.d.ts +19 -0
- package/dist/integration/importPlan.js +90 -0
- package/dist/integration/importPlan.js.map +1 -0
- package/dist/integration/index.d.ts +14 -0
- package/dist/integration/index.js +13 -0
- package/dist/integration/index.js.map +1 -0
- package/dist/integration/manifest.d.ts +120 -0
- package/dist/integration/manifest.js +147 -0
- package/dist/integration/manifest.js.map +1 -0
- package/dist/integration/manifestParts.d.ts +29 -0
- package/dist/integration/manifestParts.js +65 -0
- package/dist/integration/manifestParts.js.map +1 -0
- package/dist/integration/manifestSink.d.ts +75 -0
- package/dist/integration/manifestSink.js +157 -0
- package/dist/integration/manifestSink.js.map +1 -0
- package/dist/integration/manifestUpload.d.ts +64 -0
- package/dist/integration/manifestUpload.js +177 -0
- package/dist/integration/manifestUpload.js.map +1 -0
- package/dist/integration/middleware.d.ts +55 -0
- package/dist/integration/middleware.js +379 -0
- package/dist/integration/middleware.js.map +1 -0
- package/dist/integration/nextStyles.d.ts +4 -0
- package/dist/integration/nextStyles.js +121 -0
- package/dist/integration/nextStyles.js.map +1 -0
- package/dist/integration/requestGuards.d.ts +71 -0
- package/dist/integration/requestGuards.js +255 -0
- package/dist/integration/requestGuards.js.map +1 -0
- package/dist/integration/sharedBuild.d.ts +71 -0
- package/dist/integration/sharedBuild.js +105 -0
- package/dist/integration/sharedBuild.js.map +1 -0
- package/dist/integration/sharedInject.d.ts +88 -0
- package/dist/integration/sharedInject.js +164 -0
- package/dist/integration/sharedInject.js.map +1 -0
- package/dist/integration/sidecarProcess.d.ts +26 -0
- package/dist/integration/sidecarProcess.js +137 -0
- package/dist/integration/sidecarProcess.js.map +1 -0
- package/dist/integration/styleCollector.d.ts +49 -0
- package/dist/integration/styleCollector.js +220 -0
- package/dist/integration/styleCollector.js.map +1 -0
- package/dist/integration/transform.d.ts +24 -0
- package/dist/integration/transform.js +36 -0
- package/dist/integration/transform.js.map +1 -0
- package/dist/integration/tunnelClient.d.ts +44 -0
- package/dist/integration/tunnelClient.js +148 -0
- package/dist/integration/tunnelClient.js.map +1 -0
- package/dist/integration/tunnelProtocol.d.ts +152 -0
- package/dist/integration/tunnelProtocol.js +110 -0
- package/dist/integration/tunnelProtocol.js.map +1 -0
- package/dist/mcp/cli.d.ts +2 -0
- package/dist/mcp/cli.js +327 -0
- package/dist/mcp/cli.js.map +1 -0
- package/dist/mcp/cloudRefresh.d.ts +36 -0
- package/dist/mcp/cloudRefresh.js +52 -0
- package/dist/mcp/cloudRefresh.js.map +1 -0
- package/dist/mcp/context.d.ts +7 -0
- package/dist/mcp/context.js +18 -0
- package/dist/mcp/context.js.map +1 -0
- package/dist/mcp/files.d.ts +66 -0
- package/dist/mcp/files.js +157 -0
- package/dist/mcp/files.js.map +1 -0
- package/dist/mcp/search.d.ts +3 -0
- package/dist/mcp/search.js +9 -0
- package/dist/mcp/search.js.map +1 -0
- package/dist/mcp/server.d.ts +50 -0
- package/dist/mcp/server.js +555 -0
- package/dist/mcp/server.js.map +1 -0
- package/dist/overlay/anchors.d.ts +130 -0
- package/dist/overlay/anchors.js +365 -0
- package/dist/overlay/anchors.js.map +1 -0
- package/dist/overlay/api.d.ts +150 -0
- package/dist/overlay/api.js +259 -0
- package/dist/overlay/api.js.map +1 -0
- package/dist/overlay/attachments.d.ts +60 -0
- package/dist/overlay/attachments.js +163 -0
- package/dist/overlay/attachments.js.map +1 -0
- package/dist/overlay/browser.d.ts +1 -0
- package/dist/overlay/browser.js +203 -0
- package/dist/overlay/browser.js.map +1 -0
- package/dist/overlay/chip.d.ts +27 -0
- package/dist/overlay/chip.js +31 -0
- package/dist/overlay/chip.js.map +1 -0
- package/dist/overlay/compact.d.ts +11 -0
- package/dist/overlay/compact.js +21 -0
- package/dist/overlay/compact.js.map +1 -0
- package/dist/overlay/cssScope.d.ts +46 -0
- package/dist/overlay/cssScope.js +180 -0
- package/dist/overlay/cssScope.js.map +1 -0
- package/dist/overlay/cursor.d.ts +2 -0
- package/dist/overlay/cursor.js +68 -0
- package/dist/overlay/cursor.js.map +1 -0
- package/dist/overlay/devBrowser.d.ts +1 -0
- package/dist/overlay/devBrowser.js +18 -0
- package/dist/overlay/devBrowser.js.map +1 -0
- package/dist/overlay/devReview.d.ts +4 -0
- package/dist/overlay/devReview.js +18 -0
- package/dist/overlay/devReview.js.map +1 -0
- package/dist/overlay/directReviewer.d.ts +149 -0
- package/dist/overlay/directReviewer.js +448 -0
- package/dist/overlay/directReviewer.js.map +1 -0
- package/dist/overlay/elementDescription.d.ts +10 -0
- package/dist/overlay/elementDescription.js +251 -0
- package/dist/overlay/elementDescription.js.map +1 -0
- package/dist/overlay/icons.d.ts +8 -0
- package/dist/overlay/icons.js +36 -0
- package/dist/overlay/icons.js.map +1 -0
- package/dist/overlay/identity.d.ts +48 -0
- package/dist/overlay/identity.js +125 -0
- package/dist/overlay/identity.js.map +1 -0
- package/dist/overlay/localMachine.d.ts +23 -0
- package/dist/overlay/localMachine.js +40 -0
- package/dist/overlay/localMachine.js.map +1 -0
- package/dist/overlay/magicLink.d.ts +10 -0
- package/dist/overlay/magicLink.js +87 -0
- package/dist/overlay/magicLink.js.map +1 -0
- package/dist/overlay/modern-screenshot.js +1676 -0
- package/dist/overlay/movedAnchors.d.ts +30 -0
- package/dist/overlay/movedAnchors.js +128 -0
- package/dist/overlay/movedAnchors.js.map +1 -0
- package/dist/overlay/notificationGroups.d.ts +2 -0
- package/dist/overlay/notificationGroups.js +41 -0
- package/dist/overlay/notificationGroups.js.map +1 -0
- package/dist/overlay/permissions.d.ts +10 -0
- package/dist/overlay/permissions.js +9 -0
- package/dist/overlay/permissions.js.map +1 -0
- package/dist/overlay/pinGroups.d.ts +16 -0
- package/dist/overlay/pinGroups.js +17 -0
- package/dist/overlay/pinGroups.js.map +1 -0
- package/dist/overlay/presence.d.ts +50 -0
- package/dist/overlay/presence.js +258 -0
- package/dist/overlay/presence.js.map +1 -0
- package/dist/overlay/projectChannel.d.ts +11 -0
- package/dist/overlay/projectChannel.js +111 -0
- package/dist/overlay/projectChannel.js.map +1 -0
- package/dist/overlay/recorder.d.ts +56 -0
- package/dist/overlay/recorder.js +130 -0
- package/dist/overlay/recorder.js.map +1 -0
- package/dist/overlay/reviewMode.d.ts +21 -0
- package/dist/overlay/reviewMode.js +59 -0
- package/dist/overlay/reviewMode.js.map +1 -0
- package/dist/overlay/reviewerAuth.d.ts +131 -0
- package/dist/overlay/reviewerAuth.js +279 -0
- package/dist/overlay/reviewerAuth.js.map +1 -0
- package/dist/overlay/route.d.ts +18 -0
- package/dist/overlay/route.js +56 -0
- package/dist/overlay/route.js.map +1 -0
- package/dist/overlay/rrweb-record.js +63 -0
- package/dist/overlay/runtime.d.ts +1 -0
- package/dist/overlay/runtime.js +4857 -0
- package/dist/overlay/runtime.js.map +1 -0
- package/dist/overlay/session.d.ts +32 -0
- package/dist/overlay/session.js +76 -0
- package/dist/overlay/session.js.map +1 -0
- package/dist/overlay/sharedMode.d.ts +38 -0
- package/dist/overlay/sharedMode.js +37 -0
- package/dist/overlay/sharedMode.js.map +1 -0
- package/dist/overlay/sheet.d.ts +73 -0
- package/dist/overlay/sheet.js +278 -0
- package/dist/overlay/sheet.js.map +1 -0
- package/dist/overlay/snapshot.d.ts +26 -0
- package/dist/overlay/snapshot.js +185 -0
- package/dist/overlay/snapshot.js.map +1 -0
- package/dist/overlay/state.d.ts +63 -0
- package/dist/overlay/state.js +241 -0
- package/dist/overlay/state.js.map +1 -0
- package/dist/overlay/steps.d.ts +22 -0
- package/dist/overlay/steps.js +34 -0
- package/dist/overlay/steps.js.map +1 -0
- package/dist/overlay/styles.d.ts +7 -0
- package/dist/overlay/styles.js +1449 -0
- package/dist/overlay/styles.js.map +1 -0
- package/dist/overlay/trace.d.ts +19 -0
- package/dist/overlay/trace.js +29 -0
- package/dist/overlay/trace.js.map +1 -0
- package/dist/overlay/upload.d.ts +35 -0
- package/dist/overlay/upload.js +99 -0
- package/dist/overlay/upload.js.map +1 -0
- package/dist/plugin/astro.d.ts +31 -0
- package/dist/plugin/astro.js +22 -0
- package/dist/plugin/astro.js.map +1 -0
- package/dist/plugin/eleventy.d.ts +44 -0
- package/dist/plugin/eleventy.js +186 -0
- package/dist/plugin/eleventy.js.map +1 -0
- package/dist/plugin/next-loader.cjs +11 -0
- package/dist/plugin/next.d.ts +29 -0
- package/dist/plugin/next.js +176 -0
- package/dist/plugin/next.js.map +1 -0
- package/dist/plugin/nextOverlay.d.ts +2 -0
- package/dist/plugin/nextOverlay.js +22 -0
- package/dist/plugin/nextOverlay.js.map +1 -0
- package/dist/plugin/nextTransform.d.ts +19 -0
- package/dist/plugin/nextTransform.js +29 -0
- package/dist/plugin/nextTransform.js.map +1 -0
- package/dist/plugin/rsbuild.d.ts +25 -0
- package/dist/plugin/rsbuild.js +56 -0
- package/dist/plugin/rsbuild.js.map +1 -0
- package/dist/plugin/vite.d.ts +39 -0
- package/dist/plugin/vite.js +582 -0
- package/dist/plugin/vite.js.map +1 -0
- package/dist/plugin/webpack.d.ts +69 -0
- package/dist/plugin/webpack.js +192 -0
- package/dist/plugin/webpack.js.map +1 -0
- package/dist/remote/account.d.ts +41 -0
- package/dist/remote/account.js +177 -0
- package/dist/remote/account.js.map +1 -0
- package/dist/remote/base64url.d.ts +14 -0
- package/dist/remote/base64url.js +71 -0
- package/dist/remote/base64url.js.map +1 -0
- package/dist/remote/branchLabel.d.ts +12 -0
- package/dist/remote/branchLabel.js +20 -0
- package/dist/remote/branchLabel.js.map +1 -0
- package/dist/remote/client.d.ts +340 -0
- package/dist/remote/client.js +424 -0
- package/dist/remote/client.js.map +1 -0
- package/dist/remote/cloudApi.d.ts +72 -0
- package/dist/remote/cloudApi.js +72 -0
- package/dist/remote/cloudApi.js.map +1 -0
- package/dist/remote/codec.d.ts +54 -0
- package/dist/remote/codec.js +62 -0
- package/dist/remote/codec.js.map +1 -0
- package/dist/remote/config.d.ts +30 -0
- package/dist/remote/config.js +112 -0
- package/dist/remote/config.js.map +1 -0
- package/dist/remote/content-schema.d.ts +428 -0
- package/dist/remote/content-schema.js +209 -0
- package/dist/remote/content-schema.js.map +1 -0
- package/dist/remote/content.d.ts +44 -0
- package/dist/remote/content.js +75 -0
- package/dist/remote/content.js.map +1 -0
- package/dist/remote/envelope.d.ts +76 -0
- package/dist/remote/envelope.js +109 -0
- package/dist/remote/envelope.js.map +1 -0
- package/dist/remote/errors.d.ts +55 -0
- package/dist/remote/errors.js +63 -0
- package/dist/remote/errors.js.map +1 -0
- package/dist/remote/ids.d.ts +8 -0
- package/dist/remote/ids.js +25 -0
- package/dist/remote/ids.js.map +1 -0
- package/dist/remote/index.d.ts +7 -0
- package/dist/remote/index.js +8 -0
- package/dist/remote/index.js.map +1 -0
- package/dist/remote/keys.d.ts +62 -0
- package/dist/remote/keys.js +162 -0
- package/dist/remote/keys.js.map +1 -0
- package/dist/remote/localAnchors.d.ts +4 -0
- package/dist/remote/localAnchors.js +23 -0
- package/dist/remote/localAnchors.js.map +1 -0
- package/dist/remote/mapping.d.ts +11 -0
- package/dist/remote/mapping.js +22 -0
- package/dist/remote/mapping.js.map +1 -0
- package/dist/remote/presence.d.ts +63 -0
- package/dist/remote/presence.js +143 -0
- package/dist/remote/presence.js.map +1 -0
- package/dist/remote/realtime.d.ts +142 -0
- package/dist/remote/realtime.js +326 -0
- package/dist/remote/realtime.js.map +1 -0
- package/dist/remote/store.d.ts +183 -0
- package/dist/remote/store.js +907 -0
- package/dist/remote/store.js.map +1 -0
- package/dist/remote/sync.d.ts +113 -0
- package/dist/remote/sync.js +370 -0
- package/dist/remote/sync.js.map +1 -0
- package/dist/remote/types.d.ts +99 -0
- package/dist/remote/types.js +6 -0
- package/dist/remote/types.js.map +1 -0
- package/dist/setup/agents.d.ts +23 -0
- package/dist/setup/agents.js +80 -0
- package/dist/setup/agents.js.map +1 -0
- package/dist/setup/configure.d.ts +27 -0
- package/dist/setup/configure.js +201 -0
- package/dist/setup/configure.js.map +1 -0
- package/dist/setup/connect.d.ts +60 -0
- package/dist/setup/connect.js +244 -0
- package/dist/setup/connect.js.map +1 -0
- package/dist/setup/detect.d.ts +67 -0
- package/dist/setup/detect.js +168 -0
- package/dist/setup/detect.js.map +1 -0
- package/dist/setup/frameworks.d.ts +41 -0
- package/dist/setup/frameworks.js +81 -0
- package/dist/setup/frameworks.js.map +1 -0
- package/dist/sidecar/cli.d.ts +1 -0
- package/dist/sidecar/cli.js +70 -0
- package/dist/sidecar/cli.js.map +1 -0
- package/dist/sidecar/cloudSync.d.ts +33 -0
- package/dist/sidecar/cloudSync.js +139 -0
- package/dist/sidecar/cloudSync.js.map +1 -0
- package/dist/sidecar/commentFiles.d.ts +59 -0
- package/dist/sidecar/commentFiles.js +217 -0
- package/dist/sidecar/commentFiles.js.map +1 -0
- package/dist/sidecar/cssAttribution.d.ts +26 -0
- package/dist/sidecar/cssAttribution.js +114 -0
- package/dist/sidecar/cssAttribution.js.map +1 -0
- package/dist/sidecar/exportTasks.d.ts +38 -0
- package/dist/sidecar/exportTasks.js +249 -0
- package/dist/sidecar/exportTasks.js.map +1 -0
- package/dist/sidecar/http.d.ts +20 -0
- package/dist/sidecar/http.js +904 -0
- package/dist/sidecar/http.js.map +1 -0
- package/dist/sidecar/inviteTarget.d.ts +4 -0
- package/dist/sidecar/inviteTarget.js +32 -0
- package/dist/sidecar/inviteTarget.js.map +1 -0
- package/dist/sidecar/presence.d.ts +4 -0
- package/dist/sidecar/presence.js +92 -0
- package/dist/sidecar/presence.js.map +1 -0
- package/dist/storage/cliSession.d.ts +8 -0
- package/dist/storage/cliSession.js +41 -0
- package/dist/storage/cliSession.js.map +1 -0
- package/dist/storage/devStyleMap.d.ts +12 -0
- package/dist/storage/devStyleMap.js +31 -0
- package/dist/storage/devStyleMap.js.map +1 -0
- package/dist/storage/fileCache.d.ts +34 -0
- package/dist/storage/fileCache.js +122 -0
- package/dist/storage/fileCache.js.map +1 -0
- package/dist/storage/localAttachments.d.ts +82 -0
- package/dist/storage/localAttachments.js +276 -0
- package/dist/storage/localAttachments.js.map +1 -0
- package/dist/storage/localComments.d.ts +31 -0
- package/dist/storage/localComments.js +159 -0
- package/dist/storage/localComments.js.map +1 -0
- package/dist/storage/localCredentials.d.ts +74 -0
- package/dist/storage/localCredentials.js +210 -0
- package/dist/storage/localCredentials.js.map +1 -0
- package/dist/storage/localParticipants.d.ts +33 -0
- package/dist/storage/localParticipants.js +110 -0
- package/dist/storage/localParticipants.js.map +1 -0
- package/dist/storage/localRecipe.d.ts +22 -0
- package/dist/storage/localRecipe.js +46 -0
- package/dist/storage/localRecipe.js.map +1 -0
- package/dist/storage/localScreenshots.d.ts +23 -0
- package/dist/storage/localScreenshots.js +55 -0
- package/dist/storage/localScreenshots.js.map +1 -0
- package/dist/storage/localSource.d.ts +31 -0
- package/dist/storage/localSource.js +175 -0
- package/dist/storage/localSource.js.map +1 -0
- package/dist/storage/pulledComments.d.ts +81 -0
- package/dist/storage/pulledComments.js +107 -0
- package/dist/storage/pulledComments.js.map +1 -0
- package/dist/storage/remoteRecipe.d.ts +7 -0
- package/dist/storage/remoteRecipe.js +85 -0
- package/dist/storage/remoteRecipe.js.map +1 -0
- package/dist/storage/savedRemote.d.ts +2 -0
- package/dist/storage/savedRemote.js +22 -0
- package/dist/storage/savedRemote.js.map +1 -0
- package/dist/storage/sidecarAccess.d.ts +7 -0
- package/dist/storage/sidecarAccess.js +68 -0
- package/dist/storage/sidecarAccess.js.map +1 -0
- package/package.json +308 -4
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
export const defaultApiBase = 'https://api.ontrackd.com';
|
|
2
|
+
/** Build/session metadata was obtained from the API; it lets browsers avoid a legacy CORS preflight. */
|
|
3
|
+
function selectedKind(target, fetchImpl) {
|
|
4
|
+
if (typeof target !== 'string') {
|
|
5
|
+
if (target.apiKind)
|
|
6
|
+
return target.apiKind;
|
|
7
|
+
if (target.sessionId || target.plan === 'cloud')
|
|
8
|
+
return 'v0';
|
|
9
|
+
}
|
|
10
|
+
return knownKind(typeof target === 'string' ? target : target.apiBase, fetchImpl);
|
|
11
|
+
}
|
|
12
|
+
export function apiKindFor(target, fetchImpl = fetch) {
|
|
13
|
+
return selectedKind(target, fetchImpl) ?? 'legacy';
|
|
14
|
+
}
|
|
15
|
+
export function hasContractSession(target) {
|
|
16
|
+
return Boolean(target && apiKindFor(target) === 'v0' && target.sessionId);
|
|
17
|
+
}
|
|
18
|
+
const remembered = new WeakMap();
|
|
19
|
+
const normalize = (apiBase) => apiBase.replace(/\/$/, '');
|
|
20
|
+
/** What is known of this API so far; the default service is the contract v0 Worker. */
|
|
21
|
+
export function knownKind(apiBase, fetchImpl = fetch) {
|
|
22
|
+
const base = normalize(apiBase);
|
|
23
|
+
return base === defaultApiBase ? 'v0' : remembered.get(fetchImpl)?.get(base);
|
|
24
|
+
}
|
|
25
|
+
/** Records what an answer showed (for callers that cannot use `routedFetch`). */
|
|
26
|
+
export function rememberKind(apiBase, fetchImpl, kind) {
|
|
27
|
+
let known = remembered.get(fetchImpl);
|
|
28
|
+
if (!known) {
|
|
29
|
+
known = new Map();
|
|
30
|
+
remembered.set(fetchImpl, known);
|
|
31
|
+
}
|
|
32
|
+
known.set(normalize(apiBase), kind);
|
|
33
|
+
}
|
|
34
|
+
/** A contract v0 refusal of a route it does not have: 404 with the v0 error envelope. */
|
|
35
|
+
export async function isV0NotFound(response) {
|
|
36
|
+
if (response.status !== 404)
|
|
37
|
+
return false;
|
|
38
|
+
const body = (await response
|
|
39
|
+
.clone()
|
|
40
|
+
.json()
|
|
41
|
+
.catch(() => null));
|
|
42
|
+
const error = body?.error;
|
|
43
|
+
return typeof error === 'object' && error !== null && typeof error.code === 'string';
|
|
44
|
+
}
|
|
45
|
+
/** Response-based discovery for routes which have no equivalent on the other API. */
|
|
46
|
+
export async function observeApiKind(apiBase, fetchImpl, response) {
|
|
47
|
+
if (knownKind(apiBase, fetchImpl) === 'legacy')
|
|
48
|
+
return 'legacy';
|
|
49
|
+
if (await isV0NotFound(response)) {
|
|
50
|
+
rememberKind(apiBase, fetchImpl, 'v0');
|
|
51
|
+
return 'v0';
|
|
52
|
+
}
|
|
53
|
+
return knownKind(apiBase, fetchImpl) ?? 'legacy';
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Sends a request on the route set the API speaks: `route(true)` is the legacy request, `route(false)`
|
|
57
|
+
* the v0 one (paths, and bodies where they differ). The answer says which was used.
|
|
58
|
+
*/
|
|
59
|
+
export async function routedFetch(target, fetchImpl, route) {
|
|
60
|
+
const apiBase = typeof target === 'string' ? target : target.apiBase;
|
|
61
|
+
const known = selectedKind(target, fetchImpl);
|
|
62
|
+
if (known) {
|
|
63
|
+
const { url, init } = route(known === 'legacy');
|
|
64
|
+
return { response: await fetchImpl(url, init), kind: known };
|
|
65
|
+
}
|
|
66
|
+
const legacy = route(true);
|
|
67
|
+
const response = await fetchImpl(legacy.url, legacy.init);
|
|
68
|
+
if ((await observeApiKind(apiBase, fetchImpl, response)) === 'v0') {
|
|
69
|
+
// Discovery read a clone, so this is one branch of a tee. Cancellation can wait for
|
|
70
|
+
// the other branch's cleanup indefinitely; it must not hold up the v0 request.
|
|
71
|
+
void response.body?.cancel().catch(() => { });
|
|
72
|
+
const v0 = route(false);
|
|
73
|
+
return { response: await fetchImpl(v0.url, v0.init), kind: 'v0' };
|
|
74
|
+
}
|
|
75
|
+
// An inconclusive response (including an HTTP outage) leaves discovery open for the next call.
|
|
76
|
+
return { response, kind: 'legacy' };
|
|
77
|
+
}
|
|
78
|
+
export function pluginPath(legacy, route, commentId = '') {
|
|
79
|
+
if (route === 'comment')
|
|
80
|
+
return `${legacy ? '/v1/comments/' : '/v0/plugin/comments/'}${encodeURIComponent(commentId)}`;
|
|
81
|
+
return `${legacy ? '/v1/' : '/v0/plugin/'}${route}`;
|
|
82
|
+
}
|
|
83
|
+
//# sourceMappingURL=apiKind.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"apiKind.js","sourceRoot":"","sources":["../../src/core/apiKind.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,cAAc,GAAG,0BAA0B,CAAC;AAmBzD,wGAAwG;AACxG,SAAS,YAAY,CAAC,MAA0B,EAAE,SAAuB;IACvE,IAAI,OAAO,MAAM,KAAK,QAAQ,EAAE,CAAC;QAC/B,IAAI,MAAM,CAAC,OAAO;YAAE,OAAO,MAAM,CAAC,OAAO,CAAC;QAC1C,IAAI,MAAM,CAAC,SAAS,I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AC"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { type AnchorResult, type SourceAnchorOptions } from './sourceAnchors.js';
|
|
2
|
+
/**
|
|
3
|
+
* Anchors for `.astro` templates.
|
|
4
|
+
*
|
|
5
|
+
* A second parser, not a second design. `.astro` is its own syntax - a frontmatter fence and
|
|
6
|
+
* then an HTML-ish template - which oxc cannot read, so the parse comes from Astro's own
|
|
7
|
+
* compiler. Everything after the parse is the JSX path: splice an attribute in after the tag
|
|
8
|
+
* name, leave every other character alone, and hand back the same `AnchorResult`.
|
|
9
|
+
*
|
|
10
|
+
* ## Two compilers, because Astro has two
|
|
11
|
+
*
|
|
12
|
+
* Astro 5 and earlier parse with `@astrojs/compiler` (Go, via wasm) and produce nodes typed
|
|
13
|
+
* `element` / `component` / `fragment`. Astro 7 replaced it with `@astrojs/compiler-rs` (Rust),
|
|
14
|
+
* whose AST is JSX-shaped: `JSXElement` with an `openingElement`.
|
|
15
|
+
*
|
|
16
|
+
* This was found the hard way. The first version resolved only `@astrojs/compiler` on the
|
|
17
|
+
* reasoning that "astro depends on it, so it resolves wherever Astro is" - true when it was
|
|
18
|
+
* written, and false on the version a real project was using. Both are supported, and the
|
|
19
|
+
* difference is absorbed into `collect`, so there is one stamping rule rather than two.
|
|
20
|
+
*/
|
|
21
|
+
export declare const astroFilePattern: RegExp;
|
|
22
|
+
/** One element worth stamping, normalised away from whichever compiler produced it. */
|
|
23
|
+
type Element = {
|
|
24
|
+
name: string;
|
|
25
|
+
/** Offset of the `<`. */
|
|
26
|
+
start: number;
|
|
27
|
+
/** Offset immediately after the tag name, where an attribute is always valid. */
|
|
28
|
+
insertAt: number;
|
|
29
|
+
attributes: string[];
|
|
30
|
+
};
|
|
31
|
+
type AnyNode = Record<string, any>;
|
|
32
|
+
/** Astro 5 and earlier: `element` / `custom-element` / `component` / `fragment`. */
|
|
33
|
+
export declare function collectLegacy(root: AnyNode): Element[];
|
|
34
|
+
/** Astro 7 and later: a JSX-shaped tree from `@astrojs/compiler-rs`. */
|
|
35
|
+
export declare function collectRust(root: AnyNode): Element[];
|
|
36
|
+
/** `src/components/Card.astro` -> `Card`. In `.astro` the file is the component. */
|
|
37
|
+
export declare function componentNameFor(sourceId: string): string | null;
|
|
38
|
+
export declare function injectAstroAnchors(code: string, filename: string, { sourceId, attributeName, componentAttributeName, secret, }: SourceAnchorOptions): Promise<AnchorResult | null>;
|
|
39
|
+
export {};
|
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
import MagicString from 'magic-string';
|
|
2
|
+
import { anchorId } from './anchorId.js';
|
|
3
|
+
import { lineStarts, positionAt } from './oxcAst.js';
|
|
4
|
+
import { escapeAttribute, idAttributeName, rawMap, } from './sourceAnchors.js';
|
|
5
|
+
/**
|
|
6
|
+
* Anchors for `.astro` templates.
|
|
7
|
+
*
|
|
8
|
+
* A second parser, not a second design. `.astro` is its own syntax - a frontmatter fence and
|
|
9
|
+
* then an HTML-ish template - which oxc cannot read, so the parse comes from Astro's own
|
|
10
|
+
* compiler. Everything after the parse is the JSX path: splice an attribute in after the tag
|
|
11
|
+
* name, leave every other character alone, and hand back the same `AnchorResult`.
|
|
12
|
+
*
|
|
13
|
+
* ## Two compilers, because Astro has two
|
|
14
|
+
*
|
|
15
|
+
* Astro 5 and earlier parse with `@astrojs/compiler` (Go, via wasm) and produce nodes typed
|
|
16
|
+
* `element` / `component` / `fragment`. Astro 7 replaced it with `@astrojs/compiler-rs` (Rust),
|
|
17
|
+
* whose AST is JSX-shaped: `JSXElement` with an `openingElement`.
|
|
18
|
+
*
|
|
19
|
+
* This was found the hard way. The first version resolved only `@astrojs/compiler` on the
|
|
20
|
+
* reasoning that "astro depends on it, so it resolves wherever Astro is" - true when it was
|
|
21
|
+
* written, and false on the version a real project was using. Both are supported, and the
|
|
22
|
+
* difference is absorbed into `collect`, so there is one stamping rule rather than two.
|
|
23
|
+
*/
|
|
24
|
+
export const astroFilePattern = /\.astro$/;
|
|
25
|
+
/**
|
|
26
|
+
* Elements that render nothing, and must not be stamped.
|
|
27
|
+
*
|
|
28
|
+
* Two reasons, and either alone would be enough. They are not clickable, so an anchor on one
|
|
29
|
+
* can never be the target of a comment - it is manifest weight for an element no reviewer can
|
|
30
|
+
* reach. And on `<script>` the attribute changes meaning: Astro treats a script carrying an
|
|
31
|
+
* unrecognised attribute as `is:inline`, which stops it processing the `import` inside, and the
|
|
32
|
+
* build fails with `Cannot assign to this expression` pointing at the first line of the script.
|
|
33
|
+
*
|
|
34
|
+
* That was reported from a real project with five such components, and it is the shape worth
|
|
35
|
+
* remembering: an attribute that is inert on every element we had tested, and load-bearing on
|
|
36
|
+
* one we had not.
|
|
37
|
+
*/
|
|
38
|
+
const neverStamped = new Set([
|
|
39
|
+
'script', 'style', 'meta', 'link', 'title', 'base', 'head', 'noscript', 'template',
|
|
40
|
+
]);
|
|
41
|
+
/**
|
|
42
|
+
* A component invocation, not an element.
|
|
43
|
+
*
|
|
44
|
+
* Stamping `<Card data-fb-src="...">` passes an unknown prop to a component that has no reason
|
|
45
|
+
* to spread it onto anything, so the attribute reaches no element and the anchor points at a
|
|
46
|
+
* location nothing in the page carries. Invisible from both ends: the build reports an anchor,
|
|
47
|
+
* the manifest records it, and no click ever resolves to it.
|
|
48
|
+
*
|
|
49
|
+
* The Go compiler says so in the node type. The Rust one does not, so the JSX convention
|
|
50
|
+
* decides it - which is the same rule Astro itself applies.
|
|
51
|
+
*/
|
|
52
|
+
const isComponentName = (name) => /^[A-Z]/.test(name) || name === 'Fragment';
|
|
53
|
+
/** Astro 5 and earlier: `element` / `custom-element` / `component` / `fragment`. */
|
|
54
|
+
export function collectLegacy(root) {
|
|
55
|
+
const found = [];
|
|
56
|
+
const visit = (node) => {
|
|
57
|
+
const name = node?.name;
|
|
58
|
+
const start = node?.position?.start?.offset;
|
|
59
|
+
if ((node?.type === 'element' || node?.type === 'custom-element') && name && typeof start === 'number') {
|
|
60
|
+
found.push({
|
|
61
|
+
name,
|
|
62
|
+
start,
|
|
63
|
+
insertAt: start + 1 + name.length,
|
|
64
|
+
attributes: (node.attributes ?? []).map((a) => String(a?.name ?? '')),
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
// Walked for every node type, not just stamped ones: elements written inside an expression
|
|
68
|
+
// (`{items.map((i) => <li>…</li>)}`) are children of that expression, and skipping
|
|
69
|
+
// non-stampable nodes would drop every one of them.
|
|
70
|
+
for (const child of node?.children ?? [])
|
|
71
|
+
visit(child);
|
|
72
|
+
};
|
|
73
|
+
visit(root);
|
|
74
|
+
return found;
|
|
75
|
+
}
|
|
76
|
+
/** Astro 7 and later: a JSX-shaped tree from `@astrojs/compiler-rs`. */
|
|
77
|
+
export function collectRust(root) {
|
|
78
|
+
const found = [];
|
|
79
|
+
const visit = (node) => {
|
|
80
|
+
if (!node || typeof node !== 'object')
|
|
81
|
+
return;
|
|
82
|
+
if (node.type === 'JSXElement' && node.openingElement) {
|
|
83
|
+
const nameNode = node.openingElement.name;
|
|
84
|
+
const name = nameNode?.name;
|
|
85
|
+
// `name.end` is the offset immediately after the tag name - the same insertion point the
|
|
86
|
+
// oxc path computes, handed over rather than recomputed.
|
|
87
|
+
if (name && typeof nameNode?.end === 'number' && !isComponentName(name)) {
|
|
88
|
+
found.push({
|
|
89
|
+
name,
|
|
90
|
+
start: typeof node.start === 'number' ? node.start : nameNode.end - name.length - 1,
|
|
91
|
+
insertAt: nameNode.end,
|
|
92
|
+
attributes: (node.openingElement.attributes ?? [])
|
|
93
|
+
.map((a) => String(a?.name?.name ?? a?.name ?? '')),
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
// Walked generically rather than through named keys. The Rust AST is a JavaScript AST, so
|
|
98
|
+
// an element inside `{items.map((i) => <li/>)}` hangs off an expression container, a call
|
|
99
|
+
// expression and an arrow body - none of them called `children`. Following only the obvious
|
|
100
|
+
// keys found the list and none of its items, which is most of a real page.
|
|
101
|
+
for (const value of Object.values(node)) {
|
|
102
|
+
if (Array.isArray(value)) {
|
|
103
|
+
for (const child of value)
|
|
104
|
+
visit(child);
|
|
105
|
+
}
|
|
106
|
+
else if (value && typeof value === 'object') {
|
|
107
|
+
visit(value);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
};
|
|
111
|
+
visit(root);
|
|
112
|
+
return found;
|
|
113
|
+
}
|
|
114
|
+
let parseAndCollect = null;
|
|
115
|
+
/**
|
|
116
|
+
* Astro's parser, loaded once, whichever one this project has.
|
|
117
|
+
*
|
|
118
|
+
* Failure is thrown rather than swallowed into "no anchors". A `.astro` file that silently
|
|
119
|
+
* produces nothing is the exact shape this project keeps rediscovering: a build that succeeds,
|
|
120
|
+
* reports itself fine, and stamps nothing.
|
|
121
|
+
*/
|
|
122
|
+
async function loadParser() {
|
|
123
|
+
if (parseAndCollect)
|
|
124
|
+
return parseAndCollect;
|
|
125
|
+
const attempts = [];
|
|
126
|
+
// Newest first: a project on Astro 7 may still have the old compiler somewhere in its tree,
|
|
127
|
+
// and parsing with the one that does not match its Astro is how positions drift.
|
|
128
|
+
try {
|
|
129
|
+
const rs = (await import('@astrojs/compiler-rs'));
|
|
130
|
+
parseAndCollect = async (code) => {
|
|
131
|
+
const out = await rs.parse(code, { position: true });
|
|
132
|
+
const root = out?.ast ?? out;
|
|
133
|
+
return root ? { elements: collectRust(root) } : null;
|
|
134
|
+
};
|
|
135
|
+
return parseAndCollect;
|
|
136
|
+
}
|
|
137
|
+
catch (error) {
|
|
138
|
+
attempts.push(`@astrojs/compiler-rs: ${error instanceof Error ? error.message : String(error)}`);
|
|
139
|
+
}
|
|
140
|
+
try {
|
|
141
|
+
const go = (await import('@astrojs/compiler'));
|
|
142
|
+
parseAndCollect = async (code) => {
|
|
143
|
+
const out = await go.parse(code, { position: true });
|
|
144
|
+
const root = out?.ast ?? out;
|
|
145
|
+
return root ? { elements: collectLegacy(root) } : null;
|
|
146
|
+
};
|
|
147
|
+
return parseAndCollect;
|
|
148
|
+
}
|
|
149
|
+
catch (error) {
|
|
150
|
+
attempts.push(`@astrojs/compiler: ${error instanceof Error ? error.message : String(error)}`);
|
|
151
|
+
}
|
|
152
|
+
throw new Error('feedback: cannot read .astro files - no Astro compiler could be loaded.\n' +
|
|
153
|
+
' Astro 7 and later ship @astrojs/compiler-rs; Astro 5 and earlier ship @astrojs/compiler.\n' +
|
|
154
|
+
' Neither resolved from here, which usually means .astro files are being built outside an ' +
|
|
155
|
+
'Astro project, or by a package manager that hides transitive dependencies.\n' +
|
|
156
|
+
' Installing either one directly is a valid fix.\n' +
|
|
157
|
+
attempts.map((line) => ` (${line})`).join('\n'));
|
|
158
|
+
}
|
|
159
|
+
/** `src/components/Card.astro` -> `Card`. In `.astro` the file is the component. */
|
|
160
|
+
export function componentNameFor(sourceId) {
|
|
161
|
+
const base = sourceId.split('/').pop() ?? '';
|
|
162
|
+
const name = base.replace(/\.astro$/, '');
|
|
163
|
+
return name.length > 0 ? name : null;
|
|
164
|
+
}
|
|
165
|
+
export async function injectAstroAnchors(code, filename, { sourceId, attributeName = 'data-fb-src', componentAttributeName = 'data-fb-component', secret, }) {
|
|
166
|
+
const parse = await loadParser();
|
|
167
|
+
let collected;
|
|
168
|
+
try {
|
|
169
|
+
collected = await parse(code);
|
|
170
|
+
}
|
|
171
|
+
catch {
|
|
172
|
+
// A file the compiler cannot parse is one Astro itself will refuse a moment later, with a
|
|
173
|
+
// better message than anything written here. Declining leaves that error intact.
|
|
174
|
+
return null;
|
|
175
|
+
}
|
|
176
|
+
if (!collected)
|
|
177
|
+
return null;
|
|
178
|
+
// Line and column are derived from the offset with the same helpers the JSX path uses,
|
|
179
|
+
// rather than read from what a compiler reports. An anchor whose line is off by one resolves
|
|
180
|
+
// to the wrong element and reads downstream as stale code, so agreement between the two
|
|
181
|
+
// parsers is built in rather than depended on.
|
|
182
|
+
const starts = lineStarts(code);
|
|
183
|
+
const magic = new MagicString(code);
|
|
184
|
+
const anchors = [];
|
|
185
|
+
const componentName = componentNameFor(sourceId);
|
|
186
|
+
const stamped = secret === undefined ? attributeName : idAttributeName;
|
|
187
|
+
let injected = 0;
|
|
188
|
+
for (const element of collected.elements) {
|
|
189
|
+
if (neverStamped.has(element.name.toLowerCase()))
|
|
190
|
+
continue;
|
|
191
|
+
if (isComponentName(element.name))
|
|
192
|
+
continue;
|
|
193
|
+
if (element.attributes.includes(stamped))
|
|
194
|
+
continue;
|
|
195
|
+
const at = positionAt(starts, element.start);
|
|
196
|
+
if (secret === undefined) {
|
|
197
|
+
const attributes = (componentName && !element.attributes.includes(componentAttributeName)
|
|
198
|
+
? ` ${componentAttributeName}="${escapeAttribute(componentName)}"`
|
|
199
|
+
: '') + ` ${attributeName}="${escapeAttribute(`${sourceId}:${at.line}:${at.column}`)}"`;
|
|
200
|
+
magic.appendLeft(element.insertAt, attributes);
|
|
201
|
+
}
|
|
202
|
+
else {
|
|
203
|
+
// Shared mode: the id alone, so the bundle cannot be read backwards into a file tree.
|
|
204
|
+
const id = anchorId(secret, sourceId, at.line, at.column);
|
|
205
|
+
magic.appendLeft(element.insertAt, ` ${idAttributeName}="${id}"`);
|
|
206
|
+
anchors.push({ id, file: sourceId, line: at.line, column: at.column, component: componentName });
|
|
207
|
+
}
|
|
208
|
+
injected += 1;
|
|
209
|
+
}
|
|
210
|
+
return {
|
|
211
|
+
code: injected === 0 ? code : magic.toString(),
|
|
212
|
+
map: rawMap(magic, filename),
|
|
213
|
+
injected,
|
|
214
|
+
anchors,
|
|
215
|
+
};
|
|
216
|
+
}
|
|
217
|
+
//# sourceMappingURL=astroAnchors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"astroAnchors.js","sourceRoot":"","sources":["../../src/core/astroAnchors.ts"],"names":[],"mappings":"AAAA,OAAO,WAAW,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACrD,OAAO,EACL,eAAe,EACf,eAAe,EACf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Q;QACR,OAAO;KACR,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What a comment or reply may carry as a file (docs/superpowers/specs/2026-10-30-attachments-design.md).
|
|
3
|
+
*
|
|
4
|
+
* The list is contract/v0/attachments.json. It is repeated here because the published package
|
|
5
|
+
* cannot read the contract; test/attachment-types-check.mjs and worker/test/attachments.test.ts
|
|
6
|
+
* compare the two. This is also the one type check: the Worker (worker/src/attachments.ts), the
|
|
7
|
+
* sidecar (storage/localAttachments.ts) and the overlay's pre-check all call it.
|
|
8
|
+
*
|
|
9
|
+
* The bytes decide. Images and PDF say what they are in their first bytes; a name claiming
|
|
10
|
+
* something else does not change that. ZIP-based and text documents cannot be told apart by bytes,
|
|
11
|
+
* so for those the extension must name an allowed type and the bytes must fit it.
|
|
12
|
+
*
|
|
13
|
+
* Pure: no Node or DOM APIs, no imports. The Worker typechecks it with noUncheckedIndexedAccess.
|
|
14
|
+
*/
|
|
15
|
+
export type AttachmentKind = 'image' | 'document' | 'recording';
|
|
16
|
+
export type AttachmentType = {
|
|
17
|
+
type: string;
|
|
18
|
+
kind: AttachmentKind;
|
|
19
|
+
mime: string;
|
|
20
|
+
extensions: string[];
|
|
21
|
+
maxBytes: number;
|
|
22
|
+
};
|
|
23
|
+
export declare const ATTACHMENTS: {
|
|
24
|
+
maxFilesPerMessage: number;
|
|
25
|
+
types: AttachmentType[];
|
|
26
|
+
};
|
|
27
|
+
export declare const MAX_ATTACHMENT_BYTES: number;
|
|
28
|
+
export type AttachmentCheck = {
|
|
29
|
+
ok: true;
|
|
30
|
+
type: AttachmentType;
|
|
31
|
+
name: string;
|
|
32
|
+
width: number | null;
|
|
33
|
+
height: number | null;
|
|
34
|
+
} | {
|
|
35
|
+
ok: false;
|
|
36
|
+
reason: 'type' | 'size' | 'empty';
|
|
37
|
+
limit?: number;
|
|
38
|
+
};
|
|
39
|
+
/** An image's pixel size from its header, or null when the header does not say. */
|
|
40
|
+
export declare function imageSize(type: string, bytes: Uint8Array): {
|
|
41
|
+
width: number;
|
|
42
|
+
height: number;
|
|
43
|
+
} | null;
|
|
44
|
+
/** The name a file is stored and downloaded under: clean, at most 120 characters, ending in an extension of its type. */
|
|
45
|
+
export declare function storedName(name: string, type: AttachmentType): string;
|
|
46
|
+
/**
|
|
47
|
+
* `recordings`: the caller can also vouch for an rrweb recording (the Worker, which then decompresses and
|
|
48
|
+
* checks its shape; gzip cannot be read here). Without it a recording is refused, as in local mode.
|
|
49
|
+
*/
|
|
50
|
+
export declare function checkAttachment(name: string, bytes: Uint8Array, options?: {
|
|
51
|
+
recordings?: boolean;
|
|
52
|
+
}): AttachmentCheck;
|
|
53
|
+
/** What a stored MIME type is served as: text with its charset, the rest as stored. */
|
|
54
|
+
export declare const servedType: (mime: string) => string;
|
|
55
|
+
/** Images open in place; documents are always downloads. The name is given twice: ASCII, and RFC 5987 UTF-8. */
|
|
56
|
+
export declare function contentDisposition(kind: AttachmentKind, name: string): string;
|
|
57
|
+
/** Before uploading: what the name (or, for a pasted image, the type) and size allow. The server still checks the bytes. */
|
|
58
|
+
export declare function precheckAttachment(file: {
|
|
59
|
+
name: string;
|
|
60
|
+
size: number;
|
|
61
|
+
type?: string;
|
|
62
|
+
}): {
|
|
63
|
+
ok: true;
|
|
64
|
+
kind: 'image' | 'document';
|
|
65
|
+
} | {
|
|
66
|
+
ok: false;
|
|
67
|
+
reason: 'type' | 'size' | 'empty';
|
|
68
|
+
limit?: number;
|
|
69
|
+
};
|
|
70
|
+
/** The words a refused file is shown with. */
|
|
71
|
+
export declare function refusalText(reason: 'type' | 'size' | 'empty' | 'count', limit?: number): string;
|
|
72
|
+
/** For the file picker: the types and extensions allowed (on a phone, images offer the camera and the library). */
|
|
73
|
+
export declare const acceptAttribute: string;
|
|
74
|
+
export declare function formatBytes(bytes: number): string;
|
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
const IMAGE_BYTES = 5242880;
|
|
2
|
+
const DOCUMENT_BYTES = 10485760;
|
|
3
|
+
const documentType = (type, mime) => ({ type, kind: 'document', mime, extensions: [type], maxBytes: DOCUMENT_BYTES });
|
|
4
|
+
export const ATTACHMENTS = {
|
|
5
|
+
maxFilesPerMessage: 5,
|
|
6
|
+
types: [
|
|
7
|
+
{ type: 'png', kind: 'image', mime: 'image/png', extensions: ['png'], maxBytes: IMAGE_BYTES },
|
|
8
|
+
{ type: 'jpeg', kind: 'image', mime: 'image/jpeg', extensions: ['jpg', 'jpeg'], maxBytes: IMAGE_BYTES },
|
|
9
|
+
{ type: 'webp', kind: 'image', mime: 'image/webp', extensions: ['webp'], maxBytes: IMAGE_BYTES },
|
|
10
|
+
{ type: 'gif', kind: 'image', mime: 'image/gif', extensions: ['gif'], maxBytes: IMAGE_BYTES },
|
|
11
|
+
documentType('pdf', 'application/pdf'),
|
|
12
|
+
documentType('docx', 'application/vnd.openxmlformats-officedocument.wordprocessingml.document'),
|
|
13
|
+
documentType('xlsx', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'),
|
|
14
|
+
documentType('pptx', 'application/vnd.openxmlformats-officedocument.presentationml.presentation'),
|
|
15
|
+
documentType('txt', 'text/plain'),
|
|
16
|
+
documentType('md', 'text/plain'),
|
|
17
|
+
documentType('csv', 'text/plain'),
|
|
18
|
+
documentType('json', 'text/plain'),
|
|
19
|
+
documentType('log', 'text/plain'),
|
|
20
|
+
{ type: 'rrweb', kind: 'recording', mime: 'application/vnd.ontrackd.recording+gzip', extensions: ['rrweb'], maxBytes: DOCUMENT_BYTES },
|
|
21
|
+
],
|
|
22
|
+
};
|
|
23
|
+
export const MAX_ATTACHMENT_BYTES = Math.max(...ATTACHMENTS.types.map((entry) => entry.maxBytes));
|
|
24
|
+
const ZIP_TYPES = ['docx', 'xlsx', 'pptx'];
|
|
25
|
+
const TEXT_TYPES = ['txt', 'md', 'csv', 'json', 'log'];
|
|
26
|
+
const byType = (type) => ATTACHMENTS.types.find((entry) => entry.type === type);
|
|
27
|
+
const byExtension = (extension) => extension ? ATTACHMENTS.types.find((entry) => entry.extensions.includes(extension)) : undefined;
|
|
28
|
+
const at = (bytes, index) => bytes[index] ?? -1;
|
|
29
|
+
const ascii = (bytes, from, to) => String.fromCharCode(...bytes.subarray(from, to));
|
|
30
|
+
/** The types whose first bytes say what they are. */
|
|
31
|
+
function sniff(bytes) {
|
|
32
|
+
if (bytes.length > 8 && at(bytes, 0) === 0x89 && ascii(bytes, 1, 4) === 'PNG' && at(bytes, 4) === 0x0d && at(bytes, 5) === 0x0a
|
|
33
|
+
&& at(bytes, 6) === 0x1a && at(bytes, 7) === 0x0a)
|
|
34
|
+
return 'png';
|
|
35
|
+
if (bytes.length > 3 && at(bytes, 0) === 0xff && at(bytes, 1) === 0xd8 && at(bytes, 2) === 0xff)
|
|
36
|
+
return 'jpeg';
|
|
37
|
+
if (bytes.length > 12 && ascii(bytes, 0, 4) === 'RIFF' && ascii(bytes, 8, 12) === 'WEBP')
|
|
38
|
+
return 'webp';
|
|
39
|
+
if (bytes.length > 6 && (ascii(bytes, 0, 6) === 'GIF87a' || ascii(bytes, 0, 6) === 'GIF89a'))
|
|
40
|
+
return 'gif';
|
|
41
|
+
if (bytes.length > 5 && ascii(bytes, 0, 5) === '%PDF-')
|
|
42
|
+
return 'pdf';
|
|
43
|
+
return null;
|
|
44
|
+
}
|
|
45
|
+
const isZip = (bytes) => bytes.length > 4 && at(bytes, 0) === 0x50 && at(bytes, 1) === 0x4b && at(bytes, 2) === 0x03 && at(bytes, 3) === 0x04;
|
|
46
|
+
function isText(bytes) {
|
|
47
|
+
if (bytes.includes(0))
|
|
48
|
+
return false;
|
|
49
|
+
try {
|
|
50
|
+
new TextDecoder('utf-8', { fatal: true, ignoreBOM: false }).decode(bytes);
|
|
51
|
+
return true;
|
|
52
|
+
}
|
|
53
|
+
catch {
|
|
54
|
+
return false;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
/** An image's pixel size from its header, or null when the header does not say. */
|
|
58
|
+
export function imageSize(type, bytes) {
|
|
59
|
+
const u16be = (i) => ((bytes[i] ?? 0) << 8) | (bytes[i + 1] ?? 0);
|
|
60
|
+
const u16le = (i) => (bytes[i] ?? 0) | ((bytes[i + 1] ?? 0) << 8);
|
|
61
|
+
const u24le = (i) => (bytes[i] ?? 0) | ((bytes[i + 1] ?? 0) << 8) | ((bytes[i + 2] ?? 0) << 16);
|
|
62
|
+
const u32be = (i) => ((bytes[i] ?? 0) * 0x1000000) + (((bytes[i + 1] ?? 0) << 16) | ((bytes[i + 2] ?? 0) << 8) | (bytes[i + 3] ?? 0));
|
|
63
|
+
let size = null;
|
|
64
|
+
if (type === 'png' && bytes.length >= 24)
|
|
65
|
+
size = { width: u32be(16), height: u32be(20) };
|
|
66
|
+
else if (type === 'gif' && bytes.length >= 10)
|
|
67
|
+
size = { width: u16le(6), height: u16le(8) };
|
|
68
|
+
else if (type === 'webp' && bytes.length >= 30) {
|
|
69
|
+
const chunk = ascii(bytes, 12, 16);
|
|
70
|
+
if (chunk === 'VP8X')
|
|
71
|
+
size = { width: u24le(24) + 1, height: u24le(27) + 1 };
|
|
72
|
+
else if (chunk === 'VP8 ')
|
|
73
|
+
size = { width: u16le(26) & 0x3fff, height: u16le(28) & 0x3fff };
|
|
74
|
+
else if (chunk === 'VP8L') {
|
|
75
|
+
const bits = ((bytes[21] ?? 0) | ((bytes[22] ?? 0) << 8) | ((bytes[23] ?? 0) << 16) | ((bytes[24] ?? 0) << 24)) >>> 0;
|
|
76
|
+
size = { width: (bits & 0x3fff) + 1, height: ((bits >>> 14) & 0x3fff) + 1 };
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
else if (type === 'jpeg') {
|
|
80
|
+
let i = 2;
|
|
81
|
+
while (i + 9 < bytes.length) {
|
|
82
|
+
if (bytes[i] !== 0xff) {
|
|
83
|
+
i++;
|
|
84
|
+
continue;
|
|
85
|
+
}
|
|
86
|
+
const marker = bytes[i + 1] ?? 0;
|
|
87
|
+
if (marker === 0xff) {
|
|
88
|
+
i++;
|
|
89
|
+
continue;
|
|
90
|
+
}
|
|
91
|
+
if (marker === 0xd8 || marker === 0x01 || (marker >= 0xd0 && marker <= 0xd7)) {
|
|
92
|
+
i += 2;
|
|
93
|
+
continue;
|
|
94
|
+
}
|
|
95
|
+
// Start of frame (not DHT, JPG or DAC, which share the range): precision, height, width.
|
|
96
|
+
if (marker >= 0xc0 && marker <= 0xcf && marker !== 0xc4 && marker !== 0xc8 && marker !== 0xcc) {
|
|
97
|
+
size = { width: u16be(i + 7), height: u16be(i + 5) };
|
|
98
|
+
break;
|
|
99
|
+
}
|
|
100
|
+
i += 2 + u16be(i + 2);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
return size && size.width >= 1 && size.height >= 1 && size.width <= 100000 && size.height <= 100000 ? size : null;
|
|
104
|
+
}
|
|
105
|
+
/** Unpaired UTF-16 surrogates: they make encodeURIComponent throw, and no file system keeps them. */
|
|
106
|
+
const LONE_SURROGATE = /[\ud800-\udbff](?![\udc00-\udfff])|(?<![\ud800-\udbff])[\udc00-\udfff]/g;
|
|
107
|
+
/** Zero-width, bidi and other invisible format characters, which could make a name display as another type. */
|
|
108
|
+
const INVISIBLE = /[\u061c\u200b-\u200f\u2028-\u202e\u2066-\u2069\ufeff]/g;
|
|
109
|
+
/** Without control characters, unpaired surrogates, invisible or bidi characters, path separators, surrounding space or leading dots. */
|
|
110
|
+
function cleanName(name) {
|
|
111
|
+
return name.replace(/[\u0000-\u001f\u007f-\u009f]/g, '').replace(LONE_SURROGATE, '').replace(INVISIBLE, '').replace(/[/\\]/g, '')
|
|
112
|
+
.trim().replace(/^\.+/, '').trim();
|
|
113
|
+
}
|
|
114
|
+
const extensionOf = (name) => {
|
|
115
|
+
const dot = name.lastIndexOf('.');
|
|
116
|
+
return dot > 0 ? name.slice(dot + 1).toLowerCase() : '';
|
|
117
|
+
};
|
|
118
|
+
/** The name a file is stored and downloaded under: clean, at most 120 characters, ending in an extension of its type. */
|
|
119
|
+
export function storedName(name, type) {
|
|
120
|
+
const clean = cleanName(name);
|
|
121
|
+
const extension = extensionOf(clean);
|
|
122
|
+
const kept = type.extensions.includes(extension);
|
|
123
|
+
const base = (kept ? clean.slice(0, clean.lastIndexOf('.')) : clean).trim() || 'file';
|
|
124
|
+
const ending = kept ? extension : type.extensions[0] ?? type.type;
|
|
125
|
+
return `${[...base].slice(0, 120 - ending.length - 1).join('')}.${ending}`;
|
|
126
|
+
}
|
|
127
|
+
const isGzip = (bytes) => bytes.length > 2 && at(bytes, 0) === 0x1f && at(bytes, 1) === 0x8b;
|
|
128
|
+
/**
|
|
129
|
+
* `recordings`: the caller can also vouch for an rrweb recording (the Worker, which then decompresses and
|
|
130
|
+
* checks its shape; gzip cannot be read here). Without it a recording is refused, as in local mode.
|
|
131
|
+
*/
|
|
132
|
+
export function checkAttachment(name, bytes, options = {}) {
|
|
133
|
+
if (bytes.length === 0)
|
|
134
|
+
return { ok: false, reason: 'empty' };
|
|
135
|
+
const extension = extensionOf(cleanName(name));
|
|
136
|
+
const sniffed = sniff(bytes);
|
|
137
|
+
let type;
|
|
138
|
+
if (sniffed) {
|
|
139
|
+
type = byType(sniffed);
|
|
140
|
+
// A PDF is known by its bytes, but a name claiming another document type is a lie about it.
|
|
141
|
+
if (type?.kind === 'document' && extension && !type.extensions.includes(extension))
|
|
142
|
+
return { ok: false, reason: 'type' };
|
|
143
|
+
}
|
|
144
|
+
else {
|
|
145
|
+
const named = byExtension(extension);
|
|
146
|
+
if (named && ZIP_TYPES.includes(named.type) && isZip(bytes))
|
|
147
|
+
type = named;
|
|
148
|
+
else if (named && TEXT_TYPES.includes(named.type) && isText(bytes))
|
|
149
|
+
type = named;
|
|
150
|
+
else if (named?.kind === 'recording' && options.recordings && isGzip(bytes))
|
|
151
|
+
type = named;
|
|
152
|
+
}
|
|
153
|
+
if (!type)
|
|
154
|
+
return { ok: false, reason: 'type' };
|
|
155
|
+
if (bytes.length > type.maxBytes)
|
|
156
|
+
return { ok: false, reason: 'size', limit: type.maxBytes };
|
|
157
|
+
const size = type.kind === 'image' ? imageSize(type.type, bytes) : null;
|
|
158
|
+
return { ok: true, type, name: storedName(name, type), width: size?.width ?? null, height: size?.height ?? null };
|
|
159
|
+
}
|
|
160
|
+
/** What a stored MIME type is served as: text with its charset, the rest as stored. */
|
|
161
|
+
export const servedType = (mime) => mime === 'text/plain' ? 'text/plain; charset=utf-8' : mime;
|
|
162
|
+
/** Images open in place; documents are always downloads. The name is given twice: ASCII, and RFC 5987 UTF-8. */
|
|
163
|
+
export function contentDisposition(kind, name) {
|
|
164
|
+
const fallback = name.replace(/[^\x20-\x7e]/g, '_').replace(/["\\]/g, '_');
|
|
165
|
+
const encoded = encodeURIComponent(name).replace(/['()*]/g, (character) => `%${character.charCodeAt(0).toString(16).toUpperCase()}`);
|
|
166
|
+
return `${kind === 'image' ? 'inline' : 'attachment'}; filename="${fallback}"; filename*=UTF-8''${encoded}`;
|
|
167
|
+
}
|
|
168
|
+
/** Before uploading: what the name (or, for a pasted image, the type) and size allow. The server still checks the bytes. */
|
|
169
|
+
export function precheckAttachment(file) {
|
|
170
|
+
const type = byExtension(extensionOf(cleanName(file.name))) ?? ATTACHMENTS.types.find((entry) => entry.kind === 'image' && entry.mime === file.type);
|
|
171
|
+
// A recording is made by the overlay's Record button, never picked.
|
|
172
|
+
if (!type || type.kind === 'recording')
|
|
173
|
+
return { ok: false, reason: 'type' };
|
|
174
|
+
if (file.size === 0)
|
|
175
|
+
return { ok: false, reason: 'empty' };
|
|
176
|
+
if (file.size > type.maxBytes)
|
|
177
|
+
return { ok: false, reason: 'size', limit: type.maxBytes };
|
|
178
|
+
return { ok: true, kind: type.kind };
|
|
179
|
+
}
|
|
180
|
+
/** The words a refused file is shown with. */
|
|
181
|
+
export function refusalText(reason, limit) {
|
|
182
|
+
if (reason === 'size')
|
|
183
|
+
return `Over ${Math.round((limit ?? MAX_ATTACHMENT_BYTES) / 1048576)} MB`;
|
|
184
|
+
if (reason === 'count')
|
|
185
|
+
return `${ATTACHMENTS.maxFilesPerMessage} files at most`;
|
|
186
|
+
if (reason === 'empty')
|
|
187
|
+
return 'This file is empty';
|
|
188
|
+
return 'Only images and documents';
|
|
189
|
+
}
|
|
190
|
+
/** For the file picker: the types and extensions allowed (on a phone, images offer the camera and the library). */
|
|
191
|
+
export const acceptAttribute = [...new Set(ATTACHMENTS.types.filter((entry) => entry.kind !== 'recording').flatMap((entry) => [entry.mime, ...entry.extensions.map((extension) => `.${extension}`)]))].join(',');
|
|
192
|
+
export function formatBytes(bytes) {
|
|
193
|
+
if (bytes < 1024)
|
|
194
|
+
return `${bytes} B`;
|
|
195
|
+
if (bytes < 1048576)
|
|
196
|
+
return `${Math.round(bytes / 1024)} KB`;
|
|
197
|
+
return `${(bytes / 1048576).toFixed(1)} MB`;
|
|
198
|
+
}
|
|
199
|
+
//# sourceMappingURL=attachmentTypes.js.map
|