@shware/security 2.5.3 → 3.0.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.
Files changed (225) hide show
  1. package/dist/auth/index.cjs +519 -561
  2. package/dist/auth/index.cjs.map +1 -1
  3. package/dist/auth/index.d.cts +104 -106
  4. package/dist/auth/index.d.cts.map +1 -0
  5. package/dist/auth/index.d.mts +109 -0
  6. package/dist/auth/index.d.mts.map +1 -0
  7. package/dist/auth/index.mjs +512 -536
  8. package/dist/auth/index.mjs.map +1 -1
  9. package/dist/auth/types.cjs +0 -19
  10. package/dist/auth/types.d.cts +44 -44
  11. package/dist/auth/types.d.cts.map +1 -0
  12. package/dist/auth/types.d.mts +50 -0
  13. package/dist/auth/types.d.mts.map +1 -0
  14. package/dist/auth/types.mjs +1 -1
  15. package/dist/core/index.cjs +18 -59
  16. package/dist/core/index.cjs.map +1 -1
  17. package/dist/core/index.d.cts +13 -24
  18. package/dist/core/index.d.cts.map +1 -0
  19. package/dist/core/index.d.mts +21 -0
  20. package/dist/core/index.d.mts.map +1 -0
  21. package/dist/core/index.mjs +17 -33
  22. package/dist/core/index.mjs.map +1 -1
  23. package/dist/email/schema.cjs +13 -38
  24. package/dist/email/schema.cjs.map +1 -1
  25. package/dist/email/schema.d.cts +11 -12
  26. package/dist/email/schema.d.cts.map +1 -0
  27. package/dist/email/schema.d.mts +12 -0
  28. package/dist/email/schema.d.mts.map +1 -0
  29. package/dist/email/schema.mjs +10 -11
  30. package/dist/email/schema.mjs.map +1 -1
  31. package/dist/index.cjs +18 -54
  32. package/dist/index.d.cts +10 -15
  33. package/dist/index.d.mts +10 -0
  34. package/dist/index.mjs +5 -17
  35. package/dist/oauth2/client.cjs +109 -145
  36. package/dist/oauth2/client.cjs.map +1 -1
  37. package/dist/oauth2/client.d.cts +55 -56
  38. package/dist/oauth2/client.d.cts.map +1 -0
  39. package/dist/oauth2/client.d.mts +58 -0
  40. package/dist/oauth2/client.d.mts.map +1 -0
  41. package/dist/oauth2/client.mjs +104 -116
  42. package/dist/oauth2/client.mjs.map +1 -1
  43. package/dist/oauth2/error.cjs +19 -44
  44. package/dist/oauth2/error.cjs.map +1 -1
  45. package/dist/oauth2/error.d.cts +8 -6
  46. package/dist/oauth2/error.d.cts.map +1 -0
  47. package/dist/oauth2/{error.d.ts → error.d.mts} +8 -6
  48. package/dist/oauth2/error.d.mts.map +1 -0
  49. package/dist/oauth2/error.mjs +18 -19
  50. package/dist/oauth2/error.mjs.map +1 -1
  51. package/dist/oauth2/provider/apple.cjs +75 -88
  52. package/dist/oauth2/provider/apple.cjs.map +1 -1
  53. package/dist/oauth2/provider/apple.d.cts +31 -30
  54. package/dist/oauth2/provider/apple.d.cts.map +1 -0
  55. package/dist/oauth2/provider/apple.d.mts +42 -0
  56. package/dist/oauth2/provider/apple.d.mts.map +1 -0
  57. package/dist/oauth2/provider/apple.mjs +71 -60
  58. package/dist/oauth2/provider/apple.mjs.map +1 -1
  59. package/dist/oauth2/provider/common.cjs +86 -109
  60. package/dist/oauth2/provider/common.cjs.map +1 -1
  61. package/dist/oauth2/provider/common.d.cts +19 -18
  62. package/dist/oauth2/provider/common.d.cts.map +1 -0
  63. package/dist/oauth2/provider/common.d.mts +30 -0
  64. package/dist/oauth2/provider/common.d.mts.map +1 -0
  65. package/dist/oauth2/provider/common.mjs +80 -79
  66. package/dist/oauth2/provider/common.mjs.map +1 -1
  67. package/dist/oauth2/provider/facebook.cjs +93 -109
  68. package/dist/oauth2/provider/facebook.cjs.map +1 -1
  69. package/dist/oauth2/provider/facebook.d.cts +29 -28
  70. package/dist/oauth2/provider/facebook.d.cts.map +1 -0
  71. package/dist/oauth2/provider/facebook.d.mts +45 -0
  72. package/dist/oauth2/provider/facebook.d.mts.map +1 -0
  73. package/dist/oauth2/provider/facebook.mjs +89 -81
  74. package/dist/oauth2/provider/facebook.mjs.map +1 -1
  75. package/dist/oauth2/provider/github.cjs +64 -91
  76. package/dist/oauth2/provider/github.cjs.map +1 -1
  77. package/dist/oauth2/provider/github.d.cts +52 -51
  78. package/dist/oauth2/provider/github.d.cts.map +1 -0
  79. package/dist/oauth2/provider/github.d.mts +60 -0
  80. package/dist/oauth2/provider/github.d.mts.map +1 -0
  81. package/dist/oauth2/provider/github.mjs +60 -63
  82. package/dist/oauth2/provider/github.mjs.map +1 -1
  83. package/dist/oauth2/provider/google.cjs +105 -122
  84. package/dist/oauth2/provider/google.cjs.map +1 -1
  85. package/dist/oauth2/provider/google.d.cts +34 -33
  86. package/dist/oauth2/provider/google.d.cts.map +1 -0
  87. package/dist/oauth2/provider/google.d.mts +44 -0
  88. package/dist/oauth2/provider/google.d.mts.map +1 -0
  89. package/dist/oauth2/provider/google.mjs +101 -94
  90. package/dist/oauth2/provider/google.mjs.map +1 -1
  91. package/dist/oauth2/provider/index.cjs +13 -46
  92. package/dist/oauth2/provider/index.d.cts +7 -7
  93. package/dist/oauth2/provider/index.d.mts +7 -0
  94. package/dist/oauth2/provider/index.mjs +1 -10
  95. package/dist/oauth2/provider/wechat.cjs +77 -99
  96. package/dist/oauth2/provider/wechat.cjs.map +1 -1
  97. package/dist/oauth2/provider/wechat.d.cts +28 -27
  98. package/dist/oauth2/provider/wechat.d.cts.map +1 -0
  99. package/dist/oauth2/provider/wechat.d.mts +39 -0
  100. package/dist/oauth2/provider/wechat.d.mts.map +1 -0
  101. package/dist/oauth2/provider/wechat.mjs +74 -72
  102. package/dist/oauth2/provider/wechat.mjs.map +1 -1
  103. package/dist/oauth2/provider/x.cjs +102 -125
  104. package/dist/oauth2/provider/x.cjs.map +1 -1
  105. package/dist/oauth2/provider/x.d.cts +51 -50
  106. package/dist/oauth2/provider/x.d.cts.map +1 -0
  107. package/dist/oauth2/provider/x.d.mts +69 -0
  108. package/dist/oauth2/provider/x.d.mts.map +1 -0
  109. package/dist/oauth2/provider/x.mjs +99 -103
  110. package/dist/oauth2/provider/x.mjs.map +1 -1
  111. package/dist/oauth2/types.cjs +12 -37
  112. package/dist/oauth2/types.cjs.map +1 -1
  113. package/dist/oauth2/types.d.cts +176 -180
  114. package/dist/oauth2/types.d.cts.map +1 -0
  115. package/dist/oauth2/types.d.mts +207 -0
  116. package/dist/oauth2/types.d.mts.map +1 -0
  117. package/dist/oauth2/types.mjs +12 -13
  118. package/dist/oauth2/types.mjs.map +1 -1
  119. package/dist/session/common.cjs +17 -43
  120. package/dist/session/common.cjs.map +1 -1
  121. package/dist/session/common.d.cts +4 -4
  122. package/dist/session/common.d.cts.map +1 -0
  123. package/dist/session/{common.d.ts → common.d.mts} +4 -4
  124. package/dist/session/common.d.mts.map +1 -0
  125. package/dist/session/common.mjs +14 -16
  126. package/dist/session/common.mjs.map +1 -1
  127. package/dist/session/db.cjs +88 -123
  128. package/dist/session/db.cjs.map +1 -1
  129. package/dist/session/db.d.cts +36 -36
  130. package/dist/session/db.d.cts.map +1 -0
  131. package/dist/session/db.d.mts +44 -0
  132. package/dist/session/db.d.mts.map +1 -0
  133. package/dist/session/db.mjs +84 -95
  134. package/dist/session/db.mjs.map +1 -1
  135. package/dist/session/map-session.cjs +71 -103
  136. package/dist/session/map-session.cjs.map +1 -1
  137. package/dist/session/map-session.d.cts +24 -24
  138. package/dist/session/map-session.d.cts.map +1 -0
  139. package/dist/session/map-session.d.mts +27 -0
  140. package/dist/session/map-session.d.mts.map +1 -0
  141. package/dist/session/map-session.mjs +70 -78
  142. package/dist/session/map-session.mjs.map +1 -1
  143. package/dist/session/redis.cjs +270 -319
  144. package/dist/session/redis.cjs.map +1 -1
  145. package/dist/session/redis.d.cts +51 -51
  146. package/dist/session/redis.d.cts.map +1 -0
  147. package/dist/session/redis.d.mts +58 -0
  148. package/dist/session/redis.d.mts.map +1 -0
  149. package/dist/session/redis.mjs +266 -291
  150. package/dist/session/redis.mjs.map +1 -1
  151. package/dist/session/types.cjs +0 -19
  152. package/dist/session/types.d.cts +34 -33
  153. package/dist/session/types.d.cts.map +1 -0
  154. package/dist/session/types.d.mts +45 -0
  155. package/dist/session/types.d.mts.map +1 -0
  156. package/dist/session/types.mjs +1 -1
  157. package/dist/utils/http.cjs +31 -55
  158. package/dist/utils/http.cjs.map +1 -1
  159. package/dist/utils/http.d.cts +7 -10
  160. package/dist/utils/http.d.cts.map +1 -0
  161. package/dist/utils/{http.d.ts → http.d.mts} +7 -10
  162. package/dist/utils/http.d.mts.map +1 -0
  163. package/dist/utils/http.mjs +24 -24
  164. package/dist/utils/http.mjs.map +1 -1
  165. package/dist/utils/oauth2.cjs +6 -30
  166. package/dist/utils/oauth2.cjs.map +1 -1
  167. package/dist/utils/oauth2.d.cts +3 -1
  168. package/dist/utils/oauth2.d.cts.map +1 -0
  169. package/dist/utils/oauth2.d.mts +5 -0
  170. package/dist/utils/oauth2.d.mts.map +1 -0
  171. package/dist/utils/oauth2.mjs +5 -5
  172. package/dist/utils/oauth2.mjs.map +1 -1
  173. package/dist/utils/timing.cjs +49 -70
  174. package/dist/utils/timing.cjs.map +1 -1
  175. package/dist/utils/timing.d.cts +10 -8
  176. package/dist/utils/timing.d.cts.map +1 -0
  177. package/dist/utils/timing.d.mts +15 -0
  178. package/dist/utils/timing.d.mts.map +1 -0
  179. package/dist/utils/timing.mjs +48 -45
  180. package/dist/utils/timing.mjs.map +1 -1
  181. package/dist/utils/valid.cjs +50 -71
  182. package/dist/utils/valid.cjs.map +1 -1
  183. package/dist/utils/valid.d.cts +17 -16
  184. package/dist/utils/valid.d.cts.map +1 -0
  185. package/dist/utils/valid.d.mts +28 -0
  186. package/dist/utils/valid.d.mts.map +1 -0
  187. package/dist/utils/valid.mjs +47 -44
  188. package/dist/utils/valid.mjs.map +1 -1
  189. package/package.json +22 -12
  190. package/dist/auth/index.d.ts +0 -111
  191. package/dist/auth/types.cjs.map +0 -1
  192. package/dist/auth/types.d.ts +0 -50
  193. package/dist/auth/types.mjs.map +0 -1
  194. package/dist/core/index.d.ts +0 -32
  195. package/dist/email/schema.d.ts +0 -13
  196. package/dist/index.cjs.map +0 -1
  197. package/dist/index.d.ts +0 -15
  198. package/dist/index.mjs.map +0 -1
  199. package/dist/oauth2/client.d.ts +0 -59
  200. package/dist/oauth2/provider/apple.d.ts +0 -41
  201. package/dist/oauth2/provider/common.d.ts +0 -29
  202. package/dist/oauth2/provider/facebook.d.ts +0 -44
  203. package/dist/oauth2/provider/github.d.ts +0 -59
  204. package/dist/oauth2/provider/google.d.ts +0 -43
  205. package/dist/oauth2/provider/index.cjs.map +0 -1
  206. package/dist/oauth2/provider/index.d.ts +0 -7
  207. package/dist/oauth2/provider/index.mjs.map +0 -1
  208. package/dist/oauth2/provider/wechat.d.ts +0 -38
  209. package/dist/oauth2/provider/x.d.ts +0 -68
  210. package/dist/oauth2/types.d.ts +0 -211
  211. package/dist/session/__tests__/redis.test.cjs +0 -247
  212. package/dist/session/__tests__/redis.test.cjs.map +0 -1
  213. package/dist/session/__tests__/redis.test.d.cts +0 -2
  214. package/dist/session/__tests__/redis.test.d.ts +0 -2
  215. package/dist/session/__tests__/redis.test.mjs +0 -252
  216. package/dist/session/__tests__/redis.test.mjs.map +0 -1
  217. package/dist/session/db.d.ts +0 -44
  218. package/dist/session/map-session.d.ts +0 -27
  219. package/dist/session/redis.d.ts +0 -58
  220. package/dist/session/types.cjs.map +0 -1
  221. package/dist/session/types.d.ts +0 -44
  222. package/dist/session/types.mjs.map +0 -1
  223. package/dist/utils/oauth2.d.ts +0 -3
  224. package/dist/utils/timing.d.ts +0 -13
  225. package/dist/utils/valid.d.ts +0 -27
