@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.js
CHANGED
|
@@ -1,9 +1,20 @@
|
|
|
1
|
+
import {
|
|
2
|
+
PreprError,
|
|
3
|
+
VERSION,
|
|
4
|
+
extractAccessToken,
|
|
5
|
+
getActiveSegment,
|
|
6
|
+
getActiveVariant,
|
|
7
|
+
getPreprHeaders,
|
|
8
|
+
getPreprUUID,
|
|
9
|
+
getToolbarProps,
|
|
10
|
+
isPersonalizedResponse,
|
|
11
|
+
resolveFeatures,
|
|
12
|
+
validatePreprToken
|
|
13
|
+
} from "./chunk-U4HXENF7.js";
|
|
14
|
+
|
|
1
15
|
// src/nextjs/middleware.ts
|
|
2
16
|
import { NextResponse } from "next/server";
|
|
3
17
|
|
|
4
|
-
// src/version.ts
|
|
5
|
-
var VERSION = "0.5.0-rc.2";
|
|
6
|
-
|
|
7
18
|
// src/core/constants.ts
|
|
8
19
|
var COOKIE_PREVIEW_MODE = "Prepr-Preview-Mode";
|
|
9
20
|
var COOKIE_SEGMENT = "Prepr-Segments";
|
|
@@ -15,24 +26,6 @@ var PARAM_VARIANT = "prepr_preview_ab";
|
|
|
15
26
|
var PARAM_HIDE_BAR = "prepr_hide_bar";
|
|
16
27
|
var ONE_YEAR_SECONDS = 60 * 60 * 24 * 365;
|
|
17
28
|
|
|
18
|
-
// src/core/features.ts
|
|
19
|
-
function isEnabled(config) {
|
|
20
|
-
if (typeof config === "boolean") return config;
|
|
21
|
-
return config?.enabled ?? true;
|
|
22
|
-
}
|
|
23
|
-
function resolveFeatures(features) {
|
|
24
|
-
return {
|
|
25
|
-
segments: isEnabled(features?.segments),
|
|
26
|
-
abTesting: isEnabled(features?.abTesting),
|
|
27
|
-
editMode: isEnabled(features?.editMode)
|
|
28
|
-
};
|
|
29
|
-
}
|
|
30
|
-
var ALL_FEATURES_ENABLED = Object.freeze({
|
|
31
|
-
segments: true,
|
|
32
|
-
abTesting: true,
|
|
33
|
-
editMode: true
|
|
34
|
-
});
|
|
35
|
-
|
|
36
29
|
// src/core/middleware.ts
|
|
37
30
|
var UTM_PARAMS = [
|
|
38
31
|
"utm_source",
|
|
@@ -47,9 +40,9 @@ function sanitizeHeaderValue(value) {
|
|
|
47
40
|
return stripped.length > MAX_HEADER_VALUE_LENGTH ? stripped.slice(0, MAX_HEADER_VALUE_LENGTH) : stripped;
|
|
48
41
|
}
|
|
49
42
|
function parseCookies(request) {
|
|
50
|
-
const
|
|
43
|
+
const cookies2 = /* @__PURE__ */ new Map();
|
|
51
44
|
const header = request.headers.get("cookie");
|
|
52
|
-
if (!header) return
|
|
45
|
+
if (!header) return cookies2;
|
|
53
46
|
for (const part of header.split(";")) {
|
|
54
47
|
const eq = part.indexOf("=");
|
|
55
48
|
if (eq === -1) continue;
|
|
@@ -57,12 +50,12 @@ function parseCookies(request) {
|
|
|
57
50
|
const value = part.slice(eq + 1).trim();
|
|
58
51
|
if (!name) continue;
|
|
59
52
|
try {
|
|
60
|
-
|
|
53
|
+
cookies2.set(name, decodeURIComponent(value));
|
|
61
54
|
} catch {
|
|
62
|
-
|
|
55
|
+
cookies2.set(name, value);
|
|
63
56
|
}
|
|
64
57
|
}
|
|
65
|
-
return
|
|
58
|
+
return cookies2;
|
|
66
59
|
}
|
|
67
60
|
function processFrameworkRequest(request, opts, framework) {
|
|
68
61
|
const requestHeaders = new Headers(request.headers);
|
|
@@ -182,6 +175,10 @@ function processFrameworkRequest(request, opts, framework) {
|
|
|
182
175
|
});
|
|
183
176
|
}
|
|
184
177
|
}
|
|
178
|
+
if (requestHeaders.has("Prepr-Segments")) {
|
|
179
|
+
requestHeaders.delete("Prepr-Customer-Id");
|
|
180
|
+
requestHeaders.delete("Prepr-Customer-Id-Created");
|
|
181
|
+
}
|
|
185
182
|
return { requestHeaders, responseCookies };
|
|
186
183
|
}
|
|
187
184
|
|
|
@@ -226,195 +223,103 @@ function createPreprMiddleware(request, responseOrOptions, maybeOptions) {
|
|
|
226
223
|
return response;
|
|
227
224
|
}
|
|
228
225
|
|
|
229
|
-
// src/nextjs/
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
};
|
|
242
|
-
function getPreprUUIDFromHeaders(headers2) {
|
|
243
|
-
return headers2.get("prepr-customer-id");
|
|
244
|
-
}
|
|
245
|
-
function getActiveSegmentFromHeaders(headers2) {
|
|
246
|
-
return headers2.get("Prepr-Segments");
|
|
247
|
-
}
|
|
248
|
-
function getActiveVariantFromHeaders(headers2) {
|
|
249
|
-
return headers2.get("Prepr-ABtesting");
|
|
250
|
-
}
|
|
251
|
-
var PREPR_HEADER_KEYS = [
|
|
252
|
-
"prepr-customer-id",
|
|
253
|
-
"Prepr-Segments",
|
|
254
|
-
"Prepr-ABtesting",
|
|
255
|
-
"Prepr-Preview-Bar",
|
|
256
|
-
"Prepr-Context-utm_source",
|
|
257
|
-
"Prepr-Context-utm_medium",
|
|
258
|
-
"Prepr-Context-utm_term",
|
|
259
|
-
"Prepr-Context-utm_content",
|
|
260
|
-
"Prepr-Context-utm_campaign",
|
|
261
|
-
"Prepr-Context-initial_referral",
|
|
262
|
-
"Prepr-Visitor-IP",
|
|
263
|
-
"Prepr-Hubspot-Id",
|
|
264
|
-
"Prepr-Customer-Id-Created",
|
|
265
|
-
"User-Agent",
|
|
266
|
-
"Prepr-Package"
|
|
267
|
-
];
|
|
268
|
-
function getPreprHeadersFromHeaders(headers2) {
|
|
269
|
-
const preprHeaders = {};
|
|
270
|
-
const copy = (key) => {
|
|
271
|
-
const value = headers2.get(key);
|
|
272
|
-
if (value !== null) {
|
|
273
|
-
preprHeaders[key] = value;
|
|
274
|
-
}
|
|
275
|
-
};
|
|
276
|
-
for (const key of PREPR_HEADER_KEYS) {
|
|
277
|
-
copy(key);
|
|
278
|
-
}
|
|
279
|
-
return preprHeaders;
|
|
280
|
-
}
|
|
281
|
-
function validatePreprToken(token) {
|
|
282
|
-
if (!token) {
|
|
283
|
-
throw new PreprError(
|
|
284
|
-
"Token is required",
|
|
285
|
-
"MISSING_TOKEN",
|
|
286
|
-
"validatePreprToken"
|
|
287
|
-
);
|
|
288
|
-
}
|
|
289
|
-
if (!token.startsWith("https://")) {
|
|
290
|
-
throw new PreprError(
|
|
291
|
-
"Token must be a valid HTTPS URL",
|
|
292
|
-
"INVALID_TOKEN",
|
|
293
|
-
"validatePreprToken"
|
|
294
|
-
);
|
|
295
|
-
}
|
|
226
|
+
// src/nextjs/bucket.ts
|
|
227
|
+
var PREPR_BUCKET_COOKIE = "prepr_ab_bucket";
|
|
228
|
+
var isBucket = (value) => value === "A" || value === "B";
|
|
229
|
+
function setBucketCookie(request, response, bucket) {
|
|
230
|
+
response.cookies.set(PREPR_BUCKET_COOKIE, bucket, {
|
|
231
|
+
path: "/",
|
|
232
|
+
sameSite: "lax",
|
|
233
|
+
// Readable on purpose: PreprStack's inline switch reads it before first
|
|
234
|
+
// paint. It holds only "A" or "B".
|
|
235
|
+
httpOnly: false,
|
|
236
|
+
secure: request.nextUrl.protocol === "https:",
|
|
237
|
+
maxAge: 60 * 60 * 24 * 365
|
|
238
|
+
});
|
|
296
239
|
}
|
|
297
|
-
function
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
"Token must be a valid URL",
|
|
304
|
-
"INVALID_TOKEN",
|
|
305
|
-
"extractAccessToken",
|
|
306
|
-
error instanceof Error ? error : new Error(String(error))
|
|
307
|
-
);
|
|
308
|
-
}
|
|
309
|
-
if (url.hostname !== "graphql.prepr.io") {
|
|
310
|
-
throw new PreprError(
|
|
311
|
-
"Token must be a graphql.prepr.io URL",
|
|
312
|
-
"INVALID_TOKEN",
|
|
313
|
-
"extractAccessToken"
|
|
314
|
-
);
|
|
240
|
+
async function resolvePreprBucket(request, response, options) {
|
|
241
|
+
const stored = request.cookies.get(PREPR_BUCKET_COOKIE)?.value;
|
|
242
|
+
const forced = response.headers.get("x-middleware-request-prepr-abtesting") ?? request.cookies.get(COOKIE_VARIANT)?.value;
|
|
243
|
+
if (options.preview && isBucket(forced)) {
|
|
244
|
+
if (forced !== stored) setBucketCookie(request, response, forced);
|
|
245
|
+
return forced;
|
|
315
246
|
}
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
"Token URL is missing an access token segment",
|
|
321
|
-
"INVALID_TOKEN",
|
|
322
|
-
"extractAccessToken"
|
|
323
|
-
);
|
|
247
|
+
if (isBucket(stored)) return stored;
|
|
248
|
+
if (options.onlyIf) {
|
|
249
|
+
const needed = await Promise.resolve().then(options.onlyIf).catch(() => true);
|
|
250
|
+
if (!needed) return "A";
|
|
324
251
|
}
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
async function getPreprEnvironmentSegments(token) {
|
|
328
|
-
validatePreprToken(token);
|
|
252
|
+
const customerId = request.cookies.get(COOKIE_UID)?.value ?? response.cookies.get(COOKIE_UID)?.value;
|
|
253
|
+
if (!customerId) return "A";
|
|
329
254
|
try {
|
|
330
|
-
const
|
|
255
|
+
const res = await fetch(options.url, {
|
|
256
|
+
method: "POST",
|
|
331
257
|
headers: {
|
|
332
|
-
"
|
|
333
|
-
|
|
334
|
-
// format used by `@preprio/prepr-nextjs`, for Prepr API consumers that
|
|
335
|
-
// still identify the toolbar by that string.
|
|
336
|
-
"User-Agent": `Prepr-Preview-Bar/${VERSION}`,
|
|
337
|
-
"Content-Type": "application/json"
|
|
258
|
+
"Content-Type": "application/json",
|
|
259
|
+
"Prepr-Customer-Id": customerId
|
|
338
260
|
},
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
_Segments {
|
|
343
|
-
_id
|
|
344
|
-
name
|
|
345
|
-
}
|
|
346
|
-
}`
|
|
347
|
-
})
|
|
261
|
+
body: JSON.stringify({ query: "{ __typename }" }),
|
|
262
|
+
cache: "no-store",
|
|
263
|
+
signal: AbortSignal.timeout(options.timeoutMs ?? 1500)
|
|
348
264
|
});
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
"getPreprEnvironmentSegments"
|
|
354
|
-
);
|
|
355
|
-
}
|
|
356
|
-
const json = await response.json();
|
|
357
|
-
if (!json || !json.data || !json.data._Segments) {
|
|
358
|
-
throw new PreprError(
|
|
359
|
-
"Invalid response format from Prepr API",
|
|
360
|
-
"INVALID_RESPONSE",
|
|
361
|
-
"getPreprEnvironmentSegments"
|
|
362
|
-
);
|
|
363
|
-
}
|
|
364
|
-
return json.data._Segments;
|
|
365
|
-
} catch (error) {
|
|
366
|
-
if (error instanceof PreprError) {
|
|
367
|
-
throw error;
|
|
265
|
+
const bucket = res.headers.get("x-prepr-customer-bucket");
|
|
266
|
+
if (isBucket(bucket)) {
|
|
267
|
+
setBucketCookie(request, response, bucket);
|
|
268
|
+
return bucket;
|
|
368
269
|
}
|
|
369
|
-
|
|
370
|
-
"Failed to fetch segments from Prepr API",
|
|
371
|
-
"FETCH_ERROR",
|
|
372
|
-
"getPreprEnvironmentSegments",
|
|
373
|
-
error instanceof Error ? error : new Error(String(error))
|
|
374
|
-
);
|
|
270
|
+
} catch {
|
|
375
271
|
}
|
|
376
|
-
|
|
377
|
-
async function getToolbarPropsFromHeaders(headers2, token, features) {
|
|
378
|
-
const resolved = resolveFeatures(features);
|
|
379
|
-
let segments = [];
|
|
380
|
-
if (resolved.segments) {
|
|
381
|
-
try {
|
|
382
|
-
segments = await getPreprEnvironmentSegments(token);
|
|
383
|
-
} catch {
|
|
384
|
-
segments = [];
|
|
385
|
-
}
|
|
386
|
-
}
|
|
387
|
-
return {
|
|
388
|
-
activeSegment: resolved.segments ? getActiveSegmentFromHeaders(headers2) : null,
|
|
389
|
-
activeVariant: resolved.abTesting ? getActiveVariantFromHeaders(headers2) : null,
|
|
390
|
-
segments,
|
|
391
|
-
data: segments
|
|
392
|
-
};
|
|
272
|
+
return "A";
|
|
393
273
|
}
|
|
394
274
|
|
|
395
|
-
// src/nextjs/
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
}
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
275
|
+
// src/nextjs/draft.ts
|
|
276
|
+
import { cookies, draftMode } from "next/headers";
|
|
277
|
+
import { redirect } from "next/navigation";
|
|
278
|
+
import { NextResponse as NextResponse2 } from "next/server";
|
|
279
|
+
var DRAFT_COOKIE = "__prerender_bypass";
|
|
280
|
+
var RETURN_PARAM = "prepr_draft";
|
|
281
|
+
var DEFAULT_ROUTE = "/api/prepr/draft";
|
|
282
|
+
function preprDraftRedirect(request, options) {
|
|
283
|
+
if (!options.preview) return null;
|
|
284
|
+
if (request.method !== "GET" && request.method !== "HEAD") return null;
|
|
285
|
+
const url = request.nextUrl;
|
|
286
|
+
if (url.pathname === (options.route ?? DEFAULT_ROUTE)) return null;
|
|
287
|
+
if (request.cookies.has(DRAFT_COOKIE)) {
|
|
288
|
+
if (!url.searchParams.has(RETURN_PARAM)) return null;
|
|
289
|
+
const clean = url.clone();
|
|
290
|
+
clean.searchParams.delete(RETURN_PARAM);
|
|
291
|
+
return NextResponse2.redirect(clean, 307);
|
|
292
|
+
}
|
|
293
|
+
if (url.searchParams.has(RETURN_PARAM)) return null;
|
|
294
|
+
const target = new URL(options.route ?? DEFAULT_ROUTE, request.url);
|
|
295
|
+
target.searchParams.set("to", url.pathname + url.search);
|
|
296
|
+
return NextResponse2.redirect(target, 307);
|
|
414
297
|
}
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
298
|
+
function createPreprDraftRoute(options) {
|
|
299
|
+
return async (request) => {
|
|
300
|
+
if (!options.preview) return new Response("Not found", { status: 404 });
|
|
301
|
+
(await draftMode()).enable();
|
|
302
|
+
const self = new URL(request.url);
|
|
303
|
+
if (self.protocol === "https:") {
|
|
304
|
+
const jar = await cookies();
|
|
305
|
+
const draft = jar.get(DRAFT_COOKIE);
|
|
306
|
+
if (draft) {
|
|
307
|
+
jar.set({
|
|
308
|
+
name: DRAFT_COOKIE,
|
|
309
|
+
value: draft.value,
|
|
310
|
+
path: "/",
|
|
311
|
+
httpOnly: true,
|
|
312
|
+
secure: true,
|
|
313
|
+
sameSite: "none",
|
|
314
|
+
partitioned: true
|
|
315
|
+
});
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
let to = new URL(self.searchParams.get("to") ?? "/", self);
|
|
319
|
+
if (to.origin !== self.origin) to = new URL("/", self);
|
|
320
|
+
to.searchParams.set(RETURN_PARAM, "1");
|
|
321
|
+
redirect(to.pathname + to.search);
|
|
322
|
+
};
|
|
418
323
|
}
|
|
419
324
|
|
|
420
325
|
// src/nextjs/index.ts
|
|
@@ -423,9 +328,11 @@ import {
|
|
|
423
328
|
PreprTrackingPixel
|
|
424
329
|
} from "./components.js";
|
|
425
330
|
export {
|
|
331
|
+
PREPR_BUCKET_COOKIE,
|
|
426
332
|
PreprError,
|
|
427
333
|
PreprToolbar,
|
|
428
334
|
PreprTrackingPixel,
|
|
335
|
+
createPreprDraftRoute,
|
|
429
336
|
createPreprMiddleware,
|
|
430
337
|
extractAccessToken,
|
|
431
338
|
getActiveSegment,
|
|
@@ -433,5 +340,8 @@ export {
|
|
|
433
340
|
getPreprHeaders,
|
|
434
341
|
getPreprUUID,
|
|
435
342
|
getToolbarProps,
|
|
343
|
+
isPersonalizedResponse,
|
|
344
|
+
preprDraftRedirect,
|
|
345
|
+
resolvePreprBucket,
|
|
436
346
|
validatePreprToken
|
|
437
347
|
};
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
type Dictionary = Record<string, unknown>;
|
|
2
|
+
declare const dictionaries: {
|
|
3
|
+
en: Dictionary;
|
|
4
|
+
nl: Dictionary;
|
|
5
|
+
};
|
|
6
|
+
type Locale = keyof typeof dictionaries;
|
|
7
|
+
|
|
8
|
+
interface PreprSegment {
|
|
9
|
+
readonly _id: string;
|
|
10
|
+
readonly name: string;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Per-feature config. `false` is shorthand for `{ enabled: false }`; the object
|
|
14
|
+
* form leaves room for per-feature options later without a breaking change.
|
|
15
|
+
*/
|
|
16
|
+
type PreprFeatureConfig = boolean | {
|
|
17
|
+
enabled?: boolean;
|
|
18
|
+
};
|
|
19
|
+
/** Toolkit features a consumer can turn off. Omitted keys stay enabled. */
|
|
20
|
+
interface PreprFeatures {
|
|
21
|
+
/** Segment picker, `Prepr-Segments` header and its cookie/query param. */
|
|
22
|
+
segments?: PreprFeatureConfig;
|
|
23
|
+
/** A/B variant switch, `Prepr-ABtesting` header and its cookie/query param. */
|
|
24
|
+
abTesting?: PreprFeatureConfig;
|
|
25
|
+
/**
|
|
26
|
+
* The site's own click-to-edit: the toolbar's Edit mode control, the stega
|
|
27
|
+
* tooltip/overlay and the close-edit pill.
|
|
28
|
+
*
|
|
29
|
+
* NOT a security control, and NOT the Prepr editor's live preview. When the
|
|
30
|
+
* site is framed by the editor, `prepr:initVE` still activates edit mode —
|
|
31
|
+
* that is the CMS operating inside its own iframe, not an affordance offered
|
|
32
|
+
* to visitors. See iframe-bridge.ts.
|
|
33
|
+
*/
|
|
34
|
+
editMode?: PreprFeatureConfig;
|
|
35
|
+
}
|
|
36
|
+
interface PreprToolbarOptions {
|
|
37
|
+
debug?: boolean;
|
|
38
|
+
locale?: Locale;
|
|
39
|
+
/** Disable features app-wide. Pass the same object to the middleware. */
|
|
40
|
+
features?: PreprFeatures;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Options for the preview runtime. Two independent axes: `features` decides
|
|
44
|
+
* *what runs*, `ui` decides *whether the toolbar is visible*.
|
|
45
|
+
*/
|
|
46
|
+
interface PreprPreviewOptions extends PreprToolbarOptions {
|
|
47
|
+
/**
|
|
48
|
+
* Mount the visible `<prepr-toolbar>` element. Default `true`.
|
|
49
|
+
*
|
|
50
|
+
* `false` keeps every non-visual side effect wired — click-to-edit, the
|
|
51
|
+
* editor bridge, scroll restore, cookies and headers — with no chrome of its
|
|
52
|
+
* own. That is how a site gets live editing, or editor scroll restore, while
|
|
53
|
+
* rendering its own UI instead of the bar.
|
|
54
|
+
*
|
|
55
|
+
* Already implied inside the editor's iframe (the CMS owns the chrome there)
|
|
56
|
+
* and by `?prepr_hide_bar=true`, so this option is for consumers who want a
|
|
57
|
+
* headless preview by their own choice.
|
|
58
|
+
*/
|
|
59
|
+
ui?: boolean;
|
|
60
|
+
/**
|
|
61
|
+
* Replace the `*.prepr.io` editor-origin wildcard with an exact list.
|
|
62
|
+
* Intended for self-hosted editors; when set, the wildcard no longer applies.
|
|
63
|
+
*/
|
|
64
|
+
allowedEditorOrigins?: string[];
|
|
65
|
+
/**
|
|
66
|
+
* Strip the invisible stega characters out of visible text at runtime.
|
|
67
|
+
* Default `true`.
|
|
68
|
+
*
|
|
69
|
+
* Preview content carries an encoded payload inside the text itself. Left in
|
|
70
|
+
* place it is invisible but real: it inflates `String.length`, breaks text
|
|
71
|
+
* measurement and truncation, and is announced by screen readers.
|
|
72
|
+
*
|
|
73
|
+
* Set `false` only when the site already strips the characters itself — for
|
|
74
|
+
* example by passing every field through `stegaClean` as it renders.
|
|
75
|
+
* Click-to-edit is unaffected either way: elements are still tagged from the
|
|
76
|
+
* payload, so the overlay keeps working.
|
|
77
|
+
*/
|
|
78
|
+
autoClean?: boolean;
|
|
79
|
+
}
|
|
80
|
+
interface PreprToolbarProps {
|
|
81
|
+
/**
|
|
82
|
+
* Server-resolved active segment. Optional: omit it with `segments`
|
|
83
|
+
* disabled, where there is nothing to resolve. When enabled and omitted,
|
|
84
|
+
* the persisted cookie is used.
|
|
85
|
+
*/
|
|
86
|
+
readonly activeSegment?: string | null;
|
|
87
|
+
/**
|
|
88
|
+
* Server-resolved active A/B variant. Optional: omit it with `abTesting`
|
|
89
|
+
* disabled, where there is nothing to resolve. When enabled and omitted,
|
|
90
|
+
* the persisted cookie is used.
|
|
91
|
+
*/
|
|
92
|
+
readonly activeVariant?: string | null;
|
|
93
|
+
/** Available segments to personalize on. */
|
|
94
|
+
readonly segments?: readonly PreprSegment[];
|
|
95
|
+
/** @deprecated Alias for `segments`. */
|
|
96
|
+
readonly data?: readonly PreprSegment[];
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Prop type for the framework `<PreprToolbar>` components: the toolbar data
|
|
100
|
+
* plus the options bag core `createPreprPreview` accepts.
|
|
101
|
+
*/
|
|
102
|
+
interface PreprToolbarComponentProps extends PreprToolbarProps {
|
|
103
|
+
options?: PreprPreviewOptions;
|
|
104
|
+
}
|
|
105
|
+
type PreprVariant = 'A' | 'B';
|
|
106
|
+
interface PreprHeaders {
|
|
107
|
+
readonly 'prepr-customer-id'?: string;
|
|
108
|
+
readonly 'Prepr-Segments'?: string;
|
|
109
|
+
readonly 'Prepr-ABtesting'?: PreprVariant;
|
|
110
|
+
readonly 'Prepr-Preview-Bar'?: 'true';
|
|
111
|
+
readonly 'Prepr-Context-utm_source'?: string;
|
|
112
|
+
readonly 'Prepr-Context-utm_medium'?: string;
|
|
113
|
+
readonly 'Prepr-Context-utm_term'?: string;
|
|
114
|
+
readonly 'Prepr-Context-utm_content'?: string;
|
|
115
|
+
readonly 'Prepr-Context-utm_campaign'?: string;
|
|
116
|
+
readonly 'Prepr-Context-initial_referral'?: string;
|
|
117
|
+
readonly 'Prepr-Visitor-IP'?: string;
|
|
118
|
+
readonly 'Prepr-Hubspot-Id'?: string;
|
|
119
|
+
readonly 'Prepr-Customer-Id-Created'?: 'true';
|
|
120
|
+
/** The visitor's browser User-Agent, used by the API for device detection. */
|
|
121
|
+
readonly 'User-Agent'?: string;
|
|
122
|
+
/** @deprecated Never populated; the visitor's value is under `User-Agent`. */
|
|
123
|
+
readonly 'Prepr-User-Agent'?: string;
|
|
124
|
+
readonly 'Prepr-Package'?: string;
|
|
125
|
+
}
|
|
126
|
+
type PreprErrorCode = 'INVALID_TOKEN' | 'MISSING_TOKEN' | 'HTTP_ERROR' | 'FETCH_ERROR' | 'INVALID_RESPONSE' | 'CONTEXT_ERROR' | 'GRAPHQL_ERROR' | 'INVALID_DOCUMENT';
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Whether a Prepr GraphQL response differs per visitor, read from its `Vary`
|
|
130
|
+
* header. Use it when fetching with your own GraphQL client; the toolkit's
|
|
131
|
+
* `createPreprClient` already returns it as `personalized`.
|
|
132
|
+
*
|
|
133
|
+
* Never throws; a response without `Vary` is not personalized.
|
|
134
|
+
*/
|
|
135
|
+
declare function isPersonalizedResponse(source: Response | Headers): boolean;
|
|
136
|
+
|
|
137
|
+
/** Error thrown by the token helpers and the segments fetch. */
|
|
138
|
+
declare class PreprError extends Error {
|
|
139
|
+
readonly code: PreprErrorCode;
|
|
140
|
+
readonly context?: string | undefined;
|
|
141
|
+
readonly originalError?: Error | undefined;
|
|
142
|
+
constructor(message: string, code: PreprErrorCode, context?: string | undefined, originalError?: Error | undefined);
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Asserts `token` is the full `https://graphql.prepr.io/<token>` URL.
|
|
146
|
+
* @throws PreprError if the token is missing or not an HTTPS URL.
|
|
147
|
+
*/
|
|
148
|
+
declare function validatePreprToken(token: string): void;
|
|
149
|
+
/**
|
|
150
|
+
* Pulls the access token out of a GraphQL URL: `https://graphql.prepr.io/abc123`
|
|
151
|
+
* -> `abc123`.
|
|
152
|
+
* @throws PreprError if the URL is not a valid `graphql.prepr.io` URL.
|
|
153
|
+
*/
|
|
154
|
+
declare function extractAccessToken(graphqlUrl: string): string;
|
|
155
|
+
|
|
156
|
+
export { type PreprHeaders as P, PreprError as a, type PreprFeatures as b, type PreprToolbarProps as c, type PreprToolbarComponentProps as d, extractAccessToken as e, isPersonalizedResponse as i, validatePreprToken as v };
|