@donkeylabs/cli 2.0.14 → 2.0.16

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 (85) hide show
  1. package/package.json +1 -1
  2. package/src/commands/config.ts +610 -0
  3. package/src/commands/deploy-enhanced.ts +354 -0
  4. package/src/commands/deploy.ts +204 -0
  5. package/src/commands/generate.ts +11 -13
  6. package/src/commands/init-enhanced.ts +1994 -0
  7. package/src/deployment/manager.ts +356 -0
  8. package/src/index.ts +47 -19
  9. package/templates/starter/.env.example +0 -44
  10. package/templates/starter/.gitignore.template +0 -4
  11. package/templates/starter/donkeylabs.config.ts +0 -6
  12. package/templates/starter/package.json +0 -21
  13. package/templates/starter/src/index.ts +0 -54
  14. package/templates/starter/src/plugins/stats/index.ts +0 -105
  15. package/templates/starter/src/routes/health/handlers/ping.ts +0 -22
  16. package/templates/starter/src/routes/health/index.ts +0 -19
  17. package/templates/starter/tsconfig.json +0 -27
  18. package/templates/sveltekit-app/.env.example +0 -59
  19. package/templates/sveltekit-app/README.md +0 -103
  20. package/templates/sveltekit-app/bun.lock +0 -683
  21. package/templates/sveltekit-app/donkeylabs.config.ts +0 -12
  22. package/templates/sveltekit-app/package.json +0 -38
  23. package/templates/sveltekit-app/src/app.css +0 -40
  24. package/templates/sveltekit-app/src/app.html +0 -12
  25. package/templates/sveltekit-app/src/hooks.server.ts +0 -4
  26. package/templates/sveltekit-app/src/lib/components/ui/badge/badge.svelte +0 -30
  27. package/templates/sveltekit-app/src/lib/components/ui/badge/index.ts +0 -3
  28. package/templates/sveltekit-app/src/lib/components/ui/button/button.svelte +0 -48
  29. package/templates/sveltekit-app/src/lib/components/ui/button/index.ts +0 -9
  30. package/templates/sveltekit-app/src/lib/components/ui/card/card-content.svelte +0 -18
  31. package/templates/sveltekit-app/src/lib/components/ui/card/card-description.svelte +0 -18
  32. package/templates/sveltekit-app/src/lib/components/ui/card/card-footer.svelte +0 -18
  33. package/templates/sveltekit-app/src/lib/components/ui/card/card-header.svelte +0 -18
  34. package/templates/sveltekit-app/src/lib/components/ui/card/card-title.svelte +0 -18
  35. package/templates/sveltekit-app/src/lib/components/ui/card/card.svelte +0 -21
  36. package/templates/sveltekit-app/src/lib/components/ui/card/index.ts +0 -21
  37. package/templates/sveltekit-app/src/lib/components/ui/index.ts +0 -4
  38. package/templates/sveltekit-app/src/lib/components/ui/input/index.ts +0 -2
  39. package/templates/sveltekit-app/src/lib/components/ui/input/input.svelte +0 -20
  40. package/templates/sveltekit-app/src/lib/permissions.ts +0 -213
  41. package/templates/sveltekit-app/src/lib/utils/index.ts +0 -6
  42. package/templates/sveltekit-app/src/routes/+layout.svelte +0 -8
  43. package/templates/sveltekit-app/src/routes/+page.server.ts +0 -25
  44. package/templates/sveltekit-app/src/routes/+page.svelte +0 -680
  45. package/templates/sveltekit-app/src/routes/workflows/+page.server.ts +0 -23
  46. package/templates/sveltekit-app/src/routes/workflows/+page.svelte +0 -522
  47. package/templates/sveltekit-app/src/server/events.ts +0 -28
  48. package/templates/sveltekit-app/src/server/index.ts +0 -124
  49. package/templates/sveltekit-app/src/server/plugins/auth/auth.test.ts +0 -377
  50. package/templates/sveltekit-app/src/server/plugins/auth/index.ts +0 -815
  51. package/templates/sveltekit-app/src/server/plugins/auth/migrations/001_create_users.ts +0 -25
  52. package/templates/sveltekit-app/src/server/plugins/auth/migrations/002_create_sessions.ts +0 -32
  53. package/templates/sveltekit-app/src/server/plugins/auth/migrations/003_create_refresh_tokens.ts +0 -33
  54. package/templates/sveltekit-app/src/server/plugins/auth/migrations/004_create_passkeys.ts +0 -60
  55. package/templates/sveltekit-app/src/server/plugins/auth/schema.ts +0 -65
  56. package/templates/sveltekit-app/src/server/plugins/demo/index.ts +0 -262
  57. package/templates/sveltekit-app/src/server/plugins/email/email.test.ts +0 -369
  58. package/templates/sveltekit-app/src/server/plugins/email/index.ts +0 -411
  59. package/templates/sveltekit-app/src/server/plugins/email/migrations/001_create_email_tokens.ts +0 -33
  60. package/templates/sveltekit-app/src/server/plugins/email/schema.ts +0 -24
  61. package/templates/sveltekit-app/src/server/plugins/permissions/index.ts +0 -1048
  62. package/templates/sveltekit-app/src/server/plugins/permissions/migrations/001_create_tenants.ts +0 -63
  63. package/templates/sveltekit-app/src/server/plugins/permissions/migrations/002_create_roles.ts +0 -90
  64. package/templates/sveltekit-app/src/server/plugins/permissions/migrations/003_create_resource_grants.ts +0 -50
  65. package/templates/sveltekit-app/src/server/plugins/permissions/permissions.test.ts +0 -566
  66. package/templates/sveltekit-app/src/server/plugins/permissions/schema.ts +0 -67
  67. package/templates/sveltekit-app/src/server/plugins/workflow-demo/index.ts +0 -198
  68. package/templates/sveltekit-app/src/server/routes/auth/auth.schemas.ts +0 -66
  69. package/templates/sveltekit-app/src/server/routes/auth/handlers/login.handler.ts +0 -18
  70. package/templates/sveltekit-app/src/server/routes/auth/handlers/logout.handler.ts +0 -16
  71. package/templates/sveltekit-app/src/server/routes/auth/handlers/me.handler.ts +0 -20
  72. package/templates/sveltekit-app/src/server/routes/auth/handlers/refresh.handler.ts +0 -17
  73. package/templates/sveltekit-app/src/server/routes/auth/handlers/register.handler.ts +0 -19
  74. package/templates/sveltekit-app/src/server/routes/auth/handlers/update-profile.handler.ts +0 -21
  75. package/templates/sveltekit-app/src/server/routes/auth/index.ts +0 -73
  76. package/templates/sveltekit-app/src/server/routes/demo.ts +0 -464
  77. package/templates/sveltekit-app/src/server/routes/example/example.schemas.ts +0 -22
  78. package/templates/sveltekit-app/src/server/routes/example/handlers/greet.handler.ts +0 -21
  79. package/templates/sveltekit-app/src/server/routes/example/index.ts +0 -28
  80. package/templates/sveltekit-app/src/server/routes/permissions/index.ts +0 -248
  81. package/templates/sveltekit-app/src/server/routes/tenants/index.ts +0 -339
  82. package/templates/sveltekit-app/static/robots.txt +0 -3
  83. package/templates/sveltekit-app/svelte.config.ts +0 -17
  84. package/templates/sveltekit-app/tsconfig.json +0 -20
  85. package/templates/sveltekit-app/vite.config.ts +0 -12
