@dreamkit/app 0.0.13 → 0.0.15
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/lib/App.d.ts +1 -1
- package/lib/App.d.ts.map +1 -1
- package/lib/App.js +22 -5
- package/lib/utils/buffer.d.ts +1 -0
- package/lib/utils/buffer.d.ts.map +1 -1
- package/lib/utils/buffer.js +3 -0
- package/lib/utils/crypto.d.ts.map +1 -1
- package/lib/utils/crypto.js +3 -3
- package/package.json +1 -1
package/lib/App.d.ts
CHANGED
|
@@ -62,7 +62,7 @@ export declare class App {
|
|
|
62
62
|
};
|
|
63
63
|
add(input: Record<string, any> | any[]): Promise<void>;
|
|
64
64
|
createRequestContext(request: Request): RequestContext;
|
|
65
|
-
request(request: Request): Promise<any>;
|
|
65
|
+
request(request: Request, context?: RequestContext): Promise<any>;
|
|
66
66
|
protected initSettingsValue(constructor: SettingsConstructor): Promise<{
|
|
67
67
|
[x: string]: any;
|
|
68
68
|
} | undefined>;
|
package/lib/App.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"App.d.ts","sourceRoot":"","sources":["../src/App.ts"],"names":[],"mappings":"AAGA,OAAO,EAEL,qBAAqB,EACtB,MAAM,iCAAiC,CAAC;AACzC,OAAO,EAAE,KAAK,EAAE,MAAM,4BAA4B,CAAC;AACnD,OAAO,EACL,UAAU,EAEV,kBAAkB,EACnB,MAAM,8BAA8B,CAAC;
|
|
1
|
+
{"version":3,"file":"App.d.ts","sourceRoot":"","sources":["../src/App.ts"],"names":[],"mappings":"AAGA,OAAO,EAEL,qBAAqB,EACtB,MAAM,iCAAiC,CAAC;AACzC,OAAO,EAAE,KAAK,EAAE,MAAM,4BAA4B,CAAC;AACnD,OAAO,EACL,UAAU,EAEV,kBAAkB,EACnB,MAAM,8BAA8B,CAAC;AAEtC,OAAO,EAAc,mBAAmB,EAAE,MAAM,+BAA+B,CAAC;AAChF,OAAO,EAAE,UA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AAmB;cAUnB,gBAAgB,CAAC,WAAW,EAAE,mBAAmB;IAUjE,SAAS,CAAC,cAAc,CAAC,WAAW,EAAE,mBAAmB;IAKzD,SAAS,CAAC,gBAAgB,IAAI,eAAe,GAAG,SAAS;IAMnD,KAAK;IAQL,IAAI;IAkBV,KAAK;CAWN"}
|
package/lib/App.js
CHANGED
|
@@ -3,6 +3,7 @@ import { ResponseHeaders } from "./ResponseHeaders.js";
|
|
|
3
3
|
import { isApi } from "./builders/ApiBuilder.js";
|
|
4
4
|
import { isMiddleware, } from "./builders/MiddlewareBuilder.js";
|
|
5
5
|
import { isService, } from "./builders/ServiceBuilder.js";
|
|
6
|
+
import { Session } from "./builders/SessionBuilder.js";
|
|
6
7
|
import { isSettings } from "./builders/SettingsBuilder.js";
|
|
7
8
|
import { AppContext } from "./contexts/AppContext.js";
|
|
8
9
|
import { RequestContext } from "./contexts/RequestContext.js";
|
|
@@ -258,13 +259,23 @@ export class App {
|
|
|
258
259
|
const context = new RequestContext({
|
|
259
260
|
parentContainer: this.context,
|
|
260
261
|
});
|
|
262
|
+
const host = request.headers.get("host") ?? "localhost";
|
|
261
263
|
const requestContext = context
|
|
262
264
|
.register(RequestContext, { value: context })
|
|
263
265
|
.register(Request, { value: request })
|
|
264
266
|
.register(Headers, { value: request.headers })
|
|
265
267
|
.register(ResponseHeaders, { value: new ResponseHeaders() })
|
|
266
268
|
.register(RequestUrl, {
|
|
267
|
-
value: new RequestUrl(request.url,
|
|
269
|
+
value: new RequestUrl(request.url, `http://${host}`),
|
|
270
|
+
})
|
|
271
|
+
.register(Session, {
|
|
272
|
+
useFactory: (ctx, Session) => {
|
|
273
|
+
const sessionHandler = ctx.resolve(SessionHandler);
|
|
274
|
+
const data = sessionHandler.get(Session);
|
|
275
|
+
if (!data)
|
|
276
|
+
return;
|
|
277
|
+
return new Session(data);
|
|
278
|
+
},
|
|
268
279
|
});
|
|
269
280
|
if (this.sessionHandler)
|
|
270
281
|
requestContext.register(SessionHandler, {
|
|
@@ -273,14 +284,20 @@ export class App {
|
|
|
273
284
|
});
|
|
274
285
|
return requestContext;
|
|
275
286
|
}
|
|
276
|
-
async request(request) {
|
|
277
|
-
|
|
287
|
+
async request(request, context) {
|
|
288
|
+
if (!context)
|
|
289
|
+
context = this.createRequestContext(request);
|
|
278
290
|
log("request", context.resolve(RequestUrl).pathname);
|
|
279
291
|
for (const middleware of this.middlewares) {
|
|
280
292
|
const $md = context.resolve(middleware);
|
|
281
293
|
const response = await $md.onRequest();
|
|
282
|
-
if (response)
|
|
283
|
-
|
|
294
|
+
if (response && response instanceof Response) {
|
|
295
|
+
const headers = context.resolve(ResponseHeaders);
|
|
296
|
+
for (const [name, value] of headers.entries()) {
|
|
297
|
+
response.headers.set(name, value);
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
return response;
|
|
284
301
|
}
|
|
285
302
|
}
|
|
286
303
|
async initSettingsValue(constructor) {
|
package/lib/utils/buffer.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"buffer.d.ts","sourceRoot":"","sources":["../../src/utils/buffer.ts"],"names":[],"mappings":"AAAA,wBAAgB,QAAQ,CAAC,KAAK,EAAE,WAAW,GAAG,MAAM,CAEnD;AAED,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,GAAG,UAAU,CAEpD"}
|
|
1
|
+
{"version":3,"file":"buffer.d.ts","sourceRoot":"","sources":["../../src/utils/buffer.ts"],"names":[],"mappings":"AAAA,wBAAgB,QAAQ,CAAC,KAAK,EAAE,WAAW,GAAG,MAAM,CAEnD;AAED,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,GAAG,UAAU,CAEpD;AAED,wBAAgB,aAAa,CAAC,KAAK,EAAE,UAAU,GAAG,WAAW,CAK5D"}
|
package/lib/utils/buffer.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"crypto.d.ts","sourceRoot":"","sources":["../../src/utils/crypto.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,SAAS;;;CAGrB,CAAC;AAEF,wBAAgB,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,
|
|
1
|
+
{"version":3,"file":"crypto.d.ts","sourceRoot":"","sources":["../../src/utils/crypto.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,SAAS;;;CAGrB,CAAC;AAEF,wBAAgB,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAI7C;AAED,wBAAgB,UAAU,IAAI,MAAM,CAEnC;AAED,wBAAgB,WAAW,IAAI,MAAM,CAEpC;AAED,wBAAgB,YAAY,CAC1B,GAAG,KAAK,EAAE,CAAC,MAAM,GAAG,WAAW,CAAC,EAAE,GACjC,WAAW,EAAE,CAIf;AAED,wBAAsB,OAAO,CAC3B,KAAK,EAAE,MAAM,EACb,EAAE,EAAE,MAAM,GAAG,WAAW,EACxB,GAAG,EAAE,MAAM,GAAG,WAAW,mBAmB1B;AAED,wBAAsB,OAAO,CAC3B,KAAK,EAAE,MAAM,GAAG,WAAW,EAC3B,EAAE,EAAE,MAAM,GAAG,WAAW,EACxB,GAAG,EAAE,MAAM,GAAG,WAAW,mBAiB1B"}
|
package/lib/utils/crypto.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
// https://medium.com/@tony.infisical/guide-to-web-crypto-api-for-encryption-decryption-1a2c698ebc25
|
|
2
|
-
import { fromBase64, toBase64 } from "./buffer.js";
|
|
2
|
+
import { fromBase64, toArrayBuffer, toBase64 } from "./buffer.js";
|
|
3
3
|
export const algorithm = {
|
|
4
4
|
name: "AES-GCM",
|
|
5
5
|
length: 256,
|
|
6
6
|
};
|
|
7
7
|
export function random(length) {
|
|
8
|
-
return toBase64(crypto.getRandomValues(new Uint8Array(length)));
|
|
8
|
+
return toBase64(toArrayBuffer(crypto.getRandomValues(new Uint8Array(length))));
|
|
9
9
|
}
|
|
10
10
|
export function generateIv() {
|
|
11
11
|
return random(16);
|
|
@@ -14,7 +14,7 @@ export function generateKey() {
|
|
|
14
14
|
return random(32);
|
|
15
15
|
}
|
|
16
16
|
export function parseSecrets(...input) {
|
|
17
|
-
return input.map((v) =>
|
|
17
|
+
return input.map((v) => typeof v === "string" ? toArrayBuffer(fromBase64(v)) : v);
|
|
18
18
|
}
|
|
19
19
|
export async function encrypt(input, iv, key) {
|
|
20
20
|
const [ivBuffer, keyBuffer] = parseSecrets(iv, key);
|