@stonyx/oauth 0.1.1-beta.6 → 0.1.1-beta.60

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 (38) hide show
  1. package/README.md +4 -0
  2. package/config/environment.js +12 -7
  3. package/config/environment.ts +7 -0
  4. package/dist/auth-request.d.ts +35 -0
  5. package/dist/auth-request.js +68 -0
  6. package/dist/main.d.ts +22 -0
  7. package/dist/main.js +75 -0
  8. package/dist/oauth-flow.d.ts +30 -0
  9. package/dist/oauth-flow.js +83 -0
  10. package/dist/providers/discord.d.ts +30 -0
  11. package/dist/providers/discord.js +43 -0
  12. package/dist/session-manager.d.ts +20 -0
  13. package/dist/session-manager.js +30 -0
  14. package/dist/token-manager.d.ts +15 -0
  15. package/dist/token-manager.js +24 -0
  16. package/package.json +45 -8
  17. package/src/{auth-request.js → auth-request.ts} +26 -6
  18. package/src/{main.js → main.ts} +31 -10
  19. package/src/{oauth-flow.js → oauth-flow.ts} +31 -7
  20. package/src/providers/{discord.js → discord.ts} +29 -3
  21. package/src/{session-manager.js → session-manager.ts} +19 -6
  22. package/src/token-manager.ts +35 -0
  23. package/src/types/node.d.ts +3 -0
  24. package/src/types/stonyx-events.d.ts +4 -0
  25. package/src/types/stonyx-rest-server.d.ts +11 -0
  26. package/src/types/stonyx.d.ts +30 -0
  27. package/.github/workflows/ci.yml +0 -16
  28. package/.github/workflows/publish.yml +0 -51
  29. package/src/token-manager.js +0 -26
  30. package/test/config/environment.js +0 -18
  31. package/test/integration/oauth-test.js +0 -149
  32. package/test/sample/providers/mock.js +0 -40
  33. package/test/sample/requests/.gitkeep +0 -0
  34. package/test/unit/oauth-flow-test.js +0 -137
  35. package/test/unit/providers/discord-test.js +0 -115
  36. package/test/unit/session-manager-test.js +0 -85
  37. package/test/unit/state-validation-test.js +0 -118
  38. package/test/unit/token-manager-test.js +0 -76
@@ -1,76 +0,0 @@
1
- import QUnit from 'qunit';
2
- import TokenManager from '../../src/token-manager.js';
3
-
4
- const { module, test } = QUnit;
5
-
6
- function createMockFlow() {
7
- return {
8
- exchangeCode: async (code) => ({
9
- accessToken: `token-for-${code}`,
10
- refreshToken: 'refresh-123',
11
- expiresIn: 3600,
12
- }),
13
- refreshAccessToken: async (refreshToken) => ({
14
- accessToken: 'new-access',
15
- refreshToken,
16
- expiresIn: 7200,
17
- }),
18
- revokeToken: async () => {},
19
- };
20
- }
21
-
22
- module('[Unit] TokenManager', function() {
23
- module('getTokens', function() {
24
- test('delegates to flow.exchangeCode and sets expiresAt', async function(assert) {
25
- const manager = new TokenManager(createMockFlow());
26
- const before = Date.now();
27
- const result = await manager.getTokens('my-code');
28
-
29
- assert.equal(result.accessToken, 'token-for-my-code');
30
- assert.equal(result.refreshToken, 'refresh-123');
31
- assert.ok(result.expiresAt >= before + 3600 * 1000);
32
- });
33
- });
34
-
35
- module('refresh', function() {
36
- test('delegates to flow.refreshAccessToken and sets expiresAt', async function(assert) {
37
- const manager = new TokenManager(createMockFlow());
38
- const result = await manager.refresh('refresh-123');
39
-
40
- assert.equal(result.accessToken, 'new-access');
41
- assert.ok(result.expiresAt > Date.now());
42
- });
43
- });
44
-
45
- module('revoke', function() {
46
- test('delegates to flow.revokeToken', async function(assert) {
47
- let revoked = false;
48
- const flow = { ...createMockFlow(), revokeToken: async () => { revoked = true; } };
49
- const manager = new TokenManager(flow);
50
-
51
- await manager.revoke('some-token');
52
- assert.ok(revoked);
53
- });
54
- });
55
-
56
- module('isExpired', function() {
57
- test('returns true if expiresAt is in the past', function(assert) {
58
- const manager = new TokenManager(createMockFlow());
59
-
60
- assert.true(manager.isExpired({ expiresAt: Date.now() - 1000 }));
61
- });
62
-
63
- test('returns false if expiresAt is in the future', function(assert) {
64
- const manager = new TokenManager(createMockFlow());
65
-
66
- assert.false(manager.isExpired({ expiresAt: Date.now() + 60000 }));
67
- });
68
-
69
- test('returns true if tokenData is null or missing expiresAt', function(assert) {
70
- const manager = new TokenManager(createMockFlow());
71
-
72
- assert.true(manager.isExpired(null));
73
- assert.true(manager.isExpired({}));
74
- });
75
- });
76
- });