@@ -1,377 +0,0 @@
1
- /**
2
- * Auth Plugin Tests
3
- *
4
- * Tests for authentication with multiple strategies:
5
- * - session: Stateful database sessions
6
- * - jwt: Stateless JWT tokens
7
- * - refresh-token: Access + refresh token pattern
8
- */
9
-
10
- import { describe, it, expect, beforeEach, afterEach } from "bun:test";
11
- import { createTestHarness } from "@donkeylabs/server";
12
- import { authPlugin } from "./index";
13
-
14
- // Helper to create test harness with auth plugin
15
- async function createAuthTestHarness(config: Parameters<typeof authPlugin>[0] = {}) {
16
- const harness = await createTestHarness(authPlugin(config));
17
- return { ...harness, auth: harness.manager.getServices().auth };
18
- }
19
-
20
- // ==========================================
21
- // Session Strategy Tests
22
- // ==========================================
23
- describe("Auth Plugin - Session Strategy", () => {
24
- let harness: Awaited<ReturnType<typeof createAuthTestHarness>>;
25
-
26
- beforeEach(async () => {
27
- harness = await createAuthTestHarness({ strategy: "session" });
28
- });
29
-
30
- afterEach(async () => {
31
- await harness.db.destroy();
32
- });
33
-
34
- it("should register a new user", async () => {
35
- const result = await harness.auth.register({
36
- email: "test@example.com",
37
- password: "password123",
38
- name: "Test User",
39
- });
40
-
41
- expect(result.user).toBeDefined();
42
- expect(result.user.email).toBe("test@example.com");
43
- expect(result.user.name).toBe("Test User");
44
- expect(result.tokens.accessToken).toBeDefined();
45
- expect(result.tokens.expiresIn).toBeGreaterThan(0);
46
- });
47
-
48
- it("should prevent duplicate email registration", async () => {
49
- await harness.auth.register({
50
- email: "test@example.com",
51
- password: "password123",
52
- });
53
-
54
- await expect(
55
- harness.auth.register({
56
- email: "test@example.com",
57
- password: "differentpassword",
58
- })
59
- ).rejects.toThrow();
60
- });
61
-
62
- it("should login with correct credentials", async () => {
63
- await harness.auth.register({
64
- email: "test@example.com",
65
- password: "password123",
66
- });
67
-
68
- const result = await harness.auth.login({
69
- email: "test@example.com",
70
- password: "password123",
71
- });
72
-
73
- expect(result.user.email).toBe("test@example.com");
74
- expect(result.tokens.accessToken).toBeDefined();
75
- });
76
-
77
- it("should reject login with wrong password", async () => {
78
- await harness.auth.register({
79
- email: "test@example.com",
80
- password: "password123",
81
- });
82
-
83
- await expect(
84
- harness.auth.login({
85
- email: "test@example.com",
86
- password: "wrongpassword",
87
- })
88
- ).rejects.toThrow();
89
- });
90
-
91
- it("should reject login for non-existent user", async () => {
92
- await expect(
93
- harness.auth.login({
94
- email: "nonexistent@example.com",
95
- password: "password123",
96
- })
97
- ).rejects.toThrow();
98
- });
99
-
100
- it("should validate session token", async () => {
101
- const { tokens } = await harness.auth.register({
102
- email: "test@example.com",
103
- password: "password123",
104
- });
105
-
106
- const user = await harness.auth.validateToken(tokens.accessToken);
107
- expect(user).toBeDefined();
108
- expect(user?.email).toBe("test@example.com");
109
- });
110
-
111
- it("should invalidate session on logout", async () => {
112
- const { tokens } = await harness.auth.register({
113
- email: "test@example.com",
114
- password: "password123",
115
- });
116
-
117
- await harness.auth.logout(tokens.accessToken);
118
-
119
- const user = await harness.auth.validateToken(tokens.accessToken);
120
- expect(user).toBeNull();
121
- });
122
-
123
- it("should return null for invalid token", async () => {
124
- const user = await harness.auth.validateToken("invalid-token");
125
- expect(user).toBeNull();
126
- });
127
-
128
- it("should get user by ID", async () => {
129
- const { user: created } = await harness.auth.register({
130
- email: "test@example.com",
131
- password: "password123",
132
- name: "Test User",
133
- });
134
-
135
- const user = await harness.auth.getUserById(created.id);
136
- expect(user).toBeDefined();
137
- expect(user?.email).toBe("test@example.com");
138
- });
139
-
140
- it("should update user profile", async () => {
141
- const { user: created } = await harness.auth.register({
142
- email: "test@example.com",
143
- password: "password123",
144
- name: "Original Name",
145
- });
146
-
147
- const updated = await harness.auth.updateProfile(created.id, {
148
- name: "Updated Name",
149
- });
150
-
151
- expect(updated.name).toBe("Updated Name");
152
- });
153
- });
154
-
155
- // ==========================================
156
- // JWT Strategy Tests
157
- // ==========================================
158
- describe("Auth Plugin - JWT Strategy", () => {
159
- let harness: Awaited<ReturnType<typeof createAuthTestHarness>>;
160
-
161
- beforeEach(async () => {
162
- harness = await createAuthTestHarness({
163
- strategy: "jwt",
164
- jwt: { secret: "test-secret-key-at-least-32-chars!" },
165
- });
166
- });
167
-
168
- afterEach(async () => {
169
- await harness.db.destroy();
170
- });
171
-
172
- it("should register and return JWT token", async () => {
173
- const result = await harness.auth.register({
174
- email: "test@example.com",
175
- password: "password123",
176
- });
177
-
178
- expect(result.tokens.accessToken).toBeDefined();
179
- // JWT tokens are longer and have 3 parts
180
- expect(result.tokens.accessToken.split(".").length).toBe(3);
181
- expect(result.tokens.refreshToken).toBeUndefined();
182
- });
183
-
184
- it("should validate JWT token", async () => {
185
- const { tokens } = await harness.auth.register({
186
- email: "test@example.com",
187
- password: "password123",
188
- });
189
-
190
- const user = await harness.auth.validateToken(tokens.accessToken);
191
- expect(user).toBeDefined();
192
- expect(user?.email).toBe("test@example.com");
193
- });
194
-
195
- it("should reject invalid JWT token", async () => {
196
- const user = await harness.auth.validateToken("invalid.jwt.token");
197
- expect(user).toBeNull();
198
- });
199
-
200
- it("should login and return JWT", async () => {
201
- await harness.auth.register({
202
- email: "test@example.com",
203
- password: "password123",
204
- });
205
-
206
- const result = await harness.auth.login({
207
- email: "test@example.com",
208
- password: "password123",
209
- });
210
-
211
- expect(result.tokens.accessToken.split(".").length).toBe(3);
212
- });
213
- });
214
-
215
- // ==========================================
216
- // Refresh Token Strategy Tests
217
- // ==========================================
218
- describe("Auth Plugin - Refresh Token Strategy", () => {
219
- let harness: Awaited<ReturnType<typeof createAuthTestHarness>>;
220
-
221
- beforeEach(async () => {
222
- harness = await createAuthTestHarness({
223
- strategy: "refresh-token",
224
- jwt: { secret: "test-secret-key-at-least-32-chars!" },
225
- });
226
- });
227
-
228
- afterEach(async () => {
229
- await harness.db.destroy();
230
- });
231
-
232
- it("should return both access and refresh tokens", async () => {
233
- const result = await harness.auth.register({
234
- email: "test@example.com",
235
- password: "password123",
236
- });
237
-
238
- expect(result.tokens.accessToken).toBeDefined();
239
- expect(result.tokens.refreshToken).toBeDefined();
240
- expect(result.tokens.accessToken.split(".").length).toBe(3);
241
- expect(result.tokens.refreshToken!.split(".").length).toBe(3);
242
- });
243
-
244
- it("should validate access token", async () => {
245
- const { tokens } = await harness.auth.register({
246
- email: "test@example.com",
247
- password: "password123",
248
- });
249
-
250
- const user = await harness.auth.validateToken(tokens.accessToken);
251
- expect(user).toBeDefined();
252
- expect(user?.email).toBe("test@example.com");
253
- });
254
-
255
- it("should refresh tokens with refresh token", async () => {
256
- const { tokens: initial } = await harness.auth.register({
257
- email: "test@example.com",
258
- password: "password123",
259
- });
260
-
261
- // Small delay to ensure different token timestamps
262
- await new Promise(resolve => setTimeout(resolve, 10));
263
-
264
- const refreshed = await harness.auth.refresh(initial.refreshToken!);
265
-
266
- expect(refreshed.accessToken).toBeDefined();
267
- // Verify we got a new valid token (structure check)
268
- expect(refreshed.accessToken.split(".").length).toBe(3);
269
- expect(refreshed.expiresIn).toBeGreaterThan(0);
270
- });
271
-
272
- it("should reject invalid refresh token", async () => {
273
- await expect(
274
- harness.auth.refresh("invalid.refresh.token")
275
- ).rejects.toThrow();
276
- });
277
-
278
- it("should invalidate refresh token on logout", async () => {
279
- const { tokens } = await harness.auth.register({
280
- email: "test@example.com",
281
- password: "password123",
282
- });
283
-
284
- await harness.auth.logout(tokens.refreshToken!);
285
-
286
- await expect(
287
- harness.auth.refresh(tokens.refreshToken!)
288
- ).rejects.toThrow();
289
- });
290
- });
291
-
292
- // ==========================================
293
- // Configuration Tests
294
- // ==========================================
295
- describe("Auth Plugin - Configuration", () => {
296
- it("should use session strategy by default", async () => {
297
- const harness = await createAuthTestHarness({});
298
- expect(harness.auth.getStrategy()).toBe("session");
299
- await harness.db.destroy();
300
- });
301
-
302
- it("should respect custom strategy", async () => {
303
- const harness = await createAuthTestHarness({
304
- strategy: "jwt",
305
- jwt: { secret: "test-secret-key-at-least-32-chars!" },
306
- });
307
- expect(harness.auth.getStrategy()).toBe("jwt");
308
- await harness.db.destroy();
309
- });
310
-
311
- it("should throw if JWT secret missing for jwt strategy", async () => {
312
- await expect(
313
- createAuthTestHarness({ strategy: "jwt" })
314
- ).rejects.toThrow(/jwt.secret/);
315
- });
316
-
317
- it("should throw if JWT secret missing for refresh-token strategy", async () => {
318
- await expect(
319
- createAuthTestHarness({ strategy: "refresh-token" })
320
- ).rejects.toThrow(/jwt.secret/);
321
- });
322
-
323
- it("should return cookie config", async () => {
324
- const harness = await createAuthTestHarness({
325
- cookie: { name: "myauth", httpOnly: true, secure: false },
326
- });
327
- const config = harness.auth.getCookieConfig();
328
- expect(config.name).toBe("myauth");
329
- expect(config.httpOnly).toBe(true);
330
- expect(config.secure).toBe(false);
331
- await harness.db.destroy();
332
- });
333
- });
334
-
335
- // ==========================================
336
- // Edge Cases
337
- // ==========================================
338
- describe("Auth Plugin - Edge Cases", () => {
339
- let harness: Awaited<ReturnType<typeof createAuthTestHarness>>;
340
-
341
- beforeEach(async () => {
342
- harness = await createAuthTestHarness({ strategy: "session" });
343
- });
344
-
345
- afterEach(async () => {
346
- await harness.db.destroy();
347
- });
348
-
349
- it("should handle email case-insensitively", async () => {
350
- await harness.auth.register({
351
- email: "Test@Example.COM",
352
- password: "password123",
353
- });
354
-
355
- const result = await harness.auth.login({
356
- email: "test@example.com",
357
- password: "password123",
358
- });
359
-
360
- expect(result.user.email).toBe("test@example.com");
361
- });
362
-
363
- it("should handle registration without name", async () => {
364
- const result = await harness.auth.register({
365
- email: "test@example.com",
366
- password: "password123",
367
- });
368
-
369
- expect(result.user.name).toBeNull();
370
- });
371
-
372
- it("should return null for non-existent user ID", async () => {
373
- const user = await harness.auth.getUserById("non-existent-id");
374
- expect(user).toBeNull();
375
- });
376
-
377
- });