zuplo 6.69.6 → 6.69.9

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.
@@ -0,0 +1,243 @@
1
+ ---
2
+ title: Hooks
3
+ sidebar_icon: webhook
4
+ description: Reference for the React hooks exported by Zudoku.
5
+ ---
6
+
7
+ Dev Portal exposes a set of React hooks that let you read and interact with the runtime state of your
8
+ site from custom components, MDX pages, plugins, and [slots](../configuration/slots.mdx). All hooks
9
+ are available from the `zudoku/hooks` entry point.
10
+
11
+ ```typescript
12
+ import {
13
+ useAuth,
14
+ useVerifiedEmail,
15
+ useRefreshUserProfile,
16
+ useZudoku,
17
+ useCache,
18
+ useEvent,
19
+ useExposedProps,
20
+ useTheme,
21
+ useMDXComponents,
22
+ } from "zudoku/hooks";
23
+ ```
24
+
25
+ ## `useAuth`
26
+
27
+ The `useAuth` hook is the primary way to interact with authentication in Zudoku. It returns the
28
+ current auth state along with the actions needed to sign users in and out. It works with any of the
29
+ supported [authentication providers](../configuration/authentication.md).
30
+
31
+ ```typescript
32
+ import { useAuth } from "zudoku/hooks";
33
+
34
+ const { isAuthEnabled, isAuthenticated, isPending, profile, login, logout, signup } = useAuth();
35
+ ```
36
+
37
+ ### Returned values
38
+
39
+ | Property | Type | Description |
40
+ | ----------------- | ------------------------------------------------ | -------------------------------------------------------------------------------------------------------------------------------------- |
41
+ | `isAuthEnabled` | `boolean` | `true` if an `authentication` provider is configured in `zudoku.config.ts`. When `false`, the action methods will throw if called. |
42
+ | `isAuthenticated` | `boolean` | Whether a user is currently signed in. |
43
+ | `isPending` | `boolean` | `true` while the provider is still initializing or restoring a session. Use this to render loading states and avoid flashing UI. |
44
+ | `profile` | `UserProfile \| null` | The authenticated user's profile, or `null` when signed out. See [User profile](#user-profile). |
45
+ | `providerData` | `ProviderData \| null` | Raw provider-specific data (for example the Supabase session or Firebase user). Useful when you need access to provider-only features. |
46
+ | `login` | `(options?: AuthActionOptions) => Promise<void>` | Starts the sign-in flow. Redirects back to the current page by default. |
47
+ | `logout` | `() => Promise<void>` | Signs the user out. |
48
+ | `signup` | `(options?: AuthActionOptions) => Promise<void>` | Starts the sign-up flow, if the provider supports it. Redirects back to the current page by default. |
49
+
50
+ `AuthActionOptions` accepts:
51
+
52
+ ```typescript
53
+ type AuthActionOptions = {
54
+ /** URL to redirect to after the action completes. Defaults to the current page. */
55
+ redirectTo?: string;
56
+ /** Replace the current history entry instead of pushing a new one. */
57
+ replace?: boolean;
58
+ };
59
+ ```
60
+
61
+ ### User profile
62
+
63
+ When `isAuthenticated` is `true`, `profile` is populated with the fields returned by the provider's
64
+ user info endpoint:
65
+
66
+ ```typescript
67
+ type UserProfile = {
68
+ sub: string;
69
+ email: string | undefined;
70
+ emailVerified: boolean;
71
+ name: string | undefined;
72
+ pictureUrl: string | undefined;
73
+ // Any additional claims returned by the provider
74
+ [key: string]: string | boolean | undefined;
75
+ };
76
+ ```
77
+
78
+ ### Example: sign-in button
79
+
80
+ ```tsx
81
+ import { useAuth } from "zudoku/hooks";
82
+ import { Button } from "zudoku/ui/Button.js";
83
+
84
+ export const AuthButton = () => {
85
+ const { isAuthenticated, isPending, profile, login, logout } = useAuth();
86
+
87
+ if (isPending) {
88
+ return <Button disabled>Loading…</Button>;
89
+ }
90
+
91
+ if (!isAuthenticated) {
92
+ return <Button onClick={() => login()}>Sign in</Button>;
93
+ }
94
+
95
+ return (
96
+ <div className="flex items-center gap-2">
97
+ <span>Hi, {profile?.name ?? profile?.email}</span>
98
+ <Button onClick={() => logout()}>Sign out</Button>
99
+ </div>
100
+ );
101
+ };
102
+ ```
103
+
104
+ ### Example: gating content
105
+
106
+ ```tsx
107
+ import { useAuth } from "zudoku/hooks";
108
+
109
+ export const PremiumContent = ({ children }: { children: React.ReactNode }) => {
110
+ const { isAuthenticated, isPending, login } = useAuth();
111
+
112
+ if (isPending) return null;
113
+
114
+ if (!isAuthenticated) {
115
+ return (
116
+ <button type="button" onClick={() => login({ redirectTo: window.location.href })}>
117
+ Sign in to view this content
118
+ </button>
119
+ );
120
+ }
121
+
122
+ return <>{children}</>;
123
+ };
124
+ ```
125
+
126
+ For route-level gating, prefer the declarative
127
+ [protected routes](../configuration/protected-routes.md) configuration.
128
+
129
+ ## `useVerifiedEmail`
130
+
131
+ Returns the current user's email verification state and exposes helpers to refresh it or request a
132
+ new verification email. Use this in components that show verification banners or block actions until
133
+ the user has verified their address.
134
+
135
+ ```typescript
136
+ import { useVerifiedEmail } from "zudoku/hooks";
137
+
138
+ const { email, isVerified, supportsEmailVerification, refresh, requestEmailVerification } =
139
+ useVerifiedEmail();
140
+ ```
141
+
142
+ | Property | Type | Description |
143
+ | --------------------------- | ------------------------------------------------ | -------------------------------------------------------------------------------------------------------------------------- |
144
+ | `email` | `string \| undefined` | The user's email address, if any. |
145
+ | `isVerified` | `boolean \| undefined` | Whether the provider reports the email as verified. `undefined` when no profile is available (e.g. signed out or pending). |
146
+ | `supportsEmailVerification` | `boolean` | `true` when the provider implements a `requestEmailVerification` method. |
147
+ | `refresh` | `() => void` | Re-fetch the user profile from the provider — useful after the user verifies in another tab. |
148
+ | `requestEmailVerification` | `(options?: AuthActionOptions) => Promise<void>` | Triggers the provider's "resend verification email" flow. |
149
+
150
+ The hook automatically refreshes the profile when the window regains focus so `isVerified` updates
151
+ after the user completes verification elsewhere.
152
+
153
+ ## `useRefreshUserProfile`
154
+
155
+ Low-level hook that re-fetches the authenticated user's profile from the configured provider. Most
156
+ applications do not need to call this directly — `useAuth` already invokes it, and
157
+ `useVerifiedEmail` exposes a more ergonomic `refresh()`. Reach for it when you need fine-grained
158
+ control over the underlying React Query.
159
+
160
+ ```typescript
161
+ import { useRefreshUserProfile } from "zudoku/hooks";
162
+
163
+ const { refetch, isFetching } = useRefreshUserProfile({ refetchOnWindowFocus: "always" });
164
+ ```
165
+
166
+ It returns the full
167
+ [React Query `UseQueryResult`](https://tanstack.com/query/latest/docs/framework/react/reference/useQuery).
168
+
169
+ ## `useZudoku`
170
+
171
+ Returns the global [`ZudokuContext`](../custom-plugins.md) — the object that holds navigation, auth,
172
+ plugins, the React Query client, and user-configured options. Use it when you need access to app
173
+ configuration that isn't exposed by a more specific hook.
174
+
175
+ ```typescript
176
+ import { useZudoku } from "zudoku/hooks";
177
+
178
+ const { options, navigation, queryClient, addEventListener, emitEvent } = useZudoku();
179
+ ```
180
+
181
+ Must be called inside the `ZudokuProvider` (i.e. inside any Dev Portal page or slot). Calling it outside
182
+ throws.
183
+
184
+ ## `useEvent`
185
+
186
+ Subscribes to Dev Portal events (such as navigation or authentication changes) with automatic cleanup.
187
+ See the [Events](./events.md) page for the full guide and the list of available events.
188
+
189
+ ```typescript
190
+ import { useEvent } from "zudoku/hooks";
191
+
192
+ // Access the latest event payload. When called without a callback, useEvent
193
+ // returns the event's argument tuple — destructure it to get the payload.
194
+ const [locationEvent] = useEvent("location") ?? [];
195
+
196
+ // Or transform the payload with a callback
197
+ const pathname = useEvent("location", ({ to }) => to.pathname);
198
+
199
+ // Or run a side effect only
200
+ useEvent("auth", ({ prev, next }) => {
201
+ if (!prev.isAuthenticated && next.isAuthenticated) {
202
+ trackSignIn(next.profile);
203
+ }
204
+ });
205
+ ```
206
+
207
+ ## `useExposedProps`
208
+
209
+ Convenience wrapper around React Router's hooks. Returns the props Dev Portal passes to `custom-page`
210
+ navigation entries, so you get the same shape whether you're writing a page component or a slot.
211
+
212
+ ```typescript
213
+ import { useExposedProps } from "zudoku/hooks";
214
+
215
+ const { location, navigate, params, searchParams, setSearchParams } = useExposedProps();
216
+ ```
217
+
218
+ ## `useCache`
219
+
220
+ Invalidates Zudoku's internal React Query caches. Today this supports `API_IDENTITIES`, which is
221
+ useful when you change something that affects the identities available to the API playground (for
222
+ example after a user creates a new API key).
223
+
224
+ ```typescript
225
+ import { useCache } from "zudoku/hooks";
226
+
227
+ const { invalidateCache } = useCache();
228
+
229
+ await invalidateCache("API_IDENTITIES");
230
+ ```
231
+
232
+ ## Re-exported hooks
233
+
234
+ For convenience, Dev Portal re-exports two hooks from its underlying libraries:
235
+
236
+ - `useTheme` from [`next-themes`](https://github.com/pacocoursey/next-themes#usetheme) — read or
237
+ change the active color scheme (`light`, `dark`, or `system`).
238
+ - `useMDXComponents` from [`@mdx-js/react`](https://mdxjs.com/packages/react/) — access the MDX
239
+ component mapping when rendering MDX content inside a custom component.
240
+
241
+ ```typescript
242
+ import { useMDXComponents, useTheme } from "zudoku/hooks";
243
+ ```
@@ -95,6 +95,25 @@ toc: false
95
95
  ---
96
96
  ```
97
97
 
98
+ ### `fullWidth`
99
+
100
+ Removes the table of contents sidebar and lets the page content span the full available width. When
101
+ enabled, the table of contents is still accessible via an "On this page" toggle in the page header
102
+ (unless `toc: false` is also set, in which case it is hidden entirely).
103
+
104
+ ```md
105
+ ---
106
+ fullWidth: true
107
+ ---
108
+ ```
109
+
110
+ | `fullWidth` | `toc` | Result |
111
+ | ----------- | ------- | --------------------------------------------------------------- |
112
+ | `false` | `true` | TOC shown in the sidebar (default). |
113
+ | `false` | `false` | TOC hidden; content keeps its standard width. |
114
+ | `true` | `true` | Content spans full width; TOC is available via a toggle button. |
115
+ | `true` | `false` | Content spans full width; TOC is not available at all. |
116
+
98
117
  ### `disable_pager`
99
118
 
100
119
  Controls whether the previous/next page navigation is displayed at the bottom of the page. Set to
@@ -75,6 +75,12 @@
75
75
  "enum": [1, 2],
76
76
  "x-show-example": false,
77
77
  "description": "The version of the policy."
78
+ },
79
+ "enableSuspiciousHeaderWarning": {
80
+ "type": "boolean",
81
+ "default": true,
82
+ "x-show-example": false,
83
+ "description": "When `true` (the default), emits a warning if the inbound request carries headers like `X-Serverless-Authorization` or `X-Goog-IAP-JWT-Assertion`. Forwarding those to a downstream Cloud Run typically causes a `the access token could not be verified` 401 because Cloud Run prefers `X-Serverless-Authorization` over `Authorization` for IAM checks. Set this to `false` only if you have intentionally chosen to forward those headers (e.g. the upstream service is also IAP-fronted and expects them) — the warning is otherwise a useful diagnostic signal."
78
84
  }
79
85
  }
80
86
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zuplo",
3
- "version": "6.69.6",
3
+ "version": "6.69.9",
4
4
  "type": "module",
5
5
  "description": "The programmable API Gateway",
6
6
  "author": "Zuplo, Inc.",
@@ -19,9 +19,9 @@
19
19
  "zuplo": "zuplo.js"
20
20
  },
21
21
  "dependencies": {
22
- "@zuplo/cli": "6.69.6",
23
- "@zuplo/core": "6.69.6",
24
- "@zuplo/runtime": "6.69.6",
22
+ "@zuplo/cli": "6.69.9",
23
+ "@zuplo/core": "6.69.9",
24
+ "@zuplo/runtime": "6.69.9",
25
25
  "@zuplo/test": "1.4.0"
26
26
  }
27
27
  }