@kywi-software/js 0.14.0 → 0.15.1

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.
@@ -1,3 +1,4 @@
1
+ import { type ConsentGateOptions } from '../consent.js';
1
2
  export interface BehavioralResult {
2
3
  session: {
3
4
  pageViewCount: number;
@@ -11,5 +12,5 @@ export interface BehavioralResult {
11
12
  totalScore: number;
12
13
  };
13
14
  }
14
- export declare function collectBehavioral(currentPath: string, category?: string): BehavioralResult;
15
+ export declare function collectBehavioral(currentPath: string, category?: string, gate?: ConsentGateOptions): BehavioralResult;
15
16
  //# sourceMappingURL=behavioral-collector.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"behavioral-collector.d.ts","sourceRoot":"","sources":["../../src/audience/behavioral-collector.ts"],"names":[],"mappings":"AAQA,MAAM,WAAW,gBAAgB;IAC/B,OAAO,EAAE;QAAE,aAAa,EAAE,MAAM,CAAC;QAAC,cAAc,EAAE,MAAM,CAAC;QAAC,eAAe,EAAE,MAAM,CAAC;QAAC,SAAS,EAAE,MAAM,CAAC;QAAC,YAAY,EAAE,MAAM,EAAE,CAAA;KAAE,CAAA;IAC9H,UAAU,EAAE;QAAE,cAAc,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;QAAC,UAAU,EAAE,MAAM,CAAA;KAAE,CAAA;CAC3E;AAsBD,wBAAgB,iBAAiB,CAAC,WAAW,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,gBAAgB,CAqB1F"}
1
+ {"version":3,"file":"behavioral-collector.d.ts","sourceRoot":"","sources":["../../src/audience/behavioral-collector.ts"],"names":[],"mappings":"AAEA,OAAO,EAAc,KAAK,kBAAkB,EAAE,MAAM,eAAe,CAAA;AASnE,MAAM,WAAW,gBAAgB;IAC/B,OAAO,EAAE;QAAE,aAAa,EAAE,MAAM,CAAC;QAAC,cAAc,EAAE,MAAM,CAAC;QAAC,eAAe,EAAE,MAAM,CAAC;QAAC,SAAS,EAAE,MAAM,CAAC;QAAC,YAAY,EAAE,MAAM,EAAE,CAAA;KAAE,CAAA;IAC9H,UAAU,EAAE;QAAE,cAAc,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;QAAC,UAAU,EAAE,MAAM,CAAA;KAAE,CAAA;CAC3E;AAsBD,wBAAgB,iBAAiB,CAC/B,WAAW,EAAE,MAAM,EACnB,QAAQ,CAAC,EAAE,MAAM,EACjB,IAAI,GAAE,kBAAuB,GAC5B,gBAAgB,CA+BlB"}
@@ -1 +1 @@
1
- {"version":3,"file":"dom-patcher.d.ts","sourceRoot":"","sources":["../../src/audience/dom-patcher.ts"],"names":[],"mappings":"AACA,wBAAgB,sBAAsB,CAAC,iBAAiB,EAAE,MAAM,GAAG,IAAI,GAAG,IAAI,CAiC7E"}
1
+ {"version":3,"file":"dom-patcher.d.ts","sourceRoot":"","sources":["../../src/audience/dom-patcher.ts"],"names":[],"mappings":"AACA,wBAAgB,sBAAsB,CAAC,iBAAiB,EAAE,MAAM,GAAG,IAAI,GAAG,IAAI,CAwC7E"}
@@ -1,3 +1,11 @@
1
1
  import type { Audience, VisitorSignals, AudienceResult } from '@kywi-software/core/audiences/types';
2
- export declare function evaluateClientSide(audiences: Audience[], serverSignals: Partial<VisitorSignals>, currentPath: string, pageCategory?: string): AudienceResult;
2
+ import type { ConsentGateOptions } from '../consent.js';
3
+ export declare function evaluateClientSide(audiences: Audience[], serverSignals: Partial<VisitorSignals>, currentPath: string, pageCategory?: string,
4
+ /**
5
+ * `theme.personalization.requireConsent` (kywi-cms#91), passed through to the
6
+ * behavioral collector so what it REMEMBERS between page views follows the
7
+ * same rule the server's cookies do. Omitted, consent is required — the
8
+ * compliant default.
9
+ */
10
+ gate?: ConsentGateOptions): AudienceResult;
3
11
  //# sourceMappingURL=evaluate.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"evaluate.d.ts","sourceRoot":"","sources":["../../src/audience/evaluate.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,qCAAqC,CAAA;AAenG,wBAAgB,kBAAkB,CAChC,SAAS,EAAE,QAAQ,EAAE,EAAE,aAAa,EAAE,OAAO,CAAC,cAAc,CAAC,EAAE,WAAW,EAAE,MAAM,EAAE,YAAY,CAAC,EAAE,MAAM,GACxG,cAAc,CAQhB"}
1
+ {"version":3,"file":"evaluate.d.ts","sourceRoot":"","sources":["../../src/audience/evaluate.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,qCAAqC,CAAA;AAMnG,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAA;AAYvD,wBAAgB,kBAAkB,CAChC,SAAS,EAAE,QAAQ,EAAE,EAAE,aAAa,EAAE,OAAO,CAAC,cAAc,CAAC,EAAE,WAAW,EAAE,MAAM,EAAE,YAAY,CAAC,EAAE,MAAM;AACzG;;;;;GAKG;AACH,IAAI,GAAE,kBAAuB,GAC5B,cAAc,CAWhB"}
@@ -26,6 +26,14 @@ export interface AudienceBootConfig {
26
26
  * the host page passes the resolved config value through.
27
27
  */
28
28
  transparencyNotice?: boolean;
29
+ /**
30
+ * `theme.personalization.requireConsent` (kywi-cms#91). Defaults to true —
31
+ * the resolved audience is only remembered for a visitor who consented to
32
+ * personalization. `false` turns that gate off for a site whose consent is
33
+ * collected by external tooling; the server applies the same flag, so the two
34
+ * must agree or the request is made and then refused persistence.
35
+ */
36
+ requireConsent?: boolean;
29
37
  }
30
38
  export declare function bootAudienceEngine(config: AudienceBootConfig): Promise<void>;
31
39
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/audience/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,cAAc,EAAE,MAAM,qCAAqC,CAAA;AASn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C,IAAI,EAAE,QAAQ,GAAG,cAAc,CAAC;QAAC,MAAM,EAAE,MAAM,EAAE,CAAC;QAAC,OAAO,EAAE,CAAC,CAAC,EAAE,OAAO,CAAC,cAAc,CAAC,KAAK,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAA;KAAE,CAAC,CAAA;IAC9J,YAAY,CAAC,EAAE,kBAAkB,CAAA;IACjC;;;;;OAKG;IACH,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB;;;;;OAKG;IACH,kBAAkB,CAAC,EAAE,OAAO,CAAA;IAC5B;;;;;;OAMG;IACH,cAAc,CAAC,EAAE,OAAO,CAAA;CACzB;AAUD,wBAAsB,kBAAkB,CAAC,MAAM,EAAE,kBAAkB,GAAG,OAAO,CAAC,IAAI,CAAC,CAiIlF"}
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Every query parameter of the current URL. Repeated params keep the FIRST
3
+ * value, matching the server's `collectQuery`. Empty off the browser.
4
+ */
5
+ export declare function collectQuery(): Record<string, string>;
6
+ /**
7
+ * The entry page to record for a page view: the path the host handed us, with
8
+ * this page's query string appended when the path does not already carry one.
9
+ *
10
+ * The query is the interesting half of a campaign landing (`?from=marketer`),
11
+ * and the host passes a bare pathname — so without this the client's entry page
12
+ * and the server's would disagree on every campaign link.
13
+ */
14
+ export declare function entryPageFor(currentPath: string): string;
15
+ //# sourceMappingURL=query-collector.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"query-collector.d.ts","sourceRoot":"","sources":["../../src/audience/query-collector.ts"],"names":[],"mappings":"AAQA;;;GAGG;AACH,wBAAgB,YAAY,IAAI,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CASrD;AAED;;;;;;;GAOG;AACH,wBAAgB,YAAY,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM,CAIxD"}
@@ -0,0 +1,57 @@
1
+ /** The audience the server resolved the visitor to, if any. */
2
+ export interface SelfIdAudience {
3
+ id: string;
4
+ name: string;
5
+ }
6
+ export interface SelfIdResult {
7
+ /** The audience the answers resolved to, or null when nothing matched. */
8
+ audience: SelfIdAudience | null;
9
+ /**
10
+ * Whether the answers were stored SERVER-side. False for a visitor who has
11
+ * not consented to personalization — the audience is still pinned and this
12
+ * page still changes, the profile simply is not kept (kywi-cms#91).
13
+ */
14
+ persisted: boolean;
15
+ /** The answers now on record in the browser. */
16
+ fields: Record<string, string>;
17
+ }
18
+ export interface SelfIdOptions {
19
+ /** Mounted CMS API base. Defaults to the one `Kywi.boot()` derived. */
20
+ apiBase?: string;
21
+ csrfToken?: string | null;
22
+ /** Reload so the server can re-render with the new pin. Default true. */
23
+ reload?: boolean;
24
+ /**
25
+ * Pin this audience BY ID instead of resolving one from the answers — the id
26
+ * comes from `GET {apiBase}/kywi/audiences`, which lists the audiences an
27
+ * editor marked public (kywi-cms#200). Use it when the page renders the
28
+ * chooser FROM that list, so the visitor's pick lands exactly, and an
29
+ * audience with no rules of its own is still reachable. The server validates
30
+ * the id against the same public, site-scoped list.
31
+ */
32
+ audienceId?: string;
33
+ }
34
+ /**
35
+ * Record the visitor's self-identification and resolve their audience.
36
+ *
37
+ * Answers MERGE into whatever is already on record — two controls on the same
38
+ * page (a role picker and an industry picker) do not clobber each other — and a
39
+ * field submitted as `''` is removed, which is what a "Change" / "Clear"
40
+ * control sends.
41
+ *
42
+ * Pass `audienceId` to pin one of the site's PUBLIC audiences directly instead
43
+ * of resolving from the answers; see {@link SelfIdOptions}.
44
+ *
45
+ * Resolves once the server has answered, with the audience it resolved to.
46
+ * Never throws for a failed request: an offline visitor gets
47
+ * `{ audience: null, persisted: false }` and no reload, so the page is not
48
+ * dropped back onto itself with nothing changed.
49
+ */
50
+ export declare function setSelfId(fields: Record<string, string>, options?: SelfIdOptions): Promise<SelfIdResult>;
51
+ /**
52
+ * Forget the visitor's self-identification: clears the browser copy, the
53
+ * server-side copy and the audience pin, so resolution goes back to signals.
54
+ * The mirror of `setSelfId`, and what a "Change" control calls.
55
+ */
56
+ export declare function clearSelfId(options?: SelfIdOptions): Promise<SelfIdResult>;
57
+ //# sourceMappingURL=selfid-api.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"selfid-api.d.ts","sourceRoot":"","sources":["../../src/audience/selfid-api.ts"],"names":[],"mappings":"AAiCA,+DAA+D;AAC/D,MAAM,WAAW,cAAc;IAC7B,EAAE,EAAE,MAAM,CAAA;IACV,IAAI,EAAE,MAAM,CAAA;CACb;AAED,MAAM,WAAW,YAAY;IAC3B,0EAA0E;IAC1E,QAAQ,EAAE,cAAc,GAAG,IAAI,CAAA;IAC/B;;;;OAIG;IACH,SAAS,EAAE,OAAO,CAAA;IAClB,gDAAgD;IAChD,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;CAC/B;AAED,MAAM,WAAW,aAAa;IAC5B,uEAAuE;IACvE,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,SAAS,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;IACzB,yEAAyE;IACzE,MAAM,CAAC,EAAE,OAAO,CAAA;IAChB;;;;;;;OAOG;IACH,UAAU,CAAC,EAAE,MAAM,CAAA;CACpB;AAqBD;;;;;;;;;;;;;;;GAeG;AACH,wBAAsB,SAAS,CAC7B,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EAC9B,OAAO,GAAE,aAAkB,GAC1B,OAAO,CAAC,YAAY,CAAC,CAYvB;AAED;;;;GAIG;AACH,wBAAsB,WAAW,CAAC,OAAO,GAAE,aAAkB,GAAG,OAAO,CAAC,YAAY,CAAC,CAKpF"}
@@ -1,3 +1,5 @@
1
1
  export declare function collectSelfId(): Record<string, string>;
2
2
  export declare function storeSelfId(responses: Record<string, string>): void;
3
+ /** Forget the visitor's answers entirely (the browser half of clearSelfId). */
4
+ export declare function clearStoredSelfId(): void;
3
5
  //# sourceMappingURL=selfid-collector.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"selfid-collector.d.ts","sourceRoot":"","sources":["../../src/audience/selfid-collector.ts"],"names":[],"mappings":"AAGA,wBAAgB,aAAa,IAAI,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAItD;AAED,wBAAgB,WAAW,CAAC,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,IAAI,CAEnE"}
1
+ {"version":3,"file":"selfid-collector.d.ts","sourceRoot":"","sources":["../../src/audience/selfid-collector.ts"],"names":[],"mappings":"AAQA,wBAAgB,aAAa,IAAI,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAQtD;AAED,wBAAgB,WAAW,CAAC,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,IAAI,CAEnE;AAED,+EAA+E;AAC/E,wBAAgB,iBAAiB,IAAI,IAAI,CAExC"}
@@ -31,13 +31,22 @@ export declare function optIn(): void;
31
31
  export declare function resetToAutomatic(): void;
32
32
  /**
33
33
  * Pins the visitor to `audienceId` via the public runtime route — the same
34
- * endpoint and payload the boot path already uses to persist a client-resolved
35
- * audience. The server re-validates the id against the active audiences.
34
+ * endpoint the boot path uses, but marked `source: 'switcher'`. That flag is
35
+ * what tells the server this is the visitor operating a control by hand rather
36
+ * than the runtime remembering something automatically, which is why it is
37
+ * honoured as an `essential` preference and not gated on personalization consent
38
+ * (kywi-cms#91; the same argument as kywi_optout — see the block above).
39
+ *
40
+ * The server re-validates the id against the active audiences.
41
+ *
42
+ * Returns whether the pin will SURVIVE this page: false when the server declined
43
+ * to store it (an older server that predates `source`, or a refusal), so the
44
+ * caller can say so instead of reloading into an unchanged page.
36
45
  */
37
46
  export declare function pinAudience(audienceId: string, opts?: {
38
47
  apiBase?: string | undefined;
39
48
  csrfToken?: string | null | undefined;
40
- }): Promise<void>;
49
+ }): Promise<boolean>;
41
50
  /**
42
51
  * Renders (or removes) the transparency surface for `state`. Safe to call on
43
52
  * every boot; it replaces whatever is currently mounted.
@@ -1 +1 @@
1
- {"version":3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;AAClD,wBAAgB,WAAW,IAAI,IAAI,CAGlC;AAED,oFAAoF;AACpF,wBAAgB,aAAa,IAAI,IAAI,CAIpC;AAED;;;;;;GAMG;AACH,wBAAgB,qBAAqB,IAAI,IAAI,CAU5C;AAED,wEAAwE;AACxE,wBAAgB,sBAAsB,IAAI,IAAI,CAG7C"}
package/dist/consent.d.ts CHANGED
@@ -1,5 +1,32 @@
1
1
  export declare const CONSENT_COOKIE: "kywi_consent";
2
+ /** The cookie an audience pin lives in. */
3
+ export declare const AUDIENCE_PIN_COOKIE: "kywi_audience";
4
+ /**
5
+ * The `kywi_audience` value prefix marking a pin the visitor chose BY HAND in
6
+ * the transparency panel, rather than one the runtime remembered on its own.
7
+ * Mirrors `SWITCHER_PIN_PREFIX` in core's `audiences/consent.ts`.
8
+ */
9
+ export declare const SWITCHER_PIN_PREFIX: "switcher:";
2
10
  export type ConsentCategory = 'essential' | 'analytics' | 'marketing' | 'personalization';
