@enlitt/sdk 0.0.0-stage → 0.1.1
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/CHANGELOG.md +35 -0
- package/LICENSE +21 -0
- package/README.md +63 -2
- package/dist/browser/auth.d.cts +44 -0
- package/dist/browser/auth.d.ts +45 -0
- package/dist/browser/auth.d.ts.map +1 -0
- package/dist/browser.cjs +35 -0
- package/dist/browser.cjs.map +1 -0
- package/dist/browser.d.cts +12 -0
- package/dist/browser.d.ts +13 -0
- package/dist/browser.d.ts.map +1 -0
- package/dist/browser.js +32 -0
- package/dist/browser.js.map +1 -0
- package/dist/chunk-2BGWYTJM.cjs +1097 -0
- package/dist/chunk-2BGWYTJM.cjs.map +1 -0
- package/dist/chunk-6OWXYBBT.cjs +146 -0
- package/dist/chunk-6OWXYBBT.cjs.map +1 -0
- package/dist/chunk-NI6WH5FI.js +33 -0
- package/dist/chunk-NI6WH5FI.js.map +1 -0
- package/dist/chunk-O6ASIA3X.js +866 -0
- package/dist/chunk-O6ASIA3X.js.map +1 -0
- package/dist/chunk-PPOUNWNA.cjs +895 -0
- package/dist/chunk-PPOUNWNA.cjs.map +1 -0
- package/dist/chunk-UVZMKGIL.js +1091 -0
- package/dist/chunk-UVZMKGIL.js.map +1 -0
- package/dist/chunk-V5TCSQ7C.js +143 -0
- package/dist/chunk-V5TCSQ7C.js.map +1 -0
- package/dist/chunk-YPA4R65T.cjs +35 -0
- package/dist/chunk-YPA4R65T.cjs.map +1 -0
- package/dist/core/errors.d.cts +262 -0
- package/dist/core/errors.d.ts +263 -0
- package/dist/core/errors.d.ts.map +1 -0
- package/dist/core/index.d.cts +24 -0
- package/dist/core/index.d.ts +25 -0
- package/dist/core/index.d.ts.map +1 -0
- package/dist/core/premium.d.cts +230 -0
- package/dist/core/premium.d.ts +231 -0
- package/dist/core/premium.d.ts.map +1 -0
- package/dist/core/session.d.cts +122 -0
- package/dist/core/session.d.ts +123 -0
- package/dist/core/session.d.ts.map +1 -0
- package/dist/core/sse.d.cts +79 -0
- package/dist/core/sse.d.ts +80 -0
- package/dist/core/sse.d.ts.map +1 -0
- package/dist/core/transport.d.cts +223 -0
- package/dist/core/transport.d.ts +224 -0
- package/dist/core/transport.d.ts.map +1 -0
- package/dist/core/usage.d.cts +35 -0
- package/dist/core/usage.d.ts +36 -0
- package/dist/core/usage.d.ts.map +1 -0
- package/dist/core.cjs +77 -0
- package/dist/core.cjs.map +1 -0
- package/dist/core.js +4 -0
- package/dist/core.js.map +1 -0
- package/dist/index.cjs +4 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +16 -0
- package/dist/index.d.ts +17 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -0
- package/dist/openai/client.d.cts +72 -0
- package/dist/openai/client.d.ts +73 -0
- package/dist/openai/client.d.ts.map +1 -0
- package/dist/openai/index.d.cts +2 -0
- package/dist/openai/index.d.ts +3 -0
- package/dist/openai/index.d.ts.map +1 -0
- package/dist/openai/media.d.cts +108 -0
- package/dist/openai/media.d.ts +109 -0
- package/dist/openai/media.d.ts.map +1 -0
- package/dist/openai.cjs +623 -0
- package/dist/openai.cjs.map +1 -0
- package/dist/openai.js +617 -0
- package/dist/openai.js.map +1 -0
- package/dist/server/callback.d.cts +107 -0
- package/dist/server/callback.d.ts +108 -0
- package/dist/server/callback.d.ts.map +1 -0
- package/dist/server/client-sign-in.d.cts +77 -0
- package/dist/server/client-sign-in.d.ts +78 -0
- package/dist/server/client-sign-in.d.ts.map +1 -0
- package/dist/server/index.d.cts +20 -0
- package/dist/server/index.d.ts +21 -0
- package/dist/server/index.d.ts.map +1 -0
- package/dist/server/secrets.d.cts +46 -0
- package/dist/server/secrets.d.ts +47 -0
- package/dist/server/secrets.d.ts.map +1 -0
- package/dist/server-unavailable.cjs +8 -0
- package/dist/server-unavailable.cjs.map +1 -0
- package/dist/server-unavailable.d.cts +10 -0
- package/dist/server-unavailable.d.ts +11 -0
- package/dist/server-unavailable.d.ts.map +1 -0
- package/dist/server-unavailable.js +6 -0
- package/dist/server-unavailable.js.map +1 -0
- package/dist/server.cjs +880 -0
- package/dist/server.cjs.map +1 -0
- package/dist/server.js +795 -0
- package/dist/server.js.map +1 -0
- package/dist/vercel/index.d.cts +17 -0
- package/dist/vercel/index.d.ts +18 -0
- package/dist/vercel/index.d.ts.map +1 -0
- package/dist/vercel/language-model.d.cts +146 -0
- package/dist/vercel/language-model.d.ts +147 -0
- package/dist/vercel/language-model.d.ts.map +1 -0
- package/dist/vercel/premium-language-model.d.cts +127 -0
- package/dist/vercel/premium-language-model.d.ts +128 -0
- package/dist/vercel/premium-language-model.d.ts.map +1 -0
- package/dist/vercel/premium-media-model.d.cts +101 -0
- package/dist/vercel/premium-media-model.d.ts +102 -0
- package/dist/vercel/premium-media-model.d.ts.map +1 -0
- package/dist/vercel/standard-language-model.d.cts +104 -0
- package/dist/vercel/standard-language-model.d.ts +105 -0
- package/dist/vercel/standard-language-model.d.ts.map +1 -0
- package/dist/vercel.cjs +22 -0
- package/dist/vercel.cjs.map +1 -0
- package/dist/vercel.js +5 -0
- package/dist/vercel.js.map +1 -0
- package/package.json +139 -3
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## 0.1.1
|
|
4
|
+
|
|
5
|
+
- The Vercel adapter's premium wrappers accept Vercel AI SDK v4 models (`ai@7`, for example
|
|
6
|
+
`@ai-sdk/openai` 4.x) as well as v3 models (`ai@6`); a wrapped model keeps its version. Streaming
|
|
7
|
+
speech and transcription are not exposed through Enlitt.
|
|
8
|
+
|
|
9
|
+
- Premium image generation, text-to-speech, and speech-to-text: `enlitt()` from
|
|
10
|
+
`@enlitt/sdk/vercel` wraps Vercel AI SDK image, speech, and transcription models, and the
|
|
11
|
+
`@enlitt/sdk/openai` client adds premium-only `images.generate()`, `audio.speech.create()`, and
|
|
12
|
+
`audio.transcriptions.create()`. A media call is priced with a constant `price` or the
|
|
13
|
+
business's own price function, which receives the image, speech, or transcription result.
|
|
14
|
+
|
|
15
|
+
- `premium_not_enabled` (the application's premium switch is off) surfaces as
|
|
16
|
+
`EnlittAuthorizationError` with that code, from a premium start (no provider runs) or a terminal
|
|
17
|
+
report (the call is not charged).
|
|
18
|
+
|
|
19
|
+
- Client sign-in handoff for games and native apps: `createClientSignInHandler()` and
|
|
20
|
+
`createMemoryClientSignInStore()` from `@enlitt/sdk/server` hand a signed-in session to a client
|
|
21
|
+
with no cookie jar (loopback, redirect, or pairing).
|
|
22
|
+
|
|
23
|
+
- `enlittSessionMiddleware({ header: true })` also reads the session from the `Enlitt-Session`
|
|
24
|
+
header (`ENLITT_SESSION_HEADER_NAME`) for those clients. It is off by default; when on, a
|
|
25
|
+
non-empty header wins over the cookie.
|
|
26
|
+
|
|
27
|
+
- The login callback sends every outcome after a valid `state`, signed out included, to the stored
|
|
28
|
+
`returnTo` page instead of `defaultReturnTo`. A signed-out arrival carries no cookie.
|
|
29
|
+
|
|
30
|
+
## 0.1.0
|
|
31
|
+
|
|
32
|
+
- First public release: the `@enlitt/sdk/vercel` and `@enlitt/sdk/openai` model adapters, the
|
|
33
|
+
framework-neutral `@enlitt/sdk/core` (session middleware, typed errors, `withPremiumCharge()`,
|
|
34
|
+
`usage()`), the `@enlitt/sdk/server` login, callback, and logout handlers, and the browser-safe
|
|
35
|
+
`@enlitt/sdk/browser` login entry.
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Enlitt
|
|
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,64 @@
|
|
|
1
|
-
#
|
|
1
|
+
# `@enlitt/sdk`
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
TypeScript SDK for integrating your application with Enlitt. Offer standard
|
|
4
|
+
AI calls through Enlitt or charge premium calls made directly to your provider.
|
|
5
|
+
Both require your application's App key and a personal user's Enlitt session.
|
|
6
|
+
|
|
7
|
+
Install it with `npm i @enlitt/sdk`. The package requires Node.js
|
|
8
|
+
22 or later; model, authentication, and reporting APIs run on your server.
|
|
9
|
+
|
|
10
|
+
## Start here
|
|
11
|
+
|
|
12
|
+
1. Register an application in the Enlitt business dashboard.
|
|
13
|
+
2. Create an App key (`scope: "model"` on the wire) and store it on your server as `ENLITT_SECRET_KEY`.
|
|
14
|
+
3. Mount the login handlers and session middleware.
|
|
15
|
+
4. Call a model inside the user's session context.
|
|
16
|
+
|
|
17
|
+
```ts
|
|
18
|
+
import { enlitt, ENLITT_STANDARD_MODEL } from "@enlitt/sdk/vercel";
|
|
19
|
+
import { generateText } from "ai";
|
|
20
|
+
|
|
21
|
+
// Inside enlittSessionMiddleware(), after the user signs in:
|
|
22
|
+
const result = await generateText({
|
|
23
|
+
model: enlitt(ENLITT_STANDARD_MODEL),
|
|
24
|
+
prompt: "Write a short welcome message."
|
|
25
|
+
});
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## Link application-owned users
|
|
29
|
+
|
|
30
|
+
The server-side login exchange returns an application-scoped stable `subject`
|
|
31
|
+
alongside the opaque session token. Set the optional `CallbackConfig.onSignIn`
|
|
32
|
+
hook to find/create your own user by that subject and append your own secure
|
|
33
|
+
session cookie to the supplied redirect `Response`. The SDK awaits the hook
|
|
34
|
+
before adding its Enlitt cookie. The subject is stable across future logins and
|
|
35
|
+
reauthorization, differs between applications, and is not a credential.
|
|
36
|
+
|
|
37
|
+
The hook receives only `{ subject }`, never an identity supplied in the callback
|
|
38
|
+
URL. Hook failures propagate to your server rather than completing login.
|
|
39
|
+
Protect your history with your own authenticated session and clear that session
|
|
40
|
+
on logout. `getEnlittSession()` continues to expose only the opaque token used
|
|
41
|
+
for Enlitt calls. Updated callback handlers require the backend's subject field;
|
|
42
|
+
existing callers can omit the hook, and older SDKs ignore the added field.
|
|
43
|
+
|
|
44
|
+
## Public entries
|
|
45
|
+
|
|
46
|
+
| Import | Purpose |
|
|
47
|
+
| -------------------- | ------------------------------------------------------- |
|
|
48
|
+
| `@enlitt/sdk/vercel` | Vercel AI SDK model wrapping and pricing. |
|
|
49
|
+
| `@enlitt/sdk/openai` | Official OpenAI Responses, images, and audio adapter. |
|
|
50
|
+
| `@enlitt/sdk/core` | Sessions, errors, `usage()`, and `withPremiumCharge()`. |
|
|
51
|
+
| `@enlitt/sdk/server` | Login handlers and core/Vercel compatibility exports. |
|
|
52
|
+
|
|
53
|
+
All four entries are server-only. The root and browser entries currently
|
|
54
|
+
export no integration APIs. Never put a business key in browser code.
|
|
55
|
+
|
|
56
|
+
Premium pricing uses exact NANOUSD strings with `maxCharge` and `price`.
|
|
57
|
+
Premium also wraps image, speech, and transcription models, priced with a constant
|
|
58
|
+
or your own price function; there is no standard media model.
|
|
59
|
+
Test applications consume real credits.
|
|
60
|
+
|
|
61
|
+
Read the [developer guide](https://enlitt.com/docs), starting with
|
|
62
|
+
[login and sessions](https://enlitt.com/docs/authentication) and
|
|
63
|
+
[models and pricing](https://enlitt.com/docs/models). The versioned MDX sources
|
|
64
|
+
live in `apps/frontend/content/docs/` in this repository.
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The browser-only entry to Enlitt login, and nothing beyond it.
|
|
3
|
+
*
|
|
4
|
+
* `login()` sends the visitor to the business's own login-start route and
|
|
5
|
+
* `logout()` to the business's own logout route. Both are plain top-level
|
|
6
|
+
* navigations to the business's own origin. This module holds no secret,
|
|
7
|
+
* generates no verifier, performs no exchange, and never receives, reads,
|
|
8
|
+
* stores, or exposes a session credential.
|
|
9
|
+
*
|
|
10
|
+
* There is deliberately no session accessor and no subscription here. The
|
|
11
|
+
* session cookie is HttpOnly on the business's domain precisely so a
|
|
12
|
+
* cross-site scripting flaw cannot read it, which also means this file cannot.
|
|
13
|
+
* A browser API that appeared to return the session could only do so by
|
|
14
|
+
* weakening that cookie or by inventing a second, readable copy of a
|
|
15
|
+
* credential. Signed-in state is read on the business's server through
|
|
16
|
+
* SDK-side routing's `getEnlittSession()` and rendered from there.
|
|
17
|
+
*
|
|
18
|
+
* Application login always resolves a personal account: this file names no
|
|
19
|
+
* account type, carries no credential, and can present none, so a business
|
|
20
|
+
* dashboard session has no path through here to become application access.
|
|
21
|
+
*/
|
|
22
|
+
export interface AuthNavigationOptions {
|
|
23
|
+
/**
|
|
24
|
+
* Where to send the visitor once the flow finishes.
|
|
25
|
+
*
|
|
26
|
+
* The value is passed through verbatim for the business's server to
|
|
27
|
+
* validate against its own origin. Nothing here inspects, resolves, or
|
|
28
|
+
* rewrites it: validation belongs on the server, and doing it twice in two
|
|
29
|
+
* places is how the two copies drift apart.
|
|
30
|
+
*/
|
|
31
|
+
readonly returnTo?: string;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Send the visitor to the business's own login-start route.
|
|
35
|
+
*
|
|
36
|
+
* Returns nothing, because the call ends in a navigation and there is no
|
|
37
|
+
* session for it to hand back.
|
|
38
|
+
*/
|
|
39
|
+
export declare function login(options?: AuthNavigationOptions): void;
|
|
40
|
+
/**
|
|
41
|
+
* Send the visitor to the business's own logout route, which clears the
|
|
42
|
+
* cookie and asks Enlitt to revoke the session server-side.
|
|
43
|
+
*/
|
|
44
|
+
export declare function logout(options?: AuthNavigationOptions): void;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The browser-only entry to Enlitt login, and nothing beyond it.
|
|
3
|
+
*
|
|
4
|
+
* `login()` sends the visitor to the business's own login-start route and
|
|
5
|
+
* `logout()` to the business's own logout route. Both are plain top-level
|
|
6
|
+
* navigations to the business's own origin. This module holds no secret,
|
|
7
|
+
* generates no verifier, performs no exchange, and never receives, reads,
|
|
8
|
+
* stores, or exposes a session credential.
|
|
9
|
+
*
|
|
10
|
+
* There is deliberately no session accessor and no subscription here. The
|
|
11
|
+
* session cookie is HttpOnly on the business's domain precisely so a
|
|
12
|
+
* cross-site scripting flaw cannot read it, which also means this file cannot.
|
|
13
|
+
* A browser API that appeared to return the session could only do so by
|
|
14
|
+
* weakening that cookie or by inventing a second, readable copy of a
|
|
15
|
+
* credential. Signed-in state is read on the business's server through
|
|
16
|
+
* SDK-side routing's `getEnlittSession()` and rendered from there.
|
|
17
|
+
*
|
|
18
|
+
* Application login always resolves a personal account: this file names no
|
|
19
|
+
* account type, carries no credential, and can present none, so a business
|
|
20
|
+
* dashboard session has no path through here to become application access.
|
|
21
|
+
*/
|
|
22
|
+
export interface AuthNavigationOptions {
|
|
23
|
+
/**
|
|
24
|
+
* Where to send the visitor once the flow finishes.
|
|
25
|
+
*
|
|
26
|
+
* The value is passed through verbatim for the business's server to
|
|
27
|
+
* validate against its own origin. Nothing here inspects, resolves, or
|
|
28
|
+
* rewrites it: validation belongs on the server, and doing it twice in two
|
|
29
|
+
* places is how the two copies drift apart.
|
|
30
|
+
*/
|
|
31
|
+
readonly returnTo?: string;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Send the visitor to the business's own login-start route.
|
|
35
|
+
*
|
|
36
|
+
* Returns nothing, because the call ends in a navigation and there is no
|
|
37
|
+
* session for it to hand back.
|
|
38
|
+
*/
|
|
39
|
+
export declare function login(options?: AuthNavigationOptions): void;
|
|
40
|
+
/**
|
|
41
|
+
* Send the visitor to the business's own logout route, which clears the
|
|
42
|
+
* cookie and asks Enlitt to revoke the session server-side.
|
|
43
|
+
*/
|
|
44
|
+
export declare function logout(options?: AuthNavigationOptions): void;
|
|
45
|
+
//# sourceMappingURL=auth.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../../src/browser/auth.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAoBH,MAAM,WAAW,qBAAqB;IACpC;;;;;;;OAOG;IACH,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;CAC5B;AA+BD;;;;;GAKG;AACH,wBAAgB,KAAK,CAAC,OAAO,CAAC,EAAE,qBAAqB,GAAG,IAAI,CAE3D;AAED;;;GAGG;AACH,wBAAgB,MAAM,CAAC,OAAO,CAAC,EAAE,qBAAqB,GAAG,IAAI,CAE5D"}
|
package/dist/browser.cjs
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// src/browser/auth.ts
|
|
4
|
+
var LOGIN_START_PATH = "/auth/login";
|
|
5
|
+
var LOGOUT_PATH = "/auth/logout";
|
|
6
|
+
var RETURN_TO_PARAM = "return_to";
|
|
7
|
+
function currentNavigationTarget() {
|
|
8
|
+
const globalWindow = globalThis.window;
|
|
9
|
+
const target = globalWindow?.location;
|
|
10
|
+
if (!target) {
|
|
11
|
+
throw new Error(
|
|
12
|
+
"@enlitt/sdk/browser: login() and logout() navigate the browser and can only be called in a browser environment."
|
|
13
|
+
);
|
|
14
|
+
}
|
|
15
|
+
return target;
|
|
16
|
+
}
|
|
17
|
+
function navigate(path, returnTo) {
|
|
18
|
+
const target = currentNavigationTarget();
|
|
19
|
+
const destination = new URL(path, target.href);
|
|
20
|
+
if (returnTo !== void 0) {
|
|
21
|
+
destination.searchParams.set(RETURN_TO_PARAM, returnTo);
|
|
22
|
+
}
|
|
23
|
+
target.assign(destination.toString());
|
|
24
|
+
}
|
|
25
|
+
function login(options) {
|
|
26
|
+
navigate(LOGIN_START_PATH, options?.returnTo);
|
|
27
|
+
}
|
|
28
|
+
function logout(options) {
|
|
29
|
+
navigate(LOGOUT_PATH, options?.returnTo);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
exports.login = login;
|
|
33
|
+
exports.logout = logout;
|
|
34
|
+
//# sourceMappingURL=browser.cjs.map
|
|
35
|
+
//# sourceMappingURL=browser.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/browser/auth.ts"],"names":[],"mappings":";;;AA8BA,IAAM,gBAAA,GAAmB,aAAA;AACzB,IAAM,WAAA,GAAc,cAAA;AAOpB,IAAM,eAAA,GAAkB,WAAA;AAoBxB,SAAS,uBAAA,GAA4C;AACnD,EAAA,MAAM,eAAgB,UAAA,CAA4D,MAAA;AAClF,EAAA,MAAM,SAAS,YAAA,EAAc,QAAA;AAC7B,EAAA,IAAI,CAAC,MAAA,EAAQ;AACX,IAAA,MAAM,IAAI,KAAA;AAAA,MACR;AAAA,KAEF;AAAA,EACF;AACA,EAAA,OAAO,MAAA;AACT;AAEA,SAAS,QAAA,CAAS,MAAc,QAAA,EAAoC;AAClE,EAAA,MAAM,SAAS,uBAAA,EAAwB;AAGvC,EAAA,MAAM,WAAA,GAAc,IAAI,GAAA,CAAI,IAAA,EAAM,OAAO,IAAI,CAAA;AAC7C,EAAA,IAAI,aAAa,MAAA,EAAW;AAC1B,IAAA,WAAA,CAAY,YAAA,CAAa,GAAA,CAAI,eAAA,EAAiB,QAAQ,CAAA;AAAA,EACxD;AACA,EAAA,MAAA,CAAO,MAAA,CAAO,WAAA,CAAY,QAAA,EAAU,CAAA;AACtC;AAQO,SAAS,MAAM,OAAA,EAAuC;AAC3D,EAAA,QAAA,CAAS,gBAAA,EAAkB,SAAS,QAAQ,CAAA;AAC9C;AAMO,SAAS,OAAO,OAAA,EAAuC;AAC5D,EAAA,QAAA,CAAS,WAAA,EAAa,SAAS,QAAQ,CAAA;AACzC","file":"browser.cjs","sourcesContent":["/**\n * The browser-only entry to Enlitt login, and nothing beyond it.\n *\n * `login()` sends the visitor to the business's own login-start route and\n * `logout()` to the business's own logout route. Both are plain top-level\n * navigations to the business's own origin. This module holds no secret,\n * generates no verifier, performs no exchange, and never receives, reads,\n * stores, or exposes a session credential.\n *\n * There is deliberately no session accessor and no subscription here. The\n * session cookie is HttpOnly on the business's domain precisely so a\n * cross-site scripting flaw cannot read it, which also means this file cannot.\n * A browser API that appeared to return the session could only do so by\n * weakening that cookie or by inventing a second, readable copy of a\n * credential. Signed-in state is read on the business's server through\n * SDK-side routing's `getEnlittSession()` and rendered from there.\n *\n * Application login always resolves a personal account: this file names no\n * account type, carries no credential, and can present none, so a business\n * dashboard session has no path through here to become application access.\n */\n\n/**\n * Where the business mounts the SDK's server-side handlers.\n *\n * These are the business's own routes on the business's own origin, matching\n * the mount point in `specs/Chatbot.md`. They are constants rather than\n * options because the spec fixes this entry point's surface at exactly\n * `login(options?)` and `logout(options?)`.\n */\nconst LOGIN_START_PATH = \"/auth/login\";\nconst LOGOUT_PATH = \"/auth/logout\";\n\n/**\n * The query parameter carrying the post-flow destination. The server-side\n * handlers in `../server/callback.ts` read the same name and are the only\n * place the value is validated.\n */\nconst RETURN_TO_PARAM = \"return_to\";\n\nexport interface AuthNavigationOptions {\n /**\n * Where to send the visitor once the flow finishes.\n *\n * The value is passed through verbatim for the business's server to\n * validate against its own origin. Nothing here inspects, resolves, or\n * rewrites it: validation belongs on the server, and doing it twice in two\n * places is how the two copies drift apart.\n */\n readonly returnTo?: string;\n}\n\n/** The one thing this module needs from the browser. */\ninterface NavigationTarget {\n readonly href: string;\n assign(url: string): void;\n}\n\nfunction currentNavigationTarget(): NavigationTarget {\n const globalWindow = (globalThis as { window?: { location?: NavigationTarget } }).window;\n const target = globalWindow?.location;\n if (!target) {\n throw new Error(\n \"@enlitt/sdk/browser: login() and logout() navigate the browser and can only \" +\n \"be called in a browser environment.\"\n );\n }\n return target;\n}\n\nfunction navigate(path: string, returnTo: string | undefined): void {\n const target = currentNavigationTarget();\n // `path` is one of this module's own constants, so the result is always on\n // the page's own origin no matter what the caller passed.\n const destination = new URL(path, target.href);\n if (returnTo !== undefined) {\n destination.searchParams.set(RETURN_TO_PARAM, returnTo);\n }\n target.assign(destination.toString());\n}\n\n/**\n * Send the visitor to the business's own login-start route.\n *\n * Returns nothing, because the call ends in a navigation and there is no\n * session for it to hand back.\n */\nexport function login(options?: AuthNavigationOptions): void {\n navigate(LOGIN_START_PATH, options?.returnTo);\n}\n\n/**\n * Send the visitor to the business's own logout route, which clears the\n * cookie and asks Enlitt to revoke the session server-side.\n */\nexport function logout(options?: AuthNavigationOptions): void {\n navigate(LOGOUT_PATH, options?.returnTo);\n}\n"]}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@enlitt/sdk/browser` — the entry point a business ships to its own users.
|
|
3
|
+
*
|
|
4
|
+
* This subpath must never import a secret key or a server-only module: it is
|
|
5
|
+
* bundled and served to consumers. What it exposes is deliberately small —
|
|
6
|
+
* two navigations and nothing else. There is no session accessor here,
|
|
7
|
+
* because the session cookie is HttpOnly on the business's domain and no
|
|
8
|
+
* browser code can read it; signed-in state is rendered from the business's
|
|
9
|
+
* server through SDK-side routing.
|
|
10
|
+
*/
|
|
11
|
+
export { login, logout } from "./browser/auth.cjs";
|
|
12
|
+
export type { AuthNavigationOptions } from "./browser/auth.cjs";
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@enlitt/sdk/browser` — the entry point a business ships to its own users.
|
|
3
|
+
*
|
|
4
|
+
* This subpath must never import a secret key or a server-only module: it is
|
|
5
|
+
* bundled and served to consumers. What it exposes is deliberately small —
|
|
6
|
+
* two navigations and nothing else. There is no session accessor here,
|
|
7
|
+
* because the session cookie is HttpOnly on the business's domain and no
|
|
8
|
+
* browser code can read it; signed-in state is rendered from the business's
|
|
9
|
+
* server through SDK-side routing.
|
|
10
|
+
*/
|
|
11
|
+
export { login, logout } from "./browser/auth.js";
|
|
12
|
+
export type { AuthNavigationOptions } from "./browser/auth.js";
|
|
13
|
+
//# sourceMappingURL=browser.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"browser.d.ts","sourceRoot":"","sources":["../src/browser.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAClD,YAAY,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAC"}
|
package/dist/browser.js
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
// src/browser/auth.ts
|
|
2
|
+
var LOGIN_START_PATH = "/auth/login";
|
|
3
|
+
var LOGOUT_PATH = "/auth/logout";
|
|
4
|
+
var RETURN_TO_PARAM = "return_to";
|
|
5
|
+
function currentNavigationTarget() {
|
|
6
|
+
const globalWindow = globalThis.window;
|
|
7
|
+
const target = globalWindow?.location;
|
|
8
|
+
if (!target) {
|
|
9
|
+
throw new Error(
|
|
10
|
+
"@enlitt/sdk/browser: login() and logout() navigate the browser and can only be called in a browser environment."
|
|
11
|
+
);
|
|
12
|
+
}
|
|
13
|
+
return target;
|
|
14
|
+
}
|
|
15
|
+
function navigate(path, returnTo) {
|
|
16
|
+
const target = currentNavigationTarget();
|
|
17
|
+
const destination = new URL(path, target.href);
|
|
18
|
+
if (returnTo !== void 0) {
|
|
19
|
+
destination.searchParams.set(RETURN_TO_PARAM, returnTo);
|
|
20
|
+
}
|
|
21
|
+
target.assign(destination.toString());
|
|
22
|
+
}
|
|
23
|
+
function login(options) {
|
|
24
|
+
navigate(LOGIN_START_PATH, options?.returnTo);
|
|
25
|
+
}
|
|
26
|
+
function logout(options) {
|
|
27
|
+
navigate(LOGOUT_PATH, options?.returnTo);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export { login, logout };
|
|
31
|
+
//# sourceMappingURL=browser.js.map
|
|
32
|
+
//# sourceMappingURL=browser.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/browser/auth.ts"],"names":[],"mappings":";AA8BA,IAAM,gBAAA,GAAmB,aAAA;AACzB,IAAM,WAAA,GAAc,cAAA;AAOpB,IAAM,eAAA,GAAkB,WAAA;AAoBxB,SAAS,uBAAA,GAA4C;AACnD,EAAA,MAAM,eAAgB,UAAA,CAA4D,MAAA;AAClF,EAAA,MAAM,SAAS,YAAA,EAAc,QAAA;AAC7B,EAAA,IAAI,CAAC,MAAA,EAAQ;AACX,IAAA,MAAM,IAAI,KAAA;AAAA,MACR;AAAA,KAEF;AAAA,EACF;AACA,EAAA,OAAO,MAAA;AACT;AAEA,SAAS,QAAA,CAAS,MAAc,QAAA,EAAoC;AAClE,EAAA,MAAM,SAAS,uBAAA,EAAwB;AAGvC,EAAA,MAAM,WAAA,GAAc,IAAI,GAAA,CAAI,IAAA,EAAM,OAAO,IAAI,CAAA;AAC7C,EAAA,IAAI,aAAa,MAAA,EAAW;AAC1B,IAAA,WAAA,CAAY,YAAA,CAAa,GAAA,CAAI,eAAA,EAAiB,QAAQ,CAAA;AAAA,EACxD;AACA,EAAA,MAAA,CAAO,MAAA,CAAO,WAAA,CAAY,QAAA,EAAU,CAAA;AACtC;AAQO,SAAS,MAAM,OAAA,EAAuC;AAC3D,EAAA,QAAA,CAAS,gBAAA,EAAkB,SAAS,QAAQ,CAAA;AAC9C;AAMO,SAAS,OAAO,OAAA,EAAuC;AAC5D,EAAA,QAAA,CAAS,WAAA,EAAa,SAAS,QAAQ,CAAA;AACzC","file":"browser.js","sourcesContent":["/**\n * The browser-only entry to Enlitt login, and nothing beyond it.\n *\n * `login()` sends the visitor to the business's own login-start route and\n * `logout()` to the business's own logout route. Both are plain top-level\n * navigations to the business's own origin. This module holds no secret,\n * generates no verifier, performs no exchange, and never receives, reads,\n * stores, or exposes a session credential.\n *\n * There is deliberately no session accessor and no subscription here. The\n * session cookie is HttpOnly on the business's domain precisely so a\n * cross-site scripting flaw cannot read it, which also means this file cannot.\n * A browser API that appeared to return the session could only do so by\n * weakening that cookie or by inventing a second, readable copy of a\n * credential. Signed-in state is read on the business's server through\n * SDK-side routing's `getEnlittSession()` and rendered from there.\n *\n * Application login always resolves a personal account: this file names no\n * account type, carries no credential, and can present none, so a business\n * dashboard session has no path through here to become application access.\n */\n\n/**\n * Where the business mounts the SDK's server-side handlers.\n *\n * These are the business's own routes on the business's own origin, matching\n * the mount point in `specs/Chatbot.md`. They are constants rather than\n * options because the spec fixes this entry point's surface at exactly\n * `login(options?)` and `logout(options?)`.\n */\nconst LOGIN_START_PATH = \"/auth/login\";\nconst LOGOUT_PATH = \"/auth/logout\";\n\n/**\n * The query parameter carrying the post-flow destination. The server-side\n * handlers in `../server/callback.ts` read the same name and are the only\n * place the value is validated.\n */\nconst RETURN_TO_PARAM = \"return_to\";\n\nexport interface AuthNavigationOptions {\n /**\n * Where to send the visitor once the flow finishes.\n *\n * The value is passed through verbatim for the business's server to\n * validate against its own origin. Nothing here inspects, resolves, or\n * rewrites it: validation belongs on the server, and doing it twice in two\n * places is how the two copies drift apart.\n */\n readonly returnTo?: string;\n}\n\n/** The one thing this module needs from the browser. */\ninterface NavigationTarget {\n readonly href: string;\n assign(url: string): void;\n}\n\nfunction currentNavigationTarget(): NavigationTarget {\n const globalWindow = (globalThis as { window?: { location?: NavigationTarget } }).window;\n const target = globalWindow?.location;\n if (!target) {\n throw new Error(\n \"@enlitt/sdk/browser: login() and logout() navigate the browser and can only \" +\n \"be called in a browser environment.\"\n );\n }\n return target;\n}\n\nfunction navigate(path: string, returnTo: string | undefined): void {\n const target = currentNavigationTarget();\n // `path` is one of this module's own constants, so the result is always on\n // the page's own origin no matter what the caller passed.\n const destination = new URL(path, target.href);\n if (returnTo !== undefined) {\n destination.searchParams.set(RETURN_TO_PARAM, returnTo);\n }\n target.assign(destination.toString());\n}\n\n/**\n * Send the visitor to the business's own login-start route.\n *\n * Returns nothing, because the call ends in a navigation and there is no\n * session for it to hand back.\n */\nexport function login(options?: AuthNavigationOptions): void {\n navigate(LOGIN_START_PATH, options?.returnTo);\n}\n\n/**\n * Send the visitor to the business's own logout route, which clears the\n * cookie and asks Enlitt to revoke the session server-side.\n */\nexport function logout(options?: AuthNavigationOptions): void {\n navigate(LOGOUT_PATH, options?.returnTo);\n}\n"]}
|