@aifeatures/react 0.8.0 → 0.9.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/README.md CHANGED
@@ -1,4 +1,44 @@
1
- # @aifeatures/react consent runtime
1
+ # @aifeatures/react
2
+
3
+ ## Public feature API configuration
4
+
5
+ `AifeaturesProvider` configures the public API base for forms and captcha, products, carts, checkout, order status, geo suggestions, and customer accounts:
6
+
7
+ ```tsx
8
+ import { AifeaturesProvider } from '@aifeatures/react';
9
+
10
+ <AifeaturesProvider apiUrl="/_ls">
11
+ <App />
12
+ </AifeaturesProvider>
13
+ ```
14
+
15
+ Every feature component and hook resolves its API base in this order: an explicit `apiUrl`, the nearest `AifeaturesProvider`, then `https://aifeatures.dev`. Without a provider, existing installed source keeps its platform requests after an upgrade. Adding a provider is an explicit source change; upgrading the package does not migrate forms or rewrite URLs. Relative bases remain relative during SSR and hydration; the resolver does not read `window`.
16
+
17
+ Authored form actions and `fetch` calls must use the same base as their captcha. The provider cannot rewrite an existing form action. Use `useAifeaturesApiUrl(explicitApiUrl?)` in the component that owns submission:
18
+
19
+ ```tsx
20
+ import { AifeaturesCaptcha, useAifeaturesApiUrl } from '@aifeatures/react';
21
+
22
+ function ContactForm({ formId, apiUrl: explicitApiUrl }: {
23
+ formId: string;
24
+ apiUrl?: string;
25
+ }) {
26
+ const apiUrl = useAifeaturesApiUrl(explicitApiUrl);
27
+ return (
28
+ <form action={`${apiUrl}/f/${formId}`} method="POST">
29
+ <input name="email" type="email" required />
30
+ <AifeaturesCaptcha formId={formId} apiUrl={explicitApiUrl} />
31
+ <button type="submit">Send</button>
32
+ </form>
33
+ );
34
+ }
35
+ ```
36
+
37
+ Pass base URLs without a trailing slash. `apiUrl=""` explicitly selects root API paths. Opted-in production hosts and previews must serve `/_ls` through site-services; local development needs that same trusted forwarding path. The provider changes request destinations only. Payment redirects and Turnstile's external script retain their existing behavior; a failed submission does not fall back to a different API origin.
38
+
39
+ `ConsentProvider` has independent configuration: its existing default remains `/_ls`, even without `AifeaturesProvider`, and its own explicit `apiUrl` still wins.
40
+
41
+ ## Consent runtime
2
42
 
3
43
  `ConsentProvider` requests `/_ls/v1/geo` and `/_ls/v1/prefs/{configId}` on the current site's origin by default. Published sites, shared/editor previews, and local development must serve those two paths through site-services. No hostname is needed in generated site code:
4
44
 
@@ -9,7 +49,7 @@
9
49
  </ConsentProvider>
10
50
  ```
11
51
 
12
- An explicit `apiUrl` still selects another base URL, including the existing public API and Storybook's mock hosts. Other components retain their existing defaults. Response bodies must match the consent contract, including `country`, `region`, and `shape` on geo responses. The legacy country-only geo response is invalid and causes a strict fallback. Additive response headers are diagnostic information; missing or unfamiliar versions do not override a valid body.
52
+ An explicit `apiUrl` still selects another base URL, including the existing public API and Storybook's mock hosts. Response bodies must match the consent contract, including `country`, `region`, and `shape` on geo responses. The legacy country-only geo response is invalid and causes a strict fallback. Additive response headers are diagnostic information; missing or unfamiliar versions do not override a valid body.
13
53
 
14
54
  ## Inspect a decision in DevTools
15
55