11
+ /**
12
+ * Every cookie the engine writes → the consent category it requires.
13
+ *
14
+ * A MIRROR of `COOKIE_CONSENT_CATEGORY` in `@kywi-software/core`'s
15
+ * `audiences/consent.ts`, which is the authority. This package cannot import
16
+ * core (neither depends on the other), so the copy exists to let a decision made
17
+ * here REVOKE the cookies it denies without a round trip.
18
+ * `__tests__/consent-parity.test.ts` asserts the two maps are identical.
19
+ */
20
+ export declare const COOKIE_CONSENT_CATEGORY: Record<string, ConsentCategory>;
21
+ /** Mirrors `ConsentGateOptions` in core's `audiences/consent.ts`. */
22
+ export interface ConsentGateOptions {
23
+ /**
24
+ * `theme.personalization.requireConsent`. Defaults to true. When explicitly
25
+ * `false` the gate is off and every category reads as allowed — for a site
26
+ * whose consent is collected by external tooling (kywi-cms#91).
27
+ */
28
+ requireConsent?: boolean;
29
+ }
3
30
  export interface ConsentState {
4
31
  essential: boolean;
5
32
  analytics: boolean;
@@ -9,6 +36,19 @@ export interface ConsentState {
9
36
  /**
10
37
  * Read the current consent state from the `kywi_consent` cookie.
11
38
  * Returns the parsed ConsentState, or null if the cookie is missing or malformed.
39
+ *
40
+ * The payload is NORMALIZED, not trusted: `essential` is forced true and every
41
+ * other category is `=== true` or false. The cookie is client-writable, so it
42
+ * can arrive partial (written by an older version), tampered with, or carrying
43
+ * `"yes"` where a boolean belongs. Casting it to `ConsentState` and hoping left
44
+ * callers reading `state.marketing` a truthy string. This mirrors
45
+ * `parseConsentValue` in core's `audiences/consent.ts` exactly, so the client
46
+ * and the server can never disagree about what a given cookie means
47
+ * (`__tests__/consent-parity.test.ts` pins that).
48
+ *
49
+ * Unlike core's version this does NOT decodeURIComponent: `readCookies` has
50
+ * already decoded the value, and decoding twice would corrupt a payload
51
+ * containing a literal `%`.
12
52
  */
13
53
  export declare function getConsentState(): ConsentState | null;
14
54
  /**
@@ -16,9 +56,36 @@ export declare function getConsentState(): ConsentState | null;
16
56
  * The cookie is stored with a 1-year Max-Age.
17
57
  */
18
58
  export declare function setConsent(prefs: Partial<Omit<ConsentState, 'essential'>>): void;
59
+ /**
60
+ * Delete every cookie whose category `state` does not grant, and return the
61
+ * names deleted.
62
+ *
63
+ * Refusing to WRITE new cookies is only half of "Reject All": a visitor who
64
+ * accepted last month and rejects today is still carrying a `kywi_visitor` id,
65
+ * and a gate that only blocked writes would keep reading it forever
66
+ * (kywi-cms#91).
67
+ *
68
+ * `kywi_signals` is HttpOnly and cannot be removed from script; the attempt is
69
+ * harmless, the server stops writing it, and it expires on its own 60-second
70
+ * horizon. Core's server-side read paths also ignore personalization cookies
71
+ * whenever the gate denies, so a cookie script cannot clear is inert anyway.
72
+ */
73
+ export declare function clearDeniedCookies(state: ConsentState | null): string[];
19
74
  /**
20
75
  * Check whether a specific consent category has been granted.
21
- * Returns false if no consent cookie exists or the category is unknown.
76
+ *
77
+ * `essential` is ALWAYS granted, decision or not — necessary cookies (the
78
+ * consent record itself, the personalization opt-out flag) are never gated, and
79
+ * before kywi-cms#91 that was true only by accident because nothing called this
80
+ * function at all. Every other category needs an explicit `true`, so an
81
+ * undecided visitor grants nothing and an unknown category is denied.
82
+ *
83
+ * `requireConsent: false` (from `theme.personalization.requireConsent`) turns the
84
+ * gate off entirely for a site whose consent is collected by external tooling.
85
+ *
86
+ * The authoritative cookie→category map lives in `@kywi-software/core`'s
87
+ * `audiences/consent.ts` (`COOKIE_CONSENT_CATEGORY`) — this package cannot
88
+ * import core, so `__tests__/consent-parity.test.ts` asserts the two agree.
22
89
  */
23
- export declare function hasConsent(category: ConsentCategory): boolean;
90
+ export declare function hasConsent(category: ConsentCategory, options?: ConsentGateOptions): boolean;
24
91
  //# sourceMappingURL=consent.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"consent.d.ts","sourceRoot":"","sources":["../src/consent.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,cAAc,EAAG,cAAuB,CAAA;AAErD,MAAM,MAAM,eAAe,GAAG,WAAW,GAAG,WAAW,GAAG,WAAW,GAAG,iBAAiB,CAAA;AAEzF,MAAM,WAAW,YAAY;IAC3B,SAAS,EAAE,OAAO,CAAA;IAClB,SAAS,EAAE,OAAO,CAAA;IAClB,SAAS,EAAE,OAAO,CAAA;IAClB,eAAe,EAAE,OAAO,CAAA;CACzB;AAED;;;GAGG;AACH,wBAAgB,eAAe,IAAI,YAAY,GAAG,IAAI,CAYrD;AAED;;;GAGG;AACH,wBAAgB,UAAU,CACxB,KAAK,EAAE,OAAO,CAAC,IAAI,CAAC,YAAY,EAAE,WAAW,CAAC,CAAC,GAC9C,IAAI,CASN;AAED;;;GAGG;AACH,wBAAgB,UAAU,CAAC,QAAQ,EAAE,eAAe,GAAG,OAAO,CAI7D"}
1
+ {"version":3,"file":"consent.d.ts","sourceRoot":"","sources":["../src/consent.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,cAAc,EAAG,cAAuB,CAAA;AAErD,2CAA2C;AAC3C,eAAO,MAAM,mBAAmB,EAAG,eAAwB,CAAA;AAE3D;;;;GAIG;AACH,eAAO,MAAM,mBAAmB,EAAG,WAAoB,CAAA;AAEvD,MAAM,MAAM,eAAe,GAAG,WAAW,GAAG,WAAW,GAAG,WAAW,GAAG,iBAAiB,CAAA;AAEzF;;;;;;;;GAQG;AACH,eAAO,MAAM,uBAAuB,EAAE,MAAM,CAAC,MAAM,EAAE,eAAe,CAWnE,CAAA;AAED,qEAAqE;AACrE,MAAM,WAAW,kBAAkB;IACjC;;;;OAIG;IACH,cAAc,CAAC,EAAE,OAAO,CAAA;CACzB;AAED,MAAM,WAAW,YAAY;IAC3B,SAAS,EAAE,OAAO,CAAA;IAClB,SAAS,EAAE,OAAO,CAAA;IAClB,SAAS,EAAE,OAAO,CAAA;IAClB,eAAe,EAAE,OAAO,CAAA;CACzB;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,eAAe,IAAI,YAAY,GAAG,IAAI,CAmBrD;AAED;;;GAGG;AACH,wBAAgB,UAAU,CACxB,KAAK,EAAE,OAAO,CAAC,IAAI,CAAC,YAAY,EAAE,WAAW,CAAC,CAAC,GAC9C,IAAI,CAYN;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,YAAY,GAAG,IAAI,GAAG,MAAM,EAAE,CAYvE;AAyBD;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,UAAU,CAAC,QAAQ,EAAE,eAAe,EAAE,OAAO,GAAE,kBAAuB,GAAG,OAAO,CAM/F"}
package/dist/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import type { KywiContext, KywiModuleDefinition } from './types.js';
2
+ import { setSelfId, clearSelfId } from './audience/selfid-api.js';
2
3
  type PreInitCallback = (kywi: typeof Kywi) => void;
3
4
  export declare const Kywi: {
4
5
  version: string;
@@ -14,13 +15,28 @@ export declare const Kywi: {
14
15
  extend(methods: Record<string, (...args: unknown[]) => unknown>): void;
15
16
  };
16
17
  };
18
+ /**
19
+ * Record who the visitor says they are, and resolve their audience
20
+ * (kywi-cms#200). Writes the browser-side answers, posts them to the
21
+ * consent-gated runtime endpoint, and reloads so the SERVER can re-render
22
+ * with the resolved audience pinned — which is the only way to reach a
23
+ * variant arm, since every losing arm is pruned server-side (#167).
24
+ *
25
+ * On the global because a site's own "What brings you here?" control needs
26
+ * it: the built-in widget's write path is module-private.
27
+ */
28
+ setSelfId: typeof setSelfId;
29
+ /** Forget the visitor's self-identification and un-pin their audience. */
30
+ clearSelfId: typeof clearSelfId;
17
31
  getEntity: (type: string) => any;
18
32
  getFeed: (type: string) => any;
19
33
  renderFeed: (options: any) => void;
20
34
  boot(): void;
21
35
  };
22
36
  export { bootAudienceEngine } from './audience/index.js';
37
+ export { setSelfId, clearSelfId, type SelfIdAudience, type SelfIdOptions, type SelfIdResult, } from './audience/selfid-api.js';
23
38
  export { openTransparencyPanel, renderTransparencyPanel, type TransparencyState, type TransparencyAudience, } from './audience/transparency.js';
24
39
  export { bootExperiments, type ExperimentRuntime, type ConversionSignal } from './experiments/index.js';
25
40
  export { initNavMenus, enhanceNav, NAV_BREAKPOINT } from './nav/menu.js';
41
+ export { getConsentState, setConsent, hasConsent, clearDeniedCookies, COOKIE_CONSENT_CATEGORY, CONSENT_COOKIE, AUDIENCE_PIN_COOKIE, SWITCHER_PIN_PREFIX, type ConsentCategory, type ConsentGateOptions, type ConsentState, } from './consent.js';
26
42
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAA;AAUnE,KAAK,eAAe,GAAG,CAAC,IAAI,EAAE,OAAO,IAAI,KAAK,IAAI,CAAA;AAIlD,eAAO,MAAM,IAAI;;aAEa,WAAW;YACzB,MAAM,CAAC,MAAM,EAAE,oBAAoB,CAAC;gBACtC,eAAe,GAAG,IAAI;;2BAIb,oBAAoB,GAAG,oBAAoB;;;;oBAM9C,MAAM,CAAC,MAAM,EAAE,CAAC,GAAG,IA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