@@ -1 +1 @@
1
- {"version":3,"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 === null || 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 (!entries || 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 || 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 await this.redis.get(key);\n }\n\n async removeItem(key: string) {\n await this.redis.del(key);\n }\n}\n"],"mappings":";AACA,SAAS,2BAA2B,yBAAyB,yBAAyB;AACtF,SAAS,kBAAkB;AAG3B,IAAM,oBAAoB;AAC1B,IAAM,yBAAyB;AAC/B,IAAM,4BAA4B;AAClC,IAAM,mBAAmB;AACzB,IAAM,yBAAyB;AAE/B,IAAM,eAAN,MAAsC;AAAA,EACnB;AAAA,EAEV;AAAA,EACA,QAAQ,oBAAI,IAAoC;AAAA,EAChD;AAAA,EACA;AAAA,EACA,yBAAwC;AAAA,EAE/C,YAAY,QAAoB,OAAgB;AAC9C,SAAK,SAAS;AACd,SAAK,QAAQ;AACb,SAAK,oBAAoB,OAAO,MAAM;AACtC,SAAK,wBAAwB,kBAAkB,IAAI;AAEnD,QAAI,OAAO;AACT,WAAK,MAAM,IAAI,mBAAmB,OAAO,gBAAgB,CAAC;AAC1D,WAAK,MAAM,IAAI,wBAAwB,OAAO,oBAAoB,CAAC;AACnE,WAAK,MAAM,IAAI,2BAA2B,OAAO,uBAAuB,CAAC;AACzE,WAAK,OAAO,kBAAkB,EAAE,QAAQ,CAAC,SAAS;AAChD,cAAM,QAAQ,KAAK,OAAO,aAAa,IAAI;AAC3C,YAAI,MAAO,MAAK,MAAM,IAAI,KAAK,sBAAsB,IAAI,GAAG,KAAK;AAAA,MACnE,CAAC;AAAA,IACH;AAAA,EACF;AAAA,EAEA,sBAAsB,MAAc;AAClC,WAAO,mBAAmB;AAAA,EAC5B;AAAA;AAAA,EAGA,oBAAoB,kBAA0B;AAC5C,SAAK,OAAO,oBAAoB,gBAAgB;AAChD,SAAK,MAAM,IAAI,wBAAwB,gBAAgB;AAAA,EACzD;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ACf;AAAA,EAEA,MAAM,QAAQ,KAAa,OAAe,WAAoB;AAC5D,QAAI,WAAW;AACb,YAAM,KAAK,MAAM,IAAI,KAAK,OAAO,MAAM,SAAS;AAAA,IAClD,OAAO;AACL,YAAM,KAAK,MAAM,IAAI,KAAK,KAAK;AAAA,IACjC;AAAA,EACF;AAAA,EAEA,MAAM,QAAQ,KAAqC;AACjD,WAAO,MAAM,KAAK,MAAM,IAAI,GAAG;AAAA,EACjC;AAAA,EAEA,MAAM,WAAW,KAAa;AAC5B,UAAM,KAAK,MAAM,IAAI,GAAG;AAAA,EAC1B;AACF;","names":["key"]}
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 === null || 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 (!entries || 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 || 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 await 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,oBA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AM,QAAQ,KAAqC;EACjD,OAAO,MAAM,KAAK,MAAM,IAAI,GAAG;CACjC;CAEA,MAAM,WAAW,KAAa;EAC5B,MAAM,KAAK,MAAM,IAAI,GAAG;CAC1B;AACF"}
@@ -1,19 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __copyProps = (to, from, except, desc) => {
7
- if (from && typeof from === "object" || typeof from === "function") {
8
- for (let key of __getOwnPropNames(from))
9
- if (!__hasOwnProp.call(to, key) && key !== except)
10
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
11
- }
12
- return to;
13
- };
14
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
15
-
16
- // src/session/types.ts
17
- var types_exports = {};
18
- module.exports = __toCommonJS(types_exports);
19
- //# sourceMappingURL=types.cjs.map
@@ -1,44 +1,45 @@
1
- import { Principal } from '../core/index.cjs';
2
-
1
+ import { Principal } from "../core/index.cjs";
2
+ //#region src/session/types.d.ts
3
3
  interface Authentication extends Principal {
4
- '@class': string;
5
- principal?: Principal;
6
- authorities?: string[];
7
- credentials?: object;
8
- details?: object;
4
+ '@class': string;
5
+ principal?: Principal;
6
+ authorities?: string[];
7
+ credentials?: object;
8
+ details?: object;
9
9
  }
10
10
  interface SecurityContext {
11
- '@class': string;
12
- authentication?: Authentication;
11
+ '@class': string;
12
+ authentication?: Authentication;
13
13
  }
14
14
  type Namespace = `${string}:session`;
15
15
  interface Session {
16
- getId(): string;
17
- changeSessionId(): string;
18
- getAttribute(name: string): string | number | null;
19
- getAttributeNames(): string[];
20
- setAttribute(name: string, value: string | number): void;
21
- removeAttribute(name: string): void;
22
- getCreationTime(): number;
23
- getLastAccessedTime(): number;
24
- setLastAccessedTime(lastAccessedTime: number): void;
25
- getMaxInactiveInterval(): number;
26
- setMaxInactiveInterval(interval: number): void;
27
- isExpired(): boolean;
16
+ getId(): string;
17
+ changeSessionId(): string;
18
+ getAttribute(name: string): string | number | null;
19
+ getAttributeNames(): string[];
20
+ setAttribute(name: string, value: string | number): void;
21
+ removeAttribute(name: string): void;
22
+ getCreationTime(): number;
23
+ getLastAccessedTime(): number;
24
+ setLastAccessedTime(lastAccessedTime: number): void;
25
+ getMaxInactiveInterval(): number;
26
+ setMaxInactiveInterval(interval: number): void;
27
+ isExpired(): boolean;
28
28
  }
29
29
  interface SessionRepository<S extends Session = Session> {
30
- createSession(): S;
31
- save(session: S): Promise<void>;
32
- findById(sessionId: string): Promise<S | null>;
33
- deleteById(sessionId: string): Promise<void>;
34
- findByIndexNameAndIndexValue(indexName: string, indexValue: string): Promise<Map<string, S>>;
35
- findByPrincipalName(principalName: string): Promise<Map<string, S>>;
36
- cleanupExpiredSessions(cleanupCount?: number): Promise<void>;
30
+ createSession(): S;
31
+ save(session: S): Promise<void>;
32
+ findById(sessionId: string): Promise<S | null>;
33
+ deleteById(sessionId: string): Promise<void>;
34
+ findByIndexNameAndIndexValue(indexName: string, indexValue: string): Promise<Map<string, S>>;
35
+ findByPrincipalName(principalName: string): Promise<Map<string, S>>;
36
+ cleanupExpiredSessions(cleanupCount?: number): Promise<void>;
37
37
  }
38
38
  interface KVRepository {
39
- setItem(key: string, value: string, expiresIn?: number): Promise<void>;
40
- getItem(key: string): Promise<string | null>;
41
- removeItem(key: string): Promise<void>;
39
+ setItem(key: string, value: string, expiresIn?: number): Promise<void>;
40
+ getItem(key: string): Promise<string | null>;
41
+ removeItem(key: string): Promise<void>;
42
42
  }
43
-
44
- export type { Authentication, KVRepository, Namespace, SecurityContext, Session, SessionRepository };
43
+ //#endregion
44
+ export { Authentication, KVRepository, Namespace, SecurityContext, Session, SessionRepository };
45
+ //# sourceMappingURL=types.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.cts","names":[],"sources":["../../src/session/types.ts"],"mappings":";;UAEiB,uBAAuB;EACtC;EACA,YAAY;EACZ;EACA;EACA;;UAGe;EACf;EACA,iBAAiB;;KAGP;UAGK;EACf;EACA;EAEA,aAAa;EACb;EACA,aAAa,cAAc;EAC3B,gBAAgB;EAEhB;EACA;EACA,oBAAoB;EAEpB;EACA,uBAAuB;EAEvB;;UAGe,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;;UAGhC;EACf,QAAQ,aAAa,eAAe,qBAAqB;EACzD,QAAQ,cAAc;EACtB,WAAW,cAAc"}
@@ -0,0 +1,45 @@
1
+ import { Principal } from "../core/index.mjs";
2
+ //#region src/session/types.d.ts
3
+ interface Authentication extends Principal {
4
+ '@class': string;
5
+ principal?: Principal;
6
+ authorities?: string[];
7
+ credentials?: object;
8
+ details?: object;
9
+ }
10
+ interface SecurityContext {
11
+ '@class': string;
12
+ authentication?: Authentication;
13
+ }
14
+ type Namespace = `${string}:session`;
15
+ interface Session {
16
+ getId(): string;
17
+ changeSessionId(): string;
18
+ getAttribute(name: string): string | number | null;
19
+ getAttributeNames(): string[];
20
+ setAttribute(name: string, value: string | number): void;
21
+ removeAttribute(name: string): void;
22
+ getCreationTime(): number;
23
+ getLastAccessedTime(): number;
24
+ setLastAccessedTime(lastAccessedTime: number): void;
25
+ getMaxInactiveInterval(): number;
26
+ setMaxInactiveInterval(interval: number): void;
27
+ isExpired(): boolean;
28
+ }
29
+ interface SessionRepository<S extends Session = Session> {
30
+ createSession(): S;
31
+ save(session: S): Promise<void>;
32
+ findById(sessionId: string): Promise<S | null>;
33
+ deleteById(sessionId: string): Promise<void>;
34
+ findByIndexNameAndIndexValue(indexName: string, indexValue: string): Promise<Map<string, S>>;
35
+ findByPrincipalName(principalName: string): Promise<Map<string, S>>;
36
+ cleanupExpiredSessions(cleanupCount?: number): Promise<void>;
37
+ }
38
+ interface KVRepository {
39
+ setItem(key: string, value: string, expiresIn?: number): Promise<void>;
40
+ getItem(key: string): Promise<string | null>;
41
+ removeItem(key: string): Promise<void>;
42
+ }
43
+ //#endregion
44
+ export { Authentication, KVRepository, Namespace, SecurityContext, Session, SessionRepository };
45
+ //# sourceMappingURL=types.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.mts","names":[],"sources":["../../src/session/types.ts"],"mappings":";;UAEiB,uBAAuB;EACtC;EACA,YAAY;EACZ;EACA;EACA;;UAGe;EACf;EACA,iBAAiB;;KAGP;UAGK;EACf;EACA;EAEA,aAAa;EACb;EACA,aAAa,cAAc;EAC3B,gBAAgB;EAEhB;EACA;EACA,oBAAoB;EAEpB;EACA,uBAAuB;EAEvB;;UAGe,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;;UAGhC;EACf,QAAQ,aAAa,eAAe,qBAAqB;EACzD,QAAQ,cAAc;EACtB,WAAW,cAAc"}
@@ -1 +1 @@
1
- //# sourceMappingURL=types.mjs.map
1
+ export {};
@@ -1,66 +1,42 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
-
20
- // src/utils/http.ts
21
- var http_exports = {};
22
- __export(http_exports, {
23
- deleteCookie: () => deleteCookie,
24
- getCookie: () => getCookie,
25
- param: () => param,
26
- query: () => query,
27
- setCookie: () => setCookie
28
- });
29
- module.exports = __toCommonJS(http_exports);
30
- var import_cookie = require("cookie");
31
- var import_path_to_regexp = require("path-to-regexp");
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ let cookie = require("cookie");
3
+ let path_to_regexp = require("path-to-regexp");
4
+ //#region src/utils/http.ts
32
5
  function getCookie(request, name) {
33
- const cookie = request.headers.get("Cookie");
34
- if (!cookie) return void 0;
35
- const parsed = (0, import_cookie.parseCookie)(cookie);
36
- return parsed[name];
6
+ const cookie$1 = request.headers.get("Cookie");
7
+ if (!cookie$1) return void 0;
8
+ return (0, cookie.parseCookie)(cookie$1)[name];
37
9
  }
38
10
  function setCookie(response, name, value, options) {
39
- response.headers.append("Set-Cookie", (0, import_cookie.stringifySetCookie)({ name, value, ...options }));
11
+ response.headers.append("Set-Cookie", (0, cookie.stringifySetCookie)({
12
+ name,
13
+ value,
14
+ ...options
15
+ }));
40
16
  }
41
17
  function deleteCookie(response, name, options) {
42
- response.headers.append(
43
- "Set-Cookie",
44
- (0, import_cookie.stringifySetCookie)({ name, value: "", ...options, maxAge: 0 })
45
- );
18
+ response.headers.append("Set-Cookie", (0, cookie.stringifySetCookie)({
19
+ name,
20
+ value: "",
21
+ ...options,
22
+ maxAge: 0
23
+ }));
46
24
  }
47
25
  function param(request, path) {
48
- const url = new URL(request.url);
49
- const fn = (0, import_path_to_regexp.match)(path);
50
- const result = fn(url.pathname);
51
- if (!result) throw new Error(`Path not matched: ${url.pathname}, path: ${path}`);
52
- return result.params;
26
+ const url = new URL(request.url);
27
+ const result = (0, path_to_regexp.match)(path)(url.pathname);
28
+ if (!result) throw new Error(`Path not matched: ${url.pathname}, path: ${path}`);
29
+ return result.params;
53
30
  }
54
31
  function query(request) {
55
- const url = new URL(request.url);
56
- return Object.fromEntries(url.searchParams.entries());
32
+ const url = new URL(request.url);
33
+ return Object.fromEntries(url.searchParams.entries());
57
34
  }
58
- // Annotate the CommonJS export names for ESM import in node:
59
- 0 && (module.exports = {
60
- deleteCookie,
61
- getCookie,
62
- param,
63
- query,
64
- setCookie
65
- });
35
+ //#endregion
36
+ exports.deleteCookie = deleteCookie;
37
+ exports.getCookie = getCookie;
38
+ exports.param = param;
39
+ exports.query = query;
40
+ exports.setCookie = setCookie;
41
+
66
42
  //# sourceMappingURL=http.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/utils/http.ts"],"sourcesContent":["import { type SerializeOptions, parseCookie, stringifySetCookie } from 'cookie';\nimport { match } from 'path-to-regexp';\n\nexport type CookieOptions = Omit<SerializeOptions, 'encode'>;\n\nexport function getCookie(request: Request, name: string): string | undefined {\n const cookie = request.headers.get('Cookie');\n if (!cookie) return undefined;\n const parsed = parseCookie(cookie);\n return parsed[name];\n}\n\nexport function setCookie(\n response: Response,\n name: string,\n value: string,\n options?: SerializeOptions\n) {\n response.headers.append('Set-Cookie', stringifySetCookie({ name, value, ...options }));\n}\n\nexport function deleteCookie(response: Response, name: string, options?: SerializeOptions) {\n response.headers.append(\n 'Set-Cookie',\n stringifySetCookie({ name, value: '', ...options, maxAge: 0 })\n );\n}\n\ntype PathParam<T extends string> = T extends `${string}:${infer Param}/${infer Rest}`\n ? { [K in Param]: string } & PathParam<Rest>\n : T extends `${string}:${infer Param}`\n ? { [K in Param]: string }\n : // eslint-disable-next-line @typescript-eslint/no-empty-object-type\n {};\n\nexport function param<P extends string>(request: Request, path: P): PathParam<P> {\n const url = new URL(request.url);\n const fn = match(path);\n const result = fn(url.pathname);\n if (!result) throw new Error(`Path not matched: ${url.pathname}, path: ${path}`);\n return result.params as PathParam<P>;\n}\n\nexport function query(request: Request) {\n const url = new URL(request.url);\n return Object.fromEntries(url.searchParams.entries());\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAAuE;AACvE,4BAAsB;AAIf,SAAS,UAAU,SAAkB,MAAkC;AAC5E,QAAM,SAAS,QAAQ,QAAQ,IAAI,QAAQ;AAC3C,MAAI,CAAC,OAAQ,QAAO;AACpB,QAAM,aAAS,2BAAY,MAAM;AACjC,SAAO,OAAO,IAAI;AACpB;AAEO,SAAS,UACd,UACA,MACA,OACA,SACA;AACA,WAAS,QAAQ,OAAO,kBAAc,kCAAmB,EAAE,MAAM,OAAO,GAAG,QAAQ,CAAC,CAAC;AACvF;AAEO,SAAS,aAAa,UAAoB,MAAc,SAA4B;AACzF,WAAS,QAAQ;AAAA,IACf;AAAA,QACA,kCAAmB,EAAE,MAAM,OAAO,IAAI,GAAG,SAAS,QAAQ,EAAE,CAAC;AAAA,EAC/D;AACF;AASO,SAAS,MAAwB,SAAkB,MAAuB;AAC/E,QAAM,MAAM,IAAI,IAAI,QAAQ,GAAG;AAC/B,QAAM,SAAK,6BAAM,IAAI;AACrB,QAAM,SAAS,GAAG,IAAI,QAAQ;AAC9B,MAAI,CAAC,OAAQ,OAAM,IAAI,MAAM,qBAAqB,IAAI,QAAQ,WAAW,IAAI,EAAE;AAC/E,SAAO,OAAO;AAChB;AAEO,SAAS,MAAM,SAAkB;AACtC,QAAM,MAAM,IAAI,IAAI,QAAQ,GAAG;AAC/B,SAAO,OAAO,YAAY,IAAI,aAAa,QAAQ,CAAC;AACtD;","names":[]}
1
+ {"version":3,"file":"http.cjs","names":["cookie"],"sources":["../../src/utils/http.ts"],"sourcesContent":["import { type SerializeOptions, parseCookie, stringifySetCookie } from 'cookie';\nimport { match } from 'path-to-regexp';\n\nexport type CookieOptions = Omit<SerializeOptions, 'encode'>;\n\nexport function getCookie(request: Request, name: string): string | undefined {\n const cookie = request.headers.get('Cookie');\n if (!cookie) return undefined;\n const parsed = parseCookie(cookie);\n return parsed[name];\n}\n\nexport function setCookie(\n response: Response,\n name: string,\n value: string,\n options?: SerializeOptions\n) {\n response.headers.append('Set-Cookie', stringifySetCookie({ name, value, ...options }));\n}\n\nexport function deleteCookie(response: Response, name: string, options?: SerializeOptions) {\n response.headers.append(\n 'Set-Cookie',\n stringifySetCookie({ name, value: '', ...options, maxAge: 0 })\n );\n}\n\ntype PathParam<T extends string> = T extends `${string}:${infer Param}/${infer Rest}`\n ? { [K in Param]: string } & PathParam<Rest>\n : T extends `${string}:${infer Param}`\n ? { [K in Param]: string }\n : // eslint-disable-next-line @typescript-eslint/no-empty-object-type\n {};\n\nexport function param<P extends string>(request: Request, path: P): PathParam<P> {\n const url = new URL(request.url);\n const fn = match(path);\n const result = fn(url.pathname);\n if (!result) throw new Error(`Path not matched: ${url.pathname}, path: ${path}`);\n return result.params as PathParam<P>;\n}\n\nexport function query(request: Request) {\n const url = new URL(request.url);\n return Object.fromEntries(url.searchParams.entries());\n}\n"],"mappings":";;;;AAKA,SAAgB,UAAU,SAAkB,MAAkC;CAC5E,MAAMA,WAAS,QAAQ,QAAQ,IAAI,QAAQ;CAC3C,IAAI,CAACA,UAAQ,OAAO,KAAA;CAEpB,QAAA,GAAA,OAAA,YAAA,CAD2BA,QACf,CAAC,CAAC;AAChB;AAEA,SAAgB,UACd,UACA,MACA,OACA,SACA;CACA,SAAS,QAAQ,OAAO,eAAA,GAAA,OAAA,mBAAA,CAAiC;EAAE;EAAM;EAAO,GAAG;CAAQ,CAAC,CAAC;AACvF;AAEA,SAAgB,aAAa,UAAoB,MAAc,SAA4B;CACzF,SAAS,QAAQ,OACf,eAAA,GAAA,OAAA,mBAAA,CACmB;EAAE;EAAM,OAAO;EAAI,GAAG;EAAS,QAAQ;CAAE,CAAC,CAC/D;AACF;AASA,SAAgB,MAAwB,SAAkB,MAAuB;CAC/E,MAAM,MAAM,IAAI,IAAI,QAAQ,GAAG;CAE/B,MAAM,UAAA,GAAA,eAAA,MAAA,CADW,IACD,CAAC,CAAC,IAAI,QAAQ;CAC9B,IAAI,CAAC,QAAQ,MAAM,IAAI,MAAM,qBAAqB,IAAI,SAAS,UAAU,MAAM;CAC/E,OAAO,OAAO;AAChB;AAEA,SAAgB,MAAM,SAAkB;CACtC,MAAM,MAAM,IAAI,IAAI,QAAQ,GAAG;CAC/B,OAAO,OAAO,YAAY,IAAI,aAAa,QAAQ,CAAC;AACtD"}
@@ -1,17 +1,14 @@
1
- import { SerializeOptions } from 'cookie';
2
-
1
+ import { SerializeOptions } from "cookie";
2
+ //#region src/utils/http.d.ts
3
3
  type CookieOptions = Omit<SerializeOptions, 'encode'>;
4
4
  declare function getCookie(request: Request, name: string): string | undefined;
5
5
  declare function setCookie(response: Response, name: string, value: string, options?: SerializeOptions): void;
6
6
  declare function deleteCookie(response: Response, name: string, options?: SerializeOptions): void;
7
- type PathParam<T extends string> = T extends `${string}:${infer Param}/${infer Rest}` ? {
8
- [K in Param]: string;
9
- } & PathParam<Rest> : T extends `${string}:${infer Param}` ? {
10
- [K in Param]: string;
11
- } : {};
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; } : {};
12
8
  declare function param<P extends string>(request: Request, path: P): PathParam<P>;
