@lumoauth/backend 0.0.0-stage → 1.0.0
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/LICENSE +21 -0
- package/README.md +51 -2
- package/dist/index.d.mts +146 -0
- package/dist/index.d.ts +146 -0
- package/dist/index.js +195 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +180 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +59 -5
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 LumoAuth LLC
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,52 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @lumoauth/backend
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
The LumoAuth server SDK for plain Node services. Credentialed with a tenant
|
|
4
|
+
API key (`lmk_…`) or machine token, guarded against browser construction, and
|
|
5
|
+
exposing the full namespace blueprint: `auth`, `permissions`, `zanzibar`,
|
|
6
|
+
`abac`, `agents`, `approvals`, `delegation`, `jit`, `mcp`, plus the `api`
|
|
7
|
+
escape hatch to the generated OpenAPI client.
|
|
8
|
+
|
|
9
|
+
Using Express? Install `@lumoauth/express` instead (it re-exports this
|
|
10
|
+
package). Next.js apps want `@lumoauth/nextjs`.
|
|
11
|
+
|
|
12
|
+
## Install
|
|
13
|
+
|
|
14
|
+
```sh
|
|
15
|
+
npm install @lumoauth/backend
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
## Example
|
|
19
|
+
|
|
20
|
+
```ts
|
|
21
|
+
import { LumoAuthBackend } from '@lumoauth/backend';
|
|
22
|
+
|
|
23
|
+
const lumo = new LumoAuthBackend({
|
|
24
|
+
baseUrl: process.env.LUMOAUTH_URL!,
|
|
25
|
+
secretKey: process.env.LUMOAUTH_SECRET_KEY!, // never ship this to a browser
|
|
26
|
+
orgId: 'acme-corp',
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
// RBAC / ReBAC / ABAC checks
|
|
30
|
+
const allowed = await lumo.permissions.check('documents.edit');
|
|
31
|
+
|
|
32
|
+
// Push-approval for irreversible agent actions
|
|
33
|
+
const approval = await lumo.approvals.require({
|
|
34
|
+
taskId: 'wire-001',
|
|
35
|
+
reason: 'Wire $4,500 to vendor INV-7741',
|
|
36
|
+
impact: 'high',
|
|
37
|
+
onBehalfOf: 'ada@acme.com',
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
// Full REST surface (admin, SCIM, audit logs) via the generated client
|
|
41
|
+
// (requires `npm install @lumoauth/api-client`):
|
|
42
|
+
const { AdminUsersApi } = lumo.api.module;
|
|
43
|
+
const users = lumo.api.create(AdminUsersApi);
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
## Docs
|
|
47
|
+
|
|
48
|
+
https://docs.lumoauth.dev
|
|
49
|
+
|
|
50
|
+
## License
|
|
51
|
+
|
|
52
|
+
MIT
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import { PermissionsModule, ZanzibarModule, AbacModule, AuthModule, AgentsModule, ApprovalsModule, DelegationModule, JitModule, McpModule, PermissionsModuleOptions } from '@lumoauth/shared';
|
|
2
|
+
export * from '@lumoauth/shared';
|
|
3
|
+
|
|
4
|
+
interface LumoAuthBackendConfig {
|
|
5
|
+
/**
|
|
6
|
+
* Base URL of your LumoAuth instance.
|
|
7
|
+
* @example "https://app.lumoauth.dev"
|
|
8
|
+
*/
|
|
9
|
+
baseUrl: string;
|
|
10
|
+
/**
|
|
11
|
+
* Server credential — a tenant API key (`lmk_…`) or a machine access
|
|
12
|
+
* token. Unlike the browser client, this may be a long-lived secret.
|
|
13
|
+
*
|
|
14
|
+
* Load it from the environment. Never inline it, and never expose it
|
|
15
|
+
* through a framework's public-env mechanism (`NEXT_PUBLIC_*`, `VITE_*`).
|
|
16
|
+
*/
|
|
17
|
+
secretKey: string | (() => string | Promise<string>);
|
|
18
|
+
/** Organization slug. Required for org-scoped surfaces (ABAC, agents). */
|
|
19
|
+
orgId?: string;
|
|
20
|
+
/** OAuth client ID, when using the auth or delegation modules server-side. */
|
|
21
|
+
clientId?: string;
|
|
22
|
+
/**
|
|
23
|
+
* OAuth client secret for confidential flows — required by
|
|
24
|
+
* `delegation` for the consent-code exchange and revocation.
|
|
25
|
+
*/
|
|
26
|
+
clientSecret?: string;
|
|
27
|
+
/** OAuth callback URL for the delegation consent flow. */
|
|
28
|
+
redirectUri?: string;
|
|
29
|
+
/** Request timeout in milliseconds. */
|
|
30
|
+
timeout?: number;
|
|
31
|
+
/** Custom fetch implementation. */
|
|
32
|
+
fetch?: typeof globalThis.fetch;
|
|
33
|
+
/** Extra headers applied to every request. */
|
|
34
|
+
headers?: Record<string, string>;
|
|
35
|
+
/** Permission cache configuration; `false` disables caching. */
|
|
36
|
+
cache?: boolean | PermissionsModuleOptions['cache'];
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* The generated OpenAPI client (`@lumoauth/api-client`), pre-configured with
|
|
40
|
+
* this backend's base URL and credential. Loosely typed here so the backend
|
|
41
|
+
* package does not take a compile-time dependency on the generated code.
|
|
42
|
+
*/
|
|
43
|
+
interface LumoAuthApiEscapeHatch {
|
|
44
|
+
/** The raw `@lumoauth/api-client` module (`AgentsApi`, `AdminUsersApi`, …). */
|
|
45
|
+
readonly module: Record<string, unknown>;
|
|
46
|
+
/** A `Configuration` instance carrying this backend's baseUrl + credential. */
|
|
47
|
+
readonly configuration: unknown;
|
|
48
|
+
/**
|
|
49
|
+
* Instantiate a generated API class with this backend's configuration.
|
|
50
|
+
*
|
|
51
|
+
* ```ts
|
|
52
|
+
* const { AdminUsersApi } = lumo.api.module;
|
|
53
|
+
* const users = lumo.api.create(AdminUsersApi);
|
|
54
|
+
* ```
|
|
55
|
+
*/
|
|
56
|
+
create<T>(apiClass: new (configuration?: unknown) => T): T;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Server-side LumoAuth client.
|
|
60
|
+
*
|
|
61
|
+
* Same authorization surface as `@lumoauth/client`, but credentialed for a
|
|
62
|
+
* server and guarded against browser construction.
|
|
63
|
+
*
|
|
64
|
+
* ```ts
|
|
65
|
+
* // app/api/documents/route.ts
|
|
66
|
+
* import { LumoAuthBackend } from '@lumoauth/backend';
|
|
67
|
+
*
|
|
68
|
+
* const lumo = new LumoAuthBackend({
|
|
69
|
+
* baseUrl: process.env.LUMOAUTH_URL!,
|
|
70
|
+
* secretKey: process.env.LUMOAUTH_SECRET_KEY!,
|
|
71
|
+
* orgId: 'acme-corp',
|
|
72
|
+
* });
|
|
73
|
+
*
|
|
74
|
+
* const allowed = await lumo.permissions.check('documents.edit');
|
|
75
|
+
* ```
|
|
76
|
+
*
|
|
77
|
+
* For admin operations (users, roles, webhooks, audit logs) use the `api`
|
|
78
|
+
* escape hatch — the ~200 generated endpoints are already typed and
|
|
79
|
+
* regenerated from the OpenAPI spec.
|
|
80
|
+
*/
|
|
81
|
+
declare class LumoAuthBackend {
|
|
82
|
+
/** RBAC permission checks. */
|
|
83
|
+
readonly permissions: PermissionsModule;
|
|
84
|
+
/** Zanzibar-style (ReBAC) relationship checks. */
|
|
85
|
+
readonly zanzibar: ZanzibarModule;
|
|
86
|
+
/** ABAC policy evaluation and attribute management. */
|
|
87
|
+
readonly abac: AbacModule;
|
|
88
|
+
/** OAuth 2.0 — token exchange and refresh, including confidential clients. */
|
|
89
|
+
readonly auth: AuthModule;
|
|
90
|
+
/** Agent identity — ask/isAllowed, self-inspection, registration. */
|
|
91
|
+
readonly agents: AgentsModule;
|
|
92
|
+
/** Push-approval-for-agent-actions. */
|
|
93
|
+
readonly approvals: ApprovalsModule;
|
|
94
|
+
/** Chain of Agency — RFC 8693 delegation and nested agent chains. */
|
|
95
|
+
readonly delegation: DelegationModule;
|
|
96
|
+
/** Just-in-Time permissions — ephemeral tasks and scoped tokens. */
|
|
97
|
+
readonly jit: JitModule;
|
|
98
|
+
/** Token exchange for secured MCP servers. */
|
|
99
|
+
readonly mcp: McpModule;
|
|
100
|
+
private readonly http;
|
|
101
|
+
private readonly baseUrl;
|
|
102
|
+
private readonly secretProvider;
|
|
103
|
+
private apiInstance;
|
|
104
|
+
constructor(config: LumoAuthBackendConfig);
|
|
105
|
+
/**
|
|
106
|
+
* @deprecated Renamed to {@link agents}. This alias will be removed
|
|
107
|
+
* before 2.0.
|
|
108
|
+
*/
|
|
109
|
+
get agent(): AgentsModule;
|
|
110
|
+
/**
|
|
111
|
+
* Escape hatch to the full generated REST surface (`@lumoauth/api-client`)
|
|
112
|
+
* — every admin endpoint, SCIM, audit logs — pre-configured with this
|
|
113
|
+
* backend's base URL and credential.
|
|
114
|
+
*
|
|
115
|
+
* Loaded lazily on first access so apps that never reach for it don't
|
|
116
|
+
* pay for it. Requires `@lumoauth/api-client` to be installed:
|
|
117
|
+
*
|
|
118
|
+
* ```sh
|
|
119
|
+
* npm install @lumoauth/api-client
|
|
120
|
+
* ```
|
|
121
|
+
*/
|
|
122
|
+
get api(): LumoAuthApiEscapeHatch;
|
|
123
|
+
/** Clear all server-side caches. */
|
|
124
|
+
clearCache(): void;
|
|
125
|
+
private loadApiClient;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Refuse to run server-credentialed code in a browser.
|
|
130
|
+
*
|
|
131
|
+
* This is the mirror of `@lumoauth/client`'s guard. That one stops a server
|
|
132
|
+
* credential reaching browser code; this one stops browser code reaching for a
|
|
133
|
+
* server credential in the first place.
|
|
134
|
+
*
|
|
135
|
+
* The check is intentionally `window.document` rather than just `window`:
|
|
136
|
+
* some server runtimes define a bare `window` global, and failing there would
|
|
137
|
+
* be a false positive on a legitimate server.
|
|
138
|
+
*
|
|
139
|
+
* Web Workers and edge runtimes have no `document`, so they pass. That is
|
|
140
|
+
* deliberate — an edge function is a server, and it is a supported place to
|
|
141
|
+
* hold a secret. What this catches is the case that actually leaks: a module
|
|
142
|
+
* that ends up in a bundle served to a real browser.
|
|
143
|
+
*/
|
|
144
|
+
declare function assertServerOnly(what: string): void;
|
|
145
|
+
|
|
146
|
+
export { type LumoAuthApiEscapeHatch, LumoAuthBackend, type LumoAuthBackendConfig, assertServerOnly };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import { PermissionsModule, ZanzibarModule, AbacModule, AuthModule, AgentsModule, ApprovalsModule, DelegationModule, JitModule, McpModule, PermissionsModuleOptions } from '@lumoauth/shared';
|
|
2
|
+
export * from '@lumoauth/shared';
|
|
3
|
+
|
|
4
|
+
interface LumoAuthBackendConfig {
|
|
5
|
+
/**
|
|
6
|
+
* Base URL of your LumoAuth instance.
|
|
7
|
+
* @example "https://app.lumoauth.dev"
|
|
8
|
+
*/
|
|
9
|
+
baseUrl: string;
|
|
10
|
+
/**
|
|
11
|
+
* Server credential — a tenant API key (`lmk_…`) or a machine access
|
|
12
|
+
* token. Unlike the browser client, this may be a long-lived secret.
|
|
13
|
+
*
|
|
14
|
+
* Load it from the environment. Never inline it, and never expose it
|
|
15
|
+
* through a framework's public-env mechanism (`NEXT_PUBLIC_*`, `VITE_*`).
|
|
16
|
+
*/
|
|
17
|
+
secretKey: string | (() => string | Promise<string>);
|
|
18
|
+
/** Organization slug. Required for org-scoped surfaces (ABAC, agents). */
|
|
19
|
+
orgId?: string;
|
|
20
|
+
/** OAuth client ID, when using the auth or delegation modules server-side. */
|
|
21
|
+
clientId?: string;
|
|
22
|
+
/**
|
|
23
|
+
* OAuth client secret for confidential flows — required by
|
|
24
|
+
* `delegation` for the consent-code exchange and revocation.
|
|
25
|
+
*/
|
|
26
|
+
clientSecret?: string;
|
|
27
|
+
/** OAuth callback URL for the delegation consent flow. */
|
|
28
|
+
redirectUri?: string;
|
|
29
|
+
/** Request timeout in milliseconds. */
|
|
30
|
+
timeout?: number;
|
|
31
|
+
/** Custom fetch implementation. */
|
|
32
|
+
fetch?: typeof globalThis.fetch;
|
|
33
|
+
/** Extra headers applied to every request. */
|
|
34
|
+
headers?: Record<string, string>;
|
|
35
|
+
/** Permission cache configuration; `false` disables caching. */
|
|
36
|
+
cache?: boolean | PermissionsModuleOptions['cache'];
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* The generated OpenAPI client (`@lumoauth/api-client`), pre-configured with
|
|
40
|
+
* this backend's base URL and credential. Loosely typed here so the backend
|
|
41
|
+
* package does not take a compile-time dependency on the generated code.
|
|
42
|
+
*/
|
|
43
|
+
interface LumoAuthApiEscapeHatch {
|
|
44
|
+
/** The raw `@lumoauth/api-client` module (`AgentsApi`, `AdminUsersApi`, …). */
|
|
45
|
+
readonly module: Record<string, unknown>;
|
|
46
|
+
/** A `Configuration` instance carrying this backend's baseUrl + credential. */
|
|
47
|
+
readonly configuration: unknown;
|
|
48
|
+
/**
|
|
49
|
+
* Instantiate a generated API class with this backend's configuration.
|
|
50
|
+
*
|
|
51
|
+
* ```ts
|
|
52
|
+
* const { AdminUsersApi } = lumo.api.module;
|
|
53
|
+
* const users = lumo.api.create(AdminUsersApi);
|
|
54
|
+
* ```
|
|
55
|
+
*/
|
|
56
|
+
create<T>(apiClass: new (configuration?: unknown) => T): T;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Server-side LumoAuth client.
|
|
60
|
+
*
|
|
61
|
+
* Same authorization surface as `@lumoauth/client`, but credentialed for a
|
|
62
|
+
* server and guarded against browser construction.
|
|
63
|
+
*
|
|
64
|
+
* ```ts
|
|
65
|
+
* // app/api/documents/route.ts
|
|
66
|
+
* import { LumoAuthBackend } from '@lumoauth/backend';
|
|
67
|
+
*
|
|
68
|
+
* const lumo = new LumoAuthBackend({
|
|
69
|
+
* baseUrl: process.env.LUMOAUTH_URL!,
|
|
70
|
+
* secretKey: process.env.LUMOAUTH_SECRET_KEY!,
|
|
71
|
+
* orgId: 'acme-corp',
|
|
72
|
+
* });
|
|
73
|
+
*
|
|
74
|
+
* const allowed = await lumo.permissions.check('documents.edit');
|
|
75
|
+
* ```
|
|
76
|
+
*
|
|
77
|
+
* For admin operations (users, roles, webhooks, audit logs) use the `api`
|
|
78
|
+
* escape hatch — the ~200 generated endpoints are already typed and
|
|
79
|
+
* regenerated from the OpenAPI spec.
|
|
80
|
+
*/
|
|
81
|
+
declare class LumoAuthBackend {
|
|
82
|
+
/** RBAC permission checks. */
|
|
83
|
+
readonly permissions: PermissionsModule;
|
|
84
|
+
/** Zanzibar-style (ReBAC) relationship checks. */
|
|
85
|
+
readonly zanzibar: ZanzibarModule;
|
|
86
|
+
/** ABAC policy evaluation and attribute management. */
|
|
87
|
+
readonly abac: AbacModule;
|
|
88
|
+
/** OAuth 2.0 — token exchange and refresh, including confidential clients. */
|
|
89
|
+
readonly auth: AuthModule;
|
|
90
|
+
/** Agent identity — ask/isAllowed, self-inspection, registration. */
|
|
91
|
+
readonly agents: AgentsModule;
|
|
92
|
+
/** Push-approval-for-agent-actions. */
|
|
93
|
+
readonly approvals: ApprovalsModule;
|
|
94
|
+
/** Chain of Agency — RFC 8693 delegation and nested agent chains. */
|
|
95
|
+
readonly delegation: DelegationModule;
|
|
96
|
+
/** Just-in-Time permissions — ephemeral tasks and scoped tokens. */
|
|
97
|
+
readonly jit: JitModule;
|
|
98
|
+
/** Token exchange for secured MCP servers. */
|
|
99
|
+
readonly mcp: McpModule;
|
|
100
|
+
private readonly http;
|
|
101
|
+
private readonly baseUrl;
|
|
102
|
+
private readonly secretProvider;
|
|
103
|
+
private apiInstance;
|
|
104
|
+
constructor(config: LumoAuthBackendConfig);
|
|
105
|
+
/**
|
|
106
|
+
* @deprecated Renamed to {@link agents}. This alias will be removed
|
|
107
|
+
* before 2.0.
|
|
108
|
+
*/
|
|
109
|
+
get agent(): AgentsModule;
|
|
110
|
+
/**
|
|
111
|
+
* Escape hatch to the full generated REST surface (`@lumoauth/api-client`)
|
|
112
|
+
* — every admin endpoint, SCIM, audit logs — pre-configured with this
|
|
113
|
+
* backend's base URL and credential.
|
|
114
|
+
*
|
|
115
|
+
* Loaded lazily on first access so apps that never reach for it don't
|
|
116
|
+
* pay for it. Requires `@lumoauth/api-client` to be installed:
|
|
117
|
+
*
|
|
118
|
+
* ```sh
|
|
119
|
+
* npm install @lumoauth/api-client
|
|
120
|
+
* ```
|
|
121
|
+
*/
|
|
122
|
+
get api(): LumoAuthApiEscapeHatch;
|
|
123
|
+
/** Clear all server-side caches. */
|
|
124
|
+
clearCache(): void;
|
|
125
|
+
private loadApiClient;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Refuse to run server-credentialed code in a browser.
|
|
130
|
+
*
|
|
131
|
+
* This is the mirror of `@lumoauth/client`'s guard. That one stops a server
|
|
132
|
+
* credential reaching browser code; this one stops browser code reaching for a
|
|
133
|
+
* server credential in the first place.
|
|
134
|
+
*
|
|
135
|
+
* The check is intentionally `window.document` rather than just `window`:
|
|
136
|
+
* some server runtimes define a bare `window` global, and failing there would
|
|
137
|
+
* be a false positive on a legitimate server.
|
|
138
|
+
*
|
|
139
|
+
* Web Workers and edge runtimes have no `document`, so they pass. That is
|
|
140
|
+
* deliberate — an edge function is a server, and it is a supported place to
|
|
141
|
+
* hold a secret. What this catches is the case that actually leaks: a module
|
|
142
|
+
* that ends up in a bundle served to a real browser.
|
|
143
|
+
*/
|
|
144
|
+
declare function assertServerOnly(what: string): void;
|
|
145
|
+
|
|
146
|
+
export { type LumoAuthApiEscapeHatch, LumoAuthBackend, type LumoAuthBackendConfig, assertServerOnly };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
19
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
20
|
+
|
|
21
|
+
// src/index.ts
|
|
22
|
+
var index_exports = {};
|
|
23
|
+
__export(index_exports, {
|
|
24
|
+
LumoAuthBackend: () => LumoAuthBackend,
|
|
25
|
+
assertServerOnly: () => assertServerOnly
|
|
26
|
+
});
|
|
27
|
+
module.exports = __toCommonJS(index_exports);
|
|
28
|
+
|
|
29
|
+
// ../../node_modules/tsup/assets/cjs_shims.js
|
|
30
|
+
var getImportMetaUrl = () => typeof document === "undefined" ? new URL(`file:${__filename}`).href : document.currentScript && document.currentScript.tagName.toUpperCase() === "SCRIPT" ? document.currentScript.src : new URL("main.js", document.baseURI).href;
|
|
31
|
+
var importMetaUrl = /* @__PURE__ */ getImportMetaUrl();
|
|
32
|
+
|
|
33
|
+
// src/backend.ts
|
|
34
|
+
var import_shared2 = require("@lumoauth/shared");
|
|
35
|
+
var import_node_module = require("module");
|
|
36
|
+
|
|
37
|
+
// src/guard.ts
|
|
38
|
+
var import_shared = require("@lumoauth/shared");
|
|
39
|
+
function assertServerOnly(what) {
|
|
40
|
+
if (typeof window !== "undefined" && typeof window.document !== "undefined") {
|
|
41
|
+
throw new import_shared.LumoAuthConfigError(
|
|
42
|
+
`${what} is server-only and was constructed in a browser. @lumoauth/backend holds credentials that authenticate as your entire organization, so it must never ship to the client. Import @lumoauth/client in browser code, and keep this import in a route handler, server component, or API route.`
|
|
43
|
+
);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// src/backend.ts
|
|
48
|
+
var LumoAuthBackend = class {
|
|
49
|
+
constructor(config) {
|
|
50
|
+
this.apiInstance = null;
|
|
51
|
+
assertServerOnly("LumoAuthBackend");
|
|
52
|
+
if (!config.baseUrl) {
|
|
53
|
+
throw new import_shared2.LumoAuthConfigError("baseUrl is required");
|
|
54
|
+
}
|
|
55
|
+
if (!config.secretKey) {
|
|
56
|
+
throw new import_shared2.LumoAuthConfigError(
|
|
57
|
+
"secretKey is required. For browser code use @lumoauth/client with a user access token instead."
|
|
58
|
+
);
|
|
59
|
+
}
|
|
60
|
+
this.baseUrl = config.baseUrl.replace(/\/+$/, "");
|
|
61
|
+
this.secretProvider = typeof config.secretKey === "function" ? config.secretKey : () => config.secretKey;
|
|
62
|
+
const httpConfig = {
|
|
63
|
+
baseUrl: config.baseUrl,
|
|
64
|
+
token: config.secretKey,
|
|
65
|
+
timeout: config.timeout,
|
|
66
|
+
fetch: config.fetch,
|
|
67
|
+
headers: config.headers
|
|
68
|
+
};
|
|
69
|
+
this.http = new import_shared2.HttpClient(httpConfig);
|
|
70
|
+
const orgId = config.orgId ?? "";
|
|
71
|
+
this.permissions = new import_shared2.PermissionsModule(this.http, { cache: config.cache });
|
|
72
|
+
this.zanzibar = new import_shared2.ZanzibarModule(this.http);
|
|
73
|
+
this.abac = new import_shared2.AbacModule(this.http, orgId);
|
|
74
|
+
this.agents = new import_shared2.AgentsModule(this.http, orgId);
|
|
75
|
+
this.approvals = new import_shared2.ApprovalsModule(this.http, orgId);
|
|
76
|
+
this.jit = new import_shared2.JitModule(this.http, orgId);
|
|
77
|
+
this.mcp = new import_shared2.McpModule({
|
|
78
|
+
baseUrl: this.baseUrl,
|
|
79
|
+
orgId,
|
|
80
|
+
token: this.secretProvider,
|
|
81
|
+
fetch: config.fetch
|
|
82
|
+
});
|
|
83
|
+
this.delegation = new import_shared2.DelegationModule({
|
|
84
|
+
baseUrl: this.baseUrl,
|
|
85
|
+
orgId,
|
|
86
|
+
clientId: config.clientId ?? "",
|
|
87
|
+
clientSecret: config.clientSecret,
|
|
88
|
+
redirectUri: config.redirectUri,
|
|
89
|
+
agentToken: this.secretProvider,
|
|
90
|
+
fetch: config.fetch
|
|
91
|
+
});
|
|
92
|
+
const authConfig = {
|
|
93
|
+
baseUrl: config.baseUrl,
|
|
94
|
+
orgId,
|
|
95
|
+
clientId: config.clientId ?? "",
|
|
96
|
+
fetch: config.fetch
|
|
97
|
+
};
|
|
98
|
+
this.auth = new import_shared2.AuthModule(authConfig);
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* @deprecated Renamed to {@link agents}. This alias will be removed
|
|
102
|
+
* before 2.0.
|
|
103
|
+
*/
|
|
104
|
+
get agent() {
|
|
105
|
+
return this.agents;
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Escape hatch to the full generated REST surface (`@lumoauth/api-client`)
|
|
109
|
+
* — every admin endpoint, SCIM, audit logs — pre-configured with this
|
|
110
|
+
* backend's base URL and credential.
|
|
111
|
+
*
|
|
112
|
+
* Loaded lazily on first access so apps that never reach for it don't
|
|
113
|
+
* pay for it. Requires `@lumoauth/api-client` to be installed:
|
|
114
|
+
*
|
|
115
|
+
* ```sh
|
|
116
|
+
* npm install @lumoauth/api-client
|
|
117
|
+
* ```
|
|
118
|
+
*/
|
|
119
|
+
get api() {
|
|
120
|
+
if (!this.apiInstance) {
|
|
121
|
+
this.apiInstance = this.loadApiClient();
|
|
122
|
+
}
|
|
123
|
+
return this.apiInstance;
|
|
124
|
+
}
|
|
125
|
+
/** Clear all server-side caches. */
|
|
126
|
+
clearCache() {
|
|
127
|
+
this.permissions.clearCache();
|
|
128
|
+
}
|
|
129
|
+
// ── Internal ──────────────────────────────────────────────────────
|
|
130
|
+
loadApiClient() {
|
|
131
|
+
let mod;
|
|
132
|
+
try {
|
|
133
|
+
const requireFn = (0, import_node_module.createRequire)(
|
|
134
|
+
typeof __dirname === "string" ? `${__dirname}/` : importMetaUrl
|
|
135
|
+
);
|
|
136
|
+
mod = requireFn("@lumoauth/api-client");
|
|
137
|
+
} catch (error) {
|
|
138
|
+
throw new import_shared2.LumoAuthConfigError(
|
|
139
|
+
`lumo.api requires the generated client \`@lumoauth/api-client\`, which is not installed. Install it with \`npm install @lumoauth/api-client\` (it covers the full REST surface \u2014 admin endpoints, SCIM, audit logs) and try again. Original error: ${error instanceof Error ? error.message : String(error)}`
|
|
140
|
+
);
|
|
141
|
+
}
|
|
142
|
+
const ConfigurationCtor = mod.Configuration;
|
|
143
|
+
if (typeof ConfigurationCtor !== "function") {
|
|
144
|
+
throw new import_shared2.LumoAuthConfigError(
|
|
145
|
+
"@lumoauth/api-client was found but does not export `Configuration` \u2014 is the installed version compatible (>=0.1.0)?"
|
|
146
|
+
);
|
|
147
|
+
}
|
|
148
|
+
const params = { basePath: this.baseUrl };
|
|
149
|
+
const probe = this.secretProvider();
|
|
150
|
+
if (typeof probe === "string") {
|
|
151
|
+
if (probe.startsWith("lmk_")) {
|
|
152
|
+
params.apiKey = () => this.secretProvider();
|
|
153
|
+
} else {
|
|
154
|
+
params.accessToken = () => this.secretProvider();
|
|
155
|
+
}
|
|
156
|
+
} else {
|
|
157
|
+
params.apiKey = async () => {
|
|
158
|
+
const secret = await probe;
|
|
159
|
+
if (!secret.startsWith("lmk_")) {
|
|
160
|
+
configuration.apiKey = void 0;
|
|
161
|
+
return void 0;
|
|
162
|
+
}
|
|
163
|
+
configuration.accessToken = void 0;
|
|
164
|
+
return this.secretProvider();
|
|
165
|
+
};
|
|
166
|
+
params.accessToken = async () => {
|
|
167
|
+
const secret = await probe;
|
|
168
|
+
if (secret.startsWith("lmk_")) {
|
|
169
|
+
configuration.accessToken = void 0;
|
|
170
|
+
return "";
|
|
171
|
+
}
|
|
172
|
+
configuration.apiKey = void 0;
|
|
173
|
+
return this.secretProvider();
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
const configuration = new ConfigurationCtor(params);
|
|
177
|
+
return {
|
|
178
|
+
module: mod,
|
|
179
|
+
configuration,
|
|
180
|
+
create(apiClass) {
|
|
181
|
+
return new apiClass(configuration);
|
|
182
|
+
}
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
};
|
|
186
|
+
|
|
187
|
+
// src/index.ts
|
|
188
|
+
__reExport(index_exports, require("@lumoauth/shared"), module.exports);
|
|
189
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
190
|
+
0 && (module.exports = {
|
|
191
|
+
LumoAuthBackend,
|
|
192
|
+
assertServerOnly,
|
|
193
|
+
...require("@lumoauth/shared")
|
|
194
|
+
});
|
|
195
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../../../node_modules/tsup/assets/cjs_shims.js","../src/backend.ts","../src/guard.ts"],"sourcesContent":["// @lumoauth/backend — the server SDK.\n//\n// The counterpart to @lumoauth/client. This package expects server\n// credentials (a tenant API key, `lmk_…`, or a machine token) and refuses to\n// construct in a browser, so a server credential cannot reach a client bundle\n// by accident.\n//\n// For the full REST surface — every admin endpoint, SCIM, audit logs — use\n// the `lumo.api` escape hatch, which lazily loads the generated client\n// `@lumoauth/api-client` pre-configured with this backend's credential. It is\n// declared as an optional peer dependency because the generated client is not\n// yet published to a registry.\n// TODO(publish): once @lumoauth/api-client is published, drop\n// `peerDependenciesMeta.optional` in package.json so installs pull it in by\n// default (the lazy getter already handles both cases).\n\nexport {\n LumoAuthBackend,\n type LumoAuthBackendConfig,\n type LumoAuthApiEscapeHatch,\n} from './backend';\nexport { assertServerOnly } from './guard';\n\n// The full isomorphic surface: authorization modules, OAuth/PKCE helpers,\n// schemas, errors, and the HTTP client.\nexport * from '@lumoauth/shared';\n","// Shim globals in cjs bundle\n// There's a weird bug that esbuild will always inject importMetaUrl\n// if we export it as `const importMetaUrl = ... __filename ...`\n// But using a function will not cause this issue\n\nconst getImportMetaUrl = () => \n typeof document === \"undefined\" \n ? new URL(`file:${__filename}`).href \n : (document.currentScript && document.currentScript.tagName.toUpperCase() === 'SCRIPT') \n ? document.currentScript.src \n : new URL(\"main.js\", document.baseURI).href;\n\nexport const importMetaUrl = /* @__PURE__ */ getImportMetaUrl()\n","import {\n HttpClient,\n type HttpClientConfig,\n PermissionsModule,\n type PermissionsModuleOptions,\n ZanzibarModule,\n AbacModule,\n AuthModule,\n type AuthModuleConfig,\n AgentsModule,\n ApprovalsModule,\n DelegationModule,\n JitModule,\n McpModule,\n LumoAuthConfigError,\n} from '@lumoauth/shared';\nimport { createRequire } from 'node:module';\nimport { assertServerOnly } from './guard';\n\nexport interface LumoAuthBackendConfig {\n /**\n * Base URL of your LumoAuth instance.\n * @example \"https://app.lumoauth.dev\"\n */\n baseUrl: string;\n\n /**\n * Server credential — a tenant API key (`lmk_…`) or a machine access\n * token. Unlike the browser client, this may be a long-lived secret.\n *\n * Load it from the environment. Never inline it, and never expose it\n * through a framework's public-env mechanism (`NEXT_PUBLIC_*`, `VITE_*`).\n */\n secretKey: string | (() => string | Promise<string>);\n\n /** Organization slug. Required for org-scoped surfaces (ABAC, agents). */\n orgId?: string;\n\n /** OAuth client ID, when using the auth or delegation modules server-side. */\n clientId?: string;\n\n /**\n * OAuth client secret for confidential flows — required by\n * `delegation` for the consent-code exchange and revocation.\n */\n clientSecret?: string;\n\n /** OAuth callback URL for the delegation consent flow. */\n redirectUri?: string;\n\n /** Request timeout in milliseconds. */\n timeout?: number;\n\n /** Custom fetch implementation. */\n fetch?: typeof globalThis.fetch;\n\n /** Extra headers applied to every request. */\n headers?: Record<string, string>;\n\n /** Permission cache configuration; `false` disables caching. */\n cache?: boolean | PermissionsModuleOptions['cache'];\n}\n\n/**\n * The generated OpenAPI client (`@lumoauth/api-client`), pre-configured with\n * this backend's base URL and credential. Loosely typed here so the backend\n * package does not take a compile-time dependency on the generated code.\n */\nexport interface LumoAuthApiEscapeHatch {\n /** The raw `@lumoauth/api-client` module (`AgentsApi`, `AdminUsersApi`, …). */\n readonly module: Record<string, unknown>;\n /** A `Configuration` instance carrying this backend's baseUrl + credential. */\n readonly configuration: unknown;\n /**\n * Instantiate a generated API class with this backend's configuration.\n *\n * ```ts\n * const { AdminUsersApi } = lumo.api.module;\n * const users = lumo.api.create(AdminUsersApi);\n * ```\n */\n create<T>(apiClass: new (configuration?: unknown) => T): T;\n}\n\n/**\n * Server-side LumoAuth client.\n *\n * Same authorization surface as `@lumoauth/client`, but credentialed for a\n * server and guarded against browser construction.\n *\n * ```ts\n * // app/api/documents/route.ts\n * import { LumoAuthBackend } from '@lumoauth/backend';\n *\n * const lumo = new LumoAuthBackend({\n * baseUrl: process.env.LUMOAUTH_URL!,\n * secretKey: process.env.LUMOAUTH_SECRET_KEY!,\n * orgId: 'acme-corp',\n * });\n *\n * const allowed = await lumo.permissions.check('documents.edit');\n * ```\n *\n * For admin operations (users, roles, webhooks, audit logs) use the `api`\n * escape hatch — the ~200 generated endpoints are already typed and\n * regenerated from the OpenAPI spec.\n */\nexport class LumoAuthBackend {\n /** RBAC permission checks. */\n public readonly permissions: PermissionsModule;\n /** Zanzibar-style (ReBAC) relationship checks. */\n public readonly zanzibar: ZanzibarModule;\n /** ABAC policy evaluation and attribute management. */\n public readonly abac: AbacModule;\n /** OAuth 2.0 — token exchange and refresh, including confidential clients. */\n public readonly auth: AuthModule;\n /** Agent identity — ask/isAllowed, self-inspection, registration. */\n public readonly agents: AgentsModule;\n /** Push-approval-for-agent-actions. */\n public readonly approvals: ApprovalsModule;\n /** Chain of Agency — RFC 8693 delegation and nested agent chains. */\n public readonly delegation: DelegationModule;\n /** Just-in-Time permissions — ephemeral tasks and scoped tokens. */\n public readonly jit: JitModule;\n /** Token exchange for secured MCP servers. */\n public readonly mcp: McpModule;\n\n private readonly http: HttpClient;\n private readonly baseUrl: string;\n private readonly secretProvider: () => string | Promise<string>;\n private apiInstance: LumoAuthApiEscapeHatch | null = null;\n\n constructor(config: LumoAuthBackendConfig) {\n assertServerOnly('LumoAuthBackend');\n\n if (!config.baseUrl) {\n throw new LumoAuthConfigError('baseUrl is required');\n }\n if (!config.secretKey) {\n throw new LumoAuthConfigError(\n 'secretKey is required. For browser code use @lumoauth/client with a user access token instead.',\n );\n }\n\n this.baseUrl = config.baseUrl.replace(/\\/+$/, '');\n this.secretProvider =\n typeof config.secretKey === 'function'\n ? config.secretKey\n : () => config.secretKey as string;\n\n const httpConfig: HttpClientConfig = {\n baseUrl: config.baseUrl,\n token: config.secretKey,\n timeout: config.timeout,\n fetch: config.fetch,\n headers: config.headers,\n };\n this.http = new HttpClient(httpConfig);\n\n const orgId = config.orgId ?? '';\n\n this.permissions = new PermissionsModule(this.http, { cache: config.cache });\n this.zanzibar = new ZanzibarModule(this.http);\n this.abac = new AbacModule(this.http, orgId);\n this.agents = new AgentsModule(this.http, orgId);\n this.approvals = new ApprovalsModule(this.http, orgId);\n this.jit = new JitModule(this.http, orgId);\n this.mcp = new McpModule({\n baseUrl: this.baseUrl,\n orgId,\n token: this.secretProvider,\n fetch: config.fetch,\n });\n this.delegation = new DelegationModule({\n baseUrl: this.baseUrl,\n orgId,\n clientId: config.clientId ?? '',\n clientSecret: config.clientSecret,\n redirectUri: config.redirectUri,\n agentToken: this.secretProvider,\n fetch: config.fetch,\n });\n\n const authConfig: AuthModuleConfig = {\n baseUrl: config.baseUrl,\n orgId,\n clientId: config.clientId ?? '',\n fetch: config.fetch,\n };\n this.auth = new AuthModule(authConfig);\n }\n\n /**\n * @deprecated Renamed to {@link agents}. This alias will be removed\n * before 2.0.\n */\n get agent(): AgentsModule {\n return this.agents;\n }\n\n /**\n * Escape hatch to the full generated REST surface (`@lumoauth/api-client`)\n * — every admin endpoint, SCIM, audit logs — pre-configured with this\n * backend's base URL and credential.\n *\n * Loaded lazily on first access so apps that never reach for it don't\n * pay for it. Requires `@lumoauth/api-client` to be installed:\n *\n * ```sh\n * npm install @lumoauth/api-client\n * ```\n */\n get api(): LumoAuthApiEscapeHatch {\n if (!this.apiInstance) {\n this.apiInstance = this.loadApiClient();\n }\n return this.apiInstance;\n }\n\n /** Clear all server-side caches. */\n clearCache(): void {\n this.permissions.clearCache();\n }\n\n // ── Internal ──────────────────────────────────────────────────────\n\n private loadApiClient(): LumoAuthApiEscapeHatch {\n let mod: Record<string, unknown>;\n try {\n // Works from both the CJS build (__dirname) and the ESM build\n // (import.meta.url). `@lumoauth/backend` is Node-only, so\n // node:module is always available, and module resolution walks\n // up from this package to the host app's node_modules.\n const requireFn: NodeRequire = createRequire(\n typeof __dirname === 'string' ? `${__dirname}/` : import.meta.url,\n );\n mod = requireFn('@lumoauth/api-client') as Record<string, unknown>;\n } catch (error) {\n throw new LumoAuthConfigError(\n 'lumo.api requires the generated client `@lumoauth/api-client`, which is not installed. ' +\n 'Install it with `npm install @lumoauth/api-client` (it covers the full REST surface — ' +\n 'admin endpoints, SCIM, audit logs) and try again. ' +\n `Original error: ${error instanceof Error ? error.message : String(error)}`,\n );\n }\n\n const ConfigurationCtor = mod.Configuration as\n | (new (params: Record<string, unknown>) => unknown)\n | undefined;\n if (typeof ConfigurationCtor !== 'function') {\n throw new LumoAuthConfigError(\n '@lumoauth/api-client was found but does not export `Configuration` — ' +\n 'is the installed version compatible (>=0.1.0)?',\n );\n }\n\n // The backend credential may be an API key (lmk_…, sent as X-API-Key)\n // or a bearer token (sent as Authorization). The generated client\n // emits a header for every configured scheme, so only the slot\n // matching the credential's shape may be populated.\n const params: Record<string, unknown> = { basePath: this.baseUrl };\n const probe = this.secretProvider();\n if (typeof probe === 'string') {\n if (probe.startsWith('lmk_')) {\n params.apiKey = () => this.secretProvider();\n } else {\n params.accessToken = () => this.secretProvider();\n }\n } else {\n // Async provider: shape unknown until first resolution. Route by\n // shape per call, then drop the mismatched slot so subsequent\n // requests carry exactly one auth header.\n params.apiKey = async () => {\n const secret = await probe;\n if (!secret.startsWith('lmk_')) {\n (configuration as { apiKey?: unknown }).apiKey = undefined;\n return undefined;\n }\n (configuration as { accessToken?: unknown }).accessToken = undefined;\n return this.secretProvider();\n };\n params.accessToken = async () => {\n const secret = await probe;\n if (secret.startsWith('lmk_')) {\n (configuration as { accessToken?: unknown }).accessToken = undefined;\n return '';\n }\n (configuration as { apiKey?: unknown }).apiKey = undefined;\n return this.secretProvider();\n };\n }\n\n const configuration = new ConfigurationCtor(params);\n\n return {\n module: mod,\n configuration,\n create<T>(apiClass: new (configuration?: unknown) => T): T {\n return new apiClass(configuration);\n },\n };\n }\n}\n","import { LumoAuthConfigError } from '@lumoauth/shared';\n\n/**\n * Refuse to run server-credentialed code in a browser.\n *\n * This is the mirror of `@lumoauth/client`'s guard. That one stops a server\n * credential reaching browser code; this one stops browser code reaching for a\n * server credential in the first place.\n *\n * The check is intentionally `window.document` rather than just `window`:\n * some server runtimes define a bare `window` global, and failing there would\n * be a false positive on a legitimate server.\n *\n * Web Workers and edge runtimes have no `document`, so they pass. That is\n * deliberate — an edge function is a server, and it is a supported place to\n * hold a secret. What this catches is the case that actually leaks: a module\n * that ends up in a bundle served to a real browser.\n */\nexport function assertServerOnly(what: string): void {\n if (typeof window !== 'undefined' && typeof window.document !== 'undefined') {\n throw new LumoAuthConfigError(\n `${what} is server-only and was constructed in a browser. ` +\n '@lumoauth/backend holds credentials that authenticate as your ' +\n 'entire organization, so it must never ship to the client. Import ' +\n '@lumoauth/client in browser code, and keep this import in a route ' +\n 'handler, server component, or API route.',\n );\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACKA,IAAM,mBAAmB,MACvB,OAAO,aAAa,cAChB,IAAI,IAAI,QAAQ,UAAU,EAAE,EAAE,OAC7B,SAAS,iBAAiB,SAAS,cAAc,QAAQ,YAAY,MAAM,WAC1E,SAAS,cAAc,MACvB,IAAI,IAAI,WAAW,SAAS,OAAO,EAAE;AAEtC,IAAM,gBAAgC,iCAAiB;;;ACZ9D,IAAAA,iBAeO;AACP,yBAA8B;;;AChB9B,oBAAoC;AAkB7B,SAAS,iBAAiB,MAAoB;AACjD,MAAI,OAAO,WAAW,eAAe,OAAO,OAAO,aAAa,aAAa;AACzE,UAAM,IAAI;AAAA,MACN,GAAG,IAAI;AAAA,IAKX;AAAA,EACJ;AACJ;;;AD+EO,IAAM,kBAAN,MAAsB;AAAA,EAyBzB,YAAY,QAA+B;AAF3C,SAAQ,cAA6C;AAGjD,qBAAiB,iBAAiB;AAElC,QAAI,CAAC,OAAO,SAAS;AACjB,YAAM,IAAI,mCAAoB,qBAAqB;AAAA,IACvD;AACA,QAAI,CAAC,OAAO,WAAW;AACnB,YAAM,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,MAAM;AACrB,YAAI,OAAO,WAAW,MAAM,GAAG;AAC3B,UAAC,cAA4C,cAAc;AAC3D,iBAAO;AAAA,QACX;AACA,QAAC,cAAuC,SAAS;AACjD,eAAO,KAAK,eAAe;AAAA,MAC/B;AAAA,IACJ;AAEA,UAAM,gBAAgB,IAAI,kBAAkB,MAAM;AAElD,WAAO;AAAA,MACH,QAAQ;AAAA,MACR;AAAA,MACA,OAAU,UAAiD;AACvD,eAAO,IAAI,SAAS,aAAa;AAAA,MACrC;AAAA,IACJ;AAAA,EACJ;AACJ;;;AFrRA,0BAAc,6BAzBd;","names":["import_shared"]}
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
// ../../node_modules/tsup/assets/esm_shims.js
|
|
2
|
+
import path from "path";
|
|
3
|
+
import { fileURLToPath } from "url";
|
|
4
|
+
var getFilename = () => fileURLToPath(import.meta.url);
|
|
5
|
+
var getDirname = () => path.dirname(getFilename());
|
|
6
|
+
var __dirname = /* @__PURE__ */ getDirname();
|
|
7
|
+
|
|
8
|
+
// src/backend.ts
|
|
9
|
+
import {
|
|
10
|
+
HttpClient,
|
|
11
|
+
PermissionsModule,
|
|
12
|
+
ZanzibarModule,
|
|
13
|
+
AbacModule,
|
|
14
|
+
AuthModule,
|
|
15
|
+
AgentsModule,
|
|
16
|
+
ApprovalsModule,
|
|
17
|
+
DelegationModule,
|
|
18
|
+
JitModule,
|
|
19
|
+
McpModule,
|
|
20
|
+
LumoAuthConfigError as LumoAuthConfigError2
|
|
21
|
+
} from "@lumoauth/shared";
|
|
22
|
+
import { createRequire } from "module";
|
|
23
|
+
|
|
24
|
+
// src/guard.ts
|
|
25
|
+
import { LumoAuthConfigError } from "@lumoauth/shared";
|
|
26
|
+
function assertServerOnly(what) {
|
|
27
|
+
if (typeof window !== "undefined" && typeof window.document !== "undefined") {
|
|
28
|
+
throw new LumoAuthConfigError(
|
|
29
|
+
`${what} is server-only and was constructed in a browser. @lumoauth/backend holds credentials that authenticate as your entire organization, so it must never ship to the client. Import @lumoauth/client in browser code, and keep this import in a route handler, server component, or API route.`
|
|
30
|
+
);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// src/backend.ts
|
|
35
|
+
var LumoAuthBackend = class {
|
|
36
|
+
constructor(config) {
|
|
37
|
+
this.apiInstance = null;
|
|
38
|
+
assertServerOnly("LumoAuthBackend");
|
|
39
|
+
if (!config.baseUrl) {
|
|
40
|
+
throw new LumoAuthConfigError2("baseUrl is required");
|
|
41
|
+
}
|
|
42
|
+
if (!config.secretKey) {
|
|
43
|
+
throw new LumoAuthConfigError2(
|
|
44
|
+
"secretKey is required. For browser code use @lumoauth/client with a user access token instead."
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
this.baseUrl = config.baseUrl.replace(/\/+$/, "");
|
|
48
|
+
this.secretProvider = typeof config.secretKey === "function" ? config.secretKey : () => config.secretKey;
|
|
49
|
+
const httpConfig = {
|
|
50
|
+
baseUrl: config.baseUrl,
|
|
51
|
+
token: config.secretKey,
|
|
52
|
+
timeout: config.timeout,
|
|
53
|
+
fetch: config.fetch,
|
|
54
|
+
headers: config.headers
|
|
55
|
+
};
|
|
56
|
+
this.http = new HttpClient(httpConfig);
|
|
57
|
+
const orgId = config.orgId ?? "";
|
|
58
|
+
this.permissions = new PermissionsModule(this.http, { cache: config.cache });
|
|
59
|
+
this.zanzibar = new ZanzibarModule(this.http);
|
|
60
|
+
this.abac = new AbacModule(this.http, orgId);
|
|
61
|
+
this.agents = new AgentsModule(this.http, orgId);
|
|
62
|
+
this.approvals = new ApprovalsModule(this.http, orgId);
|
|
63
|
+
this.jit = new JitModule(this.http, orgId);
|
|
64
|
+
this.mcp = new McpModule({
|
|
65
|
+
baseUrl: this.baseUrl,
|
|
66
|
+
orgId,
|
|
67
|
+
token: this.secretProvider,
|
|
68
|
+
fetch: config.fetch
|
|
69
|
+
});
|
|
70
|
+
this.delegation = new DelegationModule({
|
|
71
|
+
baseUrl: this.baseUrl,
|
|
72
|
+
orgId,
|
|
73
|
+
clientId: config.clientId ?? "",
|
|
74
|
+
clientSecret: config.clientSecret,
|
|
75
|
+
redirectUri: config.redirectUri,
|
|
76
|
+
agentToken: this.secretProvider,
|
|
77
|
+
fetch: config.fetch
|
|
78
|
+
});
|
|
79
|
+
const authConfig = {
|
|
80
|
+
baseUrl: config.baseUrl,
|
|
81
|
+
orgId,
|
|
82
|
+
clientId: config.clientId ?? "",
|
|
83
|
+
fetch: config.fetch
|
|
84
|
+
};
|
|
85
|
+
this.auth = new AuthModule(authConfig);
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* @deprecated Renamed to {@link agents}. This alias will be removed
|
|
89
|
+
* before 2.0.
|
|
90
|
+
*/
|
|
91
|
+
get agent() {
|
|
92
|
+
return this.agents;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Escape hatch to the full generated REST surface (`@lumoauth/api-client`)
|
|
96
|
+
* — every admin endpoint, SCIM, audit logs — pre-configured with this
|
|
97
|
+
* backend's base URL and credential.
|
|
98
|
+
*
|
|
99
|
+
* Loaded lazily on first access so apps that never reach for it don't
|
|
100
|
+
* pay for it. Requires `@lumoauth/api-client` to be installed:
|
|
101
|
+
*
|
|
102
|
+
* ```sh
|
|
103
|
+
* npm install @lumoauth/api-client
|
|
104
|
+
* ```
|
|
105
|
+
*/
|
|
106
|
+
get api() {
|
|
107
|
+
if (!this.apiInstance) {
|
|
108
|
+
this.apiInstance = this.loadApiClient();
|
|
109
|
+
}
|
|
110
|
+
return this.apiInstance;
|
|
111
|
+
}
|
|
112
|
+
/** Clear all server-side caches. */
|
|
113
|
+
clearCache() {
|
|
114
|
+
this.permissions.clearCache();
|
|
115
|
+
}
|
|
116
|
+
// ── Internal ──────────────────────────────────────────────────────
|
|
117
|
+
loadApiClient() {
|
|
118
|
+
let mod;
|
|
119
|
+
try {
|
|
120
|
+
const requireFn = createRequire(
|
|
121
|
+
typeof __dirname === "string" ? `${__dirname}/` : import.meta.url
|
|
122
|
+
);
|
|
123
|
+
mod = requireFn("@lumoauth/api-client");
|
|
124
|
+
} catch (error) {
|
|
125
|
+
throw new LumoAuthConfigError2(
|
|
126
|
+
`lumo.api requires the generated client \`@lumoauth/api-client\`, which is not installed. Install it with \`npm install @lumoauth/api-client\` (it covers the full REST surface \u2014 admin endpoints, SCIM, audit logs) and try again. Original error: ${error instanceof Error ? error.message : String(error)}`
|
|
127
|
+
);
|
|
128
|
+
}
|
|
129
|
+
const ConfigurationCtor = mod.Configuration;
|
|
130
|
+
if (typeof ConfigurationCtor !== "function") {
|
|
131
|
+
throw new LumoAuthConfigError2(
|
|
132
|
+
"@lumoauth/api-client was found but does not export `Configuration` \u2014 is the installed version compatible (>=0.1.0)?"
|
|
133
|
+
);
|
|
134
|
+
}
|
|
135
|
+
const params = { basePath: this.baseUrl };
|
|
136
|
+
const probe = this.secretProvider();
|
|
137
|
+
if (typeof probe === "string") {
|
|
138
|
+
if (probe.startsWith("lmk_")) {
|
|
139
|
+
params.apiKey = () => this.secretProvider();
|
|
140
|
+
} else {
|
|
141
|
+
params.accessToken = () => this.secretProvider();
|
|
142
|
+
}
|
|
143
|
+
} else {
|
|
144
|
+
params.apiKey = async () => {
|
|
145
|
+
const secret = await probe;
|
|
146
|
+
if (!secret.startsWith("lmk_")) {
|
|
147
|
+
configuration.apiKey = void 0;
|
|
148
|
+
return void 0;
|
|
149
|
+
}
|
|
150
|
+
configuration.accessToken = void 0;
|
|
151
|
+
return this.secretProvider();
|
|
152
|
+
};
|
|
153
|
+
params.accessToken = async () => {
|
|
154
|
+
const secret = await probe;
|
|
155
|
+
if (secret.startsWith("lmk_")) {
|
|
156
|
+
configuration.accessToken = void 0;
|
|
157
|
+
return "";
|
|
158
|
+
}
|
|
159
|
+
configuration.apiKey = void 0;
|
|
160
|
+
return this.secretProvider();
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
const configuration = new ConfigurationCtor(params);
|
|
164
|
+
return {
|
|
165
|
+
module: mod,
|
|
166
|
+
configuration,
|
|
167
|
+
create(apiClass) {
|
|
168
|
+
return new apiClass(configuration);
|
|
169
|
+
}
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
};
|
|
173
|
+
|
|
174
|
+
// src/index.ts
|
|
175
|
+
export * from "@lumoauth/shared";
|
|
176
|
+
export {
|
|
177
|
+
LumoAuthBackend,
|
|
178
|
+
assertServerOnly
|
|
179
|
+
};
|
|
180
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../node_modules/tsup/assets/esm_shims.js","../src/backend.ts","../src/guard.ts","../src/index.ts"],"sourcesContent":["// Shim globals in esm bundle\nimport path from 'node:path'\nimport { fileURLToPath } from 'node:url'\n\nconst getFilename = () => fileURLToPath(import.meta.url)\nconst getDirname = () => path.dirname(getFilename())\n\nexport const __dirname = /* @__PURE__ */ getDirname()\nexport const __filename = /* @__PURE__ */ getFilename()\n","import {\n HttpClient,\n type HttpClientConfig,\n PermissionsModule,\n type PermissionsModuleOptions,\n ZanzibarModule,\n AbacModule,\n AuthModule,\n type AuthModuleConfig,\n AgentsModule,\n ApprovalsModule,\n DelegationModule,\n JitModule,\n McpModule,\n LumoAuthConfigError,\n} from '@lumoauth/shared';\nimport { createRequire } from 'node:module';\nimport { assertServerOnly } from './guard';\n\nexport interface LumoAuthBackendConfig {\n /**\n * Base URL of your LumoAuth instance.\n * @example \"https://app.lumoauth.dev\"\n */\n baseUrl: string;\n\n /**\n * Server credential — a tenant API key (`lmk_…`) or a machine access\n * token. Unlike the browser client, this may be a long-lived secret.\n *\n * Load it from the environment. Never inline it, and never expose it\n * through a framework's public-env mechanism (`NEXT_PUBLIC_*`, `VITE_*`).\n */\n secretKey: string | (() => string | Promise<string>);\n\n /** Organization slug. Required for org-scoped surfaces (ABAC, agents). */\n orgId?: string;\n\n /** OAuth client ID, when using the auth or delegation modules server-side. */\n clientId?: string;\n\n /**\n * OAuth client secret for confidential flows — required by\n * `delegation` for the consent-code exchange and revocation.\n */\n clientSecret?: string;\n\n /** OAuth callback URL for the delegation consent flow. */\n redirectUri?: string;\n\n /** Request timeout in milliseconds. */\n timeout?: number;\n\n /** Custom fetch implementation. */\n fetch?: typeof globalThis.fetch;\n\n /** Extra headers applied to every request. */\n headers?: Record<string, string>;\n\n /** Permission cache configuration; `false` disables caching. */\n cache?: boolean | PermissionsModuleOptions['cache'];\n}\n\n/**\n * The generated OpenAPI client (`@lumoauth/api-client`), pre-configured with\n * this backend's base URL and credential. Loosely typed here so the backend\n * package does not take a compile-time dependency on the generated code.\n */\nexport interface LumoAuthApiEscapeHatch {\n /** The raw `@lumoauth/api-client` module (`AgentsApi`, `AdminUsersApi`, …). */\n readonly module: Record<string, unknown>;\n /** A `Configuration` instance carrying this backend's baseUrl + credential. */\n readonly configuration: unknown;\n /**\n * Instantiate a generated API class with this backend's configuration.\n *\n * ```ts\n * const { AdminUsersApi } = lumo.api.module;\n * const users = lumo.api.create(AdminUsersApi);\n * ```\n */\n create<T>(apiClass: new (configuration?: unknown) => T): T;\n}\n\n/**\n * Server-side LumoAuth client.\n *\n * Same authorization surface as `@lumoauth/client`, but credentialed for a\n * server and guarded against browser construction.\n *\n * ```ts\n * // app/api/documents/route.ts\n * import { LumoAuthBackend } from '@lumoauth/backend';\n *\n * const lumo = new LumoAuthBackend({\n * baseUrl: process.env.LUMOAUTH_URL!,\n * secretKey: process.env.LUMOAUTH_SECRET_KEY!,\n * orgId: 'acme-corp',\n * });\n *\n * const allowed = await lumo.permissions.check('documents.edit');\n * ```\n *\n * For admin operations (users, roles, webhooks, audit logs) use the `api`\n * escape hatch — the ~200 generated endpoints are already typed and\n * regenerated from the OpenAPI spec.\n */\nexport class LumoAuthBackend {\n /** RBAC permission checks. */\n public readonly permissions: PermissionsModule;\n /** Zanzibar-style (ReBAC) relationship checks. */\n public readonly zanzibar: ZanzibarModule;\n /** ABAC policy evaluation and attribute management. */\n public readonly abac: AbacModule;\n /** OAuth 2.0 — token exchange and refresh, including confidential clients. */\n public readonly auth: AuthModule;\n /** Agent identity — ask/isAllowed, self-inspection, registration. */\n public readonly agents: AgentsModule;\n /** Push-approval-for-agent-actions. */\n public readonly approvals: ApprovalsModule;\n /** Chain of Agency — RFC 8693 delegation and nested agent chains. */\n public readonly delegation: DelegationModule;\n /** Just-in-Time permissions — ephemeral tasks and scoped tokens. */\n public readonly jit: JitModule;\n /** Token exchange for secured MCP servers. */\n public readonly mcp: McpModule;\n\n private readonly http: HttpClient;\n private readonly baseUrl: string;\n private readonly secretProvider: () => string | Promise<string>;\n private apiInstance: LumoAuthApiEscapeHatch | null = null;\n\n constructor(config: LumoAuthBackendConfig) {\n assertServerOnly('LumoAuthBackend');\n\n if (!config.baseUrl) {\n throw new LumoAuthConfigError('baseUrl is required');\n }\n if (!config.secretKey) {\n throw new LumoAuthConfigError(\n 'secretKey is required. For browser code use @lumoauth/client with a user access token instead.',\n );\n }\n\n this.baseUrl = config.baseUrl.replace(/\\/+$/, '');\n this.secretProvider =\n typeof config.secretKey === 'function'\n ? config.secretKey\n : () => config.secretKey as string;\n\n const httpConfig: HttpClientConfig = {\n baseUrl: config.baseUrl,\n token: config.secretKey,\n timeout: config.timeout,\n fetch: config.fetch,\n headers: config.headers,\n };\n this.http = new HttpClient(httpConfig);\n\n const orgId = config.orgId ?? '';\n\n this.permissions = new PermissionsModule(this.http, { cache: config.cache });\n this.zanzibar = new ZanzibarModule(this.http);\n this.abac = new AbacModule(this.http, orgId);\n this.agents = new AgentsModule(this.http, orgId);\n this.approvals = new ApprovalsModule(this.http, orgId);\n this.jit = new JitModule(this.http, orgId);\n this.mcp = new McpModule({\n baseUrl: this.baseUrl,\n orgId,\n token: this.secretProvider,\n fetch: config.fetch,\n });\n this.delegation = new DelegationModule({\n baseUrl: this.baseUrl,\n orgId,\n clientId: config.clientId ?? '',\n clientSecret: config.clientSecret,\n redirectUri: config.redirectUri,\n agentToken: this.secretProvider,\n fetch: config.fetch,\n });\n\n const authConfig: AuthModuleConfig = {\n baseUrl: config.baseUrl,\n orgId,\n clientId: config.clientId ?? '',\n fetch: config.fetch,\n };\n this.auth = new AuthModule(authConfig);\n }\n\n /**\n * @deprecated Renamed to {@link agents}. This alias will be removed\n * before 2.0.\n */\n get agent(): AgentsModule {\n return this.agents;\n }\n\n /**\n * Escape hatch to the full generated REST surface (`@lumoauth/api-client`)\n * — every admin endpoint, SCIM, audit logs — pre-configured with this\n * backend's base URL and credential.\n *\n * Loaded lazily on first access so apps that never reach for it don't\n * pay for it. Requires `@lumoauth/api-client` to be installed:\n *\n * ```sh\n * npm install @lumoauth/api-client\n * ```\n */\n get api(): LumoAuthApiEscapeHatch {\n if (!this.apiInstance) {\n this.apiInstance = this.loadApiClient();\n }\n return this.apiInstance;\n }\n\n /** Clear all server-side caches. */\n clearCache(): void {\n this.permissions.clearCache();\n }\n\n // ── Internal ──────────────────────────────────────────────────────\n\n private loadApiClient(): LumoAuthApiEscapeHatch {\n let mod: Record<string, unknown>;\n try {\n // Works from both the CJS build (__dirname) and the ESM build\n // (import.meta.url). `@lumoauth/backend` is Node-only, so\n // node:module is always available, and module resolution walks\n // up from this package to the host app's node_modules.\n const requireFn: NodeRequire = createRequire(\n typeof __dirname === 'string' ? `${__dirname}/` : import.meta.url,\n );\n mod = requireFn('@lumoauth/api-client') as Record<string, unknown>;\n } catch (error) {\n throw new LumoAuthConfigError(\n 'lumo.api requires the generated client `@lumoauth/api-client`, which is not installed. ' +\n 'Install it with `npm install @lumoauth/api-client` (it covers the full REST surface — ' +\n 'admin endpoints, SCIM, audit logs) and try again. ' +\n `Original error: ${error instanceof Error ? error.message : String(error)}`,\n );\n }\n\n const ConfigurationCtor = mod.Configuration as\n | (new (params: Record<string, unknown>) => unknown)\n | undefined;\n if (typeof ConfigurationCtor !== 'function') {\n throw new LumoAuthConfigError(\n '@lumoauth/api-client was found but does not export `Configuration` — ' +\n 'is the installed version compatible (>=0.1.0)?',\n );\n }\n\n // The backend credential may be an API key (lmk_…, sent as X-API-Key)\n // or a bearer token (sent as Authorization). The generated client\n // emits a header for every configured scheme, so only the slot\n // matching the credential's shape may be populated.\n const params: Record<string, unknown> = { basePath: this.baseUrl };\n const probe = this.secretProvider();\n if (typeof probe === 'string') {\n if (probe.startsWith('lmk_')) {\n params.apiKey = () => this.secretProvider();\n } else {\n params.accessToken = () => this.secretProvider();\n }\n } else {\n // Async provider: shape unknown until first resolution. Route by\n // shape per call, then drop the mismatched slot so subsequent\n // requests carry exactly one auth header.\n params.apiKey = async () => {\n const secret = await probe;\n if (!secret.startsWith('lmk_')) {\n (configuration as { apiKey?: unknown }).apiKey = undefined;\n return undefined;\n }\n (configuration as { accessToken?: unknown }).accessToken = undefined;\n return this.secretProvider();\n };\n params.accessToken = async () => {\n const secret = await probe;\n if (secret.startsWith('lmk_')) {\n (configuration as { accessToken?: unknown }).accessToken = undefined;\n return '';\n }\n (configuration as { apiKey?: unknown }).apiKey = undefined;\n return this.secretProvider();\n };\n }\n\n const configuration = new ConfigurationCtor(params);\n\n return {\n module: mod,\n configuration,\n create<T>(apiClass: new (configuration?: unknown) => T): T {\n return new apiClass(configuration);\n },\n };\n }\n}\n","import { LumoAuthConfigError } from '@lumoauth/shared';\n\n/**\n * Refuse to run server-credentialed code in a browser.\n *\n * This is the mirror of `@lumoauth/client`'s guard. That one stops a server\n * credential reaching browser code; this one stops browser code reaching for a\n * server credential in the first place.\n *\n * The check is intentionally `window.document` rather than just `window`:\n * some server runtimes define a bare `window` global, and failing there would\n * be a false positive on a legitimate server.\n *\n * Web Workers and edge runtimes have no `document`, so they pass. That is\n * deliberate — an edge function is a server, and it is a supported place to\n * hold a secret. What this catches is the case that actually leaks: a module\n * that ends up in a bundle served to a real browser.\n */\nexport function assertServerOnly(what: string): void {\n if (typeof window !== 'undefined' && typeof window.document !== 'undefined') {\n throw new LumoAuthConfigError(\n `${what} is server-only and was constructed in a browser. ` +\n '@lumoauth/backend holds credentials that authenticate as your ' +\n 'entire organization, so it must never ship to the client. Import ' +\n '@lumoauth/client in browser code, and keep this import in a route ' +\n 'handler, server component, or API route.',\n );\n }\n}\n","// @lumoauth/backend — the server SDK.\n//\n// The counterpart to @lumoauth/client. This package expects server\n// credentials (a tenant API key, `lmk_…`, or a machine token) and refuses to\n// construct in a browser, so a server credential cannot reach a client bundle\n// by accident.\n//\n// For the full REST surface — every admin endpoint, SCIM, audit logs — use\n// the `lumo.api` escape hatch, which lazily loads the generated client\n// `@lumoauth/api-client` pre-configured with this backend's credential. It is\n// declared as an optional peer dependency because the generated client is not\n// yet published to a registry.\n// TODO(publish): once @lumoauth/api-client is published, drop\n// `peerDependenciesMeta.optional` in package.json so installs pull it in by\n// default (the lazy getter already handles both cases).\n\nexport {\n LumoAuthBackend,\n type LumoAuthBackendConfig,\n type LumoAuthApiEscapeHatch,\n} from './backend';\nexport { assertServerOnly } from './guard';\n\n// The full isomorphic surface: authorization modules, OAuth/PKCE helpers,\n// schemas, errors, and the HTTP client.\nexport * from '@lumoauth/shared';\n"],"mappings":";AACA,OAAO,UAAU;AACjB,SAAS,qBAAqB;AAE9B,IAAM,cAAc,MAAM,cAAc,YAAY,GAAG;AACvD,IAAM,aAAa,MAAM,KAAK,QAAQ,YAAY,CAAC;AAE5C,IAAM,YAA4B,2BAAW;;;ACPpD;AAAA,EACI;AAAA,EAEA;AAAA,EAEA;AAAA,EACA;AAAA,EACA;AAAA,EAEA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,uBAAAA;AAAA,OACG;AACP,SAAS,qBAAqB;;;AChB9B,SAAS,2BAA2B;AAkB7B,SAAS,iBAAiB,MAAoB;AACjD,MAAI,OAAO,WAAW,eAAe,OAAO,OAAO,aAAa,aAAa;AACzE,UAAM,IAAI;AAAA,MACN,GAAG,IAAI;AAAA,IAKX;AAAA,EACJ;AACJ;;;AD+EO,IAAM,kBAAN,MAAsB;AAAA,EAyBzB,YAAY,QAA+B;AAF3C,SAA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AAC5B,UAAC,cAAuC,SAAS;AACjD,iBAAO;AAAA,QACX;AACA,QAAC,cAA4C,cAAc;AAC3D,eAAO,KAAK,eAAe;AAAA,MAC/B;AACA,aAAO,cAAc,YAAY;AAC7B,cAAM,SAAS,MAAM;AACrB,YAAI,OAAO,WAAW,MAAM,GAAG;AAC3B,UAAC,cAA4C,cAAc;AAC3D,iBAAO;AAAA,QACX;AACA,QAAC,cAAuC,SAAS;AACjD,eAAO,KAAK,eAAe;AAAA,MAC/B;AAAA,IACJ;AAEA,UAAM,gBAAgB,IAAI,kBAAkB,MAAM;AAElD,WAAO;AAAA,MACH,QAAQ;AAAA,MACR;AAAA,MACA,OAAU,UAAiD;AACvD,eAAO,IAAI,SAAS,aAAa;AAAA,MACrC;AAAA,IACJ;AAAA,EACJ;AACJ;;;AErRA,cAAc;","names":["LumoAuthConfigError","LumoAuthConfigError"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,60 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
2
|
+
"name": "@lumoauth/backend",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Official LumoAuth server SDK — token verification and server-side auth. Never import this from browser code.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"author": "LumoAuth",
|
|
7
|
+
"publishConfig": {
|
|
8
|
+
"access": "public",
|
|
9
|
+
"provenance": true
|
|
10
|
+
},
|
|
11
|
+
"main": "dist/index.js",
|
|
12
|
+
"module": "dist/index.mjs",
|
|
13
|
+
"types": "dist/index.d.ts",
|
|
14
|
+
"exports": {
|
|
15
|
+
".": {
|
|
16
|
+
"types": "./dist/index.d.ts",
|
|
17
|
+
"import": "./dist/index.mjs",
|
|
18
|
+
"require": "./dist/index.js"
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
"files": [
|
|
22
|
+
"dist",
|
|
23
|
+
"README.md",
|
|
24
|
+
"LICENSE"
|
|
25
|
+
],
|
|
26
|
+
"scripts": {
|
|
27
|
+
"build": "tsup",
|
|
28
|
+
"dev": "tsup --watch",
|
|
29
|
+
"typecheck": "tsc --noEmit",
|
|
30
|
+
"prepublishOnly": "npm run build",
|
|
31
|
+
"test": "npm run build && node --test tests/*.test.mjs"
|
|
32
|
+
},
|
|
33
|
+
"keywords": [
|
|
34
|
+
"lumoauth",
|
|
35
|
+
"backend",
|
|
36
|
+
"server",
|
|
37
|
+
"jwt"
|
|
38
|
+
],
|
|
39
|
+
"dependencies": {
|
|
40
|
+
"@lumoauth/shared": "^1.0.0",
|
|
41
|
+
"zod": "^3.24.0"
|
|
42
|
+
},
|
|
43
|
+
"devDependencies": {
|
|
44
|
+
"@types/node": "^20.19.43",
|
|
45
|
+
"tsup": "^8.0.0",
|
|
46
|
+
"typescript": "^5.5.0"
|
|
47
|
+
},
|
|
48
|
+
"engines": {
|
|
49
|
+
"node": ">=18.0.0"
|
|
50
|
+
},
|
|
51
|
+
"sideEffects": false,
|
|
52
|
+
"peerDependencies": {
|
|
53
|
+
"@lumoauth/api-client": ">=0.1.0"
|
|
54
|
+
},
|
|
55
|
+
"peerDependenciesMeta": {
|
|
56
|
+
"@lumoauth/api-client": {
|
|
57
|
+
"optional": true
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|