@geekmidas/auth 10.0.0-alpha.12 → 10.0.0-alpha.121

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 (128) hide show
  1. package/dist/{cacheTokenStorage-DaqxdNxI.d.mts → cacheTokenStorage-B3u8Sf-6.d.cts} +2 -5
  2. package/dist/cacheTokenStorage-B3u8Sf-6.d.cts.map +1 -0
  3. package/dist/{cacheTokenStorage-B7sOoysu.d.cts → cacheTokenStorage-B3u8Sf-6.d.mts} +2 -5
  4. package/dist/cacheTokenStorage-B3u8Sf-6.d.mts.map +1 -0
  5. package/dist/cacheTokenStorage.cjs +30 -2
  6. package/dist/cacheTokenStorage.cjs.map +1 -0
  7. package/dist/cacheTokenStorage.d.cts +1 -1
  8. package/dist/cacheTokenStorage.d.mts +1 -1
  9. package/dist/cacheTokenStorage.mjs +29 -2
  10. package/dist/cacheTokenStorage.mjs.map +1 -0
  11. package/dist/client.cjs +144 -6
  12. package/dist/client.cjs.map +1 -0
  13. package/dist/client.d.cts +1 -1
  14. package/dist/client.d.mts +1 -1
  15. package/dist/client.mjs +140 -3
  16. package/dist/client.mjs.map +1 -0
  17. package/dist/cookies.cjs +24 -2
  18. package/dist/cookies.cjs.map +1 -0
  19. package/dist/cookies.d.cts +1 -3
  20. package/dist/cookies.d.cts.map +1 -1
  21. package/dist/cookies.d.mts +1 -3
  22. package/dist/cookies.d.mts.map +1 -1
  23. package/dist/cookies.mjs +23 -2
  24. package/dist/cookies.mjs.map +1 -0
  25. package/dist/hono/jwt.cjs +5 -5
  26. package/dist/hono/jwt.cjs.map +1 -1
  27. package/dist/hono/jwt.d.cts +4 -6
  28. package/dist/hono/jwt.d.cts.map +1 -1
  29. package/dist/hono/jwt.d.mts +4 -6
  30. package/dist/hono/jwt.d.mts.map +1 -1
  31. package/dist/hono/jwt.mjs +4 -5
  32. package/dist/hono/jwt.mjs.map +1 -1
  33. package/dist/hono/oidc.cjs +5 -5
  34. package/dist/hono/oidc.cjs.map +1 -1
  35. package/dist/hono/oidc.d.cts +5 -7
  36. package/dist/hono/oidc.d.cts.map +1 -1
  37. package/dist/hono/oidc.d.mts +5 -7
  38. package/dist/hono/oidc.d.mts.map +1 -1
  39. package/dist/hono/oidc.mjs +4 -5
  40. package/dist/hono/oidc.mjs.map +1 -1
  41. package/dist/index.cjs +5 -5
  42. package/dist/index.d.cts +2 -2
  43. package/dist/index.d.mts +2 -2
  44. package/dist/index.mjs +4 -5
  45. package/dist/{jwt-kejix7rd.d.mts → jwt-CoKrpeMB.d.cts} +2 -3
  46. package/dist/jwt-CoKrpeMB.d.cts.map +1 -0
  47. package/dist/{jwt-3eIuY2dg.d.cts → jwt-CoKrpeMB.d.mts} +2 -3
  48. package/dist/jwt-CoKrpeMB.d.mts.map +1 -0
  49. package/dist/jwt.cjs +56 -4
  50. package/dist/jwt.cjs.map +1 -0
  51. package/dist/jwt.d.cts +1 -1
  52. package/dist/jwt.d.mts +1 -1
  53. package/dist/jwt.mjs +51 -2
  54. package/dist/jwt.mjs.map +1 -0
  55. package/dist/lambda/jwt.cjs +14 -17
  56. package/dist/lambda/jwt.cjs.map +1 -1
  57. package/dist/lambda/jwt.d.cts +4 -6
  58. package/dist/lambda/jwt.d.cts.map +1 -1
  59. package/dist/lambda/jwt.d.mts +4 -6
  60. package/dist/lambda/jwt.d.mts.map +1 -1
  61. package/dist/lambda/jwt.mjs +13 -17
  62. package/dist/lambda/jwt.mjs.map +1 -1
  63. package/dist/lambda/oidc.cjs +14 -17
  64. package/dist/lambda/oidc.cjs.map +1 -1
  65. package/dist/lambda/oidc.d.cts +5 -7
  66. package/dist/lambda/oidc.d.cts.map +1 -1
  67. package/dist/lambda/oidc.d.mts +5 -7
  68. package/dist/lambda/oidc.d.mts.map +1 -1
  69. package/dist/lambda/oidc.mjs +13 -17
  70. package/dist/lambda/oidc.mjs.map +1 -1
  71. package/dist/oidc.cjs +64 -2
  72. package/dist/oidc.cjs.map +1 -0
  73. package/dist/oidc.d.cts +84 -3
  74. package/dist/oidc.d.cts.map +1 -0
  75. package/dist/oidc.d.mts +84 -3
  76. package/dist/oidc.d.mts.map +1 -0
  77. package/dist/oidc.mjs +61 -2
  78. package/dist/oidc.mjs.map +1 -0
  79. package/dist/{chunk-CUT6urMc.cjs → rolldown-runtime-VH7oDXx4.cjs} +8 -10
  80. package/dist/server.cjs +4 -4
  81. package/dist/server.d.cts +3 -3
  82. package/dist/server.d.mts +3 -3
  83. package/dist/server.mjs +3 -4
  84. package/dist/tokenManager.cjs +64 -2
  85. package/dist/tokenManager.cjs.map +1 -0
  86. package/dist/tokenManager.d.cts +37 -2
  87. package/dist/tokenManager.d.cts.map +1 -0
  88. package/dist/tokenManager.d.mts +37 -2
  89. package/dist/tokenManager.d.mts.map +1 -0
  90. package/dist/tokenManager.mjs +61 -2
  91. package/dist/tokenManager.mjs.map +1 -0
  92. package/package.json +5 -4
  93. package/dist/cacheTokenStorage-16NE8Cd9.mjs +0 -32
  94. package/dist/cacheTokenStorage-16NE8Cd9.mjs.map +0 -1
  95. package/dist/cacheTokenStorage-B7sOoysu.d.cts.map +0 -1
  96. package/dist/cacheTokenStorage-CEpMniTi.cjs +0 -38
  97. package/dist/cacheTokenStorage-CEpMniTi.cjs.map +0 -1
  98. package/dist/cacheTokenStorage-DaqxdNxI.d.mts.map +0 -1
  99. package/dist/client-BPl_mMvb.cjs +0 -162
  100. package/dist/client-BPl_mMvb.cjs.map +0 -1
  101. package/dist/client-eidYNJSH.mjs +0 -144
  102. package/dist/client-eidYNJSH.mjs.map +0 -1
  103. package/dist/cookies-Bc6gUjb6.cjs +0 -30
  104. package/dist/cookies-Bc6gUjb6.cjs.map +0 -1
  105. package/dist/cookies-C80f8JtE.mjs +0 -24
  106. package/dist/cookies-C80f8JtE.mjs.map +0 -1
  107. package/dist/jwt-3eIuY2dg.d.cts.map +0 -1
  108. package/dist/jwt-bZR2_t8F.mjs +0 -52
  109. package/dist/jwt-bZR2_t8F.mjs.map +0 -1
  110. package/dist/jwt-clq6I6vG.cjs +0 -70
  111. package/dist/jwt-clq6I6vG.cjs.map +0 -1
  112. package/dist/jwt-kejix7rd.d.mts.map +0 -1
  113. package/dist/oidc-BYHREHir.mjs +0 -62
  114. package/dist/oidc-BYHREHir.mjs.map +0 -1
  115. package/dist/oidc-Ca7GYwmM.d.mts +0 -87
  116. package/dist/oidc-Ca7GYwmM.d.mts.map +0 -1
  117. package/dist/oidc-ChA17wLB.d.cts +0 -87
  118. package/dist/oidc-ChA17wLB.d.cts.map +0 -1
  119. package/dist/oidc-jdMfVyyC.cjs +0 -68
  120. package/dist/oidc-jdMfVyyC.cjs.map +0 -1
  121. package/dist/tokenManager-BbylTW7F.mjs +0 -66
  122. package/dist/tokenManager-BbylTW7F.mjs.map +0 -1
  123. package/dist/tokenManager-CL3yE06D.d.cts +0 -40
  124. package/dist/tokenManager-CL3yE06D.d.cts.map +0 -1
  125. package/dist/tokenManager-CosB7J0i.d.mts +0 -40
  126. package/dist/tokenManager-CosB7J0i.d.mts.map +0 -1
  127. package/dist/tokenManager-PQ-OI_NU.cjs +0 -72
  128. package/dist/tokenManager-PQ-OI_NU.cjs.map +0 -1