13
9
  declare function query(request: Request): {
14
- [k: string]: string;
10
+ [k: string]: string;
15
11
  };
16
-
17
- export { type CookieOptions, deleteCookie, getCookie, param, query, setCookie };
12
+ //#endregion
13
+ export { CookieOptions, deleteCookie, getCookie, param, query, setCookie };
14
+ //# sourceMappingURL=http.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"http.d.cts","names":[],"sources":["../../src/utils/http.ts"],"mappings":";;KAGY,gBAAgB,KAAK;iBAEjB,UAAU,SAAS,SAAS;iBAO5B,UACd,UAAU,UACV,cACA,eACA,UAAU;iBAKI,aAAa,UAAU,UAAU,cAAc,UAAU;KAOpE,UAAU,oBAAoB,6BAA6B,eAAe,YACxE,KAAK,oBAAmB,UAAU,QACrC,6BAA6B,aACxB,KAAK;iBAIE,MAAM,kBAAkB,SAAS,SAAS,MAAM,IAAI,UAAU;iBAQ9D,MAAM,SAAS"}
@@ -1,17 +1,14 @@
1
- import { SerializeOptions } from 'cookie';
2
-
1
+ import { SerializeOptions } from "cookie";
2
+ //#region src/utils/http.d.ts
3
3
  type CookieOptions = Omit<SerializeOptions, 'encode'>;
