@air-jam/sdk 0.9.0 → 0.9.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/dist/arcade/bridge/controller.cjs +1 -1
- package/dist/arcade/bridge/controller.js +2 -2
- package/dist/arcade/bridge/host.cjs +1 -1
- package/dist/arcade/bridge/host.js +2 -2
- package/dist/arcade/bridge/iframe.cjs +1 -1
- package/dist/arcade/bridge/iframe.js +5 -5
- package/dist/arcade/bridge.cjs +1 -1
- package/dist/arcade/bridge.js +8 -8
- package/dist/arcade/host.cjs +0 -7
- package/dist/arcade/host.cjs.map +1 -1
- package/dist/arcade/host.js +4 -3
- package/dist/arcade/url.cjs +183 -2
- package/dist/arcade/url.cjs.map +1 -1
- package/dist/arcade/url.d.cts +1 -1
- package/dist/arcade/url.d.ts +1 -1
- package/dist/arcade/url.js +5 -4
- package/dist/arcade.cjs +184 -12
- package/dist/arcade.cjs.map +1 -1
- package/dist/arcade.d.cts +1 -1
- package/dist/arcade.d.ts +1 -1
- package/dist/arcade.js +22 -21
- package/dist/{chunk-VN5LDWVN.js → chunk-7UXSWCZZ.js} +2 -2
- package/dist/{chunk-VDRNNGHX.js → chunk-CABEUV65.js} +9 -9
- package/dist/{chunk-VDRNNGHX.js.map → chunk-CABEUV65.js.map} +1 -1
- package/dist/{chunk-D3X4MN4U.js → chunk-CEJ5RFSG.js} +2 -2
- package/dist/{chunk-XLUWV45V.js → chunk-EDRQIOCV.js} +2 -2
- package/dist/{chunk-Y4RAPKKB.js → chunk-FAT2KJ3K.js} +2 -2
- package/dist/{chunk-CQUG24WX.js → chunk-JEHV5C2X.js} +2 -2
- package/dist/{chunk-2J65FXEP.js → chunk-JO2HR5PV.js} +6 -4
- package/dist/chunk-JO2HR5PV.js.map +1 -0
- package/dist/{chunk-2432OL7L.js → chunk-KXAFI5OP.js} +2 -2
- package/dist/{chunk-HFWRZVZ3.js → chunk-NUJBMV3O.js} +13 -16
- package/dist/chunk-NUJBMV3O.js.map +1 -0
- package/dist/chunk-UWJOIVON.js +369 -0
- package/dist/chunk-UWJOIVON.js.map +1 -0
- package/dist/{chunk-MKBASO6X.js → chunk-VKBMZHMQ.js} +2 -2
- package/dist/{chunk-NU5W6VAV.js → chunk-W3YA5BWR.js} +3 -3
- package/dist/index.cjs +344 -24
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +22 -20
- package/dist/index.js.map +1 -1
- package/dist/preview.cjs +22 -11
- package/dist/preview.cjs.map +1 -1
- package/dist/preview.d.cts +1 -1
- package/dist/preview.d.ts +1 -1
- package/dist/preview.js +12 -12
- package/dist/preview.js.map +1 -1
- package/dist/runtime-topology.cjs +405 -0
- package/dist/runtime-topology.cjs.map +1 -0
- package/dist/runtime-topology.d.cts +59 -0
- package/dist/runtime-topology.d.ts +59 -0
- package/dist/runtime-topology.js +31 -0
- package/dist/runtime-topology.js.map +1 -0
- package/dist/ui.cjs +246 -12
- package/dist/ui.cjs.map +1 -1
- package/dist/ui.js +9 -8
- package/dist/ui.js.map +1 -1
- package/package.json +10 -3
- package/src/arcade/url.ts +2 -2
- package/src/context/air-jam-context.tsx +2 -2
- package/src/dev/browser-log-sink.ts +1 -1
- package/src/preview/ownership.ts +1 -1
- package/src/runtime/air-jam-config.ts +1 -1
- package/src/runtime/create-air-jam-app.tsx +2 -2
- package/src/runtime/embedded-runtime-adapters.ts +1 -1
- package/src/runtime/runtime-session-params.ts +2 -2
- package/src/runtime-topology.ts +569 -0
- package/dist/chunk-2J65FXEP.js.map +0 -1
- package/dist/chunk-HFWRZVZ3.js.map +0 -1
- /package/dist/{chunk-VN5LDWVN.js.map → chunk-7UXSWCZZ.js.map} +0 -0
- /package/dist/{chunk-D3X4MN4U.js.map → chunk-CEJ5RFSG.js.map} +0 -0
- /package/dist/{chunk-XLUWV45V.js.map → chunk-EDRQIOCV.js.map} +0 -0
- /package/dist/{chunk-Y4RAPKKB.js.map → chunk-FAT2KJ3K.js.map} +0 -0
- /package/dist/{chunk-CQUG24WX.js.map → chunk-JEHV5C2X.js.map} +0 -0
- /package/dist/{chunk-2432OL7L.js.map → chunk-KXAFI5OP.js.map} +0 -0
- /package/dist/{chunk-MKBASO6X.js.map → chunk-VKBMZHMQ.js.map} +0 -0
- /package/dist/{chunk-NU5W6VAV.js.map → chunk-W3YA5BWR.js.map} +0 -0
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { ResolvedAirJamRuntimeTopology } from "
|
|
2
|
-
import { resolveProjectRuntimeTopology } from "
|
|
1
|
+
import type { ResolvedAirJamRuntimeTopology } from "../runtime-topology";
|
|
2
|
+
import { resolveProjectRuntimeTopology } from "../runtime-topology";
|
|
3
3
|
import type { JSX, ReactNode } from "react";
|
|
4
4
|
import type { z } from "zod";
|
|
5
5
|
import type { AirJamAgentContract } from "../agent/agent-contract";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ResolvedAirJamRuntimeTopology } from "
|
|
1
|
+
import type { ResolvedAirJamRuntimeTopology } from "../runtime-topology";
|
|
2
2
|
import type { RoomCode } from "../protocol";
|
|
3
3
|
import { roomCodeSchema } from "../protocol";
|
|
4
4
|
import type { ArcadeSurfaceRuntimeIdentity } from "./arcade-surface-identity";
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import type { ResolvedAirJamRuntimeTopology } from "
|
|
1
|
+
import type { ResolvedAirJamRuntimeTopology } from "../runtime-topology";
|
|
2
2
|
import {
|
|
3
3
|
parseRuntimeTopologyFromSearchParams,
|
|
4
4
|
resolveRuntimeTopology,
|
|
5
|
-
} from "
|
|
5
|
+
} from "../runtime-topology";
|
|
6
6
|
import type { PlayerProfile } from "../protocol";
|
|
7
7
|
import { normalizeRuntimeUrl } from "../protocol/url-policy";
|
|
8
8
|
import { parseOptionalArcadeSurfaceFromSearchParams } from "./arcade-runtime-url";
|
|
@@ -0,0 +1,569 @@
|
|
|
1
|
+
export type RuntimeMode =
|
|
2
|
+
| "standalone-dev"
|
|
3
|
+
| "standalone-secure"
|
|
4
|
+
| "arcade-live"
|
|
5
|
+
| "arcade-built"
|
|
6
|
+
| "self-hosted-production"
|
|
7
|
+
| "hosted-release";
|
|
8
|
+
|
|
9
|
+
export type SurfaceRole =
|
|
10
|
+
| "host"
|
|
11
|
+
| "controller"
|
|
12
|
+
| "platform-host"
|
|
13
|
+
| "platform-controller";
|
|
14
|
+
|
|
15
|
+
export type ProxyStrategy = "none" | "platform-proxy" | "dev-proxy";
|
|
16
|
+
|
|
17
|
+
export interface RuntimeTopologyInput {
|
|
18
|
+
runtimeMode: RuntimeMode;
|
|
19
|
+
surfaceRole: SurfaceRole;
|
|
20
|
+
appOrigin: string;
|
|
21
|
+
backendOrigin: string;
|
|
22
|
+
socketOrigin?: string;
|
|
23
|
+
publicHost?: string;
|
|
24
|
+
assetBasePath?: string;
|
|
25
|
+
secureTransport?: boolean;
|
|
26
|
+
embedded?: boolean;
|
|
27
|
+
embedParentOrigin?: string;
|
|
28
|
+
proxyStrategy?: ProxyStrategy;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export interface ProjectRuntimeTopologyInput {
|
|
32
|
+
runtimeMode?:
|
|
33
|
+
| "standalone-dev"
|
|
34
|
+
| "standalone-secure"
|
|
35
|
+
| "self-hosted-production"
|
|
36
|
+
| "hosted-release";
|
|
37
|
+
surfaceRole: Extract<SurfaceRole, "host" | "controller">;
|
|
38
|
+
appOrigin: string;
|
|
39
|
+
backendOrigin?: string;
|
|
40
|
+
socketOrigin?: string;
|
|
41
|
+
publicHost?: string;
|
|
42
|
+
assetBasePath?: string;
|
|
43
|
+
secureTransport?: boolean;
|
|
44
|
+
embedded?: boolean;
|
|
45
|
+
embedParentOrigin?: string;
|
|
46
|
+
proxyStrategy?: Extract<ProxyStrategy, "none" | "dev-proxy">;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export interface ResolvedAirJamRuntimeTopology {
|
|
50
|
+
runtimeMode: RuntimeMode;
|
|
51
|
+
surfaceRole: SurfaceRole;
|
|
52
|
+
appOrigin: string;
|
|
53
|
+
backendOrigin: string;
|
|
54
|
+
socketOrigin: string;
|
|
55
|
+
publicHost: string;
|
|
56
|
+
assetBasePath: string;
|
|
57
|
+
secureTransport: boolean;
|
|
58
|
+
embedded: boolean;
|
|
59
|
+
embedParentOrigin?: string;
|
|
60
|
+
proxyStrategy: ProxyStrategy;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const RUNTIME_MODES = new Set<RuntimeMode>([
|
|
64
|
+
"standalone-dev",
|
|
65
|
+
"standalone-secure",
|
|
66
|
+
"arcade-live",
|
|
67
|
+
"arcade-built",
|
|
68
|
+
"self-hosted-production",
|
|
69
|
+
"hosted-release",
|
|
70
|
+
]);
|
|
71
|
+
|
|
72
|
+
const SURFACE_ROLES = new Set<SurfaceRole>([
|
|
73
|
+
"host",
|
|
74
|
+
"controller",
|
|
75
|
+
"platform-host",
|
|
76
|
+
"platform-controller",
|
|
77
|
+
]);
|
|
78
|
+
|
|
79
|
+
const PROXY_STRATEGIES = new Set<ProxyStrategy>([
|
|
80
|
+
"none",
|
|
81
|
+
"platform-proxy",
|
|
82
|
+
"dev-proxy",
|
|
83
|
+
]);
|
|
84
|
+
|
|
85
|
+
const PROJECT_RUNTIME_MODES = new Set<
|
|
86
|
+
NonNullable<ProjectRuntimeTopologyInput["runtimeMode"]>
|
|
87
|
+
>([
|
|
88
|
+
"standalone-dev",
|
|
89
|
+
"standalone-secure",
|
|
90
|
+
"self-hosted-production",
|
|
91
|
+
"hosted-release",
|
|
92
|
+
]);
|
|
93
|
+
|
|
94
|
+
const LOCAL_DEV_CONTROL_SURFACE_RUNTIME_MODES = new Set<RuntimeMode>([
|
|
95
|
+
"standalone-dev",
|
|
96
|
+
"standalone-secure",
|
|
97
|
+
"arcade-live",
|
|
98
|
+
"arcade-built",
|
|
99
|
+
]);
|
|
100
|
+
|
|
101
|
+
export const AIR_JAM_RUNTIME_TOPOLOGY_ENV_KEYS = [
|
|
102
|
+
"VITE_AIR_JAM_RUNTIME_TOPOLOGY",
|
|
103
|
+
"NEXT_PUBLIC_AIR_JAM_RUNTIME_TOPOLOGY",
|
|
104
|
+
"AIR_JAM_RUNTIME_TOPOLOGY",
|
|
105
|
+
];
|
|
106
|
+
|
|
107
|
+
export const AIR_JAM_RUNTIME_TOPOLOGY_QUERY_PARAM_PREFIX = "aj_topology_";
|
|
108
|
+
export const AIR_JAM_RUNTIME_TOPOLOGY_WINDOW_KEY =
|
|
109
|
+
"__AIR_JAM_RUNTIME_TOPOLOGY__";
|
|
110
|
+
|
|
111
|
+
const REQUIRED_QUERY_KEYS = [
|
|
112
|
+
"runtime_mode",
|
|
113
|
+
"surface_role",
|
|
114
|
+
"app_origin",
|
|
115
|
+
"backend_origin",
|
|
116
|
+
"public_host",
|
|
117
|
+
"asset_base_path",
|
|
118
|
+
"secure_transport",
|
|
119
|
+
"embedded",
|
|
120
|
+
"proxy_strategy",
|
|
121
|
+
] as const;
|
|
122
|
+
|
|
123
|
+
const isObject = (value: unknown): value is Record<string, unknown> =>
|
|
124
|
+
value !== null && typeof value === "object" && !Array.isArray(value);
|
|
125
|
+
|
|
126
|
+
const assertString = (value: unknown, fieldName: string): string => {
|
|
127
|
+
if (typeof value !== "string") {
|
|
128
|
+
throw new Error(`Runtime topology field "${fieldName}" must be a string.`);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
const normalized = value.trim();
|
|
132
|
+
if (!normalized) {
|
|
133
|
+
throw new Error(`Runtime topology field "${fieldName}" cannot be empty.`);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
return normalized;
|
|
137
|
+
};
|
|
138
|
+
|
|
139
|
+
const assertBoolean = (value: unknown, fieldName: string): boolean => {
|
|
140
|
+
if (typeof value !== "boolean") {
|
|
141
|
+
throw new Error(`Runtime topology field "${fieldName}" must be a boolean.`);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
return value;
|
|
145
|
+
};
|
|
146
|
+
|
|
147
|
+
const assertUrl = (value: unknown, fieldName: string): string => {
|
|
148
|
+
const normalized = assertString(value, fieldName);
|
|
149
|
+
const withScheme = normalized.includes("://")
|
|
150
|
+
? normalized
|
|
151
|
+
: `http://${normalized}`;
|
|
152
|
+
|
|
153
|
+
let parsed: URL;
|
|
154
|
+
try {
|
|
155
|
+
parsed = new URL(withScheme);
|
|
156
|
+
} catch {
|
|
157
|
+
throw new Error(
|
|
158
|
+
`Runtime topology field "${fieldName}" must be a valid absolute URL.`,
|
|
159
|
+
);
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
if (parsed.protocol !== "http:" && parsed.protocol !== "https:") {
|
|
163
|
+
throw new Error(
|
|
164
|
+
`Runtime topology field "${fieldName}" must use http or https.`,
|
|
165
|
+
);
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
parsed.pathname = "";
|
|
169
|
+
parsed.search = "";
|
|
170
|
+
parsed.hash = "";
|
|
171
|
+
return parsed.origin;
|
|
172
|
+
};
|
|
173
|
+
|
|
174
|
+
const normalizeAssetBasePath = (value: unknown): string => {
|
|
175
|
+
if (value == null) {
|
|
176
|
+
return "/";
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
const normalized = assertString(value, "assetBasePath");
|
|
180
|
+
if (normalized === "/") {
|
|
181
|
+
return normalized;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
const withLeadingSlash = normalized.startsWith("/")
|
|
185
|
+
? normalized
|
|
186
|
+
: `/${normalized}`;
|
|
187
|
+
|
|
188
|
+
return withLeadingSlash.endsWith("/") && withLeadingSlash.length > 1
|
|
189
|
+
? withLeadingSlash.slice(0, -1)
|
|
190
|
+
: withLeadingSlash;
|
|
191
|
+
};
|
|
192
|
+
|
|
193
|
+
const toBooleanParam = (value: boolean): string => (value ? "true" : "false");
|
|
194
|
+
|
|
195
|
+
const fromBooleanParam = (value: string | null, fieldName: string): boolean => {
|
|
196
|
+
if (value === "true") {
|
|
197
|
+
return true;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
if (value === "false") {
|
|
201
|
+
return false;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
throw new Error(
|
|
205
|
+
`Runtime topology query field "${fieldName}" must be "true" or "false".`,
|
|
206
|
+
);
|
|
207
|
+
};
|
|
208
|
+
|
|
209
|
+
const resolveDefaultSocketOrigin = ({
|
|
210
|
+
proxyStrategy,
|
|
211
|
+
appOrigin,
|
|
212
|
+
backendOrigin,
|
|
213
|
+
}: {
|
|
214
|
+
proxyStrategy: ProxyStrategy;
|
|
215
|
+
appOrigin: string;
|
|
216
|
+
backendOrigin: string;
|
|
217
|
+
}): string => {
|
|
218
|
+
if (proxyStrategy === "none") {
|
|
219
|
+
return backendOrigin;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
return appOrigin;
|
|
223
|
+
};
|
|
224
|
+
|
|
225
|
+
const inferSecureTransport = ({
|
|
226
|
+
runtimeMode,
|
|
227
|
+
appOrigin,
|
|
228
|
+
backendOrigin,
|
|
229
|
+
socketOrigin,
|
|
230
|
+
publicHost,
|
|
231
|
+
}: {
|
|
232
|
+
runtimeMode: RuntimeMode;
|
|
233
|
+
appOrigin: string;
|
|
234
|
+
backendOrigin: string;
|
|
235
|
+
socketOrigin: string;
|
|
236
|
+
publicHost: string;
|
|
237
|
+
}): boolean => {
|
|
238
|
+
if (runtimeMode === "standalone-secure") {
|
|
239
|
+
return true;
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
return [appOrigin, backendOrigin, socketOrigin, publicHost].every((origin) =>
|
|
243
|
+
origin.startsWith("https://"),
|
|
244
|
+
);
|
|
245
|
+
};
|
|
246
|
+
|
|
247
|
+
export const resolveRuntimeTopology = (
|
|
248
|
+
input: RuntimeTopologyInput,
|
|
249
|
+
): ResolvedAirJamRuntimeTopology => {
|
|
250
|
+
if (!isObject(input)) {
|
|
251
|
+
throw new Error("Runtime topology input must be an object.");
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
const runtimeMode = assertString(
|
|
255
|
+
input.runtimeMode,
|
|
256
|
+
"runtimeMode",
|
|
257
|
+
) as RuntimeMode;
|
|
258
|
+
if (!RUNTIME_MODES.has(runtimeMode)) {
|
|
259
|
+
throw new Error(
|
|
260
|
+
`Unsupported runtime mode "${runtimeMode}". Use one of: ${Array.from(RUNTIME_MODES).join(", ")}.`,
|
|
261
|
+
);
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
const surfaceRole = assertString(
|
|
265
|
+
input.surfaceRole,
|
|
266
|
+
"surfaceRole",
|
|
267
|
+
) as SurfaceRole;
|
|
268
|
+
if (!SURFACE_ROLES.has(surfaceRole)) {
|
|
269
|
+
throw new Error(
|
|
270
|
+
`Unsupported surface role "${surfaceRole}". Use one of: ${Array.from(SURFACE_ROLES).join(", ")}.`,
|
|
271
|
+
);
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
const appOrigin = assertUrl(input.appOrigin, "appOrigin");
|
|
275
|
+
const backendOrigin = assertUrl(input.backendOrigin, "backendOrigin");
|
|
276
|
+
|
|
277
|
+
const proxyStrategy =
|
|
278
|
+
input.proxyStrategy == null
|
|
279
|
+
? "none"
|
|
280
|
+
: (assertString(input.proxyStrategy, "proxyStrategy") as ProxyStrategy);
|
|
281
|
+
if (!PROXY_STRATEGIES.has(proxyStrategy)) {
|
|
282
|
+
throw new Error(
|
|
283
|
+
`Unsupported proxy strategy "${proxyStrategy}". Use one of: ${Array.from(PROXY_STRATEGIES).join(", ")}.`,
|
|
284
|
+
);
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
const socketOrigin =
|
|
288
|
+
input.socketOrigin != null
|
|
289
|
+
? assertUrl(input.socketOrigin, "socketOrigin")
|
|
290
|
+
: resolveDefaultSocketOrigin({ proxyStrategy, appOrigin, backendOrigin });
|
|
291
|
+
const publicHost =
|
|
292
|
+
input.publicHost != null
|
|
293
|
+
? assertUrl(input.publicHost, "publicHost")
|
|
294
|
+
: appOrigin;
|
|
295
|
+
const assetBasePath = normalizeAssetBasePath(input.assetBasePath);
|
|
296
|
+
const embedded =
|
|
297
|
+
input.embedded == null ? false : assertBoolean(input.embedded, "embedded");
|
|
298
|
+
const embedParentOrigin =
|
|
299
|
+
input.embedParentOrigin == null
|
|
300
|
+
? undefined
|
|
301
|
+
: assertUrl(input.embedParentOrigin, "embedParentOrigin");
|
|
302
|
+
|
|
303
|
+
if (embedded && !embedParentOrigin) {
|
|
304
|
+
throw new Error(
|
|
305
|
+
'Embedded runtimes must provide "embedParentOrigin" in their topology.',
|
|
306
|
+
);
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
if (!embedded && embedParentOrigin) {
|
|
310
|
+
throw new Error(
|
|
311
|
+
'Non-embedded runtimes cannot provide "embedParentOrigin" in their topology.',
|
|
312
|
+
);
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
const secureTransport =
|
|
316
|
+
input.secureTransport == null
|
|
317
|
+
? inferSecureTransport({
|
|
318
|
+
runtimeMode,
|
|
319
|
+
appOrigin,
|
|
320
|
+
backendOrigin,
|
|
321
|
+
socketOrigin,
|
|
322
|
+
publicHost,
|
|
323
|
+
})
|
|
324
|
+
: assertBoolean(input.secureTransport, "secureTransport");
|
|
325
|
+
|
|
326
|
+
return {
|
|
327
|
+
runtimeMode,
|
|
328
|
+
surfaceRole,
|
|
329
|
+
appOrigin,
|
|
330
|
+
backendOrigin,
|
|
331
|
+
socketOrigin,
|
|
332
|
+
publicHost,
|
|
333
|
+
assetBasePath,
|
|
334
|
+
secureTransport,
|
|
335
|
+
embedded,
|
|
336
|
+
...(embedParentOrigin ? { embedParentOrigin } : {}),
|
|
337
|
+
proxyStrategy,
|
|
338
|
+
};
|
|
339
|
+
};
|
|
340
|
+
|
|
341
|
+
export const resolveProjectRuntimeTopology = (
|
|
342
|
+
input: ProjectRuntimeTopologyInput,
|
|
343
|
+
): ResolvedAirJamRuntimeTopology => {
|
|
344
|
+
if (!isObject(input)) {
|
|
345
|
+
throw new Error("Project runtime topology input must be an object.");
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
const requestedRuntimeMode =
|
|
349
|
+
input.runtimeMode == null
|
|
350
|
+
? input.secureTransport
|
|
351
|
+
? "standalone-secure"
|
|
352
|
+
: "standalone-dev"
|
|
353
|
+
: (assertString(input.runtimeMode, "runtimeMode") as NonNullable<
|
|
354
|
+
ProjectRuntimeTopologyInput["runtimeMode"]
|
|
355
|
+
>);
|
|
356
|
+
|
|
357
|
+
if (!PROJECT_RUNTIME_MODES.has(requestedRuntimeMode)) {
|
|
358
|
+
throw new Error(
|
|
359
|
+
`Unsupported project runtime mode "${requestedRuntimeMode}". Use one of: ${Array.from(PROJECT_RUNTIME_MODES).join(", ")}.`,
|
|
360
|
+
);
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
const proxyStrategy =
|
|
364
|
+
input.proxyStrategy ??
|
|
365
|
+
(requestedRuntimeMode === "standalone-dev" ||
|
|
366
|
+
requestedRuntimeMode === "standalone-secure"
|
|
367
|
+
? "dev-proxy"
|
|
368
|
+
: "none");
|
|
369
|
+
|
|
370
|
+
const appOrigin = assertUrl(input.appOrigin, "appOrigin");
|
|
371
|
+
const backendOrigin =
|
|
372
|
+
input.backendOrigin != null
|
|
373
|
+
? assertUrl(input.backendOrigin, "backendOrigin")
|
|
374
|
+
: appOrigin;
|
|
375
|
+
const publicHost =
|
|
376
|
+
input.publicHost != null
|
|
377
|
+
? assertUrl(input.publicHost, "publicHost")
|
|
378
|
+
: appOrigin;
|
|
379
|
+
|
|
380
|
+
return resolveRuntimeTopology({
|
|
381
|
+
runtimeMode: requestedRuntimeMode,
|
|
382
|
+
surfaceRole: input.surfaceRole,
|
|
383
|
+
appOrigin,
|
|
384
|
+
backendOrigin,
|
|
385
|
+
publicHost,
|
|
386
|
+
assetBasePath: input.assetBasePath,
|
|
387
|
+
secureTransport: input.secureTransport,
|
|
388
|
+
embedded: input.embedded,
|
|
389
|
+
embedParentOrigin: input.embedParentOrigin,
|
|
390
|
+
proxyStrategy,
|
|
391
|
+
...(input.socketOrigin ? { socketOrigin: input.socketOrigin } : {}),
|
|
392
|
+
});
|
|
393
|
+
};
|
|
394
|
+
|
|
395
|
+
export const isLocalDevControlSurfaceRuntimeMode = (
|
|
396
|
+
runtimeMode: RuntimeMode,
|
|
397
|
+
): boolean =>
|
|
398
|
+
LOCAL_DEV_CONTROL_SURFACE_RUNTIME_MODES.has(
|
|
399
|
+
assertString(runtimeMode, "runtimeMode") as RuntimeMode,
|
|
400
|
+
);
|
|
401
|
+
|
|
402
|
+
export const isLocalDevControlSurfaceTopology = ({
|
|
403
|
+
runtimeMode,
|
|
404
|
+
}: Pick<ResolvedAirJamRuntimeTopology, "runtimeMode">): boolean =>
|
|
405
|
+
isLocalDevControlSurfaceRuntimeMode(runtimeMode);
|
|
406
|
+
|
|
407
|
+
export const serializeRuntimeTopology = (
|
|
408
|
+
topology: RuntimeTopologyInput | ResolvedAirJamRuntimeTopology,
|
|
409
|
+
): string => JSON.stringify(resolveRuntimeTopology(topology));
|
|
410
|
+
|
|
411
|
+
export const parseRuntimeTopology = (
|
|
412
|
+
serialized: string,
|
|
413
|
+
): ResolvedAirJamRuntimeTopology => {
|
|
414
|
+
const normalized = assertString(
|
|
415
|
+
serialized,
|
|
416
|
+
"serialized runtime topology",
|
|
417
|
+
);
|
|
418
|
+
|
|
419
|
+
let parsed: unknown;
|
|
420
|
+
try {
|
|
421
|
+
parsed = JSON.parse(normalized);
|
|
422
|
+
} catch {
|
|
423
|
+
throw new Error("Runtime topology must be valid JSON.");
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
return resolveRuntimeTopology(parsed as RuntimeTopologyInput);
|
|
427
|
+
};
|
|
428
|
+
|
|
429
|
+
export const readRuntimeTopologyFromEnv = (
|
|
430
|
+
env: Record<string, string | undefined> = process.env,
|
|
431
|
+
): ResolvedAirJamRuntimeTopology | null => {
|
|
432
|
+
for (const key of AIR_JAM_RUNTIME_TOPOLOGY_ENV_KEYS) {
|
|
433
|
+
const candidate = env?.[key];
|
|
434
|
+
if (typeof candidate === "string" && candidate.trim().length > 0) {
|
|
435
|
+
return parseRuntimeTopology(candidate);
|
|
436
|
+
}
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
return null;
|
|
440
|
+
};
|
|
441
|
+
|
|
442
|
+
export const readRuntimeTopologyFromWindow = (
|
|
443
|
+
target:
|
|
444
|
+
| Record<string, unknown>
|
|
445
|
+
| { [AIR_JAM_RUNTIME_TOPOLOGY_WINDOW_KEY]?: unknown }
|
|
446
|
+
| undefined = (globalThis as typeof globalThis & {
|
|
447
|
+
window?: { [AIR_JAM_RUNTIME_TOPOLOGY_WINDOW_KEY]?: unknown };
|
|
448
|
+
}).window,
|
|
449
|
+
): ResolvedAirJamRuntimeTopology | null => {
|
|
450
|
+
if (!target || typeof target !== "object") {
|
|
451
|
+
return null;
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
const candidate = target[AIR_JAM_RUNTIME_TOPOLOGY_WINDOW_KEY];
|
|
455
|
+
if (typeof candidate === "string" && candidate.trim().length > 0) {
|
|
456
|
+
return parseRuntimeTopology(candidate);
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
if (isObject(candidate)) {
|
|
460
|
+
return resolveRuntimeTopology(candidate as unknown as RuntimeTopologyInput);
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
return null;
|
|
464
|
+
};
|
|
465
|
+
|
|
466
|
+
export const runtimeTopologyToQueryParams = (
|
|
467
|
+
topology: RuntimeTopologyInput | ResolvedAirJamRuntimeTopology,
|
|
468
|
+
): Record<string, string> => {
|
|
469
|
+
const resolved = resolveRuntimeTopology(topology);
|
|
470
|
+
|
|
471
|
+
return {
|
|
472
|
+
[`${AIR_JAM_RUNTIME_TOPOLOGY_QUERY_PARAM_PREFIX}runtime_mode`]:
|
|
473
|
+
resolved.runtimeMode,
|
|
474
|
+
[`${AIR_JAM_RUNTIME_TOPOLOGY_QUERY_PARAM_PREFIX}surface_role`]:
|
|
475
|
+
resolved.surfaceRole,
|
|
476
|
+
[`${AIR_JAM_RUNTIME_TOPOLOGY_QUERY_PARAM_PREFIX}app_origin`]:
|
|
477
|
+
resolved.appOrigin,
|
|
478
|
+
[`${AIR_JAM_RUNTIME_TOPOLOGY_QUERY_PARAM_PREFIX}backend_origin`]:
|
|
479
|
+
resolved.backendOrigin,
|
|
480
|
+
[`${AIR_JAM_RUNTIME_TOPOLOGY_QUERY_PARAM_PREFIX}socket_origin`]:
|
|
481
|
+
resolved.socketOrigin,
|
|
482
|
+
[`${AIR_JAM_RUNTIME_TOPOLOGY_QUERY_PARAM_PREFIX}public_host`]:
|
|
483
|
+
resolved.publicHost,
|
|
484
|
+
[`${AIR_JAM_RUNTIME_TOPOLOGY_QUERY_PARAM_PREFIX}asset_base_path`]:
|
|
485
|
+
resolved.assetBasePath,
|
|
486
|
+
[`${AIR_JAM_RUNTIME_TOPOLOGY_QUERY_PARAM_PREFIX}secure_transport`]:
|
|
487
|
+
toBooleanParam(resolved.secureTransport),
|
|
488
|
+
[`${AIR_JAM_RUNTIME_TOPOLOGY_QUERY_PARAM_PREFIX}embedded`]: toBooleanParam(
|
|
489
|
+
resolved.embedded,
|
|
490
|
+
),
|
|
491
|
+
[`${AIR_JAM_RUNTIME_TOPOLOGY_QUERY_PARAM_PREFIX}proxy_strategy`]:
|
|
492
|
+
resolved.proxyStrategy,
|
|
493
|
+
...(resolved.embedParentOrigin
|
|
494
|
+
? {
|
|
495
|
+
[`${AIR_JAM_RUNTIME_TOPOLOGY_QUERY_PARAM_PREFIX}embed_parent_origin`]:
|
|
496
|
+
resolved.embedParentOrigin,
|
|
497
|
+
}
|
|
498
|
+
: {}),
|
|
499
|
+
};
|
|
500
|
+
};
|
|
501
|
+
|
|
502
|
+
export const parseRuntimeTopologyFromSearchParams = (
|
|
503
|
+
params: URLSearchParams,
|
|
504
|
+
): ResolvedAirJamRuntimeTopology | null => {
|
|
505
|
+
if (!(params instanceof URLSearchParams)) {
|
|
506
|
+
throw new Error(
|
|
507
|
+
"Runtime topology search param reader expects URLSearchParams.",
|
|
508
|
+
);
|
|
509
|
+
}
|
|
510
|
+
|
|
511
|
+
const hasAnyTopologyParam = REQUIRED_QUERY_KEYS.some((key) =>
|
|
512
|
+
params.has(`${AIR_JAM_RUNTIME_TOPOLOGY_QUERY_PARAM_PREFIX}${key}`),
|
|
513
|
+
);
|
|
514
|
+
if (!hasAnyTopologyParam) {
|
|
515
|
+
return null;
|
|
516
|
+
}
|
|
517
|
+
|
|
518
|
+
const missing = REQUIRED_QUERY_KEYS.filter(
|
|
519
|
+
(key) =>
|
|
520
|
+
!params.has(`${AIR_JAM_RUNTIME_TOPOLOGY_QUERY_PARAM_PREFIX}${key}`),
|
|
521
|
+
);
|
|
522
|
+
if (missing.length > 0) {
|
|
523
|
+
throw new Error(
|
|
524
|
+
`Runtime topology search params are incomplete. Missing: ${missing.join(", ")}.`,
|
|
525
|
+
);
|
|
526
|
+
}
|
|
527
|
+
|
|
528
|
+
const embedParentOrigin = params.get(
|
|
529
|
+
`${AIR_JAM_RUNTIME_TOPOLOGY_QUERY_PARAM_PREFIX}embed_parent_origin`,
|
|
530
|
+
);
|
|
531
|
+
|
|
532
|
+
return resolveRuntimeTopology({
|
|
533
|
+
runtimeMode: params.get(
|
|
534
|
+
`${AIR_JAM_RUNTIME_TOPOLOGY_QUERY_PARAM_PREFIX}runtime_mode`,
|
|
535
|
+
) as RuntimeMode,
|
|
536
|
+
surfaceRole: params.get(
|
|
537
|
+
`${AIR_JAM_RUNTIME_TOPOLOGY_QUERY_PARAM_PREFIX}surface_role`,
|
|
538
|
+
) as SurfaceRole,
|
|
539
|
+
appOrigin: params.get(
|
|
540
|
+
`${AIR_JAM_RUNTIME_TOPOLOGY_QUERY_PARAM_PREFIX}app_origin`,
|
|
541
|
+
) as string,
|
|
542
|
+
backendOrigin: params.get(
|
|
543
|
+
`${AIR_JAM_RUNTIME_TOPOLOGY_QUERY_PARAM_PREFIX}backend_origin`,
|
|
544
|
+
) as string,
|
|
545
|
+
socketOrigin: params.get(
|
|
546
|
+
`${AIR_JAM_RUNTIME_TOPOLOGY_QUERY_PARAM_PREFIX}socket_origin`,
|
|
547
|
+
) as string,
|
|
548
|
+
publicHost: params.get(
|
|
549
|
+
`${AIR_JAM_RUNTIME_TOPOLOGY_QUERY_PARAM_PREFIX}public_host`,
|
|
550
|
+
) as string,
|
|
551
|
+
assetBasePath: params.get(
|
|
552
|
+
`${AIR_JAM_RUNTIME_TOPOLOGY_QUERY_PARAM_PREFIX}asset_base_path`,
|
|
553
|
+
) as string,
|
|
554
|
+
secureTransport: fromBooleanParam(
|
|
555
|
+
params.get(
|
|
556
|
+
`${AIR_JAM_RUNTIME_TOPOLOGY_QUERY_PARAM_PREFIX}secure_transport`,
|
|
557
|
+
),
|
|
558
|
+
"secure_transport",
|
|
559
|
+
),
|
|
560
|
+
embedded: fromBooleanParam(
|
|
561
|
+
params.get(`${AIR_JAM_RUNTIME_TOPOLOGY_QUERY_PARAM_PREFIX}embedded`),
|
|
562
|
+
"embedded",
|
|
563
|
+
),
|
|
564
|
+
proxyStrategy: params.get(
|
|
565
|
+
`${AIR_JAM_RUNTIME_TOPOLOGY_QUERY_PARAM_PREFIX}proxy_strategy`,
|
|
566
|
+
) as ProxyStrategy,
|
|
567
|
+
...(embedParentOrigin ? { embedParentOrigin } : {}),
|
|
568
|
+
});
|
|
569
|
+
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/arcade/url.ts"],"sourcesContent":["import type { ResolvedAirJamRuntimeTopology } from \"@air-jam/runtime-topology\";\nimport { runtimeTopologyToQueryParams } from \"@air-jam/runtime-topology\";\nimport type { ChildHostCapability } from \"../protocol\";\nimport {\n appendRuntimeQueryParams,\n getRuntimeUrlOrigin,\n normalizeRuntimeUrl,\n} from \"../protocol/url-policy\";\nimport {\n arcadeSurfaceRuntimeUrlParams,\n type ArcadeSurfaceRuntimeIdentity,\n} from \"./surface\";\nexport { urlBuilder } from \"../utils/url-builder\";\nexport { arcadeSurfaceRuntimeUrlParams } from \"./surface\";\nexport { appendRuntimeQueryParams, getRuntimeUrlOrigin, normalizeRuntimeUrl };\n\nexport const buildArcadeGameIframeSrc = ({\n normalizedUrl,\n roomId,\n launchCapability,\n joinUrl,\n topology,\n arcadeSurface,\n}: {\n normalizedUrl: string;\n roomId: string;\n launchCapability: ChildHostCapability;\n joinUrl?: string | null;\n topology: ResolvedAirJamRuntimeTopology;\n arcadeSurface: ArcadeSurfaceRuntimeIdentity;\n}): string | null =>\n appendRuntimeQueryParams(normalizedUrl, {\n aj_room: roomId,\n aj_cap: launchCapability.token,\n aj_cap_exp: String(launchCapability.expiresAt),\n aj_join_url: joinUrl,\n ...runtimeTopologyToQueryParams(topology),\n ...arcadeSurfaceRuntimeUrlParams(arcadeSurface),\n });\n\nexport const buildArcadeControllerRuntimeUrl = (\n normalizedUrl: string,\n): string | null => {\n try {\n const runtimeUrl = new URL(normalizedUrl);\n const trimmedPath =\n runtimeUrl.pathname !== \"/\" && runtimeUrl.pathname.endsWith(\"/\")\n ? runtimeUrl.pathname.slice(0, -1)\n : runtimeUrl.pathname;\n const pathSegments = trimmedPath.split(\"/\").filter(Boolean);\n const controllerPath =\n trimmedPath === \"/\" || pathSegments.length <= 1\n ? \"/controller\"\n : `${trimmedPath}/controller`;\n\n return new URL(controllerPath, runtimeUrl.origin).toString();\n } catch {\n return null;\n }\n};\n"],"mappings":";;;;;;;;AACA,SAAS,oCAAoC;AAetC,IAAM,2BAA2B,CAAC;AAAA,EACvC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,MAQE,yBAAyB,eAAe;AAAA,EACtC,SAAS;AAAA,EACT,QAAQ,iBAAiB;AAAA,EACzB,YAAY,OAAO,iBAAiB,SAAS;AAAA,EAC7C,aAAa;AAAA,EACb,GAAG,6BAA6B,QAAQ;AAAA,EACxC,GAAG,8BAA8B,aAAa;AAChD,CAAC;AAEI,IAAM,kCAAkC,CAC7C,kBACkB;AAClB,MAAI;AACF,UAAM,aAAa,IAAI,IAAI,aAAa;AACxC,UAAM,cACJ,WAAW,aAAa,OAAO,WAAW,SAAS,SAAS,GAAG,IAC3D,WAAW,SAAS,MAAM,GAAG,EAAE,IAC/B,WAAW;AACjB,UAAM,eAAe,YAAY,MAAM,GAAG,EAAE,OAAO,OAAO;AAC1D,UAAM,iBACJ,gBAAgB,OAAO,aAAa,UAAU,IAC1C,gBACA,GAAG,WAAW;AAEpB,WAAO,IAAI,IAAI,gBAAgB,WAAW,MAAM,EAAE,SAAS;AAAA,EAC7D,QAAQ;AACN,WAAO;AAAA,EACT;AACF;","names":[]}
|