@docyrus/docyrus 0.0.19 → 0.0.21

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 (111) hide show
  1. package/agent-loader.js +37 -3
  2. package/agent-loader.js.map +2 -2
  3. package/main.js +498 -93
  4. package/main.js.map +4 -4
  5. package/package.json +14 -4
  6. package/resources/chrome-tools/browser-content.js +103 -0
  7. package/resources/chrome-tools/browser-cookies.js +35 -0
  8. package/resources/chrome-tools/browser-eval.js +53 -0
  9. package/resources/chrome-tools/browser-hn-scraper.js +108 -0
  10. package/resources/chrome-tools/browser-nav.js +44 -0
  11. package/resources/chrome-tools/browser-pick.js +162 -0
  12. package/resources/chrome-tools/browser-screenshot.js +34 -0
  13. package/resources/chrome-tools/browser-start.js +86 -0
  14. package/resources/pi-agent/extensions/answer.ts +532 -0
  15. package/resources/pi-agent/extensions/context.ts +578 -0
  16. package/resources/pi-agent/extensions/control.ts +1779 -0
  17. package/resources/pi-agent/extensions/diff.ts +218 -0
  18. package/resources/pi-agent/extensions/files.ts +199 -0
  19. package/resources/pi-agent/extensions/loop.ts +446 -0
  20. package/resources/pi-agent/extensions/multi-edit.ts +835 -0
  21. package/resources/pi-agent/extensions/notify.ts +88 -0
  22. package/resources/pi-agent/extensions/pi-mcp-adapter/CHANGELOG.md +192 -0
  23. package/resources/pi-agent/extensions/pi-mcp-adapter/LICENSE +21 -0
  24. package/resources/pi-agent/extensions/pi-mcp-adapter/README.md +296 -0
  25. package/resources/pi-agent/extensions/pi-mcp-adapter/app-bridge.bundle.js +67 -0
  26. package/resources/pi-agent/extensions/pi-mcp-adapter/cli.js +108 -0
  27. package/resources/pi-agent/extensions/pi-mcp-adapter/commands.ts +211 -0
  28. package/resources/pi-agent/extensions/pi-mcp-adapter/config.ts +227 -0
  29. package/resources/pi-agent/extensions/pi-mcp-adapter/consent-manager.ts +64 -0
  30. package/resources/pi-agent/extensions/pi-mcp-adapter/direct-tools.ts +301 -0
  31. package/resources/pi-agent/extensions/pi-mcp-adapter/errors.ts +219 -0
  32. package/resources/pi-agent/extensions/pi-mcp-adapter/glimpse-ui.ts +80 -0
  33. package/resources/pi-agent/extensions/pi-mcp-adapter/host-html-template.ts +427 -0
  34. package/resources/pi-agent/extensions/pi-mcp-adapter/index.ts +232 -0
  35. package/resources/pi-agent/extensions/pi-mcp-adapter/init.ts +319 -0
  36. package/resources/pi-agent/extensions/pi-mcp-adapter/lifecycle.ts +93 -0
  37. package/resources/pi-agent/extensions/pi-mcp-adapter/logger.ts +169 -0
  38. package/resources/pi-agent/extensions/pi-mcp-adapter/mcp-panel.ts +713 -0
  39. package/resources/pi-agent/extensions/pi-mcp-adapter/metadata-cache.ts +191 -0
  40. package/resources/pi-agent/extensions/pi-mcp-adapter/npx-resolver.ts +419 -0
  41. package/resources/pi-agent/extensions/pi-mcp-adapter/oauth-handler.ts +56 -0
  42. package/resources/pi-agent/extensions/pi-mcp-adapter/package.json +85 -0
  43. package/resources/pi-agent/extensions/pi-mcp-adapter/paths.ts +29 -0
  44. package/resources/pi-agent/extensions/pi-mcp-adapter/proxy-modes.ts +635 -0
  45. package/resources/pi-agent/extensions/pi-mcp-adapter/resource-tools.ts +17 -0
  46. package/resources/pi-agent/extensions/pi-mcp-adapter/server-manager.ts +330 -0
  47. package/resources/pi-agent/extensions/pi-mcp-adapter/state.ts +41 -0
  48. package/resources/pi-agent/extensions/pi-mcp-adapter/tool-metadata.ts +144 -0
  49. package/resources/pi-agent/extensions/pi-mcp-adapter/tool-registrar.ts +46 -0
  50. package/resources/pi-agent/extensions/pi-mcp-adapter/types.ts +367 -0
  51. package/resources/pi-agent/extensions/pi-mcp-adapter/ui-resource-handler.ts +145 -0
  52. package/resources/pi-agent/extensions/pi-mcp-adapter/ui-server.ts +623 -0
  53. package/resources/pi-agent/extensions/pi-mcp-adapter/ui-session.ts +384 -0
  54. package/resources/pi-agent/extensions/pi-mcp-adapter/ui-stream-types.ts +89 -0
  55. package/resources/pi-agent/extensions/pi-mcp-adapter/utils.ts +75 -0
  56. package/resources/pi-agent/extensions/prompt-editor.ts +1315 -0
  57. package/resources/pi-agent/extensions/prompt-url-widget.ts +158 -0
  58. package/resources/pi-agent/extensions/redraws.ts +24 -0
  59. package/resources/pi-agent/extensions/review.ts +2160 -0
  60. package/resources/pi-agent/extensions/todos.ts +2076 -0
  61. package/resources/pi-agent/extensions/tps.ts +47 -0
  62. package/resources/pi-agent/extensions/whimsical.ts +474 -0
  63. package/resources/pi-agent/prompts/coder-system.md +106 -0
  64. package/resources/pi-agent/skills/changelog-generator/SKILL.md +425 -0
  65. package/resources/pi-agent/skills/docyrus-chrome-devtools-cli/SKILL.md +80 -0
  66. package/resources/pi-agent/skills/docyrus-platform/SKILL.md +71 -0
  67. package/resources/pi-agent/skills/docyrus-platform/references/ai-capabilities.md +43 -0
  68. package/resources/pi-agent/skills/docyrus-platform/references/auth-and-multi-tenancy.md +35 -0
  69. package/resources/pi-agent/skills/docyrus-platform/references/automation-and-workflows.md +30 -0
  70. package/resources/pi-agent/skills/docyrus-platform/references/core-building-blocks.md +53 -0
  71. package/resources/pi-agent/skills/{docyrus-api-dev → docyrus-platform}/references/data-source-query-guide.md +32 -28
  72. package/resources/pi-agent/skills/docyrus-platform/references/developer-tools.md +28 -0
  73. package/resources/pi-agent/skills/docyrus-platform/references/docyrus-cli-usage.md +554 -0
  74. package/resources/pi-agent/skills/{docyrus-api-dev → docyrus-platform}/references/formula-design-guide-llm.md +15 -23
  75. package/resources/pi-agent/skills/docyrus-platform/references/integrations-and-events.md +60 -0
  76. package/resources/pi-agent/skills/docyrus-platform/references/platform-services.md +58 -0
  77. package/resources/pi-agent/skills/docyrus-platform/references/querying-and-data-operations.md +27 -0
  78. package/resources/pi-agent/prompts/coder-append-system.md +0 -19
  79. package/resources/pi-agent/skills/docyrus-ai/SKILL.md +0 -28
  80. package/resources/pi-agent/skills/docyrus-api-dev/SKILL.md +0 -161
  81. package/resources/pi-agent/skills/docyrus-api-dev/references/api-client.md +0 -349
  82. package/resources/pi-agent/skills/docyrus-api-dev/references/authentication.md +0 -238
  83. package/resources/pi-agent/skills/docyrus-api-dev/references/query-and-formulas.md +0 -592
  84. package/resources/pi-agent/skills/docyrus-api-doctor/SKILL.md +0 -70
  85. package/resources/pi-agent/skills/docyrus-api-doctor/references/checklist-details.md +0 -588
  86. package/resources/pi-agent/skills/docyrus-app-dev/SKILL.md +0 -159
  87. package/resources/pi-agent/skills/docyrus-app-dev/references/api-client-and-auth.md +0 -275
  88. package/resources/pi-agent/skills/docyrus-app-dev/references/collections-and-patterns.md +0 -352
  89. package/resources/pi-agent/skills/docyrus-app-dev/references/data-source-query-guide.md +0 -2059
  90. package/resources/pi-agent/skills/docyrus-app-dev/references/formula-design-guide-llm.md +0 -320
  91. package/resources/pi-agent/skills/docyrus-app-dev/references/query-guide.md +0 -525
  92. package/resources/pi-agent/skills/docyrus-app-ui-design/SKILL.md +0 -466
  93. package/resources/pi-agent/skills/docyrus-app-ui-design/references/component-selection-guide.md +0 -602
  94. package/resources/pi-agent/skills/docyrus-app-ui-design/references/icon-usage-guide.md +0 -463
  95. package/resources/pi-agent/skills/docyrus-app-ui-design/references/preferred-components-catalog.md +0 -242
  96. package/resources/pi-agent/skills/docyrus-apps/SKILL.md +0 -54
  97. package/resources/pi-agent/skills/docyrus-architect/SKILL.md +0 -174
  98. package/resources/pi-agent/skills/docyrus-architect/references/custom-query-guide.md +0 -410
  99. package/resources/pi-agent/skills/docyrus-architect/references/data-source-query-guide.md +0 -2059
  100. package/resources/pi-agent/skills/docyrus-architect/references/formula-design-guide-llm.md +0 -320
  101. package/resources/pi-agent/skills/docyrus-architect/references/formula-reference.md +0 -145
  102. package/resources/pi-agent/skills/docyrus-auth/SKILL.md +0 -100
  103. package/resources/pi-agent/skills/docyrus-cli-app/SKILL.md +0 -279
  104. package/resources/pi-agent/skills/docyrus-cli-app/references/cli-manifest.md +0 -532
  105. package/resources/pi-agent/skills/docyrus-cli-app/references/list-query-examples.md +0 -248
  106. package/resources/pi-agent/skills/docyrus-curl/SKILL.md +0 -32
  107. package/resources/pi-agent/skills/docyrus-discover/SKILL.md +0 -63
  108. package/resources/pi-agent/skills/docyrus-ds/SKILL.md +0 -95
  109. package/resources/pi-agent/skills/docyrus-env/SKILL.md +0 -21
  110. package/resources/pi-agent/skills/docyrus-studio/SKILL.md +0 -369
  111. package/resources/pi-agent/skills/docyrus-tui/SKILL.md +0 -15