4
4
  declare function getCookie(request: Request, name: string): string | undefined;
5
5
  declare function setCookie(response: Response, name: string, value: string, options?: SerializeOptions): void;
6
6
  declare function deleteCookie(response: Response, name: string, options?: SerializeOptions): void;
7
- type PathParam<T extends string> = T extends `${string}:${infer Param}/${infer Rest}` ? {
8
- [K in Param]: string;
9
- } & PathParam<Rest> : T extends `${string}:${infer Param}` ? {
10
- [K in Param]: string;
11
- } : {};
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; } : {};
12
8
  declare function param<P extends string>(request: Request, path: P): PathParam<P>;
13
9
  declare function query(request: Request): {
14
- [k: string]: string;
10
+ [k: string]: string;
15
11
  };
16
-
17
- export { type CookieOptions, deleteCookie, getCookie, param, query, setCookie };
12
+ //#endregion
13
+ export { CookieOptions, deleteCookie, getCookie, param, query, setCookie };
14
+ //# sourceMappingURL=http.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"http.d.mts","names":[],"sources":["../../src/utils/http.ts"],"mappings":";;KAGY,gBAAgB,KAAK;iBAEjB,UAAU,SAAS,SAAS;iBAO5B,UACd,UAAU,UACV,cACA,eACA,UAAU;iBAKI,aAAa,UAAU,UAAU,cAAc,UAAU;KAOpE,UAAU,oBAAoB,6BAA6B,eAAe,YACxE,KAAK,oBAAmB,UAAU,QACrC,6BAA6B,aACxB,KAAK;iBAIE,MAAM,kBAAkB,SAAS,SAAS,MAAM,IAAI,UAAU;iBAQ9D,MAAM,SAAS"}
@@ -1,37 +1,37 @@
1
- // src/utils/http.ts
2
1
  import { parseCookie, stringifySetCookie } from "cookie";
