Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,22 @@
*/

import type { Context } from "~/context";
import { Gamedev } from "./api/generated/Gamedev";
import type { AuthManager } from "./auth";
import { GG_API } from "./config";
import { Gamedev } from "./generated/Gamedev";
import { GG_API } from "../config";

export const getApiClient = (ctx: Context, auth: AuthManager) =>
new Gamedev({
export { LinkStorage, type GxGamesLink } from "./storage";

export function getApiClient(
ctx: Context,
auth: {
getAccessToken(): Promise<string>;
},
) {
return new Gamedev({
customFetch: ctx.fetch,
baseUrl: GG_API,
securityWorker: async () => ({
headers: { Authorization: `Bearer ${await auth.getAccessToken()}` },
}),
});
}
60 changes: 60 additions & 0 deletions src/commands/gxgames/api/storage.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/**
* Copyright 2026, Opera Norway AS
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import type { Context } from "~/context";
import { KnownError } from "~/error";
import { Cache } from "~/cache";
import { z } from "zod";
import { CACHE_SUBDIR } from "../config";

const LINK_FILENAME = "link.json";

const LinkSchema = z.object({
studioId: z.string(),
gameId: z.string(),
});

export type GxGamesLink = z.infer<typeof LinkSchema>;

export class LinkStorage {
constructor(private readonly ctx: Context) {}

async read(): Promise<GxGamesLink> {
const cache = await Cache.initLazy(this.ctx, { type: "infer" });
const dir = await cache.getSubDirPath(this.ctx, CACHE_SUBDIR);
try {
const raw = await this.ctx.fs.readFile(
this.ctx.path.join(dir, LINK_FILENAME),
"utf-8",
);
return LinkSchema.parse(JSON.parse(raw));
} catch {
throw new KnownError(
"Game not linked. Run `gm-cli gxgames link --studioid <studio> --gameid <game>` first.",
);
}
}

async write(link: GxGamesLink): Promise<void> {
// TODO: later, we may want to store this as part of the "manifest" file instead under a "tools.gxgames" key.
const cache = await Cache.initLazy(this.ctx, { type: "infer" });
const dir = await cache.getSubDirPath(this.ctx, CACHE_SUBDIR);
await this.ctx.fs.writeFile(
this.ctx.path.join(dir, LINK_FILENAME),
JSON.stringify(link, null, 2),
);
}
}
130 changes: 0 additions & 130 deletions src/commands/gxgames/auth.ts

This file was deleted.

Empty file.
66 changes: 66 additions & 0 deletions src/commands/gxgames/auth/error.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>GX.games — Authentication Failed</title>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}

body {
background: #050305;
color: #e8e8e8;
font-family: "Segoe UI", system-ui, sans-serif;
display: flex;
align-items: center;
justify-content: center;
min-height: 100vh;
}

.card {
background: #111011;
border: 1px solid #222022;
border-top: 3px solid #6b7ff7;
border-radius: 6px;
padding: 40px 48px;
max-width: 380px;
width: 90%;
}

h1 {
font-size: 1.1rem;
font-weight: 600;
margin-bottom: 8px;
}

p {
font-size: 0.875rem;
color: #888;
line-height: 1.6;
margin-bottom: 16px;
}

.error-detail {
background: #050305;
border: 1px solid #222022;
border-radius: 4px;
padding: 10px 14px;
font-family: "Consolas", "Courier New", monospace;
font-size: 0.8rem;
color: #aaa;
word-break: break-word;
}
</style>
</head>
<body>
<div class="card">
<h1>Authentication failed</h1>
<p>Something went wrong. You can close this tab and try again.</p>
<div class="error-detail">{{ERROR_MESSAGE}}</div>
</div>
</body>
</html>
Loading
Loading