@aifeatures/react 0.8.0 → 0.10.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 +72 -2
- package/dist/index.cjs +2 -2
- package/dist/index.d.cts +277 -128
- package/dist/index.d.ts +277 -128
- package/dist/index.js +2 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,4 +1,74 @@
|
|
|
1
|
-
# @aifeatures/react
|
|
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
|
+
## Product reviews
|
|
42
|
+
|
|
43
|
+
The review components are part of the pending minor release after `0.9.0` (expected `0.10.0`). They are available in this workspace build; verify the published package exports before upgrading a customer site or adding imports to it.
|
|
44
|
+
|
|
45
|
+
Mount one composer on the product page, using the actual product ID:
|
|
46
|
+
|
|
47
|
+
```tsx
|
|
48
|
+
import { ProductRating, ProductReviews, ProductReviewForm } from '@aifeatures/react';
|
|
49
|
+
|
|
50
|
+
function Reviews({ productId }: { productId: string }) {
|
|
51
|
+
return <>
|
|
52
|
+
<ProductRating productId={productId} />
|
|
53
|
+
<ProductReviews productId={productId} />
|
|
54
|
+
<ProductReviewForm productId={productId} />
|
|
55
|
+
</>;
|
|
56
|
+
}
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
These components use the same optional `apiUrl` and `AifeaturesProvider` resolution as the other features. `ProductRating` is useful beside a product title; `ProductReviews` includes its own summary, distribution, filters, pagination, and merchant replies. Confirmed customer mutations refresh subscribed widgets for the same product. Public text is rendered as escaped text. No customer email or order identifiers are displayed.
|
|
60
|
+
|
|
61
|
+
Keep `AccountPage` mounted at the published `/account` route. The composer starts email sign-in; `AccountPage` exchanges the code, saves the existing same-origin customer session, and returns to the validated product route at `#product-review-form`. Account review history provides product links and withdrawal, without a second editor. Sign-in must finish on the store's canonical serving origin: apex, `www`, and secondary domains do not share browser sessions or drafts.
|
|
62
|
+
|
|
63
|
+
The server checks store readiness, site collection settings, production Turnstile keys, and the global collection switch. Pass `preview` to `ProductReviews` and `ProductReviewForm` in previews; the server also refuses preview writes. A disabled store setting pauses new reviews and resubmissions while preserving public reviews, withdrawal, and protected editing on active product pages. A global collection pause stops all content writes. A verified-purchase badge is derived from historical purchases of that exact product at that store; it is never supplied by the browser.
|
|
64
|
+
|
|
65
|
+
The composer owns its fields, JSON requests, validation, and draft recovery. Drafts are scoped to the authenticated identity and product and expire after 24 hours in the current browser. Expired or failed CAPTCHA challenges preserve the draft. An uncertain write triggers a saved-review read before another attempt; a stale revision requires the customer to review the latest state.
|
|
66
|
+
|
|
67
|
+
Only the package-internal Turnstile widget lifecycle and server verification adapter are shared with contact forms. `AifeaturesCaptcha` retains its `formId` configuration, hidden response field, consent behavior, and `/f/:formId` contracts. Reviews use `/v1/p/...` and `/v1/account/...` JSON endpoints. Future booking features can reuse the small CAPTCHA adapter while owning their own availability, capacity, reservation, calendar, and notification behavior.
|
|
68
|
+
|
|
69
|
+
See [product-review operations and release gates](../../docs/OPERATIONS.md#product-reviews--release-and-operations) before enabling collection.
|
|
70
|
+
|
|
71
|
+
## Consent runtime
|
|
2
72
|
|
|
3
73
|
`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
74
|
|
|
@@ -9,7 +79,7 @@
|
|
|
9
79
|
</ConsentProvider>
|
|
10
80
|
```
|
|
11
81
|
|
|
12
|
-
An explicit `apiUrl` still selects another base URL, including the existing public API and Storybook's mock hosts.
|
|
82
|
+
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
83
|
|
|
14
84
|
## Inspect a decision in DevTools
|
|
15
85
|
|