3
2
  import { match } from "path-to-regexp";
3
+ //#region src/utils/http.ts
4
4
  function getCookie(request, name) {
5
- const cookie = request.headers.get("Cookie");
6
- if (!cookie) return void 0;
7
- const parsed = parseCookie(cookie);
8
- return parsed[name];
5
+ const cookie = request.headers.get("Cookie");
6
+ if (!cookie) return void 0;
7
+ return parseCookie(cookie)[name];
9
8
  }
10
9
  function setCookie(response, name, value, options) {
11
- response.headers.append("Set-Cookie", stringifySetCookie({ name, value, ...options }));
10
+ response.headers.append("Set-Cookie", stringifySetCookie({
11
+ name,
12
+ value,
13
+ ...options
14
+ }));
12
15
  }
13
16
  function deleteCookie(response, name, options) {
14
- response.headers.append(
15
- "Set-Cookie",
16
- stringifySetCookie({ name, value: "", ...options, maxAge: 0 })
17
- );
17
+ response.headers.append("Set-Cookie", stringifySetCookie({
18
+ name,
19
+ value: "",
20
+ ...options,
21
+ maxAge: 0
22
+ }));
18
23
  }
19
24
  function param(request, path) {
20
- const url = new URL(request.url);
21
- const fn = match(path);
22
- const result = fn(url.pathname);
23
- if (!result) throw new Error(`Path not matched: ${url.pathname}, path: ${path}`);
24
- return result.params;
25
+ const url = new URL(request.url);
26
+ const result = match(path)(url.pathname);
27
+ if (!result) throw new Error(`Path not matched: ${url.pathname}, path: ${path}`);
28
+ return result.params;
25
29
  }
