@ultrst-armada/kloks 2.2.7 → 2.2.9

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.
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "schema": 1,
3
3
  "packageName": "@ultrst-armada/kloks",
4
- "version": "2.2.7",
5
- "sourceCommit": "8e2d29a9204c32532face96a8ea36cec4eaba05f",
4
+ "version": "2.2.9",
5
+ "sourceCommit": "8fd058dee8dda59fe3cee4cf60b1d68803f52867",
6
6
  "releaseWorkflow": "npm Release",
7
- "workflowRunId": "44698999455"
7
+ "workflowRunId": "44814035725"
8
8
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ultrst-armada/kloks",
3
- "version": "2.2.7",
3
+ "version": "2.2.9",
4
4
  "private": false,
5
5
  "publishConfig": {
6
6
  "access": "public",
@@ -361,7 +361,7 @@
361
361
  "verify:package-exports": "node scripts/verify-package-exports.mjs"
362
362
  },
363
363
  "dependencies": {
364
- "@dinilmusick/gutts": "2.2.3",
364
+ "@dinilmusick/gutts": "2.2.4",
365
365
  "@jitl/quickjs-wasmfile-release-sync": "0.32.0",
366
366
  "@webcontainer/api": "^1.6.4",
367
367
  "quickjs-emscripten-core": "0.32.0",
@@ -1,23 +1,25 @@
1
+ /**
2
+ * All runtime configuration for ULTRST deployments is reached using these
3
+ * four canonical bindings. Application credentials are kept in the protected
4
+ * system database, never passed as Worker/Vercel/local environment variables.
5
+ */
1
6
  export interface CanonicalApplicationAuthEnvironment {
2
7
  APP_URL?: unknown;
3
8
  SYSTEM_DATABASE_URL?: unknown;
4
9
  SYSTEM_DATABASE_URL_2?: unknown;
5
10
  SYSTEM_DATABASE_URL_3?: unknown;
6
- LUTH_OAUTH_CLIENT_ID?: unknown;
7
- LUTH_OAUTH_CLIENT_SECRET?: unknown;
8
- LUTH_OAUTH_BFF_SECRET?: unknown;
9
11
  [key: string]: unknown;
10
12
  }
11
13
  /**
12
- * Single authoritative adapter from a verified application deployment to
13
- * Kloks' OAuth 2.1 BFF. App code must supply its compile-time canonical app ID
14
- * and trusted deployment bindings; never accept these from request JSON.
14
+ * Resolve a *fresh* application credential on every request. A revoked Luth
15
+ * client or removed origin stops new operations immediately, rather than
16
+ * remaining authorized by a stale in-memory credential cache.
15
17
  */
16
18
  export declare function createCanonicalApplicationOAuthBff(request: Request, env: CanonicalApplicationAuthEnvironment, applicationId: string): {
17
- start: (request: Request) => Promise<Response>;
18
- callback: (request: Request) => Promise<Response>;
19
- getSession: (request: Request) => Promise<import("./OidcBff.js").OAuthBffSession | null>;
20
- session: (request: Request) => Promise<Response>;
21
- signOut: (request: Request) => Promise<Response>;
22
- handle: (request: Request) => Promise<Response | null>;
19
+ handle: (current: Request) => Promise<Response>;
20
+ getSession: (current: Request) => Promise<import("./OidcBff.js").OAuthBffSession>;
21
+ start: (current: Request) => Promise<Response>;
22
+ callback: (current: Request) => Promise<Response>;
23
+ session: (current: Request) => Promise<Response>;
24
+ signOut: (current: Request) => Promise<Response>;
23
25
  };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,55 @@
1
+ /** Structural invocation type only. The actual wire validator lives in GutTS. */
2
+ type UniversalRuntimeKind = 'browser' | 'cloudflare-worker' | 'serverless' | 'server' | 'desktop' | 'android' | 'ios' | 'headless';
3
+ type UniversalAuthReadiness = 'discovery' | 'unauthenticated' | 'authenticating' | 'authenticated' | 'configuring' | 'ready' | 'denied' | 'unavailable';
4
+ interface UniversalDiscoveryV1 {
5
+ application: {
6
+ appId: string;
7
+ ecosystemId: string;
8
+ name: string;
9
+ };
10
+ issuer: string;
11
+ configurationUrl: string;
12
+ }
13
+ interface UniversalConfigurationV1 {
14
+ application: {
15
+ appId: string;
16
+ ecosystemId: string;
17
+ name: string;
18
+ };
19
+ principal: {
20
+ userId: string;
21
+ };
22
+ settings: {
23
+ supportedServices: string[];
24
+ };
25
+ }
26
+ /**
27
+ * Canonical Kloks service for public discovery and least-privilege user
28
+ * configuration. All schema validation, issuer pinning and retries live in
29
+ * GutTS; this runtime adapter does not recreate the identity protocol.
30
+ *
31
+ * This is NOT a way to fetch OAuth client secrets, BFF encryption keys, or
32
+ * database credentials. The existing OIDC BFF keeps its protected bootstrap
33
+ * until authenticated confidential workload provisioning is implemented.
34
+ */
35
+ export interface UniversalLuthRuntimeAdapter {
36
+ runtime: UniversalRuntimeKind;
37
+ appId: string;
38
+ /** Existing Luth issuer origin; pinned before accepting discovery URLs. */
39
+ issuerOrigin: string;
40
+ /** Adapter may supply verified session cookies or OAuth bearer transport. */
41
+ authorizationHeaders?: () => Promise<HeadersInit>;
42
+ /** Injectable URL for local and integration fixtures only. */
43
+ discoveryUrl?: string;
44
+ fetcher?: typeof fetch;
45
+ onStateChange?: (state: UniversalAuthReadiness) => void;
46
+ }
47
+ export interface UniversalLuthRuntimeService {
48
+ discover(): Promise<UniversalDiscoveryV1>;
49
+ getConfiguration(): Promise<UniversalConfigurationV1>;
50
+ invalidate(): void;
51
+ readonly readiness: UniversalAuthReadiness;
52
+ }
53
+ /** Runtime privilege is never inferred from app ID or APP_URL. */
54
+ export declare function createUniversalLuthRuntimeService(adapter: UniversalLuthRuntimeAdapter): UniversalLuthRuntimeService;
55
+ export {};
@@ -2,3 +2,4 @@ export * from './CanonicalAuthClient.js';
2
2
  export * from './UnifiedAuthCore.js';
3
3
  export * from './OidcBff.js';
4
4
  export * from './OidcBffEnv.js';
5
+ export * from './UniversalLuthInitialization.js';
@@ -1,16 +1,17 @@
1
1
  import {
2
2
  createCanonicalApplicationOAuthBff,
3
3
  createOAuthBff
4
- } from "../chunk-SEKPSCWP.js";
4
+ } from "../chunk-AKVBFHHD.js";
5
5
  import {
6
6
  LuthAuthClient,
7
7
  LuthAuthClient2,
8
8
  LuthAuthError,
9
9
  createLuthAuthClient,
10
10
  createLuthAuthClient2,
11
+ createUniversalLuthRuntimeService,
11
12
  resolveClientEnvironment,
12
13
  resolveClientOrigin
13
- } from "../chunk-Y7ZE6D5H.js";
14
+ } from "../chunk-MDTLU7H4.js";
14
15
  import {
15
16
  loginSystemUser,
16
17
  resolveUserFromToken
@@ -23,6 +24,7 @@ export {
23
24
  createLuthAuthClient2 as createCanonicalAuthClient,
24
25
  createLuthAuthClient,
25
26
  createOAuthBff,
27
+ createUniversalLuthRuntimeService,
26
28
  loginSystemUser,
27
29
  resolveClientEnvironment,
28
30
  resolveClientOrigin,
@@ -314,34 +314,82 @@ function createOAuthBff(config) {
314
314
  import { neon } from "@neondatabase/serverless";
315
315
  import { DEFAULT_LUTH_URL } from "@dinilmusick/gutts/auth";
316
316
  function createCanonicalApplicationOAuthBff(request, env, applicationId) {
317
- if (!/^[a-z0-9][a-z0-9_-]{0,119}$/.test(applicationId)) throw new Error("INVALID_APP_ID");
318
- const origin = String(env.APP_URL || "").trim();
319
- const clientId = String(env.LUTH_OAUTH_CLIENT_ID || "").trim();
320
- const clientSecret = String(env.LUTH_OAUTH_CLIENT_SECRET || "").trim();
321
- const secret = String(env.LUTH_OAUTH_BFF_SECRET || "");
322
- const dbUrl = String(env.SYSTEM_DATABASE_URL || env.SYSTEM_DATABASE_URL_2 || env.SYSTEM_DATABASE_URL_3 || "");
323
- if (!origin || !clientId || !clientSecret || secret.length < 32 || !dbUrl) {
324
- throw new Error("CANONICAL_APP_AUTH_NOT_PROVISIONED");
317
+ if (!/^[a-z0-9][a-z0-9_-]{0,119}$/.test(applicationId)) {
318
+ throw new Error("INVALID_APP_ID");
325
319
  }
320
+ const origin = String(env.APP_URL || "").trim();
321
+ const candidates = [
322
+ env.SYSTEM_DATABASE_URL,
323
+ env.SYSTEM_DATABASE_URL_2,
324
+ env.SYSTEM_DATABASE_URL_3
325
+ ].filter((value) => typeof value === "string" && !!value.trim()).map((value) => value.trim());
326
+ if (!origin || !candidates.length) throw new Error("CANONICAL_APP_AUTH_NOT_PROVISIONED");
326
327
  const verifiedOrigin = new URL(origin);
327
328
  if (verifiedOrigin.origin !== origin.replace(/\/$/, "") || !["http:", "https:"].includes(verifiedOrigin.protocol) || new URL(request.url).origin !== verifiedOrigin.origin) {
328
329
  throw new Error("APPLICATION_ORIGIN_MISMATCH");
329
330
  }
330
- const sql = neon(dbUrl);
331
- return createOAuthBff({
332
- appId: applicationId,
333
- issuer: DEFAULT_LUTH_URL.replace(/\/$/, "") + "/api/auth",
334
- clientId,
335
- clientSecret,
336
- redirectUri: verifiedOrigin.origin + "/api/auth/oidc/callback",
337
- encryptionSecret: secret,
338
- database: {
339
- async query(statement, values) {
340
- const rows = await sql(statement, [...values]);
341
- return { rows: [...rows] };
331
+ async function resolve(current) {
332
+ if (new URL(current.url).origin !== verifiedOrigin.origin) {
333
+ throw new Error("APPLICATION_ORIGIN_MISMATCH");
334
+ }
335
+ const settingsKey = applicationId + "|" + verifiedOrigin.origin;
336
+ const statement = `
337
+ SELECT c."clientId" AS client_id,
338
+ cred.credentials #> ARRAY['applicationOAuth', $3::text] AS settings
339
+ FROM public."ultrst-apps" a
340
+ JOIN public.luth_ecosystems e ON e.id = a.ecosystem_id
341
+ JOIN public.luth_auth_origins o
342
+ ON o.app_id = a.app_id AND o.ecosystem_id = a.ecosystem_id
343
+ JOIN public."oauthClient" c
344
+ ON c.metadata->>'appId' = a.app_id
345
+ AND c.metadata->>'origin' = o.origin
346
+ JOIN public."ultrst-credentials" cred ON cred.id = 'system'
347
+ WHERE a.app_id = $1 AND a.status = 'active' AND e.status = 'active'
348
+ AND o.origin = $2 AND o.enabled = true
349
+ AND COALESCE(c.disabled, false) = false
350
+ LIMIT 2
351
+ `;
352
+ let lastError;
353
+ for (const dbUrl of candidates) {
354
+ const sql = neon(dbUrl);
355
+ let rows;
356
+ try {
357
+ rows = [...await sql(statement, [applicationId, verifiedOrigin.origin, settingsKey])];
358
+ } catch (error) {
359
+ lastError = error;
360
+ continue;
342
361
  }
362
+ if (rows.length !== 1) throw new Error("CANONICAL_APP_AUTH_NOT_PROVISIONED");
363
+ const raw = rows[0].settings;
364
+ const credential = raw && typeof raw === "object" && !Array.isArray(raw) ? raw : {};
365
+ if (typeof credential.clientId !== "string" || typeof credential.clientSecret !== "string" || typeof credential.bffSecret !== "string" || credential.bffSecret.length < 32 || credential.clientId !== rows[0].client_id || !credential.clientSecret) {
366
+ throw new Error("CANONICAL_APP_AUTH_NOT_PROVISIONED");
367
+ }
368
+ return createOAuthBff({
369
+ appId: applicationId,
370
+ issuer: DEFAULT_LUTH_URL.replace(/\/$/, "") + "/api/auth",
371
+ clientId: credential.clientId,
372
+ clientSecret: credential.clientSecret,
373
+ redirectUri: verifiedOrigin.origin + "/api/auth/oidc/callback",
374
+ encryptionSecret: credential.bffSecret,
375
+ database: {
376
+ async query(query, values) {
377
+ const result = await sql(query, [...values]);
378
+ return { rows: [...result] };
379
+ }
380
+ }
381
+ });
343
382
  }
344
- });
383
+ throw new Error(lastError ? "SYSTEM_DATABASE_UNAVAILABLE" : "CANONICAL_APP_AUTH_NOT_PROVISIONED");
384
+ }
385
+ return {
386
+ handle: async (current) => (await resolve(current)).handle(current),
387
+ getSession: async (current) => (await resolve(current)).getSession(current),
388
+ start: async (current) => (await resolve(current)).start(current),
389
+ callback: async (current) => (await resolve(current)).callback(current),
390
+ session: async (current) => (await resolve(current)).session(current),
391
+ signOut: async (current) => (await resolve(current)).signOut(current)
392
+ };
345
393
  }
346
394
 
347
395
  export {
@@ -0,0 +1,58 @@
1
+ // src/auth/CanonicalAuthClient.ts
2
+ import {
3
+ LuthAuthClient,
4
+ createLuthAuthClient,
5
+ resolveClientOrigin,
6
+ resolveClientEnvironment
7
+ } from "@dinilmusick/gutts/auth";
8
+ import { LuthAuthError } from "@dinilmusick/gutts/auth";
9
+ import { LuthAuthClient as LuthAuthClient2 } from "@dinilmusick/gutts/auth";
10
+ import { createLuthAuthClient as createLuthAuthClient2 } from "@dinilmusick/gutts/auth";
11
+
12
+ // src/auth/UniversalLuthInitialization.ts
13
+ import * as PortableLuthAuth from "@dinilmusick/gutts/auth";
14
+ function requiredGutTSFactory() {
15
+ const source = PortableLuthAuth;
16
+ const factory = source.createUniversalInitializationClient;
17
+ if (typeof factory !== "function") {
18
+ throw new Error("UNIVERSAL_INITIALIZATION_CONTRACT_UNAVAILABLE");
19
+ }
20
+ return factory;
21
+ }
22
+ function createUniversalLuthRuntimeService(adapter) {
23
+ if (adapter.runtime === "headless") {
24
+ throw new Error("VERIFIED_WORKLOAD_AUTHENTICATION_REQUIRED");
25
+ }
26
+ const client = requiredGutTSFactory()(
27
+ {
28
+ appId: adapter.appId,
29
+ runtime: adapter.runtime,
30
+ ...adapter.discoveryUrl ? { discoveryUrl: adapter.discoveryUrl } : {}
31
+ },
32
+ {
33
+ expectedIssuerOrigin: adapter.issuerOrigin,
34
+ ...adapter.authorizationHeaders ? { authorize: adapter.authorizationHeaders } : {},
35
+ ...adapter.fetcher ? { fetcher: adapter.fetcher } : {},
36
+ ...adapter.onStateChange ? { onStateChange: adapter.onStateChange } : {}
37
+ }
38
+ );
39
+ return {
40
+ discover: () => client.discover(),
41
+ getConfiguration: () => client.configuration(),
42
+ invalidate: () => client.invalidate(),
43
+ get readiness() {
44
+ return client.readiness;
45
+ }
46
+ };
47
+ }
48
+
49
+ export {
50
+ LuthAuthClient,
51
+ createLuthAuthClient,
52
+ resolveClientOrigin,
53
+ resolveClientEnvironment,
54
+ LuthAuthError,
55
+ LuthAuthClient2,
56
+ createLuthAuthClient2,
57
+ createUniversalLuthRuntimeService
58
+ };
@@ -8,3 +8,4 @@ export * from './services/index.js';
8
8
  export * from './resolver/index.js';
9
9
  export type { Runtime, Deployment, FunctionSet, ServiceFacade, OrchestrationFn, BackendFacade, ServiceRegistryRecord, } from './architecture/types.js';
10
10
  export * from './provider-services/index.js';
11
+ export * from './auth/UniversalLuthInitialization.js';
@@ -105,9 +105,10 @@ import {
105
105
  LuthAuthError,
106
106
  createLuthAuthClient,
107
107
  createLuthAuthClient2,
108
+ createUniversalLuthRuntimeService,
108
109
  resolveClientEnvironment,
109
110
  resolveClientOrigin
110
- } from "./chunk-Y7ZE6D5H.js";
111
+ } from "./chunk-MDTLU7H4.js";
111
112
  import {
112
113
  BackendRegistry,
113
114
  ConcurrencyConflictError,
@@ -203,6 +204,7 @@ export {
203
204
  createLuthAuthClient,
204
205
  createProviderClient,
205
206
  createSSEResponse,
207
+ createUniversalLuthRuntimeService,
206
208
  b2DownloadFile as downloadBackblazeB2File,
207
209
  fetchCloudflareCapacity,
208
210
  fetchVercelCapacity,
@@ -93,7 +93,7 @@ import {
93
93
  import {
94
94
  createCanonicalApplicationOAuthBff,
95
95
  createOAuthBff
96
- } from "./chunk-SEKPSCWP.js";
96
+ } from "./chunk-AKVBFHHD.js";
97
97
  import {
98
98
  BackendProvider,
99
99
  useBackend,
@@ -138,9 +138,10 @@ import {
138
138
  LuthAuthError,
139
139
  createLuthAuthClient,
140
140
  createLuthAuthClient2,
141
+ createUniversalLuthRuntimeService,
141
142
  resolveClientEnvironment,
142
143
  resolveClientOrigin
143
- } from "./chunk-Y7ZE6D5H.js";
144
+ } from "./chunk-MDTLU7H4.js";
144
145
  import {
145
146
  BackendRegistry,
146
147
  ConcurrencyConflictError,
@@ -4750,6 +4751,7 @@ export {
4750
4751
  createRemoteService,
4751
4752
  createSSEResponse,
4752
4753
  createSrklClient,
4754
+ createUniversalLuthRuntimeService,
4753
4755
  createWavBuffer,
4754
4756
  createWorkspace,
4755
4757
  createWorkspaceGraph,
@@ -225,7 +225,7 @@
225
225
  "clean": "rm -rf dist"
226
226
  },
227
227
  "dependencies": {
228
- "@dinilmusick/gutts": "2.2.3",
228
+ "@dinilmusick/gutts": "2.2.4",
229
229
  "@kloks/functions": "workspace:*",
230
230
  "@kloks/state-graph": "workspace:*",
231
231
  "@webcontainer/api": "^1.6.4",
@@ -1,4 +1,5 @@
1
1
  import { DeploymentEnvironment } from '@dinilmusick/gutts/auth';
2
+ export * from '@dinilmusick/gutts/auth';
2
3
  export { ApplicationAuthClient, ApplicationAuthClientConfig, LuthAuthClient as CanonicalAuthClient, DEFAULT_LUTH_URL, DeploymentEnvironment, EmailSignInCredentials, EmailSignUpData, GoogleSignInOptions, LuthAuthClient, LuthAuthClientConfig, LuthAuthError, LuthAuthTokenStore, LuthSession, LuthSessionResult, LuthUser, RegisterApplicationResult, createApplicationAuthClient, createLuthAuthClient as createCanonicalAuthClient, createLuthAuthClient, hydrateLuthTokenFromUrl, resolveClientEnvironment, resolveClientOrigin } from '@dinilmusick/gutts/auth';
3
4
 
4
5
  interface LuthPrincipal {
@@ -15,7 +15,7 @@ import {
15
15
  resolveClientEnvironment,
16
16
  resolveClientOrigin,
17
17
  verifyLuthRequest
18
- } from "./chunk-WYC7RG32.js";
18
+ } from "./chunk-4HR374IB.js";
19
19
  export {
20
20
  ApplicationAuthClient,
21
21
  CANONICAL_PUBLIC_ROUTES,
@@ -103,6 +103,7 @@ async function verifyLuthRequest(request, options) {
103
103
  }
104
104
 
105
105
  // src/auth.ts
106
+ export * from "@dinilmusick/gutts/auth";
106
107
  function createUniversalAuthFetch(authClient) {
107
108
  return async function universalAuthFetch(input, init = {}) {
108
109
  const headers = new Headers();
@@ -1,4 +1,5 @@
1
1
  export { CANONICAL_PUBLIC_ROUTES, LuthDeploymentRecord, LuthPrincipal, createUniversalAuthFetch, extractLuthToken, isPublicRoute, verifyLuthRequest } from './auth.js';
2
+ export * from '@dinilmusick/gutts/auth';
2
3
  export { ApplicationAuthClient, ApplicationAuthClientConfig, LuthAuthClient as CanonicalAuthClient, DEFAULT_LUTH_URL, DeploymentEnvironment, EmailSignInCredentials, EmailSignUpData, GoogleSignInOptions, LuthAuthClient, LuthAuthClientConfig, LuthAuthError, LuthAuthTokenStore, LuthSession, LuthSessionResult, LuthUser, RegisterApplicationResult, createApplicationAuthClient, createLuthAuthClient as createCanonicalAuthClient, createLuthAuthClient, hydrateLuthTokenFromUrl, resolveClientEnvironment, resolveClientOrigin } from '@dinilmusick/gutts/auth';
3
4
 
4
5
  /**
@@ -15,7 +15,7 @@ import {
15
15
  resolveClientEnvironment,
16
16
  resolveClientOrigin,
17
17
  verifyLuthRequest
18
- } from "./chunk-WYC7RG32.js";
18
+ } from "./chunk-4HR374IB.js";
19
19
 
20
20
  // src/browserExecutionClient.ts
21
21
  var BrowserExecutionClient = class {
@@ -30,7 +30,7 @@
30
30
  "clean": "rm -rf dist"
31
31
  },
32
32
  "dependencies": {
33
- "@dinilmusick/gutts": "2.2.3",
33
+ "@dinilmusick/gutts": "2.2.4",
34
34
  "zod": "^3.24.1"
35
35
  },
36
36
  "peerDependencies": {
@@ -1,20 +0,0 @@
1
- // src/auth/CanonicalAuthClient.ts
2
- import {
3
- LuthAuthClient,
4
- createLuthAuthClient,
5
- resolveClientOrigin,
6
- resolveClientEnvironment
7
- } from "@dinilmusick/gutts/auth";
8
- import { LuthAuthError } from "@dinilmusick/gutts/auth";
9
- import { LuthAuthClient as LuthAuthClient2 } from "@dinilmusick/gutts/auth";
10
- import { createLuthAuthClient as createLuthAuthClient2 } from "@dinilmusick/gutts/auth";
11
-
12
- export {
13
- LuthAuthClient,
14
- createLuthAuthClient,
15
- resolveClientOrigin,
16
- resolveClientEnvironment,
17
- LuthAuthError,
18
- LuthAuthClient2,
19
- createLuthAuthClient2
20
- };