@@ -1,5 +1,4 @@
1
1
  import { Cache } from "@geekmidas/cache";
2
-
3
2
  //#region src/client.d.ts
4
3
  interface TokenStorage {
5
4
  getAccessToken(): Promise<string | null> | string | null;
@@ -66,8 +65,6 @@ declare class CacheTokenStorage implements TokenStorage {
66
65
  setRefreshToken(token: string, ttl?: number): Promise<void>;
67
66
  clearTokens(): Promise<void>;
68
67
  }
69
- //# sourceMappingURL=cacheTokenStorage.d.ts.map
70
-
71
68
  //#endregion
72
- export { CacheTokenStorage, LocalStorageTokenStorage, MemoryTokenStorage, TokenClient, TokenClientOptions, TokenStorage };
73
- //# sourceMappingURL=cacheTokenStorage-DaqxdNxI.d.mts.map
69
+ export { TokenClientOptions as a, TokenClient as i, LocalStorageTokenStorage as n, TokenStorage as o, MemoryTokenStorage as r, CacheTokenStorage as t };
70
+ //# sourceMappingURL=cacheTokenStorage-B3u8Sf-6.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cacheTokenStorage-B3u8Sf-6.d.cts","names":[],"sources":["../src/client.ts","../src/cacheTokenStorage.ts"],"mappings":";;UAAiB;EAChB,kBAAkB;EAClB,eAAe,eAAe,eAAe;EAC7C,mBAAmB;EACnB,gBAAgB,eAAe,eAAe;EAC9C,eAAe;;cAGH,oCAAoC;UACxC;UACA;EAER,YACC,yBACA;EAMD;EAKA,eAAe,eAAe;EAK9B;EAKA,gBAAgB,eAAe;EAK/B;;cAOY,8BAA8B;UAClC;UACA;EAER;EAIA,eAAe,eAAe;EAI9B;EAIA,gBAAgB,eAAe;EAI/B;;UAMgB;EAChB,UAAU;EACV;EACA,kBAAkB;IACjB;IACA;;EAED;;cAGY;UACJ;UACA;UACA;UAIA;EAER,YAAY,UAAS;EAOf,kBAAkB;EAIlB,mBAAmB;EAInB,UACL,qBACA,uBACA,oBACA,sBACE;EAOG,eAAe;EAIrB,eAAe;EAaf,mBAAmB,gBAAgB;EAY7B,iBAAiB;EA0CjB,uBAAuB;EAkBvB,qBAAqB,QAAQ;EAK7B,0BAA0B,QAAQ;;;;cClN5B,6BAA6B;UACjC;UACA;UACA;EAER,YACC,OAAO,OACP,yBACA;EAOK,kBAAkB;EAKlB,eAAe,eAAe,eAAe;EAI7C,mBAAmB;EAKnB,gBAAgB,eAAe,eAAe;EAI9C,eAAe"}
@@ -1,5 +1,4 @@
1
1
  import { Cache } from "@geekmidas/cache";
2
-
3
2
  //#region src/client.d.ts
4
3
  interface TokenStorage {
5
4
  getAccessToken(): Promise<string | null> | string | null;
@@ -66,8 +65,6 @@ declare class CacheTokenStorage implements TokenStorage {
66
65
  setRefreshToken(token: string, ttl?: number): Promise<void>;
67
66
  clearTokens(): Promise<void>;
68
67
  }
69
- //# sourceMappingURL=cacheTokenStorage.d.ts.map
70
-
71
68
  //#endregion
72
- export { CacheTokenStorage, LocalStorageTokenStorage, MemoryTokenStorage, TokenClient, TokenClientOptions, TokenStorage };
73
- //# sourceMappingURL=cacheTokenStorage-B7sOoysu.d.cts.map
69
+ export { TokenClientOptions as a, TokenClient as i, LocalStorageTokenStorage as n, TokenStorage as o, MemoryTokenStorage as r, CacheTokenStorage as t };
70
+ //# sourceMappingURL=cacheTokenStorage-B3u8Sf-6.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cacheTokenStorage-B3u8Sf-6.d.mts","names":[],"sources":["../src/client.ts","../src/cacheTokenStorage.ts"],"mappings":";;UAAiB;EAChB,kBAAkB;EAClB,eAAe,eAAe,eAAe;EAC7C,mBAAmB;EACnB,gBAAgB,eAAe,eAAe;EAC9C,eAAe;;cAGH,oCAAoC;UACxC;UACA;EAER,YACC,yBACA;EAMD;EAKA,eAAe,eAAe;EAK9B;EAKA,gBAAgB,eAAe;EAK/B;;cAOY,8BAA8B;UAClC;UACA;EAER;EAIA,eAAe,eAAe;EAI9B;EAIA,gBAAgB,eAAe;EAI/B;;UAMgB;EAChB,UAAU;EACV;EACA,kBAAkB;IACjB;IACA;;EAED;;cAGY;UACJ;UACA;UACA;UAIA;EAER,YAAY,UAAS;EAOf,kBAAkB;EAIlB,mBAAmB;EAInB,UACL,qBACA,uBACA,oBACA,sBACE;EAOG,eAAe;EAIrB,eAAe;EAaf,mBAAmB,gBAAgB;EAY7B,iBAAiB;EA0CjB,uBAAuB;EAkBvB,qBAAqB,QAAQ;EAK7B,0BAA0B,QAAQ;;;;cClN5B,6BAA6B;UACjC;UACA;UACA;EAER,YACC,OAAO,OACP,yBACA;EAOK,kBAAkB;EAKlB,eAAe,eAAe,eAAe;EAI7C,mBAAmB;EAKnB,gBAAgB,eAAe,eAAe;EAI9C,eAAe"}
@@ -1,3 +1,31 @@
1
- const require_cacheTokenStorage = require('./cacheTokenStorage-CEpMniTi.cjs');
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ //#region src/cacheTokenStorage.ts
3
+ var CacheTokenStorage = class {
4
+ cache;
5
+ accessTokenKey;
6
+ refreshTokenKey;
7
+ constructor(cache, accessTokenKey = "access_token", refreshTokenKey = "refresh_token") {
8
+ this.cache = cache;
9
+ this.accessTokenKey = accessTokenKey;
10
+ this.refreshTokenKey = refreshTokenKey;
11
+ }
12
+ async getAccessToken() {
13
+ return await this.cache.get(this.accessTokenKey) ?? null;
14
+ }
15
+ async setAccessToken(token, ttl) {
16
+ await this.cache.set(this.accessTokenKey, token, ttl);
17
+ }
18
+ async getRefreshToken() {
19
+ return await this.cache.get(this.refreshTokenKey) ?? null;
20
+ }
21
+ async setRefreshToken(token, ttl) {
22
+ await this.cache.set(this.refreshTokenKey, token, ttl);
23
+ }
24
+ async clearTokens() {
25
+ await Promise.all([this.cache.delete(this.accessTokenKey), this.cache.delete(this.refreshTokenKey)]);
26
+ }
27
+ };
28
+ //#endregion
29
+ exports.CacheTokenStorage = CacheTokenStorage;
2
30
 
3
- exports.CacheTokenStorage = require_cacheTokenStorage.CacheTokenStorage;
31
+ //# sourceMappingURL=cacheTokenStorage.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cacheTokenStorage.cjs","names":[],"sources":["../src/cacheTokenStorage.ts"],"sourcesContent":["import type { Cache } from '@geekmidas/cache';\nimport type { TokenStorage } from './client.js';\n\nexport class CacheTokenStorage implements TokenStorage {\n\tprivate cache: Cache;\n\tprivate accessTokenKey: string;\n\tprivate refreshTokenKey: string;\n\n\tconstructor(\n\t\tcache: Cache,\n\t\taccessTokenKey: string = 'access_token',\n\t\trefreshTokenKey: string = 'refresh_token',\n\t) {\n\t\tthis.cache = cache;\n\t\tthis.accessTokenKey = accessTokenKey;\n\t\tthis.refreshTokenKey = refreshTokenKey;\n\t}\n\n\tasync getAccessToken(): Promise<string | null> {\n\t\tconst token = await this.cache.get<string>(this.accessTokenKey);\n\t\treturn token ?? null;\n\t}\n\n\tasync setAccessToken(token: string, ttl?: number): Promise<void> {\n\t\tawait this.cache.set(this.accessTokenKey, token, ttl);\n\t}\n\n\tasync getRefreshToken(): Promise<string | null> {\n\t\tconst token = await this.cache.get<string>(this.refreshTokenKey);\n\t\treturn token ?? null;\n\t}\n\n\tasync setRefreshToken(token: string, ttl?: number): Promise<void> {\n\t\tawait this.cache.set(this.refreshTokenKey, token, ttl);\n\t}\n\n\tasync clearTokens(): Promise<void> {\n\t\tawait Promise.all([\n\t\t\tthis.cache.delete(this.accessTokenKey),\n\t\t\tthis.cache.delete(this.refreshTokenKey),\n\t\t]);\n\t}\n}\n"],"mappings":";;AAGA,IAAa,oBAAb,MAAuD;CACtD;CACA;CACA;CAEA,YACC,OACA,iBAAyB,gBACzB,kBAA0B,iBACzB;EACD,KAAK,QAAQ;EACb,KAAK,iBAAiB;EACtB,KAAK,kBAAkB;CACxB;CAEA,MAAM,iBAAyC;EAE9C,OAAO,MADa,KAAK,MAAM,IAAY,KAAK,cAAc,KAC9C;CACjB;CAEA,MAAM,eAAe,OAAe,KAA6B;EAChE,MAAM,KAAK,MAAM,IAAI,KAAK,gBAAgB,OAAO,GAAG;CACrD;CAEA,MAAM,kBAA0C;EAE/C,OAAO,MADa,KAAK,MAAM,IAAY,KAAK,eAAe,KAC/C;CACjB;CAEA,MAAM,gBAAgB,OAAe,KAA6B;EACjE,MAAM,KAAK,MAAM,IAAI,KAAK,iBAAiB,OAAO,GAAG;CACtD;CAEA,MAAM,cAA6B;EAClC,MAAM,QAAQ,IAAI,CACjB,KAAK,MAAM,OAAO,KAAK,cAAc,GACrC,KAAK,MAAM,OAAO,KAAK,eAAe,CACvC,CAAC;CACF;AACD"}
@@ -1,2 +1,2 @@
1
- import { CacheTokenStorage } from "./cacheTokenStorage-B7sOoysu.cjs";
1
+ import { t as CacheTokenStorage } from "./cacheTokenStorage-B3u8Sf-6.cjs";
2
2
  export { CacheTokenStorage };
@@ -1,2 +1,2 @@
1
- import { CacheTokenStorage } from "./cacheTokenStorage-DaqxdNxI.mjs";
1
+ import { t as CacheTokenStorage } from "./cacheTokenStorage-B3u8Sf-6.mjs";
2
2
  export { CacheTokenStorage };
@@ -1,3 +1,30 @@
1
- import { CacheTokenStorage } from "./cacheTokenStorage-16NE8Cd9.mjs";
1
+ //#region src/cacheTokenStorage.ts
2
+ var CacheTokenStorage = class {
3
+ cache;
4
+ accessTokenKey;
5
+ refreshTokenKey;
6
+ constructor(cache, accessTokenKey = "access_token", refreshTokenKey = "refresh_token") {
7
+ this.cache = cache;
8
+ this.accessTokenKey = accessTokenKey;
9
+ this.refreshTokenKey = refreshTokenKey;
10
+ }
11
+ async getAccessToken() {
12
+ return await this.cache.get(this.accessTokenKey) ?? null;
13
+ }
14
+ async setAccessToken(token, ttl) {
15
+ await this.cache.set(this.accessTokenKey, token, ttl);
16
+ }
17
+ async getRefreshToken() {
18
+ return await this.cache.get(this.refreshTokenKey) ?? null;
19
+ }
20
+ async setRefreshToken(token, ttl) {
21
+ await this.cache.set(this.refreshTokenKey, token, ttl);
22
+ }
23
+ async clearTokens() {
24
+ await Promise.all([this.cache.delete(this.accessTokenKey), this.cache.delete(this.refreshTokenKey)]);
25
+ }
26
+ };
27
+ //#endregion
28
+ export { CacheTokenStorage };
2
29
 
3
- export { CacheTokenStorage };
30
+ //# sourceMappingURL=cacheTokenStorage.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cacheTokenStorage.mjs","names":[],"sources":["../src/cacheTokenStorage.ts"],"sourcesContent":["import type { Cache } from '@geekmidas/cache';\nimport type { TokenStorage } from './client.js';\n\nexport class CacheTokenStorage implements TokenStorage {\n\tprivate cache: Cache;\n\tprivate accessTokenKey: string;\n\tprivate refreshTokenKey: string;\n\n\tconstructor(\n\t\tcache: Cache,\n\t\taccessTokenKey: string = 'access_token',\n\t\trefreshTokenKey: string = 'refresh_token',\n\t) {\n\t\tthis.cache = cache;\n\t\tthis.accessTokenKey = accessTokenKey;\n\t\tthis.refreshTokenKey = refreshTokenKey;\n\t}\n\n\tasync getAccessToken(): Promise<string | null> {\n\t\tconst token = await this.cache.get<string>(this.accessTokenKey);\n\t\treturn token ?? null;\n\t}\n\n\tasync setAccessToken(token: string, ttl?: number): Promise<void> {\n\t\tawait this.cache.set(this.accessTokenKey, token, ttl);\n\t}\n\n\tasync getRefreshToken(): Promise<string | null> {\n\t\tconst token = await this.cache.get<string>(this.refreshTokenKey);\n\t\treturn token ?? null;\n\t}\n\n\tasync setRefreshToken(token: string, ttl?: number): Promise<void> {\n\t\tawait this.cache.set(this.refreshTokenKey, token, ttl);\n\t}\n\n\tasync clearTokens(): Promise<void> {\n\t\tawait Promise.all([\n\t\t\tthis.cache.delete(this.accessTokenKey),\n\t\t\tthis.cache.delete(this.refreshTokenKey),\n\t\t]);\n\t}\n}\n"],"mappings":";AAGA,IAAa,oBAAb,MAAuD;CACtD;CACA;CACA;CAEA,YACC,OACA,iBAAyB,gBACzB,kBAA0B,iBACzB;EACD,KAAK,QAAQ;EACb,KAAK,iBAAiB;EACtB,KAAK,kBAAkB;CACxB;CAEA,MAAM,iBAAyC;EAE9C,OAAO,MADa,KAAK,MAAM,IAAY,KAAK,cAAc,KAC9C;CACjB;CAEA,MAAM,eAAe,OAAe,KAA6B;EAChE,MAAM,KAAK,MAAM,IAAI,KAAK,gBAAgB,OAAO,GAAG;CACrD;CAEA,MAAM,kBAA0C;EAE/C,OAAO,MADa,KAAK,MAAM,IAAY,KAAK,eAAe,KAC/C;CACjB;CAEA,MAAM,gBAAgB,OAAe,KAA6B;EACjE,MAAM,KAAK,MAAM,IAAI,KAAK,iBAAiB,OAAO,GAAG;CACtD;CAEA,MAAM,cAA6B;EAClC,MAAM,QAAQ,IAAI,CACjB,KAAK,MAAM,OAAO,KAAK,cAAc,GACrC,KAAK,MAAM,OAAO,KAAK,eAAe,CACvC,CAAC;CACF;AACD"}
package/dist/client.cjs CHANGED
@@ -1,7 +1,145 @@
1
- const require_cacheTokenStorage = require('./cacheTokenStorage-CEpMniTi.cjs');
2
- const require_client = require('./client-BPl_mMvb.cjs');
3
-
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_cacheTokenStorage = require("./cacheTokenStorage.cjs");
3
+ //#region src/client.ts
4
+ var LocalStorageTokenStorage = class {
5
+ accessTokenKey;
6
+ refreshTokenKey;
7
+ constructor(accessTokenKey = "access_token", refreshTokenKey = "refresh_token") {
8
+ this.accessTokenKey = accessTokenKey;
9
+ this.refreshTokenKey = refreshTokenKey;
10
+ }
11
+ getAccessToken() {
12
+ if (typeof window === "undefined") return null;
13
+ return localStorage.getItem(this.accessTokenKey);
14
+ }
15
+ setAccessToken(token, _ttl) {
16
+ if (typeof window === "undefined") return;
17
+ localStorage.setItem(this.accessTokenKey, token);
18
+ }
19
+ getRefreshToken() {
20
+ if (typeof window === "undefined") return null;
21
+ return localStorage.getItem(this.refreshTokenKey);
22
+ }
23
+ setRefreshToken(token, _ttl) {
24
+ if (typeof window === "undefined") return;
25
+ localStorage.setItem(this.refreshTokenKey, token);
26
+ }
27
+ clearTokens() {
28
+ if (typeof window === "undefined") return;
29
+ localStorage.removeItem(this.accessTokenKey);
30
+ localStorage.removeItem(this.refreshTokenKey);
31
+ }
32
+ };
33
+ var MemoryTokenStorage = class {
34
+ accessToken = null;
35
+ refreshToken = null;
36
+ getAccessToken() {
37
+ return this.accessToken;
38
+ }
39
+ setAccessToken(token, _ttl) {
40
+ this.accessToken = token;
41
+ }
42
+ getRefreshToken() {
43
+ return this.refreshToken;
44
+ }
45
+ setRefreshToken(token, _ttl) {
46
+ this.refreshToken = token;
47
+ }
48
+ clearTokens() {
49
+ this.accessToken = null;
50
+ this.refreshToken = null;
51
+ }
52
+ };
53
+ var TokenClient = class {
54
+ storage;
55
+ refreshEndpoint;
56
+ onTokenRefresh;
57
+ onTokenExpired;
58
+ constructor(options = {}) {
59
+ this.storage = options.storage || new LocalStorageTokenStorage();
60
+ this.refreshEndpoint = options.refreshEndpoint;
61
+ this.onTokenRefresh = options.onTokenRefresh;
62
+ this.onTokenExpired = options.onTokenExpired;
63
+ }
64
+ async getAccessToken() {
65
+ return await this.storage.getAccessToken();
66
+ }
67
+ async getRefreshToken() {
68
+ return await this.storage.getRefreshToken();
69
+ }
70
+ async setTokens(accessToken, refreshToken, accessTtl, refreshTtl) {
71
+ await this.storage.setAccessToken(accessToken, accessTtl);
72
+ if (refreshToken) await this.storage.setRefreshToken(refreshToken, refreshTtl);
73
+ }
74
+ async clearTokens() {
75
+ await this.storage.clearTokens();
76
+ }
77
+ isTokenExpired(token) {
78
+ try {
79
+ const payloadPart = token.split(".")[1];
80
+ if (!payloadPart) return true;
81
+ const payload = JSON.parse(atob(payloadPart));
82
+ const now = Math.floor(Date.now() / 1e3);
83
+ return payload.exp < now;
84
+ } catch {
85
+ return true;
86
+ }
87
+ }
88
+ getTokenExpiration(token) {
89
+ try {
90
+ const payloadPart = token.split(".")[1];
91
+ if (!payloadPart) return null;
92
+ const payload = JSON.parse(atob(payloadPart));
93
+ return /* @__PURE__ */ new Date(payload.exp * 1e3);
94
+ } catch {
95
+ return null;
96
+ }
97
+ }
98
+ async refreshTokens() {
99
+ const refreshToken = await this.getRefreshToken();
100
+ if (!refreshToken || !this.refreshEndpoint) return false;
101
+ try {
102
+ const response = await fetch(this.refreshEndpoint, {
103
+ method: "POST",
104
+ headers: { "Content-Type": "application/json" },
105
+ body: JSON.stringify({ refreshToken })
106
+ });
107
+ if (!response.ok) throw new Error("Failed to refresh token");
108
+ const { accessToken, refreshToken: newRefreshToken } = await response.json();
109
+ await this.setTokens(accessToken, newRefreshToken);
110
+ if (this.onTokenRefresh) this.onTokenRefresh({
111
+ accessToken,
112
+ refreshToken: newRefreshToken
113
+ });
114
+ return true;
115
+ } catch (_error) {
116
+ await this.clearTokens();
117
+ if (this.onTokenExpired) this.onTokenExpired();
118
+ return false;
119
+ }
120
+ }
121
+ async getValidAccessToken() {
122
+ const accessToken = await this.getAccessToken();
123
+ if (!accessToken) return null;
124
+ if (this.isTokenExpired(accessToken)) {
125
+ if (!await this.refreshTokens()) return null;
126
+ return await this.getAccessToken();
127
+ }
128
+ return accessToken;
129
+ }
130
+ async createAuthHeaders() {
131
+ const token = await this.getAccessToken();
132
+ return token ? { Authorization: `Bearer ${token}` } : {};
133
+ }
134
+ async createValidAuthHeaders() {
135
+ const token = await this.getValidAccessToken();
136
+ return token ? { Authorization: `Bearer ${token}` } : {};
137
+ }
138
+ };
139
+ //#endregion
4
140
  exports.CacheTokenStorage = require_cacheTokenStorage.CacheTokenStorage;
5
- exports.LocalStorageTokenStorage = require_client.LocalStorageTokenStorage;
6
- exports.MemoryTokenStorage = require_client.MemoryTokenStorage;
7
- exports.TokenClient = require_client.TokenClient;
141
+ exports.LocalStorageTokenStorage = LocalStorageTokenStorage;
142
+ exports.MemoryTokenStorage = MemoryTokenStorage;
143
+ exports.TokenClient = TokenClient;
144
+
145
+ //# sourceMappingURL=client.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.cjs","names":[],"sources":["../src/client.ts"],"sourcesContent":["export interface TokenStorage {\n\tgetAccessToken(): Promise<string | null> | string | null;\n\tsetAccessToken(token: string, ttl?: number): Promise<void> | void;\n\tgetRefreshToken(): Promise<string | null> | string | null;\n\tsetRefreshToken(token: string, ttl?: number): Promise<void> | void;\n\tclearTokens(): Promise<void> | void;\n}\n\nexport class LocalStorageTokenStorage implements TokenStorage {\n\tprivate accessTokenKey: string;\n\tprivate refreshTokenKey: string;\n\n\tconstructor(\n\t\taccessTokenKey: string = 'access_token',\n\t\trefreshTokenKey: string = 'refresh_token',\n\t) {\n\t\tthis.accessTokenKey = accessTokenKey;\n\t\tthis.refreshTokenKey = refreshTokenKey;\n\t}\n\n\tgetAccessToken(): string | null {\n\t\tif (typeof window === 'undefined') return null;\n\t\treturn localStorage.getItem(this.accessTokenKey);\n\t}\n\n\tsetAccessToken(token: string, _ttl?: number): void {\n\t\tif (typeof window === 'undefined') return;\n\t\tlocalStorage.setItem(this.accessTokenKey, token);\n\t}\n\n\tgetRefreshToken(): string | null {\n\t\tif (typeof window === 'undefined') return null;\n\t\treturn localStorage.getItem(this.refreshTokenKey);\n\t}\n\n\tsetRefreshToken(token: string, _ttl?: number): void {\n\t\tif (typeof window === 'undefined') return;\n\t\tlocalStorage.setItem(this.refreshTokenKey, token);\n\t}\n\n\tclearTokens(): void {\n\t\tif (typeof window === 'undefined') return;\n\t\tlocalStorage.removeItem(this.accessTokenKey);\n\t\tlocalStorage.removeItem(this.refreshTokenKey);\n\t}\n}\n\nexport class MemoryTokenStorage implements TokenStorage {\n\tprivate accessToken: string | null = null;\n\tprivate refreshToken: string | null = null;\n\n\tgetAccessToken(): string | null {\n\t\treturn this.accessToken;\n\t}\n\n\tsetAccessToken(token: string, _ttl?: number): void {\n\t\tthis.accessToken = token;\n\t}\n\n\tgetRefreshToken(): string | null {\n\t\treturn this.refreshToken;\n\t}\n\n\tsetRefreshToken(token: string, _ttl?: number): void {\n\t\tthis.refreshToken = token;\n\t}\n\n\tclearTokens(): void {\n\t\tthis.accessToken = null;\n\t\tthis.refreshToken = null;\n\t}\n}\n\nexport interface TokenClientOptions {\n\tstorage?: TokenStorage;\n\trefreshEndpoint?: string;\n\tonTokenRefresh?: (tokens: {\n\t\taccessToken: string;\n\t\trefreshToken?: string;\n\t}) => void;\n\tonTokenExpired?: () => void;\n}\n\nexport class TokenClient {\n\tprivate storage: TokenStorage;\n\tprivate refreshEndpoint?: string;\n\tprivate onTokenRefresh?: (tokens: {\n\t\taccessToken: string;\n\t\trefreshToken?: string;\n\t}) => void;\n\tprivate onTokenExpired?: () => void;\n\n\tconstructor(options: TokenClientOptions = {}) {\n\t\tthis.storage = options.storage || new LocalStorageTokenStorage();\n\t\tthis.refreshEndpoint = options.refreshEndpoint;\n\t\tthis.onTokenRefresh = options.onTokenRefresh;\n\t\tthis.onTokenExpired = options.onTokenExpired;\n\t}\n\n\tasync getAccessToken(): Promise<string | null> {\n\t\treturn await this.storage.getAccessToken();\n\t}\n\n\tasync getRefreshToken(): Promise<string | null> {\n\t\treturn await this.storage.getRefreshToken();\n\t}\n\n\tasync setTokens(\n\t\taccessToken: string,\n\t\trefreshToken?: string,\n\t\taccessTtl?: number,\n\t\trefreshTtl?: number,\n\t): Promise<void> {\n\t\tawait this.storage.setAccessToken(accessToken, accessTtl);\n\t\tif (refreshToken) {\n\t\t\tawait this.storage.setRefreshToken(refreshToken, refreshTtl);\n\t\t}\n\t}\n\n\tasync clearTokens(): Promise<void> {\n\t\tawait this.storage.clearTokens();\n\t}\n\n\tisTokenExpired(token: string): boolean {\n\t\ttry {\n\t\t\tconst parts = token.split('.');\n\t\t\tconst payloadPart = parts[1];\n\t\t\tif (!payloadPart) return true;\n\t\t\tconst payload = JSON.parse(atob(payloadPart));\n\t\t\tconst now = Math.floor(Date.now() / 1000);\n\t\t\treturn payload.exp < now;\n\t\t} catch {\n\t\t\treturn true;\n\t\t}\n\t}\n\n\tgetTokenExpiration(token: string): Date | null {\n\t\ttry {\n\t\t\tconst parts = token.split('.');\n\t\t\tconst payloadPart = parts[1];\n\t\t\tif (!payloadPart) return null;\n\t\t\tconst payload = JSON.parse(atob(payloadPart));\n\t\t\treturn new Date(payload.exp * 1000);\n\t\t} catch {\n\t\t\treturn null;\n\t\t}\n\t}\n\n\tasync refreshTokens(): Promise<boolean> {\n\t\tconst refreshToken = await this.getRefreshToken();\n\n\t\tif (!refreshToken || !this.refreshEndpoint) {\n\t\t\treturn false;\n\t\t}\n\n\t\ttry {\n\t\t\tconst response = await fetch(this.refreshEndpoint, {\n\t\t\t\tmethod: 'POST',\n\t\t\t\theaders: {\n\t\t\t\t\t'Content-Type': 'application/json',\n\t\t\t\t},\n\t\t\t\tbody: JSON.stringify({ refreshToken }),\n\t\t\t});\n\n\t\t\tif (!response.ok) {\n\t\t\t\tthrow new Error('Failed to refresh token');\n\t\t\t}\n\n\t\t\tconst data = (await response.json()) as {\n\t\t\t\taccessToken: string;\n\t\t\t\trefreshToken: string;\n\t\t\t};\n\t\t\tconst { accessToken, refreshToken: newRefreshToken } = data;\n\n\t\t\tawait this.setTokens(accessToken, newRefreshToken);\n\n\t\t\tif (this.onTokenRefresh) {\n\t\t\t\tthis.onTokenRefresh({ accessToken, refreshToken: newRefreshToken });\n\t\t\t}\n\n\t\t\treturn true;\n\t\t} catch (_error) {\n\t\t\tawait this.clearTokens();\n\t\t\tif (this.onTokenExpired) {\n\t\t\t\tthis.onTokenExpired();\n\t\t\t}\n\t\t\treturn false;\n\t\t}\n\t}\n\n\tasync getValidAccessToken(): Promise<string | null> {\n\t\tconst accessToken = await this.getAccessToken();\n\n\t\tif (!accessToken) {\n\t\t\treturn null;\n\t\t}\n\n\t\tif (this.isTokenExpired(accessToken)) {\n\t\t\tconst refreshed = await this.refreshTokens();\n\t\t\tif (!refreshed) {\n\t\t\t\treturn null;\n\t\t\t}\n\t\t\treturn await this.getAccessToken();\n\t\t}\n\n\t\treturn accessToken;\n\t}\n\n\tasync createAuthHeaders(): Promise<Record<string, string>> {\n\t\tconst token = await this.getAccessToken();\n\t\treturn token ? { Authorization: `Bearer ${token}` } : {};\n\t}\n\n\tasync createValidAuthHeaders(): Promise<Record<string, string>> {\n\t\tconst token = await this.getValidAccessToken();\n\t\treturn token ? { Authorization: `Bearer ${token}` } : {};\n\t}\n}\n\nexport { CacheTokenStorage } from './cacheTokenStorage.js';\n"],"mappings":"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"}
package/dist/client.d.cts CHANGED
@@ -1,2 +1,2 @@
1
- import { CacheTokenStorage, LocalStorageTokenStorage, MemoryTokenStorage, TokenClient, TokenClientOptions, TokenStorage } from "./cacheTokenStorage-B7sOoysu.cjs";
1
+ import { a as TokenClientOptions, i as TokenClient, n as LocalStorageTokenStorage, o as TokenStorage, r as MemoryTokenStorage, t as CacheTokenStorage } from "./cacheTokenStorage-B3u8Sf-6.cjs";
2
2
  export { CacheTokenStorage, LocalStorageTokenStorage, MemoryTokenStorage, TokenClient, TokenClientOptions, TokenStorage };
package/dist/client.d.mts CHANGED
@@ -1,2 +1,2 @@
1
- import { CacheTokenStorage, LocalStorageTokenStorage, MemoryTokenStorage, TokenClient, TokenClientOptions, TokenStorage } from "./cacheTokenStorage-DaqxdNxI.mjs";
1
+ import { a as TokenClientOptions, i as TokenClient, n as LocalStorageTokenStorage, o as TokenStorage, r as MemoryTokenStorage, t as CacheTokenStorage } from "./cacheTokenStorage-B3u8Sf-6.mjs";
2
2
  export { CacheTokenStorage, LocalStorageTokenStorage, MemoryTokenStorage, TokenClient, TokenClientOptions, TokenStorage };
package/dist/client.mjs CHANGED
@@ -1,4 +1,141 @@
1
- import { CacheTokenStorage } from "./cacheTokenStorage-16NE8Cd9.mjs";
2
- import { LocalStorageTokenStorage, MemoryTokenStorage, TokenClient } from "./client-eidYNJSH.mjs";
1
+ import { CacheTokenStorage } from "./cacheTokenStorage.mjs";
2
+ //#region src/client.ts
3
+ var LocalStorageTokenStorage = class {
4
+ accessTokenKey;
5
+ refreshTokenKey;
6
+ constructor(accessTokenKey = "access_token", refreshTokenKey = "refresh_token") {
7
+ this.accessTokenKey = accessTokenKey;
8
+ this.refreshTokenKey = refreshTokenKey;
9
+ }
10
+ getAccessToken() {
11
+ if (typeof window === "undefined") return null;
12
+ return localStorage.getItem(this.accessTokenKey);
13
+ }
14
+ setAccessToken(token, _ttl) {
15
+ if (typeof window === "undefined") return;
16
+ localStorage.setItem(this.accessTokenKey, token);
17
+ }
18
+ getRefreshToken() {
19
+ if (typeof window === "undefined") return null;
20
+ return localStorage.getItem(this.refreshTokenKey);
21
+ }
22
+ setRefreshToken(token, _ttl) {
23
+ if (typeof window === "undefined") return;
24
+ localStorage.setItem(this.refreshTokenKey, token);
25
+ }
26
+ clearTokens() {
27
+ if (typeof window === "undefined") return;
28
+ localStorage.removeItem(this.accessTokenKey);
29
+ localStorage.removeItem(this.refreshTokenKey);
30
+ }
31
+ };
32
+ var MemoryTokenStorage = class {
33
+ accessToken = null;
34
+ refreshToken = null;
35
+ getAccessToken() {
36
+ return this.accessToken;
37
+ }
38
+ setAccessToken(token, _ttl) {
39
+ this.accessToken = token;
40
+ }
41
+ getRefreshToken() {
42
+ return this.refreshToken;
43
+ }
44
+ setRefreshToken(token, _ttl) {
45
+ this.refreshToken = token;
46
+ }
47
+ clearTokens() {
48
+ this.accessToken = null;
49
+ this.refreshToken = null;
50
+ }
51
+ };
52
+ var TokenClient = class {
53
+ storage;
54
+ refreshEndpoint;
55
+ onTokenRefresh;
56
+ onTokenExpired;
57
+ constructor(options = {}) {
58
+ this.storage = options.storage || new LocalStorageTokenStorage();
59
+ this.refreshEndpoint = options.refreshEndpoint;
60
+ this.onTokenRefresh = options.onTokenRefresh;
61
+ this.onTokenExpired = options.onTokenExpired;
62
+ }
63
+ async getAccessToken() {
64
+ return await this.storage.getAccessToken();
65
+ }
66
+ async getRefreshToken() {
67
+ return await this.storage.getRefreshToken();
68
+ }
69
+ async setTokens(accessToken, refreshToken, accessTtl, refreshTtl) {
70
+ await this.storage.setAccessToken(accessToken, accessTtl);
71
+ if (refreshToken) await this.storage.setRefreshToken(refreshToken, refreshTtl);
72
+ }
73
+ async clearTokens() {
74
+ await this.storage.clearTokens();
75
+ }
76
+ isTokenExpired(token) {
77
+ try {
78
+ const payloadPart = token.split(".")[1];
79
+ if (!payloadPart) return true;
80
+ const payload = JSON.parse(atob(payloadPart));
81
+ const now = Math.floor(Date.now() / 1e3);
82
+ return payload.exp < now;
83
+ } catch {
84
+ return true;
85
+ }
86
+ }
87
+ getTokenExpiration(token) {
88
+ try {
89
+ const payloadPart = token.split(".")[1];
90
+ if (!payloadPart) return null;
91
+ const payload = JSON.parse(atob(payloadPart));
92
+ return /* @__PURE__ */ new Date(payload.exp * 1e3);
93
+ } catch {
94
+ return null;
95
+ }
96
+ }
97
+ async refreshTokens() {
98
+ const refreshToken = await this.getRefreshToken();
99
+ if (!refreshToken || !this.refreshEndpoint) return false;
100
+ try {
101
+ const response = await fetch(this.refreshEndpoint, {
102
+ method: "POST",
103
+ headers: { "Content-Type": "application/json" },
104
+ body: JSON.stringify({ refreshToken })
105
+ });
106
+ if (!response.ok) throw new Error("Failed to refresh token");
107
+ const { accessToken, refreshToken: newRefreshToken } = await response.json();
108
+ await this.setTokens(accessToken, newRefreshToken);
109
+ if (this.onTokenRefresh) this.onTokenRefresh({
110
+ accessToken,
111
+ refreshToken: newRefreshToken
112
+ });
113
+ return true;
114
+ } catch (_error) {
115
+ await this.clearTokens();
116
+ if (this.onTokenExpired) this.onTokenExpired();
117
+ return false;
118
+ }
119
+ }
120
+ async getValidAccessToken() {
121
+ const accessToken = await this.getAccessToken();
122
+ if (!accessToken) return null;
123
+ if (this.isTokenExpired(accessToken)) {
124
+ if (!await this.refreshTokens()) return null;
125
+ return await this.getAccessToken();
126
+ }
127
+ return accessToken;
128
+ }
129
+ async createAuthHeaders() {
130
+ const token = await this.getAccessToken();
131
+ return token ? { Authorization: `Bearer ${token}` } : {};
132
+ }
133
+ async createValidAuthHeaders() {
134
+ const token = await this.getValidAccessToken();
135
+ return token ? { Authorization: `Bearer ${token}` } : {};
136
+ }
137
+ };
138
+ //#endregion
139
+ export { CacheTokenStorage, LocalStorageTokenStorage, MemoryTokenStorage, TokenClient };
3
140
 
4
- export { CacheTokenStorage, LocalStorageTokenStorage, MemoryTokenStorage, TokenClient };
141
+ //# sourceMappingURL=client.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.mjs","names":[],"sources":["../src/client.ts"],"sourcesContent":["export interface TokenStorage {\n\tgetAccessToken(): Promise<string | null> | string | null;\n\tsetAccessToken(token: string, ttl?: number): Promise<void> | void;\n\tgetRefreshToken(): Promise<string | null> | string | null;\n\tsetRefreshToken(token: string, ttl?: number): Promise<void> | void;\n\tclearTokens(): Promise<void> | void;\n}\n\nexport class LocalStorageTokenStorage implements TokenStorage {\n\tprivate accessTokenKey: string;\n\tprivate refreshTokenKey: string;\n\n\tconstructor(\n\t\taccessTokenKey: string = 'access_token',\n\t\trefreshTokenKey: string = 'refresh_token',\n\t) {\n\t\tthis.accessTokenKey = accessTokenKey;\n\t\tthis.refreshTokenKey = refreshTokenKey;\n\t}\n\n\tgetAccessToken(): string | null {\n\t\tif (typeof window === 'undefined') return null;\n\t\treturn localStorage.getItem(this.accessTokenKey);\n\t}\n\n\tsetAccessToken(token: string, _ttl?: number): void {\n\t\tif (typeof window === 'undefined') return;\n\t\tlocalStorage.setItem(this.accessTokenKey, token);\n\t}\n\n\tgetRefreshToken(): string | null {\n\t\tif (typeof window === 'undefined') return null;\n\t\treturn localStorage.getItem(this.refreshTokenKey);\n\t}\n\n\tsetRefreshToken(token: string, _ttl?: number): void {\n\t\tif (typeof window === 'undefined') return;\n\t\tlocalStorage.setItem(this.refreshTokenKey, token);\n\t}\n\n\tclearTokens(): void {\n\t\tif (typeof window === 'undefined') return;\n\t\tlocalStorage.removeItem(this.accessTokenKey);\n\t\tlocalStorage.removeItem(this.refreshTokenKey);\n\t}\n}\n\nexport class MemoryTokenStorage implements TokenStorage {\n\tprivate accessToken: string | null = null;\n\tprivate refreshToken: string | null = null;\n\n\tgetAccessToken(): string | null {\n\t\treturn this.accessToken;\n\t}\n\n\tsetAccessToken(token: string, _ttl?: number): void {\n\t\tthis.accessToken = token;\n\t}\n\n\tgetRefreshToken(): string | null {\n\t\treturn this.refreshToken;\n\t}\n\n\tsetRefreshToken(token: string, _ttl?: number): void {\n\t\tthis.refreshToken = token;\n\t}\n\n\tclearTokens(): void {\n\t\tthis.accessToken = null;\n\t\tthis.refreshToken = null;\n\t}\n}\n\nexport interface TokenClientOptions {\n\tstorage?: TokenStorage;\n\trefreshEndpoint?: string;\n\tonTokenRefresh?: (tokens: {\n\t\taccessToken: string;\n\t\trefreshToken?: string;\n\t}) => void;\n\tonTokenExpired?: () => void;\n}\n\nexport class TokenClient {\n\tprivate storage: TokenStorage;\n\tprivate refreshEndpoint?: string;\n\tprivate onTokenRefresh?: (tokens: {\n\t\taccessToken: string;\n\t\trefreshToken?: string;\n\t}) => void;\n\tprivate onTokenExpired?: () => void;\n\n\tconstructor(options: TokenClientOptions = {}) {\n\t\tthis.storage = options.storage || new LocalStorageTokenStorage();\n\t\tthis.refreshEndpoint = options.refreshEndpoint;\n\t\tthis.onTokenRefresh = options.onTokenRefresh;\n\t\tthis.onTokenExpired = options.onTokenExpired;\n\t}\n\n\tasync getAccessToken(): Promise<string | null> {\n\t\treturn await this.storage.getAccessToken();\n\t}\n\n\tasync getRefreshToken(): Promise<string | null> {\n\t\treturn await this.storage.getRefreshToken();\n\t}\n\n\tasync setTokens(\n\t\taccessToken: string,\n\t\trefreshToken?: string,\n\t\taccessTtl?: number,\n\t\trefreshTtl?: number,\n\t): Promise<void> {\n\t\tawait this.storage.setAccessToken(accessToken, accessTtl);\n\t\tif (refreshToken) {\n\t\t\tawait this.storage.setRefreshToken(refreshToken, refreshTtl);\n\t\t}\n\t}\n\n\tasync clearTokens(): Promise<void> {\n\t\tawait this.storage.clearTokens();\n\t}\n\n\tisTokenExpired(token: string): boolean {\n\t\ttry {\n\t\t\tconst parts = token.split('.');\n\t\t\tconst payloadPart = parts[1];\n\t\t\tif (!payloadPart) return true;\n\t\t\tconst payload = JSON.parse(atob(payloadPart));\n\t\t\tconst now = Math.floor(Date.now() / 1000);\n\t\t\treturn payload.exp < now;\n\t\t} catch {\n\t\t\treturn true;\n\t\t}\n\t}\n\n\tgetTokenExpiration(token: string): Date | null {\n\t\ttry {\n\t\t\tconst parts = token.split('.');\n\t\t\tconst payloadPart = parts[1];\n\t\t\tif (!payloadPart) return null;\n\t\t\tconst payload = JSON.parse(atob(payloadPart));\n\t\t\treturn new Date(payload.exp * 1000);\n\t\t} catch {\n\t\t\treturn null;\n\t\t}\n\t}\n\n\tasync refreshTokens(): Promise<boolean> {\n\t\tconst refreshToken = await this.getRefreshToken();\n\n\t\tif (!refreshToken || !this.refreshEndpoint) {\n\t\t\treturn false;\n\t\t}\n\n\t\ttry {\n\t\t\tconst response = await fetch(this.refreshEndpoint, {\n\t\t\t\tmethod: 'POST',\n\t\t\t\theaders: {\n\t\t\t\t\t'Content-Type': 'application/json',\n\t\t\t\t},\n\t\t\t\tbody: JSON.stringify({ refreshToken }),\n\t\t\t});\n\n\t\t\tif (!response.ok) {\n\t\t\t\tthrow new Error('Failed to refresh token');\n\t\t\t}\n\n\t\t\tconst data = (await response.json()) as {\n\t\t\t\taccessToken: string;\n\t\t\t\trefreshToken: string;\n\t\t\t};\n\t\t\tconst { accessToken, refreshToken: newRefreshToken } = data;\n\n\t\t\tawait this.setTokens(accessToken, newRefreshToken);\n\n\t\t\tif (this.onTokenRefresh) {\n\t\t\t\tthis.onTokenRefresh({ accessToken, refreshToken: newRefreshToken });\n\t\t\t}\n\n\t\t\treturn true;\n\t\t} catch (_error) {\n\t\t\tawait this.clearTokens();\n\t\t\tif (this.onTokenExpired) {\n\t\t\t\tthis.onTokenExpired();\n\t\t\t}\n\t\t\treturn false;\n\t\t}\n\t}\n\n\tasync getValidAccessToken(): Promise<string | null> {\n\t\tconst accessToken = await this.getAccessToken();\n\n\t\tif (!accessToken) {\n\t\t\treturn null;\n\t\t}\n\n\t\tif (this.isTokenExpired(accessToken)) {\n\t\t\tconst refreshed = await this.refreshTokens();\n\t\t\tif (!refreshed) {\n\t\t\t\treturn null;\n\t\t\t}\n\t\t\treturn await this.getAccessToken();\n\t\t}\n\n\t\treturn accessToken;\n\t}\n\n\tasync createAuthHeaders(): Promise<Record<string, string>> {\n\t\tconst token = await this.getAccessToken();\n\t\treturn token ? { Authorization: `Bearer ${token}` } : {};\n\t}\n\n\tasync createValidAuthHeaders(): Promise<Record<string, string>> {\n\t\tconst token = await this.getValidAccessToken();\n\t\treturn token ? { Authorization: `Bearer ${token}` } : {};\n\t}\n}\n\nexport { CacheTokenStorage } from './cacheTokenStorage.js';\n"],"mappings":"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"}
package/dist/cookies.cjs CHANGED
@@ -1,3 +1,25 @@
1
- const require_cookies = require('./cookies-Bc6gUjb6.cjs');
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ //#region src/cookies.ts
3
+ /**
4
+ * Reads one cookie out of a `Cookie` header.
5
+ *
6
+ * The header is a list of `name=value` pairs, so the name has to be matched
7
+ * against a whole pair. Searching the raw header for `name=` instead lets an
8
+ * attacker prefix their own cookie — `evil_session=ATTACKER; session=REAL`
9
+ * contains `session=ATTACKER` — and the first match wins.
10
+ */
11
+ function readCookie(cookieHeader, name) {
12
+ if (!cookieHeader) return null;
13
+ for (const pair of cookieHeader.split(";")) {
14
+ const separator = pair.indexOf("=");
15
+ if (separator === -1) continue;
16
+ if (pair.slice(0, separator).trim() !== name) continue;
17
+ const value = pair.slice(separator + 1).trim();
18
+ return value === "" ? null : value;
19
+ }
20
+ return null;
21
+ }
22
+ //#endregion
23
+ exports.readCookie = readCookie;
2
24
 
3
- exports.readCookie = require_cookies.readCookie;
25
+ //# sourceMappingURL=cookies.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cookies.cjs","names":[],"sources":["../src/cookies.ts"],"sourcesContent":["/**\n * Reads one cookie out of a `Cookie` header.\n *\n * The header is a list of `name=value` pairs, so the name has to be matched\n * against a whole pair. Searching the raw header for `name=` instead lets an\n * attacker prefix their own cookie — `evil_session=ATTACKER; session=REAL`\n * contains `session=ATTACKER` — and the first match wins.\n */\nexport function readCookie(\n\tcookieHeader: string | undefined,\n\tname: string,\n): string | null {\n\tif (!cookieHeader) {\n\t\treturn null;\n\t}\n\n\tfor (const pair of cookieHeader.split(';')) {\n\t\tconst separator = pair.indexOf('=');\n\t\tif (separator === -1) {\n\t\t\tcontinue;\n\t\t}\n\n\t\tif (pair.slice(0, separator).trim() !== name) {\n\t\t\tcontinue;\n\t\t}\n\n\t\tconst value = pair.slice(separator + 1).trim();\n\t\treturn value === '' ? null : value;\n\t}\n\n\treturn null;\n}\n"],"mappings":";;;;;;;;;;AAQA,SAAgB,WACf,cACA,MACgB;CAChB,IAAI,CAAC,cACJ,OAAO;CAGR,KAAK,MAAM,QAAQ,aAAa,MAAM,GAAG,GAAG;EAC3C,MAAM,YAAY,KAAK,QAAQ,GAAG;EAClC,IAAI,cAAc,IACjB;EAGD,IAAI,KAAK,MAAM,GAAG,SAAS,CAAC,CAAC,KAAK,MAAM,MACvC;EAGD,MAAM,QAAQ,KAAK,MAAM,YAAY,CAAC,CAAC,CAAC,KAAK;EAC7C,OAAO,UAAU,KAAK,OAAO;CAC9B;CAEA,OAAO;AACR"}
@@ -7,8 +7,6 @@
7
7
  * attacker prefix their own cookie — `evil_session=ATTACKER; session=REAL`
8
8
  * contains `session=ATTACKER` — and the first match wins.
9
9
  */
10
- declare function readCookie(cookieHeader: string | undefined, name: string): string | null;
11
- //# sourceMappingURL=cookies.d.ts.map
10
+ export declare function readCookie(cookieHeader: string | undefined, name: string): string | null;
12
11
  //#endregion
13
- export { readCookie };
14
12
  //# sourceMappingURL=cookies.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"cookies.d.cts","names":[],"sources":["../src/cookies.ts"],"sourcesContent":[],"mappings":";;AAQA;;;;;;;iBAAgB,UAAA"}
1
+ {"version":3,"file":"cookies.d.cts","names":[],"sources":["../src/cookies.ts"],"mappings":";;;;;;;;;wBAQgB,WACf,kCACA"}
@@ -7,8 +7,6 @@
7
7
  * attacker prefix their own cookie — `evil_session=ATTACKER; session=REAL`
8
8
  * contains `session=ATTACKER` — and the first match wins.
9
9
  */
10
- declare function readCookie(cookieHeader: string | undefined, name: string): string | null;
11
- //# sourceMappingURL=cookies.d.ts.map
10
+ export declare function readCookie(cookieHeader: string | undefined, name: string): string | null;
12
11
  //#endregion
13
- export { readCookie };
14
12
  //# sourceMappingURL=cookies.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"cookies.d.mts","names":[],"sources":["../src/cookies.ts"],"sourcesContent":[],"mappings":";;AAQA;;;;;;;iBAAgB,UAAA"}
1
+ {"version":3,"file":"cookies.d.mts","names":[],"sources":["../src/cookies.ts"],"mappings":";;;;;;;;;wBAQgB,WACf,kCACA"}
package/dist/cookies.mjs CHANGED
@@ -1,3 +1,24 @@
1
- import { readCookie } from "./cookies-C80f8JtE.mjs";
1
+ //#region src/cookies.ts
2
+ /**
3
+ * Reads one cookie out of a `Cookie` header.
4
+ *
5
+ * The header is a list of `name=value` pairs, so the name has to be matched
6
+ * against a whole pair. Searching the raw header for `name=` instead lets an
7
+ * attacker prefix their own cookie — `evil_session=ATTACKER; session=REAL`
8
+ * contains `session=ATTACKER` — and the first match wins.
9
+ */
10
+ function readCookie(cookieHeader, name) {
11
+ if (!cookieHeader) return null;
12
+ for (const pair of cookieHeader.split(";")) {
13
+ const separator = pair.indexOf("=");
14
+ if (separator === -1) continue;
15
+ if (pair.slice(0, separator).trim() !== name) continue;
16
+ const value = pair.slice(separator + 1).trim();
17
+ return value === "" ? null : value;
18
+ }
19
+ return null;
20
+ }
21
+ //#endregion
22
+ export { readCookie };
2
23
 
3
- export { readCookie };
24
+ //# sourceMappingURL=cookies.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cookies.mjs","names":[],"sources":["../src/cookies.ts"],"sourcesContent":["/**\n * Reads one cookie out of a `Cookie` header.\n *\n * The header is a list of `name=value` pairs, so the name has to be matched\n * against a whole pair. Searching the raw header for `name=` instead lets an\n * attacker prefix their own cookie — `evil_session=ATTACKER; session=REAL`\n * contains `session=ATTACKER` — and the first match wins.\n */\nexport function readCookie(\n\tcookieHeader: string | undefined,\n\tname: string,\n): string | null {\n\tif (!cookieHeader) {\n\t\treturn null;\n\t}\n\n\tfor (const pair of cookieHeader.split(';')) {\n\t\tconst separator = pair.indexOf('=');\n\t\tif (separator === -1) {\n\t\t\tcontinue;\n\t\t}\n\n\t\tif (pair.slice(0, separator).trim() !== name) {\n\t\t\tcontinue;\n\t\t}\n\n\t\tconst value = pair.slice(separator + 1).trim();\n\t\treturn value === '' ? null : value;\n\t}\n\n\treturn null;\n}\n"],"mappings":";;;;;;;;;AAQA,SAAgB,WACf,cACA,MACgB;CAChB,IAAI,CAAC,cACJ,OAAO;CAGR,KAAK,MAAM,QAAQ,aAAa,MAAM,GAAG,GAAG;EAC3C,MAAM,YAAY,KAAK,QAAQ,GAAG;EAClC,IAAI,cAAc,IACjB;EAGD,IAAI,KAAK,MAAM,GAAG,SAAS,CAAC,CAAC,KAAK,MAAM,MACvC;EAGD,MAAM,QAAQ,KAAK,MAAM,YAAY,CAAC,CAAC,CAAC,KAAK;EAC7C,OAAO,UAAU,KAAK,OAAO;CAC9B;CAEA,OAAO;AACR"}
package/dist/hono/jwt.cjs CHANGED
@@ -1,6 +1,6 @@
1
- const require_cookies = require('../cookies-Bc6gUjb6.cjs');
2
- const require_jwt = require('../jwt-clq6I6vG.cjs');
3
-
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_cookies = require("../cookies.cjs");
3
+ const require_jwt = require("../jwt.cjs");
4
4
  //#region src/hono/jwt.ts
5
5
  function extractToken(c, options = {}) {
6
6
  const { headerName = "authorization", cookieName, tokenPrefix = "Bearer " } = options;
@@ -50,7 +50,7 @@ var JwtMiddleware = class {
50
50
  return async (c, next) => {
51
51
  const token = extractToken(c, this.extraction);
52
52
  if (!token) {
53
- if (this.onError) return this.onError(c, new Error("No token provided"));
53
+ if (this.onError) return this.onError(c, /* @__PURE__ */ new Error("No token provided"));
54
54
  return c.json({ error: "Unauthorized" }, 401);
55
55
  }
56
56
  try {
@@ -83,7 +83,7 @@ var JwtMiddleware = class {
83
83
  };
84
84
  }
85
85
  };
86
-
87
86
  //#endregion
88
87
  exports.JwtMiddleware = JwtMiddleware;
88
+
89
89
  //# sourceMappingURL=jwt.cjs.map