26
30
  function query(request) {
27
- const url = new URL(request.url);
28
- return Object.fromEntries(url.searchParams.entries());
31
+ const url = new URL(request.url);
32
+ return Object.fromEntries(url.searchParams.entries());
29
33
  }
30
- export {
31
- deleteCookie,
32
- getCookie,
33
- param,
34
- query,
35
- setCookie
36
- };
34
+ //#endregion
35
+ export { deleteCookie, getCookie, param, query, setCookie };
36
+
37
37
  //# sourceMappingURL=http.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/utils/http.ts"],"sourcesContent":["import { type SerializeOptions, parseCookie, stringifySetCookie } from 'cookie';\nimport { match } from 'path-to-regexp';\n\nexport type CookieOptions = Omit<SerializeOptions, 'encode'>;\n\nexport function getCookie(request: Request, name: string): string | undefined {\n const cookie = request.headers.get('Cookie');\n if (!cookie) return undefined;\n const parsed = parseCookie(cookie);\n return parsed[name];\n}\n\nexport function setCookie(\n response: Response,\n name: string,\n value: string,\n options?: SerializeOptions\n) {\n response.headers.append('Set-Cookie', stringifySetCookie({ name, value, ...options }));\n}\n\nexport function deleteCookie(response: Response, name: string, options?: SerializeOptions) {\n response.headers.append(\n 'Set-Cookie',\n stringifySetCookie({ name, value: '', ...options, maxAge: 0 })\n );\n}\n\ntype PathParam<T extends string> = T extends `${string}:${infer Param}/${infer Rest}`\n ? { [K in Param]: string } & PathParam<Rest>\n : T extends `${string}:${infer Param}`\n ? { [K in Param]: string }\n : // eslint-disable-next-line @typescript-eslint/no-empty-object-type\n {};\n\nexport function param<P extends string>(request: Request, path: P): PathParam<P> {\n const url = new URL(request.url);\n const fn = match(path);\n const result = fn(url.pathname);\n if (!result) throw new Error(`Path not matched: ${url.pathname}, path: ${path}`);\n return result.params as PathParam<P>;\n}\n\nexport function query(request: Request) {\n const url = new URL(request.url);\n return Object.fromEntries(url.searchParams.entries());\n}\n"],"mappings":";AAAA,SAAgC,aAAa,0BAA0B;AACvE,SAAS,aAAa;AAIf,SAAS,UAAU,SAAkB,MAAkC;AAC5E,QAAM,SAAS,QAAQ,QAAQ,IAAI,QAAQ;AAC3C,MAAI,CAAC,OAAQ,QAAO;AACpB,QAAM,SAAS,YAAY,MAAM;AACjC,SAAO,OAAO,IAAI;AACpB;AAEO,SAAS,UACd,UACA,MACA,OACA,SACA;AACA,WAAS,QAAQ,OAAO,cAAc,mBAAmB,EAAE,MAAM,OAAO,GAAG,QAAQ,CAAC,CAAC;AACvF;AAEO,SAAS,aAAa,UAAoB,MAAc,SAA4B;AACzF,WAAS,QAAQ;AAAA,IACf;AAAA,IACA,mBAAmB,EAAE,MAAM,OAAO,IAAI,GAAG,SAAS,QAAQ,EAAE,CAAC;AAAA,EAC/D;AACF;AASO,SAAS,MAAwB,SAAkB,MAAuB;AAC/E,QAAM,MAAM,IAAI,IAAI,QAAQ,GAAG;AAC/B,QAAM,KAAK,MAAM,IAAI;AACrB,QAAM,SAAS,GAAG,IAAI,QAAQ;AAC9B,MAAI,CAAC,OAAQ,OAAM,IAAI,MAAM,qBAAqB,IAAI,QAAQ,WAAW,IAAI,EAAE;AAC/E,SAAO,OAAO;AAChB;AAEO,SAAS,MAAM,SAAkB;AACtC,QAAM,MAAM,IAAI,IAAI,QAAQ,GAAG;AAC/B,SAAO,OAAO,YAAY,IAAI,aAAa,QAAQ,CAAC;AACtD;","names":[]}
