@korajs/cli 0.4.0 → 0.5.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 (103) hide show
  1. package/dist/bin.cjs +1609 -643
  2. package/dist/bin.cjs.map +1 -1
  3. package/dist/bin.js +1086 -139
  4. package/dist/bin.js.map +1 -1
  5. package/dist/{chunk-CMSX76KM.js → chunk-3WNFM3QB.js} +103 -96
  6. package/dist/chunk-3WNFM3QB.js.map +1 -0
  7. package/dist/{chunk-MVP5PDT4.js → chunk-PSRM56B7.js} +2 -2
  8. package/dist/{chunk-YGVO4POI.js → chunk-SOTZIWIF.js} +27 -15
  9. package/dist/chunk-SOTZIWIF.js.map +1 -0
  10. package/dist/create.cjs +54 -47
  11. package/dist/create.cjs.map +1 -1
  12. package/dist/create.js +2 -2
  13. package/dist/index.cjs +78 -59
  14. package/dist/index.cjs.map +1 -1
  15. package/dist/index.d.cts +5 -3
  16. package/dist/index.d.ts +5 -3
  17. package/dist/index.js +2 -2
  18. package/package.json +9 -3
  19. package/templates/react-basic/README.md.hbs +10 -1
  20. package/templates/react-basic/src/App.tsx +112 -126
  21. package/templates/react-basic/src/index.css +165 -159
  22. package/templates/react-basic/src/kora-worker.ts +0 -1
  23. package/templates/react-basic/src/main.tsx +12 -12
  24. package/templates/react-basic/src/modules/todos/todo.mutations.ts +25 -0
  25. package/templates/react-basic/src/modules/todos/todo.queries.ts +5 -0
  26. package/templates/react-basic/src/modules/todos/todo.schema.ts +10 -0
  27. package/templates/react-basic/src/modules/todos/useTodos.ts +31 -0
  28. package/templates/react-basic/src/schema.ts +6 -12
  29. package/templates/react-basic/src/vite-env.d.ts +17 -0
  30. package/templates/react-basic/{tsconfig.json → tsconfig.json.hbs} +1 -2
  31. package/templates/react-basic/vite.config.ts +57 -50
  32. package/templates/react-sync/.env.example +19 -0
  33. package/templates/react-sync/README.md.hbs +43 -1
  34. package/templates/react-sync/package.json.hbs +3 -0
  35. package/templates/react-sync/server.ts +90 -26
  36. package/templates/react-sync/src/App.tsx +132 -130
  37. package/templates/react-sync/src/auth.ts +25 -0
  38. package/templates/react-sync/src/index.css +212 -165
  39. package/templates/react-sync/src/kora-worker.ts +0 -1
  40. package/templates/react-sync/src/main.tsx +34 -18
  41. package/templates/react-sync/src/modules/todos/todo.mutations.ts +25 -0
  42. package/templates/react-sync/src/modules/todos/todo.queries.ts +5 -0
  43. package/templates/react-sync/src/modules/todos/todo.schema.ts +10 -0
  44. package/templates/react-sync/src/modules/todos/useTodos.ts +31 -0
  45. package/templates/react-sync/src/schema.ts +6 -12
  46. package/templates/react-sync/src/vite-env.d.ts +17 -0
  47. package/templates/react-sync/{tsconfig.json → tsconfig.json.hbs} +1 -2
  48. package/templates/react-sync/vite.config.ts +67 -60
  49. package/templates/react-tailwind/README.md.hbs +10 -1
  50. package/templates/react-tailwind/src/App.tsx +186 -197
  51. package/templates/react-tailwind/src/index.css +3 -3
  52. package/templates/react-tailwind/src/kora-worker.ts +0 -1
  53. package/templates/react-tailwind/src/main.tsx +19 -12
  54. package/templates/react-tailwind/src/modules/todos/todo.mutations.ts +25 -0
  55. package/templates/react-tailwind/src/modules/todos/todo.queries.ts +5 -0
  56. package/templates/react-tailwind/src/modules/todos/todo.schema.ts +10 -0
  57. package/templates/react-tailwind/src/modules/todos/useTodos.ts +31 -0
  58. package/templates/react-tailwind/src/schema.ts +6 -12
  59. package/templates/react-tailwind/src/vite-env.d.ts +17 -0
  60. package/templates/react-tailwind/{tsconfig.json → tsconfig.json.hbs} +1 -2
  61. package/templates/react-tailwind/vite.config.ts +57 -50
  62. package/templates/react-tailwind-sync/.env.example +19 -0
  63. package/templates/react-tailwind-sync/README.md.hbs +43 -1
  64. package/templates/react-tailwind-sync/package.json.hbs +3 -0
  65. package/templates/react-tailwind-sync/server.ts +90 -26
  66. package/templates/react-tailwind-sync/src/App.tsx +246 -222
  67. package/templates/react-tailwind-sync/src/auth.ts +25 -0
  68. package/templates/react-tailwind-sync/src/index.css +3 -3
  69. package/templates/react-tailwind-sync/src/kora-worker.ts +0 -1
  70. package/templates/react-tailwind-sync/src/main.tsx +48 -18
  71. package/templates/react-tailwind-sync/src/modules/todos/todo.mutations.ts +25 -0
  72. package/templates/react-tailwind-sync/src/modules/todos/todo.queries.ts +5 -0
  73. package/templates/react-tailwind-sync/src/modules/todos/todo.schema.ts +10 -0
  74. package/templates/react-tailwind-sync/src/modules/todos/useTodos.ts +31 -0
  75. package/templates/react-tailwind-sync/src/schema.ts +6 -12
  76. package/templates/react-tailwind-sync/src/vite-env.d.ts +17 -0
  77. package/templates/react-tailwind-sync/{tsconfig.json → tsconfig.json.hbs} +1 -2
  78. package/templates/react-tailwind-sync/vite.config.ts +67 -60
  79. package/templates/tauri-react/.env.example +20 -0
  80. package/templates/tauri-react/README.md.hbs +36 -1
  81. package/templates/tauri-react/dev.ts +11 -11
  82. package/templates/tauri-react/package.json.hbs +2 -0
  83. package/templates/tauri-react/server.ts +86 -12
  84. package/templates/tauri-react/src/App.tsx +769 -544
  85. package/templates/tauri-react/src/AppShell.tsx +125 -83
  86. package/templates/tauri-react/src/SetupScreen.tsx +257 -208
  87. package/templates/tauri-react/src/auth.ts +45 -0
  88. package/templates/tauri-react/src/main.tsx +3 -3
  89. package/templates/tauri-react/src/modules/todos/todo.mutations.ts +25 -0
  90. package/templates/tauri-react/src/modules/todos/todo.queries.ts +5 -0
  91. package/templates/tauri-react/src/modules/todos/todo.schema.ts +10 -0
  92. package/templates/tauri-react/src/modules/todos/useTodos.ts +31 -0
  93. package/templates/tauri-react/src/schema.ts +6 -12
  94. package/templates/tauri-react/src/sync-config.ts +47 -47
  95. package/templates/tauri-react/src/updater.ts +15 -15
  96. package/templates/tauri-react/src/vite-env.d.ts +17 -0
  97. package/templates/tauri-react/src-tauri/tauri.conf.json +1 -1
  98. package/templates/tauri-react/tsconfig.json.hbs +14 -0
  99. package/templates/tauri-react/vite.config.ts +9 -9
  100. package/dist/chunk-CMSX76KM.js.map +0 -1
  101. package/dist/chunk-YGVO4POI.js.map +0 -1
  102. package/templates/tauri-react/tsconfig.json +0 -15
  103. /package/dist/{chunk-MVP5PDT4.js.map → chunk-PSRM56B7.js.map} +0 -0
