@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,130 @@
|
|
|
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
|
+
* Whether a Prepr GraphQL response differs per visitor, read from its `Vary`
|
|
85
|
+
* header. Use it when fetching with your own GraphQL client; the toolkit's
|
|
86
|
+
* `createPreprClient` already returns it as `personalized`.
|
|
87
|
+
*
|
|
88
|
+
* Never throws; a response without `Vary` is not personalized.
|
|
89
|
+
*/
|
|
90
|
+
declare function isPersonalizedResponse(source: Response | Headers): boolean;
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Structural stand-in for Astro's `APIContext`, so this package needs no
|
|
94
|
+
* build-time dependency on `astro`. Only the fields `onPreprRequest` uses.
|
|
95
|
+
*/
|
|
96
|
+
interface AstroLikeContext {
|
|
97
|
+
request: Request;
|
|
98
|
+
/** Unused; typed loosely so passing the real Astro context still checks. */
|
|
99
|
+
cookies?: unknown;
|
|
100
|
+
}
|
|
101
|
+
/** Astro middleware's `next()` — resolves to the `Response` from downstream. */
|
|
102
|
+
type AstroNext = () => Promise<Response>;
|
|
103
|
+
/**
|
|
104
|
+
* Astro middleware entry point: computes the Prepr headers/cookies for this
|
|
105
|
+
* request, forwards the headers downstream and sets the cookies on the response.
|
|
106
|
+
*
|
|
107
|
+
* Astro hands downstream code the same `Request` instance this middleware receives, so the
|
|
108
|
+
* headers are mutated in place — building a new `Request` would go nowhere,
|
|
109
|
+
* there's no way to hand a replacement back out of middleware.
|
|
110
|
+
*/
|
|
111
|
+
declare function onPreprRequest(context: AstroLikeContext, next: AstroNext, options?: PreprMiddlewareOptions): Promise<Response>;
|
|
112
|
+
/** Prepr Customer ID for this request, from `Astro.request.headers`. */
|
|
113
|
+
declare function getPreprUUID(headers: Headers): string | null;
|
|
114
|
+
/** Active segment for this request, from `Astro.request.headers`. */
|
|
115
|
+
declare function getActiveSegment(headers: Headers): string | null;
|
|
116
|
+
/** Active A/B variant for this request, from `Astro.request.headers`. */
|
|
117
|
+
declare function getActiveVariant(headers: Headers): string | null;
|
|
118
|
+
/** All Prepr headers for this request, from `Astro.request.headers`. */
|
|
119
|
+
declare function getPreprHeaders(headers: Headers): PreprHeaders;
|
|
120
|
+
/**
|
|
121
|
+
* Props needed to mount `PreprToolbar.astro`, from `Astro.request.headers`
|
|
122
|
+
* plus a Prepr GraphQL token.
|
|
123
|
+
*
|
|
124
|
+
* Ungated: call it only when your app is in preview mode. Resolve that however
|
|
125
|
+
* your deployment already does — the toolkit reads no environment variables of
|
|
126
|
+
* its own.
|
|
127
|
+
*/
|
|
128
|
+
declare function getToolbarProps(headers: Headers, token: string, features?: PreprFeatures): Promise<PreprToolbarProps>;
|
|
129
|
+
|
|
130
|
+
export { type AstroLikeContext as A, type PreprHeaders as P, type PreprErrorCode as a, type AstroNext as b, type PreprMiddlewareOptions as c, getActiveVariant as d, getPreprHeaders as e, getPreprUUID as f, getActiveSegment as g, getToolbarProps as h, isPersonalizedResponse as i, onPreprRequest as o };
|
|
@@ -0,0 +1,130 @@
|
|
|
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
|
+
* Whether a Prepr GraphQL response differs per visitor, read from its `Vary`
|
|
85
|
+
* header. Use it when fetching with your own GraphQL client; the toolkit's
|
|
86
|
+
* `createPreprClient` already returns it as `personalized`.
|
|
87
|
+
*
|
|
88
|
+
* Never throws; a response without `Vary` is not personalized.
|
|
89
|
+
*/
|
|
90
|
+
declare function isPersonalizedResponse(source: Response | Headers): boolean;
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Structural stand-in for Astro's `APIContext`, so this package needs no
|
|
94
|
+
* build-time dependency on `astro`. Only the fields `onPreprRequest` uses.
|
|
95
|
+
*/
|
|
96
|
+
interface AstroLikeContext {
|
|
97
|
+
request: Request;
|
|
98
|
+
/** Unused; typed loosely so passing the real Astro context still checks. */
|
|
99
|
+
cookies?: unknown;
|
|
100
|
+
}
|
|
101
|
+
/** Astro middleware's `next()` — resolves to the `Response` from downstream. */
|
|
102
|
+
type AstroNext = () => Promise<Response>;
|
|
103
|
+
/**
|
|
104
|
+
* Astro middleware entry point: computes the Prepr headers/cookies for this
|
|
105
|
+
* request, forwards the headers downstream and sets the cookies on the response.
|
|
106
|
+
*
|
|
107
|
+
* Astro hands downstream code the same `Request` instance this middleware receives, so the
|
|
108
|
+
* headers are mutated in place — building a new `Request` would go nowhere,
|
|
109
|
+
* there's no way to hand a replacement back out of middleware.
|
|
110
|
+
*/
|
|
111
|
+
declare function onPreprRequest(context: AstroLikeContext, next: AstroNext, options?: PreprMiddlewareOptions): Promise<Response>;
|
|
112
|
+
/** Prepr Customer ID for this request, from `Astro.request.headers`. */
|
|
113
|
+
declare function getPreprUUID(headers: Headers): string | null;
|
|
114
|
+
/** Active segment for this request, from `Astro.request.headers`. */
|
|
115
|
+
declare function getActiveSegment(headers: Headers): string | null;
|
|
116
|
+
/** Active A/B variant for this request, from `Astro.request.headers`. */
|
|
117
|
+
declare function getActiveVariant(headers: Headers): string | null;
|
|
118
|
+
/** All Prepr headers for this request, from `Astro.request.headers`. */
|
|
119
|
+
declare function getPreprHeaders(headers: Headers): PreprHeaders;
|
|
120
|
+
/**
|
|
121
|
+
* Props needed to mount `PreprToolbar.astro`, from `Astro.request.headers`
|
|
122
|
+
* plus a Prepr GraphQL token.
|
|
123
|
+
*
|
|
124
|
+
* Ungated: call it only when your app is in preview mode. Resolve that however
|
|
125
|
+
* your deployment already does — the toolkit reads no environment variables of
|
|
126
|
+
* its own.
|
|
127
|
+
*/
|
|
128
|
+
declare function getToolbarProps(headers: Headers, token: string, features?: PreprFeatures): Promise<PreprToolbarProps>;
|
|
129
|
+
|
|
130
|
+
export { type AstroLikeContext as A, type PreprHeaders as P, type PreprErrorCode as a, type AstroNext as b, type PreprMiddlewareOptions as c, getActiveVariant as d, getPreprHeaders as e, getPreprUUID as f, getActiveSegment as g, getToolbarProps as h, isPersonalizedResponse as i, onPreprRequest as o };
|
package/dist/astro/index.cjs
CHANGED
|
@@ -25,12 +25,13 @@ __export(astro_exports, {
|
|
|
25
25
|
getPreprHeaders: () => getPreprHeaders,
|
|
26
26
|
getPreprUUID: () => getPreprUUID,
|
|
27
27
|
getToolbarProps: () => getToolbarProps,
|
|
28
|
+
isPersonalizedResponse: () => isPersonalizedResponse,
|
|
28
29
|
onPreprRequest: () => onPreprRequest
|
|
29
30
|
});
|
|
30
31
|
module.exports = __toCommonJS(astro_exports);
|
|
31
32
|
|
|
32
33
|
// src/version.ts
|
|
33
|
-
var VERSION = "0.
|
|
34
|
+
var VERSION = "0.6.0-alpha.1";
|
|
34
35
|
|
|
35
36
|
// src/core/features.ts
|
|
36
37
|
function isEnabled(config) {
|
|
@@ -357,9 +358,20 @@ function processFrameworkRequest(request, opts, framework) {
|
|
|
357
358
|
});
|
|
358
359
|
}
|
|
359
360
|
}
|
|
361
|
+
if (requestHeaders.has("Prepr-Segments")) {
|
|
362
|
+
requestHeaders.delete("Prepr-Customer-Id");
|
|
363
|
+
requestHeaders.delete("Prepr-Customer-Id-Created");
|
|
364
|
+
}
|
|
360
365
|
return { requestHeaders, responseCookies };
|
|
361
366
|
}
|
|
362
367
|
|
|
368
|
+
// src/core/personalization.ts
|
|
369
|
+
var PERSONALIZED_VARY = /\bPrepr-(Segments|ABTesting)/i;
|
|
370
|
+
function isPersonalizedResponse(source) {
|
|
371
|
+
const headers = "headers" in source ? source.headers : source;
|
|
372
|
+
return PERSONALIZED_VARY.test(headers.get("vary") ?? "");
|
|
373
|
+
}
|
|
374
|
+
|
|
363
375
|
// src/astro/index.ts
|
|
364
376
|
async function onPreprRequest(context, next, options) {
|
|
365
377
|
const { requestHeaders, responseCookies } = processFrameworkRequest(
|
|
@@ -398,5 +410,6 @@ async function getToolbarProps(headers, token, features) {
|
|
|
398
410
|
getPreprHeaders,
|
|
399
411
|
getPreprUUID,
|
|
400
412
|
getToolbarProps,
|
|
413
|
+
isPersonalizedResponse,
|
|
401
414
|
onPreprRequest
|
|
402
415
|
});
|
package/dist/astro/index.d.cts
CHANGED
|
@@ -1,120 +1 @@
|
|
|
1
|
-
|
|
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
|
-
|
|
69
|
-
interface PreprMiddlewareOptions {
|
|
70
|
-
/** Enable preview-mode headers (segment/AB overrides, preview bar). */
|
|
71
|
-
preview?: boolean;
|
|
72
|
-
/**
|
|
73
|
-
* Disable features app-wide. Pass the same object you give the toolbar: a
|
|
74
|
-
* disabled feature injects no header and persists no cookie, whatever the
|
|
75
|
-
* request carries.
|
|
76
|
-
*/
|
|
77
|
-
features?: PreprFeatures;
|
|
78
|
-
/** Override the version reported in Prepr-Package (mainly for tests). */
|
|
79
|
-
version?: string;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
/**
|
|
83
|
-
* Structural stand-in for Astro's `APIContext`, so this package needs no
|
|
84
|
-
* build-time dependency on `astro`. Only the fields `onPreprRequest` uses.
|
|
85
|
-
*/
|
|
86
|
-
interface AstroLikeContext {
|
|
87
|
-
request: Request;
|
|
88
|
-
/** Unused; typed loosely so passing the real Astro context still checks. */
|
|
89
|
-
cookies?: unknown;
|
|
90
|
-
}
|
|
91
|
-
/** Astro middleware's `next()` — resolves to the `Response` from downstream. */
|
|
92
|
-
type AstroNext = () => Promise<Response>;
|
|
93
|
-
/**
|
|
94
|
-
* Astro middleware entry point: computes the Prepr headers/cookies for this
|
|
95
|
-
* request, forwards the headers downstream and sets the cookies on the response.
|
|
96
|
-
*
|
|
97
|
-
* Astro hands downstream code the same `Request` instance this middleware receives, so the
|
|
98
|
-
* headers are mutated in place — building a new `Request` would go nowhere,
|
|
99
|
-
* there's no way to hand a replacement back out of middleware.
|
|
100
|
-
*/
|
|
101
|
-
declare function onPreprRequest(context: AstroLikeContext, next: AstroNext, options?: PreprMiddlewareOptions): Promise<Response>;
|
|
102
|
-
/** Prepr Customer ID for this request, from `Astro.request.headers`. */
|
|
103
|
-
declare function getPreprUUID(headers: Headers): string | null;
|
|
104
|
-
/** Active segment for this request, from `Astro.request.headers`. */
|
|
105
|
-
declare function getActiveSegment(headers: Headers): string | null;
|
|
106
|
-
/** Active A/B variant for this request, from `Astro.request.headers`. */
|
|
107
|
-
declare function getActiveVariant(headers: Headers): string | null;
|
|
108
|
-
/** All Prepr headers for this request, from `Astro.request.headers`. */
|
|
109
|
-
declare function getPreprHeaders(headers: Headers): PreprHeaders;
|
|
110
|
-
/**
|
|
111
|
-
* Props needed to mount `PreprToolbar.astro`, from `Astro.request.headers`
|
|
112
|
-
* plus a Prepr GraphQL token.
|
|
113
|
-
*
|
|
114
|
-
* Ungated: call it only when your app is in preview mode. Resolve that however
|
|
115
|
-
* your deployment already does — the toolkit reads no environment variables of
|
|
116
|
-
* its own.
|
|
117
|
-
*/
|
|
118
|
-
declare function getToolbarProps(headers: Headers, token: string, features?: PreprFeatures): Promise<PreprToolbarProps>;
|
|
119
|
-
|
|
120
|
-
export { type AstroLikeContext, type AstroNext, type PreprMiddlewareOptions, getActiveSegment, getActiveVariant, getPreprHeaders, getPreprUUID, getToolbarProps, onPreprRequest };
|
|
1
|
+
export { A as AstroLikeContext, b as AstroNext, c as PreprMiddlewareOptions, g as getActiveSegment, d as getActiveVariant, e as getPreprHeaders, f as getPreprUUID, h as getToolbarProps, i as isPersonalizedResponse, o as onPreprRequest } from './index-XT_z-RYT.cjs';
|
package/dist/astro/index.d.ts
CHANGED
|
@@ -1,120 +1 @@
|
|
|
1
|
-
|
|
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
|
-
|
|
69
|
-
interface PreprMiddlewareOptions {
|
|
70
|
-
/** Enable preview-mode headers (segment/AB overrides, preview bar). */
|
|
71
|
-
preview?: boolean;
|
|
72
|
-
/**
|
|
73
|
-
* Disable features app-wide. Pass the same object you give the toolbar: a
|
|
74
|
-
* disabled feature injects no header and persists no cookie, whatever the
|
|
75
|
-
* request carries.
|
|
76
|
-
*/
|
|
77
|
-
features?: PreprFeatures;
|
|
78
|
-
/** Override the version reported in Prepr-Package (mainly for tests). */
|
|
79
|
-
version?: string;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
/**
|
|
83
|
-
* Structural stand-in for Astro's `APIContext`, so this package needs no
|
|
84
|
-
* build-time dependency on `astro`. Only the fields `onPreprRequest` uses.
|
|
85
|
-
*/
|
|
86
|
-
interface AstroLikeContext {
|
|
87
|
-
request: Request;
|
|
88
|
-
/** Unused; typed loosely so passing the real Astro context still checks. */
|
|
89
|
-
cookies?: unknown;
|
|
90
|
-
}
|
|
91
|
-
/** Astro middleware's `next()` — resolves to the `Response` from downstream. */
|
|
92
|
-
type AstroNext = () => Promise<Response>;
|
|
93
|
-
/**
|
|
94
|
-
* Astro middleware entry point: computes the Prepr headers/cookies for this
|
|
95
|
-
* request, forwards the headers downstream and sets the cookies on the response.
|
|
96
|
-
*
|
|
97
|
-
* Astro hands downstream code the same `Request` instance this middleware receives, so the
|
|
98
|
-
* headers are mutated in place — building a new `Request` would go nowhere,
|
|
99
|
-
* there's no way to hand a replacement back out of middleware.
|
|
100
|
-
*/
|
|
101
|
-
declare function onPreprRequest(context: AstroLikeContext, next: AstroNext, options?: PreprMiddlewareOptions): Promise<Response>;
|
|
102
|
-
/** Prepr Customer ID for this request, from `Astro.request.headers`. */
|
|
103
|
-
declare function getPreprUUID(headers: Headers): string | null;
|
|
104
|
-
/** Active segment for this request, from `Astro.request.headers`. */
|
|
105
|
-
declare function getActiveSegment(headers: Headers): string | null;
|
|
106
|
-
/** Active A/B variant for this request, from `Astro.request.headers`. */
|
|
107
|
-
declare function getActiveVariant(headers: Headers): string | null;
|
|
108
|
-
/** All Prepr headers for this request, from `Astro.request.headers`. */
|
|
109
|
-
declare function getPreprHeaders(headers: Headers): PreprHeaders;
|
|
110
|
-
/**
|
|
111
|
-
* Props needed to mount `PreprToolbar.astro`, from `Astro.request.headers`
|
|
112
|
-
* plus a Prepr GraphQL token.
|
|
113
|
-
*
|
|
114
|
-
* Ungated: call it only when your app is in preview mode. Resolve that however
|
|
115
|
-
* your deployment already does — the toolkit reads no environment variables of
|
|
116
|
-
* its own.
|
|
117
|
-
*/
|
|
118
|
-
declare function getToolbarProps(headers: Headers, token: string, features?: PreprFeatures): Promise<PreprToolbarProps>;
|
|
119
|
-
|
|
120
|
-
export { type AstroLikeContext, type AstroNext, type PreprMiddlewareOptions, getActiveSegment, getActiveVariant, getPreprHeaders, getPreprUUID, getToolbarProps, onPreprRequest };
|
|
1
|
+
export { A as AstroLikeContext, b as AstroNext, c as PreprMiddlewareOptions, g as getActiveSegment, d as getActiveVariant, e as getPreprHeaders, f as getPreprUUID, h as getToolbarProps, i as isPersonalizedResponse, o as onPreprRequest } from './index-XT_z-RYT.js';
|