1
+ {"version":3,"file":"http.mjs","names":[],"sources":["../../src/utils/http.ts"],"sourcesContent":["import { type SerializeOptions, parseCookie, stringifySetCookie } from 'cookie';\nimport { match } from 'path-to-regexp';\n\nexport type CookieOptions = Omit<SerializeOptions, 'encode'>;\n\nexport function getCookie(request: Request, name: string): string | undefined {\n const cookie = request.headers.get('Cookie');\n if (!cookie) return undefined;\n const parsed = parseCookie(cookie);\n return parsed[name];\n}\n\nexport function setCookie(\n response: Response,\n name: string,\n value: string,\n options?: SerializeOptions\n) {\n response.headers.append('Set-Cookie', stringifySetCookie({ name, value, ...options }));\n}\n\nexport function deleteCookie(response: Response, name: string, options?: SerializeOptions) {\n response.headers.append(\n 'Set-Cookie',\n stringifySetCookie({ name, value: '', ...options, maxAge: 0 })\n );\n}\n\ntype PathParam<T extends string> = T extends `${string}:${infer Param}/${infer Rest}`\n ? { [K in Param]: string } & PathParam<Rest>\n : T extends `${string}:${infer Param}`\n ? { [K in Param]: string }\n : // eslint-disable-next-line @typescript-eslint/no-empty-object-type\n {};\n\nexport function param<P extends string>(request: Request, path: P): PathParam<P> {\n const url = new URL(request.url);\n const fn = match(path);\n const result = fn(url.pathname);\n if (!result) throw new Error(`Path not matched: ${url.pathname}, path: ${path}`);\n return result.params as PathParam<P>;\n}\n\nexport function query(request: Request) {\n const url = new URL(request.url);\n return Object.fromEntries(url.searchParams.entries());\n}\n"],"mappings":";;;AAKA,SAAgB,UAAU,SAAkB,MAAkC;CAC5E,MAAM,SAAS,QAAQ,QAAQ,IAAI,QAAQ;CAC3C,IAAI,CAAC,QAAQ,OAAO,KAAA;CAEpB,OADe,YAAY,MACf,CAAC,CAAC;AAChB;AAEA,SAAgB,UACd,UACA,MACA,OACA,SACA;CACA,SAAS,QAAQ,OAAO,cAAc,mBAAmB;EAAE;EAAM;EAAO,GAAG;CAAQ,CAAC,CAAC;AACvF;AAEA,SAAgB,aAAa,UAAoB,MAAc,SAA4B;CACzF,SAAS,QAAQ,OACf,cACA,mBAAmB;EAAE;EAAM,OAAO;EAAI,GAAG;EAAS,QAAQ;CAAE,CAAC,CAC/D;AACF;AASA,SAAgB,MAAwB,SAAkB,MAAuB;CAC/E,MAAM,MAAM,IAAI,IAAI,QAAQ,GAAG;CAE/B,MAAM,SADK,MAAM,IACD,CAAC,CAAC,IAAI,QAAQ;CAC9B,IAAI,CAAC,QAAQ,MAAM,IAAI,MAAM,qBAAqB,IAAI,SAAS,UAAU,MAAM;CAC/E,OAAO,OAAO;AAChB;AAEA,SAAgB,MAAM,SAAkB;CACtC,MAAM,MAAM,IAAI,IAAI,QAAQ,GAAG;CAC/B,OAAO,OAAO,YAAY,IAAI,aAAa,QAAQ,CAAC;AACtD"}
@@ -1,33 +1,9 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
-
20
- // src/utils/oauth2.ts
21
- var oauth2_exports = {};
22
- __export(oauth2_exports, {
23
- inWechatBrowser: () => inWechatBrowser
24
- });
25
- module.exports = __toCommonJS(oauth2_exports);
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ //#region src/utils/oauth2.ts
26
3
  function inWechatBrowser() {
27
- return navigator.userAgent.includes("MicroMessenger");
4
+ return navigator.userAgent.includes("MicroMessenger");
28
5
  }
