@docyrus/docyrus 0.0.15 → 0.0.17

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 (41) hide show
  1. package/README.md +25 -2
  2. package/main.js +1028 -540
  3. package/main.js.map +4 -4
  4. package/package.json +2 -1
  5. package/resources/pi-agent/prompts/agent-system.md +25 -0
  6. package/resources/pi-agent/prompts/coder-append-system.md +19 -0
  7. package/resources/pi-agent/skills/docyrus-ai/SKILL.md +28 -0
  8. package/resources/pi-agent/skills/docyrus-api-dev/SKILL.md +161 -0
  9. package/resources/pi-agent/skills/docyrus-api-dev/references/api-client.md +349 -0
  10. package/resources/pi-agent/skills/docyrus-api-dev/references/authentication.md +238 -0
  11. package/resources/pi-agent/skills/docyrus-api-dev/references/data-source-query-guide.md +2059 -0
  12. package/resources/pi-agent/skills/docyrus-api-dev/references/formula-design-guide-llm.md +320 -0
  13. package/resources/pi-agent/skills/docyrus-api-dev/references/query-and-formulas.md +592 -0
  14. package/resources/pi-agent/skills/docyrus-api-doctor/SKILL.md +70 -0
  15. package/resources/pi-agent/skills/docyrus-api-doctor/references/checklist-details.md +588 -0
  16. package/resources/pi-agent/skills/docyrus-app-dev/SKILL.md +159 -0
  17. package/resources/pi-agent/skills/docyrus-app-dev/references/api-client-and-auth.md +275 -0
  18. package/resources/pi-agent/skills/docyrus-app-dev/references/collections-and-patterns.md +352 -0
  19. package/resources/pi-agent/skills/docyrus-app-dev/references/data-source-query-guide.md +2059 -0
  20. package/resources/pi-agent/skills/docyrus-app-dev/references/formula-design-guide-llm.md +320 -0
  21. package/resources/pi-agent/skills/docyrus-app-dev/references/query-guide.md +525 -0
  22. package/resources/pi-agent/skills/docyrus-app-ui-design/SKILL.md +466 -0
  23. package/resources/pi-agent/skills/docyrus-app-ui-design/references/component-selection-guide.md +602 -0
  24. package/resources/pi-agent/skills/docyrus-app-ui-design/references/icon-usage-guide.md +463 -0
  25. package/resources/pi-agent/skills/docyrus-app-ui-design/references/preferred-components-catalog.md +242 -0
  26. package/resources/pi-agent/skills/docyrus-apps/SKILL.md +54 -0
  27. package/resources/pi-agent/skills/docyrus-architect/SKILL.md +174 -0
  28. package/resources/pi-agent/skills/docyrus-architect/references/custom-query-guide.md +410 -0
  29. package/resources/pi-agent/skills/docyrus-architect/references/data-source-query-guide.md +2059 -0
  30. package/resources/pi-agent/skills/docyrus-architect/references/formula-design-guide-llm.md +320 -0
  31. package/resources/pi-agent/skills/docyrus-architect/references/formula-reference.md +145 -0
  32. package/resources/pi-agent/skills/docyrus-auth/SKILL.md +100 -0
  33. package/resources/pi-agent/skills/docyrus-cli-app/SKILL.md +279 -0
  34. package/resources/pi-agent/skills/docyrus-cli-app/references/cli-manifest.md +532 -0
  35. package/resources/pi-agent/skills/docyrus-cli-app/references/list-query-examples.md +248 -0
  36. package/resources/pi-agent/skills/docyrus-curl/SKILL.md +32 -0
  37. package/resources/pi-agent/skills/docyrus-discover/SKILL.md +63 -0
  38. package/resources/pi-agent/skills/docyrus-ds/SKILL.md +95 -0
  39. package/resources/pi-agent/skills/docyrus-env/SKILL.md +21 -0
  40. package/resources/pi-agent/skills/docyrus-studio/SKILL.md +369 -0
  41. package/resources/pi-agent/skills/docyrus-tui/SKILL.md +15 -0
