@soulcraft/sdk 1.4.12 → 1.5.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/dist/client/create-client-sdk.d.ts +99 -0
- package/dist/client/create-client-sdk.d.ts.map +1 -0
- package/dist/client/create-client-sdk.js +174 -0
- package/dist/client/create-client-sdk.js.map +1 -0
- package/dist/client/index.d.ts +1 -0
- package/dist/client/index.d.ts.map +1 -1
- package/dist/client/index.js +2 -0
- package/dist/client/index.js.map +1 -1
- package/dist/index.d.ts +8 -8
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +13 -8
- package/dist/index.js.map +1 -1
- package/dist/modules/auth/middleware.d.ts +246 -68
- package/dist/modules/auth/middleware.d.ts.map +1 -1
- package/dist/modules/auth/middleware.js +369 -67
- package/dist/modules/auth/middleware.js.map +1 -1
- package/dist/modules/auth/types.d.ts +4 -3
- package/dist/modules/auth/types.d.ts.map +1 -1
- package/dist/modules/brainy/errors.d.ts +16 -6
- package/dist/modules/brainy/errors.d.ts.map +1 -1
- package/dist/modules/brainy/errors.js +21 -11
- package/dist/modules/brainy/errors.js.map +1 -1
- package/dist/server/from-license.d.ts.map +1 -1
- package/dist/server/from-license.js +11 -4
- package/dist/server/from-license.js.map +1 -1
- package/dist/server/index.d.ts +3 -3
- package/dist/server/index.d.ts.map +1 -1
- package/dist/server/index.js +3 -3
- package/dist/server/index.js.map +1 -1
- package/dist/server/instance-pool.d.ts +12 -35
- package/dist/server/instance-pool.d.ts.map +1 -1
- package/dist/server/instance-pool.js +14 -44
- package/dist/server/instance-pool.js.map +1 -1
- package/dist/server/postmessage-handler.d.ts +25 -0
- package/dist/server/postmessage-handler.d.ts.map +1 -1
- package/dist/server/postmessage-handler.js +13 -0
- package/dist/server/postmessage-handler.js.map +1 -1
- package/dist/transports/http.d.ts +1 -1
- package/dist/transports/http.d.ts.map +1 -1
- package/dist/transports/http.js +5 -2
- package/dist/transports/http.js.map +1 -1
- package/dist/transports/postmessage.d.ts +13 -7
- package/dist/transports/postmessage.d.ts.map +1 -1
- package/dist/transports/postmessage.js +24 -8
- package/dist/transports/postmessage.js.map +1 -1
- package/dist/transports/sse.d.ts +5 -1
- package/dist/transports/sse.d.ts.map +1 -1
- package/dist/transports/sse.js +12 -3
- package/dist/transports/sse.js.map +1 -1
- package/dist/transports/ws.d.ts +7 -3
- package/dist/transports/ws.d.ts.map +1 -1
- package/dist/transports/ws.js +28 -9
- package/dist/transports/ws.js.map +1 -1
- package/package.json +17 -5
|
@@ -1,31 +1,41 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @module modules/auth/middleware
|
|
3
|
-
* @description Hono auth middleware factories
|
|
4
|
-
* for Soulcraft product backends.
|
|
3
|
+
* @description Hono auth middleware factories, remote session verification, and
|
|
4
|
+
* dev/guest session utilities for Soulcraft product backends.
|
|
5
5
|
*
|
|
6
|
-
*
|
|
7
|
-
* to authenticate requests against a better-auth instance (local or remote IdP).
|
|
6
|
+
* ## Session verification strategies
|
|
8
7
|
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
* per-product copies of `requireAuth` / `optionalAuth` in Workshop's better-auth.ts.
|
|
8
|
+
* All products share the same `createAuthMiddleware` factory, but each product
|
|
9
|
+
* selects the right session verifier for its deployment context:
|
|
12
10
|
*
|
|
13
|
-
*
|
|
11
|
+
* ```
|
|
12
|
+
* Production (all products):
|
|
13
|
+
* createRemoteSessionVerifier({ idpUrl: 'https://auth.soulcraft.com' })
|
|
14
|
+
*
|
|
15
|
+
* Development (all products):
|
|
16
|
+
* createDevSessionVerifier({ role: 'owner' }) // auto-login, no OAuth needed
|
|
17
|
+
*
|
|
18
|
+
* Workshop standalone (legacy / local OAuth):
|
|
19
|
+
* createAuthMiddleware(betterAuthInstance) // BetterAuthLike overload
|
|
20
|
+
* ```
|
|
21
|
+
*
|
|
22
|
+
* ## Dev and guest endpoint factories
|
|
14
23
|
*
|
|
15
|
-
* `
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
24
|
+
* - `createDevLoginHandler` — mounts a `/api/dev/login` endpoint for role-switching
|
|
25
|
+
* during development. Issues a signed dev session cookie. No-ops in production.
|
|
26
|
+
* - `createGuestSessionHandler` — mounts a `/api/guest/session` endpoint so Venue
|
|
27
|
+
* visitors can obtain a guest session (platformRole `'guest'`) for anonymous
|
|
28
|
+
* browse and booking flows, before they create an account.
|
|
19
29
|
*
|
|
20
|
-
* @example
|
|
30
|
+
* @example Production setup (Venue / Academy)
|
|
21
31
|
* ```typescript
|
|
22
|
-
* import { createAuthMiddleware } from '@soulcraft/sdk/server'
|
|
23
|
-
* import { auth } from './better-auth.js'
|
|
32
|
+
* import { createAuthMiddleware, createRemoteSessionVerifier } from '@soulcraft/sdk/server'
|
|
24
33
|
*
|
|
25
|
-
* const {
|
|
34
|
+
* const verifySession = createRemoteSessionVerifier({ idpUrl: process.env.SOULCRAFT_IDP_URL! })
|
|
35
|
+
* const { requireAuth, optionalAuth } = createAuthMiddleware(verifySession)
|
|
26
36
|
*
|
|
27
|
-
* app.get('/api/
|
|
28
|
-
* const user = c.get('user')! // SoulcraftSessionUser
|
|
37
|
+
* app.get('/api/bookings', requireAuth, async (c) => {
|
|
38
|
+
* const user = c.get('user')! // SoulcraftSessionUser
|
|
29
39
|
* })
|
|
30
40
|
* ```
|
|
31
41
|
*/
|
|
@@ -54,41 +64,48 @@ export interface BetterAuthLike {
|
|
|
54
64
|
};
|
|
55
65
|
}
|
|
56
66
|
/**
|
|
57
|
-
*
|
|
67
|
+
* A session verifier function — the common abstraction for session resolution
|
|
68
|
+
* across all products in non-standalone auth mode.
|
|
69
|
+
*
|
|
70
|
+
* Returned by `createRemoteSessionVerifier` and `createDevSessionVerifier`.
|
|
71
|
+
* `createAuthMiddleware` accepts either a `BetterAuthLike` instance (Workshop
|
|
72
|
+
* standalone mode) or a `SessionVerifier` function (all other products and modes).
|
|
73
|
+
*/
|
|
74
|
+
export type SessionVerifier = (cookieHeader: string) => Promise<SoulcraftSession | null>;
|
|
75
|
+
/**
|
|
76
|
+
* Options for `createAuthMiddleware()`.
|
|
58
77
|
*/
|
|
59
78
|
export interface AuthMiddlewareOptions {
|
|
60
79
|
/**
|
|
61
|
-
* If true, a synthetic dev user is injected in non-production environments
|
|
62
|
-
*
|
|
63
|
-
*
|
|
80
|
+
* If true, a synthetic dev user is injected in non-production environments
|
|
81
|
+
* when a `BetterAuthLike` auth instance is provided and session lookup fails.
|
|
82
|
+
* Not used when a `SessionVerifier` function is provided — use
|
|
83
|
+
* `createDevSessionVerifier` instead for full dev auto-login in that mode.
|
|
64
84
|
* @default true
|
|
65
85
|
*/
|
|
66
86
|
devAutoLogin?: boolean;
|
|
67
87
|
}
|
|
68
88
|
/**
|
|
69
|
-
*
|
|
89
|
+
* The object returned by `createAuthMiddleware()`.
|
|
70
90
|
*/
|
|
71
91
|
export interface AuthMiddleware {
|
|
72
92
|
/**
|
|
73
|
-
* Require authentication. Resolves the
|
|
74
|
-
* valid, attaches the typed user to the Hono context
|
|
75
|
-
* HTTP 401 if unauthenticated.
|
|
76
|
-
*
|
|
77
|
-
* In development mode (unless devAutoLogin is disabled), a synthetic dev user
|
|
78
|
-
* is injected automatically.
|
|
93
|
+
* Require authentication. Resolves the session from request cookies. If the
|
|
94
|
+
* session is valid, attaches the typed user to the Hono context under the
|
|
95
|
+
* `'user'` key and calls `next()`. Returns HTTP 401 if unauthenticated.
|
|
79
96
|
*/
|
|
80
97
|
requireAuth: (c: AuthContext, next: Next) => Promise<void | Response>;
|
|
81
98
|
/**
|
|
82
99
|
* Optional authentication. Resolves the session if one exists, but does not
|
|
83
|
-
* reject unauthenticated requests. User will be null for anonymous requests.
|
|
100
|
+
* reject unauthenticated requests. User will be `null` for anonymous requests.
|
|
84
101
|
*/
|
|
85
102
|
optionalAuth: (c: AuthContext, next: Next) => Promise<void | Response>;
|
|
86
103
|
}
|
|
87
104
|
/**
|
|
88
|
-
*
|
|
105
|
+
* Options for `createRemoteSessionVerifier()`.
|
|
89
106
|
*/
|
|
90
107
|
export interface RemoteSessionVerifierOptions {
|
|
91
|
-
/** The central IdP base URL, e.g. "https://auth.soulcraft.com"
|
|
108
|
+
/** The central IdP base URL, e.g. `"https://auth.soulcraft.com"`. */
|
|
92
109
|
idpUrl: string;
|
|
93
110
|
/** Session cache TTL in milliseconds. Default: 30 000 (30 seconds). */
|
|
94
111
|
cacheTtlMs?: number;
|
|
@@ -96,7 +113,7 @@ export interface RemoteSessionVerifierOptions {
|
|
|
96
113
|
cacheMax?: number;
|
|
97
114
|
}
|
|
98
115
|
/**
|
|
99
|
-
*
|
|
116
|
+
* Options for `createDevSessionVerifier()`.
|
|
100
117
|
*/
|
|
101
118
|
export interface DevSessionVerifierOptions {
|
|
102
119
|
/**
|
|
@@ -116,40 +133,101 @@ export interface DevSessionVerifierOptions {
|
|
|
116
133
|
name?: string;
|
|
117
134
|
}
|
|
118
135
|
/**
|
|
119
|
-
*
|
|
136
|
+
* Options for `createDevLoginHandler()`.
|
|
137
|
+
*/
|
|
138
|
+
export interface DevLoginHandlerOptions {
|
|
139
|
+
/**
|
|
140
|
+
* Allowed platform roles. The role must be in this list for the handler to
|
|
141
|
+
* issue a session cookie. Defaults to all non-guest platform roles.
|
|
142
|
+
* @default ['creator','viewer','customer','staff','manager','owner','learner','instructor']
|
|
143
|
+
*/
|
|
144
|
+
allowedRoles?: SoulcraftSessionUser['platformRole'][];
|
|
145
|
+
/**
|
|
146
|
+
* Cookie name for the issued dev session.
|
|
147
|
+
* @default 'soulcraft_dev_session'
|
|
148
|
+
*/
|
|
149
|
+
cookieName?: string;
|
|
150
|
+
/**
|
|
151
|
+
* Session cookie max-age in seconds.
|
|
152
|
+
* @default 86400 (24 hours)
|
|
153
|
+
*/
|
|
154
|
+
maxAgeSeconds?: number;
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Options for `createGuestSessionHandler()`.
|
|
158
|
+
*/
|
|
159
|
+
export interface GuestSessionHandlerOptions {
|
|
160
|
+
/**
|
|
161
|
+
* Cookie name for the issued guest session.
|
|
162
|
+
* @default 'soulcraft_guest_session'
|
|
163
|
+
*/
|
|
164
|
+
cookieName?: string;
|
|
165
|
+
/**
|
|
166
|
+
* Guest session max-age in seconds.
|
|
167
|
+
* @default 3600 (1 hour)
|
|
168
|
+
*/
|
|
169
|
+
maxAgeSeconds?: number;
|
|
170
|
+
/**
|
|
171
|
+
* An optional callback invoked when a new guest session is created.
|
|
172
|
+
* Receives the generated guest ID. Useful for analytics or initializing
|
|
173
|
+
* a guest cart/basket in the product's store.
|
|
174
|
+
*
|
|
175
|
+
* @param guestId - The newly generated unique guest ID.
|
|
176
|
+
*/
|
|
177
|
+
onGuestCreated?: (guestId: string) => Promise<void> | void;
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* Creates Hono auth middleware from a `SessionVerifier` function or a `BetterAuthLike`
|
|
181
|
+
* instance.
|
|
182
|
+
*
|
|
183
|
+
* **Preferred form (all products in OIDC-client mode):**
|
|
184
|
+
* Pass a `SessionVerifier` returned by `createRemoteSessionVerifier` or
|
|
185
|
+
* `createDevSessionVerifier`. The middleware reads the request cookie header and
|
|
186
|
+
* passes it to the verifier.
|
|
120
187
|
*
|
|
121
|
-
*
|
|
122
|
-
*
|
|
123
|
-
*
|
|
188
|
+
* **Legacy form (Workshop standalone mode):**
|
|
189
|
+
* Pass a `better-auth` instance directly. The middleware calls `auth.api.getSession`.
|
|
190
|
+
* In non-production environments and when `devAutoLogin` is enabled, a synthetic dev
|
|
191
|
+
* user is injected on failed lookups so local dev works without OAuth.
|
|
124
192
|
*
|
|
125
|
-
*
|
|
126
|
-
* user is injected automatically to allow local development without OAuth setup.
|
|
127
|
-
* Disable this with `options.devAutoLogin = false`.
|
|
193
|
+
* Both forms return identical `{ requireAuth, optionalAuth }` middleware.
|
|
128
194
|
*
|
|
129
|
-
* @param
|
|
130
|
-
* @param options - Optional middleware configuration.
|
|
195
|
+
* @param authOrVerifier - A `better-auth` instance or a `SessionVerifier` function.
|
|
196
|
+
* @param options - Optional middleware configuration (only applies to `BetterAuthLike` form).
|
|
131
197
|
* @returns Middleware pair: `{ requireAuth, optionalAuth }`.
|
|
132
198
|
*
|
|
133
|
-
* @example
|
|
199
|
+
* @example Verifier form (Venue / Academy / Workshop in OIDC mode)
|
|
134
200
|
* ```typescript
|
|
135
|
-
* const {
|
|
136
|
-
*
|
|
201
|
+
* const verifySession = createRemoteSessionVerifier({ idpUrl: process.env.SOULCRAFT_IDP_URL! })
|
|
202
|
+
* const { requireAuth } = createAuthMiddleware(verifySession)
|
|
203
|
+
* ```
|
|
204
|
+
*
|
|
205
|
+
* @example BetterAuth form (Workshop dev standalone)
|
|
206
|
+
* ```typescript
|
|
207
|
+
* import { auth } from './better-auth.js'
|
|
208
|
+
* const { requireAuth } = createAuthMiddleware(auth)
|
|
137
209
|
* ```
|
|
138
210
|
*/
|
|
139
|
-
export declare function createAuthMiddleware(
|
|
211
|
+
export declare function createAuthMiddleware(authOrVerifier: BetterAuthLike | SessionVerifier, options?: AuthMiddlewareOptions): AuthMiddleware;
|
|
140
212
|
/**
|
|
141
|
-
*
|
|
142
|
-
*
|
|
213
|
+
* Creates a cached remote session verifier that proxies session lookups to
|
|
214
|
+
* the central IdP at `auth.soulcraft.com`.
|
|
143
215
|
*
|
|
144
|
-
* Used by products that operate as OIDC clients
|
|
145
|
-
*
|
|
146
|
-
*
|
|
216
|
+
* Used by products that operate as OIDC clients (Venue, Academy, and Workshop
|
|
217
|
+
* in production). Caches successful lookups in an LRU cache to avoid per-request
|
|
218
|
+
* HTTP round-trips to the IdP.
|
|
147
219
|
*
|
|
148
220
|
* The verifier sends the cookie header to the IdP's `/api/auth/get-session` endpoint
|
|
149
|
-
* and returns the resolved `SoulcraftSession` or null if the session is invalid.
|
|
221
|
+
* and returns the resolved `SoulcraftSession` or `null` if the session is invalid.
|
|
222
|
+
*
|
|
223
|
+
* Pass the returned function directly to `createAuthMiddleware`:
|
|
224
|
+
* ```typescript
|
|
225
|
+
* const verifySession = createRemoteSessionVerifier({ idpUrl: process.env.SOULCRAFT_IDP_URL! })
|
|
226
|
+
* const { requireAuth } = createAuthMiddleware(verifySession)
|
|
227
|
+
* ```
|
|
150
228
|
*
|
|
151
229
|
* @param options - IdP URL, cache TTL, and max cache size.
|
|
152
|
-
* @returns
|
|
230
|
+
* @returns A `SessionVerifier` — async function that accepts a cookie header string.
|
|
153
231
|
*
|
|
154
232
|
* @example
|
|
155
233
|
* ```typescript
|
|
@@ -162,35 +240,31 @@ export declare function createAuthMiddleware(auth: BetterAuthLike, options?: Aut
|
|
|
162
240
|
* if (!session) return c.json({ error: 'Unauthorized' }, 401)
|
|
163
241
|
* ```
|
|
164
242
|
*/
|
|
165
|
-
export declare function createRemoteSessionVerifier(options: RemoteSessionVerifierOptions):
|
|
243
|
+
export declare function createRemoteSessionVerifier(options: RemoteSessionVerifierOptions): SessionVerifier;
|
|
166
244
|
/**
|
|
167
|
-
*
|
|
245
|
+
* Creates a session verifier that always resolves to a synthetic dev session.
|
|
168
246
|
*
|
|
169
|
-
* Intended for products that run as OIDC clients
|
|
170
|
-
*
|
|
171
|
-
*
|
|
172
|
-
* configured synthetic user.
|
|
247
|
+
* Intended for products that run as OIDC clients but need local development auth
|
|
248
|
+
* without OAuth, network calls, SQLite, or real cookies. The returned verifier always
|
|
249
|
+
* succeeds — any request resolves to the configured synthetic user.
|
|
173
250
|
*
|
|
174
|
-
* Designed
|
|
251
|
+
* Designed as a drop-in replacement for `createRemoteSessionVerifier` in local dev:
|
|
175
252
|
*
|
|
176
253
|
* ```typescript
|
|
177
254
|
* const verifySession = process.env.SOULCRAFT_IDP_URL
|
|
178
255
|
* ? createRemoteSessionVerifier({ idpUrl: process.env.SOULCRAFT_IDP_URL })
|
|
179
256
|
* : createDevSessionVerifier({ role: 'owner' })
|
|
180
|
-
* ```
|
|
181
257
|
*
|
|
182
|
-
*
|
|
183
|
-
*
|
|
258
|
+
* const { requireAuth } = createAuthMiddleware(verifySession)
|
|
259
|
+
* ```
|
|
184
260
|
*
|
|
185
261
|
* **Never use in production.** The verifier performs no validation whatsoever.
|
|
186
262
|
*
|
|
187
263
|
* @param options - Optional synthetic user configuration.
|
|
188
|
-
* @returns
|
|
264
|
+
* @returns A `SessionVerifier` with the same signature as `createRemoteSessionVerifier`.
|
|
189
265
|
*
|
|
190
|
-
* @example
|
|
266
|
+
* @example
|
|
191
267
|
* ```typescript
|
|
192
|
-
* import { createRemoteSessionVerifier, createDevSessionVerifier } from '@soulcraft/sdk/server'
|
|
193
|
-
*
|
|
194
268
|
* const verifySession = process.env.SOULCRAFT_IDP_URL
|
|
195
269
|
* ? createRemoteSessionVerifier({ idpUrl: process.env.SOULCRAFT_IDP_URL })
|
|
196
270
|
* : createDevSessionVerifier({ role: 'owner' })
|
|
@@ -202,5 +276,109 @@ export declare function createRemoteSessionVerifier(options: RemoteSessionVerifi
|
|
|
202
276
|
* }
|
|
203
277
|
* ```
|
|
204
278
|
*/
|
|
205
|
-
export declare function createDevSessionVerifier(options?: DevSessionVerifierOptions):
|
|
279
|
+
export declare function createDevSessionVerifier(options?: DevSessionVerifierOptions): SessionVerifier;
|
|
280
|
+
/**
|
|
281
|
+
* Creates a Hono request handler for a dev login endpoint.
|
|
282
|
+
*
|
|
283
|
+
* Mount at `/api/dev/login` to get a role-switching endpoint for local
|
|
284
|
+
* development. Accepts `?role=<platformRole>` and optional `?email=` / `?name=`
|
|
285
|
+
* query params. Issues a signed base64url session cookie that `createAuthMiddleware`
|
|
286
|
+
* (when used with a `SessionVerifier` that reads dev cookies) can resolve.
|
|
287
|
+
*
|
|
288
|
+
* **Guards against production use:** the handler returns HTTP 404 when
|
|
289
|
+
* `NODE_ENV === 'production'` — it is safe to leave mounted in all environments.
|
|
290
|
+
*
|
|
291
|
+
* @param options - Allowed roles, cookie name, and max-age.
|
|
292
|
+
* @returns A Hono-compatible request handler `(c: Context) => Response`.
|
|
293
|
+
*
|
|
294
|
+
* @example
|
|
295
|
+
* ```typescript
|
|
296
|
+
* import { createDevLoginHandler } from '@soulcraft/sdk/server'
|
|
297
|
+
*
|
|
298
|
+
* // In your Hono server setup:
|
|
299
|
+
* app.get('/api/dev/login', createDevLoginHandler({ allowedRoles: ['owner', 'staff', 'customer'] }))
|
|
300
|
+
*
|
|
301
|
+
* // Usage: GET /api/dev/login?role=staff → sets cookie + redirects to /
|
|
302
|
+
* ```
|
|
303
|
+
*/
|
|
304
|
+
export declare function createDevLoginHandler(options?: DevLoginHandlerOptions): (c: Context) => Response | Promise<Response>;
|
|
305
|
+
/**
|
|
306
|
+
* Creates a session verifier that reads the cookie issued by `createDevLoginHandler`.
|
|
307
|
+
*
|
|
308
|
+
* Use this together with `createDevLoginHandler` when you want dev role-switching
|
|
309
|
+
* (e.g. clicking "Login as Staff" in a dev UI) rather than a fixed synthetic user.
|
|
310
|
+
*
|
|
311
|
+
* The verifier decodes the base64url cookie value and returns the embedded session.
|
|
312
|
+
* Falls back to `null` (unauthenticated) if the cookie is absent or expired.
|
|
313
|
+
*
|
|
314
|
+
* ```typescript
|
|
315
|
+
* // Only one of these in dev — pick what fits your workflow:
|
|
316
|
+
*
|
|
317
|
+
* // Option A: Fixed dev user, no login UI needed
|
|
318
|
+
* const verifySession = createDevSessionVerifier({ role: 'owner' })
|
|
319
|
+
*
|
|
320
|
+
* // Option B: Role-switching dev login UI
|
|
321
|
+
* app.get('/api/dev/login', createDevLoginHandler({ allowedRoles: ['owner', 'staff', 'customer'] }))
|
|
322
|
+
* const verifySession = createDevCookieVerifier()
|
|
323
|
+
* ```
|
|
324
|
+
*
|
|
325
|
+
* @param cookieName - Must match the `cookieName` passed to `createDevLoginHandler`. Default: `'soulcraft_dev_session'`.
|
|
326
|
+
* @returns A `SessionVerifier` compatible with `createAuthMiddleware`.
|
|
327
|
+
*/
|
|
328
|
+
export declare function createDevCookieVerifier(cookieName?: string): SessionVerifier;
|
|
329
|
+
/**
|
|
330
|
+
* Creates a Hono request handler that issues a guest session cookie.
|
|
331
|
+
*
|
|
332
|
+
* Venue visitors can browse and initiate bookings without creating an account.
|
|
333
|
+
* This handler mounts at e.g. `/api/guest/session` and issues a session cookie
|
|
334
|
+
* with `platformRole: 'guest'` and a unique guest ID on each call (if no valid
|
|
335
|
+
* guest session already exists).
|
|
336
|
+
*
|
|
337
|
+
* The guest session cookie can be verified using `createGuestCookieVerifier`,
|
|
338
|
+
* which returns a `SessionVerifier` compatible with `createAuthMiddleware`.
|
|
339
|
+
*
|
|
340
|
+
* @param options - Cookie name, max-age, and optional `onGuestCreated` callback.
|
|
341
|
+
* @returns A Hono-compatible request handler.
|
|
342
|
+
*
|
|
343
|
+
* @example
|
|
344
|
+
* ```typescript
|
|
345
|
+
* import { createGuestSessionHandler, createGuestCookieVerifier, createAuthMiddleware } from '@soulcraft/sdk/server'
|
|
346
|
+
*
|
|
347
|
+
* // Issue guest sessions
|
|
348
|
+
* app.post('/api/guest/session', createGuestSessionHandler({
|
|
349
|
+
* onGuestCreated: async (guestId) => {
|
|
350
|
+
* await db.guests.insert({ id: guestId, createdAt: new Date() })
|
|
351
|
+
* },
|
|
352
|
+
* }))
|
|
353
|
+
*
|
|
354
|
+
* // Verify guest sessions in optional auth (guests can browse)
|
|
355
|
+
* const verifyGuest = createGuestCookieVerifier()
|
|
356
|
+
* const verifySession = createRemoteSessionVerifier({ idpUrl: process.env.SOULCRAFT_IDP_URL! })
|
|
357
|
+
*
|
|
358
|
+
* // Compose: check real session first, fall back to guest
|
|
359
|
+
* const { optionalAuth } = createAuthMiddleware(async (cookie) =>
|
|
360
|
+
* await verifySession(cookie) ?? await verifyGuest(cookie)
|
|
361
|
+
* )
|
|
362
|
+
* ```
|
|
363
|
+
*/
|
|
364
|
+
export declare function createGuestSessionHandler(options?: GuestSessionHandlerOptions): (c: Context) => Promise<Response>;
|
|
365
|
+
/**
|
|
366
|
+
* Creates a session verifier that reads the cookie issued by `createGuestSessionHandler`.
|
|
367
|
+
*
|
|
368
|
+
* Returns the guest `SoulcraftSession` or `null` if no valid guest cookie is present.
|
|
369
|
+
* Compose with `createRemoteSessionVerifier` to allow both authenticated and guest access:
|
|
370
|
+
*
|
|
371
|
+
* ```typescript
|
|
372
|
+
* const verifyReal = createRemoteSessionVerifier({ idpUrl: process.env.SOULCRAFT_IDP_URL! })
|
|
373
|
+
* const verifyGuest = createGuestCookieVerifier()
|
|
374
|
+
*
|
|
375
|
+
* const { optionalAuth } = createAuthMiddleware(async (cookie) =>
|
|
376
|
+
* await verifyReal(cookie) ?? await verifyGuest(cookie)
|
|
377
|
+
* )
|
|
378
|
+
* ```
|
|
379
|
+
*
|
|
380
|
+
* @param cookieName - Must match the `cookieName` passed to `createGuestSessionHandler`. Default: `'soulcraft_guest_session'`.
|
|
381
|
+
* @returns A `SessionVerifier` compatible with `createAuthMiddleware`.
|
|
382
|
+
*/
|
|
383
|
+
export declare function createGuestCookieVerifier(cookieName?: string): SessionVerifier;
|
|
206
384
|
//# sourceMappingURL=middleware.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"middleware.d.ts","sourceRoot":"","sources":["../../../src/modules/auth/middleware.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"middleware.d.ts","sourceRoot":"","sources":["../../../src/modules/auth/middleware.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwCG;AAIH,OAAO,KAAK,EAAE,oBAAoB,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAA;AACxE,OAAO,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAA;AAMzC,uEAAuE;AACvE,eAAO,MAAM,aAAa,EAAG,MAAe,CAAA;AAE5C,mEAAmE;AACnE,MAAM,MAAM,WAAW,GAAG,OAAO,CAAC;IAAE,SAAS,EAAE;QAAE,CAAC,aAAa,CAAC,EAAE,oBAAoB,GAAG,IAAI,CAAA;KAAE,CAAA;CAAE,CAAC,CAAA;AAElG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