@originals/auth 1.8.1 → 1.8.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +8 -12
- package/.turbo/turbo-build.log +0 -1
- package/eslint.config.js +0 -32
- package/src/client/index.ts +0 -36
- package/src/client/server-auth.ts +0 -101
- package/src/client/turnkey-client.ts +0 -364
- package/src/client/turnkey-did-signer.ts +0 -203
- package/src/index.ts +0 -32
- package/src/server/email-auth.ts +0 -258
- package/src/server/index.ts +0 -42
- package/src/server/jwt.ts +0 -154
- package/src/server/middleware.ts +0 -142
- package/src/server/turnkey-client.ts +0 -156
- package/src/server/turnkey-signer.ts +0 -170
- package/src/types.ts +0 -172
- package/tests/index.test.ts +0 -29
- package/tests/server-auth.test.ts +0 -167
- package/tsconfig.json +0 -32
|
@@ -1,167 +0,0 @@
|
|
|
1
|
-
import { describe, test, expect, mock } from 'bun:test';
|
|
2
|
-
import { sendOtp, verifyOtp } from '../src/client/server-auth';
|
|
3
|
-
|
|
4
|
-
describe('server-auth', () => {
|
|
5
|
-
describe('sendOtp', () => {
|
|
6
|
-
test('sends email to endpoint and returns result', async () => {
|
|
7
|
-
const mockFetch = mock(() =>
|
|
8
|
-
Promise.resolve({
|
|
9
|
-
ok: true,
|
|
10
|
-
json: () => Promise.resolve({ sessionId: 'session_123', message: 'Code sent' }),
|
|
11
|
-
})
|
|
12
|
-
);
|
|
13
|
-
const result = await sendOtp('test@example.com', '/api/auth/send-otp', {
|
|
14
|
-
fetch: mockFetch as unknown as typeof fetch,
|
|
15
|
-
});
|
|
16
|
-
expect(result.sessionId).toBe('session_123');
|
|
17
|
-
expect(result.message).toBe('Code sent');
|
|
18
|
-
expect(mockFetch).toHaveBeenCalledWith(
|
|
19
|
-
'/api/auth/send-otp',
|
|
20
|
-
expect.objectContaining({
|
|
21
|
-
method: 'POST',
|
|
22
|
-
headers: { 'Content-Type': 'application/json' },
|
|
23
|
-
body: JSON.stringify({ email: 'test@example.com' }),
|
|
24
|
-
})
|
|
25
|
-
);
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
test('throws on non-ok response with server message', async () => {
|
|
29
|
-
const mockFetch = mock(() =>
|
|
30
|
-
Promise.resolve({
|
|
31
|
-
ok: false,
|
|
32
|
-
status: 400,
|
|
33
|
-
json: () => Promise.resolve({ message: 'Invalid email' }),
|
|
34
|
-
})
|
|
35
|
-
);
|
|
36
|
-
await expect(
|
|
37
|
-
sendOtp('bad', '/api/auth/send-otp', { fetch: mockFetch as unknown as typeof fetch })
|
|
38
|
-
).rejects.toThrow('Invalid email');
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
test('throws with HTTP status when no message in response', async () => {
|
|
42
|
-
const mockFetch = mock(() =>
|
|
43
|
-
Promise.resolve({
|
|
44
|
-
ok: false,
|
|
45
|
-
status: 500,
|
|
46
|
-
json: () => Promise.resolve({}),
|
|
47
|
-
})
|
|
48
|
-
);
|
|
49
|
-
await expect(
|
|
50
|
-
sendOtp('test@example.com', '/api/auth/send-otp', {
|
|
51
|
-
fetch: mockFetch as unknown as typeof fetch,
|
|
52
|
-
})
|
|
53
|
-
).rejects.toThrow('HTTP 500');
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
test('throws fallback message when json parsing fails', async () => {
|
|
57
|
-
const mockFetch = mock(() =>
|
|
58
|
-
Promise.resolve({
|
|
59
|
-
ok: false,
|
|
60
|
-
status: 502,
|
|
61
|
-
json: () => Promise.reject(new Error('Invalid JSON')),
|
|
62
|
-
})
|
|
63
|
-
);
|
|
64
|
-
await expect(
|
|
65
|
-
sendOtp('test@example.com', '/api/auth/send-otp', {
|
|
66
|
-
fetch: mockFetch as unknown as typeof fetch,
|
|
67
|
-
})
|
|
68
|
-
).rejects.toThrow('Failed to send OTP');
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
test('uses default endpoint when not provided', async () => {
|
|
72
|
-
const mockFetch = mock(() =>
|
|
73
|
-
Promise.resolve({
|
|
74
|
-
ok: true,
|
|
75
|
-
json: () => Promise.resolve({ sessionId: 's1', message: 'ok' }),
|
|
76
|
-
})
|
|
77
|
-
);
|
|
78
|
-
await sendOtp('test@example.com', undefined, { fetch: mockFetch as unknown as typeof fetch });
|
|
79
|
-
expect(mockFetch).toHaveBeenCalledWith('/api/auth/send-otp', expect.anything());
|
|
80
|
-
});
|
|
81
|
-
});
|
|
82
|
-
|
|
83
|
-
describe('verifyOtp', () => {
|
|
84
|
-
test('sends sessionId and code, returns verification result', async () => {
|
|
85
|
-
const mockFetch = mock(() =>
|
|
86
|
-
Promise.resolve({
|
|
87
|
-
ok: true,
|
|
88
|
-
json: () =>
|
|
89
|
-
Promise.resolve({ verified: true, email: 'test@example.com', subOrgId: 'org_123' }),
|
|
90
|
-
})
|
|
91
|
-
);
|
|
92
|
-
const result = await verifyOtp('session_123', '123456', '/api/auth/verify-otp', {
|
|
93
|
-
fetch: mockFetch as unknown as typeof fetch,
|
|
94
|
-
});
|
|
95
|
-
expect(result.verified).toBe(true);
|
|
96
|
-
expect(result.email).toBe('test@example.com');
|
|
97
|
-
expect(result.subOrgId).toBe('org_123');
|
|
98
|
-
expect(mockFetch).toHaveBeenCalledWith(
|
|
99
|
-
'/api/auth/verify-otp',
|
|
100
|
-
expect.objectContaining({
|
|
101
|
-
method: 'POST',
|
|
102
|
-
headers: { 'Content-Type': 'application/json' },
|
|
103
|
-
body: JSON.stringify({ sessionId: 'session_123', code: '123456' }),
|
|
104
|
-
})
|
|
105
|
-
);
|
|
106
|
-
});
|
|
107
|
-
|
|
108
|
-
test('throws on verification failure with server message', async () => {
|
|
109
|
-
const mockFetch = mock(() =>
|
|
110
|
-
Promise.resolve({
|
|
111
|
-
ok: false,
|
|
112
|
-
status: 401,
|
|
113
|
-
json: () => Promise.resolve({ message: 'Invalid code' }),
|
|
114
|
-
})
|
|
115
|
-
);
|
|
116
|
-
await expect(
|
|
117
|
-
verifyOtp('s1', 'wrong', '/api/auth/verify-otp', {
|
|
118
|
-
fetch: mockFetch as unknown as typeof fetch,
|
|
119
|
-
})
|
|
120
|
-
).rejects.toThrow('Invalid code');
|
|
121
|
-
});
|
|
122
|
-
|
|
123
|
-
test('throws with HTTP status when no message in response', async () => {
|
|
124
|
-
const mockFetch = mock(() =>
|
|
125
|
-
Promise.resolve({
|
|
126
|
-
ok: false,
|
|
127
|
-
status: 403,
|
|
128
|
-
json: () => Promise.resolve({}),
|
|
129
|
-
})
|
|
130
|
-
);
|
|
131
|
-
await expect(
|
|
132
|
-
verifyOtp('s1', '123456', '/api/auth/verify-otp', {
|
|
133
|
-
fetch: mockFetch as unknown as typeof fetch,
|
|
134
|
-
})
|
|
135
|
-
).rejects.toThrow('HTTP 403');
|
|
136
|
-
});
|
|
137
|
-
|
|
138
|
-
test('throws fallback message when json parsing fails', async () => {
|
|
139
|
-
const mockFetch = mock(() =>
|
|
140
|
-
Promise.resolve({
|
|
141
|
-
ok: false,
|
|
142
|
-
status: 500,
|
|
143
|
-
json: () => Promise.reject(new Error('Invalid JSON')),
|
|
144
|
-
})
|
|
145
|
-
);
|
|
146
|
-
await expect(
|
|
147
|
-
verifyOtp('s1', '123456', '/api/auth/verify-otp', {
|
|
148
|
-
fetch: mockFetch as unknown as typeof fetch,
|
|
149
|
-
})
|
|
150
|
-
).rejects.toThrow('Verification failed');
|
|
151
|
-
});
|
|
152
|
-
|
|
153
|
-
test('uses default endpoint when not provided', async () => {
|
|
154
|
-
const mockFetch = mock(() =>
|
|
155
|
-
Promise.resolve({
|
|
156
|
-
ok: true,
|
|
157
|
-
json: () =>
|
|
158
|
-
Promise.resolve({ verified: true, email: 'test@example.com', subOrgId: 'org_123' }),
|
|
159
|
-
})
|
|
160
|
-
);
|
|
161
|
-
await verifyOtp('session_123', '123456', undefined, {
|
|
162
|
-
fetch: mockFetch as unknown as typeof fetch,
|
|
163
|
-
});
|
|
164
|
-
expect(mockFetch).toHaveBeenCalledWith('/api/auth/verify-otp', expect.anything());
|
|
165
|
-
});
|
|
166
|
-
});
|
|
167
|
-
});
|
package/tsconfig.json
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"target": "ES2022",
|
|
4
|
-
"module": "ESNext",
|
|
5
|
-
"moduleResolution": "bundler",
|
|
6
|
-
"declaration": true,
|
|
7
|
-
"declarationMap": true,
|
|
8
|
-
"sourceMap": true,
|
|
9
|
-
"outDir": "./dist",
|
|
10
|
-
"rootDir": "./src",
|
|
11
|
-
"strict": true,
|
|
12
|
-
"esModuleInterop": true,
|
|
13
|
-
"skipLibCheck": true,
|
|
14
|
-
"forceConsistentCasingInFileNames": true,
|
|
15
|
-
"resolveJsonModule": true,
|
|
16
|
-
"isolatedModules": true,
|
|
17
|
-
"lib": ["ES2022", "DOM"],
|
|
18
|
-
"types": ["bun-types"],
|
|
19
|
-
"paths": {
|
|
20
|
-
"@/*": ["./src/*"]
|
|
21
|
-
}
|
|
22
|
-
},
|
|
23
|
-
"include": ["src/**/*"],
|
|
24
|
-
"exclude": ["node_modules", "dist", "tests"]
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|