@portel/photon 1.33.0 → 1.33.1
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 +5 -1
- package/dist/auth/mcp-jwt.d.ts +59 -0
- package/dist/auth/mcp-jwt.d.ts.map +1 -0
- package/dist/auth/mcp-jwt.js +177 -0
- package/dist/auth/mcp-jwt.js.map +1 -0
- package/dist/auto-ui/beam.d.ts +1 -0
- package/dist/auto-ui/beam.d.ts.map +1 -1
- package/dist/auto-ui/beam.js +35 -1
- package/dist/auto-ui/beam.js.map +1 -1
- package/dist/auto-ui/playground-html.d.ts.map +1 -1
- package/dist/auto-ui/playground-html.js +28 -38
- package/dist/auto-ui/playground-html.js.map +1 -1
- package/dist/beam.bundle.js +6 -0
- package/dist/beam.bundle.js.map +2 -2
- package/dist/cli/commands/auth.d.ts +15 -0
- package/dist/cli/commands/auth.d.ts.map +1 -0
- package/dist/cli/commands/auth.js +105 -0
- package/dist/cli/commands/auth.js.map +1 -0
- package/dist/cli/commands/host.d.ts.map +1 -1
- package/dist/cli/commands/host.js +9 -0
- package/dist/cli/commands/host.js.map +1 -1
- package/dist/cli/commands/run.d.ts.map +1 -1
- package/dist/cli/commands/run.js +3 -0
- package/dist/cli/commands/run.js.map +1 -1
- package/dist/cli/index.d.ts.map +1 -1
- package/dist/cli/index.js +6 -0
- package/dist/cli/index.js.map +1 -1
- package/dist/deploy/cloudflare.d.ts +2 -0
- package/dist/deploy/cloudflare.d.ts.map +1 -1
- package/dist/deploy/cloudflare.js +120 -13
- package/dist/deploy/cloudflare.js.map +1 -1
- package/dist/editor-support/docblock-tag-catalog.d.ts.map +1 -1
- package/dist/editor-support/docblock-tag-catalog.js +6 -0
- package/dist/editor-support/docblock-tag-catalog.js.map +1 -1
- package/dist/loader.d.ts +3 -0
- package/dist/loader.d.ts.map +1 -1
- package/dist/loader.js +49 -0
- package/dist/loader.js.map +1 -1
- package/dist/photon-doc-extractor.d.ts +1 -0
- package/dist/photon-doc-extractor.d.ts.map +1 -1
- package/dist/photon-doc-extractor.js +13 -0
- package/dist/photon-doc-extractor.js.map +1 -1
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +150 -168
- package/dist/server.js.map +1 -1
- package/package.json +1 -1
- package/templates/cloudflare/worker.ts.template +314 -47
package/README.md
CHANGED
|
@@ -550,6 +550,8 @@ Uses Bun's compiler under the hood. The binary bundles the photon, its `@depende
|
|
|
550
550
|
| `@param ... {@format email}` | Param | Input validation and field type |
|
|
551
551
|
| `@param ... {@min N} {@max N}` | Param | Numeric range constraints |
|
|
552
552
|
| `@ui` | Class/Method | Link a custom HTML template |
|
|
553
|
+
| `@auth` | Class | Require or describe MCP authentication and populate `this.caller` |
|
|
554
|
+
| `@scope` | Method | Override the inferred OAuth scope for a protected MCP tool call |
|
|
553
555
|
| `@expose` | Method | Auto-bind to `POST /api/<kebab>` for SPA fetch (`public` skips the SameSite gate) |
|
|
554
556
|
| `@get /path` | Method | HTTP-only GET route; shown as a web app in Beam, not an MCP tool. Supports `:param` segments |
|
|
555
557
|
| `@post /path` | Method | HTTP-only POST route; shown as a web app in Beam, not an MCP tool. Supports `:param` segments |
|
|
@@ -574,6 +576,7 @@ Uses Bun's compiler under the hood. The binary bundles the photon, its `@depende
|
|
|
574
576
|
|---|---|
|
|
575
577
|
| [Getting Started](./docs/getting-started.md) | Install, build, and run your first photon in 5 minutes |
|
|
576
578
|
| [Core Concepts](./docs/concepts.md) | The 6 ideas behind Photon |
|
|
579
|
+
| [Tag Reference](./docs/reference/DOCBLOCK-TAGS.md) | Public reference for every docblock tag Photon understands |
|
|
577
580
|
| [Output Formats](./docs/formats.md) | Visual gallery of every `@format` type |
|
|
578
581
|
| [Intent Metadata](./docs/reference/INTENT-METADATA.md) | How comments, schemas, annotations, and formats map to native surfaces |
|
|
579
582
|
| [Settings](./docs/GUIDE.md#settings-user-configurable-knobs) | Declare runtime knobs with `protected settings` (the canonical config pattern) |
|
|
@@ -585,6 +588,7 @@ Uses Bun's compiler under the hood. The binary bundles the photon, its `@depende
|
|
|
585
588
|
|---|---|
|
|
586
589
|
| [Custom UI](./docs/guides/CUSTOM-UI.md) | Build rich interactive interfaces with the photon bridge API |
|
|
587
590
|
| [OAuth](./docs/guides/AUTH.md) | Built-in OAuth 2.0 with Google, GitHub, Microsoft |
|
|
591
|
+
| [MCP JWT Auth](./docs/guides/MCP-JWT-AUTH.md) | Secure deployed MCP tool calls with short-lived scoped JWTs |
|
|
588
592
|
| [MCP Client Registration](./docs/guides/mcp-client-registration.md) | Register MCP clients with Photon's AS via CIMD or DCR |
|
|
589
593
|
| [Observability](./docs/guides/observability.md) | OpenTelemetry traces, metrics, logs, and structured errors |
|
|
590
594
|
| [Protocol Features](./docs/guides/PROTOCOL-FEATURES.md) | Capability handshake, structured errors, trace correlation |
|
|
@@ -603,7 +607,7 @@ Uses Bun's compiler under the hood. The binary bundles the photon, its `@depende
|
|
|
603
607
|
| [Marketplace Publishing](./docs/guides/MARKETPLACE-PUBLISHING.md) | Create and share team marketplaces |
|
|
604
608
|
| [Best Practices](./docs/guides/BEST-PRACTICES.md) | Patterns for production photons |
|
|
605
609
|
|
|
606
|
-
**Reference:** [Complete Developer Guide](./docs/GUIDE.md) · [Tag Reference](./docs/reference/DOCBLOCK-TAGS.md) · [Naming Conventions](./docs/guides/NAMING-CONVENTIONS.md) · [Architecture](./docs/internals/ARCHITECTURE.md) · [
|
|
610
|
+
**Reference:** [Complete Developer Guide](./docs/GUIDE.md) · [Tag Reference](./docs/reference/DOCBLOCK-TAGS.md) · [Naming Conventions](./docs/guides/NAMING-CONVENTIONS.md) · [Architecture](./docs/internals/ARCHITECTURE.md) · [Lifecycle & Ingress](./docs/internals/LIFECYCLE-AND-INGRESS.md) · [PHOTON_DIR & Namespace](./docs/internals/PHOTON-DIR-AND-NAMESPACE.md) · [Changelog](./CHANGELOG.md) · [Contributing](./CONTRIBUTING.md)
|
|
607
611
|
|
|
608
612
|
---
|
|
609
613
|
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { type JsonWebKey } from 'node:crypto';
|
|
2
|
+
export interface PhotonAuthIssuer {
|
|
3
|
+
issuer: string;
|
|
4
|
+
algorithm: 'ES256';
|
|
5
|
+
kid: string;
|
|
6
|
+
defaultTtlSeconds: number;
|
|
7
|
+
}
|
|
8
|
+
export interface PhotonAuthTokenOptions {
|
|
9
|
+
agent: string;
|
|
10
|
+
audience: string;
|
|
11
|
+
tenant?: string;
|
|
12
|
+
scopes?: string[];
|
|
13
|
+
ttlSeconds?: number;
|
|
14
|
+
now?: Date;
|
|
15
|
+
jti?: string;
|
|
16
|
+
}
|
|
17
|
+
export interface PhotonAuthVerifyOptions {
|
|
18
|
+
issuer: string;
|
|
19
|
+
audience: string;
|
|
20
|
+
jwks: {
|
|
21
|
+
keys: JsonWebKey[];
|
|
22
|
+
};
|
|
23
|
+
now?: Date;
|
|
24
|
+
clockSkewSeconds?: number;
|
|
25
|
+
requiredScopes?: string[];
|
|
26
|
+
}
|
|
27
|
+
export type PhotonJwtVerifyReason = 'missing_token' | 'malformed_token' | 'unsupported_alg' | 'unknown_kid' | 'bad_signature' | 'expired_token' | 'token_not_yet_valid' | 'wrong_issuer' | 'wrong_audience' | 'insufficient_scope' | 'tenant_mismatch';
|
|
28
|
+
export interface PhotonJwtClaims {
|
|
29
|
+
iss: string;
|
|
30
|
+
sub: string;
|
|
31
|
+
aud: string | string[];
|
|
32
|
+
tenant_id: string;
|
|
33
|
+
client_id: string;
|
|
34
|
+
scope?: string;
|
|
35
|
+
iat: number;
|
|
36
|
+
nbf: number;
|
|
37
|
+
exp: number;
|
|
38
|
+
jti: string;
|
|
39
|
+
[key: string]: unknown;
|
|
40
|
+
}
|
|
41
|
+
export type PhotonJwtVerifyResult = {
|
|
42
|
+
ok: true;
|
|
43
|
+
claims: PhotonJwtClaims;
|
|
44
|
+
} | {
|
|
45
|
+
ok: false;
|
|
46
|
+
reason: PhotonJwtVerifyReason;
|
|
47
|
+
};
|
|
48
|
+
export declare function createPhotonAuthKeypair(name: string, now?: Date): {
|
|
49
|
+
issuer: PhotonAuthIssuer;
|
|
50
|
+
privateJwk: JsonWebKey;
|
|
51
|
+
publicJwk: JsonWebKey;
|
|
52
|
+
jwks: {
|
|
53
|
+
keys: JsonWebKey[];
|
|
54
|
+
};
|
|
55
|
+
};
|
|
56
|
+
export declare function signPhotonAuthToken(issuer: PhotonAuthIssuer, privateJwk: JsonWebKey, options: PhotonAuthTokenOptions): string;
|
|
57
|
+
export declare function verifyPhotonAuthToken(token: string | null | undefined, options: PhotonAuthVerifyOptions): PhotonJwtVerifyResult;
|
|
58
|
+
export declare function normalizeScopes(scopes: string[]): string[];
|
|
59
|
+
//# sourceMappingURL=mcp-jwt.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mcp-jwt.d.ts","sourceRoot":"","sources":["../../src/auth/mcp-jwt.ts"],"names":[],"mappings":"AAAA,OAAO,EAOL,KAAK,UAAU,EAChB,MAAM,aAAa,CAAC;AAErB,MAAM,WAAW,gBAAgB;IAC/B,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,OAAO,CAAC;IACnB,GAAG,EAAE,MAAM,CAAC;IACZ,iBAAiB,EAAE,MAAM,CAAC;CAC3B;AAED,MAAM,WAAW,sBAAsB;IACrC,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;IAClB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,GAAG,CAAC,EAAE,IAAI,CAAC;IACX,GAAG,CAAC,EAAE,MAAM,CAAC;CACd;AAED,MAAM,WAAW,uBAAuB;IACtC,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE;QAAE,IAAI,EAAE,UAAU,EAAE,CAAA;KAAE,CAAC;IAC7B,G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BR;AAED,wBAAgB,qBAAqB,CACnC,KAAK,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,EAChC,OAAO,EAAE,uBAAuB,GAC/B,qBAAqB,CA4CvB;AAED,wBAAgB,eAAe,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,MAAM,EAAE,CAY1D"}
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
import { createPrivateKey, createPublicKey, createSign, createVerify, generateKeyPairSync, randomBytes, } from 'node:crypto';
|
|
2
|
+
export function createPhotonAuthKeypair(name, now = new Date()) {
|
|
3
|
+
const date = now.toISOString().slice(0, 10);
|
|
4
|
+
const kid = `${name}-${date}`;
|
|
5
|
+
const { privateKey, publicKey } = generateKeyPairSync('ec', { namedCurve: 'P-256' });
|
|
6
|
+
const privateJwk = privateKey.export({ format: 'jwk' });
|
|
7
|
+
const publicJwk = publicKey.export({ format: 'jwk' });
|
|
8
|
+
for (const jwk of [privateJwk, publicJwk]) {
|
|
9
|
+
jwk.alg = 'ES256';
|
|
10
|
+
jwk.kid = kid;
|
|
11
|
+
jwk.use = 'sig';
|
|
12
|
+
}
|
|
13
|
+
return {
|
|
14
|
+
issuer: {
|
|
15
|
+
issuer: `photon-local:${name}`,
|
|
16
|
+
algorithm: 'ES256',
|
|
17
|
+
kid,
|
|
18
|
+
defaultTtlSeconds: 15 * 60,
|
|
19
|
+
},
|
|
20
|
+
privateJwk,
|
|
21
|
+
publicJwk,
|
|
22
|
+
jwks: { keys: [publicJwk] },
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
export function signPhotonAuthToken(issuer, privateJwk, options) {
|
|
26
|
+
const nowSec = Math.floor((options.now?.getTime() ?? Date.now()) / 1000);
|
|
27
|
+
const ttl = options.ttlSeconds ?? issuer.defaultTtlSeconds;
|
|
28
|
+
const scopes = normalizeScopes(options.scopes ?? []);
|
|
29
|
+
const payload = {
|
|
30
|
+
iss: issuer.issuer,
|
|
31
|
+
sub: `agent:${options.agent}`,
|
|
32
|
+
aud: options.audience,
|
|
33
|
+
tenant_id: options.tenant ?? 'default',
|
|
34
|
+
client_id: options.agent,
|
|
35
|
+
...(scopes.length > 0 ? { scope: scopes.join(' ') } : {}),
|
|
36
|
+
iat: nowSec,
|
|
37
|
+
nbf: nowSec,
|
|
38
|
+
exp: nowSec + ttl,
|
|
39
|
+
jti: options.jti ?? `tok_${randomBytes(16).toString('base64url')}`,
|
|
40
|
+
};
|
|
41
|
+
return signJwt(payload, privateJwk, issuer.kid);
|
|
42
|
+
}
|
|
43
|
+
export function verifyPhotonAuthToken(token, options) {
|
|
44
|
+
if (!token)
|
|
45
|
+
return { ok: false, reason: 'missing_token' };
|
|
46
|
+
const parts = token.split('.');
|
|
47
|
+
if (parts.length !== 3)
|
|
48
|
+
return { ok: false, reason: 'malformed_token' };
|
|
49
|
+
let header;
|
|
50
|
+
let claims;
|
|
51
|
+
try {
|
|
52
|
+
header = JSON.parse(base64UrlDecode(parts[0]));
|
|
53
|
+
claims = JSON.parse(base64UrlDecode(parts[1]));
|
|
54
|
+
}
|
|
55
|
+
catch {
|
|
56
|
+
return { ok: false, reason: 'malformed_token' };
|
|
57
|
+
}
|
|
58
|
+
if (header.alg !== 'ES256')
|
|
59
|
+
return { ok: false, reason: 'unsupported_alg' };
|
|
60
|
+
const kid = typeof header.kid === 'string' ? header.kid : '';
|
|
61
|
+
const jwk = options.jwks.keys.find((key) => key.kid === kid);
|
|
62
|
+
if (!kid || !jwk)
|
|
63
|
+
return { ok: false, reason: 'unknown_kid' };
|
|
64
|
+
if (!verifyJwtSignature(parts, jwk))
|
|
65
|
+
return { ok: false, reason: 'bad_signature' };
|
|
66
|
+
if (claims.iss !== options.issuer)
|
|
67
|
+
return { ok: false, reason: 'wrong_issuer' };
|
|
68
|
+
const audMatches = Array.isArray(claims.aud)
|
|
69
|
+
? claims.aud.includes(options.audience)
|
|
70
|
+
: claims.aud === options.audience;
|
|
71
|
+
if (!audMatches)
|
|
72
|
+
return { ok: false, reason: 'wrong_audience' };
|
|
73
|
+
const now = Math.floor((options.now?.getTime() ?? Date.now()) / 1000);
|
|
74
|
+
const skew = options.clockSkewSeconds ?? 60;
|
|
75
|
+
if (typeof claims.exp !== 'number' || claims.exp < now - skew) {
|
|
76
|
+
return { ok: false, reason: 'expired_token' };
|
|
77
|
+
}
|
|
78
|
+
if (typeof claims.nbf === 'number' && claims.nbf > now + skew) {
|
|
79
|
+
return { ok: false, reason: 'token_not_yet_valid' };
|
|
80
|
+
}
|
|
81
|
+
if (typeof claims.iat === 'number' && claims.iat > now + skew) {
|
|
82
|
+
return { ok: false, reason: 'token_not_yet_valid' };
|
|
83
|
+
}
|
|
84
|
+
const required = normalizeScopes(options.requiredScopes ?? []);
|
|
85
|
+
if (required.length > 0) {
|
|
86
|
+
const granted = new Set(normalizeScopes((claims.scope ?? '').split(/\s+/)));
|
|
87
|
+
for (const scope of required) {
|
|
88
|
+
if (!granted.has(scope))
|
|
89
|
+
return { ok: false, reason: 'insufficient_scope' };
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
return { ok: true, claims };
|
|
93
|
+
}
|
|
94
|
+
export function normalizeScopes(scopes) {
|
|
95
|
+
const out = [];
|
|
96
|
+
const seen = new Set();
|
|
97
|
+
for (const raw of scopes) {
|
|
98
|
+
for (const scope of raw.split(/\s+/)) {
|
|
99
|
+
const trimmed = scope.trim();
|
|
100
|
+
if (!trimmed || seen.has(trimmed))
|
|
101
|
+
continue;
|
|
102
|
+
seen.add(trimmed);
|
|
103
|
+
out.push(trimmed);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
return out;
|
|
107
|
+
}
|
|
108
|
+
function signJwt(payload, privateJwk, kid) {
|
|
109
|
+
const header = { alg: 'ES256', typ: 'JWT', kid };
|
|
110
|
+
const input = `${base64UrlEncode(JSON.stringify(header))}.${base64UrlEncode(JSON.stringify(payload))}`;
|
|
111
|
+
const key = createPrivateKey({ key: privateJwk, format: 'jwk' });
|
|
112
|
+
const signer = createSign('sha256');
|
|
113
|
+
signer.update(input);
|
|
114
|
+
signer.end();
|
|
115
|
+
const der = signer.sign(key);
|
|
116
|
+
return `${input}.${derToP1363(der, 32).toString('base64url')}`;
|
|
117
|
+
}
|
|
118
|
+
function verifyJwtSignature(parts, publicJwk) {
|
|
119
|
+
try {
|
|
120
|
+
const key = createPublicKey({ key: publicJwk, format: 'jwk' });
|
|
121
|
+
const verifier = createVerify('sha256');
|
|
122
|
+
verifier.update(`${parts[0]}.${parts[1]}`);
|
|
123
|
+
verifier.end();
|
|
124
|
+
return verifier.verify(key, p1363ToDer(Buffer.from(parts[2], 'base64url')));
|
|
125
|
+
}
|
|
126
|
+
catch {
|
|
127
|
+
return false;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
function base64UrlEncode(str) {
|
|
131
|
+
return Buffer.from(str, 'utf-8').toString('base64url');
|
|
132
|
+
}
|
|
133
|
+
function base64UrlDecode(str) {
|
|
134
|
+
return Buffer.from(str, 'base64url').toString('utf-8');
|
|
135
|
+
}
|
|
136
|
+
function derToP1363(der, componentLen) {
|
|
137
|
+
if (der[0] !== 0x30)
|
|
138
|
+
throw new Error('invalid DER signature');
|
|
139
|
+
let offset = 2;
|
|
140
|
+
if ((der[1] & 0x80) !== 0)
|
|
141
|
+
offset += der[1] & 0x7f;
|
|
142
|
+
const readInt = () => {
|
|
143
|
+
if (der[offset] !== 0x02)
|
|
144
|
+
throw new Error('invalid DER signature');
|
|
145
|
+
const len = der[offset + 1];
|
|
146
|
+
const start = offset + 2;
|
|
147
|
+
let value = der.subarray(start, start + len);
|
|
148
|
+
offset = start + len;
|
|
149
|
+
while (value.length > 1 && value[0] === 0x00)
|
|
150
|
+
value = value.subarray(1);
|
|
151
|
+
if (value.length > componentLen)
|
|
152
|
+
throw new Error('ECDSA component overflow');
|
|
153
|
+
return value;
|
|
154
|
+
};
|
|
155
|
+
const r = readInt();
|
|
156
|
+
const s = readInt();
|
|
157
|
+
const out = Buffer.alloc(componentLen * 2);
|
|
158
|
+
r.copy(out, componentLen - r.length);
|
|
159
|
+
s.copy(out, componentLen * 2 - s.length);
|
|
160
|
+
return out;
|
|
161
|
+
}
|
|
162
|
+
function p1363ToDer(p1363) {
|
|
163
|
+
if (p1363.length % 2 !== 0)
|
|
164
|
+
throw new Error('invalid P1363 signature');
|
|
165
|
+
const half = p1363.length / 2;
|
|
166
|
+
const encodeInt = (value) => {
|
|
167
|
+
let v = value;
|
|
168
|
+
while (v.length > 1 && v[0] === 0x00)
|
|
169
|
+
v = v.subarray(1);
|
|
170
|
+
if ((v[0] & 0x80) !== 0)
|
|
171
|
+
v = Buffer.concat([Buffer.from([0x00]), v]);
|
|
172
|
+
return Buffer.concat([Buffer.from([0x02, v.length]), v]);
|
|
173
|
+
};
|
|
174
|
+
const body = Buffer.concat([encodeInt(p1363.subarray(0, half)), encodeInt(p1363.subarray(half))]);
|
|
175
|
+
return Buffer.concat([Buffer.from([0x30, body.length]), body]);
|
|
176
|
+
}
|
|
177
|
+
//# sourceMappingURL=mcp-jwt.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mcp-jwt.js","sourceRoot":"","sources":["../../src/auth/mcp-jwt.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,gBAAgB,EAChB,eAAe,EACf,UAAU,EACV,YAAY,EACZ,mBAAmB,EACnB,WAAW,GAEZ,MAAM,aAAa,CAAC;AA2DrB,MAAM,UAAU,uBAAuB,CACrC,IAAY,EACZ,GAAG,GAAG,IAAI,IAAI,EAAE;IAOhB,MAAM,IAAI,GAAG,GAAG,CAAC,WAAW,EAAE,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;IAC5C,MAAM,GAAG,GAAG,GAAG,IAAI,IAAI,IAAI,EAAE,CAAC;IAC9B,MAAM,EAAE,UAAU,EAAE,SAAS,EAAE,GAAG,mBAAmB,CAAC,IAAI,EAAE,EAAE,UAAU,EAAE,OAAO,EAAE,CAAC,CAAC;IACrF,MAAM,UAAU,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AC,CAAC,MAAM,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,KAAK,IAAI;YAAE,CAAC,GAAG,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC;QACxD,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC;YAAE,CAAC,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;QACrE,OAAO,MAAM,CAAC,MAAM,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;IAC3D,CAAC,CAAC;IACF,MAAM,IAAI,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC,SAAS,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC,EAAE,SAAS,CAAC,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;IAClG,OAAO,MAAM,CAAC,MAAM,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC,CAAC;AACjE,CAAC"}
|
package/dist/auto-ui/beam.d.ts
CHANGED
|
@@ -16,6 +16,7 @@ export declare function shouldServeLinkedAppForWebPath(pathname: string, searchP
|
|
|
16
16
|
export declare function selectClientAppUi(photonInfo: PhotonInfo | undefined): string | undefined;
|
|
17
17
|
export declare function shouldFallbackToClientAppForWebPath(pathname: string, searchParams: URLSearchParams, route: BeamWebRouteDef | undefined): boolean;
|
|
18
18
|
export declare function findBeamWebRoute(routes: BeamWebRouteDef[] | undefined, method: string, requestPath: string): BeamWebRouteDef | undefined;
|
|
19
|
+
export declare function rewriteBeamWebRedirectLocation(location: string | null, prefix: string, requestOrigin: string): string | null;
|
|
19
20
|
import type { PhotonInfo } from './types.js';
|
|
20
21
|
export type { PhotonConfig } from './beam/types.js';
|
|
21
22
|
export type { BeamState } from './beam/types.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"beam.d.ts","sourceRoot":"","sources":["../../src/auto-ui/beam.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAgEH,MAAM,WAAW,eAAe;IAC9B,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAQD,wBAAgB,mBAAmB,CAAC,SAAS,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,GAAG,OAAO,CAenF;AAYD,wBAAgB,8BAA8B,CAC5C,QAAQ,EAAE,MAAM,EAChB,YAAY,EAAE,eAAe,GAC5B,OAAO,CAIT;AAUD,wBAAgB,iBAAiB,CAAC,UAAU,EAAE,UAAU,GAAG,SAAS,GAAG,MAAM,GAAG,SAAS,CAmBxF;AAED,wBAAgB,mCAAmC,CACjD,QAAQ,EAAE,MAAM,EAChB,YAAY,EAAE,eAAe,EAC7B,KAAK,EAAE,eAAe,GAAG,SAAS,GACjC,OAAO,CAIT;AAED,wBAAgB,gBAAgB,CAC9B,MAAM,EAAE,eAAe,EAAE,GAAG,SAAS,EACrC,MAAM,EAAE,MAAM,EACd,WAAW,EAAE,MAAM,GAClB,eAAe,GAAG,SAAS,CAO7B;
|
|
1
|
+
{"version":3,"file":"beam.d.ts","sourceRoot":"","sources":["../../src/auto-ui/beam.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAgEH,MAAM,WAAW,eAAe;IAC9B,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAQD,wBAAgB,mBAAmB,CAAC,SAAS,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,GAAG,OAAO,CAenF;AAYD,wBAAgB,8BAA8B,CAC5C,QAAQ,EAAE,MAAM,EAChB,YAAY,EAAE,eAAe,GAC5B,OAAO,CAIT;AAUD,wBAAgB,iBAAiB,CAAC,UAAU,EAAE,UAAU,GAAG,SAAS,GAAG,MAAM,GAAG,SAAS,CAmBxF;AAED,wBAAgB,mCAAmC,CACjD,QAAQ,EAAE,MAAM,EAChB,YAAY,EAAE,eAAe,EAC7B,KAAK,EAAE,eAAe,GAAG,SAAS,GACjC,OAAO,CAIT;AAED,wBAAgB,gBAAgB,CAC9B,MAAM,EAAE,eAAe,EAAE,GAAG,SAAS,EACrC,MAAM,EAAE,MAAM,EACd,WAAW,EAAE,MAAM,GAClB,eAAe,GAAG,SAAS,CAO7B;AAwCD,wBAAgB,8BAA8B,CAC5C,QAAQ,EAAE,MAAM,GAAG,IAAI,EACvB,MAAM,EAAE,MAAM,EACd,aAAa,EAAE,MAAM,GACpB,MAAM,GAAG,IAAI,CAaf;AAsED,OAAO,KAAK,EACV,UAAU,EAKX,MAAM,YAAY,CAAC;AAsCpB,YAAY,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AACpD,YAAY,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAqYjD,wBAAsB,SAAS,CAAC,aAAa,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAi7FlF;AAED;;;GAGG;AACH,wBAAsB,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC,CAM9C"}
|
package/dist/auto-ui/beam.js
CHANGED
|
@@ -165,6 +165,22 @@ async function writeFetchResponseToNode(response, res) {
|
|
|
165
165
|
res.off('close', cancelReader);
|
|
166
166
|
}
|
|
167
167
|
}
|
|
168
|
+
export function rewriteBeamWebRedirectLocation(location, prefix, requestOrigin) {
|
|
169
|
+
if (!location)
|
|
170
|
+
return null;
|
|
171
|
+
try {
|
|
172
|
+
const target = new URL(location, requestOrigin);
|
|
173
|
+
if (target.origin !== requestOrigin)
|
|
174
|
+
return location;
|
|
175
|
+
if (target.pathname === prefix || target.pathname.startsWith(`${prefix}/`)) {
|
|
176
|
+
return target.pathname + target.search + target.hash;
|
|
177
|
+
}
|
|
178
|
+
return `${prefix}${target.pathname}${target.search}${target.hash}`;
|
|
179
|
+
}
|
|
180
|
+
catch {
|
|
181
|
+
return location;
|
|
182
|
+
}
|
|
183
|
+
}
|
|
168
184
|
/**
|
|
169
185
|
* Resolve raw icon image paths to MCP Icon[] format (data URIs)
|
|
170
186
|
*/
|
|
@@ -2125,6 +2141,25 @@ export async function startBeam(rawWorkingDir, port) {
|
|
|
2125
2141
|
});
|
|
2126
2142
|
const result = await fn.call(photonClass.instance, webReq);
|
|
2127
2143
|
if (result instanceof Response) {
|
|
2144
|
+
const prefix = `/web/${photonName}`;
|
|
2145
|
+
if (result.status >= 300 && result.status < 400) {
|
|
2146
|
+
const responseHeaders = {};
|
|
2147
|
+
result.headers.forEach((value, key) => {
|
|
2148
|
+
if (key.toLowerCase() !== 'location')
|
|
2149
|
+
responseHeaders[key] = value;
|
|
2150
|
+
});
|
|
2151
|
+
const location = rewriteBeamWebRedirectLocation(result.headers.get('location'), prefix, internalUrl.origin);
|
|
2152
|
+
if (location) {
|
|
2153
|
+
responseHeaders.location = location;
|
|
2154
|
+
}
|
|
2155
|
+
const body = Buffer.from(await result.arrayBuffer());
|
|
2156
|
+
if (body.length > 0) {
|
|
2157
|
+
responseHeaders['content-length'] = String(body.length);
|
|
2158
|
+
}
|
|
2159
|
+
res.writeHead(result.status, responseHeaders);
|
|
2160
|
+
res.end(body.length > 0 ? body : undefined);
|
|
2161
|
+
return;
|
|
2162
|
+
}
|
|
2128
2163
|
const contentType = result.headers.get('content-type') || '';
|
|
2129
2164
|
if (!contentType.includes('text/html')) {
|
|
2130
2165
|
await writeFetchResponseToNode(result, res);
|
|
@@ -2137,7 +2172,6 @@ export async function startBeam(rawWorkingDir, port) {
|
|
|
2137
2172
|
responseHeaders[key] = value;
|
|
2138
2173
|
});
|
|
2139
2174
|
let body = Buffer.from(await result.arrayBuffer());
|
|
2140
|
-
const prefix = `/web/${photonName}`;
|
|
2141
2175
|
const interceptor = `<script>
|
|
2142
2176
|
(function(){
|
|
2143
2177
|
const _prefix="${prefix}";
|