@enlitt/sdk 0.0.0-stage → 0.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/CHANGELOG.md +8 -0
- package/LICENSE +21 -0
- package/README.md +61 -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-26SW63P5.cjs +883 -0
- package/dist/chunk-26SW63P5.cjs.map +1 -0
- package/dist/chunk-6DPBYLA5.js +855 -0
- package/dist/chunk-6DPBYLA5.js.map +1 -0
- package/dist/chunk-6OWXYBBT.cjs +146 -0
- package/dist/chunk-6OWXYBBT.cjs.map +1 -0
- package/dist/chunk-C76K6HLL.cjs +906 -0
- package/dist/chunk-C76K6HLL.cjs.map +1 -0
- package/dist/chunk-G4DTTV5E.cjs +35 -0
- package/dist/chunk-G4DTTV5E.cjs.map +1 -0
- package/dist/chunk-SFI4RLNN.js +900 -0
- package/dist/chunk-SFI4RLNN.js.map +1 -0
- package/dist/chunk-V5TCSQ7C.js +143 -0
- package/dist/chunk-V5TCSQ7C.js.map +1 -0
- package/dist/chunk-VNVMEU34.js +33 -0
- package/dist/chunk-VNVMEU34.js.map +1 -0
- package/dist/core/errors.d.cts +254 -0
- package/dist/core/errors.d.ts +255 -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 +107 -0
- package/dist/core/session.d.ts +108 -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 +73 -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 +48 -0
- package/dist/openai/client.d.ts +49 -0
- package/dist/openai/client.d.ts.map +1 -0
- package/dist/openai/index.d.cts +1 -0
- package/dist/openai/index.d.ts +2 -0
- package/dist/openai/index.d.ts.map +1 -0
- package/dist/openai.cjs +479 -0
- package/dist/openai.cjs.map +1 -0
- package/dist/openai.js +473 -0
- package/dist/openai.js.map +1 -0
- package/dist/server/callback.d.cts +106 -0
- package/dist/server/callback.d.ts +107 -0
- package/dist/server/callback.d.ts.map +1 -0
- package/dist/server/index.d.cts +19 -0
- package/dist/server/index.d.ts +20 -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 +354 -0
- package/dist/server.cjs.map +1 -0
- package/dist/server.js +275 -0
- package/dist/server.js.map +1 -0
- package/dist/vercel/index.d.cts +15 -0
- package/dist/vercel/index.d.ts +16 -0
- package/dist/vercel/index.d.ts.map +1 -0
- package/dist/vercel/language-model.d.cts +131 -0
- package/dist/vercel/language-model.d.ts +132 -0
- package/dist/vercel/language-model.d.ts.map +1 -0
- package/dist/vercel/premium-language-model.d.cts +98 -0
- package/dist/vercel/premium-language-model.d.ts +99 -0
- package/dist/vercel/premium-language-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 +129 -3
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The authorization callback a business mounts at its registered redirect URL,
|
|
3
|
+
* and the one place a consumer session token becomes a cookie.
|
|
4
|
+
*
|
|
5
|
+
* This is the mint end of the token's lifecycle. Login-start issues the
|
|
6
|
+
* `state`, the callback validates it, exchanges the one-time code with Enlitt
|
|
7
|
+
* authenticated by the business's own secret key, and sets the resulting
|
|
8
|
+
* opaque session token as an HttpOnly, Secure, SameSite=Lax cookie on the
|
|
9
|
+
* business's own domain. Reading that cookie back on later requests is
|
|
10
|
+
* `./session.ts`, which SDK-side routing owns and which also owns the
|
|
11
|
+
* cookie's name: the mint end and the read end of one cookie cannot disagree,
|
|
12
|
+
* so the default comes from there rather than from a second literal here.
|
|
13
|
+
*
|
|
14
|
+
* The core here is framework-agnostic over `Request` and `Response`;
|
|
15
|
+
* per-framework adapters are separate entry points over this same core, so
|
|
16
|
+
* behaviour cannot drift between frameworks.
|
|
17
|
+
*
|
|
18
|
+
* Invariants this file exists to hold:
|
|
19
|
+
*
|
|
20
|
+
* - No cookie is ever set from an unverified value, and no token supplied in
|
|
21
|
+
* the callback request itself is ever honoured — the only source of a
|
|
22
|
+
* session token is the authenticated exchange response.
|
|
23
|
+
* - The token and the one-time code are never written into a URL, a redirect
|
|
24
|
+
* target, a log line, a trace, or an error body. Nothing in this file
|
|
25
|
+
* prints.
|
|
26
|
+
* - Every onward redirect resolves to `appOrigin` or is replaced by
|
|
27
|
+
* `defaultReturnTo`, so a login link can never become an open redirect.
|
|
28
|
+
* - A rejected `state`, a failed exchange, or an Enlitt error yields a
|
|
29
|
+
* signed-out outcome and no cookie.
|
|
30
|
+
*/
|
|
31
|
+
/** A store may be synchronous (an in-process map) or asynchronous (Redis). */
|
|
32
|
+
type Awaitable<T> = T | Promise<T>;
|
|
33
|
+
/**
|
|
34
|
+
* What login-start remembers about a pending login, server-side.
|
|
35
|
+
*
|
|
36
|
+
* The post-login destination is captured here rather than carried through the
|
|
37
|
+
* round trip in a parameter the callback reads back, so a crafted callback URL
|
|
38
|
+
* has nothing to say about where the consumer lands.
|
|
39
|
+
*/
|
|
40
|
+
export interface StateRecord {
|
|
41
|
+
/** The destination requested at login-start, still unvalidated. */
|
|
42
|
+
readonly returnTo?: string;
|
|
43
|
+
readonly createdAt: number;
|
|
44
|
+
readonly expiresAt: number;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Server-side storage for issued `state` values, with a TTL.
|
|
48
|
+
*
|
|
49
|
+
* `consume` must be single-use: it returns the record and removes it in one
|
|
50
|
+
* step, so a replayed callback finds nothing. `get` exists for callers that
|
|
51
|
+
* need to inspect a pending login without spending it; the callback handler
|
|
52
|
+
* never uses it.
|
|
53
|
+
*/
|
|
54
|
+
export interface StateStore {
|
|
55
|
+
set(state: string, record: StateRecord, ttlMs: number): Awaitable<void>;
|
|
56
|
+
get(state: string): Awaitable<StateRecord | null>;
|
|
57
|
+
consume(state: string): Awaitable<StateRecord | null>;
|
|
58
|
+
}
|
|
59
|
+
export interface CallbackConfig {
|
|
60
|
+
readonly clientId: string;
|
|
61
|
+
/** Falls back to `ENLITT_SECRET_KEY`; never reaches a browser bundle. */
|
|
62
|
+
readonly secretKey?: string;
|
|
63
|
+
/** Must equal a registered redirect URI exactly. */
|
|
64
|
+
readonly redirectUri: string;
|
|
65
|
+
/** Enlitt's authorization origin (the dashboard host). Defaults to the deployed one. */
|
|
66
|
+
readonly enlittOrigin?: string;
|
|
67
|
+
/**
|
|
68
|
+
* Origin for the two server-to-server requests (code exchange and
|
|
69
|
+
* revocation). Defaults to `enlittOrigin`. A server running as a Cloudflare
|
|
70
|
+
* Worker in Enlitt's own zone must pass the API host: Cloudflare does not run
|
|
71
|
+
* the route-bound Worker behind `enlittOrigin/auth/*` for a same-zone Worker
|
|
72
|
+
* subrequest, so the exchange would reach the wrong Worker and fail.
|
|
73
|
+
*/
|
|
74
|
+
readonly enlittApiOrigin?: string;
|
|
75
|
+
/** The business's own origin. It bounds every redirect this file emits. */
|
|
76
|
+
readonly appOrigin: string;
|
|
77
|
+
/** Path on `appOrigin`, used whenever no valid destination survives. */
|
|
78
|
+
readonly defaultReturnTo: string;
|
|
79
|
+
readonly cookieName?: string;
|
|
80
|
+
readonly stateStore: StateStore;
|
|
81
|
+
/** Link your own user/session before login completes; no token is passed. */
|
|
82
|
+
readonly onSignIn?: (identity: {
|
|
83
|
+
readonly subject: string;
|
|
84
|
+
}, response: Response) => Awaitable<void>;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Begin login: issue a `state`, remember it server-side, and send the consumer
|
|
88
|
+
* to Enlitt's authorization endpoint.
|
|
89
|
+
*/
|
|
90
|
+
export declare function createLoginStartHandler(config: CallbackConfig): (request: Request) => Promise<Response>;
|
|
91
|
+
/**
|
|
92
|
+
* Receive Enlitt's callback: validate `state`, exchange the code, set the one
|
|
93
|
+
* cookie, and send the consumer onward within `appOrigin`.
|
|
94
|
+
*/
|
|
95
|
+
export declare function createCallbackHandler(config: CallbackConfig): (request: Request) => Promise<Response>;
|
|
96
|
+
/**
|
|
97
|
+
* End the session: clear the cookie and ask Enlitt to revoke the token.
|
|
98
|
+
*
|
|
99
|
+
* Revocation is what makes the opaque token worth its lookup, so a signed-out
|
|
100
|
+
* consumer is signed out server-side and not merely cookie-less. A revocation
|
|
101
|
+
* that fails still clears the cookie: leaving the consumer holding a cookie
|
|
102
|
+
* because Enlitt was briefly unreachable would be the worse of the two
|
|
103
|
+
* outcomes, and the token stays revocable from the dashboard.
|
|
104
|
+
*/
|
|
105
|
+
export declare function createLogoutHandler(config: CallbackConfig): (request: Request) => Promise<Response>;
|
|
106
|
+
export {};
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The authorization callback a business mounts at its registered redirect URL,
|
|
3
|
+
* and the one place a consumer session token becomes a cookie.
|
|
4
|
+
*
|
|
5
|
+
* This is the mint end of the token's lifecycle. Login-start issues the
|
|
6
|
+
* `state`, the callback validates it, exchanges the one-time code with Enlitt
|
|
7
|
+
* authenticated by the business's own secret key, and sets the resulting
|
|
8
|
+
* opaque session token as an HttpOnly, Secure, SameSite=Lax cookie on the
|
|
9
|
+
* business's own domain. Reading that cookie back on later requests is
|
|
10
|
+
* `./session.ts`, which SDK-side routing owns and which also owns the
|
|
11
|
+
* cookie's name: the mint end and the read end of one cookie cannot disagree,
|
|
12
|
+
* so the default comes from there rather than from a second literal here.
|
|
13
|
+
*
|
|
14
|
+
* The core here is framework-agnostic over `Request` and `Response`;
|
|
15
|
+
* per-framework adapters are separate entry points over this same core, so
|
|
16
|
+
* behaviour cannot drift between frameworks.
|
|
17
|
+
*
|
|
18
|
+
* Invariants this file exists to hold:
|
|
19
|
+
*
|
|
20
|
+
* - No cookie is ever set from an unverified value, and no token supplied in
|
|
21
|
+
* the callback request itself is ever honoured — the only source of a
|
|
22
|
+
* session token is the authenticated exchange response.
|
|
23
|
+
* - The token and the one-time code are never written into a URL, a redirect
|
|
24
|
+
* target, a log line, a trace, or an error body. Nothing in this file
|
|
25
|
+
* prints.
|
|
26
|
+
* - Every onward redirect resolves to `appOrigin` or is replaced by
|
|
27
|
+
* `defaultReturnTo`, so a login link can never become an open redirect.
|
|
28
|
+
* - A rejected `state`, a failed exchange, or an Enlitt error yields a
|
|
29
|
+
* signed-out outcome and no cookie.
|
|
30
|
+
*/
|
|
31
|
+
/** A store may be synchronous (an in-process map) or asynchronous (Redis). */
|
|
32
|
+
type Awaitable<T> = T | Promise<T>;
|
|
33
|
+
/**
|
|
34
|
+
* What login-start remembers about a pending login, server-side.
|
|
35
|
+
*
|
|
36
|
+
* The post-login destination is captured here rather than carried through the
|
|
37
|
+
* round trip in a parameter the callback reads back, so a crafted callback URL
|
|
38
|
+
* has nothing to say about where the consumer lands.
|
|
39
|
+
*/
|
|
40
|
+
export interface StateRecord {
|
|
41
|
+
/** The destination requested at login-start, still unvalidated. */
|
|
42
|
+
readonly returnTo?: string;
|
|
43
|
+
readonly createdAt: number;
|
|
44
|
+
readonly expiresAt: number;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Server-side storage for issued `state` values, with a TTL.
|
|
48
|
+
*
|
|
49
|
+
* `consume` must be single-use: it returns the record and removes it in one
|
|
50
|
+
* step, so a replayed callback finds nothing. `get` exists for callers that
|
|
51
|
+
* need to inspect a pending login without spending it; the callback handler
|
|
52
|
+
* never uses it.
|
|
53
|
+
*/
|
|
54
|
+
export interface StateStore {
|
|
55
|
+
set(state: string, record: StateRecord, ttlMs: number): Awaitable<void>;
|
|
56
|
+
get(state: string): Awaitable<StateRecord | null>;
|
|
57
|
+
consume(state: string): Awaitable<StateRecord | null>;
|
|
58
|
+
}
|
|
59
|
+
export interface CallbackConfig {
|
|
60
|
+
readonly clientId: string;
|
|
61
|
+
/** Falls back to `ENLITT_SECRET_KEY`; never reaches a browser bundle. */
|
|
62
|
+
readonly secretKey?: string;
|
|
63
|
+
/** Must equal a registered redirect URI exactly. */
|
|
64
|
+
readonly redirectUri: string;
|
|
65
|
+
/** Enlitt's authorization origin (the dashboard host). Defaults to the deployed one. */
|
|
66
|
+
readonly enlittOrigin?: string;
|
|
67
|
+
/**
|
|
68
|
+
* Origin for the two server-to-server requests (code exchange and
|
|
69
|
+
* revocation). Defaults to `enlittOrigin`. A server running as a Cloudflare
|
|
70
|
+
* Worker in Enlitt's own zone must pass the API host: Cloudflare does not run
|
|
71
|
+
* the route-bound Worker behind `enlittOrigin/auth/*` for a same-zone Worker
|
|
72
|
+
* subrequest, so the exchange would reach the wrong Worker and fail.
|
|
73
|
+
*/
|
|
74
|
+
readonly enlittApiOrigin?: string;
|
|
75
|
+
/** The business's own origin. It bounds every redirect this file emits. */
|
|
76
|
+
readonly appOrigin: string;
|
|
77
|
+
/** Path on `appOrigin`, used whenever no valid destination survives. */
|
|
78
|
+
readonly defaultReturnTo: string;
|
|
79
|
+
readonly cookieName?: string;
|
|
80
|
+
readonly stateStore: StateStore;
|
|
81
|
+
/** Link your own user/session before login completes; no token is passed. */
|
|
82
|
+
readonly onSignIn?: (identity: {
|
|
83
|
+
readonly subject: string;
|
|
84
|
+
}, response: Response) => Awaitable<void>;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Begin login: issue a `state`, remember it server-side, and send the consumer
|
|
88
|
+
* to Enlitt's authorization endpoint.
|
|
89
|
+
*/
|
|
90
|
+
export declare function createLoginStartHandler(config: CallbackConfig): (request: Request) => Promise<Response>;
|
|
91
|
+
/**
|
|
92
|
+
* Receive Enlitt's callback: validate `state`, exchange the code, set the one
|
|
93
|
+
* cookie, and send the consumer onward within `appOrigin`.
|
|
94
|
+
*/
|
|
95
|
+
export declare function createCallbackHandler(config: CallbackConfig): (request: Request) => Promise<Response>;
|
|
96
|
+
/**
|
|
97
|
+
* End the session: clear the cookie and ask Enlitt to revoke the token.
|
|
98
|
+
*
|
|
99
|
+
* Revocation is what makes the opaque token worth its lookup, so a signed-out
|
|
100
|
+
* consumer is signed out server-side and not merely cookie-less. A revocation
|
|
101
|
+
* that fails still clears the cookie: leaving the consumer holding a cookie
|
|
102
|
+
* because Enlitt was briefly unreachable would be the worse of the two
|
|
103
|
+
* outcomes, and the token stays revocable from the dashboard.
|
|
104
|
+
*/
|
|
105
|
+
export declare function createLogoutHandler(config: CallbackConfig): (request: Request) => Promise<Response>;
|
|
106
|
+
export {};
|
|
107
|
+
//# sourceMappingURL=callback.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"callback.d.ts","sourceRoot":"","sources":["../../src/server/callback.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AAMH,8EAA8E;AAC9E,KAAK,SAAS,CAAC,CAAC,IAAI,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;AAEnC;;;;;;GAMG;AACH,MAAM,WAAW,WAAW;IAC1B,mEAAmE;IACnE,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;CAC5B;AAED;;;;;;;GAOG;AACH,MAAM,WAAW,UAAU;IACzB,GAAG,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,WAAW,EAAE,KAAK,EAAE,MAAM,GAAG,SAAS,CAAC,IAAI,CAAC,CAAC;IACxE,GAAG,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,CAAC,WAAW,GAAG,IAAI,CAAC,CAAC;IAClD,OAAO,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,CAAC,WAAW,GAAG,IAAI,CAAC,CAAC;CACvD;AAED,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,yEAAyE;IACzE,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;IAC5B,oDAAoD;IACpD,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,wFAAwF;IACxF,QAAQ,CAAC,YAAY,CAAC,EAAE,MAAM,CAAC;IAC/B;;;;;;OAMG;IACH,QAAQ,CAAC,eAAe,CAAC,EAAE,MAAM,CAAC;IAClC,2EAA2E;IAC3E,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,wEAAwE;IACxE,QAAQ,CAAC,eAAe,EAAE,MAAM,CAAC;IACjC,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,UAAU,EAAE,UAAU,CAAC;IAChC,6EAA6E;IAC7E,QAAQ,CAAC,QAAQ,CAAC,EAAE,CAAC,QAAQ,EAAE;QAAE,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAA;KAAE,EAAE,QAAQ,EAAE,QAAQ,KAAK,SAAS,CAAC,IAAI,CAAC,CAAC;CACrG;AA+TD;;;GAGG;AACH,wBAAgB,uBAAuB,CAAC,MAAM,EAAE,cAAc,GAAG,CAAC,OAAO,EAAE,OAAO,KAAK,OAAO,CAAC,QAAQ,CAAC,CA0BvG;AAED;;;GAGG;AACH,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,cAAc,GAAG,CAAC,OAAO,EAAE,OAAO,KAAK,OAAO,CAAC,QAAQ,CAAC,CAwCrG;AAED;;;;;;;;GAQG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,cAAc,GAAG,CAAC,OAAO,EAAE,OAAO,KAAK,OAAO,CAAC,QAAQ,CAAC,CAoCnG"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@enlitt/sdk/server` — the entry point a business runs on its own server,
|
|
3
|
+
* and its entire public surface.
|
|
4
|
+
*
|
|
5
|
+
* Exactly one file answers "what does a business import": this module
|
|
6
|
+
* re-exports the model factory and the types naming its arguments, the
|
|
7
|
+
* session helpers, the typed error hierarchy, and Account's login-start,
|
|
8
|
+
* callback, and logout handlers, and adds no behavior of its own. The package
|
|
9
|
+
* export map resolves the `./server` subpath's `browser` condition to
|
|
10
|
+
* `src/server-unavailable.ts`, never to this file, so no transport, secret
|
|
11
|
+
* resolution, or premium code can enter a browser bundle by import path.
|
|
12
|
+
* The raw transport, SSE parser, and premium state machine are not exported at
|
|
13
|
+
* all; they are reachable only from within the package.
|
|
14
|
+
*
|
|
15
|
+
* Everything reachable from here may read the business secret key.
|
|
16
|
+
*/
|
|
17
|
+
export { enlitt, ENLITT_STANDARD_MODEL, perToken, type EnlittPrice, type EnlittProviderOptions, type EnlittTarget, type PremiumPriceContext } from "../vercel/index.cjs";
|
|
18
|
+
export { ENLITT_SESSION_COOKIE_NAME, EnlittAuthenticationError, EnlittAuthorizationError, EnlittConfigurationError, EnlittError, EnlittInsufficientCreditsError, EnlittLimitExceededError, EnlittLoginRequiredError, EnlittRateLimitError, EnlittSubscriptionInactiveError, enlittSession, enlittSessionMiddleware, getEnlittSession, runWithEnlittSession, usage, withPremiumCharge, type EnlittOptions, type EnlittRateLimitRetryOptions, type EnlittSession, type PremiumChargeFunction, type PremiumChargeHandle, type PremiumTerminalFacts, type UsageAvailability, type WithPremiumChargeOptions } from "../core/index.cjs";
|
|
19
|
+
export { createCallbackHandler, createLoginStartHandler, createLogoutHandler, type CallbackConfig, type StateRecord, type StateStore } from "./callback.cjs";
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@enlitt/sdk/server` — the entry point a business runs on its own server,
|
|
3
|
+
* and its entire public surface.
|
|
4
|
+
*
|
|
5
|
+
* Exactly one file answers "what does a business import": this module
|
|
6
|
+
* re-exports the model factory and the types naming its arguments, the
|
|
7
|
+
* session helpers, the typed error hierarchy, and Account's login-start,
|
|
8
|
+
* callback, and logout handlers, and adds no behavior of its own. The package
|
|
9
|
+
* export map resolves the `./server` subpath's `browser` condition to
|
|
10
|
+
* `src/server-unavailable.ts`, never to this file, so no transport, secret
|
|
11
|
+
* resolution, or premium code can enter a browser bundle by import path.
|
|
12
|
+
* The raw transport, SSE parser, and premium state machine are not exported at
|
|
13
|
+
* all; they are reachable only from within the package.
|
|
14
|
+
*
|
|
15
|
+
* Everything reachable from here may read the business secret key.
|
|
16
|
+
*/
|
|
17
|
+
export { enlitt, ENLITT_STANDARD_MODEL, perToken, type EnlittPrice, type EnlittProviderOptions, type EnlittTarget, type PremiumPriceContext } from "../vercel/index.js";
|
|
18
|
+
export { ENLITT_SESSION_COOKIE_NAME, EnlittAuthenticationError, EnlittAuthorizationError, EnlittConfigurationError, EnlittError, EnlittInsufficientCreditsError, EnlittLimitExceededError, EnlittLoginRequiredError, EnlittRateLimitError, EnlittSubscriptionInactiveError, enlittSession, enlittSessionMiddleware, getEnlittSession, runWithEnlittSession, usage, withPremiumCharge, type EnlittOptions, type EnlittRateLimitRetryOptions, type EnlittSession, type PremiumChargeFunction, type PremiumChargeHandle, type PremiumTerminalFacts, type UsageAvailability, type WithPremiumChargeOptions } from "../core/index.js";
|
|
19
|
+
export { createCallbackHandler, createLoginStartHandler, createLogoutHandler, type CallbackConfig, type StateRecord, type StateStore } from "./callback.js";
|
|
20
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/server/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,EACL,MAAM,EACN,qBAAqB,EACrB,QAAQ,EACR,KAAK,WAAW,EAChB,KAAK,qBAAqB,EAC1B,KAAK,YAAY,EACjB,KAAK,mBAAmB,EACzB,MAAM,oBAAoB,CAAC;AAE5B,OAAO,EACL,0BAA0B,EAC1B,yBAAyB,EACzB,wBAAwB,EACxB,wBAAwB,EACxB,WAAW,EACX,8BAA8B,EAC9B,wBAAwB,EACxB,wBAAwB,EACxB,oBAAoB,EACpB,+BAA+B,EAC/B,aAAa,EACb,uBAAuB,EACvB,gBAAgB,EAChB,oBAAoB,EACpB,KAAK,EACL,iBAAiB,EACjB,KAAK,aAAa,EAClB,KAAK,2BAA2B,EAChC,KAAK,aAAa,EAClB,KAAK,qBAAqB,EAC1B,KAAK,mBAAmB,EACxB,KAAK,oBAAoB,EACzB,KAAK,iBAAiB,EACtB,KAAK,wBAAwB,EAC9B,MAAM,kBAAkB,CAAC;AAE1B,OAAO,EACL,qBAAqB,EACrB,uBAAuB,EACvB,mBAAmB,EACnB,KAAK,cAAc,EACnB,KAAK,WAAW,EAChB,KAAK,UAAU,EAChB,MAAM,eAAe,CAAC"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The server-only boundary that turns a business secret into an outgoing
|
|
3
|
+
* authorization header.
|
|
4
|
+
*
|
|
5
|
+
* There is exactly one export. Resolving a key and formatting a header used to
|
|
6
|
+
* be two of them, which made "resolve the key and forget to use it" a
|
|
7
|
+
* reachable mistake at every call site; there is now no way to obtain the
|
|
8
|
+
* secret through this module's public surface without obtaining the header.
|
|
9
|
+
*
|
|
10
|
+
* A missing or unusable secret throws locally, before any network call, and
|
|
11
|
+
* never yields an unauthenticated client or a credential-free request. That
|
|
12
|
+
* local failure is what stops a managed premium call from silently falling
|
|
13
|
+
* through to a direct, business-funded provider call.
|
|
14
|
+
*
|
|
15
|
+
* The resolved value is a secret. It is never logged, never serialized into a
|
|
16
|
+
* thrown error's message or fields, and never returned to a caller: the
|
|
17
|
+
* `browser` condition on the `./server` subpath keeps this file out of every
|
|
18
|
+
* browser bundle, and the environment assertion below is the second net for a
|
|
19
|
+
* bundler or runtime that ignores that condition.
|
|
20
|
+
*
|
|
21
|
+
* Both local failures — a browser environment and an unusable secret — raise
|
|
22
|
+
* `EnlittConfigurationError`. That is what `enlitt()` documents its callers
|
|
23
|
+
* will see for a missing or invalid secret, and the type has to be right here
|
|
24
|
+
* rather than at one caller's boundary: any other caller of this function
|
|
25
|
+
* (`server/callback.ts`'s handlers among them) would otherwise receive a bare
|
|
26
|
+
* `Error` for exactly the same misconfiguration, and a business catching the
|
|
27
|
+
* package's own error class would miss it.
|
|
28
|
+
*/
|
|
29
|
+
/**
|
|
30
|
+
* Resolve the business secret and return the one header value that carries it.
|
|
31
|
+
*
|
|
32
|
+
* Resolution order is explicit configuration first, then the `ENLITT_SECRET_KEY`
|
|
33
|
+
* environment fallback. An explicitly supplied key is never abandoned in
|
|
34
|
+
* favour of the environment: a business that passed an empty or malformed
|
|
35
|
+
* value has misconfigured that value, and silently authenticating as whatever
|
|
36
|
+
* the environment happens to hold would be a different identity than the one
|
|
37
|
+
* the call site asked for.
|
|
38
|
+
*
|
|
39
|
+
* @returns a single `Bearer <secret>` header value.
|
|
40
|
+
* @throws {EnlittConfigurationError} in a browser environment, or when no
|
|
41
|
+
* usable secret resolves. Neither the message nor any field of the thrown
|
|
42
|
+
* error carries any part of the secret.
|
|
43
|
+
*/
|
|
44
|
+
export declare function resolveBusinessAuthorizationHeader(config: {
|
|
45
|
+
secretKey?: string;
|
|
46
|
+
}): string;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The server-only boundary that turns a business secret into an outgoing
|
|
3
|
+
* authorization header.
|
|
4
|
+
*
|
|
5
|
+
* There is exactly one export. Resolving a key and formatting a header used to
|
|
6
|
+
* be two of them, which made "resolve the key and forget to use it" a
|
|
7
|
+
* reachable mistake at every call site; there is now no way to obtain the
|
|
8
|
+
* secret through this module's public surface without obtaining the header.
|
|
9
|
+
*
|
|
10
|
+
* A missing or unusable secret throws locally, before any network call, and
|
|
11
|
+
* never yields an unauthenticated client or a credential-free request. That
|
|
12
|
+
* local failure is what stops a managed premium call from silently falling
|
|
13
|
+
* through to a direct, business-funded provider call.
|
|
14
|
+
*
|
|
15
|
+
* The resolved value is a secret. It is never logged, never serialized into a
|
|
16
|
+
* thrown error's message or fields, and never returned to a caller: the
|
|
17
|
+
* `browser` condition on the `./server` subpath keeps this file out of every
|
|
18
|
+
* browser bundle, and the environment assertion below is the second net for a
|
|
19
|
+
* bundler or runtime that ignores that condition.
|
|
20
|
+
*
|
|
21
|
+
* Both local failures — a browser environment and an unusable secret — raise
|
|
22
|
+
* `EnlittConfigurationError`. That is what `enlitt()` documents its callers
|
|
23
|
+
* will see for a missing or invalid secret, and the type has to be right here
|
|
24
|
+
* rather than at one caller's boundary: any other caller of this function
|
|
25
|
+
* (`server/callback.ts`'s handlers among them) would otherwise receive a bare
|
|
26
|
+
* `Error` for exactly the same misconfiguration, and a business catching the
|
|
27
|
+
* package's own error class would miss it.
|
|
28
|
+
*/
|
|
29
|
+
/**
|
|
30
|
+
* Resolve the business secret and return the one header value that carries it.
|
|
31
|
+
*
|
|
32
|
+
* Resolution order is explicit configuration first, then the `ENLITT_SECRET_KEY`
|
|
33
|
+
* environment fallback. An explicitly supplied key is never abandoned in
|
|
34
|
+
* favour of the environment: a business that passed an empty or malformed
|
|
35
|
+
* value has misconfigured that value, and silently authenticating as whatever
|
|
36
|
+
* the environment happens to hold would be a different identity than the one
|
|
37
|
+
* the call site asked for.
|
|
38
|
+
*
|
|
39
|
+
* @returns a single `Bearer <secret>` header value.
|
|
40
|
+
* @throws {EnlittConfigurationError} in a browser environment, or when no
|
|
41
|
+
* usable secret resolves. Neither the message nor any field of the thrown
|
|
42
|
+
* error carries any part of the secret.
|
|
43
|
+
*/
|
|
44
|
+
export declare function resolveBusinessAuthorizationHeader(config: {
|
|
45
|
+
secretKey?: string;
|
|
46
|
+
}): string;
|
|
47
|
+
//# sourceMappingURL=secrets.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"secrets.d.ts","sourceRoot":"","sources":["../../src/server/secrets.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AAmDH;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,kCAAkC,CAAC,MAAM,EAAE;IAAE,SAAS,CAAC,EAAE,MAAM,CAAA;CAAE,GAAG,MAAM,CAsBzF"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// src/server-unavailable.ts
|
|
4
|
+
throw new Error(
|
|
5
|
+
"This @enlitt/sdk entry (server, core, vercel, or openai) is a server-only entry point and was resolved in a browser bundle. Import it from server code only; use @enlitt/sdk/browser in code you ship to consumers."
|
|
6
|
+
);
|
|
7
|
+
//# sourceMappingURL=server-unavailable.cjs.map
|
|
8
|
+
//# sourceMappingURL=server-unavailable.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/server-unavailable.ts"],"names":[],"mappings":";;;AAUA,MAAM,IAAI,KAAA;AAAA,EACR;AAGF,CAAA","file":"server-unavailable.cjs","sourcesContent":["/**\n * The `browser` condition for `@enlitt/sdk/server`, `@enlitt/sdk/core`, and\n * `@enlitt/sdk/vercel`, and `@enlitt/sdk/openai` resolves here.\n *\n * A bundler that follows browser conditions can therefore never pull the real\n * server module — and with it `process.env.ENLITT_SECRET_KEY` — into a client\n * bundle. Failing at import time makes the mistake loud at build or first\n * load rather than silently shipping a secret read to consumers.\n */\n\nthrow new Error(\n \"This @enlitt/sdk entry (server, core, vercel, or openai) is a server-only entry point and was resolved in a \" +\n \"browser bundle. Import it from server code only; use @enlitt/sdk/browser \" +\n \"in code you ship to consumers.\"\n);\n\nexport {};\n"]}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The `browser` condition for `@enlitt/sdk/server`, `@enlitt/sdk/core`, and
|
|
3
|
+
* `@enlitt/sdk/vercel`, and `@enlitt/sdk/openai` resolves here.
|
|
4
|
+
*
|
|
5
|
+
* A bundler that follows browser conditions can therefore never pull the real
|
|
6
|
+
* server module — and with it `process.env.ENLITT_SECRET_KEY` — into a client
|
|
7
|
+
* bundle. Failing at import time makes the mistake loud at build or first
|
|
8
|
+
* load rather than silently shipping a secret read to consumers.
|
|
9
|
+
*/
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The `browser` condition for `@enlitt/sdk/server`, `@enlitt/sdk/core`, and
|
|
3
|
+
* `@enlitt/sdk/vercel`, and `@enlitt/sdk/openai` resolves here.
|
|
4
|
+
*
|
|
5
|
+
* A bundler that follows browser conditions can therefore never pull the real
|
|
6
|
+
* server module — and with it `process.env.ENLITT_SECRET_KEY` — into a client
|
|
7
|
+
* bundle. Failing at import time makes the mistake loud at build or first
|
|
8
|
+
* load rather than silently shipping a secret read to consumers.
|
|
9
|
+
*/
|
|
10
|
+
export {};
|
|
11
|
+
//# sourceMappingURL=server-unavailable.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server-unavailable.d.ts","sourceRoot":"","sources":["../src/server-unavailable.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAQH,OAAO,EAAE,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
// src/server-unavailable.ts
|
|
2
|
+
throw new Error(
|
|
3
|
+
"This @enlitt/sdk entry (server, core, vercel, or openai) is a server-only entry point and was resolved in a browser bundle. Import it from server code only; use @enlitt/sdk/browser in code you ship to consumers."
|
|
4
|
+
);
|
|
5
|
+
//# sourceMappingURL=server-unavailable.js.map
|
|
6
|
+
//# sourceMappingURL=server-unavailable.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/server-unavailable.ts"],"names":[],"mappings":";AAUA,MAAM,IAAI,KAAA;AAAA,EACR;AAGF,CAAA","file":"server-unavailable.js","sourcesContent":["/**\n * The `browser` condition for `@enlitt/sdk/server`, `@enlitt/sdk/core`, and\n * `@enlitt/sdk/vercel`, and `@enlitt/sdk/openai` resolves here.\n *\n * A bundler that follows browser conditions can therefore never pull the real\n * server module — and with it `process.env.ENLITT_SECRET_KEY` — into a client\n * bundle. Failing at import time makes the mistake loud at build or first\n * load rather than silently shipping a secret read to consumers.\n */\n\nthrow new Error(\n \"This @enlitt/sdk entry (server, core, vercel, or openai) is a server-only entry point and was resolved in a \" +\n \"browser bundle. Import it from server code only; use @enlitt/sdk/browser \" +\n \"in code you ship to consumers.\"\n);\n\nexport {};\n"]}
|