@arkstack/driver-express 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.
- package/dist/index.js +81 -8
- package/dist/middlewares/index.js +1 -1
- package/package.json +8 -8
package/dist/index.js
CHANGED
|
@@ -62,8 +62,9 @@ const defaultErrorHandler = async (err, req, res, next) => {
|
|
|
62
62
|
}));
|
|
63
63
|
};
|
|
64
64
|
//#endregion
|
|
65
|
-
//#region ../http/dist/redirect-
|
|
65
|
+
//#region ../http/dist/redirect-CFGcSkzk.js
|
|
66
66
|
const unwrapRequestSource = (source) => {
|
|
67
|
+
if (source.original) return unwrapRequestSource(source.original);
|
|
67
68
|
if (source.headers) return source;
|
|
68
69
|
if (source.req) return source.req;
|
|
69
70
|
if (source.request) return source.request;
|
|
@@ -115,18 +116,48 @@ var Request$1$1 = class Request$1$2 extends Request$1 {
|
|
|
115
116
|
headers;
|
|
116
117
|
ip;
|
|
117
118
|
source;
|
|
118
|
-
|
|
119
|
-
|
|
119
|
+
currentUser;
|
|
120
|
+
currentAuth;
|
|
121
|
+
currentAuthUser;
|
|
122
|
+
currentAuthToken;
|
|
123
|
+
get user() {
|
|
124
|
+
return this.getSourceRequest()?.user ?? this.currentUser;
|
|
125
|
+
}
|
|
126
|
+
set user(user) {
|
|
127
|
+
this.currentUser = user;
|
|
128
|
+
}
|
|
129
|
+
get auth() {
|
|
130
|
+
return this.getSourceRequest()?.auth ?? this.currentAuth;
|
|
131
|
+
}
|
|
132
|
+
set auth(auth) {
|
|
133
|
+
this.currentAuth = auth;
|
|
134
|
+
}
|
|
135
|
+
get authUser() {
|
|
136
|
+
return this.getSourceRequest()?.authUser ?? this.currentAuthUser;
|
|
137
|
+
}
|
|
138
|
+
set authUser(user) {
|
|
139
|
+
this.currentAuthUser = user;
|
|
140
|
+
}
|
|
141
|
+
get authToken() {
|
|
142
|
+
return this.getSourceRequest()?.authToken ?? this.currentAuthToken;
|
|
143
|
+
}
|
|
144
|
+
set authToken(token) {
|
|
145
|
+
this.currentAuthToken = token;
|
|
146
|
+
}
|
|
120
147
|
constructor(options = {}) {
|
|
121
148
|
super(options);
|
|
149
|
+
const source = options.source ?? options.original;
|
|
150
|
+
const sourceRequest = isRecord(source) ? source : void 0;
|
|
122
151
|
this.headers = normalizeHeaders(options.headers);
|
|
123
152
|
if (this.method) this.method = options.method;
|
|
124
153
|
if (this.url) this.url = options.url;
|
|
125
154
|
if (this.path) this.path = options.path;
|
|
126
|
-
this.ip = options.ip ?? null;
|
|
127
|
-
this.user = options.user;
|
|
128
|
-
this.
|
|
129
|
-
this.
|
|
155
|
+
this.ip = options.ip ?? sourceRequest?.ip ?? null;
|
|
156
|
+
this.user = options.user ?? sourceRequest?.user;
|
|
157
|
+
this.auth = options.auth ?? sourceRequest?.auth;
|
|
158
|
+
this.authUser = options.authUser ?? sourceRequest?.authUser;
|
|
159
|
+
this.authToken = options.authToken ?? sourceRequest?.authToken;
|
|
160
|
+
this.source = source;
|
|
130
161
|
globalThis.request = (key) => key ? this.input(key) : this;
|
|
131
162
|
}
|
|
132
163
|
static from(source) {
|
|
@@ -140,8 +171,10 @@ var Request$1$1 = class Request$1$2 extends Request$1 {
|
|
|
140
171
|
path: request.path,
|
|
141
172
|
ip: request.ip ?? null,
|
|
142
173
|
user: request.user,
|
|
174
|
+
auth: request.auth,
|
|
175
|
+
authUser: request.authUser,
|
|
143
176
|
authToken: request.authToken,
|
|
144
|
-
source
|
|
177
|
+
source: request
|
|
145
178
|
});
|
|
146
179
|
}
|
|
147
180
|
header(name) {
|
|
@@ -157,6 +190,43 @@ var Request$1$1 = class Request$1$2 extends Request$1 {
|
|
|
157
190
|
if (isRecord(this.source)) this.source.user = user;
|
|
158
191
|
return this;
|
|
159
192
|
}
|
|
193
|
+
setAuthentication(auth, user, token) {
|
|
194
|
+
this.auth = auth;
|
|
195
|
+
this.authUser = user;
|
|
196
|
+
this.authToken = token;
|
|
197
|
+
this.setUser(user);
|
|
198
|
+
if (isRecord(this.source)) {
|
|
199
|
+
this.source.auth = auth;
|
|
200
|
+
this.source.authUser = user;
|
|
201
|
+
this.source.authToken = token;
|
|
202
|
+
}
|
|
203
|
+
return this;
|
|
204
|
+
}
|
|
205
|
+
syncFromSource() {
|
|
206
|
+
if (!isRecord(this.source)) return this;
|
|
207
|
+
const source = this.source;
|
|
208
|
+
this.user = source.user ?? this.user;
|
|
209
|
+
this.auth = source.auth ?? this.auth;
|
|
210
|
+
this.authUser = source.authUser ?? this.authUser;
|
|
211
|
+
this.authToken = source.authToken ?? this.authToken;
|
|
212
|
+
return this;
|
|
213
|
+
}
|
|
214
|
+
getSourceRequest() {
|
|
215
|
+
return isRecord(this.source) ? this.source : void 0;
|
|
216
|
+
}
|
|
217
|
+
clearAuthentication() {
|
|
218
|
+
this.auth = void 0;
|
|
219
|
+
this.authUser = void 0;
|
|
220
|
+
this.authToken = void 0;
|
|
221
|
+
this.user = void 0;
|
|
222
|
+
if (isRecord(this.source)) {
|
|
223
|
+
this.source.auth = void 0;
|
|
224
|
+
this.source.authUser = void 0;
|
|
225
|
+
this.source.authToken = void 0;
|
|
226
|
+
this.source.user = void 0;
|
|
227
|
+
}
|
|
228
|
+
return this;
|
|
229
|
+
}
|
|
160
230
|
};
|
|
161
231
|
var FlashBag = class {
|
|
162
232
|
bag = {};
|
|
@@ -1176,6 +1246,9 @@ definePlugin({
|
|
|
1176
1246
|
registerResponseFlashSweep(ctx, session);
|
|
1177
1247
|
return session;
|
|
1178
1248
|
});
|
|
1249
|
+
bind(Request$1$1, ({ request, ctx }) => {
|
|
1250
|
+
return (request instanceof Request$1$1 ? request : Request$1$1.from(request ?? ctx)).syncFromSource();
|
|
1251
|
+
});
|
|
1179
1252
|
useHttpContext((context) => {
|
|
1180
1253
|
const session = getSession(context.ctx);
|
|
1181
1254
|
if (session) {
|
|
@@ -15,7 +15,7 @@ const auth = async (req, res, next) => {
|
|
|
15
15
|
status: 401
|
|
16
16
|
});
|
|
17
17
|
const auth = Auth.make().setRequest(req);
|
|
18
|
-
const user = await
|
|
18
|
+
const user = await auth.authorizeToken(token);
|
|
19
19
|
req.user = user;
|
|
20
20
|
req.auth = auth;
|
|
21
21
|
req.authUser = user;
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@arkstack/driver-express",
|
|
3
|
-
"version": "0.12.
|
|
3
|
+
"version": "0.12.21",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Express driver for Arkstack, providing Express-based runtime integration for the framework.",
|
|
6
6
|
"homepage": "https://arkstack.toneflix.net",
|
|
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/driver-express"
|
|
11
11
|
},
|
|
12
12
|
"keywords": [
|
|
@@ -40,15 +40,15 @@
|
|
|
40
40
|
"multer": "^2.1.1",
|
|
41
41
|
"clear-router": "^2.8.6",
|
|
42
42
|
"express-rate-limit": "^8.4.1",
|
|
43
|
-
"@resora/plugin-clear-router": "^1.0.
|
|
44
|
-
"resora": "^1.3.
|
|
45
|
-
"@arkstack/contract": "^0.12.
|
|
43
|
+
"@resora/plugin-clear-router": "^1.0.48",
|
|
44
|
+
"resora": "^1.3.16",
|
|
45
|
+
"@arkstack/contract": "^0.12.21"
|
|
46
46
|
},
|
|
47
47
|
"peerDependencies": {
|
|
48
48
|
"express": "^5.2.1",
|
|
49
|
-
"@arkstack/auth": "^0.12.
|
|
50
|
-
"@arkstack/
|
|
51
|
-
"@arkstack/
|
|
49
|
+
"@arkstack/auth": "^0.12.21",
|
|
50
|
+
"@arkstack/common": "^0.12.21",
|
|
51
|
+
"@arkstack/foundry": "^0.12.21"
|
|
52
52
|
},
|
|
53
53
|
"peerDependenciesMeta": {
|
|
54
54
|
"@arkstack/auth": {
|