@arkstack/http 0.12.18 → 0.12.20
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.
|
@@ -301,7 +301,7 @@ declare class Session {
|
|
|
301
301
|
};
|
|
302
302
|
}
|
|
303
303
|
//#endregion
|
|
304
|
-
//#region src/
|
|
304
|
+
//#region src/plugins.d.ts
|
|
305
305
|
declare const arkstackHttpPlugin: _$clear_router0.ClearRouterPlugin<any, ClearHttpContext>;
|
|
306
306
|
declare const kanunSessionPlugin: _$kanun.ValidatorPlugin;
|
|
307
307
|
//#endregion
|
|
@@ -408,6 +408,8 @@ type RequestSource<TUser = unknown> = {
|
|
|
408
408
|
path?: string;
|
|
409
409
|
ip?: string;
|
|
410
410
|
user?: TUser;
|
|
411
|
+
auth?: unknown;
|
|
412
|
+
authUser?: TUser;
|
|
411
413
|
authToken?: string;
|
|
412
414
|
req?: RequestSource<TUser>;
|
|
413
415
|
request?: RequestSource<TUser>;
|
|
@@ -429,6 +431,8 @@ type RequestOptions<TUser = unknown> = {
|
|
|
429
431
|
path?: string;
|
|
430
432
|
ip?: string | null;
|
|
431
433
|
user?: TUser;
|
|
434
|
+
auth?: unknown;
|
|
435
|
+
authUser?: TUser;
|
|
432
436
|
authToken?: string;
|
|
433
437
|
source?: unknown;
|
|
434
438
|
};
|
|
@@ -460,12 +464,16 @@ declare class Request$1<TUser = unknown> extends Request {
|
|
|
460
464
|
readonly ip: string | null;
|
|
461
465
|
readonly source?: unknown;
|
|
462
466
|
user?: TUser;
|
|
467
|
+
auth?: unknown;
|
|
468
|
+
authUser?: TUser;
|
|
463
469
|
authToken?: string;
|
|
464
470
|
constructor(options?: RequestOptions<TUser>);
|
|
465
471
|
static from<TUser = unknown>(source?: Request$1<TUser> | RequestSource<TUser>): Request$1<TUser> | undefined;
|
|
466
472
|
header(name: string): string;
|
|
467
473
|
bearerToken(): string | null;
|
|
468
474
|
setUser(user: TUser): this;
|
|
475
|
+
setAuthentication<TAuth>(auth: TAuth, user: TUser, token?: string): this;
|
|
476
|
+
clearAuthentication(): this;
|
|
469
477
|
}
|
|
470
478
|
//#endregion
|
|
471
479
|
//#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-De_2oJZT.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-C1DNCiO9.js";
|
|
2
2
|
//#region src/middlewares/web.ts
|
|
3
3
|
const webMiddlewareKey = Symbol.for("arkstack:http:web");
|
|
4
4
|
const markWebRequest = (target) => {
|
|
@@ -66,6 +66,8 @@ var Request$1 = class Request$1 extends Request {
|
|
|
66
66
|
ip;
|
|
67
67
|
source;
|
|
68
68
|
user;
|
|
69
|
+
auth;
|
|
70
|
+
authUser;
|
|
69
71
|
authToken;
|
|
70
72
|
constructor(options = {}) {
|
|
71
73
|
super(options);
|
|
@@ -75,6 +77,8 @@ var Request$1 = class Request$1 extends Request {
|
|
|
75
77
|
if (this.path) this.path = options.path;
|
|
76
78
|
this.ip = options.ip ?? null;
|
|
77
79
|
this.user = options.user;
|
|
80
|
+
this.auth = options.auth;
|
|
81
|
+
this.authUser = options.authUser;
|
|
78
82
|
this.authToken = options.authToken;
|
|
79
83
|
this.source = options.source;
|
|
80
84
|
globalThis.request = (key) => key ? this.input(key) : this;
|
|
@@ -90,6 +94,8 @@ var Request$1 = class Request$1 extends Request {
|
|
|
90
94
|
path: request.path,
|
|
91
95
|
ip: request.ip ?? null,
|
|
92
96
|
user: request.user,
|
|
97
|
+
auth: request.auth,
|
|
98
|
+
authUser: request.authUser,
|
|
93
99
|
authToken: request.authToken,
|
|
94
100
|
source
|
|
95
101
|
});
|
|
@@ -107,6 +113,31 @@ var Request$1 = class Request$1 extends Request {
|
|
|
107
113
|
if (isRecord(this.source)) this.source.user = user;
|
|
108
114
|
return this;
|
|
109
115
|
}
|
|
116
|
+
setAuthentication(auth, user, token) {
|
|
117
|
+
this.auth = auth;
|
|
118
|
+
this.authUser = user;
|
|
119
|
+
this.authToken = token;
|
|
120
|
+
this.setUser(user);
|
|
121
|
+
if (isRecord(this.source)) {
|
|
122
|
+
this.source.auth = auth;
|
|
123
|
+
this.source.authUser = user;
|
|
124
|
+
this.source.authToken = token;
|
|
125
|
+
}
|
|
126
|
+
return this;
|
|
127
|
+
}
|
|
128
|
+
clearAuthentication() {
|
|
129
|
+
this.auth = void 0;
|
|
130
|
+
this.authUser = void 0;
|
|
131
|
+
this.authToken = void 0;
|
|
132
|
+
this.user = void 0;
|
|
133
|
+
if (isRecord(this.source)) {
|
|
134
|
+
this.source.auth = void 0;
|
|
135
|
+
this.source.authUser = void 0;
|
|
136
|
+
this.source.authToken = void 0;
|
|
137
|
+
this.source.user = void 0;
|
|
138
|
+
}
|
|
139
|
+
return this;
|
|
140
|
+
}
|
|
110
141
|
};
|
|
111
142
|
//#endregion
|
|
112
143
|
//#region src/Response.ts
|
|
@@ -1200,7 +1231,7 @@ const getSessionDriver = () => {
|
|
|
1200
1231
|
return configuredDriver;
|
|
1201
1232
|
};
|
|
1202
1233
|
//#endregion
|
|
1203
|
-
//#region src/
|
|
1234
|
+
//#region src/plugins.ts
|
|
1204
1235
|
const arkstackHttpPlugin = definePlugin({
|
|
1205
1236
|
name: "arkstack-http",
|
|
1206
1237
|
setup: ({ bind, useHttpContext }) => {
|
|
@@ -1213,6 +1244,9 @@ const arkstackHttpPlugin = definePlugin({
|
|
|
1213
1244
|
registerResponseFlashSweep(ctx, session);
|
|
1214
1245
|
return session;
|
|
1215
1246
|
});
|
|
1247
|
+
bind(Request$1, ({ request, ctx }) => {
|
|
1248
|
+
return request instanceof Request$1 ? request : Request$1.from(request ?? ctx);
|
|
1249
|
+
});
|
|
1216
1250
|
useHttpContext((context) => {
|
|
1217
1251
|
const session = getSession(context.ctx);
|
|
1218
1252
|
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-De_2oJZT.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-C1DNCiO9.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.20",
|
|
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/common": "^0.12.
|
|
34
|
-
"@arkstack/contract": "^0.12.
|
|
33
|
+
"@arkstack/common": "^0.12.20",
|
|
34
|
+
"@arkstack/contract": "^0.12.20"
|
|
35
35
|
},
|
|
36
36
|
"peerDependencies": {
|
|
37
|
-
"arkormx": "^2.
|
|
37
|
+
"arkormx": "^2.5.6",
|
|
38
38
|
"kanun": "^1.2.0"
|
|
39
39
|
},
|
|
40
40
|
"scripts": {
|