@preprio/toolkit 0.5.0-rc.1 → 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.
Files changed (69) hide show
  1. package/README.md +300 -19
  2. package/dist/astro/chunk-3UVUDDNY.js +173 -0
  3. package/dist/astro/graphql.cjs +983 -0
  4. package/dist/astro/graphql.d.cts +231 -0
  5. package/dist/astro/graphql.d.ts +231 -0
  6. package/dist/astro/graphql.js +893 -0
  7. package/dist/astro/index-XT_z-RYT.d.cts +130 -0
  8. package/dist/astro/index-XT_z-RYT.d.ts +130 -0
  9. package/dist/astro/index.cjs +14 -1
  10. package/dist/astro/index.d.cts +1 -120
  11. package/dist/astro/index.d.ts +1 -120
  12. package/dist/astro/index.js +15 -153
  13. package/dist/{chunk-4JNKYIEV.js → chunk-BJ2LBLWO.js} +69 -268
  14. package/dist/chunk-DGZA7KX7.js +172 -0
  15. package/dist/chunk-YR7P4IWE.js +187 -0
  16. package/dist/graphql.cjs +894 -0
  17. package/dist/graphql.d.cts +231 -0
  18. package/dist/graphql.d.ts +231 -0
  19. package/dist/graphql.js +787 -0
  20. package/dist/index.cjs +74 -111
  21. package/dist/index.d.cts +11 -62
  22. package/dist/index.d.ts +11 -62
  23. package/dist/index.js +23 -167
  24. package/dist/nextjs/chunk-U4HXENF7.js +231 -0
  25. package/dist/nextjs/components.cjs +188 -114
  26. package/dist/nextjs/components.d.cts +33 -2
  27. package/dist/nextjs/components.d.ts +33 -2
  28. package/dist/nextjs/components.js +132 -4
  29. package/dist/nextjs/graphql.cjs +1315 -0
  30. package/dist/nextjs/graphql.d.cts +361 -0
  31. package/dist/nextjs/graphql.d.ts +361 -0
  32. package/dist/nextjs/graphql.js +1218 -0
  33. package/dist/nextjs/index.cjs +126 -6
  34. package/dist/nextjs/index.d.cts +53 -141
  35. package/dist/nextjs/index.d.ts +53 -141
  36. package/dist/nextjs/index.js +113 -203
  37. package/dist/nextjs/server-CjpELYvq.d.cts +156 -0
  38. package/dist/nextjs/server-CjpELYvq.d.ts +156 -0
  39. package/dist/nuxt/chunk-P6ENNAEE.js +417 -0
  40. package/dist/nuxt/graphql.cjs +990 -0
  41. package/dist/nuxt/graphql.d.cts +228 -0
  42. package/dist/nuxt/graphql.d.ts +228 -0
  43. package/dist/nuxt/graphql.js +894 -0
  44. package/dist/nuxt/index.cjs +14 -1
  45. package/dist/nuxt/index.d.cts +3 -148
  46. package/dist/nuxt/index.d.ts +3 -148
  47. package/dist/nuxt/index.js +15 -391
  48. package/dist/nuxt/server-8v6OHbsw.d.cts +158 -0
  49. package/dist/nuxt/server-8v6OHbsw.d.ts +158 -0
  50. package/dist/pixel-DwW7cXJm.d.cts +49 -0
  51. package/dist/pixel-DwW7cXJm.d.ts +49 -0
  52. package/dist/react/components.cjs +86 -112
  53. package/dist/react/components.js +86 -112
  54. package/dist/server-Brr1UgtW.d.ts +59 -0
  55. package/dist/server-DJuS3YU0.d.cts +59 -0
  56. package/dist/sveltekit/chunk-FSARVMG5.js +413 -0
  57. package/dist/sveltekit/graphql.cjs +996 -0
  58. package/dist/sveltekit/graphql.d.cts +233 -0
  59. package/dist/sveltekit/graphql.d.ts +233 -0
  60. package/dist/sveltekit/graphql.js +900 -0
  61. package/dist/sveltekit/index.cjs +14 -1
  62. package/dist/sveltekit/index.d.cts +3 -88
  63. package/dist/sveltekit/index.d.ts +3 -88
  64. package/dist/sveltekit/index.js +15 -387
  65. package/dist/sveltekit/server-CO847mEV.d.cts +98 -0
  66. package/dist/sveltekit/server-CO847mEV.d.ts +98 -0
  67. package/dist/{pixel-e1fUWl2Y.d.cts → types-BYH9XqmN.d.cts} +2 -50
  68. package/dist/{pixel-e1fUWl2Y.d.ts → types-BYH9XqmN.d.ts} +2 -50
  69. package/package.json +31 -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 };
@@ -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.5.0-rc.1";
34
+ var VERSION = "0.6.0-alpha.0";
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
  });
@@ -1,120 +1 @@
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
-
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';
@@ -1,120 +1 @@
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
-
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';