@arkstack/http 0.12.19 → 0.12.21
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.
|
@@ -2,6 +2,7 @@ import * as _$clear_router0 from "clear-router";
|
|
|
2
2
|
import { ClearHttpContext, Request, Response } from "clear-router";
|
|
3
3
|
import * as _$kanun from "kanun";
|
|
4
4
|
import { MiddlewareClass, MiddlewareInstance, RequestData } from "clear-router/types/basic";
|
|
5
|
+
import { User } from "@app/models/User";
|
|
5
6
|
|
|
6
7
|
//#region src/Response.d.ts
|
|
7
8
|
/**
|
|
@@ -301,7 +302,7 @@ declare class Session {
|
|
|
301
302
|
};
|
|
302
303
|
}
|
|
303
304
|
//#endregion
|
|
304
|
-
//#region src/
|
|
305
|
+
//#region src/plugins.d.ts
|
|
305
306
|
declare const arkstackHttpPlugin: _$clear_router0.ClearRouterPlugin<any, ClearHttpContext>;
|
|
306
307
|
declare const kanunSessionPlugin: _$kanun.ValidatorPlugin;
|
|
307
308
|
//#endregion
|
|
@@ -408,9 +409,12 @@ type RequestSource<TUser = unknown> = {
|
|
|
408
409
|
path?: string;
|
|
409
410
|
ip?: string;
|
|
410
411
|
user?: TUser;
|
|
412
|
+
auth?: unknown;
|
|
413
|
+
authUser?: TUser;
|
|
411
414
|
authToken?: string;
|
|
412
415
|
req?: RequestSource<TUser>;
|
|
413
416
|
request?: RequestSource<TUser>;
|
|
417
|
+
original?: RequestSource<TUser>;
|
|
414
418
|
};
|
|
415
419
|
type ResponseSource = {
|
|
416
420
|
statusCode?: number;
|
|
@@ -429,8 +433,11 @@ type RequestOptions<TUser = unknown> = {
|
|
|
429
433
|
path?: string;
|
|
430
434
|
ip?: string | null;
|
|
431
435
|
user?: TUser;
|
|
436
|
+
auth?: unknown;
|
|
437
|
+
authUser?: TUser;
|
|
432
438
|
authToken?: string;
|
|
433
439
|
source?: unknown;
|
|
440
|
+
original?: unknown;
|
|
434
441
|
};
|
|
435
442
|
interface RequestHelper<TUser = unknown> {
|
|
436
443
|
(): Request$1;
|
|
@@ -455,17 +462,31 @@ interface OldHelper {
|
|
|
455
462
|
*
|
|
456
463
|
* @author 3m1n3nc3
|
|
457
464
|
*/
|
|
458
|
-
declare class Request$1<TUser =
|
|
465
|
+
declare class Request$1<TUser = User> extends Request {
|
|
459
466
|
readonly headers: HeaderMap;
|
|
460
467
|
readonly ip: string | null;
|
|
461
468
|
readonly source?: unknown;
|
|
462
|
-
|
|
463
|
-
|
|
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);
|
|
464
481
|
constructor(options?: RequestOptions<TUser>);
|
|
465
482
|
static from<TUser = unknown>(source?: Request$1<TUser> | RequestSource<TUser>): Request$1<TUser> | undefined;
|
|
466
483
|
header(name: string): string;
|
|
467
484
|
bearerToken(): string | null;
|
|
468
485
|
setUser(user: TUser): this;
|
|
486
|
+
setAuthentication<TAuth>(auth: TAuth, user: TUser, token?: string): this;
|
|
487
|
+
syncFromSource(): this;
|
|
488
|
+
private getSourceRequest;
|
|
489
|
+
clearAuthentication(): this;
|
|
469
490
|
}
|
|
470
491
|
//#endregion
|
|
471
492
|
//#region src/helpers.d.ts
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
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-
|
|
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
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 };
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { A as registerResponseFlashSweep, B as normalizeHeaderValue, C as parseCookies, D as attachViewState, E as signValue, F as Response, H as resolveMiddleware, I as Request, L as isHeaders, M as Session, N as ErrorBag, O as ensureSession, P as FlashBag, R as isRecord, S as getCookie, T as setCookie, U as unwrapRequestSource, V as normalizeHeaders, _ as decodeJson, a as kanunSessionPlugin, b as encodeSignedValue, c as getSessionDriver, d as CookieSessionDriver, f as BaseSessionDriver, g as encodeSessionPayload, h as decodeSessionPayload, i as arkstackHttpPlugin, j as old, k as getSession, l as FileSessionDriver, m as encryptSessionValue, n as redirectBackTarget, o as configureSession, p as decryptSessionValue, r as resolveRedirectTarget, s as createSessionDriver, t as redirect, u as DatabaseSessionDriver, v as decodeSignedValue, w as serializeCookie, x as generateSessionId, y as encodeJson, z as makeHeaders } from "./redirect-
|
|
1
|
+
import { A as registerResponseFlashSweep, B as normalizeHeaderValue, C as parseCookies, D as attachViewState, E as signValue, F as Response, H as resolveMiddleware, I as Request, L as isHeaders, M as Session, N as ErrorBag, O as ensureSession, P as FlashBag, R as isRecord, S as getCookie, T as setCookie, U as unwrapRequestSource, V as normalizeHeaders, _ as decodeJson, a as kanunSessionPlugin, b as encodeSignedValue, c as getSessionDriver, d as CookieSessionDriver, f as BaseSessionDriver, g as encodeSessionPayload, h as decodeSessionPayload, i as arkstackHttpPlugin, j as old, k as getSession, l as FileSessionDriver, m as encryptSessionValue, n as redirectBackTarget, o as configureSession, p as decryptSessionValue, r as resolveRedirectTarget, s as createSessionDriver, t as redirect, u as DatabaseSessionDriver, v as decodeSignedValue, w as serializeCookie, x as generateSessionId, y as encodeJson, z as makeHeaders } from "./redirect-CFGcSkzk.js";
|
|
2
2
|
//#region src/middlewares/web.ts
|
|
3
3
|
const webMiddlewareKey = Symbol.for("arkstack:http:web");
|
|
4
4
|
const markWebRequest = (target) => {
|
|
@@ -9,6 +9,7 @@ import { mkdir, readFile, rm, writeFile } from "node:fs/promises";
|
|
|
9
9
|
import { Arkstack } from "@arkstack/contract";
|
|
10
10
|
//#region src/helpers.ts
|
|
11
11
|
const unwrapRequestSource = (source) => {
|
|
12
|
+
if (source.original) return unwrapRequestSource(source.original);
|
|
12
13
|
if (source.headers) return source;
|
|
13
14
|
if (source.req) return source.req;
|
|
14
15
|
if (source.request) return source.request;
|
|
@@ -65,18 +66,48 @@ var Request$1 = class Request$1 extends Request {
|
|
|
65
66
|
headers;
|
|
66
67
|
ip;
|
|
67
68
|
source;
|
|
68
|
-
|
|
69
|
-
|
|
69
|
+
currentUser;
|
|
70
|
+
currentAuth;
|
|
71
|
+
currentAuthUser;
|
|
72
|
+
currentAuthToken;
|
|
73
|
+
get user() {
|
|
74
|
+
return this.getSourceRequest()?.user ?? this.currentUser;
|
|
75
|
+
}
|
|
76
|
+
set user(user) {
|
|
77
|
+
this.currentUser = user;
|
|
78
|
+
}
|
|
79
|
+
get auth() {
|
|
80
|
+
return this.getSourceRequest()?.auth ?? this.currentAuth;
|
|
81
|
+
}
|
|
82
|
+
set auth(auth) {
|
|
83
|
+
this.currentAuth = auth;
|
|
84
|
+
}
|
|
85
|
+
get authUser() {
|
|
86
|
+
return this.getSourceRequest()?.authUser ?? this.currentAuthUser;
|
|
87
|
+
}
|
|
88
|
+
set authUser(user) {
|
|
89
|
+
this.currentAuthUser = user;
|
|
90
|
+
}
|
|
91
|
+
get authToken() {
|
|
92
|
+
return this.getSourceRequest()?.authToken ?? this.currentAuthToken;
|
|
93
|
+
}
|
|
94
|
+
set authToken(token) {
|
|
95
|
+
this.currentAuthToken = token;
|
|
96
|
+
}
|
|
70
97
|
constructor(options = {}) {
|
|
71
98
|
super(options);
|
|
99
|
+
const source = options.source ?? options.original;
|
|
100
|
+
const sourceRequest = isRecord(source) ? source : void 0;
|
|
72
101
|
this.headers = normalizeHeaders(options.headers);
|
|
73
102
|
if (this.method) this.method = options.method;
|
|
74
103
|
if (this.url) this.url = options.url;
|
|
75
104
|
if (this.path) this.path = options.path;
|
|
76
|
-
this.ip = options.ip ?? null;
|
|
77
|
-
this.user = options.user;
|
|
78
|
-
this.
|
|
79
|
-
this.
|
|
105
|
+
this.ip = options.ip ?? sourceRequest?.ip ?? null;
|
|
106
|
+
this.user = options.user ?? sourceRequest?.user;
|
|
107
|
+
this.auth = options.auth ?? sourceRequest?.auth;
|
|
108
|
+
this.authUser = options.authUser ?? sourceRequest?.authUser;
|
|
109
|
+
this.authToken = options.authToken ?? sourceRequest?.authToken;
|
|
110
|
+
this.source = source;
|
|
80
111
|
globalThis.request = (key) => key ? this.input(key) : this;
|
|
81
112
|
}
|
|
82
113
|
static from(source) {
|
|
@@ -90,8 +121,10 @@ var Request$1 = class Request$1 extends Request {
|
|
|
90
121
|
path: request.path,
|
|
91
122
|
ip: request.ip ?? null,
|
|
92
123
|
user: request.user,
|
|
124
|
+
auth: request.auth,
|
|
125
|
+
authUser: request.authUser,
|
|
93
126
|
authToken: request.authToken,
|
|
94
|
-
source
|
|
127
|
+
source: request
|
|
95
128
|
});
|
|
96
129
|
}
|
|
97
130
|
header(name) {
|
|
@@ -107,6 +140,43 @@ var Request$1 = class Request$1 extends Request {
|
|
|
107
140
|
if (isRecord(this.source)) this.source.user = user;
|
|
108
141
|
return this;
|
|
109
142
|
}
|
|
143
|
+
setAuthentication(auth, user, token) {
|
|
144
|
+
this.auth = auth;
|
|
145
|
+
this.authUser = user;
|
|
146
|
+
this.authToken = token;
|
|
147
|
+
this.setUser(user);
|
|
148
|
+
if (isRecord(this.source)) {
|
|
149
|
+
this.source.auth = auth;
|
|
150
|
+
this.source.authUser = user;
|
|
151
|
+
this.source.authToken = token;
|
|
152
|
+
}
|
|
153
|
+
return this;
|
|
154
|
+
}
|
|
155
|
+
syncFromSource() {
|
|
156
|
+
if (!isRecord(this.source)) return this;
|
|
157
|
+
const source = this.source;
|
|
158
|
+
this.user = source.user ?? this.user;
|
|
159
|
+
this.auth = source.auth ?? this.auth;
|
|
160
|
+
this.authUser = source.authUser ?? this.authUser;
|
|
161
|
+
this.authToken = source.authToken ?? this.authToken;
|
|
162
|
+
return this;
|
|
163
|
+
}
|
|
164
|
+
getSourceRequest() {
|
|
165
|
+
return isRecord(this.source) ? this.source : void 0;
|
|
166
|
+
}
|
|
167
|
+
clearAuthentication() {
|
|
168
|
+
this.auth = void 0;
|
|
169
|
+
this.authUser = void 0;
|
|
170
|
+
this.authToken = void 0;
|
|
171
|
+
this.user = void 0;
|
|
172
|
+
if (isRecord(this.source)) {
|
|
173
|
+
this.source.auth = void 0;
|
|
174
|
+
this.source.authUser = void 0;
|
|
175
|
+
this.source.authToken = void 0;
|
|
176
|
+
this.source.user = void 0;
|
|
177
|
+
}
|
|
178
|
+
return this;
|
|
179
|
+
}
|
|
110
180
|
};
|
|
111
181
|
//#endregion
|
|
112
182
|
//#region src/Response.ts
|
|
@@ -1200,7 +1270,7 @@ const getSessionDriver = () => {
|
|
|
1200
1270
|
return configuredDriver;
|
|
1201
1271
|
};
|
|
1202
1272
|
//#endregion
|
|
1203
|
-
//#region src/
|
|
1273
|
+
//#region src/plugins.ts
|
|
1204
1274
|
const arkstackHttpPlugin = definePlugin({
|
|
1205
1275
|
name: "arkstack-http",
|
|
1206
1276
|
setup: ({ bind, useHttpContext }) => {
|
|
@@ -1213,6 +1283,9 @@ const arkstackHttpPlugin = definePlugin({
|
|
|
1213
1283
|
registerResponseFlashSweep(ctx, session);
|
|
1214
1284
|
return session;
|
|
1215
1285
|
});
|
|
1286
|
+
bind(Request$1, ({ request, ctx }) => {
|
|
1287
|
+
return (request instanceof Request$1 ? request : Request$1.from(request ?? ctx)).syncFromSource();
|
|
1288
|
+
});
|
|
1216
1289
|
useHttpContext((context) => {
|
|
1217
1290
|
const session = getSession(context.ctx);
|
|
1218
1291
|
if (session) {
|
package/dist/setup.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { C as RequestHelper, D as SessionHelper, S as RedirectHelper, x as OldHelper, yt as Response } from "./index-
|
|
1
|
+
import { C as RequestHelper, D as SessionHelper, S as RedirectHelper, x as OldHelper, yt as Response } from "./index-C-YhZgaG.js";
|
|
2
2
|
//#region src/setup.d.ts
|
|
3
3
|
declare global {
|
|
4
4
|
var session: SessionHelper;
|
package/dist/setup.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { F as Response$1, I as Request$1, a as kanunSessionPlugin, i as arkstackHttpPlugin, j as old, t as redirect } from "./redirect-
|
|
1
|
+
import { F as Response$1, I as Request$1, a as kanunSessionPlugin, i as arkstackHttpPlugin, j as old, t as redirect } from "./redirect-CFGcSkzk.js";
|
|
2
2
|
import { CoreRouter } from "clear-router";
|
|
3
3
|
import { Validator } from "kanun";
|
|
4
4
|
import "dotenv/config";
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@arkstack/http",
|
|
3
|
-
"version": "0.12.
|
|
3
|
+
"version": "0.12.21",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "HTTP module for Arkstack, providing framework-agnostic request and response primitives.",
|
|
6
6
|
"homepage": "https://arkstack.toneflix.net/guide/http",
|
|
7
7
|
"repository": {
|
|
8
8
|
"type": "git",
|
|
9
|
-
"url": "git+https://github.com/arkstack-
|
|
9
|
+
"url": "git+https://github.com/arkstack-hq/arkstack.git",
|
|
10
10
|
"directory": "packages/http"
|
|
11
11
|
},
|
|
12
12
|
"keywords": [
|
|
@@ -30,11 +30,11 @@
|
|
|
30
30
|
"dependencies": {
|
|
31
31
|
"clear-router": "^2.8.6",
|
|
32
32
|
"dotenv": "17.3.1",
|
|
33
|
-
"@arkstack/contract": "^0.12.
|
|
34
|
-
"@arkstack/common": "^0.12.
|
|
33
|
+
"@arkstack/contract": "^0.12.21",
|
|
34
|
+
"@arkstack/common": "^0.12.21"
|
|
35
35
|
},
|
|
36
36
|
"peerDependencies": {
|
|
37
|
-
"arkormx": "^2.
|
|
37
|
+
"arkormx": "^2.5.6",
|
|
38
38
|
"kanun": "^1.2.0"
|
|
39
39
|
},
|
|
40
40
|
"scripts": {
|