@arkstack/http 0.5.2 → 0.5.3

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/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # @arkstack/http
2
2
 
3
+ [![@arkstack/http](https://img.shields.io/npm/dt/@arkstack/http?style=flat-square&label=@arkstack/http&link=https%3A%2F%2Fwww.npmjs.com%2Fpackage%2F@arkstack/http)](https://www.npmjs.com/package/@arkstack/http)
4
+
3
5
  HTTP module for Arkstack, providing framework-agnostic request and response primitives.
4
6
 
5
7
  ```ts
package/dist/app.d.ts ADDED
@@ -0,0 +1,46 @@
1
+ import type { ErrorBag } from '.'
2
+ import type { AuthSession } from '@arkstack/auth'
3
+
4
+ declare module 'clear-router' {
5
+ interface ClearHttpContext {
6
+ errors: ErrorBag
7
+ }
8
+ }
9
+
10
+
11
+ declare module 'node:http' {
12
+ interface IncomingMessage {
13
+ rawBody?: Buffer
14
+ session?: AuthSession | undefined;
15
+ }
16
+ }
17
+
18
+ declare module 'clear-router/types/h3' {
19
+ interface HttpRequest {
20
+ rawBody?: Buffer
21
+ session?: AuthSession | undefined;
22
+ }
23
+ }
24
+
25
+ declare module 'clear-router' {
26
+ interface HttpRequests {
27
+ rawBody?: Buffer
28
+ session?: AuthSession | undefined;
29
+ }
30
+ }
31
+
32
+ declare module 'h3' {
33
+ interface H3EventContext {
34
+ rawBody?: Buffer
35
+ session?: AuthSession | undefined;
36
+ }
37
+ }
38
+
39
+ declare global {
40
+ namespace Express {
41
+ interface Request {
42
+ rawBody?: Buffer
43
+ session?: AuthSession | undefined;
44
+ }
45
+ }
46
+ }
@@ -0,0 +1,520 @@
1
+ import * as _$clear_router0 from "clear-router";
2
+ import { ClearHttpContext, Request, Response } from "clear-router";
3
+ import * as _$kanun from "kanun";
4
+ import { MiddlewareClass, MiddlewareInstance, RequestData } from "clear-router/types/basic";
5
+ import { User } from "@app/models/User";
6
+
7
+ //#region src/Response.d.ts
8
+ /**
9
+ * Represents an HTTP response, providing a consistent interface for accessing response data.
10
+ *
11
+ * @author 3m1n3nc3
12
+ */
13
+ declare class Response$1<TBody = unknown> extends Response {
14
+ body: TBody;
15
+ readonly source?: unknown;
16
+ constructor(options?: {
17
+ statusCode?: number;
18
+ headers?: HeaderSource;
19
+ body?: TBody;
20
+ source?: unknown;
21
+ });
22
+ static from<TBody extends RequestData = RequestData>(source?: Response$1<TBody> | ResponseSource): Response$1<TBody> | undefined;
23
+ status(code: number): this;
24
+ header(name: string, value: string): this;
25
+ getHeaders(): HeaderMap;
26
+ json(body: TBody): any;
27
+ send(body: TBody): any;
28
+ }
29
+ //#endregion
30
+ //#region src/session/FlashBag.d.ts
31
+ declare class FlashBag<T = unknown> {
32
+ protected bag: Record<string, T>;
33
+ private sweepKeys;
34
+ constructor(items?: Record<string, T>);
35
+ put(key: string, value: T): this;
36
+ set(key: string, value: T): this;
37
+ get(key: string, defaultValue?: T): T;
38
+ has(key?: string | string[] | null): boolean;
39
+ any(): boolean;
40
+ isEmpty(): boolean;
41
+ isNotEmpty(): boolean;
42
+ keys(): string[];
43
+ all(): {
44
+ [x: string]: T;
45
+ };
46
+ clear(key?: string | string[]): this;
47
+ forget(key: string): this;
48
+ markForSweep(keys?: string[]): this;
49
+ sweep(): this;
50
+ toJSON(): {
51
+ [x: string]: T;
52
+ };
53
+ }
54
+ //#endregion
55
+ //#region src/session/types.d.ts
56
+ type SessionDriverType = 'file' | 'cookie' | 'database' | SessionDriver;
57
+ type SessionErrorValue = string | string[] | Error | unknown;
58
+ type SessionErrorRecord = Record<string, SessionErrorValue>;
59
+ interface SessionMessageProvider {
60
+ getMessageBag?: () => SessionMessageProvider;
61
+ getMessages?: () => SessionErrorRecord;
62
+ messagesRaw?: () => SessionErrorRecord;
63
+ toArray?: () => SessionErrorRecord;
64
+ all?: (...args: any[]) => SessionErrorRecord | string[];
65
+ errors?: (() => SessionErrorRecord | SessionMessageProvider) | SessionErrorRecord | SessionMessageProvider;
66
+ }
67
+ type SessionErrorSource = SessionErrorRecord | ErrorBag | SessionMessageProvider;
68
+ interface SessionInitialState {
69
+ data?: Record<string, any>;
70
+ errors?: SessionErrorSource;
71
+ flash?: Record<string, any> | FlashBag;
72
+ }
73
+ type SessionPayload = {
74
+ data?: Record<string, any>;
75
+ errors?: SessionErrorRecord;
76
+ flash?: Record<string, any>;
77
+ };
78
+ type cookie_options = {
79
+ path?: string;
80
+ domain?: string;
81
+ httpOnly?: boolean;
82
+ secure?: boolean;
83
+ sameSite?: 'Strict' | 'Lax' | 'None';
84
+ maxAge?: number;
85
+ expires?: Date;
86
+ };
87
+ type HttpContextLike = Record<string, any>;
88
+ type SessionDriverResult = {
89
+ id: string;
90
+ state?: SessionPayload;
91
+ save: (payload: SessionPayload) => void | Promise<void>;
92
+ destroy?: () => void | Promise<void>;
93
+ };
94
+ interface SessionDriver {
95
+ start(context: HttpContextLike): Promise<SessionDriverResult>;
96
+ }
97
+ type BaseSessionDriverOptions = {
98
+ cookie?: string;
99
+ secret?: string;
100
+ ttl?: number;
101
+ cookie_options?: cookie_options;
102
+ };
103
+ type DatabaseSessionDriverOptions = BaseSessionDriverOptions & {
104
+ table?: string;
105
+ };
106
+ type PersistentSessionConfig = {
107
+ driver?: SessionDriverType;
108
+ cookie?: string;
109
+ secret?: string;
110
+ ttl?: number;
111
+ cookie_options?: cookie_options;
112
+ file?: {
113
+ directory?: string;
114
+ };
115
+ database?: {
116
+ table?: string;
117
+ };
118
+ };
119
+ type SessionConfig = {
120
+ secret?: string;
121
+ driver?: SessionDriverType;
122
+ cookie?: string;
123
+ ttl?: number;
124
+ http_only?: boolean;
125
+ secure?: boolean;
126
+ same_site?: cookie_options['sameSite'];
127
+ path?: string;
128
+ table?: string;
129
+ directory?: string;
130
+ };
131
+ //#endregion
132
+ //#region src/session/ErrorBag.d.ts
133
+ declare class ErrorBag extends FlashBag<string[]> {
134
+ constructor(errors?: SessionErrorSource);
135
+ add(field: string, message: SessionErrorValue): this;
136
+ addIf(condition: boolean, field: string, message: SessionErrorValue): this;
137
+ merge(errors: SessionErrorSource): ErrorBag;
138
+ validation(error: unknown): ErrorBag;
139
+ keys(): string[];
140
+ get(field?: string): string[];
141
+ first(field?: string | null): string;
142
+ has(field?: string | string[] | null): boolean;
143
+ hasAny(fields: string | string[]): boolean;
144
+ missing(fields: string | string[]): boolean;
145
+ any(): boolean;
146
+ isEmpty(): boolean;
147
+ isNotEmpty(): boolean;
148
+ count(): number;
149
+ all(): never;
150
+ unique(): unknown[];
151
+ clear(field?: string | string[]): this;
152
+ forget(field: string): this;
153
+ messagesRaw(): Record<string, string[]>;
154
+ getMessages(): Record<string, string[]>;
155
+ getMessageBag(): this;
156
+ toArray(): Record<string, string[]>;
157
+ toJSON(): Record<string, string[]>;
158
+ }
159
+ //#endregion
160
+ //#region src/session/Session.d.ts
161
+ declare class Session {
162
+ readonly errors: ErrorBag;
163
+ readonly flashBag: FlashBag;
164
+ readonly id?: string;
165
+ private data;
166
+ private persistent?;
167
+ private saveQueue;
168
+ constructor(initial?: SessionInitialState | Record<string, any> | Session, persistent?: SessionDriverResult);
169
+ private snapshot;
170
+ private queuePersist;
171
+ save(): Promise<this>;
172
+ destroy(): Promise<this>;
173
+ /**
174
+ * Get an item from the session bag
175
+ *
176
+ * @param key
177
+ * @param defaultValue
178
+ * @returns
179
+ */
180
+ get<T = any>(key: string, defaultValue?: T): T;
181
+ /**
182
+ * Add an item to the session bag
183
+ *
184
+ * @param key
185
+ * @param defaultValue
186
+ * @returns
187
+ */
188
+ put<T = any>(key: string, value: T): this;
189
+ /**
190
+ * Add an item to the session bag
191
+ *
192
+ * @param key
193
+ * @param defaultValue
194
+ * @returns
195
+ */
196
+ set<T = any>(key: string, value: T): this;
197
+ /**
198
+ * Check if an item exist in the session bag
199
+ *
200
+ * @param key
201
+ * @returns
202
+ */
203
+ has(key: string): boolean;
204
+ /**
205
+ * Remove an item from the session bag
206
+ *
207
+ * @param key
208
+ * @returns
209
+ */
210
+ forget(key: string): this;
211
+ /**
212
+ * Clear the session bag
213
+ *
214
+ * @returns
215
+ */
216
+ clear(): this;
217
+ /**
218
+ * Get all items in the session bag
219
+ *
220
+ * @returns
221
+ */
222
+ all(): {
223
+ [x: string]: any;
224
+ };
225
+ /**
226
+ * Add a flash item for the next request
227
+ *
228
+ * @param key
229
+ * @param value
230
+ * @returns
231
+ */
232
+ flash<T = any>(key: string, value: T): this;
233
+ /**
234
+ * Get a flash item
235
+ *
236
+ * @param key
237
+ * @param defaultValue
238
+ * @returns
239
+ */
240
+ getFlash<T = any>(key: string, defaultValue?: T): T;
241
+ /**
242
+ * Sweep flashed data that was loaded for this request
243
+ *
244
+ * @returns
245
+ */
246
+ sweepFlash(): Promise<this>;
247
+ /**
248
+ * Add an error to the session error bag
249
+ *
250
+ * @param field
251
+ * @param message
252
+ * @returns
253
+ */
254
+ addError(field: string, message: SessionErrorValue): this;
255
+ /**
256
+ * Add multiple errors to the session error bag
257
+ *
258
+ * @param errors
259
+ * @returns
260
+ */
261
+ addErrors(errors: SessionErrorRecord | ErrorBag): this;
262
+ /**
263
+ * Add a validation error to the session error bag
264
+ *
265
+ * @param error
266
+ * @returns
267
+ */
268
+ addValidationErrors(error: unknown): this;
269
+ /**
270
+ * Check if the session error bag has any errors
271
+ *
272
+ * @param field
273
+ * @returns
274
+ */
275
+ hasErrors(field?: string): boolean;
276
+ /**
277
+ * Clear all errors in the session error bag
278
+ *
279
+ * @param field
280
+ * @returns
281
+ */
282
+ clearErrors(field?: string): this;
283
+ /**
284
+ * Parse session for views
285
+ *
286
+ * @returns
287
+ */
288
+ forView(): {
289
+ errors: ErrorBag;
290
+ flash: FlashBag<unknown>;
291
+ };
292
+ /**
293
+ * Return session as json
294
+ *
295
+ * @returns
296
+ */
297
+ toJSON(): {
298
+ errors: Record<string, string[]>;
299
+ flash: {
300
+ [x: string]: unknown;
301
+ };
302
+ };
303
+ }
304
+ //#endregion
305
+ //#region src/plugins.d.ts
306
+ declare const arkstackHttpPlugin: _$clear_router0.ClearRouterPlugin<any, ClearHttpContext>;
307
+ declare const kanunSessionPlugin: _$kanun.ValidatorPlugin;
308
+ //#endregion
309
+ //#region src/session/helpers.d.ts
310
+ declare const registerResponseFlashSweep: (target: unknown, session?: Session) => void;
311
+ declare const attachViewState: (target: Record<PropertyKey, any>, session: Session) => void;
312
+ /**
313
+ * Ensure a valid session exists
314
+ *
315
+ * @param ctx
316
+ * @param initial
317
+ * @returns
318
+ */
319
+ declare const ensureSession: (ctx: unknown, initial?: SessionInitialState | Record<string, any>, persistent?: SessionDriverResult) => Session;
320
+ /**
321
+ * Get the current session
322
+ *
323
+ * @param ctx
324
+ * @returns
325
+ */
326
+ declare const getSession: (ctx: unknown) => Session | undefined;
327
+ //#endregion
328
+ //#region src/session/config.d.ts
329
+ declare const createSessionDriver: (config?: PersistentSessionConfig) => SessionDriver;
330
+ declare const configureSession: (config: PersistentSessionConfig | SessionDriver) => SessionDriver;
331
+ declare const getSessionDriver: () => SessionDriver;
332
+ //#endregion
333
+ //#region src/session/cookie.d.ts
334
+ declare const generateSessionId: () => string;
335
+ declare const signValue: (value: string, secret: string) => string;
336
+ declare const encodeSignedValue: (value: string, secret: string) => string;
337
+ declare const decodeSignedValue: (value: string | undefined, secret: string) => string | undefined;
338
+ declare const encodeJson: (value: unknown) => string;
339
+ declare const decodeJson: <T = unknown>(value: string | undefined) => T | undefined;
340
+ declare const parseCookies: (header?: string | string[] | null) => Record<string, string>;
341
+ declare const getCookie: (context: HttpContextLike, name: string) => string;
342
+ declare const serializeCookie: (name: string, value: string, options?: cookie_options) => string;
343
+ declare const setCookie: (context: HttpContextLike, name: string, value: string, options?: cookie_options) => string;
344
+ //#endregion
345
+ //#region src/session/encryption.d.ts
346
+ declare const encryptSessionValue: (value: string, secret: string) => string;
347
+ declare const decryptSessionValue: (payload: string | undefined, secret: string) => string | undefined;
348
+ //#endregion
349
+ //#region src/session/serialization.d.ts
350
+ declare const encodeSessionPayload: (payload: SessionPayload & {
351
+ id?: string;
352
+ }) => string;
353
+ declare const decodeSessionPayload: <T extends SessionPayload & {
354
+ id?: string;
355
+ } = SessionPayload & {
356
+ id?: string;
357
+ }>(value: string | undefined) => T | undefined;
358
+ //#endregion
359
+ //#region src/session/drivers/BaseSessionDriver.d.ts
360
+ declare abstract class BaseSessionDriver implements SessionDriver {
361
+ readonly cookie: string;
362
+ readonly secret: string;
363
+ readonly ttl?: number;
364
+ readonly cookie_options: cookie_options;
365
+ constructor(options?: BaseSessionDriverOptions);
366
+ protected readSessionId(context: HttpContextLike): string | undefined;
367
+ protected encryptPayload(value: string): string;
368
+ protected decryptPayload(value: string | undefined): string | undefined;
369
+ protected writeSessionId(context: HttpContextLike, id: string): void;
370
+ abstract start(context: HttpContextLike): Promise<SessionDriverResult>;
371
+ }
372
+ //#endregion
373
+ //#region src/session/drivers/CookieSessionDriver.d.ts
374
+ declare class CookieSessionDriver extends BaseSessionDriver {
375
+ start(context: HttpContextLike): Promise<SessionDriverResult>;
376
+ }
377
+ //#endregion
378
+ //#region src/session/drivers/DatabaseSessionDriver.d.ts
379
+ declare class DatabaseSessionDriver extends BaseSessionDriver {
380
+ readonly tableName: string;
381
+ constructor(options?: DatabaseSessionDriverOptions);
382
+ private table;
383
+ start(context: HttpContextLike): Promise<SessionDriverResult>;
384
+ }
385
+ //#endregion
386
+ //#region src/session/drivers/FileSessionDriver.d.ts
387
+ declare class FileSessionDriver extends BaseSessionDriver {
388
+ readonly directory: string;
389
+ constructor(options?: BaseSessionDriverOptions & {
390
+ directory?: string;
391
+ });
392
+ private path;
393
+ start(context: HttpContextLike): Promise<SessionDriverResult>;
394
+ }
395
+ //#endregion
396
+ //#region src/types/Http.d.ts
397
+ type HeaderValue = string | string[] | number | boolean | null | undefined;
398
+ type HeaderMap = Record<string, string>;
399
+ type HeaderSource = Headers | Record<string, HeaderValue>;
400
+ type FunctionMiddleware = (...args: any[]) => any;
401
+ type ClassMiddleware = new (...args: any[]) => {
402
+ handle: FunctionMiddleware;
403
+ };
404
+ type RequestSource<TUser = unknown> = {
405
+ headers?: HeaderSource;
406
+ method?: string;
407
+ url?: string;
408
+ originalUrl?: string;
409
+ path?: string;
410
+ ip?: string;
411
+ user?: TUser;
412
+ auth?: unknown;
413
+ authUser?: TUser;
414
+ authToken?: string;
415
+ req?: RequestSource<TUser>;
416
+ request?: RequestSource<TUser>;
417
+ original?: RequestSource<TUser>;
418
+ };
419
+ type ResponseSource = {
420
+ statusCode?: number;
421
+ status?: number | ((code: number) => unknown);
422
+ headers?: HeaderSource;
423
+ setHeader?: (name: string, value: string | string[]) => unknown;
424
+ getHeader?: (name: string) => string | string[] | number | undefined;
425
+ json?: (body: unknown) => unknown;
426
+ send?: (body: unknown) => unknown;
427
+ redirect?: (status: number, path: string) => unknown;
428
+ };
429
+ type RequestOptions<TUser = unknown> = {
430
+ headers?: HeaderSource;
431
+ method?: string;
432
+ url?: string;
433
+ path?: string;
434
+ ip?: string | null;
435
+ user?: TUser;
436
+ auth?: unknown;
437
+ authUser?: TUser;
438
+ authToken?: string;
439
+ source?: unknown;
440
+ original?: unknown;
441
+ };
442
+ interface RequestHelper<TUser = unknown> {
443
+ (): Request$1;
444
+ <X extends string>(key: X): Request$1<TUser>['body'][X];
445
+ }
446
+ interface SessionHelper {
447
+ (): Session;
448
+ <X extends string>(key: X): any;
449
+ }
450
+ interface RedirectHelper {
451
+ (): Response$1;
452
+ (to?: string, status?: number): Response$1;
453
+ }
454
+ interface OldHelper {
455
+ (): Record<string, any>;
456
+ <T = any>(key: string, defaultValue?: T): T;
457
+ }
458
+ //#endregion
459
+ //#region src/Request.d.ts
460
+ /**
461
+ * Represents an HTTP request, providing a consistent interface for accessing request data.
462
+ *
463
+ * @author 3m1n3nc3
464
+ */
465
+ declare class Request$1<TUser = User> extends Request {
466
+ readonly headers: HeaderMap;
467
+ readonly ip: string | null;
468
+ readonly source?: unknown;
469
+ private currentUser?;
470
+ private currentAuth?;
471
+ private currentAuthUser?;
472
+ private currentAuthToken?;
473
+ get user(): TUser | undefined;
474
+ set user(user: TUser | undefined);
475
+ get auth(): unknown;
476
+ set auth(auth: unknown);
477
+ get authUser(): TUser | undefined;
478
+ set authUser(user: TUser | undefined);
479
+ get authToken(): string | undefined;
480
+ set authToken(token: string | undefined);
481
+ constructor(options?: RequestOptions<TUser>);
482
+ static from<TUser = unknown>(source?: Request$1<TUser> | RequestSource<TUser>): Request$1<TUser> | undefined;
483
+ header(name: string): string;
484
+ bearerToken(): string | null;
485
+ setUser(user: TUser): this;
486
+ setAuthentication<TAuth>(auth: TAuth, user: TUser, token?: string): this;
487
+ syncFromSource(): this;
488
+ private getSourceRequest;
489
+ clearAuthentication(): this;
490
+ }
491
+ //#endregion
492
+ //#region src/helpers.d.ts
493
+ declare const unwrapRequestSource: <TUser>(source: RequestSource<TUser>) => RequestSource<TUser>;
494
+ declare const makeHeaders: (headers?: HeaderSource) => Headers;
495
+ declare const normalizeHeaders: (headers?: HeaderSource) => HeaderMap;
496
+ declare const normalizeHeaderValue: (value: HeaderValue) => string | undefined;
497
+ declare const isHeaders: (value: unknown) => value is Headers;
498
+ declare const isRecord: (value: unknown) => value is Record<PropertyKey, any>;
499
+ /**
500
+ * Resolve Middleware
501
+ *
502
+ * @param middleware
503
+ * @returns
504
+ */
505
+ declare const resolveMiddleware: <T extends FunctionMiddleware | MiddlewareClass | MiddlewareInstance>(middleware: T) => T extends MiddlewareClass<FunctionMiddleware> ? InstanceType<T>["handle"] : T extends MiddlewareInstance ? T["handle"] : T;
506
+ //#endregion
507
+ //#region src/redirect.d.ts
508
+ declare const redirectBackTarget: (fallback?: string) => string;
509
+ declare const resolveRedirectTarget: (to?: string, fallback?: string) => string;
510
+ declare const redirect: (to?: string, status?: number) => Response$1<unknown>;
511
+ //#endregion
512
+ //#region src/old.d.ts
513
+ declare const old: <T = any>(key?: string, defaultValue?: T) => T;
514
+ //#endregion
515
+ //#region src/middlewares/web.d.ts
516
+ declare const webMiddlewareKey: unique symbol;
517
+ declare const web: (...args: any[]) => Promise<any>;
518
+ declare const isWebRequest: (target: unknown) => boolean;
519
+ //#endregion
520
+ export { arkstackHttpPlugin as $, CookieSessionDriver as A, generateSessionId as B, RequestHelper as C, SessionHelper as D, ResponseSource as E, encryptSessionValue as F, signValue as G, parseCookies as H, decodeJson as I, getSessionDriver as J, configureSession as K, decodeSignedValue as L, decodeSessionPayload as M, encodeSessionPayload as N, FileSessionDriver as O, decryptSessionValue as P, registerResponseFlashSweep as Q, encodeJson as R, RedirectHelper as S, RequestSource as T, serializeCookie as U, getCookie as V, setCookie as W, ensureSession as X, attachViewState as Y, getSession as Z, FunctionMiddleware as _, cookie_options as _t, redirect as a, HttpContextLike as at, HeaderValue as b, isHeaders as c, SessionDriver as ct, normalizeHeaderValue as d, SessionErrorRecord as dt, kanunSessionPlugin as et, normalizeHeaders as f, SessionErrorSource as ft, ClassMiddleware as g, SessionPayload as gt, Request$1 as h, SessionMessageProvider as ht, old as i, DatabaseSessionDriverOptions as it, BaseSessionDriver as j, DatabaseSessionDriver as k, isRecord as l, SessionDriverResult as lt, unwrapRequestSource as m, SessionInitialState as mt, web as n, ErrorBag as nt, redirectBackTarget as o, PersistentSessionConfig as ot, resolveMiddleware as p, SessionErrorValue as pt, createSessionDriver as q, webMiddlewareKey as r, BaseSessionDriverOptions as rt, resolveRedirectTarget as s, SessionConfig as st, isWebRequest as t, Session as tt, makeHeaders as u, SessionDriverType as ut, HeaderMap as v, FlashBag as vt, RequestOptions as w, OldHelper as x, HeaderSource as y, Response$1 as yt, encodeSignedValue as z };
package/dist/index.d.ts CHANGED
@@ -1,80 +1,3 @@
1
- import { Request as Request$1, Response as Response$1 } from "clear-router";
2
- import { RequestData } from "clear-router/types/basic";
3
-
4
- //#region src/types/Http.d.ts
5
- type HeaderValue = string | string[] | number | boolean | null | undefined;
6
- type HeaderMap = Record<string, string>;
7
- type HeaderSource = Headers | Record<string, HeaderValue>;
8
- type RequestSource<TUser = unknown> = {
9
- headers?: HeaderSource;
10
- method?: string;
11
- url?: string;
12
- originalUrl?: string;
13
- path?: string;
14
- ip?: string;
15
- user?: TUser;
16
- authToken?: string;
17
- req?: RequestSource<TUser>;
18
- request?: RequestSource<TUser>;
19
- };
20
- type ResponseSource = {
21
- statusCode?: number;
22
- status?: number | ((code: number) => unknown);
23
- headers?: HeaderSource;
24
- setHeader?: (name: string, value: string) => unknown;
25
- json?: (body: unknown) => unknown;
26
- send?: (body: unknown) => unknown;
27
- };
28
- type RequestOptions<TUser = unknown> = {
29
- headers?: HeaderSource;
30
- method?: string;
31
- url?: string;
32
- path?: string;
33
- ip?: string | null;
34
- user?: TUser;
35
- authToken?: string;
36
- source?: unknown;
37
- };
38
- //#endregion
39
- //#region src/Request.d.ts
40
- declare class Request<TUser = unknown> extends Request$1 {
41
- readonly headers: HeaderMap;
42
- readonly ip: string | null;
43
- readonly source?: unknown;
44
- user?: TUser;
45
- authToken?: string;
46
- constructor(options?: RequestOptions<TUser>);
47
- static from<TUser = unknown>(source?: Request<TUser> | RequestSource<TUser>): Request<TUser> | undefined;
48
- header(name: string): string;
49
- bearerToken(): string | null;
50
- setUser(user: TUser): this;
51
- }
52
- //#endregion
53
- //#region src/Response.d.ts
54
- declare class Response<TBody = unknown> extends Response$1 {
55
- body: TBody;
56
- readonly source?: unknown;
57
- constructor(options?: {
58
- statusCode?: number;
59
- headers?: HeaderSource;
60
- body?: TBody;
61
- source?: unknown;
62
- });
63
- static from<TBody extends RequestData = RequestData>(source?: Response<TBody> | ResponseSource): Response<TBody> | undefined;
64
- status(code: number): this;
65
- header(name: string, value: string): this;
66
- getHeaders(): HeaderMap;
67
- json(body: TBody): any;
68
- send(body: TBody): any;
69
- }
70
- //#endregion
71
- //#region src/helpers.d.ts
72
- declare const unwrapRequestSource: <TUser>(source: RequestSource<TUser>) => RequestSource<TUser>;
73
- declare const makeHeaders: (headers?: HeaderSource) => Headers;
74
- declare const normalizeHeaders: (headers?: HeaderSource) => HeaderMap;
75
- declare const normalizeHeaderValue: (value: HeaderValue) => string | undefined;
76
- declare const isHeaders: (value: unknown) => value is Headers;
77
- declare const isRecord: (value: unknown) => value is Record<string, any>;
78
- //#endregion
79
- export { HeaderMap, HeaderSource, HeaderValue, Request, RequestOptions, RequestSource, Response, ResponseSource, isHeaders, isRecord, makeHeaders, normalizeHeaderValue, normalizeHeaders, unwrapRequestSource };
80
- //# sourceMappingURL=index.d.ts.map
1
+ /// <reference path="./app.d.ts" />
2
+ import { $ as arkstackHttpPlugin, A as CookieSessionDriver, B as generateSessionId, C as RequestHelper, D as SessionHelper, E as ResponseSource, F as encryptSessionValue, G as signValue, H as parseCookies, I as decodeJson, J as getSessionDriver, K as configureSession, L as decodeSignedValue, M as decodeSessionPayload, N as encodeSessionPayload, O as FileSessionDriver, P as decryptSessionValue, Q as registerResponseFlashSweep, R as encodeJson, S as RedirectHelper, T as RequestSource, U as serializeCookie, V as getCookie, W as setCookie, X as ensureSession, Y as attachViewState, Z as getSession, _ as FunctionMiddleware, _t as cookie_options, a as redirect, at as HttpContextLike, b as HeaderValue, c as isHeaders, ct as SessionDriver, d as normalizeHeaderValue, dt as SessionErrorRecord, et as kanunSessionPlugin, f as normalizeHeaders, ft as SessionErrorSource, g as ClassMiddleware, gt as SessionPayload, h as Request, ht as SessionMessageProvider, i as old, it as DatabaseSessionDriverOptions, j as BaseSessionDriver, k as DatabaseSessionDriver, l as isRecord, lt as SessionDriverResult, m as unwrapRequestSource, mt as SessionInitialState, n as web, nt as ErrorBag, o as redirectBackTarget, ot as PersistentSessionConfig, p as resolveMiddleware, pt as SessionErrorValue, q as createSessionDriver, r as webMiddlewareKey, rt as BaseSessionDriverOptions, s as resolveRedirectTarget, st as SessionConfig, t as isWebRequest, tt as Session, u as makeHeaders, ut as SessionDriverType, v as HeaderMap, vt as FlashBag, w as RequestOptions, x as OldHelper, y as HeaderSource, yt as Response, z as encodeSignedValue } from "./index-C-YhZgaG.js";
3
+ export { BaseSessionDriver, BaseSessionDriverOptions, ClassMiddleware, CookieSessionDriver, DatabaseSessionDriver, DatabaseSessionDriverOptions, ErrorBag, FileSessionDriver, FlashBag, FunctionMiddleware, HeaderMap, HeaderSource, HeaderValue, HttpContextLike, OldHelper, PersistentSessionConfig, RedirectHelper, Request, RequestHelper, RequestOptions, RequestSource, Response, ResponseSource, Session, SessionConfig, SessionDriver, SessionDriverResult, SessionDriverType, SessionErrorRecord, SessionErrorSource, SessionErrorValue, SessionHelper, SessionInitialState, SessionMessageProvider, SessionPayload, arkstackHttpPlugin, attachViewState, configureSession, cookie_options, createSessionDriver, decodeJson, decodeSessionPayload, decodeSignedValue, decryptSessionValue, encodeJson, encodeSessionPayload, encodeSignedValue, encryptSessionValue, ensureSession, generateSessionId, getCookie, getSession, getSessionDriver, isHeaders, isRecord, isWebRequest, kanunSessionPlugin, makeHeaders, normalizeHeaderValue, normalizeHeaders, old, parseCookies, redirect, redirectBackTarget, registerResponseFlashSweep, resolveMiddleware, resolveRedirectTarget, serializeCookie, setCookie, signValue, unwrapRequestSource, web, webMiddlewareKey };