@autobusal/providers 1.2.12 → 1.3.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.
package/CHANGELOG.md CHANGED
@@ -4,6 +4,18 @@ All notable changes to `@autobusal/providers` are documented here. This project
4
4
  adheres to [Keep a Changelog](https://keepachangelog.com/en/1.1.0/) and
5
5
  [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6
6
 
7
+ ## [1.3.0] - 2026-07-25
8
+
9
+ ### Changed
10
+
11
+ - **Captcha is now a runtime, per-label setting.** `Recaptcha.tsx` reads the
12
+ label's captcha config (provider + public site key) from `/api/settings/get`
13
+ via `useGetSettings()` and mounts `GoogleReCaptchaProvider` ONLY when the
14
+ provider is `recaptcha` (build-time `VITE_RECAPTCHA_KEY` remains as a
15
+ fallback). Cloudflare Turnstile needs no app-level provider. Because the
16
+ component now needs the query client, it moved INSIDE `<Queries>` in
17
+ `Providers.tsx`. `SettingsData`/`LabelSettings` types gained `captcha`.
18
+
7
19
  ## [1.2.12] - 2026-07-24
8
20
 
9
21
  ### Fixed
package/Providers.tsx CHANGED
@@ -20,9 +20,13 @@ const Providers = ({ type, loading, children }: Props): JSX.Element => (
20
20
  // the initial settings fetch). The QueryClient in <Queries> is created at
21
21
  // module scope, so remounting this subtree while suspended keeps the same
22
22
  // client and cache - no refetch loop.
23
+ // Edited: Ferjolt Ozuni - Date: 2026-07-25
24
+ // Recaptcha moved INSIDE Queries: it now reads the label's runtime captcha
25
+ // settings via useGetSettings(), which needs the QueryClientProvider (and
26
+ // suspends into the outer boundary on a cold cache, like Styles/Setup).
23
27
  <Suspense fallback={ loading }>
24
- <Recaptcha>
25
- <Queries>
28
+ <Queries>
29
+ <Recaptcha>
26
30
  <Styles>
27
31
  <Notifications>
28
32
  <Setup type={ type }>
@@ -32,8 +36,8 @@ const Providers = ({ type, loading, children }: Props): JSX.Element => (
32
36
  </Setup>
33
37
  </Notifications>
34
38
  </Styles>
35
- </Queries>
36
- </Recaptcha>
39
+ </Recaptcha>
40
+ </Queries>
37
41
  </Suspense>
38
42
  );
39
43
 
@@ -1,13 +1,36 @@
1
1
  import { GoogleReCaptchaProvider } from 'react-google-recaptcha-v3';
2
+ import { useGetSettings } from '../services';
2
3
 
3
4
  interface Props {
4
5
  children: JSX.Element
5
6
  }
6
7
 
7
- const Recaptcha = ({ children }: Props): JSX.Element => (
8
- <GoogleReCaptchaProvider reCaptchaKey={ import.meta.env.VITE_RECAPTCHA_KEY }>
9
- { children }
10
- </GoogleReCaptchaProvider>
11
- );
8
+ // Edited: Ferjolt Ozuni - Date: 2026-07-25
9
+ // The captcha provider + site key are now the label's runtime settings
10
+ // (/api/settings/get, managed at /admin/label?type=captcha) instead of the
11
+ // build-time VITE_RECAPTCHA_KEY - which stays only as a fallback for labels
12
+ // without a captcha config yet. The Google provider script is mounted ONLY
13
+ // when reCAPTCHA is the active provider; Cloudflare Turnstile needs no
14
+ // app-wide provider (its script is loaded on demand by useRecaptcha in
15
+ // @autobusal/hooks). NB: this component now calls useGetSettings(), so it
16
+ // must sit INSIDE <Queries> (see Providers.tsx).
17
+ const Recaptcha = ({ children }: Props): JSX.Element => {
18
+ const { data } = useGetSettings();
12
19
 
13
- export default Recaptcha;
20
+ const provider = data?.captcha?.provider
21
+ ?? (import.meta.env.VITE_RECAPTCHA_KEY ? 'recaptcha' : 'none');
22
+
23
+ const siteKey = data?.captcha?.site_key ?? import.meta.env.VITE_RECAPTCHA_KEY;
24
+
25
+ if (provider !== 'recaptcha' || !siteKey) {
26
+ return children;
27
+ }
28
+
29
+ return (
30
+ <GoogleReCaptchaProvider reCaptchaKey={ siteKey }>
31
+ { children }
32
+ </GoogleReCaptchaProvider>
33
+ );
34
+ };
35
+
36
+ export default Recaptcha;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@autobusal/providers",
3
- "version": "1.2.12",
3
+ "version": "1.3.0",
4
4
  "author": "Ferjolt Ozuni",
5
5
  "type": "module",
6
6
  "main": "index.ts"
package/types/settings.ts CHANGED
@@ -1,6 +1,14 @@
1
1
  export interface SettingsData {
2
2
  url: string
3
3
 
4
+ // Edited: Ferjolt Ozuni - Date: 2026-07-25
5
+ // Runtime captcha config (provider + PUBLIC site key) from
6
+ // /api/settings/get - replaces the build-time VITE_RECAPTCHA_KEY.
7
+ captcha?: {
8
+ provider: 'none' | 'recaptcha' | 'turnstile'
9
+ site_key: string | null
10
+ }
11
+
4
12
  preferences: {
5
13
  company: string
6
14
 
@@ -122,6 +130,21 @@ export interface LabelSettings {
122
130
  client_secret: string
123
131
  }
124
132
  }
133
+
134
+ // Edited: Ferjolt Ozuni - Date: 2026-07-25
135
+ // Admin-managed captcha configuration; a single provider field makes
136
+ // reCAPTCHA and Turnstile mutually exclusive.
137
+ captcha?: {
138
+ provider: 'none' | 'recaptcha' | 'turnstile'
139
+ recaptcha: {
140
+ site_key?: string
141
+ secret_key?: string
142
+ }
143
+ turnstile: {
144
+ site_key?: string
145
+ secret_key?: string
146
+ }
147
+ }
125
148
  }
126
149
 
127
150
  // Edited: Ferjolt Ozuni - Date: 2026-07-18