@scaleway/cookie-consent
Advanced tools
Comparing version 1.2.2 to 1.2.3
# @scaleway/cookie-consent | ||
## 1.2.3 | ||
### Patch Changes | ||
- [#1946](https://github.com/scaleway/scaleway-lib/pull/1946) [`65e62ec`](https://github.com/scaleway/scaleway-lib/commit/65e62ec0de2aacc22db09debded47bcbd0cd4eb1) Thanks [@philibea](https://github.com/philibea)! - Fix issue with initialization on save content doens't load segment on first render. | ||
## 1.2.2 | ||
@@ -4,0 +10,0 @@ |
@@ -1,143 +0,151 @@ | ||
import { jsx as H } from "react/jsx-runtime"; | ||
import C from "cookie"; | ||
import { createContext as K, useContext as j, useState as z, useMemo as s, useEffect as G, useCallback as X } from "react"; | ||
import { uniq as S } from "../helpers/array.js"; | ||
import { stringToHash as x } from "../helpers/misc.js"; | ||
import { isCategoryKind as D } from "./helpers.js"; | ||
import { useSegmentIntegrations as L } from "./useSegmentIntegrations.js"; | ||
const $ = "_scw_rgpd", O = `${$}_hash`, V = 13 * 30 * 24 * 60 * 60, F = 6 * 30 * 24 * 60 * 60, P = { | ||
import { jsx as x } from "react/jsx-runtime"; | ||
import d from "cookie"; | ||
import { createContext as z, useContext as G, useState as $, useMemo as s, useEffect as X, useCallback as D } from "react"; | ||
import { uniq as _ } from "../helpers/array.js"; | ||
import { stringToHash as L } from "../helpers/misc.js"; | ||
import { isCategoryKind as P } from "./helpers.js"; | ||
import { useSegmentIntegrations as V } from "./useSegmentIntegrations.js"; | ||
const b = "_scw_rgpd", p = `${b}_hash`, F = 13 * 30 * 24 * 60 * 60, B = 6 * 30 * 24 * 60 * 60, J = { | ||
sameSite: "strict", | ||
secure: !0, | ||
path: "/" | ||
}, A = K(void 0), Z = () => { | ||
const a = j(A); | ||
if (a === void 0) | ||
}, y = z(void 0), q = () => { | ||
const m = G(y); | ||
if (m === void 0) | ||
throw new Error( | ||
"useCookieConsent must be used within a CookieConsentProvider" | ||
); | ||
return a; | ||
}, w = () => C.parse(document.cookie), R = ({ | ||
children: a, | ||
isConsentRequired: e, | ||
essentialIntegrations: m, | ||
config: T, | ||
cookiePrefix: c = $, | ||
consentMaxAge: _ = V, | ||
consentAdvertisingMaxAge: d = F, | ||
cookiesOptions: i = P | ||
return m; | ||
}, oo = ({ | ||
children: m, | ||
isConsentRequired: n, | ||
essentialIntegrations: i, | ||
config: H, | ||
cookiePrefix: g = b, | ||
consentMaxAge: E = F, | ||
consentAdvertisingMaxAge: l = B, | ||
cookiesOptions: u = J | ||
}) => { | ||
const [g, f] = z(!1), { | ||
const [r, k] = $(!1), [C, N] = $( | ||
d.parse(document.cookie) | ||
), { | ||
integrations: o, | ||
isLoaded: p | ||
} = L(T), E = s( | ||
() => S([ | ||
isLoaded: v | ||
} = V(H), I = s( | ||
() => _([ | ||
...o ?? [], | ||
...m.map((t) => ({ | ||
name: t, | ||
...i.map((e) => ({ | ||
name: e, | ||
category: "essential" | ||
})) | ||
]), | ||
[o, m] | ||
), u = s( | ||
() => x( | ||
S([ | ||
...(o ?? []).map(({ name: t }) => t), | ||
...m | ||
[o, i] | ||
), a = s( | ||
() => L( | ||
_([ | ||
...(o ?? []).map(({ name: e }) => e), | ||
...i | ||
]).sort().join(void 0) | ||
), | ||
[o, m] | ||
[o, i] | ||
); | ||
G(() => { | ||
f( | ||
e && w()[O] !== u.toString() && o !== void 0 | ||
X(() => { | ||
k( | ||
n && C[p] !== a.toString() && o !== void 0 | ||
); | ||
}, [e, u, o]); | ||
const N = s( | ||
() => S((o ?? []).map(({ category: t }) => t)).sort( | ||
}, [n, a, o, C]); | ||
const h = s( | ||
() => _((o ?? []).map(({ category: e }) => e)).sort( | ||
void 0 | ||
), | ||
[o] | ||
), r = s( | ||
() => N.reduce( | ||
(t, n) => ({ | ||
...t, | ||
[n]: e ? w()[`${c}_${n}`] === "true" : !0 | ||
), c = s( | ||
() => h.reduce( | ||
(e, t) => ({ | ||
...e, | ||
[t]: n || r ? C[`${g}_${t}`] === "true" : !0 | ||
}), | ||
{} | ||
), | ||
[e, N, c] | ||
), v = X( | ||
(t) => { | ||
for (const [n, k] of Object.entries( | ||
t | ||
[n, h, g, r, C] | ||
), O = D( | ||
(e) => { | ||
for (const [t, S] of Object.entries( | ||
e | ||
)) { | ||
const l = D(n) ? n : "unknown", y = `${c}_${l}`; | ||
k ? document.cookie = C.serialize( | ||
`${c}_${l}`, | ||
k.toString(), | ||
const T = P(t) ? t : "unknown", f = `${g}_${T}`; | ||
S ? document.cookie = d.serialize( | ||
f, | ||
S.toString(), | ||
{ | ||
...i, | ||
maxAge: l === "advertising" ? d : _ | ||
...u, | ||
maxAge: T === "advertising" ? l : E | ||
} | ||
) : document.cookie = C.serialize(y, "", { | ||
...i, | ||
) : document.cookie = d.serialize(f, "", { | ||
...u, | ||
expires: /* @__PURE__ */ new Date(0) | ||
}); | ||
}), N((j) => ({ | ||
...j, | ||
[f]: S ? "true" : "false" | ||
})); | ||
} | ||
document.cookie = C.serialize( | ||
O, | ||
u.toString(), | ||
document.cookie = d.serialize( | ||
p, | ||
a.toString(), | ||
{ | ||
...i, | ||
...u, | ||
// Here we use the shortest max age to force to ask again for expired consent | ||
maxAge: d | ||
maxAge: l | ||
} | ||
), f(!1); | ||
), N((t) => ({ | ||
...t, | ||
[p]: a.toString() | ||
})), k(!1); | ||
}, | ||
[ | ||
u, | ||
d, | ||
_, | ||
c, | ||
i | ||
a, | ||
l, | ||
E, | ||
g, | ||
u | ||
] | ||
), I = s( | ||
() => e ? !g && !!o?.some( | ||
(t) => r[t.category] | ||
), w = s( | ||
() => n ? !r && !!o?.some( | ||
(e) => c[e.category] | ||
) : !0, | ||
[e, o, r, g] | ||
), h = s( | ||
() => o?.length === 0 ? { All: !e } : (o ?? []).reduce( | ||
(t, n) => ({ | ||
...t, | ||
[n.name]: r[n.category] ?? !1 | ||
[n, o, c, r] | ||
), A = s( | ||
() => o?.length === 0 ? { All: !n } : (o ?? []).reduce( | ||
(e, t) => ({ | ||
...e, | ||
[t.name]: c[t.category] ?? !1 | ||
}), | ||
{} | ||
), | ||
[r, e, o] | ||
), b = s( | ||
[c, n, o] | ||
), K = s( | ||
() => ({ | ||
integrations: E, | ||
needConsent: g, | ||
isSegmentAllowed: I, | ||
isSegmentIntegrationsLoaded: p, | ||
segmentIntegrations: h, | ||
categoriesConsent: r, | ||
saveConsent: v | ||
integrations: I, | ||
needConsent: r, | ||
isSegmentAllowed: w, | ||
isSegmentIntegrationsLoaded: v, | ||
segmentIntegrations: A, | ||
categoriesConsent: c, | ||
saveConsent: O | ||
}), | ||
[ | ||
E, | ||
g, | ||
I, | ||
p, | ||
h, | ||
r, | ||
v | ||
w, | ||
v, | ||
A, | ||
c, | ||
O | ||
] | ||
); | ||
return /* @__PURE__ */ H(A.Provider, { value: b, children: a }); | ||
return /* @__PURE__ */ x(y.Provider, { value: K, children: m }); | ||
}; | ||
export { | ||
R as CookieConsentProvider, | ||
Z as useCookieConsent | ||
oo as CookieConsentProvider, | ||
q as useCookieConsent | ||
}; |
{ | ||
"name": "@scaleway/cookie-consent", | ||
"version": "1.2.2", | ||
"version": "1.2.3", | ||
"description": "React provider to handle website end user consent cookie storage based on segment integrations", | ||
@@ -5,0 +5,0 @@ "type": "module", |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
22310
354
1