@geekmidas/auth 0.1.0 → 1.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 (117) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/dist/{cacheTokenStorage-Ca05vf3T.mjs → cacheTokenStorage-16NE8Cd9.mjs} +3 -3
  3. package/dist/cacheTokenStorage-16NE8Cd9.mjs.map +1 -0
  4. package/dist/{cacheTokenStorage-BzBRJfd-.d.mts → cacheTokenStorage-B7sOoysu.d.cts} +8 -6
  5. package/dist/cacheTokenStorage-B7sOoysu.d.cts.map +1 -0
  6. package/dist/{cacheTokenStorage-CvptztkW.cjs → cacheTokenStorage-CEpMniTi.cjs} +3 -3
  7. package/dist/cacheTokenStorage-CEpMniTi.cjs.map +1 -0
  8. package/dist/{cacheTokenStorage-yNUpDD8W.d.cts → cacheTokenStorage-_tq4Kmhc.d.mts} +8 -6
  9. package/dist/cacheTokenStorage-_tq4Kmhc.d.mts.map +1 -0
  10. package/dist/cacheTokenStorage.cjs +1 -1
  11. package/dist/cacheTokenStorage.d.cts +1 -1
  12. package/dist/cacheTokenStorage.d.mts +1 -1
  13. package/dist/cacheTokenStorage.mjs +1 -1
  14. package/dist/{client-DaiUm0UZ.cjs → client-BPl_mMvb.cjs} +14 -8
  15. package/dist/client-BPl_mMvb.cjs.map +1 -0
  16. package/dist/{client-DjNZS6vZ.mjs → client-eidYNJSH.mjs} +14 -8
  17. package/dist/client-eidYNJSH.mjs.map +1 -0
  18. package/dist/client.cjs +2 -2
  19. package/dist/client.d.cts +1 -1
  20. package/dist/client.d.mts +1 -1
  21. package/dist/client.mjs +2 -2
  22. package/dist/hono/jwt.cjs +1 -1
  23. package/dist/hono/jwt.cjs.map +1 -1
  24. package/dist/hono/jwt.d.cts +2 -1
  25. package/dist/hono/jwt.d.cts.map +1 -0
  26. package/dist/hono/jwt.d.mts +2 -1
  27. package/dist/hono/jwt.d.mts.map +1 -0
  28. package/dist/hono/jwt.mjs +1 -1
  29. package/dist/hono/jwt.mjs.map +1 -1
  30. package/dist/hono/oidc.cjs +1 -1
  31. package/dist/hono/oidc.cjs.map +1 -1
  32. package/dist/hono/oidc.d.cts +3 -2
  33. package/dist/hono/oidc.d.cts.map +1 -0
  34. package/dist/hono/oidc.d.mts +3 -2
  35. package/dist/hono/oidc.d.mts.map +1 -0
  36. package/dist/hono/oidc.mjs +1 -1
  37. package/dist/hono/oidc.mjs.map +1 -1
  38. package/dist/index.cjs +3 -3
  39. package/dist/index.d.cts +2 -2
  40. package/dist/index.d.mts +2 -2
  41. package/dist/index.mjs +3 -3
  42. package/dist/{jwt-DF9kFbmh.d.cts → jwt-3eIuY2dg.d.cts} +2 -1
  43. package/dist/jwt-3eIuY2dg.d.cts.map +1 -0
  44. package/dist/jwt-Bo_eACEi.cjs.map +1 -1
  45. package/dist/{jwt-DH8CJ2xC.d.mts → jwt-BqLlRkw-.d.mts} +2 -1
  46. package/dist/jwt-BqLlRkw-.d.mts.map +1 -0
  47. package/dist/jwt-D88cPJyT.mjs.map +1 -1
  48. package/dist/jwt.d.cts +1 -1
  49. package/dist/jwt.d.mts +1 -1
  50. package/dist/lambda/jwt.cjs +2 -2
  51. package/dist/lambda/jwt.cjs.map +1 -1
  52. package/dist/lambda/jwt.d.cts +2 -1
  53. package/dist/lambda/jwt.d.cts.map +1 -0
  54. package/dist/lambda/jwt.d.mts +2 -1
  55. package/dist/lambda/jwt.d.mts.map +1 -0
  56. package/dist/lambda/jwt.mjs +2 -2
  57. package/dist/lambda/jwt.mjs.map +1 -1
  58. package/dist/lambda/oidc.cjs +2 -2
  59. package/dist/lambda/oidc.cjs.map +1 -1
  60. package/dist/lambda/oidc.d.cts +3 -2
  61. package/dist/lambda/oidc.d.cts.map +1 -0
  62. package/dist/lambda/oidc.d.mts +3 -2
  63. package/dist/lambda/oidc.d.mts.map +1 -0
  64. package/dist/lambda/oidc.mjs +2 -2
  65. package/dist/lambda/oidc.mjs.map +1 -1
  66. package/dist/oidc-C0KyYaAK.cjs.map +1 -1
  67. package/dist/{oidc-CKOGLxjV.d.mts → oidc-ChA17wLB.d.cts} +3 -2
  68. package/dist/oidc-ChA17wLB.d.cts.map +1 -0
  69. package/dist/{oidc-DDLIB5gb.d.cts → oidc-DTRgBBl6.d.mts} +3 -2
  70. package/dist/oidc-DTRgBBl6.d.mts.map +1 -0
  71. package/dist/oidc-KA30gMlx.mjs.map +1 -1
  72. package/dist/oidc.d.cts +2 -2
  73. package/dist/oidc.d.mts +2 -2
  74. package/dist/server.cjs +2 -2
  75. package/dist/server.d.cts +2 -2
  76. package/dist/server.d.mts +2 -2
  77. package/dist/server.mjs +2 -2
  78. package/dist/{tokenManager--Q93eNYr.d.mts → tokenManager-CL3yE06D.d.cts} +2 -1
  79. package/dist/tokenManager-CL3yE06D.d.cts.map +1 -0
  80. package/dist/{tokenManager-BVXxfHRa.mjs → tokenManager-Ci2Tgxp8.mjs} +5 -3
  81. package/dist/tokenManager-Ci2Tgxp8.mjs.map +1 -0
  82. package/dist/{tokenManager-EPmwgai2.cjs → tokenManager-CvEMgxOp.cjs} +5 -3
  83. package/dist/tokenManager-CvEMgxOp.cjs.map +1 -0
  84. package/dist/{tokenManager-H6-lWEah.d.cts → tokenManager-RrwjL0y-.d.mts} +2 -1
  85. package/dist/tokenManager-RrwjL0y-.d.mts.map +1 -0
  86. package/dist/tokenManager.cjs +1 -1
  87. package/dist/tokenManager.d.cts +1 -1
  88. package/dist/tokenManager.d.mts +1 -1
  89. package/dist/tokenManager.mjs +1 -1
  90. package/package.json +3 -3
  91. package/src/__tests__/cacheTokenStorage.spec.ts +148 -148
  92. package/src/__tests__/client.spec.ts +339 -339
  93. package/src/__tests__/hono-jwt.spec.ts +219 -219
  94. package/src/__tests__/hono-oidc.spec.ts +560 -560
  95. package/src/__tests__/jwt.spec.ts +150 -127
  96. package/src/__tests__/lambda-jwt.spec.ts +205 -205
  97. package/src/__tests__/lambda-oidc.spec.ts +580 -579
  98. package/src/__tests__/oidc.spec.ts +365 -365
  99. package/src/__tests__/tokenManager.spec.ts +254 -254
  100. package/src/cacheTokenStorage.ts +32 -32
  101. package/src/client.ts +199 -190
  102. package/src/hono/jwt.ts +111 -111
  103. package/src/hono/oidc.ts +131 -131
  104. package/src/index.ts +2 -2
  105. package/src/jwt.ts +57 -57
  106. package/src/lambda/jwt.ts +170 -170
  107. package/src/lambda/oidc.ts +165 -165
  108. package/src/oidc.ts +121 -121
  109. package/src/server.ts +6 -7
  110. package/src/tokenManager.ts +89 -87
  111. package/tsconfig.json +10 -0
  112. package/dist/cacheTokenStorage-Ca05vf3T.mjs.map +0 -1
  113. package/dist/cacheTokenStorage-CvptztkW.cjs.map +0 -1
  114. package/dist/client-DaiUm0UZ.cjs.map +0 -1
  115. package/dist/client-DjNZS6vZ.mjs.map +0 -1
  116. package/dist/tokenManager-BVXxfHRa.mjs.map +0 -1
  117. package/dist/tokenManager-EPmwgai2.cjs.map +0 -1
