@preprio/toolkit 0.5.0-rc.2 → 0.6.0-alpha.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.
- package/README.md +415 -27
- package/dist/astro/chunk-O7N6GPAH.js +173 -0
- package/dist/astro/graphql.cjs +1030 -0
- package/dist/astro/graphql.d.cts +305 -0
- package/dist/astro/graphql.d.ts +305 -0
- package/dist/astro/graphql.js +936 -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-3JLWZQ37.js +179 -0
- package/dist/chunk-3NCEVJJ3.js +10 -0
- package/dist/chunk-S5RWVMDJ.js +148 -0
- package/dist/chunk-TBKSBXGH.js +452 -0
- package/dist/{chunk-FLPNN3CV.js → chunk-VI6QZTBM.js} +73 -276
- package/dist/chunk-YWIKKWBR.js +26 -0
- package/dist/graphql/codegen.cjs +510 -0
- package/dist/graphql/codegen.d.cts +23 -0
- package/dist/graphql/codegen.d.ts +23 -0
- package/dist/graphql/codegen.js +99 -0
- package/dist/graphql.cjs +941 -0
- package/dist/graphql.d.cts +305 -0
- package/dist/graphql.d.ts +305 -0
- package/dist/graphql.js +419 -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 +27 -167
- package/dist/nextjs/chunk-BQ6IGSH6.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 +133 -4
- package/dist/nextjs/graphql.cjs +1362 -0
- package/dist/nextjs/graphql.d.cts +435 -0
- package/dist/nextjs/graphql.d.ts +435 -0
- package/dist/nextjs/graphql.js +1261 -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-IQDSBPDN.js +417 -0
- package/dist/nuxt/graphql.cjs +1037 -0
- package/dist/nuxt/graphql.d.cts +302 -0
- package/dist/nuxt/graphql.d.ts +302 -0
- package/dist/nuxt/graphql.js +937 -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-OKYZ6HPH.js +413 -0
- package/dist/sveltekit/graphql.cjs +1043 -0
- package/dist/sveltekit/graphql.d.cts +307 -0
- package/dist/sveltekit/graphql.d.ts +307 -0
- package/dist/sveltekit/graphql.js +943 -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 +36 -1
|
@@ -0,0 +1,98 @@
|
|
|
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
|
+
/**
|
|
71
|
+
* Whether a Prepr GraphQL response differs per visitor, read from its `Vary`
|
|
72
|
+
* header. Use it when fetching with your own GraphQL client; the toolkit's
|
|
73
|
+
* `createPreprClient` already returns it as `personalized`.
|
|
74
|
+
*
|
|
75
|
+
* Never throws; a response without `Vary` is not personalized.
|
|
76
|
+
*/
|
|
77
|
+
declare function isPersonalizedResponse(source: Response | Headers): boolean;
|
|
78
|
+
|
|
79
|
+
/** Error thrown by the token helpers and the segments fetch. */
|
|
80
|
+
declare class PreprError extends Error {
|
|
81
|
+
readonly code: PreprErrorCode;
|
|
82
|
+
readonly context?: string | undefined;
|
|
83
|
+
readonly originalError?: Error | undefined;
|
|
84
|
+
constructor(message: string, code: PreprErrorCode, context?: string | undefined, originalError?: Error | undefined);
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Asserts `token` is the full `https://graphql.prepr.io/<token>` URL.
|
|
88
|
+
* @throws PreprError if the token is missing or not an HTTPS URL.
|
|
89
|
+
*/
|
|
90
|
+
declare function validatePreprToken(token: string): void;
|
|
91
|
+
/**
|
|
92
|
+
* Pulls the access token out of a GraphQL URL: `https://graphql.prepr.io/abc123`
|
|
93
|
+
* -> `abc123`.
|
|
94
|
+
* @throws PreprError if the URL is not a valid `graphql.prepr.io` URL.
|
|
95
|
+
*/
|
|
96
|
+
declare function extractAccessToken(graphqlUrl: string): string;
|
|
97
|
+
|
|
98
|
+
export { type PreprHeaders as P, PreprError as a, type PreprFeatures as b, type PreprToolbarProps as c, extractAccessToken as e, isPersonalizedResponse as i, validatePreprToken as v };
|
|
@@ -0,0 +1,98 @@
|
|
|
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
|
+
/**
|
|
71
|
+
* Whether a Prepr GraphQL response differs per visitor, read from its `Vary`
|
|
72
|
+
* header. Use it when fetching with your own GraphQL client; the toolkit's
|
|
73
|
+
* `createPreprClient` already returns it as `personalized`.
|
|
74
|
+
*
|
|
75
|
+
* Never throws; a response without `Vary` is not personalized.
|
|
76
|
+
*/
|
|
77
|
+
declare function isPersonalizedResponse(source: Response | Headers): boolean;
|
|
78
|
+
|
|
79
|
+
/** Error thrown by the token helpers and the segments fetch. */
|
|
80
|
+
declare class PreprError extends Error {
|
|
81
|
+
readonly code: PreprErrorCode;
|
|
82
|
+
readonly context?: string | undefined;
|
|
83
|
+
readonly originalError?: Error | undefined;
|
|
84
|
+
constructor(message: string, code: PreprErrorCode, context?: string | undefined, originalError?: Error | undefined);
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Asserts `token` is the full `https://graphql.prepr.io/<token>` URL.
|
|
88
|
+
* @throws PreprError if the token is missing or not an HTTPS URL.
|
|
89
|
+
*/
|
|
90
|
+
declare function validatePreprToken(token: string): void;
|
|
91
|
+
/**
|
|
92
|
+
* Pulls the access token out of a GraphQL URL: `https://graphql.prepr.io/abc123`
|
|
93
|
+
* -> `abc123`.
|
|
94
|
+
* @throws PreprError if the URL is not a valid `graphql.prepr.io` URL.
|
|
95
|
+
*/
|
|
96
|
+
declare function extractAccessToken(graphqlUrl: string): string;
|
|
97
|
+
|
|
98
|
+
export { type PreprHeaders as P, PreprError as a, type PreprFeatures as b, type PreprToolbarProps as c, extractAccessToken as e, isPersonalizedResponse as i, validatePreprToken as v };
|
|
@@ -64,14 +64,8 @@ interface PreprPreviewOptions extends PreprToolbarOptions {
|
|
|
64
64
|
*/
|
|
65
65
|
ui?: boolean;
|
|
66
66
|
/**
|
|
67
|
-
* Replace the `*.prepr.io` editor-origin wildcard with an exact list
|
|
68
|
-
*
|
|
69
|
-
* editors; when set, the wildcard no longer applies. Entries are compared to
|
|
70
|
-
* the editor's origin exactly: scheme, host and port.
|
|
71
|
-
*
|
|
72
|
-
* `['*']` accepts any editor origin. Use it for development only: any page
|
|
73
|
-
* that frames the preview can then switch on preview and edit mode and
|
|
74
|
-
* receives the field-edit events, which carry content item ids.
|
|
67
|
+
* Replace the `*.prepr.io` editor-origin wildcard with an exact list.
|
|
68
|
+
* Intended for self-hosted editors; when set, the wildcard no longer applies.
|
|
75
69
|
*/
|
|
76
70
|
allowedEditorOrigins?: string[];
|
|
77
71
|
/**
|
|
@@ -138,54 +132,6 @@ interface PreprHeaders {
|
|
|
138
132
|
readonly 'Prepr-User-Agent'?: string;
|
|
139
133
|
readonly 'Prepr-Package'?: string;
|
|
140
134
|
}
|
|
141
|
-
type PreprErrorCode = 'INVALID_TOKEN' | 'MISSING_TOKEN' | 'HTTP_ERROR' | 'FETCH_ERROR' | 'INVALID_RESPONSE' | 'CONTEXT_ERROR';
|
|
142
|
-
|
|
143
|
-
/**
|
|
144
|
-
* Loader + typed facade for Prepr's CDN tracking pixel, so consumers don't have
|
|
145
|
-
* to paste a `<script>` tag. The pixel itself lives on the CDN; this only sets
|
|
146
|
-
* up the handoff.
|
|
147
|
-
*
|
|
148
|
-
* The CDN script expects a queue stub to already exist when it loads, so the
|
|
149
|
-
* contract must be reproduced exactly:
|
|
150
|
-
* - `window.prepr` pushes `arguments` onto `.queue` until the real script
|
|
151
|
-
* lands and replaces `.process`.
|
|
152
|
-
* - `.t` must be a `Date.now()` timestamp.
|
|
153
|
-
* - The tag is inserted async, `src` cache-busted every 24h via
|
|
154
|
-
* `Math.ceil(Date.now() / cacheTime) * cacheTime`.
|
|
155
|
-
*/
|
|
156
|
-
/** Config accepted by the CDN pixel. */
|
|
157
|
-
interface PreprPixelConfig {
|
|
158
|
-
destinations?: {
|
|
159
|
-
googleTagManager?: boolean;
|
|
160
|
-
};
|
|
161
|
-
variantImpressionThreshold?: number;
|
|
162
|
-
}
|
|
163
|
-
type PreprQueueArgs = unknown[];
|
|
164
|
-
interface PreprQueueFn {
|
|
165
|
-
(...args: PreprQueueArgs): void;
|
|
166
|
-
queue: PreprQueueArgs[];
|
|
167
|
-
t: number;
|
|
168
|
-
process?: (...args: PreprQueueArgs) => void;
|
|
169
|
-
}
|
|
170
|
-
declare global {
|
|
171
|
-
interface Window {
|
|
172
|
-
prepr?: PreprQueueFn;
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
/**
|
|
176
|
-
* Install the queue stub, inject the pixel script, then queue
|
|
177
|
-
* `('init', trackingId, config?)` and `('event', 'pageload')` in that order.
|
|
178
|
-
*
|
|
179
|
-
* Idempotent, and a no-op outside a browser.
|
|
180
|
-
*/
|
|
181
|
-
declare function loadTrackingPixel(trackingId: string, config?: PreprPixelConfig): void;
|
|
182
|
-
/**
|
|
183
|
-
* Send a tracking event through `window.prepr`. Only depends on `window.prepr`
|
|
184
|
-
* existing, never on how it got installed. Warns once and returns quietly when
|
|
185
|
-
* no pixel is present.
|
|
186
|
-
*/
|
|
187
|
-
declare function trackEvent(name: string, data?: string | Record<string, unknown>): void;
|
|
188
|
-
/** Loader-independent like `trackEvent`; warns once if no pixel is installed. */
|
|
189
|
-
declare function setTrackingParam(key: string, value: string): void;
|
|
135
|
+
type PreprErrorCode = 'INVALID_TOKEN' | 'MISSING_TOKEN' | 'HTTP_ERROR' | 'FETCH_ERROR' | 'INVALID_RESPONSE' | 'CONTEXT_ERROR' | 'GRAPHQL_ERROR' | 'INVALID_DOCUMENT';
|
|
190
136
|
|
|
191
|
-
export {
|
|
137
|
+
export type { Locale as L, PreprHeaders as P, ResolvedPreprFeatures as R, PreprErrorCode as a, PreprFeatures as b, PreprSegment as c, PreprVariant as d, PreprToolbarProps as e, PreprPreviewOptions as f, PreprEnvironment as g, PreprEventType as h, PreprFeatureConfig as i, PreprHeaderName as j, PreprToolbarComponentProps as k, PreprToolbarOptions as l };
|
|
@@ -64,14 +64,8 @@ interface PreprPreviewOptions extends PreprToolbarOptions {
|
|
|
64
64
|
*/
|
|
65
65
|
ui?: boolean;
|
|
66
66
|
/**
|
|
67
|
-
* Replace the `*.prepr.io` editor-origin wildcard with an exact list
|
|
68
|
-
*
|
|
69
|
-
* editors; when set, the wildcard no longer applies. Entries are compared to
|
|
70
|
-
* the editor's origin exactly: scheme, host and port.
|
|
71
|
-
*
|
|
72
|
-
* `['*']` accepts any editor origin. Use it for development only: any page
|
|
73
|
-
* that frames the preview can then switch on preview and edit mode and
|
|
74
|
-
* receives the field-edit events, which carry content item ids.
|
|
67
|
+
* Replace the `*.prepr.io` editor-origin wildcard with an exact list.
|
|
68
|
+
* Intended for self-hosted editors; when set, the wildcard no longer applies.
|
|
75
69
|
*/
|
|
76
70
|
allowedEditorOrigins?: string[];
|
|
77
71
|
/**
|
|
@@ -138,54 +132,6 @@ interface PreprHeaders {
|
|
|
138
132
|
readonly 'Prepr-User-Agent'?: string;
|
|
139
133
|
readonly 'Prepr-Package'?: string;
|
|
140
134
|
}
|
|
141
|
-
type PreprErrorCode = 'INVALID_TOKEN' | 'MISSING_TOKEN' | 'HTTP_ERROR' | 'FETCH_ERROR' | 'INVALID_RESPONSE' | 'CONTEXT_ERROR';
|
|
142
|
-
|
|
143
|
-
/**
|
|
144
|
-
* Loader + typed facade for Prepr's CDN tracking pixel, so consumers don't have
|
|
145
|
-
* to paste a `<script>` tag. The pixel itself lives on the CDN; this only sets
|
|
146
|
-
* up the handoff.
|
|
147
|
-
*
|
|
148
|
-
* The CDN script expects a queue stub to already exist when it loads, so the
|
|
149
|
-
* contract must be reproduced exactly:
|
|
150
|
-
* - `window.prepr` pushes `arguments` onto `.queue` until the real script
|
|
151
|
-
* lands and replaces `.process`.
|
|
152
|
-
* - `.t` must be a `Date.now()` timestamp.
|
|
153
|
-
* - The tag is inserted async, `src` cache-busted every 24h via
|
|
154
|
-
* `Math.ceil(Date.now() / cacheTime) * cacheTime`.
|
|
155
|
-
*/
|
|
156
|
-
/** Config accepted by the CDN pixel. */
|
|
157
|
-
interface PreprPixelConfig {
|
|
158
|
-
destinations?: {
|
|
159
|
-
googleTagManager?: boolean;
|
|
160
|
-
};
|
|
161
|
-
variantImpressionThreshold?: number;
|
|
162
|
-
}
|
|
163
|
-
type PreprQueueArgs = unknown[];
|
|
164
|
-
interface PreprQueueFn {
|
|
165
|
-
(...args: PreprQueueArgs): void;
|
|
166
|
-
queue: PreprQueueArgs[];
|
|
167
|
-
t: number;
|
|
168
|
-
process?: (...args: PreprQueueArgs) => void;
|
|
169
|
-
}
|
|
170
|
-
declare global {
|
|
171
|
-
interface Window {
|
|
172
|
-
prepr?: PreprQueueFn;
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
/**
|
|
176
|
-
* Install the queue stub, inject the pixel script, then queue
|
|
177
|
-
* `('init', trackingId, config?)` and `('event', 'pageload')` in that order.
|
|
178
|
-
*
|
|
179
|
-
* Idempotent, and a no-op outside a browser.
|
|
180
|
-
*/
|
|
181
|
-
declare function loadTrackingPixel(trackingId: string, config?: PreprPixelConfig): void;
|
|
182
|
-
/**
|
|
183
|
-
* Send a tracking event through `window.prepr`. Only depends on `window.prepr`
|
|
184
|
-
* existing, never on how it got installed. Warns once and returns quietly when
|
|
185
|
-
* no pixel is present.
|
|
186
|
-
*/
|
|
187
|
-
declare function trackEvent(name: string, data?: string | Record<string, unknown>): void;
|
|
188
|
-
/** Loader-independent like `trackEvent`; warns once if no pixel is installed. */
|
|
189
|
-
declare function setTrackingParam(key: string, value: string): void;
|
|
135
|
+
type PreprErrorCode = 'INVALID_TOKEN' | 'MISSING_TOKEN' | 'HTTP_ERROR' | 'FETCH_ERROR' | 'INVALID_RESPONSE' | 'CONTEXT_ERROR' | 'GRAPHQL_ERROR' | 'INVALID_DOCUMENT';
|
|
190
136
|
|
|
191
|
-
export {
|
|
137
|
+
export type { Locale as L, PreprHeaders as P, ResolvedPreprFeatures as R, PreprErrorCode as a, PreprFeatures as b, PreprSegment as c, PreprVariant as d, PreprToolbarProps as e, PreprPreviewOptions as f, PreprEnvironment as g, PreprEventType as h, PreprFeatureConfig as i, PreprHeaderName as j, PreprToolbarComponentProps as k, PreprToolbarOptions as l };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@preprio/toolkit",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0-alpha.1",
|
|
4
4
|
"description": "Prepr personalization, A/B testing and preview toolkit for React, Next.js, Nuxt, Astro, SvelteKit and Express",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"author": "Prepr B.V. (https://prepr.io)",
|
|
@@ -39,6 +39,16 @@
|
|
|
39
39
|
"import": "./dist/index.js",
|
|
40
40
|
"require": "./dist/index.cjs"
|
|
41
41
|
},
|
|
42
|
+
"./graphql": {
|
|
43
|
+
"types": "./dist/graphql.d.ts",
|
|
44
|
+
"import": "./dist/graphql.js",
|
|
45
|
+
"require": "./dist/graphql.cjs"
|
|
46
|
+
},
|
|
47
|
+
"./graphql/codegen": {
|
|
48
|
+
"types": "./dist/graphql/codegen.d.ts",
|
|
49
|
+
"import": "./dist/graphql/codegen.js",
|
|
50
|
+
"require": "./dist/graphql/codegen.cjs"
|
|
51
|
+
},
|
|
42
52
|
"./react": {
|
|
43
53
|
"types": "./dist/react/index.d.ts",
|
|
44
54
|
"import": "./dist/react/index.js",
|
|
@@ -54,6 +64,11 @@
|
|
|
54
64
|
"import": "./dist/nextjs/index.js",
|
|
55
65
|
"require": "./dist/nextjs/index.cjs"
|
|
56
66
|
},
|
|
67
|
+
"./nextjs/graphql": {
|
|
68
|
+
"types": "./dist/nextjs/graphql.d.ts",
|
|
69
|
+
"import": "./dist/nextjs/graphql.js",
|
|
70
|
+
"require": "./dist/nextjs/graphql.cjs"
|
|
71
|
+
},
|
|
57
72
|
"./json-script": {
|
|
58
73
|
"types": "./dist/json-script.d.ts",
|
|
59
74
|
"import": "./dist/json-script.js",
|
|
@@ -74,18 +89,33 @@
|
|
|
74
89
|
"import": "./dist/astro/index.js",
|
|
75
90
|
"require": "./dist/astro/index.cjs"
|
|
76
91
|
},
|
|
92
|
+
"./astro/graphql": {
|
|
93
|
+
"types": "./dist/astro/graphql.d.ts",
|
|
94
|
+
"import": "./dist/astro/graphql.js",
|
|
95
|
+
"require": "./dist/astro/graphql.cjs"
|
|
96
|
+
},
|
|
77
97
|
"./astro/components/*": "./src/astro/*.astro",
|
|
78
98
|
"./sveltekit": {
|
|
79
99
|
"types": "./dist/sveltekit/index.d.ts",
|
|
80
100
|
"import": "./dist/sveltekit/index.js",
|
|
81
101
|
"require": "./dist/sveltekit/index.cjs"
|
|
82
102
|
},
|
|
103
|
+
"./sveltekit/graphql": {
|
|
104
|
+
"types": "./dist/sveltekit/graphql.d.ts",
|
|
105
|
+
"import": "./dist/sveltekit/graphql.js",
|
|
106
|
+
"require": "./dist/sveltekit/graphql.cjs"
|
|
107
|
+
},
|
|
83
108
|
"./sveltekit/components/*": "./src/sveltekit/*.svelte",
|
|
84
109
|
"./nuxt": {
|
|
85
110
|
"types": "./dist/nuxt/index.d.ts",
|
|
86
111
|
"import": "./dist/nuxt/index.js",
|
|
87
112
|
"require": "./dist/nuxt/index.cjs"
|
|
88
113
|
},
|
|
114
|
+
"./nuxt/graphql": {
|
|
115
|
+
"types": "./dist/nuxt/graphql.d.ts",
|
|
116
|
+
"import": "./dist/nuxt/graphql.js",
|
|
117
|
+
"require": "./dist/nuxt/graphql.cjs"
|
|
118
|
+
},
|
|
89
119
|
"./nuxt/components/*": "./src/nuxt/*.vue"
|
|
90
120
|
},
|
|
91
121
|
"files": [
|
|
@@ -109,6 +139,7 @@
|
|
|
109
139
|
"preact": "^10.29.7"
|
|
110
140
|
},
|
|
111
141
|
"peerDependencies": {
|
|
142
|
+
"graphql": ">=16",
|
|
112
143
|
"next": ">=13",
|
|
113
144
|
"react": ">=17",
|
|
114
145
|
"react-dom": ">=17",
|
|
@@ -116,6 +147,9 @@
|
|
|
116
147
|
"vue": ">=3.3"
|
|
117
148
|
},
|
|
118
149
|
"peerDependenciesMeta": {
|
|
150
|
+
"graphql": {
|
|
151
|
+
"optional": true
|
|
152
|
+
},
|
|
119
153
|
"next": {
|
|
120
154
|
"optional": true
|
|
121
155
|
},
|
|
@@ -137,6 +171,7 @@
|
|
|
137
171
|
"@types/react": "^19.2.17",
|
|
138
172
|
"@types/react-dom": "^19.2.3",
|
|
139
173
|
"browserslist": "^4.28.7",
|
|
174
|
+
"graphql": "^16.14.2",
|
|
140
175
|
"happy-dom": "^20.11.1",
|
|
141
176
|
"lightningcss": "^1.33.0",
|
|
142
177
|
"next": "^16.2.12",
|