@taruvi/sdk 1.5.0-beta.1 → 1.5.0-beta.2

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 (69) hide show
  1. package/README.md +58 -1295
  2. package/package.json +10 -2
  3. package/.claude/settings.local.json +0 -19
  4. package/.github/worflows/publish.yml +0 -57
  5. package/.github/workflows/publish.yml +0 -58
  6. package/.kiro/settings/lsp.json +0 -198
  7. package/MODULE_NAMING_CHANGES.md +0 -81
  8. package/PARAMETER_NAMING_CHANGES.md +0 -106
  9. package/USAGE_EXAMPLE.md +0 -86
  10. package/src/client.ts +0 -88
  11. package/src/index.ts +0 -51
  12. package/src/lib/analytics/AnalyticsClient.ts +0 -24
  13. package/src/lib/analytics/types.ts +0 -8
  14. package/src/lib/app/AppClient.ts +0 -54
  15. package/src/lib/app/types.ts +0 -50
  16. package/src/lib/auth/AuthClient.ts +0 -126
  17. package/src/lib/auth/types.ts +0 -123
  18. package/src/lib/database/DatabaseClient.ts +0 -306
  19. package/src/lib/database/types.ts +0 -156
  20. package/src/lib/functions/FunctionsClient.ts +0 -27
  21. package/src/lib/functions/types.ts +0 -27
  22. package/src/lib/policy/PolicyClient.ts +0 -79
  23. package/src/lib/policy/types.ts +0 -39
  24. package/src/lib/secrets/SecretsClient.ts +0 -75
  25. package/src/lib/secrets/types.ts +0 -59
  26. package/src/lib/settings/SettingsClient.ts +0 -22
  27. package/src/lib/settings/types.ts +0 -9
  28. package/src/lib/storage/StorageClient.ts +0 -131
  29. package/src/lib/storage/types.ts +0 -86
  30. package/src/lib/users/UserClient.ts +0 -63
  31. package/src/lib/users/types.ts +0 -123
  32. package/src/lib-internal/errors/ErrorClient.ts +0 -114
  33. package/src/lib-internal/errors/index.ts +0 -3
  34. package/src/lib-internal/errors/types.ts +0 -29
  35. package/src/lib-internal/http/HttpClient.ts +0 -116
  36. package/src/lib-internal/http/types.ts +0 -12
  37. package/src/lib-internal/routes/AnalyticsRoutes.ts +0 -3
  38. package/src/lib-internal/routes/AppRoutes.ts +0 -9
  39. package/src/lib-internal/routes/AuthRoutes.ts +0 -0
  40. package/src/lib-internal/routes/DatabaseRoutes.ts +0 -10
  41. package/src/lib-internal/routes/FunctionRoutes.ts +0 -3
  42. package/src/lib-internal/routes/PolicyRoutes.ts +0 -4
  43. package/src/lib-internal/routes/SecretsRoutes.ts +0 -5
  44. package/src/lib-internal/routes/SettingsRoutes.ts +0 -4
  45. package/src/lib-internal/routes/StorageRoutes.ts +0 -15
  46. package/src/lib-internal/routes/UserRoutes.ts +0 -12
  47. package/src/lib-internal/routes/index.ts +0 -0
  48. package/src/lib-internal/token/TokenClient.ts +0 -108
  49. package/src/lib-internal/token/types.ts +0 -0
  50. package/src/types.ts +0 -104
  51. package/src/utils/enums.ts +0 -24
  52. package/src/utils/utils.ts +0 -38
  53. package/tests/fixtures/mockClient.ts +0 -19
  54. package/tests/mocks/db.json +0 -1
  55. package/tests/unit/analytics/AnalyticsClient.test.ts +0 -84
  56. package/tests/unit/app/AppClient.test.ts +0 -114
  57. package/tests/unit/auth/AuthClient.test.ts +0 -91
  58. package/tests/unit/client/Client.test.ts +0 -87
  59. package/tests/unit/database/DatabaseClient.test.ts +0 -652
  60. package/tests/unit/edge-cases/robustness.test.ts +0 -258
  61. package/tests/unit/errors/errors.test.ts +0 -236
  62. package/tests/unit/functions/FunctionsClient.test.ts +0 -99
  63. package/tests/unit/policy/PolicyClient.test.ts +0 -180
  64. package/tests/unit/secrets/SecretsClient.test.ts +0 -146
  65. package/tests/unit/settings/SettingsClient.test.ts +0 -50
  66. package/tests/unit/storage/StorageClient.test.ts +0 -252
  67. package/tests/unit/users/UserClient.test.ts +0 -150
  68. package/tsconfig.json +0 -44
  69. package/vitest.config.ts +0 -7