@@ -4,210 +4,210 @@ import { beforeEach, describe, expect, it } from 'vitest';
4
4
  import { CacheTokenStorage } from '../cacheTokenStorage.ts';
5
5
 
6
6
  describe('CacheTokenStorage', () => {
7
- let storage: CacheTokenStorage;
8
- let cache: Cache<string>;
7
+ let storage: CacheTokenStorage;
8
+ let cache: Cache<string>;
9
9
 
10
- beforeEach(() => {
11
- cache = new InMemoryCache<string>();
12
- storage = new CacheTokenStorage(cache);
13
- });
10
+ beforeEach(() => {
11
+ cache = new InMemoryCache<string>();
12
+ storage = new CacheTokenStorage(cache);
13
+ });
14
14
 
15
- describe('access token operations', () => {
16
- it('should store and retrieve access token', async () => {
17
- await storage.setAccessToken('test-access-token');
15
+ describe('access token operations', () => {
16
+ it('should store and retrieve access token', async () => {
17
+ await storage.setAccessToken('test-access-token');
18
18
 
19
- const token = await storage.getAccessToken();
19
+ const token = await storage.getAccessToken();
20
20
 
21
- expect(token).toBe('test-access-token');
22
- });
21
+ expect(token).toBe('test-access-token');
22
+ });
23
23
 
24
- it('should return null when no access token exists', async () => {
25
- const token = await storage.getAccessToken();
24
+ it('should return null when no access token exists', async () => {
25
+ const token = await storage.getAccessToken();
26
26
 
27
- expect(token).toBeNull();
28
- });
27
+ expect(token).toBeNull();
28
+ });
29
29
 
30
- it('should store access token with TTL', async () => {
31
- await storage.setAccessToken('test-access-token', 3600);
30
+ it('should store access token with TTL', async () => {
31
+ await storage.setAccessToken('test-access-token', 3600);
32
32
 
33
- const token = await storage.getAccessToken();
33
+ const token = await storage.getAccessToken();
34
34
 
35
- expect(token).toBe('test-access-token');
36
- });
35
+ expect(token).toBe('test-access-token');
36
+ });
37
37
 
38
- it('should overwrite existing access token', async () => {
39
- await storage.setAccessToken('first-token');
40
- await storage.setAccessToken('second-token');
38
+ it('should overwrite existing access token', async () => {
39
+ await storage.setAccessToken('first-token');
40
+ await storage.setAccessToken('second-token');
41
41
 
42
- const token = await storage.getAccessToken();
42
+ const token = await storage.getAccessToken();
43
43
 
44
- expect(token).toBe('second-token');
45
- });
46
- });
44
+ expect(token).toBe('second-token');
45
+ });
46
+ });
47
47
 
48
- describe('refresh token operations', () => {
49
- it('should store and retrieve refresh token', async () => {
50
- await storage.setRefreshToken('test-refresh-token');
48
+ describe('refresh token operations', () => {
49
+ it('should store and retrieve refresh token', async () => {
50
+ await storage.setRefreshToken('test-refresh-token');
51
51
 
52
- const token = await storage.getRefreshToken();
52
+ const token = await storage.getRefreshToken();
53
53
 
54
- expect(token).toBe('test-refresh-token');
55
- });
54
+ expect(token).toBe('test-refresh-token');
55
+ });
56
56
 
57
- it('should return null when no refresh token exists', async () => {
58
- const token = await storage.getRefreshToken();
57
+ it('should return null when no refresh token exists', async () => {
58
+ const token = await storage.getRefreshToken();
59
59
 
60
- expect(token).toBeNull();
61
- });
60
+ expect(token).toBeNull();
61
+ });
62
62
 
63
- it('should store refresh token with TTL', async () => {
64
- await storage.setRefreshToken('test-refresh-token', 7200);
63
+ it('should store refresh token with TTL', async () => {
64
+ await storage.setRefreshToken('test-refresh-token', 7200);
65
65
 
66
- const token = await storage.getRefreshToken();
66
+ const token = await storage.getRefreshToken();
67
67
 
68
- expect(token).toBe('test-refresh-token');
69
- });
68
+ expect(token).toBe('test-refresh-token');
69
+ });
70
70
 
71
- it('should overwrite existing refresh token', async () => {
72
- await storage.setRefreshToken('first-refresh-token');
73
- await storage.setRefreshToken('second-refresh-token');
71
+ it('should overwrite existing refresh token', async () => {
72
+ await storage.setRefreshToken('first-refresh-token');
73
+ await storage.setRefreshToken('second-refresh-token');
74
74
 
75
- const token = await storage.getRefreshToken();
75
+ const token = await storage.getRefreshToken();
76
76
 
77
- expect(token).toBe('second-refresh-token');
78
- });
79
- });
77
+ expect(token).toBe('second-refresh-token');
78
+ });
79
+ });
80
80
 
81
- describe('token lifecycle', () => {
82
- it('should store both tokens independently', async () => {
83
- await storage.setAccessToken('access-token');
84
- await storage.setRefreshToken('refresh-token');
81
+ describe('token lifecycle', () => {
82
+ it('should store both tokens independently', async () => {
83
+ await storage.setAccessToken('access-token');
84
+ await storage.setRefreshToken('refresh-token');
85
85
 
86
- const accessToken = await storage.getAccessToken();
87
- const refreshToken = await storage.getRefreshToken();
86
+ const accessToken = await storage.getAccessToken();
87
+ const refreshToken = await storage.getRefreshToken();
88
88
 
89
- expect(accessToken).toBe('access-token');
90
- expect(refreshToken).toBe('refresh-token');
91
- });
89
+ expect(accessToken).toBe('access-token');
90
+ expect(refreshToken).toBe('refresh-token');
91
+ });
92
92
 
93
- it('should clear both tokens', async () => {
94
- await storage.setAccessToken('access-token');
95
- await storage.setRefreshToken('refresh-token');
93
+ it('should clear both tokens', async () => {
94
+ await storage.setAccessToken('access-token');
95
+ await storage.setRefreshToken('refresh-token');
96
96
 
97
- await storage.clearTokens();
97
+ await storage.clearTokens();
98
98
 
99
- const accessToken = await storage.getAccessToken();
100
- const refreshToken = await storage.getRefreshToken();
99
+ const accessToken = await storage.getAccessToken();
100
+ const refreshToken = await storage.getRefreshToken();
101
101
 
102
- expect(accessToken).toBeNull();
103
- expect(refreshToken).toBeNull();
104
- });
102
+ expect(accessToken).toBeNull();
103
+ expect(refreshToken).toBeNull();
104
+ });
105
105
 
106
- it('should clear tokens when some are missing', async () => {
107
- await storage.setAccessToken('access-token');
106
+ it('should clear tokens when some are missing', async () => {
107
+ await storage.setAccessToken('access-token');
108
108
 
109
- await storage.clearTokens();
109
+ await storage.clearTokens();
110
110
 
111
- const accessToken = await storage.getAccessToken();
112
- const refreshToken = await storage.getRefreshToken();
111
+ const accessToken = await storage.getAccessToken();
112
+ const refreshToken = await storage.getRefreshToken();
113
113
 
114
- expect(accessToken).toBeNull();
115
- expect(refreshToken).toBeNull();
116
- });
117
- });
114
+ expect(accessToken).toBeNull();
115
+ expect(refreshToken).toBeNull();
116
+ });
117
+ });
118
118
 
119
- describe('custom storage keys', () => {
120
- it('should use custom keys for token storage', async () => {
121
- const customStorage = new CacheTokenStorage(
122
- cache,
123
- 'custom_access_key',
124
- 'custom_refresh_key',
125
- );
119
+ describe('custom storage keys', () => {
120
+ it('should use custom keys for token storage', async () => {
121
+ const customStorage = new CacheTokenStorage(
122
+ cache,
123
+ 'custom_access_key',
124
+ 'custom_refresh_key',
125
+ );
126
126
 
127
- await customStorage.setAccessToken('access-token');
128
- await customStorage.setRefreshToken('refresh-token');
127
+ await customStorage.setAccessToken('access-token');
128
+ await customStorage.setRefreshToken('refresh-token');
129
129
 
130
- const accessToken = await customStorage.getAccessToken();
131
- const refreshToken = await customStorage.getRefreshToken();
130
+ const accessToken = await customStorage.getAccessToken();
131
+ const refreshToken = await customStorage.getRefreshToken();
132
132
 
133
- expect(accessToken).toBe('access-token');
134
- expect(refreshToken).toBe('refresh-token');
135
- });
133
+ expect(accessToken).toBe('access-token');
134
+ expect(refreshToken).toBe('refresh-token');
135
+ });
136
136
 
137
- it('should isolate tokens between different storage instances', async () => {
138
- const defaultStorage = new CacheTokenStorage(cache);
139
- const customStorage = new CacheTokenStorage(
140
- cache,
141
- 'custom_access',
142
- 'custom_refresh',
143
- );
137
+ it('should isolate tokens between different storage instances', async () => {
138
+ const defaultStorage = new CacheTokenStorage(cache);
139
+ const customStorage = new CacheTokenStorage(
140
+ cache,
141
+ 'custom_access',
142
+ 'custom_refresh',
143
+ );
144
144
 
145
- await defaultStorage.setAccessToken('default-access');
146
- await customStorage.setAccessToken('custom-access');
145
+ await defaultStorage.setAccessToken('default-access');
146
+ await customStorage.setAccessToken('custom-access');
147
147
 
148
- const defaultToken = await defaultStorage.getAccessToken();
149
- const customToken = await customStorage.getAccessToken();
148
+ const defaultToken = await defaultStorage.getAccessToken();
149
+ const customToken = await customStorage.getAccessToken();
150
150
 
151
- expect(defaultToken).toBe('default-access');
152
- expect(customToken).toBe('custom-access');
153
- });
151
+ expect(defaultToken).toBe('default-access');
152
+ expect(customToken).toBe('custom-access');
153
+ });
154
154
 
155
- it('should clear tokens independently with custom keys', async () => {
156
- const defaultStorage = new CacheTokenStorage(cache);
157
- const customStorage = new CacheTokenStorage(
158
- cache,
159
- 'custom_access',
160
- 'custom_refresh',
161
- );
155
+ it('should clear tokens independently with custom keys', async () => {
156
+ const defaultStorage = new CacheTokenStorage(cache);
157
+ const customStorage = new CacheTokenStorage(
158
+ cache,
159
+ 'custom_access',
160
+ 'custom_refresh',
161
+ );
162
162
 
163
- await defaultStorage.setAccessToken('default-access');
164
- await customStorage.setAccessToken('custom-access');
163
+ await defaultStorage.setAccessToken('default-access');
164
+ await customStorage.setAccessToken('custom-access');
165
165
 
166
- await defaultStorage.clearTokens();
166
+ await defaultStorage.clearTokens();
167
167
 
168
- const defaultToken = await defaultStorage.getAccessToken();
169
- const customToken = await customStorage.getAccessToken();
168
+ const defaultToken = await defaultStorage.getAccessToken();
169
+ const customToken = await customStorage.getAccessToken();
170
170
 
171
- expect(defaultToken).toBeNull();
172
- expect(customToken).toBe('custom-access');
173
- });
174
- });
171
+ expect(defaultToken).toBeNull();
172
+ expect(customToken).toBe('custom-access');
173
+ });
174
+ });
175
175
 
176
- describe('integration with real cache', () => {
177
- it('should work with multiple cache instances', async () => {
178
- const cache1 = new InMemoryCache<string>();
179
- const cache2 = new InMemoryCache<string>();
176
+ describe('integration with real cache', () => {
177
+ it('should work with multiple cache instances', async () => {
178
+ const cache1 = new InMemoryCache<string>();
179
+ const cache2 = new InMemoryCache<string>();
180
180
 
181
- const storage1 = new CacheTokenStorage(cache1);
182
- const storage2 = new CacheTokenStorage(cache2);
181
+ const storage1 = new CacheTokenStorage(cache1);
182
+ const storage2 = new CacheTokenStorage(cache2);
183
183
 
184
- await storage1.setAccessToken('token-1');
185
- await storage2.setAccessToken('token-2');
184
+ await storage1.setAccessToken('token-1');
185
+ await storage2.setAccessToken('token-2');
186
186
 
187
- const token1 = await storage1.getAccessToken();
188
- const token2 = await storage2.getAccessToken();
187
+ const token1 = await storage1.getAccessToken();
188
+ const token2 = await storage2.getAccessToken();
189
189
 
190
- expect(token1).toBe('token-1');
191
- expect(token2).toBe('token-2');
192
- });
190
+ expect(token1).toBe('token-1');
191
+ expect(token2).toBe('token-2');
192
+ });
193
193
 
194
- it('should maintain token state across operations', async () => {
195
- await storage.setAccessToken('initial-access');
196
- await storage.setRefreshToken('initial-refresh');
194
+ it('should maintain token state across operations', async () => {
195
+ await storage.setAccessToken('initial-access');
196
+ await storage.setRefreshToken('initial-refresh');
197
197
 
198
- let accessToken = await storage.getAccessToken();
199
- let refreshToken = await storage.getRefreshToken();
198
+ let accessToken = await storage.getAccessToken();
199
+ let refreshToken = await storage.getRefreshToken();
200
200
 
201
- expect(accessToken).toBe('initial-access');
202
- expect(refreshToken).toBe('initial-refresh');
201
+ expect(accessToken).toBe('initial-access');
202
+ expect(refreshToken).toBe('initial-refresh');
203
203
 
204
- await storage.setAccessToken('updated-access');
204
+ await storage.setAccessToken('updated-access');
205
205
 
206
- accessToken = await storage.getAccessToken();
207
- refreshToken = await storage.getRefreshToken();
206
+ accessToken = await storage.getAccessToken();
207
+ refreshToken = await storage.getRefreshToken();
208
208
 
209
- expect(accessToken).toBe('updated-access');
210
- expect(refreshToken).toBe('initial-refresh');
211
- });
212
- });
209
+ expect(accessToken).toBe('updated-access');
210
+ expect(refreshToken).toBe('initial-refresh');
211
+ });
212
+ });
213
213
  });