@shware/security 3.3.1 → 3.4.0
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/README.md +353 -23
- package/dist/auth/index.cjs +1 -1
- package/dist/auth/index.cjs.map +1 -1
- package/dist/auth/index.d.cts +2 -3
- package/dist/auth/index.d.cts.map +1 -1
- package/dist/auth/index.d.mts +2 -3
- package/dist/auth/index.d.mts.map +1 -1
- package/dist/auth/index.mjs +1 -1
- package/dist/auth/index.mjs.map +1 -1
- package/dist/auth/types.d.cts +4 -5
- package/dist/auth/types.d.cts.map +1 -1
- package/dist/auth/types.d.mts +4 -5
- package/dist/auth/types.d.mts.map +1 -1
- package/dist/core/index.d.cts +6 -7
- package/dist/core/index.d.cts.map +1 -1
- package/dist/core/index.d.mts +6 -7
- package/dist/core/index.d.mts.map +1 -1
- package/dist/email/schema.d.cts +2 -3
- package/dist/email/schema.d.cts.map +1 -1
- package/dist/email/schema.d.mts +2 -3
- package/dist/email/schema.d.mts.map +1 -1
- package/dist/oauth2/client.d.cts +3 -4
- package/dist/oauth2/client.d.cts.map +1 -1
- package/dist/oauth2/client.d.mts +3 -4
- package/dist/oauth2/client.d.mts.map +1 -1
- package/dist/oauth2/error.d.cts +3 -4
- package/dist/oauth2/error.d.cts.map +1 -1
- package/dist/oauth2/error.d.mts +3 -4
- package/dist/oauth2/error.d.mts.map +1 -1
- package/dist/oauth2/provider/apple-client-secret.d.cts +2 -3
- package/dist/oauth2/provider/apple-client-secret.d.cts.map +1 -1
- package/dist/oauth2/provider/apple-client-secret.d.mts +2 -3
- package/dist/oauth2/provider/apple-client-secret.d.mts.map +1 -1
- package/dist/oauth2/provider/apple.d.cts +6 -7
- package/dist/oauth2/provider/apple.d.cts.map +1 -1
- package/dist/oauth2/provider/apple.d.mts +6 -7
- package/dist/oauth2/provider/apple.d.mts.map +1 -1
- package/dist/oauth2/provider/common.d.cts +6 -6
- package/dist/oauth2/provider/common.d.cts.map +1 -1
- package/dist/oauth2/provider/common.d.mts +6 -6
- package/dist/oauth2/provider/common.d.mts.map +1 -1
- package/dist/oauth2/provider/facebook.d.cts +6 -7
- package/dist/oauth2/provider/facebook.d.cts.map +1 -1
- package/dist/oauth2/provider/facebook.d.mts +6 -7
- package/dist/oauth2/provider/facebook.d.mts.map +1 -1
- package/dist/oauth2/provider/github.d.cts +4 -5
- package/dist/oauth2/provider/github.d.cts.map +1 -1
- package/dist/oauth2/provider/github.d.mts +4 -5
- package/dist/oauth2/provider/github.d.mts.map +1 -1
- package/dist/oauth2/provider/google.d.cts +6 -7
- package/dist/oauth2/provider/google.d.cts.map +1 -1
- package/dist/oauth2/provider/google.d.mts +6 -7
- package/dist/oauth2/provider/google.d.mts.map +1 -1
- package/dist/oauth2/provider/wechat.d.cts +5 -6
- package/dist/oauth2/provider/wechat.d.cts.map +1 -1
- package/dist/oauth2/provider/wechat.d.mts +5 -6
- package/dist/oauth2/provider/wechat.d.mts.map +1 -1
- package/dist/oauth2/provider/x.d.cts +7 -7
- package/dist/oauth2/provider/x.d.cts.map +1 -1
- package/dist/oauth2/provider/x.d.mts +7 -7
- package/dist/oauth2/provider/x.d.mts.map +1 -1
- package/dist/oauth2/types.d.cts +18 -18
- package/dist/oauth2/types.d.cts.map +1 -1
- package/dist/oauth2/types.d.mts +18 -18
- package/dist/oauth2/types.d.mts.map +1 -1
- package/dist/session/common.d.cts +3 -4
- package/dist/session/common.d.cts.map +1 -1
- package/dist/session/common.d.mts +3 -4
- package/dist/session/common.d.mts.map +1 -1
- package/dist/session/db.cjs +1 -1
- package/dist/session/db.cjs.map +1 -1
- package/dist/session/db.d.cts +3 -3
- package/dist/session/db.d.cts.map +1 -1
- package/dist/session/db.d.mts +3 -3
- package/dist/session/db.d.mts.map +1 -1
- package/dist/session/db.mjs +1 -1
- package/dist/session/db.mjs.map +1 -1
- package/dist/session/map-session.d.cts +1 -2
- package/dist/session/map-session.d.cts.map +1 -1
- package/dist/session/map-session.d.mts +1 -2
- package/dist/session/map-session.d.mts.map +1 -1
- package/dist/session/redis.cjs +1 -1
- package/dist/session/redis.cjs.map +1 -1
- package/dist/session/redis.d.cts +3 -3
- package/dist/session/redis.d.cts.map +1 -1
- package/dist/session/redis.d.mts +3 -3
- package/dist/session/redis.d.mts.map +1 -1
- package/dist/session/redis.mjs +1 -1
- package/dist/session/redis.mjs.map +1 -1
- package/dist/session/types.d.cts +6 -7
- package/dist/session/types.d.cts.map +1 -1
- package/dist/session/types.d.mts +6 -7
- package/dist/session/types.d.mts.map +1 -1
- package/dist/utils/http.d.cts +7 -7
- package/dist/utils/http.d.cts.map +1 -1
- package/dist/utils/http.d.mts +7 -7
- package/dist/utils/http.d.mts.map +1 -1
- package/dist/utils/oauth2.d.cts +1 -2
- package/dist/utils/oauth2.d.cts.map +1 -1
- package/dist/utils/oauth2.d.mts +1 -2
- package/dist/utils/oauth2.d.mts.map +1 -1
- package/dist/utils/timing.d.cts +2 -2
- package/dist/utils/timing.d.cts.map +1 -1
- package/dist/utils/timing.d.mts +2 -2
- package/dist/utils/timing.d.mts.map +1 -1
- package/dist/utils/valid.d.cts +4 -4
- package/dist/utils/valid.d.cts.map +1 -1
- package/dist/utils/valid.d.mts +4 -4
- package/dist/utils/valid.d.mts.map +1 -1
- package/package.json +17 -10
package/dist/session/redis.d.mts
CHANGED
|
@@ -24,7 +24,7 @@ declare class RedisSession implements Session {
|
|
|
24
24
|
setAttribute(name: string, value: string): void;
|
|
25
25
|
removeAttribute(name: string): void;
|
|
26
26
|
}
|
|
27
|
-
declare class RedisIndexedSessionRepository implements SessionRepository<RedisSession> {
|
|
27
|
+
export declare class RedisIndexedSessionRepository implements SessionRepository<RedisSession> {
|
|
28
28
|
private readonly redis;
|
|
29
29
|
private readonly namespace;
|
|
30
30
|
private readonly expirationStore;
|
|
@@ -46,7 +46,7 @@ declare class RedisIndexedSessionRepository implements SessionRepository<RedisSe
|
|
|
46
46
|
findByPrincipalName(principalName: string): Promise<Map<string, RedisSession>>;
|
|
47
47
|
cleanupExpiredSessions(cleanupCount?: number): Promise<void>;
|
|
48
48
|
}
|
|
49
|
-
declare class RedisKVRepository implements KVRepository {
|
|
49
|
+
export declare class RedisKVRepository implements KVRepository {
|
|
50
50
|
private readonly redis;
|
|
51
51
|
constructor(redis: Redis);
|
|
52
52
|
setItem(key: string, value: string, expiresIn?: number): Promise<void>;
|
|
@@ -54,5 +54,5 @@ declare class RedisKVRepository implements KVRepository {
|
|
|
54
54
|
removeItem(key: string): Promise<void>;
|
|
55
55
|
}
|
|
56
56
|
//#endregion
|
|
57
|
-
export {
|
|
57
|
+
export {};
|
|
58
58
|
//# sourceMappingURL=redis.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"redis.d.mts","names":[],"sources":["../../src/session/redis.ts"],"mappings":";;;;cAWM,wBAAwB;mBACX;EAEV;EACA,OAAK;EACL;EACA;EACA;EAEP,YAAY,QAAQ,YAAY;EAiBhC,sBAAsB;EAKtB,oBAAoB;EAKpB;EAIA;EAIA;EAIA;EAIA;EAIA,uBAAuB;EAKvB;EAIA,aAAa;EAIb;EAIA,aAAa,cAAc;EAK3B,gBAAgB;;
|
|
1
|
+
{"version":3,"file":"redis.d.mts","names":[],"sources":["../../src/session/redis.ts"],"mappings":";;;;cAWM,wBAAwB;mBACX;EAEV;EACA,OAAK;EACL;EACA;EACA;EAEP,YAAY,QAAQ,YAAY;EAiBhC,sBAAsB;EAKtB,oBAAoB;EAKpB;EAIA;EAIA;EAIA;EAIA;EAIA,uBAAuB;EAKvB;EAIA,aAAa;EAIb;EAIA,aAAa,cAAc;EAK3B,gBAAgB;;qBA6DL,yCAAyC,kBAAkB;mBACrD;mBACA;mBACA;UAET;EAER,YAAY,OAAO,OAAO,YAAW;EAMrC,8BAA8B;UAItB;UAIA;UAIA;UAIA;UAIM;UAyBA;UAgEA;EAuBd,iBAAa;EAMP,KAAK,SAAS,eAAY;EAK1B,SAAS,oBAAoB,QAAQ;EAIrC,WAAW,oBAAiB;EAkB5B,6BAA6B,mBAAmB,qBAAkB,QAAA,YAAA;EAoBlE,oBAAoB,wBAAqB,QAAA,YAAA;EAIzC,uBAAuB,wBAAqB;;qBAKvC,6BAA6B;mBACvB;EAEjB,YAAY,OAAO;EAIb,QAAQ,aAAa,eAAe,qBAAkB;EAQtD,QAAQ,cAAc;EAItB,WAAW,cAAW"}
|
package/dist/session/redis.mjs
CHANGED
|
@@ -237,7 +237,7 @@ var RedisIndexedSessionRepository = class {
|
|
|
237
237
|
await this.save(session);
|
|
238
238
|
}
|
|
239
239
|
async findByIndexNameAndIndexValue(indexName, indexValue) {
|
|
240
|
-
if (indexName !== PRINCIPAL_NAME_INDEX_NAME) return /* @__PURE__ */ new Map();
|
|
240
|
+
if (indexName !== "org.springframework.session.FindByIndexNameSessionRepository.PRINCIPAL_NAME_INDEX_NAME") return /* @__PURE__ */ new Map();
|
|
241
241
|
const principalKey = this.getPrincipalKey(indexValue);
|
|
242
242
|
const sessionIds = await this.redis.smembers(principalKey);
|
|
243
243
|
if (sessionIds.length === 0) return /* @__PURE__ */ new Map();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"redis.mjs","names":[],"sources":["../../src/session/redis.ts"],"sourcesContent":["import type { Redis } from 'ioredis';\nimport { PRINCIPAL_NAME_INDEX_NAME, SPRING_SECURITY_CONTEXT, resolveIndexesFor } from './common';\nimport { MapSession } from './map-session';\nimport type { KVRepository, Namespace, Session, SessionRepository } from './types';\n\nconst CREATION_TIME_KEY = 'creationTime';\nconst LAST_ACCESSED_TIME_KEY = 'lastAccessedTime';\nconst MAX_INACTIVE_INTERVAL_KEY = 'maxInactiveInterval';\nconst ATTRIBUTE_PREFIX = 'sessionAttr:';\nconst SESSION_EXPIRES_PREFIX = 'expires:';\n\nclass RedisSession implements Session {\n private readonly cached: MapSession;\n\n public isNew: boolean;\n public delta = new Map<string, string | number | null>();\n public originalSessionId: string;\n public originalPrincipalName: string | null;\n public originalLastAccessTime: number | null = null;\n\n constructor(cached: MapSession, isNew: boolean) {\n this.cached = cached;\n this.isNew = isNew;\n this.originalSessionId = cached.getId();\n this.originalPrincipalName = resolveIndexesFor(this);\n\n if (isNew) {\n this.delta.set(CREATION_TIME_KEY, cached.getCreationTime());\n this.delta.set(LAST_ACCESSED_TIME_KEY, cached.getLastAccessedTime());\n this.delta.set(MAX_INACTIVE_INTERVAL_KEY, cached.getMaxInactiveInterval());\n this.cached.getAttributeNames().forEach((name) => {\n const value = this.cached.getAttribute(name);\n if (value) this.delta.set(this.getSessionAttrNameKey(name), value);\n });\n }\n }\n\n getSessionAttrNameKey(name: string) {\n return ATTRIBUTE_PREFIX + name;\n }\n\n // override\n setLastAccessedTime(lastAccessedTime: number) {\n this.cached.setLastAccessedTime(lastAccessedTime);\n this.delta.set(LAST_ACCESSED_TIME_KEY, lastAccessedTime);\n }\n\n isExpired() {\n return this.cached.isExpired();\n }\n\n getCreationTime() {\n return this.cached.getCreationTime();\n }\n\n getId() {\n return this.cached.getId();\n }\n\n changeSessionId() {\n return this.cached.changeSessionId();\n }\n\n getLastAccessedTime() {\n return this.cached.getLastAccessedTime();\n }\n\n setMaxInactiveInterval(interval: number) {\n this.cached.setMaxInactiveInterval(interval);\n this.delta.set(MAX_INACTIVE_INTERVAL_KEY, interval);\n }\n\n getMaxInactiveInterval() {\n return this.cached.getMaxInactiveInterval();\n }\n\n getAttribute(name: string) {\n return this.cached.getAttribute(name);\n }\n\n getAttributeNames() {\n return this.cached.getAttributeNames();\n }\n\n setAttribute(name: string, value: string) {\n this.cached.setAttribute(name, value);\n this.delta.set(this.getSessionAttrNameKey(name), value);\n }\n\n removeAttribute(name: string) {\n this.cached.removeAttribute(name);\n this.delta.set(this.getSessionAttrNameKey(name), null);\n }\n}\n\ninterface RedisSessionExpirationStore {\n save(session: RedisSession): Promise<void>;\n remove(sessionId: string): Promise<void>;\n rename(session: RedisSession): Promise<void>;\n cleanupExpiredSessions(cleanupCount?: number): Promise<void>;\n}\n\nclass SortedSetRedisSessionExpirationStore implements RedisSessionExpirationStore {\n private readonly redis: Redis;\n private readonly namespace: Namespace;\n private readonly expirationsKey: string;\n\n constructor(redis: Redis, namespace: Namespace) {\n this.redis = redis;\n this.namespace = namespace;\n this.expirationsKey = `${this.namespace}:sessions:expirations`;\n }\n\n getSessionKey(sessionId: string) {\n return `${this.namespace}:sessions:${sessionId}`;\n }\n\n async save(session: RedisSession) {\n const expirationInMillis =\n session.getLastAccessedTime() + session.getMaxInactiveInterval() * 1000;\n await this.redis.zadd(this.expirationsKey, expirationInMillis, session.getId());\n }\n\n async remove(sessionId: string) {\n await this.redis.zrem(this.expirationsKey, sessionId);\n }\n\n async rename(session: RedisSession) {\n if (session.originalSessionId === session.getId()) return;\n await this.remove(session.originalSessionId);\n await this.save(session);\n }\n\n async cleanupExpiredSessions(cleanupCount = 100) {\n const key = this.expirationsKey;\n const score = Date.now();\n const sessionIds = await this.redis.zrevrangebyscore(key, score, 0, 'LIMIT', 0, cleanupCount);\n if (sessionIds.length === 0) return;\n for (const sessionId of sessionIds) {\n const sessionKey = this.getSessionKey(sessionId);\n // Checks if the session exists. By trying to access the session we only trigger a deletion\n // if the TTL is expired.\n await this.redis.exists(sessionKey);\n }\n }\n}\n\n// <spring:session:sessions:uuid, hash<session>> + 300s\n// <spring:session:sessions:expirations, sorted_set<uuid>>\n// <spring:session:sessions:expires:uuid, string<empty>>: for expire check & event\nexport class RedisIndexedSessionRepository implements SessionRepository<RedisSession> {\n private readonly redis: Redis;\n private readonly namespace: Namespace;\n private readonly expirationStore: RedisSessionExpirationStore;\n\n private defaultMaxInactiveInterval = 1800;\n\n constructor(redis: Redis, namespace: Namespace = 'spring:session') {\n this.redis = redis;\n this.namespace = namespace;\n this.expirationStore = new SortedSetRedisSessionExpirationStore(redis, namespace);\n }\n\n setDefaultMaxInactiveInterval(interval: number) {\n this.defaultMaxInactiveInterval = interval;\n }\n\n private getSessionKey(sessionId: string) {\n return `${this.namespace}:sessions:${sessionId}`;\n }\n\n private getExpiredKey(sessionId: string) {\n return `${this.namespace}:sessions:expires:${sessionId}`;\n }\n\n private getSessionAttrNameKey(name: string) {\n return ATTRIBUTE_PREFIX + name;\n }\n\n private getPrincipalKey(principalName: string) {\n return `${this.namespace}:index:${PRINCIPAL_NAME_INDEX_NAME}:${principalName}`;\n }\n\n private async getSession(id: string, allowExpired: boolean): Promise<RedisSession | null> {\n const key = this.getSessionKey(id);\n const entries = await this.redis.hgetall(key);\n if (Object.keys(entries).length === 0) return null;\n const loaded = new MapSession(id);\n if (!entries.creationTime) throw new Error('creationTime attribute not found');\n if (!entries.lastAccessedTime) throw new Error('lastAccessedTime attribute not found');\n if (!entries.maxInactiveInterval) throw new Error('maxInactiveInterval attribute not found');\n\n loaded.setCreationTime(Number(entries.creationTime));\n loaded.setLastAccessedTime(Number(entries.lastAccessedTime));\n loaded.setMaxInactiveInterval(Number(entries.maxInactiveInterval));\n\n for (const [key, value] of Object.entries(entries)) {\n if (key.startsWith(ATTRIBUTE_PREFIX)) {\n loaded.setAttribute(key.slice(ATTRIBUTE_PREFIX.length), value);\n }\n }\n\n if (!allowExpired && loaded.isExpired()) return null;\n const result = new RedisSession(loaded, false);\n result.originalLastAccessTime = loaded.getLastAccessedTime();\n return result;\n }\n\n private async saveDelta(session: RedisSession) {\n if (session.delta.size === 0) return;\n const sessionId = session.getId();\n const delta = new Map<string, string | number>();\n const removes: string[] = [];\n session.delta.forEach((value, key) => {\n if (value !== null) delta.set(key, value);\n else removes.push(key);\n });\n\n if (delta.size !== 0) {\n await this.redis.hset(this.getSessionKey(sessionId), delta);\n }\n if (removes.length !== 0) {\n await this.redis.hdel(this.getSessionKey(sessionId), ...removes);\n }\n\n const principalSessionKey = this.getSessionAttrNameKey(PRINCIPAL_NAME_INDEX_NAME);\n const securityPrincipalSessionKey = this.getSessionAttrNameKey(SPRING_SECURITY_CONTEXT);\n if (session.delta.has(principalSessionKey) || session.delta.has(securityPrincipalSessionKey)) {\n if (session.originalPrincipalName !== null) {\n const originalPrincipalRedisKey = this.getPrincipalKey(session.originalPrincipalName);\n await this.redis.srem(originalPrincipalRedisKey, sessionId);\n }\n const principal = resolveIndexesFor(session);\n session.originalPrincipalName = principal;\n if (principal !== null) {\n const principalRedisKey = this.getPrincipalKey(principal);\n await this.redis.sadd(principalRedisKey, sessionId);\n }\n }\n\n if (session.isNew) {\n // here your can send session created message to channel\n session.isNew = false;\n }\n\n const sessionExpireInSeconds = session.getMaxInactiveInterval();\n\n // createShadowKey start\n const keyToExpire = SESSION_EXPIRES_PREFIX + session.getId();\n const sessionKey = this.getSessionKey(keyToExpire);\n\n if (sessionExpireInSeconds < 0) {\n await this.redis.append(sessionKey, '');\n await this.redis.persist(sessionKey);\n await this.redis.persist(this.getSessionKey(session.getId()));\n } else if (sessionExpireInSeconds === 0) {\n await this.redis.del(sessionKey);\n } else {\n await this.redis.append(sessionKey, '');\n await this.redis.expire(sessionKey, sessionExpireInSeconds);\n }\n // createShadowKey end\n\n if (sessionExpireInSeconds > 0) {\n const fiveMinutesAfterExpires = sessionExpireInSeconds + 5 * 60;\n await this.redis.expire(this.getSessionKey(session.getId()), fiveMinutesAfterExpires);\n }\n\n await this.expirationStore.save(session);\n session.delta.clear();\n }\n\n private async saveChangeSessionId(session: RedisSession) {\n const sessionId = session.getId();\n if (sessionId === session.originalSessionId) return;\n if (!session.isNew) {\n const originalSessionIdKey = this.getSessionKey(session.originalSessionId);\n const sessionIdKey = this.getSessionKey(sessionId);\n const originalExpiredKey = this.getExpiredKey(session.originalSessionId);\n const expiredKey = this.getExpiredKey(sessionId);\n\n await this.redis.rename(originalSessionIdKey, sessionIdKey);\n await this.redis.rename(originalExpiredKey, expiredKey);\n\n if (session.originalPrincipalName !== null) {\n const originalPrincipalRedisKey = this.getPrincipalKey(session.originalPrincipalName);\n await this.redis.srem(originalPrincipalRedisKey, session.originalSessionId);\n await this.redis.sadd(originalPrincipalRedisKey, sessionId);\n }\n await this.expirationStore.rename(session);\n }\n session.originalSessionId = sessionId;\n }\n\n // override\n createSession() {\n const cached = new MapSession();\n cached.setMaxInactiveInterval(this.defaultMaxInactiveInterval);\n return new RedisSession(cached, true);\n }\n\n async save(session: RedisSession) {\n await this.saveChangeSessionId(session);\n await this.saveDelta(session);\n }\n\n async findById(sessionId: string): Promise<RedisSession | null> {\n return this.getSession(sessionId, false);\n }\n\n async deleteById(sessionId: string) {\n const session = await this.getSession(sessionId, true);\n if (!session) return;\n // 1. cleanup index\n const principal = resolveIndexesFor(session);\n if (principal !== null) {\n await this.redis.srem(this.getPrincipalKey(principal), sessionId);\n }\n // 2. delete in set\n await this.expirationStore.remove(sessionId);\n // 3. delete expired key\n const expiredKey = this.getExpiredKey(sessionId);\n await this.redis.del(expiredKey);\n\n session.setMaxInactiveInterval(0);\n await this.save(session);\n }\n\n async findByIndexNameAndIndexValue(indexName: string, indexValue: string) {\n if (indexName !== PRINCIPAL_NAME_INDEX_NAME) {\n return new Map<string, RedisSession>();\n }\n\n const principalKey = this.getPrincipalKey(indexValue);\n const sessionIds = await this.redis.smembers(principalKey);\n if (sessionIds.length === 0) {\n return new Map<string, RedisSession>();\n }\n const sessions = new Map<string, RedisSession>();\n for (const sessionId of sessionIds) {\n const session = await this.findById(sessionId);\n if (session !== null) {\n sessions.set(sessionId, session);\n }\n }\n return sessions;\n }\n\n async findByPrincipalName(principalName: string) {\n return this.findByIndexNameAndIndexValue(PRINCIPAL_NAME_INDEX_NAME, principalName);\n }\n\n async cleanupExpiredSessions(cleanupCount?: number) {\n await this.expirationStore.cleanupExpiredSessions(cleanupCount);\n }\n}\n\nexport class RedisKVRepository implements KVRepository {\n private readonly redis: Redis;\n\n constructor(redis: Redis) {\n this.redis = redis;\n }\n\n async setItem(key: string, value: string, expiresIn?: number) {\n if (expiresIn) {\n await this.redis.set(key, value, 'EX', expiresIn);\n } else {\n await this.redis.set(key, value);\n }\n }\n\n async getItem(key: string): Promise<string | null> {\n return this.redis.get(key);\n }\n\n async removeItem(key: string) {\n await this.redis.del(key);\n }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AACF;AAEA,IAAa,oBAAb,MAAuD;CACrD;CAEA,YAAY,OAAc;EACxB,KAAK,QAAQ;CACf;CAEA,MAAM,QAAQ,KAAa,OAAe,WAAoB;EAC5D,IAAI,WACF,MAAM,KAAK,MAAM,IAAI,KAAK,OAAO,MAAM,SAAS;OAEhD,MAAM,KAAK,MAAM,IAAI,KAAK,KAAK;CAEnC;CAEA,MAAM,QAAQ,KAAqC;EACjD,OAAO,KAAK,MAAM,IAAI,GAAG;CAC3B;CAEA,MAAM,WAAW,KAAa;EAC5B,MAAM,KAAK,MAAM,IAAI,GAAG;CAC1B;AACF"}
|
|
1
|
+
{"version":3,"file":"redis.mjs","names":[],"sources":["../../src/session/redis.ts"],"sourcesContent":["import type { Redis } from 'ioredis';\nimport { PRINCIPAL_NAME_INDEX_NAME, SPRING_SECURITY_CONTEXT, resolveIndexesFor } from './common';\nimport { MapSession } from './map-session';\nimport type { KVRepository, Namespace, Session, SessionRepository } from './types';\n\nconst CREATION_TIME_KEY = 'creationTime';\nconst LAST_ACCESSED_TIME_KEY = 'lastAccessedTime';\nconst MAX_INACTIVE_INTERVAL_KEY = 'maxInactiveInterval';\nconst ATTRIBUTE_PREFIX = 'sessionAttr:';\nconst SESSION_EXPIRES_PREFIX = 'expires:';\n\nclass RedisSession implements Session {\n private readonly cached: MapSession;\n\n public isNew: boolean;\n public delta = new Map<string, string | number | null>();\n public originalSessionId: string;\n public originalPrincipalName: string | null;\n public originalLastAccessTime: number | null = null;\n\n constructor(cached: MapSession, isNew: boolean) {\n this.cached = cached;\n this.isNew = isNew;\n this.originalSessionId = cached.getId();\n this.originalPrincipalName = resolveIndexesFor(this);\n\n if (isNew) {\n this.delta.set(CREATION_TIME_KEY, cached.getCreationTime());\n this.delta.set(LAST_ACCESSED_TIME_KEY, cached.getLastAccessedTime());\n this.delta.set(MAX_INACTIVE_INTERVAL_KEY, cached.getMaxInactiveInterval());\n this.cached.getAttributeNames().forEach((name) => {\n const value = this.cached.getAttribute(name);\n if (value) this.delta.set(this.getSessionAttrNameKey(name), value);\n });\n }\n }\n\n getSessionAttrNameKey(name: string) {\n return ATTRIBUTE_PREFIX + name;\n }\n\n // override\n setLastAccessedTime(lastAccessedTime: number) {\n this.cached.setLastAccessedTime(lastAccessedTime);\n this.delta.set(LAST_ACCESSED_TIME_KEY, lastAccessedTime);\n }\n\n isExpired() {\n return this.cached.isExpired();\n }\n\n getCreationTime() {\n return this.cached.getCreationTime();\n }\n\n getId() {\n return this.cached.getId();\n }\n\n changeSessionId() {\n return this.cached.changeSessionId();\n }\n\n getLastAccessedTime() {\n return this.cached.getLastAccessedTime();\n }\n\n setMaxInactiveInterval(interval: number) {\n this.cached.setMaxInactiveInterval(interval);\n this.delta.set(MAX_INACTIVE_INTERVAL_KEY, interval);\n }\n\n getMaxInactiveInterval() {\n return this.cached.getMaxInactiveInterval();\n }\n\n getAttribute(name: string) {\n return this.cached.getAttribute(name);\n }\n\n getAttributeNames() {\n return this.cached.getAttributeNames();\n }\n\n setAttribute(name: string, value: string) {\n this.cached.setAttribute(name, value);\n this.delta.set(this.getSessionAttrNameKey(name), value);\n }\n\n removeAttribute(name: string) {\n this.cached.removeAttribute(name);\n this.delta.set(this.getSessionAttrNameKey(name), null);\n }\n}\n\ninterface RedisSessionExpirationStore {\n save(session: RedisSession): Promise<void>;\n remove(sessionId: string): Promise<void>;\n rename(session: RedisSession): Promise<void>;\n cleanupExpiredSessions(cleanupCount?: number): Promise<void>;\n}\n\nclass SortedSetRedisSessionExpirationStore implements RedisSessionExpirationStore {\n private readonly redis: Redis;\n private readonly namespace: Namespace;\n private readonly expirationsKey: string;\n\n constructor(redis: Redis, namespace: Namespace) {\n this.redis = redis;\n this.namespace = namespace;\n this.expirationsKey = `${this.namespace}:sessions:expirations`;\n }\n\n getSessionKey(sessionId: string) {\n return `${this.namespace}:sessions:${sessionId}`;\n }\n\n async save(session: RedisSession) {\n const expirationInMillis =\n session.getLastAccessedTime() + session.getMaxInactiveInterval() * 1000;\n await this.redis.zadd(this.expirationsKey, expirationInMillis, session.getId());\n }\n\n async remove(sessionId: string) {\n await this.redis.zrem(this.expirationsKey, sessionId);\n }\n\n async rename(session: RedisSession) {\n if (session.originalSessionId === session.getId()) return;\n await this.remove(session.originalSessionId);\n await this.save(session);\n }\n\n async cleanupExpiredSessions(cleanupCount = 100) {\n const key = this.expirationsKey;\n const score = Date.now();\n const sessionIds = await this.redis.zrevrangebyscore(key, score, 0, 'LIMIT', 0, cleanupCount);\n if (sessionIds.length === 0) return;\n for (const sessionId of sessionIds) {\n const sessionKey = this.getSessionKey(sessionId);\n // Checks if the session exists. By trying to access the session we only trigger a deletion\n // if the TTL is expired.\n await this.redis.exists(sessionKey);\n }\n }\n}\n\n// <spring:session:sessions:uuid, hash<session>> + 300s\n// <spring:session:sessions:expirations, sorted_set<uuid>>\n// <spring:session:sessions:expires:uuid, string<empty>>: for expire check & event\nexport class RedisIndexedSessionRepository implements SessionRepository<RedisSession> {\n private readonly redis: Redis;\n private readonly namespace: Namespace;\n private readonly expirationStore: RedisSessionExpirationStore;\n\n private defaultMaxInactiveInterval = 1800;\n\n constructor(redis: Redis, namespace: Namespace = 'spring:session') {\n this.redis = redis;\n this.namespace = namespace;\n this.expirationStore = new SortedSetRedisSessionExpirationStore(redis, namespace);\n }\n\n setDefaultMaxInactiveInterval(interval: number) {\n this.defaultMaxInactiveInterval = interval;\n }\n\n private getSessionKey(sessionId: string) {\n return `${this.namespace}:sessions:${sessionId}`;\n }\n\n private getExpiredKey(sessionId: string) {\n return `${this.namespace}:sessions:expires:${sessionId}`;\n }\n\n private getSessionAttrNameKey(name: string) {\n return ATTRIBUTE_PREFIX + name;\n }\n\n private getPrincipalKey(principalName: string) {\n return `${this.namespace}:index:${PRINCIPAL_NAME_INDEX_NAME}:${principalName}`;\n }\n\n private async getSession(id: string, allowExpired: boolean): Promise<RedisSession | null> {\n const key = this.getSessionKey(id);\n const entries = await this.redis.hgetall(key);\n if (Object.keys(entries).length === 0) return null;\n const loaded = new MapSession(id);\n if (!entries.creationTime) throw new Error('creationTime attribute not found');\n if (!entries.lastAccessedTime) throw new Error('lastAccessedTime attribute not found');\n if (!entries.maxInactiveInterval) throw new Error('maxInactiveInterval attribute not found');\n\n loaded.setCreationTime(Number(entries.creationTime));\n loaded.setLastAccessedTime(Number(entries.lastAccessedTime));\n loaded.setMaxInactiveInterval(Number(entries.maxInactiveInterval));\n\n for (const [key, value] of Object.entries(entries)) {\n if (key.startsWith(ATTRIBUTE_PREFIX)) {\n loaded.setAttribute(key.slice(ATTRIBUTE_PREFIX.length), value);\n }\n }\n\n if (!allowExpired && loaded.isExpired()) return null;\n const result = new RedisSession(loaded, false);\n result.originalLastAccessTime = loaded.getLastAccessedTime();\n return result;\n }\n\n private async saveDelta(session: RedisSession) {\n if (session.delta.size === 0) return;\n const sessionId = session.getId();\n const delta = new Map<string, string | number>();\n const removes: string[] = [];\n session.delta.forEach((value, key) => {\n if (value !== null) delta.set(key, value);\n else removes.push(key);\n });\n\n if (delta.size !== 0) {\n await this.redis.hset(this.getSessionKey(sessionId), delta);\n }\n if (removes.length !== 0) {\n await this.redis.hdel(this.getSessionKey(sessionId), ...removes);\n }\n\n const principalSessionKey = this.getSessionAttrNameKey(PRINCIPAL_NAME_INDEX_NAME);\n const securityPrincipalSessionKey = this.getSessionAttrNameKey(SPRING_SECURITY_CONTEXT);\n if (session.delta.has(principalSessionKey) || session.delta.has(securityPrincipalSessionKey)) {\n if (session.originalPrincipalName !== null) {\n const originalPrincipalRedisKey = this.getPrincipalKey(session.originalPrincipalName);\n await this.redis.srem(originalPrincipalRedisKey, sessionId);\n }\n const principal = resolveIndexesFor(session);\n session.originalPrincipalName = principal;\n if (principal !== null) {\n const principalRedisKey = this.getPrincipalKey(principal);\n await this.redis.sadd(principalRedisKey, sessionId);\n }\n }\n\n if (session.isNew) {\n // here your can send session created message to channel\n session.isNew = false;\n }\n\n const sessionExpireInSeconds = session.getMaxInactiveInterval();\n\n // createShadowKey start\n const keyToExpire = SESSION_EXPIRES_PREFIX + session.getId();\n const sessionKey = this.getSessionKey(keyToExpire);\n\n if (sessionExpireInSeconds < 0) {\n await this.redis.append(sessionKey, '');\n await this.redis.persist(sessionKey);\n await this.redis.persist(this.getSessionKey(session.getId()));\n } else if (sessionExpireInSeconds === 0) {\n await this.redis.del(sessionKey);\n } else {\n await this.redis.append(sessionKey, '');\n await this.redis.expire(sessionKey, sessionExpireInSeconds);\n }\n // createShadowKey end\n\n if (sessionExpireInSeconds > 0) {\n const fiveMinutesAfterExpires = sessionExpireInSeconds + 5 * 60;\n await this.redis.expire(this.getSessionKey(session.getId()), fiveMinutesAfterExpires);\n }\n\n await this.expirationStore.save(session);\n session.delta.clear();\n }\n\n private async saveChangeSessionId(session: RedisSession) {\n const sessionId = session.getId();\n if (sessionId === session.originalSessionId) return;\n if (!session.isNew) {\n const originalSessionIdKey = this.getSessionKey(session.originalSessionId);\n const sessionIdKey = this.getSessionKey(sessionId);\n const originalExpiredKey = this.getExpiredKey(session.originalSessionId);\n const expiredKey = this.getExpiredKey(sessionId);\n\n await this.redis.rename(originalSessionIdKey, sessionIdKey);\n await this.redis.rename(originalExpiredKey, expiredKey);\n\n if (session.originalPrincipalName !== null) {\n const originalPrincipalRedisKey = this.getPrincipalKey(session.originalPrincipalName);\n await this.redis.srem(originalPrincipalRedisKey, session.originalSessionId);\n await this.redis.sadd(originalPrincipalRedisKey, sessionId);\n }\n await this.expirationStore.rename(session);\n }\n session.originalSessionId = sessionId;\n }\n\n // override\n createSession() {\n const cached = new MapSession();\n cached.setMaxInactiveInterval(this.defaultMaxInactiveInterval);\n return new RedisSession(cached, true);\n }\n\n async save(session: RedisSession) {\n await this.saveChangeSessionId(session);\n await this.saveDelta(session);\n }\n\n async findById(sessionId: string): Promise<RedisSession | null> {\n return this.getSession(sessionId, false);\n }\n\n async deleteById(sessionId: string) {\n const session = await this.getSession(sessionId, true);\n if (!session) return;\n // 1. cleanup index\n const principal = resolveIndexesFor(session);\n if (principal !== null) {\n await this.redis.srem(this.getPrincipalKey(principal), sessionId);\n }\n // 2. delete in set\n await this.expirationStore.remove(sessionId);\n // 3. delete expired key\n const expiredKey = this.getExpiredKey(sessionId);\n await this.redis.del(expiredKey);\n\n session.setMaxInactiveInterval(0);\n await this.save(session);\n }\n\n async findByIndexNameAndIndexValue(indexName: string, indexValue: string) {\n if (indexName !== PRINCIPAL_NAME_INDEX_NAME) {\n return new Map<string, RedisSession>();\n }\n\n const principalKey = this.getPrincipalKey(indexValue);\n const sessionIds = await this.redis.smembers(principalKey);\n if (sessionIds.length === 0) {\n return new Map<string, RedisSession>();\n }\n const sessions = new Map<string, RedisSession>();\n for (const sessionId of sessionIds) {\n const session = await this.findById(sessionId);\n if (session !== null) {\n sessions.set(sessionId, session);\n }\n }\n return sessions;\n }\n\n async findByPrincipalName(principalName: string) {\n return this.findByIndexNameAndIndexValue(PRINCIPAL_NAME_INDEX_NAME, principalName);\n }\n\n async cleanupExpiredSessions(cleanupCount?: number) {\n await this.expirationStore.cleanupExpiredSessions(cleanupCount);\n }\n}\n\nexport class RedisKVRepository implements KVRepository {\n private readonly redis: Redis;\n\n constructor(redis: Redis) {\n this.redis = redis;\n }\n\n async setItem(key: string, value: string, expiresIn?: number) {\n if (expiresIn) {\n await this.redis.set(key, value, 'EX', expiresIn);\n } else {\n await this.redis.set(key, value);\n }\n }\n\n async getItem(key: string): Promise<string | null> {\n return this.redis.get(key);\n }\n\n async removeItem(key: string) {\n await this.redis.del(key);\n }\n}\n"],"mappings":";;;AAKA,MAAM,oBAAoB;AAC1B,MAAM,yBAAyB;AAC/B,MAAM,4BAA4B;AAClC,MAAM,mBAAmB;AACzB,MAAM,yBAAyB;AAE/B,IAAM,eAAN,MAAsC;CACpC;CAEA;CACA,wBAAe,IAAI,IAAoC;CACvD;CACA;CACA,yBAA+C;CAE/C,YAAY,QAAoB,OAAgB;EAC9C,KAAK,SAAS;EACd,KAAK,QAAQ;EACb,KAAK,oBAAoB,OAAO,MAAM;EACtC,KA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WAAW,KAAa;EAC5B,MAAM,KAAK,MAAM,IAAI,GAAG;CAC1B;AACF"}
|
package/dist/session/types.d.cts
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
import { Principal } from "../core/index.cjs";
|
|
2
2
|
//#region src/session/types.d.ts
|
|
3
|
-
interface Authentication extends Principal {
|
|
3
|
+
export interface Authentication extends Principal {
|
|
4
4
|
'@class': string;
|
|
5
5
|
principal?: Principal;
|
|
6
6
|
authorities?: string[];
|
|
7
7
|
credentials?: object;
|
|
8
8
|
details?: object;
|
|
9
9
|
}
|
|
10
|
-
interface SecurityContext {
|
|
10
|
+
export interface SecurityContext {
|
|
11
11
|
'@class': string;
|
|
12
12
|
authentication?: Authentication;
|
|
13
13
|
}
|
|
14
|
-
type Namespace = `${string}:session`;
|
|
15
|
-
interface Session {
|
|
14
|
+
export type Namespace = `${string}:session`;
|
|
15
|
+
export interface Session {
|
|
16
16
|
getId(): string;
|
|
17
17
|
changeSessionId(): string;
|
|
18
18
|
getAttribute(name: string): string | number | null;
|
|
@@ -26,7 +26,7 @@ interface Session {
|
|
|
26
26
|
setMaxInactiveInterval(interval: number): void;
|
|
27
27
|
isExpired(): boolean;
|
|
28
28
|
}
|
|
29
|
-
interface SessionRepository<S extends Session = Session> {
|
|
29
|
+
export interface SessionRepository<S extends Session = Session> {
|
|
30
30
|
createSession(): S;
|
|
31
31
|
save(session: S): Promise<void>;
|
|
32
32
|
findById(sessionId: string): Promise<S | null>;
|
|
@@ -35,11 +35,10 @@ interface SessionRepository<S extends Session = Session> {
|
|
|
35
35
|
findByPrincipalName(principalName: string): Promise<Map<string, S>>;
|
|
36
36
|
cleanupExpiredSessions(cleanupCount?: number): Promise<void>;
|
|
37
37
|
}
|
|
38
|
-
interface KVRepository {
|
|
38
|
+
export interface KVRepository {
|
|
39
39
|
setItem(key: string, value: string, expiresIn?: number): Promise<void>;
|
|
40
40
|
getItem(key: string): Promise<string | null>;
|
|
41
41
|
removeItem(key: string): Promise<void>;
|
|
42
42
|
}
|
|
43
43
|
//#endregion
|
|
44
|
-
export { Authentication, KVRepository, Namespace, SecurityContext, Session, SessionRepository };
|
|
45
44
|
//# sourceMappingURL=types.d.cts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.cts","names":[],"sources":["../../src/session/types.ts"],"mappings":";;
|
|
1
|
+
{"version":3,"file":"types.d.cts","names":[],"sources":["../../src/session/types.ts"],"mappings":";;iBAEiB,uBAAuB;EACtC;EACA,YAAY;EACZ;EACA;EACA;;iBAGe;EACf;EACA,iBAAiB;;YAGP;iBAGK;EACf;EACA;EAEA,aAAa;EACb;EACA,aAAa,cAAc;EAC3B,gBAAgB;EAEhB;EACA;EACA,oBAAoB;EAEpB;EACA,uBAAuB;EAEvB;;iBAGe,kBAAkB,UAAU,UAAU;EACrD,iBAAiB;EACjB,KAAK,SAAS,IAAI;EAClB,SAAS,oBAAoB,QAAQ;EACrC,WAAW,oBAAoB;EAG/B,6BAA6B,mBAAmB,qBAAqB,QAAQ,YAAY;EACzF,oBAAoB,wBAAwB,QAAQ,YAAY;EAGhE,uBAAuB,wBAAwB;;iBAGhC;EACf,QAAQ,aAAa,eAAe,qBAAqB;EACzD,QAAQ,cAAc;EACtB,WAAW,cAAc"}
|
package/dist/session/types.d.mts
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
import { Principal } from "../core/index.mjs";
|
|
2
2
|
//#region src/session/types.d.ts
|
|
3
|
-
interface Authentication extends Principal {
|
|
3
|
+
export interface Authentication extends Principal {
|
|
4
4
|
'@class': string;
|
|
5
5
|
principal?: Principal;
|
|
6
6
|
authorities?: string[];
|
|
7
7
|
credentials?: object;
|
|
8
8
|
details?: object;
|
|
9
9
|
}
|
|
10
|
-
interface SecurityContext {
|
|
10
|
+
export interface SecurityContext {
|
|
11
11
|
'@class': string;
|
|
12
12
|
authentication?: Authentication;
|
|
13
13
|
}
|
|
14
|
-
type Namespace = `${string}:session`;
|
|
15
|
-
interface Session {
|
|
14
|
+
export type Namespace = `${string}:session`;
|
|
15
|
+
export interface Session {
|
|
16
16
|
getId(): string;
|
|
17
17
|
changeSessionId(): string;
|
|
18
18
|
getAttribute(name: string): string | number | null;
|
|
@@ -26,7 +26,7 @@ interface Session {
|
|
|
26
26
|
setMaxInactiveInterval(interval: number): void;
|
|
27
27
|
isExpired(): boolean;
|
|
28
28
|
}
|
|
29
|
-
interface SessionRepository<S extends Session = Session> {
|
|
29
|
+
export interface SessionRepository<S extends Session = Session> {
|
|
30
30
|
createSession(): S;
|
|
31
31
|
save(session: S): Promise<void>;
|
|
32
32
|
findById(sessionId: string): Promise<S | null>;
|
|
@@ -35,11 +35,10 @@ interface SessionRepository<S extends Session = Session> {
|
|
|
35
35
|
findByPrincipalName(principalName: string): Promise<Map<string, S>>;
|
|
36
36
|
cleanupExpiredSessions(cleanupCount?: number): Promise<void>;
|
|
37
37
|
}
|
|
38
|
-
interface KVRepository {
|
|
38
|
+
export interface KVRepository {
|
|
39
39
|
setItem(key: string, value: string, expiresIn?: number): Promise<void>;
|
|
40
40
|
getItem(key: string): Promise<string | null>;
|
|
41
41
|
removeItem(key: string): Promise<void>;
|
|
42
42
|
}
|
|
43
43
|
//#endregion
|
|
44
|
-
export { Authentication, KVRepository, Namespace, SecurityContext, Session, SessionRepository };
|
|
45
44
|
//# sourceMappingURL=types.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.mts","names":[],"sources":["../../src/session/types.ts"],"mappings":";;
|
|
1
|
+
{"version":3,"file":"types.d.mts","names":[],"sources":["../../src/session/types.ts"],"mappings":";;iBAEiB,uBAAuB;EACtC;EACA,YAAY;EACZ;EACA;EACA;;iBAGe;EACf;EACA,iBAAiB;;YAGP;iBAGK;EACf;EACA;EAEA,aAAa;EACb;EACA,aAAa,cAAc;EAC3B,gBAAgB;EAEhB;EACA;EACA,oBAAoB;EAEpB;EACA,uBAAuB;EAEvB;;iBAGe,kBAAkB,UAAU,UAAU;EACrD,iBAAiB;EACjB,KAAK,SAAS,IAAI;EAClB,SAAS,oBAAoB,QAAQ;EACrC,WAAW,oBAAoB;EAG/B,6BAA6B,mBAAmB,qBAAqB,QAAQ,YAAY;EACzF,oBAAoB,wBAAwB,QAAQ,YAAY;EAGhE,uBAAuB,wBAAwB;;iBAGhC;EACf,QAAQ,aAAa,eAAe,qBAAqB;EACzD,QAAQ,cAAc;EACtB,WAAW,cAAc"}
|
package/dist/utils/http.d.cts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { SerializeOptions } from "cookie";
|
|
2
2
|
//#region src/utils/http.d.ts
|
|
3
|
-
type CookieOptions = Omit<SerializeOptions, 'encode'>;
|
|
4
|
-
declare function getCookie(request: Request, name: string): string | undefined;
|
|
5
|
-
declare function setCookie(response: Response, name: string, value: string, options?: SerializeOptions): void;
|
|
6
|
-
declare function deleteCookie(response: Response, name: string, options?: SerializeOptions): void;
|
|
3
|
+
export type CookieOptions = Omit<SerializeOptions, 'encode'>;
|
|
4
|
+
export declare function getCookie(request: Request, name: string): string | undefined;
|
|
5
|
+
export declare function setCookie(response: Response, name: string, value: string, options?: SerializeOptions): void;
|
|
6
|
+
export declare function deleteCookie(response: Response, name: string, options?: SerializeOptions): void;
|
|
7
7
|
type PathParam<T extends string> = T extends `${string}:${infer Param}/${infer Rest}` ? { [K in Param]: string; } & PathParam<Rest> : T extends `${string}:${infer Param}` ? { [K in Param]: string; } : {};
|
|
8
|
-
declare function param<P extends string>(request: Request, path: P): PathParam<P>;
|
|
9
|
-
declare function query(request: Request): {
|
|
8
|
+
export declare function param<P extends string>(request: Request, path: P): PathParam<P>;
|
|
9
|
+
export declare function query(request: Request): {
|
|
10
10
|
[k: string]: string;
|
|
11
11
|
};
|
|
12
12
|
//#endregion
|
|
13
|
-
export {
|
|
13
|
+
export {};
|
|
14
14
|
//# sourceMappingURL=http.d.cts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"http.d.cts","names":[],"sources":["../../src/utils/http.ts"],"mappings":";;
|
|
1
|
+
{"version":3,"file":"http.d.cts","names":[],"sources":["../../src/utils/http.ts"],"mappings":";;YAGY,gBAAgB,KAAK;wBAEjB,UAAU,SAAS,SAAS;wBAO5B,UACd,UAAU,UACV,cACA,eACA,UAAU;wBAKI,aAAa,UAAU,UAAU,cAAc,UAAU;KAOpE,UAAU,oBAAoB,6BAA6B,eAAe,YACxE,KAAK,oBAAmB,UAAU,QACrC,6BAA6B,aACxB,KAAK;wBAIE,MAAM,kBAAkB,SAAS,SAAS,MAAM,IAAI,UAAU;wBAQ9D,MAAM,SAAS"}
|
package/dist/utils/http.d.mts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { SerializeOptions } from "cookie";
|
|
2
2
|
//#region src/utils/http.d.ts
|
|
3
|
-
type CookieOptions = Omit<SerializeOptions, 'encode'>;
|
|
4
|
-
declare function getCookie(request: Request, name: string): string | undefined;
|
|
5
|
-
declare function setCookie(response: Response, name: string, value: string, options?: SerializeOptions): void;
|
|
6
|
-
declare function deleteCookie(response: Response, name: string, options?: SerializeOptions): void;
|
|
3
|
+
export type CookieOptions = Omit<SerializeOptions, 'encode'>;
|
|
4
|
+
export declare function getCookie(request: Request, name: string): string | undefined;
|
|
5
|
+
export declare function setCookie(response: Response, name: string, value: string, options?: SerializeOptions): void;
|
|
6
|
+
export declare function deleteCookie(response: Response, name: string, options?: SerializeOptions): void;
|
|
7
7
|
type PathParam<T extends string> = T extends `${string}:${infer Param}/${infer Rest}` ? { [K in Param]: string; } & PathParam<Rest> : T extends `${string}:${infer Param}` ? { [K in Param]: string; } : {};
|
|
8
|
-
declare function param<P extends string>(request: Request, path: P): PathParam<P>;
|
|
9
|
-
declare function query(request: Request): {
|
|
8
|
+
export declare function param<P extends string>(request: Request, path: P): PathParam<P>;
|
|
9
|
+
export declare function query(request: Request): {
|
|
10
10
|
[k: string]: string;
|
|
11
11
|
};
|
|
12
12
|
//#endregion
|
|
13
|
-
export {
|
|
13
|
+
export {};
|
|
14
14
|
//# sourceMappingURL=http.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"http.d.mts","names":[],"sources":["../../src/utils/http.ts"],"mappings":";;
|
|
1
|
+
{"version":3,"file":"http.d.mts","names":[],"sources":["../../src/utils/http.ts"],"mappings":";;YAGY,gBAAgB,KAAK;wBAEjB,UAAU,SAAS,SAAS;wBAO5B,UACd,UAAU,UACV,cACA,eACA,UAAU;wBAKI,aAAa,UAAU,UAAU,cAAc,UAAU;KAOpE,UAAU,oBAAoB,6BAA6B,eAAe,YACxE,KAAK,oBAAmB,UAAU,QACrC,6BAA6B,aACxB,KAAK;wBAIE,MAAM,kBAAkB,SAAS,SAAS,MAAM,IAAI,UAAU;wBAQ9D,MAAM,SAAS"}
|
package/dist/utils/oauth2.d.cts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"oauth2.d.cts","names":[],"sources":["../../src/utils/oauth2.ts"],"mappings":";
|
|
1
|
+
{"version":3,"file":"oauth2.d.cts","names":[],"sources":["../../src/utils/oauth2.ts"],"mappings":";wBAAgB"}
|
package/dist/utils/oauth2.d.mts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"oauth2.d.mts","names":[],"sources":["../../src/utils/oauth2.ts"],"mappings":";
|
|
1
|
+
{"version":3,"file":"oauth2.d.mts","names":[],"sources":["../../src/utils/oauth2.ts"],"mappings":";wBAAgB"}
|
package/dist/utils/timing.d.cts
CHANGED
|
@@ -3,7 +3,7 @@ interface Options {
|
|
|
3
3
|
enabled: boolean;
|
|
4
4
|
crossOrigin?: string;
|
|
5
5
|
}
|
|
6
|
-
declare function timing({ enabled, crossOrigin }: Options): {
|
|
6
|
+
export declare function timing({ enabled, crossOrigin }: Options): {
|
|
7
7
|
startTime: (name: Lowercase<string>, description?: string) => void;
|
|
8
8
|
endTime: (name: Lowercase<string>, precision?: number) => void;
|
|
9
9
|
mark: (name: Lowercase<string>, description?: string, precision?: number) => void;
|
|
@@ -11,5 +11,5 @@ declare function timing({ enabled, crossOrigin }: Options): {
|
|
|
11
11
|
setTiming: (response: Response) => void;
|
|
12
12
|
};
|
|
13
13
|
//#endregion
|
|
14
|
-
export {
|
|
14
|
+
export {};
|
|
15
15
|
//# sourceMappingURL=timing.d.cts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"timing.d.cts","names":[],"sources":["../../src/utils/timing.ts"],"mappings":";UAKU;EACR;EACA;;
|
|
1
|
+
{"version":3,"file":"timing.d.cts","names":[],"sources":["../../src/utils/timing.ts"],"mappings":";UAKU;EACR;EACA;;wBAGc,SAAS,SAAS,eAAe;EAM7C,YAAS,MAAS,mBAAiB;EAGnC,UAAO,MAAS,mBAAiB;EAcjC,OAAI,MAAS,mBAAiB,sBAAsB;EAQpD,YAAS,MACD,mBAAiB,oCACW,sBACd;EActB,YAAS,UAAa"}
|
package/dist/utils/timing.d.mts
CHANGED
|
@@ -3,7 +3,7 @@ interface Options {
|
|
|
3
3
|
enabled: boolean;
|
|
4
4
|
crossOrigin?: string;
|
|
5
5
|
}
|
|
6
|
-
declare function timing({ enabled, crossOrigin }: Options): {
|
|
6
|
+
export declare function timing({ enabled, crossOrigin }: Options): {
|
|
7
7
|
startTime: (name: Lowercase<string>, description?: string) => void;
|
|
8
8
|
endTime: (name: Lowercase<string>, precision?: number) => void;
|
|
9
9
|
mark: (name: Lowercase<string>, description?: string, precision?: number) => void;
|
|
@@ -11,5 +11,5 @@ declare function timing({ enabled, crossOrigin }: Options): {
|
|
|
11
11
|
setTiming: (response: Response) => void;
|
|
12
12
|
};
|
|
13
13
|
//#endregion
|
|
14
|
-
export {
|
|
14
|
+
export {};
|
|
15
15
|
//# sourceMappingURL=timing.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"timing.d.mts","names":[],"sources":["../../src/utils/timing.ts"],"mappings":";UAKU;EACR;EACA;;
|
|
1
|
+
{"version":3,"file":"timing.d.mts","names":[],"sources":["../../src/utils/timing.ts"],"mappings":";UAKU;EACR;EACA;;wBAGc,SAAS,SAAS,eAAe;EAM7C,YAAS,MAAS,mBAAiB;EAGnC,UAAO,MAAS,mBAAiB;EAcjC,OAAI,MAAS,mBAAiB,sBAAsB;EAQpD,YAAS,MACD,mBAAiB,oCACW,sBACd;EActB,YAAS,UAAa"}
|
package/dist/utils/valid.d.cts
CHANGED
|
@@ -9,7 +9,7 @@ type ErrorBody = {
|
|
|
9
9
|
details: unknown[];
|
|
10
10
|
};
|
|
11
11
|
};
|
|
12
|
-
declare function invalidArgument(reason: string): ErrorBody;
|
|
12
|
+
export declare function invalidArgument(reason: string): ErrorBody;
|
|
13
13
|
type Result<S extends ZodType | ZodMiniType> = {
|
|
14
14
|
error: null;
|
|
15
15
|
data: S extends ZodType ? output<S> : output$1<S>;
|
|
@@ -17,12 +17,12 @@ type Result<S extends ZodType | ZodMiniType> = {
|
|
|
17
17
|
error: ErrorBody;
|
|
18
18
|
data: null;
|
|
19
19
|
};
|
|
20
|
-
declare function valid<S extends ZodType | ZodMiniType>(schema: S, json: unknown): Result<S>;
|
|
21
|
-
declare function verifyTurnstileToken(secret: string, token: string): Promise<{
|
|
20
|
+
export declare function valid<S extends ZodType | ZodMiniType>(schema: S, json: unknown): Result<S>;
|
|
21
|
+
export declare function verifyTurnstileToken(secret: string, token: string): Promise<{
|
|
22
22
|
error: null;
|
|
23
23
|
} | {
|
|
24
24
|
error: ErrorBody;
|
|
25
25
|
}>;
|
|
26
26
|
//#endregion
|
|
27
|
-
export {
|
|
27
|
+
export {};
|
|
28
28
|
//# sourceMappingURL=valid.d.cts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"valid.d.cts","names":[],"sources":["../../src/utils/valid.ts"],"mappings":";;;KAGK;EACH;IACE;IACA;IACA;IACA;;;
|
|
1
|
+
{"version":3,"file":"valid.d.cts","names":["outputMini"],"sources":["../../src/utils/valid.ts"],"mappings":";;;KAGK;EACH;IACE;IACA;IACA;IACA;;;wBAIY,gBAAgB,iBAAiB;KAW5C,OAAO,UAAU,UAAU;EAC1B;EAAa,MAAM,UAAU,UAAU,OAAO,KAAKA,SAAW;;EAC9D,OAAO;EAAW;;wBAER,MAAM,UAAU,UAAU,aAAa,QAAQ,GAAG,gBAAgB,OAAO;wBA4BnE,qBAAqB,gBAAgB,gBAAa"}
|
package/dist/utils/valid.d.mts
CHANGED
|
@@ -9,7 +9,7 @@ type ErrorBody = {
|
|
|
9
9
|
details: unknown[];
|
|
10
10
|
};
|
|
11
11
|
};
|
|
12
|
-
declare function invalidArgument(reason: string): ErrorBody;
|
|
12
|
+
export declare function invalidArgument(reason: string): ErrorBody;
|
|
13
13
|
type Result<S extends ZodType | ZodMiniType> = {
|
|
14
14
|
error: null;
|
|
15
15
|
data: S extends ZodType ? output$1<S> : output<S>;
|
|
@@ -17,12 +17,12 @@ type Result<S extends ZodType | ZodMiniType> = {
|
|
|
17
17
|
error: ErrorBody;
|
|
18
18
|
data: null;
|
|
19
19
|
};
|
|
20
|
-
declare function valid<S extends ZodType | ZodMiniType>(schema: S, json: unknown): Result<S>;
|
|
21
|
-
declare function verifyTurnstileToken(secret: string, token: string): Promise<{
|
|
20
|
+
export declare function valid<S extends ZodType | ZodMiniType>(schema: S, json: unknown): Result<S>;
|
|
21
|
+
export declare function verifyTurnstileToken(secret: string, token: string): Promise<{
|
|
22
22
|
error: null;
|
|
23
23
|
} | {
|
|
24
24
|
error: ErrorBody;
|
|
25
25
|
}>;
|
|
26
26
|
//#endregion
|
|
27
|
-
export {
|
|
27
|
+
export {};
|
|
28
28
|
//# sourceMappingURL=valid.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"valid.d.mts","names":[],"sources":["../../src/utils/valid.ts"],"mappings":";;;KAGK;EACH;IACE;IACA;IACA;IACA;;;
|
|
1
|
+
{"version":3,"file":"valid.d.mts","names":["output","outputMini"],"sources":["../../src/utils/valid.ts"],"mappings":";;;KAGK;EACH;IACE;IACA;IACA;IACA;;;wBAIY,gBAAgB,iBAAiB;KAW5C,OAAO,UAAU,UAAU;EAC1B;EAAa,MAAM,UAAU,UAAUA,SAAO,KAAKC,OAAW;;EAC9D,OAAO;EAAW;;wBAER,MAAM,UAAU,UAAU,aAAa,QAAQ,GAAG,gBAAgB,OAAO;wBA4BnE,qBAAqB,gBAAgB,gBAAa"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shware/security",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.4.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -36,20 +36,27 @@
|
|
|
36
36
|
"access": "public"
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"@shware/utils": "^1.6.
|
|
39
|
+
"@shware/utils": "^1.6.3",
|
|
40
40
|
"cookie": "^2.0.1",
|
|
41
|
-
"
|
|
42
|
-
"
|
|
43
|
-
"path-to-regexp": "^8.4.2",
|
|
44
|
-
"uuid": "^14.0.2",
|
|
45
|
-
"zod": "^4.4.3"
|
|
41
|
+
"jose": "^6.2.12",
|
|
42
|
+
"path-to-regexp": "^8.4.2"
|
|
46
43
|
},
|
|
47
44
|
"devDependencies": {
|
|
48
45
|
"@repo/typescript-config": "0.0.0",
|
|
49
|
-
"@types/node": "^26.
|
|
50
|
-
"
|
|
46
|
+
"@types/node": "^26.6.5",
|
|
47
|
+
"ioredis": "^6.0.0",
|
|
51
48
|
"typescript": "7.0.2",
|
|
52
|
-
"vitest": "^
|
|
49
|
+
"vitest": "^5.0.5",
|
|
50
|
+
"zod": "^4.6.7"
|
|
51
|
+
},
|
|
52
|
+
"peerDependencies": {
|
|
53
|
+
"ioredis": "^6.0.0",
|
|
54
|
+
"zod": "^4.6.5"
|
|
55
|
+
},
|
|
56
|
+
"peerDependenciesMeta": {
|
|
57
|
+
"ioredis": {
|
|
58
|
+
"optional": true
|
|
59
|
+
}
|
|
53
60
|
},
|
|
54
61
|
"scripts": {
|
|
55
62
|
"dev": "tsc --watch",
|