29
- // Annotate the CommonJS export names for ESM import in node:
30
- 0 && (module.exports = {
31
- inWechatBrowser
32
- });
6
+ //#endregion
7
+ exports.inWechatBrowser = inWechatBrowser;
8
+
33
9
  //# sourceMappingURL=oauth2.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/utils/oauth2.ts"],"sourcesContent":["export function inWechatBrowser() {\n return navigator.userAgent.includes('MicroMessenger');\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAO,SAAS,kBAAkB;AAChC,SAAO,UAAU,UAAU,SAAS,gBAAgB;AACtD;","names":[]}
1
+ {"version":3,"file":"oauth2.cjs","names":[],"sources":["../../src/utils/oauth2.ts"],"sourcesContent":["export function inWechatBrowser() {\n return navigator.userAgent.includes('MicroMessenger');\n}\n"],"mappings":";;AAAA,SAAgB,kBAAkB;CAChC,OAAO,UAAU,UAAU,SAAS,gBAAgB;AACtD"}
@@ -1,3 +1,5 @@
1
+ //#region src/utils/oauth2.d.ts
1
2
  declare function inWechatBrowser(): boolean;
2
-
3
+ //#endregion
3
4
  export { inWechatBrowser };
5
+ //# sourceMappingURL=oauth2.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"oauth2.d.cts","names":[],"sources":["../../src/utils/oauth2.ts"],"mappings":";iBAAgB"}
@@ -0,0 +1,5 @@
1
+ //#region src/utils/oauth2.d.ts
2
+ declare function inWechatBrowser(): boolean;
3
+ //#endregion
4
+ export { inWechatBrowser };
5
+ //# sourceMappingURL=oauth2.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"oauth2.d.mts","names":[],"sources":["../../src/utils/oauth2.ts"],"mappings":";iBAAgB"}
@@ -1,8 +1,8 @@
1
- // src/utils/oauth2.ts
1
+ //#region src/utils/oauth2.ts
2
2
  function inWechatBrowser() {
3
- return navigator.userAgent.includes("MicroMessenger");
3
+ return navigator.userAgent.includes("MicroMessenger");
4
4
  }
5
- export {
6
- inWechatBrowser
7
- };
5
+ //#endregion
6
+ export { inWechatBrowser };
7
+
8
8
  //# sourceMappingURL=oauth2.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/utils/oauth2.ts"],"sourcesContent":["export function inWechatBrowser() {\n return navigator.userAgent.includes('MicroMessenger');\n}\n"],"mappings":";AAAO,SAAS,kBAAkB;AAChC,SAAO,UAAU,UAAU,SAAS,gBAAgB;AACtD;","names":[]}
1
+ {"version":3,"file":"oauth2.mjs","names":[],"sources":["../../src/utils/oauth2.ts"],"sourcesContent":["export function inWechatBrowser() {\n return navigator.userAgent.includes('MicroMessenger');\n}\n"],"mappings":";AAAA,SAAgB,kBAAkB;CAChC,OAAO,UAAU,UAAU,SAAS,gBAAgB;AACtD"}