@devmoods/express-extras 0.52.0 → 0.52.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/auth/token.js +2 -2
- package/dist/cache.d.ts +4 -1
- package/dist/cache.js +26 -2
- package/dist/config.d.ts +2 -0
- package/dist/config.js +1 -0
- package/package.json +1 -1
package/dist/auth/token.js
CHANGED
|
@@ -98,14 +98,14 @@ export function setAccessTokenCookie(res, token) {
|
|
|
98
98
|
if (token == null) {
|
|
99
99
|
res.cookie(ACCESS_TOKEN_COOKIE_NAME, v4(), {
|
|
100
100
|
expires: new Date(1970, 0, 1),
|
|
101
|
-
sameSite:
|
|
101
|
+
sameSite: config.value.AUTH_COOKIE_SAME_SITE,
|
|
102
102
|
secure: process.env.NODE_ENV === 'production',
|
|
103
103
|
});
|
|
104
104
|
}
|
|
105
105
|
else {
|
|
106
106
|
res.cookie(ACCESS_TOKEN_COOKIE_NAME, token, {
|
|
107
107
|
httpOnly: true,
|
|
108
|
-
sameSite:
|
|
108
|
+
sameSite: config.value.AUTH_COOKIE_SAME_SITE,
|
|
109
109
|
secure: process.env.NODE_ENV === 'production',
|
|
110
110
|
});
|
|
111
111
|
}
|
package/dist/cache.d.ts
CHANGED
|
@@ -19,5 +19,8 @@ export declare function createCache(adapter: CacheAdapter): {
|
|
|
19
19
|
get: (key: string) => Promise<any>;
|
|
20
20
|
clear: (key?: string) => Promise<void>;
|
|
21
21
|
wrap: <T>(key: string, options: CacheOptions | number | null, fn: () => Promise<T>) => Promise<T>;
|
|
22
|
-
decorate: <T, Arguments extends any[]>(options: CacheOptions | number | null, fn: (...args: Arguments) => T | Promise<T>) =>
|
|
22
|
+
decorate: <T, Arguments extends any[]>(options: CacheOptions | number | null, fn: (...args: Arguments) => T | Promise<T>) => {
|
|
23
|
+
(...args: Arguments): Promise<T>;
|
|
24
|
+
clear(...args: Arguments): Promise<void>;
|
|
25
|
+
};
|
|
23
26
|
};
|
package/dist/cache.js
CHANGED
|
@@ -69,11 +69,14 @@ export function createCache(adapter) {
|
|
|
69
69
|
return result;
|
|
70
70
|
}
|
|
71
71
|
function cachedFn(options, fn) {
|
|
72
|
-
|
|
72
|
+
const getCacheKey = (...args) => {
|
|
73
73
|
const baseKey = typeof options === 'object' && options != null
|
|
74
74
|
? options.key
|
|
75
75
|
: undefined;
|
|
76
|
-
|
|
76
|
+
return `${baseKey ?? Buffer.from(fn.toString()).toString('hex')}-${hashKey(args)}`;
|
|
77
|
+
};
|
|
78
|
+
const wrapped = async (...args) => {
|
|
79
|
+
const cacheKey = getCacheKey(...args);
|
|
77
80
|
const cachedValue = await adapter.get(cacheKey);
|
|
78
81
|
if (cachedValue != null) {
|
|
79
82
|
return cachedValue;
|
|
@@ -85,6 +88,8 @@ export function createCache(adapter) {
|
|
|
85
88
|
await adapter.set(cacheKey, result, expiresMs);
|
|
86
89
|
return result;
|
|
87
90
|
};
|
|
91
|
+
wrapped.clear = (...args) => adapter.clear(getCacheKey(...args));
|
|
92
|
+
return wrapped;
|
|
88
93
|
}
|
|
89
94
|
return {
|
|
90
95
|
set: adapter.set.bind(adapter),
|
|
@@ -94,3 +99,22 @@ export function createCache(adapter) {
|
|
|
94
99
|
decorate: cachedFn,
|
|
95
100
|
};
|
|
96
101
|
}
|
|
102
|
+
function hashKey(obj) {
|
|
103
|
+
return JSON.stringify(obj, (key, value) => {
|
|
104
|
+
if (value === null || value === undefined) {
|
|
105
|
+
return String(value);
|
|
106
|
+
}
|
|
107
|
+
if (typeof value === 'object') {
|
|
108
|
+
if (Array.isArray(value)) {
|
|
109
|
+
return value;
|
|
110
|
+
}
|
|
111
|
+
return Object.keys(value)
|
|
112
|
+
.sort()
|
|
113
|
+
.reduce((result, item) => {
|
|
114
|
+
result[item] = value[item];
|
|
115
|
+
return result;
|
|
116
|
+
}, {});
|
|
117
|
+
}
|
|
118
|
+
return value;
|
|
119
|
+
});
|
|
120
|
+
}
|
package/dist/config.d.ts
CHANGED
|
@@ -6,6 +6,7 @@ export declare const config: {
|
|
|
6
6
|
AUTH_TOKEN_EXPIRES_IN: number;
|
|
7
7
|
AUTH_TEMP_TOKEN_EXPIRES_IN: number;
|
|
8
8
|
AUTH_SECRET: string;
|
|
9
|
+
AUTH_COOKIE_SAME_SITE: string;
|
|
9
10
|
REDIS_URL: string;
|
|
10
11
|
REDIS_KEY_PREFIX: string;
|
|
11
12
|
POSTGRES_URL: string;
|
|
@@ -37,6 +38,7 @@ export declare function extendConfig<T extends Record<string, unknown>>(appConfi
|
|
|
37
38
|
AUTH_TOKEN_EXPIRES_IN: number;
|
|
38
39
|
AUTH_TEMP_TOKEN_EXPIRES_IN: number;
|
|
39
40
|
AUTH_SECRET: string;
|
|
41
|
+
AUTH_COOKIE_SAME_SITE: string;
|
|
40
42
|
REDIS_URL: string;
|
|
41
43
|
REDIS_KEY_PREFIX: string;
|
|
42
44
|
POSTGRES_URL: string;
|
package/dist/config.js
CHANGED
|
@@ -9,6 +9,7 @@ const baseConfig = {
|
|
|
9
9
|
AUTH_TOKEN_EXPIRES_IN: readEnv.number('AUTH_TOKEN_EXPIRES', 3600 * 24 * 30), // 30 days
|
|
10
10
|
AUTH_TEMP_TOKEN_EXPIRES_IN: readEnv.number('AUTH_TEMP_TOKEN_EXPIRES', 3600),
|
|
11
11
|
AUTH_SECRET: readEnv('AUTH_JWT_SECRET', ''),
|
|
12
|
+
AUTH_COOKIE_SAME_SITE: readEnv('AUTH_COOKIE_SAME_SITE', 'strict'),
|
|
12
13
|
REDIS_URL: readEnv('REDIS_URL', ''),
|
|
13
14
|
REDIS_KEY_PREFIX: readEnv('REDIS_KEY_PREFIX', ''),
|
|
14
15
|
POSTGRES_URL: readEnv('POSTGRES_URL', ''),
|