@lumoauth/backend 0.0.0-stage → 1.1.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 +223 -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,224 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @lumoauth/backend
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[](https://www.npmjs.com/package/@lumoauth/backend)
|
|
4
|
+
[](./LICENSE)
|
|
5
|
+
|
|
6
|
+
> The LumoAuth server SDK for Node. It holds a server credential, throws an error
|
|
7
|
+
> in a browser, and gives you every namespace plus an escape hatch to the
|
|
8
|
+
> full generated REST client.
|
|
9
|
+
|
|
10
|
+
This package is part of the [LumoAuth JavaScript SDK](../../README.md). Not
|
|
11
|
+
sure that it is the package that you need? See
|
|
12
|
+
[Which package do I need?](../../README.md#which-package-do-i-need).
|
|
13
|
+
|
|
14
|
+
## Contents
|
|
15
|
+
|
|
16
|
+
- [Is this the right package?](#is-this-the-right-package)
|
|
17
|
+
- [Install](#install)
|
|
18
|
+
- [Quick start](#quick-start)
|
|
19
|
+
- [Which credential to use](#which-credential-to-use)
|
|
20
|
+
- [Configuration](#configuration)
|
|
21
|
+
- [Namespaces](#namespaces)
|
|
22
|
+
- [The `api` escape hatch](#the-api-escape-hatch)
|
|
23
|
+
- [Security model](#security-model)
|
|
24
|
+
- [Troubleshooting](#troubleshooting)
|
|
25
|
+
- [Related packages](#related-packages)
|
|
26
|
+
- [Learn more](#learn-more)
|
|
27
|
+
- [License](#license)
|
|
28
|
+
|
|
29
|
+
## Is this the right package?
|
|
30
|
+
|
|
31
|
+
| You are… | Use |
|
|
32
|
+
|---|---|
|
|
33
|
+
| Running **Express** | [`@lumoauth/express`](../express/README.md). It adds the login routes for you and re-exports this package |
|
|
34
|
+
| Running **Next.js** | [`@lumoauth/nextjs`](../nextjs/README.md) |
|
|
35
|
+
| Running any other Node server, worker, cron job or script | **This package** |
|
|
36
|
+
| Writing an **AI agent** that signs in as itself | [`@lumoauth/agent`](../agent/README.md) |
|
|
37
|
+
| Writing browser code | [`@lumoauth/client`](../client/README.md). This package throws an error in a browser |
|
|
38
|
+
|
|
39
|
+
## Install
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
npm install @lumoauth/backend
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
This package needs Node 18 or newer.
|
|
46
|
+
|
|
47
|
+
## Quick start
|
|
48
|
+
|
|
49
|
+
A permission check answers for the subject of the credential. To check a
|
|
50
|
+
signed-in user, pass that user's access token as `secretKey`. A server that
|
|
51
|
+
holds an organization API key can name the user instead; see
|
|
52
|
+
[Which credential to use](#which-credential-to-use).
|
|
53
|
+
|
|
54
|
+
```ts
|
|
55
|
+
import { LumoAuthBackend } from '@lumoauth/backend';
|
|
56
|
+
|
|
57
|
+
function lumoFor(accessToken: string) {
|
|
58
|
+
return new LumoAuthBackend({
|
|
59
|
+
baseUrl: process.env.LUMOAUTH_URL!, // https://app.lumoauth.dev
|
|
60
|
+
secretKey: accessToken,
|
|
61
|
+
orgId: 'acme-corp',
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const lumo = lumoFor(userAccessToken);
|
|
66
|
+
|
|
67
|
+
const canEdit = await lumo.permissions.check('documents.edit'); // RBAC
|
|
68
|
+
const isOwner = await lumo.zanzibar.isOwner('folder:projects', 'user:alice'); // relationships
|
|
69
|
+
const decision = await lumo.abac.check({ resourceType: 'document', resourceId: 'doc-123', action: 'read' }); // ABAC, needs abac:read
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
The ABAC call needs the `abac:read` scope on the user's token. The
|
|
73
|
+
[workspace README](../../README.md#scopes) lists every scope.
|
|
74
|
+
|
|
75
|
+
## Which credential to use
|
|
76
|
+
|
|
77
|
+
`secretKey` is the credential for every namespace call. An organization API
|
|
78
|
+
key (`lmk_…`) is sent in `X-API-Key`. Any other value is sent as
|
|
79
|
+
`Authorization: Bearer`.
|
|
80
|
+
|
|
81
|
+
| You pass | Namespace calls answer for | Notes |
|
|
82
|
+
|---|---|---|
|
|
83
|
+
| A user access token | that user | The usual choice. Some calls need a scope, for example `authz:read` for `permissions.list()` |
|
|
84
|
+
| An agent's access token | that agent | Agents usually use [`@lumoauth/agent`](../agent/README.md), which gets and refreshes this token for you |
|
|
85
|
+
| An organization API key (`lmk_…`) | the key's owner, or the user that you name | The key works on the permission and Zanzibar checks and in the [`api` escape hatch](#the-api-escape-hatch). The server rejects it on the ABAC, agent and JIT routes |
|
|
86
|
+
|
|
87
|
+
With an API key, name the user whose permission you want to check. The id is
|
|
88
|
+
the LumoAuth user id, which is the `sub` claim of that user's token. The key
|
|
89
|
+
needs the `authz:check` scope for this.
|
|
90
|
+
|
|
91
|
+
```ts
|
|
92
|
+
const lumo = new LumoAuthBackend({
|
|
93
|
+
baseUrl: process.env.LUMOAUTH_URL!,
|
|
94
|
+
secretKey: process.env.LUMOAUTH_API_KEY!, // lmk_…, with the authz:check scope
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
const allowed = await lumo.permissions.check('documents.edit', undefined, { userId: session.sub });
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
Approvals, JIT tasks and delegation accept agent credentials only. Call them
|
|
101
|
+
from `@lumoauth/agent`.
|
|
102
|
+
|
|
103
|
+
## Configuration
|
|
104
|
+
|
|
105
|
+
`new LumoAuthBackend(config)` accepts:
|
|
106
|
+
|
|
107
|
+
| Option | Type | Required | Description |
|
|
108
|
+
|---|---|---|---|
|
|
109
|
+
| `baseUrl` | `string` | yes | The LumoAuth host, for example `https://app.lumoauth.dev` |
|
|
110
|
+
| `secretKey` | `string \| () => string \| Promise<string>` | yes | The credential, as described above. A function is called before each request. Load secrets from the environment. Never put them in code or in `NEXT_PUBLIC_*` or `VITE_*` variables |
|
|
111
|
+
| `orgId` | `string` | for org-scoped calls | The organization slug. `abac`, `agents`, `approvals`, `jit`, `mcp` and `delegation` need it |
|
|
112
|
+
| `clientId` | `string` | for `auth` and `delegation` | The OAuth client ID |
|
|
113
|
+
| `clientSecret` | `string` | for `delegation` | The OAuth client secret for the consent-code exchange and for revocation |
|
|
114
|
+
| `redirectUri` | `string` | for `delegation` | The callback URL of the delegation consent flow |
|
|
115
|
+
| `timeout` | `number` | no | Request timeout in milliseconds. Default 30 000 |
|
|
116
|
+
| `fetch` | `typeof fetch` | no | A custom `fetch` |
|
|
117
|
+
| `headers` | `Record<string, string>` | no | Extra headers on every request |
|
|
118
|
+
| `cache` | `boolean \| { ttl?: number; maxSize?: number }` | no | The cache for permission checks. Default: on, 5 minutes, 1 000 entries. `false` turns it off |
|
|
119
|
+
|
|
120
|
+
The constructor throws `LumoAuthConfigError` when `baseUrl` or `secretKey` is
|
|
121
|
+
missing. Nothing is read from the environment. By convention the values come
|
|
122
|
+
from `LUMOAUTH_URL` and `LUMOAUTH_SECRET_KEY`.
|
|
123
|
+
|
|
124
|
+
## Namespaces
|
|
125
|
+
|
|
126
|
+
| Namespace | What it does | Methods |
|
|
127
|
+
|---|---|---|
|
|
128
|
+
| `permissions` | RBAC checks for the credential's subject | `check`, `checkDetailed`, `checkBulk`, `checkAny`, `checkAll`, `checkAnyDetailed`, `checkAllDetailed`, `list`, `listSlugs`, `clearCache` |
|
|
129
|
+
| `zanzibar` | Relationship checks | `check`, `checkDetailed`, `expand`, `isViewer`, `isEditor`, `isOwner`, `isMember`, `isAdmin` |
|
|
130
|
+
| `abac` | Attribute-based decisions and attributes | `check`, `isAllowed`, `checkBulk`, `getMyAttributes`, `setUserAttribute`, `getResourceAttributes`, `setResourceAttribute`, `getAttributeDefinitions` |
|
|
131
|
+
| `auth` | OAuth 2.0 flows on the server | `buildAuthorizationUrl`, `exchangeCodeForTokens`, `refreshToken`, `revokeToken`, `getUserInfo`, `passwordGrant` |
|
|
132
|
+
| `agents` | Agent identity | `ask`, `isAllowed`, `me`, `getCurrentAgent`, `capabilities`, `budget`, `register` |
|
|
133
|
+
| `approvals` | Push approval for agent actions (agent credentials only) | `require`, `create`, `getStatus`, `wait` |
|
|
134
|
+
| `delegation` | Act for a user with RFC 8693 token exchange | `getConsentUrl`, `handleConsentCallback`, `setUserToken`, `exchange`, `request`, `delegateToSubAgent`, `revoke`, `revokeAll` |
|
|
135
|
+
| `jit` | Just-in-time permissions | `createTask`, `requestPermission`, `getRequestStatus`, `getToken`, `evaluateTask`, `completeTask`, `listPendingRequests` |
|
|
136
|
+
| `mcp` | Tokens for secured MCP servers | `getToken`, `getTokenDetailed`. The server ID is the MCP server's https URL, which becomes the token's `aud` |
|
|
137
|
+
|
|
138
|
+
`lumo.clearCache()` clears the permission cache. The parameters, return
|
|
139
|
+
values and required credentials of every method are in the
|
|
140
|
+
[workspace API reference](../../README.md#api-reference), with a guide for
|
|
141
|
+
each namespace. This package re-exports all of
|
|
142
|
+
[`@lumoauth/shared`](../shared/README.md), so one import covers the client and
|
|
143
|
+
the error classes:
|
|
144
|
+
|
|
145
|
+
```ts
|
|
146
|
+
import { LumoAuthBackend, LumoAuthPermissionDeniedError } from '@lumoauth/backend';
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
## The `api` escape hatch
|
|
150
|
+
|
|
151
|
+
The namespaces cover the high-level calls. For the other REST operations
|
|
152
|
+
(admin users and roles, webhooks, SCIM, audit logs, …), `lumo.api` loads the
|
|
153
|
+
generated OpenAPI client `@lumoauth/api-client` when you first use it. The
|
|
154
|
+
client comes configured with this backend's base URL and credential:
|
|
155
|
+
|
|
156
|
+
```ts
|
|
157
|
+
const lumo = new LumoAuthBackend({
|
|
158
|
+
baseUrl: process.env.LUMOAUTH_URL!,
|
|
159
|
+
secretKey: process.env.LUMOAUTH_SECRET_KEY!, // an lmk_… organization API key
|
|
160
|
+
orgId: 'acme-corp',
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
const { AdminUsersApi, AdminWebhooksApi } = lumo.api.module;
|
|
164
|
+
const users = lumo.api.create(AdminUsersApi);
|
|
165
|
+
const hooks = lumo.api.create(AdminWebhooksApi);
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
The escape hatch sends an `lmk_…` key as `X-API-Key` and any other credential
|
|
169
|
+
as `Authorization: Bearer`. The key's scopes (for example `admin:users:read`)
|
|
170
|
+
determine which admin calls succeed.
|
|
171
|
+
|
|
172
|
+
`@lumoauth/api-client` is an **optional peer dependency**, because it is not
|
|
173
|
+
published to npm yet. Until it is, install it from the `typescript/`
|
|
174
|
+
directory of the [`LumoAuth/api-clients`](https://github.com/LumoAuth/api-clients)
|
|
175
|
+
repo. Using `lumo.api` without it throws a `LumoAuthConfigError` that says
|
|
176
|
+
how to install it.
|
|
177
|
+
|
|
178
|
+
## Security model
|
|
179
|
+
|
|
180
|
+
- **Server only, checked in code.** The constructor calls `assertServerOnly()`
|
|
181
|
+
and throws when it finds a browser. A server credential therefore cannot
|
|
182
|
+
reach a browser bundle by accident. `@lumoauth/client` applies the opposite
|
|
183
|
+
rule and rejects `lmk_…` keys.
|
|
184
|
+
- **The secret can be a function.** `secretKey` may be an async function. Use
|
|
185
|
+
that to read the secret from a secrets manager, or to rotate it without
|
|
186
|
+
creating a new client.
|
|
187
|
+
- **The cache is per process.** Permission results are cached in memory for 5
|
|
188
|
+
minutes by default. Call `lumo.permissions.clearCache()` after you change a
|
|
189
|
+
subject's roles.
|
|
190
|
+
|
|
191
|
+
## Troubleshooting
|
|
192
|
+
|
|
193
|
+
| Symptom | Cause | Fix |
|
|
194
|
+
|---|---|---|
|
|
195
|
+
| 401 on an ABAC, agent or JIT call with an `lmk_` key | Organization API keys only work on the admin API, client registration and the authorization checks | Use a user access token for ABAC, and `@lumoauth/agent` for agent calls |
|
|
196
|
+
| 403 `INSUFFICIENT_PERMISSIONS` from a check with `userId` | The key lacks the `authz:check` scope | Add the scope to the key |
|
|
197
|
+
| 404 `SUBJECT_NOT_FOUND` from a check with `userId` | The id is not a LumoAuth user id in this organization | Pass the user's `sub` claim, not your app's own id |
|
|
198
|
+
| 403 `agent_token_required` from `approvals` | Approvals accept agent credentials only | Use [`@lumoauth/agent`](../agent/README.md) |
|
|
199
|
+
| 403 with `requiredScopes` on the error | The user token lacks a scope | Request the scope at sign-in |
|
|
200
|
+
| `LumoAuthConfigError` that mentions a browser | The backend was constructed in browser code | Keep it in a route handler, a server component or an API route |
|
|
201
|
+
| `LumoAuthConfigError` that mentions `@lumoauth/api-client` | `lumo.api` was used without the generated client installed | Install it as described above |
|
|
202
|
+
|
|
203
|
+
The [workspace README](../../README.md#troubleshooting) has the full list.
|
|
204
|
+
|
|
205
|
+
## Related packages
|
|
206
|
+
|
|
207
|
+
| Package | How it relates |
|
|
208
|
+
|---|---|
|
|
209
|
+
| [`@lumoauth/express`](../express/README.md) | Express middleware built on this package. It re-exports `LumoAuthBackend` |
|
|
210
|
+
| [`@lumoauth/nextjs`](../nextjs/README.md) | Server-side auth for Next.js. Use it instead of this package in a Next.js app |
|
|
211
|
+
| [`@lumoauth/agent`](../agent/README.md) | For code that acts **as an agent** |
|
|
212
|
+
| [`@lumoauth/client`](../client/README.md) | The browser counterpart |
|
|
213
|
+
| [`@lumoauth/shared`](../shared/README.md) | The core that this package re-exports |
|
|
214
|
+
| [Workspace README](../../README.md) | How all of the packages fit together |
|
|
215
|
+
|
|
216
|
+
## Learn more
|
|
217
|
+
|
|
218
|
+
- The [Node.js and Express quickstart](https://docs.lumoauth.dev/quickstarts/node/)
|
|
219
|
+
- The [SDK overview](https://docs.lumoauth.dev/developer/sdks/)
|
|
220
|
+
- The [generated API clients](https://github.com/LumoAuth/api-clients), with notes on when to use them
|
|
221
|
+
|
|
222
|
+
## License
|
|
223
|
+
|
|
224
|
+
[MIT](./LICENSE)
|
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":"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","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":"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","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.1.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
|
+
}
|