@@ -1,159 +0,0 @@
1
- ---
2
- name: docyrus-app-dev
3
- description: Build React TypeScript web applications using Docyrus as a backend. Use when creating or modifying apps that authenticate with Docyrus OAuth2, fetch/mutate data via the @docyrus/api-client library, use auto-generated collections for CRUD operations, or build queries with filters, aggregations, formulas, pivots, and child queries against Docyrus data sources. Triggers on tasks involving @docyrus/api-client, @docyrus/signin, Docyrus collections, data source queries, or Docyrus-backed React app development.
4
- ---
5
-
6
- # Docyrus App Developer
7
-
8
- Build React TypeScript web apps with Docyrus as the backend. Authenticate via OAuth2 PKCE, query data sources with powerful filtering/aggregation, and follow established patterns.
9
-
10
- ## Tech Stack
11
-
12
- - React 19 + TypeScript + Vite
13
- - TanStack Router (code-based), TanStack Query (server state)
14
- - Tailwind CSS v4, shadcn/ui components
15
- - `@docyrus/api-client` (REST client) + `@docyrus/signin` (auth provider)
16
- - Auto-generated collections from OpenAPI spec
17
-
18
- ## Quick Start: New App Setup
19
-
20
- 1. Wrap root with `DocyrusAuthProvider`:
21
-
22
- ```tsx
23
- import { DocyrusAuthProvider } from '@docyrus/signin'
24
-
25
- <DocyrusAuthProvider
26
- apiUrl={import.meta.env.VITE_API_BASE_URL}
27
- clientId={import.meta.env.VITE_OAUTH2_CLIENT_ID}
28
- redirectUri={import.meta.env.VITE_OAUTH2_REDIRECT_URI}
29
- scopes={['offline_access', 'Read.All', 'DS.ReadWrite.All', 'Users.Read']}
30
- callbackPath="/auth/callback"
31
- >
32
- <QueryClientProvider client={queryClient}>
33
- <RouterProvider router={router} />
34
- </QueryClientProvider>
35
- </DocyrusAuthProvider>
36
- ```
37
-
38
- 2. In App.tsx, check auth and use collection hooks:
39
-
40
- ```tsx
41
- const { status } = useDocyrusAuth()
42
- const { getMyInfo } = useUsersCollection()
43
-
44
- if (status === 'loading') return <Spinner />
45
- if (status === 'unauthenticated') return <SignInButton />
46
- ```
47
-
48
- 3. Use collection hooks in components:
49
-
50
- ```tsx
51
- const { list } = useBaseProjectCollection()
52
-
53
- const { data: projects } = useQuery({
54
- queryKey: ['projects'],
55
- queryFn: () => list({
56
- columns: ['name', 'status', 'record_owner(firstname,lastname)'],
57
- filters: { rules: [{ field: 'status', operator: '!=', value: 'archived' }] },
58
- orderBy: 'created_on DESC',
59
- limit: 50,
60
- }),
61
- })
62
- ```
63
-
64
- ## Critical Rules
65
-
66
- 1. **Always send `columns`** in `.list()` and `.get()` calls. Without it, only `id` is returned.
67
- 2. **Collections are React hooks** — call `useBaseProjectCollection()`, `useUsersCollection()`, etc. inside React components. They use `useDocyrusClient()` internally for authenticated API access.
68
- 3. **Data source endpoints are dynamic** — they only exist if the data source is defined in the tenant's OpenAPI spec.
69
- 4. **Use `id` field** for `count` calculations. Use the actual field slug for `sum`, `avg`, `min`, `max`.
70
- 5. **Child query keys must appear in `columns`** — e.g., if childQuery key is `orders`, include `'orders'` in the columns array.
71
- 6. **Formula keys must appear in `columns`** — e.g., if formula key is `total`, include `'total'` in the columns array.
72
- 7. **Use `useUsersCollection().getMyInfo()`** for current user profile, not a direct API call.
73
-
74
- ## Regenerating Collections After Schema Changes
75
-
76
- When data sources or fields are created, updated, or deleted via the `docyrus-architect` MCP tools, the app's auto-generated collections become stale. To resync:
77
-
78
- 1. Call `regenerate_openapi_spec` (architect MCP) to rebuild and upload the tenant's OpenAPI spec
79
- 2. Download the new spec into the repo, overwriting the existing file:
80
- ```bash
81
- curl -o openapi.json "<publicUrl returned from step 1>"
82
- ```
83
- 3. Regenerate collections:
84
- ```bash
85
- pnpx @docyrus/tanstack-db-generator openapi.json
86
- ```
87
-
88
- Always run all three steps together — a stale `openapi.json` or outdated collections will cause missing or incorrect endpoints at runtime.
89
-
90
- ## Collection CRUD Methods
91
-
92
- Every generated collection is a React hook that returns CRUD methods:
93
-
94
- ```typescript
95
- const { list, get, create, update, delete: deleteOne, deleteMany } = useBaseProjectCollection()
96
-
97
- list(params?: ICollectionListParams) // Query with filters, sort, pagination
98
- get(id, { columns }) // Single record
99
- create(data) // Create
100
- update(id, data) // Partial update
101
- deleteOne(id) // Delete one
102
- deleteMany({ recordIds }) // Delete many
103
- ```
104
-
105
- API endpoint pattern: `/v1/apps/{appSlug}/data-sources/{slug}/items`
106
-
107
- ## Query Capabilities Summary
108
-
109
- The `.list()` method supports:
110
-
111
- | Feature | Purpose |
112
- |---------|---------|
113
- | `columns` | Select fields, expand relations `field(subfields)`, alias `alias:field`, spread `...field()` |
114
- | `filters` | Nested AND/OR groups with 50+ operators (comparison, date shortcuts, user-related) |
115
- | `filterKeyword` | Full-text search |
116
- | `orderBy` | Sort by fields with direction, including related fields |
117
- | `limit`/`offset` | Pagination (default 100) |
118
- | `fullCount` | Return total count alongside results |
119
- | `calculations` | Aggregations: count, sum, avg, min, max with grouping |
120
- | `formulas` | Computed virtual columns (simple functions, block AST, correlated subqueries) |
121
- | `childQueries` | Fetch related child records as nested JSON arrays |
122
- | `pivot` | Cross-tab matrix queries with date range series |
123
- | `expand` | Return full objects for relation/user/enum fields instead of IDs |
124
-
125
- **For query/formula details, read**:
126
- - `references/data-source-query-guide.md`
127
- - `references/formula-design-guide-llm.md`
128
-
129
- ## TanStack Query Pattern
130
-
131
- ```typescript
132
- // Query hook — call collection hook inside the component, pass methods to TanStack Query
133
- function useProjects(params?: ICollectionListParams) {
134
- const { list } = useBaseProjectCollection()
135
- return useQuery({
136
- queryKey: ['projects', 'list', params],
137
- queryFn: () => list({ columns: PROJECT_COLUMNS, ...params }),
138
- })
139
- }
140
-
141
- // Mutation hook
142
- function useCreateProject() {
143
- const { create } = useBaseProjectCollection()
144
- const qc = useQueryClient()
145
- return useMutation({
146
- mutationFn: (data: Record<string, unknown>) => create(data),
147
- onSuccess: () => { void qc.invalidateQueries({ queryKey: ['projects'] }) },
148
- })
149
- }
150
- ```
151
-
152
- ## References
153
-
154
- Read these files when you need detailed information:
155
-
156
- - **`references/api-client-and-auth.md`** — RestApiClient API, @docyrus/signin hooks, auth provider config, interceptors, error handling, SSE/streaming, file upload/download
157
- - **`references/data-source-query-guide.md`** — Up-to-date query payload guide: columns, filters, orderBy, pagination, calculations, formulas, child queries, pivots, and operator reference
158
- - **`references/formula-design-guide-llm.md`** — Up-to-date formula design guide for building and validating `formulas` payloads
159
- - **`references/collections-and-patterns.md`** — Generated collection hooks, useUsersCollection, TanStack Query/mutation hook patterns, query key factories, app bootstrap flow, routing setup, API endpoints
@@ -1,275 +0,0 @@
1
- # @docyrus/api-client & @docyrus/signin Reference
2
-
3
- ## Table of Contents
4
-
5
- 1. [RestApiClient](#restapiclient)
6
- 2. [Authentication with @docyrus/signin](#authentication-with-docyrussignin)
7
- 3. [API Client Access Pattern](#api-client-access-pattern)
8
- 4. [Interceptors](#interceptors)
9
- 5. [Error Handling](#error-handling)
10
- 6. [Advanced Features](#advanced-features)
11
-
12
- ---
13
-
14
- ## RestApiClient
15
-
16
- Type-safe REST API client from `@docyrus/api-client`.
17
-
18
- ### HTTP Methods
19
-
20
- ```typescript
21
- import { RestApiClient } from '@docyrus/api-client'
22
-
23
- client.get<T>(endpoint, params?) // GET
24
- client.post<T>(endpoint, data) // POST
25
- client.patch<T>(endpoint, data) // PATCH
26
- client.put(endpoint, data) // PUT
27
- client.delete(endpoint, data?) // DELETE
28
- ```
29
-
30
- ### Typed Responses
31
-
32
- ```typescript
33
- interface User { id: string; name: string; email: string }
34
- const response = await client.get<User[]>('/v1/users')
35
- ```
36
-
37
- ### Config Options
38
-
39
- ```typescript
40
- interface ApiClientConfig {
41
- baseURL?: string
42
- tokenManager?: TokenManager
43
- headers?: Record<string, string>
44
- timeout?: number
45
- fetch?: typeof fetch
46
- FormData?: typeof FormData
47
- AbortController?: typeof AbortController
48
- storage?: Storage
49
- }
50
- ```
51
-
52
- ---
53
-
54
- ## Authentication with @docyrus/signin
55
-
56
- Package: `@docyrus/signin` (peer dep: `@docyrus/api-client >= 0.0.10`, `react >= 18`)
57
-
58
- ### DocyrusAuthProvider Setup
59
-
60
- Wrap application root:
61
-
62
- ```tsx
63
- import { DocyrusAuthProvider } from '@docyrus/signin'
64
-
65
- <DocyrusAuthProvider
66
- apiUrl={import.meta.env.VITE_API_BASE_URL}
67
- clientId={import.meta.env.VITE_OAUTH2_CLIENT_ID}
68
- redirectUri={import.meta.env.VITE_OAUTH2_REDIRECT_URI}
69
- scopes={['offline_access', 'Read.All', 'DS.ReadWrite.All', 'Users.Read']}
70
- callbackPath="/auth/callback"
71
- >
72
- <App />
73
- </DocyrusAuthProvider>
74
- ```
75
-
76
- ### Provider Props
77
-
78
- | Prop | Type | Default | Description |
79
- |------|------|---------|-------------|
80
- | `apiUrl` | `string` | `https://alpha-api.docyrus.com` | API base URL |
81
- | `clientId` | `string` | Built-in default | OAuth2 client ID |
82
- | `redirectUri` | `string` | `origin + callbackPath` | OAuth2 redirect URI |
83
- | `scopes` | `string[]` | `['offline_access', 'Read.All', ...]` | OAuth2 scopes |
84
- | `callbackPath` | `string` | `/auth/callback` | OAuth callback route |
85
- | `forceMode` | `'standalone' \| 'iframe'` | Auto-detected | Force auth mode |
86
- | `storageKeyPrefix` | `string` | `docyrus_oauth2_` | localStorage prefix |
87
- | `allowedHostOrigins` | `string[]` | `undefined` | Extra trusted iframe origins |
88
-
89
- ### Auth Modes
90
-
91
- - **Standalone**: OAuth2 Authorization Code + PKCE via page redirect. Tokens stored in localStorage, auto-refreshed.
92
- - **Iframe**: Receives tokens via `window.postMessage` from `*.docyrus.app` hosts. Requests refresh from host when expired.
93
-
94
- ### useDocyrusAuth() Hook
95
-
96
- ```typescript
97
- const {
98
- status, // 'loading' | 'authenticated' | 'unauthenticated'
99
- mode, // 'standalone' | 'iframe'
100
- client, // RestApiClient | null
101
- tokens, // { accessToken, refreshToken, ... } | null
102
- signIn, // () => void — redirects to Docyrus login
103
- signOut, // () => void — logout and clear tokens
104
- error, // Error | null
105
- } = useDocyrusAuth()
106
- ```
107
-
108
- ### useDocyrusClient() Hook
109
-
110
- ```typescript
111
- const client = useDocyrusClient() // RestApiClient | null
112
- ```
113
-
114
- ### SignInButton Component
115
-
116
- ```tsx
117
- // Basic
118
- <SignInButton />
119
-
120
- // Styled
121
- <SignInButton className="btn" label="Log in with Docyrus" />
122
-
123
- // Render prop
124
- <SignInButton>
125
- {({ signIn, isLoading }) => (
126
- <button onClick={signIn} disabled={isLoading}>
127
- {isLoading ? 'Redirecting...' : 'Sign in'}
128
- </button>
129
- )}
130
- </SignInButton>
131
- ```
132
-
133
- ### Environment Variables (.env)
134
-
135
- ```bash
136
- VITE_API_BASE_URL=https://localhost:3366
137
- VITE_OAUTH2_CLIENT_ID=your-client-id
138
- VITE_OAUTH2_REDIRECT_URI=http://localhost:3000/auth/callback
139
- VITE_OAUTH2_SCOPES=openid profile offline_access Users.Read DS.ReadWrite.All
140
- ```
141
-
142
- ---
143
-
144
- ## API Client Access Pattern
145
-
146
- Generated collections are React hooks that use `useDocyrusClient()` internally to get the authenticated `RestApiClient` from `DocyrusAuthProvider`. No manual client syncing is needed.
147
-
148
- ```typescript
149
- // Collections get the client automatically via useDocyrusClient()
150
- function useBaseProjectCollection() {
151
- const client = useDocyrusClient()
152
- return {
153
- list: (params?) => client!.get('/v1/apps/base/data-sources/project/items', params),
154
- // ... other CRUD methods
155
- }
156
- }
157
-
158
- // In your component — just call the collection hook
159
- function ProjectList() {
160
- const { list } = useBaseProjectCollection()
161
- const { data } = useQuery({
162
- queryKey: ['projects'],
163
- queryFn: () => list({ columns: ['name', 'status'] }),
164
- })
165
- }
166
- ```
167
-
168
- For direct API access outside collections, use the `useDocyrusClient()` hook:
169
-
170
- ```typescript
171
- const client = useDocyrusClient()
172
- const data = await client!.get<MyType>('/v1/custom-endpoint')
173
- ```
174
-
175
- ---
176
-
177
- ## Interceptors
178
-
179
- Add request/response interceptors via `client.use()`:
180
-
181
- ```typescript
182
- client.use({
183
- request: (config) => {
184
- // Transform columns array to comma-separated string
185
- if (config.params?.columns && Array.isArray(config.params.columns)) {
186
- config.params.columns = config.params.columns.join(',')
187
- }
188
- return config
189
- },
190
- response: (response) => {
191
- // Unwrap nested .data property
192
- if (response.data?.data && !Array.isArray(response.data)) {
193
- response.data = response.data.data
194
- }
195
- return response
196
- },
197
- error: (error, request, response) => {
198
- if (error.status === 401) { /* handle auth error */ }
199
- return { error, request, response }
200
- },
201
- })
202
- ```
203
-
204
- ---
205
-
206
- ## Error Handling
207
-
208
- ```typescript
209
- import {
210
- ApiError, NetworkError, TimeoutError,
211
- AuthenticationError, AuthorizationError,
212
- NotFoundError, RateLimitError, ValidationError,
213
- OAuth2Error, InvalidGrantError,
214
- } from '@docyrus/api-client'
215
-
216
- try {
217
- await client.get('/resource')
218
- } catch (error) {
219
- if (error instanceof AuthenticationError) { /* 401 */ }
220
- else if (error instanceof AuthorizationError) { /* 403 */ }
221
- else if (error instanceof NotFoundError) { /* 404 */ }
222
- else if (error instanceof RateLimitError) { /* 429 - error.retryAfter */ }
223
- else if (error instanceof NetworkError) { /* network issue */ }
224
- else if (error instanceof TimeoutError) { /* timeout */ }
225
- }
226
- ```
227
-
228
- ---
229
-
230
- ## Advanced Features
231
-
232
- ### SSE (Server-Sent Events)
233
-
234
- ```typescript
235
- const eventSource = client.sse('/events', {
236
- onMessage(data) { console.log(data) },
237
- onError(error) { console.error(error) },
238
- onComplete() { console.log('done') },
239
- })
240
- eventSource.close()
241
- ```
242
-
243
- ### File Upload
244
-
245
- ```typescript
246
- const formData = new FormData()
247
- formData.append('file', fileInput.files[0])
248
- await client.post('/upload', formData)
249
- ```
250
-
251
- ### File Download
252
-
253
- ```typescript
254
- const response = await client.get('/download/file.pdf', { responseType: 'blob' })
255
- const url = URL.createObjectURL(response.data)
256
- ```
257
-
258
- ### HTML to PDF
259
-
260
- ```typescript
261
- await client.html2pdf({
262
- html: '<html><body>Content</body></html>',
263
- options: { format: 'A4', margin: { top: 10, bottom: 10 } },
264
- })
265
- ```
266
-
267
- ### Retry Logic
268
-
269
- ```typescript
270
- import { withRetry } from '@docyrus/api-client'
271
- const response = await withRetry(() => client.get('/endpoint'), {
272
- retries: 3, retryDelay: 1000,
273
- retryCondition: (error) => error.status >= 500,
274
- })
275
- ```