pinokiod 6.0.64 → 6.0.66

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pinokiod",
3
- "version": "6.0.64",
3
+ "version": "6.0.66",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -5,81 +5,6 @@ const path = require("path")
5
5
 
6
6
  const { resolveDesktopEventWorkspace } = require("./desktop_event_router")
7
7
 
8
- const escapeRegex = (value) => String(value || "").replace(/[|\\{}()[\]^$+?.]/g, "\\$&")
9
-
10
- const wildcardToRegex = (pattern) => {
11
- const source = escapeRegex(pattern).replace(/\*/g, ".*")
12
- return new RegExp(`^${source}$`)
13
- }
14
-
15
- const normalizeInjectPatterns = (value) => {
16
- const list = Array.isArray(value) ? value : [value]
17
- const patterns = list
18
- .map((item) => (typeof item === "string" ? item.trim() : ""))
19
- .filter(Boolean)
20
- return patterns.length ? patterns : ["*"]
21
- }
22
-
23
- const normalizeInjectEntries = (injectConfig) => {
24
- if (!injectConfig) {
25
- return []
26
- }
27
- const entries = Array.isArray(injectConfig) ? injectConfig : [injectConfig]
28
- const normalized = []
29
- for (const entry of entries) {
30
- const config = typeof entry === "string" ? { href: entry } : entry
31
- if (!config || typeof config !== "object") {
32
- continue
33
- }
34
- const href = typeof config.href === "string" ? config.href.trim() : ""
35
- if (!href) {
36
- continue
37
- }
38
- normalized.push({
39
- href,
40
- match: normalizeInjectPatterns(config.match)
41
- })
42
- }
43
- return normalized
44
- }
45
-
46
- const resolveInjectMatchCandidates = (targetUrl) => {
47
- if (typeof targetUrl !== "string") {
48
- return []
49
- }
50
- const value = targetUrl.trim()
51
- if (!value) {
52
- return []
53
- }
54
- let parsed
55
- try {
56
- parsed = new URL(value)
57
- } catch (_) {
58
- return [value]
59
- }
60
- const pathname = parsed.pathname || ""
61
- const originPath = `${parsed.origin}${pathname}`
62
- const hostPath = `${parsed.host}${pathname}`
63
- return [parsed.href, originPath, hostPath, pathname].filter(Boolean)
64
- }
65
-
66
- const matchesInjectPattern = (pattern, targetUrl) => {
67
- if (pattern === "*") {
68
- return true
69
- }
70
- const candidates = resolveInjectMatchCandidates(targetUrl)
71
- if (!candidates.length) {
72
- return false
73
- }
74
- let expression
75
- try {
76
- expression = wildcardToRegex(pattern)
77
- } catch (_) {
78
- return false
79
- }
80
- return candidates.some((candidate) => expression.test(candidate))
81
- }
82
-
83
8
  const normalizeInjectHrefList = (value) => {
84
9
  if (!value) {
85
10
  return []
@@ -142,7 +67,14 @@ const resolveInjectLaunchUrl = async ({ workspace, workspaceRoot, launcher, href
142
67
 
143
68
  let launchPath
144
69
  if (hrefPath.startsWith("/")) {
145
- launchPath = hrefPath
70
+ const normalized = hrefPath.trim()
71
+ if (normalized.startsWith("/api/")) {
72
+ launchPath = `/raw/${normalized.slice("/api/".length)}`
73
+ } else if (normalized.startsWith("/_api/")) {
74
+ launchPath = `/raw/${normalized.slice("/_api/".length)}`
75
+ } else {
76
+ launchPath = normalized
77
+ }
146
78
  } else {
147
79
  const launcherRoot = launcher.launcher_root
148
80
  ? path.resolve(workspaceRoot, launcher.launcher_root)
@@ -168,7 +100,7 @@ const resolveInjectLaunchUrl = async ({ workspace, workspaceRoot, launcher, href
168
100
  if (routeSegments.length === 0) {
169
101
  return null
170
102
  }
171
- launchPath = `/api/${encodeURIComponent(workspace)}/${routeSegments.join("/")}`
103
+ launchPath = `/raw/${encodeURIComponent(workspace)}/${routeSegments.join("/")}`
172
104
  }
173
105
 
174
106
  const queryParams = new URLSearchParams(querySuffix)
@@ -229,45 +161,7 @@ const createInjectRouter = ({ kernel }) => {
229
161
 
230
162
  const frameUrl = typeof context.frameUrl === "string" ? context.frameUrl : ""
231
163
  const frameInjectEntries = parseFrameInjectEntries(frameUrl)
232
- if (frameInjectEntries.length > 0) {
233
- const scripts = []
234
- for (const hrefRaw of frameInjectEntries) {
235
- const launchUrl = await resolveInjectLaunchUrl({
236
- workspace,
237
- workspaceRoot,
238
- launcher,
239
- hrefRaw
240
- })
241
- if (!launchUrl) {
242
- continue
243
- }
244
- scripts.push(launchUrl)
245
- }
246
- const uniqueScripts = [...new Set(scripts)]
247
- if (uniqueScripts.length > 0) {
248
- return {
249
- status: 200,
250
- body: {
251
- ok: true,
252
- matched: true,
253
- workspace,
254
- scripts: uniqueScripts,
255
- source: "frame_query"
256
- }
257
- }
258
- }
259
- }
260
-
261
- let injectConfig = launcher.script.inject
262
- if (typeof injectConfig === "function") {
263
- if (injectConfig.constructor.name === "AsyncFunction") {
264
- injectConfig = await injectConfig(kernel, kernel.info)
265
- } else {
266
- injectConfig = injectConfig(kernel, kernel.info)
267
- }
268
- }
269
- const entries = normalizeInjectEntries(injectConfig)
270
- if (!entries.length) {
164
+ if (frameInjectEntries.length === 0) {
271
165
  return {
272
166
  status: 200,
273
167
  body: {
@@ -275,21 +169,18 @@ const createInjectRouter = ({ kernel }) => {
275
169
  matched: false,
276
170
  workspace,
277
171
  scripts: [],
278
- reason: "inject_not_configured"
172
+ reason: "inject_not_requested"
279
173
  }
280
174
  }
281
175
  }
282
176
 
283
177
  const scripts = []
284
- for (const entry of entries) {
285
- if (!entry.match.some((pattern) => matchesInjectPattern(pattern, frameUrl))) {
286
- continue
287
- }
178
+ for (const hrefRaw of frameInjectEntries) {
288
179
  const launchUrl = await resolveInjectLaunchUrl({
289
180
  workspace,
290
181
  workspaceRoot,
291
182
  launcher,
292
- hrefRaw: entry.href
183
+ hrefRaw
293
184
  })
294
185
  if (!launchUrl) {
295
186
  continue
@@ -304,7 +195,8 @@ const createInjectRouter = ({ kernel }) => {
304
195
  ok: true,
305
196
  matched: uniqueScripts.length > 0,
306
197
  workspace,
307
- scripts: uniqueScripts
198
+ scripts: uniqueScripts,
199
+ source: "frame_query"
308
200
  }
309
201
  }
310
202
  }
@@ -12243,7 +12243,6 @@ document.addEventListener("DOMContentLoaded", () => {
12243
12243
  const messageType = event.data.e
12244
12244
  const isPinokioBridgeMessage = (
12245
12245
  messageType === "pinokio:event" ||
12246
- messageType === "pinokio:event-launch" ||
12247
12246
  messageType === "pinokio:inject:request"
12248
12247
  )
12249
12248
  const trusted = isTrustedOrigin(event.origin) || (isPinokioBridgeMessage && isKnownFrameSource(event.source))
@@ -12276,14 +12275,6 @@ document.addEventListener("DOMContentLoaded", () => {
12276
12275
  })
12277
12276
  }
12278
12277
  }).catch(() => {})
12279
- } else if (messageType === "pinokio:event-launch") {
12280
- const payloadFrameUrl = event.data && event.data.context && typeof event.data.context.frameUrl === "string"
12281
- ? event.data.context.frameUrl
12282
- : ""
12283
- openEventLaunch(event.data && event.data.launch, {
12284
- sourceWindow: event.source,
12285
- sourceFrameUrl: payloadFrameUrl || resolveFrameUrlFromSource(event.source)
12286
- })
12287
12278
  } else if (messageType === "pinokio:inject:request") {
12288
12279
  dispatchPinokioInjectRequest(event.data, event.source).then((result) => {
12289
12280
  if (!result || !result.ok || !event.source || typeof event.source.postMessage !== "function") {