@@ -1,15 +1,23 @@
1
- import { useState, useCallback, useEffect } from 'react'
2
- import { createApp } from 'korajs'
1
+ import { createKoraAuthSync } from '@korajs/auth'
2
+ import { AuthProvider } from '@korajs/auth/react'
3
3
  import { KoraProvider } from '@korajs/react'
4
- import schema from './schema'
4
+ import { createApp } from 'korajs'
5
+ import { useCallback, useEffect, useState } from 'react'
5
6
  import { App } from './App'
6
7
  import { SetupScreen } from './SetupScreen'
7
- import { getSyncUrl, setSyncUrl, clearSyncUrl, hasCompletedSetup, markSetupComplete, factoryReset } from './sync-config'
8
+ import { completeOAuthCallbackFromLocation, createDesktopAuthClient } from './auth'
9
+ import schema from './schema'
10
+ import {
11
+ clearSyncUrl,
12
+ factoryReset,
13
+ getSyncUrl,
14
+ hasCompletedSetup,
15
+ markSetupComplete,
16
+ setSyncUrl,
17
+ } from './sync-config'
8
18
  import { checkForUpdates } from './updater'
9
19
 
10
- type AppState =
11
- | { phase: 'setup' }
12
- | { phase: 'running'; syncUrl: string | null }
20
+ type AppState = { phase: 'setup' } | { phase: 'running'; syncUrl: string | null }
13
21
 