@@ -1,114 +0,0 @@
1
- import { describe, it, expect, vi, beforeEach } from 'vitest'
2
- import { App } from '../../../src/lib/app/AppClient.js'
3
- import { Client } from '../../../src/client.js'
4
- import type { RolesListResponse, AppSettingsResponse } from '../../../src/lib/app/types.js'
5
-
6
- const mockHttpClient = {
7
- get: vi.fn()
8
- }
9
-
10
- const mockClient = {
11
- getConfig: () => ({ apiKey: 'test-key', appSlug: 'test-app', apiUrl: 'https://api.test.com' }),
12
- httpClient: mockHttpClient
13
- } as unknown as Client
14
-
15
- describe('App', () => {
16
- beforeEach(() => {
17
- vi.clearAllMocks()
18
- })
19
-
20
- describe('roles()', () => {
21
- it('returns App instance for chaining', () => {
22
- const app = new App(mockClient)
23
- const result = app.roles()
24
- expect(result).toBeInstanceOf(App)
25
- })
26
-
27
- it('fetches app roles on execute', async () => {
28
- const rolesData = [
29
- { id: '1', name: 'Admin', permissions: ['read', 'write', 'delete'] },
30
- { id: '2', name: 'Editor', permissions: ['read', 'write'] }
31
- ]
32
- mockHttpClient.get.mockResolvedValue(rolesData)
33
-
34
- const app = new App(mockClient)
35
- const result = await app.roles().execute()
36
-
37
- expect(mockHttpClient.get).toHaveBeenCalledWith('api/apps/test-app/roles')
38
- expect(result).toEqual(rolesData)
39
- })
40
- })
41
-
42
- describe('settings()', () => {
43
- it('returns App instance for chaining', () => {
44
- const app = new App(mockClient)
45
- const result = app.settings()
46
- expect(result).toBeInstanceOf(App)
47
- })
48
-
49
- it('fetches app settings on execute', async () => {
50
- const settingsData = { theme: 'dark', language: 'en' }
51
- mockHttpClient.get.mockResolvedValue(settingsData)
52
-
53
- const app = new App(mockClient)
54
- const result = await app.settings().execute()
55
-
56
- expect(mockHttpClient.get).toHaveBeenCalledWith('api/apps/test-app/settings/')
57
- expect(result).toEqual(settingsData)
58
- })
59
- })
60
-
61
- describe('execute()', () => {
62
- it('calls httpClient.get by default', async () => {
63
- mockHttpClient.get.mockResolvedValue({})
64
-
65
- const app = new App(mockClient)
66
- await app.execute()
67
-
68
- expect(mockHttpClient.get).toHaveBeenCalled()
69
- })
70
-
71
- it('builds correct base URL with app slug', async () => {
72
- mockHttpClient.get.mockResolvedValue({})
73
-
74
- const app = new App(mockClient)
75
- await app.roles().execute()
76
-
77
- expect(mockHttpClient.get).toHaveBeenCalledWith(
78
- expect.stringContaining('api/apps/test-app')
79
- )
80
- })
81
- })
82
-
83
- describe('response handling', () => {
84
- it('returns roles list matching RolesListResponse type', async () => {
85
- const mockResponse: RolesListResponse = {
86
- status: 'success',
87
- message: 'Data retrieved successfully',
88
- data: [
89
- { id: '1', name: 'Admin', slug: 'admin', description: 'Admin role', is_default: false, created_at: '2024-01-01', updated_at: '2024-01-01' },
90
- { id: '2', name: 'Editor', slug: 'editor', description: 'Editor role', is_default: false, created_at: '2024-01-01', updated_at: '2024-01-01' }
91
- ],
92
- total: 2
93
- }
94
- mockHttpClient.get.mockResolvedValue(mockResponse)
95
- const result = await new App(mockClient).roles().execute() as RolesListResponse
96
- expect(result.status).toBe('success')
97
- expect(result.data).toHaveLength(2)
98
- expect(result.data[0].name).toBe('Admin')
99
- expect(result.total).toBe(2)
100
- })
101
-
102
- it('returns settings matching AppSettingsResponse type', async () => {
103
- const mockResponse: AppSettingsResponse = {
104
- status: 'success',
105
- message: 'Settings retrieved successfully',
106
- data: { name: 'My App', slug: 'my-app', description: 'Test app', is_active: true, documentation_url: null, support_email: null, default_frontend_worker_url: null, created_at: '2024-01-01', updated_at: '2024-01-01' }
107
- }
108
- mockHttpClient.get.mockResolvedValue(mockResponse)
109
- const result = await new App(mockClient).settings().execute() as AppSettingsResponse
110
- expect(result.data.name).toBe('My App')
111
- expect(result.data.is_active).toBe(true)
112
- })
113
- })
114
- })
@@ -1,91 +0,0 @@
1
- import { describe, it, expect, vi, beforeEach } from 'vitest'
2
- import { Auth } from '../../../src/lib/auth/AuthClient.js'
3
- import { Client } from '../../../src/client.js'
4
-
5
- const mockTokenClient = {
6
- isAuthenticated: vi.fn(),
7
- getToken: vi.fn(),
8
- getSessionToken: vi.fn(),
9
- clearTokens: vi.fn(),
10
- }
11
-
12
- const mockHttpClient = {
13
- get: vi.fn(),
14
- post: vi.fn()
15
- }
16
-
17
- const mockClient = {
18
- getConfig: () => ({
19
- apiKey: 'test-key',
20
- appSlug: 'test-app',
21
- apiUrl: 'https://api.test.com',
22
- deskUrl: 'https://desk.test.com'
23
- }),
24
- httpClient: mockHttpClient,
25
- tokenClient: mockTokenClient
26
- } as unknown as Client
27
-
28
- describe('Auth', () => {
29
- beforeEach(() => {
30
- vi.clearAllMocks()
31
- })
32
-
33
- describe('isUserAuthenticated()', () => {
34
- it('returns true when user is authenticated', () => {
35
- mockTokenClient.isAuthenticated.mockReturnValue(true)
36
- const auth = new Auth(mockClient)
37
- expect(auth.isUserAuthenticated()).toBe(true)
38
- })
39
-
40
- it('returns false when user is not authenticated', () => {
41
- mockTokenClient.isAuthenticated.mockReturnValue(false)
42
- const auth = new Auth(mockClient)
43
- expect(auth.isUserAuthenticated()).toBe(false)
44
- })
45
- })
46
-
47
- describe('getSessionToken()', () => {
48
- it('returns session token from tokenClient', () => {
49
- mockTokenClient.getSessionToken.mockReturnValue('session-token-123')
50
- const auth = new Auth(mockClient)
51
- expect(auth.getSessionToken()).toBe('session-token-123')
52
- })
53
-
54
- it('returns null when no session token exists', () => {
55
- mockTokenClient.getSessionToken.mockReturnValue(null)
56
- const auth = new Auth(mockClient)
57
- expect(auth.getSessionToken()).toBeNull()
58
- })
59
- })
60
-
61
- describe('getCurrentUser()', () => {
62
- it('returns null when not authenticated', async () => {
63
- mockTokenClient.isAuthenticated.mockReturnValue(false)
64
- const auth = new Auth(mockClient)
65
- const result = await auth.getCurrentUser()
66
- expect(result).toBeNull()
67
- })
68
-
69
- it('fetches user data when authenticated', async () => {
70
- mockTokenClient.isAuthenticated.mockReturnValue(true)
71
- const userData = { username: 'testuser', email: 'test@example.com' }
72
- mockHttpClient.get.mockResolvedValue(userData)
73
-
74
- const auth = new Auth(mockClient)
75
- const result = await auth.getCurrentUser()
76
-
77
- expect(mockHttpClient.get).toHaveBeenCalledWith('api/users/me/')
78
- expect(result).toEqual(userData)
79
- })
80
-
81
- it('returns null on API error', async () => {
82
- mockTokenClient.isAuthenticated.mockReturnValue(true)
83
- mockHttpClient.get.mockRejectedValue(new Error('API Error'))
84
-
85
- const auth = new Auth(mockClient)
86
- const result = await auth.getCurrentUser()
87
-
88
- expect(result).toBeNull()
89
- })
90
- })
91
- })
@@ -1,87 +0,0 @@
1
- import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest'
2
- import { Client } from '../../../src/client.js'
3
- import packageJson from '../../../package.json' with { type: 'json' }
4
-
5
- describe('Client', () => {
6
- const consoleInfoSpy = vi.spyOn(console, 'info').mockImplementation(() => undefined)
7
-
8
- beforeEach(() => {
9
- vi.clearAllMocks()
10
- })
11
-
12
- afterEach(() => {
13
- consoleInfoSpy.mockClear()
14
- })
15
-
16
- describe('constructor', () => {
17
- it('throws error when config is not provided', () => {
18
- expect(() => new Client(undefined as any)).toThrow('Config is required')
19
- })
20
-
21
- it('throws error when apiKey is missing', () => {
22
- expect(() => new Client({ apiUrl: 'https://api.test.com', appSlug: 'test' } as any))
23
- .toThrow('API key is required')
24
- })
25
-
26
- it('throws error when apiUrl is missing', () => {
27
- expect(() => new Client({ apiKey: 'key', appSlug: 'test' } as any))
28
- .toThrow('API URL is required')
29
- })
30
-
31
- it('creates client with valid config', () => {
32
- const client = new Client({
33
- apiKey: 'test-key',
34
- appSlug: 'test-app',
35
- apiUrl: 'https://api.test.com'
36
- })
37
- expect(client).toBeInstanceOf(Client)
38
- })
39
-
40
- it('logs the sdk version when initialized', () => {
41
- new Client({
42
- apiKey: 'test-key',
43
- appSlug: 'test-app',
44
- apiUrl: 'https://api.test.com'
45
- })
46
-
47
- expect(consoleInfoSpy).toHaveBeenCalledWith(`Taruvi SDK v${packageJson.version} initialized`)
48
- })
49
-
50
- it('initializes httpClient and tokenClient', () => {
51
- const client = new Client({
52
- apiKey: 'test-key',
53
- appSlug: 'test-app',
54
- apiUrl: 'https://api.test.com'
55
- })
56
- expect(client.httpClient).toBeDefined()
57
- expect(client.tokenClient).toBeDefined()
58
- })
59
- })
60
-
61
- describe('getConfig()', () => {
62
- it('returns readonly copy of config', () => {
63
- const config = {
64
- apiKey: 'test-key',
65
- appSlug: 'test-app',
66
- apiUrl: 'https://api.test.com'
67
- }
68
- const client = new Client(config)
69
- const returnedConfig = client.getConfig()
70
-
71
- expect(returnedConfig.apiKey).toBe(config.apiKey)
72
- expect(returnedConfig.appSlug).toBe(config.appSlug)
73
- expect(returnedConfig.apiUrl).toBe(config.apiUrl)
74
- })
75
-
76
- it('includes optional deskUrl when provided', () => {
77
- const config = {
78
- apiKey: 'test-key',
79
- appSlug: 'test-app',
80
- apiUrl: 'https://api.test.com',
81
- deskUrl: 'https://desk.test.com'
82
- }
83
- const client = new Client(config)
84
- expect(client.getConfig().deskUrl).toBe('https://desk.test.com')
85
- })
86
- })
87
- })