@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
package/dist/nextjs/index.cjs
CHANGED
|
@@ -20,9 +20,11 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
20
20
|
// src/nextjs/index.ts
|
|
21
21
|
var nextjs_exports = {};
|
|
22
22
|
__export(nextjs_exports, {
|
|
23
|
+
PREPR_BUCKET_COOKIE: () => PREPR_BUCKET_COOKIE,
|
|
23
24
|
PreprError: () => PreprError,
|
|
24
25
|
PreprToolbar: () => import_components.PreprToolbar,
|
|
25
26
|
PreprTrackingPixel: () => import_components.PreprTrackingPixel,
|
|
27
|
+
createPreprDraftRoute: () => createPreprDraftRoute,
|
|
26
28
|
createPreprMiddleware: () => createPreprMiddleware,
|
|
27
29
|
extractAccessToken: () => extractAccessToken,
|
|
28
30
|
getActiveSegment: () => getActiveSegment,
|
|
@@ -30,6 +32,9 @@ __export(nextjs_exports, {
|
|
|
30
32
|
getPreprHeaders: () => getPreprHeaders,
|
|
31
33
|
getPreprUUID: () => getPreprUUID,
|
|
32
34
|
getToolbarProps: () => getToolbarProps,
|
|
35
|
+
isPersonalizedResponse: () => isPersonalizedResponse,
|
|
36
|
+
preprDraftRedirect: () => preprDraftRedirect,
|
|
37
|
+
resolvePreprBucket: () => resolvePreprBucket,
|
|
33
38
|
validatePreprToken: () => validatePreprToken
|
|
34
39
|
});
|
|
35
40
|
module.exports = __toCommonJS(nextjs_exports);
|
|
@@ -38,7 +43,7 @@ module.exports = __toCommonJS(nextjs_exports);
|
|
|
38
43
|
var import_server = require("next/server");
|
|
39
44
|
|
|
40
45
|
// src/version.ts
|
|
41
|
-
var VERSION = "0.
|
|
46
|
+
var VERSION = "0.6.0-alpha.0";
|
|
42
47
|
|
|
43
48
|
// src/core/constants.ts
|
|
44
49
|
var COOKIE_PREVIEW_MODE = "Prepr-Preview-Mode";
|
|
@@ -83,9 +88,9 @@ function sanitizeHeaderValue(value) {
|
|
|
83
88
|
return stripped.length > MAX_HEADER_VALUE_LENGTH ? stripped.slice(0, MAX_HEADER_VALUE_LENGTH) : stripped;
|
|
84
89
|
}
|
|
85
90
|
function parseCookies(request) {
|
|
86
|
-
const
|
|
91
|
+
const cookies2 = /* @__PURE__ */ new Map();
|
|
87
92
|
const header = request.headers.get("cookie");
|
|
88
|
-
if (!header) return
|
|
93
|
+
if (!header) return cookies2;
|
|
89
94
|
for (const part of header.split(";")) {
|
|
90
95
|
const eq = part.indexOf("=");
|
|
91
96
|
if (eq === -1) continue;
|
|
@@ -93,12 +98,12 @@ function parseCookies(request) {
|
|
|
93
98
|
const value = part.slice(eq + 1).trim();
|
|
94
99
|
if (!name) continue;
|
|
95
100
|
try {
|
|
96
|
-
|
|
101
|
+
cookies2.set(name, decodeURIComponent(value));
|
|
97
102
|
} catch {
|
|
98
|
-
|
|
103
|
+
cookies2.set(name, value);
|
|
99
104
|
}
|
|
100
105
|
}
|
|
101
|
-
return
|
|
106
|
+
return cookies2;
|
|
102
107
|
}
|
|
103
108
|
function processFrameworkRequest(request, opts, framework) {
|
|
104
109
|
const requestHeaders = new Headers(request.headers);
|
|
@@ -218,6 +223,10 @@ function processFrameworkRequest(request, opts, framework) {
|
|
|
218
223
|
});
|
|
219
224
|
}
|
|
220
225
|
}
|
|
226
|
+
if (requestHeaders.has("Prepr-Segments")) {
|
|
227
|
+
requestHeaders.delete("Prepr-Customer-Id");
|
|
228
|
+
requestHeaders.delete("Prepr-Customer-Id-Created");
|
|
229
|
+
}
|
|
221
230
|
return { requestHeaders, responseCookies };
|
|
222
231
|
}
|
|
223
232
|
|
|
@@ -453,13 +462,121 @@ async function getToolbarProps(token, features) {
|
|
|
453
462
|
return getToolbarPropsFromHeaders(h, token, features);
|
|
454
463
|
}
|
|
455
464
|
|
|
465
|
+
// src/core/personalization.ts
|
|
466
|
+
var PERSONALIZED_VARY = /\bPrepr-(Segments|ABTesting)/i;
|
|
467
|
+
function isPersonalizedResponse(source) {
|
|
468
|
+
const headers2 = "headers" in source ? source.headers : source;
|
|
469
|
+
return PERSONALIZED_VARY.test(headers2.get("vary") ?? "");
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
// src/nextjs/bucket.ts
|
|
473
|
+
var PREPR_BUCKET_COOKIE = "prepr_ab_bucket";
|
|
474
|
+
var isBucket = (value) => value === "A" || value === "B";
|
|
475
|
+
function setBucketCookie(request, response, bucket) {
|
|
476
|
+
response.cookies.set(PREPR_BUCKET_COOKIE, bucket, {
|
|
477
|
+
path: "/",
|
|
478
|
+
sameSite: "lax",
|
|
479
|
+
// Readable on purpose: PreprStack's inline switch reads it before first
|
|
480
|
+
// paint. It holds only "A" or "B".
|
|
481
|
+
httpOnly: false,
|
|
482
|
+
secure: request.nextUrl.protocol === "https:",
|
|
483
|
+
maxAge: 60 * 60 * 24 * 365
|
|
484
|
+
});
|
|
485
|
+
}
|
|
486
|
+
async function resolvePreprBucket(request, response, options) {
|
|
487
|
+
const stored = request.cookies.get(PREPR_BUCKET_COOKIE)?.value;
|
|
488
|
+
const forced = response.headers.get("x-middleware-request-prepr-abtesting") ?? request.cookies.get(COOKIE_VARIANT)?.value;
|
|
489
|
+
if (options.preview && isBucket(forced)) {
|
|
490
|
+
if (forced !== stored) setBucketCookie(request, response, forced);
|
|
491
|
+
return forced;
|
|
492
|
+
}
|
|
493
|
+
if (isBucket(stored)) return stored;
|
|
494
|
+
if (options.onlyIf) {
|
|
495
|
+
const needed = await Promise.resolve().then(options.onlyIf).catch(() => true);
|
|
496
|
+
if (!needed) return "A";
|
|
497
|
+
}
|
|
498
|
+
const customerId = request.cookies.get(COOKIE_UID)?.value ?? response.cookies.get(COOKIE_UID)?.value;
|
|
499
|
+
if (!customerId) return "A";
|
|
500
|
+
try {
|
|
501
|
+
const res = await fetch(options.url, {
|
|
502
|
+
method: "POST",
|
|
503
|
+
headers: {
|
|
504
|
+
"Content-Type": "application/json",
|
|
505
|
+
"Prepr-Customer-Id": customerId
|
|
506
|
+
},
|
|
507
|
+
body: JSON.stringify({ query: "{ __typename }" }),
|
|
508
|
+
cache: "no-store",
|
|
509
|
+
signal: AbortSignal.timeout(options.timeoutMs ?? 1500)
|
|
510
|
+
});
|
|
511
|
+
const bucket = res.headers.get("x-prepr-customer-bucket");
|
|
512
|
+
if (isBucket(bucket)) {
|
|
513
|
+
setBucketCookie(request, response, bucket);
|
|
514
|
+
return bucket;
|
|
515
|
+
}
|
|
516
|
+
} catch {
|
|
517
|
+
}
|
|
518
|
+
return "A";
|
|
519
|
+
}
|
|
520
|
+
|
|
521
|
+
// src/nextjs/draft.ts
|
|
522
|
+
var import_headers2 = require("next/headers");
|
|
523
|
+
var import_navigation = require("next/navigation");
|
|
524
|
+
var import_server3 = require("next/server");
|
|
525
|
+
var DRAFT_COOKIE = "__prerender_bypass";
|
|
526
|
+
var RETURN_PARAM = "prepr_draft";
|
|
527
|
+
var DEFAULT_ROUTE = "/api/prepr/draft";
|
|
528
|
+
function preprDraftRedirect(request, options) {
|
|
529
|
+
if (!options.preview) return null;
|
|
530
|
+
if (request.method !== "GET" && request.method !== "HEAD") return null;
|
|
531
|
+
const url = request.nextUrl;
|
|
532
|
+
if (url.pathname === (options.route ?? DEFAULT_ROUTE)) return null;
|
|
533
|
+
if (request.cookies.has(DRAFT_COOKIE)) {
|
|
534
|
+
if (!url.searchParams.has(RETURN_PARAM)) return null;
|
|
535
|
+
const clean = url.clone();
|
|
536
|
+
clean.searchParams.delete(RETURN_PARAM);
|
|
537
|
+
return import_server3.NextResponse.redirect(clean, 307);
|
|
538
|
+
}
|
|
539
|
+
if (url.searchParams.has(RETURN_PARAM)) return null;
|
|
540
|
+
const target = new URL(options.route ?? DEFAULT_ROUTE, request.url);
|
|
541
|
+
target.searchParams.set("to", url.pathname + url.search);
|
|
542
|
+
return import_server3.NextResponse.redirect(target, 307);
|
|
543
|
+
}
|
|
544
|
+
function createPreprDraftRoute(options) {
|
|
545
|
+
return async (request) => {
|
|
546
|
+
if (!options.preview) return new Response("Not found", { status: 404 });
|
|
547
|
+
(await (0, import_headers2.draftMode)()).enable();
|
|
548
|
+
const self = new URL(request.url);
|
|
549
|
+
if (self.protocol === "https:") {
|
|
550
|
+
const jar = await (0, import_headers2.cookies)();
|
|
551
|
+
const draft = jar.get(DRAFT_COOKIE);
|
|
552
|
+
if (draft) {
|
|
553
|
+
jar.set({
|
|
554
|
+
name: DRAFT_COOKIE,
|
|
555
|
+
value: draft.value,
|
|
556
|
+
path: "/",
|
|
557
|
+
httpOnly: true,
|
|
558
|
+
secure: true,
|
|
559
|
+
sameSite: "none",
|
|
560
|
+
partitioned: true
|
|
561
|
+
});
|
|
562
|
+
}
|
|
563
|
+
}
|
|
564
|
+
let to = new URL(self.searchParams.get("to") ?? "/", self);
|
|
565
|
+
if (to.origin !== self.origin) to = new URL("/", self);
|
|
566
|
+
to.searchParams.set(RETURN_PARAM, "1");
|
|
567
|
+
(0, import_navigation.redirect)(to.pathname + to.search);
|
|
568
|
+
};
|
|
569
|
+
}
|
|
570
|
+
|
|
456
571
|
// src/nextjs/index.ts
|
|
457
572
|
var import_components = require("./components.cjs");
|
|
458
573
|
// Annotate the CommonJS export names for ESM import in node:
|
|
459
574
|
0 && (module.exports = {
|
|
575
|
+
PREPR_BUCKET_COOKIE,
|
|
460
576
|
PreprError,
|
|
461
577
|
PreprToolbar,
|
|
462
578
|
PreprTrackingPixel,
|
|
579
|
+
createPreprDraftRoute,
|
|
463
580
|
createPreprMiddleware,
|
|
464
581
|
extractAccessToken,
|
|
465
582
|
getActiveSegment,
|
|
@@ -467,5 +584,8 @@ var import_components = require("./components.cjs");
|
|
|
467
584
|
getPreprHeaders,
|
|
468
585
|
getPreprUUID,
|
|
469
586
|
getToolbarProps,
|
|
587
|
+
isPersonalizedResponse,
|
|
588
|
+
preprDraftRedirect,
|
|
589
|
+
resolvePreprBucket,
|
|
470
590
|
validatePreprToken
|
|
471
591
|
});
|
package/dist/nextjs/index.d.cts
CHANGED
|
@@ -1,137 +1,6 @@
|
|
|
1
1
|
import { NextRequest, NextResponse } from 'next/server';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
declare const dictionaries: {
|
|
5
|
-
en: Dictionary;
|
|
6
|
-
nl: Dictionary;
|
|
7
|
-
};
|
|
8
|
-
type Locale = keyof typeof dictionaries;
|
|
9
|
-
|
|
10
|
-
interface PreprSegment {
|
|
11
|
-
readonly _id: string;
|
|
12
|
-
readonly name: string;
|
|
13
|
-
}
|
|
14
|
-
/**
|
|
15
|
-
* Per-feature config. `false` is shorthand for `{ enabled: false }`; the object
|
|
16
|
-
* form leaves room for per-feature options later without a breaking change.
|
|
17
|
-
*/
|
|
18
|
-
type PreprFeatureConfig = boolean | {
|
|
19
|
-
enabled?: boolean;
|
|
20
|
-
};
|
|
21
|
-
/** Toolkit features a consumer can turn off. Omitted keys stay enabled. */
|
|
22
|
-
interface PreprFeatures {
|
|
23
|
-
/** Segment picker, `Prepr-Segments` header and its cookie/query param. */
|
|
24
|
-
segments?: PreprFeatureConfig;
|
|
25
|
-
/** A/B variant switch, `Prepr-ABtesting` header and its cookie/query param. */
|
|
26
|
-
abTesting?: PreprFeatureConfig;
|
|
27
|
-
/**
|
|
28
|
-
* The site's own click-to-edit: the toolbar's Edit mode control, the stega
|
|
29
|
-
* tooltip/overlay and the close-edit pill.
|
|
30
|
-
*
|
|
31
|
-
* NOT a security control, and NOT the Prepr editor's live preview. When the
|
|
32
|
-
* site is framed by the editor, `prepr:initVE` still activates edit mode —
|
|
33
|
-
* that is the CMS operating inside its own iframe, not an affordance offered
|
|
34
|
-
* to visitors. See iframe-bridge.ts.
|
|
35
|
-
*/
|
|
36
|
-
editMode?: PreprFeatureConfig;
|
|
37
|
-
}
|
|
38
|
-
interface PreprToolbarOptions {
|
|
39
|
-
debug?: boolean;
|
|
40
|
-
locale?: Locale;
|
|
41
|
-
/** Disable features app-wide. Pass the same object to the middleware. */
|
|
42
|
-
features?: PreprFeatures;
|
|
43
|
-
}
|
|
44
|
-
/**
|
|
45
|
-
* Options for the preview runtime. Two independent axes: `features` decides
|
|
46
|
-
* *what runs*, `ui` decides *whether the toolbar is visible*.
|
|
47
|
-
*/
|
|
48
|
-
interface PreprPreviewOptions extends PreprToolbarOptions {
|
|
49
|
-
/**
|
|
50
|
-
* Mount the visible `<prepr-toolbar>` element. Default `true`.
|
|
51
|
-
*
|
|
52
|
-
* `false` keeps every non-visual side effect wired — click-to-edit, the
|
|
53
|
-
* editor bridge, scroll restore, cookies and headers — with no chrome of its
|
|
54
|
-
* own. That is how a site gets live editing, or editor scroll restore, while
|
|
55
|
-
* rendering its own UI instead of the bar.
|
|
56
|
-
*
|
|
57
|
-
* Already implied inside the editor's iframe (the CMS owns the chrome there)
|
|
58
|
-
* and by `?prepr_hide_bar=true`, so this option is for consumers who want a
|
|
59
|
-
* headless preview by their own choice.
|
|
60
|
-
*/
|
|
61
|
-
ui?: boolean;
|
|
62
|
-
/**
|
|
63
|
-
* Replace the `*.prepr.io` editor-origin wildcard with an exact list, e.g.
|
|
64
|
-
* `['http://acme.localhost:8000']`. Intended for self-hosted or locally run
|
|
65
|
-
* editors; when set, the wildcard no longer applies. Entries are compared to
|
|
66
|
-
* the editor's origin exactly: scheme, host and port.
|
|
67
|
-
*
|
|
68
|
-
* `['*']` accepts any editor origin. Use it for development only: any page
|
|
69
|
-
* that frames the preview can then switch on preview and edit mode and
|
|
70
|
-
* receives the field-edit events, which carry content item ids.
|
|
71
|
-
*/
|
|
72
|
-
allowedEditorOrigins?: string[];
|
|
73
|
-
/**
|
|
74
|
-
* Strip the invisible stega characters out of visible text at runtime.
|
|
75
|
-
* Default `true`.
|
|
76
|
-
*
|
|
77
|
-
* Preview content carries an encoded payload inside the text itself. Left in
|
|
78
|
-
* place it is invisible but real: it inflates `String.length`, breaks text
|
|
79
|
-
* measurement and truncation, and is announced by screen readers.
|
|
80
|
-
*
|
|
81
|
-
* Set `false` only when the site already strips the characters itself — for
|
|
82
|
-
* example by passing every field through `stegaClean` as it renders.
|
|
83
|
-
* Click-to-edit is unaffected either way: elements are still tagged from the
|
|
84
|
-
* payload, so the overlay keeps working.
|
|
85
|
-
*/
|
|
86
|
-
autoClean?: boolean;
|
|
87
|
-
}
|
|
88
|
-
interface PreprToolbarProps {
|
|
89
|
-
/**
|
|
90
|
-
* Server-resolved active segment. Optional: omit it with `segments`
|
|
91
|
-
* disabled, where there is nothing to resolve. When enabled and omitted,
|
|
92
|
-
* the persisted cookie is used.
|
|
93
|
-
*/
|
|
94
|
-
readonly activeSegment?: string | null;
|
|
95
|
-
/**
|
|
96
|
-
* Server-resolved active A/B variant. Optional: omit it with `abTesting`
|
|
97
|
-
* disabled, where there is nothing to resolve. When enabled and omitted,
|
|
98
|
-
* the persisted cookie is used.
|
|
99
|
-
*/
|
|
100
|
-
readonly activeVariant?: string | null;
|
|
101
|
-
/** Available segments to personalize on. */
|
|
102
|
-
readonly segments?: readonly PreprSegment[];
|
|
103
|
-
/** @deprecated Alias for `segments`. */
|
|
104
|
-
readonly data?: readonly PreprSegment[];
|
|
105
|
-
}
|
|
106
|
-
/**
|
|
107
|
-
* Prop type for the framework `<PreprToolbar>` components: the toolbar data
|
|
108
|
-
* plus the options bag core `createPreprPreview` accepts.
|
|
109
|
-
*/
|
|
110
|
-
interface PreprToolbarComponentProps extends PreprToolbarProps {
|
|
111
|
-
options?: PreprPreviewOptions;
|
|
112
|
-
}
|
|
113
|
-
type PreprVariant = 'A' | 'B';
|
|
114
|
-
interface PreprHeaders {
|
|
115
|
-
readonly 'prepr-customer-id'?: string;
|
|
116
|
-
readonly 'Prepr-Segments'?: string;
|
|
117
|
-
readonly 'Prepr-ABtesting'?: PreprVariant;
|
|
118
|
-
readonly 'Prepr-Preview-Bar'?: 'true';
|
|
119
|
-
readonly 'Prepr-Context-utm_source'?: string;
|
|
120
|
-
readonly 'Prepr-Context-utm_medium'?: string;
|
|
121
|
-
readonly 'Prepr-Context-utm_term'?: string;
|
|
122
|
-
readonly 'Prepr-Context-utm_content'?: string;
|
|
123
|
-
readonly 'Prepr-Context-utm_campaign'?: string;
|
|
124
|
-
readonly 'Prepr-Context-initial_referral'?: string;
|
|
125
|
-
readonly 'Prepr-Visitor-IP'?: string;
|
|
126
|
-
readonly 'Prepr-Hubspot-Id'?: string;
|
|
127
|
-
readonly 'Prepr-Customer-Id-Created'?: 'true';
|
|
128
|
-
/** The visitor's browser User-Agent, used by the API for device detection. */
|
|
129
|
-
readonly 'User-Agent'?: string;
|
|
130
|
-
/** @deprecated Never populated; the visitor's value is under `User-Agent`. */
|
|
131
|
-
readonly 'Prepr-User-Agent'?: string;
|
|
132
|
-
readonly 'Prepr-Package'?: string;
|
|
133
|
-
}
|
|
134
|
-
type PreprErrorCode = 'INVALID_TOKEN' | 'MISSING_TOKEN' | 'HTTP_ERROR' | 'FETCH_ERROR' | 'INVALID_RESPONSE' | 'CONTEXT_ERROR';
|
|
2
|
+
import { b as PreprFeatures, P as PreprHeaders, c as PreprToolbarProps, d as PreprToolbarComponentProps } from './server-CjpELYvq.cjs';
|
|
3
|
+
export { a as PreprError, e as extractAccessToken, i as isPersonalizedResponse, v as validatePreprToken } from './server-CjpELYvq.cjs';
|
|
135
4
|
|
|
136
5
|
interface PreprMiddlewareOptions {
|
|
137
6
|
/** Enable preview-mode headers (segment/AB overrides, preview bar). */
|
|
@@ -175,24 +44,61 @@ declare function getPreprHeaders(): Promise<PreprHeaders>;
|
|
|
175
44
|
*/
|
|
176
45
|
declare function getToolbarProps(token: string, features?: PreprFeatures): Promise<PreprToolbarProps>;
|
|
177
46
|
|
|
178
|
-
/**
|
|
179
|
-
declare
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
47
|
+
/** Cookie holding the visitor's A/B bucket, as Prepr assigned it. */
|
|
48
|
+
declare const PREPR_BUCKET_COOKIE = "prepr_ab_bucket";
|
|
49
|
+
type PreprBucket = 'A' | 'B';
|
|
50
|
+
interface ResolvePreprBucketOptions {
|
|
51
|
+
/** Full Prepr GraphQL URL. */
|
|
52
|
+
url: string;
|
|
53
|
+
/** Preview mode: the toolbar's A/B override wins. */
|
|
54
|
+
preview?: boolean;
|
|
55
|
+
/** Abort the one-time lookup after this many ms. Default 1500. */
|
|
56
|
+
timeoutMs?: number;
|
|
57
|
+
/**
|
|
58
|
+
* Look the bucket up only when this resolves to true, typically "does this
|
|
59
|
+
* page have an A/B test": `() => prepr.hasAbTests(PageDocument, { slug })`.
|
|
60
|
+
* Only called for visitors without a bucket cookie, so visitors on pages
|
|
61
|
+
* without A/B tests never wait for the lookup.
|
|
62
|
+
*/
|
|
63
|
+
onlyIf?: () => boolean | Promise<boolean>;
|
|
64
|
+
}
|
|
65
|
+
declare function resolvePreprBucket(request: NextRequest, response: NextResponse, options: ResolvePreprBucketOptions): Promise<PreprBucket>;
|
|
66
|
+
|
|
67
|
+
interface PreprDraftOptions {
|
|
68
|
+
/** Whether this deployment serves preview content. Outside it, both helpers do nothing. */
|
|
69
|
+
preview: boolean;
|
|
70
|
+
/** Path of the route handler made with `createPreprDraftRoute`. Default `/api/prepr/draft`. */
|
|
71
|
+
route?: string;
|
|
184
72
|
}
|
|
185
73
|
/**
|
|
186
|
-
*
|
|
187
|
-
*
|
|
74
|
+
* In preview, sends a visitor without draft mode through the draft route once,
|
|
75
|
+
* from middleware (`proxy.ts`). Returns the redirect to send, or `null` to
|
|
76
|
+
* carry on.
|
|
77
|
+
*
|
|
78
|
+
* Draft mode is what keeps preview fresh with Cache Components: Next.js then
|
|
79
|
+
* renders every page per request and skips `'use cache'` entries and the Data
|
|
80
|
+
* Cache, so an edit shows on the next load without a publish webhook.
|
|
81
|
+
*
|
|
82
|
+
* Call it first in the proxy, before `createPreprMiddleware`.
|
|
83
|
+
*
|
|
84
|
+
* @example
|
|
85
|
+
* const draft = preprDraftRedirect(request, { preview });
|
|
86
|
+
* if (draft) return draft;
|
|
188
87
|
*/
|
|
189
|
-
declare function
|
|
88
|
+
declare function preprDraftRedirect(request: NextRequest, options: PreprDraftOptions): NextResponse | null;
|
|
190
89
|
/**
|
|
191
|
-
*
|
|
192
|
-
*
|
|
193
|
-
*
|
|
90
|
+
* The route handler `preprDraftRedirect` sends preview visitors to: turns on
|
|
91
|
+
* draft mode and redirects back to the page. Answers 404 outside preview.
|
|
92
|
+
* Only same-origin paths are followed, so it cannot be used as an open
|
|
93
|
+
* redirect.
|
|
94
|
+
*
|
|
95
|
+
* @example
|
|
96
|
+
* // app/api/prepr/draft/route.ts
|
|
97
|
+
* export const GET = createPreprDraftRoute({
|
|
98
|
+
* preview: process.env.PREPR_ENV === 'preview',
|
|
99
|
+
* });
|
|
194
100
|
*/
|
|
195
|
-
declare function
|
|
101
|
+
declare function createPreprDraftRoute(options: Pick<PreprDraftOptions, 'preview'>): (request: Request) => Promise<Response>;
|
|
196
102
|
|
|
197
103
|
/**
|
|
198
104
|
* Loader + typed facade for Prepr's CDN tracking pixel, so consumers don't have
|
|
@@ -248,4 +154,4 @@ declare function PreprTrackingPixel({ id, config, }: PreprTrackingPixelProps): n
|
|
|
248
154
|
*/
|
|
249
155
|
declare function PreprToolbar({ options, ...props }: PreprToolbarComponentProps): null;
|
|
250
156
|
|
|
251
|
-
export {
|
|
157
|
+
export { PREPR_BUCKET_COOKIE, type PreprBucket, type PreprDraftOptions, type PreprMiddlewareOptions, PreprToolbar, PreprTrackingPixel, type PreprTrackingPixelProps, type ResolvePreprBucketOptions, createPreprDraftRoute, createPreprMiddleware, getActiveSegment, getActiveVariant, getPreprHeaders, getPreprUUID, getToolbarProps, preprDraftRedirect, resolvePreprBucket };
|
package/dist/nextjs/index.d.ts
CHANGED
|
@@ -1,137 +1,6 @@
|
|
|
1
1
|
import { NextRequest, NextResponse } from 'next/server';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
declare const dictionaries: {
|
|
5
|
-
en: Dictionary;
|
|
6
|
-
nl: Dictionary;
|
|
7
|
-
};
|
|
8
|
-
type Locale = keyof typeof dictionaries;
|
|
9
|
-
|
|
10
|
-
interface PreprSegment {
|
|
11
|
-
readonly _id: string;
|
|
12
|
-
readonly name: string;
|
|
13
|
-
}
|
|
14
|
-
/**
|
|
15
|
-
* Per-feature config. `false` is shorthand for `{ enabled: false }`; the object
|
|
16
|
-
* form leaves room for per-feature options later without a breaking change.
|
|
17
|
-
*/
|
|
18
|
-
type PreprFeatureConfig = boolean | {
|
|
19
|
-
enabled?: boolean;
|
|
20
|
-
};
|
|
21
|
-
/** Toolkit features a consumer can turn off. Omitted keys stay enabled. */
|
|
22
|
-
interface PreprFeatures {
|
|
23
|
-
/** Segment picker, `Prepr-Segments` header and its cookie/query param. */
|
|
24
|
-
segments?: PreprFeatureConfig;
|
|
25
|
-
/** A/B variant switch, `Prepr-ABtesting` header and its cookie/query param. */
|
|
26
|
-
abTesting?: PreprFeatureConfig;
|
|
27
|
-
/**
|
|
28
|
-
* The site's own click-to-edit: the toolbar's Edit mode control, the stega
|
|
29
|
-
* tooltip/overlay and the close-edit pill.
|
|
30
|
-
*
|
|
31
|
-
* NOT a security control, and NOT the Prepr editor's live preview. When the
|
|
32
|
-
* site is framed by the editor, `prepr:initVE` still activates edit mode —
|
|
33
|
-
* that is the CMS operating inside its own iframe, not an affordance offered
|
|
34
|
-
* to visitors. See iframe-bridge.ts.
|
|
35
|
-
*/
|
|
36
|
-
editMode?: PreprFeatureConfig;
|
|
37
|
-
}
|
|
38
|
-
interface PreprToolbarOptions {
|
|
39
|
-
debug?: boolean;
|
|
40
|
-
locale?: Locale;
|
|
41
|
-
/** Disable features app-wide. Pass the same object to the middleware. */
|
|
42
|
-
features?: PreprFeatures;
|
|
43
|
-
}
|
|
44
|
-
/**
|
|
45
|
-
* Options for the preview runtime. Two independent axes: `features` decides
|
|
46
|
-
* *what runs*, `ui` decides *whether the toolbar is visible*.
|
|
47
|
-
*/
|
|
48
|
-
interface PreprPreviewOptions extends PreprToolbarOptions {
|
|
49
|
-
/**
|
|
50
|
-
* Mount the visible `<prepr-toolbar>` element. Default `true`.
|
|
51
|
-
*
|
|
52
|
-
* `false` keeps every non-visual side effect wired — click-to-edit, the
|
|
53
|
-
* editor bridge, scroll restore, cookies and headers — with no chrome of its
|
|
54
|
-
* own. That is how a site gets live editing, or editor scroll restore, while
|
|
55
|
-
* rendering its own UI instead of the bar.
|
|
56
|
-
*
|
|
57
|
-
* Already implied inside the editor's iframe (the CMS owns the chrome there)
|
|
58
|
-
* and by `?prepr_hide_bar=true`, so this option is for consumers who want a
|
|
59
|
-
* headless preview by their own choice.
|
|
60
|
-
*/
|
|
61
|
-
ui?: boolean;
|
|
62
|
-
/**
|
|
63
|
-
* Replace the `*.prepr.io` editor-origin wildcard with an exact list, e.g.
|
|
64
|
-
* `['http://acme.localhost:8000']`. Intended for self-hosted or locally run
|
|
65
|
-
* editors; when set, the wildcard no longer applies. Entries are compared to
|
|
66
|
-
* the editor's origin exactly: scheme, host and port.
|
|
67
|
-
*
|
|
68
|
-
* `['*']` accepts any editor origin. Use it for development only: any page
|
|
69
|
-
* that frames the preview can then switch on preview and edit mode and
|
|
70
|
-
* receives the field-edit events, which carry content item ids.
|
|
71
|
-
*/
|
|
72
|
-
allowedEditorOrigins?: string[];
|
|
73
|
-
/**
|
|
74
|
-
* Strip the invisible stega characters out of visible text at runtime.
|
|
75
|
-
* Default `true`.
|
|
76
|
-
*
|
|
77
|
-
* Preview content carries an encoded payload inside the text itself. Left in
|
|
78
|
-
* place it is invisible but real: it inflates `String.length`, breaks text
|
|
79
|
-
* measurement and truncation, and is announced by screen readers.
|
|
80
|
-
*
|
|
81
|
-
* Set `false` only when the site already strips the characters itself — for
|
|
82
|
-
* example by passing every field through `stegaClean` as it renders.
|
|
83
|
-
* Click-to-edit is unaffected either way: elements are still tagged from the
|
|
84
|
-
* payload, so the overlay keeps working.
|
|
85
|
-
*/
|
|
86
|
-
autoClean?: boolean;
|
|
87
|
-
}
|
|
88
|
-
interface PreprToolbarProps {
|
|
89
|
-
/**
|
|
90
|
-
* Server-resolved active segment. Optional: omit it with `segments`
|
|
91
|
-
* disabled, where there is nothing to resolve. When enabled and omitted,
|
|
92
|
-
* the persisted cookie is used.
|
|
93
|
-
*/
|
|
94
|
-
readonly activeSegment?: string | null;
|
|
95
|
-
/**
|
|
96
|
-
* Server-resolved active A/B variant. Optional: omit it with `abTesting`
|
|
97
|
-
* disabled, where there is nothing to resolve. When enabled and omitted,
|
|
98
|
-
* the persisted cookie is used.
|
|
99
|
-
*/
|
|
100
|
-
readonly activeVariant?: string | null;
|
|
101
|
-
/** Available segments to personalize on. */
|
|
102
|
-
readonly segments?: readonly PreprSegment[];
|
|
103
|
-
/** @deprecated Alias for `segments`. */
|
|
104
|
-
readonly data?: readonly PreprSegment[];
|
|
105
|
-
}
|
|
106
|
-
/**
|
|
107
|
-
* Prop type for the framework `<PreprToolbar>` components: the toolbar data
|
|
108
|
-
* plus the options bag core `createPreprPreview` accepts.
|
|
109
|
-
*/
|
|
110
|
-
interface PreprToolbarComponentProps extends PreprToolbarProps {
|
|
111
|
-
options?: PreprPreviewOptions;
|
|
112
|
-
}
|
|
113
|
-
type PreprVariant = 'A' | 'B';
|
|
114
|
-
interface PreprHeaders {
|
|
115
|
-
readonly 'prepr-customer-id'?: string;
|
|
116
|
-
readonly 'Prepr-Segments'?: string;
|
|
117
|
-
readonly 'Prepr-ABtesting'?: PreprVariant;
|
|
118
|
-
readonly 'Prepr-Preview-Bar'?: 'true';
|
|
119
|
-
readonly 'Prepr-Context-utm_source'?: string;
|
|
120
|
-
readonly 'Prepr-Context-utm_medium'?: string;
|
|
121
|
-
readonly 'Prepr-Context-utm_term'?: string;
|
|
122
|
-
readonly 'Prepr-Context-utm_content'?: string;
|
|
123
|
-
readonly 'Prepr-Context-utm_campaign'?: string;
|
|
124
|
-
readonly 'Prepr-Context-initial_referral'?: string;
|
|
125
|
-
readonly 'Prepr-Visitor-IP'?: string;
|
|
126
|
-
readonly 'Prepr-Hubspot-Id'?: string;
|
|
127
|
-
readonly 'Prepr-Customer-Id-Created'?: 'true';
|
|
128
|
-
/** The visitor's browser User-Agent, used by the API for device detection. */
|
|
129
|
-
readonly 'User-Agent'?: string;
|
|
130
|
-
/** @deprecated Never populated; the visitor's value is under `User-Agent`. */
|
|
131
|
-
readonly 'Prepr-User-Agent'?: string;
|
|
132
|
-
readonly 'Prepr-Package'?: string;
|
|
133
|
-
}
|
|
134
|
-
type PreprErrorCode = 'INVALID_TOKEN' | 'MISSING_TOKEN' | 'HTTP_ERROR' | 'FETCH_ERROR' | 'INVALID_RESPONSE' | 'CONTEXT_ERROR';
|
|
2
|
+
import { b as PreprFeatures, P as PreprHeaders, c as PreprToolbarProps, d as PreprToolbarComponentProps } from './server-CjpELYvq.js';
|
|
3
|
+
export { a as PreprError, e as extractAccessToken, i as isPersonalizedResponse, v as validatePreprToken } from './server-CjpELYvq.js';
|
|
135
4
|
|
|
136
5
|
interface PreprMiddlewareOptions {
|
|
137
6
|
/** Enable preview-mode headers (segment/AB overrides, preview bar). */
|
|
@@ -175,24 +44,61 @@ declare function getPreprHeaders(): Promise<PreprHeaders>;
|
|
|
175
44
|
*/
|
|
176
45
|
declare function getToolbarProps(token: string, features?: PreprFeatures): Promise<PreprToolbarProps>;
|
|
177
46
|
|
|
178
|
-
/**
|
|
179
|
-
declare
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
47
|
+
/** Cookie holding the visitor's A/B bucket, as Prepr assigned it. */
|
|
48
|
+
declare const PREPR_BUCKET_COOKIE = "prepr_ab_bucket";
|
|
49
|
+
type PreprBucket = 'A' | 'B';
|
|
50
|
+
interface ResolvePreprBucketOptions {
|
|
51
|
+
/** Full Prepr GraphQL URL. */
|
|
52
|
+
url: string;
|
|
53
|
+
/** Preview mode: the toolbar's A/B override wins. */
|
|
54
|
+
preview?: boolean;
|
|
55
|
+
/** Abort the one-time lookup after this many ms. Default 1500. */
|
|
56
|
+
timeoutMs?: number;
|
|
57
|
+
/**
|
|
58
|
+
* Look the bucket up only when this resolves to true, typically "does this
|
|
59
|
+
* page have an A/B test": `() => prepr.hasAbTests(PageDocument, { slug })`.
|
|
60
|
+
* Only called for visitors without a bucket cookie, so visitors on pages
|
|
61
|
+
* without A/B tests never wait for the lookup.
|
|
62
|
+
*/
|
|
63
|
+
onlyIf?: () => boolean | Promise<boolean>;
|
|
64
|
+
}
|
|
65
|
+
declare function resolvePreprBucket(request: NextRequest, response: NextResponse, options: ResolvePreprBucketOptions): Promise<PreprBucket>;
|
|
66
|
+
|
|
67
|
+
interface PreprDraftOptions {
|
|
68
|
+
/** Whether this deployment serves preview content. Outside it, both helpers do nothing. */
|
|
69
|
+
preview: boolean;
|
|
70
|
+
/** Path of the route handler made with `createPreprDraftRoute`. Default `/api/prepr/draft`. */
|
|
71
|
+
route?: string;
|
|
184
72
|
}
|
|
185
73
|
/**
|
|
186
|
-
*
|
|
187
|
-
*
|
|
74
|
+
* In preview, sends a visitor without draft mode through the draft route once,
|
|
75
|
+
* from middleware (`proxy.ts`). Returns the redirect to send, or `null` to
|
|
76
|
+
* carry on.
|
|
77
|
+
*
|
|
78
|
+
* Draft mode is what keeps preview fresh with Cache Components: Next.js then
|
|
79
|
+
* renders every page per request and skips `'use cache'` entries and the Data
|
|
80
|
+
* Cache, so an edit shows on the next load without a publish webhook.
|
|
81
|
+
*
|
|
82
|
+
* Call it first in the proxy, before `createPreprMiddleware`.
|
|
83
|
+
*
|
|
84
|
+
* @example
|
|
85
|
+
* const draft = preprDraftRedirect(request, { preview });
|
|
86
|
+
* if (draft) return draft;
|
|
188
87
|
*/
|
|
189
|
-
declare function
|
|
88
|
+
declare function preprDraftRedirect(request: NextRequest, options: PreprDraftOptions): NextResponse | null;
|
|
190
89
|
/**
|
|
191
|
-
*
|
|
192
|
-
*
|
|
193
|
-
*
|
|
90
|
+
* The route handler `preprDraftRedirect` sends preview visitors to: turns on
|
|
91
|
+
* draft mode and redirects back to the page. Answers 404 outside preview.
|
|
92
|
+
* Only same-origin paths are followed, so it cannot be used as an open
|
|
93
|
+
* redirect.
|
|
94
|
+
*
|
|
95
|
+
* @example
|
|
96
|
+
* // app/api/prepr/draft/route.ts
|
|
97
|
+
* export const GET = createPreprDraftRoute({
|
|
98
|
+
* preview: process.env.PREPR_ENV === 'preview',
|
|
99
|
+
* });
|
|
194
100
|
*/
|
|
195
|
-
declare function
|
|
101
|
+
declare function createPreprDraftRoute(options: Pick<PreprDraftOptions, 'preview'>): (request: Request) => Promise<Response>;
|
|
196
102
|
|
|
197
103
|
/**
|
|
198
104
|
* Loader + typed facade for Prepr's CDN tracking pixel, so consumers don't have
|
|
@@ -248,4 +154,4 @@ declare function PreprTrackingPixel({ id, config, }: PreprTrackingPixelProps): n
|
|
|
248
154
|
*/
|
|
249
155
|
declare function PreprToolbar({ options, ...props }: PreprToolbarComponentProps): null;
|
|
250
156
|
|
|
251
|
-
export {
|
|
157
|
+
export { PREPR_BUCKET_COOKIE, type PreprBucket, type PreprDraftOptions, type PreprMiddlewareOptions, PreprToolbar, PreprTrackingPixel, type PreprTrackingPixelProps, type ResolvePreprBucketOptions, createPreprDraftRoute, createPreprMiddleware, getActiveSegment, getActiveVariant, getPreprHeaders, getPreprUUID, getToolbarProps, preprDraftRedirect, resolvePreprBucket };
|