@urun-sh/next 0.2.32 → 0.2.34

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.
package/dist/index.d.cts CHANGED
@@ -1,5 +1,45 @@
1
1
  import { CreateClientTokenOptions } from '@urun-sh/core';
2
2
 
3
+ /**
4
+ * LOCAL-DEV credential resolution for the token route (owner ruling
5
+ * 2026-07-15: raw `pnpm dev` works without the CLI).
6
+ *
7
+ * Precedence:
8
+ * 1. `URUN_API_KEY` in the server env — the production contract, always.
9
+ * 2. DEV ONLY (`NODE_ENV === 'development'`, i.e. `next dev`): the urun
10
+ * CLI's own stored login credential, `~/.config/urun/credentials.json` —
11
+ * the SAME file `urun login` writes (same path rules: `URUN_CONFIG_HOME`,
12
+ * then `XDG_CONFIG_HOME/urun`, then `~/.config/urun`; same JSON shape:
13
+ * `{ api_key, api_url, ... }`). Never a second format, never active in
14
+ * production builds or deployed frontends.
15
+ *
16
+ * The login file also carries the control-plane `api_url`, from which the
17
+ * org's session gateway derives exactly like the CLI's `resolve_gateway_url`
18
+ * (strip a trailing `/v<N>` version segment) — so a dev-cluster login dials
19
+ * the dev gateway instead of silently defaulting to the prod front door.
20
+ */
21
+ /** Thrown when no credential exists anywhere — carries the actionable fix. */
22
+ declare class MissingCredentialError extends Error {
23
+ constructor();
24
+ }
25
+ interface ResolvedCredential {
26
+ apiKey: string;
27
+ /** Where the key came from — logged once, honestly. */
28
+ source: 'env' | 'urun-login';
29
+ /**
30
+ * Gateway derived FROM THE CREDENTIAL ITSELF (login-file `api_url` with the
31
+ * `/v<N>` control-plane path stripped). Undefined for env keys — the
32
+ * deployed contract stays `URUN_GATEWAY_URL`-or-platform-default.
33
+ */
34
+ gatewayUrl?: string;
35
+ }
36
+ /**
37
+ * Resolve the token route's org API key: env first, then (dev server only)
38
+ * the urun CLI login file. Exactly one honest log line states the source.
39
+ * Throws {@link MissingCredentialError} when neither exists.
40
+ */
41
+ declare function resolveCredential(env?: Record<string, string | undefined>): Promise<ResolvedCredential>;
42
+
3
43
  /**
4
44
  * @urun-sh/next — the Next.js on-ramp for uRun scoped client tokens.
5
45
  *
@@ -33,6 +73,8 @@ declare const URUN_API_KEY_ENV = "URUN_API_KEY";
33
73
  * provider as props.
34
74
  */
35
75
  declare const URUN_GATEWAY_URL_ENV = "URUN_GATEWAY_URL";
76
+ /** Server env var naming the API front door the token route MINTS against. */
77
+ declare const URUN_API_URL_ENV = "URUN_API_URL";
36
78
  declare const URUN_APP_ENV = "URUN_APP";
37
79
  declare const URUN_FUNCTION_ENV = "URUN_FUNCTION";
38
80
  /** The frontend's resolved session-plane config (see {@link urunSessionConfig}). */
@@ -158,4 +200,4 @@ declare function createTokenRoute(options?: CreateTokenRouteOptions): (request:
158
200
  */
159
201
  declare function urunTokenPagesHandler(options: UrunTokenRouteOptions): (req: UrunTokenPagesRequest, res: UrunTokenPagesResponse) => Promise<void>;
160
202
 
161
- export { type CreateTokenRouteOptions, type CreateTokenRouteResponseBody, URUN_API_KEY_ENV, URUN_APP_ENV, URUN_FUNCTION_ENV, URUN_GATEWAY_URL_ENV, type UrunSessionConfig, type UrunTokenPagesRequest, type UrunTokenPagesResponse, type UrunTokenResponseBody, type UrunTokenRouteOptions, createTokenRoute, urunSessionConfig, urunTokenPagesHandler, urunTokenRoute };
203
+ export { type CreateTokenRouteOptions, type CreateTokenRouteResponseBody, MissingCredentialError, URUN_API_KEY_ENV, URUN_API_URL_ENV, URUN_APP_ENV, URUN_FUNCTION_ENV, URUN_GATEWAY_URL_ENV, type UrunSessionConfig, type UrunTokenPagesRequest, type UrunTokenPagesResponse, type UrunTokenResponseBody, type UrunTokenRouteOptions, createTokenRoute, resolveCredential, urunSessionConfig, urunTokenPagesHandler, urunTokenRoute };
package/dist/index.d.ts CHANGED
@@ -1,8 +1,23 @@
1
1
  import { CreateClientTokenOptions } from '@urun-sh/core';
2
2
 
3
+ declare class MissingCredentialError extends Error {
4
+ constructor();
5
+ }
6
+ interface ResolvedCredential {
7
+ apiKey: string;
8
+
9
+ source: 'env' | 'urun-login';
10
+
11
+ gatewayUrl?: string;
12
+ }
13
+
14
+ declare function resolveCredential(env?: Record<string, string | undefined>): Promise<ResolvedCredential>;
15
+
3
16
  declare const URUN_API_KEY_ENV = "URUN_API_KEY";
4
17
 
5
18
  declare const URUN_GATEWAY_URL_ENV = "URUN_GATEWAY_URL";
19
+
20
+ declare const URUN_API_URL_ENV = "URUN_API_URL";
6
21
  declare const URUN_APP_ENV = "URUN_APP";
7
22
  declare const URUN_FUNCTION_ENV = "URUN_FUNCTION";
8
23
 
@@ -58,4 +73,4 @@ declare function createTokenRoute(options?: CreateTokenRouteOptions): (request:
58
73
 
59
74
  declare function urunTokenPagesHandler(options: UrunTokenRouteOptions): (req: UrunTokenPagesRequest, res: UrunTokenPagesResponse) => Promise<void>;
60
75
 
61
- export { type CreateTokenRouteOptions, type CreateTokenRouteResponseBody, URUN_API_KEY_ENV, URUN_APP_ENV, URUN_FUNCTION_ENV, URUN_GATEWAY_URL_ENV, type UrunSessionConfig, type UrunTokenPagesRequest, type UrunTokenPagesResponse, type UrunTokenResponseBody, type UrunTokenRouteOptions, createTokenRoute, urunSessionConfig, urunTokenPagesHandler, urunTokenRoute };
76
+ export { type CreateTokenRouteOptions, type CreateTokenRouteResponseBody, MissingCredentialError, URUN_API_KEY_ENV, URUN_API_URL_ENV, URUN_APP_ENV, URUN_FUNCTION_ENV, URUN_GATEWAY_URL_ENV, type UrunSessionConfig, type UrunTokenPagesRequest, type UrunTokenPagesResponse, type UrunTokenResponseBody, type UrunTokenRouteOptions, createTokenRoute, resolveCredential, urunSessionConfig, urunTokenPagesHandler, urunTokenRoute };