@portel/photon 1.33.1 → 1.33.2
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/README.md +38 -5
- package/dist/auto-ui/frontend/pure-view.html +5 -2
- package/dist/auto-ui/streamable-http-transport.d.ts.map +1 -1
- package/dist/auto-ui/streamable-http-transport.js +62 -11
- package/dist/auto-ui/streamable-http-transport.js.map +1 -1
- package/dist/beam.bundle.js +19 -17
- package/dist/beam.bundle.js.map +2 -2
- package/dist/capability-negotiator.d.ts +11 -0
- package/dist/capability-negotiator.d.ts.map +1 -1
- package/dist/capability-negotiator.js +20 -0
- package/dist/capability-negotiator.js.map +1 -1
- package/dist/daemon/worker-dep-proxy.d.ts +17 -0
- package/dist/daemon/worker-dep-proxy.d.ts.map +1 -0
- package/dist/daemon/worker-dep-proxy.js +92 -0
- package/dist/daemon/worker-dep-proxy.js.map +1 -0
- package/dist/daemon/worker-host.js +8 -28
- package/dist/daemon/worker-host.js.map +1 -1
- package/dist/deploy/cloudflare.d.ts.map +1 -1
- package/dist/deploy/cloudflare.js +15 -0
- package/dist/deploy/cloudflare.js.map +1 -1
- package/dist/resource-server.d.ts +15 -0
- package/dist/resource-server.d.ts.map +1 -1
- package/dist/resource-server.js +86 -5
- package/dist/resource-server.js.map +1 -1
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +20 -10
- package/dist/server.js.map +1 -1
- package/package.json +1 -1
- package/templates/cloudflare/worker.ts.template +26 -8
|
@@ -24,6 +24,7 @@ const MCP_AUTH_MODE = __MCP_AUTH_MODE__;
|
|
|
24
24
|
const MCP_JWT_ISSUER = __MCP_JWT_ISSUER__;
|
|
25
25
|
const MCP_JWT_AUDIENCE = __MCP_JWT_AUDIENCE__;
|
|
26
26
|
const MCP_JWT_JWKS = __MCP_JWT_JWKS__;
|
|
27
|
+
const DEPLOY_INSTANCE_ALIASES: Record<string, string> = __INSTANCE_ALIASES__;
|
|
27
28
|
|
|
28
29
|
/**
|
|
29
30
|
* Photon name → Worker env binding name. Generated at deploy time from the
|
|
@@ -1743,27 +1744,44 @@ const CF_ACCESS_ENABLED = __CF_ACCESS_ENABLED__;
|
|
|
1743
1744
|
* CF Access verifies the JWT at the edge before the request reaches this
|
|
1744
1745
|
* Worker, so we trust the claim without re-verifying the signature here.
|
|
1745
1746
|
*/
|
|
1746
|
-
function
|
|
1747
|
+
function canonicalizeInstance(instance: string, env: Env): string {
|
|
1748
|
+
const key = instance.trim().toLowerCase();
|
|
1749
|
+
const aliases: Record<string, string> = { ...DEPLOY_INSTANCE_ALIASES };
|
|
1750
|
+
const runtimeAliases = env.PHOTON_INSTANCE_ALIASES;
|
|
1751
|
+
if (typeof runtimeAliases === 'string' && runtimeAliases.trim()) {
|
|
1752
|
+
try {
|
|
1753
|
+
const parsed = JSON.parse(runtimeAliases) as Record<string, unknown>;
|
|
1754
|
+
for (const [from, to] of Object.entries(parsed)) {
|
|
1755
|
+
if (typeof to === 'string' && to.trim()) aliases[from.toLowerCase()] = to;
|
|
1756
|
+
}
|
|
1757
|
+
} catch (err) {
|
|
1758
|
+
console.warn('canonicalizeInstance: PHOTON_INSTANCE_ALIASES parse failed', err);
|
|
1759
|
+
}
|
|
1760
|
+
}
|
|
1761
|
+
return aliases[key] || instance;
|
|
1762
|
+
}
|
|
1763
|
+
|
|
1764
|
+
function extractInstance(request: Request, env: Env): string {
|
|
1765
|
+
let instance: string | null = null;
|
|
1747
1766
|
if (CF_ACCESS_ENABLED) {
|
|
1748
1767
|
const headerEmail = request.headers.get('Cf-Access-Authenticated-User-Email');
|
|
1749
|
-
if (headerEmail)
|
|
1768
|
+
if (headerEmail) instance = headerEmail;
|
|
1750
1769
|
const jwt = request.headers.get('Cf-Access-Jwt-Assertion');
|
|
1751
|
-
if (jwt) {
|
|
1770
|
+
if (!instance && jwt) {
|
|
1752
1771
|
try {
|
|
1753
1772
|
const part = jwt.split('.')[1];
|
|
1754
1773
|
const b64 = part.replace(/-/g, '+').replace(/_/g, '/');
|
|
1755
1774
|
const padded = b64 + '==='.slice((b64.length + 3) % 4);
|
|
1756
1775
|
const payload = JSON.parse(atob(padded));
|
|
1757
|
-
if (payload?.email)
|
|
1776
|
+
if (payload?.email) instance = payload.email as string;
|
|
1758
1777
|
} catch (err) {
|
|
1759
1778
|
console.warn('extractInstance: JWT parse failed', err);
|
|
1760
1779
|
}
|
|
1761
1780
|
}
|
|
1762
1781
|
}
|
|
1763
1782
|
const url = new URL(request.url);
|
|
1764
|
-
|
|
1765
|
-
|
|
1766
|
-
);
|
|
1783
|
+
instance ??= url.searchParams.get('instance') ?? request.headers.get('X-Photon-Instance') ?? 'default';
|
|
1784
|
+
return canonicalizeInstance(instance, env);
|
|
1767
1785
|
}
|
|
1768
1786
|
|
|
1769
1787
|
export default {
|
|
@@ -1778,7 +1796,7 @@ export default {
|
|
|
1778
1796
|
},
|
|
1779
1797
|
});
|
|
1780
1798
|
}
|
|
1781
|
-
const instance = extractInstance(request);
|
|
1799
|
+
const instance = extractInstance(request, env);
|
|
1782
1800
|
const id = env.__HOST_BINDING__.idFromName(instance);
|
|
1783
1801
|
return env.__HOST_BINDING__.get(id).fetch(request);
|
|
1784
1802
|
},
|