@air-jam/devtools 0.0.0-stage → 0.9.3

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.
Files changed (135) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +52 -2
  3. package/dist/agent.d.ts +15 -0
  4. package/dist/agent.js +19 -0
  5. package/dist/agent.js.map +1 -0
  6. package/dist/chunk-5YAARMW5.js +36 -0
  7. package/dist/chunk-5YAARMW5.js.map +1 -0
  8. package/dist/chunk-6WQODT37.js +1019 -0
  9. package/dist/chunk-6WQODT37.js.map +1 -0
  10. package/dist/chunk-CKFT2ZJE.js +801 -0
  11. package/dist/chunk-CKFT2ZJE.js.map +1 -0
  12. package/dist/chunk-ER3Q2C4G.js +358 -0
  13. package/dist/chunk-ER3Q2C4G.js.map +1 -0
  14. package/dist/chunk-GUEZP773.js +851 -0
  15. package/dist/chunk-GUEZP773.js.map +1 -0
  16. package/dist/chunk-HIDNI56E.js +33 -0
  17. package/dist/chunk-HIDNI56E.js.map +1 -0
  18. package/dist/chunk-QKXS5D35.js +43 -0
  19. package/dist/chunk-QKXS5D35.js.map +1 -0
  20. package/dist/chunk-S4LSCEVE.js +261 -0
  21. package/dist/chunk-S4LSCEVE.js.map +1 -0
  22. package/dist/chunk-VKMJO6VN.js +360 -0
  23. package/dist/chunk-VKMJO6VN.js.map +1 -0
  24. package/dist/chunk-WFUR3MXY.js +67 -0
  25. package/dist/chunk-WFUR3MXY.js.map +1 -0
  26. package/dist/chunk-XEMR7KUE.js +361 -0
  27. package/dist/chunk-XEMR7KUE.js.map +1 -0
  28. package/dist/chunk-ZLPD7FY5.js +191 -0
  29. package/dist/chunk-ZLPD7FY5.js.map +1 -0
  30. package/dist/context.d.ts +13 -0
  31. package/dist/context.js +9 -0
  32. package/dist/context.js.map +1 -0
  33. package/dist/controller.d.ts +41 -0
  34. package/dist/controller.js +30 -0
  35. package/dist/controller.js.map +1 -0
  36. package/dist/dev.d.ts +15 -0
  37. package/dist/dev.js +20 -0
  38. package/dist/dev.js.map +1 -0
  39. package/dist/game-session-broker.d.ts +57 -0
  40. package/dist/game-session-broker.js +235 -0
  41. package/dist/game-session-broker.js.map +1 -0
  42. package/dist/game-session.d.ts +13 -0
  43. package/dist/game-session.js +24 -0
  44. package/dist/game-session.js.map +1 -0
  45. package/dist/games.d.ts +21 -0
  46. package/dist/games.js +14 -0
  47. package/dist/games.js.map +1 -0
  48. package/dist/harness/visual.d.ts +321 -0
  49. package/dist/harness/visual.js +41 -0
  50. package/dist/harness/visual.js.map +1 -0
  51. package/dist/logs.d.ts +9 -0
  52. package/dist/logs.js +58 -0
  53. package/dist/logs.js.map +1 -0
  54. package/dist/mcp-config.d.ts +63 -0
  55. package/dist/mcp-config.js +190 -0
  56. package/dist/mcp-config.js.map +1 -0
  57. package/dist/platform-auth.d.ts +112 -0
  58. package/dist/platform-auth.js +37 -0
  59. package/dist/platform-auth.js.map +1 -0
  60. package/dist/platform-game-media.d.ts +309 -0
  61. package/dist/platform-game-media.js +168 -0
  62. package/dist/platform-game-media.js.map +1 -0
  63. package/dist/platform-games.d.ts +65 -0
  64. package/dist/platform-games.js +251 -0
  65. package/dist/platform-games.js.map +1 -0
  66. package/dist/quality.d.ts +10 -0
  67. package/dist/quality.js +63 -0
  68. package/dist/quality.js.map +1 -0
  69. package/dist/release.d.ts +1094 -0
  70. package/dist/release.js +1347 -0
  71. package/dist/release.js.map +1 -0
  72. package/dist/tooling/agent-contract.d.ts +2 -0
  73. package/dist/tooling/agent-contract.js +193 -0
  74. package/dist/tooling/agent-contract.js.map +1 -0
  75. package/dist/tooling/hold-runtime-host.d.ts +2 -0
  76. package/dist/tooling/hold-runtime-host.js +229 -0
  77. package/dist/tooling/hold-runtime-host.js.map +1 -0
  78. package/dist/tooling/inspect-airjam-agent.d.ts +2 -0
  79. package/dist/tooling/inspect-airjam-agent.js +37 -0
  80. package/dist/tooling/inspect-airjam-agent.js.map +1 -0
  81. package/dist/tooling/list-visual-scenarios.d.ts +2 -0
  82. package/dist/tooling/list-visual-scenarios.js +62 -0
  83. package/dist/tooling/list-visual-scenarios.js.map +1 -0
  84. package/dist/tooling/managed-dev-supervisor.d.ts +2 -0
  85. package/dist/tooling/managed-dev-supervisor.js +51 -0
  86. package/dist/tooling/managed-dev-supervisor.js.map +1 -0
  87. package/dist/tooling/run-visual-capture.d.ts +2 -0
  88. package/dist/tooling/run-visual-capture.js +167 -0
  89. package/dist/tooling/run-visual-capture.js.map +1 -0
  90. package/dist/types-C6NrHt88.d.ts +775 -0
  91. package/dist/visual.d.ts +15 -0
  92. package/dist/visual.js +263 -0
  93. package/dist/visual.js.map +1 -0
  94. package/package.json +113 -3
  95. package/src/agent.ts +380 -0
  96. package/src/commands.ts +40 -0
  97. package/src/context.ts +229 -0
  98. package/src/controller.ts +1376 -0
  99. package/src/dev.ts +999 -0
  100. package/src/fs-utils.ts +93 -0
  101. package/src/game-action-observation.ts +96 -0
  102. package/src/game-session-broker.ts +301 -0
  103. package/src/game-session.ts +459 -0
  104. package/src/games.ts +266 -0
  105. package/src/harness/visual/prefab-contract.ts +29 -0
  106. package/src/harness/visual/prefab-runner.ts +178 -0
  107. package/src/harness/visual/runner.ts +546 -0
  108. package/src/harness/visual/scenario-contract.ts +9 -0
  109. package/src/harness/visual/scenario-helpers.ts +63 -0
  110. package/src/harness/visual/session.ts +369 -0
  111. package/src/harness/visual/types.ts +181 -0
  112. package/src/harness/visual.ts +7 -0
  113. package/src/helper-scripts.ts +49 -0
  114. package/src/logs.ts +67 -0
  115. package/src/mcp-config.ts +262 -0
  116. package/src/platform-auth.ts +455 -0
  117. package/src/platform-game-media.ts +209 -0
  118. package/src/platform-games.ts +315 -0
  119. package/src/quality.ts +82 -0
  120. package/src/release.ts +1697 -0
  121. package/src/runtime-owner-protocol.ts +130 -0
  122. package/src/tooling/agent-contract.ts +232 -0
  123. package/src/tooling/agent-declaration.ts +36 -0
  124. package/src/tooling/airjam-agent-inspection.ts +45 -0
  125. package/src/tooling/airjam-agent.ts +118 -0
  126. package/src/tooling/hold-runtime-host.ts +224 -0
  127. package/src/tooling/inspect-airjam-agent.ts +20 -0
  128. package/src/tooling/list-visual-scenarios.ts +64 -0
  129. package/src/tooling/managed-dev-supervisor.ts +71 -0
  130. package/src/tooling/run-visual-capture.ts +217 -0
  131. package/src/tooling/runtime-owner-actions.ts +42 -0
  132. package/src/tooling/visual-pack.ts +46 -0
  133. package/src/types.ts +951 -0
  134. package/src/visual.ts +304 -0
  135. package/src/workspace-contract.ts +32 -0
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/mcp-config.ts"],"sourcesContent":["import { access, mkdir, readFile, writeFile } from \"node:fs/promises\";\nimport os from \"node:os\";\nimport path from \"node:path\";\nimport { inspectProject } from \"./context.js\";\nexport type AirJamMcpServerDeclaration = {\n name: \"airjam\";\n transport: \"stdio\";\n command: \"pnpm\";\n args: [\"exec\", \"airjam-mcp\"];\n};\n\nexport type AirJamProjectLocalMcpConfig = {\n mcpServers: {\n airjam: {\n command: string;\n args: string[];\n };\n };\n};\n\nexport type AirJamMcpClientProfile = \"portable\" | \"codex\" | \"claude-desktop\";\n\nexport type AirJamMcpClientProfileRender = {\n profile: AirJamMcpClientProfile;\n format: \"json\" | \"toml\";\n scope: \"project\" | \"client-global\";\n configPath: string | null;\n content: string;\n installCommand: string | null;\n};\n\nexport type AirJamMcpRegistrationInspection = {\n profile: AirJamMcpClientProfile;\n configPath: string | null;\n configPresent: boolean | null;\n registered: boolean | null;\n};\n\nexport type InspectMcpProjectSetupResult = {\n projectDir: string;\n server: AirJamMcpServerDeclaration;\n package: {\n dependencyPresent: boolean;\n scriptPresent: boolean;\n };\n portableDeclaration: {\n configPath: string;\n present: boolean;\n };\n clients: {\n codex: AirJamMcpRegistrationInspection;\n claudeDesktop: AirJamMcpRegistrationInspection;\n };\n recommendedConfig: AirJamProjectLocalMcpConfig;\n};\n\nexport const AIRJAM_PROJECT_MCP_FILE = \".mcp.json\";\nexport const AIRJAM_CODEX_PROJECT_MCP_FILE = path.join(\".codex\", \"config.toml\");\n\nexport const createAirJamMcpServerDeclaration =\n (): AirJamMcpServerDeclaration => ({\n name: \"airjam\",\n transport: \"stdio\",\n command: \"pnpm\",\n args: [\"exec\", \"airjam-mcp\"],\n });\n\nexport const createProjectLocalMcpConfig = (): AirJamProjectLocalMcpConfig => {\n const server = createAirJamMcpServerDeclaration();\n return {\n mcpServers: {\n airjam: {\n command: server.command,\n args: [...server.args],\n },\n },\n };\n};\n\nconst pathExists = async (targetPath: string): Promise<boolean> => {\n try {\n await access(targetPath);\n return true;\n } catch {\n return false;\n }\n};\n\nconst resolveClaudeDesktopConfigPath = (): string | null => {\n if (process.platform === \"darwin\") {\n return path.join(\n os.homedir(),\n \"Library\",\n \"Application Support\",\n \"Claude\",\n \"claude_desktop_config.json\",\n );\n }\n if (process.platform === \"win32\") {\n const appData = process.env.APPDATA;\n return appData\n ? path.join(appData, \"Claude\", \"claude_desktop_config.json\")\n : null;\n }\n return path.join(\n os.homedir(),\n \".config\",\n \"Claude\",\n \"claude_desktop_config.json\",\n );\n};\n\nconst inspectJsonRegistration = async (\n profile: AirJamMcpClientProfile,\n configPath: string | null,\n): Promise<AirJamMcpRegistrationInspection> => {\n if (!configPath) {\n return { profile, configPath, configPresent: null, registered: null };\n }\n if (!(await pathExists(configPath))) {\n return { profile, configPath, configPresent: false, registered: false };\n }\n try {\n const parsed = JSON.parse(await readFile(configPath, \"utf8\")) as {\n mcpServers?: Record<string, unknown>;\n };\n return {\n profile,\n configPath,\n configPresent: true,\n registered: Boolean(parsed.mcpServers?.airjam),\n };\n } catch {\n return { profile, configPath, configPresent: true, registered: false };\n }\n};\n\nconst inspectCodexRegistration = async (\n projectDir: string,\n): Promise<AirJamMcpRegistrationInspection> => {\n const configPath = path.join(projectDir, AIRJAM_CODEX_PROJECT_MCP_FILE);\n if (!(await pathExists(configPath))) {\n return {\n profile: \"codex\",\n configPath,\n configPresent: false,\n registered: false,\n };\n }\n const source = await readFile(configPath, \"utf8\");\n return {\n profile: \"codex\",\n configPath,\n configPresent: true,\n registered: /^\\s*\\[mcp_servers\\.airjam\\]\\s*$/m.test(source),\n };\n};\n\nexport const renderMcpClientProfile = ({\n profile,\n projectDir = process.cwd(),\n}: {\n profile: AirJamMcpClientProfile;\n projectDir?: string;\n}): AirJamMcpClientProfileRender => {\n const server = createAirJamMcpServerDeclaration();\n if (profile === \"codex\") {\n const escapedCwd = projectDir\n .replaceAll(\"\\\\\", \"\\\\\\\\\")\n .replaceAll('\"', '\\\\\"');\n return {\n profile,\n format: \"toml\",\n scope: \"project\",\n configPath: path.join(projectDir, AIRJAM_CODEX_PROJECT_MCP_FILE),\n content: `[mcp_servers.airjam]\\ncommand = \"${server.command}\"\\nargs = [\"exec\", \"airjam-mcp\"]\\ncwd = \"${escapedCwd}\"\\n`,\n installCommand: `codex mcp add airjam -- ${server.command} ${server.args.join(\" \")}`,\n };\n }\n\n const config = createProjectLocalMcpConfig();\n if (profile === \"claude-desktop\") {\n // Desktop launches globally, not from the game's project directory.\n config.mcpServers.airjam.args = [\n \"--dir\",\n path.resolve(projectDir),\n ...server.args,\n ];\n }\n\n return {\n profile,\n format: \"json\",\n scope: profile === \"portable\" ? \"project\" : \"client-global\",\n configPath:\n profile === \"portable\"\n ? path.join(projectDir, AIRJAM_PROJECT_MCP_FILE)\n : resolveClaudeDesktopConfigPath(),\n content: `${JSON.stringify(config, null, 2)}\\n`,\n installCommand: null,\n };\n};\n\nexport const inspectMcpProjectSetup = async ({\n cwd = process.cwd(),\n}: {\n cwd?: string;\n} = {}): Promise<InspectMcpProjectSetupResult> => {\n const project = await inspectProject({ cwd });\n const projectDir = project.context.rootDir;\n const configPath = path.join(projectDir, AIRJAM_PROJECT_MCP_FILE);\n\n return {\n projectDir,\n server: createAirJamMcpServerDeclaration(),\n package: {\n dependencyPresent: Boolean(project.airJamPackages[\"@air-jam/mcp-server\"]),\n scriptPresent: Boolean(project.scripts.mcp),\n },\n portableDeclaration: {\n configPath,\n present: await pathExists(configPath),\n },\n clients: {\n codex: await inspectCodexRegistration(projectDir),\n claudeDesktop: await inspectJsonRegistration(\n \"claude-desktop\",\n resolveClaudeDesktopConfigPath(),\n ),\n },\n recommendedConfig: createProjectLocalMcpConfig(),\n };\n};\n\nexport const writeProjectLocalMcpConfig = async ({\n cwd = process.cwd(),\n force = false,\n}: {\n cwd?: string;\n force?: boolean;\n} = {}): Promise<InspectMcpProjectSetupResult> => {\n const inspection = await inspectMcpProjectSetup({ cwd });\n const configPath = inspection.portableDeclaration.configPath;\n\n if (inspection.portableDeclaration.present && !force) {\n throw new Error(\n `MCP declaration already exists at ${configPath}. Re-run with force to overwrite it.`,\n );\n }\n\n await mkdir(path.dirname(configPath), { recursive: true });\n await writeFile(\n configPath,\n renderMcpClientProfile({\n profile: \"portable\",\n projectDir: inspection.projectDir,\n }).content,\n \"utf8\",\n );\n\n return inspectMcpProjectSetup({ cwd });\n};\n"],"mappings":";;;;;AAAA,SAAS,QAAQ,OAAO,UAAU,iBAAiB;AACnD,OAAO,QAAQ;AACf,OAAO,UAAU;AAsDV,IAAM,0BAA0B;AAChC,IAAM,gCAAgC,KAAK,KAAK,UAAU,aAAa;AAEvE,IAAM,mCACX,OAAmC;AAAA,EACjC,MAAM;AAAA,EACN,WAAW;AAAA,EACX,SAAS;AAAA,EACT,MAAM,CAAC,QAAQ,YAAY;AAC7B;AAEK,IAAM,8BAA8B,MAAmC;AAC5E,QAAM,SAAS,iCAAiC;AAChD,SAAO;AAAA,IACL,YAAY;AAAA,MACV,QAAQ;AAAA,QACN,SAAS,OAAO;AAAA,QAChB,MAAM,CAAC,GAAG,OAAO,IAAI;AAAA,MACvB;AAAA,IACF;AAAA,EACF;AACF;AAEA,IAAM,aAAa,OAAO,eAAyC;AACjE,MAAI;AACF,UAAM,OAAO,UAAU;AACvB,WAAO;AAAA,EACT,QAAQ;AACN,WAAO;AAAA,EACT;AACF;AAEA,IAAM,iCAAiC,MAAqB;AAC1D,MAAI,Q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,eAAe,QAAQ,QAAQ,QAAQ,GAAG;AAAA,IAC5C;AAAA,IACA,qBAAqB;AAAA,MACnB;AAAA,MACA,SAAS,MAAM,WAAW,UAAU;AAAA,IACtC;AAAA,IACA,SAAS;AAAA,MACP,OAAO,MAAM,yBAAyB,UAAU;AAAA,MAChD,eAAe,MAAM;AAAA,QACnB;AAAA,QACA,+BAA+B;AAAA,MACjC;AAAA,IACF;AAAA,IACA,mBAAmB,4BAA4B;AAAA,EACjD;AACF;AAEO,IAAM,6BAA6B,OAAO;AAAA,EAC/C,MAAM,QAAQ,IAAI;AAAA,EAClB,QAAQ;AACV,IAGI,CAAC,MAA6C;AAChD,QAAM,aAAa,MAAM,uBAAuB,EAAE,IAAI,CAAC;AACvD,QAAM,aAAa,WAAW,oBAAoB;AAElD,MAAI,WAAW,oBAAoB,WAAW,CAAC,OAAO;AACpD,UAAM,IAAI;AAAA,MACR,qCAAqC,UAAU;AAAA,IACjD;AAAA,EACF;AAEA,QAAM,MAAM,KAAK,QAAQ,UAAU,GAAG,EAAE,WAAW,KAAK,CAAC;AACzD,QAAM;AAAA,IACJ;AAAA,IACA,uBAAuB;AAAA,MACrB,SAAS;AAAA,MACT,YAAY,WAAW;AAAA,IACzB,CAAC,EAAE;AAAA,IACH;AAAA,EACF;AAEA,SAAO,uBAAuB,EAAE,IAAI,CAAC;AACvC;","names":[]}
@@ -0,0 +1,112 @@
1
+ import { PlatformMachineErrorCode } from '@air-jam/sdk/platform-machine';
2
+ import { a2 as AirJamPlatformMachineSessionStore, a3 as StartPlatformDeviceAuthorizationOptions, a4 as PollPlatformDeviceAuthorizationOptions, a5 as LoginPlatformWithDeviceFlowOptions, a6 as GetPlatformMachineProfileOptions, a7 as LogoutPlatformMachineSessionOptions, a8 as AirJamPlatformAuthStatus } from './types-C6NrHt88.js';
3
+ import '@air-jam/sdk';
4
+
5
+ declare const resolveAirJamStateDirectory: () => string;
6
+ declare class AirJamPlatformApiError extends Error {
7
+ readonly code: PlatformMachineErrorCode;
8
+ readonly status: number;
9
+ constructor({ code, message, status, }: {
10
+ code: PlatformMachineErrorCode;
11
+ message: string;
12
+ status: number;
13
+ });
14
+ }
15
+ declare class AirJamStoredPlatformSessionError extends Error {
16
+ readonly storagePath: string;
17
+ constructor(storagePath: string, cause: unknown);
18
+ }
19
+ declare const resolvePlatformBaseUrl: (value?: string | undefined) => string;
20
+ declare const requestPlatformMachineApi: <T>({ baseUrl, pathname, method, body, token, schema, }: {
21
+ baseUrl: string;
22
+ pathname: string;
23
+ method?: "GET" | "POST" | "PATCH";
24
+ body?: unknown;
25
+ token?: string;
26
+ schema: {
27
+ parse: (value: unknown) => T;
28
+ };
29
+ }) => Promise<T>;
30
+ declare const readStoredPlatformMachineSession: () => Promise<AirJamPlatformMachineSessionStore | null>;
31
+ declare const writeStoredPlatformMachineSession: (value: AirJamPlatformMachineSessionStore) => Promise<void>;
32
+ declare const clearStoredPlatformMachineSession: () => Promise<void>;
33
+ declare const startPlatformDeviceAuthorization: ({ platformUrl, clientName, }?: StartPlatformDeviceAuthorizationOptions) => Promise<{
34
+ deviceCode: string;
35
+ userCode: string;
36
+ verificationUrl: string;
37
+ verificationUriComplete: string;
38
+ expiresAt: string;
39
+ intervalSeconds: number;
40
+ }>;
41
+ declare const pollPlatformDeviceAuthorization: ({ platformUrl, deviceCode, }: PollPlatformDeviceAuthorizationOptions) => Promise<{
42
+ platformBaseUrl: string;
43
+ user: {
44
+ id: string;
45
+ name: string;
46
+ email: string;
47
+ role: "creator" | "ops_admin";
48
+ };
49
+ session: {
50
+ id: string;
51
+ token: string;
52
+ expiresAt: string;
53
+ createdAt: string;
54
+ userAgent: string;
55
+ };
56
+ }>;
57
+ declare const loginPlatformWithDeviceFlow: ({ platformUrl, clientName, onPrompt, }?: LoginPlatformWithDeviceFlowOptions) => Promise<{
58
+ authorization: {
59
+ deviceCode: string;
60
+ userCode: string;
61
+ verificationUrl: string;
62
+ verificationUriComplete: string;
63
+ expiresAt: string;
64
+ intervalSeconds: number;
65
+ };
66
+ authenticated: {
67
+ platformBaseUrl: string;
68
+ user: {
69
+ id: string;
70
+ name: string;
71
+ email: string;
72
+ role: "creator" | "ops_admin";
73
+ };
74
+ session: {
75
+ id: string;
76
+ token: string;
77
+ expiresAt: string;
78
+ createdAt: string;
79
+ userAgent: string;
80
+ };
81
+ };
82
+ storedSession: AirJamPlatformMachineSessionStore;
83
+ }>;
84
+ declare const resolvePlatformMachineAuth: ({ platformUrl, token, }: {
85
+ platformUrl?: string;
86
+ token?: string;
87
+ }) => Promise<{
88
+ baseUrl: string;
89
+ token: string;
90
+ }>;
91
+ declare const getPlatformMachineProfile: ({ platformUrl, token, }?: GetPlatformMachineProfileOptions) => Promise<{
92
+ platformBaseUrl: string;
93
+ user: {
94
+ id: string;
95
+ name: string;
96
+ email: string;
97
+ role: "creator" | "ops_admin";
98
+ };
99
+ session: {
100
+ id: string;
101
+ expiresAt: string;
102
+ createdAt: string;
103
+ userAgent: string;
104
+ };
105
+ }>;
106
+ declare const logoutPlatformMachineSession: ({ platformUrl, token, }?: LogoutPlatformMachineSessionOptions) => Promise<{
107
+ ok: true;
108
+ }>;
109
+ declare const getPlatformMachineAuthStatus: () => Promise<AirJamPlatformAuthStatus>;
110
+ declare const getPlatformAuthStoragePath: () => string;
111
+
112
+ export { AirJamPlatformApiError, AirJamPlatformAuthStatus, AirJamPlatformMachineSessionStore, AirJamStoredPlatformSessionError, GetPlatformMachineProfileOptions, LoginPlatformWithDeviceFlowOptions, LogoutPlatformMachineSessionOptions, PollPlatformDeviceAuthorizationOptions, StartPlatformDeviceAuthorizationOptions, clearStoredPlatformMachineSession, getPlatformAuthStoragePath, getPlatformMachineAuthStatus, getPlatformMachineProfile, loginPlatformWithDeviceFlow, logoutPlatformMachineSession, pollPlatformDeviceAuthorization, readStoredPlatformMachineSession, requestPlatformMachineApi, resolveAirJamStateDirectory, resolvePlatformBaseUrl, resolvePlatformMachineAuth, startPlatformDeviceAuthorization, writeStoredPlatformMachineSession };
@@ -0,0 +1,37 @@
1
+ import {
2
+ AirJamPlatformApiError,
3
+ AirJamStoredPlatformSessionError,
4
+ clearStoredPlatformMachineSession,
5
+ getPlatformAuthStoragePath,
6
+ getPlatformMachineAuthStatus,
7
+ getPlatformMachineProfile,
8
+ loginPlatformWithDeviceFlow,
9
+ logoutPlatformMachineSession,
10
+ pollPlatformDeviceAuthorization,
11
+ readStoredPlatformMachineSession,
12
+ requestPlatformMachineApi,
13
+ resolveAirJamStateDirectory,
14
+ resolvePlatformBaseUrl,
15
+ resolvePlatformMachineAuth,
16
+ startPlatformDeviceAuthorization,
17
+ writeStoredPlatformMachineSession
18
+ } from "./chunk-VKMJO6VN.js";
19
+ export {
20
+ AirJamPlatformApiError,
21
+ AirJamStoredPlatformSessionError,
22
+ clearStoredPlatformMachineSession,
23
+ getPlatformAuthStoragePath,
24
+ getPlatformMachineAuthStatus,
25
+ getPlatformMachineProfile,
26
+ loginPlatformWithDeviceFlow,
27
+ logoutPlatformMachineSession,
28
+ pollPlatformDeviceAuthorization,
29
+ readStoredPlatformMachineSession,
30
+ requestPlatformMachineApi,
31
+ resolveAirJamStateDirectory,
32
+ resolvePlatformBaseUrl,
33
+ resolvePlatformMachineAuth,
34
+ startPlatformDeviceAuthorization,
35
+ writeStoredPlatformMachineSession
36
+ };
37
+ //# sourceMappingURL=platform-auth.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -0,0 +1,309 @@
1
+ import { a9 as InspectPlatformGameMediaOptions, aa as RequestPlatformGameMediaUploadTargetOptions, ab as MutatePlatformGameMediaAssetOptions, ac as UploadPlatformGameMediaFileOptions } from './types-C6NrHt88.js';
2
+ import '@air-jam/sdk';
3
+ import '@air-jam/sdk/platform-machine';
4
+
5
+ declare const inspectPlatformGameMedia: ({ platformUrl, token, slugOrId, }: InspectPlatformGameMediaOptions) => Promise<{
6
+ game: {
7
+ id: string;
8
+ slug: string | null;
9
+ name: string;
10
+ description: string | null;
11
+ url: string | null;
12
+ arcadeVisibility: "hidden" | "listed";
13
+ sourceUrl: string | null;
14
+ templateId: string | null;
15
+ createdAt: string;
16
+ updatedAt: string;
17
+ };
18
+ active: {
19
+ thumbnailMediaAssetId: string | null;
20
+ coverMediaAssetId: string | null;
21
+ previewVideoMediaAssetId: string | null;
22
+ };
23
+ assets: {
24
+ id: string;
25
+ gameId: string;
26
+ kind: "cover" | "thumbnail" | "preview_video";
27
+ status: "ready" | "failed" | "draft" | "uploading" | "archived";
28
+ originalFilename: string;
29
+ mimeType: string;
30
+ sizeBytes: number;
31
+ checksum: string | null;
32
+ width: number | null;
33
+ height: number | null;
34
+ durationSeconds: number | null;
35
+ createdAt: string;
36
+ updatedAt: string;
37
+ activeAssetId: string | null;
38
+ isActive: boolean;
39
+ publicUrl: string | null;
40
+ }[];
41
+ }>;
42
+ declare const requestPlatformGameMediaUploadTarget: ({ platformUrl, token, slugOrId, input, }: RequestPlatformGameMediaUploadTargetOptions) => Promise<{
43
+ game: {
44
+ id: string;
45
+ slug: string | null;
46
+ name: string;
47
+ description: string | null;
48
+ url: string | null;
49
+ arcadeVisibility: "hidden" | "listed";
50
+ sourceUrl: string | null;
51
+ templateId: string | null;
52
+ createdAt: string;
53
+ updatedAt: string;
54
+ };
55
+ asset: {
56
+ id: string;
57
+ gameId: string;
58
+ kind: "cover" | "thumbnail" | "preview_video";
59
+ status: "ready" | "failed" | "draft" | "uploading" | "archived";
60
+ originalFilename: string;
61
+ mimeType: string;
62
+ sizeBytes: number;
63
+ checksum: string | null;
64
+ width: number | null;
65
+ height: number | null;
66
+ durationSeconds: number | null;
67
+ createdAt: string;
68
+ updatedAt: string;
69
+ activeAssetId: string | null;
70
+ isActive: boolean;
71
+ publicUrl: string | null;
72
+ };
73
+ upload: {
74
+ method: "PUT";
75
+ url: string;
76
+ headers: Record<string, string>;
77
+ expiresAt: string;
78
+ };
79
+ }>;
80
+ declare const finalizePlatformGameMediaUpload: (options: MutatePlatformGameMediaAssetOptions) => Promise<{
81
+ game: {
82
+ id: string;
83
+ slug: string | null;
84
+ name: string;
85
+ description: string | null;
86
+ url: string | null;
87
+ arcadeVisibility: "hidden" | "listed";
88
+ sourceUrl: string | null;
89
+ templateId: string | null;
90
+ createdAt: string;
91
+ updatedAt: string;
92
+ };
93
+ active: {
94
+ thumbnailMediaAssetId: string | null;
95
+ coverMediaAssetId: string | null;
96
+ previewVideoMediaAssetId: string | null;
97
+ };
98
+ asset: {
99
+ id: string;
100
+ gameId: string;
101
+ kind: "cover" | "thumbnail" | "preview_video";
102
+ status: "ready" | "failed" | "draft" | "uploading" | "archived";
103
+ originalFilename: string;
104
+ mimeType: string;
105
+ sizeBytes: number;
106
+ checksum: string | null;
107
+ width: number | null;
108
+ height: number | null;
109
+ durationSeconds: number | null;
110
+ createdAt: string;
111
+ updatedAt: string;
112
+ activeAssetId: string | null;
113
+ isActive: boolean;
114
+ publicUrl: string | null;
115
+ };
116
+ }>;
117
+ declare const assignPlatformGameMediaAsset: (options: MutatePlatformGameMediaAssetOptions) => Promise<{
118
+ game: {
119
+ id: string;
120
+ slug: string | null;
121
+ name: string;
122
+ description: string | null;
123
+ url: string | null;
124
+ arcadeVisibility: "hidden" | "listed";
125
+ sourceUrl: string | null;
126
+ templateId: string | null;
127
+ createdAt: string;
128
+ updatedAt: string;
129
+ };
130
+ active: {
131
+ thumbnailMediaAssetId: string | null;
132
+ coverMediaAssetId: string | null;
133
+ previewVideoMediaAssetId: string | null;
134
+ };
135
+ asset: {
136
+ id: string;
137
+ gameId: string;
138
+ kind: "cover" | "thumbnail" | "preview_video";
139
+ status: "ready" | "failed" | "draft" | "uploading" | "archived";
140
+ originalFilename: string;
141
+ mimeType: string;
142
+ sizeBytes: number;
143
+ checksum: string | null;
144
+ width: number | null;
145
+ height: number | null;
146
+ durationSeconds: number | null;
147
+ createdAt: string;
148
+ updatedAt: string;
149
+ activeAssetId: string | null;
150
+ isActive: boolean;
151
+ publicUrl: string | null;
152
+ };
153
+ }>;
154
+ declare const archivePlatformGameMediaAsset: (options: MutatePlatformGameMediaAssetOptions) => Promise<{
155
+ game: {
156
+ id: string;
157
+ slug: string | null;
158
+ name: string;
159
+ description: string | null;
160
+ url: string | null;
161
+ arcadeVisibility: "hidden" | "listed";
162
+ sourceUrl: string | null;
163
+ templateId: string | null;
164
+ createdAt: string;
165
+ updatedAt: string;
166
+ };
167
+ active: {
168
+ thumbnailMediaAssetId: string | null;
169
+ coverMediaAssetId: string | null;
170
+ previewVideoMediaAssetId: string | null;
171
+ };
172
+ asset: {
173
+ id: string;
174
+ gameId: string;
175
+ kind: "cover" | "thumbnail" | "preview_video";
176
+ status: "ready" | "failed" | "draft" | "uploading" | "archived";
177
+ originalFilename: string;
178
+ mimeType: string;
179
+ sizeBytes: number;
180
+ checksum: string | null;
181
+ width: number | null;
182
+ height: number | null;
183
+ durationSeconds: number | null;
184
+ createdAt: string;
185
+ updatedAt: string;
186
+ activeAssetId: string | null;
187
+ isActive: boolean;
188
+ publicUrl: string | null;
189
+ };
190
+ }>;
191
+ declare const uploadPlatformGameMediaFile: ({ platformUrl, token, slugOrId, kind, filePath, }: UploadPlatformGameMediaFileOptions) => Promise<{
192
+ requested: {
193
+ game: {
194
+ id: string;
195
+ slug: string | null;
196
+ name: string;
197
+ description: string | null;
198
+ url: string | null;
199
+ arcadeVisibility: "hidden" | "listed";
200
+ sourceUrl: string | null;
201
+ templateId: string | null;
202
+ createdAt: string;
203
+ updatedAt: string;
204
+ };
205
+ asset: {
206
+ id: string;
207
+ gameId: string;
208
+ kind: "cover" | "thumbnail" | "preview_video";
209
+ status: "ready" | "failed" | "draft" | "uploading" | "archived";
210
+ originalFilename: string;
211
+ mimeType: string;
212
+ sizeBytes: number;
213
+ checksum: string | null;
214
+ width: number | null;
215
+ height: number | null;
216
+ durationSeconds: number | null;
217
+ createdAt: string;
218
+ updatedAt: string;
219
+ activeAssetId: string | null;
220
+ isActive: boolean;
221
+ publicUrl: string | null;
222
+ };
223
+ upload: {
224
+ method: "PUT";
225
+ url: string;
226
+ headers: Record<string, string>;
227
+ expiresAt: string;
228
+ };
229
+ };
230
+ finalized: {
231
+ game: {
232
+ id: string;
233
+ slug: string | null;
234
+ name: string;
235
+ description: string | null;
236
+ url: string | null;
237
+ arcadeVisibility: "hidden" | "listed";
238
+ sourceUrl: string | null;
239
+ templateId: string | null;
240
+ createdAt: string;
241
+ updatedAt: string;
242
+ };
243
+ active: {
244
+ thumbnailMediaAssetId: string | null;
245
+ coverMediaAssetId: string | null;
246
+ previewVideoMediaAssetId: string | null;
247
+ };
248
+ asset: {
249
+ id: string;
250
+ gameId: string;
251
+ kind: "cover" | "thumbnail" | "preview_video";
252
+ status: "ready" | "failed" | "draft" | "uploading" | "archived";
253
+ originalFilename: string;
254
+ mimeType: string;
255
+ sizeBytes: number;
256
+ checksum: string | null;
257
+ width: number | null;
258
+ height: number | null;
259
+ durationSeconds: number | null;
260
+ createdAt: string;
261
+ updatedAt: string;
262
+ activeAssetId: string | null;
263
+ isActive: boolean;
264
+ publicUrl: string | null;
265
+ };
266
+ };
267
+ assigned: {
268
+ game: {
269
+ id: string;
270
+ slug: string | null;
271
+ name: string;
272
+ description: string | null;
273
+ url: string | null;
274
+ arcadeVisibility: "hidden" | "listed";
275
+ sourceUrl: string | null;
276
+ templateId: string | null;
277
+ createdAt: string;
278
+ updatedAt: string;
279
+ };
280
+ active: {
281
+ thumbnailMediaAssetId: string | null;
282
+ coverMediaAssetId: string | null;
283
+ previewVideoMediaAssetId: string | null;
284
+ };
285
+ asset: {
286
+ id: string;
287
+ gameId: string;
288
+ kind: "cover" | "thumbnail" | "preview_video";
289
+ status: "ready" | "failed" | "draft" | "uploading" | "archived";
290
+ originalFilename: string;
291
+ mimeType: string;
292
+ sizeBytes: number;
293
+ checksum: string | null;
294
+ width: number | null;
295
+ height: number | null;
296
+ durationSeconds: number | null;
297
+ createdAt: string;
298
+ updatedAt: string;
299
+ activeAssetId: string | null;
300
+ isActive: boolean;
301
+ publicUrl: string | null;
302
+ };
303
+ };
304
+ filePath: string;
305
+ sizeBytes: number;
306
+ contentType: string;
307
+ }>;
308
+
309
+ export { InspectPlatformGameMediaOptions, MutatePlatformGameMediaAssetOptions, RequestPlatformGameMediaUploadTargetOptions, UploadPlatformGameMediaFileOptions, archivePlatformGameMediaAsset, assignPlatformGameMediaAsset, finalizePlatformGameMediaUpload, inspectPlatformGameMedia, requestPlatformGameMediaUploadTarget, uploadPlatformGameMediaFile };
@@ -0,0 +1,168 @@
1
+ import {
2
+ requestPlatformMachineApi,
3
+ resolvePlatformMachineAuth
4
+ } from "./chunk-VKMJO6VN.js";
5
+
6
+ // src/platform-game-media.ts
7
+ import {
8
+ platformMachineGetOwnedGameMediaResultSchema,
9
+ platformMachineMutateOwnedGameMediaAssetResultSchema,
10
+ platformMachineRequestOwnedGameMediaUploadTargetResultSchema
11
+ } from "@air-jam/sdk/platform-machine";
12
+ import { readFile, stat } from "fs/promises";
13
+ import path from "path";
14
+ var MEDIA_FILE_CONTENT_TYPES = {
15
+ thumbnail: {
16
+ ".jpg": "image/jpeg",
17
+ ".jpeg": "image/jpeg",
18
+ ".png": "image/png",
19
+ ".webp": "image/webp"
20
+ },
21
+ cover: {
22
+ ".jpg": "image/jpeg",
23
+ ".jpeg": "image/jpeg",
24
+ ".png": "image/png",
25
+ ".webp": "image/webp"
26
+ },
27
+ preview_video: {
28
+ ".mp4": "video/mp4",
29
+ ".webm": "video/webm"
30
+ }
31
+ };
32
+ var inferMediaContentType = ({
33
+ kind,
34
+ filePath
35
+ }) => {
36
+ const extension = path.extname(filePath).toLowerCase();
37
+ const contentType = MEDIA_FILE_CONTENT_TYPES[kind][extension];
38
+ if (!contentType) {
39
+ throw new Error(
40
+ `Unsupported file extension for ${kind.replaceAll("_", " ")}: ${extension || "(none)"}`
41
+ );
42
+ }
43
+ return contentType;
44
+ };
45
+ var inspectPlatformGameMedia = async ({
46
+ platformUrl,
47
+ token,
48
+ slugOrId
49
+ }) => {
50
+ const resolved = await resolvePlatformMachineAuth({ platformUrl, token });
51
+ return requestPlatformMachineApi({
52
+ baseUrl: resolved.baseUrl,
53
+ pathname: `/api/cli/games/${encodeURIComponent(slugOrId)}/media`,
54
+ token: resolved.token,
55
+ schema: platformMachineGetOwnedGameMediaResultSchema
56
+ });
57
+ };
58
+ var requestPlatformGameMediaUploadTarget = async ({
59
+ platformUrl,
60
+ token,
61
+ slugOrId,
62
+ input
63
+ }) => {
64
+ const resolved = await resolvePlatformMachineAuth({ platformUrl, token });
65
+ return requestPlatformMachineApi({
66
+ baseUrl: resolved.baseUrl,
67
+ pathname: `/api/cli/games/${encodeURIComponent(slugOrId)}/media`,
68
+ method: "POST",
69
+ token: resolved.token,
70
+ body: input,
71
+ schema: platformMachineRequestOwnedGameMediaUploadTargetResultSchema
72
+ });
73
+ };
74
+ var mutatePlatformGameMediaAsset = async ({
75
+ platformUrl,
76
+ token,
77
+ slugOrId,
78
+ assetId,
79
+ action
80
+ }) => {
81
+ const resolved = await resolvePlatformMachineAuth({ platformUrl, token });
82
+ return requestPlatformMachineApi({
83
+ baseUrl: resolved.baseUrl,
84
+ pathname: `/api/cli/games/${encodeURIComponent(slugOrId)}/media/${encodeURIComponent(assetId)}/${action}`,
85
+ method: "POST",
86
+ token: resolved.token,
87
+ schema: platformMachineMutateOwnedGameMediaAssetResultSchema
88
+ });
89
+ };
90
+ var finalizePlatformGameMediaUpload = (options) => mutatePlatformGameMediaAsset({
91
+ ...options,
92
+ action: "finalize"
93
+ });
94
+ var assignPlatformGameMediaAsset = (options) => mutatePlatformGameMediaAsset({
95
+ ...options,
96
+ action: "assign"
97
+ });
98
+ var archivePlatformGameMediaAsset = (options) => mutatePlatformGameMediaAsset({
99
+ ...options,
100
+ action: "archive"
101
+ });
102
+ var uploadPlatformGameMediaFile = async ({
103
+ platformUrl,
104
+ token,
105
+ slugOrId,
106
+ kind,
107
+ filePath
108
+ }) => {
109
+ const resolvedFilePath = path.resolve(filePath);
110
+ const fileStats = await stat(resolvedFilePath);
111
+ if (!fileStats.isFile()) {
112
+ throw new Error(`Media path is not a file: ${resolvedFilePath}`);
113
+ }
114
+ const contentType = inferMediaContentType({
115
+ kind,
116
+ filePath: resolvedFilePath
117
+ });
118
+ const created = await requestPlatformGameMediaUploadTarget({
119
+ platformUrl,
120
+ token,
121
+ slugOrId,
122
+ input: {
123
+ kind,
124
+ originalFilename: path.basename(resolvedFilePath),
125
+ contentType,
126
+ sizeBytes: fileStats.size
127
+ }
128
+ });
129
+ const uploadResponse = await fetch(created.upload.url, {
130
+ method: created.upload.method,
131
+ headers: created.upload.headers,
132
+ body: await readFile(resolvedFilePath)
133
+ });
134
+ if (!uploadResponse.ok) {
135
+ throw new Error(
136
+ `Media upload failed with status ${uploadResponse.status}.`
137
+ );
138
+ }
139
+ const finalized = await finalizePlatformGameMediaUpload({
140
+ platformUrl,
141
+ token,
142
+ slugOrId,
143
+ assetId: created.asset.id
144
+ });
145
+ const assigned = await assignPlatformGameMediaAsset({
146
+ platformUrl,
147
+ token,
148
+ slugOrId,
149
+ assetId: created.asset.id
150
+ });
151
+ return {
152
+ requested: created,
153
+ finalized,
154
+ assigned,
155
+ filePath: resolvedFilePath,
156
+ sizeBytes: fileStats.size,
157
+ contentType
158
+ };
159
+ };
160
+ export {
161
+ archivePlatformGameMediaAsset,
162
+ assignPlatformGameMediaAsset,
163
+ finalizePlatformGameMediaUpload,
164
+ inspectPlatformGameMedia,
165
+ requestPlatformGameMediaUploadTarget,
166
+ uploadPlatformGameMediaFile
167
+ };
168
+ //# sourceMappingURL=platform-game-media.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/platform-game-media.ts"],"sourcesContent":["import {\n platformMachineGetOwnedGameMediaResultSchema,\n platformMachineMutateOwnedGameMediaAssetResultSchema,\n platformMachineRequestOwnedGameMediaUploadTargetResultSchema,\n} from \"@air-jam/sdk/platform-machine\";\nimport { readFile, stat } from \"node:fs/promises\";\nimport path from \"node:path\";\nimport {\n requestPlatformMachineApi,\n resolvePlatformMachineAuth,\n} from \"./platform-auth.js\";\nimport type {\n InspectPlatformGameMediaOptions,\n MutatePlatformGameMediaAssetOptions,\n RequestPlatformGameMediaUploadTargetOptions,\n UploadPlatformGameMediaFileOptions,\n} from \"./types.js\";\n\nexport type {\n InspectPlatformGameMediaOptions,\n MutatePlatformGameMediaAssetOptions,\n RequestPlatformGameMediaUploadTargetOptions,\n UploadPlatformGameMediaFileOptions,\n} from \"./types.js\";\n\nconst MEDIA_FILE_CONTENT_TYPES: Record<\n \"thumbnail\" | \"cover\" | \"preview_video\",\n Record<string, string>\n> = {\n thumbnail: {\n \".jpg\": \"image/jpeg\",\n \".jpeg\": \"image/jpeg\",\n \".png\": \"image/png\",\n \".webp\": \"image/webp\",\n },\n cover: {\n \".jpg\": \"image/jpeg\",\n \".jpeg\": \"image/jpeg\",\n \".png\": \"image/png\",\n \".webp\": \"image/webp\",\n },\n preview_video: {\n \".mp4\": \"video/mp4\",\n \".webm\": \"video/webm\",\n },\n};\n\nconst inferMediaContentType = ({\n kind,\n filePath,\n}: {\n kind: \"thumbnail\" | \"cover\" | \"preview_video\";\n filePath: string;\n}): string => {\n const extension = path.extname(filePath).toLowerCase();\n const contentType = MEDIA_FILE_CONTENT_TYPES[kind][extension];\n\n if (!contentType) {\n throw new Error(\n `Unsupported file extension for ${kind.replaceAll(\"_\", \" \")}: ${extension || \"(none)\"}`,\n );\n }\n\n return contentType;\n};\n\nexport const inspectPlatformGameMedia = async ({\n platformUrl,\n token,\n slugOrId,\n}: InspectPlatformGameMediaOptions) => {\n const resolved = await resolvePlatformMachineAuth({ platformUrl, token });\n\n return requestPlatformMachineApi({\n baseUrl: resolved.baseUrl,\n pathname: `/api/cli/games/${encodeURIComponent(slugOrId)}/media`,\n token: resolved.token,\n schema: platformMachineGetOwnedGameMediaResultSchema,\n });\n};\n\nexport const requestPlatformGameMediaUploadTarget = async ({\n platformUrl,\n token,\n slugOrId,\n input,\n}: RequestPlatformGameMediaUploadTargetOptions) => {\n const resolved = await resolvePlatformMachineAuth({ platformUrl, token });\n\n return requestPlatformMachineApi({\n baseUrl: resolved.baseUrl,\n pathname: `/api/cli/games/${encodeURIComponent(slugOrId)}/media`,\n method: \"POST\",\n token: resolved.token,\n body: input,\n schema: platformMachineRequestOwnedGameMediaUploadTargetResultSchema,\n });\n};\n\nconst mutatePlatformGameMediaAsset = async ({\n platformUrl,\n token,\n slugOrId,\n assetId,\n action,\n}: MutatePlatformGameMediaAssetOptions & {\n action: \"finalize\" | \"assign\" | \"archive\";\n}) => {\n const resolved = await resolvePlatformMachineAuth({ platformUrl, token });\n\n return requestPlatformMachineApi({\n baseUrl: resolved.baseUrl,\n pathname: `/api/cli/games/${encodeURIComponent(slugOrId)}/media/${encodeURIComponent(assetId)}/${action}`,\n method: \"POST\",\n token: resolved.token,\n schema: platformMachineMutateOwnedGameMediaAssetResultSchema,\n });\n};\n\nexport const finalizePlatformGameMediaUpload = (\n options: MutatePlatformGameMediaAssetOptions,\n) =>\n mutatePlatformGameMediaAsset({\n ...options,\n action: \"finalize\",\n });\n\nexport const assignPlatformGameMediaAsset = (\n options: MutatePlatformGameMediaAssetOptions,\n) =>\n mutatePlatformGameMediaAsset({\n ...options,\n action: \"assign\",\n });\n\nexport const archivePlatformGameMediaAsset = (\n options: MutatePlatformGameMediaAssetOptions,\n) =>\n mutatePlatformGameMediaAsset({\n ...options,\n action: \"archive\",\n });\n\nexport const uploadPlatformGameMediaFile = async ({\n platformUrl,\n token,\n slugOrId,\n kind,\n filePath,\n}: UploadPlatformGameMediaFileOptions) => {\n const resolvedFilePath = path.resolve(filePath);\n const fileStats = await stat(resolvedFilePath);\n\n if (!fileStats.isFile()) {\n throw new Error(`Media path is not a file: ${resolvedFilePath}`);\n }\n\n const contentType = inferMediaContentType({\n kind,\n filePath: resolvedFilePath,\n });\n\n const created = await requestPlatformGameMediaUploadTarget({\n platformUrl,\n token,\n slugOrId,\n input: {\n kind,\n originalFilename: path.basename(resolvedFilePath),\n contentType,\n sizeBytes: fileStats.size,\n },\n });\n\n const uploadResponse = await fetch(created.upload.url, {\n method: created.upload.method,\n headers: created.upload.headers,\n body: await readFile(resolvedFilePath),\n });\n\n if (!uploadResponse.ok) {\n throw new Error(\n `Media upload failed with status ${uploadResponse.status}.`,\n );\n }\n\n const finalized = await finalizePlatformGameMediaUpload({\n platformUrl,\n token,\n slugOrId,\n assetId: created.asset.id,\n });\n\n const assigned = await assignPlatformGameMediaAsset({\n platformUrl,\n token,\n slugOrId,\n assetId: created.asset.id,\n });\n\n return {\n requested: created,\n finalized,\n assigned,\n filePath: resolvedFilePath,\n sizeBytes: fileStats.size,\n contentType,\n };\n};\n"],"mappings":";;;;;;AAAA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,UAAU,YAAY;AAC/B,OAAO,UAAU;AAmBjB,IAAM,2BAGF;AAAA,EACF,WAAW;AAAA,IACT,QAAQ;AAAA,IACR,SAAS;AAAA,IACT,QAAQ;AAAA,IACR,SAAS;AAAA,EACX;AAAA,EACA,OAAO;AAAA,IACL,QAAQ;AAAA,IACR,SAAS;AAAA,IACT,QAAQ;AAAA,IACR,SAAS;AAAA,EACX;AAAA,EACA,eAAe;AAAA,IACb,QAAQ;AAAA,IACR,SAAS;AAAA,EACX;AACF;AAEA,IAAM,wBAAwB,CAAC;AAAA,EAC7B;AAAA,EACA;AACF,MAGc;AACZ,QAAM,YAAY,KAAK,QAAQ,QAAQ,EAAE,YAAY;AACrD,QAAM,cAAc,yBAAyB,IAAI,EAAE,SAAS;AAE5D,MAAI,CAAC,aAAa;AAChB,UAAM,IAAI;AAAA,MACR,kCAAkC,KAAK,WAAW,KAAK,GAAG,CAAC,KAAK,aAAa,QAAQ;AAAA,IACvF;AAAA,EACF;AAEA,SAAO;AACT;AAEO,IAAM,2BAA2B,OAAO;AAAA,EAC7C;AAAA,EACA;AAAA,EACA;AACF,MAAuC;AACrC,QAAM,WAAW,MAAM,2BAA2B,EAAE,aAAa,MAAM,C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