@preprio/toolkit 0.5.0-rc.2 → 0.6.0-alpha.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 +308 -27
- package/dist/astro/chunk-3UVUDDNY.js +173 -0
- package/dist/astro/graphql.cjs +983 -0
- package/dist/astro/graphql.d.cts +231 -0
- package/dist/astro/graphql.d.ts +231 -0
- package/dist/astro/graphql.js +893 -0
- package/dist/astro/index-XT_z-RYT.d.cts +130 -0
- package/dist/astro/index-XT_z-RYT.d.ts +130 -0
- package/dist/astro/index.cjs +14 -1
- package/dist/astro/index.d.cts +1 -120
- package/dist/astro/index.d.ts +1 -120
- package/dist/astro/index.js +15 -153
- package/dist/{chunk-FLPNN3CV.js → chunk-BJ2LBLWO.js} +71 -276
- package/dist/chunk-DGZA7KX7.js +172 -0
- package/dist/chunk-YR7P4IWE.js +187 -0
- package/dist/graphql.cjs +894 -0
- package/dist/graphql.d.cts +231 -0
- package/dist/graphql.d.ts +231 -0
- package/dist/graphql.js +787 -0
- package/dist/index.cjs +76 -119
- package/dist/index.d.cts +12 -64
- package/dist/index.d.ts +12 -64
- package/dist/index.js +23 -167
- package/dist/nextjs/chunk-U4HXENF7.js +231 -0
- package/dist/nextjs/components.cjs +190 -122
- package/dist/nextjs/components.d.cts +33 -2
- package/dist/nextjs/components.d.ts +33 -2
- package/dist/nextjs/components.js +132 -4
- package/dist/nextjs/graphql.cjs +1315 -0
- package/dist/nextjs/graphql.d.cts +361 -0
- package/dist/nextjs/graphql.d.ts +361 -0
- package/dist/nextjs/graphql.js +1218 -0
- package/dist/nextjs/index.cjs +126 -6
- package/dist/nextjs/index.d.cts +53 -147
- package/dist/nextjs/index.d.ts +53 -147
- package/dist/nextjs/index.js +113 -203
- package/dist/nextjs/server-CjpELYvq.d.cts +156 -0
- package/dist/nextjs/server-CjpELYvq.d.ts +156 -0
- package/dist/nuxt/chunk-P6ENNAEE.js +417 -0
- package/dist/nuxt/graphql.cjs +990 -0
- package/dist/nuxt/graphql.d.cts +228 -0
- package/dist/nuxt/graphql.d.ts +228 -0
- package/dist/nuxt/graphql.js +894 -0
- package/dist/nuxt/index.cjs +14 -1
- package/dist/nuxt/index.d.cts +3 -148
- package/dist/nuxt/index.d.ts +3 -148
- package/dist/nuxt/index.js +15 -391
- package/dist/nuxt/server-8v6OHbsw.d.cts +158 -0
- package/dist/nuxt/server-8v6OHbsw.d.ts +158 -0
- package/dist/pixel-DwW7cXJm.d.cts +49 -0
- package/dist/pixel-DwW7cXJm.d.ts +49 -0
- package/dist/react/components.cjs +88 -120
- package/dist/react/components.d.cts +2 -8
- package/dist/react/components.d.ts +2 -8
- package/dist/react/components.js +88 -120
- package/dist/server-Brr1UgtW.d.ts +59 -0
- package/dist/server-DJuS3YU0.d.cts +59 -0
- package/dist/sveltekit/chunk-FSARVMG5.js +413 -0
- package/dist/sveltekit/graphql.cjs +996 -0
- package/dist/sveltekit/graphql.d.cts +233 -0
- package/dist/sveltekit/graphql.d.ts +233 -0
- package/dist/sveltekit/graphql.js +900 -0
- package/dist/sveltekit/index.cjs +14 -1
- package/dist/sveltekit/index.d.cts +3 -88
- package/dist/sveltekit/index.d.ts +3 -88
- package/dist/sveltekit/index.js +15 -387
- package/dist/sveltekit/server-CO847mEV.d.cts +98 -0
- package/dist/sveltekit/server-CO847mEV.d.ts +98 -0
- package/dist/{pixel-B3oQNbZ3.d.cts → types-BYH9XqmN.d.cts} +4 -58
- package/dist/{pixel-B3oQNbZ3.d.ts → types-BYH9XqmN.d.ts} +4 -58
- package/package.json +31 -1
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
interface PreprSegment {
|
|
2
|
+
readonly _id: string;
|
|
3
|
+
readonly name: string;
|
|
4
|
+
}
|
|
5
|
+
/**
|
|
6
|
+
* Per-feature config. `false` is shorthand for `{ enabled: false }`; the object
|
|
7
|
+
* form leaves room for per-feature options later without a breaking change.
|
|
8
|
+
*/
|
|
9
|
+
type PreprFeatureConfig = boolean | {
|
|
10
|
+
enabled?: boolean;
|
|
11
|
+
};
|
|
12
|
+
/** Toolkit features a consumer can turn off. Omitted keys stay enabled. */
|
|
13
|
+
interface PreprFeatures {
|
|
14
|
+
/** Segment picker, `Prepr-Segments` header and its cookie/query param. */
|
|
15
|
+
segments?: PreprFeatureConfig;
|
|
16
|
+
/** A/B variant switch, `Prepr-ABtesting` header and its cookie/query param. */
|
|
17
|
+
abTesting?: PreprFeatureConfig;
|
|
18
|
+
/**
|
|
19
|
+
* The site's own click-to-edit: the toolbar's Edit mode control, the stega
|
|
20
|
+
* tooltip/overlay and the close-edit pill.
|
|
21
|
+
*
|
|
22
|
+
* NOT a security control, and NOT the Prepr editor's live preview. When the
|
|
23
|
+
* site is framed by the editor, `prepr:initVE` still activates edit mode —
|
|
24
|
+
* that is the CMS operating inside its own iframe, not an affordance offered
|
|
25
|
+
* to visitors. See iframe-bridge.ts.
|
|
26
|
+
*/
|
|
27
|
+
editMode?: PreprFeatureConfig;
|
|
28
|
+
}
|
|
29
|
+
interface PreprToolbarProps {
|
|
30
|
+
/**
|
|
31
|
+
* Server-resolved active segment. Optional: omit it with `segments`
|
|
32
|
+
* disabled, where there is nothing to resolve. When enabled and omitted,
|
|
33
|
+
* the persisted cookie is used.
|
|
34
|
+
*/
|
|
35
|
+
readonly activeSegment?: string | null;
|
|
36
|
+
/**
|
|
37
|
+
* Server-resolved active A/B variant. Optional: omit it with `abTesting`
|
|
38
|
+
* disabled, where there is nothing to resolve. When enabled and omitted,
|
|
39
|
+
* the persisted cookie is used.
|
|
40
|
+
*/
|
|
41
|
+
readonly activeVariant?: string | null;
|
|
42
|
+
/** Available segments to personalize on. */
|
|
43
|
+
readonly segments?: readonly PreprSegment[];
|
|
44
|
+
/** @deprecated Alias for `segments`. */
|
|
45
|
+
readonly data?: readonly PreprSegment[];
|
|
46
|
+
}
|
|
47
|
+
type PreprVariant = 'A' | 'B';
|
|
48
|
+
interface PreprHeaders {
|
|
49
|
+
readonly 'prepr-customer-id'?: string;
|
|
50
|
+
readonly 'Prepr-Segments'?: string;
|
|
51
|
+
readonly 'Prepr-ABtesting'?: PreprVariant;
|
|
52
|
+
readonly 'Prepr-Preview-Bar'?: 'true';
|
|
53
|
+
readonly 'Prepr-Context-utm_source'?: string;
|
|
54
|
+
readonly 'Prepr-Context-utm_medium'?: string;
|
|
55
|
+
readonly 'Prepr-Context-utm_term'?: string;
|
|
56
|
+
readonly 'Prepr-Context-utm_content'?: string;
|
|
57
|
+
readonly 'Prepr-Context-utm_campaign'?: string;
|
|
58
|
+
readonly 'Prepr-Context-initial_referral'?: string;
|
|
59
|
+
readonly 'Prepr-Visitor-IP'?: string;
|
|
60
|
+
readonly 'Prepr-Hubspot-Id'?: string;
|
|
61
|
+
readonly 'Prepr-Customer-Id-Created'?: 'true';
|
|
62
|
+
/** The visitor's browser User-Agent, used by the API for device detection. */
|
|
63
|
+
readonly 'User-Agent'?: string;
|
|
64
|
+
/** @deprecated Never populated; the visitor's value is under `User-Agent`. */
|
|
65
|
+
readonly 'Prepr-User-Agent'?: string;
|
|
66
|
+
readonly 'Prepr-Package'?: string;
|
|
67
|
+
}
|
|
68
|
+
type PreprErrorCode = 'INVALID_TOKEN' | 'MISSING_TOKEN' | 'HTTP_ERROR' | 'FETCH_ERROR' | 'INVALID_RESPONSE' | 'CONTEXT_ERROR' | 'GRAPHQL_ERROR' | 'INVALID_DOCUMENT';
|
|
69
|
+
|
|
70
|
+
interface PreprMiddlewareOptions {
|
|
71
|
+
/** Enable preview-mode headers (segment/AB overrides, preview bar). */
|
|
72
|
+
preview?: boolean;
|
|
73
|
+
/**
|
|
74
|
+
* Disable features app-wide. Pass the same object you give the toolbar: a
|
|
75
|
+
* disabled feature injects no header and persists no cookie, whatever the
|
|
76
|
+
* request carries.
|
|
77
|
+
*/
|
|
78
|
+
features?: PreprFeatures;
|
|
79
|
+
/** Override the version reported in Prepr-Package (mainly for tests). */
|
|
80
|
+
version?: string;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Structural stand-in for h3's `H3Event`, so this package needs no build-time
|
|
85
|
+
* dependency on `h3`/`nuxt`. Only the fields `handlePreprRequest` uses.
|
|
86
|
+
*
|
|
87
|
+
* `node` ties this to Nitro's Node.js preset (the Nuxt default). Edge presets
|
|
88
|
+
* expose no raw Node request/response to fold headers back onto.
|
|
89
|
+
*/
|
|
90
|
+
interface H3EventLike {
|
|
91
|
+
node: {
|
|
92
|
+
req: {
|
|
93
|
+
url?: string;
|
|
94
|
+
headers: Record<string, string | string[] | undefined>;
|
|
95
|
+
};
|
|
96
|
+
res: {
|
|
97
|
+
/** Node's `ServerResponse.appendHeader` (Node >= 18.3). */
|
|
98
|
+
appendHeader(name: string, value: string): unknown;
|
|
99
|
+
};
|
|
100
|
+
};
|
|
101
|
+
/** Request-scoped bag shared with route handlers and Vue via `useRequestEvent`. */
|
|
102
|
+
context: Record<string, unknown>;
|
|
103
|
+
}
|
|
104
|
+
/** Key under which `handlePreprRequest` mirrors the forwarded Prepr `Headers`. */
|
|
105
|
+
declare const PREPR_CONTEXT_KEY = "prepr";
|
|
106
|
+
/**
|
|
107
|
+
* Nuxt server middleware entry point — call it inside `defineEventHandler` in
|
|
108
|
+
* `server/middleware/prepr.ts`:
|
|
109
|
+
*
|
|
110
|
+
* ```ts
|
|
111
|
+
* export default defineEventHandler(event => {
|
|
112
|
+
* handlePreprRequest(event, { preview: import.meta.dev });
|
|
113
|
+
* });
|
|
114
|
+
* ```
|
|
115
|
+
*
|
|
116
|
+
* The computed Prepr headers are folded back onto the raw Node request
|
|
117
|
+
* (lowercased, as Node stores them), which is what `useRequestHeaders()` and
|
|
118
|
+
* downstream handlers read. The same `Headers` are mirrored onto
|
|
119
|
+
* `event.context.prepr` for callers who prefer an explicit read
|
|
120
|
+
* (`getPreprHeadersFromEvent`). Cookies are appended to the response.
|
|
121
|
+
*/
|
|
122
|
+
declare function handlePreprRequest(event: H3EventLike, options?: PreprMiddlewareOptions): void;
|
|
123
|
+
/**
|
|
124
|
+
* Personalization headers to forward to your GraphQL fetch, from the h3 event.
|
|
125
|
+
* Empty `Headers` if `handlePreprRequest` did not run, so the result is always
|
|
126
|
+
* safe to spread.
|
|
127
|
+
*/
|
|
128
|
+
declare function getPreprHeadersFromEvent(event: Pick<H3EventLike, 'context'>): Headers;
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* Whether a Prepr GraphQL response differs per visitor, read from its `Vary`
|
|
132
|
+
* header. Use it when fetching with your own GraphQL client; the toolkit's
|
|
133
|
+
* `createPreprClient` already returns it as `personalized`.
|
|
134
|
+
*
|
|
135
|
+
* Never throws; a response without `Vary` is not personalized.
|
|
136
|
+
*/
|
|
137
|
+
declare function isPersonalizedResponse(source: Response | Headers): boolean;
|
|
138
|
+
|
|
139
|
+
/** Error thrown by the token helpers and the segments fetch. */
|
|
140
|
+
declare class PreprError extends Error {
|
|
141
|
+
readonly code: PreprErrorCode;
|
|
142
|
+
readonly context?: string | undefined;
|
|
143
|
+
readonly originalError?: Error | undefined;
|
|
144
|
+
constructor(message: string, code: PreprErrorCode, context?: string | undefined, originalError?: Error | undefined);
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Asserts `token` is the full `https://graphql.prepr.io/<token>` URL.
|
|
148
|
+
* @throws PreprError if the token is missing or not an HTTPS URL.
|
|
149
|
+
*/
|
|
150
|
+
declare function validatePreprToken(token: string): void;
|
|
151
|
+
/**
|
|
152
|
+
* Pulls the access token out of a GraphQL URL: `https://graphql.prepr.io/abc123`
|
|
153
|
+
* -> `abc123`.
|
|
154
|
+
* @throws PreprError if the URL is not a valid `graphql.prepr.io` URL.
|
|
155
|
+
*/
|
|
156
|
+
declare function extractAccessToken(graphqlUrl: string): string;
|
|
157
|
+
|
|
158
|
+
export { type H3EventLike as H, type PreprHeaders as P, PreprError as a, type PreprFeatures as b, type PreprToolbarProps as c, PREPR_CONTEXT_KEY as d, type PreprMiddlewareOptions as e, extractAccessToken as f, getPreprHeadersFromEvent as g, handlePreprRequest as h, isPersonalizedResponse as i, validatePreprToken as v };
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Loader + typed facade for Prepr's CDN tracking pixel, so consumers don't have
|
|
3
|
+
* to paste a `<script>` tag. The pixel itself lives on the CDN; this only sets
|
|
4
|
+
* up the handoff.
|
|
5
|
+
*
|
|
6
|
+
* The CDN script expects a queue stub to already exist when it loads, so the
|
|
7
|
+
* contract must be reproduced exactly:
|
|
8
|
+
* - `window.prepr` pushes `arguments` onto `.queue` until the real script
|
|
9
|
+
* lands and replaces `.process`.
|
|
10
|
+
* - `.t` must be a `Date.now()` timestamp.
|
|
11
|
+
* - The tag is inserted async, `src` cache-busted every 24h via
|
|
12
|
+
* `Math.ceil(Date.now() / cacheTime) * cacheTime`.
|
|
13
|
+
*/
|
|
14
|
+
/** Config accepted by the CDN pixel. */
|
|
15
|
+
interface PreprPixelConfig {
|
|
16
|
+
destinations?: {
|
|
17
|
+
googleTagManager?: boolean;
|
|
18
|
+
};
|
|
19
|
+
variantImpressionThreshold?: number;
|
|
20
|
+
}
|
|
21
|
+
type PreprQueueArgs = unknown[];
|
|
22
|
+
interface PreprQueueFn {
|
|
23
|
+
(...args: PreprQueueArgs): void;
|
|
24
|
+
queue: PreprQueueArgs[];
|
|
25
|
+
t: number;
|
|
26
|
+
process?: (...args: PreprQueueArgs) => void;
|
|
27
|
+
}
|
|
28
|
+
declare global {
|
|
29
|
+
interface Window {
|
|
30
|
+
prepr?: PreprQueueFn;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Install the queue stub, inject the pixel script, then queue
|
|
35
|
+
* `('init', trackingId, config?)` and `('event', 'pageload')` in that order.
|
|
36
|
+
*
|
|
37
|
+
* Idempotent, and a no-op outside a browser.
|
|
38
|
+
*/
|
|
39
|
+
declare function loadTrackingPixel(trackingId: string, config?: PreprPixelConfig): void;
|
|
40
|
+
/**
|
|
41
|
+
* Send a tracking event through `window.prepr`. Only depends on `window.prepr`
|
|
42
|
+
* existing, never on how it got installed. Warns once and returns quietly when
|
|
43
|
+
* no pixel is present.
|
|
44
|
+
*/
|
|
45
|
+
declare function trackEvent(name: string, data?: string | Record<string, unknown>): void;
|
|
46
|
+
/** Loader-independent like `trackEvent`; warns once if no pixel is installed. */
|
|
47
|
+
declare function setTrackingParam(key: string, value: string): void;
|
|
48
|
+
|
|
49
|
+
export { type PreprPixelConfig as P, loadTrackingPixel as l, setTrackingParam as s, trackEvent as t };
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Loader + typed facade for Prepr's CDN tracking pixel, so consumers don't have
|
|
3
|
+
* to paste a `<script>` tag. The pixel itself lives on the CDN; this only sets
|
|
4
|
+
* up the handoff.
|
|
5
|
+
*
|
|
6
|
+
* The CDN script expects a queue stub to already exist when it loads, so the
|
|
7
|
+
* contract must be reproduced exactly:
|
|
8
|
+
* - `window.prepr` pushes `arguments` onto `.queue` until the real script
|
|
9
|
+
* lands and replaces `.process`.
|
|
10
|
+
* - `.t` must be a `Date.now()` timestamp.
|
|
11
|
+
* - The tag is inserted async, `src` cache-busted every 24h via
|
|
12
|
+
* `Math.ceil(Date.now() / cacheTime) * cacheTime`.
|
|
13
|
+
*/
|
|
14
|
+
/** Config accepted by the CDN pixel. */
|
|
15
|
+
interface PreprPixelConfig {
|
|
16
|
+
destinations?: {
|
|
17
|
+
googleTagManager?: boolean;
|
|
18
|
+
};
|
|
19
|
+
variantImpressionThreshold?: number;
|
|
20
|
+
}
|
|
21
|
+
type PreprQueueArgs = unknown[];
|
|
22
|
+
interface PreprQueueFn {
|
|
23
|
+
(...args: PreprQueueArgs): void;
|
|
24
|
+
queue: PreprQueueArgs[];
|
|
25
|
+
t: number;
|
|
26
|
+
process?: (...args: PreprQueueArgs) => void;
|
|
27
|
+
}
|
|
28
|
+
declare global {
|
|
29
|
+
interface Window {
|
|
30
|
+
prepr?: PreprQueueFn;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Install the queue stub, inject the pixel script, then queue
|
|
35
|
+
* `('init', trackingId, config?)` and `('event', 'pageload')` in that order.
|
|
36
|
+
*
|
|
37
|
+
* Idempotent, and a no-op outside a browser.
|
|
38
|
+
*/
|
|
39
|
+
declare function loadTrackingPixel(trackingId: string, config?: PreprPixelConfig): void;
|
|
40
|
+
/**
|
|
41
|
+
* Send a tracking event through `window.prepr`. Only depends on `window.prepr`
|
|
42
|
+
* existing, never on how it got installed. Warns once and returns quietly when
|
|
43
|
+
* no pixel is present.
|
|
44
|
+
*/
|
|
45
|
+
declare function trackEvent(name: string, data?: string | Record<string, unknown>): void;
|
|
46
|
+
/** Loader-independent like `trackEvent`; warns once if no pixel is installed. */
|
|
47
|
+
declare function setTrackingParam(key: string, value: string): void;
|
|
48
|
+
|
|
49
|
+
export { type PreprPixelConfig as P, loadTrackingPixel as l, setTrackingParam as s, trackEvent as t };
|