@moonbase.sh/react 1.2.1 → 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/README.md +11 -5
- package/dist/index.cjs +69 -33
- package/dist/index.d.cts +36 -11
- package/dist/index.d.ts +36 -11
- package/dist/index.js +68 -30
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -280,6 +280,11 @@ A banner that asks for Google's two consent mode signals separately can pass bot
|
|
|
280
280
|
onConsentUpdate(({ adUserData, adPersonalization }) => storefront.setAttributionConsent({ adUserData, adPersonalization }))
|
|
281
281
|
```
|
|
282
282
|
|
|
283
|
+
If your banner remembers when the visitor answered, pass that too, as ISO 8601 or a `Date`:
|
|
284
|
+
`storefront.setAttributionConsent(granted, answeredAt)`, or `attributionConsentAnsweredAt` beside `attributionConsent`.
|
|
285
|
+
Moonbase then counts the answer from when it was given rather than from each request that carries it, so an acceptance
|
|
286
|
+
a browser kept for months never outweighs a refusal the customer made since, on another device or by asking the store.
|
|
287
|
+
|
|
283
288
|
The cart, checkout, sign-up, trial, newsletter subscription and download requests also tell Moonbase what your banner
|
|
284
289
|
reported (nothing until it reports) and when and on which page (origin and path only) a tagged visit first landed.
|
|
285
290
|
Where the store connected Meta or Google Analytics in Moonbase, and the visitor's consent lets click IDs go, they also
|
|
@@ -289,15 +294,16 @@ cookies as each request is made) and the page's origin and path. `storefront.adS
|
|
|
289
294
|
or `'unknown'`). A browser that sends Global Privacy Control counts as refusing for each platform the store has not set
|
|
290
295
|
to ignore it in Moonbase: no browser IDs go for that platform, and `attributionConsentStatusByPlatform` in the state
|
|
291
296
|
says where consent stands for `meta` and `googleAnalytics` each. `attributionConsentStatus` is `'refused'` for it unless
|
|
292
|
-
the store set every platform it connected to ignore it. When your banner reports a refusal for a signed-in customer, or
|
|
293
|
-
storefront tells Moonbase, once
|
|
297
|
+
the store set every platform it connected to ignore it. When your banner reports a refusal for a signed-in customer, or
|
|
298
|
+
an acceptance with when it was given, or the browser sends Global Privacy Control, the storefront tells Moonbase, once
|
|
299
|
+
per tab.
|
|
294
300
|
|
|
295
301
|
A cookie banner of your own gets what it needs from `useAttributionConsent()`. `required` says whether the store's
|
|
296
302
|
setting asks this visitor at all: `true` or `false` once the browser has loaded the catalog for them, and `undefined`
|
|
297
303
|
until then, since a catalog fetched on a server describes where the server is. `answer` is the visitor's answer, or
|
|
298
|
-
`null` until they give one, and `setAnswer` records it. The storefront remembers the answer in the browser
|
|
299
|
-
(`moonbase_attribution_consent` in local storage) and starts from it
|
|
300
|
-
`attributionConsent` to `createStorefront`:
|
|
304
|
+
`null` until they give one, and `setAnswer` records it. The storefront remembers the answer in the browser, and when
|
|
305
|
+
it was given (`moonbase_attribution_consent` and `moonbase_attribution_consent_at` in local storage), and starts from it
|
|
306
|
+
on the next visit, unless you pass `attributionConsent` to `createStorefront`:
|
|
301
307
|
|
|
302
308
|
```tsx
|
|
303
309
|
function CookieBanner() {
|
package/dist/index.cjs
CHANGED
|
@@ -38,6 +38,7 @@ __export(index_exports, {
|
|
|
38
38
|
useCommunicationPreferences: () => useCommunicationPreferences,
|
|
39
39
|
useCurrency: () => useCurrency,
|
|
40
40
|
useEligibleOffers: () => useEligibleOffers,
|
|
41
|
+
useGift: () => useGift,
|
|
41
42
|
useGroups: () => useGroups,
|
|
42
43
|
useInventory: () => useInventory,
|
|
43
44
|
useLockedOffers: () => useLockedOffers,
|
|
@@ -66,7 +67,7 @@ module.exports = __toCommonJS(index_exports);
|
|
|
66
67
|
var import_storefront_api13 = require("@moonbase.sh/storefront-api");
|
|
67
68
|
|
|
68
69
|
// package.json
|
|
69
|
-
var version = "1.
|
|
70
|
+
var version = "1.3.0";
|
|
70
71
|
|
|
71
72
|
// src/storefront.ts
|
|
72
73
|
var import_storefront_api5 = require("@moonbase.sh/storefront-api");
|
|
@@ -649,15 +650,17 @@ var _MoonbaseStorefront = class _MoonbaseStorefront {
|
|
|
649
650
|
};
|
|
650
651
|
};
|
|
651
652
|
/**
|
|
652
|
-
* Records the visitor's answer to the site's own cookie banner: remembered in this
|
|
653
|
-
* storefront starts from it on their next visit, and passed on with `setAttributionConsent`.
|
|
654
|
-
* follow it. `useAttributionConsent` hands it out. A banner that asks for Google's two consent
|
|
655
|
-
* signals separately passes them to `setAttributionConsent` instead.
|
|
653
|
+
* Records the visitor's answer to the site's own cookie banner, and when they gave it: remembered in this
|
|
654
|
+
* browser, so the storefront starts from it on their next visit, and passed on with `setAttributionConsent`.
|
|
655
|
+
* Other tabs follow it. `useAttributionConsent` hands it out. A banner that asks for Google's two consent
|
|
656
|
+
* mode signals separately passes them to `setAttributionConsent` instead.
|
|
656
657
|
*/
|
|
657
658
|
this.answerAttributionConsent = (granted) => {
|
|
659
|
+
const answeredAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
660
|
+
(0, import_storefront_api5.writeStorage)(_MoonbaseStorefront.attributionConsentAnsweredAtKey, (0, import_storefront_api5.storedAnswerTime)(granted, answeredAt));
|
|
658
661
|
(0, import_storefront_api5.writeStorage)(_MoonbaseStorefront.attributionConsentKey, String(granted));
|
|
659
662
|
this.setState({ attributionConsentAnswer: granted });
|
|
660
|
-
this.setAttributionConsent(granted);
|
|
663
|
+
this.setAttributionConsent(granted, answeredAt);
|
|
661
664
|
};
|
|
662
665
|
var _a, _b, _c;
|
|
663
666
|
this.autoApplyItemOffers = (_a = options.autoApplyItemOffers) != null ? _a : false;
|
|
@@ -713,6 +716,7 @@ var _MoonbaseStorefront = class _MoonbaseStorefront {
|
|
|
713
716
|
fresh.adClicks = (0, import_storefront_api5.adClicksOf)(fresh);
|
|
714
717
|
const answer = _MoonbaseStorefront.parseAnswer((0, import_storefront_api5.readStorage)(_MoonbaseStorefront.attributionConsentKey));
|
|
715
718
|
this.attributionConsentSetting = (0, import_storefront_api5.copyConsent)((_c = (_b = configuration.attributionConsent) != null ? _b : answer) != null ? _c : void 0);
|
|
719
|
+
this.attributionConsentAnsweredAt = configuration.attributionConsent != null ? (0, import_storefront_api5.answeredAtOf)(configuration.attributionConsentAnsweredAt) : (0, import_storefront_api5.parseAnswerTime)((0, import_storefront_api5.readStorage)(_MoonbaseStorefront.attributionConsentAnsweredAtKey), answer);
|
|
716
720
|
const sessionRaw = (0, import_storefront_api5.readStorage)(_MoonbaseStorefront.utmKey, "session");
|
|
717
721
|
const sessionCached = _MoonbaseStorefront.parseCachedUtm(sessionRaw);
|
|
718
722
|
const cached = sessionCached != null ? sessionCached : configuration.persistUtm && this.attributionConsent ? _MoonbaseStorefront.parseCachedUtm((0, import_storefront_api5.readStorage)(_MoonbaseStorefront.utmKey, "local")) : void 0;
|
|
@@ -770,7 +774,7 @@ var _MoonbaseStorefront = class _MoonbaseStorefront {
|
|
|
770
774
|
};
|
|
771
775
|
if (this.state.catalogLoaded)
|
|
772
776
|
this.resolveCatalogLoaded();
|
|
773
|
-
void this.
|
|
777
|
+
void this.reportAdConsent();
|
|
774
778
|
if (cachedOrder) {
|
|
775
779
|
void this.refreshOrder();
|
|
776
780
|
} else if (this.hasUtmOrReferrer && this.attributionConsent) {
|
|
@@ -888,17 +892,22 @@ var _MoonbaseStorefront = class _MoonbaseStorefront {
|
|
|
888
892
|
* loads. A banner that asks for Google's two parts separately can pass `{ adUserData, adPersonalization }`,
|
|
889
893
|
* which counts as granted here when `adUserData` is.
|
|
890
894
|
*
|
|
895
|
+
* Pass `answeredAt` when the banner remembers when the visitor answered. Moonbase then counts the answer
|
|
896
|
+
* from that time, so an acceptance the browser kept never stands over a refusal the customer made since,
|
|
897
|
+
* and records a signed-in customer's acceptance on their account as well as a refusal.
|
|
898
|
+
*
|
|
891
899
|
* Granting it adds the ad click IDs the visitor arrived with in this tab (`gclid`, `fbclid` and the
|
|
892
900
|
* rest) to `utm`, and records the arrival on a new cart if there is none yet, so a visitor who leaves
|
|
893
901
|
* and comes back to buy is still put down to it. Withdrawing it drops the click IDs from `utm` and the
|
|
894
902
|
* browser's storage again. What has already been sent stays with the order.
|
|
895
903
|
*/
|
|
896
|
-
setAttributionConsent(granted) {
|
|
904
|
+
setAttributionConsent(granted, answeredAt) {
|
|
897
905
|
const before = this.attributionConsent;
|
|
898
906
|
this.attributionConsentSetting = (0, import_storefront_api5.copyConsent)(granted);
|
|
907
|
+
this.attributionConsentAnsweredAt = (0, import_storefront_api5.answeredAtOf)(answeredAt);
|
|
899
908
|
this.attributionConsentChanged(before);
|
|
900
909
|
this.setState(this.consentStatus(this.state.catalog.tracking));
|
|
901
|
-
void this.
|
|
910
|
+
void this.reportAdConsent();
|
|
902
911
|
if ((0, import_storefront_api5.grantsClickIds)(this.attributionConsentSetting) === false && typeof window !== "undefined") {
|
|
903
912
|
if (this.hasUtmOrReferrer)
|
|
904
913
|
(0, import_storefront_api5.writeStorage)(_MoonbaseStorefront.utmKey, JSON.stringify(this.state.utm), "session");
|
|
@@ -919,6 +928,7 @@ var _MoonbaseStorefront = class _MoonbaseStorefront {
|
|
|
919
928
|
const landing = (0, import_storefront_api5.hasCampaignData)(this.state.utm) ? this.landing : void 0;
|
|
920
929
|
return {
|
|
921
930
|
consent: (0, import_storefront_api5.copyConsent)(this.attributionConsentSetting),
|
|
931
|
+
...this.attributionConsentSetting !== void 0 && this.attributionConsentAnsweredAt ? { consentAnsweredAt: this.attributionConsentAnsweredAt } : {},
|
|
922
932
|
arrivedAt: landing == null ? void 0 : landing.arrivedAt,
|
|
923
933
|
landingPage: landing == null ? void 0 : landing.landingPage,
|
|
924
934
|
...this.browserIdentifiers(landing)
|
|
@@ -1062,7 +1072,7 @@ var _MoonbaseStorefront = class _MoonbaseStorefront {
|
|
|
1062
1072
|
for (const listener of [...this.listeners])
|
|
1063
1073
|
listener();
|
|
1064
1074
|
if (this.state.user !== before.user)
|
|
1065
|
-
void this.
|
|
1075
|
+
void this.reportAdConsent();
|
|
1066
1076
|
}
|
|
1067
1077
|
/**
|
|
1068
1078
|
* The server refused to renew the buyer's session: they signed out of it elsewhere, changed their
|
|
@@ -1166,22 +1176,25 @@ var _MoonbaseStorefront = class _MoonbaseStorefront {
|
|
|
1166
1176
|
};
|
|
1167
1177
|
}
|
|
1168
1178
|
/**
|
|
1169
|
-
* Tells Moonbase
|
|
1170
|
-
* and other events sent without a visit then follow
|
|
1171
|
-
*
|
|
1179
|
+
* Tells Moonbase what the site reports of a signed-in customer's choice on ad tracking, which renewals
|
|
1180
|
+
* and other events sent without a visit then follow: a refusal or Global Privacy Control always, and an
|
|
1181
|
+
* acceptance only with when the visitor gave it. Without that it would count from now, and could stand
|
|
1182
|
+
* over a refusal the customer made since. Once per tab for each customer and report, as a site's banner
|
|
1183
|
+
* often reports the same choice on every page.
|
|
1172
1184
|
*/
|
|
1173
|
-
async
|
|
1185
|
+
async reportAdConsent() {
|
|
1174
1186
|
if (typeof window === "undefined")
|
|
1175
1187
|
return;
|
|
1176
1188
|
const user = this.state.user;
|
|
1177
1189
|
const consent = this.attributionConsentSetting;
|
|
1190
|
+
const answeredAt = this.attributionConsentAnsweredAt;
|
|
1178
1191
|
const globalPrivacyControl = (0, import_storefront_api5.sendsGlobalPrivacyControl)();
|
|
1179
|
-
if (!(0, import_storefront_api5.refusesAny)(consent) && !globalPrivacyControl) {
|
|
1192
|
+
if (!(0, import_storefront_api5.refusesAny)(consent) && !globalPrivacyControl && (consent === void 0 || !answeredAt)) {
|
|
1180
1193
|
if (consent !== void 0)
|
|
1181
1194
|
(0, import_storefront_api5.removeStorage)(_MoonbaseStorefront.adConsentReportedKey, "session");
|
|
1182
1195
|
return;
|
|
1183
1196
|
}
|
|
1184
|
-
const reported = JSON.stringify({ user: user == null ? void 0 : user.id, consent, globalPrivacyControl });
|
|
1197
|
+
const reported = JSON.stringify({ user: user == null ? void 0 : user.id, consent, answeredAt, globalPrivacyControl });
|
|
1185
1198
|
if (!user || (0, import_storefront_api5.readStorage)(_MoonbaseStorefront.adConsentReportedKey, "session") === reported)
|
|
1186
1199
|
return;
|
|
1187
1200
|
(0, import_storefront_api5.writeStorage)(_MoonbaseStorefront.adConsentReportedKey, reported, "session");
|
|
@@ -1217,7 +1230,14 @@ var _MoonbaseStorefront = class _MoonbaseStorefront {
|
|
|
1217
1230
|
const answer = _MoonbaseStorefront.parseAnswer(event.newValue);
|
|
1218
1231
|
this.setState({ attributionConsentAnswer: answer });
|
|
1219
1232
|
if (answer !== null)
|
|
1220
|
-
this.setAttributionConsent(answer);
|
|
1233
|
+
this.setAttributionConsent(answer, (0, import_storefront_api5.parseAnswerTime)((0, import_storefront_api5.readStorage)(_MoonbaseStorefront.attributionConsentAnsweredAtKey), answer));
|
|
1234
|
+
break;
|
|
1235
|
+
}
|
|
1236
|
+
case _MoonbaseStorefront.attributionConsentAnsweredAtKey: {
|
|
1237
|
+
const answer = _MoonbaseStorefront.parseAnswer((0, import_storefront_api5.readStorage)(_MoonbaseStorefront.attributionConsentKey));
|
|
1238
|
+
const answeredAt = (0, import_storefront_api5.parseAnswerTime)(event.newValue, answer);
|
|
1239
|
+
if (answer !== null && answeredAt)
|
|
1240
|
+
this.setAttributionConsent(answer, answeredAt);
|
|
1221
1241
|
break;
|
|
1222
1242
|
}
|
|
1223
1243
|
case _MoonbaseStorefront.arrivalKey: {
|
|
@@ -1313,6 +1333,7 @@ _MoonbaseStorefront.utmKey = "moonbase_utm";
|
|
|
1313
1333
|
_MoonbaseStorefront.arrivalKey = "moonbase_arrival";
|
|
1314
1334
|
_MoonbaseStorefront.adConsentReportedKey = "moonbase_ad_consent_reported";
|
|
1315
1335
|
_MoonbaseStorefront.attributionConsentKey = "moonbase_attribution_consent";
|
|
1336
|
+
_MoonbaseStorefront.attributionConsentAnsweredAtKey = "moonbase_attribution_consent_at";
|
|
1316
1337
|
var MoonbaseStorefront = _MoonbaseStorefront;
|
|
1317
1338
|
|
|
1318
1339
|
// src/provider.ts
|
|
@@ -1752,7 +1773,7 @@ function useCommunicationPreferences() {
|
|
|
1752
1773
|
return (0, import_react8.useMemo)(() => {
|
|
1753
1774
|
const communications = storefront.client.communications;
|
|
1754
1775
|
return {
|
|
1755
|
-
subscribe: (input) => communications.subscribe(input, storefront.adSignals()),
|
|
1776
|
+
subscribe: (input) => communications.subscribe(input, storefront.adSignals(), storefront.hasUtmOrReferrer ? storefront.getState().utm : void 0),
|
|
1756
1777
|
confirm: (email, token) => communications.confirm(email, token),
|
|
1757
1778
|
get: (email, token) => communications.getPreferences(email, token),
|
|
1758
1779
|
update: (email, token, preferences) => communications.updatePreferences(email, token, preferences),
|
|
@@ -1761,15 +1782,29 @@ function useCommunicationPreferences() {
|
|
|
1761
1782
|
}, [storefront]);
|
|
1762
1783
|
}
|
|
1763
1784
|
|
|
1764
|
-
// src/hooks/
|
|
1785
|
+
// src/hooks/useGift.ts
|
|
1765
1786
|
var import_react9 = require("react");
|
|
1787
|
+
function useGift() {
|
|
1788
|
+
const storefront = useStorefront();
|
|
1789
|
+
return (0, import_react9.useMemo)(() => ({
|
|
1790
|
+
peek: (code) => storefront.client.gifts.peek(code),
|
|
1791
|
+
claim: async (code) => {
|
|
1792
|
+
const claimed = await storefront.client.gifts.claim(code);
|
|
1793
|
+
await storefront.refreshUser();
|
|
1794
|
+
return claimed;
|
|
1795
|
+
}
|
|
1796
|
+
}), [storefront]);
|
|
1797
|
+
}
|
|
1798
|
+
|
|
1799
|
+
// src/hooks/useGroups.ts
|
|
1800
|
+
var import_react10 = require("react");
|
|
1766
1801
|
function useGroups() {
|
|
1767
1802
|
const storefront = useStorefront();
|
|
1768
|
-
return (0,
|
|
1803
|
+
return (0, import_react10.useMemo)(() => ({ join: (groupId) => storefront.client.groups.join(groupId) }), [storefront]);
|
|
1769
1804
|
}
|
|
1770
1805
|
|
|
1771
1806
|
// src/hooks/useInventory.ts
|
|
1772
|
-
var
|
|
1807
|
+
var import_react11 = require("react");
|
|
1773
1808
|
|
|
1774
1809
|
// src/inventory.ts
|
|
1775
1810
|
var import_storefront_api10 = require("@moonbase.sh/storefront-api");
|
|
@@ -1833,14 +1868,14 @@ function createInventory(storefront) {
|
|
|
1833
1868
|
// src/hooks/useInventory.ts
|
|
1834
1869
|
function useInventory() {
|
|
1835
1870
|
const storefront = useStorefront();
|
|
1836
|
-
return (0,
|
|
1871
|
+
return (0, import_react11.useMemo)(() => createInventory(storefront), [storefront]);
|
|
1837
1872
|
}
|
|
1838
1873
|
|
|
1839
1874
|
// src/hooks/useOrders.ts
|
|
1840
|
-
var
|
|
1875
|
+
var import_react12 = require("react");
|
|
1841
1876
|
function useOrders() {
|
|
1842
1877
|
const storefront = useStorefront();
|
|
1843
|
-
return (0,
|
|
1878
|
+
return (0, import_react12.useMemo)(() => ({
|
|
1844
1879
|
getOrders: (nextUrl) => storefront.client.orders.getHistory(nextUrl),
|
|
1845
1880
|
getReceipt: (order) => storefront.client.orders.getReceipt(order.id),
|
|
1846
1881
|
downloadReceipt: async (order) => {
|
|
@@ -1859,10 +1894,10 @@ function useOrders() {
|
|
|
1859
1894
|
|
|
1860
1895
|
// src/hooks/usePrice.ts
|
|
1861
1896
|
var import_storefront_api11 = require("@moonbase.sh/storefront-api");
|
|
1862
|
-
var
|
|
1897
|
+
var import_react13 = require("react");
|
|
1863
1898
|
function usePrice(variation, format) {
|
|
1864
1899
|
const currency = useCurrency();
|
|
1865
|
-
return (0,
|
|
1900
|
+
return (0, import_react13.useMemo)(() => {
|
|
1866
1901
|
const amount = variation == null ? void 0 : variation.price[currency];
|
|
1867
1902
|
const original = (variation == null ? void 0 : variation.hasDiscount) ? variation.originalPrice[currency] : void 0;
|
|
1868
1903
|
const saving = amount !== void 0 && original !== void 0 ? Number((original - amount).toFixed(6)) : void 0;
|
|
@@ -1877,11 +1912,11 @@ function usePrice(variation, format) {
|
|
|
1877
1912
|
}
|
|
1878
1913
|
|
|
1879
1914
|
// src/hooks/useReviews.ts
|
|
1880
|
-
var
|
|
1915
|
+
var import_react14 = require("react");
|
|
1881
1916
|
function useReviews() {
|
|
1882
1917
|
const storefront = useStorefront();
|
|
1883
1918
|
const enabled = useStorefrontState((state) => !!state.catalog.reviewsEnabled);
|
|
1884
|
-
return (0,
|
|
1919
|
+
return (0, import_react14.useMemo)(() => {
|
|
1885
1920
|
const reviews = storefront.client.reviews;
|
|
1886
1921
|
return {
|
|
1887
1922
|
enabled,
|
|
@@ -1896,11 +1931,11 @@ function useReviews() {
|
|
|
1896
1931
|
}
|
|
1897
1932
|
|
|
1898
1933
|
// src/hooks/useVendor.ts
|
|
1899
|
-
var
|
|
1934
|
+
var import_react15 = require("react");
|
|
1900
1935
|
function useVendor() {
|
|
1901
1936
|
const storefront = useStorefront();
|
|
1902
|
-
const [state, setState] = (0,
|
|
1903
|
-
(0,
|
|
1937
|
+
const [state, setState] = (0, import_react15.useState)({ vendor: null, loading: true });
|
|
1938
|
+
(0, import_react15.useEffect)(() => {
|
|
1904
1939
|
let current = true;
|
|
1905
1940
|
storefront.client.vendor.get().then((vendor) => current && setState({ vendor, loading: false })).catch(() => current && setState({ vendor: null, loading: false }));
|
|
1906
1941
|
return () => {
|
|
@@ -1912,10 +1947,10 @@ function useVendor() {
|
|
|
1912
1947
|
|
|
1913
1948
|
// src/hooks/useVoucher.ts
|
|
1914
1949
|
var import_storefront_api12 = require("@moonbase.sh/storefront-api");
|
|
1915
|
-
var
|
|
1950
|
+
var import_react16 = require("react");
|
|
1916
1951
|
function useVoucher() {
|
|
1917
1952
|
const storefront = useStorefront();
|
|
1918
|
-
return (0,
|
|
1953
|
+
return (0, import_react16.useMemo)(() => {
|
|
1919
1954
|
const known = async (lookup) => {
|
|
1920
1955
|
try {
|
|
1921
1956
|
return await lookup;
|
|
@@ -1975,6 +2010,7 @@ function getStorefront(endpoint, options = {}) {
|
|
|
1975
2010
|
useCommunicationPreferences,
|
|
1976
2011
|
useCurrency,
|
|
1977
2012
|
useEligibleOffers,
|
|
2013
|
+
useGift,
|
|
1978
2014
|
useGroups,
|
|
1979
2015
|
useInventory,
|
|
1980
2016
|
useLockedOffers,
|
package/dist/index.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { User, Address, SignUpOptions, SignUpResult, CommunicationPreferences, UserAccountConfirmed, ConnectableAccountProvider, CheckoutRedirectMode, StorefrontProduct, StorefrontBundle, PricingVariation, StorefrontOffer, LineItem, MoonbaseConfiguration, Storefront, MoonbaseClient, Order, UrchinTrackingModule, OpenOrder, Money, CheckoutPaymentFailure, CompletedOrder, AdConsentReport, AdSignals, OfferConditionContext, StorefrontPromotion, OfferProgress, OwnedProduct, Activation, License, Subscription, ActivationRequest, CartTotal, SubscribeInput, CommunicationPreferencesInput, ActivationMethod, Download, SubscriptionCancellationFeedback, Page, PriceFormat, ProductReviewSort, SubmitReviewRequest, ReviewVoteDirection, Vendor, Voucher } from '@moonbase.sh/storefront-api';
|
|
1
|
+
import { User, Address, SignUpOptions, SignUpResult, CommunicationPreferences, UserAccountConfirmed, ConnectableAccountProvider, CheckoutRedirectMode, StorefrontProduct, StorefrontBundle, PricingVariation, StorefrontOffer, LineItem, MoonbaseConfiguration, Storefront, MoonbaseClient, Order, UrchinTrackingModule, OpenOrder, Money, CheckoutPaymentFailure, CompletedOrder, AdConsentReport, AdSignals, OfferConditionContext, StorefrontPromotion, OfferProgress, OwnedProduct, Activation, License, Subscription, ActivationRequest, CartTotal, SubscribeInput, CommunicationPreferencesInput, GiftClaim, ActivationMethod, Download, SubscriptionCancellationFeedback, Page, PriceFormat, ProductReviewSort, SubmitReviewRequest, ReviewVoteDirection, Vendor, Voucher } from '@moonbase.sh/storefront-api';
|
|
2
2
|
export * from '@moonbase.sh/storefront-api';
|
|
3
3
|
import { ReactNode } from 'react';
|
|
4
4
|
|
|
@@ -265,6 +265,7 @@ declare class MoonbaseStorefront {
|
|
|
265
265
|
static readonly arrivalKey = "moonbase_arrival";
|
|
266
266
|
static readonly adConsentReportedKey = "moonbase_ad_consent_reported";
|
|
267
267
|
static readonly attributionConsentKey = "moonbase_attribution_consent";
|
|
268
|
+
static readonly attributionConsentAnsweredAtKey = "moonbase_attribution_consent_at";
|
|
268
269
|
/**
|
|
269
270
|
* Whether the cart attaches eligible item-scope offers by itself. See
|
|
270
271
|
* `StorefrontOptions.autoApplyItemOffers`. Read on every cart change.
|
|
@@ -296,6 +297,8 @@ declare class MoonbaseStorefront {
|
|
|
296
297
|
private landing;
|
|
297
298
|
/** What the site said of the visitor's consent, from its cookie banner; undefined until it says. */
|
|
298
299
|
private attributionConsentSetting;
|
|
300
|
+
/** When the visitor gave that answer, where the site or this browser knows. */
|
|
301
|
+
private attributionConsentAnsweredAt;
|
|
299
302
|
/** Whether the store's own setting lets this visitor's attribution go ahead unasked, once the catalog has said. */
|
|
300
303
|
private storeAllowsAttribution;
|
|
301
304
|
private refreshOrderAbortController;
|
|
@@ -363,17 +366,21 @@ declare class MoonbaseStorefront {
|
|
|
363
366
|
* loads. A banner that asks for Google's two parts separately can pass `{ adUserData, adPersonalization }`,
|
|
364
367
|
* which counts as granted here when `adUserData` is.
|
|
365
368
|
*
|
|
369
|
+
* Pass `answeredAt` when the banner remembers when the visitor answered. Moonbase then counts the answer
|
|
370
|
+
* from that time, so an acceptance the browser kept never stands over a refusal the customer made since,
|
|
371
|
+
* and records a signed-in customer's acceptance on their account as well as a refusal.
|
|
372
|
+
*
|
|
366
373
|
* Granting it adds the ad click IDs the visitor arrived with in this tab (`gclid`, `fbclid` and the
|
|
367
374
|
* rest) to `utm`, and records the arrival on a new cart if there is none yet, so a visitor who leaves
|
|
368
375
|
* and comes back to buy is still put down to it. Withdrawing it drops the click IDs from `utm` and the
|
|
369
376
|
* browser's storage again. What has already been sent stays with the order.
|
|
370
377
|
*/
|
|
371
|
-
setAttributionConsent(granted: boolean | AdConsentReport): void;
|
|
378
|
+
setAttributionConsent(granted: boolean | AdConsentReport, answeredAt?: string | Date): void;
|
|
372
379
|
/**
|
|
373
|
-
* Records the visitor's answer to the site's own cookie banner: remembered in this
|
|
374
|
-
* storefront starts from it on their next visit, and passed on with `setAttributionConsent`.
|
|
375
|
-
* follow it. `useAttributionConsent` hands it out. A banner that asks for Google's two consent
|
|
376
|
-
* signals separately passes them to `setAttributionConsent` instead.
|
|
380
|
+
* Records the visitor's answer to the site's own cookie banner, and when they gave it: remembered in this
|
|
381
|
+
* browser, so the storefront starts from it on their next visit, and passed on with `setAttributionConsent`.
|
|
382
|
+
* Other tabs follow it. `useAttributionConsent` hands it out. A banner that asks for Google's two consent
|
|
383
|
+
* mode signals separately passes them to `setAttributionConsent` instead.
|
|
377
384
|
*/
|
|
378
385
|
readonly answerAttributionConsent: (granted: boolean) => void;
|
|
379
386
|
/**
|
|
@@ -441,11 +448,13 @@ declare class MoonbaseStorefront {
|
|
|
441
448
|
private browserIdentifiers;
|
|
442
449
|
private consentStatus;
|
|
443
450
|
/**
|
|
444
|
-
* Tells Moonbase
|
|
445
|
-
* and other events sent without a visit then follow
|
|
446
|
-
*
|
|
451
|
+
* Tells Moonbase what the site reports of a signed-in customer's choice on ad tracking, which renewals
|
|
452
|
+
* and other events sent without a visit then follow: a refusal or Global Privacy Control always, and an
|
|
453
|
+
* acceptance only with when the visitor gave it. Without that it would count from now, and could stand
|
|
454
|
+
* over a refusal the customer made since. Once per tab for each customer and report, as a site's banner
|
|
455
|
+
* often reports the same choice on every page.
|
|
447
456
|
*/
|
|
448
|
-
private
|
|
457
|
+
private reportAdConsent;
|
|
449
458
|
private handleStorageUpdate;
|
|
450
459
|
private refreshOrder;
|
|
451
460
|
private static parseAnswer;
|
|
@@ -701,6 +710,22 @@ interface Communications {
|
|
|
701
710
|
/** Newsletter sign-ups, and the preferences page an email's footer links to. */
|
|
702
711
|
declare function useCommunicationPreferences(): Communications;
|
|
703
712
|
|
|
713
|
+
interface Gift {
|
|
714
|
+
/**
|
|
715
|
+
* Who the gift is from and what it holds, for anyone with the code. Throws `NotFoundError` for a
|
|
716
|
+
* code no gift has, and `GiftUnavailableError` once it was refunded.
|
|
717
|
+
*/
|
|
718
|
+
peek: (code: string) => Promise<GiftClaim>;
|
|
719
|
+
/**
|
|
720
|
+
* Claims the gift for the signed-in customer, then reloads them, so their owned products include
|
|
721
|
+
* it. Throws `NotAuthenticatedError` when nobody is signed in, and `GiftAlreadyClaimedError` when
|
|
722
|
+
* someone else claimed it first.
|
|
723
|
+
*/
|
|
724
|
+
claim: (code: string) => Promise<GiftClaim>;
|
|
725
|
+
}
|
|
726
|
+
/** A gift someone bought for someone else, which whoever has its code can claim into their account. */
|
|
727
|
+
declare function useGift(): Gift;
|
|
728
|
+
|
|
704
729
|
interface Groups {
|
|
705
730
|
/**
|
|
706
731
|
* Joins the signed-in customer to a customer list of the store's that has been opened to sign-ups.
|
|
@@ -907,4 +932,4 @@ declare function createStorefront(endpoint: string, options?: StorefrontOptions)
|
|
|
907
932
|
*/
|
|
908
933
|
declare function getStorefront(endpoint: string, options?: StorefrontOptions): MoonbaseStorefront;
|
|
909
934
|
|
|
910
|
-
export { type AccountData, type ActivationRequestOptions, type ActivationRequestState, type AddToCartOptions, type AttributionConsent, type AttributionConsentStatus, type AttributionConsentStatusByPlatform, 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 };
|
|
935
|
+
export { type AccountData, type ActivationRequestOptions, type ActivationRequestState, type AddToCartOptions, type AttributionConsent, type AttributionConsentStatus, type AttributionConsentStatusByPlatform, type Auth, type Cart, type CartCheckoutOptions, type CartItem, type CartOfferState, type CheckoutItem, type CheckoutOptions, type CheckoutRedirectOptions, type CheckoutResult, type Communications, type Gift, 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, useGift, 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
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { User, Address, SignUpOptions, SignUpResult, CommunicationPreferences, UserAccountConfirmed, ConnectableAccountProvider, CheckoutRedirectMode, StorefrontProduct, StorefrontBundle, PricingVariation, StorefrontOffer, LineItem, MoonbaseConfiguration, Storefront, MoonbaseClient, Order, UrchinTrackingModule, OpenOrder, Money, CheckoutPaymentFailure, CompletedOrder, AdConsentReport, AdSignals, OfferConditionContext, StorefrontPromotion, OfferProgress, OwnedProduct, Activation, License, Subscription, ActivationRequest, CartTotal, SubscribeInput, CommunicationPreferencesInput, ActivationMethod, Download, SubscriptionCancellationFeedback, Page, PriceFormat, ProductReviewSort, SubmitReviewRequest, ReviewVoteDirection, Vendor, Voucher } from '@moonbase.sh/storefront-api';
|
|
1
|
+
import { User, Address, SignUpOptions, SignUpResult, CommunicationPreferences, UserAccountConfirmed, ConnectableAccountProvider, CheckoutRedirectMode, StorefrontProduct, StorefrontBundle, PricingVariation, StorefrontOffer, LineItem, MoonbaseConfiguration, Storefront, MoonbaseClient, Order, UrchinTrackingModule, OpenOrder, Money, CheckoutPaymentFailure, CompletedOrder, AdConsentReport, AdSignals, OfferConditionContext, StorefrontPromotion, OfferProgress, OwnedProduct, Activation, License, Subscription, ActivationRequest, CartTotal, SubscribeInput, CommunicationPreferencesInput, GiftClaim, ActivationMethod, Download, SubscriptionCancellationFeedback, Page, PriceFormat, ProductReviewSort, SubmitReviewRequest, ReviewVoteDirection, Vendor, Voucher } from '@moonbase.sh/storefront-api';
|
|
2
2
|
export * from '@moonbase.sh/storefront-api';
|
|
3
3
|
import { ReactNode } from 'react';
|
|
4
4
|
|
|
@@ -265,6 +265,7 @@ declare class MoonbaseStorefront {
|
|
|
265
265
|
static readonly arrivalKey = "moonbase_arrival";
|
|
266
266
|
static readonly adConsentReportedKey = "moonbase_ad_consent_reported";
|
|
267
267
|
static readonly attributionConsentKey = "moonbase_attribution_consent";
|
|
268
|
+
static readonly attributionConsentAnsweredAtKey = "moonbase_attribution_consent_at";
|
|
268
269
|
/**
|
|
269
270
|
* Whether the cart attaches eligible item-scope offers by itself. See
|
|
270
271
|
* `StorefrontOptions.autoApplyItemOffers`. Read on every cart change.
|
|
@@ -296,6 +297,8 @@ declare class MoonbaseStorefront {
|
|
|
296
297
|
private landing;
|
|
297
298
|
/** What the site said of the visitor's consent, from its cookie banner; undefined until it says. */
|
|
298
299
|
private attributionConsentSetting;
|
|
300
|
+
/** When the visitor gave that answer, where the site or this browser knows. */
|
|
301
|
+
private attributionConsentAnsweredAt;
|
|
299
302
|
/** Whether the store's own setting lets this visitor's attribution go ahead unasked, once the catalog has said. */
|
|
300
303
|
private storeAllowsAttribution;
|
|
301
304
|
private refreshOrderAbortController;
|
|
@@ -363,17 +366,21 @@ declare class MoonbaseStorefront {
|
|
|
363
366
|
* loads. A banner that asks for Google's two parts separately can pass `{ adUserData, adPersonalization }`,
|
|
364
367
|
* which counts as granted here when `adUserData` is.
|
|
365
368
|
*
|
|
369
|
+
* Pass `answeredAt` when the banner remembers when the visitor answered. Moonbase then counts the answer
|
|
370
|
+
* from that time, so an acceptance the browser kept never stands over a refusal the customer made since,
|
|
371
|
+
* and records a signed-in customer's acceptance on their account as well as a refusal.
|
|
372
|
+
*
|
|
366
373
|
* Granting it adds the ad click IDs the visitor arrived with in this tab (`gclid`, `fbclid` and the
|
|
367
374
|
* rest) to `utm`, and records the arrival on a new cart if there is none yet, so a visitor who leaves
|
|
368
375
|
* and comes back to buy is still put down to it. Withdrawing it drops the click IDs from `utm` and the
|
|
369
376
|
* browser's storage again. What has already been sent stays with the order.
|
|
370
377
|
*/
|
|
371
|
-
setAttributionConsent(granted: boolean | AdConsentReport): void;
|
|
378
|
+
setAttributionConsent(granted: boolean | AdConsentReport, answeredAt?: string | Date): void;
|
|
372
379
|
/**
|
|
373
|
-
* Records the visitor's answer to the site's own cookie banner: remembered in this
|
|
374
|
-
* storefront starts from it on their next visit, and passed on with `setAttributionConsent`.
|
|
375
|
-
* follow it. `useAttributionConsent` hands it out. A banner that asks for Google's two consent
|
|
376
|
-
* signals separately passes them to `setAttributionConsent` instead.
|
|
380
|
+
* Records the visitor's answer to the site's own cookie banner, and when they gave it: remembered in this
|
|
381
|
+
* browser, so the storefront starts from it on their next visit, and passed on with `setAttributionConsent`.
|
|
382
|
+
* Other tabs follow it. `useAttributionConsent` hands it out. A banner that asks for Google's two consent
|
|
383
|
+
* mode signals separately passes them to `setAttributionConsent` instead.
|
|
377
384
|
*/
|
|
378
385
|
readonly answerAttributionConsent: (granted: boolean) => void;
|
|
379
386
|
/**
|
|
@@ -441,11 +448,13 @@ declare class MoonbaseStorefront {
|
|
|
441
448
|
private browserIdentifiers;
|
|
442
449
|
private consentStatus;
|
|
443
450
|
/**
|
|
444
|
-
* Tells Moonbase
|
|
445
|
-
* and other events sent without a visit then follow
|
|
446
|
-
*
|
|
451
|
+
* Tells Moonbase what the site reports of a signed-in customer's choice on ad tracking, which renewals
|
|
452
|
+
* and other events sent without a visit then follow: a refusal or Global Privacy Control always, and an
|
|
453
|
+
* acceptance only with when the visitor gave it. Without that it would count from now, and could stand
|
|
454
|
+
* over a refusal the customer made since. Once per tab for each customer and report, as a site's banner
|
|
455
|
+
* often reports the same choice on every page.
|
|
447
456
|
*/
|
|
448
|
-
private
|
|
457
|
+
private reportAdConsent;
|
|
449
458
|
private handleStorageUpdate;
|
|
450
459
|
private refreshOrder;
|
|
451
460
|
private static parseAnswer;
|
|
@@ -701,6 +710,22 @@ interface Communications {
|
|
|
701
710
|
/** Newsletter sign-ups, and the preferences page an email's footer links to. */
|
|
702
711
|
declare function useCommunicationPreferences(): Communications;
|
|
703
712
|
|
|
713
|
+
interface Gift {
|
|
714
|
+
/**
|
|
715
|
+
* Who the gift is from and what it holds, for anyone with the code. Throws `NotFoundError` for a
|
|
716
|
+
* code no gift has, and `GiftUnavailableError` once it was refunded.
|
|
717
|
+
*/
|
|
718
|
+
peek: (code: string) => Promise<GiftClaim>;
|
|
719
|
+
/**
|
|
720
|
+
* Claims the gift for the signed-in customer, then reloads them, so their owned products include
|
|
721
|
+
* it. Throws `NotAuthenticatedError` when nobody is signed in, and `GiftAlreadyClaimedError` when
|
|
722
|
+
* someone else claimed it first.
|
|
723
|
+
*/
|
|
724
|
+
claim: (code: string) => Promise<GiftClaim>;
|
|
725
|
+
}
|
|
726
|
+
/** A gift someone bought for someone else, which whoever has its code can claim into their account. */
|
|
727
|
+
declare function useGift(): Gift;
|
|
728
|
+
|
|
704
729
|
interface Groups {
|
|
705
730
|
/**
|
|
706
731
|
* Joins the signed-in customer to a customer list of the store's that has been opened to sign-ups.
|
|
@@ -907,4 +932,4 @@ declare function createStorefront(endpoint: string, options?: StorefrontOptions)
|
|
|
907
932
|
*/
|
|
908
933
|
declare function getStorefront(endpoint: string, options?: StorefrontOptions): MoonbaseStorefront;
|
|
909
934
|
|
|
910
|
-
export { type AccountData, type ActivationRequestOptions, type ActivationRequestState, type AddToCartOptions, type AttributionConsent, type AttributionConsentStatus, type AttributionConsentStatusByPlatform, 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 };
|
|
935
|
+
export { type AccountData, type ActivationRequestOptions, type ActivationRequestState, type AddToCartOptions, type AttributionConsent, type AttributionConsentStatus, type AttributionConsentStatusByPlatform, type Auth, type Cart, type CartCheckoutOptions, type CartItem, type CartOfferState, type CheckoutItem, type CheckoutOptions, type CheckoutRedirectOptions, type CheckoutResult, type Communications, type Gift, 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, useGift, 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,11 +2,12 @@
|
|
|
2
2
|
import { MoonbaseClient } from "@moonbase.sh/storefront-api";
|
|
3
3
|
|
|
4
4
|
// package.json
|
|
5
|
-
var version = "1.
|
|
5
|
+
var version = "1.3.0";
|
|
6
6
|
|
|
7
7
|
// src/storefront.ts
|
|
8
8
|
import {
|
|
9
9
|
adClicksOf,
|
|
10
|
+
answeredAtOf,
|
|
10
11
|
closeCheckout as closeCheckout2,
|
|
11
12
|
copyConsent,
|
|
12
13
|
forgetPurchase as forgetPurchase3,
|
|
@@ -21,6 +22,7 @@ import {
|
|
|
21
22
|
NotAuthorizedError,
|
|
22
23
|
NotFoundError,
|
|
23
24
|
OrderStatus as OrderStatus3,
|
|
25
|
+
parseAnswerTime,
|
|
24
26
|
parseLanding,
|
|
25
27
|
parseOffSiteReferrer,
|
|
26
28
|
pruneRememberedPurchase,
|
|
@@ -35,6 +37,7 @@ import {
|
|
|
35
37
|
schemas as schemas2,
|
|
36
38
|
sendsGlobalPrivacyControl,
|
|
37
39
|
StoreClosedError,
|
|
40
|
+
storedAnswerTime,
|
|
38
41
|
TokenStore,
|
|
39
42
|
withoutClickIds,
|
|
40
43
|
withoutHandshakeParams as withoutHandshakeParams2,
|
|
@@ -654,15 +657,17 @@ var _MoonbaseStorefront = class _MoonbaseStorefront {
|
|
|
654
657
|
};
|
|
655
658
|
};
|
|
656
659
|
/**
|
|
657
|
-
* Records the visitor's answer to the site's own cookie banner: remembered in this
|
|
658
|
-
* storefront starts from it on their next visit, and passed on with `setAttributionConsent`.
|
|
659
|
-
* follow it. `useAttributionConsent` hands it out. A banner that asks for Google's two consent
|
|
660
|
-
* signals separately passes them to `setAttributionConsent` instead.
|
|
660
|
+
* Records the visitor's answer to the site's own cookie banner, and when they gave it: remembered in this
|
|
661
|
+
* browser, so the storefront starts from it on their next visit, and passed on with `setAttributionConsent`.
|
|
662
|
+
* Other tabs follow it. `useAttributionConsent` hands it out. A banner that asks for Google's two consent
|
|
663
|
+
* mode signals separately passes them to `setAttributionConsent` instead.
|
|
661
664
|
*/
|
|
662
665
|
this.answerAttributionConsent = (granted) => {
|
|
666
|
+
const answeredAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
667
|
+
writeStorage(_MoonbaseStorefront.attributionConsentAnsweredAtKey, storedAnswerTime(granted, answeredAt));
|
|
663
668
|
writeStorage(_MoonbaseStorefront.attributionConsentKey, String(granted));
|
|
664
669
|
this.setState({ attributionConsentAnswer: granted });
|
|
665
|
-
this.setAttributionConsent(granted);
|
|
670
|
+
this.setAttributionConsent(granted, answeredAt);
|
|
666
671
|
};
|
|
667
672
|
var _a, _b, _c;
|
|
668
673
|
this.autoApplyItemOffers = (_a = options.autoApplyItemOffers) != null ? _a : false;
|
|
@@ -718,6 +723,7 @@ var _MoonbaseStorefront = class _MoonbaseStorefront {
|
|
|
718
723
|
fresh.adClicks = adClicksOf(fresh);
|
|
719
724
|
const answer = _MoonbaseStorefront.parseAnswer(readStorage(_MoonbaseStorefront.attributionConsentKey));
|
|
720
725
|
this.attributionConsentSetting = copyConsent((_c = (_b = configuration.attributionConsent) != null ? _b : answer) != null ? _c : void 0);
|
|
726
|
+
this.attributionConsentAnsweredAt = configuration.attributionConsent != null ? answeredAtOf(configuration.attributionConsentAnsweredAt) : parseAnswerTime(readStorage(_MoonbaseStorefront.attributionConsentAnsweredAtKey), answer);
|
|
721
727
|
const sessionRaw = readStorage(_MoonbaseStorefront.utmKey, "session");
|
|
722
728
|
const sessionCached = _MoonbaseStorefront.parseCachedUtm(sessionRaw);
|
|
723
729
|
const cached = sessionCached != null ? sessionCached : configuration.persistUtm && this.attributionConsent ? _MoonbaseStorefront.parseCachedUtm(readStorage(_MoonbaseStorefront.utmKey, "local")) : void 0;
|
|
@@ -775,7 +781,7 @@ var _MoonbaseStorefront = class _MoonbaseStorefront {
|
|
|
775
781
|
};
|
|
776
782
|
if (this.state.catalogLoaded)
|
|
777
783
|
this.resolveCatalogLoaded();
|
|
778
|
-
void this.
|
|
784
|
+
void this.reportAdConsent();
|
|
779
785
|
if (cachedOrder) {
|
|
780
786
|
void this.refreshOrder();
|
|
781
787
|
} else if (this.hasUtmOrReferrer && this.attributionConsent) {
|
|
@@ -893,17 +899,22 @@ var _MoonbaseStorefront = class _MoonbaseStorefront {
|
|
|
893
899
|
* loads. A banner that asks for Google's two parts separately can pass `{ adUserData, adPersonalization }`,
|
|
894
900
|
* which counts as granted here when `adUserData` is.
|
|
895
901
|
*
|
|
902
|
+
* Pass `answeredAt` when the banner remembers when the visitor answered. Moonbase then counts the answer
|
|
903
|
+
* from that time, so an acceptance the browser kept never stands over a refusal the customer made since,
|
|
904
|
+
* and records a signed-in customer's acceptance on their account as well as a refusal.
|
|
905
|
+
*
|
|
896
906
|
* Granting it adds the ad click IDs the visitor arrived with in this tab (`gclid`, `fbclid` and the
|
|
897
907
|
* rest) to `utm`, and records the arrival on a new cart if there is none yet, so a visitor who leaves
|
|
898
908
|
* and comes back to buy is still put down to it. Withdrawing it drops the click IDs from `utm` and the
|
|
899
909
|
* browser's storage again. What has already been sent stays with the order.
|
|
900
910
|
*/
|
|
901
|
-
setAttributionConsent(granted) {
|
|
911
|
+
setAttributionConsent(granted, answeredAt) {
|
|
902
912
|
const before = this.attributionConsent;
|
|
903
913
|
this.attributionConsentSetting = copyConsent(granted);
|
|
914
|
+
this.attributionConsentAnsweredAt = answeredAtOf(answeredAt);
|
|
904
915
|
this.attributionConsentChanged(before);
|
|
905
916
|
this.setState(this.consentStatus(this.state.catalog.tracking));
|
|
906
|
-
void this.
|
|
917
|
+
void this.reportAdConsent();
|
|
907
918
|
if (grantsClickIds(this.attributionConsentSetting) === false && typeof window !== "undefined") {
|
|
908
919
|
if (this.hasUtmOrReferrer)
|
|
909
920
|
writeStorage(_MoonbaseStorefront.utmKey, JSON.stringify(this.state.utm), "session");
|
|
@@ -924,6 +935,7 @@ var _MoonbaseStorefront = class _MoonbaseStorefront {
|
|
|
924
935
|
const landing = hasCampaignData(this.state.utm) ? this.landing : void 0;
|
|
925
936
|
return {
|
|
926
937
|
consent: copyConsent(this.attributionConsentSetting),
|
|
938
|
+
...this.attributionConsentSetting !== void 0 && this.attributionConsentAnsweredAt ? { consentAnsweredAt: this.attributionConsentAnsweredAt } : {},
|
|
927
939
|
arrivedAt: landing == null ? void 0 : landing.arrivedAt,
|
|
928
940
|
landingPage: landing == null ? void 0 : landing.landingPage,
|
|
929
941
|
...this.browserIdentifiers(landing)
|
|
@@ -1067,7 +1079,7 @@ var _MoonbaseStorefront = class _MoonbaseStorefront {
|
|
|
1067
1079
|
for (const listener of [...this.listeners])
|
|
1068
1080
|
listener();
|
|
1069
1081
|
if (this.state.user !== before.user)
|
|
1070
|
-
void this.
|
|
1082
|
+
void this.reportAdConsent();
|
|
1071
1083
|
}
|
|
1072
1084
|
/**
|
|
1073
1085
|
* The server refused to renew the buyer's session: they signed out of it elsewhere, changed their
|
|
@@ -1171,22 +1183,25 @@ var _MoonbaseStorefront = class _MoonbaseStorefront {
|
|
|
1171
1183
|
};
|
|
1172
1184
|
}
|
|
1173
1185
|
/**
|
|
1174
|
-
* Tells Moonbase
|
|
1175
|
-
* and other events sent without a visit then follow
|
|
1176
|
-
*
|
|
1186
|
+
* Tells Moonbase what the site reports of a signed-in customer's choice on ad tracking, which renewals
|
|
1187
|
+
* and other events sent without a visit then follow: a refusal or Global Privacy Control always, and an
|
|
1188
|
+
* acceptance only with when the visitor gave it. Without that it would count from now, and could stand
|
|
1189
|
+
* over a refusal the customer made since. Once per tab for each customer and report, as a site's banner
|
|
1190
|
+
* often reports the same choice on every page.
|
|
1177
1191
|
*/
|
|
1178
|
-
async
|
|
1192
|
+
async reportAdConsent() {
|
|
1179
1193
|
if (typeof window === "undefined")
|
|
1180
1194
|
return;
|
|
1181
1195
|
const user = this.state.user;
|
|
1182
1196
|
const consent = this.attributionConsentSetting;
|
|
1197
|
+
const answeredAt = this.attributionConsentAnsweredAt;
|
|
1183
1198
|
const globalPrivacyControl = sendsGlobalPrivacyControl();
|
|
1184
|
-
if (!refusesAny(consent) && !globalPrivacyControl) {
|
|
1199
|
+
if (!refusesAny(consent) && !globalPrivacyControl && (consent === void 0 || !answeredAt)) {
|
|
1185
1200
|
if (consent !== void 0)
|
|
1186
1201
|
removeStorage(_MoonbaseStorefront.adConsentReportedKey, "session");
|
|
1187
1202
|
return;
|
|
1188
1203
|
}
|
|
1189
|
-
const reported = JSON.stringify({ user: user == null ? void 0 : user.id, consent, globalPrivacyControl });
|
|
1204
|
+
const reported = JSON.stringify({ user: user == null ? void 0 : user.id, consent, answeredAt, globalPrivacyControl });
|
|
1190
1205
|
if (!user || readStorage(_MoonbaseStorefront.adConsentReportedKey, "session") === reported)
|
|
1191
1206
|
return;
|
|
1192
1207
|
writeStorage(_MoonbaseStorefront.adConsentReportedKey, reported, "session");
|
|
@@ -1222,7 +1237,14 @@ var _MoonbaseStorefront = class _MoonbaseStorefront {
|
|
|
1222
1237
|
const answer = _MoonbaseStorefront.parseAnswer(event.newValue);
|
|
1223
1238
|
this.setState({ attributionConsentAnswer: answer });
|
|
1224
1239
|
if (answer !== null)
|
|
1225
|
-
this.setAttributionConsent(answer);
|
|
1240
|
+
this.setAttributionConsent(answer, parseAnswerTime(readStorage(_MoonbaseStorefront.attributionConsentAnsweredAtKey), answer));
|
|
1241
|
+
break;
|
|
1242
|
+
}
|
|
1243
|
+
case _MoonbaseStorefront.attributionConsentAnsweredAtKey: {
|
|
1244
|
+
const answer = _MoonbaseStorefront.parseAnswer(readStorage(_MoonbaseStorefront.attributionConsentKey));
|
|
1245
|
+
const answeredAt = parseAnswerTime(event.newValue, answer);
|
|
1246
|
+
if (answer !== null && answeredAt)
|
|
1247
|
+
this.setAttributionConsent(answer, answeredAt);
|
|
1226
1248
|
break;
|
|
1227
1249
|
}
|
|
1228
1250
|
case _MoonbaseStorefront.arrivalKey: {
|
|
@@ -1318,6 +1340,7 @@ _MoonbaseStorefront.utmKey = "moonbase_utm";
|
|
|
1318
1340
|
_MoonbaseStorefront.arrivalKey = "moonbase_arrival";
|
|
1319
1341
|
_MoonbaseStorefront.adConsentReportedKey = "moonbase_ad_consent_reported";
|
|
1320
1342
|
_MoonbaseStorefront.attributionConsentKey = "moonbase_attribution_consent";
|
|
1343
|
+
_MoonbaseStorefront.attributionConsentAnsweredAtKey = "moonbase_attribution_consent_at";
|
|
1321
1344
|
var MoonbaseStorefront = _MoonbaseStorefront;
|
|
1322
1345
|
|
|
1323
1346
|
// src/provider.ts
|
|
@@ -1757,7 +1780,7 @@ function useCommunicationPreferences() {
|
|
|
1757
1780
|
return useMemo5(() => {
|
|
1758
1781
|
const communications = storefront.client.communications;
|
|
1759
1782
|
return {
|
|
1760
|
-
subscribe: (input) => communications.subscribe(input, storefront.adSignals()),
|
|
1783
|
+
subscribe: (input) => communications.subscribe(input, storefront.adSignals(), storefront.hasUtmOrReferrer ? storefront.getState().utm : void 0),
|
|
1761
1784
|
confirm: (email, token) => communications.confirm(email, token),
|
|
1762
1785
|
get: (email, token) => communications.getPreferences(email, token),
|
|
1763
1786
|
update: (email, token, preferences) => communications.updatePreferences(email, token, preferences),
|
|
@@ -1766,15 +1789,29 @@ function useCommunicationPreferences() {
|
|
|
1766
1789
|
}, [storefront]);
|
|
1767
1790
|
}
|
|
1768
1791
|
|
|
1769
|
-
// src/hooks/
|
|
1792
|
+
// src/hooks/useGift.ts
|
|
1770
1793
|
import { useMemo as useMemo6 } from "react";
|
|
1794
|
+
function useGift() {
|
|
1795
|
+
const storefront = useStorefront();
|
|
1796
|
+
return useMemo6(() => ({
|
|
1797
|
+
peek: (code) => storefront.client.gifts.peek(code),
|
|
1798
|
+
claim: async (code) => {
|
|
1799
|
+
const claimed = await storefront.client.gifts.claim(code);
|
|
1800
|
+
await storefront.refreshUser();
|
|
1801
|
+
return claimed;
|
|
1802
|
+
}
|
|
1803
|
+
}), [storefront]);
|
|
1804
|
+
}
|
|
1805
|
+
|
|
1806
|
+
// src/hooks/useGroups.ts
|
|
1807
|
+
import { useMemo as useMemo7 } from "react";
|
|
1771
1808
|
function useGroups() {
|
|
1772
1809
|
const storefront = useStorefront();
|
|
1773
|
-
return
|
|
1810
|
+
return useMemo7(() => ({ join: (groupId) => storefront.client.groups.join(groupId) }), [storefront]);
|
|
1774
1811
|
}
|
|
1775
1812
|
|
|
1776
1813
|
// src/hooks/useInventory.ts
|
|
1777
|
-
import { useMemo as
|
|
1814
|
+
import { useMemo as useMemo8 } from "react";
|
|
1778
1815
|
|
|
1779
1816
|
// src/inventory.ts
|
|
1780
1817
|
import { mountCheckout as mountCheckout4, mountSubscription as mountSubscription2, resolveRedirect as resolveRedirect3, withPriceFormat } from "@moonbase.sh/storefront-api";
|
|
@@ -1838,14 +1875,14 @@ function createInventory(storefront) {
|
|
|
1838
1875
|
// src/hooks/useInventory.ts
|
|
1839
1876
|
function useInventory() {
|
|
1840
1877
|
const storefront = useStorefront();
|
|
1841
|
-
return
|
|
1878
|
+
return useMemo8(() => createInventory(storefront), [storefront]);
|
|
1842
1879
|
}
|
|
1843
1880
|
|
|
1844
1881
|
// src/hooks/useOrders.ts
|
|
1845
|
-
import { useMemo as
|
|
1882
|
+
import { useMemo as useMemo9 } from "react";
|
|
1846
1883
|
function useOrders() {
|
|
1847
1884
|
const storefront = useStorefront();
|
|
1848
|
-
return
|
|
1885
|
+
return useMemo9(() => ({
|
|
1849
1886
|
getOrders: (nextUrl) => storefront.client.orders.getHistory(nextUrl),
|
|
1850
1887
|
getReceipt: (order) => storefront.client.orders.getReceipt(order.id),
|
|
1851
1888
|
downloadReceipt: async (order) => {
|
|
@@ -1864,10 +1901,10 @@ function useOrders() {
|
|
|
1864
1901
|
|
|
1865
1902
|
// src/hooks/usePrice.ts
|
|
1866
1903
|
import { formatMoney } from "@moonbase.sh/storefront-api";
|
|
1867
|
-
import { useMemo as
|
|
1904
|
+
import { useMemo as useMemo10 } from "react";
|
|
1868
1905
|
function usePrice(variation, format) {
|
|
1869
1906
|
const currency = useCurrency();
|
|
1870
|
-
return
|
|
1907
|
+
return useMemo10(() => {
|
|
1871
1908
|
const amount = variation == null ? void 0 : variation.price[currency];
|
|
1872
1909
|
const original = (variation == null ? void 0 : variation.hasDiscount) ? variation.originalPrice[currency] : void 0;
|
|
1873
1910
|
const saving = amount !== void 0 && original !== void 0 ? Number((original - amount).toFixed(6)) : void 0;
|
|
@@ -1882,11 +1919,11 @@ function usePrice(variation, format) {
|
|
|
1882
1919
|
}
|
|
1883
1920
|
|
|
1884
1921
|
// src/hooks/useReviews.ts
|
|
1885
|
-
import { useMemo as
|
|
1922
|
+
import { useMemo as useMemo11 } from "react";
|
|
1886
1923
|
function useReviews() {
|
|
1887
1924
|
const storefront = useStorefront();
|
|
1888
1925
|
const enabled = useStorefrontState((state) => !!state.catalog.reviewsEnabled);
|
|
1889
|
-
return
|
|
1926
|
+
return useMemo11(() => {
|
|
1890
1927
|
const reviews = storefront.client.reviews;
|
|
1891
1928
|
return {
|
|
1892
1929
|
enabled,
|
|
@@ -1917,10 +1954,10 @@ function useVendor() {
|
|
|
1917
1954
|
|
|
1918
1955
|
// src/hooks/useVoucher.ts
|
|
1919
1956
|
import { NotFoundError as NotFoundError2 } from "@moonbase.sh/storefront-api";
|
|
1920
|
-
import { useMemo as
|
|
1957
|
+
import { useMemo as useMemo12 } from "react";
|
|
1921
1958
|
function useVoucher() {
|
|
1922
1959
|
const storefront = useStorefront();
|
|
1923
|
-
return
|
|
1960
|
+
return useMemo12(() => {
|
|
1924
1961
|
const known = async (lookup) => {
|
|
1925
1962
|
try {
|
|
1926
1963
|
return await lookup;
|
|
@@ -1979,6 +2016,7 @@ export {
|
|
|
1979
2016
|
useCommunicationPreferences,
|
|
1980
2017
|
useCurrency,
|
|
1981
2018
|
useEligibleOffers,
|
|
2019
|
+
useGift,
|
|
1982
2020
|
useGroups,
|
|
1983
2021
|
useInventory,
|
|
1984
2022
|
useLockedOffers,
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@moonbase.sh/react",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.
|
|
4
|
+
"version": "1.3.0",
|
|
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": "3.
|
|
19
|
+
"@moonbase.sh/storefront-api": "3.20.0"
|
|
20
20
|
},
|
|
21
21
|
"devDependencies": {
|
|
22
22
|
"@types/node": "^22.5.4",
|