Derive consent mode from geolocation, not banner config

The consent mode is now determined dynamically by the visitor's
country and its applicable regulation. The configured consent_mode
column is dropped from cookie_banners and added to
cookie_consent_records to persist the geo-derived mode at
consent-recording time. When no regulation matches, the default
is OPT_OUT.

Signed-off-by: Émile Ré <emile@getprobo.com>
This commit is contained in:
Émile Ré
2026-05-13 12:17:34 +04:00
parent e9d786c5d6
commit e739473bcd
30 changed files with 68 additions and 246 deletions

View File

@@ -440,7 +440,6 @@ func (r *mutationResolver) CreateCookieBanner(ctx context.Context, input types.C
PrivacyPolicyURL: input.PrivacyPolicyURL,
CookiePolicyURL: input.CookiePolicyURL,
ConsentExpiryDays: input.ConsentExpiryDays,
ConsentMode: input.ConsentMode,
},
)
if err != nil {
@@ -476,7 +475,6 @@ func (r *mutationResolver) UpdateCookieBanner(ctx context.Context, input types.U
PrivacyPolicyURL: input.PrivacyPolicyURL,
CookiePolicyURL: input.CookiePolicyURL,
ConsentExpiryDays: input.ConsentExpiryDays,
ConsentMode: input.ConsentMode,
DefaultLanguage: input.DefaultLanguage,
},
)

View File

@@ -120,7 +120,6 @@ type CookieBanner implements Node {
privacyPolicyUrl: String
cookiePolicyUrl: String!
consentExpiryDays: Int!
consentMode: CookieConsentMode!
showBranding: Boolean!
defaultLanguage: String!
@@ -528,7 +527,6 @@ input CreateCookieBannerInput {
privacyPolicyUrl: String
cookiePolicyUrl: String!
consentExpiryDays: Int!
consentMode: CookieConsentMode!
}
input UpdateCookieBannerInput {
@@ -537,7 +535,6 @@ input UpdateCookieBannerInput {
privacyPolicyUrl: String
cookiePolicyUrl: String
consentExpiryDays: Int
consentMode: CookieConsentMode
defaultLanguage: String
}

View File

@@ -72,7 +72,6 @@ func NewCookieBanner(b *coredata.CookieBanner) *CookieBanner {
PrivacyPolicyURL: b.PrivacyPolicyURL,
CookiePolicyURL: b.CookiePolicyURL,
ConsentExpiryDays: b.ConsentExpiryDays,
ConsentMode: b.ConsentMode,
ShowBranding: b.ShowBranding,
DefaultLanguage: b.DefaultLanguage,
CreatedAt: b.CreatedAt,

View File

@@ -180,12 +180,17 @@ func (h *Handler) handlePostConsent(w http.ResponseWriter, r *http.Request) {
sdkVersion := r.Header.Get("X-SDK-Version")
cc := h.resolveCountryCode(r)
var regulation *cookiebanner.Regulation
var (
regulation *cookiebanner.Regulation
resolvedRegulation cookiebanner.Regulation
)
if cc != nil {
r := cookiebanner.RegulationForCountry(*cc)
regulation = &r
resolvedRegulation = cookiebanner.RegulationForCountry(*cc)
regulation = &resolvedRegulation
}
cm := coredata.CookieConsentMode(cookiebanner.ConsentModeForRegulation(resolvedRegulation))
req := cookiebanner.RecordConsentRequest{
Version: body.Version,
VisitorID: body.VisitorID,
@@ -196,6 +201,7 @@ func (h *Handler) handlePostConsent(w http.ResponseWriter, r *http.Request) {
SdkVersion: sdkVersion,
Regulation: regulation,
CountryCode: cc,
ConsentMode: &cm,
}
record, err := h.cookieBannerSvc.RecordConsent(r.Context(), bannerID, req)

View File

@@ -4720,7 +4720,6 @@ func (r *Resolver) AddCookieBannerTool(ctx context.Context, req *mcp.CallToolReq
PrivacyPolicyURL: input.PrivacyPolicyURL,
CookiePolicyURL: input.CookiePolicyURL,
ConsentExpiryDays: input.ConsentExpiryDays,
ConsentMode: coredata.CookieConsentMode(input.ConsentMode),
})
if err != nil {
return nil, types.AddCookieBannerOutput{}, fmt.Errorf("cannot create cookie banner: %w", err)
@@ -4745,10 +4744,6 @@ func (r *Resolver) UpdateCookieBannerTool(ctx context.Context, req *mcp.CallTool
if v := UnwrapOmittable(input.ConsentExpiryDays); v != nil && *v != nil {
updateReq.ConsentExpiryDays = *v
}
if v := UnwrapOmittable(input.ConsentMode); v != nil && *v != nil {
mode := coredata.CookieConsentMode(**v)
updateReq.ConsentMode = &mode
}
if v := UnwrapOmittable(input.DefaultLanguage); v != nil && *v != nil {
updateReq.DefaultLanguage = *v
}

View File

@@ -9311,7 +9311,6 @@ components:
- state
- cookie_policy_url
- consent_expiry_days
- consent_mode
- show_branding
- default_language
- created_at
@@ -9344,10 +9343,6 @@ components:
consent_expiry_days:
type: integer
description: Days until consent expires
consent_mode:
type: string
enum: [OPT_IN, OPT_OUT]
description: Consent mode
show_branding:
type: boolean
description: Whether to show Probo branding
@@ -9726,7 +9721,6 @@ components:
- origin
- cookie_policy_url
- consent_expiry_days
- consent_mode
properties:
organization_id:
$ref: "#/components/schemas/GID"
@@ -9746,10 +9740,6 @@ components:
consent_expiry_days:
type: integer
description: Days until consent expires
consent_mode:
type: string
enum: [OPT_IN, OPT_OUT]
description: Consent mode
AddCookieBannerOutput:
type: object
@@ -9787,11 +9777,6 @@ components:
- integer
- "null"
go.probo.inc/mcpgen/omittable: true
consent_mode:
type:
- string
- "null"
go.probo.inc/mcpgen/omittable: true
default_language:
type:
- string

View File

@@ -29,7 +29,6 @@ func NewCookieBanner(b *coredata.CookieBanner) *CookieBanner {
PrivacyPolicyURL: b.PrivacyPolicyURL,
CookiePolicyURL: b.CookiePolicyURL,
ConsentExpiryDays: b.ConsentExpiryDays,
ConsentMode: CookieBannerConsentMode(b.ConsentMode),
ShowBranding: b.ShowBranding,
DefaultLanguage: b.DefaultLanguage,
CreatedAt: b.CreatedAt,