@ultrst-armada/kloks 2.2.7 → 2.2.8

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.8",
5
+ "sourceCommit": "5c29834311d8c525ec703ef51b34de2c50f54987",
6
6
  "releaseWorkflow": "npm Release",
7
- "workflowRunId": "44698999455"
7
+ "workflowRunId": "44742095336"
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.8",
4
4
  "private": false,
5
5
  "publishConfig": {
6
6
  "access": "public",
@@ -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 {};
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  createCanonicalApplicationOAuthBff,
3
3
  createOAuthBff
4
- } from "../chunk-SEKPSCWP.js";
4
+ } from "../chunk-NR7OXPB3.js";
5
5
  import {
6
6
  LuthAuthClient,
7
7
  LuthAuthClient2,
@@ -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 {
@@ -93,7 +93,7 @@ import {
93
93
  import {
94
94
  createCanonicalApplicationOAuthBff,
95
95
  createOAuthBff
96
- } from "./chunk-SEKPSCWP.js";
96
+ } from "./chunk-NR7OXPB3.js";
97
97
  import {
98
98
  BackendProvider,
99
99
  useBackend,
@@ -252,7 +252,7 @@ import {
252
252
  validateProjectGraph,
253
253
  validateUniversalConnection,
254
254
  zoomAtPoint
255
- } from "./chunk-UKTICGGV.js";
255
+ } from "./chunk-7N2LLBUW.js";
256
256
  import {
257
257
  BaseHandle,
258
258
  DataHandle,
@@ -261,7 +261,6 @@ import {
261
261
  ViewHandle,
262
262
  instantiateSubgraph
263
263
  } from "./chunk-OXUDG6HE.js";
264
- import "./chunk-RHRXPY2U.js";
265
264
  import {
266
265
  LifecycleCycleError,
267
266
  LifecycleGraph,
@@ -285,6 +284,7 @@ import {
285
284
  CustomViewWindow,
286
285
  DEFAULT_GRAPH_SETTINGS
287
286
  } from "./chunk-5KP74NMF.js";
287
+ import "./chunk-RHRXPY2U.js";
288
288
  import {
289
289
  AttractionEngine,
290
290
  GhostInferenceEngine,
@@ -294,12 +294,6 @@ import {
294
294
  getBeamPoints,
295
295
  useMagneticTraces
296
296
  } from "./chunk-JXDJZSFW.js";
297
- import {
298
- ConnectionRuleStore,
299
- HandleTypeRegistry,
300
- WireTypeRegistry,
301
- initializeDefaultGraphRules
302
- } from "./chunk-TZOL3RN7.js";
303
297
  import {
304
298
  AutoSolidify,
305
299
  SpatialEngine,
@@ -310,6 +304,12 @@ import {
310
304
  SolidConnection,
311
305
  ViewLink
312
306
  } from "./chunk-OYN4ZEZC.js";
307
+ import {
308
+ ConnectionRuleStore,
309
+ HandleTypeRegistry,
310
+ WireTypeRegistry,
311
+ initializeDefaultGraphRules
312
+ } from "./chunk-TZOL3RN7.js";
313
313
  import {
314
314
  CompatibilityMatrix
315
315
  } from "./chunk-ISFNY7EZ.js";
@@ -252,7 +252,7 @@ import {
252
252
  validateProjectGraph,
253
253
  validateUniversalConnection,
254
254
  zoomAtPoint
255
- } from "./chunk-UKTICGGV.js";
255
+ } from "./chunk-7N2LLBUW.js";
256
256
  import {
257
257
  BaseHandle,
258
258
  DataHandle,
@@ -261,7 +261,6 @@ import {
261
261
  ViewHandle,
262
262
  instantiateSubgraph
263
263
  } from "./chunk-OXUDG6HE.js";
264
- import "./chunk-RHRXPY2U.js";
265
264
  import {
266
265
  LifecycleCycleError,
267
266
  LifecycleGraph,
@@ -285,6 +284,7 @@ import {
285
284
  CustomViewWindow,
286
285
  DEFAULT_GRAPH_SETTINGS
287
286
  } from "./chunk-5KP74NMF.js";
287
+ import "./chunk-RHRXPY2U.js";
288
288
  import {
289
289
  AttractionEngine,
290
290
  GhostInferenceEngine,
@@ -294,12 +294,6 @@ import {
294
294
  getBeamPoints,
295
295
  useMagneticTraces
296
296
  } from "./chunk-JXDJZSFW.js";
297
- import {
298
- ConnectionRuleStore,
299
- HandleTypeRegistry,
300
- WireTypeRegistry,
301
- initializeDefaultGraphRules
302
- } from "./chunk-TZOL3RN7.js";
303
297
  import {
304
298
  AutoSolidify,
305
299
  SpatialEngine,
@@ -310,6 +304,12 @@ import {
310
304
  SolidConnection,
311
305
  ViewLink
312
306
  } from "./chunk-OYN4ZEZC.js";
307
+ import {
308
+ ConnectionRuleStore,
309
+ HandleTypeRegistry,
310
+ WireTypeRegistry,
311
+ initializeDefaultGraphRules
312
+ } from "./chunk-TZOL3RN7.js";
313
313
  import {
314
314
  CompatibilityMatrix
315
315
  } from "./chunk-ISFNY7EZ.js";
@@ -7,13 +7,13 @@ import {
7
7
  getBeamPoints,
8
8
  useMagneticTraces
9
9
  } from "../chunk-JXDJZSFW.js";
10
- import "../chunk-TZOL3RN7.js";
11
10
  import {
12
11
  AutoSolidify,
13
12
  SpatialEngine,
14
13
  TraceEngine
15
14
  } from "../chunk-OV4JVTNY.js";
16
15
  import "../chunk-OYN4ZEZC.js";
16
+ import "../chunk-TZOL3RN7.js";
17
17
  import "../chunk-ISFNY7EZ.js";
18
18
  export {
19
19
  AttractionEngine,
@@ -7,10 +7,6 @@ import {
7
7
  import {
8
8
  AttractionEngine
9
9
  } from "./chunk-JXDJZSFW.js";
10
- import {
11
- HandleTypeRegistry,
12
- WireTypeRegistry
13
- } from "./chunk-TZOL3RN7.js";
14
10
  import {
15
11
  AutoSolidify,
16
12
  TraceEngine
@@ -18,6 +14,10 @@ import {
18
14
  import {
19
15
  SolidConnection
20
16
  } from "./chunk-OYN4ZEZC.js";
17
+ import {
18
+ HandleTypeRegistry,
19
+ WireTypeRegistry
20
+ } from "./chunk-TZOL3RN7.js";
21
21
  import {
22
22
  CompatibilityMatrix
23
23
  } from "./chunk-ISFNY7EZ.js";