diff --git a/cloud/packages/core/src/actor.ts b/cloud/packages/core/src/actor.ts index 16720dde..943eeb47 100644 --- a/cloud/packages/core/src/actor.ts +++ b/cloud/packages/core/src/actor.ts @@ -1,9 +1,8 @@ import { Log } from "./utils"; -import { createContext } from "./context"; +import { Context } from "./context"; import { ErrorCodes, VisibleError } from "./error"; export namespace Actor { - export interface User { type: "user"; properties: { @@ -11,7 +10,7 @@ export namespace Actor { email: string; }; } - + export interface Steam { type: "steam"; properties: { @@ -42,10 +41,10 @@ export namespace Actor { export type Info = User | Public | Token | Machine | Steam; - export const Context = createContext(); + export const CurrentContext = Context.create(); export function userID() { - const actor = Context.use(); + const actor = CurrentContext.use(); if ("userID" in actor.properties) return actor.properties.userID; throw new VisibleError( "authentication", @@ -55,7 +54,7 @@ export namespace Actor { } export function steamID() { - const actor = Context.use(); + const actor = CurrentContext.use(); if ("steamID" in actor.properties) return actor.properties.steamID; throw new VisibleError( "authentication", @@ -65,7 +64,7 @@ export namespace Actor { } export function user() { - const actor = Context.use(); + const actor = CurrentContext.use(); if (actor.type == "user") return actor.properties; throw new VisibleError( "authentication", @@ -75,7 +74,7 @@ export namespace Actor { } export function teamID() { - const actor = Context.use(); + const actor = CurrentContext.use(); if ("teamID" in actor.properties) return actor.properties.teamID; throw new VisibleError( "authentication", @@ -85,7 +84,7 @@ export namespace Actor { } export function fingerprint() { - const actor = Context.use(); + const actor = CurrentContext.use(); if ("fingerprint" in actor.properties) return actor.properties.fingerprint; throw new VisibleError( "authentication", @@ -96,7 +95,7 @@ export namespace Actor { export function use() { try { - return Context.use(); + return CurrentContext.use(); } catch { return { type: "public", properties: {} } as Public; } @@ -117,7 +116,7 @@ export namespace Actor { T extends Info["type"], Next extends (...args: any) => any, >(type: T, properties: Extract["properties"], fn: Next) { - return Context.provide({ type, properties } as any, () => + return CurrentContext.provide({ type, properties } as any, () => Log.provide( { actor: type, @@ -127,4 +126,4 @@ export namespace Actor { ), ); } -} \ No newline at end of file +} diff --git a/cloud/packages/core/src/utils/log.ts b/cloud/packages/core/src/utils/log.ts index a4619bbb..b092d4fb 100644 --- a/cloud/packages/core/src/utils/log.ts +++ b/cloud/packages/core/src/utils/log.ts @@ -1,7 +1,7 @@ -import { createContext } from "../context"; +import { Context } from "../context"; export namespace Log { - const ctx = createContext<{ + const ctx = Context.create<{ tags: Record; }>(); @@ -42,7 +42,7 @@ export namespace Log { return result; }, tag(key: string, value: string) { - // Immutable update: return a fresh logger with updated tags + // Immutable update: return a fresh logger with updated tags return Log.create({ ...tags, [key]: value }); }, clone() { @@ -73,4 +73,4 @@ export namespace Log { return { tags: {} }; } } -} \ No newline at end of file +} diff --git a/cloud/packages/functions/sst-env.d.ts b/cloud/packages/functions/sst-env.d.ts index ad516d4d..5f7aa835 100644 --- a/cloud/packages/functions/sst-env.d.ts +++ b/cloud/packages/functions/sst-env.d.ts @@ -31,6 +31,7 @@ declare module "sst" { import * as cloudflare from "@cloudflare/workers-types"; declare module "sst" { export interface Resource { + "Auth": cloudflare.Service "AuthStorage": cloudflare.KVNamespace } } diff --git a/sst-env.d.ts b/sst-env.d.ts index ad516d4d..5f7aa835 100644 --- a/sst-env.d.ts +++ b/sst-env.d.ts @@ -31,6 +31,7 @@ declare module "sst" { import * as cloudflare from "@cloudflare/workers-types"; declare module "sst" { export interface Resource { + "Auth": cloudflare.Service "AuthStorage": cloudflare.KVNamespace } }