@thisisagile/easy 7.35.0 → 7.37.1
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/http/CacheControl.d.ts +15 -0
- package/dist/http/CacheControl.js +31 -0
- package/dist/http/CacheControl.js.map +1 -0
- package/dist/http/Verb.d.ts +2 -1
- package/dist/http/Verb.js +1 -0
- package/dist/http/Verb.js.map +1 -1
- package/dist/http/index.d.ts +1 -0
- package/dist/http/index.js +1 -0
- package/dist/http/index.js.map +1 -1
- package/dist/security/Jwt.d.ts +6 -1
- package/dist/security/Jwt.js +2 -1
- package/dist/security/Jwt.js.map +1 -1
- package/package.json +2 -2
- package/src/http/CacheControl.ts +31 -0
- package/src/http/Verb.ts +3 -2
- package/src/http/index.ts +1 -0
- package/src/security/Jwt.ts +6 -1
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export declare class CacheControl {
|
|
2
|
+
private age;
|
|
3
|
+
private stale?;
|
|
4
|
+
readonly enabled: boolean;
|
|
5
|
+
private constructor();
|
|
6
|
+
static disabled: () => CacheControl;
|
|
7
|
+
static OneSecond: () => CacheControl;
|
|
8
|
+
static fiveSeconds: () => CacheControl;
|
|
9
|
+
static tenSeconds: () => CacheControl;
|
|
10
|
+
static custom: (maxAge: number, staleWhileRevalidate?: number | undefined) => CacheControl;
|
|
11
|
+
maxAge: (a: number) => this;
|
|
12
|
+
staleWhileRevalidate: (s?: number | undefined) => this;
|
|
13
|
+
value: () => string;
|
|
14
|
+
set: (setHeader: (name: string, value: number | string | ReadonlyArray<string>) => any) => any;
|
|
15
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CacheControl = void 0;
|
|
4
|
+
const types_1 = require("../types");
|
|
5
|
+
class CacheControl {
|
|
6
|
+
constructor(age = 1, stale, enabled = true) {
|
|
7
|
+
this.age = age;
|
|
8
|
+
this.stale = stale;
|
|
9
|
+
this.enabled = enabled;
|
|
10
|
+
this.maxAge = (a) => {
|
|
11
|
+
this.age = Math.abs(a);
|
|
12
|
+
return this;
|
|
13
|
+
};
|
|
14
|
+
this.staleWhileRevalidate = (s) => {
|
|
15
|
+
this.stale = (0, types_1.isDefined)(s) ? Math.abs(s) : undefined;
|
|
16
|
+
return this;
|
|
17
|
+
};
|
|
18
|
+
this.value = () => {
|
|
19
|
+
const swr = (0, types_1.isDefined)(this.stale) ? `, stale-while-revalidate=${this.stale}` : '';
|
|
20
|
+
return this.enabled ? `max-age=${this.age}${swr}` : '';
|
|
21
|
+
};
|
|
22
|
+
this.set = (setHeader) => this.enabled ? setHeader('Cache-Control', this.value()) : {};
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
exports.CacheControl = CacheControl;
|
|
26
|
+
CacheControl.disabled = () => new CacheControl(0, 0, false);
|
|
27
|
+
CacheControl.OneSecond = () => new CacheControl().maxAge(1).staleWhileRevalidate(1);
|
|
28
|
+
CacheControl.fiveSeconds = () => new CacheControl().maxAge(5).staleWhileRevalidate(5);
|
|
29
|
+
CacheControl.tenSeconds = () => new CacheControl().maxAge(10).staleWhileRevalidate(10);
|
|
30
|
+
CacheControl.custom = (maxAge, staleWhileRevalidate) => new CacheControl().maxAge(maxAge).staleWhileRevalidate(staleWhileRevalidate);
|
|
31
|
+
//# sourceMappingURL=CacheControl.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CacheControl.js","sourceRoot":"","sources":["../../src/http/CacheControl.ts"],"names":[],"mappings":";;;AAAA,oCAAqC;AAErC,MAAa,YAAY;IAEvB,YAA4B,MAAc,CAAC,EAAU,KAAc,EAAW,UAAU,IAAI;QAAhE,QAAG,GAAH,GAAG,CAAY;QAAU,UAAK,GAAL,KAAK,CAAS;QAAW,YAAO,GAAP,OAAO,CAAO;QAS5F,WAAM,GAAG,CAAC,CAAS,EAAQ,EAAE;YAC3B,IAAI,CAAC,G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AAI,YAAY,EAAE,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,oBAAoB,CAAC,EAAE,CAAC,CAAC;AAC1E,mBAAM,GAAG,CAAC,MAAc,EAAE,oBAA6B,EAAE,EAAE,CAAC,IAAI,YAAY,EAAE,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,oBAAoB,CAAC,oBAAoB,CAAC,CAAC"}
|
package/dist/http/Verb.d.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import { ContentType, HttpStatus, HttpVerb } from './index';
|
|
1
|
+
import { CacheControl, ContentType, HttpStatus, HttpVerb } from './index';
|
|
2
2
|
export declare type VerbOptions = {
|
|
3
3
|
onOk?: HttpStatus;
|
|
4
4
|
onNotFound?: HttpStatus;
|
|
5
5
|
onError?: HttpStatus;
|
|
6
6
|
type?: ContentType;
|
|
7
|
+
cache?: CacheControl;
|
|
7
8
|
};
|
|
8
9
|
export declare type Verb = {
|
|
9
10
|
verb: HttpVerb;
|
package/dist/http/Verb.js
CHANGED
|
@@ -8,6 +8,7 @@ const toVerbOptions = (options) => ({
|
|
|
8
8
|
onNotFound: options?.onNotFound ?? index_1.HttpStatus.NotFound,
|
|
9
9
|
onError: options?.onError ?? index_1.HttpStatus.BadRequest,
|
|
10
10
|
type: options?.type ?? index_1.ContentType.Json,
|
|
11
|
+
cache: options?.cache ?? index_1.CacheControl.disabled()
|
|
11
12
|
});
|
|
12
13
|
exports.toVerbOptions = toVerbOptions;
|
|
13
14
|
const toVerb = (verb, options) => (subject, property) => {
|
package/dist/http/Verb.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Verb.js","sourceRoot":"","sources":["../../src/http/Verb.ts"],"names":[],"mappings":";;;AAAA,oCAAgC;AAChC,
|
|
1
|
+
{"version":3,"file":"Verb.js","sourceRoot":"","sources":["../../src/http/Verb.ts"],"names":[],"mappings":";;;AAAA,oCAAgC;AAChC,mCAA0E;AAKnE,MAAM,aAAa,GAAG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AE,OAAO,CAAC,CAAC;AAAtF,QAAA,KAAK,SAAiF;AAE5F,MAAM,IAAI,GAAG,CAAC,OAAqB,EAAqB,EAAE,CAAC,MAAM,CAAC,gBAAQ,CAAC,IAAI,EAAE,EAAE,IAAI,EAAE,kBAAU,CAAC,OAAO,EAAE,GAAG,OAAO,EAAE,CAAC,CAAC;AAArH,QAAA,IAAI,QAAiH;AAE3H,MAAM,GAAG,GAAG,CAAC,OAAqB,EAAqB,EAAE,CAAC,MAAM,CAAC,gBAAQ,CAAC,MAAM,EAAE,EAAE,IAAI,EAAE,kBAAU,CAAC,SAAS,EAAE,GAAG,OAAO,EAAE,CAAC,CAAC;AAAxH,QAAA,GAAG,OAAqH;AAE9H,MAAM,MAAM,GAAG,CAAC,OAAqB,EAAqB,EAAE,CAAC,MAAM,CAAC,gBAAQ,CAAC,GAAG,EAAE,EAAE,IAAI,EAAE,mBAAW,CAAC,MAAM,EAAE,GAAG,OAAO,EAAE,CAAC,CAAC;AAAtH,QAAA,MAAM,UAAgH"}
|
package/dist/http/index.d.ts
CHANGED
package/dist/http/index.js
CHANGED
|
@@ -10,6 +10,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
10
10
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
11
11
|
};
|
|
12
12
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
__exportStar(require("./CacheControl"), exports);
|
|
13
14
|
__exportStar(require("./ContentType"), exports);
|
|
14
15
|
__exportStar(require("./HttpHeader"), exports);
|
|
15
16
|
__exportStar(require("./HttpStatus"), exports);
|
package/dist/http/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/http/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,gDAA8B;AAC9B,+CAA6B;AAC7B,+CAA6B;AAC7B,6CAA2B;AAC3B,oDAAkC;AAClC,4CAA0B;AAC1B,mDAAiC;AACjC,oDAAkC;AAClC,6CAA2B;AAC3B,+CAA6B;AAC7B,yCAAuB"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/http/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,iDAA8B;AAC9B,gDAA8B;AAC9B,+CAA6B;AAC7B,+CAA6B;AAC7B,6CAA2B;AAC3B,oDAAkC;AAClC,4CAA0B;AAC1B,mDAAiC;AACjC,oDAAkC;AAClC,6CAA2B;AAC3B,+CAA6B;AAC7B,yCAAuB"}
|
package/dist/security/Jwt.d.ts
CHANGED
|
@@ -1,10 +1,15 @@
|
|
|
1
1
|
import { Json, Validatable, Value } from '../types';
|
|
2
|
+
interface SignOptions {
|
|
3
|
+
audience?: string | string[] | undefined;
|
|
4
|
+
issuer?: string | undefined;
|
|
5
|
+
}
|
|
2
6
|
export declare class Jwt extends Value implements Validatable {
|
|
3
7
|
get isValid(): boolean;
|
|
4
|
-
static sign: (token: Json) => Jwt;
|
|
8
|
+
static sign: (token: Json, options?: SignOptions | undefined) => Jwt;
|
|
5
9
|
static of: (a: {
|
|
6
10
|
jwt: string;
|
|
7
11
|
}) => Jwt;
|
|
8
12
|
decode: () => Json;
|
|
9
13
|
toJSON(): Json;
|
|
10
14
|
}
|
|
15
|
+
export {};
|
package/dist/security/Jwt.js
CHANGED
|
@@ -18,8 +18,9 @@ class Jwt extends types_1.Value {
|
|
|
18
18
|
}
|
|
19
19
|
}
|
|
20
20
|
exports.Jwt = Jwt;
|
|
21
|
-
Jwt.sign = (token) => (0, types_1.tryTo)(() => types_1.ctx.env.get('tokenPrivateKey') ?? '').is.not.empty()
|
|
21
|
+
Jwt.sign = (token, options) => (0, types_1.tryTo)(() => types_1.ctx.env.get('tokenPrivateKey') ?? '').is.not.empty()
|
|
22
22
|
.map(key => (0, jsonwebtoken_1.sign)(token, key, {
|
|
23
|
+
...options,
|
|
23
24
|
expiresIn: types_1.ctx.env.get('tokenExpiresIn') ?? '1h',
|
|
24
25
|
keyid: types_1.ctx.env.get('tokenKeyid') ?? 'easy',
|
|
25
26
|
algorithm: types_1.ctx.env.get('tokenAlgorithm', 'RS256'),
|
package/dist/security/Jwt.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Jwt.js","sourceRoot":"","sources":["../../src/security/Jwt.ts"],"names":[],"mappings":";;;AAAA,+CAA+D;AAC/D,oCAAgE;
|
|
1
|
+
{"version":3,"file":"Jwt.js","sourceRoot":"","sources":["../../src/security/Jwt.ts"],"names":[],"mappings":";;;AAAA,+CAA+D;AAC/D,oCAAgE;AAMhE,MAAa,GAAI,SAAQ,aAAK;IAA9B;;QAoBE,WAAM,GAAG,GAAS,EAAE,CAAC,IAAA,qBAAM,EAAC,IAAI,CAAC,KAAK,CAAS,CAAC;IAKlD,CAAC;IAvBC,IAAI,OAAO;QACT,OAAO,IAAA,aAAK,EAAC,GAAG,EAAE,CAAC,CAAC,WAAG,CAAC,GAAG,CAAC,GAAG,CAAC,gBAAgB,CAAC,IAAI,EAAE,CAAC,CAAC;aACtD,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,IAAA,qBAAM,EAAC,IAAI,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;aACnC,GAAG,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,IAAI,KAAK,CAAC;IACvC,CAAC;IAgBD,MAAM;QACJ,OAAO,EAAE,GAAG,EAAE,IAAI,CAAC,KAAK,EAAE,CAAC;IAC7B,CAAC;;AAxBH,kBAyBC;AAjBQ,QAAI,GAAG,CAAC,KAAW,EAAE,OAAqB,EAAO,EAAE,CACxD,IAAA,aAAK,EAAC,GAAG,EAAE,CAAC,WAAG,CAAC,GAAG,CAAC,GAAG,CAAC,iBAAiB,CAAC,IAAI,EAAE,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,KAAK,EAAE;KAC7D,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,IAAA,mBAAI,EAAC,KAAK,EAAE,GAAG,EAAE;IAC3B,GAAG,OAAO;IACV,SAAS,EAAE,WAAG,CAAC,GAAG,CAAC,GAAG,CAAC,gBAAgB,CAAC,IAAI,IAAI;IAChD,KAAK,EAAE,WAAG,CAAC,GAAG,CAAC,GAAG,CAAC,YAAY,CAAC,IAAI,MAAM;IAC1C,SAAS,EAAE,WAAG,CAAC,GAAG,CAAC,GAAG,CAAC,gBAAgB,EAAE,OAAO,CAAc;CAC/D,CAAC,CAAC;KACF,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,IAAI,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC;AAEzB,MAAE,GAAG,CAAC,CAAkB,EAAO,EAAE,CAAC,IAAI,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@thisisagile/easy",
|
|
3
|
-
"version": "7.
|
|
3
|
+
"version": "7.37.1",
|
|
4
4
|
"description": "Straightforward library for building domain-driven microservice architectures",
|
|
5
5
|
"author": "Sander Hoogendoorn",
|
|
6
6
|
"license": "MIT",
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"access": "public"
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {
|
|
34
|
-
"@thisisagile/easy-test": "7.
|
|
34
|
+
"@thisisagile/easy-test": "7.37.1",
|
|
35
35
|
"@types/form-urlencoded": "^4.4.0",
|
|
36
36
|
"@types/jsonwebtoken": "^8.5.5",
|
|
37
37
|
"@types/validator": "^13.6.5"
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { isDefined } from '../types';
|
|
2
|
+
|
|
3
|
+
export class CacheControl {
|
|
4
|
+
|
|
5
|
+
private constructor(private age: number = 1, private stale?: number, readonly enabled = true) {
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
static disabled = () => new CacheControl(0, 0, false);
|
|
9
|
+
static OneSecond = () => new CacheControl().maxAge(1).staleWhileRevalidate(1);
|
|
10
|
+
static fiveSeconds = () => new CacheControl().maxAge(5).staleWhileRevalidate(5);
|
|
11
|
+
static tenSeconds = () => new CacheControl().maxAge(10).staleWhileRevalidate(10);
|
|
12
|
+
static custom = (maxAge: number, staleWhileRevalidate?: number) => new CacheControl().maxAge(maxAge).staleWhileRevalidate(staleWhileRevalidate);
|
|
13
|
+
|
|
14
|
+
maxAge = (a: number): this => {
|
|
15
|
+
this.age = Math.abs(a);
|
|
16
|
+
return this;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
staleWhileRevalidate = (s?: number): this => {
|
|
20
|
+
this.stale = isDefined(s) ? Math.abs(s) : undefined;
|
|
21
|
+
return this;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
value = (): string => {
|
|
25
|
+
const swr = isDefined(this.stale) ? `, stale-while-revalidate=${this.stale}` : '';
|
|
26
|
+
return this.enabled ? `max-age=${this.age}${swr}` : '';
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
set = (setHeader: (name: string, value: number | string | ReadonlyArray<string>) => any) =>
|
|
30
|
+
this.enabled ? setHeader('Cache-Control', this.value()) : {};
|
|
31
|
+
}
|
package/src/http/Verb.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { meta } from '../types';
|
|
2
|
-
import { ContentType, HttpStatus, HttpVerb } from './index';
|
|
2
|
+
import { CacheControl, ContentType, HttpStatus, HttpVerb } from './index';
|
|
3
3
|
|
|
4
|
-
export type VerbOptions = { onOk?: HttpStatus; onNotFound?: HttpStatus; onError?: HttpStatus; type?: ContentType };
|
|
4
|
+
export type VerbOptions = { onOk?: HttpStatus; onNotFound?: HttpStatus; onError?: HttpStatus; type?: ContentType, cache?: CacheControl };
|
|
5
5
|
export type Verb = { verb: HttpVerb; options: VerbOptions };
|
|
6
6
|
|
|
7
7
|
export const toVerbOptions = (options?: VerbOptions): Required<VerbOptions> => ({
|
|
@@ -9,6 +9,7 @@ export const toVerbOptions = (options?: VerbOptions): Required<VerbOptions> => (
|
|
|
9
9
|
onNotFound: options?.onNotFound ?? HttpStatus.NotFound,
|
|
10
10
|
onError: options?.onError ?? HttpStatus.BadRequest,
|
|
11
11
|
type: options?.type ?? ContentType.Json,
|
|
12
|
+
cache: options?.cache ?? CacheControl.disabled()
|
|
12
13
|
});
|
|
13
14
|
|
|
14
15
|
const toVerb =
|
package/src/http/index.ts
CHANGED
package/src/security/Jwt.ts
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import { Algorithm, decode, sign, verify } from 'jsonwebtoken';
|
|
2
2
|
import { ctx, Json, tryTo, Validatable, Value } from '../types';
|
|
3
3
|
|
|
4
|
+
interface SignOptions {
|
|
5
|
+
audience?: string | string[] | undefined;
|
|
6
|
+
issuer?: string | undefined;
|
|
7
|
+
}
|
|
4
8
|
export class Jwt extends Value implements Validatable {
|
|
5
9
|
|
|
6
10
|
get isValid(): boolean {
|
|
@@ -9,9 +13,10 @@ export class Jwt extends Value implements Validatable {
|
|
|
9
13
|
.map(() => true).orElse() ?? false;
|
|
10
14
|
}
|
|
11
15
|
|
|
12
|
-
static sign = (token: Json): Jwt =>
|
|
16
|
+
static sign = (token: Json, options?: SignOptions): Jwt =>
|
|
13
17
|
tryTo(() => ctx.env.get('tokenPrivateKey') ?? '').is.not.empty()
|
|
14
18
|
.map(key => sign(token, key, {
|
|
19
|
+
...options,
|
|
15
20
|
expiresIn: ctx.env.get('tokenExpiresIn') ?? '1h',
|
|
16
21
|
keyid: ctx.env.get('tokenKeyid') ?? 'easy',
|
|
17
22
|
algorithm: ctx.env.get('tokenAlgorithm', 'RS256') as Algorithm,
|