@@ -0,0 +1,238 @@
1
+ # @docyrus/signin — React Authentication Reference
2
+
3
+ ## Table of Contents
4
+
5
+ 1. [Overview](#overview)
6
+ 2. [Installation](#installation)
7
+ 3. [DocyrusAuthProvider](#docyrusauthprovider)
8
+ 4. [Auth Hooks](#auth-hooks)
9
+ 5. [SignInButton](#signinbutton)
10
+ 6. [Auth Modes](#auth-modes)
11
+ 7. [Environment Variables](#environment-variables)
12
+ 8. [App Integration Pattern](#app-integration-pattern)
13
+ 9. [Advanced Usage](#advanced-usage)
14
+
15
+ ---
16
+
17
+ ## Overview
18
+
19
+ `@docyrus/signin` provides "Sign in with Docyrus" for React apps. Auto-detects environment:
20
+ - **Standalone**: OAuth2 Authorization Code + PKCE via page redirect
21
+ - **Iframe**: Receives tokens via `window.postMessage` from `*.docyrus.app` hosts
22
+
23
+ Peer dependencies: `react >= 18`, `@docyrus/api-client >= 0.0.10`
24
+
25
+ ---
26
+
27
+ ## Installation
28
+
29
+ ```bash
30
+ pnpm add @docyrus/signin @docyrus/api-client
31
+ ```
32
+
33
+ ---
34
+
35
+ ## DocyrusAuthProvider
36
+
37
+ Wrap application root:
38
+
39
+ ```tsx
40
+ import { DocyrusAuthProvider } from '@docyrus/signin'
41
+
42
+ <DocyrusAuthProvider
43
+ apiUrl="https://alpha-api.docyrus.com"
44
+ clientId="your-oauth2-client-id"
45
+ redirectUri="http://localhost:3000/auth/callback"
46
+ scopes={['offline_access', 'Read.All', 'DS.ReadWrite.All', 'Users.Read']}
47
+ callbackPath="/auth/callback"
48
+ >
49
+ <App />
50
+ </DocyrusAuthProvider>
51
+ ```
52
+
53
+ ### Props
54
+
55
+ | Prop | Type | Default | Description |
56
+ |------|------|---------|-------------|
57
+ | `apiUrl` | `string` | `https://alpha-api.docyrus.com` | API base URL |
58
+ | `clientId` | `string` | Built-in default | OAuth2 client ID |
59
+ | `redirectUri` | `string` | `origin + callbackPath` | OAuth2 redirect URI |
60
+ | `scopes` | `string[]` | `['offline_access', 'Read.All', ...]` | OAuth2 scopes |
61
+ | `callbackPath` | `string` | `/auth/callback` | Path to detect OAuth callback |
62
+ | `forceMode` | `'standalone' \| 'iframe'` | Auto-detected | Force a specific auth mode |
63
+ | `storageKeyPrefix` | `string` | `docyrus_oauth2_` | localStorage key prefix |
64
+ | `allowedHostOrigins` | `string[]` | `undefined` | Extra trusted iframe origins |
65
+
66
+ ---
67
+
68
+ ## Auth Hooks
69
+
70
+ ### useDocyrusAuth()
71
+
72
+ Full authentication context:
73
+
74
+ ```typescript
75
+ import { useDocyrusAuth } from '@docyrus/signin'
76
+
77
+ const {
78
+ status, // 'loading' | 'authenticated' | 'unauthenticated'
79
+ mode, // 'standalone' | 'iframe'
80
+ client, // RestApiClient | null — configured API client with tokens
81
+ tokens, // { accessToken, refreshToken, ... } | null
82
+ signIn, // () => void — redirects to Docyrus login page
83
+ signOut, // () => void — logout and clear tokens
84
+ error, // Error | null
85
+ } = useDocyrusAuth()
86
+ ```
87
+
88
+ ### useDocyrusClient()
89
+
90
+ Shorthand for just the API client:
91
+
92
+ ```typescript
93
+ import { useDocyrusClient } from '@docyrus/signin'
94
+
95
+ const client = useDocyrusClient() // RestApiClient | null
96
+
97
+ if (client) {
98
+ const user = await client.get('/v1/users/me')
99
+ const items = await client.get('/v1/apps/base/data-sources/project/items', queryPayload)
100
+ }
101
+ ```
102
+
103
+ ---
104
+
105
+ ## SignInButton
106
+
107
+ Unstyled button. Automatically hidden when authenticated or in iframe mode.
108
+
109
+ ```tsx
110
+ import { SignInButton } from '@docyrus/signin'
111
+
112
+ // Basic
113
+ <SignInButton />
114
+
115
+ // Styled
116
+ <SignInButton className="btn btn-primary" label="Log in with Docyrus" />
117
+
118
+ // Render prop for full control
119
+ <SignInButton>
120
+ {({ signIn, isLoading }) => (
121
+ <button onClick={signIn} disabled={isLoading}>
122
+ {isLoading ? 'Redirecting...' : 'Sign in with Docyrus'}
123
+ </button>
124
+ )}
125
+ </SignInButton>
126
+ ```
127
+
128
+ ---
129
+
130
+ ## Auth Modes
131
+
132
+ ### Standalone (OAuth2 PKCE)
133
+
134
+ For apps running directly in the browser:
135
+
136
+ 1. User clicks sign-in
137
+ 2. Page redirects to Docyrus authorization endpoint
138
+ 3. After login, redirects back with authorization code
139
+ 4. Provider automatically exchanges code for tokens
140
+ 5. Tokens stored in localStorage, auto-refreshed before expiry
141
+
142
+ ### Iframe (postMessage)
143
+
144
+ For apps embedded in an iframe on `*.docyrus.app`:
145
+
146
+ 1. Provider detects iframe environment and validates host origin
147
+ 2. Host sends `{ type: 'signin', accessToken, refreshToken }` via `postMessage`
148
+ 3. Provider creates API client with received tokens
149
+ 4. When tokens expire, provider sends `{ type: 'token-refresh-request' }` to host
150
+ 5. Host responds with fresh tokens
151
+
152
+ ---
153
+
154
+ ## Environment Variables
155
+
156
+ ```bash
157
+ # .env
158
+ VITE_API_BASE_URL=https://localhost:3366
159
+ VITE_OAUTH2_CLIENT_ID=your-client-id
160
+ VITE_OAUTH2_REDIRECT_URI=http://localhost:3000/auth/callback
161
+ VITE_OAUTH2_SCOPES=openid profile offline_access Users.Read DS.ReadWrite.All
162
+ ```
163
+
164
+ Access in code: `import.meta.env.VITE_API_BASE_URL`
165
+
166
+ ---
167
+
168
+ ## App Integration Pattern
169
+
170
+ ### Minimal Setup (main.tsx)
171
+
172
+ ```tsx
173
+ import { StrictMode } from 'react'
174
+ import { createRoot } from 'react-dom/client'
175
+ import { DocyrusAuthProvider } from '@docyrus/signin'
176
+
177
+ const scopes = (import.meta.env.VITE_OAUTH2_SCOPES || '').split(' ').filter(Boolean)
178
+
179
+ createRoot(document.getElementById('root')!).render(
180
+ <StrictMode>
181
+ <DocyrusAuthProvider
182
+ apiUrl={import.meta.env.VITE_API_BASE_URL}
183
+ clientId={import.meta.env.VITE_OAUTH2_CLIENT_ID}
184
+ redirectUri={import.meta.env.VITE_OAUTH2_REDIRECT_URI}
185
+ scopes={scopes}
186
+ callbackPath="/auth/callback"
187
+ >
188
+ <App />
189
+ </DocyrusAuthProvider>
190
+ </StrictMode>,
191
+ )
192
+ ```
193
+
194
+ ### Auth-Gated App (App.tsx)
195
+
196
+ ```tsx
197
+ import { useDocyrusAuth, useDocyrusClient, SignInButton } from '@docyrus/signin'
198
+
199
+ function App() {
200
+ const { status, signOut } = useDocyrusAuth()
201
+ const client = useDocyrusClient()
202
+
203
+ if (status === 'loading') return <div>Loading...</div>
204
+ if (status === 'unauthenticated') return <SignInButton />
205
+
206
+ // client is guaranteed non-null when authenticated
207
+ return (
208
+ <div>
209
+ <p>Authenticated!</p>
210
+ <button onClick={() => client!.get('/v1/users/me').then(console.log)}>My Profile</button>
211
+ <button onClick={signOut}>Sign Out</button>
212
+ </div>
213
+ )
214
+ }
215
+ ```
216
+
217
+ ### Accessing the API Client
218
+
219
+ In React components, use `useDocyrusClient()` to get the authenticated client. Generated collections are hooks that call `useDocyrusClient()` internally, so no manual client syncing is needed:
220
+
221
+ ```typescript
222
+ // Generated collections use useDocyrusClient() internally
223
+ const { list, get, create } = useBaseProjectCollection()
224
+
225
+ // For direct API access in React components
226
+ const client = useDocyrusClient()
227
+ const data = await client!.get('/v1/custom-endpoint')
228
+ ```
229
+
230
+ ---
231
+
232
+ ## Advanced Usage
233
+
234
+ Core classes exported for advanced scenarios:
235
+
236
+ ```typescript
237
+ import { AuthManager, StandaloneOAuth2Auth, IframeAuth, detectAuthMode } from '@docyrus/signin'
238
+ ```