14
22
  /**
15
23
  * Root component that handles the first-launch setup flow.
@@ -23,94 +31,128 @@ type AppState =
23
31
  * partial state from one server leaking to another.
24
32
  */
25
33
  export function AppShell() {
26
- const [state, setState] = useState<AppState>(() => {
27
- if (hasCompletedSetup()) {
28
- return { phase: 'running', syncUrl: getSyncUrl() }
29
- }
30
- return { phase: 'setup' }
31
- })
34
+ const [state, setState] = useState<AppState>(() => {
35
+ if (hasCompletedSetup()) {
36
+ return { phase: 'running', syncUrl: getSyncUrl() }
37
+ }
38
+ return { phase: 'setup' }
39
+ })
32
40
 
33
- const handleConnect = useCallback((url: string) => {
34
- setSyncUrl(url)
35
- setState({ phase: 'running', syncUrl: url })
36
- }, [])
41
+ const handleConnect = useCallback((url: string) => {
42
+ setSyncUrl(url)
43
+ setState({ phase: 'running', syncUrl: url })
44
+ }, [])
37
45
 
38
- const handleSkip = useCallback(() => {
39
- markSetupComplete()
40
- setState({ phase: 'running', syncUrl: null })
41
- }, [])
46
+ const handleSkip = useCallback(() => {
47
+ markSetupComplete()
48
+ setState({ phase: 'running', syncUrl: null })
49
+ }, [])
42
50
 
43
- // Change to a different server URL.
44
- // This requires restarting the app to create a fresh Kora instance.
45
- const handleChangeServer = useCallback((newUrl: string | null) => {
46
- if (newUrl) {
47
- setSyncUrl(newUrl)
48
- } else {
49
- clearSyncUrl()
50
- markSetupComplete() // Still completed — just disconnected
51
- }
52
- // Reload to re-initialize Kora with the new URL.
53
- // This is cleaner than trying to hot-swap the sync connection,
54
- // and prevents data from one server context leaking to another.
55
- window.location.reload()
56
- }, [])
51
+ // Change to a different server URL.
52
+ // This requires restarting the app to create a fresh Kora instance.
53
+ const handleChangeServer = useCallback((newUrl: string | null) => {
54
+ if (newUrl) {
55
+ setSyncUrl(newUrl)
56
+ } else {
57
+ clearSyncUrl()
58
+ markSetupComplete() // Still completed — just disconnected
59
+ }
60
+ // Reload to re-initialize Kora with the new URL.
61
+ // This is cleaner than trying to hot-swap the sync connection,
62
+ // and prevents data from one server context leaking to another.
63
+ window.location.reload()
64
+ }, [])
57
65
 
58
- const handleFactoryReset = useCallback(() => {
59
- factoryReset() // Clears all data and reloads
60
- }, [])
66
+ const handleFactoryReset = useCallback(() => {
67
+ factoryReset() // Clears all data and reloads
68
+ }, [])
61
69
 
62
- if (state.phase === 'setup') {
63
- return <SetupScreen onConnect={handleConnect} onSkip={handleSkip} />
64
- }
70
+ if (state.phase === 'setup') {
71
+ return <SetupScreen onConnect={handleConnect} onSkip={handleSkip} />
72
+ }
65
73
 
66
- return (
67
- <ConnectedApp
68
- syncUrl={state.syncUrl}
69
- onChangeServer={handleChangeServer}
70
- onFactoryReset={handleFactoryReset}
71
- />
72
- )
74
+ return (
75
+ <ConnectedApp
76
+ syncUrl={state.syncUrl}
77
+ onChangeServer={handleChangeServer}
78
+ onFactoryReset={handleFactoryReset}
79
+ />
80
+ )
73
81
  }
