@adep/vite-plugin 0.1.9 → 0.1.10
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/dist/ide-proxy.d.ts +11 -1
- package/dist/index.js +4 -1
- package/package.json +1 -1
package/dist/ide-proxy.d.ts
CHANGED
|
@@ -26,10 +26,20 @@
|
|
|
26
26
|
* blob URL SPA 路由:patch `history.pushState/replaceState`,对相对路径直接吞掉(blob 不可
|
|
27
27
|
* 分层,原生 pushState 解析相对路径抛 TypeError),`location.pathname` 覆盖为当前路由路径,
|
|
28
28
|
* sessionStorage 持久化,刷新后恢复。
|
|
29
|
+
*
|
|
30
|
+
* 同源收窄(2026-11-03 生产实录):拦截判定原先只看 pathname,把**跨域绝对 URL** 中路径
|
|
31
|
+
* 恰为 /api/* 的请求也劫走——用户应用在预览里接平台 OIDC 登录(issuer 推导为
|
|
32
|
+
* `https://<平台域>/api`,register 路径 `/api/oauth/register`),请求被送进模拟函数运行时
|
|
33
|
+
* 按「函数 oauth 不存在」回 4xx/5xx,登录按钮报「注册登录客户端失败(HTTP 500)」,且
|
|
34
|
+
* 请求从未离开浏览器(服务端 access.log 无痕)。故拦截限**同源**(`u.origin ===
|
|
35
|
+
* location.origin`)的 /api/*:应用自身的函数面(相对路径或预览子域绝对 URL)不变;
|
|
36
|
+
* 跨域 /api/*(平台 OIDC 端点、三方 API)一律放行原生 fetch。blob 预览继承创建者 origin,
|
|
37
|
+
* 相对 /api/* 经 location.origin 兜底解析后仍判同源,行为不变;该形态下应用若以绝对 URL
|
|
38
|
+
* 调平台 API 则与自身函数面同 origin、无法区分,仍会被劫持——已知限制,非本收窄目标。
|
|
29
39
|
*/
|
|
30
40
|
import type { IncomingMessage, ServerResponse } from 'node:http';
|
|
31
41
|
/** 浏览器端 fetch 拦截器脚本(IIFE,纯 JS——必须能直接内联进 script 标签,无 TS / ESM)。 */
|
|
32
|
-
export declare const FN_FETCH_INTERCEPTOR_SCRIPT = "(function () {\n if (window.__adepFnProxyInstalled) return;\n window.__adepFnProxyInstalled = true;\n var ORIGINAL_FETCH = window.fetch.bind(window);\n var pending = {};\n var nextId = 1;\n var TIMEOUT_MS = 15000;\n\n window.addEventListener(\"message\", function (event) {\n var data = event.data;\n if (!data || data.__adepFnResponse !== true) return;\n var entry = pending[data.id];\n if (!entry) return;\n delete pending[data.id];\n clearTimeout(entry.timer);\n var headers;\n try { headers = new Headers(data.headers || {}); }\n catch (e) { headers = new Headers({ \"content-type\": \"text/plain\" }); }\n var body = data.body == null ? null : data.body;\n try {\n entry.resolve(new Response(body, { status: data.status || 200, statusText: \"\", headers: headers }));\n } catch (e2) {\n entry.resolve(new Response(String(body), { status: data.status || 200, headers: { \"content-type\": \"text/plain\" } }));\n }\n });\n\n function readBody(input, init) {\n if (typeof Request !== \"undefined\" && input instanceof Request) {\n return input.text().catch(function () { return null; });\n }\n var body = init && init.body !== undefined ? init.body : input;\n if (body == null) return Promise.resolve(null);\n if (typeof body === \"string\") return Promise.resolve(body);\n if (typeof ArrayBuffer !== \"undefined\" && body instanceof ArrayBuffer) {\n return Promise.resolve(new TextDecoder().decode(body));\n }\n if (typeof Blob !== \"undefined\" && body instanceof Blob) return body.text();\n if (typeof URLSearchParams !== \"undefined\" && body instanceof URLSearchParams) {\n return Promise.resolve(body.toString());\n }\n try { return Promise.resolve(String(body)); } catch (e) { return Promise.resolve(null); }\n }\n\n function collectHeaders(input, init) {\n var out = {};\n try { input.headers.forEach(function (v, k) { out[k] = v; }); } catch (e) {}\n if (init && init.headers) {\n try { new Headers(init.headers).forEach(function (v, k) { out[k] = v; }); } catch (e2) {}\n }\n return out;\n }\n\n window.fetch = function (input, init) {\n var urlStr;\n var method;\n var headers = {};\n var isRequest = typeof Request !== \"undefined\" && input instanceof Request;\n if (isRequest) {\n urlStr = String(input.url);\n method = (init && init.method) || input.method || \"GET\";\n headers = collectHeaders(input, init);\n } else if (typeof input === \"string\" || (typeof URL !== \"undefined\" && input instanceof URL)) {\n urlStr = String(input);\n method = (init && init.method) || \"GET\";\n try { new Headers(init && init.headers || {}).forEach(function (v, k) { headers[k] = v; }); } catch (e) {}\n } else {\n return ORIGINAL_FETCH(input, init);\n }\n var u;\n try { u = new URL(urlStr, document.baseURI); }\n catch (e0) {\n try { u = new URL(urlStr, window.location.origin); }\n catch (e1) { return ORIGINAL_FETCH(input, init); }\n }\n if (u.pathname.indexOf(\"/api/\") !== 0 && u.pathname !== \"/api\") {\n return ORIGINAL_FETCH(input, init);\n }\n var bridgeWindow = window.parent !== window ? window.parent : window.opener;\n if (!bridgeWindow) return ORIGINAL_FETCH(input, init);\n method = (method || \"GET\").toUpperCase();\n var target = u.pathname + u.search;\n return readBody(input, init).then(function (textBody) {\n return new Promise(function (resolve) {\n var id = nextId++;\n var timer = setTimeout(function () {\n delete pending[id];\n resolve(new Response('{\"error\":{\"code\":\"FN_PROXY_TIMEOUT\",\"message\":\"\\u4e91\\u51fd\\u6570\\u6267\\u884c\\u8d85\\u65f6\"}}', { status: 504, headers: { \"content-type\": \"application/json\" } }));\n }, TIMEOUT_MS);\n pending[id] = { resolve: resolve, timer: timer };\n bridgeWindow.postMessage({ __adepFnRequest: true, id: id, method: method, url: target, headers: headers, body: textBody }, \"*\");\n });\n });\n };\n\n /* \u2014\u2014 blob URL SPA \u8DEF\u7531\u652F\u6301 \u2014\u2014\n blob: \u662F\u4E0D\u53EF\u5206\u5C42 scheme\uFF0Chistory.pushState('/about') \u5185\u90E8\u89E3\u6790\u76F8\u5BF9\u8DEF\u5F84\u4F1A\u629B\n TypeError \u2192 SPA history \u6A21\u5F0F\u8DEF\u7531\u5D29\u6E83\u3002patch pushState/replaceState\uFF0C\u5BF9\u76F8\u5BF9\n \u8DEF\u5F84\u76F4\u63A5\u541E\u6389\uFF08\u4E0D\u5BFC\u822A\u3001\u4E0D\u629B\u9519\uFF09\uFF0C\u8DEF\u7531\u5E93\u5185\u90E8\u72B6\u6001\u81EA\u884C\u66F4\u65B0\uFF1Blocation.pathname\n \u8986\u76D6\u4E3A\u5F53\u524D\u8DEF\u7531\u8DEF\u5F84\uFF0C\u4F9B\u8DEF\u7531\u5E93\u521D\u59CB\u5316\u65F6\u8BFB\u53D6\u3002sessionStorage \u6301\u4E45\u5316\uFF0C\u5237\u65B0\u540E\u6062\u590D\u3002 */\n if (window.location.protocol === \"blob:\") {\n var SPA_KEY = \"__adep_spa_path\";\n var spaPath = \"/\";\n try {\n var _saved = window.sessionStorage.getItem(SPA_KEY);\n if (_saved) spaPath = _saved;\n } catch (e) {}\n try {\n Object.defineProperty(window.location, \"pathname\", {\n get: function () { return spaPath; },\n configurable: true\n });\n } catch (e) {}\n var _origPush = window.history.pushState.bind(window.history);\n var _origReplace = window.history.replaceState.bind(window.history);\n function _isRelative(url) {\n if (!url || typeof url !== \"string\") return false;\n if (url.charAt(0) === \"#\") return false;\n if (/^[a-zA-Z][a-zA-Z0-9+.-]*:/.test(url)) return false;\n return true;\n }\n function _resolvePath(url) {\n var qi = url.indexOf(\"?\");\n var hi = url.indexOf(\"#\");\n var end = url.length;\n if (qi !== -1) end = qi;\n if (hi !== -1 && hi < end) end = hi;\n var p = url.slice(0, end);\n if (p.charAt(0) !== \"/\") {\n var base = spaPath.slice(0, spaPath.lastIndexOf(\"/\") + 1);\n p = base + p;\n }\n var parts = p.split(\"/\");\n var out = [];\n for (var i = 0; i < parts.length; i++) {\n var seg = parts[i];\n if (seg === \"\" || seg === \".\") continue;\n if (seg === \"..\") { out.pop(); continue; }\n out.push(seg);\n }\n return \"/\" + out.join(\"/\");\n }\n window.history.pushState = function (state, title, url) {\n if (_isRelative(url)) {\n spaPath = _resolvePath(url);\n try { window.sessionStorage.setItem(SPA_KEY, spaPath); } catch (e) {}\n return;\n }\n return _origPush(state, title, url);\n };\n window.history.replaceState = function (state, title, url) {\n if (_isRelative(url)) {\n spaPath = _resolvePath(url);\n try { window.sessionStorage.setItem(SPA_KEY, spaPath); } catch (e) {}\n return;\n }\n return _origReplace(state, title, url);\n };\n }\n})();";
|
|
42
|
+
export declare const FN_FETCH_INTERCEPTOR_SCRIPT = "(function () {\n if (window.__adepFnProxyInstalled) return;\n window.__adepFnProxyInstalled = true;\n var ORIGINAL_FETCH = window.fetch.bind(window);\n var pending = {};\n var nextId = 1;\n var TIMEOUT_MS = 15000;\n\n window.addEventListener(\"message\", function (event) {\n var data = event.data;\n if (!data || data.__adepFnResponse !== true) return;\n var entry = pending[data.id];\n if (!entry) return;\n delete pending[data.id];\n clearTimeout(entry.timer);\n var headers;\n try { headers = new Headers(data.headers || {}); }\n catch (e) { headers = new Headers({ \"content-type\": \"text/plain\" }); }\n var body = data.body == null ? null : data.body;\n try {\n entry.resolve(new Response(body, { status: data.status || 200, statusText: \"\", headers: headers }));\n } catch (e2) {\n entry.resolve(new Response(String(body), { status: data.status || 200, headers: { \"content-type\": \"text/plain\" } }));\n }\n });\n\n function readBody(input, init) {\n if (typeof Request !== \"undefined\" && input instanceof Request) {\n return input.text().catch(function () { return null; });\n }\n var body = init && init.body !== undefined ? init.body : input;\n if (body == null) return Promise.resolve(null);\n if (typeof body === \"string\") return Promise.resolve(body);\n if (typeof ArrayBuffer !== \"undefined\" && body instanceof ArrayBuffer) {\n return Promise.resolve(new TextDecoder().decode(body));\n }\n if (typeof Blob !== \"undefined\" && body instanceof Blob) return body.text();\n if (typeof URLSearchParams !== \"undefined\" && body instanceof URLSearchParams) {\n return Promise.resolve(body.toString());\n }\n try { return Promise.resolve(String(body)); } catch (e) { return Promise.resolve(null); }\n }\n\n function collectHeaders(input, init) {\n var out = {};\n try { input.headers.forEach(function (v, k) { out[k] = v; }); } catch (e) {}\n if (init && init.headers) {\n try { new Headers(init.headers).forEach(function (v, k) { out[k] = v; }); } catch (e2) {}\n }\n return out;\n }\n\n window.fetch = function (input, init) {\n var urlStr;\n var method;\n var headers = {};\n var isRequest = typeof Request !== \"undefined\" && input instanceof Request;\n if (isRequest) {\n urlStr = String(input.url);\n method = (init && init.method) || input.method || \"GET\";\n headers = collectHeaders(input, init);\n } else if (typeof input === \"string\" || (typeof URL !== \"undefined\" && input instanceof URL)) {\n urlStr = String(input);\n method = (init && init.method) || \"GET\";\n try { new Headers(init && init.headers || {}).forEach(function (v, k) { headers[k] = v; }); } catch (e) {}\n } else {\n return ORIGINAL_FETCH(input, init);\n }\n var u;\n try { u = new URL(urlStr, document.baseURI); }\n catch (e0) {\n try { u = new URL(urlStr, window.location.origin); }\n catch (e1) { return ORIGINAL_FETCH(input, init); }\n }\n if (\n u.origin !== window.location.origin ||\n (u.pathname.indexOf(\"/api/\") !== 0 && u.pathname !== \"/api\")\n ) {\n return ORIGINAL_FETCH(input, init);\n }\n var bridgeWindow = window.parent !== window ? window.parent : window.opener;\n if (!bridgeWindow) return ORIGINAL_FETCH(input, init);\n method = (method || \"GET\").toUpperCase();\n var target = u.pathname + u.search;\n return readBody(input, init).then(function (textBody) {\n return new Promise(function (resolve) {\n var id = nextId++;\n var timer = setTimeout(function () {\n delete pending[id];\n resolve(new Response('{\"error\":{\"code\":\"FN_PROXY_TIMEOUT\",\"message\":\"\\u4e91\\u51fd\\u6570\\u6267\\u884c\\u8d85\\u65f6\"}}', { status: 504, headers: { \"content-type\": \"application/json\" } }));\n }, TIMEOUT_MS);\n pending[id] = { resolve: resolve, timer: timer };\n bridgeWindow.postMessage({ __adepFnRequest: true, id: id, method: method, url: target, headers: headers, body: textBody }, \"*\");\n });\n });\n };\n\n /* \u2014\u2014 blob URL SPA \u8DEF\u7531\u652F\u6301 \u2014\u2014\n blob: \u662F\u4E0D\u53EF\u5206\u5C42 scheme\uFF0Chistory.pushState('/about') \u5185\u90E8\u89E3\u6790\u76F8\u5BF9\u8DEF\u5F84\u4F1A\u629B\n TypeError \u2192 SPA history \u6A21\u5F0F\u8DEF\u7531\u5D29\u6E83\u3002patch pushState/replaceState\uFF0C\u5BF9\u76F8\u5BF9\n \u8DEF\u5F84\u76F4\u63A5\u541E\u6389\uFF08\u4E0D\u5BFC\u822A\u3001\u4E0D\u629B\u9519\uFF09\uFF0C\u8DEF\u7531\u5E93\u5185\u90E8\u72B6\u6001\u81EA\u884C\u66F4\u65B0\uFF1Blocation.pathname\n \u8986\u76D6\u4E3A\u5F53\u524D\u8DEF\u7531\u8DEF\u5F84\uFF0C\u4F9B\u8DEF\u7531\u5E93\u521D\u59CB\u5316\u65F6\u8BFB\u53D6\u3002sessionStorage \u6301\u4E45\u5316\uFF0C\u5237\u65B0\u540E\u6062\u590D\u3002 */\n if (window.location.protocol === \"blob:\") {\n var SPA_KEY = \"__adep_spa_path\";\n var spaPath = \"/\";\n try {\n var _saved = window.sessionStorage.getItem(SPA_KEY);\n if (_saved) spaPath = _saved;\n } catch (e) {}\n try {\n Object.defineProperty(window.location, \"pathname\", {\n get: function () { return spaPath; },\n configurable: true\n });\n } catch (e) {}\n var _origPush = window.history.pushState.bind(window.history);\n var _origReplace = window.history.replaceState.bind(window.history);\n function _isRelative(url) {\n if (!url || typeof url !== \"string\") return false;\n if (url.charAt(0) === \"#\") return false;\n if (/^[a-zA-Z][a-zA-Z0-9+.-]*:/.test(url)) return false;\n return true;\n }\n function _resolvePath(url) {\n var qi = url.indexOf(\"?\");\n var hi = url.indexOf(\"#\");\n var end = url.length;\n if (qi !== -1) end = qi;\n if (hi !== -1 && hi < end) end = hi;\n var p = url.slice(0, end);\n if (p.charAt(0) !== \"/\") {\n var base = spaPath.slice(0, spaPath.lastIndexOf(\"/\") + 1);\n p = base + p;\n }\n var parts = p.split(\"/\");\n var out = [];\n for (var i = 0; i < parts.length; i++) {\n var seg = parts[i];\n if (seg === \"\" || seg === \".\") continue;\n if (seg === \"..\") { out.pop(); continue; }\n out.push(seg);\n }\n return \"/\" + out.join(\"/\");\n }\n window.history.pushState = function (state, title, url) {\n if (_isRelative(url)) {\n spaPath = _resolvePath(url);\n try { window.sessionStorage.setItem(SPA_KEY, spaPath); } catch (e) {}\n return;\n }\n return _origPush(state, title, url);\n };\n window.history.replaceState = function (state, title, url) {\n if (_isRelative(url)) {\n spaPath = _resolvePath(url);\n try { window.sessionStorage.setItem(SPA_KEY, spaPath); } catch (e) {}\n return;\n }\n return _origReplace(state, title, url);\n };\n }\n})();";
|
|
33
43
|
/**
|
|
34
44
|
* 浏览器端控制台中继脚本(IIFE,纯 JS——必须能直接内联进 script 标签,无 TS / ESM)。
|
|
35
45
|
*
|
package/dist/index.js
CHANGED
|
@@ -594,7 +594,10 @@ var FN_FETCH_INTERCEPTOR_SCRIPT = `(function () {
|
|
|
594
594
|
try { u = new URL(urlStr, window.location.origin); }
|
|
595
595
|
catch (e1) { return ORIGINAL_FETCH(input, init); }
|
|
596
596
|
}
|
|
597
|
-
if (
|
|
597
|
+
if (
|
|
598
|
+
u.origin !== window.location.origin ||
|
|
599
|
+
(u.pathname.indexOf("/api/") !== 0 && u.pathname !== "/api")
|
|
600
|
+
) {
|
|
598
601
|
return ORIGINAL_FETCH(input, init);
|
|
599
602
|
}
|
|
600
603
|
var bridgeWindow = window.parent !== window ? window.parent : window.opener;
|
package/package.json
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
},
|
|
8
8
|
"homepage": "https://adep.top",
|
|
9
9
|
"bugs": "https://gitcode.com/yunqiang_wu/ai-yunke/issues",
|
|
10
|
-
"version": "0.1.
|
|
10
|
+
"version": "0.1.10",
|
|
11
11
|
"private": false,
|
|
12
12
|
"type": "module",
|
|
13
13
|
"description": "云函数 Vite 插件(IDE-030,自 CLI-014 @adep/cli/vite 抽出):vite dev 进程内启动本地 adep dev server 并代理 /{prefix}/* 到云函数;同时 serve /@adep/fn-proxy.js(Web IDE 预览 fetch 拦截器)。本地运行时与配置加载经 createDevServer / loadConfig 注入端口接入,供 CLI / Web IDE / 非 CLI 用户独立使用。",
|