mirror of
https://github.com/nestriness/nestri.git
synced 2026-12-02 03:56:13 +02:00
POST /steam/link took a Steam id from the request body and linked it. A Steam id is public, so anyone could claim any account, its library, and the one free weekend that is keyed on it. Linking is now POST /steam/link/start, which returns a Steam sign-in URL tied to a one-time, ten-minute request, and GET /steam/link/callback, where the browser comes back. The callback accepts the id only if Steam confirms the assertion, the assertion was issued for exactly this callback, and the id is read from Steam's claimed identity URL in the one shape Steam issues it. The request is spent on use.
100 lines
3.4 KiB
TypeScript
100 lines
3.4 KiB
TypeScript
import { z } from 'zod';
|
|
|
|
import { memo } from './utils/memo.js';
|
|
|
|
let _overrides: Record<string, unknown> = {};
|
|
|
|
export namespace Env {
|
|
export const Info = z.object({
|
|
NODE_ENV: z.enum(['development', 'production', 'test']).default('development'),
|
|
|
|
AUTH_ISSUER_URL: z.string().optional(),
|
|
|
|
/**
|
|
* Where to *reach* the issuer, when that is not where it *lives*.
|
|
*
|
|
* `AUTH_ISSUER_URL` is an identity: a token carries the address it was
|
|
* minted through and verification compares the two literally, so it is
|
|
* the public name and can be nothing else. But the public name is
|
|
* often not routable from inside a deployment — a container on a
|
|
* private network, a host behind its own proxy — and one setting
|
|
* cannot be both.
|
|
*
|
|
* So this one is the route and the other is the name, which is the
|
|
* same split a service binding makes on its own: the binding is the
|
|
* route, and the `iss` claim is still the name. Unset means they are
|
|
* the same address, which is the ordinary case.
|
|
*/
|
|
AUTH_INTERNAL_URL: z.string().optional(),
|
|
|
|
/**
|
|
* Burn allowances per plan, as JSON. Unset takes the placeholder set.
|
|
*
|
|
* Configuration rather than constants because these are retuned against
|
|
* real burn far more often than the code that reads them changes, and a
|
|
* rate that needs a deploy is a rate that stays wrong until the next one.
|
|
*/
|
|
BURN_LIMITS: z.string().optional(),
|
|
|
|
/**
|
|
* The payment provider.
|
|
*
|
|
* `POLAR_SERVER` picks the instance and the two are entirely separate
|
|
* servers with separate data, so a token from one is refused by the
|
|
* other and a product id from one means nothing to it. Getting this
|
|
* wrong fails loudly rather than quietly charging somebody.
|
|
*/
|
|
POLAR_ACCESS_TOKEN: z.string().optional(),
|
|
POLAR_WEBHOOK_SECRET: z.string().optional(),
|
|
POLAR_PRODUCT_ID: z.string().optional(),
|
|
/** The product a team is put on at signup, priced at nothing. */
|
|
POLAR_FREE_PRODUCT_ID: z.string().optional(),
|
|
POLAR_SERVER: z.enum(['sandbox', 'production']).optional(),
|
|
|
|
/**
|
|
* Where installable binaries are kept: an S3-compatible bucket that is
|
|
* never public. Downloads are answered with a short-lived signed URL,
|
|
* so every one passes through a route that can be logged or turned off.
|
|
* Scope the key to this bucket and to reads.
|
|
*/
|
|
RELEASES_BUCKET: z.string().optional(),
|
|
RELEASES_ENDPOINT: z.string().optional(),
|
|
RELEASES_REGION: z.string().default('us-east-1'),
|
|
RELEASES_ACCESS_KEY_ID: z.string().optional(),
|
|
RELEASES_SECRET_ACCESS_KEY: z.string().optional(),
|
|
|
|
DATABASE_URL: z.string().optional(),
|
|
/**
|
|
* The organisation whose machines are rented to customers: the fleet.
|
|
* Unset, nothing is placed on rented hardware. Configured per deploy,
|
|
* never written into the repository.
|
|
*/
|
|
FLEET_ORGANISATION_ID: z.string().optional(),
|
|
/**
|
|
* This API's public address, for URLs handed to a browser that must come
|
|
* back here (Steam's sign-in). Unset, the request's own host over https.
|
|
*/
|
|
API_URL: z.string().optional()
|
|
});
|
|
|
|
export type Info = z.infer<typeof Info>;
|
|
|
|
const _get = memo(() => Info.parse({ ...process.env, ..._overrides }));
|
|
|
|
export function get(): Info {
|
|
return _get();
|
|
}
|
|
|
|
export function init(bindings: Record<string, unknown>) {
|
|
_overrides = {
|
|
...bindings,
|
|
...(bindings.HYPERDRIVE
|
|
? {
|
|
DATABASE_URL: (bindings.HYPERDRIVE as { connectionString: string }).connectionString
|
|
}
|
|
: {})
|
|
};
|
|
_get.reset();
|
|
}
|
|
}
|