@moonbase.sh/react 0.0.0-next-20261111171855 → 0.0.0-next-20261111174148
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 +17 -11
- package/dist/index.cjs +38 -3
- package/dist/index.d.cts +41 -1
- package/dist/index.d.ts +41 -1
- package/dist/index.js +37 -3
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -112,9 +112,11 @@ identity across renders, so it can go in a dependency list or to a memoized chil
|
|
|
112
112
|
with the catalog, and `hasRating(rating)` says whether there is a score worth showing yet.
|
|
113
113
|
- `useCommunicationPreferences()` - newsletter sign-ups, and the preferences page an email's footer links to.
|
|
114
114
|
- `useVendor()` - who runs the store.
|
|
115
|
+
- `useAttributionConsent()` - what a cookie banner of your own needs: whether the store asks this visitor, their
|
|
116
|
+
remembered answer, and `setAnswer`. See [Attribution and consent](#attribution-and-consent).
|
|
115
117
|
- `useStorefront()` - the storefront itself, and `useStorefrontState(state => ...)` for any part of its state
|
|
116
|
-
(`attributionConsentRequired`, `attributionConsentStatus`, `catalog`, `catalogLoaded`,
|
|
117
|
-
`userLoaded`, `utm`).
|
|
118
|
+
(`attributionConsentAnswer`, `attributionConsentRequired`, `attributionConsentStatus`, `catalog`, `catalogLoaded`,
|
|
119
|
+
`closed`, `order`, `user`, `userLoaded`, `utm`).
|
|
118
120
|
|
|
119
121
|
### Where checkout happens
|
|
120
122
|
|
|
@@ -287,28 +289,32 @@ cookies as each request is made) and the page's origin and path. `storefront.adS
|
|
|
287
289
|
or `'unknown'`). When your banner reports a refusal for a signed-in customer, the storefront tells Moonbase, once per
|
|
288
290
|
tab.
|
|
289
291
|
|
|
290
|
-
|
|
291
|
-
once the browser has loaded the catalog for them, and `undefined`
|
|
292
|
-
|
|
292
|
+
A cookie banner of your own gets what it needs from `useAttributionConsent()`. `required` says whether the store's
|
|
293
|
+
setting asks this visitor at all: `true` or `false` once the browser has loaded the catalog for them, and `undefined`
|
|
294
|
+
until then, since a catalog fetched on a server describes where the server is. `answer` is the visitor's answer, or
|
|
295
|
+
`null` until they give one, and `setAnswer` records it. The storefront remembers the answer in the browser
|
|
296
|
+
(`moonbase_attribution_consent` in local storage) and starts from it on the next visit, unless you pass
|
|
297
|
+
`attributionConsent` to `createStorefront`:
|
|
293
298
|
|
|
294
299
|
```tsx
|
|
295
300
|
function CookieBanner() {
|
|
296
|
-
const required =
|
|
297
|
-
const status = useStorefrontState(state => state.attributionConsentStatus)
|
|
298
|
-
const storefront = useStorefront()
|
|
301
|
+
const { required, answer, setAnswer } = useAttributionConsent()
|
|
299
302
|
|
|
300
|
-
if (!required ||
|
|
303
|
+
if (!required || answer !== null)
|
|
301
304
|
return null
|
|
302
305
|
|
|
303
306
|
return (
|
|
304
307
|
<div role="dialog">
|
|
305
|
-
<button onClick={() =>
|
|
306
|
-
<button onClick={() =>
|
|
308
|
+
<button onClick={() => setAnswer(true)}>Accept</button>
|
|
309
|
+
<button onClick={() => setAnswer(false)}>Decline</button>
|
|
307
310
|
</div>
|
|
308
311
|
)
|
|
309
312
|
}
|
|
310
313
|
```
|
|
311
314
|
|
|
315
|
+
A consent manager that reports on every page keeps calling `storefront.setAttributionConsent` instead, which remembers
|
|
316
|
+
nothing.
|
|
317
|
+
|
|
312
318
|
## Server rendering
|
|
313
319
|
|
|
314
320
|
`fetchCatalog(endpoint, options)` fetches the catalog on a server, as anyone sees it, for the `initialCatalog` a page's
|
package/dist/index.cjs
CHANGED
|
@@ -26,6 +26,7 @@ __export(index_exports, {
|
|
|
26
26
|
createStorefront: () => createStorefront,
|
|
27
27
|
getStorefront: () => getStorefront,
|
|
28
28
|
useActivationRequest: () => useActivationRequest,
|
|
29
|
+
useAttributionConsent: () => useAttributionConsent,
|
|
29
30
|
useAuth: () => useAuth,
|
|
30
31
|
useBundle: () => useBundle,
|
|
31
32
|
useBundles: () => useBundles,
|
|
@@ -65,7 +66,7 @@ module.exports = __toCommonJS(index_exports);
|
|
|
65
66
|
var import_storefront_api13 = require("@moonbase.sh/storefront-api");
|
|
66
67
|
|
|
67
68
|
// package.json
|
|
68
|
-
var version = "0.0.0-next-
|
|
69
|
+
var version = "0.0.0-next-20261111174148";
|
|
69
70
|
|
|
70
71
|
// src/storefront.ts
|
|
71
72
|
var import_storefront_api5 = require("@moonbase.sh/storefront-api");
|
|
@@ -647,7 +648,18 @@ var _MoonbaseStorefront = class _MoonbaseStorefront {
|
|
|
647
648
|
this.listeners.delete(listener);
|
|
648
649
|
};
|
|
649
650
|
};
|
|
650
|
-
|
|
651
|
+
/**
|
|
652
|
+
* Records the visitor's answer to the site's own cookie banner: remembered in this browser, so the
|
|
653
|
+
* storefront starts from it on their next visit, and passed on with `setAttributionConsent`. Other tabs
|
|
654
|
+
* follow it. `useAttributionConsent` hands it out. A banner that asks for Google's two consent mode
|
|
655
|
+
* signals separately passes them to `setAttributionConsent` instead.
|
|
656
|
+
*/
|
|
657
|
+
this.answerAttributionConsent = (granted) => {
|
|
658
|
+
(0, import_storefront_api5.writeStorage)(_MoonbaseStorefront.attributionConsentKey, String(granted));
|
|
659
|
+
this.setState({ attributionConsentAnswer: granted });
|
|
660
|
+
this.setAttributionConsent(granted);
|
|
661
|
+
};
|
|
662
|
+
var _a, _b, _c;
|
|
651
663
|
this.autoApplyItemOffers = (_a = options.autoApplyItemOffers) != null ? _a : false;
|
|
652
664
|
this.catalogLoadedPromise = new Promise((resolve) => this.resolveCatalogLoaded = resolve);
|
|
653
665
|
this.userLoadedPromise = new Promise((resolve) => this.resolveUserLoaded = resolve);
|
|
@@ -655,6 +667,7 @@ var _MoonbaseStorefront = class _MoonbaseStorefront {
|
|
|
655
667
|
this.cart = createCart(this, { setOrder: (order2) => this.setState({ order: order2 }) });
|
|
656
668
|
const initialCatalog = options.initialCatalog ? _MoonbaseStorefront.normalizeCatalog(options.initialCatalog) : emptyCatalog();
|
|
657
669
|
this.serverState = {
|
|
670
|
+
attributionConsentAnswer: null,
|
|
658
671
|
attributionConsentRequired: void 0,
|
|
659
672
|
attributionConsentStatus: "unknown",
|
|
660
673
|
catalog: initialCatalog,
|
|
@@ -697,7 +710,8 @@ var _MoonbaseStorefront = class _MoonbaseStorefront {
|
|
|
697
710
|
ttclid: urlParams.get("ttclid") || void 0
|
|
698
711
|
};
|
|
699
712
|
fresh.adClicks = (0, import_storefront_api5.adClicksOf)(fresh);
|
|
700
|
-
|
|
713
|
+
const answer = _MoonbaseStorefront.parseAnswer((0, import_storefront_api5.readStorage)(_MoonbaseStorefront.attributionConsentKey));
|
|
714
|
+
this.attributionConsentSetting = (0, import_storefront_api5.copyConsent)((_c = (_b = configuration.attributionConsent) != null ? _b : answer) != null ? _c : void 0);
|
|
701
715
|
const sessionRaw = (0, import_storefront_api5.readStorage)(_MoonbaseStorefront.utmKey, "session");
|
|
702
716
|
const sessionCached = _MoonbaseStorefront.parseCachedUtm(sessionRaw);
|
|
703
717
|
const cached = sessionCached != null ? sessionCached : configuration.persistUtm && this.attributionConsent ? _MoonbaseStorefront.parseCachedUtm((0, import_storefront_api5.readStorage)(_MoonbaseStorefront.utmKey, "local")) : void 0;
|
|
@@ -740,6 +754,7 @@ var _MoonbaseStorefront = class _MoonbaseStorefront {
|
|
|
740
754
|
}
|
|
741
755
|
}
|
|
742
756
|
this.state = {
|
|
757
|
+
attributionConsentAnswer: answer,
|
|
743
758
|
attributionConsentRequired: void 0,
|
|
744
759
|
attributionConsentStatus: this.consentStatus(),
|
|
745
760
|
catalog,
|
|
@@ -1189,6 +1204,13 @@ var _MoonbaseStorefront = class _MoonbaseStorefront {
|
|
|
1189
1204
|
}
|
|
1190
1205
|
break;
|
|
1191
1206
|
}
|
|
1207
|
+
case _MoonbaseStorefront.attributionConsentKey: {
|
|
1208
|
+
const answer = _MoonbaseStorefront.parseAnswer(event.newValue);
|
|
1209
|
+
this.setState({ attributionConsentAnswer: answer });
|
|
1210
|
+
if (answer !== null)
|
|
1211
|
+
this.setAttributionConsent(answer);
|
|
1212
|
+
break;
|
|
1213
|
+
}
|
|
1192
1214
|
case _MoonbaseStorefront.arrivalKey: {
|
|
1193
1215
|
const landing = (0, import_storefront_api5.parseLanding)(event.newValue);
|
|
1194
1216
|
if (landing)
|
|
@@ -1232,6 +1254,9 @@ var _MoonbaseStorefront = class _MoonbaseStorefront {
|
|
|
1232
1254
|
this.resetOrder();
|
|
1233
1255
|
}
|
|
1234
1256
|
}
|
|
1257
|
+
static parseAnswer(raw) {
|
|
1258
|
+
return raw === "true" ? true : raw === "false" ? false : null;
|
|
1259
|
+
}
|
|
1235
1260
|
static parseCachedUtm(raw) {
|
|
1236
1261
|
if (!raw)
|
|
1237
1262
|
return void 0;
|
|
@@ -1278,6 +1303,7 @@ _MoonbaseStorefront.storefrontKey = "moonbase_storefront";
|
|
|
1278
1303
|
_MoonbaseStorefront.utmKey = "moonbase_utm";
|
|
1279
1304
|
_MoonbaseStorefront.arrivalKey = "moonbase_arrival";
|
|
1280
1305
|
_MoonbaseStorefront.adConsentReportedKey = "moonbase_ad_consent_reported";
|
|
1306
|
+
_MoonbaseStorefront.attributionConsentKey = "moonbase_attribution_consent";
|
|
1281
1307
|
var MoonbaseStorefront = _MoonbaseStorefront;
|
|
1282
1308
|
|
|
1283
1309
|
// src/provider.ts
|
|
@@ -1657,6 +1683,14 @@ function useActivationRequest(token, options = {}) {
|
|
|
1657
1683
|
};
|
|
1658
1684
|
}
|
|
1659
1685
|
|
|
1686
|
+
// src/hooks/useAttributionConsent.ts
|
|
1687
|
+
function useAttributionConsent() {
|
|
1688
|
+
const storefront = useStorefront();
|
|
1689
|
+
const required = useStorefrontState((state) => state.attributionConsentRequired);
|
|
1690
|
+
const answer = useStorefrontState((state) => state.attributionConsentAnswer);
|
|
1691
|
+
return { required, answer, setAnswer: storefront.answerAttributionConsent };
|
|
1692
|
+
}
|
|
1693
|
+
|
|
1660
1694
|
// src/hooks/useAuth.ts
|
|
1661
1695
|
var import_react5 = require("react");
|
|
1662
1696
|
function useAuth() {
|
|
@@ -1920,6 +1954,7 @@ function getStorefront(endpoint, options = {}) {
|
|
|
1920
1954
|
createStorefront,
|
|
1921
1955
|
getStorefront,
|
|
1922
1956
|
useActivationRequest,
|
|
1957
|
+
useAttributionConsent,
|
|
1923
1958
|
useAuth,
|
|
1924
1959
|
useBundle,
|
|
1925
1960
|
useBundles,
|
package/dist/index.d.cts
CHANGED
|
@@ -136,6 +136,12 @@ interface StorefrontCart {
|
|
|
136
136
|
type AttributionConsentStatus = 'granted' | 'refused' | 'unknown';
|
|
137
137
|
/** Everything a storefront knows that a page draws from. Replaced, never changed in place, on every update. */
|
|
138
138
|
interface StorefrontState {
|
|
139
|
+
/**
|
|
140
|
+
* The visitor's answer to the site's cookie banner, given with `answerAttributionConsent` and
|
|
141
|
+
* remembered in this browser across visits, or `null` until they answer. The storefront starts from it
|
|
142
|
+
* when `attributionConsent` isn't passed to `createStorefront`.
|
|
143
|
+
*/
|
|
144
|
+
attributionConsentAnswer: boolean | null;
|
|
139
145
|
/**
|
|
140
146
|
* Whether the store asks this visitor to agree to marketing cookies before it keeps the ad click IDs
|
|
141
147
|
* they arrived with, as its "Ad and campaign tracking" setting in Moonbase decides for where they are.
|
|
@@ -246,6 +252,7 @@ declare class MoonbaseStorefront {
|
|
|
246
252
|
static readonly utmKey = "moonbase_utm";
|
|
247
253
|
static readonly arrivalKey = "moonbase_arrival";
|
|
248
254
|
static readonly adConsentReportedKey = "moonbase_ad_consent_reported";
|
|
255
|
+
static readonly attributionConsentKey = "moonbase_attribution_consent";
|
|
249
256
|
/**
|
|
250
257
|
* Whether the cart attaches eligible item-scope offers by itself. See
|
|
251
258
|
* `StorefrontOptions.autoApplyItemOffers`. Read on every cart change.
|
|
@@ -350,6 +357,13 @@ declare class MoonbaseStorefront {
|
|
|
350
357
|
* browser's storage again. What has already been sent stays with the order.
|
|
351
358
|
*/
|
|
352
359
|
setAttributionConsent(granted: boolean | AdConsentReport): void;
|
|
360
|
+
/**
|
|
361
|
+
* Records the visitor's answer to the site's own cookie banner: remembered in this browser, so the
|
|
362
|
+
* storefront starts from it on their next visit, and passed on with `setAttributionConsent`. Other tabs
|
|
363
|
+
* follow it. `useAttributionConsent` hands it out. A banner that asks for Google's two consent mode
|
|
364
|
+
* signals separately passes them to `setAttributionConsent` instead.
|
|
365
|
+
*/
|
|
366
|
+
readonly answerAttributionConsent: (granted: boolean) => void;
|
|
353
367
|
/**
|
|
354
368
|
* What the storefront's requests say of the visit for ad measurement, beside `utm`: what the site last
|
|
355
369
|
* reported of the visitor's consent, left out until it says, and when and on which page the visit's
|
|
@@ -421,6 +435,7 @@ declare class MoonbaseStorefront {
|
|
|
421
435
|
private reportAdConsentRefusal;
|
|
422
436
|
private handleStorageUpdate;
|
|
423
437
|
private refreshOrder;
|
|
438
|
+
private static parseAnswer;
|
|
424
439
|
private static parseCachedUtm;
|
|
425
440
|
private static parseCachedOrder;
|
|
426
441
|
/**
|
|
@@ -575,6 +590,31 @@ interface ActivationRequestOptions {
|
|
|
575
590
|
*/
|
|
576
591
|
declare function useActivationRequest(token: string | null | undefined, options?: ActivationRequestOptions): ActivationRequestState;
|
|
577
592
|
|
|
593
|
+
interface AttributionConsent {
|
|
594
|
+
/**
|
|
595
|
+
* Whether the store asks this visitor to agree to marketing cookies, as its "Ad and campaign tracking"
|
|
596
|
+
* setting decides for where they are, or `undefined` until the browser has loaded the catalog for them.
|
|
597
|
+
*/
|
|
598
|
+
required: boolean | undefined;
|
|
599
|
+
/** The visitor's answer, remembered in this browser across visits, or `null` until they answer. */
|
|
600
|
+
answer: boolean | null;
|
|
601
|
+
/** Records the visitor's answer, remembers it, and has the storefront follow it. */
|
|
602
|
+
setAnswer: (granted: boolean) => void;
|
|
603
|
+
}
|
|
604
|
+
/**
|
|
605
|
+
* What a cookie banner of the site's own needs: ask when `required` is `true` and `answer` is `null`, and
|
|
606
|
+
* hand the visitor's choice to `setAnswer`. The storefront remembers it in this browser and starts from it
|
|
607
|
+
* on their next visit, unless `attributionConsent` is passed to `createStorefront`. The banner itself is
|
|
608
|
+
* the site's.
|
|
609
|
+
*
|
|
610
|
+
* ```tsx
|
|
611
|
+
* const { required, answer, setAnswer } = useAttributionConsent()
|
|
612
|
+
* if (required && answer === null)
|
|
613
|
+
* return <Banner onAccept={() => setAnswer(true)} onDecline={() => setAnswer(false)} />
|
|
614
|
+
* ```
|
|
615
|
+
*/
|
|
616
|
+
declare function useAttributionConsent(): AttributionConsent;
|
|
617
|
+
|
|
578
618
|
interface Auth extends StorefrontAuth {
|
|
579
619
|
/** The signed-in customer, or null. */
|
|
580
620
|
user: User | null;
|
|
@@ -854,4 +894,4 @@ declare function createStorefront(endpoint: string, options?: StorefrontOptions)
|
|
|
854
894
|
*/
|
|
855
895
|
declare function getStorefront(endpoint: string, options?: StorefrontOptions): MoonbaseStorefront;
|
|
856
896
|
|
|
857
|
-
export { type AccountData, type ActivationRequestOptions, type ActivationRequestState, type AddToCartOptions, type AttributionConsentStatus, type Auth, type Cart, type CartCheckoutOptions, type CartItem, type CartOfferState, type CheckoutItem, type CheckoutOptions, type CheckoutRedirectOptions, type CheckoutResult, type Communications, type Groups, type LockedOffer, MoonbaseStorefront, type Orders, type PagedAccountData, type ProductReviews, type StorefrontAuth, type StorefrontCart, type StorefrontEvents, type StorefrontInventory, type StorefrontOptions, StorefrontProvider, type StorefrontProviderProps, type StorefrontState, type VariationPrice, type VendorState, type Vouchers, createStorefront, getStorefront, useActivationRequest, useAuth, useBundle, useBundles, useCart, useCartActions, useCartOffer, useCatalog, useCheckout, useCommunicationPreferences, useCurrency, useEligibleOffers, useGroups, useInventory, useLockedOffers, useOffer, useOffers, useOrderHistory, useOrders, useOwnedProduct, useOwnedProducts, usePrice, useProduct, useProductActivations, useProductLicenses, useProducts, usePromotions, useReviews, useStorefront, useStorefrontEvent, useStorefrontState, useSubscription, useSubscriptions, useVendor, useVoucher };
|
|
897
|
+
export { type AccountData, type ActivationRequestOptions, type ActivationRequestState, type AddToCartOptions, type AttributionConsent, type AttributionConsentStatus, type Auth, type Cart, type CartCheckoutOptions, type CartItem, type CartOfferState, type CheckoutItem, type CheckoutOptions, type CheckoutRedirectOptions, type CheckoutResult, type Communications, type Groups, type LockedOffer, MoonbaseStorefront, type Orders, type PagedAccountData, type ProductReviews, type StorefrontAuth, type StorefrontCart, type StorefrontEvents, type StorefrontInventory, type StorefrontOptions, StorefrontProvider, type StorefrontProviderProps, type StorefrontState, type VariationPrice, type VendorState, type Vouchers, createStorefront, getStorefront, useActivationRequest, useAttributionConsent, useAuth, useBundle, useBundles, useCart, useCartActions, useCartOffer, useCatalog, useCheckout, useCommunicationPreferences, useCurrency, useEligibleOffers, useGroups, useInventory, useLockedOffers, useOffer, useOffers, useOrderHistory, useOrders, useOwnedProduct, useOwnedProducts, usePrice, useProduct, useProductActivations, useProductLicenses, useProducts, usePromotions, useReviews, useStorefront, useStorefrontEvent, useStorefrontState, useSubscription, useSubscriptions, useVendor, useVoucher };
|
package/dist/index.d.ts
CHANGED
|
@@ -136,6 +136,12 @@ interface StorefrontCart {
|
|
|
136
136
|
type AttributionConsentStatus = 'granted' | 'refused' | 'unknown';
|
|
137
137
|
/** Everything a storefront knows that a page draws from. Replaced, never changed in place, on every update. */
|
|
138
138
|
interface StorefrontState {
|
|
139
|
+
/**
|
|
140
|
+
* The visitor's answer to the site's cookie banner, given with `answerAttributionConsent` and
|
|
141
|
+
* remembered in this browser across visits, or `null` until they answer. The storefront starts from it
|
|
142
|
+
* when `attributionConsent` isn't passed to `createStorefront`.
|
|
143
|
+
*/
|
|
144
|
+
attributionConsentAnswer: boolean | null;
|
|
139
145
|
/**
|
|
140
146
|
* Whether the store asks this visitor to agree to marketing cookies before it keeps the ad click IDs
|
|
141
147
|
* they arrived with, as its "Ad and campaign tracking" setting in Moonbase decides for where they are.
|
|
@@ -246,6 +252,7 @@ declare class MoonbaseStorefront {
|
|
|
246
252
|
static readonly utmKey = "moonbase_utm";
|
|
247
253
|
static readonly arrivalKey = "moonbase_arrival";
|
|
248
254
|
static readonly adConsentReportedKey = "moonbase_ad_consent_reported";
|
|
255
|
+
static readonly attributionConsentKey = "moonbase_attribution_consent";
|
|
249
256
|
/**
|
|
250
257
|
* Whether the cart attaches eligible item-scope offers by itself. See
|
|
251
258
|
* `StorefrontOptions.autoApplyItemOffers`. Read on every cart change.
|
|
@@ -350,6 +357,13 @@ declare class MoonbaseStorefront {
|
|
|
350
357
|
* browser's storage again. What has already been sent stays with the order.
|
|
351
358
|
*/
|
|
352
359
|
setAttributionConsent(granted: boolean | AdConsentReport): void;
|
|
360
|
+
/**
|
|
361
|
+
* Records the visitor's answer to the site's own cookie banner: remembered in this browser, so the
|
|
362
|
+
* storefront starts from it on their next visit, and passed on with `setAttributionConsent`. Other tabs
|
|
363
|
+
* follow it. `useAttributionConsent` hands it out. A banner that asks for Google's two consent mode
|
|
364
|
+
* signals separately passes them to `setAttributionConsent` instead.
|
|
365
|
+
*/
|
|
366
|
+
readonly answerAttributionConsent: (granted: boolean) => void;
|
|
353
367
|
/**
|
|
354
368
|
* What the storefront's requests say of the visit for ad measurement, beside `utm`: what the site last
|
|
355
369
|
* reported of the visitor's consent, left out until it says, and when and on which page the visit's
|
|
@@ -421,6 +435,7 @@ declare class MoonbaseStorefront {
|
|
|
421
435
|
private reportAdConsentRefusal;
|
|
422
436
|
private handleStorageUpdate;
|
|
423
437
|
private refreshOrder;
|
|
438
|
+
private static parseAnswer;
|
|
424
439
|
private static parseCachedUtm;
|
|
425
440
|
private static parseCachedOrder;
|
|
426
441
|
/**
|
|
@@ -575,6 +590,31 @@ interface ActivationRequestOptions {
|
|
|
575
590
|
*/
|
|
576
591
|
declare function useActivationRequest(token: string | null | undefined, options?: ActivationRequestOptions): ActivationRequestState;
|
|
577
592
|
|
|
593
|
+
interface AttributionConsent {
|
|
594
|
+
/**
|
|
595
|
+
* Whether the store asks this visitor to agree to marketing cookies, as its "Ad and campaign tracking"
|
|
596
|
+
* setting decides for where they are, or `undefined` until the browser has loaded the catalog for them.
|
|
597
|
+
*/
|
|
598
|
+
required: boolean | undefined;
|
|
599
|
+
/** The visitor's answer, remembered in this browser across visits, or `null` until they answer. */
|
|
600
|
+
answer: boolean | null;
|
|
601
|
+
/** Records the visitor's answer, remembers it, and has the storefront follow it. */
|
|
602
|
+
setAnswer: (granted: boolean) => void;
|
|
603
|
+
}
|
|
604
|
+
/**
|
|
605
|
+
* What a cookie banner of the site's own needs: ask when `required` is `true` and `answer` is `null`, and
|
|
606
|
+
* hand the visitor's choice to `setAnswer`. The storefront remembers it in this browser and starts from it
|
|
607
|
+
* on their next visit, unless `attributionConsent` is passed to `createStorefront`. The banner itself is
|
|
608
|
+
* the site's.
|
|
609
|
+
*
|
|
610
|
+
* ```tsx
|
|
611
|
+
* const { required, answer, setAnswer } = useAttributionConsent()
|
|
612
|
+
* if (required && answer === null)
|
|
613
|
+
* return <Banner onAccept={() => setAnswer(true)} onDecline={() => setAnswer(false)} />
|
|
614
|
+
* ```
|
|
615
|
+
*/
|
|
616
|
+
declare function useAttributionConsent(): AttributionConsent;
|
|
617
|
+
|
|
578
618
|
interface Auth extends StorefrontAuth {
|
|
579
619
|
/** The signed-in customer, or null. */
|
|
580
620
|
user: User | null;
|
|
@@ -854,4 +894,4 @@ declare function createStorefront(endpoint: string, options?: StorefrontOptions)
|
|
|
854
894
|
*/
|
|
855
895
|
declare function getStorefront(endpoint: string, options?: StorefrontOptions): MoonbaseStorefront;
|
|
856
896
|
|
|
857
|
-
export { type AccountData, type ActivationRequestOptions, type ActivationRequestState, type AddToCartOptions, type AttributionConsentStatus, type Auth, type Cart, type CartCheckoutOptions, type CartItem, type CartOfferState, type CheckoutItem, type CheckoutOptions, type CheckoutRedirectOptions, type CheckoutResult, type Communications, type Groups, type LockedOffer, MoonbaseStorefront, type Orders, type PagedAccountData, type ProductReviews, type StorefrontAuth, type StorefrontCart, type StorefrontEvents, type StorefrontInventory, type StorefrontOptions, StorefrontProvider, type StorefrontProviderProps, type StorefrontState, type VariationPrice, type VendorState, type Vouchers, createStorefront, getStorefront, useActivationRequest, useAuth, useBundle, useBundles, useCart, useCartActions, useCartOffer, useCatalog, useCheckout, useCommunicationPreferences, useCurrency, useEligibleOffers, useGroups, useInventory, useLockedOffers, useOffer, useOffers, useOrderHistory, useOrders, useOwnedProduct, useOwnedProducts, usePrice, useProduct, useProductActivations, useProductLicenses, useProducts, usePromotions, useReviews, useStorefront, useStorefrontEvent, useStorefrontState, useSubscription, useSubscriptions, useVendor, useVoucher };
|
|
897
|
+
export { type AccountData, type ActivationRequestOptions, type ActivationRequestState, type AddToCartOptions, type AttributionConsent, type AttributionConsentStatus, type Auth, type Cart, type CartCheckoutOptions, type CartItem, type CartOfferState, type CheckoutItem, type CheckoutOptions, type CheckoutRedirectOptions, type CheckoutResult, type Communications, type Groups, type LockedOffer, MoonbaseStorefront, type Orders, type PagedAccountData, type ProductReviews, type StorefrontAuth, type StorefrontCart, type StorefrontEvents, type StorefrontInventory, type StorefrontOptions, StorefrontProvider, type StorefrontProviderProps, type StorefrontState, type VariationPrice, type VendorState, type Vouchers, createStorefront, getStorefront, useActivationRequest, useAttributionConsent, useAuth, useBundle, useBundles, useCart, useCartActions, useCartOffer, useCatalog, useCheckout, useCommunicationPreferences, useCurrency, useEligibleOffers, useGroups, useInventory, useLockedOffers, useOffer, useOffers, useOrderHistory, useOrders, useOwnedProduct, useOwnedProducts, usePrice, useProduct, useProductActivations, useProductLicenses, useProducts, usePromotions, useReviews, useStorefront, useStorefrontEvent, useStorefrontState, useSubscription, useSubscriptions, useVendor, useVoucher };
|
package/dist/index.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { MoonbaseClient } from "@moonbase.sh/storefront-api";
|
|
3
3
|
|
|
4
4
|
// package.json
|
|
5
|
-
var version = "0.0.0-next-
|
|
5
|
+
var version = "0.0.0-next-20261111174148";
|
|
6
6
|
|
|
7
7
|
// src/storefront.ts
|
|
8
8
|
import {
|
|
@@ -651,7 +651,18 @@ var _MoonbaseStorefront = class _MoonbaseStorefront {
|
|
|
651
651
|
this.listeners.delete(listener);
|
|
652
652
|
};
|
|
653
653
|
};
|
|
654
|
-
|
|
654
|
+
/**
|
|
655
|
+
* Records the visitor's answer to the site's own cookie banner: remembered in this browser, so the
|
|
656
|
+
* storefront starts from it on their next visit, and passed on with `setAttributionConsent`. Other tabs
|
|
657
|
+
* follow it. `useAttributionConsent` hands it out. A banner that asks for Google's two consent mode
|
|
658
|
+
* signals separately passes them to `setAttributionConsent` instead.
|
|
659
|
+
*/
|
|
660
|
+
this.answerAttributionConsent = (granted) => {
|
|
661
|
+
writeStorage(_MoonbaseStorefront.attributionConsentKey, String(granted));
|
|
662
|
+
this.setState({ attributionConsentAnswer: granted });
|
|
663
|
+
this.setAttributionConsent(granted);
|
|
664
|
+
};
|
|
665
|
+
var _a, _b, _c;
|
|
655
666
|
this.autoApplyItemOffers = (_a = options.autoApplyItemOffers) != null ? _a : false;
|
|
656
667
|
this.catalogLoadedPromise = new Promise((resolve) => this.resolveCatalogLoaded = resolve);
|
|
657
668
|
this.userLoadedPromise = new Promise((resolve) => this.resolveUserLoaded = resolve);
|
|
@@ -659,6 +670,7 @@ var _MoonbaseStorefront = class _MoonbaseStorefront {
|
|
|
659
670
|
this.cart = createCart(this, { setOrder: (order2) => this.setState({ order: order2 }) });
|
|
660
671
|
const initialCatalog = options.initialCatalog ? _MoonbaseStorefront.normalizeCatalog(options.initialCatalog) : emptyCatalog();
|
|
661
672
|
this.serverState = {
|
|
673
|
+
attributionConsentAnswer: null,
|
|
662
674
|
attributionConsentRequired: void 0,
|
|
663
675
|
attributionConsentStatus: "unknown",
|
|
664
676
|
catalog: initialCatalog,
|
|
@@ -701,7 +713,8 @@ var _MoonbaseStorefront = class _MoonbaseStorefront {
|
|
|
701
713
|
ttclid: urlParams.get("ttclid") || void 0
|
|
702
714
|
};
|
|
703
715
|
fresh.adClicks = adClicksOf(fresh);
|
|
704
|
-
|
|
716
|
+
const answer = _MoonbaseStorefront.parseAnswer(readStorage(_MoonbaseStorefront.attributionConsentKey));
|
|
717
|
+
this.attributionConsentSetting = copyConsent((_c = (_b = configuration.attributionConsent) != null ? _b : answer) != null ? _c : void 0);
|
|
705
718
|
const sessionRaw = readStorage(_MoonbaseStorefront.utmKey, "session");
|
|
706
719
|
const sessionCached = _MoonbaseStorefront.parseCachedUtm(sessionRaw);
|
|
707
720
|
const cached = sessionCached != null ? sessionCached : configuration.persistUtm && this.attributionConsent ? _MoonbaseStorefront.parseCachedUtm(readStorage(_MoonbaseStorefront.utmKey, "local")) : void 0;
|
|
@@ -744,6 +757,7 @@ var _MoonbaseStorefront = class _MoonbaseStorefront {
|
|
|
744
757
|
}
|
|
745
758
|
}
|
|
746
759
|
this.state = {
|
|
760
|
+
attributionConsentAnswer: answer,
|
|
747
761
|
attributionConsentRequired: void 0,
|
|
748
762
|
attributionConsentStatus: this.consentStatus(),
|
|
749
763
|
catalog,
|
|
@@ -1193,6 +1207,13 @@ var _MoonbaseStorefront = class _MoonbaseStorefront {
|
|
|
1193
1207
|
}
|
|
1194
1208
|
break;
|
|
1195
1209
|
}
|
|
1210
|
+
case _MoonbaseStorefront.attributionConsentKey: {
|
|
1211
|
+
const answer = _MoonbaseStorefront.parseAnswer(event.newValue);
|
|
1212
|
+
this.setState({ attributionConsentAnswer: answer });
|
|
1213
|
+
if (answer !== null)
|
|
1214
|
+
this.setAttributionConsent(answer);
|
|
1215
|
+
break;
|
|
1216
|
+
}
|
|
1196
1217
|
case _MoonbaseStorefront.arrivalKey: {
|
|
1197
1218
|
const landing = parseLanding(event.newValue);
|
|
1198
1219
|
if (landing)
|
|
@@ -1236,6 +1257,9 @@ var _MoonbaseStorefront = class _MoonbaseStorefront {
|
|
|
1236
1257
|
this.resetOrder();
|
|
1237
1258
|
}
|
|
1238
1259
|
}
|
|
1260
|
+
static parseAnswer(raw) {
|
|
1261
|
+
return raw === "true" ? true : raw === "false" ? false : null;
|
|
1262
|
+
}
|
|
1239
1263
|
static parseCachedUtm(raw) {
|
|
1240
1264
|
if (!raw)
|
|
1241
1265
|
return void 0;
|
|
@@ -1282,6 +1306,7 @@ _MoonbaseStorefront.storefrontKey = "moonbase_storefront";
|
|
|
1282
1306
|
_MoonbaseStorefront.utmKey = "moonbase_utm";
|
|
1283
1307
|
_MoonbaseStorefront.arrivalKey = "moonbase_arrival";
|
|
1284
1308
|
_MoonbaseStorefront.adConsentReportedKey = "moonbase_ad_consent_reported";
|
|
1309
|
+
_MoonbaseStorefront.attributionConsentKey = "moonbase_attribution_consent";
|
|
1285
1310
|
var MoonbaseStorefront = _MoonbaseStorefront;
|
|
1286
1311
|
|
|
1287
1312
|
// src/provider.ts
|
|
@@ -1661,6 +1686,14 @@ function useActivationRequest(token, options = {}) {
|
|
|
1661
1686
|
};
|
|
1662
1687
|
}
|
|
1663
1688
|
|
|
1689
|
+
// src/hooks/useAttributionConsent.ts
|
|
1690
|
+
function useAttributionConsent() {
|
|
1691
|
+
const storefront = useStorefront();
|
|
1692
|
+
const required = useStorefrontState((state) => state.attributionConsentRequired);
|
|
1693
|
+
const answer = useStorefrontState((state) => state.attributionConsentAnswer);
|
|
1694
|
+
return { required, answer, setAnswer: storefront.answerAttributionConsent };
|
|
1695
|
+
}
|
|
1696
|
+
|
|
1664
1697
|
// src/hooks/useAuth.ts
|
|
1665
1698
|
import { useMemo as useMemo3 } from "react";
|
|
1666
1699
|
function useAuth() {
|
|
@@ -1923,6 +1956,7 @@ export {
|
|
|
1923
1956
|
createStorefront,
|
|
1924
1957
|
getStorefront,
|
|
1925
1958
|
useActivationRequest,
|
|
1959
|
+
useAttributionConsent,
|
|
1926
1960
|
useAuth,
|
|
1927
1961
|
useBundle,
|
|
1928
1962
|
useBundles,
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@moonbase.sh/react",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.0.0-next-
|
|
4
|
+
"version": "0.0.0-next-20261111174148",
|
|
5
5
|
"description": "Package to let you build React storefronts with Moonbase.sh as payment and delivery provider",
|
|
6
6
|
"author": "Tobias Lønnerød Madsen <m@dsen.tv>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
"react": ">=18"
|
|
17
17
|
},
|
|
18
18
|
"dependencies": {
|
|
19
|
-
"@moonbase.sh/storefront-api": "0.0.0-next-
|
|
19
|
+
"@moonbase.sh/storefront-api": "0.0.0-next-20261111174148"
|
|
20
20
|
},
|
|
21
21
|
"devDependencies": {
|
|
22
22
|
"@types/node": "^22.5.4",
|