74
82
 
75
83
  interface ConnectedAppProps {
76
- syncUrl: string | null
77
- onChangeServer: (newUrl: string | null) => void
78
- onFactoryReset: () => void
84
+ syncUrl: string | null
85
+ onChangeServer: (newUrl: string | null) => void
86
+ onFactoryReset: () => void
79
87
  }
80
88
 
81
89
  function ConnectedApp({ syncUrl, onChangeServer, onFactoryReset }: ConnectedAppProps) {
82
- // Create the Kora app instance with optional sync.
83
- // This only runs once — the app instance is stable for the lifetime of this component.
84
- const [app] = useState(() =>
85
- createApp({
86
- schema,
87
- ...(syncUrl ? { sync: { url: syncUrl } } : {}),
88
- devtools: true,
89
- })
90
- )
90
+ const [authClient] = useState(() => createDesktopAuthClient(syncUrl))
91
+ // Create the Kora app instance with optional sync.
92
+ // This only runs once — the app instance is stable for the lifetime of this component.
93
+ const [app] = useState(() =>
94
+ createApp({
95
+ schema,
96
+ ...(syncUrl
97
+ ? {
98
+ sync: {
99
+ url: syncUrl,
100
+ authClient: createKoraAuthSync({ authClient, schema }),
101
+ },
102
+ }
103
+ : {}),
104
+ devtools: true,
105
+ }),
106
+ )
91
107
 
92
- // Connect to sync server once ready, and check for updates
93
- useEffect(() => {
94
- if (syncUrl) {
95
- app.ready.then(() => app.sync?.connect())
96
- }
97
- checkForUpdates()
98
- }, [])
108
+ // Connect to sync server once ready, and check for updates
109
+ useEffect(() => {
110
+ void completeOAuthCallbackFromLocation(authClient).catch((error) => {
111
+ console.error('[Kora Auth] OAuth callback failed:', error)
112
+ })
113
+ if (syncUrl) {
114
+ app.ready.then(() => app.sync?.connect())
115
+ }
116
+ checkForUpdates()
117
+ }, [app, authClient, syncUrl])
99
118
 
100
- return (
101
- <KoraProvider
102
- app={app}
103
- fallback={
104
- <div style={{ display: 'flex', alignItems: 'center', justifyContent: 'center', height: '100vh', background: '#0a0a0a', color: '#6b7280' }}>
105
- Loading...
106
- </div>
107
- }
108
- >
109
- <App
110
- syncUrl={syncUrl}
111
- onChangeServer={onChangeServer}
112
- onFactoryReset={onFactoryReset}
113
- />
114
- </KoraProvider>
115
- )
119
+ return (
120
+ <AuthProvider
121
+ client={authClient}
122
+ fallback={
123
+ <div
124
+ style={{
125
+ display: 'flex',
126
+ alignItems: 'center',
127
+ justifyContent: 'center',
128
+ height: '100vh',
129
+ background: '#0a0a0a',
130
+ color: '#6b7280',
131
+ }}
132
+ >
133
+ Restoring session...
134
+ </div>
135
+ }
136
+ >
137
+ <KoraProvider
138
+ app={app}
139
+ fallback={
140
+ <div
141
+ style={{
142
+ display: 'flex',
143
+ alignItems: 'center',
144
+ justifyContent: 'center',
145
+ height: '100vh',
146
+ background: '#0a0a0a',
147
+ color: '#6b7280',
148
+ }}
149
+ >
150
+ Loading...
151
+ </div>
152
+ }
153
+ >
154
+ <App syncUrl={syncUrl} onChangeServer={onChangeServer} onFactoryReset={onFactoryReset} />
155
+ </KoraProvider>
156
+ </AuthProvider>
157
+ )
116
158
  }